mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
json: Take advantage of new API's.
* Use "o*" format specifier for optional fields in ast_json_party_id. * Stop using ast_json_deep_copy on immutable objects, it is now thread safe to just use ast_json_ref. Additional changes to ast_json_pack calls in the vicinity: * Use "O" when an object needs to be bumped. This was previously avoided as it was not thread safe. * Use "o?" and "O?" to replace NULL with ast_json_null(). The "?" is a new feature of ast_json_pack starting with Asterisk 16. Change-Id: I8382d28d7d83ee0ce13334e51ae45dbc0bdaef48
This commit is contained in:
36
main/json.c
36
main/json.c
@@ -21,7 +21,7 @@
|
|||||||
* \brief JSON abstraction layer.
|
* \brief JSON abstraction layer.
|
||||||
*
|
*
|
||||||
* This is a very thin wrapper around the Jansson API. For more details on it,
|
* This is a very thin wrapper around the Jansson API. For more details on it,
|
||||||
* see its docs at http://www.digip.org/jansson/doc/2.4/apiref.html.
|
* see its docs at http://www.digip.org/jansson/doc/2.11/apiref.html.
|
||||||
*
|
*
|
||||||
* \author David M. Lee, II <dlee@digium.com>
|
* \author David M. Lee, II <dlee@digium.com>
|
||||||
*/
|
*/
|
||||||
@@ -747,37 +747,15 @@ static struct ast_json *json_party_subaddress(struct ast_party_subaddress *subad
|
|||||||
|
|
||||||
struct ast_json *ast_json_party_id(struct ast_party_id *party)
|
struct ast_json *ast_json_party_id(struct ast_party_id *party)
|
||||||
{
|
{
|
||||||
RAII_VAR(struct ast_json *, json_party_id, NULL, ast_json_unref);
|
int pres = ast_party_id_presentation(party);
|
||||||
int pres;
|
|
||||||
|
|
||||||
/* Combined party presentation */
|
/* Combined party presentation */
|
||||||
pres = ast_party_id_presentation(party);
|
return ast_json_pack("{s: i, s: s, s: o*, s: o*, s: o*}",
|
||||||
json_party_id = ast_json_pack("{s: i, s: s}",
|
|
||||||
"presentation", pres,
|
"presentation", pres,
|
||||||
"presentation_txt", ast_describe_caller_presentation(pres));
|
"presentation_txt", ast_describe_caller_presentation(pres),
|
||||||
if (!json_party_id) {
|
"number", json_party_number(&party->number),
|
||||||
return NULL;
|
"name", json_party_name(&party->name),
|
||||||
}
|
"subaddress", json_party_subaddress(&party->subaddress));
|
||||||
|
|
||||||
/* Party number */
|
|
||||||
if (party->number.valid
|
|
||||||
&& ast_json_object_set(json_party_id, "number", json_party_number(&party->number))) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Party name */
|
|
||||||
if (party->name.valid
|
|
||||||
&& ast_json_object_set(json_party_id, "name", json_party_name(&party->name))) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Party subaddress */
|
|
||||||
if (party->subaddress.valid
|
|
||||||
&& ast_json_object_set(json_party_id, "subaddress", json_party_subaddress(&party->subaddress))) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ast_json_ref(json_party_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)
|
enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)
|
||||||
|
@@ -3430,10 +3430,10 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast_json_pack("{s: o, s: o, s: o}",
|
return ast_json_pack("{s: o?, s: o, s: O?}",
|
||||||
"channel", payload->snapshot ? json_channel : ast_json_null(),
|
"channel", json_channel,
|
||||||
"rtcp_report", json_rtcp_report,
|
"rtcp_report", json_rtcp_report,
|
||||||
"blob", ast_json_deep_copy(payload->blob) ?: ast_json_null());
|
"blob", payload->blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rtp_rtcp_report_dtor(void *obj)
|
static void rtp_rtcp_report_dtor(void *obj)
|
||||||
|
@@ -1368,8 +1368,8 @@ static struct ast_json *multi_user_event_to_json(
|
|||||||
|
|
||||||
ast_json_object_set(out, "type", ast_json_string_create("ChannelUserevent"));
|
ast_json_object_set(out, "type", ast_json_string_create("ChannelUserevent"));
|
||||||
ast_json_object_set(out, "timestamp", ast_json_timeval(*tv, NULL));
|
ast_json_object_set(out, "timestamp", ast_json_timeval(*tv, NULL));
|
||||||
ast_json_object_set(out, "eventname", ast_json_string_create(ast_json_string_get((ast_json_object_get(blob, "eventname")))));
|
ast_json_object_set(out, "eventname", ast_json_ref(ast_json_object_get(blob, "eventname")));
|
||||||
ast_json_object_set(out, "userevent", ast_json_deep_copy(blob));
|
ast_json_object_set(out, "userevent", ast_json_ref(blob));
|
||||||
|
|
||||||
for (type = 0; type < STASIS_UMOS_MAX; ++type) {
|
for (type = 0; type < STASIS_UMOS_MAX; ++type) {
|
||||||
for (i = 0; i < AST_VECTOR_SIZE(&multi->snapshots[type]); ++i) {
|
for (i = 0; i < AST_VECTOR_SIZE(&multi->snapshots[type]); ++i) {
|
||||||
|
@@ -148,10 +148,10 @@ static struct ast_json *stasis_start_to_json(struct stasis_message *message,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = ast_json_pack("{s: s, s: o, s: o, s: o}",
|
msg = ast_json_pack("{s: s, s: O, s: O, s: o}",
|
||||||
"type", "StasisStart",
|
"type", "StasisStart",
|
||||||
"timestamp", ast_json_copy(ast_json_object_get(payload->blob, "timestamp")),
|
"timestamp", ast_json_object_get(payload->blob, "timestamp"),
|
||||||
"args", ast_json_deep_copy(ast_json_object_get(payload->blob, "args")),
|
"args", ast_json_object_get(payload->blob, "args"),
|
||||||
"channel", ast_channel_snapshot_to_json(payload->channel, NULL));
|
"channel", ast_channel_snapshot_to_json(payload->channel, NULL));
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
ast_log(LOG_ERROR, "Failed to pack JSON for StasisStart message\n");
|
ast_log(LOG_ERROR, "Failed to pack JSON for StasisStart message\n");
|
||||||
|
@@ -111,9 +111,9 @@ static struct ast_json *playback_to_json(struct stasis_message *message,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast_json_pack("{s: s, s: o}",
|
return ast_json_pack("{s: s, s: O}",
|
||||||
"type", type,
|
"type", type,
|
||||||
"playback", ast_json_deep_copy(blob));
|
"playback", blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
STASIS_MESSAGE_TYPE_DEFN(stasis_app_playback_snapshot_type,
|
STASIS_MESSAGE_TYPE_DEFN(stasis_app_playback_snapshot_type,
|
||||||
|
@@ -89,9 +89,9 @@ static struct ast_json *recording_to_json(struct stasis_message *message,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast_json_pack("{s: s, s: o}",
|
return ast_json_pack("{s: s, s: O}",
|
||||||
"type", type,
|
"type", type,
|
||||||
"recording", ast_json_deep_copy(blob));
|
"recording", blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
STASIS_MESSAGE_TYPE_DEFN(stasis_app_recording_snapshot_type,
|
STASIS_MESSAGE_TYPE_DEFN(stasis_app_recording_snapshot_type,
|
||||||
|
Reference in New Issue
Block a user