diff options
author | dequis <dx@dxzone.com.ar> | 2015-03-09 07:14:58 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-04-10 14:10:40 -0300 |
commit | d80822c66f79471bc2e12167a14611dd3c49da65 (patch) | |
tree | 5f8013dd11dbe463368cc29c3e05a780b7a33ef3 | |
parent | 11e42dcf7366ee547b9651648724d35d12e36091 (diff) |
msn: implement PUT /user to set status as online
-rw-r--r-- | protocols/msn/msn.c | 43 | ||||
-rw-r--r-- | protocols/msn/msn.h | 25 | ||||
-rw-r--r-- | protocols/msn/msn_util.c | 11 |
3 files changed, 42 insertions, 37 deletions
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index c1b5ce77..a2f13104 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -177,8 +177,8 @@ static GList *msn_away_states(struct im_connection *ic) static void msn_set_away(struct im_connection *ic, char *state, char *message) { - //char *uux; struct msn_data *md = ic->proto_data; + char *nick, *psm, *idle, *statecode, *body, *buf; if (state == NULL) { md->away_state = msn_away_state_list; @@ -186,32 +186,23 @@ static void msn_set_away(struct im_connection *ic, char *state, char *message) md->away_state = msn_away_state_list + 1; } - if (!msn_ns_write(ic, -1, "CHG %d %s %d:%02d\r\n", ++md->trId, md->away_state->code, MSN_CAP1, MSN_CAP2)) { - return; - } + statecode = (char *) md->away_state->code; + nick = set_getstr(&ic->acc->set, "display_name"); + psm = message ? message : ""; + idle = strcmp(statecode, "IDL") ? "false" : "true"; + + body = g_markup_printf_escaped(MSN_PUT_USER_BODY, + nick, psm, psm, md->uuid, statecode, md->uuid, idle, statecode, + MSN_CAP1, MSN_CAP2, MSN_CAP1, MSN_CAP2 + ); + + buf = g_strdup_printf(MSN_PUT_HEADERS, ic->acc->user, ic->acc->user, md->uuid, + "/user", "application/user+xml", + strlen(body), body); + msn_ns_write(ic, -1, "PUT %d %zd\r\n%s", ++md->trId, strlen(buf), buf); - uux = g_markup_printf_escaped("<EndpointData><Capabilities>%d:%02d" - "</Capabilities></EndpointData>", - MSN_CAP1, MSN_CAP2); - msn_ns_write(ic, -1, "UUX %d %zd\r\n%s", ++md->trId, strlen(uux), uux); - g_free(uux); - - uux = g_markup_printf_escaped("<PrivateEndpointData><EpName>%s</EpName>" - "<Idle>%s</Idle><ClientType>%d</ClientType>" - "<State>%s</State></PrivateEndpointData>", - md->uuid, - strcmp(md->away_state->code, "IDL") ? "false" : "true", - 1, /* ? */ - md->away_state->code); - msn_ns_write(ic, -1, "UUX %d %zd\r\n%s", ++md->trId, strlen(uux), uux); - g_free(uux); - - uux = g_markup_printf_escaped("<Data><DDP></DDP><PSM>%s</PSM>" - "<CurrentMedia></CurrentMedia>" - "<MachineGuid>%s</MachineGuid></Data>", - message ? message : "", md->uuid); - msn_ns_write(ic, -1, "UUX %d %zd\r\n%s", ++md->trId, strlen(uux), uux); - g_free(uux); + g_free(buf); + g_free(body); } static void msn_get_info(struct im_connection *ic, char *who) diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index 3827c992..c4517b78 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -66,13 +66,15 @@ #define MSN_CAP1 0xC000 #define MSN_CAP2 0x0000 -#define MSN_MESSAGE_HEADERS \ +#define MSN_BASE_HEADERS \ "Routing: 1.0\r\n" \ "To: 1:%s\r\n" \ "From: 1:%s;epid={%s}\r\n" \ "\r\n" \ "Reliability: 1.0\r\n" \ - "\r\n" \ + "\r\n" + +#define MSN_MESSAGE_HEADERS MSN_BASE_HEADERS \ "Messaging: 2.0\r\n" \ "Message-Type: Text\r\n" \ "Content-Length: %zd\r\n" \ @@ -81,6 +83,25 @@ "\r\n" \ "%s" +#define MSN_PUT_HEADERS MSN_BASE_HEADERS \ + "Publication: 1.0\r\n" \ + "Uri: %s\r\n" \ + "Content-Type: %s\r\n" \ + "Content-Length: %zd\r\n" \ + "\r\n" \ + "%s" + +#define MSN_PUT_USER_BODY \ + "<user>" \ + "<s n=\"PE\"><UserTileLocation></UserTileLocation><FriendlyName>%s</FriendlyName><PSM>%s</PSM><DDP></DDP>" \ + "<Scene></Scene><ASN></ASN><ColorScheme>-3</ColorScheme><BDG></BDG><RUM>%s</RUM><RUL></RUL><RLT>0</RLT>" \ + "<RID></RID><SUL></SUL><MachineGuid>%s</MachineGuid></s>" \ + "<s n=\"IM\"><Status>%s</Status><CurrentMedia></CurrentMedia></s>" \ + "<sep n=\"PD\"><ClientType>1</ClientType><EpName>%s</EpName><Idle>%s</Idle><State>%s</State></sep>" \ + "<sep n=\"PE\"><VER>BitlBee:" BITLBEE_VERSION "</VER><TYP>1</TYP><Capabilities>%d:%d</Capabilities></sep>" \ + "<sep n=\"IM\"><Capabilities>%d:%d</Capabilities></sep>" \ + "</user>" + #define MSN_TYPING_HEADERS "MIME-Version: 1.0\r\n" \ "Content-Type: text/x-msmsgscontrol\r\n" \ "TypingUser: %s\r\n" \ diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 43256a2a..c5832b1b 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -537,15 +537,8 @@ struct msn_group *msn_group_by_id(struct im_connection *ic, const char *id) int msn_ns_set_display_name(struct im_connection *ic, const char *value) { - struct msn_data *md = ic->proto_data; - char fn[strlen(value) * 3 + 1]; - - strcpy(fn, value); - http_encode(fn); - - /* Note: We don't actually know if the server accepted the new name, - and won't give proper feedback yet if it doesn't. */ - return msn_ns_write(ic, -1, "PRP %d MFN %s\r\n", ++md->trId, fn); + // TODO, implement this through msn_set_away's method + return 1; } const char *msn_normalize_handle(const char *handle) |