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,186 +0,0 @@
1
-/*
2
- * Copyright (C) 2005-2006 iptelorg GmbH
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version
10
- *
11
- * Kamailio is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
- *
20
- */
21
-
22
-/*!
23
- * \file
24
- * \brief Kamailio core :: static buffer for select results (mma)
25
- *	            each process owns a separate space
26
- *	            each request starts using the buffer from the start
27
- * \ingroup core
28
- * Module: \ref core
29
- */
30
-
31
-#include <stdio.h>
32
-#include <stdlib.h>
33
-#include <string.h>
34
-#include <unistd.h>
35
-#include <ctype.h>
36
-
37
-#include "dprint.h"
38
-#include "mem/mem.h"
39
-#include "str.h"
40
-#include "ut.h"
41
-
42
-/*
43
- * Placeholder for the buffer
44
- *
45
- * two buffers are actually used to cover the different size requests
46
- * assuming that resize can move the result to newly allocated space
47
- * and comparing two selects from the script could require two static buffers
48
- *
49
- * if more static buffers need to be valid at the same time change
50
- * the following constant
51
- */
52
-
53
-#define MAX_BUFFERS 2
54
-#define BUFFER_GRANULARITY 256
55
-
56
-typedef struct stat_buffer_ {
57
-	char *b;
58
-	int size;
59
-	int offset;
60
-} stat_buffer_t;
61
-
62
-static stat_buffer_t buffer[MAX_BUFFERS];
63
-static int active_buffer=-1;
64
-
65
-#define ALLOC_SIZE(req_size) (((req_size/BUFFER_GRANULARITY)+1)*BUFFER_GRANULARITY)
66
-
67
-static int allocate_buffer(int req_size) {
68
-	void *b;
69
-	int size=ALLOC_SIZE(req_size);
70
-	
71
-	if (buffer[active_buffer].b == NULL) {
72
-		if ((buffer[active_buffer].b=pkg_malloc(size))==NULL)
73
-			return 0;
74
-		buffer[active_buffer].size=size;
75
-		buffer[active_buffer].offset=0;
76
-		return 1;
77
-	}
78
-	
79
-	active_buffer = (active_buffer?active_buffer:MAX_BUFFERS)-1;
80
-	if (buffer[active_buffer].size >= req_size) {
81
-		buffer[active_buffer].offset = 0;
82
-		return 1;
83
-	}
84
-	
85
-	if ((b=pkg_realloc(buffer[active_buffer].b,size))) {
86
-		buffer[active_buffer].b=b;
87
-		buffer[active_buffer].size=size;
88
-		buffer[active_buffer].offset=0;
89
-		return 1;
90
-	}
91
-	
92
-	return 0;
93
-}
94
-
95
-/*
96
- * Request for space from buffer
97
- *
98
- * Returns:  NULL  memory allocation failure (no more space)
99
- *           pointer to the space on success
100
- */
101
-
102
-char* get_static_buffer(int req_size) {
103
-	char *p = NULL;
104
-
105
-#ifdef EXTRA_DEBUG
106
-	if ((active_buffer < 0) || (active_buffer > MAX_BUFFERS-1)) {
107
-		LM_CRIT("buffers have not been initialized yet. "
108
-			"Call reset_static_buffer() before executing "
109
-			"a route block.\n");
110
-		abort();
111
-	}
112
-#endif
113
-	if ((buffer[active_buffer].size >= buffer[active_buffer].offset + req_size)
114
-			|| (allocate_buffer(req_size))) {
115
-		/* enough space in current buffer or allocation successful */
116
-		p = buffer[active_buffer].b+buffer[active_buffer].offset;
117
-		buffer[active_buffer].offset += req_size;	
118
-		return p;
119
-	}
120
-	return NULL;
121
-}
122
-
123
-/* Internal function - called before request is going to be processed
124
- *
125
- * Reset offset to unused space
126
- */
127
-
128
-int reset_static_buffer(void) {
129
-	int i;
130
-
131
-	if (active_buffer == -1) {
132
-		memset(buffer, 0, sizeof(buffer));
133
-	} else {
134
-		for (i=0; i<MAX_BUFFERS; i++)
135
-			buffer[i].offset=0;
136
-	}
137
-	active_buffer=0;
138
-	return 0;
139
-}
140
-
141
-int str_to_static_buffer(str* res, str* s)
142
-{
143
-	res->s = get_static_buffer(s->len);
144
-	if (!res->s) return -1;
145
-	memcpy(res->s, s->s, s->len);
146
-	res->len = s->len;
147
-	return 0;
148
-}
149
-
150
-int int_to_static_buffer(str* res, int val)
151
-{
152
-	char *c;
153
-	c = int2str(abs(val), &res->len);
154
-	res->s = get_static_buffer(res->len+((val<0)?1:0));
155
-	if (!res->s) return -1;
156
-	if (val < 0) {
157
-		res->s[0] = '-';	
158
-		memcpy(res->s+1, c, res->len);
159
-		res->len++;
160
-	}
161
-	else {
162
-		memcpy(res->s, c, res->len);
163
-	}
164
-	return 0;
165
-}
166
-
167
-int uint_to_static_buffer(str* res, unsigned int val)
168
-{
169
-	char *c;
170
-	c = int2str(val, &res->len);
171
-	res->s = get_static_buffer(res->len);
172
-	if (!res->s) return -1;
173
-	memcpy(res->s, c, res->len);
174
-	return 0;
175
-}
176
-
177
-int uint_to_static_buffer_ex(str* res, unsigned int val, int base, int pad)
178
-{
179
-	char *c;
180
-	c = int2str_base_0pad(val, &res->len, base, pad); 
181
-	res->s = get_static_buffer(res->len);
182
-	if (!res->s) return -1;
183
-	memcpy(res->s, c, res->len);
184
-	return 0;
185
-}
186
-
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
... ...
@@ -8,12 +8,7 @@
8 8
  * the Free Software Foundation; either version 2 of the License, or
