Changeset 6e74911


Ignore:
Timestamp:
2015-03-15T14:41:47Z (9 years ago)
Author:
dequis <dx@…>
Children:
c5a1502
Parents:
ffa5b70
git-author:
dequis <dx@…> (09-03-15 10:14:58)
git-committer:
dequis <dx@…> (15-03-15 14:41:47)
Message:

msn: implement PUT /user to set status as online

Location:
protocols/msn
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    rffa5b70 r6e74911  
    178178static void msn_set_away(struct im_connection *ic, char *state, char *message)
    179179{
    180         //char *uux;
    181180        struct msn_data *md = ic->proto_data;
     181        char *nick, *psm, *idle, *statecode, *body, *buf;
    182182
    183183        if (state == NULL) {
     
    187187        }
    188188
    189         if (!msn_ns_write(ic, -1, "CHG %d %s %d:%02d\r\n", ++md->trId, md->away_state->code, MSN_CAP1, MSN_CAP2)) {
    190                 return;
    191         }
    192 
    193         uux = g_markup_printf_escaped("<EndpointData><Capabilities>%d:%02d"
    194                                       "</Capabilities></EndpointData>",
    195                                       MSN_CAP1, MSN_CAP2);
    196         msn_ns_write(ic, -1, "UUX %d %zd\r\n%s", ++md->trId, strlen(uux), uux);
    197         g_free(uux);
    198 
    199         uux = g_markup_printf_escaped("<PrivateEndpointData><EpName>%s</EpName>"
    200                                       "<Idle>%s</Idle><ClientType>%d</ClientType>"
    201                                       "<State>%s</State></PrivateEndpointData>",
    202                                       md->uuid,
    203                                       strcmp(md->away_state->code, "IDL") ? "false" : "true",
    204                                       1,  /* ? */
    205                                       md->away_state->code);
    206         msn_ns_write(ic, -1, "UUX %d %zd\r\n%s", ++md->trId, strlen(uux), uux);
    207         g_free(uux);
    208 
    209         uux = g_markup_printf_escaped("<Data><DDP></DDP><PSM>%s</PSM>"
    210                                       "<CurrentMedia></CurrentMedia>"
    211                                       "<MachineGuid>%s</MachineGuid></Data>",
    212                                       message ? message : "", md->uuid);
    213         msn_ns_write(ic, -1, "UUX %d %zd\r\n%s", ++md->trId, strlen(uux), uux);
    214         g_free(uux);
     189        statecode = (char *) md->away_state->code;
     190        nick = set_getstr(&ic->acc->set, "display_name");
     191        psm = message ? message : "";
     192        idle = strcmp(statecode, "IDL") ? "false" : "true";
     193
     194        body = g_markup_printf_escaped(MSN_PUT_USER_BODY,
     195                nick, psm, psm, md->uuid, statecode, md->uuid, idle, statecode,
     196                MSN_CAP1, MSN_CAP2, MSN_CAP1, MSN_CAP2
     197        );
     198
     199        buf = g_strdup_printf(MSN_PUT_HEADERS, ic->acc->user, ic->acc->user, md->uuid,
     200                "/user", "application/user+xml",
     201                strlen(body), body);
     202        msn_ns_write(ic, -1, "PUT %d %zd\r\n%s", ++md->trId, strlen(buf), buf);
     203
     204        g_free(buf);
     205        g_free(body);
    215206}
    216207
  • protocols/msn/msn.h

    rffa5b70 r6e74911  
    6767#define MSN_CAP2        0x0000
    6868
    69 #define MSN_MESSAGE_HEADERS \
     69#define MSN_BASE_HEADERS \
    7070        "Routing: 1.0\r\n" \
    7171        "To: 1:%s\r\n" \
     
    7373        "\r\n" \
    7474        "Reliability: 1.0\r\n" \
    75         "\r\n" \
     75        "\r\n"
     76
     77#define MSN_MESSAGE_HEADERS MSN_BASE_HEADERS \
    7678        "Messaging: 2.0\r\n" \
    7779        "Message-Type: Text\r\n" \
     
    8183        "\r\n" \
    8284        "%s"
     85
     86#define MSN_PUT_HEADERS MSN_BASE_HEADERS \
     87        "Publication: 1.0\r\n" \
     88        "Uri: %s\r\n" \
     89        "Content-Type: %s\r\n" \
     90        "Content-Length: %zd\r\n" \
     91        "\r\n" \
     92        "%s"
     93
     94#define MSN_PUT_USER_BODY \
     95        "<user>" \
     96        "<s n=\"PE\"><UserTileLocation></UserTileLocation><FriendlyName>%s</FriendlyName><PSM>%s</PSM><DDP></DDP>" \
     97        "<Scene></Scene><ASN></ASN><ColorScheme>-3</ColorScheme><BDG></BDG><RUM>%s</RUM><RUL></RUL><RLT>0</RLT>" \
     98        "<RID></RID><SUL></SUL><MachineGuid>%s</MachineGuid></s>" \
     99        "<s n=\"IM\"><Status>%s</Status><CurrentMedia></CurrentMedia></s>" \
     100        "<sep n=\"PD\"><ClientType>1</ClientType><EpName>%s</EpName><Idle>%s</Idle><State>%s</State></sep>" \
     101        "<sep n=\"PE\"><VER>BitlBee:" BITLBEE_VERSION "</VER><TYP>1</TYP><Capabilities>%d:%d</Capabilities></sep>" \
     102        "<sep n=\"IM\"><Capabilities>%d:%d</Capabilities></sep>" \
     103        "</user>"
    83104
    84105#define MSN_TYPING_HEADERS "MIME-Version: 1.0\r\n" \
  • protocols/msn/msn_util.c

    rffa5b70 r6e74911  
    532532int msn_ns_set_display_name(struct im_connection *ic, const char *value)
    533533{
    534         struct msn_data *md = ic->proto_data;
    535         char fn[strlen(value) * 3 + 1];
    536 
    537         strcpy(fn, value);
    538         http_encode(fn);
    539 
    540         /* Note: We don't actually know if the server accepted the new name,
    541            and won't give proper feedback yet if it doesn't. */
    542         return msn_ns_write(ic, -1, "PRP %d MFN %s\r\n", ++md->trId, fn);
     534        // TODO, implement this through msn_set_away's method
     535        return 1;
    543536}
    544537
Note: See TracChangeset for help on using the changeset viewer.