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