im.pidgin.pidgin: c3509bf14bc4bd03cc7c631a2329b33df504a825

nosnilmot at pidgin.im nosnilmot at pidgin.im
Sat Oct 27 10:05:45 EDT 2007


-----------------------------------------------------------------
Revision: c3509bf14bc4bd03cc7c631a2329b33df504a825
Ancestor: 20395453ab17cd8dd060d4d0794affda17e3272f
Author: nosnilmot at pidgin.im
Date: 2007-10-27T13:12:27
Branch: im.pidgin.pidgin

Modified files:
        libpurple/protocols/simple/simple.c
        libpurple/protocols/simple/simple.h
        libpurple/protocols/simple/sipmsg.c
        libpurple/protocols/simple/sipmsg.h

ChangeLog: 

Some constification, which also found and fixed some potential double-free
errors.

-------------- next part --------------
============================================================
--- libpurple/protocols/simple/simple.c	2051c619d9b03815a99dca8d02d460cd9147bada
+++ libpurple/protocols/simple/simple.c	f7a13081f5248fe20c7a1abccf2920067309f7ad
@@ -321,7 +321,7 @@ static char *parse_attribute(const char 
 	return retval;
 }
 
-static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) {
+static void fill_auth(struct simple_account_data *sip, const gchar *hdr, struct sip_auth *auth) {
 	int i = 0;
 	const char *authuser;
 	char *tmp;
@@ -592,7 +592,7 @@ static struct transaction *transactions_
 static struct transaction *transactions_find(struct simple_account_data *sip, struct sipmsg *msg) {
 	struct transaction *trans;
 	GSList *transactions = sip->transactions;
-	gchar *cseq = sipmsg_find_header(msg, "CSeq");
+	const gchar *cseq = sipmsg_find_header(msg, "CSeq");
 
 	if (cseq) {
 		while(transactions) {
@@ -800,7 +800,7 @@ static gboolean simple_add_lcs_contacts(
 }
 
 static gboolean simple_add_lcs_contacts(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
-	gchar *tmp;
+	const gchar *tmp;
 	xmlnode *item, *group, *isc;
 	const char *name_group;
 	PurpleBuddy *b;
@@ -960,7 +960,7 @@ static void process_incoming_message(str
 
 static void process_incoming_message(struct simple_account_data *sip, struct sipmsg *msg) {
 	gchar *from;
-	gchar *contenttype;
+	const gchar *contenttype;
 	gboolean found = FALSE;
 
 	from = parse_from(sipmsg_find_header(msg, "From"));
@@ -1015,7 +1015,7 @@ gboolean process_register_response(struc
 
 
 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
-	gchar *tmp;
+	const gchar *tmp;
 	purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response);
 	switch (msg->response) {
 		case 200:
@@ -1072,7 +1072,7 @@ static void process_incoming_notify(stru
 
 static void process_incoming_notify(struct simple_account_data *sip, struct sipmsg *msg) {
 	gchar *from;
-	gchar *fromhdr;
+	const gchar *fromhdr;
 	gchar *basicstatus_data;
 	xmlnode *pidf;
 	xmlnode *basicstatus = NULL, *tuple, *status;
@@ -1255,8 +1255,8 @@ static void process_incoming_subscribe(s
 	gchar *theirtag = find_tag(from_hdr);
 	gchar *ourtag = find_tag(sipmsg_find_header(msg, "To"));
 	gboolean tagadded = FALSE;
-	gchar *callid = sipmsg_find_header(msg, "Call-ID");
-	gchar *expire = sipmsg_find_header(msg, "Expire");
+	const gchar *callid = sipmsg_find_header(msg, "Call-ID");
+	const gchar *expire = sipmsg_find_header(msg, "Expire");
 	gchar *tmp;
 	struct simple_watcher *watcher = watcher_find(sip, from);
 	if(!ourtag) {
@@ -1264,14 +1264,14 @@ static void process_incoming_subscribe(s
 		ourtag = gentag();
 	}
 	if(!watcher) { /* new subscription */
-		gchar *acceptheader = sipmsg_find_header(msg, "Accept");
+		const gchar *acceptheader = sipmsg_find_header(msg, "Accept");
 		gboolean needsxpidf = FALSE;
 		if(!purple_privacy_check(sip->account, from)) {
 			send_sip_response(sip->gc, msg, 202, "Ok", NULL);
 			goto privend;
 		}
 		if(acceptheader) {
-			gchar *tmp = acceptheader;
+			const gchar *tmp = acceptheader;
 			gboolean foundpidf = FALSE;
 			gboolean foundxpidf = FALSE;
 			while(tmp && tmp < acceptheader + strlen(acceptheader)) {
@@ -1289,7 +1289,6 @@ static void process_incoming_subscribe(s
 					tmp = 0;
 			}
 			if(!foundpidf && foundxpidf) needsxpidf = TRUE;
-			g_free(acceptheader);
 		}
 		watcher = watcher_create(sip, from, callid, ourtag, theirtag, needsxpidf);
 	}
@@ -1314,8 +1313,6 @@ privend:
 	g_free(from);
 	g_free(theirtag);
 	g_free(ourtag);
-	g_free(callid);
-	g_free(expire);
 }
 
 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) {
@@ -1337,7 +1334,8 @@ static void process_input_message(struct
 		struct transaction *trans = transactions_find(sip, msg);
 		if(trans) {
 			if(msg->response == 407) {
-				gchar *resend, *auth, *ptmp;
+				gchar *resend, *auth;
+				const gchar *ptmp;
 
 				if(sip->proxy.retries > 3) return;
 				sip->proxy.retries++;
@@ -1381,7 +1379,8 @@ static void process_input_message(struct
 							/* This is encountered when a generic (MESSAGE, NOTIFY, etc)
 							 * was denied until further authorization is provided.
 							 */
-							gchar *resend, *auth, *ptmp;
+							gchar *resend, *auth;
+							const gchar *ptmp;
 
 							if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) return;
 							sip->registrar.retries++;
============================================================
--- libpurple/protocols/simple/simple.h	502d503c44e90e5b9c7f9591401936247c4d1353
+++ libpurple/protocols/simple/simple.h	fd2b60ab061bbb8ca0851d34124fcccb75d17113
@@ -127,7 +127,7 @@ struct transaction {
 	int retries;
 	int transport; /* 0 = tcp, 1 = udp */
 	int fd;
-	gchar *cseq;
+	const gchar *cseq;
 	struct sipmsg *msg;
 	TransCallback callback;
 };
============================================================
--- libpurple/protocols/simple/sipmsg.c	83bb87bf8d3fe9639e9ffbfe82fd797b206b1a6e
+++ libpurple/protocols/simple/sipmsg.c	60021dd8200e0ea65ee3e0c9a4db915fa96176be
@@ -58,6 +58,7 @@ struct sipmsg *sipmsg_parse_header(const
 	gchar *dummy;
 	gchar *dummy2;
 	gchar *tmp;
+	const gchar *tmp2;
 	int i=1;
 	if(!lines[0]) return NULL;
 	parts = g_strsplit(lines[0], " ", 3);
@@ -100,14 +101,16 @@ struct sipmsg *sipmsg_parse_header(const
 		g_strfreev(parts);
 	}
 	g_strfreev(lines);
-	msg->bodylen = strtol(sipmsg_find_header(msg, "Content-Length"),NULL,10);
+	tmp2 = sipmsg_find_header(msg, "Content-Length");
+	if (tmp2 != NULL)
+		msg->bodylen = strtol(tmp2, NULL, 10);
 	if(msg->response) {
-		tmp = sipmsg_find_header(msg, "CSeq");
-		if(!tmp) {
+		tmp2 = sipmsg_find_header(msg, "CSeq");
+		if(!tmp2) {
 			/* SHOULD NOT HAPPEN */
 			msg->method = 0;
 		} else {
-			parts = g_strsplit(tmp, " ", 2);
+			parts = g_strsplit(tmp2, " ", 2);
 			msg->method = g_strdup(parts[1]);
 			g_strfreev(parts);
 		}
@@ -192,7 +195,7 @@ void sipmsg_remove_header(struct sipmsg 
 	return;
 }
 
-gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name) {
+const gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name) {
 	GSList *tmp;
 	struct siphdrelement *elem;
 	tmp = msg->headers;
============================================================
--- libpurple/protocols/simple/sipmsg.h	f1a413086a51e2c5fea2f3a3ffe647a65d4d185b
+++ libpurple/protocols/simple/sipmsg.h	feb4377691f964e3a45fffd6d4f13141ea9d1251
@@ -43,7 +43,7 @@ void sipmsg_free(struct sipmsg *msg);
 struct sipmsg *sipmsg_parse_header(const gchar *header);
 void sipmsg_add_header(struct sipmsg *msg, const gchar *name, const gchar *value);
 void sipmsg_free(struct sipmsg *msg);
-gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name);
+const gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name);
 void sipmsg_remove_header(struct sipmsg *msg, const gchar *name);
 void sipmsg_print(const struct sipmsg *msg);
 char *sipmsg_to_string(const struct sipmsg *msg);


More information about the Commits mailing list