dialog: kemi functions to remove or test for null vars
authorDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 11 Jun 2019 10:10:53 +0000 (12:10 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Tue, 11 Jun 2019 10:10:53 +0000 (12:10 +0200)
src/modules/dialog/dialog.c

index cb3a80b..34d243a 100644 (file)
@@ -1931,6 +1931,37 @@ static sr_kemi_xval_t* ki_dlg_var_getw(sip_msg_t *msg, str *name)
 /**
  *
  */
+static int ki_dlg_var_rm(sip_msg_t *msg, str *name)
+{
+       dlg_cell_t *dlg;
+
+       dlg = dlg_get_msg_dialog(msg);
+       set_dlg_variable_unsafe(dlg, name, NULL);
+       return 1;
+}
+
+/**
+ *
+ */
+static int ki_dlg_var_is_null(sip_msg_t *msg, str *name)
+{
+       dlg_cell_t *dlg;
+       str *pval;
+
+       dlg = dlg_get_msg_dialog(msg);
+       if(dlg==NULL) {
+               return 1;
+       }
+       pval = get_dlg_variable(dlg, name);
+       if(pval==NULL || pval->s==NULL) {
+               return 1;
+       }
+       return -1;
+}
+
+/**
+ *
+ */
 /* clang-format off */
 static sr_kemi_t sr_kemi_dialog_exports[] = {
        { str_init("dialog"), str_init("dlg_manage"),
@@ -2053,6 +2084,16 @@ static sr_kemi_t sr_kemi_dialog_exports[] = {
                { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
                        SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
        },
+       { str_init("dialog"), str_init("var_rm"),
+               SR_KEMIP_XVAL, ki_dlg_var_rm,
+               { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
+       { str_init("dialog"), str_init("var_is_null"),
+               SR_KEMIP_XVAL, ki_dlg_var_is_null,
+               { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
 
        { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };