Tue, 05 Nov 2019 21:22:01 -0500
Credit Evert Mouw for the portion of his PR that I accepted.
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
1 | /** |
| 15884 | 2 | * purple |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
3 | * |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
4 | * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de> |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
5 | * |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
6 | * This program is free software; you can redistribute it and/or modify |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
7 | * it under the terms of the GNU General Public License as published by |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
8 | * the Free Software Foundation; either version 2 of the License, or |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
9 | * (at your option) any later version. |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
10 | * |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
11 | * This program is distributed in the hope that it will be useful, |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
14 | * GNU General Public License for more details. |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
15 | * |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
16 | * You should have received a copy of the GNU General Public License |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
17 | * along with this program; if not, write to the Free Software |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17155
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
19 | */ |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
20 | |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
21 | #include "internal.h" |
|
39962
c3ba045d5293
migrate the simple prpl to using purple.h
Gary Kramlich <grim@reaperworld.com>
parents:
37390
diff
changeset
|
22 | #include <purple.h> |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
23 | |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
24 | #include "simple.h" |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
25 | #include "sipmsg.h" |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
26 | |
|
35225
179a49ea2a4b
Ignore incoming sip messages with bodies longer than 30 MB.
Mark Doliner <mark@kingant.net>
parents:
35221
diff
changeset
|
27 | #define MAX_CONTENT_LENGTH 30000000 |
|
179a49ea2a4b
Ignore incoming sip messages with bodies longer than 30 MB.
Mark Doliner <mark@kingant.net>
parents:
35221
diff
changeset
|
28 | |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
29 | struct sipmsg *sipmsg_parse_msg(const gchar *msg) { |
|
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
30 | const char *tmp = strstr(msg, "\r\n\r\n"); |
|
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
31 | char *line; |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
32 | struct sipmsg *smsg; |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
33 | |
|
11398
513a7f8f547a
[gaim-migrate @ 13630]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11181
diff
changeset
|
34 | if(!tmp) return NULL; |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
35 | |
|
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
36 | line = g_strndup(msg, tmp - msg); |
|
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
37 | |
|
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
38 | smsg = sipmsg_parse_header(line); |
|
21939
8d8200de2ade
Fix #4345 by ignoring a malformed message.
Daniel Atallah <datallah@pidgin.im>
parents:
20287
diff
changeset
|
39 | if(smsg != NULL) |
|
8d8200de2ade
Fix #4345 by ignoring a malformed message.
Daniel Atallah <datallah@pidgin.im>
parents:
20287
diff
changeset
|
40 | smsg->body = g_strdup(tmp + 4); |
|
8d8200de2ade
Fix #4345 by ignoring a malformed message.
Daniel Atallah <datallah@pidgin.im>
parents:
20287
diff
changeset
|
41 | else |
|
8d8200de2ade
Fix #4345 by ignoring a malformed message.
Daniel Atallah <datallah@pidgin.im>
parents:
20287
diff
changeset
|
42 | purple_debug_error("SIMPLE", "No header parsed from line: %s\n", line); |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
43 | |
|
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
44 | g_free(line); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
45 | return smsg; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
46 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
47 | |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
48 | struct sipmsg *sipmsg_parse_header(const gchar *header) { |
|
29997
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
49 | struct sipmsg *msg; |
|
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
50 | gchar **parts, **lines; |
|
24590
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
51 | gchar *dummy, *dummy2, *tmp; |
|
20287
4a25d4144f16
applied changes from 20395453ab17cd8dd060d4d0794affda17e3272f
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
52 | const gchar *tmp2; |
|
24590
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
53 | int i = 1; |
|
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
54 | |
|
29997
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
55 | lines = g_strsplit(header,"\r\n",0); |
|
24590
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
56 | if(!lines[0]) { |
|
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
57 | g_strfreev(lines); |
|
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
58 | return NULL; |
|
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
59 | } |
|
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
60 | |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
61 | parts = g_strsplit(lines[0], " ", 3); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
62 | if(!parts[0] || !parts[1] || !parts[2]) { |
|
11439
e76bc2f9deb0
[gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents:
11398
diff
changeset
|
63 | g_strfreev(parts); |
|
e76bc2f9deb0
[gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents:
11398
diff
changeset
|
64 | g_strfreev(lines); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
65 | return NULL; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
66 | } |
|
24590
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
67 | |
|
29997
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
68 | msg = g_new0(struct sipmsg,1); |
|
11820
534903b9226e
[gaim-migrate @ 14111]
Richard Laager <rlaager@pidgin.im>
parents:
11483
diff
changeset
|
69 | if(strstr(parts[0],"SIP")) { /* numeric response */ |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
70 | msg->method = g_strdup(parts[2]); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
71 | msg->response = strtol(parts[1],NULL,10); |
|
11820
534903b9226e
[gaim-migrate @ 14111]
Richard Laager <rlaager@pidgin.im>
parents:
11483
diff
changeset
|
72 | } else { /* request */ |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
73 | msg->method = g_strdup(parts[0]); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
74 | msg->target = g_strdup(parts[1]); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
75 | msg->response = 0; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
76 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
77 | g_strfreev(parts); |
|
24590
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
78 | |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
79 | for(i=1; lines[i] && strlen(lines[i])>2; i++) { |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
80 | parts = g_strsplit(lines[i], ":", 2); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
81 | if(!parts[0] || !parts[1]) { |
|
11439
e76bc2f9deb0
[gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents:
11398
diff
changeset
|
82 | g_strfreev(parts); |
|
e76bc2f9deb0
[gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents:
11398
diff
changeset
|
83 | g_strfreev(lines); |
|
29997
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
84 | sipmsg_free(msg); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
85 | return NULL; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
86 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
87 | dummy = parts[1]; |
|
37390
209a1350d87f
Assign pointers to NULL rather than 0.
Michael McConville <mmcconville@mykolab.com>
parents:
37016
diff
changeset
|
88 | dummy2 = NULL; |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
89 | while(*dummy==' ' || *dummy=='\t') dummy++; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
90 | dummy2 = g_strdup(dummy); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
91 | while(lines[i+1] && (lines[i+1][0]==' ' || lines[i+1][0]=='\t')) { |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
92 | i++; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
93 | dummy = lines[i]; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
94 | while(*dummy==' ' || *dummy=='\t') dummy++; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
95 | tmp = g_strdup_printf("%s %s",dummy2, dummy); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
96 | g_free(dummy2); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
97 | dummy2 = tmp; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
98 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
99 | sipmsg_add_header(msg, parts[0], dummy2); |
|
29997
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
100 | g_free(dummy2); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
101 | g_strfreev(parts); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
102 | } |
|
11439
e76bc2f9deb0
[gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents:
11398
diff
changeset
|
103 | g_strfreev(lines); |
|
24590
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
104 | |
|
20287
4a25d4144f16
applied changes from 20395453ab17cd8dd060d4d0794affda17e3272f
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
105 | tmp2 = sipmsg_find_header(msg, "Content-Length"); |
|
4a25d4144f16
applied changes from 20395453ab17cd8dd060d4d0794affda17e3272f
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
106 | if (tmp2 != NULL) |
|
4a25d4144f16
applied changes from 20395453ab17cd8dd060d4d0794affda17e3272f
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
107 | msg->bodylen = strtol(tmp2, NULL, 10); |
|
35221
6bd2dd10e5da
Simple: fix a possible NULL-pointer dereference and add some input filtering. Fixes VRT-2013-1004
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
29997
diff
changeset
|
108 | if (msg->bodylen < 0) { |
|
6bd2dd10e5da
Simple: fix a possible NULL-pointer dereference and add some input filtering. Fixes VRT-2013-1004
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
29997
diff
changeset
|
109 | purple_debug_warning("simple", "Invalid body length: %d", |
|
6bd2dd10e5da
Simple: fix a possible NULL-pointer dereference and add some input filtering. Fixes VRT-2013-1004
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
29997
diff
changeset
|
110 | msg->bodylen); |
|
6bd2dd10e5da
Simple: fix a possible NULL-pointer dereference and add some input filtering. Fixes VRT-2013-1004
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
29997
diff
changeset
|
111 | msg->bodylen = 0; |
|
35225
179a49ea2a4b
Ignore incoming sip messages with bodies longer than 30 MB.
Mark Doliner <mark@kingant.net>
parents:
35221
diff
changeset
|
112 | } else if (msg->bodylen > MAX_CONTENT_LENGTH) { |
|
179a49ea2a4b
Ignore incoming sip messages with bodies longer than 30 MB.
Mark Doliner <mark@kingant.net>
parents:
35221
diff
changeset
|
113 | purple_debug_warning("simple", "Got Content-Length of %d bytes on " |
|
179a49ea2a4b
Ignore incoming sip messages with bodies longer than 30 MB.
Mark Doliner <mark@kingant.net>
parents:
35221
diff
changeset
|
114 | "incoming message (max is %u bytes). Ignoring message body.\n", |
|
179a49ea2a4b
Ignore incoming sip messages with bodies longer than 30 MB.
Mark Doliner <mark@kingant.net>
parents:
35221
diff
changeset
|
115 | msg->bodylen, MAX_CONTENT_LENGTH); |
|
179a49ea2a4b
Ignore incoming sip messages with bodies longer than 30 MB.
Mark Doliner <mark@kingant.net>
parents:
35221
diff
changeset
|
116 | msg->bodylen = 0; |
|
35221
6bd2dd10e5da
Simple: fix a possible NULL-pointer dereference and add some input filtering. Fixes VRT-2013-1004
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
29997
diff
changeset
|
117 | } |
|
24590
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
118 | |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
119 | if(msg->response) { |
|
20287
4a25d4144f16
applied changes from 20395453ab17cd8dd060d4d0794affda17e3272f
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
120 | tmp2 = sipmsg_find_header(msg, "CSeq"); |
|
29997
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
121 | g_free(msg->method); |
|
20287
4a25d4144f16
applied changes from 20395453ab17cd8dd060d4d0794affda17e3272f
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
122 | if(!tmp2) { |
|
11820
534903b9226e
[gaim-migrate @ 14111]
Richard Laager <rlaager@pidgin.im>
parents:
11483
diff
changeset
|
123 | /* SHOULD NOT HAPPEN */ |
|
29997
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
124 | msg->method = NULL; |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
125 | } else { |
|
20287
4a25d4144f16
applied changes from 20395453ab17cd8dd060d4d0794affda17e3272f
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
126 | parts = g_strsplit(tmp2, " ", 2); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
127 | msg->method = g_strdup(parts[1]); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
128 | g_strfreev(parts); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
129 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
130 | } |
|
24590
43ba4176a7f9
Fix a potential leak, thanks to "KuSh". Fixes #7465.
Daniel Atallah <datallah@pidgin.im>
parents:
21939
diff
changeset
|
131 | |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
132 | return msg; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
133 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
134 | |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
135 | void sipmsg_print(const struct sipmsg *msg) { |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
136 | GSList *cur; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
137 | struct siphdrelement *elem; |
| 15884 | 138 | purple_debug(PURPLE_DEBUG_MISC, "simple", "SIP MSG\n"); |
| 139 | purple_debug(PURPLE_DEBUG_MISC, "simple", "response: %d\nmethod: %s\nbodylen: %d\n",msg->response,msg->method,msg->bodylen); | |
| 140 | if(msg->target) purple_debug(PURPLE_DEBUG_MISC, "simple", "target: %s\n",msg->target); | |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
141 | cur = msg->headers; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
142 | while(cur) { |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
143 | elem = cur->data; |
| 15884 | 144 | purple_debug(PURPLE_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
145 | cur = g_slist_next(cur); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
146 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
147 | } |
|
11439
e76bc2f9deb0
[gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents:
11398
diff
changeset
|
148 | |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
149 | char *sipmsg_to_string(const struct sipmsg *msg) { |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
150 | GSList *cur; |
|
12743
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
151 | GString *outstr = g_string_new(""); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
152 | struct siphdrelement *elem; |
|
12743
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
153 | |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
154 | if(msg->response) |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
155 | g_string_append_printf(outstr, "SIP/2.0 %d Unknown\r\n", |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
156 | msg->response); |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
157 | else |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
158 | g_string_append_printf(outstr, "%s %s SIP/2.0\r\n", |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
159 | msg->method, msg->target); |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
160 | |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
161 | cur = msg->headers; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
162 | while(cur) { |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
163 | elem = cur->data; |
|
12743
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
164 | g_string_append_printf(outstr, "%s: %s\r\n", elem->name, |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
165 | elem->value); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
166 | cur = g_slist_next(cur); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
167 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
168 | |
|
12743
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
169 | g_string_append_printf(outstr, "\r\n%s", msg->bodylen ? msg->body : ""); |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
170 | |
|
dfc698f04f77
[gaim-migrate @ 15090]
Daniel Atallah <datallah@pidgin.im>
parents:
11820
diff
changeset
|
171 | return g_string_free(outstr, FALSE); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
172 | } |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
173 | void sipmsg_add_header(struct sipmsg *msg, const gchar *name, const gchar *value) { |
|
29997
9a9b586ac254
Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents:
24590
diff
changeset
|
174 | struct siphdrelement *element = g_new(struct siphdrelement,1); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
175 | element->name = g_strdup(name); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
176 | element->value = g_strdup(value); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
177 | msg->headers = g_slist_append(msg->headers, element); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
178 | } |
|
11439
e76bc2f9deb0
[gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents:
11398
diff
changeset
|
179 | |
|
40077
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
180 | static void |
|
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
181 | sipmsg_free_header(struct siphdrelement *elem) |
|
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
182 | { |
|
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
183 | g_free(elem->name); |
|
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
184 | g_free(elem->value); |
|
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
185 | g_free(elem); |
|
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
186 | } |
|
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
187 | |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
188 | void sipmsg_free(struct sipmsg *msg) { |
|
40077
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
189 | g_slist_free_full(msg->headers, (GDestroyNotify)sipmsg_free_header); |
|
12747
189b28291088
[gaim-migrate @ 15094]
Daniel Atallah <datallah@pidgin.im>
parents:
12743
diff
changeset
|
190 | g_free(msg->method); |
|
189b28291088
[gaim-migrate @ 15094]
Daniel Atallah <datallah@pidgin.im>
parents:
12743
diff
changeset
|
191 | g_free(msg->target); |
|
189b28291088
[gaim-migrate @ 15094]
Daniel Atallah <datallah@pidgin.im>
parents:
12743
diff
changeset
|
192 | g_free(msg->body); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
193 | g_free(msg); |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
194 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
195 | |
|
14131
2cd4ddea2f52
[gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents:
12747
diff
changeset
|
196 | void sipmsg_remove_header(struct sipmsg *msg, const gchar *name) { |
|
40052
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39962
diff
changeset
|
197 | GSList *tmp = g_slist_find_custom(msg->headers, name, (GCompareFunc)g_ascii_strcasecmp); |
|
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39962
diff
changeset
|
198 | if(tmp) { |
|
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39962
diff
changeset
|
199 | struct siphdrelement *elem = tmp->data; |
|
40053
abbd9caef452
Use g_slist_delete_link instead of g_slist_remove
Arkadiy Illarionov <qarkai@gmail.com>
parents:
40052
diff
changeset
|
200 | msg->headers = g_slist_delete_link(msg->headers, tmp); |
|
40077
b5d8e7f5b5ce
simple: Add explicit destroy functions for structs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40053
diff
changeset
|
201 | sipmsg_free_header(elem); |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
202 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
203 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
204 | |
|
20287
4a25d4144f16
applied changes from 20395453ab17cd8dd060d4d0794affda17e3272f
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
205 | const gchar *sipmsg_find_header(struct sipmsg *msg, const gchar *name) { |
|
40052
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39962
diff
changeset
|
206 | GSList *tmp = g_slist_find_custom(msg->headers, name, (GCompareFunc)g_ascii_strcasecmp); |
|
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39962
diff
changeset
|
207 | if(tmp) { |
|
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39962
diff
changeset
|
208 | struct siphdrelement *elem = tmp->data; |
|
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39962
diff
changeset
|
209 | return elem->value; |
|
11181
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
210 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
211 | return NULL; |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
212 | } |
|
e872a55b9524
[gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
213 |