[Asterisk-code-review] json: Take advantage of new API's. (asterisk[16])
George Joseph
asteriskteam at digium.com
Wed Sep 26 07:58:52 CDT 2018
George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/10194 )
Change subject: json: Take advantage of new API's.
......................................................................
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
---
M main/json.c
M main/rtp_engine.c
M main/stasis.c
M res/res_stasis.c
M res/res_stasis_playback.c
M res/res_stasis_recording.c
6 files changed, 19 insertions(+), 41 deletions(-)
Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
Richard Mudgett: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
diff --git a/main/json.c b/main/json.c
index f8f4c0d..0bc1bd8 100644
--- a/main/json.c
+++ b/main/json.c
@@ -21,7 +21,7 @@
* \brief JSON abstraction layer.
*
* 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 at digium.com>
*/
@@ -747,37 +747,15 @@
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;
+ int pres = ast_party_id_presentation(party);
/* Combined party presentation */
- pres = ast_party_id_presentation(party);
- json_party_id = ast_json_pack("{s: i, s: s}",
+ return ast_json_pack("{s: i, s: s, s: o*, s: o*, s: o*}",
"presentation", pres,
- "presentation_txt", ast_describe_caller_presentation(pres));
- if (!json_party_id) {
- return NULL;
- }
-
- /* 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);
+ "presentation_txt", ast_describe_caller_presentation(pres),
+ "number", json_party_number(&party->number),
+ "name", json_party_name(&party->name),
+ "subaddress", json_party_subaddress(&party->subaddress));
}
enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index 3d50774..8d40594 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -3430,10 +3430,10 @@
}
}
- return ast_json_pack("{s: o, s: o, s: o}",
- "channel", payload->snapshot ? json_channel : ast_json_null(),
+ return ast_json_pack("{s: o?, s: o, s: O?}",
+ "channel", json_channel,
"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)
diff --git a/main/stasis.c b/main/stasis.c
index c20156f..51f01c0 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -1368,8 +1368,8 @@
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, "eventname", ast_json_string_create(ast_json_string_get((ast_json_object_get(blob, "eventname")))));
- ast_json_object_set(out, "userevent", ast_json_deep_copy(blob));
+ ast_json_object_set(out, "eventname", ast_json_ref(ast_json_object_get(blob, "eventname")));
+ ast_json_object_set(out, "userevent", ast_json_ref(blob));
for (type = 0; type < STASIS_UMOS_MAX; ++type) {
for (i = 0; i < AST_VECTOR_SIZE(&multi->snapshots[type]); ++i) {
diff --git a/res/res_stasis.c b/res/res_stasis.c
index dcd7414..29c0c7c 100644
--- a/res/res_stasis.c
+++ b/res/res_stasis.c
@@ -148,10 +148,10 @@
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",
- "timestamp", ast_json_copy(ast_json_object_get(payload->blob, "timestamp")),
- "args", ast_json_deep_copy(ast_json_object_get(payload->blob, "args")),
+ "timestamp", ast_json_object_get(payload->blob, "timestamp"),
+ "args", ast_json_object_get(payload->blob, "args"),
"channel", ast_channel_snapshot_to_json(payload->channel, NULL));
if (!msg) {
ast_log(LOG_ERROR, "Failed to pack JSON for StasisStart message\n");
diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c
index 5b8256f..a25a300 100644
--- a/res/res_stasis_playback.c
+++ b/res/res_stasis_playback.c
@@ -111,9 +111,9 @@
return NULL;
}
- return ast_json_pack("{s: s, s: o}",
+ return ast_json_pack("{s: s, s: O}",
"type", type,
- "playback", ast_json_deep_copy(blob));
+ "playback", blob);
}
STASIS_MESSAGE_TYPE_DEFN(stasis_app_playback_snapshot_type,
diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c
index 17213aa..755bdcf 100644
--- a/res/res_stasis_recording.c
+++ b/res/res_stasis_recording.c
@@ -89,9 +89,9 @@
return NULL;
}
- return ast_json_pack("{s: s, s: o}",
+ return ast_json_pack("{s: s, s: O}",
"type", type,
- "recording", ast_json_deep_copy(blob));
+ "recording", blob);
}
STASIS_MESSAGE_TYPE_DEFN(stasis_app_recording_snapshot_type,
--
To view, visit https://gerrit.asterisk.org/10194
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: I8382d28d7d83ee0ce13334e51ae45dbc0bdaef48
Gerrit-Change-Number: 10194
Gerrit-PatchSet: 3
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180926/8e3c8f42/attachment.html>
More information about the asterisk-code-review
mailing list