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,285 +0,0 @@
1
-/*
2
- * $Id: tree.c 4518 2008-07-28 15:39:28Z henningw $
3
- *
4
- * Copyright (C) 2006 Voice Sistem SRL
5
- *
6
- * This file is part of Kamailio, a free SIP server.
7
- *
8
- * Kamailio 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
- * Kamailio is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
- *
22
- *
23
- * History:
24
- * ---------
25
- *  2006-09-08  first version (bogdan)
26
- */
27
-
28
-/*!
29
- * \file 
30
- * \brief MI :: Tree 
31
- * \ingroup mi
32
- */
33
-
34
-#include <string.h>
35
-#include <stdio.h>
36
-#include <errno.h>
37
-#include "../../dprint.h"
38
-#include "mi_mem.h"
39
-#include "tree.h"
40
-#include "fmt.h"
41
-
42
-
43
-static int use_shm = 0;
44
-
45
-struct mi_root *init_mi_tree(unsigned int code, char *reason, int reason_len)
46
-{
47
-	struct mi_root *root;
48
-
49
-	if (use_shm)
50
-		root = (struct mi_root *)shm_malloc(sizeof(struct mi_root));
51
-	else
52
-		root = (struct mi_root *)mi_malloc(sizeof(struct mi_root));
53
-	if (!root) {
54
-		LM_ERR("no more pkg mem\n");
55
-		return NULL;
56
-	}
57
-
58
-	memset(root,0,sizeof(struct mi_root));
59
-	root->node.next = root->node.last = &root->node;
60
-
61
-	if (reason && reason_len) {
62
-		root->reason.s = reason;
63
-		root->reason.len = reason_len;
64
-	}
65
-	root->code = code;
66
-
67
-	return root;
68
-}
69
-
70
-
71
-static void free_mi_node(struct mi_node *parent)
72
-{
73
-	struct mi_node *p, *q;
74
-
75
-	for(p = parent->kids ; p ; ){
76
-		q = p;
77
-		p = p->next;
78
-		free_mi_node(q);
79
-	}
80
-
81
-	if (use_shm) {
82
-		shm_free(parent);
83
-	} else {
84
-		del_mi_attr_list(parent);
85
-		mi_free(parent);
86
-	}
87
-}
88
-
89
-void free_mi_tree(struct mi_root *parent)
90
-{
91
-	struct mi_node *p, *q;
92
-
93
-	for(p = parent->node.kids ; p ; ){
94
-		q = p;
95
-		p = p->next;
96
-		free_mi_node(q);
97
-	}
98
-
99
-	if (use_shm)
100
-		shm_free(parent);
101
-	else
102
-		mi_free(parent);
103
-}
104
-
105
-
106
-static inline struct mi_node *create_mi_node(char *name, int name_len,
107
-									char *value, int value_len, int flags)
108
-{
109
-	struct mi_node *new;
110
-	int size_mem;
111
-	int name_pos;
112
-	int value_pos;
113
-
114
-	if (!name) name_len=0;
115
-	if (!name_len) name=0;
116
-	if (!value) value_len=0;
117
-	if (!value_len) value=0;
118
-
119
-	if (!name && !value)
120
-		return NULL;
121
-
122
-	size_mem = sizeof(struct mi_node);
123
-	value_pos = name_pos = 0;
124
-
125
-	if (name && (flags & MI_DUP_NAME)){
126
-		name_pos = size_mem;
127
-		size_mem += name_len;
128
-	}
129
-	if (value && (flags & MI_DUP_VALUE)){
130
-		value_pos = size_mem;
131
-		size_mem += value_len;
132
-	}
133
-
134
-	if (use_shm)
135
-		new = (struct mi_node *)shm_malloc(size_mem);
136
-	else
137
-		new = (struct mi_node *)mi_malloc(size_mem);
138
-	if(!new) {
139
-		LM_ERR("no more pkg mem\n");
140
-		return NULL;
141
-	}
142
-	memset(new,0,size_mem);
143
-
144
-	if (name) {
145
-		new->name.len = name_len;
146
-		if(flags & MI_DUP_NAME){
147
-			new->name.s = ((char *)new) + name_pos;
148
-			strncpy(new->name.s, name, name_len);
149
-		} else{
150
-			new->name.s = name;
151
-		}
152
-	}
153
-
154
-	if (value) {
155
-		new->value.len = value_len;
156
-		if(flags & MI_DUP_VALUE){
157
-			new->value.s = ((char *)new) + value_pos;
158
-			strncpy(new->value.s, value, value_len);
159
-		}else{
160
-			new->value.s = value;
161
-		}
162
-	}
163
-	new->last = new;
164
-
165
-	return new;
166
-}
167
-
168
-
169
-static inline struct mi_node *add_next(struct mi_node *brother,
170
-			char *name, int name_len, char *value, int value_len, int flags)
171
-{
172
-	struct mi_node *new;
173
-
174
-	if(!brother)
175
-		return NULL;
176
-	
177
-	new = create_mi_node(name, name_len, value, value_len, flags);
178
-	if(!new)
179
-		return NULL;
180
-
181
-	brother->last->next = new;
182
-	brother->last = new;
183
-
184
-	return new;
185
-}
186
-
187
-
188
-struct mi_node *add_mi_node_sibling( struct mi_node *brother, int flags,
189
-						char *name, int name_len, char *value, int value_len)
190
-{
191
-	return add_next(brother, name, name_len, value, value_len, flags);
192
-}
193
-
194
-
195
-struct mi_node *addf_mi_node_sibling(struct mi_node *brother, int flags,
196
-							char *name, int name_len, char *fmt_val, ...)
197
-{
198
-	va_list ap;
199
-	char *p;
200
-	int  len;
201
-
202
-	va_start(ap, fmt_val);
203
-	p = mi_print_fmt( fmt_val, ap, &len);
204
-	va_end(ap);
205
-	if (p==NULL)
206
-		return 0;
207
-	return add_mi_node_sibling( brother, flags|MI_DUP_VALUE,
208
-		name, name_len, p, len);
209
-}
210
-
211
-
212
-struct mi_node *add_mi_node_child( struct mi_node *parent, int flags,
213
-						char *name, int name_len, char *value, int value_len)
214
-{
215
-	if(parent->kids){
216
-		return add_next(parent->kids, name, name_len, value, value_len, flags);
217
-	}else{
218
-		parent->kids = create_mi_node(name, name_len, value, value_len, flags);
219
-		return parent->kids;
220
-	}
221
-}
222
-
223
-
224
-struct mi_node *addf_mi_node_child(struct mi_node *parent, int flags,
225
-							char *name, int name_len, char *fmt_val, ...)
226
-{
227
-	va_list ap;
228
-	char *p;
229
-	int  len;
230
-
231
-	va_start(ap, fmt_val);
232
-	p = mi_print_fmt( fmt_val, ap, &len);
233
-	va_end(ap);
234
-	if (p==NULL)
235
-		return 0;
236
-	return add_mi_node_child( parent, flags|MI_DUP_VALUE,
237
-		name, name_len, p, len);
238
-}
239
-
240
-
241
-static int clone_mi_node(struct mi_node *org, struct mi_node *parent)
242
-{
243
-	struct mi_node *p, *q;
244
-
245
-	for(p = org->kids ; p ; p=p->next){
246
-		q = add_mi_node_child( parent, MI_DUP_VALUE|MI_DUP_NAME,
247
-			p->name.s, p->name.len, p->value.s, p->value.len);
248
-		if (q==NULL)
249
-			return -1;
250
-		if (clone_mi_node( p, q)!=0)
251
-			return -1;
252
-	}
253
-	return 0;
254
-}
255
-
256
-
257
-struct mi_root* clone_mi_tree(struct mi_root *org, int shm)
258
-{
259
-	struct mi_root *root;
260
-
261
-	use_shm = shm?1:0;
262
-
263
-	root = init_mi_tree( org->code, org->reason.s, org->reason.len);
264
-	if (root==NULL)
265
-		goto done;
266
-
267
-	if (clone_mi_node( &(org->node), &(root->node) )!=0 ) {
268
-		free_mi_tree(root);
269
-		root = NULL;
270
-		goto done;
271
-	}
272
-
273
-done:
274
-	use_shm=0;
275
-	return root;
276
-}
277
-
278
-
279
-
280
-void free_shm_mi_tree(struct mi_root *parent)
281
-{
282
-	use_shm = 1;
283
-	free_mi_tree(parent);
284
-	use_shm = 0;
285
-}
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
... ...
@@ -17,7 +17,7 @@
17 17
  *
