Browse code

cnxcc: minor changes

* use [PKG|SHM]_MEM_ERROR
* use memset and avoid initialization per field
* init variables
* add cnxcc to lgtm build
* use localtime_r() for a safer multi-thread usage
* replaced deprecated STR_PARAM with PARAM_STR
* clean includes
* clang-format

Victor Seva authored on 02/06/2020 17:12:31
Showing 1 changed files
... ...
@@ -20,29 +20,30 @@
20 20
  *
21 21
  */
22 22
 
23
+#include <sys/socket.h>
24
+
23 25
 #include "../../core/parser/msg_parser.h"
24 26
 #include "../../core/globals.h"
25 27
 
26
-#include <sys/socket.h>
27
-
28 28
 #define FAKED_SIP_MSG_FORMAT                                                 \
29 29
 	"OPTIONS sip:you@kamailio.org SIP/2.0\r\nVia: SIP/2.0/UDP "              \
30 30
 	"127.0.0.1\r\nFrom: <%.*s>;tag=%.*s\r\nTo: <%.*s>;tag=%.*s\r\nCall-ID: " \
31 31
 	"%.*s\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
32 32
 
33 33
 #define FAKED_SIP_MSG_BUF_LEN 1024
34
-char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN];
34
+static char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN];
35 35
 
36 36
 static struct sip_msg _faked_msg;
37 37
 
38
-int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag,
39
-		str *to_uri, str *to_tag, struct sip_msg **msg)
38
+int cnxcc_faked_msg_init_with_dlg_info(str *callid, str *from_uri,
39
+		str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg)
40 40
 {
41 41
 	memset(_faked_sip_msg_buf, 0, FAKED_SIP_MSG_BUF_LEN);
42
+	memset(&_faked_msg, 0, sizeof(struct sip_msg));
42 43
 
43
-	snprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_BUF_LEN, FAKED_SIP_MSG_FORMAT, from_uri->len,
44
-			from_uri->s, from_tag->len, from_tag->s, to_uri->len, to_uri->s,
45
-			to_tag->len, to_tag->s, callid->len, callid->s);
44
+	snprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_BUF_LEN, FAKED_SIP_MSG_FORMAT,
45
+			from_uri->len, from_uri->s, from_tag->len, from_tag->s, to_uri->len,
46
+			to_uri->s, to_tag->len, to_tag->s, callid->len, callid->s);
46 47
 
47 48
 	LM_DBG("fake msg:\n%s\n", _faked_sip_msg_buf);
48 49
 
Browse code

cnxcc: use snprintf() instead of sprintf()

Daniel-Constantin Mierla authored on 18/11/2019 17:29:05
Showing 1 changed files
... ...
@@ -40,7 +40,7 @@ int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag,
40 40
 {
41 41
 	memset(_faked_sip_msg_buf, 0, FAKED_SIP_MSG_BUF_LEN);
42 42
 
43
-	sprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_FORMAT, from_uri->len,
43
+	snprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_BUF_LEN, FAKED_SIP_MSG_FORMAT, from_uri->len,
44 44
 			from_uri->s, from_tag->len, from_tag->s, to_uri->len, to_uri->s,
45 45
 			to_tag->len, to_tag->s, callid->len, callid->s);
46 46
 
Browse code

cnxcc: clang format the code

Daniel-Constantin Mierla authored on 24/11/2017 11:37:54
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2012 Carlos Ruiz Díaz (caruizdiaz.com),
5 3
  *                    ConexionGroup (www.conexiongroup.com)
6 4
  *
... ...
@@ -27,30 +25,34 @@
27 25
 
28 26
 #include <sys/socket.h>
29 27
 
30
-#define FAKED_SIP_MSG_FORMAT "OPTIONS sip:you@kamailio.org SIP/2.0\r\nVia: SIP/2.0/UDP 127.0.0.1\r\nFrom: <%.*s>;tag=%.*s\r\nTo: <%.*s>;tag=%.*s\r\nCall-ID: %.*s\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
28
+#define FAKED_SIP_MSG_FORMAT                                                 \
29
+	"OPTIONS sip:you@kamailio.org SIP/2.0\r\nVia: SIP/2.0/UDP "              \
30
+	"127.0.0.1\r\nFrom: <%.*s>;tag=%.*s\r\nTo: <%.*s>;tag=%.*s\r\nCall-ID: " \
31
+	"%.*s\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
31 32
 
32
-#define FAKED_SIP_MSG_BUF_LEN	1024
33
+#define FAKED_SIP_MSG_BUF_LEN 1024
33 34
 char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN];
34 35
 
35 36
 static struct sip_msg _faked_msg;
36 37
 
