comparison plugins/msn/msn.c @ 2014:162f749ee5e7

[gaim-migrate @ 2024] step 1 in moving towards group chat stuff. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 14 Jun 2001 03:40:56 +0000
parents 0c8073b877d2
children 0d11fd498068
comparison
equal deleted inserted replaced
2013:0be1e533036c 2014:162f749ee5e7
34 struct msn_data { 34 struct msn_data {
35 int fd; 35 int fd;
36 int trId; 36 int trId;
37 int inpa; 37 int inpa;
38 GSList *switches; 38 GSList *switches;
39 GSList *xfrs;
40 GSList *fl; 39 GSList *fl;
41 gboolean imported; 40 gboolean imported;
42 }; 41 };
43 42
44 struct msn_switchboard { 43 struct msn_switchboard {
51 int total; 50 int total;
52 char *user; 51 char *user;
53 char *txqueue; 52 char *txqueue;
54 }; 53 };
55 54
56 struct msn_xfr {
57 struct gaim_connection *gc;
58 char *user;
59 char *what;
60 };
61
62 struct msn_buddy { 55 struct msn_buddy {
63 char *user; 56 char *user;
64 char *friend; 57 char *friend;
65 }; 58 };
66 59
294 287
295 while (m) { 288 while (m) {
296 struct msn_switchboard *ms = m->data; 289 struct msn_switchboard *ms = m->data;
297 m = m->next; 290 m = m->next;
298 if (!g_strcasecmp(ms->user, id)) 291 if (!g_strcasecmp(ms->user, id))
292 return ms;
293 }
294
295 return NULL;
296 }
297
298 static struct msn_switchboard *msn_find_writable_switch(struct gaim_connection *gc)
299 {
300 struct msn_data *md = gc->proto_data;
301 GSList *m = md->switches;
302
303 while (m) {
304 struct msn_switchboard *ms = m->data;
305 m = m->next;
306 if (ms->txqueue)
299 return ms; 307 return ms;
300 } 308 }
301 309
302 return NULL; 310 return NULL;
303 } 311 }
313 g_free(ms->sessid); 321 g_free(ms->sessid);
314 g_free(ms->auth); 322 g_free(ms->auth);
315 if (ms->user) 323 if (ms->user)
316 g_free(ms->user); 324 g_free(ms->user);
317 if (ms->txqueue) 325 if (ms->txqueue)
318 ms->txqueue = NULL; 326 g_free(ms->txqueue);
327 ms->txqueue = NULL;
319 328
320 md->switches = g_slist_remove(md->switches, ms); 329 md->switches = g_slist_remove(md->switches, ms);
321 330
322 g_free(ms); 331 g_free(ms);
323 } 332 }
324 333
325 static void msn_switchboard_callback(gpointer data, gint source, GdkInputCondition cond) 334 static void msn_switchboard_callback(gpointer data, gint source, GdkInputCondition cond)
326 { 335 {
327 struct msn_switchboard *ms = data; 336 struct msn_switchboard *ms = data;
328 struct gaim_connection *gc = ms->gc; 337 struct gaim_connection *gc = ms->gc;
329 struct msn_data *md = gc->proto_data;
330 char buf[MSN_BUF_LEN]; 338 char buf[MSN_BUF_LEN];
331 int i = 0; 339 int i = 0;
332 340
333 bzero(buf, sizeof(buf)); 341 bzero(buf, sizeof(buf));
334 while ((read(ms->fd, buf + i, 1) > 0) && (buf[i++] != '\n')) 342 while ((read(ms->fd, buf + i, 1) > 0) && (buf[i++] != '\n'))
345 if (!g_strncasecmp(buf, "ACK", 3)) { 353 if (!g_strncasecmp(buf, "ACK", 3)) {
346 } else if (!g_strncasecmp(buf, "ANS", 3)) { 354 } else if (!g_strncasecmp(buf, "ANS", 3)) {
347 } else if (!g_strncasecmp(buf, "BYE", 3)) { 355 } else if (!g_strncasecmp(buf, "BYE", 3)) {
348 } else if (!g_strncasecmp(buf, "CAL", 3)) { 356 } else if (!g_strncasecmp(buf, "CAL", 3)) {
349 } else if (!g_strncasecmp(buf, "IRO", 3)) { 357 } else if (!g_strncasecmp(buf, "IRO", 3)) {
358 char *tot, *friend, *tmp = buf;
359
360 GET_NEXT(tmp);
361 GET_NEXT(tmp);
362 GET_NEXT(tmp);
363 tot = tmp;
364 GET_NEXT(tmp);
365 ms->total = atoi(tot);
366 GET_NEXT(tmp);
367 friend = tmp;
350 } else if (!g_strncasecmp(buf, "JOI", 3)) { 368 } else if (!g_strncasecmp(buf, "JOI", 3)) {
351 if (ms->txqueue) { 369 if (ms->txqueue) {
352 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, 370 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId,
353 strlen(MIME_HEADER) + strlen(ms->txqueue), 371 strlen(MIME_HEADER) + strlen(ms->txqueue),
354 MIME_HEADER, ms->txqueue); 372 MIME_HEADER, ms->txqueue);
355 g_free(ms->txqueue); 373 g_free(ms->txqueue);
356 ms->txqueue = NULL; 374 ms->txqueue = NULL;
357 if (msn_write(ms->fd, buf, strlen(buf)) < 0) 375 if (msn_write(ms->fd, buf, strlen(buf)) < 0)
358 msn_kill_switch(ms); 376 msn_kill_switch(ms);
377 debug_printf("\n");
359 } 378 }
360 } else if (!g_strncasecmp(buf, "MSG", 3)) { 379 } else if (!g_strncasecmp(buf, "MSG", 3)) {
361 char *user, *tmp = buf; 380 char *user, *tmp = buf;
362 int length; 381 int length;
363 char *msg, *content, *skiphead, *utf, *final; 382 char *msg, *content, *skiphead, *utf, *final;
393 skiphead = strstr(msg, "\r\n\r\n"); 412 skiphead = strstr(msg, "\r\n\r\n");
394 if (!skiphead || !skiphead[4]) { 413 if (!skiphead || !skiphead[4]) {
395 g_free(msg); 414 g_free(msg);
396 return; 415 return;
397 } 416 }
398 *skiphead = 0;
399 debug_printf("%s\n", msg);
400 skiphead += 4; 417 skiphead += 4;
401 utf = utf8_to_str(skiphead); 418 utf = utf8_to_str(skiphead);
402 len = MAX(strlen(utf) + 1, BUF_LEN); 419 len = MAX(strlen(utf) + 1, BUF_LEN);
403 final = g_malloc(len); 420 final = g_malloc(len);
404 g_snprintf(final, len, "%s", utf); 421 g_snprintf(final, len, "%s", utf);
412 do_error_dialog("A message may not have been received.", "MSN Error"); 429 do_error_dialog("A message may not have been received.", "MSN Error");
413 } else if (!g_strncasecmp(buf, "NLN", 3)) { 430 } else if (!g_strncasecmp(buf, "NLN", 3)) {
414 } else if (!g_strncasecmp(buf, "OUT", 3)) { 431 } else if (!g_strncasecmp(buf, "OUT", 3)) {
415 } else if (!g_strncasecmp(buf, "USR", 3)) { 432 } else if (!g_strncasecmp(buf, "USR", 3)) {
416 /* good, we got USR, now we need to find out who we want to talk to */ 433 /* good, we got USR, now we need to find out who we want to talk to */
417 struct msn_xfr *mx; 434 struct msn_switchboard *ms = msn_find_writable_switch(gc);
418 435
419 if (!md->xfrs) 436 if (!ms)
420 return; 437 return;
421 mx = md->xfrs->data; 438
422 md->xfrs = g_slist_remove(md->xfrs, mx); 439 g_snprintf(buf, sizeof(buf), "CAL %d %s\n", ++ms->trId, ms->user);
423
424 g_snprintf(buf, sizeof(buf), "CAL %d %s\n", ++ms->trId, mx->user);
425 ms->txqueue = mx->what;
426 ms->user = mx->user;
427 g_free(mx);
428 if (msn_write(ms->fd, buf, strlen(buf)) < 0) 440 if (msn_write(ms->fd, buf, strlen(buf)) < 0)
429 msn_kill_switch(ms); 441 msn_kill_switch(ms);
430 } else if (isdigit(*buf)) { 442 } else if (isdigit(*buf)) {
431 handle_errcode(buf, TRUE); 443 handle_errcode(buf, TRUE);
432 } else { 444 } else {
468 480
469 static void msn_ss_xfr_connect(gpointer data, gint source, GdkInputCondition cond) 481 static void msn_ss_xfr_connect(gpointer data, gint source, GdkInputCondition cond)
470 { 482 {
471 struct msn_switchboard *ms = data; 483 struct msn_switchboard *ms = data;
472 struct gaim_connection *gc = ms->gc; 484 struct gaim_connection *gc = ms->gc;
473 struct msn_data *md;
474 char buf[MSN_BUF_LEN]; 485 char buf[MSN_BUF_LEN];
475 486
476 if (source == -1 || !g_slist_find(connections, gc)) { 487 if (source == -1 || !g_slist_find(connections, gc)) {
477 g_free(ms->auth); 488 g_free(ms->auth);
478 g_free(ms); 489 g_free(ms);
479 return; 490 return;
480 } 491 }
481 492
482 if (ms->fd != source) 493 if (ms->fd != source)
483 ms->fd = source; 494 ms->fd = source;
484
485 md = gc->proto_data;
486 495
487 g_snprintf(buf, sizeof(buf), "USR %d %s %s\n", ++ms->trId, gc->username, ms->auth); 496 g_snprintf(buf, sizeof(buf), "USR %d %s %s\n", ++ms->trId, gc->username, ms->auth);
488 if (msn_write(ms->fd, buf, strlen(buf)) < 0) { 497 if (msn_write(ms->fd, buf, strlen(buf)) < 0) {
489 g_free(ms->auth); 498 g_free(ms->auth);
490 g_free(ms); 499 g_free(ms);
491 return; 500 return;
492 } 501 }
493 502
494 md->switches = g_slist_append(md->switches, ms);
495 ms->inpa = gdk_input_add(ms->fd, GDK_INPUT_READ, msn_switchboard_callback, ms); 503 ms->inpa = gdk_input_add(ms->fd, GDK_INPUT_READ, msn_switchboard_callback, ms);
496 } 504 }
497 505
498 struct msn_add_permit { 506 struct msn_add_permit {
499 struct gaim_connection *gc; 507 struct gaim_connection *gc;
790 tmp = host; 798 tmp = host;
791 GET_NEXT(tmp); 799 GET_NEXT(tmp);
792 } 800 }
793 801
794 if (switchboard) { 802 if (switchboard) {
795 struct msn_switchboard *ms = g_new0(struct msn_switchboard, 1); 803 struct msn_switchboard *ms = msn_find_writable_switch(gc);
804 if (!ms)
805 return;
796 806
797 GET_NEXT(tmp); 807 GET_NEXT(tmp);
798 808
799 ms->gc = gc;
800 ms->auth = g_strdup(tmp); 809 ms->auth = g_strdup(tmp);
801 ms->fd = proxy_connect(host, port, msn_ss_xfr_connect, ms); 810 ms->fd = proxy_connect(host, port, msn_ss_xfr_connect, ms);
802 } else { 811 } else {
803 close(md->fd); 812 close(md->fd);
804 gdk_input_remove(md->inpa); 813 gdk_input_remove(md->inpa);
1044 close(md->fd); 1053 close(md->fd);
1045 if (md->inpa) 1054 if (md->inpa)
1046 gdk_input_remove(md->inpa); 1055 gdk_input_remove(md->inpa);
1047 while (md->switches) 1056 while (md->switches)
1048 msn_kill_switch(md->switches->data); 1057 msn_kill_switch(md->switches->data);
1049 while (md->xfrs) {
1050 struct msn_xfr *mx = md->xfrs->data;
1051 md->xfrs = g_slist_remove(md->xfrs, mx);
1052 g_free(mx->user);
1053 g_free(mx->what);
1054 g_free(mx);
1055 }
1056 while (md->fl) { 1058 while (md->fl) {
1057 struct msn_buddy *tmp = md->fl->data; 1059 struct msn_buddy *tmp = md->fl->data;
1058 md->fl = g_slist_remove(md->fl, tmp); 1060 md->fl = g_slist_remove(md->fl, tmp);
1059 g_free(tmp->user); 1061 g_free(tmp->user);
1060 g_free(tmp->friend); 1062 g_free(tmp->friend);
1073 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, 1075 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId,
1074 strlen(MIME_HEADER) + strlen(message), 1076 strlen(MIME_HEADER) + strlen(message),
1075 MIME_HEADER, message); 1077 MIME_HEADER, message);
1076 if (msn_write(ms->fd, buf, strlen(buf)) < 0) 1078 if (msn_write(ms->fd, buf, strlen(buf)) < 0)
1077 msn_kill_switch(ms); 1079 msn_kill_switch(ms);
1080 debug_printf("\n");
1078 } else { 1081 } else {
1079 struct msn_xfr *mx;
1080 g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\n", ++md->trId); 1082 g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\n", ++md->trId);
1081 if (msn_write(md->fd, buf, strlen(buf)) < 0) { 1083 if (msn_write(md->fd, buf, strlen(buf)) < 0) {
1082 hide_login_progress(gc, "Write error"); 1084 hide_login_progress(gc, "Write error");
1083 signoff(gc); 1085 signoff(gc);
1084 return; 1086 return;
1085 } 1087 }
1086 1088
1087 mx = g_new0(struct msn_xfr, 1); 1089 ms = g_new0(struct msn_switchboard, 1);
1088 md->xfrs = g_slist_append(md->xfrs, mx); 1090 md->switches = g_slist_append(md->switches, ms);
1089 mx->user = g_strdup(who); 1091 ms->user = g_strdup(who);
1090 mx->what = g_strdup(message); 1092 ms->txqueue = g_strdup(message);
1091 mx->gc = gc; 1093 ms->gc = gc;
1094 ms->fd = -1;
1092 } 1095 }
1093 } 1096 }
1094 1097
1095 static GList *msn_away_states() 1098 static GList *msn_away_states()
1096 { 1099 {