Browse code

cnxcc: use fixup function helper for core to get string and int params

Daniel-Constantin Mierla authored on 24/11/2017 13:48:38
Showing 1 changed files
... ...
@@ -76,7 +76,7 @@ MODULE_VERSION
76 76
 data_t _data;
77 77
 struct dlg_binds _dlgbinds;
78 78
 
79
-static int __fixup_pvar(void **param, int param_no);
79
+static int cnxcc_set_max_credit_fixup(void **param, int param_no);
80 80
 
81 81
 /*
82 82
  *  module core functions
... ...
@@ -101,16 +101,13 @@ static int __pv_get_calls(
101 101
 /*
102 102
  * Billing management functions
103 103
  */
104
-static int __set_max_time(struct sip_msg *msg, char *number, char *str2);
105
-static int __update_max_time(struct sip_msg *msg, char *number, char *str2);
106
-static int __set_max_credit(struct sip_msg *msg, char *str_pv_client,
107
-		char *str_pv_credit, char *str_pv_cps, char *str_pv_inip,
108
-		char *str_pv_finp);
109
-static int __set_max_channels(
110
-		struct sip_msg *msg, char *str_pv_client, char *str_pv_max_chan);
111
-static int __get_channel_count(
112
-		struct sip_msg *msg, char *str_pv_client, char *str_pv_max_chan);
113
-static int __terminate_all(struct sip_msg *msg, char *str_pv_client);
104
+static int __set_max_credit(sip_msg_t *msg, char *pclient,
105
+		char *pcredit, char *pcps, char *pinitp, char *pfinishp);
106
+static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs);
107
+static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs);
108
+static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan);
109
+static int __get_channel_count(sip_msg_t *msg, char *pclient, char *pcount);
110
+static int __terminate_all(sip_msg_t *msg, char *pclient, char *p2);
114 111
 
115 112
 static void __start_billing(
116 113
 		str *callid, str *from_uri, str *to_uri, str tags[2]);
... ...
@@ -154,18 +151,18 @@ static pv_export_t mod_pvs[] = {
154 151
 };
155 152
 
156 153
 static cmd_export_t cmds[] = {
154
+	{"cnxcc_set_max_credit", (cmd_function) __set_max_credit, 5,
155
+		cnxcc_set_max_credit_fixup, NULL, ANY_ROUTE},
157 156
 	{"cnxcc_set_max_time", (cmd_function) __set_max_time, 2,
158
-		fixup_pvar_pvar, fixup_free_pvar_pvar, ANY_ROUTE},
157
+		fixup_spve_igp, fixup_free_spve_igp, ANY_ROUTE},
159 158
 	{"cnxcc_update_max_time", (cmd_function) __update_max_time, 2,
160
-		fixup_pvar_pvar, fixup_free_pvar_pvar, ANY_ROUTE},
161
-	{"cnxcc_set_max_credit", (cmd_function) __set_max_credit, 5,
162
-		__fixup_pvar, NULL, ANY_ROUTE},
159
+		fixup_spve_igp, fixup_free_spve_igp, ANY_ROUTE},
163 160
 	{"cnxcc_set_max_channels", (cmd_function) __set_max_channels, 2,
164
-		fixup_pvar_pvar, NULL, ANY_ROUTE},
161
+		fixup_spve_igp, fixup_free_spve_igp, ANY_ROUTE},
165 162
 	{"cnxcc_get_channel_count", (cmd_function) __get_channel_count, 2,
166
-		fixup_pvar_pvar, NULL, ANY_ROUTE},
163
+		fixup_spve_pvar, fixup_free_spve_pvar, ANY_ROUTE},
167 164
 	{"cnxcc_terminate_all", (cmd_function) __terminate_all, 1,
168
-		fixup_pvar_null, NULL, ANY_ROUTE},
165
+		fixup_spve_null, fixup_free_spve_null, ANY_ROUTE},
169 166
 	{0,0,0,0,0,0}
170 167
 };
171 168
 
... ...
@@ -225,25 +222,20 @@ struct module_exports exports = {
225 222
 };
226 223
 /* clang-format on */
227 224
 
