comparison src/protocols/msn/msn.c @ 2591:b771cbe7e161

[gaim-migrate @ 2604] spam! glorious spam. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 23 Oct 2001 21:39:44 +0000
parents a3117e29317d
children 2ced57c58653
comparison
equal deleted inserted replaced
2590:2dd86a1af92b 2591:b771cbe7e161
51 char *sessid; 51 char *sessid;
52 char *auth; 52 char *auth;
53 int trId; 53 int trId;
54 int total; 54 int total;
55 char *user; 55 char *user;
56 char *txqueue; 56 GSList *txqueue;
57 }; 57 };
58 58
59 struct msn_buddy { 59 struct msn_buddy {
60 char *user; 60 char *user;
61 char *friend; 61 char *friend;
294 GSList *m = md->switches; 294 GSList *m = md->switches;
295 295
296 while (m) { 296 while (m) {
297 struct msn_switchboard *ms = m->data; 297 struct msn_switchboard *ms = m->data;
298 m = m->next; 298 m = m->next;
299 if ((ms->total == 1) && !g_strcasecmp(ms->user, id)) 299 if ((ms->total <= 1) && !g_strcasecmp(ms->user, id))
300 return ms; 300 return ms;
301 } 301 }
302 302
303 return NULL; 303 return NULL;
304 } 304 }
344 if (ms->sessid) 344 if (ms->sessid)
345 g_free(ms->sessid); 345 g_free(ms->sessid);
346 g_free(ms->auth); 346 g_free(ms->auth);
347 if (ms->user) 347 if (ms->user)
348 g_free(ms->user); 348 g_free(ms->user);
349 if (ms->txqueue) 349 while (ms->txqueue) {
350 g_free(ms->txqueue); 350 g_free(ms->txqueue->data);
351 ms->txqueue = g_slist_remove(ms->txqueue, ms->txqueue->data);
352 }
351 if (ms->chat) 353 if (ms->chat)
352 serv_got_chat_left(gc, ms->chat->id); 354 serv_got_chat_left(gc, ms->chat->id);
353 355
354 md->switches = g_slist_remove(md->switches, ms); 356 md->switches = g_slist_remove(md->switches, ms);
355 357
420 ms->user = NULL; 422 ms->user = NULL;
421 } 423 }
422 if (ms->chat) 424 if (ms->chat)
423 add_chat_buddy(ms->chat, user); 425 add_chat_buddy(ms->chat, user);
424 ms->total++; 426 ms->total++;
425 if (ms->txqueue) { 427 while (ms->txqueue) {
426 char *utf8 = str_to_utf8(ms->txqueue); 428 char *utf8 = str_to_utf8(ms->txqueue->data);
427 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, 429 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId,
428 strlen(MIME_HEADER) + strlen(utf8), 430 strlen(MIME_HEADER) + strlen(utf8),
429 MIME_HEADER, utf8); 431 MIME_HEADER, utf8);
430 g_free(utf8); 432 g_free(utf8);
431 g_free(ms->txqueue); 433 g_free(ms->txqueue->data);
432 ms->txqueue = NULL; 434 ms->txqueue = g_slist_remove(ms->txqueue, ms->txqueue->data);
433 if (msn_write(ms->fd, buf, strlen(buf)) < 0) 435 if (msn_write(ms->fd, buf, strlen(buf)) < 0) {
434 msn_kill_switch(ms); 436 msn_kill_switch(ms);
437 return;
438 }
435 debug_printf("\n"); 439 debug_printf("\n");
436 } 440 }
437 } else if (!g_strncasecmp(buf, "MSG", 3)) { 441 } else if (!g_strncasecmp(buf, "MSG", 3)) {
438 char *user, *tmp = buf; 442 char *user, *tmp = buf;
439 int length; 443 int length;
1192 struct msn_data *md = gc->proto_data; 1196 struct msn_data *md = gc->proto_data;
1193 struct msn_switchboard *ms = msn_find_switch(gc, who); 1197 struct msn_switchboard *ms = msn_find_switch(gc, who);
1194 char buf[MSN_BUF_LEN]; 1198 char buf[MSN_BUF_LEN];
1195 1199
1196 if (ms) { 1200 if (ms) {
1197 char *utf8 = str_to_utf8(message); 1201 char *utf8;
1202
1203 if (ms->txqueue) {
1204 debug_printf("appending to queue\n");
1205 ms->txqueue = g_slist_append(ms->txqueue, g_strdup(message));
1206 return 1;
1207 }
1208
1209 utf8 = str_to_utf8(message);
1198 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, 1210 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId,
1199 strlen(MIME_HEADER) + strlen(utf8), 1211 strlen(MIME_HEADER) + strlen(utf8),
1200 MIME_HEADER, utf8); 1212 MIME_HEADER, utf8);
1201 g_free(utf8); 1213 g_free(utf8);
1202 if (msn_write(ms->fd, buf, strlen(buf)) < 0) 1214 if (msn_write(ms->fd, buf, strlen(buf)) < 0)
1211 } 1223 }
1212 1224
1213 ms = g_new0(struct msn_switchboard, 1); 1225 ms = g_new0(struct msn_switchboard, 1);
1214 md->switches = g_slist_append(md->switches, ms); 1226 md->switches = g_slist_append(md->switches, ms);
1215 ms->user = g_strdup(who); 1227 ms->user = g_strdup(who);
1216 ms->txqueue = g_strdup(message); 1228 ms->txqueue = g_slist_append(ms->txqueue, g_strdup(message));
1217 ms->gc = gc; 1229 ms->gc = gc;
1218 ms->fd = -1; 1230 ms->fd = -1;
1219 } else 1231 } else
1220 /* in msn you can't send messages to yourself, so we'll fake like we received it ;) */ 1232 /* in msn you can't send messages to yourself, so we'll fake like we received it ;) */
1221 serv_got_im(gc, who, message, flags | IM_FLAG_GAIMUSER, time(NULL)); 1233 serv_got_im(gc, who, message, flags | IM_FLAG_GAIMUSER, time(NULL));
1231 return -EINVAL; 1243 return -EINVAL;
1232 1244
1233 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, 1245 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId,
1234 strlen(MIME_HEADER) + strlen(message), 1246 strlen(MIME_HEADER) + strlen(message),
1235 MIME_HEADER, message); 1247 MIME_HEADER, message);
1236 if (msn_write(ms->fd, buf, strlen(buf)) < 0) 1248 if (msn_write(ms->fd, buf, strlen(buf)) < 0) {
1237 msn_kill_switch(ms); 1249 msn_kill_switch(ms);
1250 return 0;
1251 }
1238 debug_printf("\n"); 1252 debug_printf("\n");
1239 serv_got_chat_in(gc, id, gc->username, 0, message, time(NULL)); 1253 serv_got_chat_in(gc, id, gc->username, 0, message, time(NULL));
1240 return 0; 1254 return 0;
1241 } 1255 }
1242 1256
1453 GList *m = NULL; 1467 GList *m = NULL;
1454 1468
1455 m = g_list_append(m, "Set Friendly Name"); 1469 m = g_list_append(m, "Set Friendly Name");
1456 1470
1457 return m; 1471 return m;
1472 }
1473
1474 static void msn_convo_closed(struct gaim_connection *gc, char *who)
1475 {
1476 struct msn_switchboard *ms = msn_find_switch(gc, who);
1477
1478 if (ms)
1479 msn_kill_switch(ms);
1458 } 1480 }
1459 1481
1460 static struct prpl *my_protocol = NULL; 1482 static struct prpl *my_protocol = NULL;
1461 1483
1462 void msn_init(struct prpl *ret) 1484 void msn_init(struct prpl *ret)
1478 ret->chat_invite = msn_chat_invite; 1500 ret->chat_invite = msn_chat_invite;
1479 ret->chat_leave = msn_chat_leave; 1501 ret->chat_leave = msn_chat_leave;
1480 ret->normalize = msn_normalize; 1502 ret->normalize = msn_normalize;
1481 ret->do_action = msn_do_action; 1503 ret->do_action = msn_do_action;
1482 ret->actions = msn_actions; 1504 ret->actions = msn_actions;
1505 ret->convo_closed = msn_convo_closed;
1483 1506
1484 my_protocol = ret; 1507 my_protocol = ret;
1485 } 1508 }
1486 1509
1487 #ifndef STATIC 1510 #ifndef STATIC