1 /*
2 * Functions that process REGISTER message
3 * and store data in usrloc
4 *
5 * Copyright (C) 2010 Daniel-Constantin Mierla (asipto.com)
6 *
7 * This file is part of Kamailio, a free SIP server.
8 *
9 * Kamailio is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version
13 *
14 * Kamailio is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 */
24
25 #include <stdio.h>
26
27 #include "../../core/dprint.h"
28
29 #include "registrar.h"
30 #include "lookup.h"
31 #include "save.h"
32 #include "api.h"
33
34 /**
35 *
36 * table->s must be zero-terminated
37 */
regapi_save(sip_msg_t * msg,str * table,int flags)38 int regapi_save(sip_msg_t *msg, str *table, int flags)
39 {
40 udomain_t* d;
41
42 if(ul.get_udomain(table->s, &d)<0)
43 {
44 LM_ERR("usrloc domain [%s] not found\n", table->s);
45 return -1;
46 }
47 return save(msg, d, flags, NULL);
48 }
49
50 /**
51 *
52 * table->s must be zero-terminated
53 */
regapi_save_uri(sip_msg_t * msg,str * table,int flags,str * uri)54 int regapi_save_uri(sip_msg_t *msg, str *table, int flags, str *uri)
55 {
56 udomain_t* d;
57
58 if(ul.get_udomain(table->s, &d)<0)
59 {
60 LM_ERR("usrloc domain [%s] not found\n", table->s);
61 return -1;
62 }
63 return save(msg, d, flags, uri);
64 }
65
66 /**
67 *
68 * table->s must be zero-terminated
69 */
regapi_lookup(sip_msg_t * msg,str * table)70 int regapi_lookup(sip_msg_t *msg, str *table)
71 {
72 udomain_t* d;
73
74 if(ul.get_udomain(table->s, &d)<0)
75 {
76 LM_ERR("usrloc domain [%s] not found\n", table->s);
77 return -1;
78 }
79 return lookup(msg, d, NULL);
80 }
81
82 /**
83 *
84 * table->s must be zero-terminated
85 */
regapi_lookup_uri(sip_msg_t * msg,str * table,str * uri)86 int regapi_lookup_uri(sip_msg_t *msg, str *table, str *uri)
87 {
88 udomain_t* d;
89
90 if(ul.get_udomain(table->s, &d)<0)
91 {
92 LM_ERR("usrloc domain [%s] not found\n", table->s);
93 return -1;
94 }
95 return lookup(msg, d, uri);
96 }
97
98 /**
99 *
100 * table->s must be zero-terminated
101 */
regapi_registered(sip_msg_t * msg,str * table)102 int regapi_registered(sip_msg_t *msg, str *table)
103 {
104 udomain_t* d;
105
106 if(ul.get_udomain(table->s, &d)<0)
107 {
108 LM_ERR("usrloc domain [%s] not found\n", table->s);
109 return -1;
110 }
111 return registered(msg, d, NULL);
112 }
113
114 /**
115 *
116 */
regapi_set_q_override(sip_msg_t * msg,str * new_q)117 int regapi_set_q_override(sip_msg_t *msg, str *new_q)
118 {
119 int _q;
120 if (str2q(&_q, new_q->s, new_q->len) < 0)
121 {
122 LM_ERR("invalid q parameter\n");
123 return -1;
124 }
125 return set_q_override(msg, _q);
126 }
127
128 /**
129 *
130 * table->s must be zero-terminated
131 */
regapi_lookup_to_dset(sip_msg_t * msg,str * table,str * uri)132 int regapi_lookup_to_dset(sip_msg_t *msg, str *table, str *uri)
133 {
134 udomain_t* d;
135
136 if(ul.get_udomain(table->s, &d)<0)
137 {
138 LM_ERR("usrloc domain [%s] not found\n", table->s);
139 return -1;
140 }
141 return lookup_to_dset(msg, d, uri);
142 }
143
144 /**
145 *
146 */
bind_registrar(registrar_api_t * api)147 int bind_registrar(registrar_api_t *api)
148 {
149 if (!api) {
150 ERR("Invalid parameter value\n");
151 return -1;
152 }
153 api->save = regapi_save;
154 api->save_uri = regapi_save_uri;
155 api->lookup = regapi_lookup;
156 api->lookup_uri = regapi_lookup_uri;
157 api->lookup_to_dset = regapi_lookup_to_dset;
158 api->registered = regapi_registered;
159 api->set_q_override = regapi_set_q_override;
160
161 return 0;
162 }
163