Browse code

3-digit reply code introduced to FIFO server

Jiri Kuthan authored on 21/09/2002 08:42:21
Showing 5 changed files
... ...
@@ -417,7 +417,7 @@ static void fifo_server(FILE *fifo_stream)
417 417
 		if (f==0) {
418 418
 			LOG(L_ERR, "ERROR: fifo_server: command %s is not available\n",
419 419
 				command);
420
-			fifo_reply(file, "[%s not available]\n", command);
420
+			fifo_reply(file, "500 command '%s' not available\n", command);
421 421
 			goto consume;
422 422
 		}
423 423
 		if (f->f(fifo_stream, file)<0) {
... ...
@@ -511,7 +511,7 @@ int open_fifo_server()
511 511
 static int print_version_cmd( FILE *stream, char *response_file )
512 512
 {
513 513
 	if (response_file) {
514
-		fifo_reply(response_file, SERVER_HDR CRLF );
514
+		fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF );
515 515
 	} else {
516 516
 		LOG(L_ERR, "ERROR: no file for print_version_cmd\n");
517 517
 	}
... ...
@@ -532,12 +532,12 @@ static int print_fifo_cmd( FILE *stream, char *response_file )
532 532
 	}
533 533
 	if (!read_line(text, MAX_PRINT_TEXT, stream, &text_len)) {
534 534
 		fifo_reply(response_file, 
535
-			"ERROR: print_fifo_cmd: too big text");
535
+			"500 print_fifo_cmd: too big text");
536 536
 		return -1;
537 537
 	}
538 538
 	/* now the work begins */
539 539
 	if (response_file) {
540
-		fifo_reply(response_file, text );
540
+		fifo_reply(response_file, "200 ok\n%s\n", text );
541 541
 	} else {
542 542
 		LOG(L_INFO, "INFO: print_fifo_cmd: %.*s\n", 
543 543
 			text_len, text );
... ...
@@ -555,7 +555,8 @@ static int uptime_fifo_cmd( FILE *stream, char *response_file )
555 555
 	}
556 556
 
557 557
 	time(&now);
558
-	fifo_reply( response_file, "Now: %sUp Since: %sUp time: %.0f [sec]\n",
558
+	fifo_reply( response_file, "200 ok\n"
559
+		"Now: %sUp Since: %sUp time: %.0f [sec]\n",
559 560
 		ctime(&now), up_since_ctime, difftime(now, up_since) );
560 561
 
561 562
 	return 1;
... ...
@@ -577,11 +578,10 @@ static int which_fifo_cmd(FILE *stream, char *response_file )
577 578
 			response_file );
578 579
 		return -1;
579 580
 	}
580
-	fputs( "------ Begin of registered FIFO commands -----------\n", reply_pipe);
581
+	fputs( "200 ok\n", reply_pipe);
581 582
 	for(c=cmd_list; c; c=c->next) {
582 583
 		fprintf( reply_pipe, "%s\n", c->name );
583 584
 	}
584
-	fputs( "------ End of registered FIFO commands -----------\n", reply_pipe);
585 585
 
586 586
 	fclose(reply_pipe);
587 587
 	return 1;
... ...
@@ -603,6 +603,7 @@ static int ps_fifo_cmd(FILE *stream, char *response_file )
603 603
 		return -1;
604 604
 	}
605 605
 
606
+	fputs( "200 ok\n", reply_pipe);
606 607
 	for (p=0; p<process_count();p++) 
607 608
 		fprintf( reply_pipe, "%d\t%d\t%s\n",
608 609
 			p, pt[p].pid, pt[p].desc );
... ...
@@ -91,6 +91,7 @@ int static fifo_stats( FILE *pipe, char *response_file )
91 91
 			response_file, strerror(errno) );
92 92
 		return -1;
93 93
 	}
94
+	fputs( "200 ok\n", file);
94 95
 	print_stats( file );
95 96
 	fclose(file);
96 97
 	
... ...
@@ -247,7 +247,7 @@ static void fifo_callback( struct cell *t, struct sip_msg *msg,
247 247
 	get_reply_status(&text,msg,code);
248 248
 	if (text.s==0) {
249 249
 		LOG(L_ERR, "ERROR: fifo_callback: get_reply_status failed\n");
250
-		fifo_reply(filename, "ERROR: fifo_callback: get_reply_status failed\n");
250
+		fifo_reply(filename, "500 fifo_callback: get_reply_status failed\n");
251 251
 		return;
252 252
 	}
253 253
 	fifo_reply(filename, "%.*s", text.len, text.s );
... ...
@@ -276,31 +276,31 @@ int fifo_uac( FILE *stream, char *response_file )
276 276
 		*/
277 277
 		LOG(L_ERR, "ERROR: fifo_uac: method expected\n");
278 278
 		fifo_reply(response_file, 
279
-			"ERROR: fifo_uac: method expected");
280
-		return -1;
279
+			"400 fifo_uac: method expected");
280
+		return 1;
281 281
 	}
