[gaim-migrate @ 15090]

Fri, 06 Jan 2006 04:17:16 +0000

author
Daniel Atallah <datallah@pidgin.im>
date
Fri, 06 Jan 2006 04:17:16 +0000
changeset 12743
dfc698f04f77
parent 12742
88e624a344cb
child 12744
45d72d69f399

[gaim-migrate @ 15090]
similar clean up to use GString instead of allocating and freeing buffers every iteration. The same basic code is used in 3 places to do this, it probably should be consolidated.

src/protocols/simple/sipmsg.c file | annotate | diff | comparison | revisions
--- a/src/protocols/simple/sipmsg.c	Fri Jan 06 03:39:21 2006 +0000
+++ b/src/protocols/simple/sipmsg.c	Fri Jan 06 04:17:16 2006 +0000
@@ -125,30 +125,28 @@
 }
 
 char *sipmsg_to_string(struct sipmsg *msg) {
-	gchar *out;
-	gchar *old;
 	GSList *cur;
+	GString *outstr = g_string_new("");
 	struct siphdrelement *elem;
-	if(msg->response) out = g_strdup_printf("SIP/2.0 %d Unknown\r\n", msg->response);
-	else out = g_strdup_printf("%s %s SIP/2.0\r\n",msg->method, msg->target);
+
+	if(msg->response)
+		g_string_append_printf(outstr, "SIP/2.0 %d Unknown\r\n",
+			msg->response);
+	else
+		g_string_append_printf(outstr, "%s %s SIP/2.0\r\n",
+			msg->method, msg->target);
+
 	cur = msg->headers;
 	while(cur) {
 		elem = cur->data;
-		old = out;
-		out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value);
-		g_free(old);
+		g_string_append_printf(outstr, "%s: %s\r\n", elem->name,
+			elem->value);
 		cur = g_slist_next(cur);
 	}
-	old = out;
-	out = g_strdup_printf("%s\r\n",out);
-	g_free(old);
 
-	if(msg->bodylen) {
-		old = out;
-		out = g_strdup_printf("%s%s",out, msg->body);
-		g_free(old);
-	}
-	return out;
+	g_string_append_printf(outstr, "\r\n%s", msg->bodylen ? msg->body : "");
+
+	return g_string_free(outstr, FALSE);
 }
 void sipmsg_add_header(struct sipmsg *msg, gchar *name, gchar *value) {
 	struct siphdrelement *element = g_new0(struct siphdrelement,1);

mercurial