Esempio n. 1
0
static int json_object_equal(json_t *object1, json_t *object2)
{
    void *iter;

    if(json_object_size(object1) != json_object_size(object2))
        return 0;

    iter = json_object_iter(object1);
    while(iter)
    {
        const char *key;
        json_t *value1, *value2;

        key = json_object_iter_key(iter);
        value1 = json_object_iter_value(iter);
        value2 = json_object_get(object2, key);

        if(!json_equal(value1, value2))
            return 0;

        iter = json_object_iter_next(object1, iter);
    }

    return 1;
}
Esempio n. 2
0
bool isOrderComplete(Parameters& params, int orderId) {

  json_t* root = authRequest(params, "https://api.kraken.com", "/0/private/OpenOrders");

  // no open order: return true
  root = json_object_get(json_object_get(root, "result"), "open");
  if (json_object_size(root) == 0) {
    *params.logFile << "No order exists" << std::endl;
    return true;
  }

  *params.logFile << json_dumps(root, 0) << std::endl;

  std::string transaction_id = (*id_to_transaction)[orderId];
  root = json_object_get(root, transaction_id.c_str());
  // open orders exist but specific order not found: return true
  if (json_object_size(root) == 0) {
    *params.logFile << "Order " << transaction_id << " does not exist" << std::endl;
    return true;
  // open orders exist and specific order was found: return false
  } else {
    *params.logFile << "Order " << transaction_id << " still exists!" << std::endl;
    return false;
  }
}
Esempio n. 3
0
static void test_clear()
{
    json_t *object, *ten;

    object = json_object();
    ten = json_integer(10);

    if(!object)
        fail("unable to create object");
    if(!ten)
        fail("unable to create integer");

    if(json_object_set(object, "a", ten) ||
       json_object_set(object, "b", ten) ||
       json_object_set(object, "c", ten) ||
       json_object_set(object, "d", ten) ||
       json_object_set(object, "e", ten))
        fail("unable to set value");

    if(json_object_size(object) != 5)
        fail("invalid size");

    json_object_clear(object);

    if(json_object_size(object) != 0)
        fail("invalid size after clear");

    json_decref(ten);
    json_decref(object);
}
Esempio n. 4
0
static int json_object_equal(json_t *object1, json_t *object2)
{
    const char *key;
    json_t *value1, *value2;

    if(json_object_size(object1) != json_object_size(object2))
        return 0;

    json_object_foreach(object1, key, value1) {
        value2 = json_object_get(object2, key);

        if(!json_equal(value1, value2))
            return 0;
    }
Esempio n. 5
0
int main(int argc,char * argv[]) {
  char *text;
  json_t *root;
  json_error_t error;

  // Adjust the URL according to your CouchDB server. 
  char url[] = "http://localhost:5984/formation/_design/forms/_view/forms";
  text = request(url);

  // Load the Json.
  root = json_loads(text, 0, &error);
  free(text);

  if(!root) {
    fprintf(stderr, "error: on line %d: %s url: %s\n", error.line, error.text, url);
    return 1;
  }

  // Get an array of form documents from the "rows".
  json_t *forms = get_couchdb_object_list(root);

  size_t x;
  for (x = 0; x < json_array_size(forms);  x++) {

      json_t *form = json_array_get(forms, x);
      if(!json_is_object(form))
      {
          fprintf(stderr, "error: row %d: is not an object\n", x + 1);
          json_decref(root);
          return 1;
      }

      json_t *doc = json_object_get(form, "value");
      if(!json_is_object(doc))
      {
          fprintf(stderr, "error: doc %d: is not an object\n", x + 1);
          json_decref(root);
          return 1;
      }

      json_t *_id;
      char *_id_v;
      _id = json_object_get(doc, "_id");
      _id_v = json_string_value(_id);

      printf("%s\n", _id_v);
     
      json_t *modifier_v = json_string("sommera");
      json_object_set(doc, "modifier", modifier_v);

      char *output = json_dumps(doc, json_object_size(doc));
      printf("%s\n", output);

      free(output);

  }

  json_decref(root);
  return 0;
}
Esempio n. 6
0
static int bser_object(json_t *obj,
                       json_dump_callback_t dump, void *data)
{
    size_t n;
    json_t *val;
    const char *key;
    void *iter;

    if (dump(&bser_object_hdr, sizeof(bser_object_hdr), data)) {
        return -1;
    }

    n = json_object_size(obj);
    if (bser_int(n, dump, data)) {
        return -1;
    }

    iter = json_object_iter(obj);
    while (iter) {
        key = json_object_iter_key(iter);
        val = json_object_iter_value(iter);

        if (bser_string(key, dump, data)) {
            return -1;
        }
        if (w_bser_dump(val, dump, data)) {
            return -1;
        }

        iter = json_object_iter_next(obj, iter);
    }

    return 0;
}
Esempio n. 7
0
void init_world(struct world *world, json_t *json) {
  json_t *items = json_object_get(json, "items"), *picks = json_object_get(json, "picks"), *c;
  const char *key;
  struct vertex *ptr;
  int i = 0;
  int mult = 0;
  int heaviestitem, maxweight = 0;
  int nthreads;
  const char **keys;

  assert(items);
  if (world->options->threads <= 0)
    nthreads = sysconf(_SC_NPROCESSORS_ONLN);
  else if (world->options->threads > MAXTHREADS)
    nthreads = MAXTHREADS;
  else
    nthreads = world->options->threads;

  world->pool = init_workers(nthreads);
  world->maxmove = 30;
  world->repulsioncap = 10;
  world->nitems = json_object_size(items);
  world->edges = calloc(world->nitems*world->nitems, sizeof(struct edge));
  world->mapping = malloc((1+world->nitems)*sizeof(int));
  ptr = world->vertices = malloc(world->nitems*sizeof(struct vertex));
  world->maxid = 0;
  keys = malloc((world->nitems+1)*sizeof(char *));
  keys[world->nitems] = NULL;
  json_object_foreach (items, key, c) {
    keys[i++] = key;
    int id = atoi(key);
    world->maxid = id > world->maxid ? id : world->maxid;
  }
Esempio n. 8
0
int main ()
{
	json_t *units, *current_unit, *stats, *targetArea;
	json_error_t error;
	const char *unitname;

	units = json_load_file ("./BattleAbilities.json", 0, &error);
	if (!units) {
		/* the error variable contains error information */
		printf ("load error \n");
		exit (1);
	}
	printf ("proceeding %d ablilities...\n", (int)json_object_size (units));

	json_object_foreach (units, unitname, current_unit) {

		json_object_del (current_unit, "damageAnimationType");	/* remove damageAnimationType  */

		stats = json_object_get (current_unit, "stats");
		if (stats) {
			targetArea = json_object_get (stats, "targetArea");
			if (targetArea)
				json_object_set(targetArea, "aoeOrderDelay", json_real (0.0));
		}else
			printf ("get targetArea error\n");

	}
Esempio n. 9
0
MltRuntime::MltRuntime(json_t* script_serialed, int give) throw(Exception):
	json_version(0),
	producer_version(0),
	json_serialize(NULL),
	producer(NULL),
	consumer(NULL),
	status(StatusCreated)
{
	if ( !script_serialed || !json_is_object(script_serialed)
			|| !json_object_size(script_serialed)) {
		if ( give && script_serialed ) json_decref(script_serialed);
		throw_error_v(ErrorImplError,"Init MltRuntime with empty json");
	}
	if (give)
		json_serialize = script_serialed;
	else
		json_serialize = json_incref(script_serialed);

	try {
		parse_struct(json_serialize, JsonPath(), uuid_pathmap);
	}
	catch(Exception& e)
	{
		if (give && json_serialize) json_decref(json_serialize);
		throw;
	}
	json_version++;
	pthread_mutex_init(&run_lock,NULL);
}
Esempio n. 10
0
long long mjson_size(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *is_error) {
	long long size = -1;
	// Special case for null
	if(args->args[0] == NULL)
		return 0;
	
	if(args->arg_type[0] != STRING_RESULT) {
		fprintf(stderr, "mjson_size - the <json> argument must be a STRING - mjson_size(<json>)\n");
	    return size;
	}


	my_bool ok;
	char * json = mjarg(args, 0);
	json_t * obj = mjloads(json, &ok);
	free(json);

	if(!ok) {
	    *is_error = 1;
	    return size;
	}

	if(json_is_array(obj))
		size = json_array_size(obj);

	if(json_is_object(obj))
		size = json_object_size(obj);

	return size;
}
Esempio n. 11
0
void keys(json_t* json)
// shoddy, prints directly
{
    void* iter;
    const char** keys;
    size_t i, n;

    if (!json_is_object(json))
        {json_err("has no keys", json); return;}
    if (!((keys = malloc(sizeof(char*) * json_object_size(json)))))
        {hard_err("internal error: out of memory");}

    iter = json_object_iter(json);
    n = 0;
    while (iter)
    {
        keys[n++] = json_object_iter_key(iter);
        iter = json_object_iter_next(json, iter);
    }

    if (dumps_flags & JSON_SORT_KEYS)
        {qsort(keys, n, sizeof(char*), compare_strcmp);}

    for (i = 0; i < n; ++i)
        {printf("%s\n", keys[i]);}

    free(keys);
}
Esempio n. 12
0
void BinWriter::writeMemberInfo(json_t *jminfo)
{
    int iname       = poolJString(json_object_get(jminfo, "name"));
    int isource     = -1;
    int ilinenumber = -1;

    json_t *jsource = json_object_get(jminfo, "source");

    if (jsource && json_is_string(jsource))
    {
        isource     = poolString(json_string_value(jsource));
        ilinenumber = (int)json_integer_value(json_object_get(jminfo, "line"));
    }

    bytes.writeInt(iname);
    bytes.writeInt((int)json_integer_value(json_object_get(jminfo, "ordinal")));
    bytes.writeInt(isource);
    bytes.writeInt(ilinenumber);

    json_t *meta_object = json_object_get(jminfo, "metainfo");

    size_t meta_object_size = json_object_size(meta_object);

    // write the size of the object
    bytes.writeInt((int)meta_object_size);

    void *iter = json_object_iter(meta_object);

    size_t count = 0;

    while (iter)
    {
        // write the name to the pool table
        bytes.writeInt(poolString(json_object_iter_key(iter)));

        json_t *metaArray = json_object_iter_value(iter);

        // write the length of the meta array
        bytes.writeInt((int)json_array_size(metaArray));

        for (UTsize i = 0; i < json_array_size(metaArray); i++)
        {
            json_t *keyArray = json_array_get(metaArray, i);

            // write the length of the key array
            bytes.writeInt((int)json_array_size(keyArray));

            for (UTsize j = 0; j < json_array_size(keyArray); j++)
            {
                bytes.writeInt(poolString(json_string_value(json_array_get(keyArray, j))));
            }
        }

        iter = json_object_iter_next(meta_object, iter);
        count++;
    }

    lmAssert(meta_object_size == count, "json object size mismatch");
}
Esempio n. 13
0
mlt_filter SingleResourceLoader::get_filter(json_t* defines) throw (Exception)
{
    if ( !json_is_object(defines) || !json_object_size(defines) ) {
        throw_error_v(ErrorRuntimeLoadFailed, "effect json serialization format error");
    }

    mlt_filter ret = (mlt_filter)MltLoader::load_mlt(JsonWrap(defines));
    return ret;
}
Esempio n. 14
0
/* 得到策略信息 */
struct policymsg
get_policy_json (char *jsonfile)
{
	struct policymsg policyinfo;
	int i, size;
	void *iter;
	json_t *object;
	json_t *iter_values;
	json_error_t error;

	object = json_object ();
	/* 读取策略 */
	object = json_load_file (jsonfile, 0, &error);
	policyinfo.size = json_object_size (object);
#if 0
	//size = json_object_size (object);
	//printf("size=%d\n", size);
	/* 取出object中的值 */
	//struct policy iter_get_value(json_t *object)
	char *result;
	result = json_dumps (object, JSON_PRESERVE_ORDER);
	printf ("result=%s\n", result);
	/* 判断读取的jansson类型 */
	printf ("判断是什么类型\n");
	my_json_type (object);
	printf ("result_size = %d\n", strlen (result));
#endif

	//printf("得到策略值\n");
	iter = json_object_iter (object);
	i = 0;
	while (1) {
		strcpy (policyinfo.keyword[i], json_object_iter_key (iter));
		iter_values = json_object_iter_value (iter);
		strcpy (policyinfo.keycount[i], json_string_value (iter_values));

		//printf("values[%d]=%s\n", i,json_string_value(iter_values[i]));

		if ((iter = json_object_iter_next (object, iter)) == NULL) {
			//printf("iterate end\n");
			break;
		}
		i++;
	}

#if 0
	iter = json_object_iter_at (object, "b");
	if (iter) {
		iter_keys[i] = json_object_iter_key (iter);
		iter_values[i] = json_object_iter_value (iter);
		printf ("values[%d]=%s\n", i, json_string_value (iter_values[i]));
	}
#endif

	json_decref (object);
	return policyinfo;
}
Esempio n. 15
0
GObject *json_gobject_deserialize (GType gtype, json_t *object)
{
    GObjectClass *klass;
    GObject *ret;
    guint n_members, i;
    json_t *head, *member;
    const char *member_name;
    GArray *construct_params;

    klass = g_type_class_ref (gtype);
    n_members = json_object_size (object);
    construct_params = g_array_sized_new (FALSE, FALSE, sizeof (GParameter), n_members);
    head = json_object_iter (object);

    for (member=head; member; member=json_object_iter_next (object, member)) {
        GParamSpec *pspec;
        GParameter param = { NULL, };
        const char *member_name = json_object_iter_key (member);
        json_t *val = json_object_iter_value(member);

        pspec = g_object_class_find_property (klass, member_name);

        if (!pspec)
            continue;

        if (pspec->flags & G_PARAM_CONSTRUCT_ONLY)
            continue;

        if (!(pspec->flags & G_PARAM_WRITABLE))
            continue;

        g_value_init(&param.value, G_PARAM_SPEC_VALUE_TYPE (pspec));

        if (json_deserialize_pspec (&param.value, pspec, val)) {
            param.name = g_strdup (pspec->name);
            g_array_append_val (construct_params, param);
        }
        else
            g_warning ("Failed to deserialize \"%s\" property of type \"%s\" for an object of type \"%s\"", 
                       pspec->name, g_type_name (G_VALUE_TYPE (&param.value)), g_type_name (gtype));
    }

    ret = g_object_newv (gtype, construct_params->len, (GParameter *) construct_params->data);

    for (i=0; i!= construct_params->len; ++i) {
        GParameter *param = &g_array_index (construct_params, GParameter, i);
        g_free ((gchar *) param->name);
        g_value_unset (&param->value);
    }

    g_array_free(construct_params, TRUE);
    g_type_class_unref(klass);

    return ret;

}
Esempio n. 16
0
size_t Json::size() const
{
	switch ( json_typeof(data) )
	{
		case JSON_ARRAY:	return json_array_size( data );				break;
		case JSON_OBJECT:	return json_object_size( data );			break;
		case JSON_STRING:	return strlen( json_string_value(data) );	break;
		default:			return 0;									break;
	}
}
Esempio n. 17
0
static size_t GetJsonSize(KonohaContext *kctx, struct JsonBuf *jsonbuf)
{
	if(json_is_array(jsonbuf->jsonobj)) {
		return json_array_size(jsonbuf->jsonobj);
	}
	else if(json_is_object(jsonbuf->jsonobj)) {
		return json_object_size(jsonbuf->jsonobj);
	}
	return 1;
}
Esempio n. 18
0
static void test_conditional_updates()
{
    json_t *object, *other;

    object = json_pack("{sisi}", "foo", 1, "bar", 2);
    other = json_pack("{sisi}", "foo", 3, "baz", 4);

    if(json_object_update_existing(object, other))
        fail("json_object_update_existing failed");

    if(json_object_size(object) != 2)
        fail("json_object_update_existing added new items");

    if(json_integer_value(json_object_get(object, "foo")) != 3)
        fail("json_object_update_existing failed to update existing key");

    if(json_integer_value(json_object_get(object, "bar")) != 2)
        fail("json_object_update_existing updated wrong key");

    json_decref(object);

    object = json_pack("{sisi}", "foo", 1, "bar", 2);

    if(json_object_update_missing(object, other))
        fail("json_object_update_missing failed");

    if(json_object_size(object) != 3)
        fail("json_object_update_missing didn't add new items");

    if(json_integer_value(json_object_get(object, "foo")) != 1)
        fail("json_object_update_missing updated existing key");

    if(json_integer_value(json_object_get(object, "bar")) != 2)
        fail("json_object_update_missing updated wrong key");

    if(json_integer_value(json_object_get(object, "baz")) != 4)
        fail("json_object_update_missing didn't add new items");

    json_decref(object);
    json_decref(other);
}
Esempio n. 19
0
void MltRuntime::parse_struct(json_t* v, const JsonPath& curPath,
		hash_map<string, JsonPath>& uuid_paths, int erase) throw(Exception)
{
	json_t* je = json_object_get(v, "uuid");
	if ( je && json_is_string(je) && strlen(json_string_value(je)) ) {
		string uuid = json_string_value(je);
		if (!erase) {
			if ( uuid_paths.find(uuid) != uuid_paths.end()) {
				throw_error_v(ErrorRuntimeJsonUUIDDup, "uuid dup:%s", uuid.c_str());
			}
			uuid_paths[uuid] = curPath;
		}
		else {
			uuid_paths.erase(string(uuid));
		}
	}

	void* it =  json_object_iter(v);
	while(it) {
		const char* k = json_object_iter_key(it);
		je = json_object_iter_value(it);
		it = json_object_iter_next(v, it);

		if ( json_is_object(je) && json_object_size(je) > 0 ) {
			JsonPath subPath(curPath);
			subPath.push_back(k);
			parse_struct(je, subPath, uuid_paths, erase);
		}
		else if (json_is_array(je) && json_array_size(je) > 0) {
			int sz = json_array_size(je);
			for ( int i=0; i<sz; i++ ) {
				json_t* ae = json_array_get(je, i);
				if ( json_is_object(ae) && json_object_size(ae) > 0 ) {
					JsonPath subPath(curPath);
					subPath.push_back(k, i);
					parse_struct(ae, subPath, uuid_paths, erase);
				}
			}
		}
	}
}
Esempio n. 20
0
void print_json_object(json_t *element, int indent) {
  print_json_indent(indent);
  size_t size = json_object_size(element);
  const char *key;
  json_t *value;

  printf("JSON Object of %ld pair%s:\n", size, json_plural(size));
  json_object_foreach(element, key, value) {
    print_json_indent(indent + 2);
    printf("JSON Key: \"%s\"\n", key);
    print_json_aux(value, indent + 2);
  }
Esempio n. 21
0
int Json::size() const { 
   switch (json_typeof(m_json)) {
      case JSON_NULL:
         return 0;
      case JSON_OBJECT:
         return json_object_size(m_json);
      case JSON_ARRAY:
         return json_array_size(m_json);
      default:
         return 1;
   }
}
Esempio n. 22
0
void	list_json_object(json_t *element, int indent, FolderListing **ls) {
  size_t size;
  const char *key;
  json_t *value;
  print_json_indent(indent);
  size = json_object_size(element);
  
  printf("JSON Object of %ld pairs\n", size);
  json_object_foreach(element, key, value) {
    print_json_indent(indent + 2);
    printf("JSON Key: \"%s\"\n", key);
    check_list_type(value, indent + 2, ls, key);
  }
Esempio n. 23
0
struct netloc_dt_lookup_table* netloc_dt_lookup_table_t_json_decode(json_t *json_lt,
                                                               void * (*func)(const char *key, json_t* json_obj))
{
    struct netloc_dt_lookup_table *table = NULL;
    const char * key = NULL;
    json_t     * value = NULL;

    table = calloc(1, sizeof(*table));
    netloc_lookup_table_init(table, json_object_size(json_lt), 0);

    json_object_foreach(json_lt, key, value) {
        netloc_lookup_table_append(table, key, func(key, value));
    }
void	command_json_object(json_t *element, int indent) {
  size_t size;
  const char *key;
  json_t *value;

  //print_json_indent(indent);
  size = json_object_size(element);

  //printf("JSON Object of %ld pair:\n", size);
  json_object_foreach(element, key, value) {
    //print_json_indent(indent + 2);
    //printf("JSON Key: \"%s\"\n", key);
    command_type(value, indent + 2,  key);
  }
Esempio n. 25
0
bool Json::asBoolean()
{
	switch ( type() )
	{
		case JSON_TRUE:		return true;	break;
		case JSON_NULL:
		case JSON_FALSE:	return false;	break;
		case JSON_REAL:		return json_real_value(data) != 0.0;	break;
		case JSON_INTEGER:	return json_integer_value(data) != 0;	break;
		case JSON_ARRAY:	return json_array_size(data) > 0;		break;
		case JSON_OBJECT:	return json_object_size(data) > 0;		break;
		case JSON_STRING:	return strlen(json_string_value(data)) > 0;	break;
	}
}
Esempio n. 26
0
void handle_json_object(json_t *element, int indent, GdaList **gda) {
  size_t size;
  const char *key;
  json_t *value;

  print_json_indent(indent);
  size = json_object_size(element);

  printf("JSON Object of %ld pair%s:\n", size, json_plural_size(size));
  json_object_foreach(element, key, value) {
    print_json_indent(indent + 2);
    printf("JSON Key: \"%s\"\n", key);
    check_light_type(value, indent + 2, gda, key);
  }
Esempio n. 27
0
File: json2bon.c Progetto: emilk/bon
bon_bool write_obj(json_t* json, bon_w_doc* B)
{
	bon_bool success = BON_TRUE;
	
#if PRESERVE_ORDER	
	size_t size = json_object_size(json);
	struct object_key* keys = malloc(size * sizeof(struct object_key));
	
	void* iter = json_object_iter((json_t *)json);
	
	size_t i = 0;
	while(iter)
	{
		keys[i].serial = hashtable_iter_serial(iter);
		keys[i].key    = json_object_iter_key(iter);
		iter = json_object_iter_next((json_t *)json, iter);
		++i;
	}
	assert(i == size);
		
	qsort(keys, size, sizeof(struct object_key), object_key_compare_serials);
	
	bon_w_obj_begin(B);
	for (i = 0; i < size; ++i)
	{
		const char* key   = keys[i].key;
		json_t*     value = json_object_get(json, key);
		bon_w_key(B, key);
		if (!write_json(value, B)) {
			success = BON_FALSE;
			if (!ATTEMPT_RECOVERY)
				break;
		}
	}
	bon_w_obj_end(B);
	
	free(keys);	
#else
	const char* key;
	json_t* value;
	
	bon_w_obj_begin(B);
	json_object_foreach(json, key, value) {
		bon_w_key(B, key);
		if (!write_json(value, B)) {
			success = BON_FALSE;
			if (!ATTEMPT_RECOVERY)
				break;
		}
	}
Esempio n. 28
0
UITheme * UITheme::FromJson(const json_t * json)
{
    const char * themeName = json_string_value(json_object_get(json, "name"));
    if (themeName == nullptr)
    {
        ThrowThemeLoadException();
    }

    json_t * jsonEntries = json_object_get(json, "entries");
    size_t numEntries = json_object_size(jsonEntries);

    UITheme * result = nullptr;
    try
    {
        result = new UITheme(themeName);

        if (json_is_true(json_object_get(json, "useLightsRide")))
        {
            result->Flags |= UITHEME_FLAG_USE_LIGHTS_RIDE;
        }
        if (json_is_true(json_object_get(json, "useLightsPark")))
        {
            result->Flags |= UITHEME_FLAG_USE_LIGHTS_PARK;
        }
        if (json_is_true(json_object_get(json, "useAltScenarioSelectFont")))
        {
            result->Flags |= UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT;
        }

        const char * jkey;
        json_t     * jvalue;
        size_t       i = 0;
        json_object_foreach(jsonEntries, jkey, jvalue)
        {
            const WindowThemeDesc * wtDesc = GetWindowThemeDescriptor(jkey);
            if (wtDesc == nullptr) continue;

            UIThemeWindowEntry entry = UIThemeWindowEntry::FromJson(wtDesc, jvalue);
            result->SetEntry(&entry);
        }

        return result;
    }
    catch (Exception ex)
    {
        delete result;
        throw ex;
    }
}
Esempio n. 29
0
//native json_object_size(Handle:hObj);
static cell_t Native_json_object_size(IPluginContext *pContext, const cell_t *params) {
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

	// Param 1
	json_t *object;
	Handle_t hndlObject = static_cast<Handle_t>(params[1]);
	if ((err=g_pHandleSys->ReadHandle(hndlObject, htJanssonObject, &sec, (void **)&object)) != HandleError_None)
    {
        return pContext->ThrowNativeError("Invalid <Object> handle %x (error %d)", hndlObject, err);
    }

	return json_object_size(object);
}
Esempio n. 30
0
static int deflate_hd_json(json_t *obj, nghttp2_hd_deflater *deflater, int seq)
{
  json_t *js;
  nghttp2_nv nva[128];
  size_t len;
  size_t i;
  size_t inputlen = 0;

  js = json_object_get(obj, "headers");
  if(js == NULL) {
    fprintf(stderr, "'headers' key is missing at %d\n", seq);
    return -1;
  }
  if(!json_is_array(js)) {
    fprintf(stderr,
            "The value of 'headers' key must be an array at %d\n", seq);
    return -1;
  }
  len = json_array_size(js);
  if(len > sizeof(nva)/sizeof(nva[0])) {
    fprintf(stderr, "Too many headers (> %zu) at %d\n",
            sizeof(nva)/sizeof(nva[0]), seq);
    return -1;
  }
  for(i = 0; i < len; ++i) {
    json_t *nv_pair = json_array_get(js, i);
    const char *name;
    json_t *value;
    if(!json_is_object(nv_pair) || json_object_size(nv_pair) != 1) {
      fprintf(stderr, "bad formatted name/value pair object at %d\n", seq);
      return -1;
    }
    json_object_foreach(nv_pair, name, value) {
      nva[i].name = (uint8_t*)name;
      nva[i].namelen = strlen(name);

      if(!json_is_string(value)) {
        fprintf(stderr, "value is not string at %d\n", seq);
        return -1;
      }
      nva[i].value = (uint8_t*)json_string_value(value);
      nva[i].valuelen = strlen(json_string_value(value));
    }
    inputlen += nva[i].namelen + nva[i].valuelen;
  }