Browse code

modules_k/rls: Fixed issues with for() loops in DB only mode

- Found and fixed by Hugh Waite @ Crocodile RCS Ltd

Peter Dunkley authored on 11/09/2012 12:08:38
Showing 2 changed files
... ...
@@ -121,7 +121,7 @@ int delete_expired_subs_rlsdb( void )
121 121
 	db1_res_t *result = NULL;
122 122
 	int n_query_cols = 0, n_result_cols = 0;
123 123
 	int r_callid_col = 0, r_to_tag_col = 0, r_from_tag_col = 0;
124
-	int i;
124
+	int i, nr_rows;
125 125
 	subs_t subs;
126 126
 	str rlsubs_did = {0, 0};
127 127
 	db_query_f query_fn = rls_dbf.query_lock ? rls_dbf.query_lock : rls_dbf.query;
... ...
@@ -167,10 +167,13 @@ int delete_expired_subs_rlsdb( void )
167 167
 
168 168
 	if(result == NULL) goto error;
169 169
 
170
-	for (i = 0; i <RES_ROW_N(result); i++)
170
+	rows = RES_ROWS(result);
171
+	nr_rows = RES_ROW_N(result);
172
+
173
+	for (i = 0; i < nr_rows; i++)
171 174
 	{
172
-		rows = RES_ROWS(result);
173
-		values = ROW_VALUES(rows);
175
+		memset(&subs, 0, sizeof(subs_t));
176
+		values = ROW_VALUES(&rows[i]);
174 177
 
175 178
 		subs.callid.s = (char *) VAL_STRING(&values[r_callid_col]);
176 179
 		subs.callid.len = strlen(subs.callid.s);
... ...
@@ -442,11 +445,11 @@ int update_all_subs_rlsdb(str *watcher_user, str *watcher_domain, str *evt)
442 445
 
443 446
 	nr_rows = RES_ROW_N(result);
444 447
 
448
+	rows = RES_ROWS(result);
445 449
 	/* get the results and fill in return data structure */
446 450
 	for (loop=0; loop <nr_rows; loop++)
447 451
 	{
448
-		rows = RES_ROWS(result);
449
-		values = ROW_VALUES(rows);
452
+		values = ROW_VALUES(&rows[loop]);
450 453
 
451 454
 		size= sizeof(subs_t) +
452 455
 			( strlen(VAL_STRING(values+r_pres_uri_col))
... ...
@@ -327,7 +327,7 @@ int reply_200(struct sip_msg* msg, str* contact, int expires)
327 327
 		LM_ERR("no more pkg memory\n");
328 328
 		return -1;
329 329
 	}
330
-	hdr_append.len = sprintf(hdr_append.s, "Expires: %d\r\n", expires);	
330
+	hdr_append.len = sprintf(hdr_append.s, "Expires: %d\r\n", expires);
331 331
 	if(hdr_append.len< 0)
332 332
 	{
333 333
 		LM_ERR("unsuccessful sprintf\n");