changeset 22061:5295c7f113da

Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 10 Jan 2008 20:24:58 +0000
parents fdebef95b300
children 786bf5f84ce7
files libpurple/protocols/simple/simple.c libpurple/protocols/simple/simple.h
diffstat 2 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/simple/simple.c	Thu Jan 10 02:28:48 2008 +0000
+++ b/libpurple/protocols/simple/simple.c	Thu Jan 10 20:24:58 2008 +0000
@@ -1356,10 +1356,21 @@
 }
 
 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
+
+	const gchar *etag = NULL;
+
 	if(msg->response != 200 && msg->response != 408) {
 		/* never send again */
 		sip->republish = -1;
 	}
+
+	etag = sipmsg_find_header(msg, "SIP-Etag");
+	if (etag) {
+		/* we must store the etag somewhere. */
+		g_free(sip->publish_etag);
+		sip->publish_etag = g_strdup(etag);
+	}
+
 	return TRUE;
 }
 
@@ -1368,10 +1379,12 @@
 	gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
 	gchar *doc = gen_pidf(sip, TRUE);
 
-	add_headers = g_strdup_printf("%s%d%s",
-		"Expires: ",
-		PUBLISH_EXPIRATION,
-		"\r\nEvent: presence\r\n"
+	add_headers = g_strdup_printf("%s%s%s%s%d\r\n%s",
+		sip->publish_etag ? "SIP-If-Match: " : "",
+		sip->publish_etag ? sip->publish_etag : "",
+		sip->publish_etag ? "\r\n" : "",
+		"Expires: ", PUBLISH_EXPIRATION,
+		"Event: presence\r\n"
 		"Content-Type: application/pidf+xml\r\n");
 
 	send_sip_request(sip->gc, "PUBLISH", uri, uri,
@@ -1384,14 +1397,23 @@
 
 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",
+	gchar *add_headers, *doc;
+
+	add_headers = g_strdup_printf("%s%s%s%s",
+		sip->publish_etag ? "SIP-If-Match: " : "",
+		sip->publish_etag ? sip->publish_etag : "",
+		sip->publish_etag ? "\r\n" : "",
+		"Expires: 600\r\n"
+		"Event: presence\r\n"
+		"Content-Type: application/pidf+xml\r\n");
+
+	doc = gen_pidf(sip, FALSE);
+	send_sip_request(sip->gc, "PUBLISH", uri, uri, add_headers,
 		doc, NULL, process_publish_response);
 	/*sip->republish = time(NULL) + 500;*/
 	g_free(uri);
 	g_free(doc);
+	g_free(add_headers);
 }
 
 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) {
@@ -1948,6 +1970,7 @@
 		g_free(sip->proxy.target);
 		g_free(sip->proxy.realm);
 		g_free(sip->proxy.digest_session_key);
+		g_free(sip->publish_etag);
 		if(sip->txbuf)
 			purple_circ_buffer_destroy(sip->txbuf);
 		g_free(sip->realhostname);
--- a/libpurple/protocols/simple/simple.h	Thu Jan 10 02:28:48 2008 +0000
+++ b/libpurple/protocols/simple/simple.h	Thu Jan 10 20:24:58 2008 +0000
@@ -112,6 +112,7 @@
 	int registerexpire;
 	gchar *realhostname;
 	int realport; /* port and hostname from SRV record */
+	gchar *publish_etag;
 };
 
 struct sip_connection {