Browse code

Merge 2c70d8415abb6663500d07370d3b7a6e265e9e55 into d32f8f52198d04a90f53a221a1797faa1a0f39af

Victor Seva authored on 16/05/2022 13:26:26 • GitHub committed on 16/05/2022 13:26:26
Showing 2 changed files
... ...
@@ -194,7 +194,12 @@ static int w_is_known_dlg(struct sip_msg *);
194 194
 static int w_dlg_set_ruri(sip_msg_t *, char *, char *);
195 195
 static int w_dlg_db_load_callid(sip_msg_t *msg, char *ci, char *p2);
196 196
 static int w_dlg_db_load_extra(sip_msg_t *msg, char *p1, char *p2);
197
-
197
+static int fixup_dlg_get_var(void** param, int param_no);
198
+static int fixup_dlg_get_var_free(void** param, int param_no);
199
+static int w_dlg_get_var(struct sip_msg*, char*, char*, char*, char*, char*);
200
+static int fixup_dlg_set_var(void** param, int param_no);
201
+static int fixup_dlg_set_var_free(void** param, int param_no);
202
+static int w_dlg_set_var(struct sip_msg*, char*, char*, char*, char*, char*);
198 203
 static int w_dlg_remote_profile(sip_msg_t *msg, char *cmd, char *pname,
199 204
 		char *pval, char *puid, char *expires);
200 205
 static int fixup_dlg_remote_profile(void** param, int param_no);
... ...
@@ -256,6 +261,10 @@ static cmd_export_t cmds[]={
256 261
 			0, ANY_ROUTE },
257 262
 	{"dlg_db_load_extra", (cmd_function)w_dlg_db_load_extra, 0, 0,
258 263
 			0, ANY_ROUTE },
264
+	{"dlg_get_var",(cmd_function)w_dlg_get_var, 5, fixup_dlg_get_var,
265
+			fixup_dlg_get_var_free, ANY_ROUTE },
266
+	{"dlg_set_var",(cmd_function)w_dlg_set_var, 5, fixup_dlg_set_var,
267
+			fixup_dlg_set_var_free, ANY_ROUTE },
259 268
 
260 269
 	{"load_dlg",  (cmd_function)load_dlg,   0, 0, 0, 0},
261 270
 	{0,0,0,0,0,0}
... ...
@@ -1502,6 +1511,198 @@ static int fixup_dlg_bridge(void** param, int param_no)
1502 1511
 	return 0;
1503 1512
 }
1504 1513
 
