]> andersk Git - libfaim.git/blob - aim_chatnav.c
- Tue May 30 22:32:31 UTC 2000
[libfaim.git] / aim_chatnav.c
1 /*
2  *
3  *
4  *
5  *
6  */
7
8 #include <faim/aim.h>
9
10
11 /*
12  * conn must be a chatnav connection!
13  */
14 u_long aim_chatnav_reqrights(struct aim_session_t *sess,
15                           struct aim_conn_t *conn)
16 {
17   struct aim_snac_t snac;
18
19   snac.id = aim_genericreq_n(sess, conn, 0x000d, 0x0002);
20
21   snac.family = 0x000d;
22   snac.type = 0x0002;
23   snac.flags = 0x0000;
24   snac.data = NULL;
25   
26   aim_newsnac(sess, &snac);
27
28   return (sess->snac_nextid); /* already incremented */
29 }
30
31 u_long aim_chatnav_clientready(struct aim_session_t *sess,
32                                struct aim_conn_t *conn)
33 {
34   struct command_tx_struct *newpacket; 
35   int i;
36
37   if (!(newpacket = aim_tx_new(0x0002, conn, 0x20)))
38     return -1;
39
40   newpacket->lock = 1;
41
42   i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid);
43
44   i+= aimutil_put16(newpacket->data+i, 0x000d);
45   i+= aimutil_put16(newpacket->data+i, 0x0001);
46
47   i+= aimutil_put16(newpacket->data+i, 0x0004);
48   i+= aimutil_put16(newpacket->data+i, 0x0001);
49
50   i+= aimutil_put16(newpacket->data+i, 0x0001);
51   i+= aimutil_put16(newpacket->data+i, 0x0003);
52
53   i+= aimutil_put16(newpacket->data+i, 0x0004);
54   i+= aimutil_put16(newpacket->data+i, 0x0686);
55
56   aim_tx_enqueue(sess, newpacket);
57
58   return (sess->snac_nextid++);
59 }
60
61 /*
62  * Since multiple things can trigger this callback,
63  * we must lookup the snacid to determine the original
64  * snac subtype that was called.
65  */
66 int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command)
67 {
68   struct aim_snac_t *snac;
69   u_long snacid;
70   rxcallback_t userfunc;
71   
72   snacid = aimutil_get32(command->data+6);
73   snac = aim_remsnac(sess, snacid);
74
75   if (!snac)
76     {
77       printf("faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snacid);
78       return 1;
79     }
80   
81   if (snac->family != 0x000d)
82     {
83       printf("faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac->family);
84       return 1;
85     }
86
87   /*
88    * We now know what the original SNAC subtype was.
89    */
90   switch(snac->type)
91     {
92     case 0x0002: /* request chat rights */
93       {
94           struct aim_tlvlist_t *tlvlist;
95           struct aim_chat_exchangeinfo *exchanges = NULL;
96           int curexchange = 0;
97           struct aim_tlv_t *exchangetlv;
98           u_char maxrooms = 0;
99           int ret = 1;
100           struct aim_tlvlist_t *innerlist;
101          
102           tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10);
103           
104           /* 
105            * Type 0x0002: Maximum concurrent rooms.
106            */ 
107           if (aim_gettlv(tlvlist, 0x0002, 1))
108             {
109               struct aim_tlv_t *maxroomstlv;
110               maxroomstlv = aim_gettlv(tlvlist, 0x0002, 1);
111               maxrooms = aimutil_get8(maxroomstlv->value);
112             }
113
114           /* 
115            * Type 0x0003: Exchange information
116            *
117            * There can be any number of these, each one
118            * representing another exchange.  
119            * 
120            */
121           curexchange = 0;
122           while ((exchangetlv = aim_gettlv(tlvlist, 0x0003, curexchange+1)))
123             {   
124               curexchange++;
125               exchanges = realloc(exchanges, curexchange * sizeof(struct aim_chat_exchangeinfo));
126               
127               /* exchange number */
128               exchanges[curexchange-1].number = aimutil_get16(exchangetlv->value);
129               innerlist = aim_readtlvchain(exchangetlv->value+2, exchangetlv->length-2);
130               
131               /* 
132                * Type 0x000d: Unknown.
133                */
134               if (aim_gettlv(innerlist, 0x000d, 1))
135                 ;
136               
137               /* 
138                * Type 0x0004: Unknown
139                */
140               if (aim_gettlv(innerlist, 0x0004, 1))
141                 ;
142
143               /*
144                * Type 0x00c9: Unknown
145                */ 
146               if (aim_gettlv(innerlist, 0x00c9, 1))
147                 ;
148               
149               /*
150                * Type 0x00ca: Creation Date 
151                */
152               if (aim_gettlv(innerlist, 0x00ca, 1))
153                 ;
154               
155               /*
156                * Type 0x00d0: Unknown
157                */
158               if (aim_gettlv(innerlist, 0x00d0, 1))
159                 ;
160
161               /*
162                * Type 0x00d1: Maximum Message length
163                */
164               if (aim_gettlv(innerlist, 0x00d1, 1))
165                 ;
166
167               /*
168                * Type 0x00d2: Unknown
169                */
170               if (aim_gettlv(innerlist, 0x00d2, 1))     
171                 ;       
172
173               /*
174                * Type 0x00d3: Exchange Name
175                */
176               if (aim_gettlv(innerlist, 0x00d3, 1))     
177                 exchanges[curexchange-1].name = aim_gettlv_str(innerlist, 0x00d3, 1);
178               else
179                 exchanges[curexchange-1].name = NULL;
180
181               /*
182                * Type 0x00d5: Unknown
183                */
184               if (aim_gettlv(innerlist, 0x00d5, 1))
185                 ;
186
187               /*
188                * Type 0x00d6: Character Set (First Time)
189                */             
190               if (aim_gettlv(innerlist, 0x00d6, 1))     
191                 exchanges[curexchange-1].charset1 = aim_gettlv_str(innerlist, 0x00d6, 1);
192               else
193                 exchanges[curexchange-1].charset1 = NULL;
194               
195               /*
196                * Type 0x00d7: Language (First Time)
197                */             
198               if (aim_gettlv(innerlist, 0x00d7, 1))     
199                 exchanges[curexchange-1].lang1 = aim_gettlv_str(innerlist, 0x00d7, 1);
200               else
201                 exchanges[curexchange-1].lang1 = NULL;
202
203               /*
204                * Type 0x00d8: Character Set (Second Time)
205                */             
206               if (aim_gettlv(innerlist, 0x00d8, 1))     
207                 exchanges[curexchange-1].charset2 = aim_gettlv_str(innerlist, 0x00d8, 1);
208               else
209                 exchanges[curexchange-1].charset2 = NULL;
210
211               /*
212                * Type 0x00d9: Language (Second Time)
213                */             
214               if (aim_gettlv(innerlist, 0x00d9, 1))     
215                 exchanges[curexchange-1].lang2 = aim_gettlv_str(innerlist, 0x00d9, 1);
216               else
217                 exchanges[curexchange-1].lang2 = NULL;
218
219             }
220           
221           /*
222            * Call client.
223            */
224           userfunc = aim_callhandler(command->conn, 0x000d, 0x0009);
225           if (userfunc)
226             ret = userfunc(sess, 
227                            command, 
228                            snac->type,
229                            maxrooms,
230                            curexchange, 
231                            exchanges);
232           curexchange--;
233           while(curexchange)
234             {
235               if (exchanges[curexchange].name)
236                 free(exchanges[curexchange].name);
237               if (exchanges[curexchange].charset1)
238                 free(exchanges[curexchange].charset1);
239               if (exchanges[curexchange].lang1)
240                 free(exchanges[curexchange].lang1);
241               if (exchanges[curexchange].charset2)
242                 free(exchanges[curexchange].charset2);
243               if (exchanges[curexchange].lang2)
244                 free(exchanges[curexchange].lang2);
245               curexchange--;
246             }
247           free(exchanges);
248           aim_freetlvchain(&innerlist);
249           aim_freetlvchain(&tlvlist);
250           return ret;
251       }
252     case 0x0003: /* request exchange info */
253       printf("faim: chatnav_parse_info: resposne to exchange info\n");
254       return 1;
255     case 0x0004: /* request room info */
256       printf("faim: chatnav_parse_info: response to room info\n");
257       return 1;
258     case 0x0005: /* request more room info */
259       printf("faim: chatnav_parse_info: response to more room info\n");
260       return 1;
261     case 0x0006: /* request occupant list */
262       printf("faim: chatnav_parse_info: response to occupant info\n");
263       return 1;
264     case 0x0007: /* search for a room */
265       printf("faim: chatnav_parse_info: search results\n");
266       return 1;
267     case 0x0008: /* create room */
268       printf("faim: chatnav_parse_info: response to create room\n");
269       return 1;
270     default: /* unknown */
271       printf("faim: chatnav_parse_info: unknown request subtype (%04x)\n", snac->type);
272     }
273
274   return 1; /* shouldn't get here */
275 }
276
277 u_long aim_chatnav_createroom(struct aim_session_t *sess,
278                               struct aim_conn_t *conn,
279                               char *name, 
280                               u_short exchange)
281 {
282   struct command_tx_struct *newpacket; 
283   int i;
284   struct aim_snac_t snac;
285
286   if (!(newpacket = aim_tx_new(0x0002, conn, 10+12+strlen("invite")+strlen(name))))
287     return -1;
288
289   newpacket->lock = 1;
290
291   i = aim_putsnac(newpacket->data, 0x000d, 0x0008, 0x0000, sess->snac_nextid);
292
293   /* exchange */
294   i+= aimutil_put16(newpacket->data+i, exchange);
295
296   /* room cookie */
297   i+= aimutil_put8(newpacket->data+i, strlen("invite"));
298   i+= aimutil_putstr(newpacket->data+i, "invite", strlen("invite"));
299
300   /* instance */
301   i+= aimutil_put16(newpacket->data+i, 0xffff);
302   
303   /* detail level */
304   i+= aimutil_put8(newpacket->data+i, 0x01);
305   
306   /* tlvcount */
307   i+= aimutil_put16(newpacket->data+i, 0x0001);
308
309   /* room name */
310   i+= aim_puttlv_str(newpacket->data+i, 0x00d3, strlen(name), name);
311
312   snac.id = sess->snac_nextid;
313   snac.family = 0x000d;
314   snac.type = 0x0008;
315   snac.flags = 0x0000;
316   snac.data = NULL;
317   
318   aim_newsnac(sess, &snac);
319
320   aim_tx_enqueue(sess, newpacket);
321
322   return (sess->snac_nextid++);
323 }
This page took 1.568121 seconds and 5 git commands to generate.