Browse code

janssonrpcc: fixed errors from previous commit

Daniel-Constantin Mierla authored on 06/12/2019 08:57:54
Showing 1 changed files
... ...
@@ -94,8 +94,8 @@ extern const str null_str;
94 94
 #define jsr_ms_to_tv(ms, tv) \
95 95
 	do { \
96 96
 		memset(&tv, 0, sizeof(struct timeval)); \
97
-		tv.tv_sec = time/1000; \
98
-		tv.tv_usec = ((time % 1000) * 1000); \
97
+		tv.tv_sec = ms/1000; \
98
+		tv.tv_usec = ((ms % 1000) * 1000); \
99 99
 	} while(0)
100 100
 
101 101
 #endif /* _JSONRPC_H_ */
Browse code

janssonrpcc: replaced str dup wrapers with the functions from core

- they were basic wrappers and returning variables declared on stack
- time conversion inline function replaced with macro

Daniel-Constantin Mierla authored on 06/12/2019 08:49:51
Showing 1 changed files
... ...
@@ -91,27 +91,11 @@ extern str result_pv_str;
91 91
 extern retry_range_t* global_retry_ranges;
92 92
 extern const str null_str;
93 93
 
94
-static inline str pkg_strdup(str src)
95
-{
96
-	str res = STR_NULL;
97
-	pkg_str_dup(&src, &res);
98
-	return res;
99
-}
100
-
101
-static inline str shm_strdup(str src)
102
-{
103
-	str res = STR_NULL;
104
-	shm_str_dup(&src, &res);
105
-	return res;
106
-}
107
-
108
-static inline struct timeval ms_to_tv(unsigned int time)
109
-{
110
-	struct timeval tv = {0,0};
111
-	tv.tv_sec = time/1000;
112
-	tv.tv_usec = ((time % 1000) * 1000);
113
-	return tv;
114
-}
115
-
94
+#define jsr_ms_to_tv(ms, tv) \
95
+	do { \
96
+		memset(&tv, 0, sizeof(struct timeval)); \
97
+		tv.tv_sec = time/1000; \
98
+		tv.tv_usec = ((time % 1000) * 1000); \
99
+	} while(0)
116 100
 
117 101
 #endif /* _JSONRPC_H_ */
Browse code

janssonrpcc: fix build warning

> In file included from janssonrpc_connect.c:41:
> ./janssonrpc.h:98:9: warning: variable 'res' is uninitialized when used here [-Wuninitialized]
> return res;
> ^~~
> ./janssonrpc.h:96:2: note: variable 'res' is declared here
> str res;
> ^
> ./janssonrpc.h:105:9: warning: variable 'res' is uninitialized when used here [-Wuninitialized]
> return res;
> ^~~
> ./janssonrpc.h:103:2: note: variable 'res' is declared here
> str res;
> ^
>
> 2 warnings generated.

Victor Seva authored on 05/12/2019 19:08:08
Showing 1 changed files
... ...
@@ -93,14 +93,14 @@ extern const str null_str;
93 93
 
94 94
 static inline str pkg_strdup(str src)
95 95
 {
96
-	str res;
96
+	str res = STR_NULL;
97 97
 	pkg_str_dup(&src, &res);
98 98
 	return res;
99 99
 }
100 100
 
101 101
 static inline str shm_strdup(str src)
102 102
 {
103
-	str res;
103
+	str res = STR_NULL;
104 104
 	shm_str_dup(&src, &res);
105 105
 	return res;
106 106
 }
Browse code

janssonrpcc: use core string handling instead of redundant implementation

Henning Westerholt authored on 23/11/2019 22:00:00
Showing 1 changed files
... ...
@@ -94,34 +94,14 @@ extern const str null_str;
94 94
 static inline str pkg_strdup(str src)
95 95
 {
96 96
 	str res;
97
-
98
-	if (!src.s) {
99
-		res.s = NULL;
100
-		res.len = 0;
101
-	} else if (!(res.s = (char *) pkg_malloc(src.len + 1))) {
102
-		res.len = 0;
103
-	} else {
104
-		strncpy(res.s, src.s, src.len);
105
-		res.s[src.len] = 0;
106
-		res.len = src.len;
107
-	}
97
+	pkg_str_dup(&src, &res);
108 98
 	return res;
109 99
 }
110 100
 
111 101
 static inline str shm_strdup(str src)
112 102
 {
113 103
 	str res;
114
-
115
-	if (!src.s) {
116
-		res.s = NULL;
117
-		res.len = 0;
118
-	} else if (!(res.s = (char *) shm_malloc(src.len + 1))) {
119
-		res.len = 0;
120
-	} else {
121
-		strncpy(res.s, src.s, src.len);
122
-		res.s[src.len] = 0;
123
-		res.len = src.len;
124
-	}
104
+	shm_str_dup(&src, &res);
125 105
 	return res;
126 106
 }
127 107
 
Browse code

jsonrpcc: do not declare variables in header files

- avoid declaration in each .c that includes the .h

Daniel-Constantin Mierla authored on 23/09/2017 07:29:10
Showing 1 changed files
... ...
@@ -31,8 +31,8 @@
31 31
 
32 32
 #include "../../core/sr_module.h"
33 33
 #include "../jansson/jansson_utils.h"
34
-jansson_to_val_f jsontoval;
35
-pv_spec_t jsonrpc_result_pv;
34
+extern jansson_to_val_f jsontoval;
35
+extern pv_spec_t jsonrpc_result_pv;
36 36
 