1514
+static str *ki_dlg_get_var(sip_msg_t *msg, str *sc, str *sf, str *st, str *key)
1515
+{
1516
+	dlg_cell_t *dlg = NULL;
1517
+	unsigned int dir = 0;
1518
+	str *val = NULL;
1519
+
1520
+	if(sc==NULL || sc->s==NULL || sc->len == 0) {
1521
+		LM_ERR("invalid Call-ID parameter\n");
1522
+		return val;
1523
+	}
1524
+	if(sf==NULL || sf->s==NULL || sf->len == 0) {
1525
+		LM_ERR("invalid From tag parameter\n");
1526
+		return val;
1527
+	}
1528
+	if(st==NULL || st->s==NULL || st->len == 0) {
1529
+		LM_ERR("invalid To tag parameter\n");
1530
+		return val;
1531
+	}
1532
+
1533
+	dlg = get_dlg(sc, sf, st, &dir);
1534
+	if(dlg==NULL)
1535
+		return val;
1536
+	val = get_dlg_variable(dlg, key);
1537
+	dlg_release(dlg);
1538
+	return val;
1539
+}
1540
+
1541
+static int w_dlg_get_var(struct sip_msg *msg, char *ci, char *ft, char *tt, char *key, char *pv)
1542
+{
1543
+	str sc = STR_NULL;
1544
+	str sf = STR_NULL;
1545
+	str st = STR_NULL;
1546
+	str k = STR_NULL;
1547
+	str *val = NULL;
1548
+	pv_value_t dst_val;
1549
+	pv_spec_t* dst_pv;
1550
+
1551
+	if(ci==0 || ft==0 || tt==0)
1552
+	{
1553
+		LM_ERR("invalid parameters\n");
1554
+		return -1;
1555
+	}
1556
+
1557
+	if(fixup_get_svalue(msg, (gparam_p)ci, &sc)!=0)
1558
+	{
1559
+		LM_ERR("unable to get Call-ID\n");
1560
+		return -1;
1561
+	}
1562
+
1563
+	if(fixup_get_svalue(msg, (gparam_p)ft, &sf)!=0)
1564
+	{
1565
+		LM_ERR("unable to get From tag\n");
1566
+		return -1;
1567
+	}
1568
+
1569
+	if(fixup_get_svalue(msg, (gparam_p)tt, &st)!=0)
1570
+	{
1571
+		LM_ERR("unable to get To Tag\n");
1572
+		return -1;
1573
+	}
1574
+	if(st.s==NULL || st.len == 0)
1575
+	{
1576
+		LM_ERR("invalid To tag parameter\n");
1577
+		return -1;
1578
+	}
1579
+	if(fixup_get_svalue(msg, (gparam_p)key, &k)!=0)
1580
+	{
1581
+		LM_ERR("unable to get key name\n");
1582
+		return -1;
1583
+	}
1584
+	dst_pv = (pv_spec_t *)pv;
1585
+	val = ki_dlg_get_var(msg, &sc, &sf, &st, &k);
1586
+	if(val) {
1587
+		memset(&dst_val, 0, sizeof(pv_value_t));
1588
+		dst_val.flags |= PV_VAL_STR;
1589
+		dst_val.rs.s = val->s;
1590
+		dst_val.rs.len = val->len;
1591
+		if(pv_set_spec_value(msg, dst_pv, 0, &dst_val) != 0) return -1;
1592
+	} else {
1593
+		if(pv_get_null(msg, NULL, &dst_val) != 0) return -1;
1594
+	}
1595
+	return 1;
1596
+}
1597
+
1598
+static int fixup_dlg_get_var(void** param, int param_no)
1599
+{
1600
+	if(param_no>=1 && param_no<=4)
1601
+		return fixup_spve_null(param, 1);
1602
+	if(param_no==5)
1603
+		return fixup_pvar_all(param, 1);
1604
+	return 0;
1605
+}
1606
+
1607
+static int fixup_dlg_get_var_free(void** param, int param_no)
1608
+{
1609
+	if (param_no <= 4)
1610
+		return fixup_free_spve_null(param, 1);
1611
+	if (param_no == 5)
1612
+		return fixup_free_pvar_all(param, 1);
1613
+	return -1;
1614
+}
1615
+
1616
+static int ki_dlg_set_var(sip_msg_t *msg, str *sc, str *sf, str *st, str *key, str *val)
1617
+{
1618
+	dlg_cell_t *dlg = NULL;
1619
+	unsigned int dir = 0;
1620
+	int ret = 1;
1621
+
1622
+	if(sc==NULL || sc->s==NULL || sc->len == 0) {
1623
+		LM_ERR("invalid Call-ID parameter\n");
1624
+		return -1;
1625
+	}
1626
+	if(sf==NULL || sf->s==NULL || sf->len == 0) {
1627
+		LM_ERR("invalid From tag parameter\n");
1628
+		return -1;
1629
+	}
1630
+	if(st==NULL || st->s==NULL || st->len == 0) {
1631
+		LM_ERR("invalid To tag parameter\n");
1632
+		return -1;
1633
+	}
1634
+
1635
+	dlg = get_dlg(sc, sf, st, &dir);
1636
+	if(dlg==NULL)
1637
+		return -1;
1638
+	if(set_dlg_variable(dlg, key, val) != 0) ret = -1;
1639
+	dlg_release(dlg);
1640
+	return ret;
1641
+}
1642
+
1643
+static int w_dlg_set_var(struct sip_msg *msg, char *ci, char *ft, char *tt, char *key, char *val)
1644
+{
1645
+	str sc = STR_NULL;
1646
+	str sf = STR_NULL;
1647
+	str st = STR_NULL;
1648
+	str k = STR_NULL;
1649
+	str v = STR_NULL;
1650
+
1651
+	if(ci==0 || ft==0 || tt==0)
1652
+	{
1653
+		LM_ERR("invalid parameters\n");
1654
+		return -1;
1655
+	}
1656
+
1657
+	if(fixup_get_svalue(msg, (gparam_p)ci, &sc)!=0)
1658
+	{
1659
+		LM_ERR("unable to get Call-ID\n");
1660
+		return -1;
1661
+	}
1662
+
1663
+	if(fixup_get_svalue(msg, (gparam_p)ft, &sf)!=0)
1664
+	{
1665
+		LM_ERR("unable to get From tag\n");
1666
+		return -1;
1667
+	}
1668
+
1669
+	if(fixup_get_svalue(msg, (gparam_p)tt, &st)!=0)
1670
+	{
1671
+		LM_ERR("unable to get To Tag\n");
1672
+		return -1;
1673
+	}
1674
+	if(st.s==NULL || st.len == 0)
1675
+	{
1676
+		LM_ERR("invalid To tag parameter\n");
1677
+		return -1;
1678
+	}
1679
+	if(fixup_get_svalue(msg, (gparam_p)key, &k)!=0)
1680
+	{
1681
+		LM_ERR("unable to get key name\n");
1682
+		return -1;
1683
+	}
1684
+	if(fixup_get_svalue(msg, (gparam_p)val, &v)!=0)
1685
+	{
1686
+		LM_ERR("unable to get value\n");
1687
+		return -1;
1688
+	}
1689
+	return ki_dlg_set_var(msg, &sc, &sf, &st, &k, &v);
1690
+}
1691
+
1692
+static int fixup_dlg_set_var(void** param, int param_no)
1693
+{
1694
+	if(param_no>=1 && param_no<=5)
1695
+		return fixup_spve_null(param, 1);
1696
+	return 0;
1697
+}
1698
+
1699
+static int fixup_dlg_set_var_free(void** param, int param_no)
1700
+{
1701
+	if (param_no <= 5)
1702
+		return fixup_free_spve_null(param, 1);
1703
+	return -1;
1704
+}
1705
+
1505 1706
 static int ki_dlg_get(sip_msg_t *msg, str *sc, str *sf, str *st)
