]> andersk Git - libfaim.git/blob - aim_im.c
- Wed Sep 13 22:01:35 UTC 2000
[libfaim.git] / aim_im.c
1 /*
2  *  aim_im.c
3  *
4  *  The routines for sending/receiving Instant Messages.
5  *
6  */
7
8 #include <faim/aim.h>
9
10 /*
11  * Send an ICBM (instant message).  
12  *
13  *
14  * Possible flags:
15  *   AIM_IMFLAGS_AWAY  -- Marks the message as an autoresponse
16  *   AIM_IMFLAGS_ACK   -- Requests that the server send an ack
17  *                        when the message is received (of type 0x0004/0x000c)
18  *
19  */
20 faim_export unsigned long aim_send_im(struct aim_session_t *sess,
21                                       struct aim_conn_t *conn, 
22                                       char *destsn, u_int flags, char *msg)
23 {   
24
25   int curbyte,i;
26   struct command_tx_struct *newpacket;
27   
28   if (strlen(msg) >= MAXMSGLEN)
29     return -1;
30
31   if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, strlen(msg)+256)))
32     return -1;
33
34   newpacket->lock = 1; /* lock struct */
35
36   curbyte  = 0;
37   curbyte += aim_putsnac(newpacket->data+curbyte, 
38                          0x0004, 0x0006, 0x0000, sess->snac_nextid);
39
40   /* 
41    * Generate a random message cookie 
42    *
43    * We could cache these like we do SNAC IDs.  (In fact, it 
44    * might be a good idea.)  In the message error functions, 
45    * the 8byte message cookie is returned as well as the 
46    * SNAC ID.
47    *
48    */
49   for (i=0;i<8;i++)
50     curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) rand());
51
52   /*
53    * Channel ID
54    */
55   curbyte += aimutil_put16(newpacket->data+curbyte,0x0001);
56
57   /* 
58    * Destination SN (prepended with byte length)
59    */
60   curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn));
61   curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
62
63   /*
64    * metaTLV start.
65    */
66   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
67   curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg) + 0x10);
68
69   /*
70    * Flag data / ICBM Parameters?
71    */
72   curbyte += aimutil_put8(newpacket->data+curbyte, 0x05);
73   curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
74
75   /* number of bytes to follow */
76   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004);
77   curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
78   curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
79   curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
80   curbyte += aimutil_put8(newpacket->data+curbyte, 0x02);
81
82   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0101);
83
84   /* 
85    * Message block length.
86    */
87   curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg) + 0x04);
88
89   /*
90    * Character set data? 
91    */
92   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
93   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
94
95   /*
96    * Message.  Not terminated.
97    */
98   curbyte += aimutil_putstr(newpacket->data+curbyte,msg, strlen(msg));
99
100   /*
101    * Set the Request Acknowledge flag.  
102    */
103   if (flags & AIM_IMFLAGS_ACK) {
104     curbyte += aimutil_put16(newpacket->data+curbyte,0x0003);
105     curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
106   }
107   
108   /*
109    * Set the Autoresponse flag.
110    */
111   if (flags & AIM_IMFLAGS_AWAY) {
112     curbyte += aimutil_put16(newpacket->data+curbyte,0x0004);
113     curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
114   }
115   
116   newpacket->commandlen = curbyte;
117   newpacket->lock = 0;
118
119   aim_tx_enqueue(sess, newpacket);
120
121 #ifdef USE_SNAC_FOR_IMS
122  {
123     struct aim_snac_t snac;
124
125     snac.id = sess->snac_nextid;
126     snac.family = 0x0004;
127     snac.type = 0x0006;
128     snac.flags = 0x0000;
129
130     snac.data = malloc(strlen(destsn)+1);
131     memcpy(snac.data, destsn, strlen(destsn)+1);
132
133     aim_newsnac(sess, &snac);
134   }
135
136  aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
137 #endif
138
139   return (sess->snac_nextid++);
140 }
141
142 faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess,
143                                                struct command_rx_struct *command)
144 {
145   unsigned int i = 0, z;
146   rxcallback_t userfunc = NULL;
147   unsigned char cookie[8];
148   int channel;
149   struct aim_tlvlist_t *tlvlist;
150   char sn[MAXSNLEN];
151   unsigned short icbmflags = 0;
152   unsigned char flag1 = 0, flag2 = 0;
153   unsigned char *msgblock = NULL, *msg = NULL;
154
155   i = 10;
156   
157   /* ICBM Cookie. */
158   for (z=0; z<8; z++,i++)
159     cookie[z] = command->data[i];
160
161   /* Channel ID */
162   channel = aimutil_get16(command->data+i);
163   i += 2;
164
165   if (channel != 0x01) {
166     printf("faim: icbm: ICBM recieved on unsupported channel.  Ignoring. (chan = %04x)\n", channel);
167     return 1;
168   }
169
170   strncpy(sn, (char *) command->data+i+1, (int) *(command->data+i));
171   i += 1 + (int) *(command->data+i);
172
173   tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
174
175   if (aim_gettlv(tlvlist, 0x0003, 1))
176     icbmflags |= AIM_IMFLAGS_ACK;
177   if (aim_gettlv(tlvlist, 0x0004, 1))
178     icbmflags |= AIM_IMFLAGS_AWAY;
179
180   if (aim_gettlv(tlvlist, 0x0002, 1)) {
181     int j = 0;
182
183     msgblock = (unsigned char *)aim_gettlv_str(tlvlist, 0x0002, 1);
184
185     /* no, this really is correct.  I'm not high or anything either. */
186     j += 2;
187     j += 2 + aimutil_get16(msgblock+j);
188     j += 2;
189     
190     j += 2; /* final block length */
191
192     flag1 = aimutil_get16(msgblock);
193     j += 2;
194     flag2 = aimutil_get16(msgblock);
195     j += 2;
196     
197     msg = msgblock+j;
198   }
199
200   if ((userfunc = aim_callhandler(command->conn, 0x0004, 0x0006)) || (i = 0))
201     i = userfunc(sess, command, channel, sn, msg, icbmflags, flag1, flag2);
202   
203   if (msgblock)
204     free(msgblock);
205   aim_freetlvchain(&tlvlist);
206
207   return 0;
208 }
209
210 /*
211  * It can easily be said that parsing ICBMs is THE single
212  * most difficult thing to do in the in AIM protocol.  In
213  * fact, I think I just did say that.
214  *
215  * Below is the best damned solution I've come up with
216  * over the past sixteen months of battling with it. This
217  * can parse both away and normal messages from every client
218  * I have access to.  Its not fast, its not clean.  But it works.
219  *
220  * We should also support at least minimal parsing of 
221  * Channel 2, so that we can at least know the name of the
222  * room we're invited to, but obviously can't attend...
223  *
224  */
225 faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
226                                                struct command_rx_struct *command)
227 {
228   u_int i = 0,z;
229   rxcallback_t userfunc = NULL;
230   u_char cookie[8];
231   int channel;
232   struct aim_tlvlist_t *tlvlist;
233   struct aim_userinfo_s userinfo;
234   u_short wastebits;
235
236   memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
237  
238   i = 10; /* Skip SNAC header */
239
240   /*
241    * Read ICBM Cookie.  And throw away.
242    */
243   for (z=0; z<8; z++,i++)
244     cookie[z] = command->data[i];
245   
246   /*
247    * Channel ID.
248    *
249    * Channel 0x0001 is the message channel.  There are 
250    * other channels for things called "rendevous"
251    * which represent chat and some of the other new
252    * features of AIM2/3/3.5. 
253    *
254    * Channel 0x0002 is the Rendevous channel, which
255    * is where Chat Invitiations and various client-client
256    * connection negotiations come from.
257    * 
258    */
259   channel = aimutil_get16(command->data+i);
260   i += 2;
261   
262   /*
263    *
264    */
265   if ((channel != 0x01) && (channel != 0x02))
266     {
267       printf("faim: icbm: ICBM received on an unsupported channel.  Ignoring.\n (chan = %04x)", channel);
268       return 1;
269     }
270
271   /*
272    * Extract the standard user info block.
273    *
274    * Note that although this contains TLVs that appear contiguous
275    * with the TLVs read below, they are two different pieces.  The
276    * userinfo block contains the number of TLVs that contain user
277    * information, the rest are not even though there is no seperation.
278    * aim_extractuserinfo() returns the number of bytes used by the
279    * userinfo tlvs, so you can start reading the rest of them right
280    * afterward.  
281    *
282    * That also means that TLV types can be duplicated between the
283    * userinfo block and the rest of the message, however there should
284    * never be two TLVs of the same type in one block.
285    * 
286    */
287   i += aim_extractuserinfo(command->data+i, &userinfo);
288   
289   /*
290    * Read block of TLVs (not including the userinfo data).  All 
291    * further data is derived from what is parsed here.
292    */
293   tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
294
295   /*
296    * From here on, its depends on what channel we're on.
297    */
298   if (channel == 1)
299     {
300      u_int j = 0, y = 0, z = 0;
301       char *msg = NULL;
302       u_int icbmflags = 0;
303       struct aim_tlv_t *msgblocktlv;
304       u_char *msgblock;
305       u_short flag1,flag2;
306            
307       /*
308        * Check Autoresponse status.  If it is an autoresponse,
309        * it will contain a type 0x0004 TLV, with zero length.
310        */
311       if (aim_gettlv(tlvlist, 0x0004, 1))
312         icbmflags |= AIM_IMFLAGS_AWAY;
313       
314       /*
315        * Check Ack Request status.
316        */
317       if (aim_gettlv(tlvlist, 0x0003, 1))
318         icbmflags |= AIM_IMFLAGS_ACK;
319       
320       /*
321        * Message block.
322        */
323       msgblocktlv = aim_gettlv(tlvlist, 0x0002, 1);
324       if (!msgblocktlv || !msgblocktlv->value) {
325         printf("faim: icbm: major error! no message block TLV found!\n");
326         aim_freetlvchain(&tlvlist);
327         return 1;
328       }
329       
330       /*
331        * Extracting the message from the unknown cruft.
332        * 
333        * This is a bit messy, and I'm not really qualified,
334        * even as the author, to comment on it.  At least
335        * its not as bad as a while loop shooting into infinity.
336        *
337        * "Do you believe in magic?"
338        *
339        */
340       msgblock = msgblocktlv->value;
341       j = 0;
342       
343       wastebits = aimutil_get8(msgblock+j++);
344       wastebits = aimutil_get8(msgblock+j++);
345       
346       y = aimutil_get16(msgblock+j);
347       j += 2;
348       for (z = 0; z < y; z++)
349         wastebits = aimutil_get8(msgblock+j++);
350       wastebits = aimutil_get8(msgblock+j++);
351       wastebits = aimutil_get8(msgblock+j++);
352       
353       /* 
354        * Message string length, including flag words.
355        */
356       i = aimutil_get16(msgblock+j);
357       j += 2;
358       
359       /*
360        * Flag words.
361        *
362        * Its rumored that these can kick in some funky
363        * 16bit-wide char stuff that used to really kill
364        * libfaim.  Hopefully the latter is no longer true.
365        *
366        * Though someone should investiagte the former.
367        *
368        */
369       flag1 = aimutil_get16(msgblock+j);
370       j += 2;
371       flag2 = aimutil_get16(msgblock+j);
372       j += 2;
373       
374       if (flag1 || flag2)
375         printf("faim: icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2);
376       
377       /* 
378        * Message string. 
379        */
380       i -= 4;
381       msg = (char *)malloc(i+1);
382       memcpy(msg, msgblock+j, i);
383       msg[i] = '\0';
384       
385       /*
386        * Call client.
387        */
388       userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
389       if (userfunc)
390         i = userfunc(sess, command, channel, &userinfo, msg, icbmflags, flag1, flag2);
391       else 
392         i = 0;
393       
394       free(msg);
395     }
396   else if (channel == 0x0002)
397     {   
398       struct aim_tlv_t *block1;
399       struct aim_tlvlist_t *list2;
400       unsigned short reqclass = 0;
401       unsigned short status = 0;
402       
403       /*
404        * There's another block of TLVs embedded in the type 5 here. 
405        */
406       block1 = aim_gettlv(tlvlist, 0x0005, 1);
407       if (!block1) {
408         printf("faim: no tlv 0x0005 in rendezvous transaction!\n");
409         aim_freetlvchain(&tlvlist);
410         return 1; /* major problem */
411       }
412
413       /*
414        * First two bytes represent the status of the connection.
415        *
416        * 0 is a request, 2 is an accept
417        */ 
418       status = aimutil_get16(block1->value+0);
419       
420       /*
421        * Next comes the cookie.  Should match the ICBM cookie.
422        */
423       if (memcmp(block1->value+2, cookie, 8) != 0) 
424         printf("faim: rend: warning cookies don't match!\n");
425
426       /*
427        * The next 16bytes are a capability block so we can
428        * identify what type of rendezvous this is.
429        *
430        * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
431        * for pointing some of this out to me.  In fact, a lot of 
432        * the client-to-client info comes from the work of the GAIM 
433        * developers. Thanks!
434        *
435        * Read off one capability string and we should have it ID'd.
436        * 
437        */
438       reqclass = aim_getcap(block1->value+2+8, 0x10);
439       if (reqclass == 0x0000) {
440         printf("faim: rend: no ID block\n");
441         aim_freetlvchain(&tlvlist);
442         return 1;
443       }
444
445       /* 
446        * What follows may be TLVs or nothing, depending on the
447        * purpose of the message.
448        *
449        * Ack packets for instance have nothing more to them.
450        */
451       list2 = aim_readtlvchain(block1->value+2+8+16, block1->length-2-8-16);
452       
453       if (!list2 || ((reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
454         struct aim_msgcookie_t *cook;
455         int type;
456         
457         type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */
458
459         if ((cook = aim_uncachecookie(sess, cookie, type)) == NULL) {
460           printf("faim: non-data rendezvous thats not in cache!\n");
461           aim_freetlvchain(&list2);
462           aim_freetlvchain(&tlvlist);
463           return 1;
464         }
465
466         if (cook->type == AIM_CAPS_SENDFILE) {
467           struct aim_filetransfer_priv *ft;
468
469           if (cook->data) {
470             struct aim_tlv_t *errortlv;
471             int errorcode = -1;
472
473             ft = (struct aim_filetransfer_priv *)cook->data;
474
475             if ((errortlv = aim_gettlv(list2, 0x000b, 1))) {
476               errorcode = aimutil_get16(errortlv->value);
477             }
478             if (errorcode) {
479               printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
480             } else if (status == 0x0002) { /* connection accepted */
481               printf("faim: transfer from %s (%s) for %s accepted\n", ft->sn, ft->ip, ft->fh.name);
482             }
483             free(cook->data);
484           } else {
485             printf("faim: not data attached to file transfer\n");
486           }
487         } else if (cook->type == AIM_CAPS_VOICE) {
488           printf("faim: voice request cancelled\n");
489         } else {
490           printf("faim: unknown cookie cache type %d\n", cook->type);
491         }
492
493         free(cook);
494         if (list2)
495           aim_freetlvchain(&list2);
496         aim_freetlvchain(&tlvlist);
497         return 1;
498       }
499
500       /*
501        * The rest of the handling depends on what type it is.
502        */
503       if (reqclass & AIM_CAPS_BUDDYICON) {
504
505         /*
506          * Call client.
507          */
508         userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
509         if (userfunc || (i = 0))
510           i = userfunc(sess, 
511                        command, 
512                        channel, 
513                        reqclass,
514                        &userinfo);
515
516       } else if (reqclass & AIM_CAPS_VOICE) {
517         struct aim_msgcookie_t *cachedcook;
518
519         printf("faim: rend: voice!\n");
520
521         if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t))))
522           return 1;
523
524         memcpy(cachedcook->cookie, cookie, 8);
525         cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
526         cachedcook->data = NULL;
527
528         if (aim_cachecookie(sess, cachedcook) != 0)
529           printf("faim: ERROR caching message cookie\n");
530
531         /* XXX: implement all this */
532
533         /*
534          * Call client.
535          */
536         userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
537         if (userfunc || (i = 0)) {
538           i = userfunc(sess, command, channel, reqclass, &userinfo);
539         }
540       } else if ((reqclass & AIM_CAPS_IMIMAGE) || (reqclass & AIM_CAPS_BUDDYICON)) {
541         char ip[30];
542         struct aim_directim_priv *priv;
543
544         memset(ip, 0, sizeof(ip));
545         
546         if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
547           struct aim_tlv_t *iptlv, *porttlv;
548           
549           iptlv = aim_gettlv(list2, 0x0003, 1);
550           porttlv = aim_gettlv(list2, 0x0005, 1);
551
552           snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d", 
553                   aimutil_get8(iptlv->value+0),
554                   aimutil_get8(iptlv->value+1),
555                   aimutil_get8(iptlv->value+2),
556                   aimutil_get8(iptlv->value+3),
557                   4443 /*aimutil_get16(porttlv->value)*/);
558         }
559
560         printf("faim: rend: directIM request from %s (%s)\n",
561                userinfo.sn,
562                ip);
563
564        /* XXX: there are a couple of different request packets for
565         *          different things */
566         
567         priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
568         memcpy(priv->ip, ip, sizeof(priv->ip));
569         memcpy(priv->sn, userinfo.sn, sizeof(priv->sn));
570         memcpy(priv->cookie, cookie, sizeof(priv->cookie));
571
572         /*
573          * Call client.
574          */
575         userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
576         if (userfunc || (i = 0))
577           i = userfunc(sess, 
578                        command, 
579                        channel, 
580                        reqclass,
581                        &userinfo, priv);
582
583       } else if (reqclass & AIM_CAPS_CHAT) {
584         struct aim_tlv_t *miscinfo;
585         struct aim_chat_roominfo roominfo;
586         char *msg=NULL,*encoding=NULL,*lang=NULL;
587
588         miscinfo = aim_gettlv(list2, 0x2711, 1);
589         aim_chat_readroominfo(miscinfo->value, &roominfo);
590                   
591         if (aim_gettlv(list2, 0x000c, 1))
592           msg = aim_gettlv_str(list2, 0x000c, 1);
593           
594         if (aim_gettlv(list2, 0x000d, 1))
595           encoding = aim_gettlv_str(list2, 0x000d, 1);
596           
597         if (aim_gettlv(list2, 0x000e, 1))
598           lang = aim_gettlv_str(list2, 0x000e, 1);
599       
600         /*
601          * Call client.
602          */
603         userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
604         if (userfunc || (i = 0))
605           i = userfunc(sess, 
606                        command, 
607                        channel, 
608                        reqclass,
609                        &userinfo, 
610                        &roominfo, 
611                        msg, 
612                        encoding?encoding+1:NULL, 
613                        lang?lang+1:NULL);
614           free(roominfo.name);
615           free(msg);
616           free(encoding);
617           free(lang);
618       } else if (reqclass & AIM_CAPS_GETFILE) {
619         char ip[30];
620         struct aim_msgcookie_t *cachedcook;
621         struct aim_tlv_t *miscinfo;
622
623         if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t))))
624           return 0;
625
626         memset(ip, 0, sizeof(ip));
627
628         if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) {
629           free(cachedcook);
630           return 0;
631         }
632
633         if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
634           struct aim_tlv_t *iptlv, *porttlv;
635
636           if (!(iptlv = aim_gettlv(list2, 0x0003, 1)) || !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
637             free(cachedcook);
638             return 0;
639           }
640
641           snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d",
642                    aimutil_get8(iptlv->value+0),
643                    aimutil_get8(iptlv->value+1),
644                    aimutil_get8(iptlv->value+2),
645                    aimutil_get8(iptlv->value+3),
646                    aimutil_get16(porttlv->value));
647         }
648
649         printf("faim: rend: file get request from %s (%s)\n", userinfo.sn, ip);
650
651 #if 0 /* XXX finish this */
652         newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
653         if (!newconn || (newconn->fd == -1)) {
654           printf("could not connect to %s\n", ip);
655           perror("aim_newconn");
656           aim_conn_kill(sess, &newconn);
657         } else {
658           struct aim_filetransfer_priv *priv;
659           priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
660           memcpy(priv->cookie, cookie, 8);
661           strncpy(priv->sn, userinfo.sn, MAXSNLEN);
662           newconn->priv = priv;
663           printf("faim: connected to peer (fd = %d)\n", newconn->fd);
664         }
665
666         memcpy(cachedcook->cookie, cookie, 8);
667
668         ft = malloc(sizeof(struct aim_filetransfer_priv));
669         ft->state = 1;
670         strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
671         strncpy(ft->ip, ip, sizeof(ft->ip));
672 #if 0
673         strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
674 #endif
675         cachedcook->type = AIM_COOKIETYPE_OFTGET;
676         cachedcook->data = ft;
677
678         if (aim_cachecookie(sess, cachedcook) != 0)
679           printf("faim: ERROR caching message cookie\n");
680
681         aim_accepttransfer(sess, command->conn, newconn, ft->sn, cookie, AIM_CAPS_GETFILE);
682
683         free(desc);
684 #endif
685         /*
686          * Call client.
687          */
688         userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
689         if (userfunc || (i = 0))
690           i = userfunc(sess, 
691                        command, 
692                        channel, 
693                        reqclass,
694                        &userinfo);
695
696       } else if (reqclass & AIM_CAPS_SENDFILE) {
697 #if 0
698        char ip[30];
699        char *desc = NULL;
700        struct aim_msgcookie_t *cachedcook;
701        struct aim_filetransfer_priv *ft;
702        struct aim_tlv_t *miscinfo;
703
704         memset(ip, 0, sizeof(ip));
705         
706         if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)))
707           return 0;
708
709         if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) {
710           struct aim_tlv_t *iptlv, *porttlv;
711           
712           iptlv = aim_gettlv(list2, 0x0003, 1);
713           porttlv = aim_gettlv(list2, 0x0005, 1);
714
715           snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d", 
716                   aimutil_get8(iptlv->value+0),
717                   aimutil_get8(iptlv->value+1),
718                   aimutil_get8(iptlv->value+2),
719                   aimutil_get8(iptlv->value+3),
720                   aimutil_get16(porttlv->value));
721         }
722
723         if (aim_gettlv(list2, 0x000c, 1)) {
724           desc = aim_gettlv_str(list2, 0x000c, 1);
725         }
726
727         printf("faim: rend: file transfer request from %s for %s: %s (%s)\n",
728                userinfo.sn,
729                miscinfo->value+8,
730                desc, 
731                ip);
732         
733         memcpy(cachedcook->cookie, cookie, 8);
734         
735         ft = malloc(sizeof(struct aim_filetransfer_priv));
736         strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
737         strncpy(ft->ip, ip, sizeof(ft->ip));
738         strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
739         cachedcook->type = AIM_COOKIETYPE_OFTSEND;
740         cachedcook->data = ft;
741
742         if (aim_cachecookie(sess, cachedcook) != 0)
743           printf("faim: ERROR caching message cookie\n");
744         
745         
746         aim_accepttransfer(sess, command->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
747         
748         if (desc)
749           free(desc);
750 #endif  
751         /*
752          * Call client.
753          */
754         userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
755         if (userfunc || (i = 0))
756           i = userfunc(sess, 
757                        command, 
758                        channel, 
759                        reqclass,
760                        &userinfo);
761       } else {
762         printf("faim: rend: unknown rendezvous 0x%04x\n", reqclass);
763       }
764
765       aim_freetlvchain(&list2);
766     }
767
768   /*
769    * Free up the TLV chain.
770    */
771   aim_freetlvchain(&tlvlist);
772   
773
774   return i;
775 }
776
777 /*
778  * Possible codes:
779  *    AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
780  *    AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
781  *    AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
782  * 
783  */
784 faim_export unsigned long aim_denytransfer(struct aim_session_t *sess,
785                                            struct aim_conn_t *conn, 
786                                            char *sender,
787                                            char *cookie, 
788                                            unsigned short code)
789 {
790   struct command_tx_struct *newpacket;
791   int curbyte, i;
792
793   if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sender)+6)))
794     return -1;
795
796   newpacket->lock = 1;
797
798   curbyte = aim_putsnac(newpacket->data, 0x0004, 0x000b, 0x0000, sess->snac_nextid);
799   for (i = 0; i < 8; i++)
800     curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
801   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
802   curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
803   curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
804   curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0003, code);
805
806   newpacket->lock = 0;
807   aim_tx_enqueue(sess, newpacket);
808
809   return (sess->snac_nextid++);
810 }
811
812 /*
813  * Not real sure what this does, nor does anyone I've talk to.
814  *
815  * Didn't use to send it.  But now I think it might be a good
816  * idea. 
817  *
818  */
819 faim_export unsigned long aim_seticbmparam(struct aim_session_t *sess,
820                                            struct aim_conn_t *conn)
821 {
822   struct command_tx_struct *newpacket;
823   int curbyte;
824
825   if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+16)))
826     return -1;
827
828   newpacket->lock = 1;
829
830   curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid);
831   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
832   curbyte += aimutil_put32(newpacket->data+curbyte, 0x00000003);
833   curbyte += aimutil_put8(newpacket->data+curbyte,  0x1f);
834   curbyte += aimutil_put8(newpacket->data+curbyte,  0x40);
835   curbyte += aimutil_put8(newpacket->data+curbyte,  0x03);
836   curbyte += aimutil_put8(newpacket->data+curbyte,  0xe7);
837   curbyte += aimutil_put8(newpacket->data+curbyte,  0x03);
838   curbyte += aimutil_put8(newpacket->data+curbyte,  0xe7);
839   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
840   curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
841
842   newpacket->lock = 0;
843   aim_tx_enqueue(sess, newpacket);
844
845   return (sess->snac_nextid++);
846 }
847
848 faim_internal int aim_parse_msgerror_middle(struct aim_session_t *sess,
849                                             struct command_rx_struct *command)
850 {
851   u_long snacid = 0x000000000;
852   struct aim_snac_t *snac = NULL;
853   int ret = 0;
854   rxcallback_t userfunc = NULL;
855   char *dest;
856   unsigned short reason = 0;
857
858   /*
859    * Get SNAC from packet and look it up 
860    * the list of unrepliedto/outstanding
861    * SNACs.
862    *
863    * After its looked up, the SN that the
864    * message should've gone to will be 
865    * in the ->data element of the snac struct.
866    *
867    */
868   snacid = aimutil_get32(command->data+6);
869   snac = aim_remsnac(sess, snacid);
870
871   if (!snac) {
872     printf("faim: msgerr: got an ICBM-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
873     dest = NULL;
874   } else
875     dest = snac->data;
876
877   reason = aimutil_get16(command->data+10);
878
879   /*
880    * Call client.
881    */
882   userfunc = aim_callhandler(command->conn, 0x0004, 0x0001);
883   if (userfunc)
884     ret =  userfunc(sess, command, dest, reason);
885   else
886     ret = 0;
887   
888   if (snac) {
889     free(snac->data);
890     free(snac);
891   }
892
893   return ret;
894 }
895
896
897 faim_internal int aim_parse_missedcall(struct aim_session_t *sess,
898                                        struct command_rx_struct *command)
899 {
900   int i, ret = 1;
901   rxcallback_t userfunc = NULL;
902   unsigned short channel, nummissed, reason;
903   struct aim_userinfo_s userinfo;
904  
905   i = 10; /* Skip SNAC header */
906
907
908   /*
909    * XXX: supposedly, this entire packet can repeat as many times
910    * as necessary. Should implement that.
911    */
912
913   /*
914    * Channel ID.
915    */
916   channel = aimutil_get16(command->data+i);
917   i += 2;
918   
919   /*
920    * Extract the standard user info block.
921    */
922   i += aim_extractuserinfo(command->data+i, &userinfo);
923   
924   nummissed = aimutil_get16(command->data+i);
925   i += 2;
926   
927   reason = aimutil_get16(command->data+i);
928   i += 2;
929
930   /*
931    * Call client.
932    */
933   userfunc = aim_callhandler(command->conn, 0x0004, 0x000a);
934   if (userfunc)
935     ret =  userfunc(sess, command, channel, &userinfo, nummissed, reason);
936   else
937     ret = 0;
938   
939   return ret;
940 }
This page took 0.138829 seconds and 5 git commands to generate.