Mercurial > pidgin.yaz
annotate plugins/msn/msn.c @ 1898:73d73939f698
[gaim-migrate @ 1908]
this is part one of three.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 28 May 2001 03:36:04 +0000 |
parents | 1c977d995da9 |
children | 0ec62ca82a8a |
rev | line source |
---|---|
1259 | 1 /* |
2 * gaim - MSN Protocol Plugin | |
3 * | |
4 * Copyright (C) 2000, Rob Flynn <rob@tgflinux.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program 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 | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
1514
0dd012166152
[gaim-migrate @ 1524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
22 #include "config.h" |
1259 | 23 |
24 #include <netdb.h> | |
25 #include <gtk/gtk.h> | |
26 #include <unistd.h> | |
27 #include <errno.h> | |
28 #include <netinet/in.h> | |
29 #include <arpa/inet.h> | |
30 #include <string.h> | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <time.h> | |
1567 | 34 #include <fcntl.h> |
1259 | 35 #include <sys/socket.h> |
36 #include <sys/stat.h> | |
1567 | 37 #include <sys/types.h> |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
38 #include <ctype.h> |
1259 | 39 #include "multi.h" |
40 #include "prpl.h" | |
41 #include "gaim.h" | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
42 #include "proxy.h" |
1259 | 43 #include "md5.h" |
44 | |
1284 | 45 #include "pixmaps/msn_online.xpm" |
1285 | 46 #include "pixmaps/msn_away.xpm" |
1717 | 47 #include "pixmaps/ok.xpm" |
1833 | 48 #include "pixmaps/cancel.xpm" |
1284 | 49 |
1567 | 50 #define MIME_HEADER "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nX-MMS-IM-Format: FN=MS%20Sans%20Serif; EF=; CO=0; CS=0; PF=0\r\n\r\n" |
1259 | 51 |
1567 | 52 #define MSN_BUF_LEN 8192 |
1259 | 53 |
54 #define MSN_ONLINE 1 | |
55 #define MSN_BUSY 2 | |
56 #define MSN_IDLE 3 | |
57 #define MSN_BRB 4 | |
58 #define MSN_AWAY 5 | |
59 #define MSN_PHONE 6 | |
60 #define MSN_LUNCH 7 | |
61 #define MSN_OFFLINE 8 | |
62 #define MSN_HIDDEN 9 | |
63 | |
1567 | 64 #define MSN_SIGNON_GOT_XFR 0x0001 |
65 #define MSN_SIGNON_SENT_USR 0x0002 | |
1259 | 66 |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
67 #define USEROPT_HOTMAIL 0 |
1717 | 68 |
69 struct mod_usr_opt { | |
70 struct aim_user *user; | |
71 int opt; | |
72 }; | |
73 | |
1598 | 74 struct msn_ask_add_permit { |
75 struct gaim_connection *gc; | |
76 char *user; | |
77 char *friendly; | |
78 }; | |
79 | |
1259 | 80 struct msn_data { |
81 int fd; | |
82 | |
83 char protocol[6]; | |
84 char *friendly; | |
85 gchar *policy; | |
1567 | 86 int inpa; |
87 int status; | |
1631 | 88 int away; |
1567 | 89 time_t last_trid; |
1259 | 90 }; |
91 | |
1833 | 92 struct msn_name_dlg { |
93 GtkWidget *window; | |
94 GtkWidget *menu; | |
95 struct aim_user *user; | |
96 GtkWidget *entry; | |
97 GtkWidget *ok; | |
98 GtkWidget *cancel; | |
99 }; | |
100 | |
1259 | 101 struct msn_conn { |
102 gchar *user; | |
103 int inpa; | |
104 int fd; | |
1572 | 105 struct gaim_connection *gc; |
106 char *secret; | |
107 char *session; | |
1584 | 108 time_t last_trid; |
109 char *txqueue; | |
1259 | 110 }; |
111 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
112 static GSList *msn_connections = NULL; |
1259 | 113 |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
114 static unsigned long long globalc = 0; |
1572 | 115 static void msn_callback(gpointer data, gint source, GdkInputCondition condition); |
1598 | 116 static void msn_add_permit(struct gaim_connection *gc, char *who); |
1717 | 117 static void process_hotmail_msg(struct gaim_connection *gc, gchar *msgdata); |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
118 static void msn_des_win(GtkWidget *a, GtkWidget *b); |
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
119 static void msn_newmail_dialog(const char *text); |
1756 | 120 static char *msn_normalize(const char *s); |
1598 | 121 |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
122 static char tochar(char *h) |
1754 | 123 { |
124 char tmp; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
125 char b = 0; |
1754 | 126 int v = 0; |
127 int i; | |
128 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
129 for (i = strlen(h); i > 0; i--) { |
1754 | 130 tmp = tolower(h[strlen(h) - i]); |
131 | |
132 if (tmp >= '0' && tmp <= '9') | |
133 b = tmp - '0'; | |
134 else if (tmp >= 'a' && tmp <= 'f') | |
135 b = (tmp - 'a') + 10; | |
136 | |
137 if (i > 1) | |
138 v =+ ((i-1) * 16) * b; | |
139 else | |
140 v += b; | |
141 } | |
142 | |
143 return v; | |
144 } | |
145 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
146 static char *url_decode(char *text) |
1754 | 147 { |
148 static char newtext[MSN_BUF_LEN]; | |
149 char *buf; | |
150 int c = 0; | |
151 int i = 0; | |
152 int j = 0; | |
153 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
154 for (i = 0; i < strlen(text); i++) { |
1754 | 155 if (text[i] == '%') |
156 c++; | |
157 } | |
158 | |
159 buf = (char *)malloc(strlen(text) + c + 1); | |
160 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
161 for (i = 0, j = 0 ; text[i] != 0; i++) { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
162 if (text[i] != '%') { |
1754 | 163 buf[j++] = text[i]; |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
164 } else { |
1754 | 165 char hex[3]; |
166 hex[0] = text[++i]; | |
167 hex[1] = text[++i]; | |
168 hex[2] = 0; | |
169 | |
170 buf[j++] = tochar(hex); | |
171 } | |
172 } | |
173 | |
1833 | 174 buf[j] = 0; |
175 | |
1754 | 176 for (i = 0; i < strlen(buf); i++) |
177 newtext[i] = buf[i]; | |
178 | |
179 free(buf); | |
180 | |
181 return newtext; | |
182 } | |
183 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
184 static void msn_accept_add_permit(gpointer w, struct msn_ask_add_permit *ap) |
1598 | 185 { |
186 msn_add_permit(ap->gc, ap->user); | |
1733 | 187 /* leak if we don't free these? */ |
188 g_free(ap->user); | |
189 g_free(ap->friendly); | |
190 g_free(ap); | |
1598 | 191 } |
192 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
193 static void msn_cancel_add_permit(gpointer w, struct msn_ask_add_permit *ap) |
1598 | 194 { |
195 g_free(ap->user); | |
196 g_free(ap->friendly); | |
197 g_free(ap); | |
198 } | |
1259 | 199 |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
200 static void free_msn_conn(struct msn_conn *mc) |
1588 | 201 { |
202 if (mc->user) | |
203 free(mc->user); | |
204 | |
205 if (mc->secret) | |
206 free(mc->secret); | |
207 | |
208 if (mc->session) | |
209 free(mc->session); | |
210 | |
211 if (mc->txqueue) | |
212 free(mc->txqueue); | |
213 | |
214 gdk_input_remove(mc->inpa); | |
215 close(mc->fd); | |
216 | |
217 msn_connections = g_slist_remove(msn_connections, mc); | |
218 | |
219 g_free(mc); | |
220 } | |
221 | |
222 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
223 static struct msn_conn *find_msn_conn_by_user(gchar * user) |
1584 | 224 { |
225 struct msn_conn *mc; | |
226 GSList *conns = msn_connections; | |
227 | |
228 while (conns) { | |
229 mc = (struct msn_conn *)conns->data; | |
230 | |
231 if (mc != NULL) { | |
232 if (strcasecmp(mc->user, user) == 0) { | |
233 return mc; | |
234 } | |
235 } | |
236 | |
237 conns = g_slist_next(conns); | |
238 } | |
239 | |
240 return NULL; | |
241 } | |
242 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
243 static struct msn_conn *find_msn_conn_by_trid(time_t trid) |
1584 | 244 { |
245 struct msn_conn *mc; | |
246 GSList *conns = msn_connections; | |
247 | |
248 while (conns) { | |
249 mc = (struct msn_conn *)conns->data; | |
250 | |
251 if (mc != NULL) { | |
252 | |
1733 | 253 debug_printf("Comparing: %d <==> %d\n", mc->last_trid, trid); |
1584 | 254 if (mc->last_trid == trid) { |
255 return mc; | |
256 } | |
257 } | |
258 | |
259 conns = g_slist_next(conns); | |
260 } | |
261 | |
262 return NULL; | |
263 } | |
264 | |
1282 | 265 static char *msn_name() |
266 { | |
1259 | 267 return "MSN"; |
268 } | |
269 | |
1282 | 270 char *name() |
271 { | |
1259 | 272 return "MSN"; |
273 } | |
274 | |
1282 | 275 char *description() |
276 { | |
1259 | 277 return "Allows gaim to use the MSN protocol. For some reason, this frightens me."; |
278 } | |
279 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
280 static time_t trId(struct msn_data *md) |
1282 | 281 { |
1567 | 282 md->last_trid = time((time_t *)NULL) + globalc++; |
283 return md->last_trid; | |
284 } | |
285 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
286 static void msn_write(int fd, char *buf) |
1567 | 287 { |
288 write(fd, buf, strlen(buf)); | |
1733 | 289 debug_printf("MSN(%d) <== %s", fd, buf); |
290 } | |
291 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
292 static void msn_add_request(struct gaim_connection *gc, char *buf) |
1733 | 293 { |
294 char **res; | |
295 | |
296 res = g_strsplit(buf, " ", 0); | |
297 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
298 if (!strcasecmp(res[2], "RL")) { |
1733 | 299 struct msn_ask_add_permit *ap = g_new0(struct msn_ask_add_permit, 1); |
300 | |
301 snprintf(buf, MSN_BUF_LEN, "The user %s (%s) wants to add you to their buddylist.", res[4], res[5]); | |
302 | |
303 ap->user = g_strdup(res[4]); | |
1833 | 304 |
1756 | 305 ap->friendly = g_strdup(url_decode(res[5])); |
1733 | 306 ap->gc = gc; |
307 | |
308 do_ask_dialog(buf, ap, (GtkFunction) msn_accept_add_permit, (GtkFunction) msn_cancel_add_permit); | |
309 } | |
310 | |
311 g_strfreev(res); | |
1567 | 312 } |
1259 | 313 |
1572 | 314 static void msn_answer_callback(gpointer data, gint source, GdkInputCondition condition) |
315 { | |
316 struct msn_conn *mc = data; | |
317 char buf[MSN_BUF_LEN]; | |
318 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
319 if (source == -1) { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
320 g_free(mc->session); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
321 g_free(mc->secret); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
322 g_free(mc->user); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
323 g_free(mc); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
324 return; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
325 } |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
326 |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
327 if (mc->fd != source) |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
328 mc->fd = source; |
1572 | 329 |
1756 | 330 g_snprintf(buf, MSN_BUF_LEN, "ANS 1 %s %s %s\n",mc->gc->username, mc->secret, mc->session); |
1572 | 331 msn_write(mc->fd, buf); |
332 | |
333 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | |
334 | |
335 /* Append our connection */ | |
336 msn_connections = g_slist_append(msn_connections, mc); | |
337 } | |
338 | |
1584 | 339 static void msn_invite_callback(gpointer data, gint source, GdkInputCondition condition) |
340 { | |
341 struct msn_conn *mc = data; | |
342 struct msn_data *md = (struct msn_data *)mc->gc->proto_data; | |
343 char buf[MSN_BUF_LEN]; | |
344 int i = 0; | |
1585 | 345 |
1584 | 346 bzero(buf, MSN_BUF_LEN); |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
347 do { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
348 if (!read(source, buf + i, 1)) { |
1588 | 349 free_msn_conn(mc); |
1584 | 350 return; |
351 } | |
352 } while (buf[i++] != '\n'); | |
353 | |
354 g_strchomp(buf); | |
355 | |
1733 | 356 debug_printf("MSN(%d) ==> %s\n", source, buf); |
1584 | 357 |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
358 if (!strncmp("USR ", buf, 4)) { |
1584 | 359 char **res; |
360 | |
361 res = g_strsplit(buf, " ", 0); | |
1733 | 362 debug_printf("%s\n",res[2]); |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
363 if (strcasecmp("OK", res[2])) { |
1584 | 364 g_strfreev(res); |
365 close(mc->fd); | |
366 return; | |
367 } | |
368 | |
369 /* We've authorized. Let's send an invite request */ | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
370 g_snprintf(buf, MSN_BUF_LEN, "CAL %ld %s\n", trId(md), mc->user); |
1584 | 371 msn_write(source, buf); |
372 return; | |
373 } | |
374 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
375 else if (!strncmp("JOI ", buf, 4)) { |
1584 | 376 /* Looks like they just joined! Write their queued message */ |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
377 g_snprintf(buf, MSN_BUF_LEN, "MSG %ld N %d\r\n%s%s", trId(md), strlen(mc->txqueue) + strlen(MIME_HEADER), MIME_HEADER, mc->txqueue); |
1584 | 378 |
379 msn_write(source, buf); | |
380 | |
381 gdk_input_remove(mc->inpa); | |
382 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | |
383 | |
384 return; | |
385 | |
386 } | |
387 } | |
388 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
389 static void msn_xfr_callback(gpointer data, gint source, GdkInputCondition condition) |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
390 { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
391 struct msn_conn *mc = data; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
392 char buf[MSN_BUF_LEN]; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
393 |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
394 if (source == -1) |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
395 return; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
396 |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
397 if (mc->fd != source) |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
398 mc->fd = source; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
399 |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
400 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_invite_callback, mc); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
401 g_snprintf(buf, MSN_BUF_LEN, "USR %ld %s %s\n", mc->last_trid, mc->gc->username, mc->secret); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
402 msn_write(mc->fd, buf); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
403 } |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
404 |
1567 | 405 static void msn_callback(gpointer data, gint source, GdkInputCondition condition) |
406 { | |
407 struct gaim_connection *gc = data; | |
408 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
409 char buf[MSN_BUF_LEN]; | |
410 int i = 0; | |
1572 | 411 int num; |
1259 | 412 |
1567 | 413 bzero(buf, MSN_BUF_LEN); |
414 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
415 do { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
416 if (!read(source, buf + i, 1)) { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
417 if (md->fd == source) { |
1588 | 418 hide_login_progress(gc, "Read error"); |
419 signoff(gc); | |
420 } | |
421 | |
422 close(source); | |
423 | |
1567 | 424 return; |
1259 | 425 } |
426 | |
1567 | 427 } while (buf[i++] != '\n'); |
428 | |
429 g_strchomp(buf); | |
430 | |
1733 | 431 debug_printf("MSN(%d) ==> %s\n", source, buf); |
1567 | 432 |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
433 if (!strncmp("NLN ", buf, 4) || !strncmp("ILN ", buf, 4)) { |
1569 | 434 int status; |
435 int query; | |
436 char **res; | |
437 | |
438 res = g_strsplit(buf, " ", 0); | |
439 | |
440 if (!strcmp(res[0], "NLN")) | |
441 query = 1; | |
442 else | |
443 query = 2; | |
444 | |
445 if (!strcasecmp(res[query], "NLN")) | |
446 status = UC_NORMAL; | |
447 else if (!strcasecmp(res[query], "BSY")) | |
448 status = UC_NORMAL | (MSN_BUSY << 5); | |
449 else if (!strcasecmp(res[query], "IDL")) | |
450 status = UC_NORMAL | (MSN_IDLE << 5); | |
451 else if (!strcasecmp(res[query], "BRB")) | |
452 status = UC_NORMAL | (MSN_BRB << 5); | |
453 else if (!strcasecmp(res[query], "AWY")) | |
454 status = UC_UNAVAILABLE; | |
455 else if (!strcasecmp(res[query], "PHN")) | |
456 status = UC_NORMAL | (MSN_PHONE << 5); | |
457 else if (!strcasecmp(res[query], "LUN")) | |
458 status = UC_NORMAL | (MSN_LUNCH << 5); | |
459 else | |
460 status = UC_NORMAL; | |
461 | |
462 serv_got_update(gc, res[query+1], 1, 0, 0, 0, status, 0); | |
463 | |
464 g_strfreev(res); | |
465 | |
466 return; | |
467 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
468 } else if (!strncmp("REA ", buf, 4)) { |
1833 | 469 char **res; |
470 | |
471 res = g_strsplit(buf, " ", 0); | |
472 | |
1864
5cb89cf24f45
[gaim-migrate @ 1874]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1851
diff
changeset
|
473 /* Kill the old one */ |
1833 | 474 g_free(md->friendly); |
475 | |
1864
5cb89cf24f45
[gaim-migrate @ 1874]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1851
diff
changeset
|
476 /* Set the new one */ |
1833 | 477 md->friendly = g_strdup(res[4]); |
478 | |
1864
5cb89cf24f45
[gaim-migrate @ 1874]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1851
diff
changeset
|
479 /* And free up some memory. That's all, folks. */ |
1833 | 480 g_strfreev(res); |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
481 } else if (!strncmp("BYE ", buf, 4)) { |
1628 | 482 char **res; |
483 struct msn_conn *mc; | |
484 | |
485 res = g_strsplit(buf, " ", 0); | |
486 | |
487 mc = find_msn_conn_by_user(res[1]); | |
488 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
489 if (mc) { |
1628 | 490 /* Looks like we need to close up some stuff :-) */ |
491 free_msn_conn(mc); | |
492 } | |
493 | |
494 g_strfreev(res); | |
495 return; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
496 } else if (!strncmp("MSG ", buf, 4)) { |
1572 | 497 /* We are receiving an incoming message */ |
498 gchar **res; | |
499 gchar *user; | |
500 gchar *msgdata; | |
501 int size; | |
1731
7fc4b9fe295a
[gaim-migrate @ 1741]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1717
diff
changeset
|
502 char rahc[MSN_BUF_LEN * 2]; |
1572 | 503 |
504 res = g_strsplit(buf, " ", 0); | |
505 | |
506 user = g_strdup(res[1]); | |
507 size = atoi(res[3]); | |
508 | |
509 /* Ok, we know who we're receiving a message from as well as | |
510 * how big the message is */ | |
511 | |
512 msgdata = (gchar *)g_malloc(sizeof(gchar) *(size + 1)); | |
513 num = recv(source, msgdata, size, 0); | |
514 msgdata[size] = 0; | |
515 | |
516 if (num < size) | |
1733 | 517 debug_printf("MSN: Uhh .. we gots a problem!. Expected %d but got %d.\n", size, num); |
1572 | 518 |
519 /* We should ignore messages from the user Hotmail */ | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
520 if (!strcasecmp("hotmail", res[1])) { |
1717 | 521 process_hotmail_msg(gc,msgdata); |
1572 | 522 g_strfreev(res); |
523 g_free(msgdata); | |
524 return; | |
525 } | |
526 | |
527 /* Check to see if any body is in the message */ | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
528 if (!strcmp(strstr(msgdata, "\r\n\r\n") + 4, "\r\n")) { |
1572 | 529 g_strfreev(res); |
530 g_free(msgdata); | |
531 return; | |
532 } | |
533 | |
534 /* Otherwise, everything is ok. Let's show the message. Skipping, | |
535 * of course, the header. */ | |
536 | |
1731
7fc4b9fe295a
[gaim-migrate @ 1741]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1717
diff
changeset
|
537 g_snprintf(rahc, sizeof(rahc), "%s", strstr(msgdata, "\r\n\r\n") + 4); |
1764 | 538 serv_got_im(gc, res[1], rahc, 0, time((time_t)NULL)); |
1572 | 539 |
540 g_strfreev(res); | |
541 g_free(msgdata); | |
542 | |
543 return; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
544 } else if (!strncmp("RNG ", buf, 4)) { |
1572 | 545 /* Ok, someone wants to talk to us. Ring ring? Hi!!! */ |
546 gchar **address; | |
547 gchar **res; | |
548 struct msn_conn *mc = g_new0(struct msn_conn, 1); | |
1864
5cb89cf24f45
[gaim-migrate @ 1874]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1851
diff
changeset
|
549 struct aim_user *user = gc->user; |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
550 mc->gc = gc; |
1572 | 551 |
552 res = g_strsplit(buf, " ", 0); | |
553 address = g_strsplit(res[2], ":", 0); | |
554 | |
555 /* Set up our struct with user and input watcher */ | |
556 mc->user = g_strdup(res[5]); | |
557 mc->secret = g_strdup(res[4]); | |
558 mc->session = g_strdup(res[1]); | |
559 | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1866
diff
changeset
|
560 mc->fd = proxy_connect(address[0], atoi(address[1]), msn_answer_callback, mc); |
1572 | 561 g_strfreev(address); |
562 g_strfreev(res); | |
1866
466fc4ada7cb
[gaim-migrate @ 1876]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1864
diff
changeset
|
563 if (!user->gc || (mc->fd < 0)) { |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
564 /* Looks like we had an error connecting. */ |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
565 g_free(mc->session); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
566 g_free(mc->secret); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
567 g_free(mc->user); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
568 g_free(mc); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
569 return; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
570 } |
1572 | 571 return; |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
572 } else if (!strncmp("XFR ", buf, 4)) { |
1584 | 573 char **res; |
574 struct msn_conn *mc; | |
575 | |
576 res = g_strsplit(buf, " ", 0); | |
577 | |
1733 | 578 debug_printf("Last trid is: %d\n", md->last_trid); |
579 debug_printf("This TrId is: %d\n", atoi(res[1])); | |
1584 | 580 |
581 mc = find_msn_conn_by_trid(atoi(res[1])); | |
582 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
583 if (!mc) { |
1584 | 584 g_strfreev(res); |
585 return; | |
586 } | |
587 | |
588 strcpy(buf, res[3]); | |
589 | |
590 mc->secret = g_strdup(res[5]); | |
591 mc->session = g_strdup(res[1]); | |
592 | |
593 g_strfreev(res); | |
594 | |
595 res = g_strsplit(buf, ":", 0); | |
596 | |
597 /* Now we have the host and port */ | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
598 debug_printf("Connecting to: %s:%s\n", res[0], res[1]); |
1584 | 599 |
1585 | 600 if (mc->inpa) |
601 gdk_input_remove(mc->inpa); | |
602 | |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1866
diff
changeset
|
603 mc->fd = proxy_connect(res[0], atoi(res[1]), msn_xfr_callback, mc); |
1584 | 604 g_strfreev(res); |
605 | |
606 return; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
607 } else if (!strncmp("LST ", buf, 4)) { |
1567 | 608 char **res; |
609 | |
610 res = g_strsplit(buf, " ", 0); | |
611 | |
1568 | 612 /* If we have zero buddies, abort */ |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
613 if (atoi(res[5]) == 0) { |
1568 | 614 g_strfreev(res); |
615 return; | |
616 } | |
617 | |
1567 | 618 /* First, let's check the list type */ |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
619 if (!strcmp("FL", res[2])) { |
1567 | 620 /* We're dealing with a forward list. Add them |
621 * to our buddylist and continue along our | |
622 * merry little way */ | |
623 | |
624 struct buddy *b; | |
625 | |
626 b = find_buddy(gc, res[6]); | |
627 | |
628 if (!b) | |
629 add_buddy(gc, "Buddies", res[6], res[7]); | |
630 } | |
631 | |
632 g_strfreev(res); | |
633 | |
634 return; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
635 } else if (!strncmp("FLN ", buf, 4)) { |
1628 | 636 /* Someone signed off */ |
637 char **res; | |
638 | |
639 res = g_strsplit(buf, " ", 0); | |
640 | |
641 serv_got_update(gc, res[1], 0, 0, 0, 0, 0, 0); | |
642 | |
643 g_strfreev(res); | |
644 | |
645 return; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
646 } else if (!strncmp("ADD ", buf, 4)) { |
1733 | 647 msn_add_request(gc,buf); |
648 return; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
649 } if ( (!strncmp("NLN ", buf, 4)) || (!strncmp("ILN ", buf, 4))) { |
1628 | 650 int status; |
651 int query; | |
652 char **res; | |
653 | |
654 res = g_strsplit(buf, " ", 0); | |
655 | |
656 if (strcasecmp(res[0], "NLN") == 0) | |
657 query = 1; | |
658 else | |
659 query = 2; | |
660 | |
661 if (!strcasecmp(res[query], "NLN")) | |
662 status = UC_NORMAL; | |
663 else if (!strcasecmp(res[query], "BSY")) | |
664 status = UC_NORMAL | (MSN_BUSY << 5); | |
665 else if (!strcasecmp(res[query], "IDL")) | |
666 status = UC_NORMAL | (MSN_IDLE << 5); | |
667 else if (!strcasecmp(res[query], "BRB")) | |
668 status = UC_NORMAL | (MSN_BRB << 5); | |
669 else if (!strcasecmp(res[query], "AWY")) | |
670 status = UC_UNAVAILABLE; | |
671 else if (!strcasecmp(res[query], "PHN")) | |
672 status = UC_NORMAL | (MSN_PHONE << 5); | |
673 else if (!strcasecmp(res[query], "LUN")) | |
674 status = UC_NORMAL | (MSN_LUNCH << 5); | |
675 else | |
676 status = UC_NORMAL; | |
677 | |
678 serv_got_update(gc, res[query+1], 1, 0, 0, 0, status, 0); | |
679 | |
680 g_strfreev(res); | |
681 return; | |
682 } | |
1259 | 683 |
684 } | |
685 | |
1567 | 686 static void msn_login_callback(gpointer data, gint source, GdkInputCondition condition) |
1282 | 687 { |
1567 | 688 struct gaim_connection *gc = data; |
689 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
690 char buf[MSN_BUF_LEN]; | |
1259 | 691 int i = 0; |
1282 | 692 |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
693 if (source == -1) { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
694 signoff(gc); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
695 return; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
696 } |
1567 | 697 |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
698 if (md->fd != source) { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
699 debug_printf("Eric, you fucked up.\n"); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
700 md->fd = source; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
701 } |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
702 |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
703 if (!gc->inpa) { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
704 if (md->inpa > 0) |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
705 gdk_input_remove(md->inpa); |
1567 | 706 md->inpa = 0; |
707 | |
708 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_login_callback, gc); | |
1307 | 709 |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
710 if (md->status & MSN_SIGNON_GOT_XFR) { |
1567 | 711 /* Looks like we were transfered here. Just send a sign on */ |
712 set_login_progress(gc, 3, "Signing On"); | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
713 g_snprintf(buf, MSN_BUF_LEN, "USR %ld %s I %s\n", md->last_trid, md->policy, gc->username); |
1567 | 714 msn_write(md->fd, buf); |
715 | |
716 /* Reset this bit */ | |
717 md->status ^= MSN_SIGNON_GOT_XFR; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
718 } else { |
1567 | 719 /* Otherwise, send an initial request */ |
1733 | 720 set_login_progress(gc, 2, "Verifying"); |
1259 | 721 |
1567 | 722 g_snprintf(md->protocol, 6, "MSNP2"); |
723 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
724 g_snprintf(buf, MSN_BUF_LEN, "VER %ld %s\n", trId(md), md->protocol); |
1567 | 725 msn_write(md->fd, buf); |
726 } | |
727 | |
728 return; | |
729 } | |
730 | |
731 bzero(buf, MSN_BUF_LEN); | |
732 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
733 do { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
734 if (!read(source, buf + i, 1)) { |
1567 | 735 hide_login_progress(gc, "Read error"); |
736 signoff(gc); | |
1259 | 737 return; |
1567 | 738 } |
739 } while (buf[i++] != '\n'); | |
1259 | 740 |
741 g_strchomp(buf); | |
742 | |
1733 | 743 debug_printf("MSN ==> %s\n", buf); |
1567 | 744 |
745 /* Check to see what was just sent back to us. We should be seeing a VER tag. */ | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
746 if (!strncmp("VER ", buf, 4) && (!strstr("MSNP2", buf))) { |
1733 | 747 /* Now that we got our ver, we should send a policy request */ |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
748 g_snprintf(buf, MSN_BUF_LEN, "INF %ld\n", trId(md)); |
1567 | 749 msn_write(md->fd, buf); |
750 | |
751 return; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
752 } else if (!strncmp("INF ", buf, 4)) { |
1567 | 753 char **res; |
754 | |
755 /* Make a copy of our resulting policy */ | |
756 res = g_strsplit(buf, " ", 0); | |
757 md->policy = g_strdup(res[2]); | |
758 | |
759 /* And send our signon packet */ | |
760 set_login_progress(gc, 3, "Signing On"); | |
761 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
762 g_snprintf(buf, MSN_BUF_LEN, "USR %ld %s I %s\n", trId(md), md->policy, gc->username); |
1567 | 763 msn_write(md->fd, buf); |
764 | |
765 g_strfreev(res); | |
766 | |
767 return; | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
768 } else if (!strncmp("ADD ", buf, 4)) { |
1733 | 769 msn_add_request(gc,buf); |
1598 | 770 return; |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
771 } else if (!strncmp("XFR ", buf, 4)) { |
1567 | 772 char **res; |
1864
5cb89cf24f45
[gaim-migrate @ 1874]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1851
diff
changeset
|
773 struct aim_user *user = gc->user; |
1567 | 774 |
775 res = g_strsplit(buf, " ", 0); | |
776 | |
777 strcpy(buf, res[3]); | |
778 | |
779 g_strfreev(res); | |
780 | |
781 res = g_strsplit(buf, ":", 0); | |
782 | |
783 close(md->fd); | |
784 | |
1603 | 785 set_login_progress(gc, 3, "Connecting to Auth"); |
1567 | 786 |
787 | |
788 md->status |= MSN_SIGNON_GOT_XFR; | |
789 | |
790 gdk_input_remove(gc->inpa); | |
791 gc->inpa = 0; | |
792 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
793 /* Now we have the host and port */ |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1866
diff
changeset
|
794 md->fd = proxy_connect(res[0], atoi(res[1]), msn_login_callback, gc); |
1866
466fc4ada7cb
[gaim-migrate @ 1876]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1864
diff
changeset
|
795 if (!user->gc || (md->fd < 0)) { |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
796 g_strfreev(res); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
797 hide_login_progress(gc, "Error connecting to server"); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
798 signoff(gc); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
799 return; |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
800 } |
1567 | 801 |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
802 g_strfreev(res); |
1567 | 803 return; |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
804 } else if (!strncmp("USR ", buf, 4)) { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
805 if (md->status & MSN_SIGNON_SENT_USR) { |
1567 | 806 char **res; |
807 | |
808 res = g_strsplit(buf, " ", 0); | |
809 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
810 if (strcasecmp("OK", res[2])) { |
1567 | 811 hide_login_progress(gc, "Error signing on"); |
812 signoff(gc); | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
813 } else { |
1833 | 814 debug_printf("Before: %s\n", res[4]); |
1756 | 815 md->friendly = g_strdup(url_decode(res[4])); |
1833 | 816 debug_printf("After: %s\n", md->friendly); |
1567 | 817 |
818 /* Ok, ok. Your account is FINALLY online. Ya think Microsoft | |
819 * could have had any more steps involved? */ | |
820 | |
821 set_login_progress(gc, 4, "Fetching config"); | |
822 | |
823 /* Sync our buddylist */ | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
824 g_snprintf(buf, MSN_BUF_LEN, "SYN %ld 0\n", trId(md)); |
1567 | 825 msn_write(md->fd, buf); |
826 | |
827 /* And set ourselves online */ | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
828 g_snprintf(buf, MSN_BUF_LEN, "CHG %ld NLN\n", trId(md)); |
1567 | 829 msn_write(md->fd, buf); |
830 | |
831 account_online(gc); | |
832 serv_finish_login(gc); | |
833 | |
834 if (bud_list_cache_exists(gc)) | |
835 do_import(NULL, gc); | |
836 | |
837 gdk_input_remove(gc->inpa); | |
838 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_callback, gc); | |
839 } | |
840 | |
841 g_strfreev(res); | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
842 } else { |
1567 | 843 char **res; |
844 char buf2[MSN_BUF_LEN]; | |
845 md5_state_t st; | |
846 md5_byte_t di[16]; | |
847 | |
848 res = g_strsplit(buf, " ", 0); | |
849 | |
850 /* Make a copy of our MD5 Hash key */ | |
851 strcpy(buf, res[4]); | |
852 | |
853 /* Generate our secret with our key and password */ | |
854 snprintf(buf2, MSN_BUF_LEN, "%s%s", buf, gc->password); | |
855 | |
856 md5_init(&st); | |
857 md5_append(&st, (const md5_byte_t *)buf2, strlen(buf2)); | |
858 md5_finish(&st, di); | |
859 | |
860 /* Now that we have the MD5 Hash, lets' hex encode this bad boy. I smoke bad crack. */ | |
861 sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", | |
862 di[0],di[1],di[2],di[3],di[4],di[5],di[6],di[7],di[8],di[9],di[10],di[11],di[12], | |
863 di[13],di[14],di[15]); | |
864 | |
865 /* And now, send our final sign on packet */ | |
866 g_snprintf(buf2, MSN_BUF_LEN, "USR %s %s S %s\n", res[1], md->policy, buf); | |
867 msn_write(md->fd, buf2); | |
868 | |
869 md->status |= MSN_SIGNON_SENT_USR; | |
870 | |
871 g_strfreev(res); | |
872 } | |
873 | |
874 return; | |
875 } | |
1259 | 876 } |
877 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
878 static void msn_login(struct aim_user *user) |
1282 | 879 { |
1567 | 880 struct gaim_connection *gc = new_gaim_conn(user); |
881 struct msn_data *md = gc->proto_data = g_new0(struct msn_data, 1); | |
1282 | 882 |
1567 | 883 gc->inpa = 0; |
1282 | 884 |
885 set_login_progress(gc, 1, "Connecting"); | |
1259 | 886 |
887 while (gtk_events_pending()) | |
888 gtk_main_iteration(); | |
1567 | 889 |
1259 | 890 if (!g_slist_find(connections, gc)) |
891 return; | |
892 | |
1567 | 893 md->status = 0; |
1282 | 894 |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
895 sprintf(gc->username, "%s", msn_normalize(gc->username)); |
1881
a02584b98823
[gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1866
diff
changeset
|
896 md->fd = proxy_connect("messenger.hotmail.com", 1863, msn_login_callback, gc); |
1866
466fc4ada7cb
[gaim-migrate @ 1876]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1864
diff
changeset
|
897 if (!user->gc || (md->fd < 0)) { |
1567 | 898 hide_login_progress(gc, "Error connecting to server"); |
1259 | 899 signoff(gc); |
900 return; | |
901 } | |
1284 | 902 } |
903 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
904 static void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
1584 | 905 { |
906 struct msn_conn *mc; | |
907 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
908 char buf[MSN_BUF_LEN]; | |
909 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
910 if (!g_strcasecmp(who, gc->username)) { |
1733 | 911 do_error_dialog("You can not send a message to yourself!", "Gaim: MSN Error"); |
1584 | 912 return; |
913 } | |
914 | |
915 mc = find_msn_conn_by_user(who); | |
916 | |
917 /* If we're not already in a conversation with | |
918 * this person then we have to do some tricky things. */ | |
919 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
920 if (!mc) { |
1584 | 921 /* Request a new switchboard connection */ |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
922 g_snprintf(buf, MSN_BUF_LEN, "XFR %ld SB\n", trId(md)); |
1584 | 923 msn_write(md->fd, buf); |
924 | |
925 mc = g_new0(struct msn_conn, 1); | |
926 | |
927 mc->user = g_strdup(who); | |
928 mc->gc = gc; | |
929 mc->last_trid = md->last_trid; | |
930 mc->txqueue = g_strdup(message); | |
931 | |
932 /* Append our connection */ | |
933 msn_connections = g_slist_append(msn_connections, mc); | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
934 } else { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
935 g_snprintf(buf, MSN_BUF_LEN, "MSG %ld N %d\r\n%s%s", trId(md), |
1598 | 936 strlen(message) + strlen(MIME_HEADER), MIME_HEADER, message); |
1585 | 937 |
938 msn_write(mc->fd, buf); | |
939 } | |
1584 | 940 |
941 } | |
942 | |
1598 | 943 static void msn_add_buddy(struct gaim_connection *gc, char *who) |
944 { | |
945 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
946 char buf[MSN_BUF_LEN - 1]; | |
947 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
948 snprintf(buf, MSN_BUF_LEN, "ADD %ld FL %s %s\n", trId(md), who, who); |
1598 | 949 msn_write(md->fd, buf); |
950 } | |
951 | |
952 static void msn_remove_buddy(struct gaim_connection *gc, char *who) | |
953 { | |
954 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
955 char buf[MSN_BUF_LEN - 1]; | |
956 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
957 snprintf(buf, MSN_BUF_LEN, "REM %ld FL %s\n", trId(md), who); |
1598 | 958 msn_write(md->fd, buf); |
959 } | |
960 | |
961 static void msn_rem_permit(struct gaim_connection *gc, char *who) | |
962 { | |
963 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
964 char buf[MSN_BUF_LEN - 1]; | |
965 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
966 snprintf(buf, MSN_BUF_LEN, "REM %ld AL %s\n", trId(md), who); |
1598 | 967 msn_write(md->fd, buf); |
968 } | |
969 | |
970 static void msn_add_permit(struct gaim_connection *gc, char *who) | |
971 { | |
972 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
973 char buf[MSN_BUF_LEN - 1]; | |
974 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
975 snprintf(buf, MSN_BUF_LEN, "ADD %ld AL %s %s\n", trId(md), who, who); |
1598 | 976 msn_write(md->fd, buf); |
977 } | |
978 | |
979 static void msn_rem_deny(struct gaim_connection *gc, char *who) | |
980 { | |
981 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
982 char buf[MSN_BUF_LEN - 1]; | |
983 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
984 snprintf(buf, MSN_BUF_LEN, "REM %ld BL %s\n", trId(md), who); |
1598 | 985 msn_write(md->fd, buf); |
986 } | |
987 | |
988 static void msn_add_deny(struct gaim_connection *gc, char *who) | |
989 { | |
990 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
991 char buf[MSN_BUF_LEN - 1]; | |
992 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
993 snprintf(buf, MSN_BUF_LEN, "ADD %ld BL %s %s\n", trId(md), who, who); |
1598 | 994 msn_write(md->fd, buf); |
995 } | |
996 | |
1630 | 997 static GList *msn_away_states() |
998 { | |
999 GList *m = NULL; | |
1000 | |
1001 m = g_list_append(m, "Available"); | |
1002 m = g_list_append(m, "Away From Computer"); | |
1003 m = g_list_append(m, "Be Right Back"); | |
1004 m = g_list_append(m, "Busy"); | |
1005 m = g_list_append(m, "On The Phone"); | |
1006 m = g_list_append(m, "Out To Lunch"); | |
1007 | |
1008 return m; | |
1009 } | |
1010 | |
1600 | 1011 static void msn_set_away(struct gaim_connection *gc, char *state, char *msg) |
1012 { | |
1013 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
1014 char buf[MSN_BUF_LEN - 1]; | |
1015 | |
1630 | 1016 |
1017 gc->away = NULL; | |
1018 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1019 if (msg) { |
1630 | 1020 gc->away = ""; |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1021 snprintf(buf, MSN_BUF_LEN, "CHG %ld AWY\n", trId(md)); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1022 } else if (state) { |
1630 | 1023 char away[4]; |
1024 | |
1025 gc->away = ""; | |
1026 | |
1027 if (!strcmp(state, "Available")) | |
1028 sprintf(away, "NLN"); | |
1029 else if (!strcmp(state, "Away From Computer")) | |
1030 sprintf(away, "AWY"); | |
1031 else if (!strcmp(state, "Be Right Back")) | |
1032 sprintf(away, "BRB"); | |
1033 else if (!strcmp(state, "Busy")) | |
1034 sprintf(away, "BSY"); | |
1035 else if (!strcmp(state, "On The Phone")) | |
1036 sprintf(away, "PHN"); | |
1037 else if (!strcmp(state, "Out To Lunch")) | |
1038 sprintf(away, "LUN"); | |
1039 else | |
1040 sprintf(away, "NLN"); | |
1041 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1042 snprintf(buf, MSN_BUF_LEN, "CHG %ld %s\n", trId(md), away); |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1043 } else if (gc->is_idle) |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1044 snprintf(buf, MSN_BUF_LEN, "CHG %ld IDL\n", trId(md)); |
1600 | 1045 else |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1046 snprintf(buf, MSN_BUF_LEN, "CHG %ld NLN\n", trId(md)); |
1600 | 1047 |
1048 msn_write(md->fd, buf); | |
1049 } | |
1050 | |
1051 | |
1052 static void msn_set_idle(struct gaim_connection *gc, int idle) | |
1053 { | |
1054 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
1055 char buf[MSN_BUF_LEN - 1]; | |
1056 | |
1057 if (idle) | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1058 snprintf(buf, MSN_BUF_LEN, "CHG %ld IDL\n", trId(md)); |
1600 | 1059 else |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1060 snprintf(buf, MSN_BUF_LEN, "CHG %ld NLN\n", trId(md)); |
1600 | 1061 |
1062 msn_write(md->fd, buf); | |
1063 } | |
1064 | |
1065 static void msn_close(struct gaim_connection *gc) | |
1066 { | |
1067 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
1068 char buf[MSN_BUF_LEN - 1]; | |
1069 struct msn_conn *mc = NULL; | |
1070 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1071 while (msn_connections) { |
1600 | 1072 mc = (struct msn_conn *)msn_connections->data; |
1073 | |
1074 free_msn_conn(mc); | |
1075 } | |
1076 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1077 if (md->fd) { |
1600 | 1078 snprintf(buf, MSN_BUF_LEN, "OUT\n"); |
1079 msn_write(md->fd, buf); | |
1080 close(md->fd); | |
1081 } | |
1082 | |
1083 if (gc->inpa) | |
1084 gdk_input_remove(gc->inpa); | |
1085 | |
1086 if (md->friendly) | |
1087 free(md->friendly); | |
1088 | |
1089 g_free(gc->proto_data); | |
1090 } | |
1091 | |
1639 | 1092 static char *msn_get_away_text(int s) |
1093 { | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1094 switch (s) { |
1639 | 1095 case MSN_BUSY : |
1096 return "Busy"; | |
1097 case MSN_BRB : | |
1098 return "Be right back"; | |
1099 case MSN_AWAY : | |
1100 return "Away from the computer"; | |
1101 case MSN_PHONE : | |
1102 return "On the phone"; | |
1103 case MSN_LUNCH : | |
1104 return "Out to lunch"; | |
1640 | 1105 case MSN_IDLE : |
1106 return "Idle"; | |
1639 | 1107 default: |
1108 return NULL; | |
1109 } | |
1110 } | |
1111 | |
1112 static void msn_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) | |
1113 { | |
1114 struct buddy *b = find_buddy(gc, who); | |
1115 char buf[MSN_BUF_LEN]; | |
1116 GtkWidget *button; | |
1117 | |
1118 if (!(b->uc >> 5)) | |
1119 return; | |
1120 | |
1121 g_snprintf(buf, MSN_BUF_LEN, "Status: %s", msn_get_away_text(b->uc >> 5)); | |
1122 | |
1123 button = gtk_menu_item_new_with_label(buf); | |
1124 gtk_menu_append(GTK_MENU(menu), button); | |
1125 gtk_widget_show(button); | |
1126 } | |
1127 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1128 static void msn_newmail_dialog(const char *text) |
1717 | 1129 { |
1130 GtkWidget *window; | |
1131 GtkWidget *vbox; | |
1132 GtkWidget *label; | |
1133 GtkWidget *hbox; | |
1134 GtkWidget *button; | |
1135 | |
1136 window = gtk_window_new(GTK_WINDOW_DIALOG); | |
1137 gtk_window_set_wmclass(GTK_WINDOW(window), "prompt", "Gaim"); | |
1138 gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE); | |
1139 gtk_window_set_title(GTK_WINDOW(window), _("Gaim-MSN: New Mail")); | |
1140 gtk_widget_realize(window); | |
1141 aol_icon(window->window); | |
1142 | |
1143 vbox = gtk_vbox_new(FALSE, 5); | |
1144 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | |
1145 gtk_container_add(GTK_CONTAINER(window), vbox); | |
1146 | |
1147 label = gtk_label_new(text); | |
1148 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | |
1149 | |
1150 hbox = gtk_hbox_new(FALSE, 5); | |
1151 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1152 | |
1153 button = picture_button(window, _("OK"), ok_xpm); | |
1154 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1155 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(msn_des_win), window); | |
1156 | |
1157 gtk_widget_show_all(window); | |
1158 } | |
1159 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1160 static void msn_des_win(GtkWidget *a, GtkWidget *b) |
1717 | 1161 { |
1162 gtk_widget_destroy(b); | |
1163 } | |
1164 | |
1165 static void mod_opt(GtkWidget *b, struct mod_usr_opt *m) | |
1166 { | |
1167 if (m->user) { | |
1168 if (m->user->proto_opt[m->opt][0] == '1') | |
1169 m->user->proto_opt[m->opt][0] = '\0'; | |
1170 else | |
1171 strcpy(m->user->proto_opt[m->opt],"1"); | |
1172 } | |
1173 } | |
1174 | |
1175 static void free_muo(GtkWidget *b, struct mod_usr_opt *m) | |
1176 { | |
1177 g_free(m); | |
1178 } | |
1179 | |
1180 static GtkWidget *msn_protoopt_button(const char *text, struct aim_user *u, int option, GtkWidget *box) | |
1181 { | |
1182 GtkWidget *button; | |
1183 struct mod_usr_opt *muo = g_new0(struct mod_usr_opt, 1); | |
1184 button = gtk_check_button_new_with_label(text); | |
1185 if (u) { | |
1186 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (u->proto_opt[option][0] == '1')); | |
1187 } | |
1188 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0); | |
1189 muo->user = u; | |
1190 muo->opt = option; | |
1191 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(mod_opt), muo); | |
1192 gtk_signal_connect(GTK_OBJECT(button), "destroy", GTK_SIGNAL_FUNC(free_muo), muo); | |
1193 gtk_widget_show(button); | |
1194 return button; | |
1195 } | |
1196 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1197 static void msn_user_opts(GtkWidget* book, struct aim_user *user) |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1198 { |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1199 /* so here, we create the new notebook page */ |
1717 | 1200 GtkWidget *vbox; |
1201 | |
1202 vbox = gtk_vbox_new(FALSE, 5); | |
1203 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1204 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("MSN Options")); |
1717 | 1205 gtk_widget_show(vbox); |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1206 |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1207 msn_protoopt_button("Notify me of new HotMail",user,USEROPT_HOTMAIL,vbox); |
1717 | 1208 } |
1209 | |
1210 /* | |
1211 Process messages from Hotmail service. right now we just check for new | |
1212 mail notifications, if the user has checking enabled. | |
1213 */ | |
1214 | |
1215 static void process_hotmail_msg(struct gaim_connection *gc, gchar *msgdata) | |
1216 { | |
1217 gchar *mailnotice; | |
1218 char *mailfrom,*mailsubj,*mailct,*mailp; | |
1219 | |
1220 if (gc->user->proto_opt[USEROPT_HOTMAIL][0] != '1') return; | |
1221 mailfrom=NULL; mailsubj=NULL; mailct=NULL; mailp=NULL; | |
1222 mailct = strstr(msgdata,"Content-Type: "); | |
1223 mailp = strstr(mailct,";"); | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1224 if ((mailct != NULL) && (mailp != NULL) && (mailp > mailct) && |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1225 !strncmp(mailct,"Content-Type: text/x-msmsgsemailnotification",(mailp-mailct)-1)) { |
1717 | 1226 mailfrom=strstr(mailp,"From: "); |
1227 mailsubj=strstr(mailp,"Subject: "); | |
1228 } | |
1229 | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1230 if (mailfrom != NULL && mailsubj != NULL) { |
1717 | 1231 mailfrom += 6; |
1232 mailp=strstr(mailfrom,"\r\n"); | |
1233 if (mailp==NULL) return; | |
1234 *mailp = 0; | |
1235 mailsubj += 9; | |
1236 mailp=strstr(mailsubj,"\r\n"); | |
1237 if (mailp==NULL) return; | |
1238 *mailp = 0; | |
1239 mailnotice = (gchar *)g_malloc(sizeof(gchar) *(strlen(mailfrom)+strlen(mailsubj)+128)); | |
1240 sprintf(mailnotice,"Mail from %s, re: %s",mailfrom,mailsubj); | |
1241 msn_newmail_dialog(mailnotice); | |
1242 g_free(mailnotice); | |
1243 } | |
1244 } | |
1245 | |
1756 | 1246 static char *msn_normalize(const char *s) |
1247 { | |
1248 static char buf[BUF_LEN]; | |
1249 char *t, *u; | |
1250 int x = 0; | |
1251 | |
1252 g_return_val_if_fail((s != NULL), NULL); | |
1253 | |
1254 u = t = g_strdup(s); | |
1255 | |
1256 g_strdown(t); | |
1257 | |
1258 while (*t && (x < BUF_LEN - 1)) { | |
1259 if (*t != ' ') | |
1260 buf[x++] = *t; | |
1261 t++; | |
1262 } | |
1263 buf[x] = '\0'; | |
1264 g_free(u); | |
1265 | |
1266 if (!strchr(buf, '@')) { | |
1851
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1267 strcat(buf, "@hotmail.com"); /* if they don't specify something, it will be hotmail.com. |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1268 msn.com is valid too, but hey, if they wanna use it, |
97a097e00139
[gaim-migrate @ 1861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1833
diff
changeset
|
1269 they gotta enter it themselves. */ |
1756 | 1270 } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) { |
1271 *u = '\0'; | |
1272 } | |
1273 | |
1274 return buf; | |
1275 } | |
1276 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1277 static void do_change_name(GtkWidget *w, struct msn_name_dlg *b) |
1833 | 1278 { |
1279 struct gaim_connection *gc = b->user->gc; | |
1280 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
1281 char buf[MSN_BUF_LEN - 1]; | |
1282 gchar *newname; | |
1283 | |
1284 newname = gtk_entry_get_text(GTK_ENTRY(b->entry)); | |
1285 | |
1286 snprintf(buf, MSN_BUF_LEN, "REA %ld %s %s\n", trId(md), gc->username, newname); | |
1287 | |
1288 msn_write(md->fd, buf); | |
1289 | |
1290 msn_des_win(NULL, b->window); | |
1291 | |
1292 return; | |
1293 } | |
1294 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1295 static void show_change_name(struct gaim_connection *gc) |
1833 | 1296 { |
1297 GtkWidget *label; | |
1298 GtkWidget *vbox; | |
1299 GtkWidget *buttons; | |
1300 GtkWidget *hbox; | |
1301 struct aim_user *tmp; | |
1302 gchar *buf; | |
1303 struct msn_data *md; | |
1304 | |
1305 struct msn_name_dlg *b = g_new0(struct msn_name_dlg, 1); | |
1306 if (!g_slist_find(connections, gc)) | |
1307 gc = connections->data; | |
1308 | |
1309 tmp = gc->user; | |
1310 b->user = tmp; | |
1311 | |
1312 md = (struct msn_data *)gc->proto_data; | |
1313 | |
1314 b->window = gtk_window_new(GTK_WINDOW_DIALOG); | |
1315 gtk_window_set_wmclass(GTK_WINDOW(b->window), "msn_change_name", "Gaim"); | |
1316 | |
1317 gtk_window_set_title(GTK_WINDOW(b->window), _("Gaim - Change MSN Name")); | |
1318 gtk_signal_connect(GTK_OBJECT(b->window), "destroy", GTK_SIGNAL_FUNC(msn_des_win), b->window); | |
1319 gtk_widget_realize(b->window); | |
1320 aol_icon(b->window->window); | |
1321 | |
1322 vbox = gtk_vbox_new(FALSE, 5); | |
1323 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | |
1324 gtk_container_add(GTK_CONTAINER(b->window), vbox); | |
1325 gtk_widget_show(vbox); | |
1326 | |
1327 hbox = gtk_hbox_new(FALSE, 5); | |
1328 gtk_container_set_border_width(GTK_CONTAINER(hbox), 5); | |
1329 gtk_widget_show(hbox); | |
1330 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
1331 | |
1332 buf = g_malloc(256); | |
1333 g_snprintf(buf, 256, "New name for %s (%s):", tmp->username, md->friendly); | |
1334 label = gtk_label_new(buf); | |
1335 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
1336 gtk_widget_show(label); | |
1337 g_free(buf); | |
1338 | |
1339 b->entry = gtk_entry_new(); | |
1340 gtk_box_pack_start(GTK_BOX(hbox), b->entry, FALSE, FALSE, 5); | |
1341 gtk_widget_show(b->entry); | |
1342 | |
1343 buttons = gtk_hbox_new(FALSE, 5); | |
1344 gtk_box_pack_start(GTK_BOX(vbox), buttons, FALSE, FALSE, 0); | |
1345 gtk_widget_show(buttons); | |
1346 | |
1347 b->cancel = picture_button(b->window, _("Cancel"), cancel_xpm); | |
1348 gtk_box_pack_end(GTK_BOX(buttons), b->cancel, FALSE, FALSE, 0); | |
1349 gtk_signal_connect(GTK_OBJECT(b->cancel), "clicked", GTK_SIGNAL_FUNC(msn_des_win), b->window); | |
1350 | |
1351 b->ok = picture_button(b->window, _("Ok"), ok_xpm); | |
1352 gtk_box_pack_end(GTK_BOX(buttons), b->ok, FALSE, FALSE, 0); | |
1353 gtk_signal_connect(GTK_OBJECT(b->ok), "clicked", GTK_SIGNAL_FUNC(do_change_name), b); | |
1354 | |
1355 | |
1356 gtk_widget_show(b->window); | |
1357 | |
1358 | |
1359 } | |
1360 | |
1361 static void msn_do_action(struct gaim_connection *gc, char *act) | |
1362 { | |
1363 if (!strcmp(act, "Change Name")) | |
1364 show_change_name(gc); | |
1365 } | |
1366 | |
1367 static GList *msn_actions() | |
1368 { | |
1369 GList *m = NULL; | |
1370 | |
1371 m = g_list_append(m, "Change Name"); | |
1372 | |
1373 return m; | |
1374 } | |
1756 | 1375 |
1572 | 1376 static char **msn_list_icon(int uc) |
1377 { | |
1378 if (uc == UC_UNAVAILABLE) | |
1379 return msn_away_xpm; | |
1380 else if (uc == UC_NORMAL) | |
1381 return msn_online_xpm; | |
1382 | |
1631 | 1383 return msn_away_xpm; |
1572 | 1384 } |
1385 | |
1259 | 1386 static struct prpl *my_protocol = NULL; |
1387 | |
1891
1c977d995da9
[gaim-migrate @ 1901]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1388 static void msn_init(struct prpl *ret) |
1282 | 1389 { |
1259 | 1390 ret->protocol = PROTO_MSN; |
1391 ret->name = msn_name; | |
1572 | 1392 ret->list_icon = msn_list_icon; |
1639 | 1393 ret->buddy_menu = msn_buddy_menu; |
1717 | 1394 ret->user_opts = msn_user_opts; |
1259 | 1395 ret->login = msn_login; |
1600 | 1396 ret->close = msn_close; |
1584 | 1397 ret->send_im = msn_send_im; |
1259 | 1398 ret->set_info = NULL; |
1399 ret->get_info = NULL; | |
1630 | 1400 ret->away_states = msn_away_states; |
1600 | 1401 ret->set_away = msn_set_away; |
1259 | 1402 ret->get_away_msg = NULL; |
1403 ret->set_dir = NULL; | |
1404 ret->get_dir = NULL; | |
1405 ret->dir_search = NULL; | |
1600 | 1406 ret->set_idle = msn_set_idle; |
1259 | 1407 ret->change_passwd = NULL; |
1598 | 1408 ret->add_buddy = msn_add_buddy; |
1259 | 1409 ret->add_buddies = NULL; |
1598 | 1410 ret->remove_buddy = msn_remove_buddy; |
1411 ret->add_permit = msn_add_permit; | |
1412 ret->rem_permit = msn_rem_permit; | |
1413 ret->add_deny = msn_add_deny; | |
1414 ret->rem_deny = msn_rem_deny; | |
1259 | 1415 ret->warn = NULL; |
1416 ret->accept_chat = NULL; | |
1417 ret->join_chat = NULL; | |
1418 ret->chat_invite = NULL; | |
1419 ret->chat_leave = NULL; | |
1420 ret->chat_whisper = NULL; | |
1421 ret->chat_send = NULL; | |
1422 ret->keepalive = NULL; | |
1833 | 1423 ret->actions = msn_actions; |
1424 ret->do_action = msn_do_action; | |
1756 | 1425 ret->normalize = msn_normalize; |
1259 | 1426 |
1427 my_protocol = ret; | |
1428 } | |
1429 | |
1282 | 1430 char *gaim_plugin_init(GModule * handle) |
1431 { | |
1443
336fc98b7f90
[gaim-migrate @ 1453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1327
diff
changeset
|
1432 load_protocol(msn_init, sizeof(struct prpl)); |
1259 | 1433 return NULL; |
1434 } | |
1435 | |
1282 | 1436 void gaim_plugin_remove() |
1437 { | |
1259 | 1438 struct prpl *p = find_prpl(PROTO_MSN); |
1439 if (p == my_protocol) | |
1440 unload_protocol(p); | |
1441 } |