Browse code

- basics for users preferences: - 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

Bogdan-Andrei Iancu authored on 06/02/2004 18:56:49
Showing 11 changed files
... ...
@@ -43,7 +43,7 @@ skip_cfg_install?=
43 43
 skip_modules?=
44 44
 
45 45
 # if not set on the cmd. line or the env, exclude this modules:
46
-exclude_modules?= 			cpl cpl-c ext extcmd \
46
+exclude_modules?= 			cpl ext extcmd \
47 47
 							postgres snmp \
48 48
 							im radius_acc radius_auth \
49 49
 							jabber mysql \
... ...
@@ -280,8 +280,7 @@ DEFS+= $(extra_defs) \
280 280
 	 -DUSE_IPV6 \
281 281
 	 -DUSE_TCP \
282 282
 	 -DDISABLE_NAGLE \
283
-	# -DDBG_QM_MALLOC \
284
-	# -DF_MALLOC \
283
+	 -DF_MALLOC \
285 284
 	# -DDBG_F_MALLOC \
286 285
 	# -DDBG_QM_MALLOC \
287 286
 	 #-DF_MALLOC \
... ...
@@ -56,6 +56,7 @@
56 56
 #include "mem/mem.h"
57 57
 #include "globals.h"
58 58
 #include "dset.h"
59
+#include "usr_avp.h"
59 60
 #ifdef USE_TCP
60 61
 #include "tcp_server.h"
61 62
 #endif
... ...
@@ -657,6 +658,21 @@ int do_action(struct action* a, struct sip_msg* msg)
657 657
 #endif
658 658
 			ret=1; /* continue processing */
659 659
 			break;
660
+		case LOAD_AVP_T:
661
+			if (a->p1_type!=NUMBER_ST || a->p2_type!=STRING_ST ||
662
+			a->p3_type!=NUMBER_ST) {
663
+				LOG(L_CRIT,"BUG: do_action: bad load_avp(%d,%d,%d) params "
664
+						"types\n",a->p1_type,a->p2_type,a->p3_type);
665
+				ret=E_BUG;
666
+				break;
667
+			}
668
+			/* load the attribute(s)*/
669
+			if ( load_avp( msg, (int)a->p1.number, a->p2.string,
670
+			(int)a->p3.number)!=0 ) {
671
+				LOG(L_ERR,"ERROR:do_action: load avp failed\n");
672
+				ret=E_UNSPEC;
673
+			}
674
+			break;
660 675
 		default:
661 676
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
662 677
 	}
... ...
@@ -114,6 +114,7 @@ IF				"if"
114 114
 ELSE			"else"
115 115
 SET_ADV_ADDRESS	"set_advertised_address"
116 116
 SET_ADV_PORT	"set_advertised_port"
117
+LOAD_AVP		"load_avp"
117 118
 
118 119
 /*ACTION LVALUES*/
119 120
 URIHOST			"uri:host"
... ...
@@ -168,8 +169,9 @@ MEMLOG		"memlog"|"mem_log"
168 168
 SIP_WARNING sip_warning
169 169
 FIFO fifo
170 170
 FIFO_DIR  fifo_dir
171
-FIFO_DB_URL fifo_db_url
172 171
 FIFO_MODE fifo_mode
172
+FIFO_DB_URL fifo_db_url
173
+AVP_DB_URL  avp_db_url
173 174
 SERVER_SIGNATURE server_signature
174 175
 REPLY_TO_VIA reply_to_via
175 176
 USER		"user"|"uid"
... ...
@@ -285,6 +287,7 @@ EAT_ABLE	[\ \t\b\r]
285 285
 <INITIAL>{FORCE_RPORT}	{ count(); yylval.strval=yytext; return FORCE_RPORT; }
286 286
 <INITIAL>{FORCE_TCP_ALIAS}	{ count(); yylval.strval=yytext;
287 287
 								return FORCE_TCP_ALIAS; }
288
+<INITIAL>{LOAD_AVP}	{ count(); yylval.strval=yytext; return LOAD_AVP; }
288 289
 	
289 290
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
290 291
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }
... ...
@@ -358,6 +361,7 @@ EAT_ABLE	[\ \t\b\r]
358 358
 <INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
359 359
 <INITIAL>{FIFO_DB_URL}	{ count(); yylval.strval=yytext; return FIFO_DB_URL; }
