comparison libfaim/aim_rxqueue.c @ 503:6e318907bcce

[gaim-migrate @ 513] bringing gaim up to latest libfaim committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 18 Jul 2000 05:37:39 +0000
parents e4c34ca88d9b
children 9a123b171f46
comparison
equal deleted inserted replaced
502:4d1e39112cbd 503:6e318907bcce
27 * Rendezvous (client-client) connections do not speak 27 * Rendezvous (client-client) connections do not speak
28 * FLAP, so this function will break on them. 28 * FLAP, so this function will break on them.
29 */ 29 */
30 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS) 30 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS)
31 return aim_get_command_rendezvous(sess, conn); 31 return aim_get_command_rendezvous(sess, conn);
32 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT)
33 return 0;
32 34
33 /* 35 /*
34 * Read FLAP header. Six bytes: 36 * Read FLAP header. Six bytes:
35 * 37 *
36 * 0 char -- Always 0x2a 38 * 0 char -- Always 0x2a
38 * 2 short -- Sequence number 40 * 2 short -- Sequence number
39 * 4 short -- Number of data bytes that follow. 41 * 4 short -- Number of data bytes that follow.
40 */ 42 */
41 faim_mutex_lock(&conn->active); 43 faim_mutex_lock(&conn->active);
42 if (read(conn->fd, generic, 6) < 6){ 44 if (read(conn->fd, generic, 6) < 6){
43 aim_conn_kill(sess, &conn); 45 aim_conn_close(conn);
44 faim_mutex_unlock(&conn->active); 46 faim_mutex_unlock(&conn->active);
45 return -1; 47 return -1;
46 } 48 }
47 49
48 /* 50 /*
49 * This shouldn't happen unless the socket breaks, the server breaks, 51 * This shouldn't happen unless the socket breaks, the server breaks,
50 * or we break. We must handle it just in case. 52 * or we break. We must handle it just in case.
51 */ 53 */
52 if (generic[0] != 0x2a) { 54 if (generic[0] != 0x2a) {
53 faimdprintf(1, "Bad incoming data!"); 55 faimdprintf(1, "Bad incoming data!");
56 aim_conn_close(conn);
54 faim_mutex_unlock(&conn->active); 57 faim_mutex_unlock(&conn->active);
55 return -1; 58 return -1;
56 } 59 }
57 60
58 /* allocate a new struct */ 61 /* allocate a new struct */
87 90
88 /* read the data portion of the packet */ 91 /* read the data portion of the packet */
89 if (read(conn->fd, newrx->data, newrx->commandlen) < newrx->commandlen){ 92 if (read(conn->fd, newrx->data, newrx->commandlen) < newrx->commandlen){
90 free(newrx->data); 93 free(newrx->data);
91 free(newrx); 94 free(newrx);
92 aim_conn_kill(sess, &conn); 95 aim_conn_close(conn);
93 faim_mutex_unlock(&conn->active); 96 faim_mutex_unlock(&conn->active);
94 return -1; 97 return -1;
95 } 98 }
96 faim_mutex_unlock(&conn->active); 99 faim_mutex_unlock(&conn->active);
97 100
118 } 121 }
119 122
120 newrx->conn->lastactivity = time(NULL); 123 newrx->conn->lastactivity = time(NULL);
121 124
122 return 0; 125 return 0;
123 }
124
125 int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn)
126 {
127 unsigned char hdrbuf1[6];
128 unsigned char *hdr = NULL;
129 int hdrlen, hdrtype;
130 int payloadlength = 0;
131 int flags = 0;
132 char *snptr = NULL;
133
134 if (read(conn->fd, hdrbuf1, 6) < 6) {
135 perror("read");
136 printf("faim: rend: read error\n");
137 aim_conn_kill(sess, &conn);
138 return -1;
139 }
140
141 hdrlen = aimutil_get16(hdrbuf1+4);
142
143 hdrlen -= 6;
144 hdr = malloc(hdrlen);
145
146 faim_mutex_lock(&conn->active);
147 if (read(conn->fd, hdr, hdrlen) < hdrlen) {
148 perror("read");
149 printf("faim: rend: read2 error\n");
150 free(hdr);
151 faim_mutex_unlock(&conn->active);
152 aim_conn_kill(sess, &conn);
153 return -1;
154 }
155
156 hdrtype = aimutil_get16(hdr);
157
158 switch (hdrtype) {
159 case 0x0001: {
160 payloadlength = aimutil_get32(hdr+22);
161 flags = aimutil_get16(hdr+32);
162 snptr = hdr+38;
163
164 printf("OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr);
165
166 if (flags == 0x000e) {
167 printf("directim: %s has started typing\n", snptr);
168 } else if ((flags == 0x0000) && payloadlength) {
169 unsigned char *buf;
170 buf = malloc(payloadlength+1);
171
172 /* XXX theres got to be a better way */
173 faim_mutex_lock(&conn->active);
174 if (recv(conn->fd, buf, payloadlength, MSG_WAITALL) < payloadlength) {
175 perror("read");
176 printf("faim: rend: read3 error\n");
177 free(buf);
178 faim_mutex_unlock(&conn->active);
179 aim_conn_kill(sess, &conn);
180 return -1;
181 }
182 faim_mutex_unlock(&conn->active);
183 buf[payloadlength] = '\0';
184 printf("directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, buf);
185 aim_send_im_direct(sess, conn, buf);
186 free(buf);
187 }
188 break;
189 }
190 default:
191 printf("OFT frame: type %04x\n", hdrtype);
192 /* data connection may be unreliable here */
193 break;
194 } /* switch */
195
196 free(hdr);
197
198 return 0;
199 } 126 }
200 127
201 /* 128 /*
202 * Purge recieve queue of all handled commands (->handled==1). Also 129 * Purge recieve queue of all handled commands (->handled==1). Also
203 * allows for selective freeing using ->nofree so that the client can 130 * allows for selective freeing using ->nofree so that the client can