282 282
 	DBG("DEBUG: fifo_uac: method: %.*s\n", sm.len, method );
283 283
 	if (!read_line(dst, MAX_DST, stream, &sd.len)||sd.len==0) {
284 284
 		fifo_reply(response_file, 
285
-			"ERROR: fifo_uac: destination expected\n");
285
+			"400 fifo_uac: destination expected\n");
286 286
 		LOG(L_ERR, "ERROR: fifo_uac: destination expected\n");
287
-		return -1;
287
+		return 1;
288 288
 	}
289 289
 	DBG("DEBUG: fifo_uac:  dst: %.*s\n", sd.len, dst );
290 290
 	/* now read header fields line by line */
291 291
 	if (!read_line_set(header, MAX_HEADER, stream, &sh.len)) {
292 292
 		fifo_reply(response_file, 
293
-			"ERROR: fifo_uac: HFs expected\n");
293
+			"400 fifo_uac: HFs expected\n");
294 294
 		LOG(L_ERR, "ERROR: fifo_uac: header fields expected\n");
295
-		return -1;
295
+		return 1;
296 296
 	}
297 297
 	DBG("DEBUG: fifo_uac: header: %.*s\n", sh.len, header );
298 298
 	/* and eventually body */
299 299
 	if (!read_body(body, MAX_BODY, stream, &sb.len)) {
300 300
 		fifo_reply(response_file, 
301
-			"ERROR: fifo_uac: body expected\n");
301
+			"400 fifo_uac: body expected\n");
302 302
 		LOG(L_ERR, "ERROR: fifo_uac: body expected\n");
303
-		return -1;
303
+		return 1;
304 304
 	}
305 305
 	DBG("DEBUG: fifo_uac: body: %.*s\n", sb.len, body );
306 306
 	DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n");
... ...
@@ -310,7 +310,9 @@ int fifo_uac( FILE *stream, char *response_file )
310 310
 		shmem_file=shm_malloc(fn_len);
311 311
 		if (shmem_file==0) {
312 312
 			LOG(L_ERR, "ERROR: fifo_uac: no shmem\n");
313
-			return -1;
313
+			fifo_reply(response_file, 
314
+				"500 fifo_uac: no shmem for shmem_file\n");
315
+			return 1;
314 316
 		}
315 317
 		memcpy(shmem_file, response_file, fn_len );
316 318
 	} else {
... ...
@@ -322,7 +324,7 @@ int fifo_uac( FILE *stream, char *response_file )
322 324
 		if (err2reason_phrase(ret, &sip_error, err_buf,
323 325
 				sizeof(err_buf), "FIFO/UAC" ) > 0 ) 
324 326
 		{
325
-			fifo_reply(response_file, "FIFO/UAC error: %d\n",
327
+			fifo_reply(response_file, "500 FIFO/UAC error: %d\n",
326 328
 				ret );
327 329
 		} else {
328 330
 			fifo_reply(response_file, err_buf );
... ...
@@ -367,38 +369,38 @@ int fifo_uac_from( FILE *stream, char *response_file )
367 369
 		*/
368 370
 		LOG(L_ERR, "ERROR: fifo_uac: method expected\n");
369 371
 		fifo_reply(response_file, 
370
-			"ERROR: fifo_uac: method expected");
371
-		return -1;
372
+			"400 fifo_uac: method expected");
373
+		return 1;
372 374
 	}
373 375
 	DBG("DEBUG: fifo_uac: method: %.*s\n", sm.len, method );
374 376
 	if (!read_line(from, MAX_FROM, stream, &sf.len)) {
375 377
 		fifo_reply(response_file, 
376
-			"ERROR: fifo_uac: from expected\n");
378
+			"400 fifo_uac: from expected\n");
377 379
 		LOG(L_ERR, "ERROR: fifo_uac: from expected\n");
378
-		return -1;
380
+		return 1;
379 381
 	}
380 382
 	DBG("DEBUG: fifo_uac:  from: %.*s\n", sf.len, from);
381 383
 	if (!read_line(dst, MAX_DST, stream, &sd.len)||sd.len==0) {
382 384
 		fifo_reply(response_file, 
383
-			"ERROR: fifo_uac: destination expected\n");
385
+			"400 fifo_uac: destination expected\n");
384 386
 		LOG(L_ERR, "ERROR: fifo_uac: destination expected\n");
385
-		return -1;
387
+		return 1;
386 388
 	}
387 389
 	DBG("DEBUG: fifo_uac:  dst: %.*s\n", sd.len, dst );
388 390
 	/* now read header fields line by line */
389 391
 	if (!read_line_set(header, MAX_HEADER, stream, &sh.len)) {
390 392
 		fifo_reply(response_file, 
391
-			"ERROR: fifo_uac: HFs expected\n");
393
+			"400 fifo_uac: HFs expected\n");
392 394
 		LOG(L_ERR, "ERROR: fifo_uac: header fields expected\n");
393
-		return -1;
395
+		return 1;
394 396
 	}
