3-digit reply code introduced to FIFO server
authorJiri Kuthan <jiri@iptel.org>
Sat, 21 Sep 2002 08:42:21 +0000 (08:42 +0000)
committerJiri Kuthan <jiri@iptel.org>
Sat, 21 Sep 2002 08:42:21 +0000 (08:42 +0000)
fifo_server.c
modules/tm/t_stats.c
modules/tm/uac.c
scripts/sc
test/sf.cfg

index 2fe90c6..8cf88c2 100644 (file)
@@ -417,7 +417,7 @@ static void fifo_server(FILE *fifo_stream)
                if (f==0) {
                        LOG(L_ERR, "ERROR: fifo_server: command %s is not available\n",
                                command);
-                       fifo_reply(file, "[%s not available]\n", command);
+                       fifo_reply(file, "500 command '%s' not available\n", command);
                        goto consume;
                }
                if (f->f(fifo_stream, file)<0) {
@@ -511,7 +511,7 @@ int open_fifo_server()
 static int print_version_cmd( FILE *stream, char *response_file )
 {
        if (response_file) {
-               fifo_reply(response_file, SERVER_HDR CRLF );
+               fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF );
        } else {
                LOG(L_ERR, "ERROR: no file for print_version_cmd\n");
        }
@@ -532,12 +532,12 @@ static int print_fifo_cmd( FILE *stream, char *response_file )
        }
        if (!read_line(text, MAX_PRINT_TEXT, stream, &text_len)) {
                fifo_reply(response_file, 
-                       "ERROR: print_fifo_cmd: too big text");
+                       "500 print_fifo_cmd: too big text");
                return -1;
        }
        /* now the work begins */
        if (response_file) {
-               fifo_reply(response_file, text );
+               fifo_reply(response_file, "200 ok\n%s\n", text );
        } else {
                LOG(L_INFO, "INFO: print_fifo_cmd: %.*s\n", 
                        text_len, text );
@@ -555,7 +555,8 @@ static int uptime_fifo_cmd( FILE *stream, char *response_file )
        }
 
        time(&now);
-       fifo_reply( response_file, "Now: %sUp Since: %sUp time: %.0f [sec]\n",
+       fifo_reply( response_file, "200 ok\n"
+               "Now: %sUp Since: %sUp time: %.0f [sec]\n",
                ctime(&now), up_since_ctime, difftime(now, up_since) );
 
        return 1;
@@ -577,11 +578,10 @@ static int which_fifo_cmd(FILE *stream, char *response_file )
                        response_file );
                return -1;
        }
-       fputs( "------ Begin of registered FIFO commands -----------\n", reply_pipe);
+       fputs( "200 ok\n", reply_pipe);
        for(c=cmd_list; c; c=c->next) {
                fprintf( reply_pipe, "%s\n", c->name );
        }
-       fputs( "------ End of registered FIFO commands -----------\n", reply_pipe);
 
        fclose(reply_pipe);
        return 1;
@@ -603,6 +603,7 @@ static int ps_fifo_cmd(FILE *stream, char *response_file )
                return -1;
        }
 
+       fputs( "200 ok\n", reply_pipe);
        for (p=0; p<process_count();p++) 
                fprintf( reply_pipe, "%d\t%d\t%s\n",
                        p, pt[p].pid, pt[p].desc );
index 326df8e..bbb37d9 100644 (file)
@@ -91,6 +91,7 @@ int static fifo_stats( FILE *pipe, char *response_file )
                        response_file, strerror(errno) );
                return -1;
        }
+       fputs( "200 ok\n", file);
        print_stats( file );
        fclose(file);
        