228
-static int __fixup_pvar(void **param, int param_no)
225
+static int cnxcc_set_max_credit_fixup(void **param, int param_no)
229 226
 {
230
-	str var;
231
-
232
-	var.s = (char *)*param;
233
-	var.len = strlen(var.s);
234
-
235
-	if(fixup_pvar_null(param, 1)) {
236
-		LM_ERR("Invalid PV [%.*s] as parameter\n", var.len, var.s);
237
-		return E_CFG;
227
+	switch(param_no) {
228
+		case 1:
229
+		case 2:
230
+		case 3:
231
+			return fixup_spve_all(param, param_no);
232
+		case 4:
233
+		case 5:
234
+			return fixup_igp_all(param, param_no);
235
+		default:
236
+			LM_ERR("unexpected parameter number: %d\n", param_no);
237
+			return E_CFG;
238 238
 	}
239
-	/*
240
-	if (((pv_spec_t*)(*param))->setf == NULL)
241
-	{
242
-		LM_ERR("[%.*s] has to be writable\n", var.len, var.s);
243
-		return E_CFG;
244
-	} */
245
-
246
-	return 0;
247 239
 }
248 240
 
249 241
 static int __mod_init(void)
... ...
@@ -1578,151 +1570,129 @@ static inline int get_pv_value(
1578 1570
 	return 0;
1579 1571
 }
1580 1572
 
1581
-static int __set_max_credit(struct sip_msg *msg, char *str_pv_client,
1582
-		char *str_pv_credit, char *str_pv_cps, char *str_pv_inip,
1583
-		char *str_pv_finp)
1573
+static int __set_max_credit(sip_msg_t *msg, char *pclient,
1574
+		char *pcredit, char *pcps, char *pinitp, char *pfinishp)
1584 1575
 {
1585 1576
 	credit_data_t *credit_data = NULL;
1586 1577
 	call_t *call = NULL;
1587
-
1588
-	pv_spec_t *client_id_spec = (pv_spec_t *)str_pv_client,
1589
-			  *credit_spec = (pv_spec_t *)str_pv_credit,
1590
-			  *cps_spec = (pv_spec_t *)str_pv_cps,
1591
-			  *initial_pulse_spec = (pv_spec_t *)str_pv_inip,
1592
-			  *final_pulse_spec = (pv_spec_t *)str_pv_finp;
1593
-
1594
-	pv_value_t client_id_val, credit_val, cps_val, initial_pulse_val,
1595
-			final_pulse_val;
1596
-
1578
+	str sclient;
1579
+	str scredit;
1580
+	str scps;
1581
+	int initp;
1582
+	int finishp;
1597 1583
 	double credit = 0, cost_per_second = 0;
1598 1584
 
1599
-	unsigned int initial_pulse = 0, final_pulse = 0;
1600
-
1601
-	if(msg->first_line.type == SIP_REQUEST
1602
-			&& msg->first_line.u.request.method_value == METHOD_INVITE) {
1603
-		if(__has_to_tag(msg)) {
1604
-			LM_ERR("INVITE is a reINVITE\n");
1605
-			return -1;
1606
-		}
1607
-
1608
-		if(pv_get_spec_value(msg, client_id_spec, &client_id_val) != 0) {
1609
-			LM_ERR("Can't get client_id's value\n");
1610
-			return -1;
1611
-		}
1612
-
1613
-		if(pv_get_spec_value(msg, credit_spec, &credit_val) != 0) {
1614
-			LM_ERR("Can't get credit's value\n");
1615
-			return -1;
1616
-		}
1617
-
1618
-		credit = str2double(&credit_val.rs);
1585
+	if(msg==NULL || pclient==NULL || pcredit==NULL || pcps==NULL
1586
+			|| pinitp==NULL || pfinishp==NULL) {
1587
+		LM_ERR("invalid parameters\n");
1588
+		return -1;
1589
+	}
1619 1590
 
1620
-		if(credit <= 0) {
1621
-			LM_ERR("credit value must be > 0: %f", credit);
1622
-			return -1;
1623
-		}
1591
+	if(msg->first_line.type != SIP_REQUEST
1592
+			|| msg->first_line.u.request.method_value != METHOD_INVITE) {
1593
+		LM_ERR("not supported - it has to be used for INVITE\n");
1594
+		return -1;
1595
+	}
1624 1596
 
1625
-		if(pv_get_spec_value(msg, cps_spec, &cps_val) != 0) {
1626
-			LM_ERR("Can't get cost_per_sec's value\n");
1627
-			return -1;
1628
-		}
1597
+	if(__has_to_tag(msg)) {
1598
+		LM_ERR("INVITE is a reINVITE\n");
1599
+		return -1;
1600
+	}
1629 1601
 
1630
-		cost_per_second = str2double(&cps_val.rs);
1602
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1603
+		LM_ERR("failed to get client parameter\n");
1604
+		return -1;
1605
+	}
1606
+	if(fixup_get_svalue(msg, (gparam_t*)pcredit, &scredit)<0) {
1607
+		LM_ERR("failed to get credit parameter\n");
1608
+		return -1;
1609
+	}
1610
+	if(fixup_get_svalue(msg, (gparam_t*)pcps, &scps)<0) {
1611
+		LM_ERR("failed to get cps parameter\n");
1612
+		return -1;
1613
+	}
1614
+	if(fixup_get_ivalue(msg, (gparam_t*)pinitp, &initp)<0) {
1615
+		LM_ERR("failed to get init pulse parameter\n");
1616
+		return -1;
1617
+	}
1618
+	if(fixup_get_ivalue(msg, (gparam_t*)pfinishp, &finishp)<0) {
1619
+		LM_ERR("failed to get finish pulse parameter\n");
1620
+		return -1;
1621
+	}
1631 1622
 
1632
-		if(cost_per_second <= 0) {
1633
-			LM_ERR("cost_per_second value must be > 0: %f\n", cost_per_second);
1634
-			return -1;
1635
-		}
1623
+	if(sclient.len == 0 || sclient.s == NULL) {
1624
+		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1625
+				msg->callid->body.s);
1626
+		return -1;
1627
+	}
1636 1628
 
1637
-		if(pv_get_spec_value(msg, initial_pulse_spec, &initial_pulse_val)
1638
-				!= 0) {
1639
-			LM_ERR("Can't get initial_pulse's value\n");
1640
-			return -1;
1641
-		}
1629
+	credit = str2double(&scredit);
1642 1630
 
1643
-		if(str2int(&initial_pulse_val.rs, &initial_pulse) != 0) {
1644
-			LM_ERR("initial_pulse value is invalid: %.*s",
1645
-					initial_pulse_val.rs.len, initial_pulse_val.rs.s);
1646
-			return -1;
1647
-		}
1631
+	if(credit <= 0) {
1632
+		LM_ERR("credit value must be > 0: %f", credit);
1633
+		return -1;
1634
+	}
1648 1635
 
1649
-		if(pv_get_spec_value(msg, final_pulse_spec, &final_pulse_val) != 0) {
1650
-			LM_ERR("Can't get final_pulse's value\n");
1651
-			return -1;
1652
-		}
1636
+	cost_per_second = str2double(&scps);
1653 1637
 
1654
-		if(str2int(&final_pulse_val.rs, &final_pulse) != 0) {
1655
-			LM_ERR("final_pulse value is invalid: %.*s", final_pulse_val.rs.len,
1656
-					final_pulse_val.rs.s);
1657
-			return -1;
1658
-		}
1638
+	if(cost_per_second <= 0) {
1639
+		LM_ERR("cost_per_second value must be > 0: %f\n", cost_per_second);
1640
+		return -1;
1641
+	}
1659 1642
 
1660
-		if(client_id_val.rs.len == 0 || client_id_val.rs.s == NULL) {
1661
-			LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1662
-					msg->callid->body.s);
1663
-			return -1;
1664
-		}
1643
+	LM_DBG("Setting up new call for client [%.*s], max-credit[%f], "
1644
+			"cost-per-sec[%f], initial-pulse [%d], "
1645
+			"final-pulse [%d], call-id[%.*s]\n",
1646
+			sclient.len, sclient.s, credit,
1647
+			cost_per_second, initp, finishp,
1648
+			msg->callid->body.len, msg->callid->body.s);
1665 1649
 
