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 1570
 	return 0;
1571 1571
 }
1572 1572
 
1573
-static int __set_max_credit(sip_msg_t *msg, char *pclient,
1574
-		char *pcredit, char *pcps, char *pinitp, char *pfinishp)
1573
+static int ki_set_max_credit(sip_msg_t *msg, str *sclient,
1574
+		str *scredit, str *scps, int initp, int finishp)
1575 1575
 {
1576 1576
 	credit_data_t *credit_data = NULL;
1577 1577
 	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 1578
 
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
-	}
1579
+	double credit = 0, cost_per_second = 0;
1590 1580
 
1591 1581
 	if(msg->first_line.type != SIP_REQUEST
1592 1582
 			|| 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 1599
 		return -1;
1600 1600
 	}
1601 1601
 
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) {
1602
+	if(sclient->len == 0 || sclient->s == NULL) {
1624 1603
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1625 1604
 				msg->callid->body.s);
1626 1605
 		return -1;
1627 1606
 	}
1628 1607
 
1629
-	credit = str2double(&scredit);
1608
+	credit = str2double(scredit);
1630 1609
 
1631 1610
 	if(credit <= 0) {
1632 1611
 		LM_ERR("credit value must be > 0: %f", credit);
1633 1612
 		return -1;
1634 1613
 	}
1635 1614
 
1636
-	cost_per_second = str2double(&scps);
1615
+	cost_per_second = str2double(scps);
1637 1616
 
1638 1617
 	if(cost_per_second <= 0) {
1639 1618
 		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 1643
 	LM_DBG("Setting up new call for client [%.*s], max-credit[%f], "
1644 1644
 			"cost-per-sec[%f], initial-pulse [%d], "
1645 1645
 			"final-pulse [%d], call-id[%.*s]\n",
1646
-			sclient.len, sclient.s, credit,
1646
+			sclient->len, sclient->s, credit,
1647 1647
 			cost_per_second, initp, finishp,
1648 1648
 			msg->callid->body.len, msg->callid->body.s);
1649 1649
 
1650 1650
 	set_ctrl_flag(msg);
1651 1651
 
1652
-	if((credit_data = __get_or_create_credit_data_entry(&sclient, CREDIT_MONEY))
1652
+	if((credit_data = __get_or_create_credit_data_entry(sclient, CREDIT_MONEY))
1653 1653
 			== NULL) {
1654 1654
 		LM_ERR("Error retrieving credit data from shared memory for client "
1655
-				"[%.*s]\n", sclient.len, sclient.s);
1655
+				"[%.*s]\n", sclient->len, sclient->s);
1656 1656
 		return -1;
1657 1657
 	}
1658 1658
 
... ...
@@ -1660,38 +1630,71 @@ static int __set_max_credit(sip_msg_t *msg, char *pclient,
1660 1660
 				cost_per_second, initp, finishp))
1661 1661
 			== NULL) {
1662 1662
 		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1663
-				sclient.len, sclient.s);
1663
+				sclient->len, sclient->s);
1664 1664
 		return -1;
1665 1665
 	}
1666 1666
 
1667 1667
 	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_MONEY) != 0) {
1668 1668
 		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1669
-				sclient.len, sclient.s);
1669
+				sclient->len, sclient->s);
1670 1670
 		return -1;
1671 1671
 	}
1672 1672
 
1673 1673
 	return 1;
1674 1674
 }
1675 1675
 
1676
-static int __terminate_all(sip_msg_t *msg, char *pclient, char *p2)
1676
+static int __set_max_credit(sip_msg_t *msg, char *pclient,
1677
+		char *pcredit, char *pcps, char *pinitp, char *pfinishp)
1677 1678
 {
1678
-	credit_data_t *credit_data = NULL;
1679 1679
 	str sclient;
1680
+	str scredit;
1681
+	str scps;
1682
+	int initp;
1683
+	int finishp;
1684
+
1685
+	if(msg==NULL || pclient==NULL || pcredit==NULL || pcps==NULL
1686
+			|| pinitp==NULL || pfinishp==NULL) {
1687
+		LM_ERR("invalid parameters\n");
1688
+		return -1;
1689
+	}
1680 1690
 
1681 1691
 	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1682 1692
 		LM_ERR("failed to get client parameter\n");
1683 1693
 		return -1;
1684 1694
 	}
