Mercurial > pidgin
annotate src/protocols/simple/sipmsg.c @ 13545:cfc2f7fcb3dd
[gaim-migrate @ 15922]
Way more changes that I initially thought I was going to make. I apologize
for the commit message spam. These changes bring a lot of consistency to
our capitalization and punctuation, especially of words like "e-mail".
For reference, I've used these rules (after discussing in #gaim):
e-mail, a case of two words joined:
"e-mail" - in the middle of a sentence caps context
"E-mail" - start of text in a sentence caps context
"E-Mail" - in a header (title) caps context
re-enable, a single word, would be:
"re-enable", "Re-enable", and "Re-enable" (respectively)
The reason this changeset exploded is that, as I went through and verified
these changes, I realized we were using improper capitalization (e.g. header
instead of sentence) in a number of dialogs. I fixed a number of these
cases before, and this corrects another pile.
This looks like I've made a LOT of work for the translators, but the impact
is significantly mitigated by three factors: 1) Many of these changes use
strings that already exist, or change one string in many places. 2) I've
used sed to correct the .po files where possible. 3) The actual changes
are extremely trivial.
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Tue, 21 Mar 2006 04:32:45 +0000 |
| parents | b62d685cf841 |
| children | d594f0466585 |
| rev | line source |
|---|---|
| 11181 | 1 /** |
| 2 * @file sipmsg.c | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
| 6 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de> | |
| 7 * | |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 */ | |
| 22 | |
| 23 #include "internal.h" | |
| 24 | |
| 25 #include "accountopt.h" | |
| 26 #include "blist.h" | |
| 27 #include "conversation.h" | |
| 28 #include "debug.h" | |
| 29 #include "notify.h" | |
| 30 #include "prpl.h" | |
| 31 #include "plugin.h" | |
| 32 #include "util.h" | |
| 33 #include "version.h" | |
| 34 | |
| 35 #include "simple.h" | |
| 36 #include "sipmsg.h" | |
| 37 | |
| 38 struct sipmsg *sipmsg_parse_msg(gchar *msg) { | |
| 39 char *tmp = strstr(msg, "\r\n\r\n"); | |
| 40 struct sipmsg *smsg; | |
| 11398 | 41 if(!tmp) return NULL; |
| 11181 | 42 tmp[0]=0; |
| 43 smsg = sipmsg_parse_header(msg); | |
| 44 tmp[0]='\r'; | |
| 45 smsg->body = g_strdup(tmp+4); | |
| 46 return smsg; | |
| 47 } | |
| 48 | |
| 49 struct sipmsg *sipmsg_parse_header(gchar *header) { | |
| 50 struct sipmsg *msg = g_new0(struct sipmsg,1); | |
| 51 gchar **lines = g_strsplit(header,"\r\n",0); | |
| 52 gchar **parts; | |
| 53 gchar *dummy; | |
| 54 gchar *dummy2; | |
| 55 gchar *tmp; | |
| 56 int i=1; | |
| 11483 | 57 if(!lines[0]) return NULL; |
| 11181 | 58 parts = g_strsplit(lines[0], " ", 3); |
| 59 if(!parts[0] || !parts[1] || !parts[2]) { | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
60 g_strfreev(parts); |
|
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
61 g_strfreev(lines); |
| 11181 | 62 g_free(msg); |
| 63 return NULL; | |
| 64 } | |
|
11820
2cf6d4cf2cb0
[gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents:
11483
diff
changeset
|
65 if(strstr(parts[0],"SIP")) { /* numeric response */ |
| 11181 | 66 msg->method = g_strdup(parts[2]); |
| 67 msg->response = strtol(parts[1],NULL,10); | |
|
11820
2cf6d4cf2cb0
[gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents:
11483
diff
changeset
|
68 } else { /* request */ |
| 11181 | 69 msg->method = g_strdup(parts[0]); |
| 70 msg->target = g_strdup(parts[1]); | |
| 71 msg->response = 0; | |
| 72 } | |
| 73 g_strfreev(parts); | |
| 74 for(i=1; lines[i] && strlen(lines[i])>2; i++) { | |
| 75 parts = g_strsplit(lines[i], ":", 2); | |
| 76 if(!parts[0] || !parts[1]) { | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
77 g_strfreev(parts); |
|
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
78 g_strfreev(lines); |
| 11181 | 79 g_free(msg); |
| 80 return NULL; | |
| 81 } | |
| 82 dummy = parts[1]; | |
| 83 dummy2 = 0; | |
| 84 while(*dummy==' ' || *dummy=='\t') dummy++; | |
| 85 dummy2 = g_strdup(dummy); | |
| 86 while(lines[i+1] && (lines[i+1][0]==' ' || lines[i+1][0]=='\t')) { | |
| 87 i++; | |
| 88 dummy = lines[i]; | |
| 89 while(*dummy==' ' || *dummy=='\t') dummy++; | |
| 90 tmp = g_strdup_printf("%s %s",dummy2, dummy); | |
| 91 g_free(dummy2); | |
| 92 dummy2 = tmp; | |
| 93 } | |
| 94 sipmsg_add_header(msg, parts[0], dummy2); | |
| 95 g_strfreev(parts); | |
| 96 } | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
97 g_strfreev(lines); |
| 11181 | 98 msg->bodylen = strtol(sipmsg_find_header(msg, "Content-Length"),NULL,10); |
| 99 if(msg->response) { | |
| 100 tmp = sipmsg_find_header(msg, "CSeq"); | |
| 101 if(!tmp) { | |
|
11820
2cf6d4cf2cb0
[gaim-migrate @ 14111]
Richard Laager <rlaager@wiktel.com>
parents:
11483
diff
changeset
|
102 /* SHOULD NOT HAPPEN */ |
| 11181 | 103 msg->method = 0; |
| 104 } else { | |
| 105 parts = g_strsplit(tmp, " ", 2); | |
| 106 msg->method = g_strdup(parts[1]); | |
| 107 g_strfreev(parts); | |
| 108 } | |
| 109 } | |
| 110 return msg; | |
| 111 } | |
| 112 | |
| 113 void sipmsg_print(struct sipmsg *msg) { | |
| 114 GSList *cur; | |
| 115 struct siphdrelement *elem; | |
| 116 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); | |
| 118 if(msg->target) gaim_debug(GAIM_DEBUG_MISC, "simple", "target: %s\n",msg->target); | |
| 119 cur = msg->headers; | |
| 120 while(cur) { | |
| 121 elem = cur->data; | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
122 gaim_debug(GAIM_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value); |
| 11181 | 123 cur = g_slist_next(cur); |
| 124 } | |
| 125 } | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
126 |
| 11181 | 127 char *sipmsg_to_string(struct sipmsg *msg) { |
| 128 GSList *cur; | |
|
12743
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
129 GString *outstr = g_string_new(""); |
| 11181 | 130 struct siphdrelement *elem; |
|
12743
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
131 |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
132 if(msg->response) |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
133 g_string_append_printf(outstr, "SIP/2.0 %d Unknown\r\n", |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
134 msg->response); |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
135 else |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
136 g_string_append_printf(outstr, "%s %s SIP/2.0\r\n", |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
137 msg->method, msg->target); |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
138 |
| 11181 | 139 cur = msg->headers; |
| 140 while(cur) { | |
| 141 elem = cur->data; | |
|
12743
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
142 g_string_append_printf(outstr, "%s: %s\r\n", elem->name, |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
143 elem->value); |
| 11181 | 144 cur = g_slist_next(cur); |
| 145 } | |
| 146 | |
|
12743
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
147 g_string_append_printf(outstr, "\r\n%s", msg->bodylen ? msg->body : ""); |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
148 |
|
33ed71b35a43
[gaim-migrate @ 15090]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11820
diff
changeset
|
149 return g_string_free(outstr, FALSE); |
| 11181 | 150 } |
| 151 void sipmsg_add_header(struct sipmsg *msg, gchar *name, gchar *value) { | |
| 152 struct siphdrelement *element = g_new0(struct siphdrelement,1); | |
| 153 element->name = g_strdup(name); | |
| 154 element->value = g_strdup(value); | |
| 155 msg->headers = g_slist_append(msg->headers, element); | |
| 156 } | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
157 |
| 11181 | 158 void sipmsg_free(struct sipmsg *msg) { |
| 159 struct siphdrelement *elem; | |
| 160 while(msg->headers) { | |
| 161 elem = msg->headers->data; | |
| 162 msg->headers = g_slist_remove(msg->headers,elem); | |
| 163 g_free(elem->name); | |
| 164 g_free(elem->value); | |
| 165 g_free(elem); | |
| 166 } | |
|
12747
b62d685cf841
[gaim-migrate @ 15094]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12743
diff
changeset
|
167 g_free(msg->method); |
|
b62d685cf841
[gaim-migrate @ 15094]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12743
diff
changeset
|
168 g_free(msg->target); |
|
b62d685cf841
[gaim-migrate @ 15094]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12743
diff
changeset
|
169 g_free(msg->body); |
| 11181 | 170 g_free(msg); |
| 171 } | |
| 172 | |
| 173 void sipmsg_remove_header(struct sipmsg *msg, gchar *name) { | |
| 174 struct siphdrelement *elem; | |
| 175 GSList *tmp = msg->headers; | |
| 176 while(tmp) { | |
| 177 elem = tmp->data; | |
| 178 if(strcmp(elem->name, name)==0) { | |
| 179 msg->headers = g_slist_remove(msg->headers, elem); | |
| 180 return; | |
| 181 } | |
| 182 tmp = g_slist_next(tmp); | |
| 183 } | |
| 184 return; | |
| 185 } | |
| 186 | |
| 187 gchar *sipmsg_find_header(struct sipmsg *msg, gchar *name) { | |
| 188 GSList *tmp; | |
| 189 struct siphdrelement *elem; | |
| 190 tmp = msg->headers; | |
| 191 while(tmp) { | |
| 192 elem = tmp->data; | |
| 193 if(strcmp(elem->name,name)==0) { | |
| 194 return elem->value; | |
| 195 } | |
| 196 tmp = g_slist_next(tmp); | |
| 197 } | |
| 198 return NULL; | |
| 199 } | |
| 200 |
