Преглед изворни кода

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

Jan Janak пре 19 година
родитељ
комит
c16e9887cf
2 измењених фајлова са 77 додато и 1 уклоњено
  1. 64 0
      sr_module.c
  2. 13 1
      sr_module.h

+ 64 - 0
sr_module.c

@@ -799,6 +799,22 @@ int fix_param(int type, void** param)
 			goto error;
 		}
 		break;
+
+	case FPARAM_SELECT:
+		name.s = (char*)*param;
+		name.len = strlen(name.s);
+		trim(&name);
+		if (!name.len || name.s[0] != '@') {
+			     /* Not a select identifier */
+			pkg_free(p);
+			return 1;
+		}
+
+		if (parse_select(&name.s, &p->v.select) < 0) {
+			ERR("Error while parsing select identifier\n");
+			goto error;
+		}
+		break;
 	}
 
 	p->type = type;
@@ -809,3 +825,51 @@ int fix_param(int type, void** param)
 	pkg_free(p);
 	return E_UNSPEC;
 }
+
+
+/*
+ * Get the function parameter value as string
+ * Return values:  0 - Success
+ *                 1 - Incompatible type (i.e. int)
+ *                -1 - Cannot get value
+ */
+int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
+{
+    int_str val;
+    int ret;
+    avp_t* avp;
+
+    switch(param->type) {
+    case FPARAM_INT:
+    case FPARAM_REGEX:
+    case FPARAM_UNSPEC:
+	return 1;
+
+    case FPARAM_STRING:
+	dst->s = param->v.asciiz;
+	dst->len = strlen(param->v.asciiz);
+	break;
+
+    case FPARAM_STR:
+	*dst = param->v.str;
+	break;
+
+    case FPARAM_AVP:
+	avp = search_first_avp(param->v.avp.flags, param->v.avp.name, &val, 0);
+	if (avp && avp->flags & AVP_VAL_STR) {
+	    *dst = val.s;
+	} else {
+	    DBG("Value for AVP function parameter '%s' not found or is not string\n", param->orig);
+	    return -1;
+	}
+	break;
+
+    case FPARAM_SELECT:
+	ret = run_select(dst, param->v.select, msg);
+	if (ret < 0 || ret > 0) return -1;
+	break;
+    }
+
+    return 0;
+}
+

+ 13 - 1
sr_module.h

@@ -48,6 +48,7 @@
 #include "version.h"
 #include "rpc.h"
 #include "route_struct.h"
+#include "str.h"
 
 typedef  struct module_exports* (*module_register)();
 typedef  int (*cmd_function)(struct sip_msg*, char*, char*);
@@ -117,6 +118,7 @@ enum {
 	FPARAM_INT    = (1 << 2),
 	FPARAM_REGEX  = (1 << 3),
 	FPARAM_AVP    = (1 << 5),
+	FPARAM_SELECT = (1 << 6),
 };
 
 /*
@@ -131,6 +133,7 @@ typedef struct fparam {
 		int i;             /* Integer value */
 		regex_t* regex;    /* Compiled regular expression */
 		avp_ident_t avp;   /* AVP identifier */
+	        select_t* select;  /* select structure */ 
 	} v;
 } fparam_t;
 
@@ -138,7 +141,7 @@ typedef struct fparam {
 typedef struct cmd_export_ cmd_export_t;
 typedef struct param_export_ param_export_t;
 
-struct module_exports{
+struct module_exports {
 	char* name;                     /* null terminated module name */
 
 	cmd_export_t* cmds;             /* null terminated array of the exported
@@ -235,6 +238,15 @@ int fixup_regex_2(void** param, int param_no);
  */
 int fix_param(int type, void** param);
 
+/*
+ * Get the function parameter value as string
+ * Return values:  0 - Success
+ *                 1 - Incompatible type (i.e. int)
+ *                -1 - Cannot get value
+ */
+int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param);
+
+
 /* API function to get other parameters from fixup */
 action_u_t *fixup_get_param(void **cur_param, int cur_param_no, int required_param_no);
 int fixup_get_param_count(void **cur_param, int cur_param_no);