1695
+	if(fixup_get_svalue(msg, (gparam_t*)pcredit, &scredit)<0) {
1696
+		LM_ERR("failed to get credit parameter\n");
1697
+		return -1;
1698
+	}
1699
+	if(fixup_get_svalue(msg, (gparam_t*)pcps, &scps)<0) {
1700
+		LM_ERR("failed to get cps parameter\n");
1701
+		return -1;
1702
+	}
1703
+	if(fixup_get_ivalue(msg, (gparam_t*)pinitp, &initp)<0) {
1704
+		LM_ERR("failed to get init pulse parameter\n");
1705
+		return -1;
1706
+	}
1707
+	if(fixup_get_ivalue(msg, (gparam_t*)pfinishp, &finishp)<0) {
1708
+		LM_ERR("failed to get finish pulse parameter\n");
1709
+		return -1;
1710
+	}
1685 1711
 
1686
-	if(sclient.len == 0 || sclient.s == NULL) {
1712
+	return ki_set_max_credit(msg, &sclient, &scredit, &scps, initp, finishp);
1713
+}
1714
+
1715
+static int ki_terminate_all(sip_msg_t *msg, str *sclient)
1716
+{
1717
+	credit_data_t *credit_data = NULL;
1718
+
1719
+	if(sclient->len == 0 || sclient->s == NULL) {
1687 1720
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1688 1721
 				msg->callid->body.s);
1689 1722
 		return -1;
1690 1723
 	}
1691 1724
 
1692
-	if(try_get_credit_data_entry(&sclient, &credit_data) != 0) {
1725
+	if(try_get_credit_data_entry(sclient, &credit_data) != 0) {
1693 1726
 		LM_DBG("credit data for [%.*s] on [%.*s] not found\n",
1694
-				sclient.len, sclient.s,
1727
+				sclient->len, sclient->s,
1695 1728
 				msg->callid->body.len, msg->callid->body.s);
1696 1729
 		return -1;
1697 1730
 	}
... ...
@@ -1700,36 +1703,41 @@ static int __terminate_all(sip_msg_t *msg, char *pclient, char *p2)
1700 1700
 	return 1;
1701 1701
 }
1702 1702
 
1703
-static int __get_channel_count(sip_msg_t *msg, char *pclient, char *pcount)
1703
+static int __terminate_all(sip_msg_t *msg, char *pclient, char *p2)
1704 1704
 {
1705
-	credit_data_t *credit_data = NULL;
1706
-	pv_spec_t *pvcount = (pv_spec_t *)pcount;
1705
+	str sclient;
1706
+
1707
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1708
+		LM_ERR("failed to get client parameter\n");
1709
+		return -1;
1710
+	}
1711
+
1712
+	return ki_terminate_all(msg, &sclient);
1713
+}
1707 1714
 
1715
+static int __get_channel_count_helper(sip_msg_t *msg, str *sclient,
1716
+		pv_spec_t *pvcount)
1717
+{
1718
+	credit_data_t *credit_data = NULL;
1708 1719
 	pv_value_t countval;
1709 1720
 	int value = -1;
1710
-	str sclient;
1711 1721
 
1712 1722
 	if(!pv_is_w(pvcount)) {
1713 1723
 		LM_ERR("pvar is not writable\n");
1714 1724
 		return -1;
1715 1725
 	}
1716 1726
 
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) {
1727
+	if(sclient->len == 0 || sclient->s == NULL) {
1723 1728
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1724 1729
 				msg->callid->body.s);
1725 1730
 		return -1;
1726 1731
 	}
1727 1732
 
1728
-	if(try_get_credit_data_entry(&sclient, &credit_data) == 0)
1733
+	if(try_get_credit_data_entry(sclient, &credit_data) == 0)
1729 1734
 		value = credit_data->number_of_calls;
1730 1735
 	else
1731
-		LM_ALERT("[%.*s] not found\n", msg->callid->body.len,
1732
-				msg->callid->body.s);
1736
+		LM_ALERT("[%.*s] [%.*s] not found\n", sclient->len, sclient->s,
1737
+				msg->callid->body.len, msg->callid->body.s);
1733 1738
 
1734 1739
 	memset(&countval, 0, sizeof(countval));
1735 1740
 
... ...
@@ -1745,12 +1753,36 @@ static int __get_channel_count(sip_msg_t *msg, char *pclient, char *pcount)
1745 1745
 	return 1;
1746 1746
 }
1747 1747
 
