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,217 @@
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
+#include "avp_new_base_data_format.h"
42
+
43
+#include "avp_new.h"
44
+
45
+extern struct cdp_binds *cdp;
46
+
47
+
48
+/* 
49
+ * RFC 3588 Basic AVP Data Types
50
+ * 
51
+ * http://tools.ietf.org/html/rfc3588#section-4.2
52
+ * 
53
+ */
54
+
55
+inline AAA_AVP *cdp_avp_new_OctetString(int avp_code,int avp_flags,int avp_vendorid,str data,AVPDataStatus data_do)
56
+{
57
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,data,data_do);
58
+}
59
+
60
+inline AAA_AVP *cdp_avp_new_Integer32(int avp_code,int avp_flags,int avp_vendorid,int32_t data)
61
+{
62
+	char x[4];
63
+	str s={x,4};
64
+	set_4bytes(x,data);
65
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,s,AVP_DUPLICATE_DATA);
66
+}
67
+
68
+
69
+inline AAA_AVP *cdp_avp_new_Integer64(int avp_code,int avp_flags,int avp_vendorid,int64_t data)
70
+{
71
+	char x[8];
72
+	str s={x,8};
73
+	int i;
74
+	for(i=7;i>=0;i--){
75
+		x[i] = data%256;
76
+		data /= 256;
77
+	}					//TODO - check if this is correct
78
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,s,AVP_DUPLICATE_DATA);	
79
+}
80
+
81
+inline AAA_AVP *cdp_avp_new_Unsigned32(int avp_code,int avp_flags,int avp_vendorid,uint32_t data)
82
+{
83
+	char x[4];
84
+	str s={x,4};
85
+	uint32_t ndata=htonl(data);
86
+	memcpy(x,&ndata,sizeof(uint32_t));
87
+	//*((uint32_t*)x) = htonl(data);
88
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,s,AVP_DUPLICATE_DATA);
89
+}
90
+
91
+inline AAA_AVP *cdp_avp_new_Unsigned64(int avp_code,int avp_flags,int avp_vendorid,uint64_t data)
92
+{
93
+	char x[8];
94
+	str s={x,8};
95
+	int i;
96
+	for(i=7;i>=0;i--){
97
+		x[i] = data%256;
98
+		data /= 256;
99
+	}
100
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,s,AVP_DUPLICATE_DATA);
101
+}
102
+
103
+inline AAA_AVP *cdp_avp_new_Float32(int avp_code,int avp_flags,int avp_vendorid,float data)
104
+{
105
+	uint32_t udata;
106
+	memcpy(&udata,&data,sizeof(uint32_t));
107
+	return cdp_avp_new_Unsigned32(avp_code,avp_flags,avp_vendorid,udata);//TODO - check if this is correct
108
+}
109
+
110
+inline AAA_AVP *cdp_avp_new_Float64(int avp_code,int avp_flags,int avp_vendorid,double data)
111
+{
112
+	uint64_t udata;
113
+	memcpy(&udata,&data,sizeof(uint32_t));	
114
+	return cdp_avp_new_Unsigned64(avp_code,avp_flags,avp_vendorid,udata);//TODO - check if this is correct
115
+}
116
+
117
+/**
118
+ * Creates a grouped AVP from a list
119
+ * @param avp_code
120
+ * @param avp_flags
121
+ * @param avp_vendorid
122
+ * @param list
123
+ * @param list_do - if this is AVP_FREE_DATA then the list will aso be freed
124
+ * @return
125
+ */
126
+inline AAA_AVP *cdp_avp_new_Grouped(int avp_code,int avp_flags,int avp_vendorid,AAA_AVP_LIST *list,AVPDataStatus list_do)
127
+{
128
+	str grp;
129
+	if (!list){
130
+		LOG(L_ERR,"The AAA_AVP_LIST was NULL!\n");
131
+		return 0;
132
+	}
133
+	grp = cdp->AAAGroupAVPS(*list);
134
+	if (!grp.len){
135
+		LOG(L_ERR,"The AAA_AVP_LIST provided was empty! (AVP Code %d VendorId %d)\n",avp_code,avp_vendorid);
136
+		return 0;
137
+	}
138
+	if (list_do==AVP_FREE_DATA)
139
+		cdp->AAAFreeAVPList(list);
140
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,grp,AVP_FREE_DATA);
141
+}
142
+
143
+/*
144
+ * RFC 3588 Derived AVP Data Formats
145
+ * 
146
+ * http://tools.ietf.org/html/rfc3588#section-4.3
147
+ * 
148
+ */
149
+
150
+inline AAA_AVP* cdp_avp_new_Address(int avp_code,int avp_flags,int avp_vendorid,ip_address data)
151
+{
152
+	char x[18];
153
+	str s;
154
+	s.s = x;
155
+	s.len = 0;
156
+
157
+	switch (data.ai_family){
158
+		case AF_INET:
159
+			x[0]=0;
160
+			x[1]=1;
161
+			memcpy(x+2, (char*)(&data.ip.v4.s_addr), 4);
162
+			s.len=6;
163
+			break;
164
+		case AF_INET6:
165
+			x[0]=0;
166
+			x[1]=2;
167
+			s.len=18;
168
+			memcpy(x+2,data.ip.v6.s6_addr,16);
169
+			break;
170
+		default:
171
+			LOG(L_ERR,"Unimplemented for ai_family %d! (AVP Code %d Vendor-Id %d)\n",data.ai_family,avp_code,avp_vendorid);
172
+			return 0;
173
+	}
174
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,s,AVP_DUPLICATE_DATA);
175
+}
176
+
177
+inline AAA_AVP* cdp_avp_new_Time(int avp_code,int avp_flags,int avp_vendorid,time_t data)
178
+{
179
+	char x[4];
180
+	str s={x,4};
181
+	uint32_t ntime = htonl(data+EPOCH_UNIX_TO_EPOCH_NTP);
182
+	memcpy(x,&ntime,sizeof(uint32_t));	
183
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,s,AVP_DUPLICATE_DATA);
184
+}
185
+
186
+inline AAA_AVP *cdp_avp_new_UTF8String(int avp_code,int avp_flags,int avp_vendorid,str data,AVPDataStatus data_do)
187
+{
188
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,data,data_do);
189
+}
190
+
191
+inline AAA_AVP* cdp_avp_new_DiameterIdentity(int avp_code,int avp_flags,int avp_vendorid,str data,AVPDataStatus data_do)
192
+{
193
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,data,data_do);
194
+}
195
+
196
+inline AAA_AVP* cdp_avp_new_DiameterURI(int avp_code,int avp_flags,int avp_vendorid,str data,AVPDataStatus data_do)
197
+{
198
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,data,data_do);
199
+}
200
+
201
+inline AAA_AVP* cdp_avp_new_Enumerated(int avp_code,int avp_flags,int avp_vendorid,int32_t data)
202
+{
203
+	char x[4];
204
+	str s={x,4};
205
+	set_4bytes(x,data);
206
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,s,AVP_DUPLICATE_DATA);
207
+}
208
+
209
+inline AAA_AVP* cdp_avp_new_IPFilterRule(int avp_code,int avp_flags,int avp_vendorid,str data,AVPDataStatus data_do)
210
+{
211
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,data,data_do);
212
+}
213
+
214
+inline AAA_AVP* cdp_avp_new_QoSFilterRule(int avp_code,int avp_flags,int avp_vendorid,str data,AVPDataStatus data_do)
215
+{
216
+	return cdp_avp_new(avp_code,avp_flags,avp_vendorid,data,data_do);
217
+}