Compare commits

...

7 Commits

Author SHA1 Message Date
Joshua Gigg 9534e68d7b
Merge 1c749fbed7 into 5cb74797fe 2025-01-17 16:40:19 +00:00
Aron Podrigal 5cb74797fe
[mod_pgsql] err is now set correctly (dbh:last_error())
New function, `void pgsql_handle_set_error_if_not_set(switch_pgsql_handle_t *handle, char **err)` has been added to mod_pgsql module. This function is now called at several points where an error occurred but *err was not yet set.
2025-01-17 18:51:45 +03:00
Joshua Gigg 1c749fbed7
Fix comment 2020-09-10 20:50:16 +01:00
Joshua Gigg 32e7e51652
Fix duplicate variable declaration 2020-09-10 20:47:56 +01:00
Joshua Gigg c475f5d8ab
Save to a temp file first, then rename
This allows the GET request to return a different mime type (and extension) to what was previously stored
2020-09-10 20:47:00 +01:00
Joshua Gigg 59eaa4c221
Don't remove the old file if the extension changes
Avoids any chance of a race condition removing a file that is about to be played
2020-09-04 11:29:02 +01:00
Joshua Gigg 1b70a706ff
[mod_httapi] Update cache file if the extension changes
If a HTTP request changes the extension (by using Content-Type header) of the existing cached file,
remove the existing cached file, and allow the new one to save with the correct extension.
2020-08-27 13:27:40 +01:00
2 changed files with 60 additions and 8 deletions

View File

@ -2787,8 +2787,12 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
switch_status_t status = SWITCH_STATUS_FALSE;
time_t now = switch_epoch_time_now(NULL);
char *metadata;
const char *cache_file_temp;
const char *ext = NULL;
const char *err_msg = NULL;
const char *ct = NULL;
const char *newext = NULL;
load_cache_data(context, url);
@ -2805,9 +2809,6 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
}
if (!context->url_params || !switch_true(switch_event_get_header(context->url_params, "nohead"))) {
const char *ct = NULL;
const char *newext = NULL;
if ((status = fetch_cache_data(context, url, &headers, NULL, NULL)) != SWITCH_STATUS_SUCCESS) {
if (status == SWITCH_STATUS_NOTFOUND) {
unreachable = 2;
@ -2819,13 +2820,17 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
}
}
if (zstr(ext) && headers && (ct = switch_event_get_header(headers, "content-type"))) {
if (headers && (ct = switch_event_get_header(headers, "content-type"))) {
newext = switch_core_mime_type2ext(ct);
}
if (newext) {
if (newext && (zstr(ext) || strcmp(ext, newext) != 0)) {
/*
* HTTP Request has returned the file with a different extension
* Update the cache_file path
*/
ext = newext;
context->cache_file = switch_core_sprintf(context->pool, "%s.%s", context->cache_file, newext);
context->cache_file = switch_core_sprintf(context->pool, "%s.%s", context->cache_file_base, newext);
}
@ -2854,10 +2859,30 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
}
if ((status = fetch_cache_data(context, url, &headers, context->cache_file, &err_msg)) != SWITCH_STATUS_SUCCESS) {
/*
* Save to a temp file first, then rename
* Just in case the extension changes
*/
cache_file_temp = switch_core_sprintf(context->pool, "%s.tmp", context->cache_file_base);
if ((status = fetch_cache_data(context, url, &headers, cache_file_temp, &err_msg)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error fetching file at URL \"%s\" (%s)\n", url, err_msg ? err_msg : "");
goto end;
}
if (headers && (ct = switch_event_get_header(headers, "content-type"))) {
newext = switch_core_mime_type2ext(ct);
}
if (newext && (zstr(ext) || strcmp(ext, newext) != 0)) {
/*
* HTTP Request has returned the file with a different extension
* Update the cache_file path for when the rename happens
*/
ext = newext;
context->cache_file = switch_core_sprintf(context->pool, "%s.%s", context->cache_file_base, newext);
}
rename(cache_file_temp, context->cache_file);
metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s",

View File

@ -106,6 +106,22 @@ char * pgsql_handle_get_error(switch_pgsql_handle_t *handle)
return err_str;
}
void pgsql_handle_set_error_if_not_set(switch_pgsql_handle_t *handle, char **err)
{
char *err_str;
if (err && !(*err)) {
err_str = pgsql_handle_get_error(handle);
if (zstr(err_str)) {
switch_safe_free(err_str);
err_str = strdup((char *)"SQL ERROR!");
}
*err = err_str;
}
}
static int db_is_up(switch_pgsql_handle_t *handle)
{
int ret = 0;
@ -553,8 +569,15 @@ switch_status_t pgsql_handle_exec_detailed(const char *file, const char *func, i
goto error;
}
return pgsql_finish_results(handle);
if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
goto error;
}
return SWITCH_STATUS_SUCCESS;
error:
pgsql_handle_set_error_if_not_set(handle, err);
return SWITCH_STATUS_FALSE;
}
@ -630,6 +653,7 @@ done:
pgsql_free_result(&result);
if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
pgsql_handle_set_error_if_not_set(handle, err);
sstatus = SWITCH_STATUS_FALSE;
}
@ -638,6 +662,7 @@ done:
error:
pgsql_free_result(&result);
pgsql_handle_set_error_if_not_set(handle, err);
return SWITCH_STATUS_FALSE;
}
@ -1050,6 +1075,8 @@ switch_status_t pgsql_handle_callback_exec_detailed(const char *file, const char
return SWITCH_STATUS_SUCCESS;
error:
pgsql_handle_set_error_if_not_set(handle, err);
return SWITCH_STATUS_FALSE;
}