18 18
  * You should have received a copy of the GNU General Public License
19 19
  * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 21
  *
22 22
  *
23 23
  * History:
Browse code

lib/kmi: option to build it with system malloc

- MI lib can be built independently of core with system malloc for pkg
memory (see Makefile)

Daniel-Constantin Mierla authored on 29/06/2009 10:34:08
Showing 1 changed files
... ...
@@ -34,9 +34,8 @@
34 34
 #include <string.h>
35 35
 #include <stdio.h>
36 36
 #include <errno.h>
37
-#include "../../mem/mem.h"
38
-#include "../../mem/shm_mem.h"
39 37
 #include "../../dprint.h"
38
+#include "mi_mem.h"
40 39
 #include "tree.h"
41 40
 #include "fmt.h"
42 41
 
... ...
@@ -50,7 +49,7 @@ struct mi_root *init_mi_tree(unsigned int code, char *reason, int reason_len)
50 49
 	if (use_shm)
51 50
 		root = (struct mi_root *)shm_malloc(sizeof(struct mi_root));
52 51
 	else
53
-		root = (struct mi_root *)pkg_malloc(sizeof(struct mi_root));
52
+		root = (struct mi_root *)mi_malloc(sizeof(struct mi_root));
54 53
 	if (!root) {
55 54
 		LM_ERR("no more pkg mem\n");
56 55
 		return NULL;
... ...
@@ -83,7 +82,7 @@ static void free_mi_node(struct mi_node *parent)
83 82
 		shm_free(parent);
84 83
 	} else {
85 84
 		del_mi_attr_list(parent);
86
-		pkg_free(parent);
85
+		mi_free(parent);
87 86
 	}
