2 * presence module - presence server implementation
4 * Copyright (C) 2007 Voice Sistem S.R.L.
6 * This file is part of Kamailio, a free SIP server.
8 * Kamailio is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version
13 * Kamailio is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * \brief Kamailio presence module :: Hash tables
35 #include "../../core/lock_ops.h"
38 #define REMOTE_TYPE 1 << 1
39 #define LOCAL_TYPE 1 << 2
41 #define PKG_MEM_STR "pkg"
42 #define SHARE_MEM "share"
44 #define ERR_MEM(mem_type) \
46 LM_ERR("No more %s memory\n", mem_type); \
50 #define CONT_COPY(buf, dest, source) \
52 dest.s = (char *)buf + size; \
53 memcpy(dest.s, source.s, source.len); \
54 dest.len = source.len; \
58 #define PKG_MEM_TYPE (1 << 1)
59 #define SHM_MEM_TYPE (1 << 2)
61 extern int pres_delete_same_subs;
63 /* subscribe hash entry */
66 typedef struct subs_entry
68 struct subscription *entries;
72 typedef subs_entry_t *shtable_t;
74 shtable_t new_shtable(int hash_size);
76 struct subscription *search_shtable(shtable_t htable, str callid, str to_tag,
77 str from_tag, unsigned int hash_code);
80 shtable_t htable, unsigned int hash_code, struct subscription *subs);
83 shtable_t htable, unsigned int hash_code, struct subscription *subs);
85 int update_shtable(shtable_t htable, unsigned int hash_code,
86 struct subscription *subs, int type);
88 struct subscription *mem_copy_subs(struct subscription *s, int mem_type);
90 void free_subs_list(struct subscription *s_array, int mem_type, int ic);
92 void destroy_shtable(shtable_t htable, int hash_size);
94 /* subs htable functions type definitions */
95 typedef shtable_t (*new_shtable_t)(int hash_size);
97 typedef struct subscription *(*search_shtable_t)(shtable_t htable, str callid,
98 str to_tag, str from_tag, unsigned int hash_code);
100 typedef int (*insert_shtable_t)(
101 shtable_t htable, unsigned int hash_code, struct subscription *subs);
103 typedef int (*delete_shtable_t)(
104 shtable_t htable, unsigned int hash_code, struct subscription *subs);
106 typedef int (*update_shtable_t)(shtable_t htable, unsigned int hash_code,
107 struct subscription *subs, int type);
109 typedef void (*destroy_shtable_t)(shtable_t htable, int hash_size);
111 typedef struct subscription *(*mem_copy_subs_t)(
112 struct subscription *s, int mem_type);
115 /* presentity hash table */
116 typedef struct pres_entry
122 struct pres_entry *next;
125 typedef struct pres_phtable
127 pres_entry_t *entries;
131 phtable_t *new_phtable(void);
133 pres_entry_t *search_phtable(str *pres_uri, int event, unsigned int hash_code);
135 int insert_phtable(str *pres_uri, int event, char *sphere);
137 int update_phtable(struct presentity *presentity, str *pres_uri, str *body);
139 int delete_phtable(str *pres_uri, int event);
141 void destroy_phtable(void);
143 int delete_db_subs(str* to_tag, str* from_tag, str* callid);
145 typedef struct ps_presentity {
158 struct ps_presentity *next;
159 struct ps_presentity *prev;
162 typedef struct ps_pslot {
163 ps_presentity_t *plist;
167 typedef struct ps_ptable {
172 ps_presentity_t *ps_presentity_new(ps_presentity_t *pt, int mtype);
173 void ps_presentity_free(ps_presentity_t *pt, int mtype);
174 void ps_presentity_list_free(ps_presentity_t *pt, int mtype);
175 int ps_presentity_match(ps_presentity_t *pta, ps_presentity_t *ptb, int mmode);
176 int ps_ptable_init(int ssize);
177 void ps_ptable_destroy(void);
178 int ps_ptable_insert(ps_presentity_t *pt);
179 int ps_ptable_replace(ps_presentity_t *ptm, ps_presentity_t *pt);
180 int ps_ptable_update(ps_presentity_t *ptm, ps_presentity_t *pt);
181 int ps_ptable_remove(ps_presentity_t *pt);
182 ps_presentity_t *ps_ptable_get_list(str *user, str *domain);
183 ps_presentity_t *ps_ptable_get_item(str *user, str *domain, str *event, str *etag);
184 ps_presentity_t *ps_ptable_get_expired(int eval);
185 ps_ptable_t *ps_ptable_get(void);