9 9
  * (at your option) any later version
10 10
  *
11
- * For a license to use the Kamailio software under conditions
12
- * other than those described here, or to purchase support for this
13
- * software, please contact iptel.org by e-mail at the following addresses:
14
- *    info@iptel.org
15
- *
16
- * ser is distributed in the hope that it will be useful,
11
+ * Kamailio is distributed in the hope that it will be useful,
17 12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 14
  * GNU General Public License for more details.
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,16 +1,14 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2005-2006 iptelorg GmbH
5 3
  *
6
- * This file is part of ser, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
7 5
  *
8
- * ser is free software; you can redistribute it and/or modify
6
+ * Kamailio is free software; you can redistribute it and/or modify
9 7
  * it under the terms of the GNU General Public License as published by
10 8
  * the Free Software Foundation; either version 2 of the License, or
11 9
  * (at your option) any later version
12 10
  *
13
- * For a license to use the ser software under conditions
11
+ * For a license to use the Kamailio software under conditions
14 12
  * other than those described here, or to purchase support for this
15 13
  * software, please contact iptel.org by e-mail at the following addresses:
16 14
  *    info@iptel.org
... ...
@@ -24,17 +22,13 @@
24 22
  * along with this program; if not, write to the Free Software
25 23
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 24
  *
27
- * History:
28
- * --------
29
- *	2006-06-16  static buffer for select results (mma)
30
- *	            each process owns a separate space
31
- *	            each request starts using the buffer from the start
32
- *
33 25
  */
34 26
 
35 27
 /*!
36 28
  * \file
37
- * \brief SIP-router core :: 
29
+ * \brief Kamailio core :: static buffer for select results (mma)
30
+ *	            each process owns a separate space
31
+ *	            each request starts using the buffer from the start
38 32
  * \ingroup core
39 33
  * Module: \ref core
40 34
  */
Browse code

