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,359 +0,0 @@
1
-/*
2
- * various general purpose functions
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- *
6
- * Permission to use, copy, modify, and distribute this software for any
7
- * purpose with or without fee is hereby granted, provided that the above
8
- * copyright notice and this permission notice appear in all copies.
9
- *
10
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
- *
18
- */
19
-
20
-
21
-/** Kamailio core :: various general purpose/utility functions.
22
- * @file ut.c
23
- * @ingroup core
24
- * Module: core
25
- */
26
-
27
-#include <sys/types.h>
28
-#include <pwd.h>
29
-#include <grp.h>
30
-#include <stdlib.h>
31
-#include <time.h>
32
-#include <sys/utsname.h> /* uname() */
33
-#include <libgen.h>
34
-
35
-
36
-#include "ut.h"
37
-#include "mem/mem.h"
38
-#include "globals.h"
39
-
40
-/* global buffer for ut.h int2str() */
41
-char ut_buf_int2str[INT2STR_MAX_LEN];
42
-
43
-
44
-/* converts a username into uid:gid,
45
- * returns -1 on error & 0 on success */
46
-int user2uid(int* uid, int* gid, char* user)
47
-{
48
-	char* tmp;
49
-	struct passwd *pw_entry;
50
-
51
-	if (user){
52
-		*uid=strtol(user, &tmp, 10);
53
-		if ((tmp==0) ||(*tmp)){
54
-			/* maybe it's a string */
55
-			pw_entry=getpwnam(user);
56
-			if (pw_entry==0){
57
-				goto error;
58
-			}
59
-			*uid=pw_entry->pw_uid;
60
-			if (gid) *gid=pw_entry->pw_gid;
61
-		}
62
-		return 0;
63
-	}
64
-error:
65
-	return -1;
66
-}
67
-
68
-
69
-
70
-/* converts a group name into a gid
71
- * returns -1 on error, 0 on success */
72
-int group2gid(int* gid, char* group)
73
-{
74
-	char* tmp;
75
-	struct group  *gr_entry;
76
-
77
-	if (group){
78
-		*gid=strtol(group, &tmp, 10);
79
-		if ((tmp==0) ||(*tmp)){
80
-			/* maybe it's a string */
81
-			gr_entry=getgrnam(group);
82
-			if (gr_entry==0){
83
-				goto error;
84
-			}
85
-			*gid=gr_entry->gr_gid;
86
-		}
87
-		return 0;
88
-	}
89
- error:
90
-	return -1;
91
-}
92
-
93
-
94
-/*
95
- * Replacement of timegm (does not exists on all platforms
96
- * Taken from
97
- * http://lists.samba.org/archive/samba-technical/2002-November/025737.html
98
- */
99
-time_t _timegm(struct tm* t)
100
-{
101
-	time_t tl, tb;
102
-	struct tm* tg;
103
-
104
-	t->tm_isdst = 0;
105
-	tl = mktime(t);
106
-	if (tl == -1) {
107
-		t->tm_hour--;
108
-		tl = mktime (t);
109
-		if (tl == -1) {
110
-			return -1; /* can't deal with output from strptime */
111
-		}
112
-		tl += 3600;
113
-	}
114
-
115
-	tg = gmtime(&tl);
116
-	tg->tm_isdst = 0;
117
-	tb = mktime(tg);
118
-	if (tb == -1) {
119
-		tg->tm_hour--;
120
-		tb = mktime (tg);
121
-		if (tb == -1) {
122
-			return -1; /* can't deal with output from gmtime */
123
-		}
124
-		tb += 3600;
125
-	}
126
-	return (tl - (tb - tl));
127
-}
128
-
129
-
130
-/* Convert time_t value that is relative to local timezone to UTC */
131
-time_t local2utc(time_t in)
132
-{
133
-	struct tm* tt;
134
-	tt = gmtime(&in);
135
-	tt->tm_isdst = -1;
136
-	return mktime(tt);
137
-}
138
-
139
-
140
-/* Convert time_t value in UTC to to value relative to local time zone */
141
-time_t utc2local(time_t in)
142
-{
143
-	struct tm* tt;
144
-	tt = localtime(&in);
145
-#ifdef HAVE_TIMEGM
146
-	return timegm(tt);
147
-#else
148
-	return _timegm(tt);
149
-#endif
150
-}
151
-
152
-
153
-/*
154
- * Return str as zero terminated string allocated
155
- * using pkg_malloc
156
- */
157
-char* as_asciiz(str* s)
158
-{
159
-    char* r;
160
-
161
-    r = (char*)pkg_malloc(s->len + 1);
162
-    if (!r) {
163
-		ERR("Out of memory\n");
164
-		return 0;
165
-    }
166
-    memcpy(r, s->s, s->len);
167
-    r[s->len] = '\0';
168
-    return r;
169
-}
170
-
171
-
172
-
173
-/* return system version (major.minor.minor2) as
174
- *  (major<<16)|(minor)<<8|(minor2)
175
- * (if some of them are missing, they are set to 0)
176
- * if the parameters are not null they are set to the coresp. part
177
- */
178
-unsigned int get_sys_version(int* major, int* minor, int* minor2)
179
-{
180
-	struct utsname un;
181
-	int m1;
182
-	int m2;
183
-	int m3;
184
-	char* p;
185
-
186
-	memset (&un, 0, sizeof(un));
187
-	m1=m2=m3=0;
188
-	/* get sys version */
189
-	uname(&un);
190
-	m1=strtol(un.release, &p, 10);
191
-	if (*p=='.'){
192
-		p++;
193
-		m2=strtol(p, &p, 10);
194
-		if (*p=='.'){
195
-			p++;
196
-			m3=strtol(p, &p, 10);
197
-		}
198
-	}
199
-	if (major) *major=m1;
200
-	if (minor) *minor=m2;
201
-	if (minor2) *minor2=m3;
202
-	return ((m1<<16)|(m2<<8)|(m3));
203
-}
204
-
205
-
206
-
207
-/** transform a relative pathname into an absolute one.
208
- * @param base  - base file, used to extract the absolute path prefix.
209
- *                Might be NULL, in which case the path of the ser.cfg is
210
- *                used.
211
- * @param file  - file path to be transformed. If it's already absolute
212
- *                (starts with '/') is left alone. If not the result will
213
- *                be `dirname base`/file.
214
- * @return  pkg allocated asciiz string or 0 on error.
215
- */
216
-char* get_abs_pathname(str* base, str* file)
217
-{
218
-	str ser_cfg;
219
-	char* buf, *dir, *res;
220
-	int len;
221
-
222
-	if (base == NULL) {
223
-		ser_cfg.s = cfg_file;
224
-		ser_cfg.len = strlen(cfg_file);
225
-		base = &ser_cfg;
226
-	}
227
-
228
-	if (!base->s || base->len <= 0 || base->s[0] != '/') {
229
-		BUG("get_abs_pathname: Base file must be absolute pathname: "
230
-			"'%.*s'\n", STR_FMT(base));
231
-		return NULL;
232
-	}
233
-
234
-	if (!file || !file->s || file->len <= 0) {
235
-		BUG("get_abs_pathname: Invalid 'file' parameter\n");
236
-		return NULL;
237
-	}
238
-
239
-	if (file->s[0] == '/') {
240
-		/* This is an absolute pathname, make a zero terminated
241
-		 * copy and use it as it is */
242
-		if ((res = pkg_malloc(file->len+1)) == NULL) {
243
-			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
244
-			return NULL;
245
-		}
246
-		memcpy(res, file->s, file->len);
247
-		res[file->len]=0;
248
-	} else {
249
-		/* This is not an absolute pathname, make it relative
250
-		 * to the location of the base file
251
-		 */
252
-		/* Make a copy, function dirname may modify the string */
253
-		if ((buf = pkg_malloc(base->len+1)) == NULL) {
254
-			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
255
-			return NULL;
256
-		}
257
-		memcpy(buf, base->s, base->len);
258
-		buf[base->len]=0;
259
-		dir = dirname(buf);
260
-
261
-		len = strlen(dir);
262
-		if ((res = pkg_malloc(len + 1 + file->len + 1)) == NULL) {
263
-			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
264
-			pkg_free(buf);
265
-			return NULL;
266
-		}
267
-		memcpy(res, dir, len);
268
-		res[len] = '/';
269
-		memcpy(res + len + 1, file->s, file->len);
270
-		res[len + 1 + file->len] = '\0';
271
-		pkg_free(buf);
272
-	}
273
-	return res;
274
-}
275
-
276
-
277
-/**
278
- * @brief search for occurence of needle in text
279
- * @return pointer to start of needle in text or NULL if the needle
280
- *	is not found
281
- */
282
-char *str_search(str *text, str *needle)
283
-{
284
-    char *p;
285
-
286
-    if(text==NULL || text->s==NULL || needle==NULL || needle->s==NULL
287
-			|| text->len<needle->len)
288
-        return NULL;
289
-
290
-    for (p = text->s; p <= text->s + text->len - needle->len; p++) {
291
-        if (*p == *needle->s && memcmp(p, needle->s, needle->len)==0) {
292
-            return p;
293
-        }
294
-    }
295
-
296
-    return NULL;
297
-}
298
-
299
-/*
300
- * ser_memmem() returns the location of the first occurrence of data
301
- * pattern b2 of size len2 in memory block b1 of size len1 or
302
- * NULL if none is found. Obtained from NetBSD.
303
- */
304
-void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2)
305
-{
306
-	/* Initialize search pointer */
307
-	char *sp = (char *) b1;
308
-
309
-	/* Initialize pattern pointer */
310
-	char *pp = (char *) b2;
311
-
312
-	/* Initialize end of search address space pointer */
313
-	char *eos = sp + len1 - len2;
314
-
315
-	/* Sanity check */
316
-	if(!(b1 && b2 && len1 && len2))
317
-		return NULL;
318
-
319
-	while (sp <= eos) {
320
-		if (*sp == *pp)
321
-			if (memcmp(sp, pp, len2) == 0)
322
-				return sp;
323
-
324
-		sp++;
325
-	}
326
-
327
-	return NULL;
328
-}
329
-
330
-/*
331
- * ser_memrmem() returns the location of the last occurrence of data
332
- * pattern b2 of size len2 in memory block b1 of size len1 or
333
- * NULL if none is found.
334
- */
335
-void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2)
336
-{
337
-	/* Initialize search pointer */
338
-	char *sp = (char *) b1 + len1 - len2;
339
-
340
-	/* Initialize pattern pointer */
341
-	char *pp = (char *) b2;
342
-
343
-	/* Initialize end of search address space pointer */
344
-	char *eos = (char *) b1;
345
-
346
-	/* Sanity check */
347
-	if(!(b1 && b2 && len1 && len2))
348
-		return NULL;
349
-
350
-	while (sp >= eos) {
351
-		if (*sp == *pp)
352
-			if (memcmp(sp, pp, len2) == 0)
353
-				return sp;
354
-
355
-		sp--;
356
-	}
357
-
358
-	return NULL;
359
-}
Browse code

