- basics for users preferences:
authorBogdan-Andrei Iancu <bogdan@voice-system.ro>
Fri, 6 Feb 2004 18:56:49 +0000 (18:56 +0000)
committerBogdan-Andrei Iancu <bogdan@voice-system.ro>
Fri, 6 Feb 2004 18:56:49 +0000 (18:56 +0000)
  - script param. "avp_db_url" added
- scrit function "load_avp" with 2 or 3 params added
- do_action updated
- init. of bd connection from core on startup per each proccess
- reseting avp list after main route and reply/failure_route execution

Makefile
Makefile.defs
action.c
cfg.lex
cfg.y
globals.h
main.c
modules/tm/t_reply.c
receive.c
route_struct.c
route_struct.h

index 3a4ce99..b59751c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -43,7 +43,7 @@ skip_cfg_install?=
 skip_modules?=
 
 # if not set on the cmd. line or the env, exclude this modules:
-exclude_modules?=                      cpl cpl-c ext extcmd \
+exclude_modules?=                      cpl ext extcmd \
                                                        postgres snmp \
                                                        im radius_acc radius_auth \
                                                        jabber mysql \
index d7f27ac..261b0ed 100644 (file)
@@ -280,8 +280,7 @@ DEFS+= $(extra_defs) \
         -DUSE_IPV6 \
         -DUSE_TCP \
         -DDISABLE_NAGLE \
-       # -DDBG_QM_MALLOC \
-       # -DF_MALLOC \
+        -DF_MALLOC \
        # -DDBG_F_MALLOC \
        # -DDBG_QM_MALLOC \
         #-DF_MALLOC \
index cd22d26..1ee61f3 100644 (file)
--- a/action.c
+++ b/action.c
@@ -56,6 +56,7 @@
 #include "mem/mem.h"
 #include "globals.h"
 #include "dset.h"
+#include "usr_avp.h"
 #ifdef USE_TCP
 #include "tcp_server.h"
 #endif
@@ -657,6 +658,21 @@ int do_action(struct action* a, struct sip_msg* msg)
 #endif
                        ret=1; /* continue processing */
                        break;
+               case LOAD_AVP_T:
+                       if (a->p1_type!=NUMBER_ST || a->p2_type!=STRING_ST ||
+                       a->p3_type!=NUMBER_ST) {
+                               LOG(L_CRIT,"BUG: do_action: bad load_avp(%d,%d,%d) params "
+                                               "types\n",a->p1_type,a->p2_type,a->p3_type);
+                               ret=E_BUG;
+                               break;
+                       }
+                       /* load the attribute(s)*/
+                       if ( load_avp( msg, (int)a->p1.number, a->p2.string,
+                       (int)a->p3.number)!=0 ) {
+                               LOG(L_ERR,"ERROR:do_action: load avp failed\n");
+                               ret=E_UNSPEC;
+                       }
+                       break;
                default:
                        LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
        }
diff --git a/cfg.lex b/cfg.lex
index b5f3522..09e6e09 100644 (file)
--- a/cfg.lex
+++ b/cfg.lex
@@ -114,6 +114,7 @@ IF                          "if"
 ELSE                   "else"
 SET_ADV_ADDRESS        "set_advertised_address"
 SET_ADV_PORT   "set_advertised_port"
+LOAD_AVP               "load_avp"
 
 /*ACTION LVALUES*/
 URIHOST                        "uri:host"
@@ -168,8 +169,9 @@ MEMLOG              "memlog"|"mem_log"
 SIP_WARNING sip_warning
 FIFO fifo
 FIFO_DIR  fifo_dir
-FIFO_DB_URL fifo_db_url
 FIFO_MODE fifo_mode
+FIFO_DB_URL fifo_db_url
+AVP_DB_URL  avp_db_url
 SERVER_SIGNATURE server_signature
 REPLY_TO_VIA reply_to_via
 USER           "user"|"uid"
@@ -285,6 +287,7 @@ EAT_ABLE    [\ \t\b\r]
 <INITIAL>{FORCE_RPORT} { count(); yylval.strval=yytext; return FORCE_RPORT; }
 <INITIAL>{FORCE_TCP_ALIAS}     { count(); yylval.strval=yytext;
                                                                return FORCE_TCP_ALIAS; }
+<INITIAL>{LOAD_AVP}    { count(); yylval.strval=yytext; return LOAD_AVP; }
        
 <INITIAL>{IF}  { count(); yylval.strval=yytext; return IF; }
 <INITIAL>{ELSE}        { count(); yylval.strval=yytext; return ELSE; }
@@ -358,6 +361,7 @@ EAT_ABLE    [\ \t\b\r]
 <INITIAL>{FIFO_DIR}    { count(); yylval.strval=yytext; return FIFO_DIR; }
 <INITIAL>{FIFO_DB_URL} { count(); yylval.strval=yytext; return FIFO_DB_URL; }
 <INITIAL>{FIFO_MODE}   { count(); yylval.strval=yytext; return FIFO_MODE; }