88 87
 }
89 88
 
... ...
@@ -100,7 +99,7 @@ void free_mi_tree(struct mi_root *parent)
100 99
 	if (use_shm)
101 100
 		shm_free(parent);
102 101
 	else
103
-		pkg_free(parent);
102
+		mi_free(parent);
104 103
 }
105 104
 
106 105
 
... ...
@@ -135,7 +134,7 @@ static inline struct mi_node *create_mi_node(char *name, int name_len,
135 134
 	if (use_shm)
136 135
 		new = (struct mi_node *)shm_malloc(size_mem);
137 136
 	else
138
-		new = (struct mi_node *)pkg_malloc(size_mem);
137
+		new = (struct mi_node *)mi_malloc(size_mem);
139 138
 	if(!new) {
140 139
 		LM_ERR("no more pkg mem\n");
141 140
 		return NULL;
Browse code

MI: core part

- code from kamailio MI

Daniel-Constantin Mierla authored on 10/02/2009 21:52:07
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,286 @@
1
+/*
2
+ * $Id: tree.c 4518 2008-07-28 15:39:28Z henningw $
3
+ *
4
+ * Copyright (C) 2006 Voice Sistem SRL
5
+ *
6
+ * This file is part of Kamailio, a free SIP server.
7
+ *
8
+ * Kamailio 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
+ * Kamailio is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
+ *
22
+ *
23
+ * History:
24
+ * ---------
25
+ *  2006-09-08  first version (bogdan)
26
+ */
27
+
28
+/*!
29
+ * \file 
30
+ * \brief MI :: Tree 
31
+ * \ingroup mi
32
+ */
33
+
34
+#include <string.h>
35
+#include <stdio.h>
36
+#include <errno.h>
37
+#include "../../mem/mem.h"
38
+#include "../../mem/shm_mem.h"
39
+#include "../../dprint.h"
40
+#include "tree.h"
41
+#include "fmt.h"
42
+
43
+
44
+static int use_shm = 0;
45
+
46
+struct mi_root *init_mi_tree(unsigned int code, char *reason, int reason_len)
47
+{
48
+	struct mi_root *root;
49
+
50
+	if (use_shm)
51
+		root = (struct mi_root *)shm_malloc(sizeof(struct mi_root));
52
+	else
53
+		root = (struct mi_root *)pkg_malloc(sizeof(struct mi_root));
54
+	if (!root) {
55
+		LM_ERR("no more pkg mem\n");
56
+		return NULL;
57
+	}
58
+
59
+	memset(root,0,sizeof(struct mi_root));
60
+	root->node.next = root->node.last = &root->node;
61
+
62
+	if (reason && reason_len) {
63
+		root->reason.s = reason;
64
+		root->reason.len = reason_len;
65
+	}
66
+	root->code = code;
67
+
68
+	return root;
69
+}
70
+
71
+
72
+static void free_mi_node(struct mi_node *parent)
73
+{
74
+	struct mi_node *p, *q;
75
+
76
+	for(p = parent->kids ; p ; ){
77
+		q = p;
78
+		p = p->next;
79
+		free_mi_node(q);
80
+	}
81
+
82
+	if (use_shm) {
83
+		shm_free(parent);
84
+	} else {
85
+		del_mi_attr_list(parent);
86
+		pkg_free(parent);
87
+	}
88
+}
89
+
90
+void free_mi_tree(struct mi_root *parent)
91
+{
92
+	struct mi_node *p, *q;
93
+
94
+	for(p = parent->node.kids ; p ; ){
95
+		q = p;
96
+		p = p->next;
97
+		free_mi_node(q);
98
+	}
99
+
100
+	if (use_shm)
101
+		shm_free(parent);
102
+	else
103
+		pkg_free(parent);
104
+}
105
+
106
+
107
+static inline struct mi_node *create_mi_node(char *name, int name_len,
108
+									char *value, int value_len, int flags)
109
+{
110
+	struct mi_node *new;
111
+	int size_mem;
112
+	int name_pos;
113
+	int value_pos;
114
+
115
+	if (!name) name_len=0;
116
+	if (!name_len) name=0;
117
+	if (!value) value_len=0;
118
+	if (!value_len) value=0;
119
+
120
+	if (!name && !value)
121
+		return NULL;
122
+
123
+	size_mem = sizeof(struct mi_node);
124
+	value_pos = name_pos = 0;
125
+
126
+	if (name && (flags & MI_DUP_NAME)){
127
+		name_pos = size_mem;
128
+		size_mem += name_len;
129
+	}
130
+	if (value && (flags & MI_DUP_VALUE)){
131
+		value_pos = size_mem;
132
+		size_mem += value_len;
133
+	}
134
+
135
+	if (use_shm)
136
+		new = (struct mi_node *)shm_malloc(size_mem);
137
+	else
138
+		new = (struct mi_node *)pkg_malloc(size_mem);
139
+	if(!new) {
140
+		LM_ERR("no more pkg mem\n");
141
+		return NULL;
142
+	}
143
+	memset(new,0,size_mem);
144
+
145
+	if (name) {
146
+		new->name.len = name_len;
147
+		if(flags & MI_DUP_NAME){
148
+			new->name.s = ((char *)new) + name_pos;
149
+			strncpy(new->name.s, name, name_len);
150
+		} else{
151
+			new->name.s = name;
152
+		}
153
+	}
154
+
155
+	if (value) {
156
+		new->value.len = value_len;
157
+		if(flags & MI_DUP_VALUE){
158
+			new->value.s = ((char *)new) + value_pos;
159
+			strncpy(new->value.s, value, value_len);
160
+		}else{
161
+			new->value.s = value;
162
+		}
163
+	}
164
+	new->last = new;
165
+
166
+	return new;
167
+}
168
+
169
+
170
+static inline struct mi_node *add_next(struct mi_node *brother,
171
+			char *name, int name_len, char *value, int value_len, int flags)
172
+{
173
+	struct mi_node *new;
174
+
175
+	if(!brother)
176
+		return NULL;
177
+	
178
+	new = create_mi_node(name, name_len, value, value_len, flags);
179
+	if(!new)
180
+		return NULL;
181
+
182
+	brother->last->next = new;
183
+	brother->last = new;
184
+
185
+	return new;
186
+}
187
+
188
+
189
+struct mi_node *add_mi_node_sibling( struct mi_node *brother, int flags,
190
+						char *name, int name_len, char *value, int value_len)
191
+{
192
+	return add_next(brother, name, name_len, value, value_len, flags);
193
+}
194
+
195
+
196
+struct mi_node *addf_mi_node_sibling(struct mi_node *brother, int flags,
197
+							char *name, int name_len, char *fmt_val, ...)
198
+{
199
+	va_list ap;
200
+	char *p;
201
+	int  len;
202
+
203
+	va_start(ap, fmt_val);
204
+	p = mi_print_fmt( fmt_val, ap, &len);
205
+	va_end(ap);
206
+	if (p==NULL)
207
+		return 0;
208
+	return add_mi_node_sibling( brother, flags|MI_DUP_VALUE,
209
+		name, name_len, p, len);
210
+}
211
+
212
+
213
+struct mi_node *add_mi_node_child( struct mi_node *parent, int flags,
214
+						char *name, int name_len, char *value, int value_len)
215
+{
216
+	if(parent->kids){
217
+		return add_next(parent->kids, name, name_len, value, value_len, flags);
218
+	}else{
219
+		parent->kids = create_mi_node(name, name_len, value, value_len, flags);
220
+		return parent->kids;
221
+	}
222
+}
223
+
224
+
225
+struct mi_node *addf_mi_node_child(struct mi_node *parent, int flags,
226
+							char *name, int name_len, char *fmt_val, ...)
227
+{
228
+	va_list ap;
229
+	char *p;
230
+	int  len;
231
+
232
+	va_start(ap, fmt_val);
233
+	p = mi_print_fmt( fmt_val, ap, &len);
234
+	va_end(ap);
235
+	if (p==NULL)
236
+		return 0;
237
+	return add_mi_node_child( parent, flags|MI_DUP_VALUE,
238
+		name, name_len, p, len);
239
+}
240
+
241
+
242
+static int clone_mi_node(struct mi_node *org, struct mi_node *parent)
243
+{
244
+	struct mi_node *p, *q;
245
+
246
+	for(p = org->kids ; p ; p=p->next){
247
+		q = add_mi_node_child( parent, MI_DUP_VALUE|MI_DUP_NAME,
248
+			p->name.s, p->name.len, p->value.s, p->value.len);
249
+		if (q==NULL)
250
+			return -1;
251
+		if (clone_mi_node( p, q)!=0)
252
+			return -1;
253
+	}
254
+	return 0;
255
+}
256
+
257
+
258
+struct mi_root* clone_mi_tree(struct mi_root *org, int shm)
259
+{
260
+	struct mi_root *root;
261
+
262
+	use_shm = shm?1:0;
263
+
264
+	root = init_mi_tree( org->code, org->reason.s, org->reason.len);
265
+	if (root==NULL)
266
+		goto done;
267
+
268
+	if (clone_mi_node( &(org->node), &(root->node) )!=0 ) {
269
+		free_mi_tree(root);
270
+		root = NULL;
271
+		goto done;
272
+	}
273
+
274
+done:
275
+	use_shm=0;
276
+	return root;
277
+}
278
+
279
+
280
+
281
+void free_shm_mi_tree(struct mi_root *parent)
282
+{
283
+	use_shm = 1;
284
+	free_mi_tree(parent);
285
+	use_shm = 0;
286
+}