comparison libpurple/protocols/simple/simple.c @ 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 5723dbc6212d
children 74ec24deb267
comparison
equal deleted inserted replaced
20910:54d232b52607 20913:b8e8b7dba8e0
78 } 78 }
79 79
80 static gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc); 80 static gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc);
81 static void send_notify(struct simple_account_data *sip, struct simple_watcher *); 81 static void send_notify(struct simple_account_data *sip, struct simple_watcher *);
82 82
83 static void send_publish(struct simple_account_data *sip); 83 static void send_open_publish(struct simple_account_data *sip);
84 static void send_closed_publish(struct simple_account_data *sip);
84 85
85 static void do_notifies(struct simple_account_data *sip) { 86 static void do_notifies(struct simple_account_data *sip) {
86 GSList *tmp = sip->watcher; 87 GSList *tmp = sip->watcher;
87 purple_debug_info("simple", "do_notifies()\n"); 88 purple_debug_info("simple", "do_notifies()\n");
88 if((sip->republish != -1) || sip->republish < time(NULL)) { 89 if((sip->republish != -1) || sip->republish < time(NULL)) {
89 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) { 90 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) {
90 send_publish(sip); 91 send_open_publish(sip);
91 } 92 }
92 } 93 }
93 94
94 while(tmp) { 95 while(tmp) {
95 purple_debug_info("simple", "notifying %s\n", ((struct simple_watcher*)tmp->data)->name); 96 purple_debug_info("simple", "notifying %s\n", ((struct simple_watcher*)tmp->data)->name);
1018 purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); 1019 purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response);
1019 switch (msg->response) { 1020 switch (msg->response) {
1020 case 200: 1021 case 200:
1021 if(sip->registerstatus < SIMPLE_REGISTER_COMPLETE) { /* registered */ 1022 if(sip->registerstatus < SIMPLE_REGISTER_COMPLETE) { /* registered */
1022 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) { 1023 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) {
1023 send_publish(sip); 1024 send_open_publish(sip);
1024 } 1025 }
1025 } 1026 }
1026 sip->registerstatus = SIMPLE_REGISTER_COMPLETE; 1027 sip->registerstatus = SIMPLE_REGISTER_COMPLETE;
1027 purple_connection_set_state(sip->gc, PURPLE_CONNECTED); 1028 purple_connection_set_state(sip->gc, PURPLE_CONNECTED);
1028 1029
1186 sip->servername, 1187 sip->servername,
1187 sip->status); 1188 sip->status);
1188 return doc; 1189 return doc;
1189 } 1190 }
1190 1191
1191 1192 static gchar* gen_pidf(struct simple_account_data *sip, gboolean open) {
1192
1193 static gchar* gen_pidf(struct simple_account_data *sip) {
1194 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 1193 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1195 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n" 1194 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n"
1196 "xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"\n" 1195 "xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"\n"
1197 "entity=\"sip:%s@%s\">\n" 1196 "entity=\"sip:%s@%s\">\n"
1198 "<tuple id=\"bs35r9f\">\n" 1197 "<tuple id=\"bs35r9f\">\n"
1199 "<status>\n" 1198 "<status>\n"
1200 "<basic>open</basic>\n" 1199 "<basic>%s</basic>\n"
1201 "</status>\n" 1200 "</status>\n"
1202 "<note>%s</note>\n" 1201 "<note>%s</note>\n"
1203 "</tuple>\n" 1202 "</tuple>\n"
1204 "</presence>", 1203 "</presence>",
1205 sip->username, 1204 sip->username,
1206 sip->servername, 1205 sip->servername,
1207 sip->status); 1206 (open == TRUE) ? "open" : "closed",
1207 (open == TRUE) ? sip->status : "");
1208 return doc; 1208 return doc;
1209 } 1209 }
1210 1210
1211 static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) { 1211 static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) {
1212 gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip); 1212 gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip, TRUE);
1213 gchar *hdr = watcher->needsxpidf ? "Event: presence\r\nContent-Type: application/xpidf+xml\r\n" : "Event: presence\r\nContent-Type: application/pidf+xml\r\n"; 1213 gchar *hdr = watcher->needsxpidf ? "Event: presence\r\nContent-Type: application/xpidf+xml\r\n" : "Event: presence\r\nContent-Type: application/pidf+xml\r\n";
1214 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL); 1214 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL);
1215 g_free(doc); 1215 g_free(doc);
1216 } 1216 }
1217 1217
1221 sip->republish = -1; 1221 sip->republish = -1;
1222 } 1222 }
1223 return TRUE; 1223 return TRUE;
1224 } 1224 }
1225 1225
1226 static void send_publish(struct simple_account_data *sip) { 1226 static void send_open_publish(struct simple_account_data *sip) {
1227 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); 1227 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
1228 gchar *doc = gen_pidf(sip); 1228 gchar *doc = gen_pidf(sip, TRUE);
1229 send_sip_request(sip->gc, "PUBLISH", uri, uri, 1229 send_sip_request(sip->gc, "PUBLISH", uri, uri,
1230 "Expires: 600\r\nEvent: presence\r\n" 1230 "Expires: 600\r\nEvent: presence\r\n"
1231 "Content-Type: application/pidf+xml\r\n", 1231 "Content-Type: application/pidf+xml\r\n",
1232 doc, NULL, process_publish_response); 1232 doc, NULL, process_publish_response);
1233 sip->republish = time(NULL) + 500; 1233 sip->republish = time(NULL) + 500;
1234 g_free(uri);
1235 g_free(doc);
1236 }
1237
1238 static void send_closed_publish(struct simple_account_data *sip) {
1239 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
1240 gchar *doc = gen_pidf(sip, FALSE);
1241 send_sip_request(sip->gc, "PUBLISH", uri, uri,
1242 "Expires: 600\r\nEvent: presence\r\n"
1243 "Content-Type: application/pidf+xml\r\n",
1244 doc, NULL, process_publish_response);
1245 /*sip->republish = time(NULL) + 500;*/
1234 g_free(uri); 1246 g_free(uri);
1235 g_free(doc); 1247 g_free(doc);
1236 } 1248 }
1237 1249
1238 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) { 1250 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) {
1736 struct simple_account_data *sip = gc->proto_data; 1748 struct simple_account_data *sip = gc->proto_data;
1737 1749
1738 if(sip) { 1750 if(sip) {
1739 /* unregister */ 1751 /* unregister */
1740 if (sip->registerstatus == SIMPLE_REGISTER_COMPLETE) 1752 if (sip->registerstatus == SIMPLE_REGISTER_COMPLETE)
1753 {
1754 if(purple_account_get_bool(sip->account,
1755 "dopublish",
1756 TRUE))
1757 send_closed_publish(sip);
1758
1741 do_register_exp(sip, 0); 1759 do_register_exp(sip, 0);
1760 }
1742 connection_free_all(sip); 1761 connection_free_all(sip);
1743 1762
1744 if (sip->query_data != NULL) 1763 if (sip->query_data != NULL)
1745 purple_dnsquery_destroy(sip->query_data); 1764 purple_dnsquery_destroy(sip->query_data);
1746 1765