Browse code

cnxcc: exported functions to kemi framework

Daniel-Constantin Mierla authored on 26/11/2017 12:09:13
Showing 1 changed files
... ...
@@ -55,6 +55,7 @@
55 55
 #include "../../core/fmsg.h"
56 56
 #include "../../core/rpc.h"
57 57
 #include "../../core/rpc_lookup.h"
58
+#include "../../core/kemi.h"
58 59
 
59 60
 #include "cnxcc_mod.h"
60 61
 #include "cnxcc.h"
... ...
@@ -1570,23 +1571,13 @@ static inline int get_pv_value(
1570 1571
 	return 0;
1571 1572
 }
1572 1573
 
1573
-static int __set_max_credit(sip_msg_t *msg, char *pclient,
1574
-		char *pcredit, char *pcps, char *pinitp, char *pfinishp)
1574
+static int ki_set_max_credit(sip_msg_t *msg, str *sclient,
1575
+		str *scredit, str *scps, int initp, int finishp)
1575 1576
 {
1576 1577
 	credit_data_t *credit_data = NULL;
1577 1578
 	call_t *call = NULL;
1578
-	str sclient;
1579
-	str scredit;
1580
-	str scps;
1581
-	int initp;
1582
-	int finishp;
1583
-	double credit = 0, cost_per_second = 0;
1584 1579
 
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
-	}
1580
+	double credit = 0, cost_per_second = 0;
1590 1581
 
1591 1582
 	if(msg->first_line.type != SIP_REQUEST
1592 1583
 			|| msg->first_line.u.request.method_value != METHOD_INVITE) {
... ...
@@ -1599,41 +1590,20 @@ static int __set_max_credit(sip_msg_t *msg, char *pclient,
1599 1590
 		return -1;
1600 1591
 	}
1601 1592
 
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
-	}
1622
-
1623
-	if(sclient.len == 0 || sclient.s == NULL) {
1593
+	if(sclient->len == 0 || sclient->s == NULL) {
1624 1594
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1625 1595
 				msg->callid->body.s);
1626 1596
 		return -1;
1627 1597
 	}
1628 1598
 
1629
-	credit = str2double(&scredit);
1599
+	credit = str2double(scredit);
1630 1600
 
1631 1601
 	if(credit <= 0) {
1632 1602
 		LM_ERR("credit value must be > 0: %f", credit);
1633 1603
 		return -1;
1634 1604
 	}
1635 1605
 
1636
-	cost_per_second = str2double(&scps);
1606
+	cost_per_second = str2double(scps);
1637 1607
 
1638 1608
 	if(cost_per_second <= 0) {
1639 1609
 		LM_ERR("cost_per_second value must be > 0: %f\n", cost_per_second);
... ...
@@ -1643,16 +1613,16 @@ static int __set_max_credit(sip_msg_t *msg, char *pclient,
1643 1613
 	LM_DBG("Setting up new call for client [%.*s], max-credit[%f], "
1644 1614
 			"cost-per-sec[%f], initial-pulse [%d], "
1645 1615
 			"final-pulse [%d], call-id[%.*s]\n",
1646
-			sclient.len, sclient.s, credit,
1616
+			sclient->len, sclient->s, credit,
1647 1617
 			cost_per_second, initp, finishp,
1648 1618
 			msg->callid->body.len, msg->callid->body.s);
1649 1619
 
1650 1620
 	set_ctrl_flag(msg);
1651 1621
 
1652
-	if((credit_data = __get_or_create_credit_data_entry(&sclient, CREDIT_MONEY))
1622
+	if((credit_data = __get_or_create_credit_data_entry(sclient, CREDIT_MONEY))
1653 1623
 			== NULL) {
1654 1624
 		LM_ERR("Error retrieving credit data from shared memory for client "
1655
-				"[%.*s]\n", sclient.len, sclient.s);
1625
+				"[%.*s]\n", sclient->len, sclient->s);
1656 1626
 		return -1;
1657 1627
 	}
1658 1628
 
... ...
@@ -1660,38 +1630,71 @@ static int __set_max_credit(sip_msg_t *msg, char *pclient,
1660 1630
 				cost_per_second, initp, finishp))
1661 1631
 			== NULL) {
1662 1632
 		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1663
-				sclient.len, sclient.s);
1633
+				sclient->len, sclient->s);
1664 1634
 		return -1;
