Mercurial > pidgin.yaz
comparison libpurple/protocols/simple/simple.c @ 20345:9acf4a2ef166
applied changes from e9e74094baa29c6f5589385507221a2502b817fb
through ca09db83bd2ae802d4a6d7078a1efdfe9a896cb5
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 21 Oct 2007 04:42:58 +0000 |
parents | 6e93a79b2ae5 |
children | 07c2e60026da |
comparison
equal
deleted
inserted
replaced
20344:b81af0bef062 | 20345:9acf4a2ef166 |
---|---|
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 |
1184 sip->servername, | 1185 sip->servername, |
1185 sip->status); | 1186 sip->status); |
1186 return doc; | 1187 return doc; |
1187 } | 1188 } |
1188 | 1189 |
1189 | 1190 static gchar* gen_pidf(struct simple_account_data *sip, gboolean open) { |
1190 | |
1191 static gchar* gen_pidf(struct simple_account_data *sip) { | |
1192 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | 1191 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
1193 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n" | 1192 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n" |
1194 "xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"\n" | 1193 "xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"\n" |
1195 "entity=\"sip:%s@%s\">\n" | 1194 "entity=\"sip:%s@%s\">\n" |
1196 "<tuple id=\"bs35r9f\">\n" | 1195 "<tuple id=\"bs35r9f\">\n" |
1197 "<status>\n" | 1196 "<status>\n" |
1198 "<basic>open</basic>\n" | 1197 "<basic>%s</basic>\n" |
1199 "</status>\n" | 1198 "</status>\n" |
1200 "<note>%s</note>\n" | 1199 "<note>%s</note>\n" |
1201 "</tuple>\n" | 1200 "</tuple>\n" |
1202 "</presence>", | 1201 "</presence>", |
1203 sip->username, | 1202 sip->username, |
1204 sip->servername, | 1203 sip->servername, |
1205 sip->status); | 1204 (open == TRUE) ? "open" : "closed", |
1205 (open == TRUE) ? sip->status : ""); | |
1206 return doc; | 1206 return doc; |
1207 } | 1207 } |
1208 | 1208 |
1209 static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) { | 1209 static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) { |
1210 gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip); | 1210 gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip, TRUE); |
1211 gchar *hdr = watcher->needsxpidf ? "Event: presence\r\nContent-Type: application/xpidf+xml\r\n" : "Event: presence\r\nContent-Type: application/pidf+xml\r\n"; | 1211 gchar *hdr = watcher->needsxpidf ? "Event: presence\r\nContent-Type: application/xpidf+xml\r\n" : "Event: presence\r\nContent-Type: application/pidf+xml\r\n"; |
1212 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL); | 1212 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL); |
1213 g_free(doc); | 1213 g_free(doc); |
1214 } | 1214 } |
1215 | 1215 |
1219 sip->republish = -1; | 1219 sip->republish = -1; |
1220 } | 1220 } |
1221 return TRUE; | 1221 return TRUE; |
1222 } | 1222 } |
1223 | 1223 |
1224 static void send_publish(struct simple_account_data *sip) { | 1224 static void send_open_publish(struct simple_account_data *sip) { |
1225 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); | 1225 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); |
1226 gchar *doc = gen_pidf(sip); | 1226 gchar *doc = gen_pidf(sip, TRUE); |
1227 send_sip_request(sip->gc, "PUBLISH", uri, uri, | 1227 send_sip_request(sip->gc, "PUBLISH", uri, uri, |
1228 "Expires: 600\r\nEvent: presence\r\n" | 1228 "Expires: 600\r\nEvent: presence\r\n" |
1229 "Content-Type: application/pidf+xml\r\n", | 1229 "Content-Type: application/pidf+xml\r\n", |
1230 doc, NULL, process_publish_response); | 1230 doc, NULL, process_publish_response); |
1231 sip->republish = time(NULL) + 500; | 1231 sip->republish = time(NULL) + 500; |
1232 g_free(uri); | |
1233 g_free(doc); | |
1234 } | |
1235 | |
1236 static void send_closed_publish(struct simple_account_data *sip) { | |
1237 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); | |
1238 gchar *doc = gen_pidf(sip, FALSE); | |
1239 send_sip_request(sip->gc, "PUBLISH", uri, uri, | |
1240 "Expires: 600\r\nEvent: presence\r\n" | |
1241 "Content-Type: application/pidf+xml\r\n", | |
1242 doc, NULL, process_publish_response); | |
1243 /*sip->republish = time(NULL) + 500;*/ | |
1232 g_free(uri); | 1244 g_free(uri); |
1233 g_free(doc); | 1245 g_free(doc); |
1234 } | 1246 } |
1235 | 1247 |
1236 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) { | 1248 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) { |
1734 struct simple_account_data *sip = gc->proto_data; | 1746 struct simple_account_data *sip = gc->proto_data; |
1735 | 1747 |
1736 if(sip) { | 1748 if(sip) { |
1737 /* unregister */ | 1749 /* unregister */ |
1738 if (sip->registerstatus == SIMPLE_REGISTER_COMPLETE) | 1750 if (sip->registerstatus == SIMPLE_REGISTER_COMPLETE) |
1751 { | |
1752 if(purple_account_get_bool(sip->account, | |
1753 "dopublish", | |
1754 TRUE)) | |
1755 send_closed_publish(sip); | |
1756 | |
1739 do_register_exp(sip, 0); | 1757 do_register_exp(sip, 0); |
1758 } | |
1740 connection_free_all(sip); | 1759 connection_free_all(sip); |
1741 | 1760 |
1742 if (sip->query_data != NULL) | 1761 if (sip->query_data != NULL) |
1743 purple_dnsquery_destroy(sip->query_data); | 1762 purple_dnsquery_destroy(sip->query_data); |
1744 | 1763 |