index bfb26d9..14fa017 100644 (file)
@@ -247,7 +247,7 @@ static void fifo_callback( struct cell *t, struct sip_msg *msg,
        get_reply_status(&text,msg,code);
        if (text.s==0) {
                LOG(L_ERR, "ERROR: fifo_callback: get_reply_status failed\n");
-               fifo_reply(filename, "ERROR: fifo_callback: get_reply_status failed\n");
+               fifo_reply(filename, "500 fifo_callback: get_reply_status failed\n");
                return;
        }
        fifo_reply(filename, "%.*s", text.len, text.s );
@@ -276,31 +276,31 @@ int fifo_uac( FILE *stream, char *response_file )
                */
                LOG(L_ERR, "ERROR: fifo_uac: method expected\n");
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: method expected");
-               return -1;
+                       "400 fifo_uac: method expected");
+               return 1;
        }
        DBG("DEBUG: fifo_uac: method: %.*s\n", sm.len, method );
        if (!read_line(dst, MAX_DST, stream, &sd.len)||sd.len==0) {
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: destination expected\n");
+                       "400 fifo_uac: destination expected\n");
                LOG(L_ERR, "ERROR: fifo_uac: destination expected\n");
-               return -1;
+               return 1;
        }
        DBG("DEBUG: fifo_uac:  dst: %.*s\n", sd.len, dst );
        /* now read header fields line by line */
        if (!read_line_set(header, MAX_HEADER, stream, &sh.len)) {
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: HFs expected\n");
+                       "400 fifo_uac: HFs expected\n");
                LOG(L_ERR, "ERROR: fifo_uac: header fields expected\n");
-               return -1;
+               return 1;
        }
        DBG("DEBUG: fifo_uac: header: %.*s\n", sh.len, header );
        /* and eventually body */
        if (!read_body(body, MAX_BODY, stream, &sb.len)) {
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: body expected\n");
+                       "400 fifo_uac: body expected\n");
                LOG(L_ERR, "ERROR: fifo_uac: body expected\n");
-               return -1;
+               return 1;
        }
        DBG("DEBUG: fifo_uac: body: %.*s\n", sb.len, body );
        DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n");
@@ -310,7 +310,9 @@ int fifo_uac( FILE *stream, char *response_file )
                shmem_file=shm_malloc(fn_len);
                if (shmem_file==0) {
                        LOG(L_ERR, "ERROR: fifo_uac: no shmem\n");
-                       return -1;
+                       fifo_reply(response_file, 
+                               "500 fifo_uac: no shmem for shmem_file\n");
+                       return 1;
                }
                memcpy(shmem_file, response_file, fn_len );
        } else {
@@ -322,7 +324,7 @@ int fifo_uac( FILE *stream, char *response_file )
                if (err2reason_phrase(ret, &sip_error, err_buf,
                                sizeof(err_buf), "FIFO/UAC" ) > 0 ) 
                {
-                       fifo_reply(response_file, "FIFO/UAC error: %d\n",
+                       fifo_reply(response_file, "500 FIFO/UAC error: %d\n",
                                ret );
                } else {
                        fifo_reply(response_file, err_buf );
@@ -367,38 +369,38 @@ int fifo_uac_from( FILE *stream, char *response_file )
                */
                LOG(L_ERR, "ERROR: fifo_uac: method expected\n");
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: method expected");
-               return -1;
+                       "400 fifo_uac: method expected");
+               return 1;
        }
        DBG("DEBUG: fifo_uac: method: %.*s\n", sm.len, method );
        if (!read_line(from, MAX_FROM, stream, &sf.len)) {
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: from expected\n");
+                       "400 fifo_uac: from expected\n");
                LOG(L_ERR, "ERROR: fifo_uac: from expected\n");
-               return -1;
+               return 1;
        }
        DBG("DEBUG: fifo_uac:  from: %.*s\n", sf.len, from);
        if (!read_line(dst, MAX_DST, stream, &sd.len)||sd.len==0) {
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: destination expected\n");
+                       "400 fifo_uac: destination expected\n");
                LOG(L_ERR, "ERROR: fifo_uac: destination expected\n");
-               return -1;
+               return 1;
        }
        DBG("DEBUG: fifo_uac:  dst: %.*s\n", sd.len, dst );
        /* now read header fields line by line */
        if (!read_line_set(header, MAX_HEADER, stream, &sh.len)) {
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: HFs expected\n");
+                       "400 fifo_uac: HFs expected\n");
                LOG(L_ERR, "ERROR: fifo_uac: header fields expected\n");