+<INITIAL>{AVP_DB_URL}  { count(); yylval.strval=yytext; return AVP_DB_URL; }
 <INITIAL>{SERVER_SIGNATURE}    { count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
 <INITIAL>{REPLY_TO_VIA}        { count(); yylval.strval=yytext; return REPLY_TO_VIA; }
 <INITIAL>{ADVERTISED_ADDRESS}  {       count(); yylval.strval=yytext;
diff --git a/cfg.y b/cfg.y
index eb9a9ed..c0fab6e 100644 (file)
--- a/cfg.y
+++ b/cfg.y
@@ -72,6 +72,7 @@
 #include "ip_addr.h"
 #include "socket_info.h"
 #include "name_alias.h"
+#include "usr_avp.h"
 #include "ut.h"
 
 
@@ -174,6 +175,7 @@ static struct id_list* mk_listen_id(char*, int, int);
 %token UDP
 %token TCP
 %token TLS
+%token LOAD_AVP
 
 /* config vars. */
 %token DEBUG
@@ -194,6 +196,7 @@ static struct id_list* mk_listen_id(char*, int, int);
 %token FIFO_DIR
 %token FIFO_MODE
 %token FIFO_DB_URL
+%token AVP_DB_URL
 %token SERVER_SIGNATURE
 %token REPLY_TO_VIA
 %token LOADMODULE
@@ -394,7 +397,9 @@ assign_stm: DEBUG EQUAL NUMBER { debug=$3; }
                | FIFO_MODE EQUAL NUMBER { fifo_mode=$3; }
                | FIFO_MODE EQUAL error { yyerror("int value expected"); }
                | FIFO_DB_URL EQUAL STRING { fifo_db_url=$3; }
-               | FIFO_DB_URL EQUAL error { yyerror("string value expected"); }
+               | FIFO_DB_URL EQUAL error  { yyerror("string value expected"); }
+               | AVP_DB_URL EQUAL STRING { avp_db_url=$3; }
+               | AVP_DB_URL EQUAL error  { yyerror("string value expected"); }
                | USER EQUAL STRING     { user=$3; }
                | USER EQUAL ID         { user=$3; }
                | USER EQUAL error      { yyerror("string value expected"); }
@@ -1461,9 +1466,29 @@ cmd:             FORWARD LPAREN host RPAREN      { $$=mk_action( FORWARD_T,
                                        #endif
                                                                                }
                | FORCE_TCP_ALIAS LPAREN error RPAREN   {$$=0; 
-                                                                                               yyerror("bad argument,"
-                                                                                                               " number expected");
-                                                                                               }
+                                       yyerror("bad argument, number expected");
+                                       }
+               | LOAD_AVP LPAREN STRING COMMA NUMBER RPAREN {
+                                       $$=(void*)get_user_type( $3 );
+                                       if ($$==(void*)-1) {
+                                               yyerror("unknown user type in arg 1 for "
+                                                       "load_avp(x,x)");
+                                       } else {
+                                               $$=mk_action3( LOAD_AVP_T, NUMBER_ST, STRING_ST,
+                                                       NUMBER_ST, $$, 0,(void*)$5);
+                                       }
+                                       }
+               | LOAD_AVP LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
+                                       $$=(void*)get_user_type( $3 );
+                                       if ($$==(void*)-1) {
+                                               yyerror("unknown user type in arg 1 for "
+                                                       "load_avp(x,x,x)");
+                                       } else {
+                                               $$=mk_action3( LOAD_AVP_T, NUMBER_ST, STRING_ST,
+                                                       NUMBER_ST, $$, $5, (void*)$7);
+                                       }
+                                       }
+               | LOAD_AVP error { $$=0; yyerror("missing '(' or ')' ?"); }
                | SET_ADV_ADDRESS LPAREN listen_id RPAREN {
                                                                $$=0;
                                                                if ((str_tmp=pkg_malloc(sizeof(str)))==0){
index 7f4a728..bf151f3 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -107,6 +107,9 @@ extern int fifo_mode;
 char extern *fifo_dir; /* dir. where  reply fifos are allowed */
 extern char *fifo_db_url;  /* db url used by db_fifo interface */
 
+/* AVP configuration */
+extern char *avp_db_url;  /* db url used by user preferences (AVPs) */
+
 /* moved to pt.h
 extern int *pids;
 extern int process_no;
diff --git a/main.c b/main.c
index 2e05bc6..1ebe9ac 100644 (file)
--- a/main.c
+++ b/main.c
@@ -45,6 +45,7 @@
  *  2003-06-29  replaced port_no_str snprintf w/ int2str (andrei)
  *  2003-10-10  added switch for config check (-c) (andrei)
  *  2003-10-24  converted to the new socket_info lists (andrei)
+ *  2004-02-06  added support for user pref. - init_avp_child() (bogdan)
  *
  */
 
@@ -93,6 +94,7 @@
 #include "parser/parse_hname2.h"
 #include "parser/digest/digest_parser.h"
 #include "fifo_server.h"
+#include "usr_avp.h"
 #include "name_alias.h"
 #include "hash_func.h"
 #include "pt.h"
@@ -843,6 +845,10 @@ int main_loop()
                        LOG(L_ERR, "main_dontfork: init_child failed\n");
                        goto error;
                }
+               if (init_avp_child(1)<0) {
+                       LOG(L_ERR, "init_avp_child failed\n");
+                       goto error;
+               }
 
                is_main=1; /* hack 42: call init_child with is_main=0 in case
                                         some modules wants to fork a child */
@@ -924,6 +930,10 @@ int main_loop()
                                        }
 #endif
                                        bind_address=si; /* shortcut */
+                                       if (init_avp_child(i + 1)<0) {
+                                               LOG(L_ERR, "init_avp_child failed\n");
+                                               goto error;
+                                       }
                                        if (init_child(i + 1) < 0) {
                                                LOG(L_ERR, "init_child failed\n");
                                                goto error;
index cb0372c..ac4575e 100644 (file)
@@ -54,6 +54,7 @@
  *  2003-11-11: build_lump_rpl() removed, add_lump_rpl() has flags (bogdan)
  *  2003-12-04  global TM callbacks switched to per transaction callbacks
  *              (bogdan)
+ *  2004-02-06: support for user pref. added - destroy_avps (bogdan)
  */
 
 
@@ -76,6 +77,7 @@
 #include "../../tags.h"
 #include "../../data_lump.h"
 #include "../../data_lump_rpl.h"
+#include "../../usr_avp.h"
 
 #include "t_hooks.h"
 #include "t_funcs.h"
@@ -515,12 +517,14 @@ static inline int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
                /* avoid recursion -- if failure_route forwards, and does not 
                 * set next failure route, failure_route will not be rentered
                 * on failure */
-               //goto_on_negative = 0;
                on_failure = t->on_negative;
                t->on_negative=0;
                /* run a reply_route action if some was marked */
                if (run_actions(failure_rlist[on_failure], &fake_req)<0)
                        LOG(L_ERR, "ERROR: run_failure_handlers: Error in do_action\n");
+               /* destroy any eventual avps */
+               if (users_avps)
+                       destroy_avps();
        }
 
        /* restore original environment and free the fake msg */
@@ -1150,6 +1154,9 @@ int reply_received( struct sip_msg  *p_msg )
                if (t->uas.request) p_msg->flags=t->uas.request->flags;
                if (run_actions(onreply_rlist[t->on_reply], p_msg)<0) 
                        LOG(L_ERR, "ERROR: on_reply processing failed\n");
+               /* destroy any eventual avps */
+               if (users_avps)
+                       destroy_avps();
                /* transfer current message context back to t */
                if (t->uas.request) t->uas.request->flags=p_msg->flags;
        }