1665 1635
 	}
1666 1636
 
1667 1637
 	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_MONEY) != 0) {
1668 1638
 		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1669
-				sclient.len, sclient.s);
1639
+				sclient->len, sclient->s);
1670 1640
 		return -1;
1671 1641
 	}
1672 1642
 
1673 1643
 	return 1;
1674 1644
 }
1675 1645
 
1676
-static int __terminate_all(sip_msg_t *msg, char *pclient, char *p2)
1646
+static int __set_max_credit(sip_msg_t *msg, char *pclient,
1647
+		char *pcredit, char *pcps, char *pinitp, char *pfinishp)
1677 1648
 {
1678
-	credit_data_t *credit_data = NULL;
1679 1649
 	str sclient;
1650
+	str scredit;
1651
+	str scps;
1652
+	int initp;
1653
+	int finishp;
1654
+
1655
+	if(msg==NULL || pclient==NULL || pcredit==NULL || pcps==NULL
1656
+			|| pinitp==NULL || pfinishp==NULL) {
1657
+		LM_ERR("invalid parameters\n");
1658
+		return -1;
1659
+	}
1680 1660
 
1681 1661
 	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1682 1662
 		LM_ERR("failed to get client parameter\n");
1683 1663
 		return -1;
1684 1664
 	}
1665
+	if(fixup_get_svalue(msg, (gparam_t*)pcredit, &scredit)<0) {
1666
+		LM_ERR("failed to get credit parameter\n");
1667
+		return -1;
1668
+	}
1669
+	if(fixup_get_svalue(msg, (gparam_t*)pcps, &scps)<0) {
1670
+		LM_ERR("failed to get cps parameter\n");
1671
+		return -1;
1672
+	}
1673
+	if(fixup_get_ivalue(msg, (gparam_t*)pinitp, &initp)<0) {
1674
+		LM_ERR("failed to get init pulse parameter\n");
1675
+		return -1;
1676
+	}
1677
+	if(fixup_get_ivalue(msg, (gparam_t*)pfinishp, &finishp)<0) {
1678
+		LM_ERR("failed to get finish pulse parameter\n");
1679
+		return -1;
1680
+	}
1685 1681
 
1686
-	if(sclient.len == 0 || sclient.s == NULL) {
1682
+	return ki_set_max_credit(msg, &sclient, &scredit, &scps, initp, finishp);
1683
+}
1684
+
1685
+static int ki_terminate_all(sip_msg_t *msg, str *sclient)
1686
+{
1687
+	credit_data_t *credit_data = NULL;
1688
+
1689
+	if(sclient->len == 0 || sclient->s == NULL) {
1687 1690
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1688 1691
 				msg->callid->body.s);
1689 1692
 		return -1;
1690 1693
 	}
1691 1694
 
1692
-	if(try_get_credit_data_entry(&sclient, &credit_data) != 0) {
1695
+	if(try_get_credit_data_entry(sclient, &credit_data) != 0) {
1693 1696
 		LM_DBG("credit data for [%.*s] on [%.*s] not found\n",
1694
-				sclient.len, sclient.s,
1697
+				sclient->len, sclient->s,
1695 1698
 				msg->callid->body.len, msg->callid->body.s);
1696 1699
 		return -1;
1697 1700
 	}
... ...
@@ -1700,36 +1703,41 @@ static int __terminate_all(sip_msg_t *msg, char *pclient, char *p2)
1700 1703
 	return 1;
1701 1704
 }
1702 1705
 
