Mercurial > pidgin
changeset 20913:b8e8b7dba8e0
Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sat, 13 Oct 2007 16:26:09 +0000 |
parents | 54d232b52607 |
children | 74ec24deb267 |
files | libpurple/protocols/simple/simple.c |
diffstat | 1 files changed, 30 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/simple/simple.c Fri Oct 12 22:26:44 2007 +0000 +++ b/libpurple/protocols/simple/simple.c Sat Oct 13 16:26:09 2007 +0000 @@ -80,14 +80,15 @@ static gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc); static void send_notify(struct simple_account_data *sip, struct simple_watcher *); -static void send_publish(struct simple_account_data *sip); +static void send_open_publish(struct simple_account_data *sip); +static void send_closed_publish(struct simple_account_data *sip); static void do_notifies(struct simple_account_data *sip) { GSList *tmp = sip->watcher; purple_debug_info("simple", "do_notifies()\n"); if((sip->republish != -1) || sip->republish < time(NULL)) { if(purple_account_get_bool(sip->account, "dopublish", TRUE)) { - send_publish(sip); + send_open_publish(sip); } } @@ -1020,7 +1021,7 @@ case 200: if(sip->registerstatus < SIMPLE_REGISTER_COMPLETE) { /* registered */ if(purple_account_get_bool(sip->account, "dopublish", TRUE)) { - send_publish(sip); + send_open_publish(sip); } } sip->registerstatus = SIMPLE_REGISTER_COMPLETE; @@ -1188,28 +1189,27 @@ return doc; } - - -static gchar* gen_pidf(struct simple_account_data *sip) { +static gchar* gen_pidf(struct simple_account_data *sip, gboolean open) { gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n" "xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"\n" "entity=\"sip:%s@%s\">\n" "<tuple id=\"bs35r9f\">\n" "<status>\n" - "<basic>open</basic>\n" + "<basic>%s</basic>\n" "</status>\n" "<note>%s</note>\n" "</tuple>\n" "</presence>", sip->username, sip->servername, - sip->status); + (open == TRUE) ? "open" : "closed", + (open == TRUE) ? sip->status : ""); return doc; } static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) { - gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip); + gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip, TRUE); gchar *hdr = watcher->needsxpidf ? "Event: presence\r\nContent-Type: application/xpidf+xml\r\n" : "Event: presence\r\nContent-Type: application/pidf+xml\r\n"; send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL); g_free(doc); @@ -1223,9 +1223,9 @@ return TRUE; } -static void send_publish(struct simple_account_data *sip) { +static void send_open_publish(struct simple_account_data *sip) { gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); - gchar *doc = gen_pidf(sip); + gchar *doc = gen_pidf(sip, TRUE); send_sip_request(sip->gc, "PUBLISH", uri, uri, "Expires: 600\r\nEvent: presence\r\n" "Content-Type: application/pidf+xml\r\n", @@ -1235,6 +1235,18 @@ g_free(doc); } +static void send_closed_publish(struct simple_account_data *sip) { + gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); + gchar *doc = gen_pidf(sip, FALSE); + send_sip_request(sip->gc, "PUBLISH", uri, uri, + "Expires: 600\r\nEvent: presence\r\n" + "Content-Type: application/pidf+xml\r\n", + doc, NULL, process_publish_response); + /*sip->republish = time(NULL) + 500;*/ + g_free(uri); + g_free(doc); +} + static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) { const char *from_hdr = sipmsg_find_header(msg, "From"); gchar *from = parse_from(from_hdr); @@ -1738,7 +1750,14 @@ if(sip) { /* unregister */ if (sip->registerstatus == SIMPLE_REGISTER_COMPLETE) + { + if(purple_account_get_bool(sip->account, + "dopublish", + TRUE)) + send_closed_publish(sip); + do_register_exp(sip, 0); + } connection_free_all(sip); if (sip->query_data != NULL)