core: ut - fix misleading indentation for IF blocks

- reported by latest gcc on debian sid

Daniel-Constantin Mierla authored on 15/09/2016 13:30:13
Showing 1 changed files
... ...
@@ -47,7 +47,7 @@ int user2uid(int* uid, int* gid, char* user)
47 47
 {
48 48
 	char* tmp;
49 49
 	struct passwd *pw_entry;
50
-	
50
+
51 51
 	if (user){
52 52
 		*uid=strtol(user, &tmp, 10);
53 53
 		if ((tmp==0) ||(*tmp)){
... ...
@@ -73,7 +73,7 @@ int group2gid(int* gid, char* group)
73 73
 {
74 74
 	char* tmp;
75 75
 	struct group  *gr_entry;
76
-	
76
+
77 77
 	if (group){
78 78
 		*gid=strtol(group, &tmp, 10);
79 79
 		if ((tmp==0) ||(*tmp)){
... ...
@@ -93,7 +93,7 @@ int group2gid(int* gid, char* group)
93 93
 
94 94
 /*
95 95
  * Replacement of timegm (does not exists on all platforms
96
- * Taken from 
96
+ * Taken from
97 97
  * http://lists.samba.org/archive/samba-technical/2002-November/025737.html
98 98
  */
99 99
 time_t _timegm(struct tm* t)
... ...
@@ -111,7 +111,7 @@ time_t _timegm(struct tm* t)
111 111
 		}
112 112
 		tl += 3600;
113 113
 	}
114
-	
114
+
115 115
 	tg = gmtime(&tl);
116 116
 	tg->tm_isdst = 0;
117 117
 	tb = mktime(tg);
... ...
@@ -173,7 +173,7 @@ char* as_asciiz(str* s)
173 173
 /* return system version (major.minor.minor2) as
174 174
  *  (major<<16)|(minor)<<8|(minor2)
175 175
  * (if some of them are missing, they are set to 0)
176
- * if the parameters are not null they are set to the coresp. part 
176
+ * if the parameters are not null they are set to the coresp. part
177 177
  */
178 178
 unsigned int get_sys_version(int* major, int* minor, int* minor2)
179 179
 {
... ...
@@ -182,7 +182,7 @@ unsigned int get_sys_version(int* major, int* minor, int* minor2)
182 182
 	int m2;
183 183
 	int m3;
184 184
 	char* p;
185
-	
185
+
186 186
 	memset (&un, 0, sizeof(un));
187 187
 	m1=m2=m3=0;
188 188
 	/* get sys version */
... ...
@@ -218,24 +218,24 @@ char* get_abs_pathname(str* base, str* file)
218 218
 	str ser_cfg;
219 219
 	char* buf, *dir, *res;
220 220
 	int len;
221
-  	
221
+
222 222
 	if (base == NULL) {
223 223
 		ser_cfg.s = cfg_file;
224 224
 		ser_cfg.len = strlen(cfg_file);
225 225
 		base = &ser_cfg;
226 226
 	}
227
-	
227
+
228 228
 	if (!base->s || base->len <= 0 || base->s[0] != '/') {
229 229
 		BUG("get_abs_pathname: Base file must be absolute pathname: "
230 230
 			"'%.*s'\n", STR_FMT(base));
231 231
 		return NULL;
232 232
 	}
233
-	
233
+
234 234
 	if (!file || !file->s || file->len <= 0) {
235 235
 		BUG("get_abs_pathname: Invalid 'file' parameter\n");
236 236
 		return NULL;
237 237
 	}
238
-	
238
+
239 239
 	if (file->s[0] == '/') {
240 240
 		/* This is an absolute pathname, make a zero terminated
241 241
 		 * copy and use it as it is */
... ...
@@ -257,7 +257,7 @@ char* get_abs_pathname(str* base, str* file)
257 257
 		memcpy(buf, base->s, base->len);
258 258
 		buf[base->len]=0;
259 259
 		dir = dirname(buf);
260
-		
260
+
261 261
 		len = strlen(dir);
262 262
 		if ((res = pkg_malloc(len + 1 + file->len + 1)) == NULL) {
263 263
 			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
... ...
@@ -321,7 +321,7 @@ void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2)
321 321
 			if (memcmp(sp, pp, len2) == 0)
322 322
 				return sp;
323 323
 
324
-			sp++;
324
+		sp++;
325 325
 	}
326 326
 
327 327
 	return NULL;
... ...
@@ -352,7 +352,7 @@ void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2)
352 352
 			if (memcmp(sp, pp, len2) == 0)
353 353
 				return sp;
354 354
 
355
-			sp--;
355
+		sp--;
356 356
 	}
357 357
 
358 358
 	return NULL;
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,6 +1,4 @@
1 1
 /*
2
- *$Id$
3
- *
4 2
  * various general purpose functions
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG Fokus
... ...
@@ -20,7 +18,7 @@
20 18
  */
21 19
 
22 20
 
23
-/** various general purpose/utility functions.
21
+/** Kamailio core :: various general purpose/utility functions.
24 22
  * @file ut.c
25 23
  * @ingroup core
26 24
  * Module: core
Browse code

core, parser: moved ser_mem[r]mem() functions from parser to ut.c

Juha Heinanen authored on 09/04/2014 17:30:23
Showing 1 changed files
... ...
@@ -297,3 +297,65 @@ char *str_search(str *text, str *needle)
297 297
 
298 298
     return NULL;
299 299
 }
300
+
301
+/*
302
+ * ser_memmem() returns the location of the first occurrence of data
303
+ * pattern b2 of size len2 in memory block b1 of size len1 or
304
+ * NULL if none is found. Obtained from NetBSD.
305
+ */
306
+void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2)
307
+{
308
+	/* Initialize search pointer */
309
+	char *sp = (char *) b1;
310
+
311
+	/* Initialize pattern pointer */
312
+	char *pp = (char *) b2;
313
+
314
+	/* Initialize end of search address space pointer */
315
+	char *eos = sp + len1 - len2;
316
+
317
+	/* Sanity check */
318
+	if(!(b1 && b2 && len1 && len2))
319
+		return NULL;
320
+
321
+	while (sp <= eos) {
322
+		if (*sp == *pp)
323
+			if (memcmp(sp, pp, len2) == 0)
324
+				return sp;
325
+
326
+			sp++;
327
+	}
328
+
329
+	return NULL;
330
+}
331
+
332
+/*
333
+ * ser_memrmem() returns the location of the last occurrence of data
334
+ * pattern b2 of size len2 in memory block b1 of size len1 or
335
+ * NULL if none is found.
336
+ */
337
+void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2)
338
+{
339
+	/* Initialize search pointer */
340
+	char *sp = (char *) b1 + len1 - len2;
341
+
342
+	/* Initialize pattern pointer */
343
+	char *pp = (char *) b2;
344
+
345
+	/* Initialize end of search address space pointer */
346
+	char *eos = (char *) b1;
347
+
348
+	/* Sanity check */
349
+	if(!(b1 && b2 && len1 && len2))
350
+		return NULL;
351
+
352
+	while (sp >= eos) {
353
+		if (*sp == *pp)
354
+			if (memcmp(sp, pp, len2) == 0)
355
+				return sp;
356
+
357
+			sp--;
358
+	}
359
+
360
+	return NULL;
361
+}
Browse code

core: added function to search a str inside a str

- str_search(text, needle) added to return the position of str needle
when it is found inside str text

Daniel-Constantin Mierla authored on 26/03/2011 22:44:01
Showing 1 changed files
... ...
@@ -274,3 +274,26 @@ char* get_abs_pathname(str* base, str* file)
274 274
 	}
