mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 20:51:58 +00:00
indent pass 2
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -99,10 +99,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
||||
}
|
||||
|
||||
if (!switch_strlen_zero(logdir)) {
|
||||
if ((path = switch_mprintf("%s%s%s.cdr.xml",
|
||||
logdir,
|
||||
SWITCH_PATH_SEPARATOR,
|
||||
switch_core_session_get_uuid(session)))) {
|
||||
if ((path = switch_mprintf("%s%s%s.cdr.xml", logdir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)))) {
|
||||
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
|
||||
int wrote;
|
||||
wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
|
||||
@@ -124,7 +121,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
||||
/* try to post it to the web server */
|
||||
if (!switch_strlen_zero(globals.url)) {
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
|
||||
if (globals.encode) {
|
||||
switch_size_t need_bytes = strlen(xml_text) * 3;
|
||||
|
||||
@@ -136,14 +133,14 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
||||
switch_url_encode(xml_text, xml_text_escaped, need_bytes);
|
||||
} else {
|
||||
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-base64-encoded");
|
||||
switch_b64_encode((unsigned char *)xml_text, need_bytes / 3, (unsigned char *)xml_text_escaped, need_bytes);
|
||||
switch_b64_encode((unsigned char *) xml_text, need_bytes / 3, (unsigned char *) xml_text_escaped, need_bytes);
|
||||
}
|
||||
switch_safe_free(xml_text);
|
||||
xml_text = xml_text_escaped;
|
||||
} else {
|
||||
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-plaintext");
|
||||
}
|
||||
|
||||
|
||||
if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
|
||||
goto error;
|
||||
@@ -165,15 +162,15 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
||||
slist = curl_slist_append(slist, "Expect:");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
|
||||
}
|
||||
|
||||
|
||||
if (globals.ignore_cacert_check) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
}
|
||||
|
||||
/* these were used for testing, optionally they may be enabled if someone desires
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 120); // tcp timeout
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
|
||||
*/
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 120); // tcp timeout
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
|
||||
*/
|
||||
|
||||
for (cur_try = 0; cur_try < globals.retries; cur_try++) {
|
||||
if (cur_try > 0) {
|
||||
@@ -184,7 +181,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
||||
if (httpRes == 200) {
|
||||
goto success;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n",httpRes, globals.url);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n", httpRes, globals.url);
|
||||
}
|
||||
}
|
||||
curl_easy_cleanup(curl_handle);
|
||||
@@ -197,10 +194,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
||||
/* if we are here the web post failed for some reason */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to post to web server, writing to file\n");
|
||||
|
||||
if ((path = switch_mprintf("%s%s%s.cdr.xml",
|
||||
globals.err_log_dir,
|
||||
SWITCH_PATH_SEPARATOR,
|
||||
switch_core_session_get_uuid(session)))) {
|
||||
if ((path = switch_mprintf("%s%s%s.cdr.xml", globals.err_log_dir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)))) {
|
||||
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
|
||||
int wrote;
|
||||
wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
|
||||
@@ -218,11 +212,11 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
||||
}
|
||||
}
|
||||
|
||||
success:
|
||||
success:
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
error:
|
||||
if (curl_handle) {
|
||||
error:
|
||||
if (curl_handle) {
|
||||
curl_easy_cleanup(curl_handle);
|
||||
}
|
||||
if (headers) {
|
||||
@@ -259,7 +253,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
|
||||
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
memset(&globals,0,sizeof(globals));
|
||||
memset(&globals, 0, sizeof(globals));
|
||||
globals.log_b = 1;
|
||||
globals.disable100continue = 0;
|
||||
|
||||
@@ -294,32 +288,22 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
|
||||
globals.retries = (uint32_t) atoi(val);
|
||||
} else if (!strcasecmp(var, "log-dir")) {
|
||||
if (switch_strlen_zero(val)) {
|
||||
globals.log_dir = switch_mprintf("%s%sxml_cdr",
|
||||
SWITCH_GLOBAL_dirs.log_dir,
|
||||
SWITCH_PATH_SEPARATOR);
|
||||
globals.log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
|
||||
} else {
|
||||
if (switch_is_file_path(val)) {
|
||||
globals.log_dir = strdup(val);
|
||||
} else {
|
||||
globals.log_dir = switch_mprintf("%s%s%s",
|
||||
SWITCH_GLOBAL_dirs.log_dir,
|
||||
SWITCH_PATH_SEPARATOR,
|
||||
val);
|
||||
globals.log_dir = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, val);
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(var, "err-log-dir")) {
|
||||
if (switch_strlen_zero(val)) {
|
||||
globals.err_log_dir = switch_mprintf("%s%sxml_cdr",
|
||||
SWITCH_GLOBAL_dirs.log_dir,
|
||||
SWITCH_PATH_SEPARATOR);
|
||||
globals.err_log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
|
||||
} else {
|
||||
if (switch_is_file_path(val)) {
|
||||
globals.err_log_dir = strdup(val);
|
||||
} else {
|
||||
globals.err_log_dir = switch_mprintf("%s%s%s",
|
||||
SWITCH_GLOBAL_dirs.log_dir,
|
||||
SWITCH_PATH_SEPARATOR,
|
||||
val);
|
||||
globals.err_log_dir = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, val);
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(var, "ignore-cacert-check") && switch_true(val)) {
|
||||
@@ -330,9 +314,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
|
||||
if (!switch_strlen_zero(globals.log_dir)) {
|
||||
globals.err_log_dir = strdup(globals.log_dir);
|
||||
} else {
|
||||
globals.err_log_dir = switch_mprintf("%s%sxml_cdr",
|
||||
SWITCH_GLOBAL_dirs.log_dir,
|
||||
SWITCH_PATH_SEPARATOR);
|
||||
globals.err_log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,7 +324,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
|
||||
globals.retries = 0;
|
||||
}
|
||||
|
||||
if (globals.retries && globals.delay<=0) {
|
||||
if (globals.retries && globals.delay <= 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "retries set but delay 0 setting to 5000ms\n");
|
||||
globals.delay = 5000;
|
||||
}
|
||||
@@ -355,9 +337,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
|
||||
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_cdr_shutdown)
|
||||
{
|
||||
|
||||
globals.shutdown=1;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
globals.shutdown = 1;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
|
||||
@@ -43,8 +43,8 @@ struct xml_binding {
|
||||
char *cred;
|
||||
int disable100continue;
|
||||
uint32_t ignore_cacert_check;
|
||||
switch_hash_t* vars_map;
|
||||
switch_memory_pool_t* vars_map_pool;
|
||||
switch_hash_t *vars_map;
|
||||
switch_memory_pool_t *vars_map_pool;
|
||||
};
|
||||
|
||||
static int keep_files_around = 0;
|
||||
@@ -78,7 +78,7 @@ SWITCH_STANDARD_API(xml_curl_function)
|
||||
stream->write_function(stream, "OK\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
usage:
|
||||
usage:
|
||||
stream->write_function(stream, "USAGE: %s\n", XML_CURL_SYNTAX);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
struct config_data *config_data = data;
|
||||
int x;
|
||||
x = write(config_data->fd, ptr, realsize);
|
||||
if ( x != (int)realsize) {
|
||||
if (x != (int) realsize) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Short write! %d out of %d\n", x, realsize);
|
||||
}
|
||||
return x;
|
||||
@@ -130,13 +130,9 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
|
||||
}
|
||||
|
||||
switch_snprintf(basic_data, sizeof(basic_data), "hostname=%s§ion=%s&tag_name=%s&key_name=%s&key_value=%s",
|
||||
hostname,
|
||||
section,
|
||||
switch_str_nil(tag_name),
|
||||
switch_str_nil(key_name),
|
||||
switch_str_nil(key_value));
|
||||
hostname, section, switch_str_nil(tag_name), switch_str_nil(key_name), switch_str_nil(key_value));
|
||||
|
||||
data = switch_event_build_param_string(params, basic_data,binding->vars_map);
|
||||
data = switch_event_build_param_string(params, basic_data, binding->vars_map);
|
||||
switch_assert(data);
|
||||
|
||||
switch_uuid_get(&uuid);
|
||||
@@ -166,8 +162,8 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
|
||||
|
||||
if (binding->disable100continue) {
|
||||
slist = curl_slist_append(slist, "Expect:");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
|
||||
slist = curl_slist_append(slist, "Expect:");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
|
||||
}
|
||||
|
||||
if (binding->ignore_cacert_check) {
|
||||
@@ -206,6 +202,7 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
#define ENABLE_PARAM_VALUE "enabled"
|
||||
static switch_status_t do_config(void)
|
||||
{
|
||||
@@ -214,9 +211,9 @@ static switch_status_t do_config(void)
|
||||
xml_binding_t *binding = NULL;
|
||||
int x = 0;
|
||||
int need_vars_map = 0;
|
||||
switch_hash_t* vars_map = NULL;
|
||||
switch_memory_pool_t* vars_map_pool = NULL;
|
||||
|
||||
switch_hash_t *vars_map = NULL;
|
||||
switch_memory_pool_t *vars_map_pool = NULL;
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
||||
return SWITCH_STATUS_TERM;
|
||||
@@ -249,29 +246,29 @@ static switch_status_t do_config(void)
|
||||
disable100continue = 1;
|
||||
} else if (!strcasecmp(var, "ignore-cacert-check") && switch_true(val)) {
|
||||
ignore_cacert_check = 1;
|
||||
} else if(!strcasecmp(var, "enable-post-var")) {
|
||||
} else if (!strcasecmp(var, "enable-post-var")) {
|
||||
if (!vars_map && need_vars_map == 0) {
|
||||
if (switch_core_new_memory_pool(&vars_map_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
need_vars_map = -1;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant create memory pool!\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (switch_core_hash_init(&vars_map,vars_map_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
need_vars_map = -1;
|
||||
switch_core_destroy_memory_pool(&vars_map_pool);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant init params hash!\n");
|
||||
continue;
|
||||
}
|
||||
need_vars_map = 1;
|
||||
if (switch_core_new_memory_pool(&vars_map_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
need_vars_map = -1;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant create memory pool!\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (switch_core_hash_init(&vars_map, vars_map_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
need_vars_map = -1;
|
||||
switch_core_destroy_memory_pool(&vars_map_pool);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant init params hash!\n");
|
||||
continue;
|
||||
}
|
||||
need_vars_map = 1;
|
||||
}
|
||||
|
||||
|
||||
if (vars_map && val)
|
||||
if (switch_core_hash_insert(vars_map, val, ENABLE_PARAM_VALUE) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant add %s to params hash!\n",val);
|
||||
}
|
||||
|
||||
}
|
||||
if (switch_core_hash_insert(vars_map, val, ENABLE_PARAM_VALUE) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant add %s to params hash!\n", val);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!url) {
|
||||
@@ -296,7 +293,7 @@ static switch_status_t do_config(void)
|
||||
|
||||
binding->disable100continue = disable100continue;
|
||||
binding->ignore_cacert_check = ignore_cacert_check;
|
||||
|
||||
|
||||
binding->vars_map = vars_map;
|
||||
binding->vars_map_pool = vars_map_pool;
|
||||
|
||||
@@ -307,7 +304,7 @@ static switch_status_t do_config(void)
|
||||
binding = NULL;
|
||||
}
|
||||
|
||||
done:
|
||||
done:
|
||||
switch_xml_free(xml);
|
||||
|
||||
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
|
||||
@@ -96,17 +96,15 @@ SWITCH_STANDARD_API(xml_ldap_function)
|
||||
}
|
||||
|
||||
if (!strcasecmp(cmd, "debug_on")) {
|
||||
}
|
||||
else if (!strcasecmp(cmd, "debug_off")) {
|
||||
}
|
||||
else {
|
||||
} else if (!strcasecmp(cmd, "debug_off")) {
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
stream->write_function(stream, "OK\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
usage:
|
||||
usage:
|
||||
stream->write_function(stream, "USAGE: %s\n", XML_LDAP_SYNTAX);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -144,11 +142,10 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
|
||||
ldap->val = ldap_first_attribute(ldap->ld, ldap->entry, &ldap->berval);
|
||||
do {
|
||||
if (strstr(ldap->val, "value")) {
|
||||
if (strstr(ldap->val, ldap->key) && strcmp(ldap->val, ldap->key) ) {
|
||||
if (strstr(ldap->val, ldap->key) && strcmp(ldap->val, ldap->key)) {
|
||||
if (!strcmp(ldap->key, "param")) {
|
||||
params = switch_xml_add_child_d(asdf, "params", loff++);
|
||||
}
|
||||
else if (!strcmp(ldap->key, "variable")) {
|
||||
} else if (!strcmp(ldap->key, "variable")) {
|
||||
variables = switch_xml_add_child_d(asdf, "variables", loff++);
|
||||
}
|
||||
|
||||
@@ -162,8 +159,7 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
|
||||
param = switch_xml_add_child_d(params, "param", loff++);
|
||||
switch_xml_set_attr_d(param, "name", ldap->keyvals[i]);
|
||||
switch_xml_set_attr_d(param, "value", ldap->valvals[i]);
|
||||
}
|
||||
else if (!strcmp(ldap->key, "variable")) {
|
||||
} else if (!strcmp(ldap->key, "variable")) {
|
||||
variable = switch_xml_add_child_d(variables, "variable", loff++);
|
||||
switch_xml_set_attr_d(variable, "name", ldap->keyvals[i]);
|
||||
switch_xml_set_attr_d(variable, "value", ldap->valvals[i]);
|
||||
@@ -177,9 +173,9 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
|
||||
if (ldap->valvals) {
|
||||
ldap_value_free(ldap->valvals);
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "seems the values %d and %d are not the same??\n",ldap_count_values(ldap->valvals), ldap_count_values(ldap->keyvals));
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "seems the values %d and %d are not the same??\n",
|
||||
ldap_count_values(ldap->valvals), ldap_count_values(ldap->keyvals));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,7 +196,7 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
|
||||
ber_free(ldap->berval, 0);
|
||||
}
|
||||
|
||||
ldap->key = ldap_next_attribute(ldap->ld, ldap->entry, ldap->berkey );
|
||||
ldap->key = ldap_next_attribute(ldap->ld, ldap->entry, ldap->berkey);
|
||||
|
||||
} while (ldap->key != NULL);
|
||||
|
||||
@@ -212,9 +208,10 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
|
||||
}
|
||||
|
||||
|
||||
static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
|
||||
static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
|
||||
void *user_data)
|
||||
{
|
||||
xml_binding_t *binding = (xml_binding_t *)user_data;
|
||||
xml_binding_t *binding = (xml_binding_t *) user_data;
|
||||
switch_event_header_t *hi;
|
||||
|
||||
switch_xml_t xml = NULL, sub = NULL;
|
||||
@@ -222,7 +219,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
|
||||
struct ldap_c ldap_connection;
|
||||
struct ldap_c *ldap = &ldap_connection;
|
||||
|
||||
int auth_method = LDAP_AUTH_SIMPLE;
|
||||
int auth_method = LDAP_AUTH_SIMPLE;
|
||||
int desired_version = LDAP_VERSION3;
|
||||
xml_ldap_query_type_t query_type;
|
||||
char *dir_exten = NULL, *dir_domain = NULL;
|
||||
@@ -237,16 +234,13 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!strcmp(section,"configuration")) {
|
||||
if (!strcmp(section, "configuration")) {
|
||||
query_type = XML_LDAP_CONFIG;
|
||||
}
|
||||
else if (!strcmp(section,"directory")) {
|
||||
} else if (!strcmp(section, "directory")) {
|
||||
query_type = XML_LDAP_DIRECTORY;
|
||||
}
|
||||
else if (!strcmp(section,"dialplan")) {
|
||||
} else if (!strcmp(section, "dialplan")) {
|
||||
query_type = XML_LDAP_DIALPLAN;
|
||||
}
|
||||
else if (!strcmp(section,"phrases")) {
|
||||
} else if (!strcmp(section, "phrases")) {
|
||||
query_type = XML_LDAP_PHRASE;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid section\n");
|
||||
@@ -256,15 +250,14 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
|
||||
if (params) {
|
||||
if ((hi = params->headers)) {
|
||||
for (; hi; hi = hi->next) {
|
||||
switch(query_type) {
|
||||
switch (query_type) {
|
||||
case XML_LDAP_CONFIG:
|
||||
break;
|
||||
|
||||
case XML_LDAP_DIRECTORY:
|
||||
if (!strcmp(hi->name,"user")) {
|
||||
if (!strcmp(hi->name, "user")) {
|
||||
dir_exten = strdup(hi->value);
|
||||
}
|
||||
else if (!strcmp(hi->name,"domain")) {
|
||||
} else if (!strcmp(hi->name, "domain")) {
|
||||
dir_domain = strdup(hi->value);
|
||||
}
|
||||
break;
|
||||
@@ -274,7 +267,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch(query_type) {
|
||||
switch (query_type) {
|
||||
case XML_LDAP_CONFIG:
|
||||
break;
|
||||
|
||||
@@ -282,7 +275,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
|
||||
if (dir_exten && dir_domain) {
|
||||
if ((xml = switch_xml_new("directory"))) {
|
||||
switch_xml_set_attr_d(xml, "type", "freeswitch/xml");
|
||||
|
||||
|
||||
if ((sub = switch_xml_add_child_d(xml, "section", off++))) {
|
||||
switch_xml_set_attr_d(sub, "name", "directory");
|
||||
}
|
||||
@@ -290,21 +283,23 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
|
||||
if ((sub = switch_xml_add_child_d(sub, "domain", off++))) {
|
||||
switch_xml_set_attr_d(sub, "name", dir_domain);
|
||||
}
|
||||
|
||||
|
||||
if ((sub = switch_xml_add_child_d(sub, "user", off++))) {
|
||||
switch_xml_set_attr_d(sub, "id", dir_exten);
|
||||
}
|
||||
}
|
||||
|
||||
search_base = switch_mprintf(binding->queryfmt, dir_exten, dir_domain, binding->ldap_base);
|
||||
|
||||
|
||||
free(dir_exten);
|
||||
dir_exten = NULL;
|
||||
|
||||
free(dir_domain);
|
||||
dir_domain = NULL;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "something bad happened during the query construction phase likely exten(%s) or domain(%s) is null\n", dir_exten, dir_domain);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"something bad happened during the query construction phase likely exten(%s) or domain(%s) is null\n", dir_exten,
|
||||
dir_domain);
|
||||
goto cleanup;
|
||||
}
|
||||
break;
|
||||
@@ -325,8 +320,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
|
||||
case XML_LDAP_PHRASE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
@@ -359,7 +353,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
cleanup:
|
||||
if (ldap->msg) {
|
||||
ldap_msgfree(ldap->msg);
|
||||
}
|
||||
@@ -409,28 +403,25 @@ static switch_status_t do_config(void)
|
||||
if (val) {
|
||||
binding->queryfmt = strdup(val);
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp(var, "base")) {
|
||||
} else if (!strcasecmp(var, "base")) {
|
||||
binding->ldap_base = strdup(val);
|
||||
}
|
||||
else if (!strcasecmp(var, "binddn")) {
|
||||
} else if (!strcasecmp(var, "binddn")) {
|
||||
binding->binddn = strdup(val);
|
||||
}
|
||||
else if (!strcasecmp(var, "bindpass")) {
|
||||
} else if (!strcasecmp(var, "bindpass")) {
|
||||
binding->bindpass = strdup(val);
|
||||
}
|
||||
else if (!strcasecmp(var, "host")) {
|
||||
} else if (!strcasecmp(var, "host")) {
|
||||
binding->host = strdup(val);
|
||||
}
|
||||
}
|
||||
|
||||
if (!binding->ldap_base || !binding->binddn || !binding->bindpass || !binding->queryfmt) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You must define \"base\", \"binddn\", \"bindpass\", and \"queryfmt\" in mod_xml_ldap.conf.xml\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"You must define \"base\", \"binddn\", \"bindpass\", and \"queryfmt\" in mod_xml_ldap.conf.xml\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
|
||||
switch_strlen_zero(bname) ? "N/A" : bname, binding->ldap_base, binding->bindings ? binding->bindings : "all");
|
||||
switch_strlen_zero(bname) ? "N/A" : bname, binding->ldap_base, binding->bindings ? binding->bindings : "all");
|
||||
|
||||
switch_xml_bind_search_function(xml_ldap_search, switch_xml_parse_section_string(bname), binding);
|
||||
|
||||
@@ -438,7 +429,7 @@ static switch_status_t do_config(void)
|
||||
binding = NULL;
|
||||
}
|
||||
|
||||
done:
|
||||
done:
|
||||
switch_xml_free(xml);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
@@ -48,7 +48,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_rpc_shutdown);
|
||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_xml_rpc_runtime);
|
||||
SWITCH_MODULE_DEFINITION(mod_xml_rpc, mod_xml_rpc_load, mod_xml_rpc_shutdown, mod_xml_rpc_runtime);
|
||||
|
||||
static abyss_bool HTTPWrite(TSession *s,char *buffer,uint32_t len);
|
||||
static abyss_bool HTTPWrite(TSession * s, char *buffer, uint32_t len);
|
||||
|
||||
static struct {
|
||||
uint16_t port;
|
||||
@@ -122,8 +122,8 @@ static switch_status_t http_stream_raw_write(switch_stream_handle_t *handle, uin
|
||||
{
|
||||
TSession *r = handle->data;
|
||||
|
||||
return HTTPWrite(r, (char *)data, (uint32_t) datalen) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
|
||||
return HTTPWrite(r, (char *) data, (uint32_t) datalen) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
|
||||
}
|
||||
|
||||
static switch_status_t http_stream_write(switch_stream_handle_t *handle, const char *fmt, ...)
|
||||
@@ -146,11 +146,11 @@ static switch_status_t http_stream_write(switch_stream_handle_t *handle, const c
|
||||
return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
static abyss_bool http_directory_auth(TSession * r, char *domain_name)
|
||||
{
|
||||
char *p;
|
||||
char *p;
|
||||
char *x;
|
||||
char z[256], t[80];
|
||||
char z[256], t[80];
|
||||
char user[512];
|
||||
char *pass;
|
||||
const char *mypass1 = NULL, *mypass2 = NULL;
|
||||
@@ -159,27 +159,27 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
int at = 0;
|
||||
switch_event_t *params = NULL;
|
||||
|
||||
p = RequestHeaderValue(r, "authorization");
|
||||
p = RequestHeaderValue(r, "authorization");
|
||||
|
||||
if (p) {
|
||||
NextToken((const char ** const)&p);
|
||||
x = GetToken(&p);
|
||||
if (x) {
|
||||
if (!strcasecmp(x, "basic")) {
|
||||
if (p) {
|
||||
NextToken((const char **const) &p);
|
||||
x = GetToken(&p);
|
||||
if (x) {
|
||||
if (!strcasecmp(x, "basic")) {
|
||||
|
||||
|
||||
NextToken((const char ** const)&p);
|
||||
NextToken((const char **const) &p);
|
||||
switch_b64_decode(p, user, sizeof(user));
|
||||
if ((pass = strchr(user, ':'))) {
|
||||
*pass++ = '\0';
|
||||
}
|
||||
|
||||
|
||||
if (!domain_name) {
|
||||
if ((domain_name = strchr(user, '@'))) {
|
||||
*domain_name++ = '\0';
|
||||
at++;
|
||||
} else {
|
||||
domain_name = (char *)r->requestInfo.host;
|
||||
domain_name = (char *) r->requestInfo.host;
|
||||
if (!strncasecmp(domain_name, "www.", 3)) {
|
||||
domain_name += 4;
|
||||
}
|
||||
@@ -189,15 +189,15 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
if (!domain_name) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
switch_snprintf(z, sizeof(z), "%s:%s", globals.user, globals.pass);
|
||||
Base64Encode(z, t);
|
||||
|
||||
|
||||
if (!strcmp(p, t)) {
|
||||
r->requestInfo.user=strdup(user);
|
||||
r->requestInfo.user = strdup(user);
|
||||
goto authed;
|
||||
}
|
||||
|
||||
|
||||
switch_event_create(¶ms, SWITCH_EVENT_MESSAGE);
|
||||
switch_assert(params);
|
||||
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "mailbox", "check");
|
||||
@@ -207,41 +207,41 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
switch_event_destroy(¶ms);
|
||||
switch_event_destroy(¶ms);
|
||||
box = switch_xml_attr_soft(x_user, "mailbox");
|
||||
|
||||
for (x_param = switch_xml_child(x_domain, "param"); x_param; x_param = x_param->next) {
|
||||
const char *var = switch_xml_attr_soft(x_param, "name");
|
||||
const char *val = switch_xml_attr_soft(x_param, "value");
|
||||
|
||||
if (!strcasecmp(var, "password")) {
|
||||
mypass1 = val;
|
||||
} else if (!strcasecmp(var, "vm-password")) {
|
||||
mypass2 = val;
|
||||
} else if (!strncasecmp(var, "http-", 5)) {
|
||||
ResponseAddField(r, (char *)var, (char *)val);
|
||||
}
|
||||
|
||||
for (x_param = switch_xml_child(x_domain, "param"); x_param; x_param = x_param->next) {
|
||||
const char *var = switch_xml_attr_soft(x_param, "name");
|
||||
const char *val = switch_xml_attr_soft(x_param, "value");
|
||||
|
||||
if (!strcasecmp(var, "password")) {
|
||||
mypass1 = val;
|
||||
} else if (!strcasecmp(var, "vm-password")) {
|
||||
mypass2 = val;
|
||||
} else if (!strncasecmp(var, "http-", 5)) {
|
||||
ResponseAddField(r, (char *) var, (char *) val);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(x_params = switch_xml_child(x_user, "params"))) {
|
||||
goto authed;
|
||||
}
|
||||
|
||||
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
|
||||
const char *var = switch_xml_attr_soft(x_param, "name");
|
||||
const char *val = switch_xml_attr_soft(x_param, "value");
|
||||
|
||||
if (!strcasecmp(var, "password")) {
|
||||
mypass1 = val;
|
||||
} else if (!strcasecmp(var, "vm-password")) {
|
||||
mypass2 = val;
|
||||
} else if (!strncasecmp(var, "http-", 5)) {
|
||||
ResponseAddField(r, (char *)var, (char *)val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
|
||||
const char *var = switch_xml_attr_soft(x_param, "name");
|
||||
const char *val = switch_xml_attr_soft(x_param, "value");
|
||||
|
||||
if (!strcasecmp(var, "password")) {
|
||||
mypass1 = val;
|
||||
} else if (!strcasecmp(var, "vm-password")) {
|
||||
mypass2 = val;
|
||||
} else if (!strncasecmp(var, "http-", 5)) {
|
||||
ResponseAddField(r, (char *) var, (char *) val);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(mypass1 && mypass2)) {
|
||||
r->requestInfo.user=strdup(user);
|
||||
r->requestInfo.user = strdup(user);
|
||||
goto authed;
|
||||
} else {
|
||||
if (mypass1) {
|
||||
@@ -251,9 +251,9 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
switch_snprintf(z, sizeof(z), "%s:%s", user, mypass1);
|
||||
}
|
||||
Base64Encode(z, t);
|
||||
|
||||
|
||||
if (!strcmp(p, t)) {
|
||||
r->requestInfo.user=strdup(box ? box : user);
|
||||
r->requestInfo.user = strdup(box ? box : user);
|
||||
goto authed;
|
||||
}
|
||||
}
|
||||
@@ -265,9 +265,9 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
switch_snprintf(z, sizeof(z), "%s:%s", user, mypass2);
|
||||
}
|
||||
Base64Encode(z, t);
|
||||
|
||||
|
||||
if (!strcmp(p, t)) {
|
||||
r->requestInfo.user=strdup(box ? box : user);
|
||||
r->requestInfo.user = strdup(box ? box : user);
|
||||
goto authed;
|
||||
}
|
||||
}
|
||||
@@ -280,13 +280,13 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
switch_snprintf(z, sizeof(z), "%s:%s", box, mypass1);
|
||||
}
|
||||
Base64Encode(z, t);
|
||||
|
||||
|
||||
if (!strcmp(p, t)) {
|
||||
r->requestInfo.user=strdup(box);
|
||||
r->requestInfo.user = strdup(box);
|
||||
goto authed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mypass2) {
|
||||
if (at) {
|
||||
switch_snprintf(z, sizeof(z), "%s@%s:%s", box, domain_name, mypass2);
|
||||
@@ -295,9 +295,9 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
}
|
||||
|
||||
Base64Encode(z, t);
|
||||
|
||||
|
||||
if (!strcmp(p, t)) {
|
||||
r->requestInfo.user=strdup(box);
|
||||
r->requestInfo.user = strdup(box);
|
||||
goto authed;
|
||||
}
|
||||
}
|
||||
@@ -305,30 +305,30 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
|
||||
}
|
||||
goto fail;
|
||||
|
||||
authed:
|
||||
|
||||
authed:
|
||||
|
||||
ResponseAddField(r, "freeswitch-user", r->requestInfo.user);
|
||||
ResponseAddField(r, "freeswitch-domain", domain_name);
|
||||
|
||||
|
||||
if (x_domain_root) {
|
||||
switch_xml_free(x_domain_root);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
|
||||
if (x_domain_root) {
|
||||
switch_xml_free(x_domain_root);
|
||||
}
|
||||
|
||||
switch_snprintf(z, sizeof(z), "Basic realm=\"%s\"", domain_name ? domain_name : globals.realm);
|
||||
ResponseAddField(r, "WWW-Authenticate", z);
|
||||
ResponseStatus(r, 401);
|
||||
return FALSE;
|
||||
switch_snprintf(z, sizeof(z), "Basic realm=\"%s\"", domain_name ? domain_name : globals.realm);
|
||||
ResponseAddField(r, "WWW-Authenticate", z);
|
||||
ResponseStatus(r, 401);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
abyss_bool auth_hook(TSession * r)
|
||||
@@ -339,7 +339,7 @@ abyss_bool auth_hook(TSession * r)
|
||||
if (!strncmp(r->requestInfo.uri, "/domains/", 9)) {
|
||||
domain_name = strdup(r->requestInfo.uri + 9);
|
||||
switch_assert(domain_name);
|
||||
|
||||
|
||||
if ((e = strchr(domain_name, '/'))) {
|
||||
*e++ = '\0';
|
||||
}
|
||||
@@ -354,36 +354,27 @@ abyss_bool auth_hook(TSession * r)
|
||||
free(domain_name);
|
||||
} else {
|
||||
char tmp[512];
|
||||
const char *list[2] = {"index.html", "index.txt"};
|
||||
const char *list[2] = { "index.html", "index.txt" };
|
||||
int x;
|
||||
|
||||
if (!strncmp(r->requestInfo.uri, "/pub", 4)) {
|
||||
char *p = (char *)r->requestInfo.uri;
|
||||
char *p = (char *) r->requestInfo.uri;
|
||||
char *new_uri = p + 4;
|
||||
if (!new_uri) {
|
||||
new_uri = "/";
|
||||
}
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "%s%s",
|
||||
SWITCH_GLOBAL_dirs.htdocs_dir,
|
||||
new_uri
|
||||
);
|
||||
switch_snprintf(tmp, sizeof(tmp), "%s%s", SWITCH_GLOBAL_dirs.htdocs_dir, new_uri);
|
||||
|
||||
if (switch_directory_exists(tmp, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||
for (x = 0; x < 2; x++) {
|
||||
switch_snprintf(tmp, sizeof(tmp), "%s%s%s%s",
|
||||
SWITCH_GLOBAL_dirs.htdocs_dir,
|
||||
new_uri,
|
||||
end_of(new_uri) == *SWITCH_PATH_SEPARATOR ? "" : SWITCH_PATH_SEPARATOR,
|
||||
list[x]
|
||||
);
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "%s%s%s%s",
|
||||
SWITCH_GLOBAL_dirs.htdocs_dir, new_uri, end_of(new_uri) == *SWITCH_PATH_SEPARATOR ? "" : SWITCH_PATH_SEPARATOR, list[x]
|
||||
);
|
||||
|
||||
if (switch_file_exists(tmp, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_snprintf(tmp, sizeof(tmp), "%s%s%s",
|
||||
new_uri,
|
||||
end_of(new_uri) == '/' ? "" : "/",
|
||||
list[x]
|
||||
);
|
||||
switch_snprintf(tmp, sizeof(tmp), "%s%s%s", new_uri, end_of(new_uri) == '/' ? "" : "/", list[x]
|
||||
);
|
||||
new_uri = tmp;
|
||||
break;
|
||||
}
|
||||
@@ -403,36 +394,34 @@ abyss_bool auth_hook(TSession * r)
|
||||
}
|
||||
|
||||
|
||||
static abyss_bool HTTPWrite(TSession *s,char *buffer,uint32_t len)
|
||||
static abyss_bool HTTPWrite(TSession * s, char *buffer, uint32_t len)
|
||||
{
|
||||
if (s->chunkedwrite && s->chunkedwritemode)
|
||||
{
|
||||
char t[16];
|
||||
if (s->chunkedwrite && s->chunkedwritemode) {
|
||||
char t[16];
|
||||
|
||||
if (ConnWrite(s->conn,t,sprintf(t,"%x"CRLF,len)))
|
||||
if (ConnWrite(s->conn,buffer,len))
|
||||
return ConnWrite(s->conn,CRLF,2);
|
||||
if (ConnWrite(s->conn, t, sprintf(t, "%x" CRLF, len)))
|
||||
if (ConnWrite(s->conn, buffer, len))
|
||||
return ConnWrite(s->conn, CRLF, 2);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ConnWrite(s->conn,buffer,len);
|
||||
return ConnWrite(s->conn, buffer, len);
|
||||
}
|
||||
|
||||
static abyss_bool HTTPWriteEnd(TSession *s)
|
||||
static abyss_bool HTTPWriteEnd(TSession * s)
|
||||
{
|
||||
if (!s->chunkedwritemode)
|
||||
return TRUE;
|
||||
if (!s->chunkedwritemode)
|
||||
return TRUE;
|
||||
|
||||
if (s->chunkedwrite)
|
||||
{
|
||||
/* May be one day trailer dumping will be added */
|
||||
s->chunkedwritemode=FALSE;
|
||||
return ConnWrite(s->conn,"0"CRLF CRLF,5);
|
||||
}
|
||||
if (s->chunkedwrite) {
|
||||
/* May be one day trailer dumping will be added */
|
||||
s->chunkedwritemode = FALSE;
|
||||
return ConnWrite(s->conn, "0" CRLF CRLF, 5);
|
||||
}
|
||||
|
||||
s->requestInfo.keepalive=FALSE;
|
||||
return TRUE;
|
||||
s->requestInfo.keepalive = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
abyss_bool handler_hook(TSession * r)
|
||||
@@ -471,8 +460,8 @@ abyss_bool handler_hook(TSession * r)
|
||||
*path_info++ = '\0';
|
||||
}
|
||||
|
||||
for (i=0;i<r->response_headers.size;i++) {
|
||||
ti=&r->response_headers.item[i];
|
||||
for (i = 0; i < r->response_headers.size; i++) {
|
||||
ti = &r->response_headers.item[i];
|
||||
if (!strcasecmp(ti->name, "freeswitch-user")) {
|
||||
fs_user = ti->value;
|
||||
} else if (!strcasecmp(ti->name, "freeswitch-domain")) {
|
||||
@@ -481,14 +470,14 @@ abyss_bool handler_hook(TSession * r)
|
||||
int argc, x;
|
||||
char *argv[256] = { 0 };
|
||||
j++;
|
||||
|
||||
|
||||
if (!strcasecmp(ti->value, "any")) {
|
||||
auth++;
|
||||
}
|
||||
|
||||
dup = strdup(ti->value);
|
||||
argc = switch_separate_string(dup, ',', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
|
||||
for (x = 0; x < argc; x++) {
|
||||
if (!strcasecmp(command, argv[x])) {
|
||||
auth++;
|
||||
@@ -502,13 +491,12 @@ abyss_bool handler_hook(TSession * r)
|
||||
} else {
|
||||
if (!j) {
|
||||
auth = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (auth) {
|
||||
goto auth;
|
||||
}
|
||||
|
||||
//unauth:
|
||||
ResponseStatus(r, 403);
|
||||
ResponseError(r);
|
||||
@@ -517,11 +505,11 @@ abyss_bool handler_hook(TSession * r)
|
||||
ret = TRUE;
|
||||
goto end;
|
||||
|
||||
auth:
|
||||
auth:
|
||||
|
||||
if (switch_event_create(&stream.param_event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
|
||||
const char * const content_length = RequestHeaderValue(r, "content-length");
|
||||
|
||||
const char *const content_length = RequestHeaderValue(r, "content-length");
|
||||
|
||||
if (fs_user)
|
||||
switch_event_add_header(stream.param_event, SWITCH_STACK_BOTTOM, "FreeSWITCH-User", "%s", fs_user);
|
||||
if (fs_domain)
|
||||
@@ -548,14 +536,14 @@ abyss_bool handler_hook(TSession * r)
|
||||
if (r->requestInfo.query || content_length) {
|
||||
char *q, *qd;
|
||||
char *next;
|
||||
char *query = (char *)r->requestInfo.query;
|
||||
char *query = (char *) r->requestInfo.query;
|
||||
char *name, *val;
|
||||
char qbuf[8192] = "";
|
||||
|
||||
|
||||
if (r->requestInfo.method == m_post && content_length) {
|
||||
int len = atoi(content_length);
|
||||
int qlen = 0;
|
||||
|
||||
|
||||
if (len > 0) {
|
||||
int succeeded;
|
||||
char *qp = qbuf;
|
||||
@@ -567,11 +555,11 @@ abyss_bool handler_hook(TSession * r)
|
||||
}
|
||||
|
||||
qlen += blen;
|
||||
|
||||
if ( qlen > sizeof(qbuf) ) {
|
||||
|
||||
if (qlen > sizeof(qbuf)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
memcpy(qp, r->conn->buffer + r->conn->bufferpos, blen);
|
||||
qp += blen;
|
||||
|
||||
@@ -579,7 +567,7 @@ abyss_bool handler_hook(TSession * r)
|
||||
break;
|
||||
}
|
||||
} while ((succeeded = ConnRead(r->conn, 2000)));
|
||||
|
||||
|
||||
query = qbuf;
|
||||
}
|
||||
}
|
||||
@@ -614,14 +602,13 @@ abyss_bool handler_hook(TSession * r)
|
||||
}
|
||||
q = next;
|
||||
} while (q != NULL);
|
||||
|
||||
|
||||
free(qd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ResponseChunked(r);
|
||||
|
||||
|
||||
//ResponseContentType(r, mime);
|
||||
//ResponseWrite(r);
|
||||
|
||||
@@ -631,7 +618,7 @@ abyss_bool handler_hook(TSession * r)
|
||||
|
||||
/* generation of the date field */
|
||||
{
|
||||
const char * dateValue;
|
||||
const char *dateValue;
|
||||
|
||||
DateToString(r->date, &dateValue);
|
||||
|
||||
@@ -640,25 +627,25 @@ abyss_bool handler_hook(TSession * r)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Generation of the server field */
|
||||
ResponseAddField(r,"Server", "FreeSWITCH-" SWITCH_VERSION_FULL "-mod_xml_rpc");
|
||||
ResponseAddField(r, "Server", "FreeSWITCH-" SWITCH_VERSION_FULL "-mod_xml_rpc");
|
||||
|
||||
if (html) {
|
||||
ResponseAddField(r, "Content-Type", "text/html");
|
||||
}
|
||||
|
||||
for (i=0;i<r->response_headers.size;i++) {
|
||||
ti=&r->response_headers.item[i];
|
||||
ConnWrite(r->conn, ti->name, (uint32_t)strlen(ti->name));
|
||||
ConnWrite(r->conn,": ",2);
|
||||
ConnWrite(r->conn, ti->value, (uint32_t)strlen(ti->value));
|
||||
ConnWrite(r->conn,CRLF,2);
|
||||
for (i = 0; i < r->response_headers.size; i++) {
|
||||
ti = &r->response_headers.item[i];
|
||||
ConnWrite(r->conn, ti->name, (uint32_t) strlen(ti->name));
|
||||
ConnWrite(r->conn, ": ", 2);
|
||||
ConnWrite(r->conn, ti->value, (uint32_t) strlen(ti->value));
|
||||
ConnWrite(r->conn, CRLF, 2);
|
||||
}
|
||||
|
||||
|
||||
switch_snprintf(buf, sizeof(buf), "Connection: close\r\n");
|
||||
ConnWrite(r->conn, buf, (uint32_t) strlen(buf));
|
||||
|
||||
|
||||
if (html) {
|
||||
ConnWrite(r->conn, "\r\n", 2);
|
||||
}
|
||||
@@ -671,10 +658,10 @@ abyss_bool handler_hook(TSession * r)
|
||||
} else {
|
||||
ResponseStatus(r, 404);
|
||||
ResponseError(r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//SocketClose(&(r->conn->socket));
|
||||
|
||||
|
||||
HTTPWriteEnd(r);
|
||||
//if(r->conn->channelP)
|
||||
//ConnKill(r->conn);
|
||||
@@ -683,7 +670,7 @@ abyss_bool handler_hook(TSession * r)
|
||||
//ChannelDestroy(r->conn->channelP);
|
||||
r->requestInfo.keepalive = 0;
|
||||
|
||||
end:
|
||||
end:
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -710,7 +697,7 @@ static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * cons
|
||||
val = xmlrpc_build_value(envP, "s", "ERROR!");
|
||||
}
|
||||
|
||||
done:
|
||||
done:
|
||||
/* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */
|
||||
switch_safe_free(command);
|
||||
switch_safe_free(arg);
|
||||
@@ -765,7 +752,7 @@ static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * cons
|
||||
/* Return our result. */
|
||||
val = xmlrpc_build_value(envP, "s", buf);
|
||||
|
||||
done:
|
||||
done:
|
||||
/* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */
|
||||
switch_safe_free(oid);
|
||||
switch_safe_free(s_action);
|
||||
@@ -795,7 +782,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_xml_rpc_runtime)
|
||||
|
||||
MIMETypeInit();
|
||||
MIMETypeAdd("text/html", "html");
|
||||
for(hi = switch_core_mime_index(); hi; hi = switch_hash_next(hi)) {
|
||||
for (hi = switch_core_mime_index(); hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, &var, NULL, &val);
|
||||
if (var && val) {
|
||||
MIMETypeAdd((char *) val, (char *) var);
|
||||
@@ -831,10 +818,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_rpc_shutdown)
|
||||
//globals.abyssServer.running = 0;
|
||||
//shutdown(globals.abyssServer.listensock, 2);
|
||||
ServerTerminate(&globals.abyssServer);
|
||||
while(globals.running) {
|
||||
while (globals.running) {
|
||||
switch_yield(100000);
|
||||
}
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user