1703
-static int __get_channel_count(sip_msg_t *msg, char *pclient, char *pcount)
1706
+static int __terminate_all(sip_msg_t *msg, char *pclient, char *p2)
1704 1707
 {
1705
-	credit_data_t *credit_data = NULL;
1706
-	pv_spec_t *pvcount = (pv_spec_t *)pcount;
1708
+	str sclient;
1709
+
1710
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1711
+		LM_ERR("failed to get client parameter\n");
1712
+		return -1;
1713
+	}
1714
+
1715
+	return ki_terminate_all(msg, &sclient);
1716
+}
1707 1717
 
1718
+static int __get_channel_count_helper(sip_msg_t *msg, str *sclient,
1719
+		pv_spec_t *pvcount)
1720
+{
1721
+	credit_data_t *credit_data = NULL;
1708 1722
 	pv_value_t countval;
1709 1723
 	int value = -1;
1710
-	str sclient;
1711 1724
 
1712 1725
 	if(!pv_is_w(pvcount)) {
1713 1726
 		LM_ERR("pvar is not writable\n");
1714 1727
 		return -1;
1715 1728
 	}
1716 1729
 
1717
-	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1718
-		LM_ERR("failed to get client parameter\n");
1719
-		return -1;
1720
-	}
1721
-
1722
-	if(sclient.len == 0 || sclient.s == NULL) {
1730
+	if(sclient->len == 0 || sclient->s == NULL) {
1723 1731
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1724 1732
 				msg->callid->body.s);
1725 1733
 		return -1;
1726 1734
 	}
1727 1735
 
1728
-	if(try_get_credit_data_entry(&sclient, &credit_data) == 0)
1736
+	if(try_get_credit_data_entry(sclient, &credit_data) == 0)
1729 1737
 		value = credit_data->number_of_calls;
1730 1738
 	else
1731
-		LM_ALERT("[%.*s] not found\n", msg->callid->body.len,
1732
-				msg->callid->body.s);
1739
+		LM_ALERT("[%.*s] [%.*s] not found\n", sclient->len, sclient->s,
1740
+				msg->callid->body.len, msg->callid->body.s);
1733 1741
 
1734 1742
 	memset(&countval, 0, sizeof(countval));
1735 1743
 
... ...
@@ -1745,12 +1753,36 @@ static int __get_channel_count(sip_msg_t *msg, char *pclient, char *pcount)
1745 1753
 	return 1;
1746 1754
 }
1747 1755
 
1748
-static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1756
+static int __get_channel_count(sip_msg_t *msg, char *pclient, char *pcount)
1757
+{
1758
+	pv_spec_t *pvcount = (pv_spec_t *)pcount;
1759
+	str sclient;
1760
+
1761
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1762
+		LM_ERR("failed to get client parameter\n");
1763
+		return -1;
1764
+	}
1765
+
1766
+	return __get_channel_count_helper(msg, &sclient, (pv_spec_t *)pcount);
1767
+}
1768
+
1769
+static int ki_get_channel_count(sip_msg_t *msg, str *sclient, str *pvname)
1770
+{
1771
+	pv_spec_t *pvcount = NULL;
1772
+
1773
+	pvcount = pv_cache_get(pvname);
1774
+
1775
+	if(pvcount==NULL) {
1776
+		LM_ERR("failed to get pv spec for [%.*s]\n", pvname->len, pvname->s);
1777
+		return -1;
1778
+	}
1779
+	return __get_channel_count_helper(msg, sclient, pvcount);
1780
+}
1781
+
1782
+static int ki_set_max_channels(sip_msg_t *msg, str *sclient, int max_chan)
1749 1783
 {
1750 1784
 	credit_data_t *credit_data = NULL;
1751 1785
 	call_t *call = NULL;
1752
-	str sclient;
1753
-	int max_chan = 0;
1754 1786
 
1755 1787
 	if(parse_headers(msg, HDR_CALLID_F, 0) != 0) {
1756 1788
 		LM_ERR("Error parsing Call-ID");
... ...
@@ -1767,15 +1799,6 @@ static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1767 1799
 		return -1;
1768 1800
 	}
1769 1801
 
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
-	}
1778
-
1779 1802
 	set_ctrl_flag(msg);
1780 1803
 