275 275
 	return res;
276 276
 }
277
+
278
+
279
+/**
280
+ * @brief search for occurence of needle in text
281
+ * @return pointer to start of needle in text or NULL if the needle
282
+ *	is not found
283
+ */
284
+char *str_search(str *text, str *needle)
285
+{
286
+    char *p;
287
+
288
+    if(text==NULL || text->s==NULL || needle==NULL || needle->s==NULL
289
+			|| text->len<needle->len)
290
+        return NULL;
291
+
292
+    for (p = text->s; p <= text->s + text->len - needle->len; p++) {
293
+        if (*p == *needle->s && memcmp(p, needle->s, needle->len)==0) {
294
+            return p;
295
+        }
296
+    }
297
+
298
+    return NULL;
299
+}
Browse code

core: In case of OOM, prevent crash

Marius Zbihlei authored on 14/01/2011 15:30:32
Showing 1 changed files
... ...
@@ -243,6 +243,7 @@ char* get_abs_pathname(str* base, str* file)
243 243
 		 * copy and use it as it is */
244 244
 		if ((res = pkg_malloc(file->len+1)) == NULL) {
245 245
 			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
246
+			return NULL;
246 247
 		}
247 248
 		memcpy(res, file->s, file->len);
248 249
 		res[file->len]=0;
