Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/ns.c

    r0864a52 rc0db0d3  
    3939static void msn_ns_send_adl(struct im_connection *ic);
    4040static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd);
    41 static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action);
     41static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action, gboolean selfmessage);
    4242static void msn_ns_nfy(struct msn_data *md, char *who, char **parts, char *action, gboolean is_put);
    4343
     
    110110        struct im_connection *ic = md->ic;
    111111
     112        /* this should be taken from XFR, but hardcoding it for now. it also prevents more redirects. */
     113        const char *redir_data = "VmVyc2lvbjogMQ0KWGZyQ291bnQ6IDINCklzR2VvWGZyOiB0cnVlDQo=";
     114
    112115        if (source == -1 && !md->is_http) {
    113116                imcb_error(ic, "Could not connect to server");
     
    135138        }
    136139
    137         if (msn_ns_write(ic, source, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER)) {
     140        /* Having to handle potential errors in each write sure makes these ifs awkward...*/
     141
     142        if (msn_ns_write(ic, source, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER) &&
     143            msn_ns_write(ic, source, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s %s\r\n",
     144                         ++md->trId, ic->acc->user, redir_data) &&
     145            msn_ns_write(ic, md->fd, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user)) {
     146
    138147                if (!md->is_http) {
    139148                        md->inpa = b_input_add(md->fd, B_EV_IO_READ, msn_ns_callback, md);
     
    208217                }
    209218
    210                 return(msn_ns_write(ic, md->fd, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s VmVyc2lvbjogMQ0KWGZyQ291bnQ6IDINClhmclNlbnRVVENUaW1lOiA2MzU2MTQ3OTU5NzgzOTAwMDANCklzR2VvWGZyOiB0cnVlDQo=\r\n",
    211                                     ++md->trId, ic->acc->user));
    212219        } else if (strcmp(cmd[0], "CVR") == 0) {
    213220                /* We don't give a damn about the information we just received */
    214                 return msn_ns_write(ic, md->fd, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user);
    215221        } else if (strcmp(cmd[0], "XFR") == 0) {
    216222                char *server;
     
    280286                        md->msglen = atoi(cmd[2]);
    281287                }
     288        } else if (strcmp(cmd[0], "RML") == 0) {
     289                /* Move along, nothing to see here */
    282290        } else if (strcmp(cmd[0], "CHL") == 0) {
    283291                char *resp;
     
    475483}
    476484
     485/* returns newly allocated string */
     486static char *msn_ns_parse_header_address(struct msn_data *md, char *headers, char *header_name)
     487{
     488        char *semicolon = NULL;
     489        char *header = NULL;
     490        char *address = NULL;
     491
     492        if (!(header = get_rfc822_header(headers, header_name, 0))) {
     493                return NULL;
     494        }
     495
     496        /* either the semicolon or the end of the string */
     497        semicolon = strchr(header, ';') ? : (header + strlen(header));
     498
     499        address = g_strndup(header + 2, semicolon - header - 2);
     500
     501        g_free(header);
     502        return address;
     503}
     504
    477505static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd)
    478506{
    479507        char **parts = NULL;
    480         char *semicolon = NULL;
    481508        char *action = NULL;
    482         char *from = NULL;
    483509        char *who = NULL;
     510        gboolean selfmessage = FALSE;
    484511
    485512        parts = g_strsplit(msg, "\r\n\r\n", 4);
    486513
    487         if (!(from = get_rfc822_header(parts[0], "From", 0))) {
     514        if (!(who = msn_ns_parse_header_address(md, parts[0], "From"))) {
    488515                goto cleanup;
    489516        }
    490517
    491         /* either the semicolon or the end of the string */
    492         semicolon = strchr(from, ';') ? : (from + strlen(from));
    493 
    494         who = g_strndup(from + 2, semicolon - from - 2);
     518        if (strcmp(who, md->ic->acc->user) == 0) {
     519                selfmessage = TRUE;
     520                g_free(who);
     521                if (!(who = msn_ns_parse_header_address(md, parts[0], "To"))) {
     522                        goto cleanup;
     523                }
     524        }
    495525
    496526        if ((strcmp(cmd[0], "SDG") == 0) && (action = get_rfc822_header(parts[2], "Message-Type", 0))) {
    497                 msn_ns_sdg(md, who, parts, action);
     527                msn_ns_sdg(md, who, parts, action, selfmessage);
    498528
    499529        } else if ((strcmp(cmd[0], "NFY") == 0) && (action = get_rfc822_header(parts[2], "Uri", 0))) {
     
    505535        g_strfreev(parts);
    506536        g_free(action);
    507         g_free(from);
    508537        g_free(who);
    509538}
    510539
    511 static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action)
     540static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action, gboolean selfmessage)
    512541{
    513542        struct im_connection *ic = md->ic;
    514543
    515         if (strcmp(action, "Control/Typing") == 0) {
     544        if (strcmp(action, "Control/Typing") == 0 && !selfmessage) {
    516545                imcb_buddy_typing(ic, who, OPT_TYPING);
    517546        } else if (strcmp(action, "Text") == 0) {
    518                 imcb_buddy_msg(ic, who, parts[3], 0, 0);
     547                imcb_buddy_msg(ic, who, parts[3], selfmessage ? OPT_SELFMESSAGE : 0, 0);
    519548        }
    520549}
     
    595624        } else {
    596625                imcb_error(ic, "Error during Passport authentication: %s", error);
    597                 imc_logout(ic, TRUE);
     626
     627                /* don't reconnect with auth errors */
     628                if (error && g_str_has_prefix(error, "wsse:FailedAuthentication")) {
     629                        imc_logout(ic, FALSE);
     630                } else {
     631                        imc_logout(ic, TRUE);
     632                }
    598633        }
    599634}
Note: See TracChangeset for help on using the changeset viewer.