Mercurial > pidgin
comparison src/protocols/simple/sipmsg.c @ 14069:d594f0466585
[gaim-migrate @ 16690]
Fix CID 221
I also fixed an imperial ton of leaks. It was quite amazing, actually.
There is also some other cleanup stuff in here too.
committer: Tailor Script <tailor@pidgin.im>
| author | Daniel Atallah <daniel.atallah@gmail.com> |
|---|---|
| date | Thu, 10 Aug 2006 23:42:17 +0000 |
| parents | b62d685cf841 |
| children |
comparison
equal
deleted
inserted
replaced
| 14068:6cb8bdc3366f | 14069:d594f0466585 |
|---|---|
| 33 #include "version.h" | 33 #include "version.h" |
| 34 | 34 |
| 35 #include "simple.h" | 35 #include "simple.h" |
| 36 #include "sipmsg.h" | 36 #include "sipmsg.h" |
| 37 | 37 |
| 38 struct sipmsg *sipmsg_parse_msg(gchar *msg) { | 38 struct sipmsg *sipmsg_parse_msg(const gchar *msg) { |
| 39 char *tmp = strstr(msg, "\r\n\r\n"); | 39 const char *tmp = strstr(msg, "\r\n\r\n"); |
| 40 char *line; | |
| 40 struct sipmsg *smsg; | 41 struct sipmsg *smsg; |
| 42 | |
| 41 if(!tmp) return NULL; | 43 if(!tmp) return NULL; |
| 42 tmp[0]=0; | 44 |
| 43 smsg = sipmsg_parse_header(msg); | 45 line = g_strndup(msg, tmp - msg); |
| 44 tmp[0]='\r'; | 46 |
| 45 smsg->body = g_strdup(tmp+4); | 47 smsg = sipmsg_parse_header(line); |
| 48 smsg->body = g_strdup(tmp + 4); | |
| 49 | |
| 50 g_free(line); | |
| 46 return smsg; | 51 return smsg; |
| 47 } | 52 } |
| 48 | 53 |
| 49 struct sipmsg *sipmsg_parse_header(gchar *header) { | 54 struct sipmsg *sipmsg_parse_header(const gchar *header) { |
| 50 struct sipmsg *msg = g_new0(struct sipmsg,1); | 55 struct sipmsg *msg = g_new0(struct sipmsg,1); |
| 51 gchar **lines = g_strsplit(header,"\r\n",0); | 56 gchar **lines = g_strsplit(header,"\r\n",0); |
| 52 gchar **parts; | 57 gchar **parts; |
| 53 gchar *dummy; | 58 gchar *dummy; |
| 54 gchar *dummy2; | 59 gchar *dummy2; |
| 108 } | 113 } |
| 109 } | 114 } |
| 110 return msg; | 115 return msg; |
| 111 } | 116 } |
| 112 | 117 |
| 113 void sipmsg_print(struct sipmsg *msg) { | 118 void sipmsg_print(const struct sipmsg *msg) { |
| 114 GSList *cur; | 119 GSList *cur; |
| 115 struct siphdrelement *elem; | 120 struct siphdrelement *elem; |
| 116 gaim_debug(GAIM_DEBUG_MISC, "simple", "SIP MSG\n"); | 121 gaim_debug(GAIM_DEBUG_MISC, "simple", "SIP MSG\n"); |
| 117 gaim_debug(GAIM_DEBUG_MISC, "simple", "response: %d\nmethod: %s\nbodylen: %d\n",msg->response,msg->method,msg->bodylen); | 122 gaim_debug(GAIM_DEBUG_MISC, "simple", "response: %d\nmethod: %s\nbodylen: %d\n",msg->response,msg->method,msg->bodylen); |
| 118 if(msg->target) gaim_debug(GAIM_DEBUG_MISC, "simple", "target: %s\n",msg->target); | 123 if(msg->target) gaim_debug(GAIM_DEBUG_MISC, "simple", "target: %s\n",msg->target); |
| 122 gaim_debug(GAIM_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value); | 127 gaim_debug(GAIM_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value); |
| 123 cur = g_slist_next(cur); | 128 cur = g_slist_next(cur); |
| 124 } | 129 } |
| 125 } | 130 } |
| 126 | 131 |
| 127 char *sipmsg_to_string(struct sipmsg *msg) { | 132 char *sipmsg_to_string(const struct sipmsg *msg) { |
| 128 GSList *cur; | 133 GSList *cur; |
| 129 GString *outstr = g_string_new(""); | 134 GString *outstr = g_string_new(""); |
| 130 struct siphdrelement *elem; | 135 struct siphdrelement *elem; |
| 131 | 136 |
| 132 if(msg->response) | 137 if(msg->response) |
| 146 | 151 |
| 147 g_string_append_printf(outstr, "\r\n%s", msg->bodylen ? msg->body : ""); | 152 g_string_append_printf(outstr, "\r\n%s", msg->bodylen ? msg->body : ""); |
| 148 | 153 |
| 149 return g_string_free(outstr, FALSE); | 154 return g_string_free(outstr, FALSE); |
| 150 } | 155 } |
| 151 void sipmsg_add_header(struct sipmsg *msg, gchar *name, gchar *value) { | 156 void sipmsg_add_header(struct sipmsg *msg, const gchar *name, const gchar *value) { |
| 152 struct siphdrelement *element = g_new0(struct siphdrelement,1); | 157 struct siphdrelement *element = g_new0(struct siphdrelement,1); |
| 153 element->name = g_strdup(name); | 158 element->name = g_strdup(name); |
| 154 element->value = g_strdup(value); | 159 element->value = g_strdup(value); |
| 155 msg->headers = g_slist_append(msg->headers, element); | 160 msg->headers = g_slist_append(msg->headers, element); |
| 156 } | 161 } |
| 168 g_free(msg->target); | 173 g_free(msg->target); |
| 169 g_free(msg->body); | 174 g_free(msg->body); |
| 170 g_free(msg); | 175 g_free(msg); |
| 171 } | 176 } |
| 172 | 177 |
| 173 void sipmsg_remove_header(struct sipmsg *msg, gchar *name) { | 178 void sipmsg_remove_header(struct sipmsg *msg, const gchar *name) { |
| 174 struct siphdrelement *elem; | 179 struct siphdrelement *elem; |
| 175 GSList *tmp = msg->headers; | 180 GSList *tmp = msg->headers; |
| 176 while(tmp) { | 181 while(tmp) { |
| 177 elem = tmp->data; | 182 elem = tmp->data; |
| 178 if(strcmp(elem->name, name)==0) { | 183 if(strcmp(elem->name, name)==0) { |
| 179 msg->headers = g_slist_remove(msg->headers, elem); | 184 msg->headers = g_slist_remove(msg->headers, elem); |
| 185 g_free(elem->name); | |
| 186 g_free(elem->value); | |
| 187 g_free(elem); | |
| 180 return; | 188 return; |
| 181 } | 189 } |
| 182 tmp = g_slist_next(tmp); | 190 tmp = g_slist_next(tmp); |
| 183 } | 191 } |
| 184 return; | 192 return; |
| 185 } | 193 } |
| 186 | 194 |
| 187 gchar *sipmsg_find_header(struct sipmsg *msg, gchar *name) { | 195 gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name) { |
| 188 GSList *tmp; | 196 GSList *tmp; |
| 189 struct siphdrelement *elem; | 197 struct siphdrelement *elem; |
| 190 tmp = msg->headers; | 198 tmp = msg->headers; |
| 191 while(tmp) { | 199 while(tmp) { |
| 192 elem = tmp->data; | 200 elem = tmp->data; |
