Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/ns.c

    rc0db0d3 r0864a52  
    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, gboolean selfmessage);
     41static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action);
    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 
    115112        if (source == -1 && !md->is_http) {
    116113                imcb_error(ic, "Could not connect to server");
     
    138135        }
    139136
    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 
     137        if (msn_ns_write(ic, source, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER)) {
    147138                if (!md->is_http) {
    148139                        md->inpa = b_input_add(md->fd, B_EV_IO_READ, msn_ns_callback, md);
     
    217208                }
    218209
     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));
    219212        } else if (strcmp(cmd[0], "CVR") == 0) {
    220213                /* 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);
    221215        } else if (strcmp(cmd[0], "XFR") == 0) {
    222216                char *server;
     
    286280                        md->msglen = atoi(cmd[2]);
    287281                }
    288         } else if (strcmp(cmd[0], "RML") == 0) {
    289                 /* Move along, nothing to see here */
    290282        } else if (strcmp(cmd[0], "CHL") == 0) {
    291283                char *resp;
     
    483475}
    484476
    485 /* returns newly allocated string */
    486 static char *msn_ns_parse_header_address(struct msn_data *md, char *headers, char *header_name)
    487 {
     477static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd)
     478{
     479        char **parts = NULL;
    488480        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;
     481        char *action = NULL;
     482        char *from = NULL;
     483        char *who = NULL;
     484
     485        parts = g_strsplit(msg, "\r\n\r\n", 4);
     486
     487        if (!(from = get_rfc822_header(parts[0], "From", 0))) {
     488                goto cleanup;
    494489        }
    495490
    496491        /* 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 
    505 static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd)
    506 {
    507         char **parts = NULL;
    508         char *action = NULL;
    509         char *who = NULL;
    510         gboolean selfmessage = FALSE;
    511 
    512         parts = g_strsplit(msg, "\r\n\r\n", 4);
    513 
    514         if (!(who = msn_ns_parse_header_address(md, parts[0], "From"))) {
    515                 goto cleanup;
    516         }
    517 
    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         }
     492        semicolon = strchr(from, ';') ? : (from + strlen(from));
     493
     494        who = g_strndup(from + 2, semicolon - from - 2);
    525495
    526496        if ((strcmp(cmd[0], "SDG") == 0) && (action = get_rfc822_header(parts[2], "Message-Type", 0))) {
    527                 msn_ns_sdg(md, who, parts, action, selfmessage);
     497                msn_ns_sdg(md, who, parts, action);
    528498
    529499        } else if ((strcmp(cmd[0], "NFY") == 0) && (action = get_rfc822_header(parts[2], "Uri", 0))) {
     
    535505        g_strfreev(parts);
    536506        g_free(action);
     507        g_free(from);
    537508        g_free(who);
    538509}
    539510
    540 static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action, gboolean selfmessage)
     511static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action)
    541512{
    542513        struct im_connection *ic = md->ic;
    543514
    544         if (strcmp(action, "Control/Typing") == 0 && !selfmessage) {
     515        if (strcmp(action, "Control/Typing") == 0) {
    545516                imcb_buddy_typing(ic, who, OPT_TYPING);
    546517        } else if (strcmp(action, "Text") == 0) {
    547                 imcb_buddy_msg(ic, who, parts[3], selfmessage ? OPT_SELFMESSAGE : 0, 0);
     518                imcb_buddy_msg(ic, who, parts[3], 0, 0);
    548519        }
    549520}
     
    624595        } else {
    625596                imcb_error(ic, "Error during Passport authentication: %s", error);
    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                 }
     597                imc_logout(ic, TRUE);
    633598        }
    634599}
Note: See TracChangeset for help on using the changeset viewer.