Changeset d550358
- Timestamp:
- 2015-04-10T17:10:40Z (10 years ago)
- Branches:
- master
- Children:
- cfeadc3
- Parents:
- d80822c
- git-author:
- dequis <dx@…> (09-03-15 08:26:16)
- git-committer:
- dequis <dx@…> (10-04-15 17:10:40)
- Location:
- protocols/msn
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn.c
rd80822c rd550358 96 96 msn_ns_close(md); 97 97 98 msn_msgq_purge(ic, &md->msgq);99 98 msn_soapq_flush(ic, FALSE); 100 99 -
protocols/msn/msn.h
rd80822c rd550358 218 218 int msn_ns_finish_login(struct im_connection *ic); 219 219 int msn_ns_sendmessage(struct im_connection *ic, struct bee_user *bu, const char *text); 220 void msn_ns_oim_send_queue(struct im_connection *ic, GSList **msgq);221 220 int msn_ns_command(struct msn_data *md, char **cmd, int num_parts); 222 221 int msn_ns_message(struct msn_data *md, char *msg, int msglen, char **cmd, int num_parts); … … 229 228 char **msn_linesplit(char *line); 230 229 int msn_handler(struct msn_data *h); 231 void msn_msgq_purge(struct im_connection *ic, GSList **list);232 230 char *msn_p11_challenge(char *challenge); 233 231 gint msn_domaintree_cmp(gconstpointer a_, gconstpointer b_); -
protocols/msn/msn_util.c
rd80822c rd550358 55 55 56 56 *groupid = '\0'; 57 #if 058 if (group) {59 int i;60 for (i = 0; i < md->groupcount; i++) {61 if (g_strcasecmp(md->grouplist[i], group) == 0) {62 g_snprintf(groupid, sizeof(groupid), " %d", i);63 break;64 }65 }66 67 if (*groupid == '\0') {68 /* Have to create this group, it doesn't exist yet. */69 struct msn_groupadd *ga;70 GSList *l;71 72 for (l = md->grpq; l; l = l->next) {73 ga = l->data;74 if (g_strcasecmp(ga->group, group) == 0) {75 break;76 }77 }78 79 ga = g_new0(struct msn_groupadd, 1);80 ga->who = g_strdup(who);81 ga->group = g_strdup(group);82 md->grpq = g_slist_prepend(md->grpq, ga);83 84 if (l == NULL) {85 char groupname[strlen(group) + 1];86 strcpy(groupname, group);87 http_encode(groupname);88 g_snprintf(buf, sizeof(buf), "ADG %d %s %d\r\n", ++md->trId, groupname, 0);89 return msn_write(ic, buf, strlen(buf));90 } else {91 /* This can happen if the user's doing lots of adds to a92 new group at once; we're still waiting for the server93 to confirm group creation. */94 return 1;95 }96 }97 }98 #endif99 57 100 58 if (!((bu = bee_user_by_handle(ic->bee, ic, who)) || … … 132 90 133 91 *groupid = '\0'; 134 #if 0135 if (group) {136 int i;137 for (i = 0; i < md->groupcount; i++) {138 if (g_strcasecmp(md->grouplist[i], group) == 0) {139 g_snprintf(groupid, sizeof(groupid), " %d", i);140 break;141 }142 }143 }144 #endif145 92 146 93 if (!(bu = bee_user_by_handle(ic->bee, ic, who)) || … … 375 322 } 376 323 377 void msn_msgq_purge(struct im_connection *ic, GSList **list)378 {379 struct msn_message *m;380 GString *ret;381 GSList *l;382 int n = 0;383 384 l = *list;385 if (l == NULL) {386 return;387 }388 389 m = l->data;390 ret = g_string_sized_new(1024);391 g_string_printf(ret, "Warning: Cleaning up MSN (switchboard) connection with unsent "392 "messages to %s:", m->who ? m->who : "unknown recipient");393 394 while (l) {395 m = l->data;396 397 if (strncmp(m->text, "\r\r\r", 3) != 0) {398 g_string_append_printf(ret, "\n%s", m->text);399 n++;400 }401 402 g_free(m->who);403 g_free(m->text);404 g_free(m);405 406 l = l->next;407 }408 g_slist_free(*list);409 *list = NULL;410 411 if (n > 0) {412 imcb_log(ic, "%s", ret->str);413 }414 g_string_free(ret, TRUE);415 }416 417 324 /* Copied and heavily modified from http://tmsnc.sourceforge.net/chl.c */ 418 325 char *msn_p11_challenge(char *challenge) -
protocols/msn/ns.c
rd80822c rd550358 248 248 handler->msglen = atoi(cmd[2]); 249 249 } 250 } else if (strcmp(cmd[0], "PRP") == 0) {251 imcb_connected(ic);252 250 } else if (strcmp(cmd[0], "CHL") == 0) { 253 251 char *resp; … … 267 265 g_free(resp); 268 266 return st; 269 } else if (strcmp(cmd[0], "ILN") == 0 || strcmp(cmd[0], "NLN") == 0) {270 const struct msn_away_state *st;271 const char *handle;272 int cap = 0;273 274 if (num_parts < 6) {275 imcb_error(ic, "Syntax error");276 imc_logout(ic, TRUE);277 return(0);278 }279 /* ILN and NLN are more or less the same, except ILN has a trId280 at the start, and NLN has a capability field at the end.281 Does ILN still exist BTW? */282 if (cmd[0][1] == 'I') {283 cmd++;284 } else {285 cap = atoi(cmd[4]);286 }287 288 handle = msn_normalize_handle(cmd[2]);289 if (strcmp(handle, ic->acc->user) == 0) {290 return 1; /* That's me! */291 292 }293 http_decode(cmd[3]);294 imcb_rename_buddy(ic, handle, cmd[3]);295 296 st = msn_away_state_by_code(cmd[1]);297 if (!st) {298 /* FIXME: Warn/Bomb about unknown away state? */299 st = msn_away_state_list + 1;300 }301 302 imcb_buddy_status(ic, handle, OPT_LOGGED_IN |303 (st != msn_away_state_list ? OPT_AWAY : 0) |304 (cap & 1 ? OPT_MOBILE : 0),305 st->name, NULL);306 307 } else if (strcmp(cmd[0], "FLN") == 0) {308 const char *handle;309 310 if (cmd[1] == NULL) {311 return 1;312 }313 314 handle = msn_normalize_handle(cmd[1]);315 imcb_buddy_status(ic, handle, 0, NULL, NULL);316 267 } else if (strcmp(cmd[0], "OUT") == 0) { 317 268 int allow_reconnect = TRUE; … … 329 280 imc_logout(ic, allow_reconnect); 330 281 return(0); 331 } else if (strcmp(cmd[0], "IPG") == 0) { 332 imcb_error(ic, "Received IPG command, we don't handle them yet."); 333 334 handler->msglen = atoi(cmd[1]); 335 336 if (handler->msglen <= 0) { 337 imcb_error(ic, "Syntax error"); 338 imc_logout(ic, TRUE); 339 return(0); 340 } 341 } 342 #if 0 343 else if (strcmp(cmd[0], "ADG") == 0) { 344 char *group = g_strdup(cmd[3]); 345 int groupnum, i; 346 GSList *l, *next; 347 348 http_decode(group); 349 if (sscanf(cmd[4], "%d", &groupnum) == 1) { 350 if (groupnum >= md->groupcount) { 351 md->grouplist = g_renew(char *, md->grouplist, groupnum + 1); 352 for (i = md->groupcount; i <= groupnum; i++) { 353 md->grouplist[i] = NULL; 354 } 355 md->groupcount = groupnum + 1; 356 } 357 g_free(md->grouplist[groupnum]); 358 md->grouplist[groupnum] = group; 359 } else { 360 /* Shouldn't happen, but if it does, give up on the group. */ 361 g_free(group); 362 imcb_error(ic, "Syntax error"); 363 imc_logout(ic, TRUE); 364 return 0; 365 } 366 367 for (l = md->grpq; l; l = next) { 368 struct msn_groupadd *ga = l->data; 369 next = l->next; 370 if (g_strcasecmp(ga->group, group) == 0) { 371 if (!msn_buddy_list_add(ic, "FL", ga->who, ga->who, group)) { 372 return 0; 373 } 374 375 g_free(ga->group); 376 g_free(ga->who); 377 g_free(ga); 378 md->grpq = g_slist_remove(md->grpq, ga); 379 } 380 } 381 } 382 #endif 383 else if (strcmp(cmd[0], "GCF") == 0) { 282 } else if (strcmp(cmd[0], "GCF") == 0) { 384 283 /* Coming up is cmd[2] bytes of stuff we're supposed to 385 284 censore. Meh. */ 386 285 handler->msglen = atoi(cmd[2]); 387 } else if (strcmp(cmd[0], "UBX") == 0) {388 /* Status message. */389 if (num_parts >= 3) {390 handler->msglen = atoi(cmd[2]);391 }392 } else if (strcmp(cmd[0], "NOT") == 0) {393 /* Some kind of notification, poorly documented but394 apparently used to announce address book changes. */395 if (num_parts >= 2) {396 handler->msglen = atoi(cmd[1]);397 }398 286 } else if ((strcmp(cmd[0], "NFY") == 0) || (strcmp(cmd[0], "SDG") == 0)) { 399 287 if (num_parts >= 3) { 400 288 handler->msglen = atoi(cmd[2]); 401 }402 } else if (strcmp(cmd[0], "UBM") == 0) {403 if (num_parts >= 7) {404 handler->msglen = atoi(cmd[6]);405 289 } 406 290 } else if (strcmp(cmd[0], "QNG") == 0) { … … 422 306 } 423 307 } else { 424 /* debug( "Received unknown command from main server: %s", cmd[0] ); */308 imcb_error(ic, "Received unknown command from main server: %s", cmd[0]); 425 309 } 426 310 … … 501 385 } 502 386 } else if (g_strncasecmp(ct, "text/x-msmsgsactivemailnotification", 35) == 0) { 503 } else if (g_strncasecmp(ct, "text/x-msmsgsinitialmdatanotification", 37) == 0 || 504 g_strncasecmp(ct, "text/x-msmsgsoimnotification", 28) == 0) { 505 /* We received an offline message. Or at least notification 506 that there is one waiting for us. Fetching the message(s) 507 and purging them from the server is a lot of SOAPy work 508 not worth doing IMHO. Also I thought it was possible to 509 have the notification server send them directly, I was 510 pretty sure I saw Pidgin do it.. 511 512 At least give a notification for now, seems like a 513 reasonable thing to do. Only problem is, they'll keep 514 coming back at login time until you read them using a 515 different client. :-( */ 516 517 char *xml = get_rfc822_header(body, "Mail-Data:", blen); 518 struct xt_node *md, *m; 519 520 if (!xml) { 521 return 1; 522 } 523 md = xt_from_string(xml, 0); 524 if (!md) { 525 return 1; 526 } 527 528 for (m = md->children; (m = xt_find_node(m, "M")); m = m->next) { 529 struct xt_node *e = xt_find_node(m->children, "E"); 530 struct xt_node *rt = xt_find_node(m->children, "RT"); 531 struct tm tp; 532 time_t msgtime = 0; 533 534 if (!e || !e->text) { 535 continue; 536 } 537 538 memset(&tp, 0, sizeof(tp)); 539 if (rt && rt->text && 540 sscanf(rt->text, "%4d-%2d-%2dT%2d:%2d:%2d.", 541 &tp.tm_year, &tp.tm_mon, &tp.tm_mday, 542 &tp.tm_hour, &tp.tm_min, &tp.tm_sec) == 6) { 543 tp.tm_year -= 1900; 544 tp.tm_mon--; 545 msgtime = mktime_utc(&tp); 546 547 } 548 imcb_buddy_msg(ic, e->text, 549 "<< \002BitlBee\002 - Received offline message. BitlBee can't show these. >>", 0, 550 msgtime); 551 } 552 553 g_free(xml); 554 xt_free_node(md); 387 /* Notification that a message has been read... Ignore it */ 555 388 } else { 556 389 debug("Can't handle %s packet from notification server", ct); … … 559 392 g_free(ct); 560 393 } 561 } else if (strcmp(cmd[0], "UBX") == 0) {562 struct xt_node *ubx, *psm;563 char *psm_text = NULL;564 565 ubx = xt_from_string(msg, msglen);566 if (ubx && strcmp(ubx->name, "Data") == 0 &&567 (psm = xt_find_node(ubx->children, "PSM"))) {568 psm_text = psm->text;569 }570 571 imcb_buddy_status_msg(ic, msn_normalize_handle(cmd[1]), psm_text);572 xt_free_node(ubx);573 394 } else if (strcmp(cmd[0], "ADL") == 0) { 574 395 struct xt_node *adl, *d, *c; … … 782 603 783 604 if ((md->flags & MSN_DONE_ADL) && (md->flags & MSN_GOT_PROFILE)) { 784 if (md->flags & MSN_EMAIL_UNVERIFIED) { 785 imcb_connected(ic); 786 } else { 787 return msn_ns_set_display_name(ic, set_getstr(&ic->acc->set, "display_name")); 788 } 605 imcb_connected(ic); 789 606 } 790 607 … … 810 627 return retval; 811 628 } 812 813 void msn_ns_oim_send_queue(struct im_connection *ic, GSList **msgq)814 {815 GSList *l;816 817 for (l = *msgq; l; l = l->next) {818 struct msn_message *m = l->data;819 bee_user_t *bu = bee_user_by_handle(ic->bee, ic, m->who);820 821 if (bu) {822 if (!msn_ns_sendmessage(ic, bu, m->text)) {823 return;824 }825 }826 }827 828 while (*msgq != NULL) {829 struct msn_message *m = (*msgq)->data;830 831 *msgq = g_slist_remove(*msgq, m);832 g_free(m->who);833 g_free(m->text);834 g_free(m);835 }836 }
Note: See TracChangeset
for help on using the changeset viewer.