1781 1804
 	if(max_chan <= 0) {
... ...
@@ -1784,7 +1807,7 @@ static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1784 1807
 		return -1;
1785 1808
 	}
1786 1809
 
1787
-	if(sclient.len == 0 || sclient.s == NULL) {
1810
+	if(sclient->len == 0 || sclient->s == NULL) {
1788 1811
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1789 1812
 				msg->callid->body.s);
1790 1813
 		return -1;
... ...
@@ -1792,13 +1815,13 @@ static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1792 1815
 
1793 1816
 	LM_DBG("Setting up new call for client [%.*s], max-chan[%d], "
1794 1817
 			"call-id[%.*s]\n",
1795
-			sclient.len, sclient.s, max_chan,
1818
+			sclient->len, sclient->s, max_chan,
1796 1819
 			msg->callid->body.len, msg->callid->body.s);
1797 1820
 
1798
-	if((credit_data = __get_or_create_credit_data_entry(&sclient,
1821
+	if((credit_data = __get_or_create_credit_data_entry(sclient,
1799 1822
 				CREDIT_CHANNEL)) == NULL) {
1800 1823
 		LM_ERR("Error retrieving credit data from shared memory for client "
1801
-				"[%.*s]\n", sclient.len, sclient.s);
1824
+				"[%.*s]\n", sclient->len, sclient->s);
1802 1825
 		return -1;
1803 1826
 	}
1804 1827
 
... ...
@@ -1811,28 +1834,41 @@ static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1811 1834
 	if((call = alloc_new_call_by_channel(credit_data, msg, max_chan))
1812 1835
 			== NULL) {
1813 1836
 		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1814
-				sclient.len, sclient.s);
1837
+				sclient->len, sclient->s);
1815 1838
 		return -1;
1816 1839
 	}
1817 1840
 
1818 1841
 	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_CHANNEL)
1819 1842
 			!= 0) {
1820 1843
 		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1821
-				sclient.len, sclient.s);
1844
+				sclient->len, sclient->s);
1822 1845
 		return -1;
1823 1846
 	}
1824 1847
 
1825 1848
 	return 1;
1826 1849
 }
1827 1850
 
1828
-static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1851
+static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1829 1852
 {
1830
-	credit_data_t *credit_data = NULL;
1831
-	call_t *call = NULL;
1832 1853
 	str sclient;
1833
-	int max_secs = 0;
1854
+	int max_chan = 0;
1834 1855
 
1835
-	set_ctrl_flag(msg);
1856
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1857
+		LM_ERR("failed to get client parameter\n");
1858
+		return -1;
1859
+	}
1860
+	if(fixup_get_ivalue(msg, (gparam_t*)pmaxchan, &max_chan)<0) {
1861
+		LM_ERR("failed to get max chan parameter\n");
1862
+		return -1;
1863
+	}
1864
+
1865
+	return ki_set_max_channels(msg, &sclient, max_chan);
1866
+}
1867
+
1868
+static int ki_set_max_time(sip_msg_t *msg, str *sclient, int max_secs)
1869
+{
1870
+	credit_data_t *credit_data = NULL;
1871
+	call_t *call = NULL;
1836 1872
 
1837 1873
 	if(parse_headers(msg, HDR_CALLID_F, 0) != 0) {
1838 1874
 		LM_ERR("Error parsing Call-ID");
... ...
@@ -1850,14 +1886,7 @@ static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1850 1886
 		return -1;
1851 1887
 	}
1852 1888
 
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
-	}
1889
+	set_ctrl_flag(msg);
1861 1890
 
