1 | |
---|
2 | /* |
---|
3 | * aim_search.c |
---|
4 | * |
---|
5 | * TODO: Add aim_usersearch_name() |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #include "aim.h" |
---|
10 | |
---|
11 | /* XXX can this be integrated with the rest of the error handling? */ |
---|
12 | static int error(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
13 | { |
---|
14 | int ret = 0; |
---|
15 | aim_rxcallback_t userfunc; |
---|
16 | aim_snac_t *snac2; |
---|
17 | |
---|
18 | /* XXX the modules interface should have already retrieved this for us */ |
---|
19 | if (!(snac2 = aim_remsnac(sess, snac->id))) { |
---|
20 | imcb_error(sess->aux_data, "couldn't get snac"); |
---|
21 | return 0; |
---|
22 | } |
---|
23 | |
---|
24 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
25 | ret = userfunc(sess, rx, snac2->data /* address */); |
---|
26 | } |
---|
27 | |
---|
28 | /* XXX freesnac()? */ |
---|
29 | if (snac2) { |
---|
30 | g_free(snac2->data); |
---|
31 | } |
---|
32 | g_free(snac2); |
---|
33 | |
---|
34 | return ret; |
---|
35 | } |
---|
36 | |
---|
37 | static int reply(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
38 | { |
---|
39 | int j = 0, m, ret = 0; |
---|
40 | aim_tlvlist_t *tlvlist; |
---|
41 | char *cur = NULL, *buf = NULL; |
---|
42 | aim_rxcallback_t userfunc; |
---|
43 | aim_snac_t *snac2; |
---|
44 | char *searchaddr = NULL; |
---|
45 | |
---|
46 | if ((snac2 = aim_remsnac(sess, snac->id))) { |
---|
47 | searchaddr = (char *) snac2->data; |
---|
48 | } |
---|
49 | |
---|
50 | tlvlist = aim_readtlvchain(bs); |
---|
51 | m = aim_counttlvchain(&tlvlist); |
---|
52 | |
---|
53 | /* XXX uhm. */ |
---|
54 | while ((cur = aim_gettlv_str(tlvlist, 0x0001, j + 1)) && j < m) { |
---|
55 | buf = g_realloc(buf, (j + 1) * (MAXSNLEN + 1)); |
---|
56 | |
---|
57 | strncpy(&buf[j * (MAXSNLEN + 1)], cur, MAXSNLEN); |
---|
58 | g_free(cur); |
---|
59 | |
---|
60 | j++; |
---|
61 | } |
---|
62 | |
---|
63 | aim_freetlvchain(&tlvlist); |
---|
64 | |
---|
65 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
66 | ret = userfunc(sess, rx, searchaddr, j, buf); |
---|
67 | } |
---|
68 | |
---|
69 | /* XXX freesnac()? */ |
---|
70 | if (snac2) { |
---|
71 | g_free(snac2->data); |
---|
72 | } |
---|
73 | g_free(snac2); |
---|
74 | |
---|
75 | g_free(buf); |
---|
76 | |
---|
77 | return ret; |
---|
78 | } |
---|
79 | |
---|
80 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
81 | { |
---|
82 | |
---|
83 | if (snac->subtype == 0x0001) { |
---|
84 | return error(sess, mod, rx, snac, bs); |
---|
85 | } else if (snac->subtype == 0x0003) { |
---|
86 | return reply(sess, mod, rx, snac, bs); |
---|
87 | } |
---|
88 | |
---|
89 | return 0; |
---|
90 | } |
---|
91 | |
---|
92 | int search_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
93 | { |
---|
94 | |
---|
95 | mod->family = 0x000a; |
---|
96 | mod->version = 0x0001; |
---|
97 | mod->toolid = 0x0110; |
---|
98 | mod->toolversion = 0x0629; |
---|
99 | mod->flags = 0; |
---|
100 | strncpy(mod->name, "search", sizeof(mod->name)); |
---|
101 | mod->snachandler = snachandler; |
---|
102 | |
---|
103 | return 0; |
---|
104 | } |
---|
105 | |
---|
106 | |
---|