spring cleaning

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2007-03-29 22:31:56 +00:00
parent a021945cef
commit 3a54126261
143 changed files with 22413 additions and 31567 deletions
+9 -8
View File
@@ -37,7 +37,7 @@ static const char modname[] = "mod_xml_cdr";
static switch_status_t my_on_hangup(switch_core_session_t *session)
{
switch_xml_t cdr;
if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(session);
char *xml_text;
@@ -51,16 +51,16 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if ((alt = switch_channel_get_variable(channel, "xml_cdr_base"))) {
logdir = alt;
}
if ((path = switch_mprintf("%s/xml_cdr/%s.cdr.xml", logdir, uuid_str))) {
if ((xml_text = switch_xml_toxml(cdr))) {
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
write(fd, header, (unsigned)strlen(header));
write(fd, xml_text, (unsigned)strlen(xml_text));
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
write(fd, header, (unsigned) strlen(header));
write(fd, xml_text, (unsigned) strlen(xml_text));
close(fd);
fd = -1;
} else {
char ebuf[512] = {0};
char ebuf[512] = { 0 };
#ifdef WIN32
strerror_s(ebuf, sizeof(ebuf), errno);
#else
@@ -77,7 +77,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Generating Data!\n");
}
return SWITCH_STATUS_SUCCESS;
}
@@ -100,7 +100,8 @@ static const switch_loadable_module_interface_t mod_xml_cdr_module_interface = {
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* test global state handlers */
switch_core_add_state_handler(&state_handlers);
+81 -84
View File
@@ -36,7 +36,7 @@ static const char modname[] = "mod_xml_curl";
struct xml_binding {
char *url;
char *bindings;
char *cred;
char *cred;
};
typedef struct xml_binding xml_binding_t;
@@ -48,7 +48,7 @@ struct config_data {
static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
{
register unsigned int realsize = (unsigned int)(size * nmemb);
register unsigned int realsize = (unsigned int) (size * nmemb);
struct config_data *config_data = data;
write(config_data->fd, ptr, realsize);
@@ -58,45 +58,42 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
static switch_xml_t xml_url_fetch(const char *section,
const char *tag_name,
const char *key_name,
const char *key_value,
const char *params,
void *user_data)
const char *key_name, const char *key_value, const char *params, void *user_data)
{
char filename[512] = "";
CURL *curl_handle = NULL;
struct config_data config_data;
switch_xml_t xml = NULL;
char *data = NULL;
char *data = NULL;
switch_uuid_t uuid;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
xml_binding_t *binding = (xml_binding_t *) user_data;
char *file_url;
xml_binding_t *binding = (xml_binding_t *) user_data;
char *file_url;
if (!binding) {
return NULL;
}
if (!binding) {
return NULL;
}
if ((file_url = strstr(binding->url, "file:"))) {
file_url += 5;
if (!(xml = switch_xml_parse_file(file_url))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
}
return xml;
}
if ((file_url = strstr(binding->url, "file:"))) {
file_url += 5;
if (!(data = switch_mprintf("section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
section,
tag_name ? tag_name : "",
key_name ? key_name : "",
key_value ? key_value : "",
params ? strchr(params,'=') ? "&" : "&params=" : "", params ? params : ""))) {
if (!(xml = switch_xml_parse_file(file_url))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
return NULL;
}
return xml;
}
if (!(data = switch_mprintf("section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
section,
tag_name ? tag_name : "",
key_name ? key_name : "",
key_value ? key_value : "",
params ? strchr(params, '=') ? "&" : "&params=" : "", params ? params : ""))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
return NULL;
}
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
@@ -107,18 +104,18 @@ static switch_xml_t xml_url_fetch(const char *section,
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
config_data.name = filename;
if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC)) > -1) {
if (!switch_strlen_zero(binding->cred)) {
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
}
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
if (!switch_strlen_zero(binding->cred)) {
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
}
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl_handle, CURLOPT_URL, binding->url);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&config_data);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &config_data);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
curl_easy_perform(curl_handle);
curl_easy_cleanup(curl_handle);
@@ -127,14 +124,14 @@ static switch_xml_t xml_url_fetch(const char *section,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error!\n");
}
switch_safe_free(data);
switch_safe_free(data);
if (!(xml = switch_xml_parse_file(filename))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
}
unlink(filename);
return xml;
}
@@ -152,12 +149,12 @@ static switch_loadable_module_interface_t xml_curl_module_interface = {
/*.directory_interface */ NULL
};
static switch_status_t do_config(void)
static switch_status_t do_config(void)
{
char *cf = "xml_curl.conf";
switch_xml_t cfg, xml, bindings_tag, binding_tag, param;
xml_binding_t *binding = NULL;
int x = 0;
xml_binding_t *binding = NULL;
int x = 0;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
@@ -165,56 +162,55 @@ static switch_status_t do_config(void)
}
if (!(bindings_tag = switch_xml_child(cfg, "bindings"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
return SWITCH_STATUS_FALSE;
}
for (binding_tag = switch_xml_child(bindings_tag, "binding"); binding_tag; binding_tag = binding_tag->next) {
char *bname = (char *) switch_xml_attr_soft(binding_tag, "name");
char *url = NULL;
char *bind_cred = NULL;
char *bind_mask = NULL;
char *bname = (char *) switch_xml_attr_soft(binding_tag, "name");
char *url = NULL;
char *bind_cred = NULL;
char *bind_mask = NULL;
for (param = switch_xml_child(binding_tag, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "gateway-url")) {
if (!strcasecmp(var, "gateway-url")) {
bind_mask = (char *) switch_xml_attr_soft(param, "bindings");
if (val) {
url = val;
}
if (val) {
url = val;
}
} else if (!strcasecmp(var, "gateway-credentials")) {
bind_cred = val;
}
bind_cred = val;
}
}
if (!url) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no url!\n");
continue;
}
if (!(binding = malloc(sizeof(*binding)))) {
return SWITCH_STATUS_FALSE;
}
memset(binding, 0, sizeof(*binding));
if (!url) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no url!\n");
continue;
}
binding->url = strdup(url);
if (!(binding = malloc(sizeof(*binding)))) {
return SWITCH_STATUS_FALSE;
}
memset(binding, 0, sizeof(*binding));
if (bind_mask) {
binding->bindings = strdup(bind_mask);
}
binding->url = strdup(url);
if (bind_cred) {
binding->cred = strdup(bind_cred);
}
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->url,
binding->bindings ? binding->bindings : "all");
if (bind_mask) {
binding->bindings = strdup(bind_mask);
}
if (bind_cred) {
binding->cred = strdup(bind_cred);
}
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->url, binding->bindings ? binding->bindings : "all");
switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->bindings), binding);
x++;
binding = NULL;
x++;
binding = NULL;
}
switch_xml_free(xml);
@@ -223,16 +219,17 @@ static switch_status_t do_config(void)
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &xml_curl_module_interface;
if (do_config() == SWITCH_STATUS_SUCCESS) {
curl_global_init(CURL_GLOBAL_ALL);
} else {
return SWITCH_STATUS_FALSE;
}
curl_global_init(CURL_GLOBAL_ALL);
} else {
return SWITCH_STATUS_FALSE;
}
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
+76 -64
View File
@@ -66,10 +66,10 @@ static struct {
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_realm, globals.realm)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_user, globals.user)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_user, globals.user)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
static switch_status_t do_config(void)
static switch_status_t do_config(void)
{
char *cf = "xml_rpc.conf";
switch_xml_t cfg, xml, settings, param;
@@ -93,11 +93,11 @@ static switch_status_t do_config(void)
} else if (!strcasecmp(var, "auth-pass")) {
pass = val;
} else if (!strcasecmp(var, "http-port")) {
globals.port = (uint16_t)atoi(val);
globals.port = (uint16_t) atoi(val);
}
}
}
if (!globals.port) {
globals.port = 8080;
}
@@ -112,14 +112,15 @@ static switch_status_t do_config(void)
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &xml_rpc_module_interface;
memset(&globals, 0, sizeof(globals));
do_config();
do_config();
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
@@ -136,73 +137,82 @@ static switch_status_t http_stream_write(switch_stream_handle_t *handle, const c
va_start(ap, fmt);
ret = switch_vasprintf(&data, fmt, ap);
va_end(ap);
if (data) {
ret = 0;
HTTPWrite(r, data, (uint32_t)strlen(data));
HTTPWrite(r, data, (uint32_t) strlen(data));
free(data);
}
return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
abyss_bool HandleHook(TSession *r)
abyss_bool HandleHook(TSession * r)
{
char *m = "text/html";
switch_stream_handle_t stream = {0};
char *m = "text/html";
switch_stream_handle_t stream = { 0 };
char *command;
stream.data = r;
stream.write_function = http_stream_write;
if (globals.realm) {
if (!RequestAuth(r,globals.realm, globals.user, globals.pass)) {
if (!RequestAuth(r, globals.realm, globals.user, globals.pass)) {
return TRUE;
}
}
if(strncmp(r->uri, "/api/", 5)) {
if (strncmp(r->uri, "/api/", 5)) {
return FALSE;
}
if (switch_event_create(&stream.event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
if (r->uri) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-URI", "%s", r->uri);
if (r->query) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-QUERY", "%s", r->query);
if (r->host) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-HOST", "%s", r->host);
if (r->from) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-FROM", "%s", r->from);
if (r->useragent) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER-AGENT", "%s", r->useragent);
if (r->referer) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REFERER", "%s", r->referer);
if (r->requestline) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REQUESTLINE", "%s", r->requestline);
if (r->user) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER", "%s", r->user);
if (r->port) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-PORT", "%u", r->port);
if (r->uri)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-URI", "%s", r->uri);
if (r->query)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-QUERY", "%s", r->query);
if (r->host)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-HOST", "%s", r->host);
if (r->from)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-FROM", "%s", r->from);
if (r->useragent)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER-AGENT", "%s", r->useragent);
if (r->referer)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REFERER", "%s", r->referer);
if (r->requestline)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REQUESTLINE", "%s", r->requestline);
if (r->user)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER", "%s", r->user);
if (r->port)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-PORT", "%u", r->port);
}
command = r->uri + 5;
ResponseChunked(r);
ResponseStatus(r,200);
ResponseStatus(r, 200);
ResponseContentType(r, m);
ResponseWrite(r);
ResponseWrite(r);
switch_api_execute(command, r->query, NULL, &stream);
HTTPWriteEnd(r);
return TRUE;
return TRUE;
}
static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData)
static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData)
{
char *command, *arg;
switch_stream_handle_t stream = {0};
switch_stream_handle_t stream = { 0 };
xmlrpc_value *val = NULL;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg);
if (envP->fault_occurred) {
return NULL;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg);
if (envP->fault_occurred) {
return NULL;
}
SWITCH_STANDARD_STREAM(stream);
@@ -217,17 +227,17 @@ static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const
return val;
}
static xmlrpc_value *freeswitch_man(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData)
static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData)
{
char *oid, *relative_oid, *s_action, *data;
char buf[SWITCH_MAX_MANAGEMENT_BUFFER_LEN] = "";
switch_management_action_t action = SMA_NONE;
xmlrpc_value *val;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
if (envP->fault_occurred) {
return NULL;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
if (envP->fault_occurred) {
return NULL;
}
if (!strncasecmp(oid, FREESWITCH_OID_PREFIX, strlen(FREESWITCH_OID_PREFIX))) {
@@ -262,46 +272,48 @@ static xmlrpc_value *freeswitch_man(xmlrpc_env *const envP, xmlrpc_value *const
snprintf(buf, sizeof(buf), "Invalid Action %s\n", s_action);
}
/* Return our result. */
val = xmlrpc_build_value(envP, "s", buf);
/* Return our result. */
val = xmlrpc_build_value(envP, "s", buf);
return val;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
{
TServer abyssServer;
xmlrpc_registry * registryP;
xmlrpc_env env;
TServer abyssServer;
xmlrpc_registry *registryP;
xmlrpc_env env;
char logfile[512];
globals.running = 1;
xmlrpc_env_init(&env);
registryP = xmlrpc_registry_new(&env);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL,"freeswitch_api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.management", &freeswitch_man, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL,"freeswitch_management", &freeswitch_man, NULL);
xmlrpc_env_init(&env);
MIMETypeInit();
registryP = xmlrpc_registry_new(&env);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch_api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.management", &freeswitch_man, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch_management", &freeswitch_man, NULL);
MIMETypeInit();
MIMETypeAdd("text/html", "html");
snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "freeswitch_http.log");
ServerCreate(&abyssServer, "XmlRpcServer", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir, logfile);
xmlrpc_server_abyss_set_handler(&env, &abyssServer, "/RPC2", registryP);
snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR,
"freeswitch_http.log");
ServerCreate(&abyssServer, "XmlRpcServer", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir, logfile);
ServerInit(&abyssServer);
xmlrpc_server_abyss_set_handler(&env, &abyssServer, "/RPC2", registryP);
ServerInit(&abyssServer);
ServerAddHandler(&abyssServer, HandleHook);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting HTTP Port %d, DocRoot [%s]\n", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir);
while (globals.running) {
ServerRunOnce2(&abyssServer, ABYSS_FOREGROUND);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting HTTP Port %d, DocRoot [%s]\n", globals.port,
SWITCH_GLOBAL_dirs.htdocs_dir);
while (globals.running) {
ServerRunOnce2(&abyssServer, ABYSS_FOREGROUND);
}
return SWITCH_STATUS_SUCCESS;