changeset 21024:61a87e02da29

Some constification, which also found and fixed some potential double-free errors.
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 27 Oct 2007 13:12:27 +0000
parents 3f8b32a4786c
children 77a35a382a73 27c72bd82a81
files libpurple/protocols/simple/simple.c libpurple/protocols/simple/simple.h libpurple/protocols/simple/sipmsg.c libpurple/protocols/simple/sipmsg.h
diffstat 4 files changed, 24 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/simple/simple.c	Fri Oct 26 13:22:49 2007 +0000
+++ b/libpurple/protocols/simple/simple.c	Sat Oct 27 13:12:27 2007 +0000
@@ -321,7 +321,7 @@
 	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_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(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(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(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(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 @@
 	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 @@
 		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 @@
 					tmp = 0;
 			}
 			if(!foundpidf && foundxpidf) needsxpidf = TRUE;
-			g_free(acceptheader);
 		}
 		watcher = watcher_create(sip, from, callid, ourtag, theirtag, needsxpidf);
 	}
@@ -1314,8 +1313,6 @@
 	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 @@
 		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 @@
 							/* 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++;
--- a/libpurple/protocols/simple/simple.h	Fri Oct 26 13:22:49 2007 +0000
+++ b/libpurple/protocols/simple/simple.h	Sat Oct 27 13:12:27 2007 +0000
@@ -127,7 +127,7 @@
 	int retries;
 	int transport; /* 0 = tcp, 1 = udp */
 	int fd;
-	gchar *cseq;
+	const gchar *cseq;
 	struct sipmsg *msg;
 	TransCallback callback;
 };
--- a/libpurple/protocols/simple/sipmsg.c	Fri Oct 26 13:22:49 2007 +0000
+++ b/libpurple/protocols/simple/sipmsg.c	Sat Oct 27 13:12:27 2007 +0000
@@ -58,6 +58,7 @@
 	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 @@
 		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 @@
 	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;
--- a/libpurple/protocols/simple/sipmsg.h	Fri Oct 26 13:22:49 2007 +0000
+++ b/libpurple/protocols/simple/sipmsg.h	Sat Oct 27 13:12:27 2007 +0000
@@ -43,7 +43,7 @@
 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);