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
deleted file mode 100644
... ...
@@ -1,323 +0,0 @@
1
-/*
2
- * proxy list & assoc. functions
3
- *
4
- *
5
- * Copyright (C) 2001-2003 FhG Fokus
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
- * \file
26
- * \brief Kamailio core :: proxy list & assoc. functions
27
- * \ingroup core
28
- * Module: \ref core
29
- */
30
-
31
-
32
-
33
-#include "config.h"
34
-#include "proxy.h"
35
-#include "error.h"
36
-#include "dprint.h"
37
-#include "mem/mem.h"
38
-#include "mem/shm_mem.h"
39
-
40
-#include <string.h>
41
-#include <stdlib.h>
42
-#include <sys/socket.h>
43
-
44
-#ifdef DNS_IP_HACK
45
-#include "ut.h"
46
-#endif
47
-
48
-#include "resolve.h"
49
-#include "ip_addr.h"
50
-#include "globals.h"
51
-
52
-
53
-struct proxy_l* proxies=0;
54
-
55
-
56
-
57
-/* searches for the proxy named 'name', on port 'port' with 
58
-   proto 'proto'; if proto==0 => proto wildcard (will match any proto)
59
-   returns: pointer to proxy_l on success or 0 if not found */ 
60
-static struct proxy_l* find_proxy(str *name, unsigned short port, int proto)
61
-{
62
-	struct proxy_l* t;
63
-	for(t=proxies; t; t=t->next)
64
-		if (((t->name.len == name->len) &&
65
-			 ((proto==PROTO_NONE)||(t->proto==proto))&&
66
-			(strncasecmp(t->name.s, name->s, name->len)==0)) &&
67
-				(t->port==port))
68
-			break;
69
-	return t;
70
-}
71
-
72
-
73
-#define HOSTENT_CPY(dst, src, he_malloc, he_free)						\
74
-	do {																\
75
-		unsigned len,len2;												\
76
-		int r,i;														\
77
-																		\
78
-		/* start copying the host entry.. */							\
79
-		/* copy h_name */												\
80
-		len=strlen(src->h_name)+1;										\
81
-		dst->h_name=(char*)he_malloc(sizeof(char) * len);				\
82
-		if (dst->h_name) strncpy(dst->h_name,src->h_name, len);			\
83
-		else{															\
84
-			ser_error=ret=E_OUT_OF_MEM;									\
85
-			goto error;													\
86
-		}																\
87
-																		\
88
-		/* copy h_aliases */											\
89
-		len=0;															\
90
-		if (src->h_aliases)												\
91
-			for (;src->h_aliases[len];len++);							\
92
-		dst->h_aliases=(char**)he_malloc(sizeof(char*)*(len+1));		\
93
-		if (dst->h_aliases==0){											\
94
-			ser_error=ret=E_OUT_OF_MEM;									\
95
-			he_free(dst->h_name);										\
96
-			goto error;													\
97
-		}																\
98
-		memset((void*)dst->h_aliases, 0, sizeof(char*) * (len+1) );		\
99
-		for (i=0;i<len;i++){											\
100
-			len2=strlen(src->h_aliases[i])+1;							\
101
-			dst->h_aliases[i]=(char*)he_malloc(sizeof(char)*len2);		\
102
-			if (dst->h_aliases==0){										\
103
-				ser_error=ret=E_OUT_OF_MEM;								\
104
-				he_free(dst->h_name);									\
105
-				for(r=0; r<i; r++)	he_free(dst->h_aliases[r]);			\
106
-				he_free(dst->h_aliases);								\
107
-				goto error;												\
108
-			}															\
109
-			strncpy(dst->h_aliases[i], src->h_aliases[i], len2);		\
110
-		}																\
111
-		/* copy h_addr_list */											\
112
-		len=0;															\
113
-		if (src->h_addr_list)											\
114
-			for (;src->h_addr_list[len];len++);							\
115
-		dst->h_addr_list=(char**)he_malloc(sizeof(char*)*(len+1));		\
116
-		if (dst->h_addr_list==0){										\
117
-			ser_error=ret=E_OUT_OF_MEM;									\
118
-			he_free(dst->h_name);										\
119
-			for(r=0; dst->h_aliases[r]; r++)							\
120
-				he_free(dst->h_aliases[r]);								\
121
-			he_free(dst->h_aliases[r]);									\
122
-			he_free(dst->h_aliases);									\
123
-			goto error;													\
124
-		}																\
125
-		memset((void*)dst->h_addr_list, 0, sizeof(char*) * (len+1) );	\
126
-		for (i=0;i<len;i++){											\
127
-			dst->h_addr_list[i]=										\
128
-				(char*)he_malloc(sizeof(char)*src->h_length);			\
129
-			if (dst->h_addr_list[i]==0){								\
130
-				ser_error=ret=E_OUT_OF_MEM;								\
131
-				he_free(dst->h_name);									\
132
-				for(r=0; dst->h_aliases[r]; r++)						\
133
-					he_free(dst->h_aliases[r]);							\
134
-				he_free(dst->h_aliases[r]);								\
135
-				he_free(dst->h_aliases);								\
136
-				for (r=0; r<i;r++) he_free(dst->h_addr_list[r]);		\
137
-				he_free(dst->h_addr_list);								\
138
-				goto error;												\
139
-			}															\
140
-			memcpy(dst->h_addr_list[i], src->h_addr_list[i],			\
141
-				   src->h_length);										\
142
-		}																\
143
-																		\
144
-		/* copy h_addr_type & length */									\
145
-		dst->h_addrtype=src->h_addrtype;								\
146
-		dst->h_length=src->h_length;									\
147
-		/*finished hostent copy */										\
148
-																		\
149
-		return 0;														\
150
-	} while(0)
151
-
152
-
153
-#define FREE_HOSTENT(dst, he_free)						\
154
-	do {												\
155
-		int r;											\
156
-		if (dst->h_name) he_free(dst->h_name);			\
157
-		if (dst->h_aliases){							\
158
-			for(r=0; dst->h_aliases[r]; r++) {			\
159
-				he_free(dst->h_aliases[r]);				\
160
-			}											\
161
-			he_free(dst->h_aliases);					\
162
-		}												\
163
-		if (dst->h_addr_list){							\
164
-			for (r=0; dst->h_addr_list[r];r++) {		\
165
-				he_free(dst->h_addr_list[r]);			\
166
-			}											\
167
-			he_free(dst->h_addr_list);					\
168
-		}												\
169
-	} while(0)
170
-
171
-
172
-
173
-/* copies a hostent structure*, returns 0 on success, <0 on error*/
174
-static int hostent_cpy(struct hostent *dst, struct hostent* src)
175
-{
176
-	int ret;
177
-	HOSTENT_CPY(dst, src, pkg_malloc, pkg_free);
178
-error:
179
-	LM_CRIT("memory allocation failure\n");
180
-	return ret;
181
-}
182
-
183
-
184
-static int hostent_shm_cpy(struct hostent *dst, struct hostent* src)
185
-{
186
-	int ret;
187
-	HOSTENT_CPY(dst, src, shm_malloc, shm_free);
188
-error:
189
-	LM_CRIT("memory allocation failure\n");
190
-	return ret;
191
-}
192
-
193
-
194
-void free_hostent(struct hostent* dst)
195
-{
196
-	FREE_HOSTENT(dst, pkg_free);
197
-}
198
-
199
-void free_shm_hostent(struct hostent* dst)
200
-{
201
-	FREE_HOSTENT(dst, shm_free);
202
-}
203
-
204
-
205
-
206
-struct proxy_l* add_proxy(str* name, unsigned short port, int proto)
207
-{
208
-	struct proxy_l* p;
209
-	
210
-	if ((p=find_proxy(name, port, proto))!=0) return p;
211
-	if ((p=mk_proxy(name, port, proto))==0) goto error;
212
-	/* add p to the proxy list */
213
-	p->next=proxies;
214
-	proxies=p;
215
-	return p;
216
-
217
-error:
218
-	return 0;
219
-}
220
-
221
-
222
-#define MK_PROXY(name, port, protocol, p_malloc, p_free, he_cpy)		\
223
-	do {																\
224
-		struct proxy_l* p;												\
225
-		struct hostent* he;												\
226
-		char proto;														\
227
-																		\
228
-		p=(struct proxy_l*) p_malloc(sizeof(struct proxy_l));			\
229
-		if (p==0){														\
230
-			ser_error=E_OUT_OF_MEM;										\
231
-			LM_ERR("memory allocation failure\n");						\
232
-			goto error;													\
233
-		}																\
234
-		memset(p,0,sizeof(struct proxy_l));								\
235
-		p->name=*name;													\
236
-		p->port=port;													\
237
-																		\
238
-		LM_DBG("doing DNS lookup...\n");								\
239
-		proto=protocol;													\
240
-		he=sip_resolvehost(name, &(p->port), &proto);					\
241
-		if (he==0){														\
242
-			ser_error=E_BAD_ADDRESS;									\
243
-			LM_CRIT("could not resolve hostname:"						\
244
-				" \"%.*s\"\n", name->len, name->s);						\
245
-			p_free(p);													\
246
-			goto error;													\
247
-		}																\
248
-		if (he_cpy(&(p->host), he)!=0){									\
249
-			p_free(p);													\
250
-			goto error;													\
251
-		}																\
252
-		p->proto=proto;													\
253
-		p->ok=1;														\
254
-		return p;														\
255
-	error:																\
256
-		return 0;														\
257
-																		\
258
-	} while(0)
259
-
260
-/* same as add_proxy, but it doesn't add the proxy to the list
261
- * uses also SRV if possible & port==0 (quick hack) */
262
-
263
-struct proxy_l* mk_proxy(str* name, unsigned short port, int protocol)
264
-{
265
-	MK_PROXY(name, port, protocol, pkg_malloc, pkg_free, hostent_cpy);
266
-}
267
-
268
-
269
-struct proxy_l* mk_shm_proxy(str* name, unsigned short port, int protocol)
270
-{
271
-	MK_PROXY(name, port, protocol, shm_malloc, shm_free, hostent_shm_cpy);
272
-}
273
-
274
-
275
-
276
-/* same as mk_proxy, but get the host as an ip*/
277
-struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
278
-									int proto)
279
-{
280
-	struct proxy_l* p;
281
-
282
-	p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
283
-	if (p==0){
284
-		LM_CRIT("memory allocation failure\n");
285
-		goto error;
286
-	}
287
-	memset(p,0,sizeof(struct proxy_l));
288
-
289
-	p->port=port;
290
-	p->proto=proto;
291
-	p->host.h_addrtype=ip->af;
292
-	p->host.h_length=ip->len;
293
-	p->host.h_addr_list=pkg_malloc(2*sizeof(char*));
294
-	if (p->host.h_addr_list==0) goto error;
295
-	p->host.h_addr_list[1]=0;
296
-	p->host.h_addr_list[0]=pkg_malloc(ip->len+1);
297
-	if (p->host.h_addr_list[0]==0){
298
-		pkg_free(p->host.h_addr_list);
299
-		goto error;
300
-	}
301
-
302
-	memcpy(p->host.h_addr_list[0], ip->u.addr, ip->len);
303
-	p->host.h_addr_list[0][ip->len]=0;
304
-
305
-	return p;
306
-
307
-error:
308
-	return 0;
309
-}
310
-
311
-
312
-
313
-
314
-void free_proxy(struct proxy_l* p)
315
-{
316
-	if (p) free_hostent(&p->host);
317
-}
318
-
319
-
320
-void free_shm_proxy(struct proxy_l* p)
321
-{
322
-	if (p) free_shm_hostent(&p->host);
323
-}
Browse code

