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
|
|
22 #include "../config.h"
|
|
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>
|
|
34 #include <sys/socket.h>
|
|
35 #include <sys/stat.h>
|
|
36 #include "multi.h"
|
|
37 #include "prpl.h"
|
|
38 #include "gaim.h"
|
|
39 #include "md5.h"
|
|
40
|
1284
|
41 #include "pixmaps/msn_online.xpm"
|
|
42
|
1259
|
43 #define MSN_BUF_LEN 4096
|
|
44
|
1277
|
45 #define MSN_OPT_SERVER 0
|
|
46 #define MSN_OPT_PORT 1
|
|
47
|
1259
|
48 #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"
|
|
49
|
|
50 #define MSN_ONLINE 1
|
|
51 #define MSN_BUSY 2
|
|
52 #define MSN_IDLE 3
|
|
53 #define MSN_BRB 4
|
|
54 #define MSN_AWAY 5
|
|
55 #define MSN_PHONE 6
|
|
56 #define MSN_LUNCH 7
|
|
57 #define MSN_OFFLINE 8
|
|
58 #define MSN_HIDDEN 9
|
|
59
|
|
60
|
|
61 struct msn_ask_add_permit {
|
|
62 struct gaim_connection *gc;
|
|
63 char *user;
|
|
64 char *friendly;
|
|
65 };
|
|
66
|
|
67 struct msn_data {
|
|
68 int fd;
|
|
69
|
|
70 char protocol[6];
|
|
71 char *friendly;
|
|
72 gchar *policy;
|
|
73 };
|
|
74
|
|
75 struct msn_conn {
|
|
76 gchar *user;
|
|
77 int inpa;
|
|
78 int fd;
|
|
79 };
|
|
80
|
1283
|
81 void msn_callback(gpointer data, gint fd, GdkInputCondition condition);
|
1259
|
82
|
1282
|
83 GSList *msn_connections = NULL;
|
1259
|
84
|
1282
|
85 static char *msn_name()
|
|
86 {
|
1259
|
87 return "MSN";
|
|
88 }
|
|
89
|
1282
|
90 char *name()
|
|
91 {
|
1259
|
92 return "MSN";
|
|
93 }
|
|
94
|
1282
|
95 char *description()
|
|
96 {
|
1259
|
97 return "Allows gaim to use the MSN protocol. For some reason, this frightens me.";
|
|
98 }
|
|
99
|
1282
|
100 struct msn_conn *find_msn_conn_by_user(gchar * user)
|
|
101 {
|
1259
|
102 struct msn_conn *mc;
|
|
103 GSList *conns = msn_connections;
|
|
104
|
|
105 while (conns) {
|
|
106 mc = (struct msn_conn *)conns->data;
|
|
107
|
|
108 if (mc != NULL) {
|
|
109 if (strcasecmp(mc->user, user) == 0) {
|
|
110 return mc;
|
|
111 }
|
|
112 }
|
|
113
|
|
114 conns = g_slist_next(conns);
|
|
115 }
|
|
116
|
|
117 return NULL;
|
|
118 }
|
|
119
|
1282
|
120 void msn_read_line(char *buf, int fd)
|
|
121 {
|
1259
|
122
|
|
123 int status;
|
|
124 char c;
|
|
125 int i = 0;
|
1282
|
126
|
1259
|
127 do {
|
|
128 status = recv(fd, &c, 1, 0);
|
|
129
|
|
130 if (!status)
|
|
131 return;
|
|
132
|
|
133 buf[i] = c;
|
|
134 i++;
|
|
135 } while (c != '\n');
|
|
136
|
|
137 buf[i] = '\0';
|
|
138 g_strchomp(buf);
|
|
139
|
|
140 /* I'm a bastard again :-) */
|
|
141 printf("MSN: %s\n", buf);
|
|
142 }
|
|
143
|
1282
|
144 int msn_connect(char *server, int port)
|
|
145 {
|
1259
|
146 int fd;
|
|
147 struct hostent *host;
|
|
148 struct sockaddr_in site;
|
|
149
|
|
150 printf("Connecting to '%s' on '%d'\n", server, port);
|
|
151 host = gethostbyname(server);
|
|
152 if (!host) {
|
|
153 return -1;
|
|
154 }
|
|
155
|
|
156 site.sin_family = AF_INET;
|
|
157 site.sin_addr.s_addr = *(long *)(host->h_addr);
|
|
158 site.sin_port = htons(port);
|
|
159
|
|
160 fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
161 if (fd < 0) {
|
|
162 return -1;
|
|
163 }
|
|
164
|
|
165 if (connect(fd, (struct sockaddr *)&site, sizeof(site)) < 0) {
|
|
166 return -1;
|
|
167 }
|
|
168
|
|
169 return fd;
|
|
170 }
|
|
171
|
1282
|
172 static void msn_add_buddy(struct gaim_connection *gc, char *who)
|
|
173 {
|
1259
|
174 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
1282
|
175 time_t trId = time((time_t *) NULL);
|
1259
|
176 gchar buf[4096];
|
|
177
|
|
178 g_snprintf(buf, 4096, "ADD %d FL %s %s\n", trId, who, who);
|
|
179 write(mdata->fd, buf, strlen(buf));
|
|
180 }
|
|
181
|
1282
|
182 static void msn_rem_permit(struct gaim_connection *gc, char *who)
|
|
183 {
|
1259
|
184 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
1282
|
185 time_t trId = time((time_t *) NULL);
|
1259
|
186 gchar buf[4096];
|
|
187
|
|
188 g_snprintf(buf, 4096, "REM %d AL %s %s\n", trId, who, who);
|
|
189 write(mdata->fd, buf, strlen(buf));
|
|
190 }
|
|
191
|
1282
|
192 static void msn_add_permit(struct gaim_connection *gc, char *who)
|
|
193 {
|
1259
|
194 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
1282
|
195 time_t trId = time((time_t *) NULL);
|
1259
|
196 gchar buf[4096];
|
|
197
|
|
198 g_snprintf(buf, 4096, "ADD %d AL %s %s\n", trId, who, who);
|
|
199 write(mdata->fd, buf, strlen(buf));
|
|
200 }
|
|
201
|
1282
|
202 static void msn_rem_deny(struct gaim_connection *gc, char *who)
|
|
203 {
|
1277
|
204 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
1282
|
205 time_t trId = time((time_t *) NULL);
|
1277
|
206 gchar buf[4096];
|
|
207
|
|
208 g_snprintf(buf, 4096, "REM %d BL %s %s\n", trId, who, who);
|
|
209 write(mdata->fd, buf, strlen(buf));
|
|
210 }
|
|
211
|
1282
|
212 static void msn_add_deny(struct gaim_connection *gc, char *who)
|
|
213 {
|
1277
|
214 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
1282
|
215 time_t trId = time((time_t *) NULL);
|
1277
|
216 gchar buf[4096];
|
|
217
|
|
218 g_snprintf(buf, 4096, "ADD %d BL %s %s\n", trId, who, who);
|
|
219 write(mdata->fd, buf, strlen(buf));
|
|
220 }
|
|
221
|
1282
|
222 static void msn_remove_buddy(struct gaim_connection *gc, char *who)
|
|
223 {
|
1259
|
224 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
1282
|
225 time_t trId = time((time_t *) NULL);
|
1259
|
226 gchar buf[4096];
|
|
227
|
|
228 g_snprintf(buf, 4096, "REM %d FL %s\n", trId, who);
|
|
229 write(mdata->fd, buf, strlen(buf));
|
|
230 }
|
|
231
|
1282
|
232 void msn_accept_add_permit(gpointer w, struct msn_ask_add_permit *ap)
|
|
233 {
|
1259
|
234 gchar buf[4096];
|
|
235
|
|
236 msn_add_permit(ap->gc, ap->user);
|
|
237 }
|
|
238
|
1282
|
239 void msn_cancel_add_permit(gpointer w, struct msn_ask_add_permit *ap)
|
|
240 {
|
|
241
|
1259
|
242 g_free(ap->user);
|
|
243 g_free(ap->friendly);
|
|
244 g_free(ap);
|
|
245 }
|
|
246
|
1283
|
247 void msn_callback(gpointer data, gint fd, GdkInputCondition condition)
|
1282
|
248 {
|
1283
|
249 struct gaim_connection *gc = data;
|
1259
|
250 struct msn_data *mdata;
|
|
251 char c;
|
|
252 int i = 0;
|
|
253 int status;
|
|
254 gchar buf[4096];
|
|
255 gchar **resps;
|
1282
|
256
|
1259
|
257 mdata = (struct msn_data *)gc->proto_data;
|
|
258
|
|
259 do {
|
|
260 /* Read data from whatever connection our inpa
|
|
261 * refered us from */
|
1282
|
262 status = recv(fd, &c, 1, 0);
|
1259
|
263
|
|
264 if (!status)
|
|
265 return;
|
|
266
|
|
267 buf[i] = c;
|
1282
|
268 i++;
|
1259
|
269 } while (c != '\n');
|
|
270
|
|
271 buf[i] = '\0';
|
|
272
|
|
273 g_strchomp(buf);
|
|
274
|
|
275 printf("MSN: %s\n", buf);
|
|
276
|
1282
|
277 if (strlen(buf) == 0) {
|
|
278 return;
|
|
279 }
|
|
280
|
1259
|
281 resps = g_strsplit(buf, " ", 0);
|
|
282
|
|
283 /* See if someone is bumping us */
|
|
284 if (strcasecmp(resps[0], "BYE") == 0) {
|
|
285 struct msn_conn *mc;
|
1282
|
286 GSList *conns = msn_connections;
|
|
287
|
1259
|
288 /* Yup. Let's find their convo and kill it */
|
|
289
|
|
290 mc = find_msn_conn_by_user(resps[1]);
|
|
291
|
|
292 /* If we have the convo, remove it */
|
|
293 if (mc != NULL) {
|
|
294 /* and remove it */
|
|
295 conns = g_slist_remove(conns, mc);
|
|
296
|
|
297 g_free(mc->user);
|
|
298 gdk_input_remove(mc->inpa);
|
|
299 close(mc->fd);
|
|
300
|
|
301
|
|
302 g_free(mc);
|
|
303 }
|
|
304
|
|
305 g_strfreev(resps);
|
|
306 return;
|
|
307 }
|
|
308
|
|
309 if (strcasecmp(resps[0], "ADD") == 0) {
|
1282
|
310
|
1259
|
311 if (strcasecmp(resps[2], "RL") == 0) {
|
|
312 gchar buf[4096];
|
|
313 struct msn_ask_add_permit *ap = g_new0(struct msn_ask_add_permit, 1);
|
1282
|
314
|
|
315 g_snprintf(buf, 4096, "The user %s (%s) wants to add you to their buddylist.",
|
|
316 resps[4], resps[5]);
|
1259
|
317
|
|
318 ap->user = g_strdup(resps[4]);
|
|
319 ap->friendly = g_strdup(resps[5]);
|
|
320 ap->gc = gc;
|
|
321
|
1282
|
322 do_ask_dialog(buf, ap, (GtkFunction) msn_accept_add_permit,
|
|
323 (GtkFunction) msn_cancel_add_permit);
|
1259
|
324 }
|
|
325
|
|
326 g_strfreev(resps);
|
|
327 return;
|
|
328 }
|
|
329
|
|
330 if (strcasecmp(resps[0], "REM") == 0) {
|
1282
|
331
|
1259
|
332 if (strcasecmp(resps[2], "RL") == 0) {
|
|
333 msn_rem_permit(gc, resps[4]);
|
|
334 }
|
|
335
|
|
336 g_strfreev(resps);
|
|
337 return;
|
|
338 }
|
1282
|
339
|
1259
|
340 if (strcasecmp(resps[0], "FLN") == 0) {
|
|
341 serv_got_update(gc, resps[1], 0, 0, 0, 0, MSN_OFFLINE, 0);
|
|
342 }
|
|
343
|
|
344 if (strcasecmp(resps[0], "ILN") == 0) {
|
|
345 int status;
|
|
346
|
|
347 if (!strcasecmp(resps[2], "NLN"))
|
|
348 status = MSN_ONLINE;
|
|
349 else if (!strcasecmp(resps[2], "BSY"))
|
|
350 status = MSN_BUSY;
|
|
351 else if (!strcasecmp(resps[2], "IDL"))
|
|
352 status = MSN_IDLE;
|
|
353 else if (!strcasecmp(resps[2], "BRB"))
|
|
354 status = MSN_BRB;
|
|
355 else if (!strcasecmp(resps[2], "AWY"))
|
|
356 status = MSN_AWAY;
|
|
357 else if (!strcasecmp(resps[2], "PHN"))
|
|
358 status = MSN_PHONE;
|
|
359 else if (!strcasecmp(resps[2], "LUN"))
|
|
360 status = MSN_LUNCH;
|
|
361 else
|
|
362 status = MSN_ONLINE;
|
|
363
|
|
364 serv_got_update(gc, resps[3], 1, 0, 0, 0, status, 0);
|
|
365
|
|
366 g_strfreev(resps);
|
|
367 return;
|
1282
|
368
|
1259
|
369 }
|
1282
|
370
|
1259
|
371 /* Check buddy update status */
|
1282
|
372 if (strcasecmp(resps[0], "NLN") == 0) {
|
1259
|
373 /* FIXME: We currently dont care if they are busy,
|
|
374 * idle, brb, away, phone, our out to lunch. This will
|
|
375 * be supported eventually (BSY,IDL,BRB,AWY,PHN,LUN)
|
|
376 * respectively */
|
|
377
|
|
378 serv_got_update(gc, resps[2], 1, 0, 0, 0, MSN_ONLINE, 0);
|
|
379 }
|
1282
|
380
|
1259
|
381 /* Check to see if we have an incoming buddylist */
|
1282
|
382 if (strcasecmp(resps[0], "LST") == 0) {
|
1259
|
383 /* Check to see if there are any buddies in the list */
|
|
384 if (atoi(resps[5]) == 0) {
|
|
385 /* No buddies */
|
|
386 g_strfreev(resps);
|
|
387 return;
|
|
388 }
|
|
389
|
|
390 /* FIXME: We should support the permit and deny
|
|
391 * lists as well */
|
|
392
|
|
393 if (strcasecmp(resps[2], "FL") == 0) {
|
|
394 struct buddy *b;
|
|
395
|
|
396 b = find_buddy(gc, resps[6]);
|
|
397
|
|
398 if (!b)
|
|
399 add_buddy(gc, "Buddies", resps[6], resps[6]);
|
|
400 }
|
1282
|
401
|
1259
|
402 g_strfreev(resps);
|
|
403 return;
|
|
404 }
|
1282
|
405
|
1259
|
406 /* Check to see if we got a message request */
|
|
407 if (strcasecmp(resps[0], "MSG") == 0) {
|
|
408 gchar *message;
|
|
409 gchar *buf2;
|
|
410 int size;
|
|
411 int status;
|
1282
|
412
|
1275
|
413 if (strcasecmp("hotmail", resps[1]) == 0) {
|
1276
|
414 /* We want to ignore these. We can parse them
|
|
415 * eventually if we ever plan on doing anything
|
|
416 * with them */
|
1275
|
417 g_strfreev(resps);
|
|
418 return;
|
|
419 }
|
1282
|
420
|
1259
|
421 /* Determine our message size */
|
|
422 size = atoi(resps[3]);
|
|
423
|
1282
|
424 buf2 = (gchar *) g_malloc(sizeof(gchar) * (size + 1));
|
1259
|
425 status = recv(fd, buf2, size, 0);
|
|
426 buf2[size] = 0;
|
|
427
|
|
428 /* Looks like we got the message. If it's blank, let's bail */
|
1282
|
429 if (strcasecmp(strstr(buf2, "\r\n\r\n") + 4, "\r\n") == 0) {
|
1259
|
430 g_free(buf2);
|
|
431 g_strfreev(resps);
|
|
432 return;
|
|
433 }
|
|
434
|
1282
|
435 serv_got_im(gc, resps[1], strstr(buf2, "\r\n\r\n") + 4, 0);
|
1259
|
436
|
|
437 g_free(buf2);
|
|
438 g_strfreev(resps);
|
|
439 return;
|
|
440 }
|
1282
|
441
|
1259
|
442
|
|
443 /* Check to see if we got a ring request */
|
|
444 if (strcasecmp(resps[0], "RNG") == 0) {
|
|
445 gchar **address;
|
|
446 struct msn_conn *mc = g_new0(struct msn_conn, 1);
|
|
447
|
|
448 address = g_strsplit(resps[2], ":", 0);
|
|
449
|
|
450 if (!(mc->fd = msn_connect(address[0], atoi(address[1])))) {
|
|
451 do_error_dialog(resps[5], "Msg Err from");
|
|
452 g_strfreev(address);
|
|
453 g_strfreev(resps);
|
|
454 g_free(mc);
|
|
455 return;
|
|
456 }
|
|
457
|
|
458 mc->user = g_strdup(resps[5]);
|
|
459
|
1283
|
460 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, gc);
|
1282
|
461
|
1259
|
462 g_snprintf(buf, 4096, "ANS 1 %s %s %s\n", gc->username, resps[4], resps[1]);
|
|
463 write(mc->fd, buf, strlen(buf));
|
|
464
|
|
465 msn_connections = g_slist_append(msn_connections, mc);
|
|
466
|
|
467 g_strfreev(address);
|
|
468 g_strfreev(resps);
|
|
469 return;
|
|
470 }
|
|
471
|
|
472 g_strfreev(resps);
|
|
473
|
|
474 }
|
|
475
|
1282
|
476 void msn_login(struct aim_user *user)
|
|
477 {
|
|
478 time_t trId = time((time_t *) NULL);
|
1259
|
479 char buf[4096];
|
|
480 char buf2[4096];
|
1282
|
481
|
1259
|
482 struct gaim_connection *gc = new_gaim_conn(user);
|
|
483 struct msn_data *mdata = gc->proto_data = g_new0(struct msn_data, 1);
|
|
484 char c;
|
|
485 int i;
|
|
486 int status;
|
|
487
|
|
488 md5_state_t st;
|
|
489 md5_byte_t di[16];
|
|
490 int x;
|
|
491
|
|
492 gchar **results;
|
|
493
|
1282
|
494 g_snprintf(mdata->protocol, strlen("MSNP2") + 1, "MSNP2");
|
|
495
|
|
496 set_login_progress(gc, 1, "Connecting");
|
1259
|
497
|
|
498 while (gtk_events_pending())
|
|
499 gtk_main_iteration();
|
|
500 if (!g_slist_find(connections, gc))
|
|
501 return;
|
|
502
|
|
503 if (!(mdata->fd = msn_connect("messenger.hotmail.com", 1863))) {
|
|
504 hide_login_progress(gc, "Error connection to server");
|
|
505 signoff(gc);
|
1282
|
506 return;
|
1259
|
507 }
|
1282
|
508
|
1259
|
509 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username);
|
|
510 set_login_progress(gc, 2, buf);
|
1282
|
511
|
1279
|
512 while (gtk_events_pending())
|
|
513 gtk_main_iteration();
|
1259
|
514
|
|
515 /* This is where we will attempt to sign on */
|
|
516 g_snprintf(buf, 4096, "VER %d %s\n", trId, mdata->protocol);
|
|
517 write(mdata->fd, buf, strlen(buf));
|
|
518
|
|
519 msn_read_line(&buf2, mdata->fd);
|
|
520
|
1282
|
521 buf[strlen(buf) - 1] = '\0';
|
1259
|
522 if (strcmp(buf, buf2) != 0) {
|
|
523 hide_login_progress(gc, buf2);
|
|
524 signoff(gc);
|
|
525 return;
|
|
526 }
|
|
527
|
|
528 /* Looks like our versions matched up. Let's find out
|
|
529 * which policy we should use */
|
|
530
|
|
531 g_snprintf(buf, 4096, "INF %d\n", trId);
|
|
532 write(mdata->fd, buf, strlen(buf));
|
|
533
|
|
534 msn_read_line(&buf2, mdata->fd);
|
|
535 results = g_strsplit(buf2, " ", 0);
|
|
536 mdata->policy = g_strdup(results[2]);
|
|
537 g_strfreev(results);
|
|
538
|
|
539 /* We've set our policy. Now, lets attempt a sign on */
|
1282
|
540 g_snprintf(buf, 4096, "USR %d %s I %s\n", trId, mdata->policy, gc->username);
|
1259
|
541 write(mdata->fd, buf, strlen(buf));
|
|
542
|
|
543 msn_read_line(&buf2, mdata->fd);
|
|
544
|
|
545 /* This is where things get kinky */
|
|
546 results = g_strsplit(buf2, " ", 0);
|
|
547
|
|
548 /* Are we being transfered to another server ? */
|
|
549 if (strcasecmp(results[0], "XFR") == 0) {
|
|
550 /* Yup. We should connect to the _new_ server */
|
|
551 strcpy(buf, results[3]);
|
|
552 g_strfreev(results);
|
|
553
|
|
554 results = g_strsplit(buf, ":", 0);
|
|
555
|
|
556 /* Connect to the new server */
|
|
557 if (!(mdata->fd = msn_connect(results[0], atoi(results[1])))) {
|
|
558 hide_login_progress(gc, "Error connecting to server");
|
|
559 signoff(gc);
|
|
560 g_strfreev(results);
|
1282
|
561 return;
|
1259
|
562 }
|
|
563
|
|
564
|
|
565 g_strfreev(results);
|
|
566
|
|
567 /* We're now connected to the new server. Send signon
|
|
568 * information again */
|
1282
|
569 g_snprintf(buf, 4096, "USR %d %s I %s\n", trId, mdata->policy, gc->username);
|
1259
|
570 write(mdata->fd, buf, strlen(buf));
|
|
571
|
|
572 msn_read_line(&buf, mdata->fd);
|
|
573 results = g_strsplit(buf, " ", 0);
|
|
574
|
|
575 }
|
1282
|
576
|
1259
|
577 /* Otherwise, if we have a USR response, let's handle it */
|
|
578 if (strcasecmp("USR", results[0]) == 0) {
|
|
579 /* Looks like we got a response. Let's get our challenge
|
|
580 * string */
|
|
581 strcpy(buf, results[4]);
|
|
582
|
1282
|
583 } else {
|
1259
|
584 g_strfreev(results);
|
|
585 hide_login_progress(gc, "Error signing on");
|
|
586 signoff(gc);
|
|
587 return;
|
|
588 }
|
|
589 g_strfreev(results);
|
|
590
|
|
591 /* Build our response string */
|
|
592 snprintf(buf2, 4096, "%s%s", buf, gc->password);
|
|
593
|
|
594 /* Use the MD5 Hashing */
|
|
595 md5_init(&st);
|
|
596 md5_append(&st, (const md5_byte_t *)buf2, strlen(buf2));
|
|
597 md5_finish(&st, di);
|
|
598
|
|
599 /* And now encode it in hex */
|
|
600 sprintf(buf, "%02x", di[0]);
|
|
601 for (x = 1; x < 16; x++) {
|
|
602 sprintf(buf, "%s%02x", buf, di[x]);
|
|
603 }
|
|
604
|
|
605 /* And now we should fire back a response */
|
|
606 g_snprintf(buf2, 4096, "USR %d %s S %s\n", trId, mdata->policy, buf);
|
|
607 write(mdata->fd, buf2, strlen(buf2));
|
|
608
|
|
609
|
|
610 msn_read_line(&buf, mdata->fd);
|
|
611
|
|
612 results = g_strsplit(buf, " ", 0);
|
|
613
|
|
614 if ((strcasecmp("USR", results[0]) == 0) && (strcasecmp("OK", results[2]) == 0)) {
|
|
615 mdata->friendly = g_strdup(results[4]);
|
|
616 g_strfreev(results);
|
1282
|
617 } else {
|
1259
|
618 g_strfreev(results);
|
|
619 hide_login_progress(gc, "Error signing on!");
|
|
620 signoff(gc);
|
|
621 return;
|
|
622
|
|
623 }
|
|
624 set_login_progress(gc, 3, "Getting Config");
|
1279
|
625 while (gtk_events_pending())
|
|
626 gtk_main_iteration();
|
|
627
|
1259
|
628 g_snprintf(buf, 4096, "SYN %d 0\n", trId);
|
|
629 write(mdata->fd, buf, strlen(buf));
|
|
630
|
|
631 /* Go online */
|
|
632 g_snprintf(buf, 4096, "CHG %d NLN\n", trId);
|
|
633 write(mdata->fd, buf, strlen(buf));
|
|
634
|
|
635 account_online(gc);
|
|
636 serv_finish_login(gc);
|
|
637
|
|
638 if (bud_list_cache_exists(gc))
|
|
639 do_import(NULL, gc);
|
|
640
|
|
641 /* We want to do this so that we can read what's going on */
|
1283
|
642 gc->inpa = gdk_input_add(mdata->fd, GDK_INPUT_READ, msn_callback, gc);
|
1259
|
643 }
|
|
644
|
1282
|
645 void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away)
|
|
646 {
|
1259
|
647 struct msn_conn *mc;
|
|
648 struct msn_data *mdata;
|
1282
|
649 time_t trId = time((time_t *) NULL);
|
1259
|
650 char *buf;
|
|
651
|
|
652 mdata = (struct msn_data *)gc->proto_data;
|
|
653 mc = find_msn_conn_by_user(who);
|
|
654
|
1282
|
655 if (mc == NULL) {
|
1259
|
656 gchar buf2[4096];
|
|
657 gchar *address;
|
|
658 gchar *auth;
|
|
659 gchar **resps;
|
|
660
|
|
661 /* Request a new switchboard connection */
|
|
662 g_snprintf(buf2, 4096, "XFR %d SB\n", trId);
|
|
663 write(mdata->fd, buf2, strlen(buf2));
|
1282
|
664
|
1259
|
665 /* Read the results */
|
|
666 msn_read_line(&buf2, mdata->fd);
|
|
667
|
|
668 resps = g_strsplit(buf2, " ", 0);
|
|
669
|
|
670 address = g_strdup(resps[3]);
|
|
671 auth = g_strdup(resps[5]);
|
|
672 g_strfreev(resps);
|
|
673
|
|
674 resps = g_strsplit(address, ":", 0);
|
|
675
|
|
676 mc = g_new0(struct msn_conn, 1);
|
|
677
|
|
678 if (!(mc->fd = msn_connect(resps[0], atoi(resps[1])))) {
|
|
679 g_strfreev(resps);
|
|
680 g_free(address);
|
|
681 g_free(auth);
|
|
682 g_free(mc);
|
|
683 return;
|
|
684 }
|
|
685
|
|
686 /* Looks like we got connected ok. Now, let's verify */
|
|
687 g_snprintf(buf2, 4096, "USR %d %s %s\n", trId, gc->username, auth);
|
|
688 write(mc->fd, buf2, strlen(buf2));
|
|
689
|
|
690 /* Read the results */
|
|
691 msn_read_line(&buf2, mc->fd);
|
|
692 g_strfreev(resps);
|
1282
|
693
|
1259
|
694 resps = g_strsplit(buf2, " ", 0);
|
1282
|
695
|
1259
|
696 if (!(strcasecmp("OK", resps[2]) == 0)) {
|
|
697 g_free(auth);
|
|
698 g_free(address);
|
|
699 g_strfreev(resps);
|
|
700 g_free(mc);
|
|
701 return;
|
|
702 }
|
|
703
|
|
704 mc->user = g_strdup(who);
|
1283
|
705 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, gc);
|
1259
|
706
|
|
707 msn_connections = g_slist_append(msn_connections, mc);
|
|
708
|
|
709 /* Now we must invite our new user to the switchboard session */
|
|
710 g_snprintf(buf2, 4096, "CAL %d %s\n", trId, who);
|
|
711 write(mc->fd, buf2, strlen(buf2));
|
|
712
|
|
713 /* FIXME: This causes a delay. I will make some sort of queing feature to prevent
|
|
714 * this from being needed */
|
|
715
|
|
716 while (!strstr(buf2, "JOI")) {
|
|
717 msn_read_line(&buf2, mc->fd);
|
|
718 }
|
1282
|
719
|
1259
|
720 g_free(auth);
|
|
721 g_free(address);
|
|
722 g_strfreev(resps);
|
|
723
|
|
724 }
|
|
725
|
1282
|
726 /* Always practice safe sets :-) */
|
|
727 buf = (gchar *) g_malloc(sizeof(gchar) * (strlen(message) + strlen(MIME_HEADER) + 64));
|
1259
|
728
|
1282
|
729 g_snprintf(buf, strlen(message) + strlen(MIME_HEADER) + 64, "MSG %d N %d\r\n%s%s", trId,
|
|
730 strlen(message) + strlen(MIME_HEADER), MIME_HEADER, message);
|
1259
|
731
|
|
732 write(mc->fd, buf, strlen(buf));
|
|
733
|
|
734 g_free(buf);
|
|
735 }
|
|
736
|
1282
|
737 static void msn_close(struct gaim_connection *gc)
|
|
738 {
|
1275
|
739 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
|
740 GSList *conns = msn_connections;
|
|
741 struct msn_conn *mc = NULL;
|
|
742 char buf[4096];
|
|
743
|
|
744 while (conns) {
|
|
745 mc = (struct msn_conn *)conns->data;
|
|
746
|
|
747 if (mc->inpa > 0)
|
|
748 gdk_input_remove(mc->inpa);
|
|
749
|
|
750 if (mc->fd > 0)
|
|
751 close(mc->fd);
|
|
752
|
|
753 if (mc->user != NULL)
|
|
754 g_free(mc->user);
|
1282
|
755
|
1275
|
756 conns = g_slist_remove(conns, mc);
|
|
757 g_free(mc);
|
|
758 }
|
|
759
|
|
760
|
|
761 g_snprintf(buf, 4096, "OUT\n");
|
|
762 write(mdata->fd, buf, strlen(buf));
|
1282
|
763
|
1275
|
764 if (gc->inpa > 0)
|
|
765 gdk_input_remove(gc->inpa);
|
|
766
|
|
767 close(mdata->fd);
|
|
768
|
|
769 if (mdata->friendly != NULL)
|
|
770 g_free(mdata->friendly);
|
|
771
|
|
772 g_free(gc->proto_data);
|
|
773
|
|
774 debug_printf(_("Signed off.\n"));
|
1282
|
775
|
1275
|
776 }
|
|
777
|
1282
|
778 static void msn_set_away(struct gaim_connection *gc, char *msg)
|
|
779 {
|
1278
|
780 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
1282
|
781 time_t trId = time((time_t *) NULL);
|
1278
|
782 gchar buf[4096];
|
|
783
|
|
784 if (msg) {
|
|
785 g_snprintf(buf, 4096, "CHG %d AWY\n", trId);
|
|
786 } else if (gc->is_idle) {
|
|
787 g_snprintf(buf, 4096, "CHG %d IDL\n", trId);
|
|
788 } else {
|
|
789 g_snprintf(buf, 4096, "CHG %d NLN\n", trId);
|
|
790 }
|
|
791
|
|
792 write(mdata->fd, buf, strlen(buf));
|
1282
|
793
|
1278
|
794 }
|
|
795
|
1282
|
796 static void msn_set_idle(struct gaim_connection *gc, int idle)
|
|
797 {
|
1278
|
798 struct msn_data *mdata = (struct msn_data *)gc->proto_data;
|
1282
|
799 time_t trId = time((time_t *) NULL);
|
1278
|
800 gchar buf[4096];
|
|
801
|
|
802 if (idle) {
|
|
803 g_snprintf(buf, 4096, "CHG %d IDL\n", trId);
|
|
804 } else {
|
|
805 g_snprintf(buf, 4096, "CHG %d NLN\n", trId);
|
|
806 }
|
|
807
|
|
808 write(mdata->fd, buf, strlen(buf));
|
1282
|
809
|
1278
|
810 }
|
|
811
|
1284
|
812 static char **msn_list_icon(int status)
|
|
813 {
|
|
814 return msn_online_xpm;
|
|
815 }
|
|
816
|
1259
|
817 static struct prpl *my_protocol = NULL;
|
|
818
|
1282
|
819 void msn_init(struct prpl *ret)
|
|
820 {
|
1259
|
821 ret->protocol = PROTO_MSN;
|
|
822 ret->name = msn_name;
|
1284
|
823 ret->list_icon = msn_list_icon;
|
1259
|
824 ret->action_menu = NULL;
|
|
825 ret->user_opts = NULL;
|
|
826 ret->login = msn_login;
|
1275
|
827 ret->close = msn_close;
|
1259
|
828 ret->send_im = msn_send_im;
|
|
829 ret->set_info = NULL;
|
|
830 ret->get_info = NULL;
|
1278
|
831 ret->set_away = msn_set_away;
|
1259
|
832 ret->get_away_msg = NULL;
|
|
833 ret->set_dir = NULL;
|
|
834 ret->get_dir = NULL;
|
|
835 ret->dir_search = NULL;
|
1278
|
836 ret->set_idle = msn_set_idle;
|
1259
|
837 ret->change_passwd = NULL;
|
|
838 ret->add_buddy = msn_add_buddy;
|
|
839 ret->add_buddies = NULL;
|
|
840 ret->remove_buddy = msn_remove_buddy;
|
|
841 ret->add_permit = msn_add_permit;
|
|
842 ret->rem_permit = msn_rem_permit;
|
1277
|
843 ret->add_deny = msn_add_deny;
|
|
844 ret->rem_deny = msn_rem_deny;
|
1259
|
845 ret->warn = NULL;
|
|
846 ret->accept_chat = NULL;
|
|
847 ret->join_chat = NULL;
|
|
848 ret->chat_invite = NULL;
|
|
849 ret->chat_leave = NULL;
|
|
850 ret->chat_whisper = NULL;
|
|
851 ret->chat_send = NULL;
|
|
852 ret->keepalive = NULL;
|
|
853
|
|
854 my_protocol = ret;
|
|
855 }
|
|
856
|
1282
|
857 char *gaim_plugin_init(GModule * handle)
|
|
858 {
|
1259
|
859 load_protocol(msn_init);
|
|
860 return NULL;
|
|
861 }
|
|
862
|
1282
|
863 void gaim_plugin_remove()
|
|
864 {
|
1259
|
865 struct prpl *p = find_prpl(PROTO_MSN);
|
|
866 if (p == my_protocol)
|
|
867 unload_protocol(p);
|
|
868 }
|