Compare commits

...

5 Commits

Author SHA1 Message Date
wmasilva 65fe83ef87
Merge d4dc78afdc into 5cb74797fe 2025-01-17 16:41:07 +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
wmasilva d4dc78afdc
Merge branch 'signalwire:master' into mod_curl_add_param_ipv4_ipv6 2025-01-15 15:56:14 +01:00
wmasilva aa3ef547c4
Merge branch 'signalwire:master' into mod_curl_add_param_ipv4_ipv6 2023-04-11 10:18:16 +01:00
António Silva c8f51d6a04 mod_curl: add option to force only ipv4 or ipv6 name resolving 2022-08-31 12:55:42 +01:00
2 changed files with 47 additions and 2 deletions

View File

@ -50,7 +50,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_curl_load);
*/
SWITCH_MODULE_DEFINITION(mod_curl, mod_curl_load, mod_curl_shutdown, NULL);
static char *SYNTAX = "curl url [headers|json|content-type <mime-type>|connect-timeout <seconds>|timeout <seconds>|append_headers <header_name:header_value>[|append_headers <header_name:header_value>]|insecure|secure|[proxy <http://proxy:port>]] [get|head|post|delete|put [data]]";
static char *SYNTAX = "curl url [headers|json|content-type <mime-type>|connect-timeout <seconds>|timeout <seconds>|append_headers <header_name:header_value>[|append_headers <header_name:header_value>]|insecure|secure|[proxy <http://proxy:port>]|ipv4|ipv6] [get|head|post|delete|put [data]]";
#define HTTP_SENDFILE_ACK_EVENT "curl_sendfile::ack"
#define HTTP_SENDFILE_RESPONSE_SIZE 32768
@ -138,6 +138,8 @@ struct curl_options_obj {
long connect_timeout;
long timeout;
int insecure;
int ipv4;
int ipv6;
char *proxy;
};
typedef struct curl_options_obj curl_options_t;
@ -217,6 +219,14 @@ static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, c
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, options->timeout);
}
if (options->ipv4) {
switch_curl_easy_setopt(curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
if (options->ipv6) {
switch_curl_easy_setopt(curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
}
if (options->proxy) {
switch_curl_easy_setopt(curl_handle, CURLOPT_PROXY, options->proxy);
}
@ -937,6 +947,10 @@ SWITCH_STANDARD_APP(curl_app_function)
if (++i < argc) {
options.proxy = argv[i];
}
} else if (!strcasecmp("ipv4", argv[i])) {
options.ipv4 = 1;
} else if (!strcasecmp("ipv6", argv[i])) {
options.ipv6 = 1;
}
}
}
@ -1080,6 +1094,10 @@ SWITCH_STANDARD_API(curl_function)
if (++i < argc) {
options.proxy = argv[i];
}
} else if (!strcasecmp("ipv4", argv[i])) {
options.ipv4 = 1;
} else if (!strcasecmp("ipv6", argv[i])) {
options.ipv6 = 1;
}
}

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;
}