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