diff --git a/src/mod/applications/mod_blacklist/mod_blacklist.c b/src/mod/applications/mod_blacklist/mod_blacklist.c index bb2cd7828e..39db253396 100644 --- a/src/mod/applications/mod_blacklist/mod_blacklist.c +++ b/src/mod/applications/mod_blacklist/mod_blacklist.c @@ -166,6 +166,7 @@ static switch_status_t do_config(switch_bool_t reload) "blacklist check \n" \ "blacklist add \n" \ "blacklist del \n" \ + "blacklist save \n" \ "blacklist reload\n" \ "blacklist help\n" @@ -249,7 +250,7 @@ SWITCH_STANDARD_API(blacklist_api_function) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Removed [%s] from list [%s]\n", argv[2], argv[1]); switch_mutex_unlock(bl->list_mutex); stream->write_function(stream, "+OK\n"); - } else if (!strcasecmp(argv[0], "dump")) { + } else if (!strcasecmp(argv[0], "save")) { switch_hash_index_t *hi; void *val; const void *var; @@ -276,15 +277,19 @@ SWITCH_STANDARD_API(blacklist_api_function) goto done; } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Dumping %s to %s\n", argv[1], filename); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Saving %s to %s\n", argv[1], filename); switch_mutex_lock(globals.lists_mutex); - if (switch_file_open(&fd, filename, SWITCH_FOPEN_WRITE, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, globals.pool) == SWITCH_STATUS_SUCCESS) { + if (switch_file_open(&fd, filename, SWITCH_FOPEN_WRITE | SWITCH_FOPEN_TRUNCATE | SWITCH_FOPEN_CREATE, SWITCH_FPROT_OS_DEFAULT, globals.pool) + == SWITCH_STATUS_SUCCESS) { for (hi = switch_hash_first(NULL, bl->list); hi; hi = switch_hash_next(hi)) { switch_hash_this(hi, &var, NULL, &val); switch_file_printf(fd, "%s\n", (char *)var); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "adding %s to the dump file\n", (char *)var); } stream->write_function(stream, "+OK\n"); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "couldn't open %s for writing\n", filename); } switch_mutex_unlock(globals.lists_mutex); } else if (!strcasecmp(argv[0], "reload")) {