1506 1707
 {
1507 1708
 	dlg_cell_t *dlg = NULL;
... ...
@@ -2087,6 +2288,16 @@ static sr_kemi_t sr_kemi_dialog_exports[] = {
2087 2288
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
2088 2289
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2089 2290
 	},
2291
+	{ str_init("dialog"), str_init("dlg_get_var"),
2292
+		SR_KEMIP_STR, ki_dlg_get_var,
2293
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
2294
+			SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }
2295
+	},
2296
+	{ str_init("dialog"), str_init("dlg_set_var"),
2297
+		SR_KEMIP_INT, ki_dlg_set_var,
2298
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
2299
+			SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE }
2300
+	},
2090 2301
 	{ str_init("dialog"), str_init("set_dlg_profile_static"),
2091 2302
 		SR_KEMIP_INT, ki_set_dlg_profile_static,
2092 2303
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
... ...
@@ -2103,6 +2103,102 @@ if(dlg_get("abcdef", "123", "456"))
2103 2103
 		</example>
2104 2104
 	</section>
2105 2105
 
2106
+	<section id="dialog.f.dlg_get_var">
2107
+		<title>
2108
+		<function moreinfo="none">dlg_get_var(callid, ftag, ttag, name, dst)</function>
2109
+		</title>
2110
+		<para>
2111
+			Get dlg_var of another dialog value based on Call-ID, From-Tag and To-Tag
2112
+			parameters.
2113
+		</para>
2114
+		<para>Meaning of the parameters is as follows:</para>
2115
+		<itemizedlist>
2116
+		<listitem>
2117
+			<para><emphasis>callid</emphasis> - SIP call-id.
2118
+			</para>
2119
+		</listitem>
2120
+		<listitem>
2121
+			<para><emphasis>ftag</emphasis> - SIP From tag.
2122
+			</para>
2123
+		</listitem>
2124
+		<listitem>
2125
+			<para><emphasis>ttag</emphasis> - SIP To tag.
2126
+			</para>
2127
+		</listitem>
2128
+		<listitem>
2129
+			<para><emphasis>name</emphasis> - key name of the $dlg_var.
2130
+			</para>
2131
+		</listitem>
2132
+		<listitem>
2133
+			<para><emphasis>dst</emphasis> - pv to store the value of $dlg_var(name).
2134
+			</para>
2135
+		</listitem>
2136
+		</itemizedlist>
2137
+		<para>
2138
+		This function can be used from BRANCH_ROUTE,
2139
+			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
2140
+		</para>
2141
+		<example>
2142
+		<title><function>dlg_get_var</function> usage</title>
2143
+		<programlisting format="linespecific">
2144
+...
2145
+if(dlg_get_var("$var(ci)", "$var(ft)", "456", "test", "$var(tmp)"))
2146
+{
2147
+	xdbg("$$dlg_var(test):$var(tmp)\n");
2148
+}
2149
+...
2150
+</programlisting>
2151
+		</example>
2152
+	</section>
2153
+
2154
+	<section id="dialog.f.dlg_set_var">
2155
+		<title>
2156
+		<function moreinfo="none">dlg_set_var(callid, ftag, ttag, name, value)</function>
2157
+		</title>
2158
+		<para>
2159
+			Set dlg_var of another dialog value based on Call-ID, From-Tag and To-Tag
2160
+			parameters.
2161
+		</para>
2162
+		<para>Meaning of the parameters is as follows:</para>
2163
+		<itemizedlist>
2164
+		<listitem>
2165
+			<para><emphasis>callid</emphasis> - SIP call-id.
2166
+			</para>
2167
+		</listitem>
2168
+		<listitem>
2169
+			<para><emphasis>ftag</emphasis> - SIP From tag.
2170
+			</para>
2171
+		</listitem>
2172
+		<listitem>
2173
+			<para><emphasis>ttag</emphasis> - SIP To tag.
2174
+			</para>
2175
+		</listitem>
2176
+		<listitem>
2177
+			<para><emphasis>name</emphasis> - key name of the $dlg_var.
2178
+			</para>
2179
+		</listitem>
2180
+		<listitem>
2181
+			<para><emphasis>value</emphasis> - string value to store at $dlg_var(name).
2182
+			</para>
2183
+		</listitem>
2184
+		</itemizedlist>
2185
+		<para>
2186
+		This function can be used from BRANCH_ROUTE,
2187
+			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
2188
+		</para>
2189
+		<example>
2190
+		<title><function>dlg_set_var</function> usage</title>
2191
+		<programlisting format="linespecific">
2192
+...
2193
+if(dlg_set_var("$var(ci)", "$var(ft)", "456", "test", "$var(tmp)"))
2194
+{
2195
+	xdbg("set $$dlg_var(test):$var(tmp)\n");
2196
+}
2197
+...
2198
+</programlisting>
2199
+		</example>
2200
+	</section>
2201
+
2106 2202
 	<section id="dialog.f.is_known_dlg">
2107 2203
 		<title>
2108 2204
 		<function moreinfo="none">is_known_dlg()</function>