Browse code

- Support for selects in fparam_t - get_str_fparam function which will return the value of fparam as string

Jan Janak authored on 04/07/2006 12:48:13
Showing 2 changed files
... ...
@@ -799,6 +799,22 @@ int fix_param(int type, void** param)
799 799
 			goto error;
800 800
 		}
801 801
 		break;
802
+
803
+	case FPARAM_SELECT:
804
+		name.s = (char*)*param;
805
+		name.len = strlen(name.s);
806
+		trim(&name);
807
+		if (!name.len || name.s[0] != '@') {
808
+			     /* Not a select identifier */
809
+			pkg_free(p);
810
+			return 1;
811
+		}
812
+
813
+		if (parse_select(&name.s, &p->v.select) < 0) {
814
+			ERR("Error while parsing select identifier\n");
815
+			goto error;
816
+		}
817
+		break;
802 818
 	}
803 819
 
804 820
 	p->type = type;
... ...
@@ -809,3 +825,51 @@ int fix_param(int type, void** param)
809 809
 	pkg_free(p);
810 810
 	return E_UNSPEC;
811 811
 }
812
+
813
+
814
+/*
815
+ * Get the function parameter value as string
816
+ * Return values:  0 - Success
817
+ *                 1 - Incompatible type (i.e. int)
818
+ *                -1 - Cannot get value
819
+ */
820
+int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
821
+{
822
+    int_str val;
823
+    int ret;
824
+    avp_t* avp;
825
+
826
+    switch(param->type) {
827
+    case FPARAM_INT:
828
+    case FPARAM_REGEX:
829
+    case FPARAM_UNSPEC:
830
+	return 1;
831
+
832
+    case FPARAM_STRING:
833
+	dst->s = param->v.asciiz;
834
+	dst->len = strlen(param->v.asciiz);
835
+	break;
836
+
837
+    case FPARAM_STR:
838
+	*dst = param->v.str;
839
+	break;
840
+
841
+    case FPARAM_AVP:
842
+	avp = search_first_avp(param->v.avp.flags, param->v.avp.name, &val, 0);
843
+	if (avp && avp->flags & AVP_VAL_STR) {
844
+	    *dst = val.s;
845
+	} else {
846
+	    DBG("Value for AVP function parameter '%s' not found or is not string\n", param->orig);
847
+	    return -1;
848
+	}
849
+	break;
850
+
851
+    case FPARAM_SELECT:
852
+	ret = run_select(dst, param->v.select, msg);
853
+	if (ret < 0 || ret > 0) return -1;
854
+	break;
855
+    }
856
+
857
+    return 0;
858
+}
859
+
... ...
@@ -48,6 +48,7 @@
48 48
 #include "version.h"
49 49
 #include "rpc.h"
50 50
 #include "route_struct.h"
51
+#include "str.h"
51 52
 
52 53
 typedef  struct module_exports* (*module_register)();
53 54
 typedef  int (*cmd_function)(struct sip_msg*, char*, char*);
... ...
@@ -117,6 +118,7 @@ enum {
117 117
 	FPARAM_INT    = (1 << 2),
118 118
 	FPARAM_REGEX  = (1 << 3),
119 119
 	FPARAM_AVP    = (1 << 5),
120
+	FPARAM_SELECT = (1 << 6),
120 121
 };
121 122
 
122 123
 /*
... ...
@@ -131,6 +133,7 @@ typedef struct fparam {
131 131
 		int i;             /* Integer value */
132 132
 		regex_t* regex;    /* Compiled regular expression */
133 133
 		avp_ident_t avp;   /* AVP identifier */
134
+	        select_t* select;  /* select structure */ 
134 135
 	} v;
135 136
 } fparam_t;
136 137
 
... ...
@@ -138,7 +141,7 @@ typedef struct fparam {
138 138
 typedef struct cmd_export_ cmd_export_t;
139 139
 typedef struct param_export_ param_export_t;
140 140
 
141
-struct module_exports{
141
+struct module_exports {
142 142
 	char* name;                     /* null terminated module name */
143 143
 
144 144
 	cmd_export_t* cmds;             /* null terminated array of the exported
... ...
@@ -235,6 +238,15 @@ int fixup_regex_2(void** param, int param_no);
235 235
  */
236 236
 int fix_param(int type, void** param);
237 237
 
238
+/*
239
+ * Get the function parameter value as string
240
+ * Return values:  0 - Success
241
+ *                 1 - Incompatible type (i.e. int)
242
+ *                -1 - Cannot get value
243
+ */
244
+int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param);
245
+
246
+
238 247
 /* API function to get other parameters from fixup */
239 248
 action_u_t *fixup_get_param(void **cur_param, int cur_param_no, int required_param_no);
240 249
 int fixup_get_param_count(void **cur_param, int cur_param_no);