Changeset 884577f


Ignore:
Timestamp:
2015-10-30T10:28:32Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0edc2fb
Parents:
fb2338d
git-author:
dequis <dx@…> (13-09-15 04:57:25)
git-committer:
dequis <dx@…> (30-10-15 10:28:32)
Message:

MSN: self message support

This is straightforward, like receiving a message with From/To swapped

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/ns.c

    rfb2338d r884577f  
    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
     
    475475}
    476476
     477/* returns newly allocated string */
     478static char *msn_ns_parse_header_address(struct msn_data *md, char *headers, char *header_name)
     479{
     480        char *semicolon = NULL;
     481        char *header = NULL;
     482        char *address = NULL;
     483
     484        if (!(header = get_rfc822_header(headers, header_name, 0))) {
     485                return NULL;
     486        }
     487
     488        /* either the semicolon or the end of the string */
     489        semicolon = strchr(header, ';') ? : (header + strlen(header));
     490
     491        address = g_strndup(header + 2, semicolon - header - 2);
     492
     493        g_free(header);
     494        return address;
     495}
     496
    477497static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd)
    478498{
    479499        char **parts = NULL;
    480         char *semicolon = NULL;
    481500        char *action = NULL;
    482         char *from = NULL;
    483501        char *who = NULL;
     502        gboolean selfmessage = FALSE;
    484503
    485504        parts = g_strsplit(msg, "\r\n\r\n", 4);
    486505
    487         if (!(from = get_rfc822_header(parts[0], "From", 0))) {
     506        if (!(who = msn_ns_parse_header_address(md, parts[0], "From"))) {
    488507                goto cleanup;
    489508        }
    490509
    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);
     510        if (strcmp(who, md->ic->acc->user) == 0) {
     511                selfmessage = TRUE;
     512                g_free(who);
     513                if (!(who = msn_ns_parse_header_address(md, parts[0], "To"))) {
     514                        goto cleanup;
     515                }
     516        }
    495517
    496518        if ((strcmp(cmd[0], "SDG") == 0) && (action = get_rfc822_header(parts[2], "Message-Type", 0))) {
    497                 msn_ns_sdg(md, who, parts, action);
     519                msn_ns_sdg(md, who, parts, action, selfmessage);
    498520
    499521        } else if ((strcmp(cmd[0], "NFY") == 0) && (action = get_rfc822_header(parts[2], "Uri", 0))) {
     
    505527        g_strfreev(parts);
    506528        g_free(action);
    507         g_free(from);
    508529        g_free(who);
    509530}
    510531
    511 static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action)
     532static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action, gboolean selfmessage)
    512533{
    513534        struct im_connection *ic = md->ic;
    514535
    515         if (strcmp(action, "Control/Typing") == 0) {
     536        if (strcmp(action, "Control/Typing") == 0 && !selfmessage) {
    516537                imcb_buddy_typing(ic, who, OPT_TYPING);
    517538        } else if (strcmp(action, "Text") == 0) {
    518                 imcb_buddy_msg(ic, who, parts[3], 0, 0);
     539                imcb_buddy_msg(ic, who, parts[3], selfmessage ? OPT_SELFMESSAGE : 0, 0);
    519540        }
    520541}
Note: See TracChangeset for help on using the changeset viewer.