<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10194">View Change</a></p><div style="white-space:pre-wrap">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
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">json: Take advantage of new API's.<br><br>* Use "o*" format specifier for optional fields in ast_json_party_id.<br>* Stop using ast_json_deep_copy on immutable objects, it is now thread<br> safe to just use ast_json_ref.<br><br>Additional changes to ast_json_pack calls in the vicinity:<br>* Use "O" when an object needs to be bumped. This was previously<br> avoided as it was not thread safe.<br>* Use "o?" and "O?" to replace NULL with ast_json_null(). The<br> "?" is a new feature of ast_json_pack starting with Asterisk 16.<br><br>Change-Id: I8382d28d7d83ee0ce13334e51ae45dbc0bdaef48<br>---<br>M main/json.c<br>M main/rtp_engine.c<br>M main/stasis.c<br>M res/res_stasis.c<br>M res/res_stasis_playback.c<br>M res/res_stasis_recording.c<br>6 files changed, 19 insertions(+), 41 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/json.c b/main/json.c</span><br><span>index f8f4c0d..0bc1bd8 100644</span><br><span>--- a/main/json.c</span><br><span>+++ b/main/json.c</span><br><span>@@ -21,7 +21,7 @@</span><br><span> * \brief JSON abstraction layer.</span><br><span> *</span><br><span> * This is a very thin wrapper around the Jansson API. For more details on it,</span><br><span style="color: hsl(0, 100%, 40%);">- * see its docs at http://www.digip.org/jansson/doc/2.4/apiref.html.</span><br><span style="color: hsl(120, 100%, 40%);">+ * see its docs at http://www.digip.org/jansson/doc/2.11/apiref.html.</span><br><span> *</span><br><span> * \author David M. Lee, II <dlee@digium.com></span><br><span> */</span><br><span>@@ -747,37 +747,15 @@</span><br><span> </span><br><span> struct ast_json *ast_json_party_id(struct ast_party_id *party)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_json *, json_party_id, NULL, ast_json_unref);</span><br><span style="color: hsl(0, 100%, 40%);">- int pres;</span><br><span style="color: hsl(120, 100%, 40%);">+ int pres = ast_party_id_presentation(party);</span><br><span> </span><br><span> /* Combined party presentation */</span><br><span style="color: hsl(0, 100%, 40%);">- pres = ast_party_id_presentation(party);</span><br><span style="color: hsl(0, 100%, 40%);">- json_party_id = ast_json_pack("{s: i, s: s}",</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_json_pack("{s: i, s: s, s: o*, s: o*, s: o*}",</span><br><span> "presentation", pres,</span><br><span style="color: hsl(0, 100%, 40%);">- "presentation_txt", ast_describe_caller_presentation(pres));</span><br><span style="color: hsl(0, 100%, 40%);">- if (!json_party_id) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Party number */</span><br><span style="color: hsl(0, 100%, 40%);">- if (party->number.valid</span><br><span style="color: hsl(0, 100%, 40%);">- && ast_json_object_set(json_party_id, "number", json_party_number(&party->number))) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Party name */</span><br><span style="color: hsl(0, 100%, 40%);">- if (party->name.valid</span><br><span style="color: hsl(0, 100%, 40%);">- && ast_json_object_set(json_party_id, "name", json_party_name(&party->name))) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Party subaddress */</span><br><span style="color: hsl(0, 100%, 40%);">- if (party->subaddress.valid</span><br><span style="color: hsl(0, 100%, 40%);">- && ast_json_object_set(json_party_id, "subaddress", json_party_subaddress(&party->subaddress))) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return ast_json_ref(json_party_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ "presentation_txt", ast_describe_caller_presentation(pres),</span><br><span style="color: hsl(120, 100%, 40%);">+ "number", json_party_number(&party->number),</span><br><span style="color: hsl(120, 100%, 40%);">+ "name", json_party_name(&party->name),</span><br><span style="color: hsl(120, 100%, 40%);">+ "subaddress", json_party_subaddress(&party->subaddress));</span><br><span> }</span><br><span> </span><br><span> enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)</span><br><span>diff --git a/main/rtp_engine.c b/main/rtp_engine.c</span><br><span>index 3d50774..8d40594 100644</span><br><span>--- a/main/rtp_engine.c</span><br><span>+++ b/main/rtp_engine.c</span><br><span>@@ -3430,10 +3430,10 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- return ast_json_pack("{s: o, s: o, s: o}",</span><br><span style="color: hsl(0, 100%, 40%);">- "channel", payload->snapshot ? json_channel : ast_json_null(),</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_json_pack("{s: o?, s: o, s: O?}",</span><br><span style="color: hsl(120, 100%, 40%);">+ "channel", json_channel,</span><br><span> "rtcp_report", json_rtcp_report,</span><br><span style="color: hsl(0, 100%, 40%);">- "blob", ast_json_deep_copy(payload->blob) ?: ast_json_null());</span><br><span style="color: hsl(120, 100%, 40%);">+ "blob", payload->blob);</span><br><span> }</span><br><span> </span><br><span> static void rtp_rtcp_report_dtor(void *obj)</span><br><span>diff --git a/main/stasis.c b/main/stasis.c</span><br><span>index c20156f..51f01c0 100644</span><br><span>--- a/main/stasis.c</span><br><span>+++ b/main/stasis.c</span><br><span>@@ -1368,8 +1368,8 @@</span><br><span> </span><br><span> ast_json_object_set(out, "type", ast_json_string_create("ChannelUserevent"));</span><br><span> ast_json_object_set(out, "timestamp", ast_json_timeval(*tv, NULL));</span><br><span style="color: hsl(0, 100%, 40%);">- ast_json_object_set(out, "eventname", ast_json_string_create(ast_json_string_get((ast_json_object_get(blob, "eventname")))));</span><br><span style="color: hsl(0, 100%, 40%);">- ast_json_object_set(out, "userevent", ast_json_deep_copy(blob));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_object_set(out, "eventname", ast_json_ref(ast_json_object_get(blob, "eventname")));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_json_object_set(out, "userevent", ast_json_ref(blob));</span><br><span> </span><br><span> for (type = 0; type < STASIS_UMOS_MAX; ++type) {</span><br><span> for (i = 0; i < AST_VECTOR_SIZE(&multi->snapshots[type]); ++i) {</span><br><span>diff --git a/res/res_stasis.c b/res/res_stasis.c</span><br><span>index dcd7414..29c0c7c 100644</span><br><span>--- a/res/res_stasis.c</span><br><span>+++ b/res/res_stasis.c</span><br><span>@@ -148,10 +148,10 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- msg = ast_json_pack("{s: s, s: o, s: o, s: o}",</span><br><span style="color: hsl(120, 100%, 40%);">+ msg = ast_json_pack("{s: s, s: O, s: O, s: o}",</span><br><span> "type", "StasisStart",</span><br><span style="color: hsl(0, 100%, 40%);">- "timestamp", ast_json_copy(ast_json_object_get(payload->blob, "timestamp")),</span><br><span style="color: hsl(0, 100%, 40%);">- "args", ast_json_deep_copy(ast_json_object_get(payload->blob, "args")),</span><br><span style="color: hsl(120, 100%, 40%);">+ "timestamp", ast_json_object_get(payload->blob, "timestamp"),</span><br><span style="color: hsl(120, 100%, 40%);">+ "args", ast_json_object_get(payload->blob, "args"),</span><br><span> "channel", ast_channel_snapshot_to_json(payload->channel, NULL));</span><br><span> if (!msg) {</span><br><span> ast_log(LOG_ERROR, "Failed to pack JSON for StasisStart message\n");</span><br><span>diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c</span><br><span>index 5b8256f..a25a300 100644</span><br><span>--- a/res/res_stasis_playback.c</span><br><span>+++ b/res/res_stasis_playback.c</span><br><span>@@ -111,9 +111,9 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- return ast_json_pack("{s: s, s: o}",</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_json_pack("{s: s, s: O}",</span><br><span> "type", type,</span><br><span style="color: hsl(0, 100%, 40%);">- "playback", ast_json_deep_copy(blob));</span><br><span style="color: hsl(120, 100%, 40%);">+ "playback", blob);</span><br><span> }</span><br><span> </span><br><span> STASIS_MESSAGE_TYPE_DEFN(stasis_app_playback_snapshot_type,</span><br><span>diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c</span><br><span>index 17213aa..755bdcf 100644</span><br><span>--- a/res/res_stasis_recording.c</span><br><span>+++ b/res/res_stasis_recording.c</span><br><span>@@ -89,9 +89,9 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- return ast_json_pack("{s: s, s: o}",</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_json_pack("{s: s, s: O}",</span><br><span> "type", type,</span><br><span style="color: hsl(0, 100%, 40%);">- "recording", ast_json_deep_copy(blob));</span><br><span style="color: hsl(120, 100%, 40%);">+ "recording", blob);</span><br><span> }</span><br><span> </span><br><span> STASIS_MESSAGE_TYPE_DEFN(stasis_app_recording_snapshot_type,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10194">change 10194</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10194"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I8382d28d7d83ee0ce13334e51ae45dbc0bdaef48 </div>
<div style="display:none"> Gerrit-Change-Number: 10194 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>