proxy.c: logging: DBG -> LM_DBG

Ovidiu Sas authored on 13/01/2015 15:41:58
Showing 1 changed files
... ...
@@ -228,19 +228,19 @@ error:
228 228
 		p=(struct proxy_l*) p_malloc(sizeof(struct proxy_l));			\
229 229
 		if (p==0){														\
230 230
 			ser_error=E_OUT_OF_MEM;										\
231
-			LM_ERR("memory allocation failure\n");		\
231
+			LM_ERR("memory allocation failure\n");						\
232 232
 			goto error;													\
233 233
 		}																\
234 234
 		memset(p,0,sizeof(struct proxy_l));								\
235 235
 		p->name=*name;													\
236 236
 		p->port=port;													\
237 237
 																		\
238
-		DBG("DEBUG: mk_proxy: doing DNS lookup...\n");					\
238
+		LM_DBG("doing DNS lookup...\n");								\
239 239
 		proto=protocol;													\
240 240
 		he=sip_resolvehost(name, &(p->port), &proto);					\
241 241
 		if (he==0){														\
242 242
 			ser_error=E_BAD_ADDRESS;									\
243
-			LM_CRIT("could not resolve hostname:"	\
243
+			LM_CRIT("could not resolve hostname:"						\
244 244
 				" \"%.*s\"\n", name->len, name->s);						\
245 245
 			p_free(p);													\
246 246
 			goto error;													\
Browse code

core Update headers, change "SIP-router" to "Kamailio", update doxygen file headers

Olle E. Johansson authored on 03/01/2015 14:15:58
Showing 1 changed files
... ...
@@ -11,11 +11,6 @@
11 11
  * the Free Software Foundation; either version 2 of the License, or
12 12
  * (at your option) any later version
13 13
  *
14
- * For a license to use the ser software under conditions
15
- * other than those described here, or to purchase support for this
16
- * software, please contact iptel.org by e-mail at the following addresses:
17
- *    info@iptel.org
18
- *
19 14
  * Kamailio is distributed in the hope that it will be useful,
20 15
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 16
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -1,14 +1,12 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * proxy list & assoc. functions
5 3
  *
6 4
  *
7 5
  * Copyright (C) 2001-2003 FhG Fokus
8 6
  *
9
- * This file is part of ser, a free SIP server.
7
+ * This file is part of Kamailio, a free SIP server.
10 8
  *
11
- * ser is free software; you can redistribute it and/or modify
9
+ * Kamailio is free software; you can redistribute it and/or modify
12 10
  * it under the terms of the GNU General Public License as published by
13 11
  * the Free Software Foundation; either version 2 of the License, or
14 12
  * (at your option) any later version
... ...
@@ -18,7 +16,7 @@
18 16
  * software, please contact iptel.org by e-mail at the following addresses:
19 17
  *    info@iptel.org
20 18
  *
21
- * ser is distributed in the hope that it will be useful,
19
+ * Kamailio is distributed in the hope that it will be useful,
22 20
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 21
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 22
  * GNU General Public License for more details.
... ...
@@ -27,16 +25,10 @@
27 25
  * along with this program; if not, write to the Free Software 
28 26
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
29 27
  */
30
- /*
31
-  * History:
32
-  * -------
33
-  *  2003-02-13  all *proxy functions are now proto aware (andrei)
34
-  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
35
-  */
36 28
 
37 29
 /*!
38 30
  * \file
39
- * \brief SIP-router core :: 
31
+ * \brief Kamailio core :: proxy list & assoc. functions
40 32
  * \ingroup core
41 33
  * Module: \ref core
42 34
  */
Browse code

proxy.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 04/10/2014 00:40:59
Showing 1 changed files
... ...
@@ -189,7 +189,7 @@ static int hostent_cpy(struct hostent *dst, struct hostent* src)
189 189
 	int ret;
190 190
 	HOSTENT_CPY(dst, src, pkg_malloc, pkg_free);
191 191
 error:
192
-	LOG(L_CRIT, "ERROR: hostent_cpy: memory allocation failure\n");
192
+	LM_CRIT("memory allocation failure\n");
193 193
 	return ret;
194 194
 }
195 195
 
... ...
@@ -199,7 +199,7 @@ static int hostent_shm_cpy(struct hostent *dst, struct hostent* src)
199 199
 	int ret;
200 200
 	HOSTENT_CPY(dst, src, shm_malloc, shm_free);
201 201
 error:
202
-	LOG(L_CRIT, "ERROR: hostent_shm_cpy: memory allocation failure\n");
202
+	LM_CRIT("memory allocation failure\n");
203 203
 	return ret;
204 204
 }
