Mercurial > pidgin
annotate src/protocols/simple/sipmsg.c @ 11454:201617d49573
[gaim-migrate @ 13693]
This commit includes a number of changes:
1. Aliases are now used consistently in chats. If the prpl uses unique screen names for chats (e.g. Jabber), then aliases are not used at all.
2. The chat list is now colorized to match the colors used in the chat itself.
3. Buddies are bolded in the chat user list.
4. Buddies are sorted above non-buddies in the chat user list.
5. The chat user list is ellipsized when possible (i.e. on GTK+ 2.6.0 or above).
6. I've accepted patch #1178248, by Matt Amato to add "buddy-added" and "buddy-removed" signals. These were used in my implementation of #3 and #4, to update the GUI when users are added or removed from the buddy list.
7. I've added a "blist-node-aliased" signal that is emitted when a buddy, contact, or chat is aliased.
8. Since it was hard to separate and I need it at some point, I'm letting it slip in... I've changed GaimConversation.log to be a GList named logs. This way, we can have multiple logs for a single conversation. This will be necessary to implement unnamed chat logging in some reasonable fasion (see my notes in the TODO file).
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Tue, 06 Sep 2005 03:04:07 +0000 |
| parents | 617e67e1c985 |
| children | 0d18fa6c3b41 |
| 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; | |
| 57 parts = g_strsplit(lines[0], " ", 3); | |
| 58 if(!parts[0] || !parts[1] || !parts[2]) { | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
59 g_strfreev(parts); |
|
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
60 g_strfreev(lines); |
| 11181 | 61 g_free(msg); |
| 62 return NULL; | |
| 63 } | |
| 64 if(strstr(parts[0],"SIP")) { // numeric response | |
| 65 msg->method = g_strdup(parts[2]); | |
| 66 msg->response = strtol(parts[1],NULL,10); | |
| 67 } else { // request | |
| 68 msg->method = g_strdup(parts[0]); | |
| 69 msg->target = g_strdup(parts[1]); | |
| 70 msg->response = 0; | |
| 71 } | |
| 72 g_strfreev(parts); | |
| 73 for(i=1; lines[i] && strlen(lines[i])>2; i++) { | |
| 74 parts = g_strsplit(lines[i], ":", 2); | |
| 75 if(!parts[0] || !parts[1]) { | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
76 g_strfreev(parts); |
|
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
77 g_strfreev(lines); |
| 11181 | 78 g_free(msg); |
| 79 return NULL; | |
| 80 } | |
| 81 dummy = parts[1]; | |
| 82 dummy2 = 0; | |
| 83 while(*dummy==' ' || *dummy=='\t') dummy++; | |
| 84 dummy2 = g_strdup(dummy); | |
| 85 while(lines[i+1] && (lines[i+1][0]==' ' || lines[i+1][0]=='\t')) { | |
| 86 i++; | |
| 87 dummy = lines[i]; | |
| 88 while(*dummy==' ' || *dummy=='\t') dummy++; | |
| 89 tmp = g_strdup_printf("%s %s",dummy2, dummy); | |
| 90 g_free(dummy2); | |
| 91 dummy2 = tmp; | |
| 92 } | |
| 93 sipmsg_add_header(msg, parts[0], dummy2); | |
| 94 g_strfreev(parts); | |
| 95 } | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
96 g_strfreev(lines); |
| 11181 | 97 msg->bodylen = strtol(sipmsg_find_header(msg, "Content-Length"),NULL,10); |
| 98 if(msg->response) { | |
| 99 tmp = sipmsg_find_header(msg, "CSeq"); | |
| 100 if(!tmp) { | |
| 101 // SHOULD NOT HAPPEN | |
| 102 msg->method = 0; | |
| 103 } else { | |
| 104 parts = g_strsplit(tmp, " ", 2); | |
| 105 msg->method = g_strdup(parts[1]); | |
| 106 g_strfreev(parts); | |
| 107 } | |
| 108 } | |
| 109 return msg; | |
| 110 } | |
| 111 | |
| 112 void sipmsg_print(struct sipmsg *msg) { | |
| 113 GSList *cur; | |
| 114 struct siphdrelement *elem; | |
| 115 gaim_debug(GAIM_DEBUG_MISC, "simple", "SIP MSG\n"); | |
| 116 gaim_debug(GAIM_DEBUG_MISC, "simple", "response: %d\nmethod: %s\nbodylen: %d\n",msg->response,msg->method,msg->bodylen); | |
| 117 if(msg->target) gaim_debug(GAIM_DEBUG_MISC, "simple", "target: %s\n",msg->target); | |
| 118 cur = msg->headers; | |
| 119 while(cur) { | |
| 120 elem = cur->data; | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
121 gaim_debug(GAIM_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value); |
| 11181 | 122 cur = g_slist_next(cur); |
| 123 } | |
| 124 } | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
125 |
| 11181 | 126 char *sipmsg_to_string(struct sipmsg *msg) { |
| 127 gchar *out; | |
| 128 gchar *old; | |
| 129 GSList *cur; | |
| 130 struct siphdrelement *elem; | |
| 131 if(msg->response) out = g_strdup_printf("SIP/2.0 %d AAA\r\n", msg->response); | |
| 132 else out = g_strdup_printf("%s %s SIP/2.0\r\n",msg->method, msg->target); | |
| 133 cur = msg->headers; | |
| 134 while(cur) { | |
| 135 elem = cur->data; | |
| 136 old = out; | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
137 out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value); |
| 11181 | 138 g_free(old); |
| 139 cur = g_slist_next(cur); | |
| 140 } | |
| 141 old = out; | |
| 142 out = g_strdup_printf("%s\r\n",out); | |
| 143 g_free(old); | |
| 144 | |
| 145 if(msg->bodylen) { | |
| 146 old = out; | |
| 147 out = g_strdup_printf("%s%s",out, msg->body); | |
| 148 g_free(old); | |
| 149 } | |
| 150 return out; | |
| 151 } | |
| 152 void sipmsg_add_header(struct sipmsg *msg, gchar *name, gchar *value) { | |
| 153 struct siphdrelement *element = g_new0(struct siphdrelement,1); | |
| 154 element->name = g_strdup(name); | |
| 155 element->value = g_strdup(value); | |
| 156 msg->headers = g_slist_append(msg->headers, element); | |
| 157 } | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
158 |
| 11181 | 159 void sipmsg_free(struct sipmsg *msg) { |
| 160 struct siphdrelement *elem; | |
| 161 while(msg->headers) { | |
| 162 elem = msg->headers->data; | |
| 163 msg->headers = g_slist_remove(msg->headers,elem); | |
| 164 g_free(elem->name); | |
| 165 g_free(elem->value); | |
| 166 g_free(elem); | |
| 167 } | |
| 168 if(msg->method) g_free(msg->method); | |
| 169 if(msg->target) g_free(msg->target); | |
| 170 if(msg->body) g_free(msg->body); | |
| 171 g_free(msg); | |
| 172 } | |
| 173 | |
| 174 void sipmsg_remove_header(struct sipmsg *msg, gchar *name) { | |
| 175 struct siphdrelement *elem; | |
| 176 GSList *tmp = msg->headers; | |
| 177 while(tmp) { | |
| 178 elem = tmp->data; | |
| 179 if(strcmp(elem->name, name)==0) { | |
| 180 msg->headers = g_slist_remove(msg->headers, elem); | |
| 181 return; | |
| 182 } | |
| 183 tmp = g_slist_next(tmp); | |
| 184 } | |
| 185 return; | |
| 186 } | |
| 187 | |
| 188 gchar *sipmsg_find_header(struct sipmsg *msg, gchar *name) { | |
| 189 GSList *tmp; | |
| 190 struct siphdrelement *elem; | |
| 191 tmp = msg->headers; | |
| 192 while(tmp) { | |
| 193 elem = tmp->data; | |
| 194 if(strcmp(elem->name,name)==0) { | |
| 195 return elem->value; | |
| 196 } | |
| 197 tmp = g_slist_next(tmp); | |
| 198 } | |
| 199 return NULL; | |
| 200 } | |
| 201 |
