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