/
usrloc.c
151 lines (132 loc) · 4.79 KB
/
usrloc.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
/*
* $Id$
*
* Copyright (C) 2012 Smile Communications, jason.penton@smilecoms.com
* Copyright (C) 2012 Smile Communications, richard.good@smilecoms.com
*
* The initial version of this code was written by Dragos Vingarzan
* (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the
* Fruanhofer Institute. It was and still is maintained in a separate
* branch of the original SER. We are therefore migrating it to
* Kamailio/SR and look forward to maintaining it from here on out.
* 2011/2012 Smile Communications, Pty. Ltd.
* ported/maintained/improved by
* Jason Penton (jason(dot)penton(at)smilecoms.com and
* Richard Good (richard(dot)good(at)smilecoms.com) as part of an
* effort to add full IMS support to Kamailio/SR using a new and
* improved architecture
*
* NB: Alot of this code was originally part of OpenIMSCore,
* FhG Fokus.
* Copyright (C) 2004-2006 FhG Fokus
* Thanks for great work! This is an effort to
* break apart the various CSCF functions into logically separate
* components. We hope this will drive wider use. We also feel
* that in this way the architecture is more complete and thereby easier
* to manage in the Kamailio/SR environment
*
* 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
*
*/
#include "usrloc.h"
#include "dlist.h"
#include "pcontact.h"
#include "udomain.h"
#include "../../core/sr_module.h"
#include "ims_usrloc_pcscf_mod.h"
#include "../../core/parser/parse_uri.h"
extern unsigned int init_flag;
extern int hashing_type;
int bind_usrloc(usrloc_api_t* api) {
if (!api) {
LM_ERR("invalid parameter value\n");
return -1;
}
if (init_flag == 0) {
LM_ERR("configuration error - trying to bind to usrloc module"
" before being initialized\n");
return -1;
}
api->register_udomain = register_udomain;
api->get_udomain = get_udomain;
api->lock_udomain = lock_udomain;
api->unlock_udomain = unlock_udomain;
api->insert_pcontact = insert_pcontact;
api->delete_pcontact = delete_pcontact;
api->get_pcontact = get_pcontact;
api->assert_identity = assert_identity;
api->update_pcontact = update_pcontact;
api->update_rx_regsession = update_rx_regsession;
api->get_all_ucontacts = get_all_ucontacts;
api->update_security = update_security;
api->update_temp_security = update_temp_security;
api->register_ulcb = register_ulcb;
return 0;
}
#define ALIAS "alias="
#define ALIAS_LEN (sizeof(ALIAS) - 1)
int get_alias_host_from_contact(str *contact_uri_params, str *alias_host) {
char *rest, *sep;
unsigned int rest_len;
rest = contact_uri_params->s;
rest_len = contact_uri_params->len;
if (rest_len == 0) {
LM_DBG("no params\n");
return -1;
}
/*Get full alias parameter*/
while (rest_len >= ALIAS_LEN) {
if (strncmp(rest, ALIAS, ALIAS_LEN) == 0) break;
sep = memchr(rest, 59 /* ; */, rest_len);
if (sep == NULL) {
LM_DBG("no alias param\n");
return -1;
} else {
rest_len = rest_len - (sep - rest + 1);
rest = sep + 1;
}
}
if (rest_len < ALIAS_LEN) {
LM_DBG("no alias param\n");
return -1;
}
alias_host->s = rest + ALIAS_LEN;
alias_host->len = rest_len - ALIAS_LEN;
/*Get host from alias*/
rest = memchr(alias_host->s, 126 /* ~ */, alias_host->len);
if (rest == NULL) {
LM_ERR("no '~' in alias param value\n");
return -1;
}
alias_host->len = rest - alias_host->s;
LM_DBG("Alias host to return [%.*s]\n", alias_host->len, alias_host->s);
return 0;
}
/* return the slot id for inserting contacts in the hash */
unsigned int get_hash_slot(udomain_t* _d, str* via_host, unsigned short via_port, unsigned short via_proto) {
unsigned int sl;
sl = get_aor_hash(_d, via_host, via_port, via_proto);
sl = sl & (_d->size - 1) ;
LM_DBG("Returning hash slot: [%d]\n", sl);
return sl;
}
unsigned int get_aor_hash(udomain_t* _d, str* via_host, unsigned short via_port, unsigned short via_proto) {
unsigned int aorhash;
aorhash = core_hash(via_host, 0, 0);
LM_DBG("Returning hash: [%u]\n", aorhash);
return aorhash;
}