Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,378 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * The initial version of this code was written by Dragos Vingarzan
5
+ * (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the
6
+ * Fruanhofer Institute. It was and still is maintained in a separate
7
+ * branch of the original SER. We are therefore migrating it to
8
+ * Kamailio/SR and look forward to maintaining it from here on out.
9
+ * 2011/2012 Smile Communications, Pty. Ltd.
10
+ * ported/maintained/improved by 
11
+ * Jason Penton (jason(dot)penton(at)smilecoms.com and
12
+ * Richard Good (richard(dot)good(at)smilecoms.com) as part of an 
13
+ * effort to add full IMS support to Kamailio/SR using a new and
14
+ * improved architecture
15
+ * 
16
+ * NB: Alot of this code was originally part of OpenIMSCore,
17
+ * FhG Focus. Thanks for great work! This is an effort to 
18
+ * break apart the various CSCF functions into logically separate
19
+ * components. We hope this will drive wider use. We also feel
20
+ * that in this way the architecture is more complete and thereby easier
21
+ * to manage in the Kamailio/SR environment
22
+ *
23
+ * This file is part of Kamailio, a free SIP server.
24
+ *
25
+ * Kamailio is free software; you can redistribute it and/or modify
26
+ * it under the terms of the GNU General Public License as published by
27
+ * the Free Software Foundation; either version 2 of the License, or
28
+ * (at your option) any later version
29
+ *
30
+ * Kamailio is distributed in the hope that it will be useful,
31
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
+ * GNU General Public License for more details.
34
+ *
35
+ * You should have received a copy of the GNU General Public License 
36
+ * along with this program; if not, write to the Free Software 
37
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
38
+ * 
39
+ */
40
+
41
+/* 
42
+ * RFC 4005 Base AVPs
43
+ * 
44
+ * http://tools.ietf.org/html/rfc4005
45
+ * 
46
+ */
47
+
48
+#include "macros.h"
49
+
50
+#undef CDP_AVP_MODULE
51
+#define CDP_AVP_MODULE nasapp
52
+
53
+#if !defined(CDP_AVP_DECLARATION) && !defined(CDP_AVP_EXPORT) && !defined(CDP_AVP_INIT) && !defined(CDP_AVP_REFERENCE)
54
+	#ifndef _CDP_AVP_NASAPP_H_1
55
+	#define _CDP_AVP_NASAPP_H_1
56
+
57
+		#include "../cdp/cdp_load.h"
58
+
59
+	#else
60
+
61
+		/* undo the macros definition if this was re-included */
62
+		#define CDP_AVP_EMPTY_MACROS
63
+			#include "macros.h"
64
+		#undef CDP_AVP_EMPTY_MACROS
65
+
66
+	#endif
67
+#endif //_CDP_AVP_NASAPP_H_1	
68
+
69
+/*
70
+ * The list of AVPs must be declared in the following format:
71
+ * 
72
+ * 		cdp_avp_add(<avp_name>.<vendor_id>,<flags>,<avp_type>,<data_type>)
73
+ * 		or
74
+ * 		cdp_avp_add_ptr(<avp_name>.<vendor_id>,<flags>,<avp_type>,<data_type>)
75
+ * 
76
+ * 		cdp_avp_get(<avp_name>.<vendor_id>,<avp_type>,<data_type>)
77
+ * 
78
+ * or, to add both add and get at once:
79
+ * 
80
+ * 		cdp_avp(<avp_name>.<vendor_id>,<flags>,<avp_type>,<data_type>)
81
+ * 		or 
82
+ * 		cdp_avp_ptr(<avp_name>.<vendor_id>,<flags>,<avp_type>,<data_type>)
83
+ * 
84
+ * The add macros ending in _ptr will generate function with the extra AVPDataStatus data_do parameter
85
+ * 
86
+ * Parameters:
87
+ *  - avp_name - a value of AVP_<avp_name> must resolve to the AVP code
88
+ *  - vendor_id - an int value
89
+ *  - flags	- AVP Flags to add to the AVP
90
+ *  - avp_type - an avp type for which a function was defined a
91
+ * 				int cdp_avp_get_<avp_type>(AAA_AVP *avp,<data_type> *data)
92
+ * 		Some valid suggestions (and the data_type):		
93
+ *  
94
+ *  			OctetString 	- str
95
+ *  			Integer32		- int32_t
96
+ *  			Integer64 		- int64_t
97
+ *  			Unsigned32 		- uint32_t
98
+ *  			Unsigned64 		- uint64_t
99
+ *  			Float32 		- float
100
+ *  			Float64 		- double
101
+ *  			Grouped 		- AAA_AVP_LIST
102
+ *  
103
+ *  			Address 		- ip_address
104
+ *  			Time 			- time_t
105
+ *  			UTF8String 		- str
106
+ *  			DiameterIdentity- str
107
+ *  			DiameterURI		- str
108
+ *  			Enumerated		- int32_t
109
+ *  			IPFilterRule	- str
110
+ *  			QoSFilterRule	- str
111
+ *  - data_type - the respective data type for the avp_type defined above
112
+ *  
113
+ *  The functions generated will return 1 on success or 0 on error or not found
114
+ *  The prototype of the function will be:
115
+ *  
116
+ *  	int cdp_avp_get_<avp_name_group>(AAA_AVP_LIST list,<data_type> *data,AAA_AVP **avp_ptr)
117
+ * 
118
+ * 
119
+ *  
120
+ *  For Grouped AVPs with 2 or 3 known inside AVPs, you can define a shortcut function which will find the group and
121
+ *  also extract the 2 or 3 AVPs. 
122
+ *  Do not define both 2 and 3 for the same type!
123
+ * 
124
+ * 
125
+ *		cdp_avp_add2(<avp_name_group>.<vendor_id_group>,<flags_group>,<avp_name_1>,<data_type_1>,<avp_name_2>,<data_type_2>)
126
+ * 		cdp_avp_get2(<avp_name_group>.<vendor_id_group>,<avp_name_1>,<data_type_1>,<avp_name_2>,<data_type_2>)
127
+ *  	
128
+ *		cdp_avp_get3(<avp_name_group>.<vendor_id_group>,<flags_group>,<avp_name_1>,<data_type_1>,<avp_name_2>,<data_type_2>,<avp_name_3>,<data_type_3>)
129
+ *  	cdp_avp_get3(<avp_name_group>.<vendor_id_group>,<avp_name_1>,<data_type_1>,<avp_name_2>,<data_type_2>,<avp_name_3>,<data_type_3>)
130
+ * 
131
+ * 	 or, to add both add and get at once:
132
+ * 
133
+ *		cdp_avp2(<avp_name_group>.<vendor_id_group>,<flags_group>,<avp_name_1>,<data_type_1>,<avp_name_2>,<data_type_2>)
134
+ * 		cdp_avp3(<avp_name_group>.<vendor_id_group>,<flags_group>,<avp_name_1>,<data_type_1>,<avp_name_2>,<data_type_2>)
135
+ *  
136
+ *  avp_name_group - a value of AVP_<avp_name_group> must resolve to the AVP code of the group
137
+ *  
138
+ *  vendor_id_group - an int value
139
+ *  
140
+ *  avp_name_N	- the name of the Nth parameter. 
141
+ *  	Previously, a cdp_avp_get(<avp_name_N>,<vendor_id_N>,<avp_type_N>,<data_type_N>) must be defined!
142
+ *  
143
+ *  data_type_N	- the respective data type for avp_type_N (same as <data_type_N) 
144
+ *  
145
+ *  The functions generated will return the number of found AVPs inside on success or 0 on error or not found
146
+ *  The prototype of the function will be:
147
+ *  
148
+ *  	int cdp_avp_get_<avp_name_group>_Group(AAA_AVP_LIST list,<data_type_1> *avp_name_1,<data_type_2> *avp_name_2[,<data_type_3> *avp_name_3],AAA_AVP **avp_ptr)
149
+ *  
150
+ *  Note - generally, all data of type str will need to be defined with ..._ptr
151
+ *  Note - Groups must be defined with:
152
+ *  	 cdp_avp_add_ptr(...) and data_type AAA_AVP_LIST*
153
+ *  	 cdp_avp_get(...) and data_type AAA_AVP_LIST 	
154
+ */
155
+
156
+
157
+cdp_avp			(Accounting_Input_Octets,		0,	AAA_AVP_FLAG_MANDATORY,	Unsigned64,			uint64_t)
158
+
159
+cdp_avp			(Accounting_Input_Packets,		0,	AAA_AVP_FLAG_MANDATORY,	Unsigned64,			uint64_t)
160
+
161
+cdp_avp			(Accounting_Output_Octets,		0,	AAA_AVP_FLAG_MANDATORY,	Unsigned64,			uint64_t)
162
+
163
+cdp_avp			(Accounting_Output_Packets,		0,	AAA_AVP_FLAG_MANDATORY,	Unsigned64,			uint64_t)
164
+
165
+cdp_avp_ptr		(Filter_Id,						0,	AAA_AVP_FLAG_MANDATORY,	UTF8String,			str)
166
+
167
+
168
+
169
+cdp_avp_ptr		(Called_Station_Id,				0,	AAA_AVP_FLAG_MANDATORY,	UTF8String,			str)
170
+
171
+
172
+
173
+
174
+
175
+/*
176
+ * From here-on you can define/export/init/declare functions which can not be generate with the macros
177
+ */
178
+
179
+#if defined(CDP_AVP_DEFINITION)
180
+
181
+	/*
182
+	 * Put here your supplimentary definitions. Typically:
183
+	 * 
184
+	 * int <function1>(param1)
185
+	 * {
186
+	 *   code1
187
+	 * }
188
+	 * 
189
+	 * 
190
+	 */
191
+	int cdp_avp_add_Framed_IP_Address(AAA_AVP_LIST *list,ip_address ip)
192
+	{
193
+		if (ip.ai_family!=AF_INET) {
194
+			LOG(L_ERR,"Trying to build from non IPv4 address!\n");
195
+			return 0;
196
+		}
197
+		char x[4];
198
+		str s={x,4};
199
+		//*((uint32_t*)x) = htonl(ip.ip.v4.s_addr);
200
+		memcpy(x,&(ip.ip.v4.s_addr),sizeof(uint32_t));
201
+		return cdp_avp_add_to_list(list,
202
+				cdp_avp_new(
203
+						AVP_Framed_IP_Address,
204
+						AAA_AVP_FLAG_MANDATORY,
205
+						0,
206
+						s,
207
+						AVP_DUPLICATE_DATA));
208
+	}
209
+	
210
+	int cdp_avp_get_Framed_IP_Address(AAA_AVP_LIST list,ip_address *ip,AAA_AVP **avp_ptr)
211
+	{
212
+		if (!ip) return 0;
213
+		AAA_AVP *avp = cdp_avp_get_next_from_list(list,
214
+				AVP_Framed_IP_Address,
215
+				0,
216
+				avp_ptr?*avp_ptr:0);
217
+		if (avp_ptr) *avp_ptr = avp;
218
+		if (!avp) {
219
+			bzero(ip,sizeof(ip_address));			
220
+			return 0;											
221
+		}			
222
+		if (avp->data.len<4){
223
+			LOG(L_ERR,"Error decoding Framed IP Address from AVP data of length %d < 4",avp->data.len);
224
+			bzero(ip,sizeof(ip_address));
225
+			return 0;
226
+		}
227
+		ip->ai_family = AF_INET;
228
+		//ip->ip.v4.s_addr = ntohl(*((uint32_t*)avp->data.s));
229
+		ip->ip.v4.s_addr = (*((uint32_t*)avp->data.s));
230
+		return 1;
231
+	}
232
+	
233
+	/**
234
+	 * http://tools.ietf.org/html/rfc4005#section-6.11.6
235
+	 * http://tools.ietf.org/html/rfc3162#section-2.3
236
+	 * @param list
237
+	 * @param data
238
+	 * @return
239
+	 */
240
+	int cdp_avp_add_Framed_IPv6_Prefix(AAA_AVP_LIST *list,ip_address_prefix ip)
241
+	{
242
+		uint8_t buffer[18];
243
+		str data={(char*)buffer,18};
244
+		if (ip.addr.ai_family!=AF_INET6) {
245
+			LOG(L_ERR,"Trying to build from non IPv6 address!\n");
246
+			return 0;
247
+		}
248
+		buffer[0]=0;
249
+		buffer[1]=ip.prefix;
250
+		memcpy(buffer+2,ip.addr.ip.v6.s6_addr,16);
251
+		return cdp_avp_add_to_list(list,
252
+				cdp_avp_new_OctetString(
253
+						AVP_Framed_IPv6_Prefix,
254
+						AAA_AVP_FLAG_MANDATORY,
255
+						0,
256
+						data,
257
+						AVP_DUPLICATE_DATA));
258
+	}
259
+
260
+	int cdp_avp_get_Framed_IPv6_Prefix(AAA_AVP_LIST list,ip_address_prefix *ip,AAA_AVP **avp_ptr)
261
+	{
262
+		if (!ip) return 0;
263
+		AAA_AVP *avp = cdp_avp_get_next_from_list(list,
264
+				AVP_Framed_IPv6_Prefix,
265
+				0,
266
+				avp_ptr?*avp_ptr:0);
267
+		if (avp_ptr) *avp_ptr = avp;
268
+		if (!avp) {
269
+			bzero(ip,sizeof(ip_address_prefix));			
270
+			return 0;											
271
+		}	
272
+		if (avp->data.len<18) {
273
+			LOG(L_ERR,"Error decoding Framed-IPv6-Prefix from data len < 18 bytes!\n");
274
+			bzero(ip,sizeof(ip_address_prefix));
275
+			return 0;
276
+		}
277
+		ip->addr.ai_family = AF_INET6;
278
+		ip->prefix = avp->data.s[1];
279
+		memcpy(ip->addr.ip.v6.s6_addr,avp->data.s+2,16);	
280
+		return 1;
281
+	}	
282
+
283
+#elif defined(CDP_AVP_EXPORT)
284
+
285
+	/*
286
+	 * Put here your supplimentary exports in the format: 
287
+	 * 	<function_type1> <nice_function_name1>; 
288
+	 *  <function_type2> <nice_function_name1>;
289
+	 *  ...
290
+	 *  
291
+	 */
292
+	cdp_avp_add_Framed_IP_Address_f		add_Framed_IP_Address;
293
+	cdp_avp_get_Framed_IP_Address_f		get_Framed_IP_Address;
294
+	
295
+	cdp_avp_add_Framed_IPv6_Prefix_f	add_Framed_IPv6_Prefix;
296
+	cdp_avp_get_Framed_IPv6_Prefix_f	get_Framed_IPv6_Prefix;	
297
+	
298
+
299
+#elif defined(CDP_AVP_INIT)
300
+
301
+	/*
302
+	 * Put here your supplimentary inits in the format: 
303
+	 * 	<function1>,
304
+	 *  <function2>,
305
+	 *  ...
306
+	 * 
307
+	 * Make sure you keep the same order as in export!
308
+	 * 
309
+	 */
310
+	cdp_avp_add_Framed_IP_Address,
311
+	cdp_avp_get_Framed_IP_Address,
312
+
313
+	cdp_avp_add_Framed_IPv6_Prefix,
314
+	cdp_avp_get_Framed_IPv6_Prefix,	
315
+
316
+#elif defined(CDP_AVP_REFERENCE)
317
+	/*
318
+	 * Put here what you want to get in the reference. Typically:
319
+	 * <function1>
320
+	 * <function2>
321
+	 * ... 
322
+	 * 
323
+	 */
324
+int CDP_AVP_MODULE.add_Framed_IP_Address(AAA_AVP_LIST *list,ip_address ip);
325
+int CDP_AVP_MODULE.get_Framed_IP_Address(AAA_AVP_LIST list,ip_address *ip,AAA_AVP **avp_ptr);
326
+	
327
+int CDP_AVP_MODULE.add_Framed_IPv6_Prefix(AAA_AVP_LIST *list,ip_address_prefix ip);
328
+int CDP_AVP_MODULE.get_Framed_IPv6_Prefix(AAA_AVP_LIST list,ip_address_prefix *ip,AAA_AVP **avp_ptr);
329
+	
330
+#elif defined(CDP_AVP_EMPTY_MACROS)
331
+	
332
+	/* this should be left blank */
333
+	
334
+#else
335
+
336
+	/*
337
+	 * Put here your definitions according to the declarations, exports, init, etc above. Typically:
338
+	 * 
339
+	 * int <function1(params1);>
340
+	 * typedef int <*function_type1>(params1);
341
+	 * 
342
+	 * int <function2(param2);>
343
+	 * typedef int <*function_type2>(params2);
344
+	 * 
345
+	 * ...
346
+	 *  
347
+	 */
348
+
349
+	
350
+	#ifndef _CDP_AVP_NASAPP_H_2
351
+	#define _CDP_AVP_NASAPP_H_2
352
+
353
+		int cdp_avp_add_Framed_IP_Address(AAA_AVP_LIST *list,ip_address ip);
354
+		typedef int (*cdp_avp_add_Framed_IP_Address_f)(AAA_AVP_LIST *list,ip_address ip);
355
+
356
+		int cdp_avp_get_Framed_IP_Address(AAA_AVP_LIST list,ip_address *ip,AAA_AVP **avp_ptr);
357
+		typedef int (*cdp_avp_get_Framed_IP_Address_f)(AAA_AVP_LIST list,ip_address *ip,AAA_AVP **avp_ptr);
358
+	
359
+		int cdp_avp_add_Framed_IPv6_Prefix(AAA_AVP_LIST *list,ip_address_prefix ip);
360
+		typedef int (*cdp_avp_add_Framed_IPv6_Prefix_f)(AAA_AVP_LIST *list,ip_address_prefix ip);
361
+
362
+		int cdp_avp_get_Framed_IPv6_Prefix(AAA_AVP_LIST list,ip_address_prefix *ip,AAA_AVP **avp_ptr);
363
+		typedef int (*cdp_avp_get_Framed_IPv6_Prefix_f)(AAA_AVP_LIST list,ip_address_prefix *ip,AAA_AVP **avp_ptr);
364
+
365
+
366
+	#endif //_CDP_AVP_BASE_H_2
367
+	
368
+#endif
369
+
370
+
371
+
372
+#define CDP_AVP_UNDEF_MACROS
373
+	#include "macros.h"
374
+#undef CDP_AVP_UNDEF_MACROS
375
+	
376
+
377
+
378
+