index 5ff616d..5598041 100644 (file)
--- a/receive.c
+++ b/receive.c
@@ -33,6 +33,7 @@
  * 2003-02-10 moved zero-term in the calling functions (udp_receive &
  *            tcp_read_req)
  * 2003-08-13 fixed exec_pre_cb returning 0 (backported from stable) (andrei)
+ * 2004-02-06 added user preferences support - destroy_avps() (bogdan)
  */
 
 
@@ -52,6 +53,7 @@
 #include "ip_addr.h"
 #include "script_cb.h"
 #include "dset.h"
+#include "usr_avp.h"
 
 #include "tcp_server.h" /* for tcpconn_add_alias */
 
@@ -153,13 +155,15 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
 #ifdef  STATS
                gettimeofday( & tvb, &tz );
 #endif
-               if (run_actions(rlist[0], msg)<0){
-
+               if (run_actions(rlist[0], msg)<0) {
                        LOG(L_WARN, "WARNING: receive_msg: "
                                        "error while trying script\n");
                        goto error;
                }
 
+               /* ... free posible loaded avps */
+               if (users_avps)
+                       destroy_avps();
 
 #ifdef STATS
                gettimeofday( & tve, &tz );
index daa60ec..1d165a6 100644 (file)
@@ -327,6 +327,9 @@ void print_action(struct action* a)
                        case FORCE_TCP_ALIAS_T:
                                        DBG("force_tcp_alias(");
                                        break;
+                       case LOAD_AVP_T:
+                                       DBG("load_avp(");
+                                       break;
                        default:
                                        DBG("UNKNOWN(");
                }
index 70fa7bb..8d67442 100644 (file)
@@ -72,7 +72,8 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
                FORCE_RPORT_T,
                SET_ADV_ADDR_T,
                SET_ADV_PORT_T,
-               FORCE_TCP_ALIAS_T
+               FORCE_TCP_ALIAS_T,
+               LOAD_AVP_T
 };
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
                EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,