-
Notifications
You must be signed in to change notification settings - Fork 909
/
dlist.c
173 lines (150 loc) · 4.31 KB
/
dlist.c
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
162
163
164
165
166
167
168
169
170
171
172
173
/*
* Copyright (C) 2001-2003 FhG Fokus
*
* This file is part of Kamailio, a free SIP server.
*
* Kamailio 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
*
* Kamailio 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*! \file
* \brief USRLOC - List of registered domains
* \ingroup usrloc
*
* - Module: \ref usrloc
*/
#include "dlist.h"
#include <stdlib.h> /* abort */
#include <string.h> /* strlen, memcmp */
#include <stdio.h> /* printf */
#include "../../core/ut.h"
#include "../../lib/srdb1/db.h"
#include "../../core/mem/shm_mem.h"
#include "../../core/dprint.h"
#include "../../core/ip_addr.h"
#include "../../core/socket_info.h"
#include "udomain.h" /* new_udomain, free_udomain */
#include "utime.h"
#include "p_usrloc_mod.h"
#include "ul_db_layer.h"
static struct domain_list_item *domain_list;
static inline struct domain_list_item *find_dlist(str *name)
{
struct domain_list_item *item;
for(item = domain_list; item != NULL; item = item->next) {
if(item->name.len == name->len
&& memcmp(item->name.s, name->s, name->len) == 0) {
return item;
}
}
return NULL;
}
static inline struct domain_list_item *add_to_dlist(str *name, int type)
{
struct domain_list_item *item;
int i;
item = (struct domain_list_item *)pkg_malloc(
sizeof(struct domain_list_item));
if(item == NULL) {
LM_ERR("Out of pkg memory.\n");
return NULL;
}
item->name.s = (char *)pkg_malloc(name->len + 1);
if(item->name.s == NULL) {
LM_ERR("Out of pkg memory (1).\n");
pkg_free(item);
return NULL;
}
memcpy(item->name.s, name->s, name->len);
item->name.s[name->len] = '\0';
item->name.len = name->len;
memset(&item->domain, 0, sizeof(struct udomain));
item->domain.name = &item->name;
item->domain.dbt = type;
item->domain.table = (hslot_t *)pkg_malloc(sizeof(hslot_t) * ul_hash_size);
if(!item->domain.table) {
LM_ERR("Out of pkg memory (2)\n");
pkg_free(item->name.s);
pkg_free(item);
return NULL;
}
for(i = 0; i < ul_hash_size; i++) {
init_slot(&item->domain, &(item->domain.table[i]), i);
}
item->domain.size = ul_hash_size;
/* Everything else is not useful for now. */
item->next = domain_list;
domain_list = item;
return item;
}
/*!
* \brief Registers a new domain with usrloc
*
* Registers a new domain with usrloc. If the domain exists,
* a pointer to existing structure will be returned, otherwise
* a new domain will be created
* \param _n domain name
* \param _d new created domain
* \return 0 on success, -1 on failure
*/
int register_udomain(const char *name, udomain_t **domain)
{
struct domain_list_item *item;
str name_str;
ul_domain_db_t *d;
name_str.s = (char *)name;
name_str.len = strlen(name);
item = find_dlist(&name_str);
if(item == NULL) {
if((d = ul_find_domain(name)) == NULL) {
LM_ERR("domain %s not found.\n", name);
return -1;
}
item = add_to_dlist(&name_str, d->dbt);
}
if(item == NULL) {
return -1;
}
*domain = &item->domain;
LM_DBG("found domain %.*s, type: %s\n", (*domain)->name->len,
(*domain)->name->s,
(((*domain)->dbt) == DB_TYPE_CLUSTER ? "cluster" : "single"));
return 0;
}
/*!
* \brief Loops through all domains summing up the number of users
* \return the number of users, could be zero
*/
unsigned long get_number_of_users(void)
{
int numberOfUsers = 0;
LM_INFO("not available with partitioned interface\n");
return numberOfUsers;
}
int get_all_ucontacts(void *buf, int len, unsigned int flags,
unsigned int part_idx, unsigned int part_max, int options)
{
LM_INFO("not available with partitioned interface\n");
return -1;
}
/*!
* \brief Run timer handler of all domains
* \return 0 if all timer return 0, != 0 otherwise
*/
int synchronize_all_udomains(void)
{
int res = 0;
LM_INFO("not available with partitioned interface\n");
return res;
}