205 205
 
... ...
@@ -241,7 +241,7 @@ error:
241 241
 		p=(struct proxy_l*) p_malloc(sizeof(struct proxy_l));			\
242 242
 		if (p==0){														\
243 243
 			ser_error=E_OUT_OF_MEM;										\
244
-			ERR("ERROR: mk_proxy: memory allocation failure\n");		\
244
+			LM_ERR("memory allocation failure\n");		\
245 245
 			goto error;													\
246 246
 		}																\
247 247
 		memset(p,0,sizeof(struct proxy_l));								\
... ...
@@ -253,7 +253,7 @@ error:
253 253
 		he=sip_resolvehost(name, &(p->port), &proto);					\
254 254
 		if (he==0){														\
255 255
 			ser_error=E_BAD_ADDRESS;									\
256
-			LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"	\
256
+			LM_CRIT("could not resolve hostname:"	\
257 257
 				" \"%.*s\"\n", name->len, name->s);						\
258 258
 			p_free(p);													\
259 259
 			goto error;													\
... ...
@@ -294,7 +294,7 @@ struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
294 294
 
295 295
 	p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
296 296
 	if (p==0){
297
-		LOG(L_CRIT, "ERROR: mk_proxy_from_ip: memory allocation failure\n");
297
+		LM_CRIT("memory allocation failure\n");
298 298
 		goto error;
299 299
 	}
300 300
 	memset(p,0,sizeof(struct proxy_l));
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -25,7 +25,7 @@
25 25
  *
26 26
  * You should have received a copy of the GNU General Public License 
27 27
  * along with this program; if not, write to the Free Software 
28
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
29 29
  */
30 30
  /*
31 31
   * History:
Browse code

Adding doxygen template to all core .c files

Please fill in after the :: to explain the function of this file.

oej authored on 10/10/2009 13:54:13
Showing 1 changed files
... ...
@@ -34,6 +34,13 @@
34 34
   *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
35 35
   */
36 36
 
37
+/*!
38
+ * \file
39
+ * \brief SIP-router core :: 
40
+ * \ingroup core
41
+ * Module: \ref core
42
+ */
43
+
37 44
 
38 45
 
39 46
 #include "config.h"
Browse code

Shared memory versions of mk_proxy and free_proxy.

This patch adds function mk_shm_proxy, which is the shared memory
version of function mk_proxy. In addition to that it adds function
free_shm_proxy which is the shared memory version of free_proxy.

To avoid code duplication, we turned the body of the original
hostent_cpy function into macro called HOSTENT_CPY, the macro takes
malloc and free functions as parameters. The macro is then called in
the body of hostent_cpy with pkg_malloc and pkg_free as parameters and
in the body of hostent_shm_cpy with shm_malloc and shm_free as
parameters.

We did the same to mk_proxy function. The original body of the function
was converted into macro MK_PROXY which, again, takes memory allocation
functions as we all the hostent copy function as parameters.

Jan Janak authored on 31/03/2009 00:47:44
Showing 1 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #include "error.h"
42 42
 #include "dprint.h"
43 43
 #include "mem/mem.h"
44
+#include "mem/shm_mem.h"
44 45
 
45 46
 #include <string.h>
46 47
 #include <stdlib.h>
... ...
@@ -75,107 +76,136 @@ static struct proxy_l* find_proxy(str *name, unsigned short port, int proto)
75 76
 }
