[5e53c4a] | 1 | /* |
---|
[862371b] | 2 | * Family 0x000a - User Search. |
---|
[5e53c4a] | 3 | * |
---|
| 4 | * TODO: Add aim_usersearch_name() |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #define FAIM_INTERNAL |
---|
| 9 | #include <aim.h> |
---|
| 10 | |
---|
[862371b] | 11 | /* |
---|
| 12 | * Subtype 0x0001 |
---|
| 13 | * |
---|
| 14 | * XXX can this be integrated with the rest of the error handling? |
---|
| 15 | */ |
---|
[5e53c4a] | 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 | |
---|
[862371b] | 39 | /* |
---|
| 40 | * Subtype 0x0002 |
---|
| 41 | * |
---|
| 42 | */ |
---|
| 43 | faim_export int aim_usersearch_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 | */ |
---|
[5e53c4a] | 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_readtlvchain(bs); |
---|
| 81 | m = aim_counttlvchain(&tlvlist); |
---|
| 82 | |
---|
| 83 | /* XXX uhm. */ |
---|
| 84 | while ((cur = aim_gettlv_str(tlvlist, 0x0001, j+1)) && j < m) { |
---|
| 85 | buf = realloc(buf, (j+1) * (MAXSNLEN+1)); |
---|
| 86 | |
---|
| 87 | strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN); |
---|
| 88 | free(cur); |
---|
| 89 | |
---|
| 90 | j++; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | aim_freetlvchain(&tlvlist); |
---|
| 94 | |
---|
| 95 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
| 96 | ret = userfunc(sess, rx, searchaddr, j, buf); |
---|
| 97 | |
---|
| 98 | /* XXX freesnac()? */ |
---|
| 99 | if (snac2) |
---|
| 100 | free(snac2->data); |
---|
| 101 | free(snac2); |
---|
| 102 | |
---|
| 103 | free(buf); |
---|
| 104 | |
---|
| 105 | return ret; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
| 109 | { |
---|
| 110 | |
---|
| 111 | if (snac->subtype == 0x0001) |
---|
| 112 | return error(sess, mod, rx, snac, bs); |
---|
| 113 | else if (snac->subtype == 0x0003) |
---|
| 114 | return reply(sess, mod, rx, snac, bs); |
---|
| 115 | |
---|
| 116 | return 0; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | faim_internal int search_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
| 120 | { |
---|
| 121 | |
---|
| 122 | mod->family = 0x000a; |
---|
| 123 | mod->version = 0x0001; |
---|
| 124 | mod->toolid = 0x0110; |
---|
| 125 | mod->toolversion = 0x047b; |
---|
| 126 | mod->flags = 0; |
---|
| 127 | strncpy(mod->name, "search", sizeof(mod->name)); |
---|
| 128 | mod->snachandler = snachandler; |
---|
| 129 | |
---|
| 130 | return 0; |
---|
| 131 | } |
---|