Browse code

Merge remote branch 'origin/andrei/tcp_tls_changes'

Asynchronous TLS support and various TCP and io_wait fixes
(especially on BSDs).

* origin/andrei/tcp_tls_changes: (67 commits)
tls: fix partial write on write-wants-read queue flush
tls: more config vars displayed by the tls.options RPC
tls: fix trailing space in new modparams
tls: verbose debugging for SSL_ERROR_WANT_WRITE
tls: add lib64 to LIBS path
tls: doc - notes about enabling debugging
tls: added debug log level modparam
tls: modparams for ct write queue params
tls: doc - new & async related config options
tls: no tls_bio debugging by default
tls: change read_ahead, buffers and freelist defaults
tcp: verbose and safer close()
tls: enable PARTIAL_WRITE by default
tls: partial SSL_write support when reading (tls_read_f)
tls: don't report SSL protocol errors as bugs
tls: more consistent low memory checking
io_wait: kqueue: use the entire array during too many errors fallback
tcp: fix dispatching closed connections to tcp readers
tcp: more complete error messages
tls: support for partial encoding and reseting send_flags
tcp: support for tls partial encoding
tls: update & fix repeated send & delayed send
tcp: change tls send callback interface
tsend: s/char*/const char*/ in function params.
tls: very verbose debug logging
tls: fix tls_send out-of-mem on new connection
tcp: force eof after read if write side hangup
tcp: don't reset read_flags on RD_CONN_REPEAT_READ
tls: deal with internal openssl buffering
tls: fix initial state error handling
tcp: more consistent IO_FD_CLOSING usage
io_wait: kqueue: use a bigger array
io_wait: kqueue: handle ENOENT and more robust error handling
io_wait: fix kqueue io_wait_add & POLLIN
io_wait: don't update FD watched status on error
io_wait: fix kqueue and too many errors in changelist
io_wait: fix: check for EV_ERROR for kqueue()
tcp: fix fd passing bug
tls: config option for sending close notify alerts
tls: SSL_shutdown() only fully established connections
tls: ssl_flush() fix and re-worked error reporting
tls: tls.list rpc: fix timeout & ip display
tls: fix queue accounting
tls: rpc: tls.list and tls.options update
tls: config options for the internal queues
tls: fix wrong wbio usage
tls: fix empty files treatment
tls: added tls.options rpc
tls: migrated to the runtime cfg framework
db_flatstore: updated get_abs_pathname use
core: get_abs_pathname() uses now pkg_malloc()
core: str.h - s/NULL/0/
tls: doc - removed handshake_timeout and send_timeout
tls: removed handshake_timeout and send_timeout
tls: s/tls_cfg/tls_domains_cfg
tls: added tls_info rpc
tls: fix unregistered rpc commands
tls: async support (major tls core rewrite)
tls: tls_bio ctrl cmd support, fixes and debug
tls: clear text write queue implementation
tls: added a minimum overhead shm buffer queue
tls: safer destroy_cfg
tcp: new tls hooks interface and async tls changes
tls: added custom memory based bio
tcp: minor cleanups & spelling
tcp: tcp_send() split in 3 smaller functions
tcp: comments & new internal command