1666
-		LM_DBG("Setting up new call for client [%.*s], max-credit[%f], "
1667
-			   "cost-per-sec[%f], initial-pulse [%d], "
1668
-			   "final-pulse [%d], call-id[%.*s]\n",
1669
-				client_id_val.rs.len, client_id_val.rs.s, credit,
1670
-				cost_per_second, initial_pulse, final_pulse,
1671
-				msg->callid->body.len, msg->callid->body.s);
1672
-		set_ctrl_flag(msg);
1650
+	set_ctrl_flag(msg);
1673 1651
 
1674
-		if((credit_data = __get_or_create_credit_data_entry(
1675
-					&client_id_val.rs, CREDIT_MONEY))
1676
-				== NULL) {
1677
-			LM_ERR("Error retrieving credit data from shared memory for client "
1678
-				   "[%.*s]\n",
1679
-					client_id_val.rs.len, client_id_val.rs.s);
1680
-			return -1;
1681
-		}
1652
+	if((credit_data = __get_or_create_credit_data_entry(&sclient, CREDIT_MONEY))
1653
+			== NULL) {
1654
+		LM_ERR("Error retrieving credit data from shared memory for client "
1655
+				"[%.*s]\n", sclient.len, sclient.s);
1656
+		return -1;
1657
+	}
1682 1658
 