-               return -1;
+               return 1;
        }
        DBG("DEBUG: fifo_uac: header: %.*s\n", sh.len, header );
        /* and eventually body */
        if (!read_body(body, MAX_BODY, stream, &sb.len)) {
                fifo_reply(response_file, 
-                       "ERROR: fifo_uac: body expected\n");
+                       "400 fifo_uac: body expected\n");
                LOG(L_ERR, "ERROR: fifo_uac: body expected\n");
-               return -1;
+               return 1;
        }
        DBG("DEBUG: fifo_uac: body: %.*s\n", sb.len, body );
        DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n");
@@ -408,7 +410,9 @@ int fifo_uac_from( FILE *stream, char *response_file )
                shmem_file=shm_malloc(fn_len);
                if (shmem_file==0) {
                        LOG(L_ERR, "ERROR: fifo_uac: no shmem\n");
-                       return -1;
+                       fifo_reply(response_file, 
+                               "500 fifo_uac: no memory for shmem_file\n");
+                       return 1;
                }
                memcpy(shmem_file, response_file, fn_len );
        } else {
@@ -427,7 +431,7 @@ int fifo_uac_from( FILE *stream, char *response_file )
                {
                        fifo_reply(response_file, err_buf );
                } else {
-                       fifo_reply(response_file, "FIFO/UAC error: %d\n",
+                       fifo_reply(response_file, "500 FIFO/UAC error: %d\n",
                                ret );
                }
        }
index 0cfed6d..90536db 100755 (executable)
@@ -117,6 +117,19 @@ prompt_pw() {
        fi
 }
 
+# process output from FIFO server; if everything is ok
+# skip the first "ok" line and proceed to returned 
+# parameters
+filter_fl()
+{
+#      tail +2
+       
+       awk 'BEGIN {line=0;IGNORECASE=1;}
+               {line++}
+               line==1 && /^200 ok/ { next }
+               { print }'
+}
+
 
 fifo_cmd()
 {
@@ -139,7 +152,7 @@ fifo_cmd()
 
        # start reader now so that it is ready for replies
        # immediately after a request was sent out
-       cat < $path &
+       cat < $path | filter_fl &
 
        # issue request
        if [ "$#" -eq 1 ] ; then
@@ -172,10 +185,15 @@ print_stats() {
 
 echo "[cycle #: $3; if constant make sure server lives and fifo is on]"
 
-cat < $2 &
+cat < $2 | filter_fl &
 cat > $SER_FIFO <<EOF
 :version:$1
 
+EOF
+wait
+
+cat < $2 | filter_fl &
+cat > $SER_FIFO << EOF
 :uptime:$1
 
 EOF
@@ -183,7 +201,7 @@ wait
 echo
 
 echo Transaction Statistics
-cat < $2 &
+cat < $2 | filter_fl &
 cat > $SER_FIFO <<EOF
 :t_stats:$1
 
@@ -192,7 +210,7 @@ wait
 echo
 
 echo Stateless Server Statistics
-cat < $2 &
+cat < $2 | filter_fl &
 cat > $SER_FIFO <<EOF
 :sl_stats:$1
 
@@ -201,7 +219,7 @@ wait
 echo
 
 echo UsrLoc Stats
-cat < $2 &
+cat < $2 | filter_fl &
 cat > $SER_FIFO <<EOF
 :ul_stats:$1
 
index 631b87b..d1a867a 100644 (file)
@@ -36,6 +36,7 @@ loadmodule "../sip_router/modules/acc/acc.so"
 loadmodule "../sip_router/modules/rr/rr.so"
 loadmodule "../sip_router/modules/maxfwd/maxfwd.so"
 loadmodule "../sip_router/modules/usrloc/usrloc.so"
+loadmodule "../sip_router/modules/registrar/registrar.so"
 
 # ----------------- setting module-specific parameters ---------------
 
@@ -102,6 +103,10 @@ route{
 #      t_relay();
 }
 
+route[3] {
+       lookup("location");
+}
+
 reply_route[1] {
        # revert to original inbound uri -- good if we want
        # to modify it; if we rewrite it completely as in the