1748
-static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1748
+static int __get_channel_count(sip_msg_t *msg, char *pclient, char *pcount)
1749
+{
1750
+	pv_spec_t *pvcount = (pv_spec_t *)pcount;
1751
+	str sclient;
1752
+
1753
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1754
+		LM_ERR("failed to get client parameter\n");
1755
+		return -1;
1756
+	}
1757
+
1758
+	return __get_channel_count_helper(msg, &sclient, (pv_spec_t *)pcount);
1759
+}
1760
+
1761
+static int ki_get_channel_count(sip_msg_t *msg, str *sclient, str *pvname)
1762
+{
1763
+	pv_spec_t *pvcount = NULL;
1764
+
1765
+	pvcount = pv_cache_get(pvname);
1766
+
1767
+	if(pvcount==NULL) {
1768
+		LM_ERR("failed to get pv spec for [%.*s]\n", pvname->len, pvname->s);
1769
+		return -1;
1770
+	}
1771
+	return __get_channel_count_helper(msg, sclient, pvcount);
1772
+}
1773
+
1774
+static int ki_set_max_channels(sip_msg_t *msg, str *sclient, int max_chan)
1749 1775
 {
1750 1776
 	credit_data_t *credit_data = NULL;
1751 1777
 	call_t *call = NULL;
1752
-	str sclient;
1753
-	int max_chan = 0;
1754 1778
 
1755 1779
 	if(parse_headers(msg, HDR_CALLID_F, 0) != 0) {
1756 1780
 		LM_ERR("Error parsing Call-ID");
... ...
@@ -1767,15 +1799,6 @@ static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1767 1767
 		return -1;
1768 1768
 	}
1769 1769
 
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 1770
 	set_ctrl_flag(msg);
1780 1771
 
1781 1772
 	if(max_chan <= 0) {
... ...
@@ -1784,7 +1807,7 @@ static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1784 1784
 		return -1;
1785 1785
 	}
1786 1786
 
1787
-	if(sclient.len == 0 || sclient.s == NULL) {
1787
+	if(sclient->len == 0 || sclient->s == NULL) {
1788 1788
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1789 1789
 				msg->callid->body.s);
1790 1790
 		return -1;
... ...
@@ -1792,13 +1815,13 @@ static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1792 1792
 
1793 1793
 	LM_DBG("Setting up new call for client [%.*s], max-chan[%d], "
1794 1794
 			"call-id[%.*s]\n",
1795
-			sclient.len, sclient.s, max_chan,
1795
+			sclient->len, sclient->s, max_chan,
1796 1796
 			msg->callid->body.len, msg->callid->body.s);
1797 1797
 
1798
-	if((credit_data = __get_or_create_credit_data_entry(&sclient,
1798
+	if((credit_data = __get_or_create_credit_data_entry(sclient,
1799 1799
 				CREDIT_CHANNEL)) == NULL) {
1800 1800
 		LM_ERR("Error retrieving credit data from shared memory for client "
1801
-				"[%.*s]\n", sclient.len, sclient.s);
1801
+				"[%.*s]\n", sclient->len, sclient->s);
1802 1802
 		return -1;
1803 1803
 	}
1804 1804
 
... ...
@@ -1811,28 +1834,41 @@ static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1811 1811
 	if((call = alloc_new_call_by_channel(credit_data, msg, max_chan))
1812 1812
 			== NULL) {
1813 1813
 		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1814
-				sclient.len, sclient.s);
1814
+				sclient->len, sclient->s);
1815 1815
 		return -1;
1816 1816
 	}
1817 1817
 
1818 1818
 	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_CHANNEL)
1819 1819
 			!= 0) {
1820 1820
 		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1821
-				sclient.len, sclient.s);
1821
+				sclient->len, sclient->s);
1822 1822
 		return -1;
1823 1823
 	}
1824 1824
 
1825 1825
 	return 1;
1826 1826
 }
1827 1827
 
1828
-static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1828
+static int __set_max_channels(sip_msg_t *msg, char *pclient, char *pmaxchan)
1829 1829
 {
1830
-	credit_data_t *credit_data = NULL;
1831
-	call_t *call = NULL;
1832 1830
 	str sclient;
1833
-	int max_secs = 0;
1831
+	int max_chan = 0;
1834 1832
 
1835
-	set_ctrl_flag(msg);
1833
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1834
+		LM_ERR("failed to get client parameter\n");
1835
+		return -1;
1836
+	}
1837
+	if(fixup_get_ivalue(msg, (gparam_t*)pmaxchan, &max_chan)<0) {
1838
+		LM_ERR("failed to get max chan parameter\n");
1839
+		return -1;
1840
+	}
1841
+
1842
+	return ki_set_max_channels(msg, &sclient, max_chan);
1843
+}
1844
+
1845
+static int ki_set_max_time(sip_msg_t *msg, str *sclient, int max_secs)
1846
+{
1847
+	credit_data_t *credit_data = NULL;
1848
+	call_t *call = NULL;
1836 1849
 
1837 1850
 	if(parse_headers(msg, HDR_CALLID_F, 0) != 0) {
1838 1851
 		LM_ERR("Error parsing Call-ID");
... ...
@@ -1850,14 +1886,7 @@ static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1850 1850
 		return -1;
1851 1851
 	}
1852 1852
 
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
-	}
1853
+	set_ctrl_flag(msg);
1861 1854
 
