1 | /* |
---|
2 | * Family 0x000a - User Search. |
---|
3 | * |
---|
4 | * TODO: Add aim_usersearch_name() |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #define FAIM_INTERNAL |
---|
9 | #include <aim.h> |
---|
10 | |
---|
11 | /* |
---|
12 | * Subtype 0x0001 |
---|
13 | * |
---|
14 | * XXX can this be integrated with the rest of the error handling? |
---|
15 | */ |
---|
16 | static int error(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
17 | { |
---|
18 | int ret = 0; |
---|
19 | aim_rxcallback_t userfunc; |
---|
20 | aim_snac_t *snac2; |
---|
21 | |
---|
22 | /* XXX the modules interface should have already retrieved this for us */ |
---|
23 | if (!(snac2 = aim_remsnac(sess, snac->id))) { |
---|
24 | faimdprintf(sess, 2, "search error: couldn't get a snac for 0x%08lx\n", snac->id); |
---|
25 | return 0; |
---|
26 | } |
---|
27 | |
---|
28 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
29 | ret = userfunc(sess, rx, snac2->data /* address */); |
---|
30 | |
---|
31 | /* XXX freesnac()? */ |
---|
32 | if (snac2) |
---|
33 | free(snac2->data); |
---|
34 | free(snac2); |
---|
35 | |
---|
36 | return ret; |
---|
37 | } |
---|
38 | |
---|
39 | /* |
---|
40 | * Subtype 0x0002 |
---|
41 | * |
---|
42 | */ |
---|
43 | faim_export int aim_search_address(aim_session_t *sess, aim_conn_t *conn, const char *address) |
---|
44 | { |
---|
45 | aim_frame_t *fr; |
---|
46 | aim_snacid_t snacid; |
---|
47 | |
---|
48 | if (!sess || !conn || !address) |
---|
49 | return -EINVAL; |
---|
50 | |
---|
51 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+strlen(address)))) |
---|
52 | return -ENOMEM; |
---|
53 | |
---|
54 | snacid = aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, strdup(address), strlen(address)+1); |
---|
55 | aim_putsnac(&fr->data, 0x000a, 0x0002, 0x0000, snacid); |
---|
56 | |
---|
57 | aimbs_putraw(&fr->data, address, strlen(address)); |
---|
58 | |
---|
59 | aim_tx_enqueue(sess, fr); |
---|
60 | |
---|
61 | return 0; |
---|
62 | } |
---|
63 | |
---|
64 | /* |
---|
65 | * Subtype 0x0003 |
---|
66 | * |
---|
67 | */ |
---|
68 | static int reply(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
69 | { |
---|
70 | int j = 0, m, ret = 0; |
---|
71 | aim_tlvlist_t *tlvlist; |
---|
72 | char *cur = NULL, *buf = NULL; |
---|
73 | aim_rxcallback_t userfunc; |
---|
74 | aim_snac_t *snac2; |
---|
75 | char *searchaddr = NULL; |
---|
76 | |
---|
77 | if ((snac2 = aim_remsnac(sess, snac->id))) |
---|
78 | searchaddr = (char *)snac2->data; |
---|
79 | |
---|
80 | tlvlist = aim_tlvlist_read(bs); |
---|
81 | m = aim_tlvlist_count(&tlvlist); |
---|
82 | |
---|
83 | /* XXX uhm. |
---|
84 | * This is the only place that uses something other than 1 for the 3rd |
---|
85 | * parameter to aim_tlv_gettlv_whatever(). |
---|
86 | */ |
---|
87 | while ((cur = aim_tlv_getstr(tlvlist, 0x0001, j+1)) && j < m) { |
---|
88 | buf = realloc(buf, (j+1) * (MAXSNLEN+1)); |
---|
89 | |
---|
90 | strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN); |
---|
91 | free(cur); |
---|
92 | |
---|
93 | j++; |
---|
94 | } |
---|
95 | |
---|
96 | aim_tlvlist_free(&tlvlist); |
---|
97 | |
---|
98 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
99 | ret = userfunc(sess, rx, searchaddr, j, buf); |
---|
100 | |
---|
101 | /* XXX freesnac()? */ |
---|
102 | if (snac2) |
---|
103 | free(snac2->data); |
---|
104 | free(snac2); |
---|
105 | |
---|
106 | free(buf); |
---|
107 | |
---|
108 | return ret; |
---|
109 | } |
---|
110 | |
---|
111 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
112 | { |
---|
113 | |
---|
114 | if (snac->subtype == 0x0001) |
---|
115 | return error(sess, mod, rx, snac, bs); |
---|
116 | else if (snac->subtype == 0x0003) |
---|
117 | return reply(sess, mod, rx, snac, bs); |
---|
118 | |
---|
119 | return 0; |
---|
120 | } |
---|
121 | |
---|
122 | faim_internal int search_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
123 | { |
---|
124 | |
---|
125 | mod->family = 0x000a; |
---|
126 | mod->version = 0x0001; |
---|
127 | mod->toolid = 0x0110; |
---|
128 | mod->toolversion = 0x0629; |
---|
129 | mod->flags = 0; |
---|
130 | strncpy(mod->name, "search", sizeof(mod->name)); |
---|
131 | mod->snachandler = snachandler; |
---|
132 | |
---|
133 | return 0; |
---|
134 | } |
---|