37
-int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg) {
38
+int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag,
39
+		str *to_uri, str *to_tag, struct sip_msg **msg)
40
+{
38 41
 	memset(_faked_sip_msg_buf, 0, FAKED_SIP_MSG_BUF_LEN);
39 42
 
40
-	sprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_FORMAT,
41
-				from_uri->len, from_uri->s, from_tag->len, from_tag->s,
42
-				to_uri->len, to_uri->s, to_tag->len, to_tag->s,
43
-				callid->len, callid->s);
44
- 
43
+	sprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_FORMAT, from_uri->len,
44
+			from_uri->s, from_tag->len, from_tag->s, to_uri->len, to_uri->s,
45
+			to_tag->len, to_tag->s, callid->len, callid->s);
46
+
45 47
 	LM_DBG("fake msg:\n%s\n", _faked_sip_msg_buf);
46 48
 
47 49
 	_faked_msg.buf = _faked_sip_msg_buf;
48 50
 	_faked_msg.len = strlen(_faked_sip_msg_buf);
49 51
 
50
-	_faked_msg.set_global_address	= default_global_address;
51
-	_faked_msg.set_global_port	= default_global_port;
52
+	_faked_msg.set_global_address = default_global_address;
53
+	_faked_msg.set_global_port = default_global_port;
52 54
 
53
-	if (parse_msg(_faked_msg.buf, _faked_msg.len, &_faked_msg) != 0) {
55
+	if(parse_msg(_faked_msg.buf, _faked_msg.len, &_faked_msg) != 0) {
54 56
 		LM_ERR("parse_msg failed\n");
55 57
 		return -1;
56 58
 	}
... ...
@@ -65,6 +67,6 @@ int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag, str
65 67
 	_faked_msg.rcv.dst_ip.af = AF_INET;
66 68
 	_faked_msg.rcv.dst_ip.len = 4;
67 69
 
68
-	*msg	= &_faked_msg;
70
+	*msg = &_faked_msg;
69 71
 	return 0;
70 72
 }
Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -22,8 +22,8 @@
22 22
  *
23 23
  */
24 24
 
25
-#include "../../parser/msg_parser.h"
26
-#include "../../globals.h"
25
+#include "../../core/parser/msg_parser.h"
26
+#include "../../core/globals.h"
27 27
 
28 28
 #include <sys/socket.h>
29 29
 
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,70 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2012 Carlos Ruiz Díaz (caruizdiaz.com),
5
+ *                    ConexionGroup (www.conexiongroup.com)
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+ *
23
+ */
24
+
25
+#include "../../parser/msg_parser.h"
26
+#include "../../globals.h"
27
+
28
+#include <sys/socket.h>
29
+
30
+#define FAKED_SIP_MSG_FORMAT "OPTIONS sip:you@kamailio.org SIP/2.0\r\nVia: SIP/2.0/UDP 127.0.0.1\r\nFrom: <%.*s>;tag=%.*s\r\nTo: <%.*s>;tag=%.*s\r\nCall-ID: %.*s\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
31
+
32
+#define FAKED_SIP_MSG_BUF_LEN	1024
33
+char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN];
34
+
35
+static struct sip_msg _faked_msg;
36
+
37
+int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg) {
38
+	memset(_faked_sip_msg_buf, 0, FAKED_SIP_MSG_BUF_LEN);
39
+
40
+	sprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_FORMAT,
41
+				from_uri->len, from_uri->s, from_tag->len, from_tag->s,
42
+				to_uri->len, to_uri->s, to_tag->len, to_tag->s,
43
+				callid->len, callid->s);
44
+ 
45
+	LM_DBG("fake msg:\n%s\n", _faked_sip_msg_buf);
46
+
47
+	_faked_msg.buf = _faked_sip_msg_buf;
48
+	_faked_msg.len = strlen(_faked_sip_msg_buf);
49
+
50
+	_faked_msg.set_global_address	= default_global_address;
51
+	_faked_msg.set_global_port	= default_global_port;
52
+
53
+	if (parse_msg(_faked_msg.buf, _faked_msg.len, &_faked_msg) != 0) {
54
+		LM_ERR("parse_msg failed\n");
55
+		return -1;
56
+	}
57
+
58
+	_faked_msg.rcv.proto = PROTO_UDP;
59
+	_faked_msg.rcv.src_port = 5060;
60
+	_faked_msg.rcv.src_ip.u.addr32[0] = 0x7f000001;
61
+	_faked_msg.rcv.src_ip.af = AF_INET;
62
+	_faked_msg.rcv.src_ip.len = 4;
63
+	_faked_msg.rcv.dst_port = 5060;
64
+	_faked_msg.rcv.dst_ip.u.addr32[0] = 0x7f000001;
65
+	_faked_msg.rcv.dst_ip.af = AF_INET;
66
+	_faked_msg.rcv.dst_ip.len = 4;
67
+
68
+	*msg	= &_faked_msg;
69
+	return 0;
70
+}