76 77
 
77 78
 
79
+#define HOSTENT_CPY(dst, src, he_malloc, he_free)						\
80
+	do {																\
81
+		unsigned len,len2;												\
82
+		int r,i;														\
83
+																		\
84
+		/* start copying the host entry.. */							\
85
+		/* copy h_name */												\
86
+		len=strlen(src->h_name)+1;										\
87
+		dst->h_name=(char*)he_malloc(sizeof(char) * len);				\
88
+		if (dst->h_name) strncpy(dst->h_name,src->h_name, len);			\
89
+		else{															\
90
+			ser_error=ret=E_OUT_OF_MEM;									\
91
+			goto error;													\
92
+		}																\
93
+																		\
94
+		/* copy h_aliases */											\
95
+		len=0;															\
96
+		if (src->h_aliases)												\
97
+			for (;src->h_aliases[len];len++);							\
98
+		dst->h_aliases=(char**)he_malloc(sizeof(char*)*(len+1));		\
99
+		if (dst->h_aliases==0){											\
100
+			ser_error=ret=E_OUT_OF_MEM;									\
101
+			he_free(dst->h_name);										\
102
+			goto error;													\
103
+		}																\
104
+		memset((void*)dst->h_aliases, 0, sizeof(char*) * (len+1) );		\
105
+		for (i=0;i<len;i++){											\
106
+			len2=strlen(src->h_aliases[i])+1;							\
107
+			dst->h_aliases[i]=(char*)he_malloc(sizeof(char)*len2);		\
108
+			if (dst->h_aliases==0){										\
109
+				ser_error=ret=E_OUT_OF_MEM;								\
110
+				he_free(dst->h_name);									\
111
+				for(r=0; r<i; r++)	he_free(dst->h_aliases[r]);			\
112
+				he_free(dst->h_aliases);								\
113
+				goto error;												\
114
+			}															\
115
+			strncpy(dst->h_aliases[i], src->h_aliases[i], len2);		\
116
+		}																\
117
+		/* copy h_addr_list */											\
118
+		len=0;															\
119
+		if (src->h_addr_list)											\
120
+			for (;src->h_addr_list[len];len++);							\
121
+		dst->h_addr_list=(char**)he_malloc(sizeof(char*)*(len+1));		\
122
+		if (dst->h_addr_list==0){										\
123
+			ser_error=ret=E_OUT_OF_MEM;									\
124
+			he_free(dst->h_name);										\
125
+			for(r=0; dst->h_aliases[r]; r++)							\
126
+				he_free(dst->h_aliases[r]);								\
127
+			he_free(dst->h_aliases[r]);									\
128
+			he_free(dst->h_aliases);									\
129
+			goto error;													\
130
+		}																\
131
+		memset((void*)dst->h_addr_list, 0, sizeof(char*) * (len+1) );	\
132
+		for (i=0;i<len;i++){											\
133
+			dst->h_addr_list[i]=										\
134
+				(char*)he_malloc(sizeof(char)*src->h_length);			\
135
+			if (dst->h_addr_list[i]==0){								\
136
+				ser_error=ret=E_OUT_OF_MEM;								\
137
+				he_free(dst->h_name);									\
138
+				for(r=0; dst->h_aliases[r]; r++)						\
139
+					he_free(dst->h_aliases[r]);							\
140
+				he_free(dst->h_aliases[r]);								\
141
+				he_free(dst->h_aliases);								\
142
+				for (r=0; r<i;r++) he_free(dst->h_addr_list[r]);		\
143
+				he_free(dst->h_addr_list);								\
144
+				goto error;												\
145
+			}															\
146
+			memcpy(dst->h_addr_list[i], src->h_addr_list[i],			\
147
+				   src->h_length);										\
148
+		}																\
149
+																		\
150
+		/* copy h_addr_type & length */									\
151
+		dst->h_addrtype=src->h_addrtype;								\
152
+		dst->h_length=src->h_length;									\
153
+		/*finished hostent copy */										\
154
+																		\
155
+		return 0;														\
156
+	} while(0)
157
+
158
+
159
+#define FREE_HOSTENT(dst, he_free)						\
160
+	do {												\
161
+		int r;											\
162
+		if (dst->h_name) he_free(dst->h_name);			\
163
+		if (dst->h_aliases){							\
164
+			for(r=0; dst->h_aliases[r]; r++) {			\
165
+				he_free(dst->h_aliases[r]);				\
166
+			}											\
167
+			he_free(dst->h_aliases);					\
168
+		}												\
169
+		if (dst->h_addr_list){							\
170
+			for (r=0; dst->h_addr_list[r];r++) {		\
171
+				he_free(dst->h_addr_list[r]);			\
172
+			}											\
173
+			he_free(dst->h_addr_list);					\
174
+		}												\
175
+	} while(0)
176
+
177
+
78 178
 