Andrei Pelinescu-Onciul authored on 16/08/2010 00:18:57
Showing 0 changed files
Browse code

core: get_abs_pathname() uses now pkg_malloc()

get_abs_pathname() used libc malloc() instead of pkg_malloc(),
making it difficult to know which free to use in fixups.

Andrei Pelinescu-Onciul authored on 28/05/2010 10:30:39
Showing 1 changed files
... ...
@@ -29,11 +29,10 @@
29 29
  */
30 30
 
31 31
 
32
-/*!
33
- * \file
34
- * \brief SIP-router core :: 
35
- * \ingroup core
36
- * Module: \ref core
32
+/** various utility functions.
33
+ * @file ut.c
34
+ * @ingroup core
35
+ * Module: @ref core
37 36
  */
38 37
 
39 38
 #include <sys/types.h>
... ...
@@ -215,6 +214,16 @@ unsigned int get_sys_version(int* major, int* minor, int* minor2)
215 214
 }
216 215
 
217 216
 
217
+
218
+/** transform a relative pathname into an absolute one.
219
+ * @param base  - base file, used to extract the absolute path prefix.
220
+ *                Might be NULL, in which case the path of the ser.cfg is
221
+ *                used.
222
+ * @param file  - file path to be transformed. If it's already absolute
223
+ *                (starts with '/') is left alone. If not the result will
224
+ *                be `dirname base`/file.
225
+ * @return  pkg allocated asciiz string or 0 on error.
226
+ */
218 227
 char* get_abs_pathname(str* base, str* file)