395 397
 	DBG("DEBUG: fifo_uac: header: %.*s\n", sh.len, header );
396 398
 	/* and eventually body */
397 399
 	if (!read_body(body, MAX_BODY, stream, &sb.len)) {
398 400
 		fifo_reply(response_file, 
399
-			"ERROR: fifo_uac: body expected\n");
401
+			"400 fifo_uac: body expected\n");
400 402
 		LOG(L_ERR, "ERROR: fifo_uac: body expected\n");
401
-		return -1;
403
+		return 1;
402 404
 	}
403 405
 	DBG("DEBUG: fifo_uac: body: %.*s\n", sb.len, body );
404 406
 	DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n");
... ...
@@ -408,7 +410,9 @@ int fifo_uac_from( FILE *stream, char *response_file )
408 410
 		shmem_file=shm_malloc(fn_len);
409 411
 		if (shmem_file==0) {
410 412
 			LOG(L_ERR, "ERROR: fifo_uac: no shmem\n");
411
-			return -1;
413
+			fifo_reply(response_file, 
414
+				"500 fifo_uac: no memory for shmem_file\n");
415
+			return 1;
412 416
 		}
413 417
 		memcpy(shmem_file, response_file, fn_len );
414 418
 	} else {
... ...
@@ -427,7 +431,7 @@ int fifo_uac_from( FILE *stream, char *response_file )
427 431
 		{
428 432
 			fifo_reply(response_file, err_buf );
429 433
 		} else {
430
-			fifo_reply(response_file, "FIFO/UAC error: %d\n",
434
+			fifo_reply(response_file, "500 FIFO/UAC error: %d\n",
431 435
 				ret );
432 436
 		}
433 437
 	}
... ...
@@ -117,6 +117,19 @@ prompt_pw() {
117 117
 	fi
118 118
 }
119 119
 
120
+# process output from FIFO server; if everything is ok
121
+# skip the first "ok" line and proceed to returned 
122
+# parameters
123
+filter_fl()
124
+{
125
+#	tail +2
126
+	
127
+	awk 'BEGIN {line=0;IGNORECASE=1;}
128
+		{line++}
129
+		line==1 && /^200 ok/ { next }
130
+		{ print }'
131
+}
132
+
120 133
 
121 134
 fifo_cmd()
122 135
 {
... ...
@@ -139,7 +152,7 @@ fifo_cmd()
139 152
 
140 153
 	# start reader now so that it is ready for replies
141 154
 	# immediately after a request was sent out
142
-	cat < $path &
155
+	cat < $path | filter_fl &
143 156
 
144 157
 	# issue request
145 158
 	if [ "$#" -eq 1 ] ; then
... ...
@@ -172,10 +185,15 @@ print_stats() {
172 185
 
173 186
 echo "[cycle #: $3; if constant make sure server lives and fifo is on]"
174 187
 
175
-cat < $2 &
188
+cat < $2 | filter_fl &
176 189
 cat > $SER_FIFO <<EOF
177 190
 :version:$1
178 191
 
192
+EOF
193
+wait
194
+
195
+cat < $2 | filter_fl &
196
+cat > $SER_FIFO << EOF
179 197
 :uptime:$1
180 198
 
181 199
 EOF
... ...
@@ -183,7 +201,7 @@ wait
183 201
 echo
184 202
 
185 203
 echo Transaction Statistics
186
-cat < $2 &
204
+cat < $2 | filter_fl &
187 205
 cat > $SER_FIFO <<EOF
188 206
 :t_stats:$1
189 207
 
... ...
@@ -192,7 +210,7 @@ wait
192 210
 echo
193 211
 
194 212
 echo Stateless Server Statistics
195
-cat < $2 &
213
+cat < $2 | filter_fl &
196 214
 cat > $SER_FIFO <<EOF
197 215
 :sl_stats:$1
198 216
 
... ...
@@ -201,7 +219,7 @@ wait
201 219
 echo
202 220
 
203 221
 echo UsrLoc Stats
204
-cat < $2 &
222
+cat < $2 | filter_fl &
205 223
 cat > $SER_FIFO <<EOF
206 224
 :ul_stats:$1
207 225
 
... ...
@@ -36,6 +36,7 @@ loadmodule "../sip_router/modules/acc/acc.so"
36 36
 loadmodule "../sip_router/modules/rr/rr.so"
37 37
 loadmodule "../sip_router/modules/maxfwd/maxfwd.so"
38 38
 loadmodule "../sip_router/modules/usrloc/usrloc.so"
39
+loadmodule "../sip_router/modules/registrar/registrar.so"
39 40
 
40 41
 # ----------------- setting module-specific parameters ---------------
41 42
 
... ...
@@ -102,6 +103,10 @@ route{
102 103
 #	t_relay();
103 104
 }
104 105
 
106
+route[3] {
107
+	lookup("location");
108
+}
109
+
105 110
 reply_route[1] {
106 111
 	# revert to original inbound uri -- good if we want
107 112
 	# to modify it; if we rewrite it completely as in the