22 #include <stringprep.h>
30 if(stringprep_xmpp_nodeprep(node, 1024) != 0)
33 if(stringprep_nameprep(domain, 1024) != 0)
36 if(resource[0] !=
'\0')
37 if(stringprep_xmpp_resourceprep(resource, 1024) != 0)
50 if(jid->
node != NULL) {
84 jid = malloc(
sizeof(
struct jid_st));
105 memset(jid, 0,
sizeof(*jid));
114 char *myid, *cur, *olddata=NULL;
116 assert((
int) (jid != NULL));
124 memset(jid, 0,
sizeof(
struct jid_st));
146 sprintf(myid,
"%.*s", len,
id);
149 if(myid[0] ==
'/' || myid[0] ==
'@') {
150 if(olddata == NULL) free(myid);
155 cur = strstr(myid,
"/");
161 if(strlen(cur) > 0) {
165 if(olddata == NULL) free(myid);
171 cur = strstr(myid,
"@");
175 if(strlen(cur) == 0) {
177 if(olddata == NULL) free(myid);
190 if(olddata == NULL) free(myid);
201 int node_l,domain_l,resource_l;
205 assert((
int) (jid != NULL));
212 if (jid->
_user != NULL )
214 if (jid->
_full != NULL )
217 memset(jid, 0,
sizeof(
struct jid_st));
220 node_l = strlen(node);
221 domain_l = strlen(domain);
222 resource_l = strlen(resource);
245 strncpy(jid->
node, node, node_l);
246 jid->
node[node_l] = 0;
249 strncpy(jid->
domain, domain, domain_l);
250 jid->
domain[domain_l] = 0;
253 strncpy(jid->
resource, resource, resource_l);
257 if((!dataStatic) && (olddata != NULL))
269 memcpy(jid->
jid_data,staticTmpBuf,node_l+domain_l+resource_l+3);
272 jid->
node = olddata+(jid->
node-(
char *)staticTmpBuf);
273 jid->
domain = olddata+(jid->
domain-(
char *)staticTmpBuf);
290 if (jid->
_user != NULL )
292 if (jid->
_full != NULL )
301 int nlen, dlen, rlen, ulen;
306 if(*jid->
domain ==
'\0') {
313 nlen = strlen(jid->
node);
314 dlen = strlen(jid->
domain);
319 jid->
_user = (
char*) realloc(jid->
_user, ulen);
322 ulen = nlen+1+dlen+1;
323 jid->
_user = (
char*) realloc(jid->
_user, ulen);
328 jid->
_full = (
char*) realloc(jid->
_full, ulen);
331 jid->
_full = (
char*) realloc(jid->
_full, ulen+1+rlen);
378 memcpy(
new, jid,
sizeof(
struct jid_st));
387 new->jid_data = malloc(new->jid_data_len);
388 memcpy(new->jid_data, jid->
jid_data, new->jid_data_len);
391 if(jid->
node[0] ==
'\0')
394 new->node =
new->jid_data + (jid->
node - jid->
jid_data);
395 if(jid->
domain[0] ==
'\0')
405 new->_user = strdup(jid->
_user);
407 new->_full = strdup(jid->
_full);
416 for(cur = list; cur != NULL; cur = cur->
next)
427 if(jid == NULL || list == NULL)
441 if(cur->
next == NULL)
479 if(scan->
next == NULL)
499 for(i = 0; i < 256; i++) {
500 r = (int) (36.0 * rand() / RAND_MAX);
501 randomBuf[i] = (r >= 0 && r <= 0) ? (r + 48) : (r + 87);
jid_t jid_reset(jid_t jid, const char *id, int len)
build a jid from an id
const char * jid_user(jid_t jid)
expand and return the user
const char * jid_full(jid_t jid)
expand and return the full
jid_t jid_new(const char *id, int len)
make a new jid
void jid_static(jid_t jid, jid_static_buf *buf)
Make jid to use static buffer (jid data won't be allocated dynamically, but given buffer will be alwa...
void shahash_r(const char *str, char hashbuf[41])
convenience (originally by Thomas Muldowney)
jid_t jid_zap(jid_t list, jid_t jid)
remove a jid_t from a list, returning the new list
void jid_random_part(jid_t jid, jid_part_t part)
create random resource
void jid_expand(jid_t jid)
build user and full if they're out of date
int jid_prep(jid_t jid)
do stringprep on the piece
jid_t jid_reset_components(jid_t jid, const char *node, const char *domain, const char *resource)
build a jid from components
char jid_static_buf[3 *1025]
JID static buffer.
int jid_search(jid_t list, jid_t jid)
util to search through jids
void jid_free(jid_t jid)
free a jid
#define MAXLEN_JID_COMP
these sizings come from xmpp-core
int jid_compare_full(jid_t a, jid_t b)
compare two full jids
jid_t jid_append(jid_t list, jid_t jid)
make a copy of jid, link into list (avoiding dups)
int jid_compare_user(jid_t a, jid_t b)
compare the user portion of two jids
static int jid_prep_pieces(char *node, char *domain, char *resource)
do stringprep on the pieces
jid_t jid_dup(jid_t jid)
duplicate a jid
static jid_t jid_reset_components_internal(jid_t jid, const char *node, const char *domain, const char *resource, int prepare)
Forward declaration.