Mercurial > pidgin
annotate src/protocols/simple/sipmsg.c @ 12645:fc28451f5d96
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Fri, 23 Dec 2005 19:26:04 +0000 |
| parents | 2cf6d4cf2cb0 |
| children | 33ed71b35a43 |
| 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 gchar *out; | |
| 129 gchar *old; | |
| 130 GSList *cur; | |
| 131 struct siphdrelement *elem; | |
| 11483 | 132 if(msg->response) out = g_strdup_printf("SIP/2.0 %d Unknown\r\n", msg->response); |
| 11181 | 133 else out = g_strdup_printf("%s %s SIP/2.0\r\n",msg->method, msg->target); |
| 134 cur = msg->headers; | |
| 135 while(cur) { | |
| 136 elem = cur->data; | |
| 137 old = out; | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
138 out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value); |
| 11181 | 139 g_free(old); |
| 140 cur = g_slist_next(cur); | |
| 141 } | |
| 142 old = out; | |
| 143 out = g_strdup_printf("%s\r\n",out); | |
| 144 g_free(old); | |
| 145 | |
| 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 } | |
| 153 void sipmsg_add_header(struct sipmsg *msg, gchar *name, gchar *value) { | |
| 154 struct siphdrelement *element = g_new0(struct siphdrelement,1); | |
| 155 element->name = g_strdup(name); | |
| 156 element->value = g_strdup(value); | |
| 157 msg->headers = g_slist_append(msg->headers, element); | |
| 158 } | |
|
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11398
diff
changeset
|
159 |
| 11181 | 160 void sipmsg_free(struct sipmsg *msg) { |
| 161 struct siphdrelement *elem; | |
| 162 while(msg->headers) { | |
| 163 elem = msg->headers->data; | |
| 164 msg->headers = g_slist_remove(msg->headers,elem); | |
| 165 g_free(elem->name); | |
| 166 g_free(elem->value); | |
| 167 g_free(elem); | |
| 168 } | |
| 169 if(msg->method) g_free(msg->method); | |
| 170 if(msg->target) g_free(msg->target); | |
| 171 if(msg->body) g_free(msg->body); | |
| 172 g_free(msg); | |
| 173 } | |
| 174 | |
| 175 void sipmsg_remove_header(struct sipmsg *msg, gchar *name) { | |
| 176 struct siphdrelement *elem; | |
| 177 GSList *tmp = msg->headers; | |
| 178 while(tmp) { | |
| 179 elem = tmp->data; | |
| 180 if(strcmp(elem->name, name)==0) { | |
| 181 msg->headers = g_slist_remove(msg->headers, elem); | |
| 182 return; | |
| 183 } | |
| 184 tmp = g_slist_next(tmp); | |
| 185 } | |
| 186 return; | |
| 187 } | |
| 188 | |
| 189 gchar *sipmsg_find_header(struct sipmsg *msg, gchar *name) { | |
| 190 GSList *tmp; | |
| 191 struct siphdrelement *elem; | |
| 192 tmp = msg->headers; | |
| 193 while(tmp) { | |
| 194 elem = tmp->data; | |
| 195 if(strcmp(elem->name,name)==0) { | |
| 196 return elem->value; | |
| 197 } | |
| 198 tmp = g_slist_next(tmp); | |
| 199 } | |
| 200 return NULL; | |
| 201 } | |
| 202 |
