Browse code

dialog: add new dlg_reset_property function

- new dlg_reset_property() function is added to disable the previously enabled dialog module behaviour.
e.g. stop sending keep-alive OPTIONS messages.

KORAY VATANSEVER authored on 09/12/2019 05:41:56
Showing 2 changed files
... ...
@@ -176,6 +176,7 @@ static int w_dlg_isflagset(struct sip_msg *msg, char *flag, str *s2);
176 176
 static int w_dlg_resetflag(struct sip_msg *msg, char *flag, str *s2);
177 177
 static int w_dlg_setflag(struct sip_msg *msg, char *flag, char *s2);
178 178
 static int w_dlg_set_property(struct sip_msg *msg, char *prop, char *s2);
179
+static int w_dlg_reset_property(struct sip_msg *msg, char *prop, char *s2);
179 180
 static int w_dlg_manage(struct sip_msg*, char*, char*);
180 181
 static int w_dlg_bye(struct sip_msg*, char*, char*);
181 182
 static int w_dlg_refer(struct sip_msg*, char*, char*);
... ...
@@ -244,6 +245,8 @@ static cmd_export_t cmds[]={
244 245
 			0, ANY_ROUTE },
245 246
 	{"dlg_set_property", (cmd_function)w_dlg_set_property,1,fixup_spve_null,
246 247
 			0, ANY_ROUTE },
248
+    {"dlg_reset_property", (cmd_function)w_dlg_reset_property,1,fixup_spve_null,
249
+            0, ANY_ROUTE }, 			
247 250
 	{"dlg_remote_profile", (cmd_function)w_dlg_remote_profile, 5, fixup_dlg_remote_profile,
248 251
 			0, ANY_ROUTE },
249 252
 	{"dlg_set_ruri",       (cmd_function)w_dlg_set_ruri,  0, NULL,
... ...
@@ -1330,6 +1333,66 @@ static int w_dlg_set_property(struct sip_msg *msg, char *prop, char *s2)
1330 1333
 	return ki_dlg_set_property(msg, &val);
1331 1334
 }
1332 1335
 
1336
+/**
1337
+ *
1338
+ */
1339
+static int ki_dlg_reset_property(sip_msg_t *msg, str *pval)
1340
+{
1341
+	dlg_ctx_t *dctx;
1342
+	dlg_cell_t *d;
1343
+
1344
+	if(pval->len<=0) {
1345
+			LM_ERR("empty property value\n");
1346
+			return -1;
1347
+	}
1348
+	if ( (dctx=dlg_get_dlg_ctx())==NULL )
1349
+			return -1;
1350
+
1351
+	if(pval->len==6 && strncmp(pval->s, "ka-src", 6)==0) {
1352
+			dctx->iflags &= ~(DLG_IFLAG_KA_SRC);
1353
+			d = dlg_get_by_iuid(&dctx->iuid);
1354
+			if(d!=NULL) {
1355
+					d->iflags &= ~(DLG_IFLAG_KA_SRC);
1356
+					dlg_release(d);
1357
+			}
1358
+	} else if(pval->len==6 && strncmp(pval->s, "ka-dst", 6)==0) {
1359
+			dctx->iflags &= ~(DLG_IFLAG_KA_DST);
1360
+			d = dlg_get_by_iuid(&dctx->iuid);
1361
+			if(d!=NULL) {
1362
+					d->iflags &= ~(DLG_IFLAG_KA_DST);
1363
+					dlg_release(d);
1364
+			}
1365
+	} else if(pval->len==15 && strncmp(pval->s, "timeout-noreset", 15)==0) {
1366
+			dctx->iflags &= ~(DLG_IFLAG_TIMER_NORESET);
1367
+			d = dlg_get_by_iuid(&dctx->iuid);
1368
+			if(d!=NULL) {
1369
+					d->iflags &= ~(DLG_IFLAG_TIMER_NORESET);
1370
+					dlg_release(d);
1371
+			}
1372
+	} else {
1373
+			LM_ERR("unknown property value [%.*s]\n", pval->len, pval->s);
1374
+			return -1;
1375
+	}
1376
+
1377
+	return 1;
1378
+}
1379
+
1380
+/**
1381
+ *
1382
+ */
1383
+static int w_dlg_reset_property(struct sip_msg *msg, char *prop, char *s2)
1384
+{
1385
+	str val;
1386
+
1387
+	if(fixup_get_svalue(msg, (gparam_t*)prop, &val)!=0)
1388
+	{
1389
+			LM_ERR("no property value\n");
1390
+			return -1;
1391
+	}
1392
+
1393
+	return ki_dlg_reset_property(msg, &val);
1394
+}
1395
+
1333 1396
 static int w_dlg_set_timeout_by_profile3(struct sip_msg *msg, char *profile,
1334 1397
 					char *value, char *timeout_str) 
1335 1398
 {
... ...
@@ -2373,6 +2373,48 @@ if(has_totag()) {
2373 2373
     }
2374 2374
 }
2375 2375
 ...
2376
+</programlisting>
2377
+		</example>
2378
+	</section>
2379
+
2380
+	<section id="dialog.f.dlg_reset_property">
2381
+		<title>
2382
+		<function moreinfo="none">dlg_reset_property(attr)</function>
2383
+		</title>
2384
+		<para>
2385
+			Reset a dialog property - an attribute that enable/disable
2386
+			various behaviours (e.g., sending keep alive requests).
2387
+		</para>
2388
+		<para>Meaning of the parameters is as follows:</para>
2389
+		<itemizedlist>
2390
+		<listitem>
2391
+			<para><emphasis>attr</emphasis> - name of property. It can be:
2392
+				<itemizedlist>
2393
+					<listitem>
2394
+						'ka-src' - send keep alive OPTION requests to caller
2395
+					</listitem>
2396
+					<listitem>
2397
+						'ka-dst' - send keep alive OPTION requests to callee
2398
+					</listitem>
2399
+					<listitem>
2400
+						'timeout-noreset' - don't reset timeout on in-dialog messages reception
2401
+					</listitem>
2402
+				</itemizedlist>
2403
+			</para>
2404
+		</listitem>
2405
+		</itemizedlist>
2406
+		<para>
2407
+			This function can be used from ANY_ROUTE.
2408
+		</para>
2409
+		<example>
2410
+		<title><function>dlg_reset_property</function> usage</title>
2411
+		<programlisting format="linespecific">
2412
+...
2413
+dlg_reset_property("ka-src");
2414
+dlg_reset_property("ka-dst");
2415
+dlg_reset_property("timeout-noreset");
2416
+...
2417
+
2376 2418
 </programlisting>
2377 2419
 		</example>
2378 2420
 	</section>