libpurple/protocols/jabber/jutil.c

Sat, 22 Aug 2009 02:52:30 +0000

author
Paul Aurich <darkrain42@pidgin.im>
date
Sat, 22 Aug 2009 02:52:30 +0000
changeset 28322
ac8fec1d2234
parent 27899
c0c7be60adae
child 28336
b586fd490665
permissions
-rw-r--r--

Remove specific copyright lines from the XMPP prpl.

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;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
156 /* goto out; */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
157 }
27899
c0c7be60adae Oops, it helps to set the resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
158
c0c7be60adae Oops, it helps to set the resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 27898
diff changeset
159 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
160 }
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
161
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
162 out:
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
163 return jid;
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
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
166 #endif /* USE_IDN */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
167
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
168 gboolean jabber_nodeprep_validate(const char *str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
169 {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
170 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
171 gboolean result;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
172 #else
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
173 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
174 #endif
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
175
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
176 if(!str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
177 return TRUE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
178
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
179 if(strlen(str) > 1023)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
180 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
181
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
182 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
183 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
184 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
185 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
186 return result;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
187 #else /* USE_IDN */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
188 c = str;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
189 while(c && *c) {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
190 gunichar ch = g_utf8_get_char(c);
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
191 if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' ||
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
192 ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
193 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
194 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
195 c = g_utf8_next_char(c);
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
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
198 return TRUE;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
199 #endif /* USE_IDN */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
200 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
201
27728
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
202 gboolean jabber_domain_validate(const char *str)
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
203 {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
204 const char *c;
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
205 size_t len;
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
206
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
207 if(!str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
208 return TRUE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
209
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
210 len = strlen(str);
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
211 if (len > 1023)
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
212 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
213
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
214 c = str;
27728
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
215
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
216 if (*c == '[') {
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
217 /* 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
218 gboolean valid = FALSE;
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
219
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
220 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
221 return FALSE;
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
222
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
223 /* Ugly, but in-place */
27731
53ddfbc48e11 Save one traversal of the domain for IPv6 validation.
Paul Aurich <darkrain42@pidgin.im>
parents: 27728
diff changeset
224 *(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
225 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
226 *(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
227
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
228 return valid;
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
229 }
03b2a20ba465 Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 27723
diff changeset
230
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
231 while(c && *c) {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
232 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
233 /* 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
234 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
235 || (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
236 || (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
237 || ch == '.'
27722
3f93427031cd XMPP allows for internationalized domain names.
Paul Aurich <darkrain42@pidgin.im>
parents: 27721
diff changeset
238 || ch == '-' )) || (ch >= 0x80 && !g_unichar_isgraph(ch)))
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
239 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
240
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
241 c = g_utf8_next_char(c);
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
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
244 return TRUE;
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
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
247 gboolean jabber_resourceprep_validate(const char *str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
248 {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
249 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
250 gboolean result;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
251 #else
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
252 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
253 #endif
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
254
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
255 if(!str)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
256 return TRUE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
257
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
258 if(strlen(str) > 1023)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
259 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
260
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
261 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
262 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
263 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
264 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
265 return result;
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
266 #else /* USE_IDN */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
267 c = str;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
268 while(c && *c) {
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
269 gunichar ch = g_utf8_get_char(c);
7419
e21bf58df190 [gaim-migrate @ 8021]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
270 if(!g_unichar_isgraph(ch) && ch != ' ')
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
271 return FALSE;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
272
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
273 c = g_utf8_next_char(c);
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
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
276 return TRUE;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
277 #endif /* USE_IDN */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
278 }
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
279
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
280 JabberID*
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
281 jabber_id_new(const char *str)
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
282 {
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
283 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
284 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
285 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
286 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
287 #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
288 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
289 #endif
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
290 #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
291 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
292 char *domain;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
293 #endif
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
294 JabberID *jid;
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
295
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
296 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
297 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
298
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
299 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
300 {
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
301 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
302 case '@':
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
303 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
304 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
305 /* 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
306 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
307 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
308 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
309 /* 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
310 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
311 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
312 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
313 /* 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
314 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
315 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
316 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
317 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
318 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
319
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
320 case '/':
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
321 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
322 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
323 /* 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
324 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
325 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
326 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
327 /* 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
328 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
329 }
27714
c86eb4fefae2 Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents: 27713
diff changeset
330 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
331 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
332 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
333
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
334 default:
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
335 /* characters allowed everywhere */
27719
cc4aea1fd74c Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents: 27714
diff changeset
336 if ((*c >= 'a' && *c <= 'z')
cc4aea1fd74c Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents: 27714
diff changeset
337 || (*c >= '0' && *c <= '9')
cc4aea1fd74c Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents: 27714
diff changeset
338 || (*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
339 || *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
340 /* 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
341 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
342
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
343 #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
344 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
345 /* 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
346 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
347 /* 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
348 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
349 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
350
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
351 /* 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
352 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
353 /*
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
354 * 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
355 * 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
356 * 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
357 * 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
358 * 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
359 */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
360 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
361 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
362 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
363 #endif
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
364
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
365 /*
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
366 * 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
367 * 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
368 * 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
369 */
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
370 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
371 break;
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
372 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
373 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
374
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
375 #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
376 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
377 /* 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
378 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
379 #endif
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
380
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 (!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
382 /* 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
383 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
384
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
385 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
386 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
387 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
388 jid->domain = g_ascii_strdown(at + 1, slash - (at + 1));
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
389 jid->resource = g_strdup(slash + 1);
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
390 } else {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
391 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
392 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
393 } else {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
394 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
395 jid->domain = g_ascii_strdown(str, slash - str);
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
396 jid->resource = g_strdup(slash + 1);
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
397 } else {
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
398 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
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 }
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
401 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
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
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
404 /*
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
405 * 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
406 * 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
407 * 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
408 */
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 if (!g_utf8_validate(str, -1, NULL))
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
411 return NULL;
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
412
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
413 #ifdef USE_IDN
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
414 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
415 #else /* USE_IDN */
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
416
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
417 jid = g_new0(JabberID, 1);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
418
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
419 /* normalization */
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
420 if(at) {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
421 node = g_utf8_casefold(str, at-str);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
422 if(slash) {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
423 domain = g_utf8_casefold(at+1, slash-(at+1));
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
424 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
425 } else {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
426 domain = g_utf8_casefold(at+1, -1);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
427 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
428 } else {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
429 if(slash) {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
430 domain = g_utf8_casefold(str, slash-str);
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
431 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
432 } else {
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
433 domain = g_utf8_casefold(str, -1);
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
434 }
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
435 }
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
436
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
437 if (node) {
27819
48b1ba24def3 For JIDs, do strdown before normalization.
Paul Aurich <darkrain42@pidgin.im>
parents: 27731
diff changeset
438 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
439 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
440 }
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
441
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
442 if (domain) {
27819
48b1ba24def3 For JIDs, do strdown before normalization.
Paul Aurich <darkrain42@pidgin.im>
parents: 27731
diff changeset
443 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
444 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
445 }
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
446
27713
9985f2f358c9 Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents: 27689
diff changeset
447 /* and finally the jabber nodeprep */
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
448 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
449 !jabber_domain_validate(jid->domain) ||
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
450 !jabber_resourceprep_validate(jid->resource)) {
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
451 jabber_id_free(jid);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
452 return NULL;
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
453 }
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
454
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
455 return jid;
27849
7f7428cb8309 When GNU Libidn is available, use it for XMPP stringprep operations.
Paul Aurich <darkrain42@pidgin.im>
parents: 27819
diff changeset
456 #endif /* USE_IDN */
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
457 }
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
458
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
459 void
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
460 jabber_id_free(JabberID *jid)
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
461 {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
462 if(jid) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
463 if(jid->node)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
464 g_free(jid->node);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
465 if(jid->domain)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
466 g_free(jid->domain);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
467 if(jid->resource)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
468 g_free(jid->resource);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
469 g_free(jid);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
470 }
2086
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
471 }
007508451e2c [gaim-migrate @ 2096]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
472
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
473
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
474 char *jabber_get_resource(const char *in)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
475 {
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
476 JabberID *jid = jabber_id_new(in);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
477 char *out;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
478
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
479 if(!jid)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
480 return NULL;
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
481
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
482 out = g_strdup(jid->resource);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
483 jabber_id_free(jid);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
484
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
485 return out;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
486 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
487
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
488 char *jabber_get_bare_jid(const char *in)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
489 {
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
490 JabberID *jid = jabber_id_new(in);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
491 char *out;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
492
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
493 if(!jid)
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
494 return NULL;
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
495
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
496 out = g_strdup_printf("%s%s%s", jid->node ? jid->node : "",
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
497 jid->node ? "@" : "", jid->domain);
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
498 jabber_id_free(jid);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
499
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
500 return out;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents: 3717
diff changeset
501 }
7261
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
502
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
503 const char *jabber_normalize(const PurpleAccount *account, const char *in)
7261
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
504 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
505 PurpleConnection *gc = account ? account->gc : NULL;
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
506 JabberStream *js = gc ? gc->proto_data : NULL;
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
507 static char buf[3072]; /* maximum legal length of a jabber jid */
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
508 JabberID *jid;
7261
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
509
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
510 jid = jabber_id_new(in);
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
511
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
512 if(!jid)
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
513 return NULL;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
514
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
515 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
516 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
517 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
518 jid->resource);
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
519 else
27130
9cb09f3df8c7 jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents: 25110
diff changeset
520 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
521 jid->node ? "@" : "", jid->domain);
7322
de15a9314c04 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
522
7429
bc354dd928bf [gaim-migrate @ 8033]
Nathan Walp <nwalp@pidgin.im>
parents: 7419
diff changeset
523 jabber_id_free(jid);
bc354dd928bf [gaim-migrate @ 8033]
Nathan Walp <nwalp@pidgin.im>
parents: 7419
diff changeset
524
7261
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
525 return buf;
4be05820d441 [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
526 }
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
527
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
528 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
529 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
530 {
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
531 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
532 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
533
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
534 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
535 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
536
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
537 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
538
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
539 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
540 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
541 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
542
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
543 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
544 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
545 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
546 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
547 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
548 }
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
549
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
550 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
551 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
552 {
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
553 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
554 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
555
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
556 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
557 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
558
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
559 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
560
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
561 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
562 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
563 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
564
27191
09b3a16e7330 Allow incoming stanzas to match 'our account' if they come from our resource.
Paul Aurich <darkrain42@pidgin.im>
parents: 27163
diff changeset
565 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
566 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
567 (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
568 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
569 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
570 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
571 }
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
572
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
573 PurpleConversation *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
574 jabber_find_unnormalized_conv(const char *name, PurpleAccount *account)
8043
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
575 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
576 PurpleConversation *c = NULL;
8043
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
577 GList *cnv;
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
578
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
579 g_return_val_if_fail(name != NULL, NULL);
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
580
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
581 for(cnv = purple_get_conversations(); cnv; cnv = cnv->next) {
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
582 c = (PurpleConversation*)cnv->data;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
583 if(purple_conversation_get_type(c) == PURPLE_CONV_TYPE_IM &&
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
584 !purple_utf8_strcasecmp(name, purple_conversation_get_name(c)) &&
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
585 account == purple_conversation_get_account(c))
8043
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
586 return c;
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
587 }
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
588
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
589 return NULL;
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
590 }
8401
9fe6cadf2581 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
591
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
592 /* The same as purple_util_get_image_checksum, but guaranteed to remain SHA1 */
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
593 char *
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
594 jabber_calculate_data_sha1sum(gconstpointer data, size_t 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
595 {
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
596 PurpleCipherContext *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
597 static gchar digest[41];
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
598
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
599 context = purple_cipher_context_new_by_name("sha1", 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
600 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
601 {
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
602 purple_debug_error("jabber", "Could not find sha1 cipher\n");
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
603 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
604 }
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
605
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
606 /* 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
607 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
608 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
609 {
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
610 purple_debug_error("jabber", "Failed to get SHA-1 digest.\n");
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
611 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
612 }
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
613 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
614
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
615 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
616 }
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
617

mercurial