Mercurial > pidgin.yaz
annotate libfaim/buddylist.c @ 2072:e105da353872
[gaim-migrate @ 2082]
I think this is prettier.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Tue, 17 Jul 2001 05:18:23 +0000 |
parents | 109cacf1ff97 |
children |
rev | line source |
---|---|
1535 | 1 |
2 #define FAIM_INTERNAL | |
3 #include <aim.h> | |
4 | |
5 /* | |
1649 | 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 * Although the offgoing notification contains no information, | |
11 * it is still in a format parsable by extractuserinfo. | |
12 * | |
13 */ | |
14 static int buddychange(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | |
15 { | |
16 struct aim_userinfo_s userinfo; | |
1839
109cacf1ff97
[gaim-migrate @ 1849]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1649
diff
changeset
|
17 aim_rxcallback_t userfunc; |
1649 | 18 |
19 aim_extractuserinfo(sess, data, &userinfo); | |
20 | |
21 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
22 return userfunc(sess, rx, &userinfo); | |
23 | |
24 return 0; | |
25 } | |
26 | |
27 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) | |
28 { | |
1839
109cacf1ff97
[gaim-migrate @ 1849]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1649
diff
changeset
|
29 aim_rxcallback_t userfunc; |
1649 | 30 struct aim_tlvlist_t *tlvlist; |
31 unsigned short maxbuddies = 0, maxwatchers = 0; | |
32 int ret = 0; | |
33 | |
34 /* | |
35 * TLVs follow | |
36 */ | |
37 if (!(tlvlist = aim_readtlvchain(data, datalen))) | |
38 return 0; | |
39 | |
40 /* | |
41 * TLV type 0x0001: Maximum number of buddies. | |
42 */ | |
43 if (aim_gettlv(tlvlist, 0x0001, 1)) | |
44 maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1); | |
45 | |
46 /* | |
47 * TLV type 0x0002: Maximum number of watchers. | |
48 * | |
49 * XXX: what the hell is a watcher? | |
50 * | |
51 */ | |
52 if (aim_gettlv(tlvlist, 0x0002, 1)) | |
53 maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1); | |
54 | |
55 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
56 ret = userfunc(sess, rx, maxbuddies, maxwatchers); | |
57 | |
58 aim_freetlvchain(&tlvlist); | |
59 | |
60 return ret; | |
61 } | |
62 | |
63 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) | |
64 { | |
65 | |
66 if (snac->subtype == 0x0003) | |
67 return rights(sess, mod, rx, snac, data, datalen); | |
68 else if ((snac->subtype == 0x000b) || (snac->subtype == 0x000c)) | |
69 return buddychange(sess, mod, rx, snac, data, datalen); | |
70 | |
71 return 0; | |
72 } | |
73 | |
74 faim_internal int buddylist_modfirst(struct aim_session_t *sess, aim_module_t *mod) | |
75 { | |
76 | |
77 mod->family = 0x0003; | |
78 mod->version = 0x0000; | |
79 mod->flags = 0; | |
80 strncpy(mod->name, "buddylist", sizeof(mod->name)); | |
81 mod->snachandler = snachandler; | |
82 | |
83 return 0; | |
84 } | |
85 | |
86 /* | |
1535 | 87 * aim_add_buddy() |
88 * | |
89 * Adds a single buddy to your buddy list after login. | |
90 * | |
91 * XXX this should just be an extension of setbuddylist() | |
92 * | |
93 */ | |
94 faim_export unsigned long aim_add_buddy(struct aim_session_t *sess, | |
95 struct aim_conn_t *conn, | |
96 char *sn ) | |
97 { | |
98 struct command_tx_struct *newpacket; | |
99 int i; | |
100 | |
101 if(!sn) | |
102 return -1; | |
103 | |
104 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn)))) | |
105 return -1; | |
106 | |
107 newpacket->lock = 1; | |
108 | |
109 i = aim_putsnac(newpacket->data, 0x0003, 0x0004, 0x0000, sess->snac_nextid); | |
110 i += aimutil_put8(newpacket->data+i, strlen(sn)); | |
111 i += aimutil_putstr(newpacket->data+i, sn, strlen(sn)); | |
112 | |
113 aim_tx_enqueue(sess, newpacket ); | |
114 | |
115 aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1); | |
116 | |
117 return sess->snac_nextid; | |
118 } | |
119 | |
120 /* | |
121 * XXX generalise to support removing multiple buddies (basically, its | |
122 * the same as setbuddylist() but with a different snac subtype). | |
123 * | |
124 */ | |
125 faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess, | |
126 struct aim_conn_t *conn, | |
127 char *sn ) | |
128 { | |
129 struct command_tx_struct *newpacket; | |
130 int i; | |
131 | |
132 if(!sn) | |
133 return -1; | |
134 | |
135 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn)))) | |
136 return -1; | |
137 | |
138 newpacket->lock = 1; | |
139 | |
140 i = aim_putsnac(newpacket->data, 0x0003, 0x0005, 0x0000, sess->snac_nextid); | |
141 | |
142 i += aimutil_put8(newpacket->data+i, strlen(sn)); | |
143 i += aimutil_putstr(newpacket->data+i, sn, strlen(sn)); | |
144 | |
145 aim_tx_enqueue(sess, newpacket); | |
146 | |
147 aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1); | |
148 | |
149 return sess->snac_nextid; | |
150 } | |
151 |