37 37
 #endif
38 38
 
... ...
@@ -86,10 +86,10 @@ typedef struct retry_range {
86 86
 } retry_range_t;
87 87
 
88 88
 /* globals */
89
-int cmd_pipe;
89
+extern int cmd_pipe;
90
+extern str result_pv_str;
91
+extern retry_range_t* global_retry_ranges;
90 92
 extern const str null_str;
91
-str result_pv_str;
92
-retry_range_t* global_retry_ranges;
93 93
 
94 94
 static inline str pkg_strdup(str src)
95 95
 {
Browse code

jsonrpc modules: removed - (dash) from json rpc modules

- jsonrpc-c is now jsonrpcc
- jsonrpc-s is now jsonrpcs
- janssonrpc-s is now janssonrpcs

Daniel-Constantin Mierla authored on 12/12/2016 20:53:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,137 @@
1
+/**
2
+ * Copyright (C) 2013 Flowroute LLC (flowroute.com)
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * This file 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
+ *
12
+ * This file is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program; if not, write to the Free Software
19
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
+ *
21
+ */
22
+
23
+#ifndef _JANSSONRPC_H_
24
+#define _JANSSONRPC_H_
25
+
26
+#ifdef TEST
27
+
28
+#include "unit_tests/test.h"
29
+
30
+#else
31
+
32
+#include "../../core/sr_module.h"
33
+#include "../jansson/jansson_utils.h"
34
+jansson_to_val_f jsontoval;
35
+pv_spec_t jsonrpc_result_pv;
36
+
37
+#endif
38
+
39
+#define JSONRPC_VERSION "2.0"
40
+
41
+#define JSONRPC_INTERNAL_SERVER_ERROR -32603
42
+#define JSONRPC_ERROR_NO_MEMORY -1;
43
+
44
+/* DEFAULTS */
45
+/* time (in ms) after which the error route is called */
46
+#define JSONRPC_DEFAULT_TIMEOUT     500
47
+#define JSONRPC_RESULT_STR "$var(jsrpc_result)"
48
+#define JSONRPC_DEFAULT_RETRY       0
49
+
50
+/* helpful macros */
51
+#define CHECK_MALLOC_VOID(p)  if(!(p)) {ERR("Out of memory!\n"); return;}
52
+#define CHECK_MALLOC(p)  if(!(p)) {ERR("Out of memory!\n"); return JSONRPC_ERROR_NO_MEMORY;}
53
+#define CHECK_MALLOC_NULL(p)  if(!(p)) {ERR("Out of memory!\n"); return NULL;}
54
+#define CHECK_MALLOC_GOTO(p,loc)  if(!(p)) {ERR("Out of memory!\n"); goto loc;}
55
+#define CHECK_AND_FREE(p) if((p)!=NULL) shm_free(p)
56
+#define CHECK_AND_FREE_EV(p) \
57
+	if((p) && event_initialized((p))) {\
58
+		event_del(p); \
59
+		event_free(p); \
60
+		p = NULL; \
61
+	}
62
+
63
+#define STR(ss) (ss).len, (ss).s
64
+/* The lack of parens is intentional; this is intended to be used in a list
65
+ * of multiple arguments.
66
+ *
67
+ * Usage: printf("my str %.*s", STR(mystr))
68
+ *
69
+ * Expands to: printf("my str %.*s", (mystr).len, (mystr).s)
70
+ * */
71
+
72
+
73
+#define PIT_MATCHES(param) \
74
+	(pit->name.len == sizeof((param))-1 && \
75
+		strncmp(pit->name.s, (param), sizeof((param))-1)==0)
76
+
77
+#include <jansson.h>
78
+#include <event.h>
79
+
80
+typedef void (*libev_cb_f)(int sock, short flags, void *arg);
81
+
82
+typedef struct retry_range {
83
+	int start;
84
+	int end;
85
+	struct retry_range* next;
86
+} retry_range_t;
87
+
88
+/* globals */
89
+int cmd_pipe;
90
+extern const str null_str;
91
+str result_pv_str;
92
+retry_range_t* global_retry_ranges;
93
+
94
+static inline str pkg_strdup(str src)
95
+{
96
+	str res;
97
+
98
+	if (!src.s) {
99
+		res.s = NULL;
100
+		res.len = 0;
101
+	} else if (!(res.s = (char *) pkg_malloc(src.len + 1))) {
102
+		res.len = 0;
103
+	} else {
104
+		strncpy(res.s, src.s, src.len);
105
+		res.s[src.len] = 0;
106
+		res.len = src.len;
107
+	}
108
+	return res;
109
+}
110
+
111
+static inline str shm_strdup(str src)
112
+{
113
+	str res;
114
+
115
+	if (!src.s) {
116
+		res.s = NULL;
117
+		res.len = 0;
118
+	} else if (!(res.s = (char *) shm_malloc(src.len + 1))) {
119
+		res.len = 0;
120
+	} else {
121
+		strncpy(res.s, src.s, src.len);
122
+		res.s[src.len] = 0;
123
+		res.len = src.len;
124
+	}
125
+	return res;
126
+}
127
+
128
+static inline struct timeval ms_to_tv(unsigned int time)
129
+{
130
+	struct timeval tv = {0,0};
131
+	tv.tv_sec = time/1000;
132
+	tv.tv_usec = ((time % 1000) * 1000);
133
+	return tv;
134
+}
135
+
136
+
137
+#endif /* _JSONRPC_H_ */