219 228
 {
220 229
 	str ser_cfg;
... ...
@@ -241,8 +250,8 @@ char* get_abs_pathname(str* base, str* file)
241 250
 	if (file->s[0] == '/') {
242 251
 		/* This is an absolute pathname, make a zero terminated
243 252
 		 * copy and use it as it is */
244
-		if ((res = malloc(file->len+1)) == NULL) {
245
-			ERR("get_abs_pathname: No memory left (malloc failed)\n");
253
+		if ((res = pkg_malloc(file->len+1)) == NULL) {
254
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
246 255
 		}
247 256
 		memcpy(res, file->s, file->len);
248 257
 		res[file->len]=0;
... ...
@@ -251,8 +260,8 @@ char* get_abs_pathname(str* base, str* file)
251 260
 		 * to the location of the base file
252 261
 		 */
253 262
 		/* Make a copy, function dirname may modify the string */
254
-		if ((buf = malloc(base->len+1)) == NULL) {
255
-			ERR("get_abs_pathname: No memory left (malloc failed)\n");
263
+		if ((buf = pkg_malloc(base->len+1)) == NULL) {
264
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
256 265
 			return NULL;
257 266
 		}
258 267
 		memcpy(buf, base->s, base->len);
... ...
@@ -260,16 +269,16 @@ char* get_abs_pathname(str* base, str* file)
260 269
 		dir = dirname(buf);
261 270
 		
262 271
 		len = strlen(dir);
263
-		if ((res = malloc(len + 1 + file->len + 1)) == NULL) {
264
-			ERR("get_abs_pathname: No memory left (malloc failed)\n");
265
-			free(buf);
272
+		if ((res = pkg_malloc(len + 1 + file->len + 1)) == NULL) {
273
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
274
+			pkg_free(buf);
266 275
 			return NULL;
267 276
 		}
268 277
 		memcpy(res, dir, len);
269 278
 		res[len] = '/';
270 279
 		memcpy(res + len + 1, file->s, file->len);
271 280
 		res[len + 1 + file->len] = '\0';
272
-		free(buf);
281
+		pkg_free(buf);
273 282
 	}
274 283
 	return res;
275 284
 }
Browse code

core: ut.* - BSD licence

Andrei Pelinescu-Onciul authored on 16/03/2010 18:33:44
Showing 1 changed files
... ...
@@ -5,35 +5,25 @@
5 5
  *
6 6
  * Copyright (C) 2001-2003 FhG Fokus
7 7
  *
8
- * This file is part of ser, a free SIP server.
8
+ * Permission to use, copy, modify, and distribute this software for any
9
+ * purpose with or without fee is hereby granted, provided that the above
10
+ * copyright notice and this permission notice appear in all copies.
9 11
  *
10
- * ser is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version
14
- *
15
- * For a license to use the ser software under conditions
16
- * other than those described here, or to purchase support for this
17
- * software, please contact iptel.org by e-mail at the following addresses:
18
- *    info@iptel.org
19
- *
20
- * ser is distributed in the hope that it will be useful,
21
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
- * GNU General Public License for more details.
24
- *
25
- * You should have received a copy of the GNU General Public License 
26
- * along with this program; if not, write to the Free Software 
27
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
12
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 19
  *
29 20
  */
30 21
 
31 22
 
32
-/*!
33
- * \file
34
- * \brief SIP-router core :: 
35
- * \ingroup core
36
- * Module: \ref core
23
+/** various general purpose/helper functions.
24
+ * @file
25
+ * @ingroup core
26
+ * Module: @ref core
37 27
  */
38 28
 
39 29
 #include <sys/types.h>
Browse code

Merge remote branch 'origin/sr_3.0'

* origin/sr_3.0:
core: new param to give outbut buffer size
core: use one buffer for int2str
core: use dlflags to load modules
uac(k): use header types for detection
uac(k): proper test for send failure
uac(k): set type for tm callback
modules/mediaproxy: take boundary string from Content-Type header.
core: stats events cbs are called only if USE_CORE_STATS is defined
update drp_reqs statistics
update drp_rpls statistics
update fwd_rpls statistics
update err_reqs statistics
update err_rpls statistics
update bad_URIs statistics
update bad_msg_hdr statistics
core: update fwd_reqs stat
kex: support to update core stats via core events
core: added new event SREV_CORE_STATS

Andrei Pelinescu-Onciul authored on 03/02/2010 22:32:55
Showing 0 changed files
Browse code

core: use one buffer for int2str

- static declaration inside ut.h function results in hard copy to many
places, affecting acc detection of int to str conversions in buffer
- reported by Alex Balashov
(cherry picked from commit 229496c7170bcc85f517a4985f7ab4bad553c8d3)

Daniel-Constantin Mierla authored on 02/02/2010 12:23:03 • Andrei Pelinescu-Onciul committed on 03/02/2010 21:50:36
Showing 1 changed files
... ...
@@ -42,6 +42,9 @@
42 42
 #include "mem/mem.h"
43 43
 #include "globals.h"
44 44
 
45
+/* global buffer for ut.h int2str() */
46
+char ut_buf_int2str[INT2STR_MAX_LEN];
47
+
45 48
 
46 49
 /* converts a username into uid:gid,
47 50
  * returns -1 on error & 0 on success */
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
... ...
@@ -29,6 +29,13 @@
29 29
  */
30 30
 
31 31
 
32
+/*!
33
+ * \file
34
+ * \brief SIP-router core :: 
35
+ * \ingroup core
36
+ * Module: \ref core
37
+ */
38
+
32 39
 #include <sys/types.h>
33 40
 #include <pwd.h>
34 41
 #include <grp.h>
Browse code

kamailio compatibility, add str_strcmp and str_casecmp functions

Henning Westerholt authored on 08/12/2008 17:13:57
Showing 1 changed files
... ...
@@ -28,7 +28,7 @@
28 28
  *
29 29
  */
30 30
 
31
-#include <string.h>
31
+
32 32
 #include <sys/types.h>
33 33
 #include <pwd.h>
34 34
 #include <grp.h>
Browse code

- fixed indentation

Jan Janak authored on 31/05/2008 17:50:34
Showing 1 changed files
... ...
@@ -88,7 +88,7 @@ int group2gid(int* gid, char* group)
88 88
 		}
89 89
 		return 0;
90 90
 	}
91
-error:
91
+ error:
92 92
 	return -1;
93 93
 }
