Merge branch 'master' of ssh://git.freeswitch.org:222/freeswitch

This commit is contained in:
Michal Bielicki - cypromis 2011-09-21 16:39:10 +02:00
commit 1fdd55f4d4
2 changed files with 37 additions and 14 deletions

View File

@ -1,6 +1,10 @@
<configuration name="mod_blacklist.conf" description="Blacklist module"> <configuration name="mod_blacklist.conf" description="Blacklist module">
<lists> <lists>
<!-- Example blacklist, the referenced file contains blacklisted items, one entry per line <!--
Example blacklist, the referenced file contains blacklisted items, one entry per line
NOTE: make sure the file exists and is readable by FreeSWITCH.
<list name="example" filename="/usr/local/freeswitch/conf/blacklists/example.list"/> <list name="example" filename="/usr/local/freeswitch/conf/blacklists/example.list"/>
--> -->
</lists> </lists>

View File

@ -86,23 +86,24 @@ void trim(char *string)
static switch_status_t load_list(const char *name, const char *filename) static switch_status_t load_list(const char *name, const char *filename)
{ {
FILE *f; FILE *f;
blacklist_t *bl = blacklist_create(name);
/* Create a hashtable + mutex for that list */
if ((f = fopen(filename, "r"))) { if ((f = fopen(filename, "r"))) {
char buf[1024] = {0}; char buf[1024] = {0};
blacklist_t *bl = blacklist_create(name); /* Create a hashtable + mutex for that list */
while (fgets(buf, 1024, f)) { while (fgets(buf, 1024, f)) {
trim(buf); trim(buf);
switch_core_hash_insert(bl->list, buf, (void *)SWITCH_TRUE); switch_core_hash_insert(bl->list, buf, (void *)SWITCH_TRUE);
} }
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't open [%s] to load list [%s]\n", filename, name);
return SWITCH_STATUS_FALSE;
}
switch_core_hash_insert(globals.lists, name, bl); switch_core_hash_insert(globals.lists, name, bl);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Loaded list [%s]\n", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Loaded list [%s]\n", name);
fclose(f);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't open [%s] to load list [%s]\n", filename, name);
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -134,9 +135,16 @@ static switch_status_t do_config(switch_bool_t reload)
const char *name = switch_xml_attr_soft(list, "name"); const char *name = switch_xml_attr_soft(list, "name");
const char *filename = switch_xml_attr_soft(list, "filename"); const char *filename = switch_xml_attr_soft(list, "filename");
if (name && filename) { if (zstr(name)) {
load_list(name, filename); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "list has no name\n");
continue;
} }
if (zstr(filename)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "list [%s] has no filename\n", name);
continue;
}
load_list(name, filename);
} }
} }
@ -150,6 +158,13 @@ static switch_status_t do_config(switch_bool_t reload)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
#define BLACKLIST_API_SYNTAX \
"blacklist check <listname> <item>\n" \
"blacklist add <listname> <item>\n" \
"blacklist del <listname> <item>\n" \
"blacklist reload\n" \
"blacklist help\n"
SWITCH_STANDARD_API(blacklist_api_function) SWITCH_STANDARD_API(blacklist_api_function)
{ {
char *data; char *data;
@ -233,6 +248,10 @@ SWITCH_STANDARD_API(blacklist_api_function)
} else if (!strcasecmp(argv[0], "reload")) { } else if (!strcasecmp(argv[0], "reload")) {
do_config(SWITCH_TRUE); do_config(SWITCH_TRUE);
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "help")) {
stream->write_function(stream, BLACKLIST_API_SYNTAX "+OK\n");
} else if (!zstr(argv[0])) {
stream->write_function(stream, "-ERR: No such command: %s (see 'blacklist help')\n", argv[0]);
} }
done: done: