libpurple/protocols/jabber/jutil.c

Wed, 12 Jan 2011 14:31:52 +0000

author
Paul Aurich <darkrain42@pidgin.im>
date
Wed, 12 Jan 2011 14:31:52 +0000
changeset 31360
4ddd59618002
parent 31294
73607ab89c6f
child 31509
992ad686ba0b
permissions
-rw-r--r--

jabber: Be friendlier to servers when we have nothing to say.

Don't try to reconnect immediately, but do so when we have something
to send. Untested (I'll test it later), but I'm hoping hsitas444 will
test it first. Refs #13008.

7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
1 /*
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2 * purple - Jabber Protocol Plugin
3127
4213ad5b231c [gaim-migrate @ 3142]
Sean Egan <seanegan@pidgin.im>
parents: 2086
diff changeset
3 *
28322
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 27899
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 27899
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 27899
diff changeset
6 * source distribution.
3127
4213ad5b231c [gaim-migrate @ 3142]
Sean Egan <seanegan@pidgin.im>
parents: 2086
diff changeset
7 *
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
8 * This program is free software; you can redistribute it and/or modify
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
9 * it under the terms of the GNU General Public License as published by
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
11 * (at your option) any later version.
3127
4213ad5b231c [gaim-migrate @ 3142]
Sean Egan <seanegan@pidgin.im>
parents: 2086
diff changeset
12 *
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
13 * This program is distributed in the hope that it will be useful,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
16 * GNU General Public License for more details.
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
17 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
18 * You should have received a copy of the GNU General Public License
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
19 * 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: 15952
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
3127
4213ad5b231c [gaim-migrate @ 3142]
Sean Egan <seanegan@pidgin.im>
parents: 2086
diff changeset
21 *
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
22 */
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
23 #include "internal.h"
15952
c087855dc551 Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
24 #include "account.h"
25110
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
25 #include "cipher.h"
15952
c087855dc551 Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
26 #include "conversation.h"
25110
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
27 #include "debug.h"
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
28 #include "server.h"
8043
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
29 #include "util.h"
15952
c087855dc551 Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
30 #include "xmlnode.h"
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
31
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
32 #include "chat.h"
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
33 #include "presence.h"
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
34 #include "jutil.h"
3127
4213ad5b231c [gaim-migrate @ 3142]
Sean Egan <seanegan@pidgin.im>
parents: 2086
diff changeset
35
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
36 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
37 #include <idna.h>
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
38 #include <stringprep.h>
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
39 static char idn_buffer[1024];
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
40 #endif
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
41
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
42 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
43 static gboolean jabber_nodeprep(char *str, size_t buflen)
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
44 {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
45 return stringprep_xmpp_nodeprep(str, buflen) == STRINGPREP_OK;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
46 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
47
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
48 static gboolean jabber_resourceprep(char *str, size_t buflen)
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
49 {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
50 return stringprep_xmpp_resourceprep(str, buflen) == STRINGPREP_OK;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
51 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
52
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
53 static JabberID*
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
54 jabber_idn_validate(const char *str, const char *at, const char *slash,
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
55 const char *null)
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
56 {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
57 const char *node = NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
58 const char *domain = NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
59 const char *resource = NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
60 int node_len = 0;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
61 int domain_len = 0;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
62 int resource_len = 0;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
63 char *out;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
64 JabberID *jid;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
65
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
66 /* Ensure no parts are > 1023 bytes */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
67 if (at) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
68 node = str;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
69 node_len = at - str;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
70
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
71 domain = at + 1;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
72 if (slash) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
73 domain_len = slash - (at + 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
74 resource = slash + 1;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
75 resource_len = null - (slash + 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
76 } else {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
77 domain_len = null - (at + 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
78 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
79 } else {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
80 domain = str;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
81
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
82 if (slash) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
83 domain_len = slash - str;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
84 resource = slash;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
85 resource_len = null - (slash + 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
86 } else {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
87 domain_len = null - (str + 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
88 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
89 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
90
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
91 if (node && node_len > 1023)
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
92 return NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
93 if (domain_len > 1023)
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
94 return NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
95 if (resource && resource_len > 1023)
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
96 return NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
97
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
98 jid = g_new0(JabberID, 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
99
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
100 if (node) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
101 strncpy(idn_buffer, node, node_len);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
102 idn_buffer[node_len] = '\0';
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
103
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
104 if (!jabber_nodeprep(idn_buffer, sizeof(idn_buffer))) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
105 jabber_id_free(jid);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
106 jid = NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
107 goto out;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
108 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
109
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
110 jid->node = g_strdup(idn_buffer);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
111 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
112
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
113 /* domain *must* be here */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
114 strncpy(idn_buffer, domain, domain_len);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
115 idn_buffer[domain_len] = '\0';
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
116 if (domain[0] == '[') { /* IPv6 address */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
117 gboolean valid = FALSE;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
118
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
119 if (idn_buffer[domain_len - 1] == ']') {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
120 idn_buffer[domain_len - 1] = '\0';
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
121 valid = purple_ipv6_address_is_valid(idn_buffer + 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
122 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
123
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
124 if (!valid) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
125 jabber_id_free(jid);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
126 jid = NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
127 goto out;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
128 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
129 } else {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
130 /* Apply nameprep */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
131 if (stringprep_nameprep(idn_buffer, sizeof(idn_buffer)) != STRINGPREP_OK) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
132 jabber_id_free(jid);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
133 jid = NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
134 goto out;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
135 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
136
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
137 /* And now ToASCII */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
138 if (idna_to_ascii_8z(idn_buffer, &out, IDNA_USE_STD3_ASCII_RULES) != IDNA_SUCCESS) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
139 jabber_id_free(jid);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
140 jid = NULL;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
141 goto out;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
142 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
143
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
144 /* This *MUST* be freed using 'free', not 'g_free' */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
145 free(out);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
146 jid->domain = g_strdup(idn_buffer);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
147 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
148
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
149 if (resource) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
150 strncpy(idn_buffer, resource, resource_len);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
151 idn_buffer[resource_len] = '\0';
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
152
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
153 if (!jabber_resourceprep(idn_buffer, sizeof(idn_buffer))) {
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
154 jabber_id_free(jid);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
155 jid = NULL;
28535
2c150600a9e9 Fix a crash when attempting to validate a JID with an invalid resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 28431
diff changeset
156 goto out;
2c150600a9e9 Fix a crash when attempting to validate a JID with an invalid resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 28431
diff changeset
157 } else
2c150600a9e9 Fix a crash when attempting to validate a JID with an invalid resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 28431
diff changeset
158 jid->resource = g_strdup(idn_buffer);
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
159 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
160
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
161 out:
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
162 return jid;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
163 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
164
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
165 #endif /* USE_IDN */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
166
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
167 gboolean jabber_nodeprep_validate(const char *str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
168 {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
169 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
170 gboolean result;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
171 #else
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
172 const char *c;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
173 #endif
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
174
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
175 if(!str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
176 return TRUE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
177
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
178 if(strlen(str) > 1023)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
179 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
180
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
181 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
182 strncpy(idn_buffer, str, sizeof(idn_buffer) - 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
183 idn_buffer[sizeof(idn_buffer) - 1] = '\0';
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
184 result = jabber_nodeprep(idn_buffer, sizeof(idn_buffer));
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
185 return result;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
186 #else /* USE_IDN */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
187 c = str;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
188 while(c && *c) {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
189 gunichar ch = g_utf8_get_char(c);
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
190 if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' ||
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
191 ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
192 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
193 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
194 c = g_utf8_next_char(c);
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
195 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
196
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
197 return TRUE;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
198 #endif /* USE_IDN */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
199 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
200
27728
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
201 gboolean jabber_domain_validate(const char *str)
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
202 {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
203 const char *c;
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
204 size_t len;
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
205
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
206 if(!str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
207 return TRUE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
208
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
209 len = strlen(str);
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
210 if (len > 1023)
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
211 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
212
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
213 c = str;
27728
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
214
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
215 if (*c == '[') {
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
216 /* Check if str is a valid IPv6 identifier */
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
217 gboolean valid = FALSE;
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
218
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
219 if (*(c + len - 1) != ']')
27728
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
220 return FALSE;
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
221
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
222 /* Ugly, but in-place */
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
223 *(gchar *)(c + len - 1) = '\0';
27728
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
224 valid = purple_ipv6_address_is_valid(c + 1);
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
225 *(gchar *)(c + len - 1) = ']';
27728
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
226
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
227 return valid;
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
228 }
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
229
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
230 while(c && *c) {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
231 gunichar ch = g_utf8_get_char(c);
27720
a809853d8d46 Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents: 27719
diff changeset
232 /* The list of characters allowed in domain names is pretty small */
27722
3f93427031cd XMPP allows for internationalized domain names.
Paul Aurich <darkrain42@pidgin.im>
parents: 27721
diff changeset
233 if ((ch <= 0x7F && !( (ch >= 'a' && ch <= 'z')
27720
a809853d8d46 Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents: 27719
diff changeset
234 || (ch >= '0' && ch <= '9')
a809853d8d46 Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents: 27719
diff changeset
235 || (ch >= 'A' && ch <= 'Z')
a809853d8d46 Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents: 27719
diff changeset
236 || ch == '.'
27722
3f93427031cd XMPP allows for internationalized domain names.
Paul Aurich <darkrain42@pidgin.im>
parents: 27721
diff changeset
237 || ch == '-' )) || (ch >= 0x80 && !g_unichar_isgraph(ch)))
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
238 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
239
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
240 c = g_utf8_next_char(c);
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
241 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
242
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
243 return TRUE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
244 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
245
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
246 gboolean jabber_resourceprep_validate(const char *str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
247 {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
248 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
249 gboolean result;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
250 #else
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
251 const char *c;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
252 #endif
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
253
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
254 if(!str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
255 return TRUE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
256
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
257 if(strlen(str) > 1023)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
258 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
259
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
260 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
261 strncpy(idn_buffer, str, sizeof(idn_buffer) - 1);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
262 idn_buffer[sizeof(idn_buffer) - 1] = '\0';
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
263 result = jabber_resourceprep(idn_buffer, sizeof(idn_buffer));
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
264 return result;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
265 #else /* USE_IDN */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
266 c = str;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
267 while(c && *c) {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
268 gunichar ch = g_utf8_get_char(c);
7419
e21bf58df190 [gaim-migrate @ 8021]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
269 if(!g_unichar_isgraph(ch) && ch != ' ')
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
270 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
271
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
272 c = g_utf8_next_char(c);
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
273 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
274
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
275 return TRUE;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
276 #endif /* USE_IDN */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
277 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
278
29027
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
279 char *jabber_saslprep(const char *in)
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
280 {
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
281 #ifdef USE_IDN
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
282 char *out;
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
283
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
284 g_return_val_if_fail(in != NULL, NULL);
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
285 g_return_val_if_fail(strlen(in) <= sizeof(idn_buffer) - 1, NULL);
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
286
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
287 strncpy(idn_buffer, in, sizeof(idn_buffer) - 1);
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
288 idn_buffer[sizeof(idn_buffer) - 1] = '\0';
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
289
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
290 if (STRINGPREP_OK != stringprep(idn_buffer, sizeof(idn_buffer), 0,
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
291 stringprep_saslprep)) {
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
292 memset(idn_buffer, 0, sizeof(idn_buffer));
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
293 return NULL;
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
294 }
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
295
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
296 out = g_strdup(idn_buffer);
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
297 memset(idn_buffer, 0, sizeof(idn_buffer));
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
298 return out;
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
299 #else /* USE_IDN */
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
300 /* TODO: Something better than disallowing all non-ASCII characters */
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
301 /* TODO: Is this even correct? */
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
302 const guchar *c;
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
303
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
304 c = (const guchar *)in;
29830
ad339cd679d1 jabber: Oops. Make jabber_saslprep have a hope of not locking the program if built without IDN support.
Paul Aurich <darkrain42@pidgin.im>
parents: 29386
diff changeset
305 for ( ; *c; ++c) {
30455
8fa81888c974 jabber: Exclude ASCII 127 (Delete) from allowed SASLprep characters
Paul Aurich <darkrain42@pidgin.im>
parents: 29911
diff changeset
306 if (*c > 0x7f || /* Non-ASCII characters */
8fa81888c974 jabber: Exclude ASCII 127 (Delete) from allowed SASLprep characters
Paul Aurich <darkrain42@pidgin.im>
parents: 29911
diff changeset
307 *c == 0x7f || /* ASCII Delete character */
29027
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
308 (*c < 0x20 && *c != '\t' && *c != '\n' && *c != '\r'))
30455
8fa81888c974 jabber: Exclude ASCII 127 (Delete) from allowed SASLprep characters
Paul Aurich <darkrain42@pidgin.im>
parents: 29911
diff changeset
309 /* ASCII control characters */
29027
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
310 return NULL;
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
311 }
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
312
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
313 return g_strdup(in);
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
314 #endif /* USE_IDN */
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
315 }
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28535
diff changeset
316
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
317 static JabberID*
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
318 jabber_id_new_internal(const char *str, gboolean allow_terminating_slash)
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
319 {
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
320 const char *at = NULL;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
321 const char *slash = NULL;
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
322 const char *c;
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
323 gboolean needs_validation = FALSE;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
324 #if 0
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
325 gboolean node_is_required = FALSE;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
326 #endif
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
327 #ifndef USE_IDN
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
328 char *node = NULL;
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
329 char *domain;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
330 #endif
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
331 JabberID *jid;
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
332
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
333 if (!str)
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
334 return NULL;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
335
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
336 for (c = str; *c != '\0'; c++)
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
337 {
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
338 switch (*c) {
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
339 case '@':
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
340 if (!slash) {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
341 if (at) {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
342 /* Multiple @'s in the node/domain portion, not a valid JID! */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
343 return NULL;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
344 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
345 if (c == str) {
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
346 /* JIDs cannot start with @ */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
347 return NULL;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
348 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
349 if (c[1] == '\0') {
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
350 /* JIDs cannot end with @ */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
351 return NULL;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
352 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
353 at = c;
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
354 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
355 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
356
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
357 case '/':
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
358 if (!slash) {
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
359 if (c == str) {
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
360 /* JIDs cannot start with / */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
361 return NULL;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
362 }
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
363 if (c[1] == '\0' && !allow_terminating_slash) {
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
364 /* JIDs cannot end with / */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
365 return NULL;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
366 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
367 slash = c;
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
368 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
369 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
370
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
371 default:
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
372 /* characters allowed everywhere */
27719
cc4aea1fd74c Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents: 27714
diff changeset
373 if ((*c >= 'a' && *c <= 'z')
cc4aea1fd74c Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents: 27714
diff changeset
374 || (*c >= '0' && *c <= '9')
cc4aea1fd74c Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents: 27714
diff changeset
375 || (*c >= 'A' && *c <= 'Z')
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
376 || *c == '.' || *c == '-')
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
377 /* We're good */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
378 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
379
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
380 #if 0
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
381 if (slash != NULL) {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
382 /* characters allowed only in the resource */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
383 if (implement_me)
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
384 /* We're good */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
385 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
386 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
387
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
388 /* characters allowed only in the node */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
389 if (implement_me) {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
390 /*
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
391 * Ok, this character is valid, but only if it's a part
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
392 * of the node and not the domain. But we don't know
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
393 * if "c" is a part of the node or the domain until after
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
394 * we've found the @. So set a flag for now and check
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
395 * that we found an @ later.
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
396 */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
397 node_is_required = TRUE;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
398 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
399 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
400 #endif
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
401
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
402 /*
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
403 * Hmm, this character is a bit more exotic. Better fall
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
404 * back to using the more expensive UTF-8 compliant
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
405 * stringprep functions.
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
406 */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
407 needs_validation = TRUE;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
408 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
409 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
410 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
411
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
412 #if 0
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
413 if (node_is_required && at == NULL)
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
414 /* Found invalid characters in the domain */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
415 return NULL;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
416 #endif
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
417
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
418 if (!needs_validation) {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
419 /* JID is made of only ASCII characters--just lowercase and return */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
420 jid = g_new0(JabberID, 1);
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
421
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
422 if (at) {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
423 jid->node = g_ascii_strdown(str, at - str);
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
424 if (slash) {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
425 jid->domain = g_ascii_strdown(at + 1, slash - (at + 1));
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
426 if (*(slash + 1))
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
427 jid->resource = g_strdup(slash + 1);
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
428 } else {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
429 jid->domain = g_ascii_strdown(at + 1, -1);
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
430 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
431 } else {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
432 if (slash) {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
433 jid->domain = g_ascii_strdown(str, slash - str);
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
434 if (*(slash + 1))
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
435 jid->resource = g_strdup(slash + 1);
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
436 } else {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
437 jid->domain = g_ascii_strdown(str, -1);
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
438 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
439 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
440 return jid;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
441 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
442
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
443 /*
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
444 * If we get here, there are some non-ASCII chars in the string, so
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
445 * we'll need to validate it, normalize, and finally do a full jabber
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
446 * nodeprep on the jid.
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
447 */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
448
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
449 if (!g_utf8_validate(str, -1, NULL))
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
450 return NULL;
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
451
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
452 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
453 return jabber_idn_validate(str, at, slash, c /* points to the null */);
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
454 #else /* USE_IDN */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
455
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
456 jid = g_new0(JabberID, 1);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
457
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
458 /* normalization */
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
459 if(at) {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
460 node = g_utf8_casefold(str, at-str);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
461 if(slash) {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
462 domain = g_utf8_casefold(at+1, slash-(at+1));
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
463 if (*(slash + 1))
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
464 jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
465 } else {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
466 domain = g_utf8_casefold(at+1, -1);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
467 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
468 } else {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
469 if(slash) {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
470 domain = g_utf8_casefold(str, slash-str);
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
471 if (*(slash + 1))
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
472 jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
473 } else {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
474 domain = g_utf8_casefold(str, -1);
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
475 }
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
476 }
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
477
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
478 if (node) {
27819
48b1ba24def3 For JIDs, do strdown before normalization.
Paul Aurich <darkrain42@pidgin.im>
parents: 27731
diff changeset
479 jid->node = g_utf8_normalize(node, -1, G_NORMALIZE_NFKC);
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
480 g_free(node);
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
481 }
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
482
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
483 if (domain) {
27819
48b1ba24def3 For JIDs, do strdown before normalization.
Paul Aurich <darkrain42@pidgin.im>
parents: 27731
diff changeset
484 jid->domain = g_utf8_normalize(domain, -1, G_NORMALIZE_NFKC);
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
485 g_free(domain);
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
486 }
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
487
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
488 /* and finally the jabber nodeprep */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
489 if(!jabber_nodeprep_validate(jid->node) ||
27728
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
490 !jabber_domain_validate(jid->domain) ||
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
491 !jabber_resourceprep_validate(jid->resource)) {
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
492 jabber_id_free(jid);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
493 return NULL;
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
494 }
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
495
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
496 return jid;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
497 #endif /* USE_IDN */
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
498 }
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
499
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
500 void
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
501 jabber_id_free(JabberID *jid)
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
502 {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
503 if(jid) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
504 if(jid->node)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
505 g_free(jid->node);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
506 if(jid->domain)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
507 g_free(jid->domain);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
508 if(jid->resource)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
509 g_free(jid->resource);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
510 g_free(jid);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
511 }
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
512 }
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
513
29063
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
514 char *jabber_get_domain(const char *in)
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
515 {
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
516 JabberID *jid = jabber_id_new(in);
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
517 char *out;
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
518
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
519 if (!jid)
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
520 return NULL;
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
521
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
522 out = g_strdup(jid->domain);
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
523 jabber_id_free(jid);
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
524
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
525 return out;
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
526 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
527
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
528 char *jabber_get_resource(const char *in)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
529 {
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
530 JabberID *jid = jabber_id_new(in);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
531 char *out;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
532
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
533 if(!jid)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
534 return NULL;
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
535
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
536 out = g_strdup(jid->resource);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
537 jabber_id_free(jid);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
538
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
539 return out;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
540 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
541
28431
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
542 char *
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
543 jabber_get_bare_jid(const char *in)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
544 {
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
545 JabberID *jid = jabber_id_new(in);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
546 char *out;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
547
28431
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
548 if (!jid)
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
549 return NULL;
28431
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
550 out = jabber_id_get_bare_jid(jid);
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
551 jabber_id_free(jid);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
552
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
553 return out;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
554 }
7261
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
555
28431
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
556 char *
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
557 jabber_id_get_bare_jid(const JabberID *jid)
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
558 {
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
559 g_return_val_if_fail(jid != NULL, NULL);
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
560
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
561 return g_strconcat(jid->node ? jid->node : "",
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
562 jid->node ? "@" : "",
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
563 jid->domain,
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
564 NULL);
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
565 }
8450418b5abd jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents: 28414
diff changeset
566
29063
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
567 gboolean
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
568 jabber_jid_is_domain(const char *jid)
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
569 {
29097
0834410aa178 Tighter scoping and slightly less memory usage.
Paul Aurich <darkrain42@pidgin.im>
parents: 29085
diff changeset
570 const char *c;
29063
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
571
29097
0834410aa178 Tighter scoping and slightly less memory usage.
Paul Aurich <darkrain42@pidgin.im>
parents: 29085
diff changeset
572 for (c = jid; *c; ++c) {
0834410aa178 Tighter scoping and slightly less memory usage.
Paul Aurich <darkrain42@pidgin.im>
parents: 29085
diff changeset
573 if (*c == '@' || *c == '/')
0834410aa178 Tighter scoping and slightly less memory usage.
Paul Aurich <darkrain42@pidgin.im>
parents: 29085
diff changeset
574 return FALSE;
0834410aa178 Tighter scoping and slightly less memory usage.
Paul Aurich <darkrain42@pidgin.im>
parents: 29085
diff changeset
575 }
0834410aa178 Tighter scoping and slightly less memory usage.
Paul Aurich <darkrain42@pidgin.im>
parents: 29085
diff changeset
576
0834410aa178 Tighter scoping and slightly less memory usage.
Paul Aurich <darkrain42@pidgin.im>
parents: 29085
diff changeset
577 return TRUE;
29063
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
578 }
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
579
f245c5e9e9f3 jabber: When getting info on a "bare" domain JID, interpret the value of "last"
Marcus Lundblad <malu@pidgin.im>
parents: 28535
diff changeset
580
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
581 JabberID *
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
582 jabber_id_new(const char *str)
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
583 {
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
584 return jabber_id_new_internal(str, FALSE);
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
585 }
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
586
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
587 const char *jabber_normalize(const PurpleAccount *account, const char *in)
7261
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
588 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
589 PurpleConnection *gc = account ? account->gc : NULL;
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
590 JabberStream *js = gc ? gc->proto_data : NULL;
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
591 static char buf[3072]; /* maximum legal length of a jabber jid */
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
592 JabberID *jid;
7261
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
593
28414
5093c1a49d5c jabber: Use a better method for dealing with terminating slashes in JIDs.
Paul Aurich <darkrain42@pidgin.im>
parents: 28336
diff changeset
594 jid = jabber_id_new_internal(in, TRUE);
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
595 if(!jid)
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
596 return NULL;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
597
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
598 if(js && jid->node && jid->resource &&
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
599 jabber_chat_find(js, jid->node, jid->domain))
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
600 g_snprintf(buf, sizeof(buf), "%s@%s/%s", jid->node, jid->domain,
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
601 jid->resource);
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
602 else
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
603 g_snprintf(buf, sizeof(buf), "%s%s%s", jid->node ? jid->node : "",
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
604 jid->node ? "@" : "", jid->domain);
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
605
7429
bc354dd928bf [gaim-migrate @ 8033]
Nathan Walp <nwalp@pidgin.im>
parents: 7419
diff changeset
606 jabber_id_free(jid);
bc354dd928bf [gaim-migrate @ 8033]
Nathan Walp <nwalp@pidgin.im>
parents: 7419
diff changeset
607
7261
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
608 return buf;
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
609 }
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
610
27163
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
611 gboolean
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
612 jabber_is_own_server(JabberStream *js, const char *str)
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
613 {
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
614 JabberID *jid;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
615 gboolean equal;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
616
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
617 if (str == NULL)
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
618 return FALSE;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
619
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
620 g_return_val_if_fail(*str != '\0', FALSE);
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
621
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
622 jid = jabber_id_new(str);
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
623 if (!jid)
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
624 return FALSE;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
625
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
626 equal = (jid->node == NULL &&
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
627 g_str_equal(jid->domain, js->user->domain) &&
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
628 jid->resource == NULL);
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
629 jabber_id_free(jid);
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
630 return equal;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
631 }
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
632
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
633 gboolean
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
634 jabber_is_own_account(JabberStream *js, const char *str)
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
635 {
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
636 JabberID *jid;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
637 gboolean equal;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
638
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
639 if (str == NULL)
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
640 return TRUE;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
641
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
642 g_return_val_if_fail(*str != '\0', FALSE);
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
643
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
644 jid = jabber_id_new(str);
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
645 if (!jid)
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
646 return FALSE;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
647
27191
09b3a16e7330 Allow incoming stanzas to match 'our account' if they come from our resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 27163
diff changeset
648 equal = (purple_strequal(jid->node, js->user->node) &&
27163
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
649 g_str_equal(jid->domain, js->user->domain) &&
27191
09b3a16e7330 Allow incoming stanzas to match 'our account' if they come from our resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 27163
diff changeset
650 (jid->resource == NULL ||
09b3a16e7330 Allow incoming stanzas to match 'our account' if they come from our resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 27163
diff changeset
651 g_str_equal(jid->resource, js->user->resource)));
27163
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
652 jabber_id_free(jid);
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
653 return equal;
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
654 }
398d47149e2f Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents: 27130
diff changeset
655
29384
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
656 static const struct {
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
657 const char *status_id; /* link to core */
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
658 const char *show; /* The show child's cdata in a presence stanza */
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
659 const char *readable; /* readable representation */
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
660 JabberBuddyState state;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
661 } jabber_statuses[] = {
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
662 { "offline", NULL, N_("Offline"), JABBER_BUDDY_STATE_UNAVAILABLE },
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
663 { "available", NULL, N_("Available"), JABBER_BUDDY_STATE_ONLINE},
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
664 { "freeforchat", "chat", N_("Chatty"), JABBER_BUDDY_STATE_CHAT },
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
665 { "away", "away", N_("Away"), JABBER_BUDDY_STATE_AWAY },
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
666 { "extended_away", "xa", N_("Extended Away"), JABBER_BUDDY_STATE_XA },
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
667 { "dnd", "dnd", N_("Do Not Disturb"), JABBER_BUDDY_STATE_DND },
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
668 { "error", NULL, N_("Error"), JABBER_BUDDY_STATE_ERROR }
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
669 };
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
670
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
671 const char *
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
672 jabber_buddy_state_get_name(const JabberBuddyState state)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
673 {
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
674 int i;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
675 for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
676 if (jabber_statuses[i].state == state)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
677 return _(jabber_statuses[i].readable);
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
678
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
679 return _("Unknown");
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
680 }
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
681
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
682 JabberBuddyState
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
683 jabber_buddy_status_id_get_state(const char *id)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
684 {
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
685 int i;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
686 if (!id)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
687 return JABBER_BUDDY_STATE_UNKNOWN;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
688
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
689 for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
690 if (g_str_equal(id, jabber_statuses[i].status_id))
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
691 return jabber_statuses[i].state;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
692
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
693 return JABBER_BUDDY_STATE_UNKNOWN;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
694 }
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
695
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
696 JabberBuddyState jabber_buddy_show_get_state(const char *id)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
697 {
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
698 int i;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
699
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
700 g_return_val_if_fail(id != NULL, JABBER_BUDDY_STATE_UNKNOWN);
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
701
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
702 for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
29386
960464383e78 jabber: Oops, crashing bad.
Paul Aurich <darkrain42@pidgin.im>
parents: 29384
diff changeset
703 if (jabber_statuses[i].show && g_str_equal(id, jabber_statuses[i].show))
29384
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
704 return jabber_statuses[i].state;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
705
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
706 purple_debug_warning("jabber", "Invalid value of presence <show/> "
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
707 "attribute: %s\n", id);
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
708 return JABBER_BUDDY_STATE_UNKNOWN;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
709 }
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
710
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
711 const char *
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
712 jabber_buddy_state_get_show(JabberBuddyState state)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
713 {
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
714 int i;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
715 for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
716 if (state == jabber_statuses[i].state)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
717 return jabber_statuses[i].show;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
718
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
719 return NULL;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
720 }
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
721
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
722 const char *
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
723 jabber_buddy_state_get_status_id(JabberBuddyState state)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
724 {
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
725 int i;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
726 for (i = 0; i < G_N_ELEMENTS(jabber_statuses); ++i)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
727 if (state == jabber_statuses[i].state)
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
728 return jabber_statuses[i].status_id;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
729
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
730 return NULL;
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
731 }
b7b6be8f77fd jabber: Move those functions to jutil.[ch]
Paul Aurich <darkrain42@pidgin.im>
parents: 29336
diff changeset
732
25110
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
733 char *
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30455
diff changeset
734 jabber_calculate_data_hash(gconstpointer data, size_t len,
29910
f1c6e586e5c1 jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <malu@pidgin.im>
parents: 29830
diff changeset
735 const gchar *hash_algo)
25110
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
736 {
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
737 PurpleCipherContext *context;
29911
bce23fcd5c7d jabber: Use a 129 byte buffer to fit the hex output of SHA-512 (including \0)
Marcus Lundblad <malu@pidgin.im>
parents: 29910
diff changeset
738 static gchar digest[129]; /* 512 bits hex + \0 */
25110
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
739
29910
f1c6e586e5c1 jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <malu@pidgin.im>
parents: 29830
diff changeset
740 context = purple_cipher_context_new_by_name(hash_algo, NULL);
25110
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
741 if (context == NULL)
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
742 {
29910
f1c6e586e5c1 jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <malu@pidgin.im>
parents: 29830
diff changeset
743 purple_debug_error("jabber", "Could not find %s cipher\n", hash_algo);
25110
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
744 g_return_val_if_reached(NULL);
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
745 }
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
746
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
747 /* Hash the data */
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
748 purple_cipher_context_append(context, data, len);
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
749 if (!purple_cipher_context_digest_to_str(context, sizeof(digest), digest, NULL))
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
750 {
29910
f1c6e586e5c1 jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <malu@pidgin.im>
parents: 29830
diff changeset
751 purple_debug_error("jabber", "Failed to get digest for %s cipher.\n",
f1c6e586e5c1 jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <malu@pidgin.im>
parents: 29830
diff changeset
752 hash_algo);
25110
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
753 g_return_val_if_reached(NULL);
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
754 }
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
755 purple_cipher_context_destroy(context);
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
756
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
757 return g_strdup(digest);
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
758 }
40b3fffdb00b Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
759

mercurial