79 179
 /* copies a hostent structure*, returns 0 on success, <0 on error*/
80 180
 static int hostent_cpy(struct hostent *dst, struct hostent* src)
81 181
 {
82
-	unsigned len,len2;
83
-	int r,ret,i;
84
-
85
-	/* start copying the host entry.. */
86
-	/* copy h_name */
87
-	len=strlen(src->h_name)+1;
88
-	dst->h_name=(char*)pkg_malloc(sizeof(char) * len);
89
-	if (dst->h_name) strncpy(dst->h_name,src->h_name, len);
90
-	else{
91
-		ser_error=ret=E_OUT_OF_MEM;
92
-		goto error;
93
-	}
94
-
95
-	/* copy h_aliases */
96
-	len=0;
97
-	if (src->h_aliases)
98
-		for (;src->h_aliases[len];len++);
99
-	dst->h_aliases=(char**)pkg_malloc(sizeof(char*)*(len+1));
100
-	if (dst->h_aliases==0){
101
-		ser_error=ret=E_OUT_OF_MEM;
102
-		pkg_free(dst->h_name);
103
-		goto error;
104
-	}
105
-	memset((void*)dst->h_aliases, 0, sizeof(char*) * (len+1) );
106
-	for (i=0;i<len;i++){
107
-		len2=strlen(src->h_aliases[i])+1;
108
-		dst->h_aliases[i]=(char*)pkg_malloc(sizeof(char)*len2);
109
-		if (dst->h_aliases==0){
110
-			ser_error=ret=E_OUT_OF_MEM;
111
-			pkg_free(dst->h_name);
112
-			for(r=0; r<i; r++)	pkg_free(dst->h_aliases[r]);
113
-			pkg_free(dst->h_aliases);
114
-			goto error;
115
-		}
116
-		strncpy(dst->h_aliases[i], src->h_aliases[i], len2);
117
-	}
118
-	/* copy h_addr_list */
119
-	len=0;
120
-	if (src->h_addr_list)
121
-		for (;src->h_addr_list[len];len++);
122
-	dst->h_addr_list=(char**)pkg_malloc(sizeof(char*)*(len+1));
123
-	if (dst->h_addr_list==0){
124
-		ser_error=ret=E_OUT_OF_MEM;
125
-		pkg_free(dst->h_name);
126
-		for(r=0; dst->h_aliases[r]; r++)	pkg_free(dst->h_aliases[r]);
127
-		pkg_free(dst->h_aliases[r]);
128
-		pkg_free(dst->h_aliases);
129
-		goto error;
130
-	}
131
-	memset((void*)dst->h_addr_list, 0, sizeof(char*) * (len+1) );
132
-	for (i=0;i<len;i++){
133
-		dst->h_addr_list[i]=(char*)pkg_malloc(sizeof(char)*src->h_length);
134
-		if (dst->h_addr_list[i]==0){
135
-			ser_error=ret=E_OUT_OF_MEM;
136
-			pkg_free(dst->h_name);
137
-			for(r=0; dst->h_aliases[r]; r++)	pkg_free(dst->h_aliases[r]);
138
-			pkg_free(dst->h_aliases[r]);
139
-			pkg_free(dst->h_aliases);
140
-			for (r=0; r<i;r++) pkg_free(dst->h_addr_list[r]);
141
-			pkg_free(dst->h_addr_list);
142
-			goto error;
143
-		}
144
-		memcpy(dst->h_addr_list[i], src->h_addr_list[i], src->h_length);
145
-	}
146
-
147
-	/* copy h_addr_type & length */
148
-	dst->h_addrtype=src->h_addrtype;
149
-	dst->h_length=src->h_length;
150
-	/*finished hostent copy */
151
-	
152
-	return 0;
153
-
182
+	int ret;
183
+	HOSTENT_CPY(dst, src, pkg_malloc, pkg_free);
154 184
 error:
155 185
 	LOG(L_CRIT, "ERROR: hostent_cpy: memory allocation failure\n");
156 186
 	return ret;
157 187
 }
