]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3617 --resolve truncate file and rename dump to save
authorRaymond Chandler <intralanman@gmail.com>
Wed, 19 Oct 2011 00:48:34 +0000 (20:48 -0400)
committerRaymond Chandler <intralanman@gmail.com>
Wed, 19 Oct 2011 00:48:34 +0000 (20:48 -0400)
src/mod/applications/mod_blacklist/mod_blacklist.c

index bb2cd7828e82241c076ded1e7325112693f2cd13..39db25339664aecfc447aec42cd26dc43ca7fa1a 100644 (file)
@@ -166,6 +166,7 @@ static switch_status_t do_config(switch_bool_t reload)
        "blacklist check <listname> <item>\n"   \
        "blacklist add <listname> <item>\n"     \
        "blacklist del <listname> <item>\n"     \
+       "blacklist save <listname>\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"))  {