1683
-		if((call = __alloc_new_call_by_money(credit_data, msg, credit,
1684
-					cost_per_second, initial_pulse, final_pulse))
1685
-				== NULL) {
1686
-			LM_ERR("Unable to allocate new call for client [%.*s]\n",
1687
-					client_id_val.rs.len, client_id_val.rs.s);
1688
-			return -1;
1689
-		}
1659
+	if((call = __alloc_new_call_by_money(credit_data, msg, credit,
1660
+				cost_per_second, initp, finishp))
1661
+			== NULL) {
1662
+		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1663
+				sclient.len, sclient.s);
1664
+		return -1;
1665
+	}
1690 1666
 
1691
-		if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_MONEY) != 0) {
1692
-			LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1693
-					client_id_val.rs.len, client_id_val.rs.s);
1694
-			return -1;
1695
-		}
1696
-	} else {
1697
-		LM_ALERT("MSG was not an INVITE\n");
1667
+	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_MONEY) != 0) {
1668
+		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1669
+				sclient.len, sclient.s);
1698 1670
 		return -1;
1699 1671
 	}
1700 1672
 
1701 1673
 	return 1;
1702 1674
 }
1703 1675
 
1704
-static int __terminate_all(struct sip_msg *msg, char *str_pv_client)
1676
+static int __terminate_all(sip_msg_t *msg, char *pclient, char *p2)
1705 1677
 {
1706 1678
 	credit_data_t *credit_data = NULL;
1707
-	pv_spec_t *client_id_spec = (pv_spec_t *)str_pv_client;
1679
+	str sclient;
1708 1680
 
1709
-	pv_value_t client_id_val;
1710
-
1711
-	if(pv_get_spec_value(msg, client_id_spec, &client_id_val) != 0) {
1712
-		LM_ERR("[%.*s]: can't get client_id pvar value\n",
1713
-				msg->callid->body.len, msg->callid->body.s);
1681
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1682
+		LM_ERR("failed to get client parameter\n");
1714 1683
 		return -1;
1715 1684
 	}
1716 1685
 
1717
-	if(client_id_val.rs.len == 0 || client_id_val.rs.s == NULL) {
1686
+	if(sclient.len == 0 || sclient.s == NULL) {
1718 1687
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1719 1688
 				msg->callid->body.s);
1720 1689
 		return -1;
1721 1690
 	}
1722 1691
 
1723
-	if(try_get_credit_data_entry(&client_id_val.rs, &credit_data) != 0) {
1724
-		LM_DBG("[%.*s] not found\n", msg->callid->body.len,
1725
-				msg->callid->body.s);
1692
+	if(try_get_credit_data_entry(&sclient, &credit_data) != 0) {
1693
+		LM_DBG("credit data for [%.*s] on [%.*s] not found\n",
1694
+				sclient.len, sclient.s,
1695
+				msg->callid->body.len, msg->callid->body.s);
1726 1696
 		return -1;
1727 1697
 	}
1728 1698
 
... ...
@@ -1730,156 +1700,136 @@ static int __terminate_all(struct sip_msg *msg, char *str_pv_client)
1730 1700
 	return 1;
1731 1701
 }
1732 1702
 
1733
-static int __get_channel_count(
1734
-		struct sip_msg *msg, char *str_pv_client, char *str_pv_chan_count)
1703
+static int __get_channel_count(sip_msg_t *msg, char *pclient, char *pcount)
1735 1704
 {
1736 1705
 	credit_data_t *credit_data = NULL;
1737
-	pv_spec_t *chan_count_spec = (pv_spec_t *)str_pv_chan_count,
1738
-			  *client_id_spec = (pv_spec_t *)str_pv_client;
1706
+	pv_spec_t *pvcount = (pv_spec_t *)pcount;
1739 1707
 
1740
-	pv_value_t chan_count_val, client_id_val;
1708
+	pv_value_t countval;
1741 1709
 	int value = -1;
1710
+	str sclient;
1742 1711
 
1743
-	if(pv_get_spec_value(msg, client_id_spec, &client_id_val) != 0) {
1744
-		LM_ERR("[%.*s]: can't get client_id pvar value\n",
1745
-				msg->callid->body.len, msg->callid->body.s);
1712
+	if(!pv_is_w(pvcount)) {
1713
+		LM_ERR("pvar is not writable\n");
1714
+		return -1;
1715
+	}
1716
+
1717
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1718
+		LM_ERR("failed to get client parameter\n");
1746 1719
 		return -1;
1747 1720
 	}
1748 1721
 
1749
-	if(client_id_val.rs.len == 0 || client_id_val.rs.s == NULL) {
1722
+	if(sclient.len == 0 || sclient.s == NULL) {
1750 1723
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1751 1724
 				msg->callid->body.s);
1752 1725
 		return -1;
1753 1726
 	}
1754 1727
 
1755
-	if(try_get_credit_data_entry(&client_id_val.rs, &credit_data) == 0)
1728
+	if(try_get_credit_data_entry(&sclient, &credit_data) == 0)
1756 1729
 		value = credit_data->number_of_calls;
1757 1730
 	else
1758 1731
 		LM_ALERT("[%.*s] not found\n", msg->callid->body.len,
1759 1732
 				msg->callid->body.s);
1760 1733
 
1761
-	if(!pv_is_w(chan_count_spec)) {
1762
-		LM_ERR("pvar is not writable\n");
1763
-		return -1;
1764
-	}
1734
+	memset(&countval, 0, sizeof(countval));
1765 1735
 
1766
-	memset(&chan_count_val, 0, sizeof(chan_count_val));
1736
+	countval.flags = PV_VAL_STR;
1767 1737
 
1768
-	chan_count_val.flags = PV_VAL_STR;
1769
-
1770
-	if(value > 0)
1771
-		chan_count_val.rs.s = int2str(value, &chan_count_val.rs.len);
1772
-	else {
1773
-		char buff[2] = {'-', '1'};
1774
-		chan_count_val.rs.s = buff;
1775
-		chan_count_val.rs.len = 2;
1776
-	}
1738
+	countval.rs.s = sint2str(value, &countval.rs.len);
1777 1739
 
1778
-	if(pv_set_spec_value(msg, chan_count_spec, 0, &chan_count_val) != 0) {
1779
-		LM_ERR("Error writing value to pvar");
1740
+	if(pv_set_spec_value(msg, pvcount, 0, &countval) != 0) {
1741
+		LM_ERR("Error writing value to pseudo-variable\n");
1780 1742
 		return -1;
1781 1743
 	}
1782 1744
 
1783 1745
 	return 1;
1784 1746
 }
1785 1747
 
1786
-static int __set_max_channels(
1787
-		struct sip_msg *msg, char *str_pv_client, char *str_pv_max_chan)
1748
+static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1788 1749
 {
1789 1750
 	credit_data_t *credit_data = NULL;
1790 1751
 	call_t *call = NULL;
1791
-	pv_spec_t *max_chan_spec = (pv_spec_t *)str_pv_max_chan,
1792
-			  *client_id_spec = (pv_spec_t *)str_pv_client;
1793
-	pv_value_t max_chan_val, client_id_val;
1752
+	str sclient;
1794 1753
 	int max_chan = 0;
1795 1754
 
1796
-	set_ctrl_flag(msg);
1797
-
1798 1755
 	if(parse_headers(msg, HDR_CALLID_F, 0) != 0) {
1799 1756
 		LM_ERR("Error parsing Call-ID");
1800 1757
 		return -1;
1801 1758
 	}
1802 1759
 
1803
-	if(msg->first_line.type == SIP_REQUEST
1804
-			&& msg->first_line.u.request.method_value == METHOD_INVITE) {
1805
-		if(__has_to_tag(msg)) {
1806
-			LM_ERR("INVITE is a reINVITE\n");
1807
-			return -1;
1808
-		}
1809
-
1810
-		if(pv_get_spec_value(msg, max_chan_spec, &max_chan_val) != 0) {
1811
-			LM_ERR("Can't get max_chan pvar value\n");
1812
-			return -1;
1813
-		}
1814
-		max_chan = max_chan_val.ri;
1760
+	if(msg->first_line.type != SIP_REQUEST
1761
+			|| msg->first_line.u.request.method_value != METHOD_INVITE) {
1762
+		LM_ALERT("MSG was not an INVITE\n");
1763
+		return -1;
1764
+	}
1765
+	if(__has_to_tag(msg)) {
1766
+		LM_ERR("INVITE is a reINVITE\n");
1767
+		return -1;
1768
+	}
1815 1769
 
1816
-		if(max_chan <= 0) {
1817
-			LM_ERR("[%.*s] MAX_CHAN cannot be less than or equal to zero: %d\n",
1818
-					msg->callid->body.len, msg->callid->body.s, max_chan);
1819
-			return -1;
1820
-		}
1770
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1771
+		LM_ERR("failed to get client parameter\n");
1772
+		return -1;
1773
+	}
1774
+	if(fixup_get_ivalue(msg, (gparam_t*)pmaxchan, &max_chan)<0) {
1775
+		LM_ERR("failed to get max chan parameter\n");
1776
+		return -1;
1777
+	}
1821 1778
 
1822
-		if(pv_get_spec_value(msg, client_id_spec, &client_id_val) != 0) {
1823
-			LM_ERR("[%.*s]: can't get client_id pvar value\n",
1824
-					msg->callid->body.len, msg->callid->body.s);
1825
-			return -1;
1826
-		}
1779
+	set_ctrl_flag(msg);
1827 1780
 
1828
-		if(client_id_val.rs.len == 0 || client_id_val.rs.s == NULL) {
1829
-			LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1830
-					msg->callid->body.s);
1831
-			return -1;
1832
-		}
1781
+	if(max_chan <= 0) {
1782
+		LM_ERR("[%.*s] MAX_CHAN cannot be less than or equal to zero: %d\n",
1783
+				msg->callid->body.len, msg->callid->body.s, max_chan);
1784
+		return -1;
1785
+	}
1833 1786
 
1834
-		LM_DBG("Setting up new call for client [%.*s], max-chan[%d], "
1835
-			   "call-id[%.*s]\n",
1836
-				client_id_val.rs.len, client_id_val.rs.s, max_chan,
1837
-				msg->callid->body.len, msg->callid->body.s);
1787
+	if(sclient.len == 0 || sclient.s == NULL) {
1788
+		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1789
+				msg->callid->body.s);
1790
+		return -1;
1791
+	}
1838 1792
 
1839
-		if((credit_data = __get_or_create_credit_data_entry(
1840
-					&client_id_val.rs, CREDIT_CHANNEL))
1841
-				== NULL) {
1842
-			LM_ERR("Error retrieving credit data from shared memory for client "
1843
-				   "[%.*s]\n",
1844
-					client_id_val.rs.len, client_id_val.rs.s);
1845
-			return -1;
1846
-		}
1793
+	LM_DBG("Setting up new call for client [%.*s], max-chan[%d], "
1794
+			"call-id[%.*s]\n",
1795
+			sclient.len, sclient.s, max_chan,
1796
+			msg->callid->body.len, msg->callid->body.s);
1847 1797
 
1848
-		if(credit_data->number_of_calls + 1 > max_chan)
1849
-			return -2; // you have, between calls being setup plus those established, more than you maximum quota
1798
+	if((credit_data = __get_or_create_credit_data_entry(&sclient,
1799
+				CREDIT_CHANNEL)) == NULL) {
1800
+		LM_ERR("Error retrieving credit data from shared memory for client "
1801
+				"[%.*s]\n", sclient.len, sclient.s);
1802
+		return -1;
1803
+	}
1850 1804
 
1851
-		if(credit_data->concurrent_calls + 1 > max_chan)
1852
-			return -3; // you have the max amount of established calls already
1805
+	if(credit_data->number_of_calls + 1 > max_chan)
1806
+		return -2; // you have, between calls being setup plus those established, more than you maximum quota
1853 1807
 
1854
-		if((call = alloc_new_call_by_channel(credit_data, msg, max_chan))
1855
-				== NULL) {
1856
-			LM_ERR("Unable to allocate new call for client [%.*s]\n",
1857
-					client_id_val.rs.len, client_id_val.rs.s);
1858
-			return -1;
1859
-		}
1808
+	if(credit_data->concurrent_calls + 1 > max_chan)
1809
+		return -3; // you have the max amount of established calls already
1860 1810
 
1861
-		if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_CHANNEL)
1862
-				!= 0) {
1863
-			LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1864
-					client_id_val.rs.len, client_id_val.rs.s);
1865
-			return -1;
1866
-		}
1811
+	if((call = alloc_new_call_by_channel(credit_data, msg, max_chan))
1812
+			== NULL) {
1813
+		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1814
+				sclient.len, sclient.s);
1815
+		return -1;
1816
+	}
1867 1817
 
