]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | #define FAIM_INTERNAL | |
3 | #include <aim.h> | |
4 | ||
5 | /* | |
6 | * Oncoming Buddy notifications contain a subset of the | |
7 | * user information structure. Its close enough to run | |
8 | * through aim_extractuserinfo() however. | |
9 | * | |
10 | */ | |
11 | static int oncoming(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | |
12 | { | |
13 | struct aim_userinfo_s userinfo; | |
14 | rxcallback_t userfunc; | |
15 | ||
16 | aim_extractuserinfo(sess, data, &userinfo); | |
17 | ||
18 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
19 | return userfunc(sess, rx, &userinfo); | |
20 | ||
21 | return 0; | |
22 | } | |
23 | ||
24 | /* | |
25 | * Offgoing Buddy notifications contain no useful | |
26 | * information other than the name it applies to. | |
27 | * | |
28 | */ | |
29 | static int offgoing(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | |
30 | { | |
31 | char sn[MAXSNLEN+1]; | |
32 | rxcallback_t userfunc; | |
33 | ||
34 | strncpy(sn, (char *)data+1, (int)*data); | |
35 | ||
36 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
37 | return userfunc(sess, rx, sn); | |
38 | ||
39 | return 0; | |
40 | } | |
41 | ||
42 | static int rights(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | |
43 | { | |
44 | rxcallback_t userfunc; | |
45 | struct aim_tlvlist_t *tlvlist; | |
46 | unsigned short maxbuddies = 0, maxwatchers = 0; | |
47 | int ret = 0; | |
48 | ||
49 | /* | |
50 | * TLVs follow | |
51 | */ | |
52 | if (!(tlvlist = aim_readtlvchain(data, datalen))) | |
53 | return 0; | |
54 | ||
55 | /* | |
56 | * TLV type 0x0001: Maximum number of buddies. | |
57 | */ | |
58 | if (aim_gettlv(tlvlist, 0x0001, 1)) | |
59 | maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1); | |
60 | ||
61 | /* | |
62 | * TLV type 0x0002: Maximum number of watchers. | |
63 | * | |
64 | * XXX: what the hell is a watcher? | |
65 | * | |
66 | */ | |
67 | if (aim_gettlv(tlvlist, 0x0002, 1)) | |
68 | maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1); | |
69 | ||
70 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
71 | ret = userfunc(sess, rx, maxbuddies, maxwatchers); | |
72 | ||
73 | aim_freetlvchain(&tlvlist); | |
74 | ||
75 | return ret; | |
76 | } | |
77 | ||
78 | static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | |
79 | { | |
80 | ||
81 | faimdprintf(sess, 0, "%s: snachandler: got %x/%x\n", mod->name, snac->family, snac->subtype); | |
82 | ||
83 | if (snac->family != mod->family) | |
84 | return 0; | |
85 | ||
86 | if (snac->subtype == 0x0001) | |
87 | ; | |
88 | else if (snac->subtype == 0x0003) | |
89 | return rights(sess, mod, rx, snac, data, datalen); | |
90 | else if (snac->subtype == 0x000b) | |
91 | return oncoming(sess, mod, rx, snac, data, datalen); | |
92 | else if (snac->subtype == 0x000c) | |
93 | return offgoing(sess, mod, rx, snac, data, datalen); | |
94 | ||
95 | return 0; | |
96 | } | |
97 | ||
98 | faim_internal int buddylist_modfirst(struct aim_session_t *sess, aim_module_t *mod) | |
99 | { | |
100 | ||
101 | mod->family = 0x0003; | |
102 | mod->version = 0x0000; | |
103 | mod->flags = 0; | |
104 | strncpy(mod->name, "buddylist", sizeof(mod->name)); | |
105 | mod->snachandler = snachandler; | |
106 | ||
107 | return 0; | |
108 | } | |
109 | ||
110 | /* | |
111 | * aim_add_buddy() | |
112 | * | |
113 | * Adds a single buddy to your buddy list after login. | |
114 | * | |
115 | * XXX this should just be an extension of setbuddylist() | |
116 | * | |
117 | */ | |
118 | faim_export unsigned long aim_add_buddy(struct aim_session_t *sess, | |
119 | struct aim_conn_t *conn, | |
120 | char *sn ) | |
121 | { | |
122 | struct command_tx_struct *newpacket; | |
123 | int i; | |
124 | ||
125 | if(!sn) | |
126 | return -1; | |
127 | ||
128 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn)))) | |
129 | return -1; | |
130 | ||
131 | newpacket->lock = 1; | |
132 | ||
133 | i = aim_putsnac(newpacket->data, 0x0003, 0x0004, 0x0000, sess->snac_nextid); | |
134 | i += aimutil_put8(newpacket->data+i, strlen(sn)); | |
135 | i += aimutil_putstr(newpacket->data+i, sn, strlen(sn)); | |
136 | ||
137 | aim_tx_enqueue(sess, newpacket ); | |
138 | ||
139 | aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1); | |
140 | ||
141 | return sess->snac_nextid; | |
142 | } | |
143 | ||
144 | /* | |
145 | * XXX generalise to support removing multiple buddies (basically, its | |
146 | * the same as setbuddylist() but with a different snac subtype). | |
147 | * | |
148 | */ | |
149 | faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess, | |
150 | struct aim_conn_t *conn, | |
151 | char *sn ) | |
152 | { | |
153 | struct command_tx_struct *newpacket; | |
154 | int i; | |
155 | ||
156 | if(!sn) | |
157 | return -1; | |
158 | ||
159 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn)))) | |
160 | return -1; | |
161 | ||
162 | newpacket->lock = 1; | |
163 | ||
164 | i = aim_putsnac(newpacket->data, 0x0003, 0x0005, 0x0000, sess->snac_nextid); | |
165 | ||
166 | i += aimutil_put8(newpacket->data+i, strlen(sn)); | |
167 | i += aimutil_putstr(newpacket->data+i, sn, strlen(sn)); | |
168 | ||
169 | aim_tx_enqueue(sess, newpacket); | |
170 | ||
171 | aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1); | |
172 | ||
173 | return sess->snac_nextid; | |
174 | } | |
175 |