158 188
 
159 189
 
190
+static int hostent_shm_cpy(struct hostent *dst, struct hostent* src)
191
+{
192
+	int ret;
193
+	HOSTENT_CPY(dst, src, shm_malloc, shm_free);
194
+error:
195
+	LOG(L_CRIT, "ERROR: hostent_shm_cpy: memory allocation failure\n");
196
+	return ret;
197
+}
198
+
160 199
 
161
-void free_hostent(struct hostent *dst)
200
+void free_hostent(struct hostent* dst)
162 201
 {
163
-	int r;
164
-	if (dst->h_name) pkg_free(dst->h_name);
165
-	if (dst->h_aliases){
166
-		for(r=0; dst->h_aliases[r]; r++) {
167
-			pkg_free(dst->h_aliases[r]);
168
-		}
169
-		pkg_free(dst->h_aliases);
170
-	}
171
-	if (dst->h_addr_list){
172
-		for (r=0; dst->h_addr_list[r];r++) { 
173
-			pkg_free(dst->h_addr_list[r]);
174
-		}
175
-		pkg_free(dst->h_addr_list);
176
-	}
202
+	FREE_HOSTENT(dst, pkg_free);
177 203
 }
178 204
 
205
+void free_shm_hostent(struct hostent* dst)
206
+{
207
+	FREE_HOSTENT(dst, shm_free);
208
+}
179 209
 
