[b7d3cc34] | 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))) { |
---|
[84b045d] | 20 | imcb_error(sess->aux_data, "couldn't get snac"); |
---|
[b7d3cc34] | 21 | return 0; |
---|
| 22 | } |
---|
| 23 | |
---|
[5ebff60] | 24 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
[b7d3cc34] | 25 | ret = userfunc(sess, rx, snac2->data /* address */); |
---|
[5ebff60] | 26 | } |
---|
[b7d3cc34] | 27 | |
---|
| 28 | /* XXX freesnac()? */ |
---|
[5ebff60] | 29 | if (snac2) { |
---|
[b7d3cc34] | 30 | g_free(snac2->data); |
---|
[5ebff60] | 31 | } |
---|
[b7d3cc34] | 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 | |
---|
[5ebff60] | 46 | if ((snac2 = aim_remsnac(sess, snac->id))) { |
---|
| 47 | searchaddr = (char *) snac2->data; |
---|
| 48 | } |
---|
[b7d3cc34] | 49 | |
---|
| 50 | tlvlist = aim_readtlvchain(bs); |
---|
| 51 | m = aim_counttlvchain(&tlvlist); |
---|
| 52 | |
---|
| 53 | /* XXX uhm. */ |
---|
[5ebff60] | 54 | while ((cur = aim_gettlv_str(tlvlist, 0x0001, j + 1)) && j < m) { |
---|
| 55 | buf = g_realloc(buf, (j + 1) * (MAXSNLEN + 1)); |
---|
[b7d3cc34] | 56 | |
---|
[5ebff60] | 57 | strncpy(&buf[j * (MAXSNLEN + 1)], cur, MAXSNLEN); |
---|
[b7d3cc34] | 58 | g_free(cur); |
---|
| 59 | |
---|
[5ebff60] | 60 | j++; |
---|
[b7d3cc34] | 61 | } |
---|
| 62 | |
---|
| 63 | aim_freetlvchain(&tlvlist); |
---|
| 64 | |
---|
[5ebff60] | 65 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
[b7d3cc34] | 66 | ret = userfunc(sess, rx, searchaddr, j, buf); |
---|
[5ebff60] | 67 | } |
---|
[b7d3cc34] | 68 | |
---|
| 69 | /* XXX freesnac()? */ |
---|
[5ebff60] | 70 | if (snac2) { |
---|
[b7d3cc34] | 71 | g_free(snac2->data); |
---|
[5ebff60] | 72 | } |
---|
[b7d3cc34] | 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 | |
---|
[5ebff60] | 83 | if (snac->subtype == 0x0001) { |
---|
[b7d3cc34] | 84 | return error(sess, mod, rx, snac, bs); |
---|
[5ebff60] | 85 | } else if (snac->subtype == 0x0003) { |
---|
[b7d3cc34] | 86 | return reply(sess, mod, rx, snac, bs); |
---|
[5ebff60] | 87 | } |
---|
[b7d3cc34] | 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 | |
---|