Compare commits

...

3 Commits

Author SHA1 Message Date
Ahron Greenberg (agree) f44b32d72c
Merge 480cb6a395 into 5cb74797fe 2025-01-17 16:41:26 +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
Ahron Greenberg (agree) 480cb6a395 [mod_dialplan_xml] new attribute to not break from nested conditions
The default behavior is to always break from proceeding to nested conditions even if a condition matches, besides when `break="never"`.

Common sense says when a condition matches and `break` is set to `on-true` to proceed to nested conditions, and `break` should only apply to the subsequent conditions.

This commit introduces a new extension attribute, `break-from-nested` that can be set to `false` to not break from nested conditions if the condition matches; besides, if `break="on-false"`

The default behavior will be `break-from-nested=true`, so it won't break any existing systems.

Example:
```xml
<extension name="break-from-nested-test" continue="true" break-from-nested="false">
	<condition>
		<action application="set" data="var1=true" inline="true"/>
	</condition>

	<condition field="${var1}" expression="^true$" break="on-true">
		<action application="log" data="err external condition" inline="true"/>

		<condition>
			<action application="log" data="err I will only log if break-from-nested is set to false" inline="true"/>
		</condition>
	</condition>

	<condition>
		<action application="log" data="err I will only log if previous conditions did not break" inline="true"/>
	</condition>
</extension>
```
2023-12-12 00:28:02 -05:00
2 changed files with 43 additions and 4 deletions

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

View File

@ -573,9 +573,15 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
}
switch_regex_safe_free(re);
if (((anti_action == SWITCH_FALSE && do_break_i == BREAK_ON_TRUE) ||
(anti_action == SWITCH_TRUE && do_break_i == BREAK_ON_FALSE)) || do_break_i == BREAK_ALWAYS) {
break;
if (switch_xml_child(xcond, "condition") && switch_xml_attr(xexten, "break-from-nested") && switch_false(switch_xml_attr(xexten, "break-from-nested"))) {
if ((anti_action == SWITCH_TRUE && do_break_i == BREAK_ON_FALSE)) {
break;
}
} else {
if (((anti_action == SWITCH_FALSE && do_break_i == BREAK_ON_TRUE) ||
(anti_action == SWITCH_TRUE && do_break_i == BREAK_ON_FALSE)) || do_break_i == BREAK_ALWAYS) {
break;
}
}
if (proceed) {
@ -588,6 +594,12 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
}
}
}
/* need to recheck this if we didn't break ealier because of break-from-nested */
if (((anti_action == SWITCH_FALSE && do_break_i == BREAK_ON_TRUE) ||
(anti_action == SWITCH_TRUE && do_break_i == BREAK_ON_FALSE)) || do_break_i == BREAK_ALWAYS) {
break;
}
}
done: