]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | |
2 | /* | |
3 | * aim_search.c | |
4 | * | |
5 | * TODO: Add aim_usersearch_name() | |
6 | * | |
7 | */ | |
8 | ||
37ee990e | 9 | #define FAIM_INTERNAL |
dd60ff8b | 10 | #include <aim.h> |
9de3ca7e | 11 | |
c5ca2538 | 12 | faim_export unsigned long aim_usersearch_address(struct aim_session_t *sess, |
13 | struct aim_conn_t *conn, | |
14 | char *address) | |
9de3ca7e | 15 | { |
5b79dc93 | 16 | struct command_tx_struct *newpacket; |
9de3ca7e | 17 | |
18 | if (!address) | |
19 | return -1; | |
20 | ||
646c6b52 | 21 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+strlen(address)))) |
5b79dc93 | 22 | return -1; |
9de3ca7e | 23 | |
5b79dc93 | 24 | newpacket->lock = 1; |
9de3ca7e | 25 | |
5b79dc93 | 26 | aim_putsnac(newpacket->data, 0x000a, 0x0002, 0x0000, sess->snac_nextid); |
9de3ca7e | 27 | |
5b79dc93 | 28 | aimutil_putstr(newpacket->data+10, address, strlen(address)); |
9de3ca7e | 29 | |
5b79dc93 | 30 | aim_tx_enqueue(sess, newpacket); |
9de3ca7e | 31 | |
1ea867e3 | 32 | aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, address, strlen(address)+1); |
9de3ca7e | 33 | |
1ea867e3 | 34 | return sess->snac_nextid; |
9de3ca7e | 35 | } |
36 | ||
00ef5271 | 37 | /* XXX can this be integrated with the rest of the error handling? */ |
9f1a4013 | 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) |
37ee990e | 39 | { |
9f1a4013 | 40 | int ret = 0; |
e677fc43 | 41 | aim_rxcallback_t userfunc; |
9f1a4013 | 42 | struct aim_snac_t *snac2; |
37ee990e | 43 | |
9f1a4013 | 44 | /* XXX the modules interface should have already retrieved this for us */ |
45 | if(!(snac2 = aim_remsnac(sess, snac->id))) { | |
46 | faimdprintf(sess, 2, "couldn't get a snac for 0x%08lx\n", snac->id); | |
37ee990e | 47 | return 0; |
48 | } | |
49 | ||
9f1a4013 | 50 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
51 | ret = userfunc(sess, rx, snac2->data /* address */); | |
37ee990e | 52 | |
9f1a4013 | 53 | /* XXX freesnac()? */ |
54 | if (snac2) { | |
55 | if(snac2->data) | |
56 | free(snac2->data); | |
57 | free(snac2); | |
37ee990e | 58 | } |
59 | ||
60 | return ret; | |
61 | } | |
9f1a4013 | 62 | |
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) | |
37ee990e | 64 | { |
9f1a4013 | 65 | unsigned int j, m, ret = 0; |
37ee990e | 66 | struct aim_tlvlist_t *tlvlist; |
67 | char *cur = NULL, *buf = NULL; | |
e677fc43 | 68 | aim_rxcallback_t userfunc; |
9f1a4013 | 69 | struct aim_snac_t *snac2; |
37ee990e | 70 | |
9f1a4013 | 71 | if (!(snac2 = aim_remsnac(sess, snac->id))) { |
72 | faimdprintf(sess, 2, "faim: couldn't get a snac for 0x%08lx\n", snac->id); | |
37ee990e | 73 | return 0; |
74 | } | |
75 | ||
9f1a4013 | 76 | if (!(tlvlist = aim_readtlvchain(data, datalen))) |
77 | return 0; | |
37ee990e | 78 | |
79 | j = 0; | |
80 | ||
81 | m = aim_counttlvchain(&tlvlist); | |
82 | ||
83 | while((cur = aim_gettlv_str(tlvlist, 0x0001, j+1)) && j < m) { | |
84 | if(!(buf = realloc(buf, (j+1) * (MAXSNLEN+1)))) | |
646c6b52 | 85 | faimdprintf(sess, 2, "faim: couldn't realloc buf. oh well.\n"); |
37ee990e | 86 | |
87 | strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN); | |
88 | free(cur); | |
89 | ||
90 | j++; | |
91 | } | |
92 | ||
93 | aim_freetlvchain(&tlvlist); | |
94 | ||
9f1a4013 | 95 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
96 | ret = userfunc(sess, rx, snac2->data /* address */, j, buf); | |
37ee990e | 97 | |
9f1a4013 | 98 | /* XXX freesnac()? */ |
99 | if(snac2) { | |
100 | if(snac2->data) | |
101 | free(snac2->data); | |
102 | free(snac2); | |
37ee990e | 103 | } |
104 | ||
105 | if(buf) | |
106 | free(buf); | |
107 | ||
108 | return ret; | |
109 | } | |
9f1a4013 | 110 | |
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) | |
112 | { | |
113 | ||
9f1a4013 | 114 | if (snac->subtype == 0x0001) |
115 | return error(sess, mod, rx, snac, data, datalen); | |
116 | else if (snac->subtype == 0x0003) | |
117 | return reply(sess, mod, rx, snac, data, datalen); | |
118 | ||
119 | return 0; | |
120 | } | |
121 | ||
122 | faim_internal int search_modfirst(struct aim_session_t *sess, aim_module_t *mod) | |
123 | { | |
124 | ||
125 | mod->family = 0x000a; | |
126 | mod->version = 0x0000; | |
127 | mod->flags = 0; | |
128 | strncpy(mod->name, "search", sizeof(mod->name)); | |
129 | mod->snachandler = snachandler; | |
130 | ||
131 | return 0; | |
132 | } |