1862 1891
 	if(max_secs <= 0) {
1863 1892
 		LM_ERR("[%.*s] MAXSECS cannot be less than or equal to zero: %d\n",
... ...
@@ -1865,7 +1894,7 @@ static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1865 1894
 		return -1;
1866 1895
 	}
1867 1896
 
1868
-	if(sclient.len == 0 || sclient.s == NULL) {
1897
+	if(sclient->len <= 0 || sclient->s == NULL) {
1869 1898
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1870 1899
 				msg->callid->body.s);
1871 1900
 		return -1;
... ...
@@ -1873,51 +1902,57 @@ static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1873 1902
 
1874 1903
 	LM_DBG("Setting up new call for client [%.*s], max-secs[%d], "
1875 1904
 			"call-id[%.*s]\n",
1876
-			sclient.len, sclient.s, max_secs,
1905
+			sclient->len, sclient->s, max_secs,
1877 1906
 			msg->callid->body.len, msg->callid->body.s);
1878 1907
 
1879
-	if((credit_data = __get_or_create_credit_data_entry(&sclient, CREDIT_TIME))
1908
+	if((credit_data = __get_or_create_credit_data_entry(sclient, CREDIT_TIME))
1880 1909
 			== NULL) {
1881 1910
 		LM_ERR("Error retrieving credit data from shared memory for client "
1882
-				"[%.*s]\n", sclient.len, sclient.s);
1911
+				"[%.*s]\n", sclient->len, sclient->s);
1883 1912
 		return -1;
1884 1913
 	}
1885 1914
 
1886 1915
 	if((call = __alloc_new_call_by_time(credit_data, msg, max_secs))
1887 1916
 			== NULL) {
1888 1917
 		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1889
-				sclient.len, sclient.s);
1918
+				sclient->len, sclient->s);
1890 1919
 		return -1;
1891 1920
 	}
1892 1921
 
1893 1922
 	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_TIME) != 0) {
1894 1923
 		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1895
-				sclient.len, sclient.s);
1924
+				sclient->len, sclient->s);
1896 1925
 		return -1;
1897 1926
 	}
1898 1927
 
1899 1928
 	return 1;
1900 1929
 }
1901 1930
 
1902
-static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1931
+static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1903 1932
 {
1904
-	credit_data_t *credit_data = NULL;
1905 1933
 	str sclient;
1906
-	int secs = 0;
1907
-
1908
-	set_ctrl_flag(msg);
1909
-
1910
-	if(parse_headers(msg, HDR_CALLID_F, 0) != 0) {
1911
-		LM_ERR("Error parsing Call-ID");
1912
-		return -1;
1913
-	}
1934
+	int max_secs = 0;
1914 1935
 
1915 1936
 	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1916 1937
 		LM_ERR("failed to get client parameter\n");
1917 1938
 		return -1;
1918 1939
 	}
1919
-	if(fixup_get_ivalue(msg, (gparam_t*)psecs, &secs)<0) {
1920
-		LM_ERR("failed to get secs parameter\n");
1940
+	if(fixup_get_ivalue(msg, (gparam_t*)pmaxsecs, &max_secs)<0) {
1941
+		LM_ERR("failed to get max secs parameter\n");
1942
+		return -1;
1943
+	}
1944
+
1945
+	return ki_set_max_time(msg, &sclient, max_secs);
1946
+}
1947
+
1948
+static int ki_update_max_time(sip_msg_t *msg, str *sclient, int secs)
1949
+{
1950
+	credit_data_t *credit_data = NULL;
1951
+
1952
+	set_ctrl_flag(msg);
1953
+
1954
+	if(parse_headers(msg, HDR_CALLID_F, 0) != 0) {
1955
+		LM_ERR("Error parsing Call-ID");
1921 1956
 		return -1;
1922 1957
 	}
1923 1958
 
... ...
@@ -1927,14 +1962,14 @@ static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1927 1962
 		return -1;
1928 1963
 	}
1929 1964
 
1930
-	if(sclient.len == 0 || sclient.s == NULL) {
1965
+	if(sclient->len == 0 || sclient->s == NULL) {
1931 1966
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1932 1967
 				msg->callid->body.s);
1933 1968
 		return -1;
1934 1969
 	}
1935 1970
 
1936 1971
 	LM_DBG("Updating call for client [%.*s], max-secs[%d], call-id[%.*s]\n",
1937
-			sclient.len, sclient.s, secs,
1972
+			sclient->len, sclient->s, secs,
1938 1973
 			msg->callid->body.len, msg->callid->body.s);
