comparison libpurple/protocols/oscar/family_alert.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /*
2 * Gaim's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /*
22 * Family 0x0018 - Email notification
23 *
24 * Used for being alerted when the email address(es) associated with
25 * your screen name get new electronic-m. For normal AIM accounts, you
26 * get the email address screenname@netscape.net. AOL accounts have
27 * screenname@aol.com, and can also activate a netscape.net account.
28 *
29 */
30
31 #include "oscar.h"
32
33 /**
34 * Subtype 0x0006 - Request information about your email account
35 *
36 * @param od The oscar session.
37 * @param conn The email connection for this session.
38 * @return Return 0 if no errors, otherwise return the error number.
39 */
40 int
41 aim_email_sendcookies(OscarData *od)
42 {
43 FlapConnection *conn;
44 FlapFrame *fr;
45 aim_snacid_t snacid;
46
47 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_ALERT)))
48 return -EINVAL;
49
50 fr = flap_frame_new(od, 0x02, 10+2+16+16);
51 snacid = aim_cachesnac(od, 0x0018, 0x0006, 0x0000, NULL, 0);
52 aim_putsnac(&fr->data, 0x0018, 0x0006, 0x0000, snacid);
53
54 /* Number of cookies to follow */
55 byte_stream_put16(&fr->data, 0x0002);
56
57 /* Cookie */
58 byte_stream_put16(&fr->data, 0x5d5e);
59 byte_stream_put16(&fr->data, 0x1708);
60 byte_stream_put16(&fr->data, 0x55aa);
61 byte_stream_put16(&fr->data, 0x11d3);
62 byte_stream_put16(&fr->data, 0xb143);
63 byte_stream_put16(&fr->data, 0x0060);
64 byte_stream_put16(&fr->data, 0xb0fb);
65 byte_stream_put16(&fr->data, 0x1ecb);
66
67 /* Cookie */
68 byte_stream_put16(&fr->data, 0xb380);
69 byte_stream_put16(&fr->data, 0x9ad8);
70 byte_stream_put16(&fr->data, 0x0dba);
71 byte_stream_put16(&fr->data, 0x11d5);
72 byte_stream_put16(&fr->data, 0x9f8a);
73 byte_stream_put16(&fr->data, 0x0060);
74 byte_stream_put16(&fr->data, 0xb0ee);
75 byte_stream_put16(&fr->data, 0x0631);
76
77 flap_connection_send(conn, fr);
78
79 return 0;
80 }
81
82
83 /**
84 * Subtype 0x0007 - Receive information about your email account
85 *
86 * So I don't even know if you can have multiple 16 byte keys,
87 * but this is coded so it will handle that, and handle it well.
88 * This tells you if you have unread mail or not, the URL you
89 * should use to access that mail, and the domain name for the
90 * email account (screenname@domainname.com). If this is the
91 * first 0x0007 SNAC you've received since you signed on, or if
92 * this is just a periodic status update, this will also contain
93 * the number of unread emails that you have.
94 */
95 static int
96 parseinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
97 {
98 int ret = 0;
99 aim_rxcallback_t userfunc;
100 struct aim_emailinfo *new;
101 aim_tlvlist_t *tlvlist;
102 guint8 *cookie8, *cookie16;
103 int tmp, havenewmail = 0; /* Used to tell the client we have _new_ mail */
104
105 char *alertitle = NULL, *alerturl = NULL;
106
107 cookie8 = byte_stream_getraw(bs, 8); /* Possibly the code used to log you in to mail? */
108 cookie16 = byte_stream_getraw(bs, 16); /* Mail cookie sent above */
109
110 /* See if we already have some info associated with this cookie */
111 for (new = od->emailinfo; (new && memcmp(cookie16, new->cookie16, 16)); new = new->next);
112 if (new) {
113 /* Free some of the old info, if it exists */
114 free(new->cookie8);
115 free(new->cookie16);
116 free(new->url);
117 free(new->domain);
118 } else {
119 /* We don't already have info, so create a new struct for it */
120 new = g_new0(struct aim_emailinfo, 1);
121 new->next = od->emailinfo;
122 od->emailinfo = new;
123 }
124
125 new->cookie8 = cookie8;
126 new->cookie16 = cookie16;
127
128 tlvlist = aim_tlvlist_readnum(bs, byte_stream_get16(bs));
129
130 tmp = aim_tlv_get16(tlvlist, 0x0080, 1);
131 if (tmp) {
132 if (new->nummsgs < tmp)
133 havenewmail = 1;
134 new->nummsgs = tmp;
135 } else {
136 /* If they don't send a 0x0080 TLV, it means we definitely have new mail */
137 /* (ie. this is not just another status update) */
138 havenewmail = 1;
139 new->nummsgs++; /* We know we have at least 1 new email */
140 }
141 new->url = aim_tlv_getstr(tlvlist, 0x0007, 1);
142 if (!(new->unread = aim_tlv_get8(tlvlist, 0x0081, 1))) {
143 havenewmail = 0;
144 new->nummsgs = 0;
145 }
146 new->domain = aim_tlv_getstr(tlvlist, 0x0082, 1);
147 new->flag = aim_tlv_get16(tlvlist, 0x0084, 1);
148
149 alertitle = aim_tlv_getstr(tlvlist, 0x0005, 1);
150 alerturl = aim_tlv_getstr(tlvlist, 0x000d, 1);
151
152 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
153 ret = userfunc(od, conn, frame, new, havenewmail, alertitle, (alerturl ? alerturl + 2 : NULL));
154
155 aim_tlvlist_free(&tlvlist);
156
157 free(alertitle);
158 free(alerturl);
159
160 return ret;
161 }
162
163 /**
164 * Subtype 0x0016 - Send something or other
165 *
166 * @param od The oscar session.
167 * @param conn The email connection for this session.
168 * @return Return 0 if no errors, otherwise return the error number.
169 */
170 int
171 aim_email_activate(OscarData *od)
172 {
173 FlapConnection *conn;
174 FlapFrame *fr;
175 aim_snacid_t snacid;
176
177 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_ALERT)))
178 return -EINVAL;
179
180 fr = flap_frame_new(od, 0x02, 10+1+16);
181 snacid = aim_cachesnac(od, 0x0018, 0x0016, 0x0000, NULL, 0);
182 aim_putsnac(&fr->data, 0x0018, 0x0016, 0x0000, snacid);
183
184 /* I would guess this tells AIM that you want updates for your mail accounts */
185 /* ...but I really have no idea */
186 byte_stream_put8(&fr->data, 0x02);
187 byte_stream_put32(&fr->data, 0x04000000);
188 byte_stream_put32(&fr->data, 0x04000000);
189 byte_stream_put32(&fr->data, 0x04000000);
190 byte_stream_put32(&fr->data, 0x00000000);
191
192 flap_connection_send(conn, fr);
193
194 return 0;
195 }
196
197 static int
198 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
199 {
200 if (snac->subtype == 0x0007)
201 return parseinfo(od, conn, mod, frame, snac, bs);
202
203 return 0;
204 }
205
206 static void
207 email_shutdown(OscarData *od, aim_module_t *mod)
208 {
209 while (od->emailinfo)
210 {
211 struct aim_emailinfo *tmp = od->emailinfo;
212 od->emailinfo = od->emailinfo->next;
213 free(tmp->cookie16);
214 free(tmp->cookie8);
215 free(tmp->url);
216 free(tmp->domain);
217 free(tmp);
218 }
219
220 return;
221 }
222
223 int
224 email_modfirst(OscarData *od, aim_module_t *mod)
225 {
226 mod->family = 0x0018;
227 mod->version = 0x0001;
228 mod->toolid = 0x0010;
229 mod->toolversion = 0x0629;
230 mod->flags = 0;
231 strncpy(mod->name, "alert", sizeof(mod->name));
232 mod->snachandler = snachandler;
233 mod->shutdown = email_shutdown;
234
235 return 0;
236 }