int auth_scheme;
int timeout;
profile_perms_t perms;
+ char *ua;
struct {
char *use_profile;
switch_file_t *lock_fd;
switch_memory_pool_t *pool;
int del_on_close;
+ char *dest_url;
+ char *ua;
+ switch_event_t *url_params;
+
+ struct {
+ char *ext;
+ } read;
+
struct {
- char *dest_url;
- char *params;
char *file_name;
char *profile_name;
char *file;
switch_event_t *save_params = NULL;
const char *put_file;
FILE *fd = NULL;
- char *creds, *dup_creds = NULL;
+ char *creds, *dup_creds = NULL, *ua = NULL;
+
if (client->one_time_params && client->one_time_params->headers) {
save_params = client->params;
switch_event_dup(&client->params, save_params);
switch_event_create(&client->one_time_params, SWITCH_EVENT_CLONE);
client->one_time_params->flags |= EF_UNIQ_HEADERS;
}
+
+
+ ua = switch_event_get_header(client->params, "user_agent");
+
+ if (zstr(ua)) {
+ ua = client->profile->ua;
+ }
if (!(session_id = switch_event_get_header(client->params, "HTTAPI_SESSION_ID"))) {
if (client->channel && !(session_id = switch_channel_get_variable(client->channel, "HTTAPI_SESSION_ID"))) {
switch_curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, get_header_callback);
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) client);
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *) client);
- switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "mod_httapi/1.0");
+ switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, ua);
if (client->profile->timeout) {
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, client->profile->timeout);
curl_easy_setopt(curl_handle, CURLOPT_INTERFACE, client->profile->bind_local);
}
- switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "mod_httapi/1.0");
+
switch_curl_easy_perform(curl_handle);
switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &client->code);
switch_curl_easy_cleanup(curl_handle);
char *ssl_cacert_file = NULL;
uint32_t enable_ssl_verifyhost = 0;
char *cookie_file = NULL;
+ char *ua = "mod_httapi/1.0";
hash_node_t *hash_node;
int auth_scheme = CURLAUTH_BASIC;
need_vars_map = 0;
if (val) {
url = val;
}
+ } else if (!strcasecmp(var, "user-agent")) {
+ ua = val;
} else if (!strcasecmp(var, "gateway-credentials")) {
bind_cred = val;
} else if (!strcasecmp(var, "auth-scheme")) {
}
memset(profile, 0, sizeof(*profile));
+
/* Defaults */
+ profile->ua = ua;
profile->conference_params.use_profile = "default";
profile->perms.set_params = 1;
profile->perms.conference.enabled = 1;
profile->perms.dial.enabled = 1;
+
if ((tag = switch_xml_child(profile_tag, "conference"))) {
for (param = switch_xml_child(tag, "param"); param; param = param->next) {
static char *load_cache_data(http_file_context_t *context, const char *url)
{
- char *ext;
+ char *ext = NULL;
char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
char meta_buffer[1024] = "";
int fd;
switch_ssize_t bytes;
switch_md5_string(digest, (void *) url, strlen(url));
+
+ if (context->url_params) {
+ ext = switch_event_get_header(context->url_params, "ext");
+ }
- if ((ext = strrchr(url, '.'))) {
- ext++;
- } else {
- ext = "wav";
+ if (zstr(ext)) {
+ if ((ext = strrchr(url, '.'))) {
+ ext++;
+ } else {
+ ext = "wav";
+ }
}
context->cache_file = switch_core_sprintf(context->pool, "%s%s%s.%s", globals.cache_path, SWITCH_PATH_SEPARATOR, digest, ext);
-static switch_status_t fetch_cache_data(const char *url, switch_event_t **headers, const char *save_path)
+static switch_status_t fetch_cache_data(http_file_context_t *context, const char *url, switch_event_t **headers, const char *save_path)
{
switch_CURL *curl_handle = NULL;
client_t client = { 0 };
long code;
switch_status_t status = SWITCH_STATUS_FALSE;
char *dup_creds = NULL, *dynamic_url = NULL, *use_url;
+ char *ua = NULL;
+
client.fd = -1;
if (save_path) {
return SWITCH_STATUS_FALSE;
}
}
+
+ if (context->url_params) {
+ ua = switch_event_get_header(context->url_params, "user_agent");
+ }
+ if (zstr(ua)) {
+ ua = "mod_httapi/1.0";
+ }
if ((use_url = strchr(url, '@'))) {
char *r, *q, *p = strstr(url, "://");
switch_curl_easy_setopt(curl_handle, CURLOPT_USERPWD, dup_creds);
}
- switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "mod_httapi/1.0");
+ switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, ua);
switch_curl_easy_perform(curl_handle);
switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &code);
switch_curl_easy_cleanup(curl_handle);
lock_file(context, SWITCH_TRUE);
- if ((status = fetch_cache_data(url, &headers, NULL)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = fetch_cache_data(context, url, &headers, NULL)) != SWITCH_STATUS_SUCCESS) {
if (status == SWITCH_STATUS_NOTFOUND) {
unreachable = 2;
if (now - context->expires < globals.not_found_expires) {
}
switch_event_destroy(&headers);
- fetch_cache_data(url, &headers, context->cache_file);
+ fetch_cache_data(context, url, &headers, context->cache_file);
metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s",
url,
switch_event_get_header_nil(headers, "last-modified"),
static switch_status_t http_file_file_open(switch_file_handle_t *handle, const char *path)
{
http_file_context_t *context;
- char *file_dup;
+ char *parsed = NULL, *pdup = NULL;
switch_status_t status;
context = switch_core_alloc(handle->memory_pool, sizeof(*context));
context->pool = handle->memory_pool;
+ pdup = switch_core_strdup(context->pool, path);
+
+ switch_event_create_brackets(pdup, '(', ')', ',', &context->url_params, &parsed, SWITCH_FALSE);
+
+ if (context->url_params) {
+ context->ua = switch_event_get_header(context->url_params, "ua");
+ }
+
+ if (parsed) path = parsed;
+
+ context->dest_url = switch_core_sprintf(context->pool, "http://%s", path);
+
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
char *ext;
-
context->fh.channels = handle->channels;
context->fh.native_rate = handle->native_rate;
context->fh.samplerate = handle->samplerate;
context->fh.prefix = handle->prefix;
- context->write.dest_url = switch_core_sprintf(context->pool, "http://%s", path);
-
- if ((context->write.params = strchr(context->write.dest_url, ';'))) {
- *context->write.params++ = '\0';
- context->write.file_name = switch_find_parameter(context->write.params, "file", context->pool);
- context->write.profile_name = switch_find_parameter(context->write.params, "profile", context->pool);
- context->write.method = switch_find_parameter(context->write.params, "method", context->pool);
- context->write.name = switch_find_parameter(context->write.params, "name", context->pool);
+
+ if (context->url_params) {
+ context->write.file_name = switch_event_get_header(context->url_params, "file");
+ context->write.profile_name = switch_event_get_header(context->url_params, "profile");
+ context->write.method = switch_event_get_header(context->url_params, "method");
+ context->write.name = switch_event_get_header(context->url_params, "name");
}
if (!context->write.file_name) {
char *p;
- if ((p = strrchr(context->write.dest_url, '/'))) {
+ if ((p = strrchr(context->dest_url, '/'))) {
p++;
context->write.file_name = switch_core_strdup(context->pool, p);
}
} else {
-
- file_dup = switch_core_sprintf(handle->memory_pool, "http://%s", path);
-
- if ((status = locate_url_file(context, file_dup)) != SWITCH_STATUS_SUCCESS) {
- return status;
+ if (context->url_params) {
+ context->read.ext = switch_event_get_header(context->url_params, "ext");
}
-
+ if ((status = locate_url_file(context, context->dest_url)) != SWITCH_STATUS_SUCCESS) {
+ return status;
+ }
if ((status = switch_core_file_open(&context->fh,
context->cache_file,
switch_event_add_header(params, SWITCH_STACK_BOTTOM, key, "%s", context->write.file);
}
- switch_event_add_header(params, SWITCH_STACK_BOTTOM, "url", "%s", context->write.dest_url);
+ switch_event_add_header(params, SWITCH_STACK_BOTTOM, "url", "%s", context->dest_url);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "file_driver", "true");
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "HTTAPI_SESSION_ID", "%s", context->write.uuid_str);
}
}
+ if (context->url_params) {
+ switch_event_destroy(&context->url_params);
+ }
+
return SWITCH_STATUS_SUCCESS;
}