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