mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 03:20:57 +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.
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
@@ -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)
|
||||
{
|
||||
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)
|
||||
|
Reference in New Issue
Block a user