select_buf.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 04/10/2014 01:26:28
Showing 1 changed files
... ...
@@ -115,7 +115,7 @@ char* get_static_buffer(int req_size) {
115 115
 
116 116
 #ifdef EXTRA_DEBUG
117 117
 	if ((active_buffer < 0) || (active_buffer > MAX_BUFFERS-1)) {
118
-		LOG(L_CRIT, "BUG: buffers have not been initialized yet. "
118
+		LM_CRIT("buffers have not been initialized yet. "
119 119
 			"Call reset_static_buffer() before executing "
120 120
 			"a route block.\n");
121 121
 		abort();
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
... ...
@@ -22,7 +22,7 @@
22 22
  *
23 23
  * You should have received a copy of the GNU General Public License
24 24
  * along with this program; if not, write to the Free Software
25
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 26
  *
27 27
  * History:
28 28
  * --------
Browse code

core: fixed several clang compiler warnings

Daniel-Constantin Mierla authored on 06/12/2013 16:16:25
Showing 1 changed files
... ...
@@ -162,7 +162,7 @@ int int_to_static_buffer(str* res, int val)
162 162
 {
163 163
 	char *c;
164 164
 	c = int2str(abs(val), &res->len);
165
-	res->s = get_static_buffer(res->len+(val<0)?1:0);
165
+	res->s = get_static_buffer(res->len+((val<0)?1:0));
166 166
 	if (!res->s) return -1;
167 167
 	if (val < 0) {
168 168
 		res->s[0] = '-';	
Browse code

master:core Continue cleaning erroneous definition of functions with no arguments

After testing with gcc 4.5.2, seems that not prototyping function cases extra assembler code regardles of optimization level

Marius Zbihlei authored on 04/04/2012 09:51:50
Showing 1 changed files
... ...
@@ -136,7 +136,7 @@ char* get_static_buffer(int req_size) {
136 136
  * Reset offset to unused space
137 137
  */
138 138
 
139
-int reset_static_buffer() {
139
+int reset_static_buffer(void) {
140 140
 	int i;
141 141
 
142 142
 	if (active_buffer == -1) {
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
... ...
@@ -32,6 +32,13 @@
32 32
  *
33 33
  */
34 34
 
35
+/*!
36
+ * \file
37
+ * \brief SIP-router core :: 
38
+ * \ingroup core
39
+ * Module: \ref core
40
+ */
41
+
35 42
 #include <stdio.h>
36 43
 #include <stdlib.h>
37 44
 #include <string.h>
Browse code

Safety check added to verify whether the static buffers have been initialized.

Miklos Tirpak authored on 07/04/2009 09:07:48
Showing 1 changed files
... ...
@@ -105,6 +105,15 @@ static int allocate_buffer(int req_size) {
105 105
 
106 106
 char* get_static_buffer(int req_size) {
107 107
 	char *p = NULL;
108
+
109
+#ifdef EXTRA_DEBUG
110
+	if ((active_buffer < 0) || (active_buffer > MAX_BUFFERS-1)) {
111
+		LOG(L_CRIT, "BUG: buffers have not been initialized yet. "
112
+			"Call reset_static_buffer() before executing "
113
+			"a route block.\n");
114
+		abort();
115
+	}
116
+#endif
108 117
 	if ((buffer[active_buffer].size >= buffer[active_buffer].offset + req_size)
109 118
 			|| (allocate_buffer(req_size))) {
110 119
 		/* enough space in current buffer or allocation successful */
Browse code

fixes SER-345 - patch accepted

Michal Matyska authored on 07/01/2008 12:45:30
Showing 1 changed files
... ...
@@ -68,7 +68,7 @@ static int active_buffer=-1;
68 68
 
69 69
 #define ALLOC_SIZE(req_size) (((req_size/BUFFER_GRANULARITY)+1)*BUFFER_GRANULARITY)
70 70
 
71
-int allocate_buffer(int req_size) {
71
+static int allocate_buffer(int req_size) {
72 72
 	void *b;
73 73
 	int size=ALLOC_SIZE(req_size);
74 74
 	
Browse code

- added (uint|int|str)_to_static_buffer functions to select_buffer - fixed minor bug in struct msg_start where is not known start of first line when empty lines preceed (sip_msg.buff points before them), so added line field holding correct position of first_line, fixed usage in textops and xmlrpc modules - added new select_core selects to resolve SER-158 - added new tm module select to resolve SER-158

Tomas Mandys authored on 18/02/2007 14:05:44
Showing 1 changed files
... ...
@@ -40,6 +40,8 @@
40 40
 
41 41
 #include "dprint.h"
42 42
 #include "mem/mem.h"
43
+#include "str.h"
44
+#include "ut.h"
43 45
 
44 46
 /*
45 47
  * Placeholder for the buffer
... ...
@@ -130,3 +132,50 @@ int reset_static_buffer() {
130 132
 	active_buffer=0;
131 133
 	return 0;
132 134
 }
135
+
136
+int str_to_static_buffer(str* res, str* s)
137
+{
138
+	res->s = get_static_buffer(s->len);
139
+	if (!res->s) return -1;
140
+	memcpy(res->s, s->s, s->len);
141
+	res->len = s->len;
142
+	return 0;
143
+}
144
+
145
+int int_to_static_buffer(str* res, int val)
146
+{
147
+	char *c;
148
+	c = int2str(abs(val), &res->len);
149
+	res->s = get_static_buffer(res->len+(val<0)?1:0);
150
+	if (!res->s) return -1;
151
+	if (val < 0) {
152
+		res->s[0] = '-';	
153
+		memcpy(res->s+1, c, res->len);
154
+		res->len++;
155
+	}
156
+	else {
157
+		memcpy(res->s, c, res->len);
158
+	}
159
+	return 0;
160
+}
161
+
162
+int uint_to_static_buffer(str* res, unsigned int val)
163
+{
164
+	char *c;
165
+	c = int2str(val, &res->len);
166
+	res->s = get_static_buffer(res->len);
167
+	if (!res->s) return -1;
168
+	memcpy(res->s, c, res->len);
169
+	return 0;
170
+}
171
+
172
+int uint_to_static_buffer_ex(str* res, unsigned int val, int base, int pad)
173
+{
174
+	char *c;
175
+	c = int2str_base_0pad(val, &res->len, base, pad); 
176
+	res->s = get_static_buffer(res->len);
177
+	if (!res->s) return -1;
178
+	memcpy(res->s, c, res->len);
179
+	return 0;
180
+}
181
+
Browse code

static buffer realloc correction

Michal Matyska authored on 10/08/2006 10:49:11
Showing 1 changed files
... ...
@@ -67,6 +67,7 @@ static int active_buffer=-1;
67 67
 #define ALLOC_SIZE(req_size) (((req_size/BUFFER_GRANULARITY)+1)*BUFFER_GRANULARITY)
68 68
 
69 69
 int allocate_buffer(int req_size) {
70
+	void *b;
70 71
 	int size=ALLOC_SIZE(req_size);
71 72
 	
72 73
 	if (buffer[active_buffer].b == NULL) {
... ...
@@ -83,7 +84,8 @@ int allocate_buffer(int req_size) {
83 84
 		return 1;
84 85
 	}
85 86
 	
86
-	if (pkg_realloc(buffer[active_buffer].b,size)) {
87
+	if ((b=pkg_realloc(buffer[active_buffer].b,size))) {
88
+		buffer[active_buffer].b=b;
87 89
 		buffer[active_buffer].size=size;
88 90
 		buffer[active_buffer].offset=0;
89 91
 		return 1;
Browse code

Added select_buf.[ch]

Michal Matyska authored on 21/06/2006 21:08:48
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,130 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2005-2006 iptelorg GmbH
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * ser is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ *
27
+ * History:
28
+ * --------
29
+ *	2006-06-16  static buffer for select results (mma)
30
+ *	            each process owns a separate space
31
+ *	            each request starts using the buffer from the start
32
+ *
33
+ */
34
+
35
+#include <stdio.h>
36
+#include <stdlib.h>
37
+#include <string.h>
38
+#include <unistd.h>
39
+#include <ctype.h>
40
+
41
+#include "dprint.h"
42
+#include "mem/mem.h"
43
+
44
+/*
45
+ * Placeholder for the buffer
46
+ *
47
+ * two buffers are actually used to cover the different size requests
48
+ * assuming that resize can move the result to newly allocated space
49
+ * and comparing two selects from the script could require two static buffers
50
+ *
51
+ * if more static buffers need to be valid at the same time change
52
+ * the following constant
53
+ */
54
+
55
+#define MAX_BUFFERS 2
56
+#define BUFFER_GRANULARITY 256
57
+
58
+typedef struct stat_buffer_ {
59
+	char *b;
60
+	int size;
61
+	int offset;
62
+} stat_buffer_t;
63
+
64
+static stat_buffer_t buffer[MAX_BUFFERS];
65
+static int active_buffer=-1;
66
+
67
+#define ALLOC_SIZE(req_size) (((req_size/BUFFER_GRANULARITY)+1)*BUFFER_GRANULARITY)
68
+
69
+int allocate_buffer(int req_size) {
70
+	int size=ALLOC_SIZE(req_size);
71
+	
72
+	if (buffer[active_buffer].b == NULL) {
73
+		if ((buffer[active_buffer].b=pkg_malloc(size))==NULL)
74
+			return 0;
75
+		buffer[active_buffer].size=size;
76
+		buffer[active_buffer].offset=0;
77
+		return 1;
78
+	}
79
+	
80
+	active_buffer = (active_buffer?active_buffer:MAX_BUFFERS)-1;
81
+	if (buffer[active_buffer].size >= req_size) {
82
+		buffer[active_buffer].offset = 0;
83
+		return 1;
84
+	}
85
+	
86
+	if (pkg_realloc(buffer[active_buffer].b,size)) {
87
+		buffer[active_buffer].size=size;
88
+		buffer[active_buffer].offset=0;
89
+		return 1;
90
+	}
91
+	
92
+	return 0;
93
+}
94
+
95
+/*
96
+ * Request for space from buffer
97
+ *
98
+ * Returns:  NULL  memory allocation failure (no more space)
99
+ *           pointer to the space on success
100
+ */
101
+
102
+char* get_static_buffer(int req_size) {
103
+	char *p = NULL;
104
+	if ((buffer[active_buffer].size >= buffer[active_buffer].offset + req_size)
105
+			|| (allocate_buffer(req_size))) {
106
+		/* enough space in current buffer or allocation successful */
107
+		p = buffer[active_buffer].b+buffer[active_buffer].offset;
108
+		buffer[active_buffer].offset += req_size;	
109
+		return p;
110
+	}
111
+	return NULL;
112
+}
113
+
114
+/* Internal function - called before request is going to be processed
115
+ *
116
+ * Reset offset to unused space
117
+ */
118
+
119
+int reset_static_buffer() {
120
+	int i;
121
+
122
+	if (active_buffer == -1) {
123
+		memset(buffer, 0, sizeof(buffer));
124
+	} else {
125
+		for (i=0; i<MAX_BUFFERS; i++)
126
+			buffer[i].offset=0;
127
+	}
128
+	active_buffer=0;
129
+	return 0;
130
+}