jabberd2  2.7.0
jid.h
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris
5  *
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.
10  *
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
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19  */
20 
35 #ifndef INCL_UTIL_JID_H
36 #define INCL_UTIL_JID_H 1
37 
39 #define MAXLEN_JID_COMP 1023 /* XMPP (RFC3920) 3.1 */
40 #define MAXLEN_JID 3071 /* nodename (1023) + '@' + domain (1023) + '/' + resource (1023) = 3071 */
41 
42 typedef struct jid_st {
43  /* basic components of the jid */
44  char *node;
45  char *domain;
46  char *resource;
47 
48  /* Points to jid broken with \0s into componets. node/domain/resource point
49  * into this string (or to statically allocated empty string, if they are
50  * empty) */
51  char *jid_data;
52  /* Valid only when jid_data != NULL. When = 0, jid_data is statically
53  * allocated. Otherwise it tells length of the allocated data. Used to
54  * implement jid_dup() */
55  size_t jid_data_len;
56 
57  /* the "user" part of the jid (sans resource) */
58  char *_user;
59 
60  /* the complete jid */
61  char *_full;
62 
63  /* application should set to 1 if user/full need regenerating */
64  int dirty;
65 
66  /* for lists of jids */
67  struct jid_st *next;
68 } *jid_t;
69 
70 typedef enum {
71  jid_NODE = 1,
74 } jid_part_t;
75 
77 typedef char jid_static_buf[3*1025];
78 
80 JABBERD2_API jid_t jid_new(const char *id, int len);
81 
85 
87 JABBERD2_API jid_t jid_reset(jid_t jid, const char *id, int len);
88 JABBERD2_API jid_t jid_reset_components(jid_t jid, const char *node, const char *domain, const char *resource);
89 
91 JABBERD2_API void jid_free(jid_t jid);
92 
94 JABBERD2_API int jid_prep(jid_t jid);
95 
98 
100 JABBERD2_API void jid_expand(jid_t jid);
101 
104 JABBERD2_API const char *jid_user(jid_t jid);
105 JABBERD2_API const char *jid_full(jid_t jid);
106 
111 
114 
118 JABBERD2_API int jid_search(jid_t list, jid_t jid);
119 
122 
125 
126 #endif
struct jid_st * jid_t
JABBERD2_API jid_t jid_reset(jid_t jid, const char *id, int len)
clear and populate the jid with the given id.
Definition: jid.c:113
char * _user
Definition: jid.h:58
JABBERD2_API jid_t jid_new(const char *id, int len)
make a new jid, and call jid_reset() to populate it
Definition: jid.c:81
int dirty
Definition: jid.h:64
#define JABBERD2_API
Definition: mio.h:39
JABBERD2_API 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...
Definition: jid.c:102
char * resource
Definition: jid.h:46
jid_part_t
Definition: jid.h:70
JABBERD2_API const char * jid_user(jid_t jid)
return the user or full jid.
Definition: jid.c:338
JABBERD2_API jid_t jid_zap(jid_t list, jid_t jid)
remove a jid from a list, and return the new list
Definition: jid.c:422
JABBERD2_API int jid_prep(jid_t jid)
do string preparation on a jid
Definition: jid.c:44
char * _full
Definition: jid.h:61
JABBERD2_API int jid_search(jid_t list, jid_t jid)
list helpers
Definition: jid.c:412
char jid_static_buf[3 *1025]
JID static buffer.
Definition: jid.h:77
Definition: jid.h:71
JABBERD2_API void jid_expand(jid_t jid)
expands user and full if the dirty flag is set
Definition: jid.c:298
char * domain
Definition: jid.h:45
Definition: jid.h:42
JABBERD2_API const char * jid_full(jid_t jid)
expand and return the full
Definition: jid.c:346
JABBERD2_API int jid_compare_user(jid_t a, jid_t b)
compare two user or full jids.
Definition: jid.c:354
JABBERD2_API jid_t jid_append(jid_t list, jid_t jid)
insert of a copy of jid into list, avoiding dups
Definition: jid.c:463
JABBERD2_API int jid_compare_full(jid_t a, jid_t b)
compare two full jids
Definition: jid.c:363
char * jid_data
Definition: jid.h:51
JABBERD2_API jid_t jid_dup(jid_t jid)
duplicate a jid
Definition: jid.c:372
JABBERD2_API void jid_random_part(jid_t jid, jid_part_t part)
fill jid's resource with a random string
Definition: jid.c:491
struct jid_st * next
Definition: jid.h:67
JABBERD2_API void jid_free(jid_t jid)
free the jid
Definition: jid.c:286
size_t jid_data_len
Definition: jid.h:55
Definition: jid.h:72
char * node
Definition: jid.h:44
JABBERD2_API jid_t jid_reset_components(jid_t jid, const char *node, const char *domain, const char *resource)
build a jid from components
Definition: jid.c:281