360 360
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
361
+<INITIAL>{AVP_DB_URL}	{ count(); yylval.strval=yytext; return AVP_DB_URL; }
361 362
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
362 363
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
363 364
 <INITIAL>{ADVERTISED_ADDRESS}	{	count(); yylval.strval=yytext;
... ...
@@ -72,6 +72,7 @@
72 72
 #include "ip_addr.h"
73 73
 #include "socket_info.h"
74 74
 #include "name_alias.h"
75
+#include "usr_avp.h"
75 76
 #include "ut.h"
76 77
 
77 78
 
... ...
@@ -174,6 +175,7 @@ static struct id_list* mk_listen_id(char*, int, int);
174 174
 %token UDP
175 175
 %token TCP
176 176
 %token TLS
177
+%token LOAD_AVP
177 178
 
178 179
 /* config vars. */
179 180
 %token DEBUG
... ...
@@ -194,6 +196,7 @@ static struct id_list* mk_listen_id(char*, int, int);
194 194
 %token FIFO_DIR
195 195
 %token FIFO_MODE
196 196
 %token FIFO_DB_URL
197
+%token AVP_DB_URL
197 198
 %token SERVER_SIGNATURE
198 199
 %token REPLY_TO_VIA
199 200
 %token LOADMODULE
... ...
@@ -394,7 +397,9 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
394 394
 		| FIFO_MODE EQUAL NUMBER { fifo_mode=$3; }
395 395
 		| FIFO_MODE EQUAL error { yyerror("int value expected"); }
396 396
 		| FIFO_DB_URL EQUAL STRING { fifo_db_url=$3; }
397
-		| FIFO_DB_URL EQUAL error { yyerror("string value expected"); }
397
+		| FIFO_DB_URL EQUAL error  { yyerror("string value expected"); }
398
+		| AVP_DB_URL EQUAL STRING { avp_db_url=$3; }
399
+		| AVP_DB_URL EQUAL error  { yyerror("string value expected"); }
398 400
 		| USER EQUAL STRING     { user=$3; }
399 401
 		| USER EQUAL ID         { user=$3; }
400 402
 		| USER EQUAL error      { yyerror("string value expected"); }
... ...
@@ -1461,9 +1466,29 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1461 1461
 					#endif
1462 1462
 										}
1463 1463
 		| FORCE_TCP_ALIAS LPAREN error RPAREN	{$$=0; 
1464
-												yyerror("bad argument,"
1465
-														" number expected");
1466
-												}
1464
+					yyerror("bad argument, number expected");
1465
+					}
1466
+		| LOAD_AVP LPAREN STRING COMMA NUMBER RPAREN {
1467
+					$$=(void*)get_user_type( $3 );
1468
+					if ($$==(void*)-1) {
1469
+						yyerror("unknown user type in arg 1 for "
1470
+							"load_avp(x,x)");
1471
+					} else {
1472
+						$$=mk_action3( LOAD_AVP_T, NUMBER_ST, STRING_ST,
1473
+							NUMBER_ST, $$, 0,(void*)$5);
1474
+					}
1475
+					}
1476
+		| LOAD_AVP LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
1477
+					$$=(void*)get_user_type( $3 );
1478
+					if ($$==(void*)-1) {
1479
+						yyerror("unknown user type in arg 1 for "
1480
+							"load_avp(x,x,x)");
1481
+					} else {
1482
+						$$=mk_action3( LOAD_AVP_T, NUMBER_ST, STRING_ST,
1483
+							NUMBER_ST, $$, $5, (void*)$7);
1484
+					}
1485
+					}
1486
+		| LOAD_AVP error { $$=0; yyerror("missing '(' or ')' ?"); }
1467 1487
 		| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
1468 1488
 								$$=0;
1469 1489
 								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
... ...
@@ -107,6 +107,9 @@ extern int fifo_mode;
107 107
 char extern *fifo_dir; /* dir. where  reply fifos are allowed */
108 108
 extern char *fifo_db_url;  /* db url used by db_fifo interface */
109 109
 
110
+/* AVP configuration */
111
+extern char *avp_db_url;  /* db url used by user preferences (AVPs) */
112
+
110 113
 /* moved to pt.h
111 114
 extern int *pids;
112 115
 extern int process_no;
... ...
@@ -45,6 +45,7 @@
45 45
  *  2003-06-29  replaced port_no_str snprintf w/ int2str (andrei)
46 46
  *  2003-10-10  added switch for config check (-c) (andrei)
47 47
  *  2003-10-24  converted to the new socket_info lists (andrei)
48
+ *  2004-02-06  added support for user pref. - init_avp_child() (bogdan)
48 49
  *
49 50
  */
50 51
 
... ...
@@ -93,6 +94,7 @@
93 93
 #include "parser/parse_hname2.h"
94 94
 #include "parser/digest/digest_parser.h"
95 95
 #include "fifo_server.h"
96
+#include "usr_avp.h"
96 97
 #include "name_alias.h"
97 98
 #include "hash_func.h"
98 99
 #include "pt.h"
... ...
@@ -843,6 +845,10 @@ int main_loop()
843 843
 			LOG(L_ERR, "main_dontfork: init_child failed\n");
844 844
 			goto error;
845 845
 		}
846
+		if (init_avp_child(1)<0) {
847
+			LOG(L_ERR, "init_avp_child failed\n");
848
+			goto error;
849
+		}
846 850
 
847 851
 		is_main=1; /* hack 42: call init_child with is_main=0 in case
848 852
 					 some modules wants to fork a child */
