Skip to content

Commit

Permalink
dialog: forbid terminating dialogs via MI when replication tag is backup
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Mar 27, 2018
1 parent 91b9259 commit 5fdbce4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
20 changes: 18 additions & 2 deletions modules/dialog/dlg_profile.c
Expand Up @@ -1346,6 +1346,7 @@ struct mi_root * mi_profile_terminate(struct mi_root *cmd_tree, void *param ) {
struct dlg_cell *cur_dlg;
struct dlg_profile_link *cur_link;
struct dialog_list *deleted = NULL, *delete_entry ;
int rtag_state;

node = cmd_tree->node.kids;
if (node==NULL || !node->value.s || !node->value.len)
Expand Down Expand Up @@ -1407,15 +1408,30 @@ struct mi_root * mi_profile_terminate(struct mi_root *cmd_tree, void *param ) {

delete_entry = deleted;
while(delete_entry){
init_dlg_term_reason(delete_entry->dlg,"MI Termination",sizeof("MI Termination")-1);
if (dialog_repl_cluster) {
rtag_state = get_repltag_state(delete_entry->dlg);
if (rtag_state < 0) {
while(delete_entry){
deleted = delete_entry;
delete_entry = delete_entry->next;
pkg_free(deleted);
}
LM_ERR("error while checking replication tag\n");
return init_mi_tree( 400, MI_SSTR("Dialog internal error"));
} else if (rtag_state == 0)
continue;
}

init_dlg_term_reason(delete_entry->dlg, "MI Termination",
sizeof("MI Termination") - 1);

if ( dlg_end_dlg( delete_entry->dlg, NULL) ) {
while(delete_entry){
deleted = delete_entry;
delete_entry = delete_entry->next;
pkg_free(deleted);
}
LM_CRIT("error while terminating dlg\n");
LM_ERR("error while terminating dlg\n");
return init_mi_tree( 400, MI_SSTR("Dialog internal error"));
}

Expand Down
15 changes: 15 additions & 0 deletions modules/dialog/dlg_req_within.c
Expand Up @@ -43,6 +43,7 @@
#include "dlg_db_handler.h"
#include "dlg_profile.h"
#include "dlg_handlers.h"
#include "dlg_replication.h"

extern str dlg_extra_hdrs;

Expand Down Expand Up @@ -481,6 +482,7 @@ struct mi_root * mi_terminate_dlg(struct mi_root *cmd_tree, void *param ){
char *msg;
char *end;
char bkp;
int rtag_state = 1;


if( d_table ==NULL)
Expand Down Expand Up @@ -528,6 +530,19 @@ struct mi_root * mi_terminate_dlg(struct mi_root *cmd_tree, void *param ){
}

if (dlg) {
if (dialog_repl_cluster) {
rtag_state = get_repltag_state(dlg);
if (rtag_state < 0) {
unref_dlg(dlg, 1);
return init_mi_tree(403, MI_DLG_OPERATION_ERR,
MI_DLG_OPERATION_ERR_LEN);
} else if (rtag_state == 0) {
unref_dlg(dlg, 1);
return init_mi_tree(403, MI_DIALOG_BACKUP_ERR,
MI_DIALOG_BACKUP_ERR_LEN);
}
}

/* lookup_dlg has incremented the reference count !! */
init_dlg_term_reason(dlg,"MI Termination",sizeof("MI Termination")-1);

Expand Down
2 changes: 2 additions & 0 deletions modules/dialog/dlg_req_within.h
Expand Up @@ -41,6 +41,8 @@

#define MI_DIALOG_NOT_FOUND "Requested Dialog not found"
#define MI_DIALOG_NOT_FOUND_LEN (sizeof(MI_DIALOG_NOT_FOUND)-1)
#define MI_DIALOG_BACKUP_ERR "Node is backup for requested dialog"
#define MI_DIALOG_BACKUP_ERR_LEN (sizeof(MI_DIALOG_BACKUP_ERR)-1)
#define MI_DLG_OPERATION_ERR "Operation failed"
#define MI_DLG_OPERATION_ERR_LEN (sizeof(MI_DLG_OPERATION_ERR)-1)

Expand Down

0 comments on commit 5fdbce4

Please sign in to comment.