94 94
 
... ...
@@ -162,8 +162,8 @@ char* as_asciiz(str* s)
162 162
 
163 163
     r = (char*)pkg_malloc(s->len + 1);
164 164
     if (!r) {
165
-	ERR("Out of memory\n");
166
-	return 0;
165
+		ERR("Out of memory\n");
166
+		return 0;
167 167
     }
168 168
     memcpy(r, s->s, s->len);
169 169
     r[s->len] = '\0';
Browse code

- replaced strndup() in get_abs_pathname() since strndup is a GNU extensions not present in non glibc based OSes

Andrei Pelinescu-Onciul authored on 02/03/2008 15:11:59
Showing 1 changed files
... ...
@@ -28,7 +28,6 @@
28 28
  *
29 29
  */
30 30
 
31
-#define _GNU_SOURCE 1 /* strndup in get_abs_pathname */
32 31
 #include <string.h>
33 32
 #include <sys/types.h>
34 33
 #include <pwd.h>
... ...
@@ -232,18 +231,22 @@ char* get_abs_pathname(str* base, str* file)
232 231
 	if (file->s[0] == '/') {
233 232
 		/* This is an absolute pathname, make a zero terminated
234 233
 		 * copy and use it as it is */
235
-		if ((res = strndup(file->s, file->len)) == NULL) {
236
-			ERR("get_abs_pathname: No memory left (strndup failed)\n");
234
+		if ((res = malloc(file->len+1)) == NULL) {
235
+			ERR("get_abs_pathname: No memory left (malloc failed)\n");
237 236
 		}
237
+		memcpy(res, file->s, file->len);
238
+		res[file->len]=0;
238 239
 	} else {
239 240
 		/* This is not an absolute pathname, make it relative
240 241
 		 * to the location of the base file
241 242
 		 */
242 243
 		/* Make a copy, function dirname may modify the string */
243
-		if ((buf = strndup(base->s, base->len)) == NULL) {
244
-			ERR("get_abs_pathname: No memory left (strdup failed)\n");
244
+		if ((buf = malloc(base->len+1)) == NULL) {
245
+			ERR("get_abs_pathname: No memory left (malloc failed)\n");
245 246
 			return NULL;
246 247
 		}
248
+		memcpy(buf, base->s, base->len);
249
+		buf[base->len]=0;
247 250
 		dir = dirname(buf);
248 251
 		
249 252
 		len = strlen(dir);
Browse code

"#include <libgen.h>" is moved to ut.c because of dirname() function

Miklos Tirpak authored on 11/02/2008 10:11:00
Showing 1 changed files
... ...
@@ -36,6 +36,7 @@
36 36
 #include <stdlib.h>
37 37
 #include <time.h>
38 38
 #include <sys/utsname.h> /* uname() */
39
+#include <libgen.h>
39 40
 
40 41
 
41 42
 #include "ut.h"
Browse code

- Make sure that the global cfg_file variable always contains full absolute pathname. - Added get_abs_pathname function that can be used to convert relative pathnames to absolutes with using the location of cfg_file (or another file) as reference.

Jan Janak authored on 08/02/2008 05:37:44
Showing 1 changed files
... ...
@@ -28,7 +28,7 @@
28 28
  *
29 29
  */
30 30
 
31
-
31
+#define _GNU_SOURCE 1 /* strndup in get_abs_pathname */
32 32
 #include <string.h>
33 33
 #include <sys/types.h>
34 34
 #include <pwd.h>
... ...
@@ -40,6 +40,7 @@
40 40
 
41 41
 #include "ut.h"
42 42
 #include "mem/mem.h"
43
+#include "globals.h"
43 44
 
44 45
 
45 46
 /* converts a username into uid:gid,
... ...
@@ -204,4 +205,57 @@ unsigned int get_sys_version(int* major, int* minor, int* minor2)
204 205
 }
205 206
 
206 207
 
207
-
208
+char* get_abs_pathname(str* base, str* file)
209
+{
210
+	str ser_cfg;
211
+	char* buf, *dir, *res;
212
+	int len;
213
+  	
214
+	if (base == NULL) {
215
+		ser_cfg.s = cfg_file;
216
+		ser_cfg.len = strlen(cfg_file);
217
+		base = &ser_cfg;
218
+	}
219
+	
220
+	if (!base->s || base->len <= 0 || base->s[0] != '/') {
221
+		BUG("get_abs_pathname: Base file must be absolute pathname: "
222
+			"'%.*s'\n", STR_FMT(base));
223
+		return NULL;
224
+	}
225
+	
226
+	if (!file || !file->s || file->len <= 0) {
227
+		BUG("get_abs_pathname: Invalid 'file' parameter\n");
228
+		return NULL;
229
+	}
230
+	
231
+	if (file->s[0] == '/') {
232
+		/* This is an absolute pathname, make a zero terminated
233
+		 * copy and use it as it is */
234
+		if ((res = strndup(file->s, file->len)) == NULL) {
235
+			ERR("get_abs_pathname: No memory left (strndup failed)\n");
236
+		}
237
+	} else {
238
+		/* This is not an absolute pathname, make it relative
239
+		 * to the location of the base file
240
+		 */
241
+		/* Make a copy, function dirname may modify the string */
242
+		if ((buf = strndup(base->s, base->len)) == NULL) {
243
+			ERR("get_abs_pathname: No memory left (strdup failed)\n");
244
+			return NULL;
245
+		}
246
+		dir = dirname(buf);
247
+		
248
+		len = strlen(dir);
249
+		if ((res = malloc(len + 1 + file->len + 1)) == NULL) {
250
+			ERR("get_abs_pathname: No memory left (malloc failed)\n");
251
+			free(buf);
252
+			return NULL;
253
+		}
254
+		memcpy(res, dir, len);
255
+		res[len] = '/';
256
+		memcpy(res + len + 1, file->s, file->len);
257
+		res[len + 1 + file->len] = '\0';
258
+		free(buf);
259
+	}
260
+	return res;
261
+}
Browse code

- _timegm resets the information about DST in struct tm structure because the date and time in that structure is in UTC. - added conversion functions that can convert time_t values between local timezones and utc.

Jan Janak authored on 21/06/2007 11:38:42
Showing 1 changed files
... ...
@@ -101,7 +101,8 @@ time_t _timegm(struct tm* t)
101 101
 {
102 102
 	time_t tl, tb;
103 103
 	struct tm* tg;
104
-	
104
+
105
+	t->tm_isdst = 0;
105 106
 	tl = mktime(t);
106 107
 	if (tl == -1) {
107 108
 		t->tm_hour--;
... ...
@@ -127,6 +128,29 @@ time_t _timegm(struct tm* t)