... ...
@@ -924,6 +930,10 @@ int main_loop()
924 924
 					}
925 925
 #endif
926 926
 					bind_address=si; /* shortcut */
927
+					if (init_avp_child(i + 1)<0) {
928
+						LOG(L_ERR, "init_avp_child failed\n");
929
+						goto error;
930
+					}
927 931
 					if (init_child(i + 1) < 0) {
928 932
 						LOG(L_ERR, "init_child failed\n");
929 933
 						goto error;
... ...
@@ -54,6 +54,7 @@
54 54
  *  2003-11-11: build_lump_rpl() removed, add_lump_rpl() has flags (bogdan)
55 55
  *  2003-12-04  global TM callbacks switched to per transaction callbacks
56 56
  *              (bogdan)
57
+ *  2004-02-06: support for user pref. added - destroy_avps (bogdan)
57 58
  */
58 59
 
59 60
 
... ...
@@ -76,6 +77,7 @@
76 76
 #include "../../tags.h"
77 77
 #include "../../data_lump.h"
78 78
 #include "../../data_lump_rpl.h"
79
+#include "../../usr_avp.h"
79 80
 
80 81
 #include "t_hooks.h"
81 82
 #include "t_funcs.h"
... ...
@@ -515,12 +517,14 @@ static inline int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
515 515
 		/* avoid recursion -- if failure_route forwards, and does not 
516 516
 		 * set next failure route, failure_route will not be rentered
517 517
 		 * on failure */
518
-		//goto_on_negative = 0;
519 518
 		on_failure = t->on_negative;
520 519
 		t->on_negative=0;
521 520
 		/* run a reply_route action if some was marked */
522 521
 		if (run_actions(failure_rlist[on_failure], &fake_req)<0)
523 522
 			LOG(L_ERR, "ERROR: run_failure_handlers: Error in do_action\n");
523
+		/* destroy any eventual avps */
524
+		if (users_avps)
525
+			destroy_avps();
524 526
 	}
525 527
 
526 528
 	/* restore original environment and free the fake msg */
... ...
@@ -1150,6 +1154,9 @@ int reply_received( struct sip_msg  *p_msg )
1150 1150
 		if (t->uas.request) p_msg->flags=t->uas.request->flags;
1151 1151
 	 	if (run_actions(onreply_rlist[t->on_reply], p_msg)<0) 
1152 1152
 			LOG(L_ERR, "ERROR: on_reply processing failed\n");
1153
+		/* destroy any eventual avps */
1154
+		if (users_avps)
1155
+			destroy_avps();
1153 1156
 		/* transfer current message context back to t */
1154 1157
 		if (t->uas.request) t->uas.request->flags=p_msg->flags;
1155 1158
 	}
... ...
@@ -33,6 +33,7 @@
33 33
  * 2003-02-10 moved zero-term in the calling functions (udp_receive &
34 34
  *            tcp_read_req)
35 35
  * 2003-08-13 fixed exec_pre_cb returning 0 (backported from stable) (andrei)
36
+ * 2004-02-06 added user preferences support - destroy_avps() (bogdan)
36 37
  */
37 38
 
38 39
 
... ...
@@ -52,6 +53,7 @@
52 52
 #include "ip_addr.h"
53 53
 #include "script_cb.h"
54 54
 #include "dset.h"
55
+#include "usr_avp.h"
55 56
 
56 57
 #include "tcp_server.h" /* for tcpconn_add_alias */
57 58
 
... ...
@@ -153,13 +155,15 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
153 153
 #ifdef  STATS
154 154
 		gettimeofday( & tvb, &tz );
155 155
 #endif
156
-		if (run_actions(rlist[0], msg)<0){
157
-
156
+		if (run_actions(rlist[0], msg)<0) {
158 157
 			LOG(L_WARN, "WARNING: receive_msg: "
159 158
 					"error while trying script\n");
160 159
 			goto error;
161 160
 		}
162 161
 
162
+		/* ... free posible loaded avps */
163
+		if (users_avps)
164
+			destroy_avps();
163 165
 
164 166
 #ifdef STATS
165 167
 		gettimeofday( & tve, &tz );
... ...
@@ -327,6 +327,9 @@ void print_action(struct action* a)
327 327
 			case FORCE_TCP_ALIAS_T:
328 328
 					DBG("force_tcp_alias(");
329 329
 					break;
330
+			case LOAD_AVP_T:
331
+					DBG("load_avp(");
332
+					break;
330 333
 			default:
331 334
 					DBG("UNKNOWN(");
332 335
 		}
... ...
@@ -72,7 +72,8 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
72 72
 		FORCE_RPORT_T,
73 73
 		SET_ADV_ADDR_T,
74 74
 		SET_ADV_PORT_T,
75
-		FORCE_TCP_ALIAS_T
75
+		FORCE_TCP_ALIAS_T,
76
+		LOAD_AVP_T
76 77
 };
77 78
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
78 79
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,