1868
-		return 1;
1869
-	} else {
1870
-		LM_ALERT("MSG was not an INVITE\n");
1818
+	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_CHANNEL)
1819
+			!= 0) {
1820
+		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1821
+				sclient.len, sclient.s);
1871 1822
 		return -1;
1872 1823
 	}
1824
+
1825
+	return 1;
1873 1826
 }
1874 1827
 
1875
-static int __set_max_time(
1876
-		struct sip_msg *msg, char *str_pv_client, char *str_pv_maxsecs)
1828
+static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1877 1829
 {
1878 1830
 	credit_data_t *credit_data = NULL;
1879 1831
 	call_t *call = NULL;
1880
-	pv_spec_t *max_secs_spec = (pv_spec_t *)str_pv_maxsecs,
1881
-			  *client_id_spec = (pv_spec_t *)str_pv_client;
1882
-	pv_value_t max_secs_val, client_id_val;
1832
+	str sclient;
1883 1833
 	int max_secs = 0;
1884 1834
 
1885 1835
 	set_ctrl_flag(msg);
... ...
@@ -1889,78 +1839,70 @@ static int __set_max_time(
1889 1839
 		return -1;
1890 1840
 	}
1891 1841
 
1892
-	if(msg->first_line.type == SIP_REQUEST
1893
-			&& msg->first_line.u.request.method_value == METHOD_INVITE) {
1894
-		if(__has_to_tag(msg)) {
1895
-			LM_ERR("INVITE is a reINVITE\n");
1896
-			return -1;
1897
-		}
1842
+	if(msg->first_line.type != SIP_REQUEST
1843
+			|| msg->first_line.u.request.method_value != METHOD_INVITE) {
1844
+		LM_ALERT("MSG was not an INVITE\n");
1845
+		return -1;
1846
+	}
1898 1847
 
1899
-		if(pv_get_spec_value(msg, max_secs_spec, &max_secs_val) != 0) {
1900
-			LM_ERR("Can't get max_secs PV value\n");
1901
-			return -1;
1902
-		}
1903
-		max_secs = max_secs_val.ri;
1848
+	if(__has_to_tag(msg)) {
1849
+		LM_ERR("INVITE is a reINVITE\n");
1850
+		return -1;
1851
+	}
1904 1852
 
1905
-		if(max_secs <= 0) {
1906
-			LM_ERR("[%.*s] MAXSECS cannot be less than or equal to zero: %d\n",
1907
-					msg->callid->body.len, msg->callid->body.s, max_secs);
1908
-			return -1;
1909
-		}
1853
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1854
+		LM_ERR("failed to get client parameter\n");
1855
+		return -1;
1856
+	}
1857
+	if(fixup_get_ivalue(msg, (gparam_t*)pmaxsecs, &max_secs)<0) {
1858
+		LM_ERR("failed to get max secs parameter\n");
1859
+		return -1;
1860
+	}
1910 1861
 
1911
-		if(pv_get_spec_value(msg, client_id_spec, &client_id_val) != 0) {
1912
-			LM_ERR("[%.*s]: can't get client_id PV value\n",
1913
-					msg->callid->body.len, msg->callid->body.s);
1914
-			return -1;
1915
-		}
1862
+	if(max_secs <= 0) {
1863
+		LM_ERR("[%.*s] MAXSECS cannot be less than or equal to zero: %d\n",
1864
+				msg->callid->body.len, msg->callid->body.s, max_secs);
1865
+		return -1;
1866
+	}
1916 1867
 
1917
-		if(client_id_val.rs.len == 0 || client_id_val.rs.s == NULL) {
1918
-			LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1919
-					msg->callid->body.s);
1920
-			return -1;
1921
-		}
1868
+	if(sclient.len == 0 || sclient.s == NULL) {
1869
+		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1870
+				msg->callid->body.s);
1871
+		return -1;
1872
+	}
1922 1873
 
