Mercurial > pidgin
annotate libfaim/aim_ft.c @ 942:e77eb4277d7c
[gaim-migrate @ 952]
Wagii.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Sun, 01 Oct 2000 08:05:48 +0000 |
parents | 13bdc97d433e |
children | fa681641643d |
rev | line source |
---|---|
503 | 1 #include <faim/aim.h> |
2 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
3 #ifndef _WIN32 |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
4 #include <netdb.h> |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
5 #include <sys/socket.h> |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
6 #include <netinet/in.h> |
503 | 7 #include <sys/utsname.h> /* for aim_directim_initiate */ |
8 #include <arpa/inet.h> /* for inet_ntoa */ | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
9 #endif |
932
13bdc97d433e
[gaim-migrate @ 942]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
10 #ifdef NEED_SOCKLEN_T |
13bdc97d433e
[gaim-migrate @ 942]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
11 typedef unsigned int socklen_t; |
13bdc97d433e
[gaim-migrate @ 942]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
889
diff
changeset
|
12 #endif |
640
2c0a7d245bd2
[gaim-migrate @ 650]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
503
diff
changeset
|
13 |
503 | 14 /* aim_msgcookies.c is mostly new. just look at the diff and replace yours, easiest. */ |
15 | |
16 /* | |
17 function name where i had it | |
18 aim_send_im_direct aim_im.c | |
19 aim_directim_initiate aim_im.c | |
20 aim_filetransfer_accept aim_im.c | |
21 aim_getlisting aim_misc.c (?!) -- prototype function. can be ignored. | |
22 establish aim_misc.c | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
23 aim_get_command_rendezvous aim_r |
503 | 24 oft_getfh aim_rxqueue.c |
25 */ | |
26 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
27 faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur) |
503 | 28 { |
29 int acceptfd = 0; | |
30 rxcallback_t userfunc; | |
31 struct sockaddr cliaddr; | |
32 socklen_t clilen = sizeof(cliaddr); | |
33 int ret = 0; | |
34 | |
35 /* | |
36 * Listener sockets only have incoming connections. No data. | |
37 */ | |
38 if( (acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1) | |
39 return -1; | |
40 | |
41 if (cliaddr.sa_family != AF_INET) /* just in case IPv6 really is happening */ | |
42 return -1; | |
43 | |
44 switch(cur->subtype) { | |
45 case AIM_CONN_SUBTYPE_OFT_DIRECTIM: { | |
46 struct aim_directim_priv *priv; | |
47 | |
48 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); | |
49 | |
50 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | |
51 | |
52 if(!cur->priv) | |
53 cur->priv = priv; /* what happens if there is one?! -- mid */ | |
54 | |
55 cur->type = AIM_CONN_TYPE_RENDEZVOUS; | |
56 close(cur->fd); /* should we really do this? seems like the client should decide. maybe clone the connection and keep the listener open. -- mid */ | |
57 cur->fd = acceptfd; | |
58 | |
59 if ( (userfunc = aim_callhandler(cur, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE))) | |
60 ret = userfunc(sess, NULL, cur); | |
61 | |
62 break; | |
63 } | |
64 case AIM_CONN_SUBTYPE_OFT_GETFILE: { | |
65 struct aim_filetransfer_priv *priv; | |
66 | |
67 priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); | |
68 | |
69 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | |
70 | |
71 if(!cur->priv) | |
72 cur->priv = priv; | |
73 | |
74 if ( (userfunc = aim_callhandler(cur, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE))) | |
75 ret = userfunc(sess, NULL, cur); | |
76 break; | |
77 } | |
78 default: { | |
79 /* XXX */ | |
80 } | |
81 } | |
82 return ret; | |
83 } | |
84 | |
85 | |
86 /* | |
87 * aim_send_im_direct: | |
88 * sess - session | |
89 * conn - directim connection | |
90 * msg - null-terminated string to send | |
91 */ | |
92 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
93 faim_export int aim_send_im_direct(struct aim_session_t *sess, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
94 struct aim_conn_t *conn, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
95 char *msg) |
503 | 96 { |
97 struct command_tx_struct *newpacket , *newpacket2; | |
98 | |
99 /* newpacket contains a real header with data, newpacket2 is just a | |
100 null packet, with a cookie and a lot of 0x00s. newpacket is the | |
101 "i'm sending", newpacket2 is the "i'm typing".*/ | |
102 | |
103 /* uhm. the client should send those as two seperate things -- mid */ | |
104 | |
105 struct aim_directim_priv *priv = NULL; | |
106 int i; | |
107 | |
108 if (strlen(msg) >= MAXMSGLEN) | |
109 return -1; | |
110 | |
111 if (!sess || !conn || !(conn->type) || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv) { | |
112 printf("faim: directim: invalid arguments\n"); | |
113 return -1; | |
114 }; | |
115 | |
116 priv = (struct aim_directim_priv *)conn->priv; | |
117 | |
118 /* NULLish Header */ | |
119 | |
120 if (!(newpacket2 = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, 0))) { | |
121 printf("faim: directim: tx_new2 failed\n"); | |
122 return -1; | |
123 } | |
124 | |
125 newpacket2->lock = 1; /* lock struct */ | |
126 | |
127 memcpy(newpacket2->hdr.oft.magic, "ODC2", 4); | |
128 newpacket2->hdr.oft.hdr2len = 0x44; | |
129 | |
130 if (!(newpacket2->hdr.oft.hdr2 = calloc(1,newpacket2->hdr.oft.hdr2len))) { | |
131 free(newpacket2); | |
132 return -1; | |
133 } | |
134 | |
135 i = 0; | |
136 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0006); | |
137 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
138 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
139 i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, (char *)priv->cookie, 8); |
503 | 140 |
141 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
142 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
143 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
144 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
145 | |
146 i += aimutil_put32(newpacket2->hdr.oft.hdr2+i, 0x00000000); | |
147 | |
148 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
149 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
150 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
151 | |
152 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x000e); | |
153 | |
154 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
155 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
156 | |
157 i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name)); | |
158 | |
159 i = 52; /* 0x34 */ | |
160 i += aimutil_put8(newpacket2->hdr.oft.hdr2+i, 0x00); /* 53 */ | |
161 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); /* 55 */ | |
162 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
163 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
164 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* 61 */ | |
165 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); | |
166 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* 65 */ | |
167 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* end of hdr2 */ | |
168 | |
169 newpacket2->lock = 0; | |
170 newpacket2->data = NULL; | |
171 | |
172 aim_tx_enqueue(sess, newpacket2); | |
173 | |
174 /* Header packet */ | |
175 | |
176 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, strlen(msg)))) { | |
177 printf("faim: directim: tx_new failed\n"); | |
178 return -1; | |
179 } | |
180 | |
181 newpacket->lock = 1; /* lock struct */ | |
182 | |
183 memcpy(newpacket->hdr.oft.magic, "ODC2", 4); | |
184 newpacket->hdr.oft.hdr2len = 0x54; | |
185 | |
186 if (!(newpacket->hdr.oft.hdr2 = calloc(1,newpacket->hdr.oft.hdr2len))) { | |
187 free(newpacket); | |
188 return -1; | |
189 } | |
190 | |
191 i = 0; | |
192 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0006); | |
193 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
194 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
195 i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, (char *)priv->cookie, 8); |
503 | 196 |
197 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
198 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
199 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
200 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
201 | |
202 i += aimutil_put32(newpacket->hdr.oft.hdr2+i, strlen(msg)); | |
203 | |
204 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
205 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
206 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
207 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
208 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
209 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
210 | |
211 i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name)); | |
212 | |
213 i = 52; /* 0x34 */ | |
214 i += aimutil_put8(newpacket->hdr.oft.hdr2+i, 0x00); /* 53 */ | |
215 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); /* 55 */ | |
216 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
217 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
218 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 61 */ | |
219 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
220 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 65 */ | |
221 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* end of hdr2 */ | |
222 | |
223 /* values grabbed from a dump */ | |
224 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008); /* 69 */ | |
225 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c); | |
226 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 71 */ | |
227 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466);/* 73 */ | |
228 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001);/* 73 */ | |
229 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f); | |
230 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e); | |
231 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8); | |
232 | |
233 memcpy(newpacket->data, msg, strlen(msg)); | |
234 | |
235 newpacket->lock = 0; | |
236 | |
237 aim_tx_enqueue(sess, newpacket); | |
238 | |
239 return 0; | |
240 } | |
241 | |
242 /* | |
243 * aim_directim_intitiate: | |
244 * For those times when we want to open up the directim channel ourselves. | |
245 * sess is your session, | |
246 * conn is the BOS conn, | |
247 * priv is a dummy priv value (we'll let it get filled in later) (if | |
248 * you pass a NULL, we alloc one) | |
249 * destsn is the SN to connect to. | |
250 */ | |
251 | |
252 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
253 faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
254 struct aim_conn_t *conn, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
255 struct aim_directim_priv *priv, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
256 char *destsn) |
503 | 257 { |
258 struct command_tx_struct *newpacket; | |
259 struct aim_conn_t *newconn; | |
260 | |
261 struct aim_msgcookie_t *cookie; | |
262 | |
263 int curbyte, i, listenfd; | |
264 short port = 4443; | |
265 | |
266 struct hostent *hptr; | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
267 char localhost[129]; |
503 | 268 |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
269 unsigned char cap[16]; |
503 | 270 char d[4]; /* XXX: IPv6. *cough* */ |
271 | |
272 /* | |
273 * Open our socket | |
274 */ | |
275 | |
276 if( (listenfd = aim_listenestablish(port)) == -1) | |
277 return NULL; | |
278 | |
279 /* | |
280 * get our local IP | |
281 */ | |
282 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
283 if(gethostname(localhost, 128) < 0) |
503 | 284 return NULL; |
285 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
286 if( (hptr = gethostbyname(localhost)) == NULL) |
503 | 287 return NULL; |
288 | |
289 memcpy(&d, hptr->h_addr_list[0], 4); /* XXX: this probably isn't quite kosher, but it works */ | |
290 | |
291 aim_putcap(cap, 16, AIM_CAPS_IMIMAGE); | |
292 | |
293 /* | |
294 * create the OSCAR packet | |
295 */ | |
296 | |
297 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(destsn)+4+4+0x32))) | |
298 return NULL; | |
299 | |
300 newpacket->lock = 1; /* lock struct */ | |
301 | |
302 curbyte = 0; | |
303 curbyte += aim_putsnac(newpacket->data+curbyte, | |
304 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
305 | |
306 /* | |
307 * Generate a random message cookie | |
308 * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible. | |
309 */ | |
310 for (i=0;i<7;i++) | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
311 curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) rand() % 20)); |
503 | 312 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); |
313 | |
314 /* | |
315 * grab all the data for cookie caching. | |
316 */ | |
317 cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)); | |
318 | |
319 memcpy(cookie->cookie, newpacket->data+curbyte-8, 8); | |
320 cookie->type = AIM_COOKIETYPE_OFTIM; | |
321 | |
322 if(!priv) | |
323 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); | |
324 | |
325 memcpy(priv->cookie, cookie, 8); | |
326 memcpy(priv->sn, destsn, sizeof(priv->sn)); | |
327 | |
328 cookie->data = priv; | |
329 | |
330 aim_cachecookie(sess, cookie); /* cache da cookie */ | |
331 | |
332 /* | |
333 * Channel ID | |
334 */ | |
335 curbyte += aimutil_put16(newpacket->data+curbyte,0x0002); | |
336 | |
337 /* | |
338 * Destination SN (prepended with byte length) | |
339 */ | |
340 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn)); | |
341 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); | |
342 | |
343 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
344 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
345 | |
346 /* | |
347 * enTLV start | |
348 */ | |
349 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
350 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0032); | |
351 | |
352 /* | |
353 * Flag data / ICBM Parameters? | |
354 */ | |
355 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
356 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
357 | |
358 /* | |
359 * Cookie | |
360 */ | |
361 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8); | |
362 | |
363 /* | |
364 * Capability String | |
365 */ | |
366 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10); | |
367 | |
368 /* | |
369 * 000a/0002 : 0001 | |
370 */ | |
371 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a); | |
372 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
373 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
374 | |
375 /* | |
376 * 0003/0004: IP address | |
377 */ | |
378 | |
379 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
380 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004); | |
381 | |
382 for(i = 0; i < 4; i++) | |
383 curbyte += aimutil_put8(newpacket->data+curbyte, d[i]); /* already in network byte order */ | |
384 | |
385 /* | |
386 * 0005/0002: Port | |
387 */ | |
388 | |
389 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
390 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
391 curbyte += aimutil_put16(newpacket->data+curbyte, port); | |
392 | |
393 /* | |
394 * 000f/0000: umm.. dunno. Zigamorph[1]? | |
395 * [1]: see esr's TNHD. | |
396 */ | |
397 | |
398 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f); | |
399 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
400 | |
401 printf("curbyte: 0x%x\n",curbyte); | |
402 | |
403 newpacket->commandlen = curbyte; | |
404 newpacket->lock = 0; | |
405 | |
406 aim_tx_enqueue(sess, newpacket); | |
407 | |
408 /* | |
409 * allocate and set up our connection | |
410 */ | |
411 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
412 #if 0 |
503 | 413 i = fcntl(listenfd, F_GETFL, 0); |
414 fcntl(listenfd, F_SETFL, i | O_NONBLOCK); | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
415 #endif |
503 | 416 |
417 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL); | |
418 if (!newconn) { | |
419 perror("aim_newconn"); | |
420 aim_conn_kill(sess, &newconn); | |
421 return NULL; | |
422 } | |
423 | |
424 newconn->fd = listenfd; | |
425 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; | |
426 newconn->priv = priv; | |
427 printf("faim: listening (fd = %d, unconnected)\n", newconn->fd); | |
428 | |
429 /* | |
430 * XXX We need some way of closing the listener socket after | |
431 * n seconds of no connection. -- mid | |
432 */ | |
433 | |
434 #ifdef USE_SNAC_FOR_IMS | |
435 { | |
436 struct aim_snac_t snac; | |
437 | |
438 snac.id = sess->snac_nextid; | |
439 snac.family = 0x0004; | |
440 snac.type = 0x0006; | |
441 snac.flags = 0x0000; | |
442 | |
443 snac.data = malloc(strlen(destsn)+1); | |
444 memcpy(snac.data, destsn, strlen(destsn)+1); | |
445 | |
446 aim_newsnac(sess, &snac); | |
447 | |
448 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */ | |
449 } | |
450 #endif | |
451 | |
452 return (newconn); | |
453 } | |
454 | |
455 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
456 faim_export struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
457 struct aim_conn_t *conn, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
458 struct aim_directim_priv *priv ) |
503 | 459 { |
460 struct aim_conn_t *newconn = NULL;; | |
461 | |
462 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, priv->ip); | |
463 if (!newconn || (newconn->fd == -1)) { | |
464 printf("could not connect to %s\n", priv->ip); | |
465 perror("aim_newconn"); | |
466 aim_conn_kill(sess, &newconn); | |
467 return NULL; | |
468 } else { | |
469 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; | |
470 newconn->priv = priv; | |
471 printf("faim: connected to peer (fd = %d)\n", newconn->fd); | |
472 return newconn; | |
473 } | |
474 return newconn; | |
475 } | |
476 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
477 faim_export unsigned long aim_accepttransfer(struct aim_session_t *sess, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
478 struct aim_conn_t *conn, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
479 struct aim_conn_t *oftconn, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
480 char *sn, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
481 char *cookie, |
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
482 unsigned short rendid) |
503 | 483 { |
484 struct command_tx_struct *newpacket, *newoft; | |
485 struct aim_fileheader_t *listingfh; | |
486 int curbyte, i; | |
487 /* now for the oft bits */ | |
488 | |
489 if(rendid == AIM_CAPS_GETFILE) { | |
490 printf("jbm: getfile request accept\n"); | |
491 if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1108, oftconn, 0))) { | |
492 printf("faim: accept_transfer: tx_new OFT failed\n"); | |
493 return -1; | |
494 } | |
495 | |
496 newoft->lock = 1; | |
497 | |
498 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
499 newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */ | |
500 | |
501 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { | |
502 free(newoft); | |
503 return -1; | |
504 } | |
505 | |
506 listingfh = aim_getlisting(sess); | |
507 | |
508 memcpy(listingfh->bcookie, cookie, 8); | |
509 | |
510 curbyte = 0; | |
511 | |
512 for(i = 0; i < 8; i++) | |
513 curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, cookie[i]); | |
514 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->encrypt); | |
515 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->compress); | |
516 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totfiles); | |
517 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->filesleft); | |
518 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totparts); | |
519 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->partsleft); | |
520 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->totsize); | |
521 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->size); | |
522 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->modtime); | |
523 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->checksum); | |
524 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfrcsum); | |
525 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfsize); | |
526 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->cretime); | |
527 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfcsum); | |
528 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->nrecvd); | |
529 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->recvcsum); | |
530 | |
531 memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32); | |
532 curbyte += 32; | |
533 | |
534 curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->flags); | |
535 curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lnameoffset); | |
536 curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lsizeoffset); | |
537 | |
538 memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->dummy, 69); | |
539 curbyte += 69; | |
540 | |
541 memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->macfileinfo, 16); | |
542 curbyte += 16; | |
543 | |
544 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode); | |
545 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage); | |
546 | |
547 memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64); | |
548 curbyte += 64; | |
549 | |
550 free(listingfh); | |
551 | |
552 newoft->lock = 0; | |
553 aim_tx_enqueue(sess, newoft); | |
554 printf("faim: getfile: OFT listing enqueued.\n"); | |
555 | |
556 } | |
557 | |
558 | |
559 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sn)+4+2+8+16))) | |
560 return -1; | |
561 | |
562 newpacket->lock = 1; | |
563 | |
564 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
565 for (i = 0; i < 8; i++) | |
566 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]); | |
567 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
568 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn)); | |
569 curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn)); | |
570 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
571 curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a); | |
572 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept */); | |
573 for (i = 0; i < 8; i++) | |
574 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]); | |
575 curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid); | |
576 | |
577 newpacket->lock = 0; | |
578 aim_tx_enqueue(sess, newpacket); | |
579 | |
580 | |
581 | |
582 return (sess->snac_nextid++); | |
583 } | |
584 | |
585 /* | |
586 * aim_getlisting() | |
587 * | |
588 * Get file listing.txt info. where else to put it? i | |
589 * dunno. client-side issue for sure tho. for now we just side-step | |
590 * the issue with a nice default. =) | |
591 * | |
592 */ | |
593 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
594 faim_internal struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess) |
503 | 595 { |
596 struct aim_fileheader_t *fh; | |
597 | |
598 if(!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) | |
599 return NULL; | |
600 | |
601 fh->encrypt = 0x0000; | |
602 fh->compress = 0x0000; | |
603 fh->totfiles = 0x0001; | |
604 fh->filesleft = 0x0001; | |
605 fh->totparts = 0x0001; | |
606 fh->partsleft = 0x0001; | |
607 fh->totsize = 0x00000064; | |
608 fh->size = 0x00000024; /* ls -l listing.txt */ | |
609 fh->modtime = (int)time(NULL); /*0x39441fb4; */ | |
610 fh->checksum = 0xb8350000; | |
611 fh->rfcsum = 0x00000000; | |
612 fh->rfsize = 0x00000000; | |
613 fh->cretime = 0x00000000; | |
614 fh->rfcsum = 0x00000000; | |
615 fh->nrecvd = 0x00000000; | |
616 fh->recvcsum = 0x00000000; | |
617 | |
618 memset(fh->idstring, 0, 32/*sizeof(fh->idstring)*/); | |
619 memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", 32/*sizeof(fh->idstring)*/); | |
620 memset(fh->idstring+strlen(fh->idstring), 0, 32-strlen(fh->idstring)); /* jbm hack */ | |
621 | |
622 fh->flags = 0x02; | |
623 fh->lnameoffset = 0x1a; | |
624 fh->lsizeoffset = 0x10; | |
625 | |
626 memset(fh->dummy, 0, 69/*sizeof(fh->dummy)*/); | |
627 /* fh->dummy = ;*/ | |
628 | |
629 memset(fh->macfileinfo, 0, 16/*sizeof(fh->macfileinfo)*/); | |
630 /* fh->macfileinfo = ; */ | |
631 | |
632 fh->nencode = 0x0000; | |
633 fh->nlanguage = 0x0000; | |
634 | |
635 memset(fh->name, 0, 64/*sizeof(fh->name)*/); | |
636 memcpy(fh->name, "listing.txt", 64 /*sizeof(fh->name)*/); | |
637 memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name)); /* jbm hack */ | |
638 | |
639 printf("jbm: fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name)))); | |
640 return fh; | |
641 } | |
642 | |
643 /* | |
644 * establish: create a listening socket on a port. you need to call | |
645 * accept() when it's connected. | |
646 * portnum is the port number to bind to. | |
647 * returns your fd | |
648 */ | |
649 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
650 faim_internal int aim_listenestablish(u_short portnum) |
503 | 651 { |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
652 #if defined(__linux__) /* XXX what other OS's support getaddrinfo? */ |
503 | 653 int listenfd; |
654 const int on = 1; | |
655 struct addrinfo hints, *res, *ressave; | |
656 char serv[5]; | |
657 sprintf(serv, "%d", portnum); | |
658 memset(&hints, 0, sizeof(struct addrinfo)); | |
659 hints.ai_flags = AI_PASSIVE; | |
660 hints.ai_family = AF_UNSPEC; | |
661 hints.ai_socktype = SOCK_STREAM; | |
662 if (getaddrinfo(NULL/*any IP*/, serv, &hints, &res) != 0) { | |
663 perror("getaddrinfo"); | |
664 return -1; | |
665 } | |
666 ressave = res; | |
667 do { | |
668 listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | |
669 if (listenfd < 0) | |
670 continue; | |
671 setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); | |
672 if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0) | |
673 break; /* success */ | |
674 close(listenfd); | |
675 } while ( (res = res->ai_next) ); | |
676 if (!res) | |
677 return -1; | |
678 if (listen(listenfd, 1024)!=0) { | |
679 perror("listen"); | |
680 return -1; | |
681 } | |
682 freeaddrinfo(ressave); | |
683 return listenfd; | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
684 #else |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
685 int listenfd; |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
686 const int on = 1; |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
687 struct sockaddr_in sockin; |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
688 |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
689 if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
690 perror("socket(listenfd)"); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
691 return -1; |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
692 } |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
693 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on) != 0)) { |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
694 perror("setsockopt(listenfd)"); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
695 close(listenfd); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
696 return -1; |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
697 } |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
698 memset(&sockin, 0, sizeof(struct sockaddr_in)); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
699 sockin.sin_family = AF_INET; |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
700 sockin.sin_port = htons(portnum); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
701 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) { |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
702 perror("bind(listenfd)"); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
703 close(listenfd); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
704 return -1; |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
705 } |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
706 if (listen(listenfd, 4) != 0) { |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
707 perror("listen(listenfd)"); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
708 close(listenfd); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
709 return -1; |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
710 } |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
711 |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
712 return listenfd; |
640
2c0a7d245bd2
[gaim-migrate @ 650]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
503
diff
changeset
|
713 #endif |
503 | 714 } |
715 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
716 faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn) |
503 | 717 { |
718 | |
719 /* XXX: NOT THREAD SAFE RIGHT NOW. the locks are acting up. deal. -- jbm */ | |
720 | |
721 unsigned char hdrbuf1[6]; | |
722 unsigned char *hdr = NULL; | |
723 int hdrlen, hdrtype; | |
724 int flags = 0; | |
725 rxcallback_t userfunc = NULL; | |
726 | |
727 | |
728 memset(hdrbuf1, 0, sizeof(hdrbuf1)); | |
729 | |
730 faim_mutex_lock(&conn->active); /* gets locked down for the entirety */ | |
731 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
732 if ( (hdrlen = aim_recv(conn->fd, hdrbuf1, 6)) < 6) { |
503 | 733 if(hdrlen < 0) |
734 perror("read"); | |
735 printf("faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n", conn->fd, hdrbuf1[0],hdrbuf1[1],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrlen); | |
736 faim_mutex_unlock(&conn->active); | |
737 aim_conn_close(conn); | |
738 return -1; | |
739 } | |
740 | |
741 hdrlen = aimutil_get16(hdrbuf1+4); | |
742 | |
743 hdrlen -= 6; | |
744 if (!(hdr = malloc(hdrlen))) | |
745 return -1; | |
746 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
747 if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) { |
503 | 748 perror("read"); |
749 printf("faim: rend: read2 error\n"); | |
750 free(hdr); | |
751 faim_mutex_unlock(&conn->active); | |
752 aim_conn_close(conn); | |
753 return 0; /* see comment on previous read check */ | |
754 } | |
755 | |
756 hdrtype = aimutil_get16(hdr); | |
757 | |
758 switch (hdrtype) { | |
759 case 0x0001: { /* directim */ | |
760 int payloadlength = 0; | |
761 char *snptr = NULL; | |
762 struct aim_directim_priv *priv; | |
763 int i; | |
764 | |
765 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); | |
766 | |
767 payloadlength = aimutil_get32(hdr+22); | |
768 flags = aimutil_get16(hdr+32); | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
769 snptr = (char *)hdr+38; |
503 | 770 |
771 strncpy(priv->sn, snptr, MAXSNLEN); | |
772 | |
773 #if 0 | |
774 printf("faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); | |
775 #endif | |
776 | |
777 if (flags == 0x000e) { | |
778 faim_mutex_unlock(&conn->active); | |
779 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) ) | |
780 return userfunc(sess, NULL, snptr); | |
781 } else if ((flags == 0x0000) && payloadlength) { | |
782 unsigned char *msg; | |
783 | |
784 if(! (msg = calloc(1, payloadlength+1)) ) { | |
785 faim_mutex_unlock(&conn->active); | |
786 return 0; | |
787 } | |
788 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
789 if (aim_recv(conn->fd, msg, payloadlength) < payloadlength) { |
503 | 790 perror("read"); |
791 printf("faim: rend: read3 error\n"); | |
792 free(msg); | |
793 faim_mutex_unlock(&conn->active); | |
794 aim_conn_close(conn); | |
795 return -1; | |
796 } | |
797 faim_mutex_unlock(&conn->active); | |
798 msg[payloadlength] = '\0'; | |
799 #if 0 | |
800 printf("faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg); | |
801 #endif | |
802 | |
803 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) ) | |
804 i = userfunc(sess, NULL, conn, snptr, msg); | |
805 | |
806 free(msg); | |
807 return i; | |
808 } | |
809 break; | |
810 } | |
811 case 0x1209: { /* get file first */ | |
812 struct aim_filetransfer_priv *ft; | |
813 struct aim_fileheader_t *fh; | |
814 struct aim_msgcookie_t *cook; | |
815 | |
816 int commandlen; | |
817 char *data; | |
818 | |
819 printf("faim: rend: fileget 0x1209\n"); | |
820 | |
821 if(hdrlen != 0x100) | |
822 printf("faim: fileget_command(1209): um. hdrlen != 0x100.. 0x%x\n", hdrlen); | |
823 | |
824 if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) { | |
825 printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n"); | |
826 faim_mutex_unlock(&conn->active); | |
827 return 0; | |
828 } | |
829 | |
830 fh = aim_oft_getfh(hdr); | |
831 | |
832 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); | |
833 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
834 cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET); |
503 | 835 |
836 if(cook->data) | |
837 free(cook->data); /* XXX */ | |
838 | |
839 cook->data = ft; | |
840 | |
841 aim_cachecookie(sess, cook); | |
842 | |
843 commandlen = 36; | |
844 | |
845 data = calloc(1, commandlen); | |
846 memcpy(data, "01/01/1999 00:00 100 file.txt\r\n", commandlen); | |
847 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
848 if (send(conn->fd, data, commandlen, 0) != commandlen) { |
503 | 849 perror("listing write error"); |
850 } | |
851 faim_mutex_unlock(&conn->active); | |
852 | |
853 printf("jbm: hit end of 1209\n"); | |
854 | |
855 break; | |
856 } | |
857 case 0x120b: { /* get file second */ | |
858 struct aim_filetransfer_priv *ft; | |
859 struct aim_msgcookie_t *cook; | |
860 | |
861 struct aim_fileheader_t *fh; | |
862 | |
863 printf("faim: rend: fileget 120b\n"); | |
864 | |
865 if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) { | |
866 printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n"); | |
867 faim_mutex_unlock(&conn->active); | |
868 return 0; | |
869 } | |
870 | |
871 if(hdrlen != 0x100) | |
872 printf("faim: fileget_command(120b): um. hdrlen != 0x100..\n"); | |
873 | |
874 fh = aim_oft_getfh(hdr); | |
875 | |
876 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); | |
877 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
878 cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET); |
503 | 879 |
880 if(cook->data) | |
881 free(cook->data); /* XXX: integrate cookie caching */ | |
882 | |
883 cook->data = ft; | |
884 | |
885 aim_cachecookie(sess, cook); | |
886 | |
887 faim_mutex_unlock(&conn->active); | |
888 | |
889 break; | |
890 } | |
891 case 0x120c: { /* yet more get file */ | |
892 struct aim_filetransfer_priv *ft; | |
893 struct aim_msgcookie_t *cook; | |
894 struct aim_fileheader_t *listingfh; | |
895 struct command_tx_struct *newoft; | |
896 int curbyte, i; | |
897 | |
898 printf("faim: rend: fileget 120c\n"); | |
899 | |
900 if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) { | |
901 printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n"); | |
902 faim_mutex_unlock(&conn->active); | |
903 return 0; | |
904 } | |
905 | |
906 if(hdrlen != 0x100) | |
907 printf("faim: fileget_command(120c): um. hdrlen != 0x100..\n"); | |
908 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
909 listingfh = aim_oft_getfh(hdr); |
503 | 910 |
911 memcpy(&(ft->fh), listingfh, sizeof(struct aim_fileheader_t)); | |
912 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
913 cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET); |
503 | 914 |
915 if(cook->data) | |
916 free(cook->data); /* XXX */ | |
917 | |
918 cook->data = ft; | |
919 | |
920 aim_cachecookie(sess, cook); | |
921 | |
922 faim_mutex_unlock(&conn->active); | |
923 | |
924 printf("faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name); | |
925 | |
926 if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0101, conn, 0/*listingfh->size*/))) { | |
927 printf("faim: send_final_transfer: tx_new OFT failed\n"); | |
928 return 0; | |
929 } | |
930 | |
931 /* XXX: actually implement Real Handling of all this */ | |
932 | |
933 printf("jbm: listingfh->size: 0x%lx\n", listingfh->size); | |
934 | |
935 newoft->lock = 1; | |
936 | |
937 /* if(!(newoft->data = calloc(1, listingfh->size))) { | |
938 printf("newoft data malloc failed. bombing.\n"); | |
939 return 0; | |
940 }*/ | |
941 | |
942 if(newoft->commandlen > 0) { | |
943 int i; | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
944 memset(newoft->data, 0, newoft->commandlen); |
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
945 for(i = 0; i < (signed)newoft->commandlen; i++) |
503 | 946 newoft->data[i] = 0x30 + (i%10); |
947 | |
948 // memcpy(newoft->data, "This has been a Test\r\n-josh\r\n", newoft->commandlen); | |
949 } | |
950 | |
951 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
952 newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */ | |
953 | |
954 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { | |
955 if(newoft->data) | |
956 free(newoft->data); /* XXX: make this into a destructor function */ | |
957 free(newoft); | |
958 return 0; | |
959 } | |
960 | |
961 memcpy(listingfh->bcookie, ft->fh.bcookie, 8); | |
962 | |
963 curbyte = 0; | |
964 | |
965 for(i = 0; i < 8; i++) | |
966 curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->bcookie[i]); | |
967 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->encrypt); | |
968 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->compress); | |
969 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totfiles); | |
970 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->filesleft); | |
971 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totparts); | |
972 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->partsleft); | |
973 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->totsize); | |
974 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->size); | |
975 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->modtime); | |
976 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->checksum); | |
977 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfrcsum); | |
978 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfsize); | |
979 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->cretime); | |
980 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfcsum); | |
981 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0 /*listingfh->nrecvd*/); | |
982 curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0/*listingfh->recvcsum*/); | |
983 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
984 strncpy((char *)newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32); |
503 | 985 curbyte += 32; |
986 | |
987 curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, 0x20 /*listingfh->flags */); | |
988 curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lnameoffset); | |
989 curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lsizeoffset); | |
990 | |
991 memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->dummy, 69); | |
992 curbyte += 69; | |
993 | |
994 memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->macfileinfo, 16); | |
995 curbyte += 16; | |
996 | |
997 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode); | |
998 curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage); | |
999 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
1000 strncpy((char *)newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64); |
503 | 1001 curbyte += 64; |
1002 | |
1003 free(listingfh); | |
1004 | |
1005 newoft->lock = 0; | |
1006 aim_tx_enqueue(sess, newoft); | |
1007 printf("jbm: OFT listing enqueued.\n"); | |
1008 | |
1009 break; | |
1010 } | |
1011 case 0x0202: { /* get file: ready to recieve data */ | |
1012 char *c; | |
1013 int i; | |
1014 | |
1015 struct aim_fileheader_t *fh; | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
1016 fh = aim_oft_getfh(hdr); |
503 | 1017 |
1018 c = (char *)calloc(1, fh->size); | |
1019 | |
1020 printf("looks like we're ready to send data.(oft 0x0202)\n"); | |
1021 | |
1022 | |
1023 | |
1024 for(i = 0; i < fh->size; i++) | |
1025 c[i] = 0x30 + (i%10); | |
1026 | |
889
e1da6a6ec42b
[gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
840
diff
changeset
|
1027 if ( (i = send(conn->fd, c, fh->size, 0)) != fh->size ) { |
503 | 1028 printf("whoopsy, didn't write it all...\n"); |
1029 } | |
1030 | |
1031 faim_mutex_unlock(&conn->active); | |
1032 | |
1033 break; | |
1034 } | |
1035 case 0x0204: { /* get file: finished. close it up */ | |
1036 printf("looks like we're done with a transfer (oft 0x0204)\n"); | |
1037 faim_mutex_unlock(&conn->active); | |
1038 aim_conn_close(conn); | |
1039 break; | |
1040 } | |
1041 default: { | |
1042 printf("OFT frame: type %04x\n", hdrtype); | |
1043 /* data connection may be unreliable here */ | |
1044 faim_mutex_unlock(&conn->active); | |
1045 break; | |
1046 } | |
1047 } /* switch */ | |
1048 | |
1049 free(hdr); | |
1050 | |
1051 return 0; | |
1052 } | |
1053 | |
1054 /* | |
1055 * this currently feeds totally bogus data | |
1056 */ | |
1057 | |
840
595ac7759563
[gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
642
diff
changeset
|
1058 faim_internal struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr) |
503 | 1059 { |
1060 struct aim_fileheader_t *fh; | |
1061 int i, j; | |
1062 | |
1063 if(!(fh = calloc(1, sizeof(struct aim_fileheader_t)))) | |
1064 return NULL; | |
1065 | |
1066 /* [0] and [1] are the type. we can ignore those here. */ | |
1067 | |
1068 i = 2; | |
1069 | |
1070 for(j = 0; j < 8; j++, i++) | |
1071 fh->bcookie[j] = hdr[i]; | |
1072 fh->encrypt = aimutil_get16(hdr+i); | |
1073 i += 2; | |
1074 fh->compress = aimutil_get16(hdr+i); | |
1075 i += 2; | |
1076 fh->totfiles = aimutil_get16(hdr+i); | |
1077 i += 2; | |
1078 fh->filesleft = aimutil_get16(hdr+i); | |
1079 i += 2; | |
1080 fh->totparts = aimutil_get16(hdr+i); | |
1081 i += 2; | |
1082 fh->partsleft = aimutil_get16(hdr+i); | |
1083 i += 2; | |
1084 fh->totsize = aimutil_get32(hdr+i); | |
1085 i += 4; | |
1086 fh->size = aimutil_get32(hdr+i); | |
1087 i += 4; | |
1088 fh->modtime = aimutil_get32(hdr+i); | |
1089 i += 4; | |
1090 fh->checksum = aimutil_get32(hdr+i); | |
1091 i += 4; | |
1092 fh->rfrcsum = aimutil_get32(hdr+i); | |
1093 i += 4; | |
1094 fh->rfsize = aimutil_get32(hdr+i); | |
1095 i += 4; | |
1096 fh->cretime = aimutil_get32(hdr+i); | |
1097 i += 4; | |
1098 fh->rfcsum = aimutil_get32(hdr+i); | |
1099 i += 4; | |
1100 fh->nrecvd = aimutil_get32(hdr+i); | |
1101 i += 4; | |
1102 fh->recvcsum = aimutil_get32(hdr+i); | |
1103 i += 4; | |
1104 | |
1105 memcpy(fh->idstring, hdr+i, 32); | |
1106 i += 32; | |
1107 | |
1108 fh->flags = aimutil_get8(hdr+i); | |
1109 i += 1; | |
1110 fh->lnameoffset = aimutil_get8(hdr+i); | |
1111 i += 1; | |
1112 fh->lsizeoffset = aimutil_get8(hdr+i); | |
1113 i += 1; | |
1114 | |
1115 memcpy(fh->dummy, hdr+i, 69); | |
1116 i += 69; | |
1117 | |
1118 memcpy(fh->macfileinfo, hdr+i, 16); | |
1119 i += 16; | |
1120 | |
1121 fh->nencode = aimutil_get16(hdr+i); | |
1122 i += 2; | |
1123 fh->nlanguage = aimutil_get16(hdr+i); | |
1124 i += 2; | |
1125 | |
1126 memcpy(fh->name, hdr+i, 64); | |
1127 i += 64; | |
1128 | |
1129 return fh; | |
1130 } |