24
22
#include <stringprep.h>
27
24
/** Forward declaration **/
28
25
static jid_t jid_reset_components_internal(jid_t jid, const unsigned char *node, const unsigned char *domain, const unsigned char *resource, int prepare);
30
/** preparation cache */
31
prep_cache_t prep_cache_new(void) {
35
pc = (prep_cache_t) malloc(sizeof(struct prep_cache_st));
36
memset(pc, 0, sizeof(struct prep_cache_st));
38
pc->node = xhash_new(301);
39
pc->domain = xhash_new(301);
40
pc->resource = xhash_new(301);
48
void prep_cache_free(prep_cache_t pc) {
51
xhash_free(pc->domain);
52
xhash_free(pc->resource);
57
char *prep_cache_node_get(prep_cache_t pc, char *from) {
58
return (char *) xhash_get(pc->node, from);
61
void prep_cache_node_set(prep_cache_t pc, char *from, char *to) {
62
xhash_put(pc->node, pstrdup(xhash_pool(pc->node), from), (void *) pstrdup(xhash_pool(pc->node), to));
65
char *prep_cache_domain_get(prep_cache_t pc, char *from) {
66
return (char *) xhash_get(pc->domain, from);
69
void prep_cache_domain_set(prep_cache_t pc, char *from, char *to) {
70
xhash_put(pc->domain, pstrdup(xhash_pool(pc->domain), from), (void *) pstrdup(xhash_pool(pc->domain), to));
73
char *prep_cache_resource_get(prep_cache_t pc, char *from) {
74
return (char *) xhash_get(pc->resource, from);
77
void prep_cache_resource_set(prep_cache_t pc, char *from, char *to) {
78
xhash_put(pc->resource, pstrdup(xhash_pool(pc->resource), from), (void *) pstrdup(xhash_pool(pc->resource), to));
81
27
/** do stringprep on the pieces */
82
int jid_prep_pieces(prep_cache_t pc, char *node, char *domain, char *resource) {
28
static int jid_prep_pieces(char *node, char *domain, char *resource) {
84
29
char str[1024], *prep;
86
/* no cache, so do a real prep */
89
if(stringprep_xmpp_nodeprep(node, 1024) != 0)
92
if(stringprep_nameprep(domain, 1024) != 0)
95
if(resource[0] != '\0')
96
if(stringprep_xmpp_resourceprep(node, 1024) != 0)
103
if(node[0] != '\0') {
105
prep = prep_cache_node_get(pc, str);
109
if(stringprep_xmpp_nodeprep(str, 1024) != 0)
111
prep_cache_node_set(pc, node, str);
117
prep = prep_cache_domain_get(pc, str);
119
strcpy(domain, prep);
121
if(stringprep_nameprep(str, 1024) != 0)
123
prep_cache_domain_set(pc, domain, str);
127
if(resource[0] != '\0') {
128
strcpy(str, resource);
129
prep = prep_cache_resource_get(pc, str);
131
strcpy(resource, prep);
133
if(stringprep_xmpp_resourceprep(str, 1024) != 0)
135
prep_cache_resource_set(pc, resource, str);
136
strcpy(resource, str);
32
if(stringprep_xmpp_nodeprep(node, 1024) != 0)
35
if(stringprep_nameprep(domain, 1024) != 0)
38
if(resource[0] != '\0')
39
if(stringprep_xmpp_resourceprep(resource, 1024) != 0)
303
200
/** build a jid from components - internal version */
304
201
static jid_t jid_reset_components_internal(jid_t jid, const unsigned char *node, const unsigned char *domain, const unsigned char *resource, int prepare) {
306
202
unsigned char *olddata=NULL;
307
203
int node_l,domain_l,resource_l;
205
jid_static_buf staticTmpBuf;
207
assert((int) (jid != NULL));
313
209
if(jid->jid_data != NULL)
314
210
olddata = jid->jid_data; /* Store old data before clearing JID */