1862 1855
 	if(max_secs <= 0) {
1863 1856
 		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 1865
 		return -1;
1866 1866
 	}
1867 1867
 
1868
-	if(sclient.len == 0 || sclient.s == NULL) {
1868
+	if(sclient->len <= 0 || sclient->s == NULL) {
1869 1869
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1870 1870
 				msg->callid->body.s);
1871 1871
 		return -1;
... ...
@@ -1873,51 +1902,57 @@ static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1873 1873
 
1874 1874
 	LM_DBG("Setting up new call for client [%.*s], max-secs[%d], "
1875 1875
 			"call-id[%.*s]\n",
1876
-			sclient.len, sclient.s, max_secs,
1876
+			sclient->len, sclient->s, max_secs,
1877 1877
 			msg->callid->body.len, msg->callid->body.s);
1878 1878
 
1879
-	if((credit_data = __get_or_create_credit_data_entry(&sclient, CREDIT_TIME))
1879
+	if((credit_data = __get_or_create_credit_data_entry(sclient, CREDIT_TIME))
1880 1880
 			== NULL) {
1881 1881
 		LM_ERR("Error retrieving credit data from shared memory for client "
1882
-				"[%.*s]\n", sclient.len, sclient.s);
1882
+				"[%.*s]\n", sclient->len, sclient->s);
1883 1883
 		return -1;
1884 1884
 	}
1885 1885
 
1886 1886
 	if((call = __alloc_new_call_by_time(credit_data, msg, max_secs))
1887 1887
 			== NULL) {
1888 1888
 		LM_ERR("Unable to allocate new call for client [%.*s]\n",
1889
-				sclient.len, sclient.s);
1889
+				sclient->len, sclient->s);
1890 1890
 		return -1;
1891 1891
 	}
1892 1892
 
1893 1893
 	if(__add_call_by_cid(&call->sip_data.callid, call, CREDIT_TIME) != 0) {
1894 1894
 		LM_ERR("Unable to allocate new cid_by_client for client [%.*s]\n",
1895
-				sclient.len, sclient.s);
1895
+				sclient->len, sclient->s);
1896 1896
 		return -1;
1897 1897
 	}
1898 1898
 
1899 1899
 	return 1;
1900 1900
 }
1901 1901
 
1902
-static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1902
+static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs)
1903 1903
 {
1904
-	credit_data_t *credit_data = NULL;
1905 1904
 	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
-	}
1905
+	int max_secs = 0;
1914 1906
 
1915 1907
 	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1916 1908
 		LM_ERR("failed to get client parameter\n");
1917 1909
 		return -1;
1918 1910
 	}
1919
-	if(fixup_get_ivalue(msg, (gparam_t*)psecs, &secs)<0) {
1920
-		LM_ERR("failed to get secs parameter\n");
1911
+	if(fixup_get_ivalue(msg, (gparam_t*)pmaxsecs, &max_secs)<0) {
1912
+		LM_ERR("failed to get max secs parameter\n");
1913
+		return -1;
1914
+	}
1915
+
1916
+	return ki_set_max_time(msg, &sclient, max_secs);
1917
+}
1918
+
1919
+static int ki_update_max_time(sip_msg_t *msg, str *sclient, int secs)
1920
+{
1921
+	credit_data_t *credit_data = NULL;
1922
+
1923
+	set_ctrl_flag(msg);
1924
+
1925
+	if(parse_headers(msg, HDR_CALLID_F, 0) != 0) {
1926
+		LM_ERR("Error parsing Call-ID");
1921 1927
 		return -1;
1922 1928
 	}
1923 1929
 
... ...
@@ -1927,14 +1962,14 @@ static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1927 1927
 		return -1;
1928 1928
 	}
1929 1929
 
