Browse code

tm: t_continue() polishing

- variables declared at beginning of function to work on old C standard
compilers
- log messages compacted - function name and log level are prefixed
automatically
- stay under 80 chars per line to fit in text terminals

(cherry picked from commit 47f6cfd76a9d801a83ca14b55926d389f6c3c2da)

Daniel-Constantin Mierla authored on 02/03/2014 14:40:17
Showing 1 changed files
... ...
@@ -163,9 +163,14 @@ int t_continue(unsigned int hash_index, unsigned int label,
163 163
 	struct ua_client *uac =NULL;
164 164
 	int	ret;
165 165
 	int cb_type;
166
+	int msg_status;
167
+	int last_uac_status;
168
+	int reply_status;
169
+	int do_put_on_wait;
170
+	struct hdr_field *hdr, *prev = 0, *tmp = 0;
166 171
 
167 172
 	if (t_lookup_ident(&t, hash_index, label) < 0) {
168
-		LOG(L_ERR, "ERROR: t_continue: transaction not found\n");
173
+		LM_ERR("transaction not found\n");
169 174
 		return -1;
170 175
 	}
171 176
 
... ...
@@ -231,7 +236,7 @@ int t_continue(unsigned int hash_index, unsigned int label,
231 236
 
232 237
 		/* fake the request and the environment, like in failure_route */
233 238
 		if (!fake_req(&faked_req, t->uas.request, 0 /* extra flags */, uac)) {
234
-			LOG(L_ERR, "ERROR: t_continue: fake_req failed\n");
239
+			LM_ERR("building fake_req failed\n");
235 240
 			ret = -1;
236 241
 			goto kill_trans;
237 242
 		}
... ...
@@ -240,7 +245,7 @@ int t_continue(unsigned int hash_index, unsigned int label,
240 245
 		/* execute the pre/post -script callbacks based on original route block */
241 246
 		if (exec_pre_script_cb(&faked_req, cb_type)>0) {
242 247
 			if (run_top_route(route, &faked_req, 0)<0)
243
-				LOG(L_ERR, "ERROR: t_continue: Error in run_top_route\n");
248
+				LM_ERR("failure inside run_top_route\n");
244 249
 			exec_post_script_cb(&faked_req, cb_type);
245 250
 		}
246 251
 
... ...
@@ -273,39 +278,37 @@ int t_continue(unsigned int hash_index, unsigned int label,
273 278
 			}
274 279
 		}
275 280
 
276
-	}else{
281
+	} else {
277 282
 		branch = t->async_backup.backup_branch;
278 283
 
279 284
 		init_cancel_info(&cancel_data);
280 285
 
281
-		LOG(L_DBG,"DEBUG: t_continue_reply: This a continue from a reply suspend\n");
282
-		/* this is a continue from a reply suspend */
286
+		LM_DBG("continuing from a suspended reply"
287
+				" - resetting the suspend branch flag\n");
283 288
 
284
-		LOG(L_DBG,"DEBUG: t_continue_reply: Disabling suspend branch");
285 289
 		t->uac[branch].reply->msg_flags &= ~FL_RPL_SUSPENDED;
286 290
 		if (t->uas.request) t->uas.request->msg_flags&= ~FL_RPL_SUSPENDED;
287 291
 
288 292
 		faked_env( t, t->uac[branch].reply, 1);
289 293
 
290
-		LOG(L_DBG,"DEBUG: Running pre script\n");
291 294
 		if (exec_pre_script_cb(t->uac[branch].reply, cb_type)>0) {
292 295
 			if (run_top_route(route, t->uac[branch].reply, 0)<0){
293 296
 				LOG(L_ERR, "ERROR: t_continue_reply: Error in run_top_route\n");
294 297
 			}
295
-			LOG(L_DBG,"DEBUG: t_continue_reply: Running exec post script\n");
296 298
 			exec_post_script_cb(t->uac[branch].reply, cb_type);
297 299
 		}
298 300
 
299
-		LOG(L_DBG,"DEBUG: t_continue_reply: Restoring previous environment");
301
+		LM_DBG("restoring previous environment");
300 302
 		faked_env( t, 0, 1);
301 303
 
302
-		int reply_status;
303
-
304 304
 		/*lock transaction replies - will be unlocked when reply is relayed*/
305 305
 		LOCK_REPLIES( t );
306 306
 		if ( is_local(t) ) {
307
-			LOG(L_DBG,"DEBUG: t_continue_reply: t is local sending local reply with status code: [%d]\n", t->uac[branch].reply->first_line.u.reply.statuscode);
308
-			reply_status = local_reply( t, t->uac[branch].reply, branch, t->uac[branch].reply->first_line.u.reply.statuscode, &cancel_data );
307
+			LM_DBG("t is local - sending reply with status code: [%d]\n",
308
+					t->uac[branch].reply->first_line.u.reply.statuscode);
309
+			reply_status = local_reply( t, t->uac[branch].reply, branch,
310
+					t->uac[branch].reply->first_line.u.reply.statuscode,
311
+					&cancel_data );
309 312
 			if (reply_status == RPS_COMPLETED) {
310 313
 				/* no more UAC FR/RETR (if I received a 2xx, there may
311 314
 				* be still pending branches ...
... ...
@@ -322,12 +325,15 @@ int t_continue(unsigned int hash_index, unsigned int label,
322 325
 			}
323 326
 
324 327
 		} else {
325
-			LOG(L_DBG,"DEBUG: t_continue_reply: t is NOT local sending relaying reply with status code: [%d]\n", t->uac[branch].reply->first_line.u.reply.statuscode);
326
-			int do_put_on_wait = 0;
328
+			LM_DBG("t is not local - relaying reply with status code: [%d]\n",
329
+					t->uac[branch].reply->first_line.u.reply.statuscode);
330
+			do_put_on_wait = 0;
327 331
 			if(t->uac[branch].reply->first_line.u.reply.statuscode>=200){
328 332
 				do_put_on_wait = 1;
329 333
 			}
330
-			reply_status=relay_reply( t, t->uac[branch].reply, branch, t->uac[branch].reply->first_line.u.reply.statuscode, &cancel_data, do_put_on_wait );
334
+			reply_status=relay_reply( t, t->uac[branch].reply, branch,
335
+					t->uac[branch].reply->first_line.u.reply.statuscode,
336
+					&cancel_data, do_put_on_wait );
331 337
 			if (reply_status == RPS_COMPLETED) {
332 338
 				/* no more UAC FR/RETR (if I received a 2xx, there may
333 339
 				be still pending branches ...
... ...
@@ -356,8 +362,8 @@ int t_continue(unsigned int hash_index, unsigned int label,
356 362
 
357 363
 		/* update FR/RETR timers on provisional replies */
358 364
 
359
-		int msg_status=t->uac[branch].reply->REPLY_STATUS;
360
-		int last_uac_status=t->uac[branch].last_received;
365
+		msg_status=t->uac[branch].reply->REPLY_STATUS;
366
+		last_uac_status=t->uac[branch].last_received;
361 367
 
362 368
 		if (is_invite(t) && msg_status<200 &&
363 369
 			( cfg_get(tm, tm_cfg, restart_fr_on_each_reply) ||
... ...
@@ -376,9 +382,7 @@ done:
376 382
 	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE){
377 383
 		/* unref the transaction */
378 384
 		t_unref(t->uas.request);
379
-	}else{
380
-		struct hdr_field *hdr, *prev = 0, *tmp = 0;
381
-
385
+	} else {
382 386
 		tm_ctx_set_branch_index(T_BR_UNDEFINED);        
383 387
 		/* unref the transaction */
384 388
 		t_unref(t->uac[branch].reply);
... ...
@@ -441,7 +445,7 @@ kill_trans:
441 445
 
442 446
 	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE){
443 447
 		t_unref(t->uas.request);
444
-	}else{
448
+	} else {
445 449
 		/* unref the transaction */
446 450
 		t_unref(t->uac[branch].reply);
447 451
 	}