]> andersk Git - libfaim.git/blob - src/buddylist.c
- Wed Oct 3 11:07:22 PDT 2001
[libfaim.git] / src / buddylist.c
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  * Although the offgoing notification contains no information,
11  * it is still in a format parsable by extractuserinfo.
12  *
13  */
14 static int buddychange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
15 {
16         aim_userinfo_t userinfo;
17         aim_rxcallback_t userfunc;
18
19         aim_extractuserinfo(sess, bs, &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(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
28 {
29         aim_rxcallback_t userfunc;
30         aim_tlvlist_t *tlvlist;
31         fu16_t maxbuddies = 0, maxwatchers = 0;
32         int ret = 0;
33
34         /* 
35          * TLVs follow 
36          */
37         tlvlist = aim_readtlvchain(bs);
38
39         /*
40          * TLV type 0x0001: Maximum number of buddies.
41          */
42         if (aim_gettlv(tlvlist, 0x0001, 1))
43                 maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1);
44
45         /*
46          * TLV type 0x0002: Maximum number of watchers.
47          *
48          * Watchers are other users who have you on their buddy
49          * list.  (This is called the "reverse list" by a certain
50          * other IM protocol.)
51          * 
52          */
53         if (aim_gettlv(tlvlist, 0x0002, 1))
54                 maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1);
55
56         if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
57                 ret = userfunc(sess, rx, maxbuddies, maxwatchers);
58
59         aim_freetlvchain(&tlvlist);
60
61         return ret;  
62 }
63
64 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
65 {
66
67         if (snac->subtype == 0x0003)
68                 return rights(sess, mod, rx, snac, bs);
69         else if ((snac->subtype == 0x000b) || (snac->subtype == 0x000c))
70                 return buddychange(sess, mod, rx, snac, bs);
71
72         return 0;
73 }
74
75 faim_internal int buddylist_modfirst(aim_session_t *sess, aim_module_t *mod)
76 {
77
78         mod->family = 0x0003;
79         mod->version = 0x0000;
80         mod->flags = 0;
81         strncpy(mod->name, "buddylist", sizeof(mod->name));
82         mod->snachandler = snachandler;
83
84         return 0;
85 }
86
87 /*
88  * aim_add_buddy()
89  *
90  * Adds a single buddy to your buddy list after login.
91  *
92  * XXX this should just be an extension of setbuddylist()
93  *
94  */
95 faim_export int aim_add_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn)
96 {
97         aim_frame_t *fr;
98         aim_snacid_t snacid;
99
100         if (!sn || !strlen(sn))
101                 return -EINVAL;
102
103         if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
104                 return -ENOMEM;
105
106         snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
107         aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid);
108
109         aimbs_put8(&fr->data, strlen(sn));
110         aimbs_putraw(&fr->data, sn, strlen(sn));
111
112         aim_tx_enqueue(sess, fr);
113
114         return 0;
115 }
116
117 /*
118  * XXX generalise to support removing multiple buddies (basically, its
119  * the same as setbuddylist() but with a different snac subtype).
120  *
121  */
122 faim_export int aim_remove_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn)
123 {
124         aim_frame_t *fr;
125         aim_snacid_t snacid;
126
127         if (!sn || !strlen(sn))
128                 return -EINVAL;
129
130         if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
131                 return -ENOMEM;
132
133         snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
134         aim_putsnac(&fr->data, 0x0003, 0x0005, 0x0000, snacid);
135
136         aimbs_put8(&fr->data, strlen(sn));
137         aimbs_putraw(&fr->data, sn, strlen(sn));
138
139         aim_tx_enqueue(sess, fr);
140
141         return 0;
142 }
143
This page took 0.061207 seconds and 5 git commands to generate.