1930
-	if(sclient.len == 0 || sclient.s == NULL) {
1930
+	if(sclient->len == 0 || sclient->s == NULL) {
1931 1931
 		LM_ERR("[%.*s]: client ID cannot be null\n", msg->callid->body.len,
1932 1932
 				msg->callid->body.s);
1933 1933
 		return -1;
1934 1934
 	}
1935 1935
 
1936 1936
 	LM_DBG("Updating call for client [%.*s], max-secs[%d], call-id[%.*s]\n",
1937
-			sclient.len, sclient.s, secs,
1937
+			sclient->len, sclient->s, secs,
1938 1938
 			msg->callid->body.len, msg->callid->body.s);
1939 1939
 
1940 1940
 
... ...
@@ -1945,12 +1980,12 @@ static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1945 1945
 	call_t *call = NULL, *tmp_call = NULL;
1946 1946
 
1947 1947
 	cnxcc_lock(_data.time.lock);
1948
-	e = str_hash_get(ht, sclient.s, sclient.len);
1948
+	e = str_hash_get(ht, sclient->s, sclient->len);
1949 1949
 	cnxcc_unlock(_data.time.lock);
1950 1950
 
1951 1951
 	if(e == NULL) {
1952
-		LM_ERR("Client [%.*s] was not found\n", sclient.len,
1953
-				sclient.s);
1952
+		LM_ERR("Client [%.*s] was not found\n", sclient->len,
1953
+				sclient->s);
1954 1954
 		return -1;
1955 1955
 	}
1956 1956
 
... ...
@@ -1975,12 +2010,28 @@ static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1975 1975
 
1976 1976
 	//redit_data->consumed_amount = 0;
1977 1977
 
1978
-
1979 1978
 	cnxcc_unlock(credit_data->lock);
1980 1979
 
1981 1980
 	return 1;
1982 1981
 }
1983 1982
 
1983
+static int __update_max_time(sip_msg_t *msg, char *pclient, char *psecs)
1984
+{
1985
+	str sclient;
1986
+	int secs = 0;
1987
+
1988
+	if(fixup_get_svalue(msg, (gparam_t*)pclient, &sclient)<0) {
1989
+		LM_ERR("failed to get client parameter\n");
1990
+		return -1;
1991
+	}
1992
+	if(fixup_get_ivalue(msg, (gparam_t*)psecs, &secs)<0) {
1993
+		LM_ERR("failed to get secs parameter\n");
1994
+		return -1;
1995
+	}
1996
+
1997
+	return ki_update_max_time(msg, &sclient, secs);
1998
+}
1999
+
1984 2000
 static int __has_to_tag(struct sip_msg *msg)
1985 2001
 {
1986 2002
 	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 2054
 	rpc->struct_add(rh, "sddd", "info", "CNX Credit Control", "active",
2055 2055
 			_data.stats->active, "dropped", _data.stats->dropped, "total",
2056 2056
 			_data.stats->total);
2057
+}
2058
+
2059
+/**
2060
+ *
2061
+ */
2062
+/* clang-format off */
2063
+static sr_kemi_t sr_kemi_cnxcc_exports[] = {
2064
+	{ str_init("cnxcc"), str_init("set_max_credit"),
2065
+		SR_KEMIP_INT, ki_set_max_credit,
2066
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
2067
+			SR_KEMIP_INT, SR_KEMIP_INT, SR_KEMIP_NONE }
2068
+	},
2069
+	{ str_init("cnxcc"), str_init("set_max_time"),
2070
+		SR_KEMIP_INT, ki_set_max_time,
2071
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2072
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2073
+	},
2074
+	{ str_init("cnxcc"), str_init("update_max_time"),
2075
+		SR_KEMIP_INT, ki_update_max_time,
2076
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2077
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2078
+	},
2079
+	{ str_init("cnxcc"), str_init("set_max_channels"),
2080
+		SR_KEMIP_INT, ki_set_max_channels,
2081
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2082
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2083
+	},
2084
+	{ str_init("cnxcc"), str_init("get_channel_count"),
2085
+		SR_KEMIP_INT, ki_get_channel_count,
2086
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2087
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2088
+	},
2089
+	{ str_init("cnxcc"), str_init("terminate_all"),
2090
+		SR_KEMIP_INT, ki_terminate_all,
2091
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
2092
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2093
+	},
2094
+
2095
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
2096
+};
2097
+/* clang-format on */
2098
+
2099
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
2100
+{
2101
+	sr_kemi_modules_add(sr_kemi_cnxcc_exports);
2102
+	return 0;
2057 2103
 }
2058 2104
\ No newline at end of file