comparison src/protocols/simple/sipmsg.c @ 12743:33ed71b35a43

[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. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 06 Jan 2006 04:17:16 +0000
parents 2cf6d4cf2cb0
children b62d685cf841
comparison
equal deleted inserted replaced
12742:258871a62600 12743:33ed71b35a43
123 cur = g_slist_next(cur); 123 cur = g_slist_next(cur);
124 } 124 }
125 } 125 }
126 126
127 char *sipmsg_to_string(struct sipmsg *msg) { 127 char *sipmsg_to_string(struct sipmsg *msg) {
128 gchar *out;
129 gchar *old;
130 GSList *cur; 128 GSList *cur;
131 struct siphdrelement *elem; 129 GString *outstr = g_string_new("");
132 if(msg->response) out = g_strdup_printf("SIP/2.0 %d Unknown\r\n", msg->response); 130 struct siphdrelement *elem;
133 else out = g_strdup_printf("%s %s SIP/2.0\r\n",msg->method, msg->target); 131
132 if(msg->response)
133 g_string_append_printf(outstr, "SIP/2.0 %d Unknown\r\n",
134 msg->response);
135 else
136 g_string_append_printf(outstr, "%s %s SIP/2.0\r\n",
137 msg->method, msg->target);
138
134 cur = msg->headers; 139 cur = msg->headers;
135 while(cur) { 140 while(cur) {
136 elem = cur->data; 141 elem = cur->data;
137 old = out; 142 g_string_append_printf(outstr, "%s: %s\r\n", elem->name,
138 out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value); 143 elem->value);
139 g_free(old);
140 cur = g_slist_next(cur); 144 cur = g_slist_next(cur);
141 } 145 }
142 old = out; 146
143 out = g_strdup_printf("%s\r\n",out); 147 g_string_append_printf(outstr, "\r\n%s", msg->bodylen ? msg->body : "");
144 g_free(old); 148
145 149 return g_string_free(outstr, FALSE);
146 if(msg->bodylen) {
147 old = out;
148 out = g_strdup_printf("%s%s",out, msg->body);
149 g_free(old);
150 }
151 return out;
152 } 150 }
153 void sipmsg_add_header(struct sipmsg *msg, gchar *name, gchar *value) { 151 void sipmsg_add_header(struct sipmsg *msg, gchar *name, gchar *value) {
154 struct siphdrelement *element = g_new0(struct siphdrelement,1); 152 struct siphdrelement *element = g_new0(struct siphdrelement,1);
155 element->name = g_strdup(name); 153 element->name = g_strdup(name);
156 element->value = g_strdup(value); 154 element->value = g_strdup(value);