180 210
 
181 211
 
... ...
@@ -195,46 +225,56 @@ error:
195 225
 }
196 226
 
197 227
 
198
-
228
+#define MK_PROXY(name, port, protocol, p_malloc, p_free, he_cpy)		\
229
+	do {																\
230
+		struct proxy_l* p;												\
231
+		struct hostent* he;												\
232
+		char proto;														\
233
+																		\
234
+		p=(struct proxy_l*) p_malloc(sizeof(struct proxy_l));			\
235
+		if (p==0){														\
236
+			ser_error=E_OUT_OF_MEM;										\
237
+			ERR("ERROR: mk_proxy: memory allocation failure\n");		\
238
+			goto error;													\
239
+		}																\
240
+		memset(p,0,sizeof(struct proxy_l));								\
241
+		p->name=*name;													\
242
+		p->port=port;													\
243
+																		\
244
+		DBG("DEBUG: mk_proxy: doing DNS lookup...\n");					\
245
+		proto=protocol;													\
246
+		he=sip_resolvehost(name, &(p->port), &proto);					\
247
+		if (he==0){														\
248
+			ser_error=E_BAD_ADDRESS;									\
249
+			LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"	\
250
+				" \"%.*s\"\n", name->len, name->s);						\
251
+			p_free(p);													\
252
+			goto error;													\
253
+		}																\
254
+		if (he_cpy(&(p->host), he)!=0){									\
255
+			p_free(p);													\
256
+			goto error;													\
257
+		}																\
258
+		p->proto=proto;													\
259
+		p->ok=1;														\
260
+		return p;														\
261
+	error:																\
262
+		return 0;														\
263
+																		\
264
+	} while(0)
199 265
 
200 266
 /* same as add_proxy, but it doesn't add the proxy to the list
201 267
  * uses also SRV if possible & port==0 (quick hack) */
202 268
 
203 269
 struct proxy_l* mk_proxy(str* name, unsigned short port, int protocol)
204 270
 {
205
-	struct proxy_l* p;
206
-	struct hostent* he;
207
-	char proto;
271
+	MK_PROXY(name, port, protocol, pkg_malloc, pkg_free, hostent_cpy);
272
+}
208 273
 
209
-	p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
210
-	if (p==0){
211
-		ser_error=E_OUT_OF_MEM;
212
-		LOG(L_CRIT, "ERROR: mk_proxy: memory allocation failure\n");
213
-		goto error;
214
-	}
215
-	memset(p,0,sizeof(struct proxy_l));
216
-	p->name=*name;
217
-	p->port=port;
218 274
 
219
-	DBG("DEBUG: mk_proxy: doing DNS lookup...\n");
220
-	proto=protocol;
221
-	he=sip_resolvehost(name, &(p->port), &proto);
222
-	if (he==0){
223
-		ser_error=E_BAD_ADDRESS;
224
-		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
225
-					" \"%.*s\"\n", name->len, name->s);
226
-		pkg_free(p);
227
-		goto error;
228
-	}
229
-	if (hostent_cpy(&(p->host), he)!=0){
230
-		pkg_free(p);
231
-		goto error;
232
-	}
233
-	p->proto=proto;
234
-	p->ok=1;
235
-	return p;
236
-error:
237
-	return 0;
275
+struct proxy_l* mk_shm_proxy(str* name, unsigned short port, int protocol)
276
+{
277
+	MK_PROXY(name, port, protocol, shm_malloc, shm_free, hostent_shm_cpy);
238 278
 }
239 279
 
240 280
 
... ...
@@ -281,3 +321,9 @@ void free_proxy(struct proxy_l* p)
281 321
 {
282 322
 	if (p) free_hostent(&p->host);
283 323
 }
324
+
325
+
326
+void free_shm_proxy(struct proxy_l* p)
327
+{
328
+	if (p) free_shm_hostent(&p->host);
329
+}
Browse code

- dns naptr support (off by default) - dns naptr related config options: dns_try_naptr (off by default), dns_udp_pref, dns_tcp_pref. dns_tls_pref (protocol preferences for naptr record selection) - dns srv load balancing config options: dns_srv_lb (off by default) - dns resolver & cache api change (to support getting the protocol via naptr) - fix: dns iteration through A & AAAA records was not correct

For more info see doc/dns.txt.

Andrei Pelinescu-Onciul authored on 18/06/2007 21:20:58
Showing 1 changed files
... ...
@@ -200,10 +200,11 @@ error:
200 200
 /* same as add_proxy, but it doesn't add the proxy to the list
201 201
  * uses also SRV if possible & port==0 (quick hack) */
