Sat, 11 Jul 2009 01:57:14 +0000
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).
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 3127 | 3 | * |
| 7014 | 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
| 3127 | 5 | * |
| 7014 | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 3127 | 10 | * |
| 7014 | 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15952
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 3127 | 19 | * |
| 7014 | 20 | */ |
| 21 | #include "internal.h" | |
|
15952
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
22 | #include "account.h" |
|
25110
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
23 | #include "cipher.h" |
|
15952
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
24 | #include "conversation.h" |
|
25110
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
25 | #include "debug.h" |
| 7014 | 26 | #include "server.h" |
| 8043 | 27 | #include "util.h" |
|
15952
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
28 | #include "xmlnode.h" |
| 7014 | 29 | |
| 7322 | 30 | #include "chat.h" |
| 7014 | 31 | #include "presence.h" |
| 32 | #include "jutil.h" | |
| 3127 | 33 | |
| 7310 | 34 | gboolean jabber_nodeprep_validate(const char *str) |
| 35 | { | |
| 36 | const char *c; | |
| 37 | ||
| 38 | if(!str) | |
| 39 | return TRUE; | |
| 40 | ||
| 41 | if(strlen(str) > 1023) | |
| 42 | return FALSE; | |
| 43 | ||
| 44 | c = str; | |
| 45 | while(c && *c) { | |
| 46 | gunichar ch = g_utf8_get_char(c); | |
| 47 | if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' || | |
| 48 | ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) { | |
| 49 | return FALSE; | |
| 50 | } | |
| 51 | c = g_utf8_next_char(c); | |
| 52 | } | |
| 53 | ||
| 54 | return TRUE; | |
| 55 | } | |
| 56 | ||
| 57 | gboolean jabber_nameprep_validate(const char *str) | |
| 58 | { | |
| 59 | const char *c; | |
| 60 | ||
| 61 | if(!str) | |
| 62 | return TRUE; | |
| 63 | ||
| 64 | if(strlen(str) > 1023) | |
| 65 | return FALSE; | |
| 66 | ||
|
27720
a809853d8d46
Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents:
27719
diff
changeset
|
67 | /* |
|
27723
f209415e8338
XMPP domains can also be IPv4 or IPv6 addresses
Paul Aurich <darkrain42@pidgin.im>
parents:
27722
diff
changeset
|
68 | * TODO: An IPv6 address of the form [2001:470:1f05:d58::2] is also |
|
f209415e8338
XMPP domains can also be IPv4 or IPv6 addresses
Paul Aurich <darkrain42@pidgin.im>
parents:
27722
diff
changeset
|
69 | * a valid XMPP domain portion. |
|
27720
a809853d8d46
Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents:
27719
diff
changeset
|
70 | */ |
| 7310 | 71 | c = str; |
| 72 | while(c && *c) { | |
| 73 | gunichar ch = g_utf8_get_char(c); | |
|
27720
a809853d8d46
Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents:
27719
diff
changeset
|
74 | /* The list of characters allowed in domain names is pretty small */ |
|
27722
3f93427031cd
XMPP allows for internationalized domain names.
Paul Aurich <darkrain42@pidgin.im>
parents:
27721
diff
changeset
|
75 | if ((ch <= 0x7F && !( (ch >= 'a' && ch <= 'z') |
|
27720
a809853d8d46
Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents:
27719
diff
changeset
|
76 | || (ch >= '0' && ch <= '9') |
|
a809853d8d46
Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents:
27719
diff
changeset
|
77 | || (ch >= 'A' && ch <= 'Z') |
|
a809853d8d46
Be more restrictive in the characters allowed by jabber_nameprep_validate()
Mark Doliner <markdoliner@pidgin.im>
parents:
27719
diff
changeset
|
78 | || ch == '.' |
|
27722
3f93427031cd
XMPP allows for internationalized domain names.
Paul Aurich <darkrain42@pidgin.im>
parents:
27721
diff
changeset
|
79 | || ch == '-' )) || (ch >= 0x80 && !g_unichar_isgraph(ch))) |
| 7310 | 80 | return FALSE; |
| 81 | ||
| 82 | c = g_utf8_next_char(c); | |
| 83 | } | |
| 84 | ||
| 85 | return TRUE; | |
| 86 | } | |
| 87 | ||
| 88 | gboolean jabber_resourceprep_validate(const char *str) | |
| 89 | { | |
| 90 | const char *c; | |
| 91 | ||
| 92 | if(!str) | |
| 93 | return TRUE; | |
| 94 | ||
| 95 | if(strlen(str) > 1023) | |
| 96 | return FALSE; | |
| 97 | ||
| 98 | c = str; | |
| 99 | while(c && *c) { | |
| 100 | gunichar ch = g_utf8_get_char(c); | |
| 7419 | 101 | if(!g_unichar_isgraph(ch) && ch != ' ') |
| 7310 | 102 | return FALSE; |
| 103 | ||
| 104 | c = g_utf8_next_char(c); | |
| 105 | } | |
| 106 | ||
| 107 | return TRUE; | |
| 108 | } | |
| 109 | ||
| 110 | ||
| 7014 | 111 | JabberID* |
| 112 | jabber_id_new(const char *str) | |
| 2086 | 113 | { |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
114 | const char *at = NULL; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
115 | const char *slash = NULL; |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
116 | const char *c; |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
117 | gboolean needs_validation = FALSE; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
118 | #if 0 |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
119 | gboolean node_is_required = FALSE; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
120 | #endif |
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
121 | char *node = NULL; |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
122 | char *domain; |
| 7014 | 123 | JabberID *jid; |
| 2086 | 124 | |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
125 | if (!str) |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
126 | return NULL; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
127 | |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
128 | for (c = str; *c != '\0'; c++) |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
129 | { |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
130 | switch (*c) { |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
131 | case '@': |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
132 | if (!slash) { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
133 | if (at) { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
134 | /* Multiple @'s in the node/domain portion, not a valid JID! */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
135 | return NULL; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
136 | } |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
137 | if (c == str) { |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
138 | /* JIDs cannot start with @ */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
139 | return NULL; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
140 | } |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
141 | if (c[1] == '\0') { |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
142 | /* JIDs cannot end with @ */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
143 | return NULL; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
144 | } |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
145 | at = c; |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
146 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
147 | break; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
148 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
149 | case '/': |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
150 | if (!slash) { |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
151 | if (c == str) { |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
152 | /* JIDs cannot start with / */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
153 | return NULL; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
154 | } |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
155 | if (c[1] == '\0') { |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
156 | /* JIDs cannot end with / */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
157 | return NULL; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
158 | } |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
159 | slash = c; |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
160 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
161 | break; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
162 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
163 | default: |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
164 | /* characters allowed everywhere */ |
|
27719
cc4aea1fd74c
Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents:
27714
diff
changeset
|
165 | if ((*c >= 'a' && *c <= 'z') |
|
cc4aea1fd74c
Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents:
27714
diff
changeset
|
166 | || (*c >= '0' && *c <= '9') |
|
cc4aea1fd74c
Of course, these should be >= and <=
Mark Doliner <markdoliner@pidgin.im>
parents:
27714
diff
changeset
|
167 | || (*c >= 'A' && *c <= 'Z') |
|
27714
c86eb4fefae2
Change jabber_id_new() to iterate byte by byte instead of character
Mark Doliner <markdoliner@pidgin.im>
parents:
27713
diff
changeset
|
168 | || *c == '.' || *c == '-') |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
169 | /* We're good */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
170 | break; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
171 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
172 | #if 0 |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
173 | if (slash != NULL) { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
174 | /* characters allowed only in the resource */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
175 | if (implement_me) |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
176 | /* We're good */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
177 | break; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
178 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
179 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
180 | /* characters allowed only in the node */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
181 | if (implement_me) { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
182 | /* |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
183 | * Ok, this character is valid, but only if it's a part |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
184 | * of the node and not the domain. But we don't know |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
185 | * if "c" is a part of the node or the domain until after |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
186 | * we've found the @. So set a flag for now and check |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
187 | * that we found an @ later. |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
188 | */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
189 | node_is_required = TRUE; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
190 | break; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
191 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
192 | #endif |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
193 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
194 | /* |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
195 | * Hmm, this character is a bit more exotic. Better fall |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
196 | * back to using the more expensive UTF-8 compliant |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
197 | * stringprep functions. |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
198 | */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
199 | needs_validation = TRUE; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
200 | break; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
201 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
202 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
203 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
204 | #if 0 |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
205 | if (node_is_required && at == NULL) |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
206 | /* Found invalid characters in the domain */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
207 | return NULL; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
208 | #endif |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
209 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
210 | if (!needs_validation) { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
211 | /* JID is made of only ASCII characters--just lowercase and return */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
212 | jid = g_new0(JabberID, 1); |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
213 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
214 | if (at) { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
215 | jid->node = g_ascii_strdown(str, at - str); |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
216 | if (slash) { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
217 | jid->domain = g_ascii_strdown(at + 1, slash - (at + 1)); |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
218 | jid->resource = g_strdup(slash + 1); |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
219 | } else { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
220 | jid->domain = g_ascii_strdown(at + 1, -1); |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
221 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
222 | } else { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
223 | if (slash) { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
224 | jid->domain = g_ascii_strdown(str, slash - str); |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
225 | jid->resource = g_strdup(slash + 1); |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
226 | } else { |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
227 | jid->domain = g_ascii_strdown(str, -1); |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
228 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
229 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
230 | return jid; |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
231 | } |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
232 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
233 | /* |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
234 | * If we get here, there are some non-ASCII chars in the string, so |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
235 | * we'll need to validate it, normalize, and finally do a full jabber |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
236 | * nodeprep on the jid. |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
237 | */ |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
238 | |
|
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
239 | if (!g_utf8_validate(str, -1, NULL)) |
| 7014 | 240 | return NULL; |
| 2086 | 241 | |
| 7014 | 242 | jid = g_new0(JabberID, 1); |
| 243 | ||
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
244 | /* normalization */ |
| 7014 | 245 | if(at) { |
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
246 | node = g_utf8_normalize(str, at-str, G_NORMALIZE_NFKC); |
| 7014 | 247 | if(slash) { |
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
248 | domain = g_utf8_normalize(at+1, slash-(at+1), G_NORMALIZE_NFKC); |
| 7306 | 249 | jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC); |
| 7014 | 250 | } else { |
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
251 | domain = g_utf8_normalize(at+1, -1, G_NORMALIZE_NFKC); |
| 7014 | 252 | } |
| 253 | } else { | |
| 254 | if(slash) { | |
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
255 | domain = g_utf8_normalize(str, slash-str, G_NORMALIZE_NFKC); |
| 7306 | 256 | jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC); |
| 7014 | 257 | } else { |
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
258 | domain = g_utf8_normalize(str, -1, G_NORMALIZE_NFKC); |
| 7306 | 259 | } |
| 260 | } | |
| 261 | ||
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
262 | if (node) { |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
263 | jid->node = g_utf8_strdown(node, -1); |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
264 | g_free(node); |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
265 | } |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
266 | |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
267 | if (domain) { |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
268 | jid->domain = g_utf8_strdown(domain, -1); |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
269 | g_free(domain); |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
270 | } |
| 7306 | 271 | |
|
27713
9985f2f358c9
Check in a version of jabber_id_new() that is hopefully more efficient.
Mark Doliner <markdoliner@pidgin.im>
parents:
27689
diff
changeset
|
272 | /* and finally the jabber nodeprep */ |
| 7310 | 273 | if(!jabber_nodeprep_validate(jid->node) || |
| 274 | !jabber_nameprep_validate(jid->domain) || | |
| 275 | !jabber_resourceprep_validate(jid->resource)) { | |
| 7306 | 276 | jabber_id_free(jid); |
| 277 | return NULL; | |
| 278 | } | |
| 279 | ||
| 7014 | 280 | return jid; |
| 2086 | 281 | } |
| 282 | ||
| 7014 | 283 | void |
| 284 | jabber_id_free(JabberID *jid) | |
| 2086 | 285 | { |
| 7014 | 286 | if(jid) { |
| 287 | if(jid->node) | |
| 288 | g_free(jid->node); | |
| 289 | if(jid->domain) | |
| 290 | g_free(jid->domain); | |
| 291 | if(jid->resource) | |
| 292 | g_free(jid->resource); | |
| 293 | g_free(jid); | |
| 294 | } | |
| 2086 | 295 | } |
| 296 | ||
| 7014 | 297 | |
| 7306 | 298 | char *jabber_get_resource(const char *in) |
| 7014 | 299 | { |
| 7306 | 300 | JabberID *jid = jabber_id_new(in); |
| 301 | char *out; | |
| 7014 | 302 | |
| 7306 | 303 | if(!jid) |
| 7014 | 304 | return NULL; |
| 7306 | 305 | |
| 306 | out = g_strdup(jid->resource); | |
| 307 | jabber_id_free(jid); | |
| 308 | ||
| 309 | return out; | |
| 7014 | 310 | } |
| 311 | ||
| 7306 | 312 | char *jabber_get_bare_jid(const char *in) |
| 7014 | 313 | { |
| 7306 | 314 | JabberID *jid = jabber_id_new(in); |
| 315 | char *out; | |
| 7014 | 316 | |
| 7306 | 317 | if(!jid) |
| 318 | return NULL; | |
| 319 | ||
| 7322 | 320 | out = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
| 321 | jid->node ? "@" : "", jid->domain); | |
| 7306 | 322 | jabber_id_free(jid); |
| 323 | ||
| 324 | return out; | |
| 7014 | 325 | } |
| 7261 | 326 | |
| 15884 | 327 | const char *jabber_normalize(const PurpleAccount *account, const char *in) |
| 7261 | 328 | { |
| 15884 | 329 | PurpleConnection *gc = account ? account->gc : NULL; |
| 7322 | 330 | JabberStream *js = gc ? gc->proto_data : NULL; |
| 331 | static char buf[3072]; /* maximum legal length of a jabber jid */ | |
| 332 | JabberID *jid; | |
| 7261 | 333 | |
| 7322 | 334 | jid = jabber_id_new(in); |
| 7310 | 335 | |
| 7322 | 336 | if(!jid) |
| 7310 | 337 | return NULL; |
| 338 | ||
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
339 | if(js && jid->node && jid->resource && |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
340 | jabber_chat_find(js, jid->node, jid->domain)) |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
341 | g_snprintf(buf, sizeof(buf), "%s@%s/%s", jid->node, jid->domain, |
| 7322 | 342 | jid->resource); |
| 343 | else | |
|
27130
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
344 | g_snprintf(buf, sizeof(buf), "%s%s%s", jid->node ? jid->node : "", |
|
9cb09f3df8c7
jabber_id_new() needs to be case-folding the node and domain.
Paul Aurich <darkrain42@pidgin.im>
parents:
25110
diff
changeset
|
345 | jid->node ? "@" : "", jid->domain); |
| 7322 | 346 | |
| 7429 | 347 | jabber_id_free(jid); |
| 348 | ||
| 7261 | 349 | return buf; |
| 350 | } | |
| 7306 | 351 | |
|
27163
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
352 | gboolean |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
353 | jabber_is_own_server(JabberStream *js, const char *str) |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
354 | { |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
355 | JabberID *jid; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
356 | gboolean equal; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
357 | |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
358 | if (str == NULL) |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
359 | return FALSE; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
360 | |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
361 | g_return_val_if_fail(*str != '\0', FALSE); |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
362 | |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
363 | jid = jabber_id_new(str); |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
364 | if (!jid) |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
365 | return FALSE; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
366 | |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
367 | equal = (jid->node == NULL && |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
368 | g_str_equal(jid->domain, js->user->domain) && |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
369 | jid->resource == NULL); |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
370 | jabber_id_free(jid); |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
371 | return equal; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
372 | } |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
373 | |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
374 | gboolean |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
375 | jabber_is_own_account(JabberStream *js, const char *str) |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
376 | { |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
377 | JabberID *jid; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
378 | gboolean equal; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
379 | |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
380 | if (str == NULL) |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
381 | return TRUE; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
382 | |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
383 | g_return_val_if_fail(*str != '\0', FALSE); |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
384 | |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
385 | jid = jabber_id_new(str); |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
386 | if (!jid) |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
387 | return FALSE; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
388 | |
|
27191
09b3a16e7330
Allow incoming stanzas to match 'our account' if they come from our resource.
Paul Aurich <darkrain42@pidgin.im>
parents:
27163
diff
changeset
|
389 | equal = (purple_strequal(jid->node, js->user->node) && |
|
27163
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
390 | g_str_equal(jid->domain, js->user->domain) && |
|
27191
09b3a16e7330
Allow incoming stanzas to match 'our account' if they come from our resource.
Paul Aurich <darkrain42@pidgin.im>
parents:
27163
diff
changeset
|
391 | (jid->resource == NULL || |
|
09b3a16e7330
Allow incoming stanzas to match 'our account' if they come from our resource.
Paul Aurich <darkrain42@pidgin.im>
parents:
27163
diff
changeset
|
392 | g_str_equal(jid->resource, js->user->resource))); |
|
27163
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
393 | jabber_id_free(jid); |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
394 | return equal; |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
395 | } |
|
398d47149e2f
Add two helper functions useful for matching the 'from' attribute on packets to either our server or our account.
Paul Aurich <darkrain42@pidgin.im>
parents:
27130
diff
changeset
|
396 | |
| 15884 | 397 | PurpleConversation * |
| 398 | jabber_find_unnormalized_conv(const char *name, PurpleAccount *account) | |
| 8043 | 399 | { |
| 15884 | 400 | PurpleConversation *c = NULL; |
| 8043 | 401 | GList *cnv; |
| 402 | ||
| 403 | g_return_val_if_fail(name != NULL, NULL); | |
| 404 | ||
| 15884 | 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)) | |
| 8043 | 410 | return c; |
| 411 | } | |
| 412 | ||
| 413 | return NULL; | |
| 414 | } | |
| 8401 | 415 | |
|
25110
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
416 | /* The same as purple_util_get_image_checksum, but guaranteed to remain SHA1 */ |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
417 | char * |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
418 | jabber_calculate_data_sha1sum(gconstpointer data, size_t len) |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
419 | { |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
420 | PurpleCipherContext *context; |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
421 | static gchar digest[41]; |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
422 | |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
423 | context = purple_cipher_context_new_by_name("sha1", NULL); |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
424 | if (context == NULL) |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
425 | { |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
426 | purple_debug_error("jabber", "Could not find sha1 cipher\n"); |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
427 | g_return_val_if_reached(NULL); |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
428 | } |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
429 | |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
430 | /* Hash the data */ |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
431 | purple_cipher_context_append(context, data, len); |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
432 | if (!purple_cipher_context_digest_to_str(context, sizeof(digest), digest, NULL)) |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
433 | { |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
434 | purple_debug_error("jabber", "Failed to get SHA-1 digest.\n"); |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
435 | g_return_val_if_reached(NULL); |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
436 | } |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
437 | purple_cipher_context_destroy(context); |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
438 | |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
439 | return g_strdup(digest); |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
440 | } |
|
40b3fffdb00b
Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum
Paul Aurich <darkrain42@pidgin.im>
parents:
19859
diff
changeset
|
441 |