Browse code

keepalive: declare variables at the beginning of functions

- fix for C standard older than C99

Daniel-Constantin Mierla authored on 05/04/2017 06:45:33
Showing 4 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 /**
2 2
  * keepalive module - remote destinations probing
3
- * 
3
+ *
4 4
  * Copyright (C) 2017 Guillaume Bour <guillaume@bour.cc>
5 5
  *
6 6
  * This file is part of Kamailio, a free SIP server.
... ...
@@ -15,8 +15,8 @@
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
17 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 
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 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  */
22 22
 
... ...
@@ -57,7 +57,6 @@ typedef struct _ka_dest
57 57
 	time_t last_checked,
58 58
 		   last_up,
59 59
 		   last_down;
60
-	//ds_attrs_t attrs;
61 60
 
62 61
 	void *user_attr;
63 62
 	ka_statechanged_f statechanged_clb;
... ...
@@ -66,7 +65,6 @@ typedef struct _ka_dest
66 65
 	struct ip_addr ip_address; 	/*!< IP-Address of the entry */
67 66
 	unsigned short int port; 	/*!< Port of the URI */
68 67
 	unsigned short int proto; 	/*!< Protocol of the URI */
69
-	//int message_count;
70 68
 	struct _ka_dest *next;
71 69
 } ka_dest_t;
72 70
 
... ...
@@ -60,9 +60,12 @@ int bind_keepalive(keepalive_api_t* api)
60 60
  * Add a new destination in keepalive pool
61 61
  */
62 62
 int ka_add_dest(str uri, str owner, int flags, ka_statechanged_f callback, void *user_attr) {
63
+	struct sip_uri _uri;
64
+	ka_dest_t *dest;
65
+
63 66
 	LM_INFO("adding destination: %.*s\n", uri.len, uri.s);
64 67
 
65
-	ka_dest_t *dest = (ka_dest_t *) shm_malloc(sizeof(ka_dest_t));
68
+	dest = (ka_dest_t *) shm_malloc(sizeof(ka_dest_t));
66 69
 	if(dest == NULL) {
67 70
 		LM_ERR("no more memory.\n");
68 71
 		goto err;
... ...
@@ -79,7 +82,6 @@ int ka_add_dest(str uri, str owner, int flags, ka_statechanged_f callback, void
79 82
 	}
80 83
 
81 84
 	// checking uri is valid
82
-	struct sip_uri _uri;
83 85
 	if (parse_uri(dest->uri.s, dest->uri.len, &_uri) != 0) {
84 86
 		LM_ERR("invalid uri <%.*s>\n", dest->uri.len, dest->uri.s);
85 87
 		goto err;
... ...
@@ -132,4 +134,3 @@ ka_state ka_destination_state(str destination) {
132 134
 
133 135
 	return ka_dest->state;
134 136
 }
135
-
... ...
@@ -142,7 +142,7 @@ int ka_parse_flags( char* flag_str, int flag_len )
142 142
  * Function callback executer per module param "destination".
143 143
  * Is just a wrapper to ka_add_dest() api function
144 144
  */
145
-static int ka_mod_add_destination(modparam_t type, void *val) 
145
+static int ka_mod_add_destination(modparam_t type, void *val)
146 146
 {
147 147
 	if (ka_alloc_destinations_list() < 0)
148 148
 		return -1;
... ...
@@ -156,7 +156,7 @@ static int ka_mod_add_destination(modparam_t type, void *val)
156 156
 
157 157
 /*
158 158
  * Allocate global variable *ka_destination_list* if not already done
159
- * WHY:  when specifying static destinations as module param, ka_mod_add_destination() is 
159
+ * WHY:  when specifying static destinations as module param, ka_mod_add_destination() is
160 160
  *       executed BEFORE mod_init()
161 161
  */
162 162
 int ka_alloc_destinations_list()
... ...
@@ -61,38 +61,41 @@ static const char *keepalive_rpc_list_doc[2] = {
61 61
 		"Return the content of dispatcher sets", 0};
62 62
 
63 63
 static void keepalive_rpc_list(rpc_t *rpc, void *ctx) {
64
+	void *foo, *bar, *baz;
65
+	void *sub;
66
+	ka_dest_t *dest;
67
+	char *_ctime;
68
+	char *_utime;
69
+	char *_dtime;
64 70
 	str text = str_init("foobar");
65
-	if (rpc->add(ctx, "Sd", &text, 42) < 0) 
66
-		LM_ERR("%s: error creating RPC struct\n", __FUNCTION__);
67
-	if (rpc->add(ctx, "Sd", &text, 42) < 0) 
68
-		LM_ERR("%s: error creating RPC struct\n", __FUNCTION__);
69 71
 
70
-	void *foo;
72
+	if (rpc->add(ctx, "Sd", &text, 42) < 0)
73
+		LM_ERR("failed creating RPC struct\n");
74
+	if (rpc->add(ctx, "Sd", &text, 42) < 0)
75
+		LM_ERR("failed creating RPC struct\n");
76
+
71 77
 	rpc->add(ctx, "{", &foo);
72 78
 	rpc->struct_add(foo, "Sd", "text", &text, "number", 42);
73 79
 
74
-	void *bar, *baz;
75 80
 	rpc->add(ctx, "{", &bar);
76 81
 	rpc->struct_add(bar, "[", "list", &baz);
77 82
 	rpc->struct_add(baz, "d", "nn", 17);
78 83
 	rpc->struct_add(baz, "d", "nn", 22);
79
-	
80 84
 
81
-	for(ka_dest_t *dest = ka_destinations_list->first; dest != NULL; dest = dest->next) {
82
-		void *sub;
85
+	for(dest = ka_destinations_list->first; dest != NULL; dest = dest->next) {
83 86
 		rpc->add(ctx, "{", &sub);
84 87
 
85
-		rpc->struct_add(sub, "SS", 
88
+		rpc->struct_add(sub, "SS",
86 89
 			"uri"  , &dest->uri,
87 90
 			"owner", &dest->owner);
88 91
 
89
-		char *_ctime = ctime(&dest->last_checked);
92
+		_ctime = ctime(&dest->last_checked);
90 93
 		_ctime[strlen(_ctime) - 1] = '\0';
91 94
 		rpc->struct_add(sub, "s", "last checked", _ctime);
92
-		char *_utime = ctime(&dest->last_up);
95
+		_utime = ctime(&dest->last_up);
93 96
 		_utime[strlen(_utime) - 1] = '\0';
94 97
 		rpc->struct_add(sub, "s", "last up", _utime);
95
-		char *_dtime = ctime(&dest->last_down);
98
+		_dtime = ctime(&dest->last_down);
96 99
 		_dtime[strlen(_dtime) - 1] = '\0';
97 100
 		rpc->struct_add(sub, "s", "last down", _dtime);
98 101
 	}