1923
-		LM_DBG("Setting up new call for client [%.*s], max-secs[%d], "
1924
-			   "call-id[%.*s]\n",
1925
-				client_id_val.rs.len, client_id_val.rs.s, max_secs,
1926
-				msg->callid->body.len, msg->callid->body.s);
1874
+	LM_DBG("Setting up new call for client [%.*s], max-secs[%d], "
1875
+			"call-id[%.*s]\n",
1876
+			sclient.len, sclient.s, max_secs,
1877
+			msg->callid->body.len, msg->callid->body.s);
1927 1878
 
1928
-		if((credit_data = __get_or_create_credit_data_entry(
1929
-					&client_id_val.rs, CREDIT_TIME))
1930
-				== NULL) {
1931
-			LM_ERR("Error retrieving credit data from shared memory for client "
1932
-				   "[%.*s]\n",
1933
-					client_id_val.rs.len, client_id_val.rs.s);
1934
-			return -1;
1935
-		}
1879
+	if((credit_data = __get_or_create_credit_data_entry(&sclient, CREDIT_TIME))
1880
+			== NULL) {
1881
+		LM_ERR("Error retrieving credit data from shared memory for client "
1882
+				"[%.*s]\n", sclient.len, sclient.s);
1883
+		return -1;
1884
+	}
1936 1885
 
