/*
 *------------------------------------------------------------------
 * json_format.h
 *
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

#ifndef __JSON_FORMAT_H__
#define __JSON_FORMAT_H__

#include <vppinfra/clib.h>
#include <vppinfra/format.h>
#ifdef __FreeBSD__
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif /* __FreeBSD__ */
#include <netinet/ip.h>

/* JSON value type */
typedef enum
{
  VAT_JSON_NONE,
  VAT_JSON_OBJECT,
  VAT_JSON_ARRAY,
  VAT_JSON_STRING,
  VAT_JSON_REAL,
  VAT_JSON_UINT,
  VAT_JSON_INT,
  VAT_JSON_IPV4,
  VAT_JSON_IPV6,
  VAT_JSON_MAX
} vat_json_val_type_t;

typedef struct vat_json_node_s vat_json_node_t;
typedef struct vat_json_pair_s vat_json_pair_t;

/* JSON object structure */
struct vat_json_node_s
{
  vat_json_val_type_t type;
  union
  {
    vat_json_pair_t *pairs;
    vat_json_node_t *array;
    u8 *string;
    struct in_addr ip4;
    struct in6_addr ip6;
    u64 uint;
    i64 sint;
    f64 real;
  };
};

struct vat_json_pair_s
{
  const char *name;
  vat_json_node_t value;
};

void vat_json_print (FILE * ofp, vat_json_node_t * node);
void vat_json_free (vat_json_node_t * node);

static_always_inline void
vat_json_init_object (vat_json_node_t * json)
{
  json->type = VAT_JSON_OBJECT;
  json->pairs = NULL;
}

static_always_inline void
vat_json_init_array (vat_json_node_t * json)
{
  json->type = VAT_JSON_ARRAY;
  json->array = NULL;
}

static_always_inline void
vat_json_set_string (vat_json_node_t * json, u8 * str)
{
  json->type = VAT_JSON_STRING;
  json->string = str;
}

static_always_inline void
vat_json_set_string_copy (vat_json_node_t * json, const u8 * str)
{
  u8 *ns = NULL;
  int len = strlen ((const char *) str);
  vec_validate_init_c_string (ns, str, len);
  vat_json_set_string (json, ns);
}

static_always_inline void
vat_json_set_int (vat_json_node_t * json, i64 num)
{
  json->type = VAT_JSON_INT;
  json->sint = num;
}

static_always_inline void
vat_json_set_uint (vat_json_node_t * json, u64 num)
{
  json->type = VAT_JSON_UINT;
  json->uint = num;
}

static_always_inline void
vat_json_set_real (vat_json_node_t * json, f64 real)
{
  json->type = VAT_JSON_REAL;
  json->real = real;
}

static_always_inline void
vat_json_set_ip4 (vat_json_node_t * json, struct in_addr ip4)
{
  json->type = VAT_JSON_IPV4;
  json->ip4 = ip4;
}

static_always_inline void
vat_json_set_ip6 (vat_json_node_t * json, struct in6_addr ip6)
{
  json->type = VAT_JSON_IPV6;
  json->ip6 = ip6;
}

static_always_inline vat_json_node_t *
vat_json_object_add (vat_json_node_t * json, const char *name)
{
  ASSERT (VAT_JSON_OBJECT == json->type);
  uword pos = vec_len (json->pairs);
  vec_validate (json->pairs, pos);
  json->pairs[pos].name = name;
  return &json->pairs[pos].value;
}

static_always_inline vat_json_node_t *
vat_json_array_add (vat_json_node_t * json)
{
  ASSERT (VAT_JSON_ARRAY == json->type);
  uword pos = vec_len (json->array);
  vec_validate (json->array, pos);
  return &json->array[pos];
}

static_always_inline vat_json_node_t *
vat_json_object_add_list (vat_json_node_t * json, const char *name)
{
  vat_json_node_t *array_node = vat_json_object_add (json, name);
  vat_json_init_array (array_node);
  return array_node;
}

static_always_inline void
vat_json_object_add_string_copy (vat_json_node_t * json,
				 const char *name, u8 * str)
{
  vat_json_set_string_copy (vat_json_object_add (json, name), str);
}

static_always_inline void
vat_json_object_add_uint (vat_json_node_t * json,
			  const char *name, u64 number)
{
  vat_json_set_uint (vat_json_object_add (json, name), number);
}

static_always_inline void
vat_json_object_add_int (vat_json_node_t * json, const char *name, i64 number)
{
  vat_json_set_int (vat_json_object_add (json, name), number);
}

static_always_inline void
vat_json_object_add_real (vat_json_node_t * json, const char *name, f64 real)
{
  vat_json_set_real (vat_json_object_add (json, name), real);
}

static_always_inline void
vat_json_object_add_ip4 (vat_json_node_t * json,
			 const char *name, struct in_addr ip4)
{
  vat_json_set_ip4 (vat_json_object_add (json, name), ip4);
}

static_always_inline void
vat_json_object_add_ip6 (vat_json_node_t * json,
			 const char *name, struct in6_addr ip6)
{
  vat_json_set_ip6 (vat_json_object_add (json, name), ip6);
}

static_always_inline void
vat_json_array_add_int (vat_json_node_t * json, i64 number)
{
  vat_json_set_int (vat_json_array_add (json), number);
}

static_always_inline void
vat_json_array_add_uint (vat_json_node_t * json, u64 number)
{
  vat_json_set_uint (vat_json_array_add (json), number);
}

static_always_inline void
vat_json_object_add_bytes (vat_json_node_t * json,
			   const char *name, u8 * array, uword size)
{
  ASSERT (VAT_JSON_OBJECT == json->type);
  vat_json_node_t *json_array = vat_json_object_add (json, name);
  vat_json_init_array (json_array);
  int i;
  for (i = 0; i < size; i++)
    {
      vat_json_array_add_uint (json_array, array[i]);
    }
}

static_always_inline vat_json_node_t *
vat_json_object_get_element (vat_json_node_t * json, const char *name)
{
  int i = 0;

  ASSERT (VAT_JSON_OBJECT == json->type);
  for (i = 0; i < vec_len (json->pairs); i++)
    {
      if (0 == strcmp (json->pairs[i].name, name))
	{
	  return &json->pairs[i].value;
	}
    }
  return NULL;
}

#endif /* __JSON_FORMAT_H__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
