-
Notifications
You must be signed in to change notification settings - Fork 564
/
hash.h
162 lines (120 loc) · 4.26 KB
/
hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* $Id$
*
* presence module - presence server implementation
*
* Copyright (C) 2007 Voice Sistem S.R.L.
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2007-08-20 initial version (Anca Vamanu)
*/
#ifndef PS_HASH_H
#define PS_HASH_H
#include "../../lock_ops.h"
#include "../../str.h"
//#include "presentity.h"
struct presentity;
#define REMOTE_TYPE 1<<1
#define LOCAL_TYPE 1<<2
#define PKG_MEM_STR "pkg"
#define SHARE_MEM "share"
#define ETAG_LEN 128
#define ERR_MEM(mem_type) \
do { LM_ERR("No more %s memory\n",mem_type);\
goto error;\
} while(0)
#define CONT_COPY_P_x(buf, dest, source)\
do{ dest= (str*)((char*)buf+ size);\
size+= sizeof(str);\
dest->s = (char*)buf + size;\
memcpy(dest->s, source->s, source->len);\
dest->len= source->len;\
size+= source->len;\
} while(0)
#define CONT_COPY(buf, dest, source)\
do{ dest.s= (char*)buf+ size;\
memcpy(dest.s, source.s, source.len);\
dest.len= source.len;\
size+= source.len;\
} while(0)
#define PKG_MEM_TYPE 0
#define SHM_MEM_TYPE 1
/* subscribe hash entry */
struct subscription;
typedef struct subs_entry
{
struct subscription* entries;
gen_lock_t lock;
}subs_entry_t;
typedef subs_entry_t* shtable_t;
shtable_t new_shtable(int hash_size);
struct subscription* search_shtable(shtable_t htable, str callid,str to_tag,str from_tag,
unsigned int hash_code);
int insert_shtable(shtable_t htable, unsigned int hash_code, struct subscription* subs);
int delete_shtable(shtable_t htable, unsigned int hash_code, str to_tag);
int update_shtable(shtable_t htable, unsigned int hash_code, struct subscription* subs,
int type);
struct subscription* mem_copy_subs(struct subscription* s, int mem_type);
void free_subs_list(struct subscription* s_array, int mem_type, int ic);
void destroy_shtable(shtable_t htable, int hash_size);
/* subs htable functions type definitions */
typedef shtable_t (*new_shtable_t)(int hash_size);
typedef struct subscription* (*search_shtable_t)(shtable_t htable, str callid,str to_tag,
str from_tag, unsigned int hash_code);
typedef int (*insert_shtable_t)(shtable_t htable, unsigned int hash_code,
struct subscription* subs);
typedef int (*delete_shtable_t)(shtable_t htable, unsigned int hash_code,
str to_tag);
typedef int (*update_shtable_t)(shtable_t htable, unsigned int hash_code,
struct subscription* subs, int type);
typedef void (*destroy_shtable_t)(shtable_t htable, int hash_size);
typedef struct subscription* (*mem_copy_subs_t)(struct subscription* s, int mem_type);
void free_subs(struct subscription* s);
/* presentity hash table */
typedef struct pres_entry
{
str pres_uri;
int event;
int etag_count;
char* sphere;
char etag[ETAG_LEN];
int etag_len;
/* ordering */
unsigned int current_turn;
unsigned int last_turn;
struct pres_entry* next;
}pres_entry_t;
typedef struct pres_htable
{
pres_entry_t* entries;
gen_lock_t lock;
}phtable_t;
phtable_t* new_phtable(void);
pres_entry_t* search_phtable(str* pres_uri, int event, unsigned int hash_code);
pres_entry_t* search_phtable_etag(str* pres_uri, int event,
str* etag, unsigned int hash_code);
void update_pres_etag(pres_entry_t* p, str* etag);
pres_entry_t* insert_phtable(str* pres_uri, int event, str* etag, char* sphere, int init_turn);
int update_phtable(struct presentity* presentity, str pres_uri, str body);
void next_turn_phtable(pres_entry_t* p_p, unsigned int hash_code);
int delete_phtable(pres_entry_t* p, unsigned int hash_code);
int delete_phtable_query(str *pres_uri, int event, str* etag);
void destroy_phtable(void);
#endif