Skip to content

Commit

Permalink
json: rename some variables and change C99 comment
Browse files Browse the repository at this point in the history
(cherry picked from commit d3def25)
  • Loading branch information
razvancrainea committed Feb 1, 2018
1 parent 8c200b8 commit 3ca4c9f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
4 changes: 1 addition & 3 deletions modules/json/Makefile
@@ -1,7 +1,5 @@
# $Id: Makefile 5862 2009-07-15 10:06:05Z andreidragus $
#
# Memcached implementation for memcache API.
#
# Json object manipulation
#
# WARNING: do not run this directly, it should be run by the master Makefile

Expand Down
4 changes: 2 additions & 2 deletions modules/json/array_del.c
Expand Up @@ -27,7 +27,7 @@

#include "opensips_json_c_helper.h"

#if JSON_C_VERSION_NUM < JSON_C_VER_013
#if JSON_C_VERSION_NUM < JSON_C_VERSION_013
void array_list_del_idx(struct array_list * arr, int idx)
{
int i;
Expand All @@ -46,7 +46,7 @@ void array_list_del_idx(struct array_list * arr, int idx)

void json_object_array_del(struct json_object* obj, int idx)
{
#if JSON_C_VERSION_NUM >= JSON_C_VER_013
#if JSON_C_VERSION_NUM >= JSON_C_VERSION_013
struct array_list * arr = json_object_get_array(obj);
array_list_del_idx(arr, idx, arr->length);
#else
Expand Down
6 changes: 3 additions & 3 deletions modules/json/json.c
Expand Up @@ -293,7 +293,7 @@ json_t * get_object(pv_json_t * var, pv_param_t* pvp , json_tag ** tag,
!json_object_is_type( cur_obj, json_type_object ) )
goto error;

#if JSON_C_VERSION_NUM >= JSON_C_VER_010
#if JSON_C_VERSION_NUM >= JSON_C_VERSION_010
if (!json_object_object_get_ex( cur_obj,buff, &cur_obj ) &&
tag == NULL)
goto error;
Expand Down Expand Up @@ -410,7 +410,7 @@ int pv_get_json (struct sip_msg* msg, pv_param_t* pvp, pv_value_t* val)
{
val->flags = PV_VAL_STR;
val->rs.s = (char*)json_object_get_string( obj );
#if JSON_C_VERSION_NUM >= JSON_C_VER_010
#if JSON_C_VERSION_NUM >= JSON_C_VERSION_010
val->rs.len = json_object_get_string_len( obj );
#else
val->rs.len = strlen(val->rs.s);
Expand Down Expand Up @@ -582,7 +582,7 @@ int pv_set_json (struct sip_msg* msg, pv_param_t* pvp, int flag ,
if (obj == NULL)
{
LM_ERR("Error parsing json: %s\n",
#if JSON_C_VERSION_NUM >= JSON_C_VER_010
#if JSON_C_VERSION_NUM >= JSON_C_VERSION_010
json_tokener_error_desc(parse_status)
#else
json_tokener_errors[(unsigned long)obj]
Expand Down
38 changes: 22 additions & 16 deletions modules/json/opensips_json_c_helper.h
Expand Up @@ -26,11 +26,13 @@
#ifndef OPENSIPS_JSON_C_HELPER_H
#define OPENSIPS_JSON_C_HELPER_H

// If those are not defined, we assume to build against json-c v0.9.
// Starting with v0.11 there is json_c_version.h, which we prefer
// anyways, so there are no regressions in this case. Everything
// conditionalized for v0.10 or later doesn't produce any fallout,
// when we are asuming v0.9 and building against v0.10.
/*
* If those are not defined, we assume to build against json-c v0.9.
* Starting with v0.11 there is json_c_version.h, which we prefer
* anyways, so there are no regressions in this case. Everything
* conditionalized for v0.10 or later doesn't produce any fallout,
* when we are asuming v0.9 and building against v0.10.
*/
#ifndef JSON_PKG_MAJOR
#define JSON_PKG_MAJOR 0
#endif
Expand All @@ -41,30 +43,34 @@
#define JSON_PKG_MICRO 0
#endif

// json.h automatically includes json_c_version.h, if available.
/* json.h automatically includes json_c_version.h, if available. */
#include <json.h>

// We prefer JSON_C_VERSION_NUM defined in json_c_version.h. If it is
// not defined, we construct it the same way from our JSON_PKG_* defines.
/*
* We prefer JSON_C_VERSION_NUM defined in json_c_version.h. If it is
* not defined, we construct it the same way from our JSON_PKG_* defines.
*/
#ifndef JSON_C_VERSION_NUM
#define JSON_C_VERSION_NUM (JSON_PKG_MAJOR << 16) | \
(JSON_PKG_MINOR << 8) | \
JSON_PKG_MICRO
#endif

// Macros for checking specific versions.
#define JSON_C_VER_010 (10 << 8)
#define JSON_C_VER_013 (13 << 8)
/* Macros for checking specific versions. */
#define JSON_C_VERSION_010 (10 << 8)
#define JSON_C_VERSION_013 (13 << 8)

// json_object_private.h is gone and not needed anymore in json-c v0.13+.
#if JSON_C_VERSION_NUM < JSON_C_VER_013
/* json_object_private.h is gone and not needed anymore in json-c v0.13+. */
#if JSON_C_VERSION_NUM < JSON_C_VERSION_013
#include <json_object_private.h>
#endif

// Newer versions of json-c define this in their headers, so we prefer
// their definition in that case.
/*
* Newer versions of json-c define this in their headers, so we prefer
* their definition in that case.
*/
#ifndef JSON_FILE_BUF_SIZE
#define JSON_FILE_BUF_SIZE 4096
#endif

#endif // OPENSIPS_JSON_C_HELPER_H
#endif /* OPENSIPS_JSON_C_HELPER_H */

0 comments on commit 3ca4c9f

Please sign in to comment.