Mercurial > pidgin
annotate libpurple/protocols/jabber/jutil.c @ 27464:da3d0159333d
XMPP domains can also be IPv4 or IPv6 addresses
We don't have an IPv6 validation function and I didn't feel
like writing one, so I left those checks commented out and
added a note to jabber_nameprep_validate (which is
increasingly misnamed).
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sat, 11 Jul 2009 01:57:14 +0000 |
parents | 167d7c3a4f7b |
children | e90fa379fcec |
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 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
5 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
6 * 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
|
7 * 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
|
8 * 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
|
9 * (at your option) any later version. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
10 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
11 * 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
|
12 * 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
|
13 * 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
|
14 * GNU General Public License for more details. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
15 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
16 * 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
|
17 * 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
|
18 * 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
|
19 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
20 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
21 #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
|
22 #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
|
23 #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
|
24 #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
|
25 #include "debug.h" |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
26 #include "server.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
27 #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
|
28 #include "xmlnode.h" |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
29 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
30 #include "chat.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
31 #include "presence.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
32 #include "jutil.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
33 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
34 gboolean jabber_nodeprep_validate(const char *str) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
35 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
36 const char *c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
37 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
38 if(!str) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
39 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
40 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
41 if(strlen(str) > 1023) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
42 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
43 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
44 c = str; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
45 while(c && *c) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
46 gunichar ch = g_utf8_get_char(c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
47 if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
48 ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
49 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
50 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
51 c = g_utf8_next_char(c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
52 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
53 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
54 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
55 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
56 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
57 gboolean jabber_nameprep_validate(const char *str) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
58 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
59 const char *c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
60 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
61 if(!str) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
62 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
63 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
64 if(strlen(str) > 1023) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
65 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
66 |
27461
7e79102cda40
Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <mark@kingant.net>
parents:
27460
diff
changeset
|
67 /* |
27464
da3d0159333d
XMPP domains can also be IPv4 or IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
68 * TODO: An IPv6 address of the form [2001:470:1f05:d58::2] is also |
da3d0159333d
XMPP domains can also be IPv4 or IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents:
27463
diff
changeset
|
69 * a valid XMPP domain portion. |
27461
7e79102cda40
Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <mark@kingant.net>
parents:
27460
diff
changeset
|
70 */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
71 c = str; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
72 while(c && *c) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
73 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
|
74 /* 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
|
75 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
|
76 || (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
|
77 || (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
|
78 || ch == '.' |
27463
167d7c3a4f7b
XMPP allows for internationalized domain names.
Paul Aurich <paul@darkrain42.org>
parents:
27462
diff
changeset
|
79 || 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
|
80 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
81 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
82 c = g_utf8_next_char(c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
83 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
84 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
85 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
86 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
87 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
88 gboolean jabber_resourceprep_validate(const char *str) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
89 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
90 const char *c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
91 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
92 if(!str) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
93 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
94 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
95 if(strlen(str) > 1023) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
96 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
97 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
98 c = str; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
99 while(c && *c) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
100 gunichar ch = g_utf8_get_char(c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
101 if(!g_unichar_isgraph(ch) && ch != ' ') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
102 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
103 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
104 c = g_utf8_next_char(c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
105 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
106 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
107 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
108 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
109 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
110 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
111 JabberID* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
112 jabber_id_new(const char *str) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
113 { |
27454
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 #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
|
119 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
|
120 #endif |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
121 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
|
122 char *domain; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
123 JabberID *jid; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
124 |
27454
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
125 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
|
126 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
|
127 |
27456
04d8452dee48
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <mark@kingant.net>
parents:
27454
diff
changeset
|
128 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
|
129 { |
27456
04d8452dee48
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <mark@kingant.net>
parents:
27454
diff
changeset
|
130 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
|
131 case '@': |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
132 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
|
133 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
|
134 /* 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
|
135 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
|
136 } |
27456
04d8452dee48
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <mark@kingant.net>
parents:
27454
diff
changeset
|
137 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
|
138 /* 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
|
139 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
|
140 } |
27456
04d8452dee48
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <mark@kingant.net>
parents:
27454
diff
changeset
|
141 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
|
142 /* 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
|
143 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
|
144 } |
27456
04d8452dee48
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <mark@kingant.net>
parents:
27454
diff
changeset
|
145 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
|
146 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
147 break; |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
148 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
149 case '/': |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
150 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
|
151 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
|
152 /* 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
|
153 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
|
154 } |
27456
04d8452dee48
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <mark@kingant.net>
parents:
27454
diff
changeset
|
155 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
|
156 /* 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
|
157 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
|
158 } |
27456
04d8452dee48
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <mark@kingant.net>
parents:
27454
diff
changeset
|
159 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
|
160 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
161 break; |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
162 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
163 default: |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
164 /* characters allowed everywhere */ |
27460
8f2dfa6ef2f7
Of course, these should be >= and <=
Mark Doliner <mark@kingant.net>
parents:
27456
diff
changeset
|
165 if ((*c >= 'a' && *c <= 'z') |
8f2dfa6ef2f7
Of course, these should be >= and <=
Mark Doliner <mark@kingant.net>
parents:
27456
diff
changeset
|
166 || (*c >= '0' && *c <= '9') |
8f2dfa6ef2f7
Of course, these should be >= and <=
Mark Doliner <mark@kingant.net>
parents:
27456
diff
changeset
|
167 || (*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
|
168 || *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
|
169 /* 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
|
170 break; |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
171 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
172 #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
|
173 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
|
174 /* 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
|
175 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
|
176 /* 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
|
177 break; |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
178 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
179 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
180 /* 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
|
181 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
|
182 /* |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
183 * 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
|
184 * 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
|
185 * 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
|
186 * 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
|
187 * 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
|
188 */ |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
189 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
|
190 break; |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
191 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
192 #endif |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
193 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
194 /* |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
195 * 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
|
196 * 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
|
197 * 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
|
198 */ |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
199 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
|
200 break; |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
201 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
202 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
203 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
204 #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
|
205 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
|
206 /* 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
|
207 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
|
208 #endif |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
209 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
210 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
|
211 /* 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
|
212 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
|
213 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 jid->domain = g_ascii_strdown(at + 1, slash - (at + 1)); |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
218 jid->resource = g_strdup(slash + 1); |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
219 } else { |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
220 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
|
221 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
222 } else { |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
223 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
|
224 jid->domain = g_ascii_strdown(str, slash - str); |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
225 jid->resource = g_strdup(slash + 1); |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
226 } else { |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
227 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
|
228 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
229 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
230 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
|
231 } |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
232 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
233 /* |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
234 * 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
|
235 * 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
|
236 * 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
|
237 */ |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
238 |
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
239 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
|
240 return NULL; |
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 jid = g_new0(JabberID, 1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
243 |
27454
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
244 /* normalization */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
245 if(at) { |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
246 node = g_utf8_normalize(str, at-str, G_NORMALIZE_NFKC); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
247 if(slash) { |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
248 domain = g_utf8_normalize(at+1, slash-(at+1), G_NORMALIZE_NFKC); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
249 jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
250 } else { |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
251 domain = g_utf8_normalize(at+1, -1, G_NORMALIZE_NFKC); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
252 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
253 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
254 if(slash) { |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
255 domain = g_utf8_normalize(str, slash-str, G_NORMALIZE_NFKC); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
256 jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
257 } else { |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
258 domain = g_utf8_normalize(str, -1, G_NORMALIZE_NFKC); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
259 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
260 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
261 |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
262 if (node) { |
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
263 jid->node = g_utf8_strdown(node, -1); |
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
264 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
|
265 } |
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
266 |
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
267 if (domain) { |
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
268 jid->domain = g_utf8_strdown(domain, -1); |
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
269 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
|
270 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
271 |
27454
1b580473e753
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <mark@kingant.net>
parents:
27430
diff
changeset
|
272 /* and finally the jabber nodeprep */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
273 if(!jabber_nodeprep_validate(jid->node) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
274 !jabber_nameprep_validate(jid->domain) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
275 !jabber_resourceprep_validate(jid->resource)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
276 jabber_id_free(jid); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
277 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
278 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
279 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
280 return jid; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
281 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
282 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
283 void |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
284 jabber_id_free(JabberID *jid) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
285 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
286 if(jid) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
287 if(jid->node) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
288 g_free(jid->node); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
289 if(jid->domain) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
290 g_free(jid->domain); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
291 if(jid->resource) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
292 g_free(jid->resource); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
293 g_free(jid); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
294 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
295 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
296 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
297 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
298 char *jabber_get_resource(const char *in) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
299 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
300 JabberID *jid = jabber_id_new(in); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
301 char *out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
302 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
303 if(!jid) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
304 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
305 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
306 out = g_strdup(jid->resource); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
307 jabber_id_free(jid); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
308 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
309 return out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
310 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
311 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
312 char *jabber_get_bare_jid(const char *in) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
313 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
314 JabberID *jid = jabber_id_new(in); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
315 char *out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
316 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
317 if(!jid) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
318 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
319 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
320 out = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
321 jid->node ? "@" : "", jid->domain); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
322 jabber_id_free(jid); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
323 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
324 return out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
325 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
326 |
15822 | 327 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
|
328 { |
15822 | 329 PurpleConnection *gc = account ? account->gc : NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
330 JabberStream *js = gc ? gc->proto_data : NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
331 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
|
332 JabberID *jid; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
333 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
334 jid = jabber_id_new(in); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
335 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
336 if(!jid) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
337 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
338 |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 jid->resource); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
343 else |
26897
34e4e2ca7db9
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <paul@darkrain42.org>
parents:
24693
diff
changeset
|
344 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
|
345 jid->node ? "@" : "", jid->domain); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
346 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
347 jabber_id_free(jid); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
348 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
349 return buf; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
350 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
351 |
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
|
352 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
|
353 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
|
354 { |
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
|
355 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
|
356 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
|
357 |
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
|
358 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
|
359 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
|
360 |
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
|
361 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
|
362 |
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
|
363 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
|
364 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
|
365 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
|
366 |
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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 } |
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
|
373 |
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
|
374 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
|
375 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
|
376 { |
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
|
377 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
|
378 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
|
379 |
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
|
380 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
|
381 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
|
382 |
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
|
383 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
|
384 |
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
|
385 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
|
386 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
|
387 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
|
388 |
26968
fd7dc5cc0310
Allow incoming stanzas to match 'our account' if they come from our resource.
Paul Aurich <paul@darkrain42.org>
parents:
26941
diff
changeset
|
389 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
|
390 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
|
391 (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
|
392 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
|
393 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
|
394 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
|
395 } |
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
|
396 |
15822 | 397 PurpleConversation * |
398 jabber_find_unnormalized_conv(const char *name, PurpleAccount *account) | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
399 { |
15822 | 400 PurpleConversation *c = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
401 GList *cnv; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
402 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
403 g_return_val_if_fail(name != NULL, NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
404 |
15822 | 405 for(cnv = purple_get_conversations(); cnv; cnv = cnv->next) { |
406 c = (PurpleConversation*)cnv->data; | |
407 if(purple_conversation_get_type(c) == PURPLE_CONV_TYPE_IM && | |
408 !purple_utf8_strcasecmp(name, purple_conversation_get_name(c)) && | |
409 account == purple_conversation_get_account(c)) | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
410 return c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
411 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
412 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
413 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
414 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
415 |
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
|
416 /* The same as purple_util_get_image_checksum, but guaranteed to remain SHA1 */ |
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
|
417 char * |
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
|
418 jabber_calculate_data_sha1sum(gconstpointer data, size_t 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
|
419 { |
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
|
420 PurpleCipherContext *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
|
421 static gchar digest[41]; |
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
|
422 |
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
|
423 context = purple_cipher_context_new_by_name("sha1", 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
|
424 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
|
425 { |
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
|
426 purple_debug_error("jabber", "Could not find sha1 cipher\n"); |
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
|
427 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
|
428 } |
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
|
429 |
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
|
430 /* 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
|
431 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
|
432 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
|
433 { |
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
|
434 purple_debug_error("jabber", "Failed to get SHA-1 digest.\n"); |
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
|
435 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
|
436 } |
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
|
437 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
|
438 |
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
|
439 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
|
440 } |
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
|
441 |