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