]> andersk Git - libfaim.git/blob - aim_search.c
- Sun Feb 11 01:07:36 UTC 2001
[libfaim.git] / aim_search.c
1
2 /*
3  * aim_search.c
4  *
5  * TODO: Add aim_usersearch_name()
6  *
7  */
8
9 #define FAIM_INTERNAL
10 #include <faim/aim.h>
11
12 faim_export unsigned long aim_usersearch_address(struct aim_session_t *sess,
13                                                  struct aim_conn_t *conn, 
14                                                  char *address)
15 {
16   struct command_tx_struct *newpacket;
17   
18   if (!address)
19     return -1;
20
21   if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+strlen(address))))
22     return -1;
23
24   newpacket->lock = 1;
25
26   aim_putsnac(newpacket->data, 0x000a, 0x0002, 0x0000, sess->snac_nextid);
27
28   aimutil_putstr(newpacket->data+10, address, strlen(address));
29
30   aim_tx_enqueue(sess, newpacket);
31
32   aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, address, strlen(address)+1);
33
34   return sess->snac_nextid;
35 }
36
37
38 faim_internal unsigned long aim_parse_searcherror(struct aim_session_t *sess, struct command_rx_struct *command) 
39 {
40   u_int i, ret;
41   int snacid;
42   rxcallback_t userfunc;
43   struct aim_snac_t *snac;
44
45   i = 6;
46
47   snacid = aimutil_get32(command->data+i);
48   i += 4;
49   
50   if(!(snac = aim_remsnac(sess, snacid))) {
51     faimdprintf(2, "faim: couldn't get a snac for %d, probably should crash.\n", snacid);
52     return 0;
53   }
54
55   if((userfunc = aim_callhandler(command->conn, 0x000a, 0x0001)))
56     ret = userfunc(sess, command, snac->data /* address */);
57   else
58     ret = 0;
59
60   if(snac) {
61     if(snac->data)
62       free(snac->data);
63     free(snac);
64   }
65
66   return ret;
67 }
68         
69   
70 faim_internal unsigned long aim_parse_searchreply(struct aim_session_t *sess, struct command_rx_struct *command)
71 {
72   u_int i, j, m, ret;
73   int snacid;
74   struct aim_tlvlist_t *tlvlist;
75   char *cur = NULL, *buf = NULL;
76   rxcallback_t userfunc;
77   struct aim_snac_t *snac;
78
79   i = 6;
80
81   snacid = aimutil_get32(command->data+i);
82   i += 4;
83
84   if(!(snac = aim_remsnac(sess, snacid))) {
85     faimdprintf(2, "faim: couldn't get a snac for %d, probably should crash.\n", snacid);
86     return 0;
87   }
88
89   tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
90
91   j = 0;
92
93   m = aim_counttlvchain(&tlvlist);
94
95   while((cur = aim_gettlv_str(tlvlist, 0x0001, j+1)) && j < m) {
96     if(!(buf = realloc(buf, (j+1) * (MAXSNLEN+1))))
97       faimdprintf(2, "faim: couldn't realloc buf. oh well.\n");
98
99     strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN);
100     free(cur);
101
102     j++; 
103   }
104
105   aim_freetlvchain(&tlvlist);
106
107   if((userfunc = aim_callhandler(command->conn, 0x000a, 0x0003)))
108     ret = userfunc(sess, command, snac->data /* address */, j, buf);
109   else
110     ret = 0;
111
112   if(snac) {
113     if(snac->data)
114       free(snac->data);
115     free(snac);
116   }
117
118   if(buf)
119     free(buf);
120
121   return ret;
122 }
This page took 0.046079 seconds and 5 git commands to generate.