1937
-		if((call = __alloc_new_call_by_time(credit_data, msg, max_secs))
1938
-				== NULL) {
1939
-			LM_ERR("Unable to allocate new call for client [%.*s]\n",
1940
-					client_id_val.rs.len, client_id_val.rs.s);
1941
-			return -1;
1942
-		}
1886
+	if((call = __alloc_new_call_by_time(credit_data, msg, max_secs))
1887
+			== NULL) {
1888
+		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1889
+				sclient.len, sclient.s);
1890
+		return -1;
1891
+	}
1943 1892
 
1944
-		if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_TIME) != 0) {
1945
-			LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1946
-					client_id_val.rs.len, client_id_val.rs.s);
1947
-			return -1;
1948
-		}
1949
-	} else {
1950
-		LM_ALERT("MSG was not an INVITE\n");
1893
+	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_TIME) != 0) {
1894
+		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1895
+				sclient.len, sclient.s);
1951 1896
 		return -1;
1952 1897
 	}
1953 1898
 
1954 1899
 	return 1;
1955 1900
 }
1956 1901
 
1957
-static int __update_max_time(
1958
-		struct sip_msg *msg, char *str_pv_client, char *str_pv_secs)
1902
+static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1959 1903
 {
1960 1904
 	credit_data_t *credit_data = NULL;
1961
-	pv_spec_t *secs_spec = (pv_spec_t *)str_pv_secs,
1962
-			  *client_id_spec = (pv_spec_t *)str_pv_client;
1963
-	pv_value_t secs_val, client_id_val;
1905
+	str sclient;
1964 1906
 	int secs = 0;
1965 1907
 
1966 1908
 	set_ctrl_flag(msg);
... ...
@@ -1970,11 +1912,14 @@ static int __update_max_time(
1970 1912
 		return -1;
1971 1913
 	}
1972 1914
 
1973
-	if(pv_get_spec_value(msg, secs_spec, &secs_val) != 0) {
1974
-		LM_ERR("Can't get secs PV value\n");
1915
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1916
+		LM_ERR("failed to get client parameter\n");
1917
+		return -1;
1918
+	}
1919
+	if(fixup_get_ivalue(msg, (gparam_t*)psecs, &secs)<0) {
1920
+		LM_ERR("failed to get secs parameter\n");
1975 1921
 		return -1;
1976 1922
 	}
1977
-	secs = secs_val.ri;
1978 1923
 
1979 1924
 	if(secs <= 0) {
1980 1925
 		LM_ERR("[%.*s] MAXSECS cannot be less than or equal to zero: %d\n",
... ...
@@ -1982,20 +1927,14 @@ static int __update_max_time(
1982 1927
 		return -1;
1983 1928
 	}
1984 1929
 
1985
-	if(pv_get_spec_value(msg, client_id_spec, &client_id_val) != 0) {
1986
-		LM_ERR("[%.*s]: can't get client_id PV value\n", msg->callid->body.len,
1987
-				msg->callid->body.s);
1988
-		return -1;
1989
-	}
1990
-
1991
-	if(client_id_val.rs.len == 0 || client_id_val.rs.s == NULL) {
1930
+	if(sclient.len == 0 || sclient.s == NULL) {
1992 1931
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1993 1932
 				msg->callid->body.s);
1994 1933
 		return -1;
1995 1934
 	}
1996 1935
 
1997 1936
 	LM_DBG("Updating call for client [%.*s], max-secs[%d], call-id[%.*s]\n",
1998
-			client_id_val.rs.len, client_id_val.rs.s, secs,
1937
+			sclient.len, sclient.s, secs,
1999 1938
 			msg->callid->body.len, msg->callid->body.s);
2000 1939
 
2001 1940
 
... ...
@@ -2006,12 +1945,12 @@ static int __update_max_time(
2006 1945
 	call_t *call = NULL, *tmp_call = NULL;
2007 1946
 
2008 1947
 	cnxcc_lock(_data.time.lock);
2009
-	e = str_hash_get(ht, client_id_val.rs.s, client_id_val.rs.len);
1948
+	e = str_hash_get(ht, sclient.s, sclient.len);
2010 1949
 	cnxcc_unlock(_data.time.lock);
2011 1950
 
2012 1951
 	if(e == NULL) {
2013
-		LM_ERR("Client [%.*s] was not found\n", client_id_val.rs.len,
2014
-				client_id_val.rs.s);
1952
+		LM_ERR("Client [%.*s] was not found\n", sclient.len,
1953
+				sclient.s);
2015 1954
 		return -1;
2016 1955
 	}
2017 1956
 
... ...
@@ -2034,7 +1973,7 @@ static int __update_max_time(
2034 1973
 		call->max_amount += update_fraction;
2035 1974
 	}
2036 1975
 
2037
-	//redit_data->consumed_amount			= 0;
1976
+	//redit_data->consumed_amount = 0;
2038 1977
 
2039 1978
 
2040 1979
 	cnxcc_unlock(credit_data->lock);