Mercurial > pidgin
comparison src/protocols/oscar/search.c @ 2246:933346315b9b
[gaim-migrate @ 2256]
heh.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 09 Sep 2001 10:07:14 +0000 |
parents | 424a40f12a6c |
children | c41030cfed76 |
comparison
equal
deleted
inserted
replaced
2245:31157c54fe6e | 2246:933346315b9b |
---|---|
7 */ | 7 */ |
8 | 8 |
9 #define FAIM_INTERNAL | 9 #define FAIM_INTERNAL |
10 #include <aim.h> | 10 #include <aim.h> |
11 | 11 |
12 faim_export unsigned long aim_usersearch_address(struct aim_session_t *sess, | 12 faim_export int aim_usersearch_address(aim_session_t *sess, aim_conn_t *conn, const char *address) |
13 struct aim_conn_t *conn, | |
14 char *address) | |
15 { | 13 { |
16 struct command_tx_struct *newpacket; | 14 aim_frame_t *fr; |
17 | 15 aim_snacid_t snacid; |
18 if (!address) | |
19 return -1; | |
20 | 16 |
21 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+strlen(address)))) | 17 if (!sess || !conn || !address) |
22 return -1; | 18 return -EINVAL; |
23 | 19 |
24 newpacket->lock = 1; | 20 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+strlen(address)))) |
21 return -ENOMEM; | |
25 | 22 |
26 aim_putsnac(newpacket->data, 0x000a, 0x0002, 0x0000, sess->snac_nextid); | 23 snacid = aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, strdup(address), strlen(address)+1); |
24 aim_putsnac(&fr->data, 0x000a, 0x0002, 0x0000, snacid); | |
25 | |
26 aimbs_putraw(&fr->data, address, strlen(address)); | |
27 | 27 |
28 aimutil_putstr(newpacket->data+10, address, strlen(address)); | 28 aim_tx_enqueue(sess, fr); |
29 | 29 |
30 aim_tx_enqueue(sess, newpacket); | 30 return 0; |
31 | |
32 aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, address, strlen(address)+1); | |
33 | |
34 return sess->snac_nextid; | |
35 } | 31 } |
36 | 32 |
37 /* XXX can this be integrated with the rest of the error handling? */ | 33 /* XXX can this be integrated with the rest of the error handling? */ |
38 static int error(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | 34 static int error(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
39 { | 35 { |
40 int ret = 0; | 36 int ret = 0; |
41 aim_rxcallback_t userfunc; | 37 aim_rxcallback_t userfunc; |
42 struct aim_snac_t *snac2; | 38 aim_snac_t *snac2; |
43 | 39 |
44 /* XXX the modules interface should have already retrieved this for us */ | 40 /* XXX the modules interface should have already retrieved this for us */ |
45 if(!(snac2 = aim_remsnac(sess, snac->id))) { | 41 if (!(snac2 = aim_remsnac(sess, snac->id))) { |
46 faimdprintf(sess, 2, "couldn't get a snac for 0x%08lx\n", snac->id); | 42 faimdprintf(sess, 2, "search error: couldn't get a snac for 0x%08lx\n", snac->id); |
47 return 0; | 43 return 0; |
48 } | 44 } |
49 | 45 |
50 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | 46 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
51 ret = userfunc(sess, rx, snac2->data /* address */); | 47 ret = userfunc(sess, rx, snac2->data /* address */); |
52 | 48 |
53 /* XXX freesnac()? */ | 49 /* XXX freesnac()? */ |
54 if (snac2) { | 50 if (snac2) |
55 if(snac2->data) | 51 free(snac2->data); |
56 free(snac2->data); | 52 free(snac2); |
57 free(snac2); | |
58 } | |
59 | 53 |
60 return ret; | 54 return ret; |
61 } | 55 } |
62 | 56 |
63 static int reply(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | 57 static int reply(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
64 { | 58 { |
65 unsigned int j, m, ret = 0; | 59 int j = 0, m, ret = 0; |
66 struct aim_tlvlist_t *tlvlist; | 60 aim_tlvlist_t *tlvlist; |
67 char *cur = NULL, *buf = NULL; | 61 char *cur = NULL, *buf = NULL; |
68 aim_rxcallback_t userfunc; | 62 aim_rxcallback_t userfunc; |
69 struct aim_snac_t *snac2; | 63 aim_snac_t *snac2; |
64 char *searchaddr = NULL; | |
70 | 65 |
71 if (!(snac2 = aim_remsnac(sess, snac->id))) { | 66 if ((snac2 = aim_remsnac(sess, snac->id))) |
72 faimdprintf(sess, 2, "faim: couldn't get a snac for 0x%08lx\n", snac->id); | 67 searchaddr = (char *)snac2->data; |
73 return 0; | |
74 } | |
75 | 68 |
76 if (!(tlvlist = aim_readtlvchain(data, datalen))) | 69 tlvlist = aim_readtlvchain(bs); |
77 return 0; | 70 m = aim_counttlvchain(&tlvlist); |
78 | 71 |
79 j = 0; | 72 /* XXX uhm. */ |
73 while ((cur = aim_gettlv_str(tlvlist, 0x0001, j+1)) && j < m) { | |
74 buf = realloc(buf, (j+1) * (MAXSNLEN+1)); | |
80 | 75 |
81 m = aim_counttlvchain(&tlvlist); | 76 strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN); |
77 free(cur); | |
82 | 78 |
83 while((cur = aim_gettlv_str(tlvlist, 0x0001, j+1)) && j < m) { | 79 j++; |
84 if(!(buf = realloc(buf, (j+1) * (MAXSNLEN+1)))) | 80 } |
85 faimdprintf(sess, 2, "faim: couldn't realloc buf. oh well.\n"); | |
86 | 81 |
87 strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN); | 82 aim_freetlvchain(&tlvlist); |
88 free(cur); | |
89 | 83 |
90 j++; | 84 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
91 } | 85 ret = userfunc(sess, rx, searchaddr, j, buf); |
92 | 86 |
93 aim_freetlvchain(&tlvlist); | 87 /* XXX freesnac()? */ |
88 if (snac2) | |
89 free(snac2->data); | |
90 free(snac2); | |
94 | 91 |
95 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | 92 free(buf); |
96 ret = userfunc(sess, rx, snac2->data /* address */, j, buf); | |
97 | 93 |
98 /* XXX freesnac()? */ | 94 return ret; |
99 if(snac2) { | |
100 if(snac2->data) | |
101 free(snac2->data); | |
102 free(snac2); | |
103 } | |
104 | |
105 if(buf) | |
106 free(buf); | |
107 | |
108 return ret; | |
109 } | 95 } |
110 | 96 |
111 static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | 97 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
112 { | 98 { |
113 | 99 |
114 if (snac->subtype == 0x0001) | 100 if (snac->subtype == 0x0001) |
115 return error(sess, mod, rx, snac, data, datalen); | 101 return error(sess, mod, rx, snac, bs); |
116 else if (snac->subtype == 0x0003) | 102 else if (snac->subtype == 0x0003) |
117 return reply(sess, mod, rx, snac, data, datalen); | 103 return reply(sess, mod, rx, snac, bs); |
118 | 104 |
119 return 0; | 105 return 0; |
120 } | 106 } |
121 | 107 |
122 faim_internal int search_modfirst(struct aim_session_t *sess, aim_module_t *mod) | 108 faim_internal int search_modfirst(aim_session_t *sess, aim_module_t *mod) |
123 { | 109 { |
124 | 110 |
125 mod->family = 0x000a; | 111 mod->family = 0x000a; |
126 mod->version = 0x0000; | 112 mod->version = 0x0000; |
127 mod->flags = 0; | 113 mod->flags = 0; |
128 strncpy(mod->name, "search", sizeof(mod->name)); | 114 strncpy(mod->name, "search", sizeof(mod->name)); |
129 mod->snachandler = snachandler; | 115 mod->snachandler = snachandler; |
130 | 116 |
131 return 0; | 117 return 0; |
132 } | 118 } |
119 | |
120 |