t_uac_from introduced (good for faking From via FIFO)
authorJiri Kuthan <jiri@iptel.org>
Tue, 3 Sep 2002 02:40:39 +0000 (02:40 +0000)
committerJiri Kuthan <jiri@iptel.org>
Tue, 3 Sep 2002 02:40:39 +0000 (02:40 +0000)
modules/tm/config.h
modules/tm/tm.c
modules/tm/uac.c
modules/tm/uac.h

index 1baa5f3..8209939 100644 (file)
@@ -51,6 +51,7 @@
 #define MAX_HEADER     1024
 #define MAX_BODY       1024
 #define MAX_DST        512
+#define MAX_FROM 512
 
 /* messages generated by server */
 #define CANCELLING "cancelling"
index 0c97325..62f4660 100644 (file)
@@ -237,6 +237,10 @@ static int mod_init(void)
                LOG(L_CRIT, "cannot register fifo uac\n");
                return -1;
        }
+       if (register_fifo_cmd(fifo_uac_from, "t_uac_from", 0)<0) {
+               LOG(L_CRIT, "cannot register fifo uac\n");
+               return -1;
+       }
        
        if (init_tm_stats()<0) {
                LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n");
index 0a40952..5ef1d2c 100644 (file)
@@ -241,6 +241,7 @@ static void fifo_callback( struct cell *t, struct sip_msg *msg,
        }
 }      
 
+/* to be obsoleted in favor of fifo_uac_from */
 int fifo_uac( FILE *stream, char *response_file ) 
 {
        char method[MAX_METHOD];
@@ -310,3 +311,92 @@ int fifo_uac( FILE *stream, char *response_file )
        }
 }
 
+/* syntax:
+
+       :t_uac_from:[file] EOL
+       method EOL
+       [from] EOL (if none, server's default from is taken)
+       dst EOL (put in r-uri and To)
+       [CR-LF separated HFs]* EOL
+       EOL
+       [body] EOL
+       EOL
+
+*/
+
+int fifo_uac_from( FILE *stream, char *response_file ) 
+{
+       char method[MAX_METHOD];
+       char header[MAX_HEADER];
+       char body[MAX_BODY];
+       char dst[MAX_DST];
+       char from[MAX_FROM];
+       str sm, sh, sb, sd, sf;
+       char *shmem_file;
+       int fn_len;
+
+       sm.s=method; sh.s=header; sb.s=body; sd.s=dst;sf.s=from;
+       while(1) {
+               if (!read_line(method, MAX_METHOD, stream,&sm.len)||sm.len==0) {
+                       /* line breaking must have failed -- consume the rest
+                          and proceed to a new request
+                       */
+                       LOG(L_ERR, "ERROR: fifo_uac: method expected\n");
+                       fifo_reply(response_file, 
+                               "ERROR: 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");
+                       LOG(L_ERR, "ERROR: fifo_uac: from expected\n");
+                       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");
+                       LOG(L_ERR, "ERROR: fifo_uac: destination expected\n");
+                       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");
+                       LOG(L_ERR, "ERROR: fifo_uac: header fields expected\n");
+                       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");
+                       LOG(L_ERR, "ERROR: fifo_uac: body expected\n");
+                       return -1;
+               }
+               DBG("DEBUG: fifo_uac: body: %.*s\n", sb.len, body );
+               DBG("DEBUG: fifo_uac: EoL -- proceeding to transaction creation\n");
+               /* we got it all, initiate transaction now! */
+               if (response_file) {
+                       fn_len=strlen(response_file)+1;
+                       shmem_file=shm_malloc(fn_len);
+                       if (shmem_file==0) {
+                               LOG(L_ERR, "ERROR: fifo_uac: no shmem\n");
+                               return -1;
+                       }
+                       memcpy(shmem_file, response_file, fn_len );
+               } else {
+                       shmem_file=0;
+               }
+               /* HACK: there is yet a shortcoming -- if t_uac fails, callback
+                  will not be triggered and no feedback will be printed
+                  to shmem_file
+               */
+               t_uac(&sm,&sd,&sh,&sb, sf.len==0 ? 0 : &sf /* default from */,
+                       fifo_callback,shmem_file,0 /* no dialog */);
+               return 1;
+
+       }
+}
index 7e58e6e..69deadc 100644 (file)
@@ -55,4 +55,5 @@ int t_uac(
        struct dialog *dlg );
 
 int fifo_uac( FILE *stream, char *response_file );
+int fifo_uac_from( FILE *stream, char *response_file );
 #endif