202 202
 
203
-struct proxy_l* mk_proxy(str* name, unsigned short port, int proto)
203
+struct proxy_l* mk_proxy(str* name, unsigned short port, int protocol)
204 204
 {
205 205
 	struct proxy_l* p;
206 206
 	struct hostent* he;
207
+	char proto;
207 208
 
208 209
 	p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
209 210
 	if (p==0){
... ...
@@ -214,10 +215,10 @@ struct proxy_l* mk_proxy(str* name, unsigned short port, int proto)
214 215
 	memset(p,0,sizeof(struct proxy_l));
215 216
 	p->name=*name;
216 217
 	p->port=port;
217
-	p->proto=proto;
218 218
 
219 219
 	DBG("DEBUG: mk_proxy: doing DNS lookup...\n");
220
-	he=sip_resolvehost(name, &(p->port), proto);
220
+	proto=protocol;
221
+	he=sip_resolvehost(name, &(p->port), &proto);
221 222
 	if (he==0){
222 223
 		ser_error=E_BAD_ADDRESS;
223 224
 		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
... ...
@@ -229,6 +230,7 @@ struct proxy_l* mk_proxy(str* name, unsigned short port, int proto)
229 230
 		pkg_free(p);
230 231
 		goto error;
231 232
 	}
233
+	p->proto=proto;
232 234
 	p->ok=1;
233 235
 	return p;
234 236
 error:
Browse code

- Spelling checked - READMEs updated

Jan Janak authored on 24/08/2004 08:45:09
Showing 1 changed files
... ...
@@ -4,7 +4,7 @@
4 4
  * proxy list & assoc. functions
5 5
  *
6 6
  *
7
- * Copyright (C) 2001-2003 Fhg Fokus
7
+ * Copyright (C) 2001-2003 FhG Fokus
8 8
  *
9 9
  * This file is part of ser, a free SIP server.
10 10
  *
Browse code

- added ipv6 address reference resolver support

Andrei Pelinescu-Onciul authored on 12/04/2003 20:55:30
Showing 1 changed files
... ...
@@ -30,7 +30,7 @@
30 30
  /*
31 31
   * History:
32 32
   * -------
33
-  *  2003-02-13  all *proxy fucntions are now proto aware (andrei)
33
+  *  2003-02-13  all *proxy functions are now proto aware (andrei)
34 34
   *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
35 35
   */
36 36
 
Browse code

- another extra pkg_free removed (a few lines down from the previous one)

Andrei Pelinescu-Onciul authored on 20/03/2003 17:10:24
Showing 1 changed files
... ...
@@ -172,7 +172,6 @@ void free_hostent(struct hostent *dst)
172 172
 		for (r=0; dst->h_addr_list[r];r++) { 
173 173
 			pkg_free(dst->h_addr_list[r]);
174 174
 		}
175
-		pkg_free(dst->h_addr_list[r]);
176 175
 		pkg_free(dst->h_addr_list);
177 176
 	}
178 177
 }
Browse code

Extra pkg_free in free_hostent removed

Jan Janak authored on 20/03/2003 16:47:16
Showing 1 changed files
... ...
@@ -163,12 +163,15 @@ void free_hostent(struct hostent *dst)
163 163
 	int r;
164 164
 	if (dst->h_name) pkg_free(dst->h_name);
165 165
 	if (dst->h_aliases){
166
-		for(r=0; dst->h_aliases[r]; r++)	pkg_free(dst->h_aliases[r]);
167
-		pkg_free(dst->h_aliases[r]);
166
+		for(r=0; dst->h_aliases[r]; r++) {
167
+			pkg_free(dst->h_aliases[r]);
168
+		}
168 169
 		pkg_free(dst->h_aliases);
169 170
 	}
170 171
 	if (dst->h_addr_list){
171
-		for (r=0; dst->h_addr_list[r];r++) pkg_free(dst->h_addr_list[r]);
172
+		for (r=0; dst->h_addr_list[r];r++) { 
173
+			pkg_free(dst->h_addr_list[r]);
174
+		}
172 175
 		pkg_free(dst->h_addr_list[r]);
173 176
 		pkg_free(dst->h_addr_list);
174 177
 	}
Browse code

- replaced all mallocs/frees w/ pkg_malloc/pkg_free - minor lock_dealloc warning fixes

Andrei Pelinescu-Onciul authored on 19/03/2003 18:41:58
Showing 1 changed files
... ...
@@ -31,6 +31,7 @@
31 31
   * History:
32 32
   * -------
33 33
   *  2003-02-13  all *proxy fucntions are now proto aware (andrei)
34
+  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
34 35
   */
35 36
 
36 37
 
... ...
@@ -39,6 +40,7 @@
39 40
 #include "proxy.h"
40 41
 #include "error.h"
41 42
 #include "dprint.h"
43
+#include "mem/mem.h"
42 44
 
43 45