]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | |
37ee990e | 2 | #define FAIM_INTERNAL |
dd60ff8b | 3 | #include <aim.h> |
9de3ca7e | 4 | |
9f1a4013 | 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 | * | |
69e7980c | 10 | * Although the offgoing notification contains no information, |
11 | * it is still in a format parsable by extractuserinfo. | |
12 | * | |
9f1a4013 | 13 | */ |
69e7980c | 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) |
9f1a4013 | 15 | { |
16 | struct aim_userinfo_s userinfo; | |
e677fc43 | 17 | aim_rxcallback_t userfunc; |
9f1a4013 | 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 | ||
9f1a4013 | 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 | { | |
e677fc43 | 29 | aim_rxcallback_t userfunc; |
9f1a4013 | 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 | ||
00ef5271 | 66 | if (snac->subtype == 0x0003) |
9f1a4013 | 67 | return rights(sess, mod, rx, snac, data, datalen); |
69e7980c | 68 | else if ((snac->subtype == 0x000b) || (snac->subtype == 0x000c)) |
69 | return buddychange(sess, mod, rx, snac, data, datalen); | |
9f1a4013 | 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 | ||
9de3ca7e | 86 | /* |
87 | * aim_add_buddy() | |
88 | * | |
89 | * Adds a single buddy to your buddy list after login. | |
90 | * | |
37ee990e | 91 | * XXX this should just be an extension of setbuddylist() |
92 | * | |
9de3ca7e | 93 | */ |
78b3fb13 | 94 | faim_export unsigned long aim_add_buddy(struct aim_session_t *sess, |
95 | struct aim_conn_t *conn, | |
96 | char *sn ) | |
9de3ca7e | 97 | { |
5b79dc93 | 98 | struct command_tx_struct *newpacket; |
99 | int i; | |
9de3ca7e | 100 | |
5b79dc93 | 101 | if(!sn) |
102 | return -1; | |
9de3ca7e | 103 | |
646c6b52 | 104 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn)))) |
5b79dc93 | 105 | return -1; |
9de3ca7e | 106 | |
5b79dc93 | 107 | newpacket->lock = 1; |
9de3ca7e | 108 | |
5b79dc93 | 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)); | |
9de3ca7e | 112 | |
5b79dc93 | 113 | aim_tx_enqueue(sess, newpacket ); |
9de3ca7e | 114 | |
1ea867e3 | 115 | aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1); |
116 | ||
117 | return sess->snac_nextid; | |
9de3ca7e | 118 | } |
119 | ||
37ee990e | 120 | /* |
121 | * XXX generalise to support removing multiple buddies (basically, its | |
122 | * the same as setbuddylist() but with a different snac subtype). | |
123 | * | |
124 | */ | |
78b3fb13 | 125 | faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess, |
126 | struct aim_conn_t *conn, | |
127 | char *sn ) | |
9de3ca7e | 128 | { |
5b79dc93 | 129 | struct command_tx_struct *newpacket; |
130 | int i; | |
9de3ca7e | 131 | |
5b79dc93 | 132 | if(!sn) |
133 | return -1; | |
9de3ca7e | 134 | |
646c6b52 | 135 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn)))) |
5b79dc93 | 136 | return -1; |
9de3ca7e | 137 | |
5b79dc93 | 138 | newpacket->lock = 1; |
9de3ca7e | 139 | |
5b79dc93 | 140 | i = aim_putsnac(newpacket->data, 0x0003, 0x0005, 0x0000, sess->snac_nextid); |
9de3ca7e | 141 | |
5b79dc93 | 142 | i += aimutil_put8(newpacket->data+i, strlen(sn)); |
143 | i += aimutil_putstr(newpacket->data+i, sn, strlen(sn)); | |
9de3ca7e | 144 | |
5b79dc93 | 145 | aim_tx_enqueue(sess, newpacket); |
9de3ca7e | 146 | |
1ea867e3 | 147 | aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1); |
9de3ca7e | 148 | |
1ea867e3 | 149 | return sess->snac_nextid; |
9de3ca7e | 150 | } |
151 |