]>
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 | ||
37ee990e | 37 | |
38 | faim_internal unsigned long aim_parse_searcherror(struct aim_session_t *sess, struct command_rx_struct *command) | |
39 | { | |
40 | u_int i, ret; | |
41 | int snacid; | |
42 | rxcallback_t userfunc; | |
43 | struct aim_snac_t *snac; | |
44 | ||
45 | i = 6; | |
46 | ||
47 | snacid = aimutil_get32(command->data+i); | |
48 | i += 4; | |
49 | ||
50 | if(!(snac = aim_remsnac(sess, snacid))) { | |
646c6b52 | 51 | faimdprintf(sess, 2, "faim: couldn't get a snac for %d, probably should crash.\n", snacid); |
37ee990e | 52 | return 0; |
53 | } | |
54 | ||
646c6b52 | 55 | if((userfunc = aim_callhandler(sess, command->conn, 0x000a, 0x0001))) |
37ee990e | 56 | ret = userfunc(sess, command, snac->data /* address */); |
57 | else | |
58 | ret = 0; | |
59 | ||
60 | if(snac) { | |
61 | if(snac->data) | |
62 | free(snac->data); | |
63 | free(snac); | |
64 | } | |
65 | ||
66 | return ret; | |
67 | } | |
68 | ||
69 | ||
70 | faim_internal unsigned long aim_parse_searchreply(struct aim_session_t *sess, struct command_rx_struct *command) | |
71 | { | |
72 | u_int i, j, m, ret; | |
73 | int snacid; | |
74 | struct aim_tlvlist_t *tlvlist; | |
75 | char *cur = NULL, *buf = NULL; | |
76 | rxcallback_t userfunc; | |
77 | struct aim_snac_t *snac; | |
78 | ||
79 | i = 6; | |
80 | ||
81 | snacid = aimutil_get32(command->data+i); | |
82 | i += 4; | |
83 | ||
84 | if(!(snac = aim_remsnac(sess, snacid))) { | |
646c6b52 | 85 | faimdprintf(sess, 2, "faim: couldn't get a snac for %d, probably should crash.\n", snacid); |
37ee990e | 86 | return 0; |
87 | } | |
88 | ||
89 | tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i); | |
90 | ||
91 | j = 0; | |
92 | ||
93 | m = aim_counttlvchain(&tlvlist); | |
94 | ||
95 | while((cur = aim_gettlv_str(tlvlist, 0x0001, j+1)) && j < m) { | |
96 | if(!(buf = realloc(buf, (j+1) * (MAXSNLEN+1)))) | |
646c6b52 | 97 | faimdprintf(sess, 2, "faim: couldn't realloc buf. oh well.\n"); |
37ee990e | 98 | |
99 | strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN); | |
100 | free(cur); | |
101 | ||
102 | j++; | |
103 | } | |
104 | ||
105 | aim_freetlvchain(&tlvlist); | |
106 | ||
646c6b52 | 107 | if((userfunc = aim_callhandler(sess, command->conn, 0x000a, 0x0003))) |
37ee990e | 108 | ret = userfunc(sess, command, snac->data /* address */, j, buf); |
109 | else | |
110 | ret = 0; | |
111 | ||
112 | if(snac) { | |
113 | if(snac->data) | |
114 | free(snac->data); | |
115 | free(snac); | |
116 | } | |
117 | ||
118 | if(buf) | |
119 | free(buf); | |
120 | ||
121 | return ret; | |
122 | } |