mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-14 13:28:31 +00:00
add centralized registration db to core db and use it from mod_sofia
This commit is contained in:
1 parent
88d410d314
commit
a2c0da53f3
5 files changed
+283
-3
No files matched your search
@@ -45,6 +45,149 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load);
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown);
|
||||
SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, mod_commands_shutdown, NULL);
|
||||
|
||||
|
||||
struct cb_helper {
|
||||
uint32_t row_process;
|
||||
switch_stream_handle_t *stream;
|
||||
};
|
||||
|
||||
static int url_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
{
|
||||
struct cb_helper *cb = (struct cb_helper *) pArg;
|
||||
|
||||
cb->row_process++;
|
||||
|
||||
if (!zstr(argv[0])) {
|
||||
cb->stream->write_function(cb->stream, "%s,", argv[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static switch_status_t select_url(const char *user,
|
||||
const char *domain,
|
||||
const char *concat,
|
||||
const char *exclude_contact,
|
||||
switch_stream_handle_t *stream)
|
||||
{
|
||||
struct cb_helper cb;
|
||||
char *sql, *errmsg = NULL;
|
||||
switch_core_flag_t cflags = switch_core_flags();
|
||||
switch_cache_db_handle_t *db = NULL;
|
||||
|
||||
if (!(cflags & SCF_USE_SQL)) {
|
||||
stream->write_function(stream, "-ERR SQL DISABLED NO DATA AVAILABLE!\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (switch_core_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
||||
stream->write_function(stream, "%s", "-ERR Databse Error!\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cb.row_process = 0;
|
||||
cb.stream = stream;
|
||||
|
||||
if (exclude_contact) {
|
||||
sql = switch_mprintf("select url, '%q' "
|
||||
"from registrations where user='%q' and realm='%q' "
|
||||
"and url not like '%%%s%%'", (concat != NULL) ? concat : "", user, domain, exclude_contact);
|
||||
} else {
|
||||
sql = switch_mprintf("select url, '%q' "
|
||||
"from registrations where user='%q' and realm='%q'",
|
||||
(concat != NULL) ? concat : "", user, domain);
|
||||
}
|
||||
|
||||
switch_assert(sql);
|
||||
switch_cache_db_execute_sql_callback(db, sql, url_callback, &cb, &errmsg);
|
||||
|
||||
if (errmsg) {
|
||||
stream->write_function(stream, "-ERR SQL Error [%s]\n", errmsg);
|
||||
free(errmsg);
|
||||
errmsg = NULL;
|
||||
}
|
||||
|
||||
switch_safe_free(sql);
|
||||
|
||||
if (db) {
|
||||
switch_cache_db_release_db_handle(&db);
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(reg_url_function)
|
||||
{
|
||||
char *data;
|
||||
char *user = NULL;
|
||||
char *domain = NULL, *dup_domain = NULL;
|
||||
char *concat = NULL;
|
||||
const char *exclude_contact = NULL;
|
||||
char *reply = "error/facility_not_subscribed";
|
||||
switch_stream_handle_t mystream = { 0 };
|
||||
|
||||
|
||||
if (!cmd) {
|
||||
stream->write_function(stream, "%s", "");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (session) {
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
exclude_contact = switch_channel_get_variable(channel, "sip_exclude_contact");
|
||||
}
|
||||
|
||||
|
||||
data = strdup(cmd);
|
||||
switch_assert(data);
|
||||
|
||||
user = data;
|
||||
|
||||
if ((domain = strchr(user, '@'))) {
|
||||
*domain++ = '\0';
|
||||
if ((concat = strchr(domain, '/'))) {
|
||||
*concat++ = '\0';
|
||||
}
|
||||
} else {
|
||||
if ((concat = strchr(user, '/'))) {
|
||||
*concat++ = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (zstr(domain)) {
|
||||
dup_domain = switch_core_get_variable_dup("domain");
|
||||
domain = dup_domain;
|
||||
}
|
||||
|
||||
if (!user) goto end;
|
||||
|
||||
|
||||
SWITCH_STANDARD_STREAM(mystream);
|
||||
switch_assert(mystream.data);
|
||||
|
||||
select_url(user, domain, concat, exclude_contact, &mystream);
|
||||
reply = mystream.data;
|
||||
|
||||
|
||||
end:
|
||||
|
||||
if (zstr(reply)) {
|
||||
reply = "error/user_not_registered";
|
||||
} else if (end_of(reply) == ',') {
|
||||
end_of(reply) = '\0';
|
||||
}
|
||||
|
||||
stream->write_function(stream, "%s", reply);
|
||||
reply = NULL;
|
||||
|
||||
switch_safe_free(mystream.data);
|
||||
|
||||
switch_safe_free(data);
|
||||
switch_safe_free(dup_domain);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(banner_function)
|
||||
{
|
||||
stream->write_function(stream, "%s", switch_core_banner());
|
||||
@@ -3738,6 +3881,14 @@ SWITCH_STANDARD_API(show_function)
|
||||
as = argv[3];
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(command, "registrations")) {
|
||||
sprintf(sql, "select * from registrations where hostname='%s'", hostname);
|
||||
if (argv[1] && !strcasecmp(argv[1], "count")) {
|
||||
holder.justcount = 1;
|
||||
if (argv[3] && !strcasecmp(argv[2], "as")) {
|
||||
as = argv[3];
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(command, "channels") && argv[1] && !strcasecmp(argv[1], "like")) {
|
||||
if (argv[2]) {
|
||||
char *p;
|
||||
@@ -4890,6 +5041,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
|
||||
SWITCH_ADD_API(commands_api_interface, "tone_detect", "Start Tone Detection on a channel", tone_detect_session_function, TONE_DETECT_SYNTAX);
|
||||
SWITCH_ADD_API(commands_api_interface, "unload", "Unload Module", unload_function, UNLOAD_SYNTAX);
|
||||
SWITCH_ADD_API(commands_api_interface, "unsched_api", "Unschedule an api command", unsched_api_function, UNSCHED_SYNTAX);
|
||||
SWITCH_ADD_API(commands_api_interface, "reg_url", "", reg_url_function, "<user>@<realm>");
|
||||
SWITCH_ADD_API(commands_api_interface, "url_decode", "url decode a string", url_decode_function, "<string>");
|
||||
SWITCH_ADD_API(commands_api_interface, "url_encode", "url encode a string", url_encode_function, "<string>");
|
||||
SWITCH_ADD_API(commands_api_interface, "user_data", "find user data", user_data_function, "<user>@<domain> [var|param|attr] <name>");
|
||||
@@ -5000,6 +5152,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
|
||||
switch_console_set_complete("add show management");
|
||||
switch_console_set_complete("add show modules");
|
||||
switch_console_set_complete("add show nat_map");
|
||||
switch_console_set_complete("add show registrations");
|
||||
switch_console_set_complete("add show say");
|
||||
switch_console_set_complete("add show timer");
|
||||
switch_console_set_complete("add shutdown");
|
||||
|
||||
Reference in new issue
Block a user