1939 1974
 
1940 1975
 
... ...
@@ -1945,12 +1980,12 @@ static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1945 1980
 	call_t *call = NULL, *tmp_call = NULL;
1946 1981
 
1947 1982
 	cnxcc_lock(_data.time.lock);
1948
-	e = str_hash_get(ht, sclient.s, sclient.len);
1983
+	e = str_hash_get(ht, sclient->s, sclient->len);
1949 1984
 	cnxcc_unlock(_data.time.lock);
1950 1985
 
1951 1986
 	if(e == NULL) {
1952
-		LM_ERR("Client [%.*s] was not found\n", sclient.len,
1953
-				sclient.s);
1987
+		LM_ERR("Client [%.*s] was not found\n", sclient->len,
1988
+				sclient->s);
1954 1989
 		return -1;
1955 1990
 	}
1956 1991
 
... ...
@@ -1975,12 +2010,28 @@ static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1975 2010
 
1976 2011
 	//redit_data->consumed_amount = 0;
1977 2012
 
1978
-
1979 2013
 	cnxcc_unlock(credit_data->lock);
1980 2014
 
1981 2015
 	return 1;
1982 2016
 }
1983 2017
 
2018
+static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
2019
+{
2020
+	str sclient;
2021
+	int secs = 0;
2022
+
2023
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
2024
+		LM_ERR("failed to get client parameter\n");
2025
+		return -1;
2026
+	}
2027
+	if(fixup_get_ivalue(msg, (gparam_t*)psecs, &secs)<0) {
2028
+		LM_ERR("failed to get secs parameter\n");
2029
+		return -1;
2030
+	}
2031
+
2032
+	return ki_update_max_time(msg, &sclient, secs);
2033
+}
2034
+
1984 2035
 static int __has_to_tag(struct sip_msg *msg)
1985 2036
 {
1986 2037
 	if(msg->to == NULL && parse_headers(msg, HDR_TO_F, 0) != 0) {
... ...
@@ -2054,4 +2105,50 @@ void rpc_credit_control_stats(rpc_t *rpc, void *ctx)
2054 2105
 	rpc->struct_add(rh, "sddd", "info", "CNX Credit Control", "active",
2055 2106
 			_data.stats->active, "dropped", _data.stats->dropped, "total",
2056 2107
 			_data.stats->total);
2108
+}
2109
+
2110
+/**
2111
+ *
2112
+ */
2113
+/* clang-format off */
2114
+static sr_kemi_t sr_kemi_cnxcc_exports[] = {
2115
+	{ str_init("cnxcc"), str_init("set_max_credit"),
2116
+		SR_KEMIP_INT, ki_set_max_credit,
2117
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
2118
+			SR_KEMIP_INT, SR_KEMIP_INT, SR_KEMIP_NONE }
2119
+	},
2120
+	{ str_init("cnxcc"), str_init("set_max_time"),
2121
+		SR_KEMIP_INT, ki_set_max_time,
2122
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2123
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2124
+	},
2125
+	{ str_init("cnxcc"), str_init("update_max_time"),
2126
+		SR_KEMIP_INT, ki_update_max_time,
2127
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2128
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2129
+	},
2130
+	{ str_init("cnxcc"), str_init("set_max_channels"),
2131
+		SR_KEMIP_INT, ki_set_max_channels,
2132
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2133
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2134
+	},
2135
+	{ str_init("cnxcc"), str_init("get_channel_count"),
2136
+		SR_KEMIP_INT, ki_get_channel_count,
2137
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2138
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2139
+	},
2140
+	{ str_init("cnxcc"), str_init("terminate_all"),
2141
+		SR_KEMIP_INT, ki_terminate_all,
2142
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
2143
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2144
+	},
2145
+
2146
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
2147
+};
2148
+/* clang-format on */
2149
+
2150
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
2151
+{
2152
+	sr_kemi_modules_add(sr_kemi_cnxcc_exports);
2153
+	return 0;
2057 2154
 }
2058 2155
\ No newline at end of file