MT#15177 implement functions to fetch billing profile details

Change-Id: I13d738b7f1207192843d31d35b234ff0b71dcfa3
changes/10/3710/11
Richard Fuchs 11 years ago
parent 720078128a
commit e3fe85f506

@ -43,7 +43,7 @@
+include ../../Makefile.modules
--- /dev/null
+++ b/modules/lcr_rate/lcr_rate_mod.c
@@ -0,0 +1,327 @@
@@ -0,0 +1,442 @@
+/*
+ * $Id$
+ *
@ -96,9 +96,15 @@
+static int child_init(int rank);
+
+static int lcr_rate(sip_msg_t *msg, char *su, char *sq);
+static int lcr_get_prepaid_from_uuid(sip_msg_t *msg, char *uuid, char *avp);
+static int lcr_get_profile_id_from_uuid(sip_msg_t *msg, char *uuid, char *avp);
+
+static cmd_export_t cmds[] = {
+ {"lcr_rate", (cmd_function)lcr_rate, 2, fixup_spve_spve, 0,
+ {"lcr_rate", lcr_rate, 2, fixup_spve_spve, 0,
+ REQUEST_ROUTE | FAILURE_ROUTE},
+ {"lcr_get_prepaid_from_uuid", lcr_get_prepaid_from_uuid, 2, fixup_spve_str, 0,
+ REQUEST_ROUTE | FAILURE_ROUTE},
+ {"lcr_get_profile_id_from_uuid", lcr_get_profile_id_from_uuid, 2, fixup_spve_str, 0,
+ REQUEST_ROUTE | FAILURE_ROUTE},
+ {0,}
+};
@ -371,3 +377,112 @@
+ LM_DBG("lcr_rate() done\n");
+ return ret;
+}
+
+static int get_avp(unsigned short *avp_type, int_str *avp_name, char *avp_s) {
+ pv_spec_t *avp_spec = NULL;
+ str *avp;
+
+ avp = (str *) avp_s;
+
+ if (pv_locate_name(avp) != avp->len)
+ {
+ LM_ERR("invalid AVP parameter\n");
+ return -1;
+ }
+
+ if (((avp_spec = pv_cache_get(avp)) == NULL)
+ || avp_spec->type!=PVT_AVP) {
+ LM_ERR("malformed or non AVP %s AVP definition\n", avp->s);
+ return -1;
+ }
+
+ if(pv_get_avp_name(0, &avp_spec->pvp, avp_name, avp_type)!=0)
+ {
+ LM_ERR("[%s]- invalid AVP definition\n", avp->s);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int get_profile_from_uuid(swr_profile_t *prof, sip_msg_t *msg, char *uuid_s) {
+ char *pc, *ip;
+ str uuid;
+
+ if (check_swrate_init())
+ return -1;
+
+ // validate parameters
+
+ if (get_str_fparam(&uuid, msg, (fparam_t *) uuid_s)) {
+ LM_ERR("unable to extract uuid parameter\n");
+ return -1;
+ }
+
+ if (!uuid.s || !*uuid.s) {
+ LM_ERR("empty uuid parameter\n");
+ return -1;
+ }
+
+ // split up "uuid;ip"
+
+ pc = strchr(uuid.s, ';');
+ if (!pc)
+ ip = NULL;
+ else {
+ *pc = 0;
+ ip = pc+1;
+ }
+
+ if (swrate_get_subscriber_billing_profile(prof, swrate_ptr, time(NULL), uuid.s, ip)) {
+ LM_ERR("swrate call returned error\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int lcr_get_prepaid_from_uuid(sip_msg_t *msg, char *uuid_s, char *avp_s) {
+ swr_profile_t prof;
+ unsigned short avp_type = 0;
+ int_str avp_val;
+ int_str avp_name;
+
+ if (get_profile_from_uuid(&prof, msg, uuid_s))
+ return -1;
+ if (get_avp(&avp_type, &avp_name, avp_s))
+ return -1;
+
+ avp_val.s.s = prof.prepaid ? "1" : "0";
+ avp_val.s.len = 1;
+
+ if (add_avp(AVP_VAL_STR | avp_type, avp_name, avp_val) != 0)
+ {
+ LM_ERR("Failed to add result avp");
+ return -1;
+ }
+
+ return 1;
+}
+
+static int lcr_get_profile_id_from_uuid(sip_msg_t *msg, char *uuid_s, char *avp_s) {
+ swr_profile_t prof;
+ unsigned short avp_type = 0;
+ int_str avp_val;
+ int_str avp_name;
+
+ if (get_profile_from_uuid(&prof, msg, uuid_s))
+ return -1;
+ if (get_avp(&avp_type, &avp_name, avp_s))
+ return -1;
+
+ avp_val.s.s = int2str(prof.profile_id, &avp_val.s.len);
+
+ if (add_avp(AVP_VAL_STR | avp_type, avp_name, avp_val) != 0)
+ {
+ LM_ERR("Failed to add result avp");
+ return -1;
+ }
+
+ return 1;
+}

Loading…
Cancel
Save