Mercurial > hg
annotate mcabber/libjabber/jid.c @ 1197:6f602d3270a4
Add /pgp [-]force
With this command it becomes possible to enforce PGP encryption without
checking if the remote client has PGP support. It can be used to send
encrypted offline messages too.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 27 Apr 2007 00:37:57 +0200 |
parents | c3ae9251c197 |
children |
rev | line source |
---|---|
25 | 1 /* |
2 * This program is free software; you can redistribute it and/or modify | |
3 * it under the terms of the GNU General Public License as published by | |
4 * the Free Software Foundation; either version 2 of the License, or | |
5 * (at your option) any later version. | |
6 * | |
7 * This program is distributed in the hope that it will be useful, | |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 * GNU General Public License for more details. | |
11 * | |
12 * You should have received a copy of the GNU General Public License | |
13 * along with this program; if not, write to the Free Software | |
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
15 * | |
16 * Jabber | |
17 * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ | |
18 */ | |
19 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
20 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
21 * @file jid.c |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
22 * @brief representation and normalization of JabberIDs |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
23 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
24 |
25 | 25 #include "jabber.h" |
26 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
27 #ifdef LIBIDN |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
28 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
29 # include <stringprep.h> |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
30 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
31 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
32 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
33 * @brief datastructure to build the stringprep caches |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
34 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
35 typedef struct _jid_prep_entry_st { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
36 char *preped; /**< the result of the preparation, NULL if unchanged */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
37 time_t last_used; /**< when this result has last been successfully used */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
38 unsigned int used_count; /**< how often this result has been successfully used */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
39 int size; /**< the min buffer size needed to hold the result (strlen+1) */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
40 } *_jid_prep_entry_t; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
41 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
42 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
43 * @brief string preparation cache |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
44 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
45 typedef struct _jid_prep_cache_st { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
46 xht hashtable; /**< the hash table containing the preped strings */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
47 pth_mutex_t mutex; /**< mutex controling the access to the hashtable */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
48 const Stringprep_profile *profile; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
49 /**< the stringprep profile used for this cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
50 } *_jid_prep_cache_t; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
51 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
52 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
53 * stringprep cache containging already preped nodes |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
54 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
55 * we are using global caches here for two reasons: |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
56 * - I do not see why different instances would want |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
57 * to have different caches as we are always doing |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
58 * the same |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
59 * - For per instance caches I would have to modify the |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
60 * interface of the jid_*() functions which would break |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
61 * compatibility with transports |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
62 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
63 _jid_prep_cache_t _jid_prep_cache_node = NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
64 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
65 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
66 * stringprep cache containing already preped domains |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
67 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
68 _jid_prep_cache_t _jid_prep_cache_domain = NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
69 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
70 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
71 * stringprep cache containing already preped resources |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
72 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
73 _jid_prep_cache_t _jid_prep_cache_resource = NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
74 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
75 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
76 * walker for cleaning up stringprep caches |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
77 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
78 * @param h the hash we are walking through |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
79 * @param key the key of this item |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
80 * @param val the value of this item |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
81 * @param arg delete entries older as this unix timestamp |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
82 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
83 void _jid_clean_walker(xht h, const char *key, void *val, void *arg) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
84 time_t *keep_newer_as = (time_t*)arg; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
85 _jid_prep_entry_t entry = (_jid_prep_entry_t)val; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
86 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
87 if (entry == NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
88 return; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
89 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
90 if (entry->last_used <= *keep_newer_as) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
91 xhash_zap(h, key); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
92 if (entry->preped != NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
93 free(entry->preped); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
94 free(entry); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
95 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
96 /* sorry, I have to cast the const away */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
97 /* any idea how I could delete the key else? */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
98 if (key != NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
99 free((void*)key); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
100 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
101 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
102 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
103 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
104 * walk through a single stringprep cache and check which entries have expired |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
105 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
106 void _jid_clean_single_cache(_jid_prep_cache_t cache, time_t keep_newer_as) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
107 /* acquire the lock on the cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
108 pth_mutex_acquire(&(cache->mutex), FALSE, NULL); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
109 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
110 /* walk over all entries */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
111 xhash_walk(cache->hashtable, _jid_clean_walker, (void*)&keep_newer_as); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
112 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
113 /* we're done, release the lock on the cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
114 pth_mutex_release(&(cache->mutex)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
115 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
116 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
117 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
118 * walk through the stringprep caches and check which entries have expired |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
119 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
120 void jid_clean_cache() { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
121 /* XXX make this configurable? */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
122 time_t keep_newer_as = time(NULL) - 900; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
123 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
124 /* cleanup the nodeprep cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
125 _jid_clean_single_cache(_jid_prep_cache_node, keep_newer_as); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
126 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
127 /* cleanup the domain preparation cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
128 _jid_clean_single_cache(_jid_prep_cache_domain, keep_newer_as); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
129 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
130 /* cleanup the resourceprep cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
131 _jid_clean_single_cache(_jid_prep_cache_resource, keep_newer_as); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
132 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
133 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
134 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
135 * caching wrapper around a stringprep function |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
136 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
137 * @param in_out_buffer buffer containing what has to be stringpreped and that gets the result |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
138 * @param max_len size of the buffer |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
139 * @param cache the used cache, defining also the used stringprep profile |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
140 * @return the return code of the stringprep call |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
141 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
142 int _jid_cached_stringprep(char *in_out_buffer, int max_len, _jid_prep_cache_t cache) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
143 _jid_prep_entry_t preped; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
144 int result = STRINGPREP_OK; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
145 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
146 /* check that the cache already exists |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
147 * we can not do anything as we don't know which profile has to be used */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
148 if (cache == NULL) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
149 return STRINGPREP_UNKNOWN_PROFILE; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
150 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
151 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
152 /* is there something that has to be stringpreped? */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
153 if (in_out_buffer == NULL) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
154 return STRINGPREP_OK; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
155 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
156 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
157 /* acquire the lock on the cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
158 pth_mutex_acquire(&(cache->mutex), FALSE, NULL); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
159 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
160 /* check if the requested preparation has already been done */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
161 preped = (_jid_prep_entry_t)xhash_get(cache->hashtable, in_out_buffer); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
162 if (preped != NULL) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
163 /* we already prepared this argument */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
164 if (preped->size <= max_len) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
165 /* we can use the result */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
166 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
167 /* update the statistic */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
168 preped->used_count++; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
169 preped->last_used = time(NULL); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
170 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
171 /* do we need to copy the result? */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
172 if (preped->preped != NULL) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
173 /* copy the result */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
174 strcpy(in_out_buffer, preped->preped); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
175 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
176 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
177 result = STRINGPREP_OK; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
178 } else { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
179 /* we need a bigger buffer */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
180 result = STRINGPREP_TOO_SMALL_BUFFER; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
181 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
182 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
183 /* we're done, release the lock on the cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
184 pth_mutex_release(&(cache->mutex)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
185 } else { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
186 char *original; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
187 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
188 /* stringprep needs time, release the lock on the cache for the meantime */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
189 pth_mutex_release(&(cache->mutex)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
190 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
191 /* we have to keep the key */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
192 original = strdup(in_out_buffer); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
193 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
194 /* try to prepare the string */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
195 result = stringprep(in_out_buffer, max_len, STRINGPREP_NO_UNASSIGNED, cache->profile); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
196 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
197 /* did we manage to prepare the string? */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
198 if (result == STRINGPREP_OK && original != NULL) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
199 /* generate an entry for the cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
200 preped = (_jid_prep_entry_t)malloc(sizeof(struct _jid_prep_entry_st)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
201 if (preped != NULL) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
202 /* has there been modified something? */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
203 if (j_strcmp(in_out_buffer, original) == 0) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
204 /* no, we don't need to store a copy of the original string */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
205 preped->preped = NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
206 } else { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
207 /* yes, store the stringpreped string */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
208 preped->preped = strdup(in_out_buffer); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
209 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
210 preped->last_used = time(NULL); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
211 preped->used_count = 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
212 preped->size = strlen(in_out_buffer)+1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
213 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
214 /* acquire the lock on the cache again */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
215 pth_mutex_acquire(&(cache->mutex), FALSE, NULL); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
216 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
217 /* store the entry in the cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
218 xhash_put(cache->hashtable, original, preped); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
219 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
220 /* we're done, release the lock on the cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
221 pth_mutex_release(&(cache->mutex)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
222 } else { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
223 /* we don't need the copy of the key, if there is no memory to store it */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
224 free(original); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
225 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
226 } else { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
227 /* we don't need the copy of the original value */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
228 if (original != NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
229 free(original); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
230 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
231 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
232 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
233 return result; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
234 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
235 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
236 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
237 * free a single stringprep cache |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
238 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
239 * @param cache the cache to free |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
240 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
241 void _jid_stop_single_cache(_jid_prep_cache_t *cache) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
242 if (*cache == NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
243 return; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
244 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
245 _jid_clean_single_cache(*cache, time(NULL)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
246 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
247 pth_mutex_acquire(&((*cache)->mutex), FALSE, NULL); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
248 xhash_free((*cache)->hashtable); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
249 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
250 free(*cache); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
251 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
252 *cache = NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
253 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
254 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
255 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
256 * init a single stringprep cache |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
257 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
258 * @param cache the cache to init |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
259 * @param prime the prime used to init the hashtable |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
260 * @param profile profile used to prepare the strings |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
261 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
262 void _jid_init_single_cache(_jid_prep_cache_t *cache, int prime, const Stringprep_profile *profile) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
263 /* do not init a cache twice */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
264 if (*cache == NULL) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
265 *cache = (_jid_prep_cache_t)malloc(sizeof(struct _jid_prep_cache_st)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
266 pth_mutex_init(&((*cache)->mutex)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
267 (*cache)->hashtable = xhash_new(prime); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
268 (*cache)->profile = profile; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
269 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
270 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
271 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
272 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
273 * free the stringprep caches |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
274 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
275 void jid_stop_caching() { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
276 _jid_stop_single_cache(&_jid_prep_cache_node); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
277 _jid_stop_single_cache(&_jid_prep_cache_domain); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
278 _jid_stop_single_cache(&_jid_prep_cache_resource); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
279 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
280 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
281 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
282 * init the stringprep caches |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
283 * (do not call this twice at the same time, we do not have the mutexes yet) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
284 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
285 void jid_init_cache() { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
286 /* init the nodeprep cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
287 _jid_init_single_cache(&_jid_prep_cache_node, 2003, stringprep_xmpp_nodeprep); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
288 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
289 /* init the nameprep cache (domains) */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
290 _jid_init_single_cache(&_jid_prep_cache_domain, 2003, stringprep_nameprep); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
291 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
292 /* init the resourceprep cache */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
293 _jid_init_single_cache(&_jid_prep_cache_resource, 2003, stringprep_xmpp_resourceprep); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
294 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
295 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
296 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
297 * nameprep the domain identifier in a JID and check if it is valid |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
298 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
299 * @param jid data structure holding the JID |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
300 * @return 0 if JID is valid, non zero otherwise |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
301 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
302 int _jid_safe_domain(jid id) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
303 int result=0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
304 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
305 /* there must be a domain identifier */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
306 if (j_strlen(id->server) == 0) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
307 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
308 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
309 /* nameprep the domain identifier */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
310 result = _jid_cached_stringprep(id->server, strlen(id->server)+1, _jid_prep_cache_domain); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
311 if (result == STRINGPREP_TOO_SMALL_BUFFER) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
312 /* nameprep wants to expand the string, e.g. conversion from ß to ss */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
313 size_t biggerbuffersize = 1024; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
314 char *biggerbuffer = pmalloc(id->p, biggerbuffersize); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
315 if (biggerbuffer == NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
316 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
317 strcpy(biggerbuffer, id->server); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
318 result = _jid_cached_stringprep(biggerbuffer, biggerbuffersize, _jid_prep_cache_domain); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
319 id->server = biggerbuffer; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
320 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
321 if (result != STRINGPREP_OK) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
322 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
323 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
324 /* the namepreped domain must not be longer than 1023 bytes */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
325 if (j_strlen(id->server) > 1023) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
326 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
327 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
328 /* if nothing failed, the domain is valid */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
329 return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
330 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
331 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
332 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
333 * nodeprep the node identifier in a JID and check if it is valid |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
334 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
335 * @param jid data structure holding the JID |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
336 * @return 0 if JID is valid, non zero otherwise |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
337 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
338 int _jid_safe_node(jid id) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
339 int result=0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
340 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
341 /* it is valid to have no node identifier in the JID */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
342 if (id->user == NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
343 return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
344 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
345 /* nodeprep */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
346 result = _jid_cached_stringprep(id->user, strlen(id->user)+1, _jid_prep_cache_node); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
347 if (result == STRINGPREP_TOO_SMALL_BUFFER) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
348 /* nodeprep wants to expand the string, e.g. conversion from ß to ss */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
349 size_t biggerbuffersize = 1024; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
350 char *biggerbuffer = pmalloc(id->p, biggerbuffersize); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
351 if (biggerbuffer == NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
352 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
353 strcpy(biggerbuffer, id->user); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
354 result = _jid_cached_stringprep(biggerbuffer, biggerbuffersize, _jid_prep_cache_node); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
355 id->user = biggerbuffer; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
356 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
357 if (result != STRINGPREP_OK) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
358 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
359 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
360 /* the nodepreped node must not be longer than 1023 bytes */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
361 if (j_strlen(id->user) > 1023) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
362 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
363 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
364 /* if nothing failed, the node is valid */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
365 return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
366 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
367 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
368 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
369 * resourceprep the resource identifier in a JID and check if it is valid |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
370 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
371 * @param jid data structure holding the JID |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
372 * @return 0 if JID is valid, non zero otherwise |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
373 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
374 int _jid_safe_resource(jid id) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
375 int result=0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
376 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
377 /* it is valid to have no resource identifier in the JID */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
378 if (id->resource == NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
379 return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
380 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
381 /* resource prep the resource identifier */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
382 result = _jid_cached_stringprep(id->resource, strlen(id->resource)+1, _jid_prep_cache_resource); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
383 if (result == STRINGPREP_TOO_SMALL_BUFFER) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
384 /* resourceprep wants to expand the string, e.g. conversion from ß to ss */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
385 size_t biggerbuffersize = 1024; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
386 char *biggerbuffer = pmalloc(id->p, biggerbuffersize); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
387 if (biggerbuffer == NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
388 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
389 strcpy(biggerbuffer, id->resource); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
390 result = _jid_cached_stringprep(id->resource, strlen(id->resource)+1, _jid_prep_cache_resource); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
391 id->resource = biggerbuffer; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
392 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
393 if (result != STRINGPREP_OK) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
394 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
395 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
396 /* the resourcepreped node must not be longer than 1023 bytes */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
397 if (j_strlen(id->resource) > 1023) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
398 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
399 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
400 /* if nothing failed, the resource is valid */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
401 return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
402 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
403 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
404 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
405 #else /* no LIBIDN */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
406 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
407 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
408 * check if the domain identifier in a JID is valid |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
409 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
410 * @param jid data structure holding the JID |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
411 * @return 0 if domain is valid, non zero otherwise |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
412 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
413 int _jid_safe_domain(jid id) { |
25 | 414 char *str; |
415 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
416 /* there must be a domain identifier */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
417 if (j_strlen(id->server) == 0) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
418 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
419 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
420 /* and it must not be longer than 1023 bytes */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
421 if (strlen(id->server) > 1023) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
422 return 1; |
25 | 423 |
424 /* lowercase the hostname, make sure it's valid characters */ | |
425 for(str = id->server; *str != '\0'; str++) | |
426 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
427 *str = tolower(*str); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
428 if(!(isalnum(*str) || *str == '.' || *str == '-' || *str == '_')) return 1; |
25 | 429 } |
430 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
431 /* otherwise it's okay as far as we can tell without LIBIDN */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
432 return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
433 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
434 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
435 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
436 * check if the node identifier in a JID is valid |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
437 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
438 * @param jid data structure holding the JID |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
439 * @return 0 if node is valid, non zero otherwise |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
440 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
441 int _jid_safe_node(jid id) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
442 char *str; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
443 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
444 /* node identifiers may not be longer than 1023 bytes */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
445 if (j_strlen(id->user) > 1023) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
446 return 1; |
25 | 447 |
448 /* check for low and invalid ascii characters in the username */ | |
449 if(id->user != NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
450 for(str = id->user; *str != '\0'; str++) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
451 if(*str <= 32 || *str == ':' || *str == '@' || *str == '<' || *str == '>' || *str == '\'' || *str == '"' || *str == '&') return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
452 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
453 /* otherwise it's okay as far as we can tell without LIBIDN */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
454 return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
455 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
456 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
457 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
458 * check if the resource identifier in a JID is valid |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
459 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
460 * @param jid data structure holding the JID |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
461 * @return 0 if resource is valid, non zero otherwise |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
462 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
463 int _jid_safe_resource(jid id) { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
464 /* resources may not be longer than 1023 bytes */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
465 if (j_strlen(id->resource) > 1023) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
466 return 1; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
467 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
468 /* otherwise it's okay as far as we can tell without LIBIDN */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
469 return 0; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
470 } |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
471 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
472 #endif |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
473 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
474 /** |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
475 * nodeprep/nameprep/resourceprep the JID and check if it is valid |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
476 * |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
477 * @param jid data structure holding the JID |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
478 * @return NULL if the JID is invalid, pointer to the jid otherwise |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
479 */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
480 jid jid_safe(jid id) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
481 { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
482 if (_jid_safe_domain(id)) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
483 return NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
484 if (_jid_safe_node(id)) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
485 return NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
486 if (_jid_safe_resource(id)) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
487 return NULL; |
25 | 488 |
489 return id; | |
490 } | |
491 | |
492 jid jid_new(pool p, char *idstr) | |
493 { | |
494 char *server, *resource, *type, *str; | |
495 jid id; | |
496 | |
497 if(p == NULL || idstr == NULL || strlen(idstr) == 0) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
498 return NULL; |
25 | 499 |
500 /* user@server/resource */ | |
501 | |
502 str = pstrdup(p, idstr); | |
503 | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
504 id = pmalloco(p,sizeof(struct jid_struct)); |
25 | 505 id->p = p; |
506 | |
507 resource = strstr(str,"/"); | |
508 if(resource != NULL) | |
509 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
510 *resource = '\0'; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
511 ++resource; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
512 if(strlen(resource) > 0) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
513 id->resource = resource; |
25 | 514 }else{ |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
515 resource = str + strlen(str); /* point to end */ |
25 | 516 } |
517 | |
518 type = strstr(str,":"); | |
519 if(type != NULL && type < resource) | |
520 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
521 *type = '\0'; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
522 ++type; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
523 str = type; /* ignore the type: prefix */ |
25 | 524 } |
525 | |
526 server = strstr(str,"@"); | |
527 if(server == NULL || server > resource) | |
528 { /* if there's no @, it's just the server address */ | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
529 id->server = str; |
25 | 530 }else{ |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
531 *server = '\0'; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
532 ++server; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
533 id->server = server; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
534 if(strlen(str) > 0) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
535 id->user = str; |
25 | 536 } |
537 | |
538 return jid_safe(id); | |
539 } | |
540 | |
541 void jid_set(jid id, char *str, int item) | |
542 { | |
543 char *old; | |
544 | |
545 if(id == NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
546 return; |
25 | 547 |
548 /* invalidate the cached copy */ | |
549 id->full = NULL; | |
550 | |
551 switch(item) | |
552 { | |
553 case JID_RESOURCE: | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
554 old = id->resource; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
555 if(str != NULL && strlen(str) != 0) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
556 id->resource = pstrdup(id->p, str); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
557 else |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
558 id->resource = NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
559 if(_jid_safe_resource(id)) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
560 id->resource = old; /* revert if invalid */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
561 break; |
25 | 562 case JID_USER: |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
563 old = id->user; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
564 if(str != NULL && strlen(str) != 0) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
565 id->user = pstrdup(id->p, str); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
566 else |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
567 id->user = NULL; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
568 if(_jid_safe_node(id)) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
569 id->user = old; /* revert if invalid */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
570 break; |
25 | 571 case JID_SERVER: |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
572 old = id->server; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
573 id->server = pstrdup(id->p, str); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
574 if(_jid_safe_domain(id)) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
575 id->server = old; /* revert if invalid */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
576 break; |
25 | 577 } |
578 | |
579 } | |
580 | |
581 char *jid_full(jid id) | |
582 { | |
583 spool s; | |
584 | |
585 if(id == NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
586 return NULL; |
25 | 587 |
588 /* use cached copy */ | |
589 if(id->full != NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
590 return id->full; |
25 | 591 |
592 s = spool_new(id->p); | |
593 | |
594 if(id->user != NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
595 spooler(s, id->user,"@",s); |
25 | 596 |
597 spool_add(s, id->server); | |
598 | |
599 if(id->resource != NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
600 spooler(s, "/",id->resource,s); |
25 | 601 |
602 id->full = spool_print(s); | |
603 return id->full; | |
604 } | |
605 | |
606 /* parses a /resource?name=value&foo=bar into an xmlnode representing <resource name="value" foo="bar"/> */ | |
607 xmlnode jid_xres(jid id) | |
608 { | |
609 char *cur, *qmark, *amp, *eq; | |
610 xmlnode x; | |
611 | |
612 if(id == NULL || id->resource == NULL) return NULL; | |
613 | |
614 cur = pstrdup(id->p, id->resource); | |
615 qmark = strstr(cur, "?"); | |
616 if(qmark == NULL) return NULL; | |
617 *qmark = '\0'; | |
618 qmark++; | |
619 | |
620 x = _xmlnode_new(id->p, cur, NTYPE_TAG); | |
621 | |
622 cur = qmark; | |
623 while(cur != '\0') | |
624 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
625 eq = strstr(cur, "="); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
626 if(eq == NULL) break; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
627 *eq = '\0'; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
628 eq++; |
25 | 629 |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
630 amp = strstr(eq, "&"); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
631 if(amp != NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
632 { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
633 *amp = '\0'; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
634 amp++; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
635 } |
25 | 636 |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
637 xmlnode_put_attrib(x,cur,eq); |
25 | 638 |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
639 if(amp != NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
640 cur = amp; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
641 else |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
642 break; |
25 | 643 } |
644 | |
645 return x; | |
646 } | |
647 | |
648 /* local utils */ | |
649 int _jid_nullstrcmp(char *a, char *b) | |
650 { | |
651 if(a == NULL && b == NULL) return 0; | |
652 if(a == NULL || b == NULL) return -1; | |
653 return strcmp(a,b); | |
654 } | |
655 int _jid_nullstrcasecmp(char *a, char *b) | |
656 { | |
657 if(a == NULL && b == NULL) return 0; | |
658 if(a == NULL || b == NULL) return -1; | |
659 return strcasecmp(a,b); | |
660 } | |
661 | |
662 int jid_cmp(jid a, jid b) | |
663 { | |
664 if(a == NULL || b == NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
665 return -1; |
25 | 666 |
667 if(_jid_nullstrcmp(a->resource, b->resource) != 0) return -1; | |
668 if(_jid_nullstrcasecmp(a->user, b->user) != 0) return -1; | |
669 if(_jid_nullstrcmp(a->server, b->server) != 0) return -1; | |
670 | |
671 return 0; | |
672 } | |
673 | |
674 /* suggested by Anders Qvist <quest@valdez.netg.se> */ | |
675 int jid_cmpx(jid a, jid b, int parts) | |
676 { | |
677 if(a == NULL || b == NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
678 return -1; |
25 | 679 |
680 if(parts & JID_RESOURCE && _jid_nullstrcmp(a->resource, b->resource) != 0) return -1; | |
681 if(parts & JID_USER && _jid_nullstrcasecmp(a->user, b->user) != 0) return -1; | |
682 if(parts & JID_SERVER && _jid_nullstrcmp(a->server, b->server) != 0) return -1; | |
683 | |
684 return 0; | |
685 } | |
686 | |
687 /* makes a copy of b in a's pool, requires a valid a first! */ | |
688 jid jid_append(jid a, jid b) | |
689 { | |
690 jid next; | |
691 | |
692 if(a == NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
693 return NULL; |
25 | 694 |
695 if(b == NULL) | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
696 return a; |
25 | 697 |
698 next = a; | |
699 while(next != NULL) | |
700 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
701 /* check for dups */ |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
702 if(jid_cmp(next,b) == 0) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
703 break; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
704 if(next->next == NULL) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
705 next->next = jid_new(a->p,jid_full(b)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
706 next = next->next; |
25 | 707 } |
708 return a; | |
709 } | |
710 | |
711 xmlnode jid_nodescan(jid id, xmlnode x) | |
712 { | |
713 xmlnode cur; | |
714 pool p; | |
715 jid tmp; | |
716 | |
717 if(id == NULL || xmlnode_get_firstchild(x) == NULL) return NULL; | |
718 | |
719 p = pool_new(); | |
720 for(cur = xmlnode_get_firstchild(x); cur != NULL; cur = xmlnode_get_nextsibling(cur)) | |
721 { | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
722 if(xmlnode_get_type(cur) != NTYPE_TAG) continue; |
25 | 723 |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
724 tmp = jid_new(p,xmlnode_get_attrib(cur,"jid")); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
725 if(tmp == NULL) continue; |
25 | 726 |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
727 if(jid_cmp(tmp,id) == 0) break; |
25 | 728 } |
729 pool_free(p); | |
730 | |
731 return cur; | |
732 } | |
417
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
733 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
734 jid jid_user(jid a) |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
735 { |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
736 jid ret; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
737 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
738 if(a == NULL || a->resource == NULL) return a; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
739 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
740 ret = pmalloco(a->p,sizeof(struct jid_struct)); |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
741 ret->p = a->p; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
742 ret->user = a->user; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
743 ret->server = a->server; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
744 |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
745 return ret; |
c3ae9251c197
Sync libjabber with upstream
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
746 } |