]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | #include <faim/aim.h> | |
3 | ||
4 | /* | |
5 | * aim_add_buddy() | |
6 | * | |
7 | * Adds a single buddy to your buddy list after login. | |
8 | * | |
9 | */ | |
10 | faim_export unsigned long aim_add_buddy(struct aim_session_t *sess, | |
11 | struct aim_conn_t *conn, | |
12 | char *sn ) | |
13 | { | |
14 | struct command_tx_struct *newpacket; | |
15 | int i; | |
16 | ||
17 | if(!sn) | |
18 | return -1; | |
19 | ||
20 | if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn)))) | |
21 | return -1; | |
22 | ||
23 | newpacket->lock = 1; | |
24 | ||
25 | i = aim_putsnac(newpacket->data, 0x0003, 0x0004, 0x0000, sess->snac_nextid); | |
26 | i += aimutil_put8(newpacket->data+i, strlen(sn)); | |
27 | i += aimutil_putstr(newpacket->data+i, sn, strlen(sn)); | |
28 | ||
29 | aim_tx_enqueue(sess, newpacket ); | |
30 | ||
31 | #if 0 /* do we really need this code? */ | |
32 | { | |
33 | struct aim_snac_t snac; | |
34 | ||
35 | snac.id = sess->snac_nextid; | |
36 | snac.family = 0x0003; | |
37 | snac.type = 0x0004; | |
38 | snac.flags = 0x0000; | |
39 | ||
40 | snac.data = malloc( strlen( sn ) + 1 ); | |
41 | memcpy( snac.data, sn, strlen( sn ) + 1 ); | |
42 | ||
43 | aim_newsnac(sess, &snac); | |
44 | } | |
45 | #endif | |
46 | ||
47 | return( sess->snac_nextid++ ); | |
48 | } | |
49 | ||
50 | faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess, | |
51 | struct aim_conn_t *conn, | |
52 | char *sn ) | |
53 | { | |
54 | struct command_tx_struct *newpacket; | |
55 | int i; | |
56 | ||
57 | if(!sn) | |
58 | return -1; | |
59 | ||
60 | if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn)))) | |
61 | return -1; | |
62 | ||
63 | newpacket->lock = 1; | |
64 | ||
65 | i = aim_putsnac(newpacket->data, 0x0003, 0x0005, 0x0000, sess->snac_nextid); | |
66 | ||
67 | i += aimutil_put8(newpacket->data+i, strlen(sn)); | |
68 | i += aimutil_putstr(newpacket->data+i, sn, strlen(sn)); | |
69 | ||
70 | aim_tx_enqueue(sess, newpacket); | |
71 | ||
72 | { | |
73 | struct aim_snac_t snac; | |
74 | ||
75 | snac.id = sess->snac_nextid; | |
76 | snac.family = 0x0003; | |
77 | snac.type = 0x0005; | |
78 | snac.flags = 0x0000; | |
79 | ||
80 | snac.data = malloc( strlen( sn ) + 1 ); | |
81 | memcpy( snac.data, sn, strlen( sn ) + 1 ); | |
82 | ||
83 | aim_newsnac(sess, &snac ); | |
84 | } | |
85 | ||
86 | return( sess->snac_nextid++ ); | |
87 | } | |
88 | ||
89 | faim_internal int aim_parse_buddyrights(struct aim_session_t *sess, | |
90 | struct command_rx_struct *command, ...) | |
91 | { | |
92 | rxcallback_t userfunc = NULL; | |
93 | int ret=1; | |
94 | struct aim_tlvlist_t *tlvlist; | |
95 | struct aim_tlv_t *tlv; | |
96 | unsigned short maxbuddies = 0, maxwatchers = 0; | |
97 | ||
98 | /* | |
99 | * TLVs follow | |
100 | */ | |
101 | if (!(tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10))) | |
102 | return ret; | |
103 | ||
104 | /* | |
105 | * TLV type 0x0001: Maximum number of buddies. | |
106 | */ | |
107 | if ((tlv = aim_gettlv(tlvlist, 0x0001, 1))) { | |
108 | maxbuddies = aimutil_get16(tlv->value); | |
109 | } | |
110 | ||
111 | /* | |
112 | * TLV type 0x0002: Maximum number of watchers. | |
113 | * | |
114 | * XXX: what the hell is a watcher? | |
115 | * | |
116 | */ | |
117 | if ((tlv = aim_gettlv(tlvlist, 0x0002, 1))) { | |
118 | maxwatchers = aimutil_get16(tlv->value); | |
119 | } | |
120 | ||
121 | userfunc = aim_callhandler(command->conn, 0x0003, 0x0003); | |
122 | if (userfunc) | |
123 | ret = userfunc(sess, command, maxbuddies, maxwatchers); | |
124 | ||
125 | aim_freetlvchain(&tlvlist); | |
126 | ||
127 | return ret; | |
128 | } |