Compare commits
3 Commits
971064eb27
...
e145d10bef
Author | SHA1 | Date |
---|---|---|
windy-wang | e145d10bef | |
Aron Podrigal | 5cb74797fe | |
windy-wang | d0cb158ab9 |
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef switch_status_t (*sofia_command_t) (char **argv, int argc, switch_stream
|
|||
|
||||
extern const char *sofia_state_names[];
|
||||
|
||||
switch_status_t build_sofia_status_json(cJSON * container)
|
||||
switch_status_t build_sofia_status_json(cJSON * container, const char *profile_type)
|
||||
{
|
||||
sofia_profile_t *profile = NULL;
|
||||
sofia_gateway_t *gp;
|
||||
|
@ -57,6 +57,11 @@ switch_status_t build_sofia_status_json(cJSON * container)
|
|||
cJSON * jprofile = cJSON_CreateObject();
|
||||
cJSON * jstatus = cJSON_CreateObject();
|
||||
switch_core_hash_this(hi, &vvar, NULL, &val);
|
||||
|
||||
if (!zstr(profile_type) && strcasecmp(profile_type, (const char *)vvar)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(container, (const char *)vvar, jprofile);
|
||||
cJSON_AddItemToObject(jprofile, "status", jstatus);
|
||||
profile = (sofia_profile_t *) val;
|
||||
|
@ -168,8 +173,10 @@ SWITCH_STANDARD_JSON_API(sofia_status_json_function)
|
|||
{
|
||||
cJSON *ret = cJSON_CreateObject();
|
||||
cJSON *profiles = cJSON_CreateObject();
|
||||
cJSON *data = cJSON_GetObjectItem(json, "data");
|
||||
const char *profile = cJSON_GetObjectCstr(data, "profile");
|
||||
cJSON_AddItemToObject(ret, "profiles", profiles);
|
||||
build_sofia_status_json(profiles);
|
||||
build_sofia_status_json(profiles, profile);
|
||||
|
||||
*json_reply = ret;
|
||||
|
||||
|
@ -180,8 +187,10 @@ SWITCH_STANDARD_JSON_API(sofia_status_info_json_function)
|
|||
{
|
||||
cJSON *ret = cJSON_CreateObject();
|
||||
cJSON *profiles = cJSON_CreateObject();
|
||||
cJSON *data = cJSON_GetObjectItem(json, "data");
|
||||
const char *profile = cJSON_GetObjectCstr(data, "profile");
|
||||
cJSON_AddItemToObject(ret, "profiles", profiles);
|
||||
build_sofia_status_json(profiles);
|
||||
build_sofia_status_json(profiles, profile);
|
||||
build_sofia_profile_info_json(profiles);
|
||||
|
||||
*json_reply = ret;
|
||||
|
@ -195,7 +204,7 @@ switch_status_t cmd_json_status(char **argv, int argc, switch_stream_handle_t *s
|
|||
cJSON *ret = cJSON_CreateObject();
|
||||
cJSON *profiles = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(ret, "profiles", profiles);
|
||||
build_sofia_status_json(profiles);
|
||||
build_sofia_status_json(profiles, NULL);
|
||||
build_sofia_profile_info_json(profiles);
|
||||
|
||||
json = cJSON_Print(ret);
|
||||
|
|
Loading…
Reference in New Issue