Exemplo n.º 1
0
static GError *
_jarray_to_beans (GSList **out, struct json_object *jv, jbean_mapper map)
{
	if (!json_object_is_type(jv, json_type_array))
		return NEWERROR(CODE_BAD_REQUEST, "Invalid JSON, exepecting array of beans");

	GSList *l = NULL;
	int vlen = json_object_array_length (jv);
	for (int i=0; i<vlen ;++i) {
		struct json_object *j = json_object_array_get_idx (jv, i);
		if (!json_object_is_type (j, json_type_object))
			return NEWERROR(CODE_BAD_REQUEST, "Invalid JSON for a bean");
		gpointer bean = NULL;
		GError *err = map(j, &bean);
		EXTRA_ASSERT((bean != NULL) ^ (err != NULL));
		if (err) {
			_bean_cleanl2 (l);
			return err;
		}
		l = g_slist_prepend(l, bean);
	}

	*out = g_slist_reverse (l);
	return NULL;
}
/**
 * If the OpenStack service represented by the given JSON object is of the type name given by callback_arg, return STOP.
 * Otherwise, if it is of some other type or if its type cannot be determined, return CONTINUE.
 */
static item_callback_return_t
filter_service_by_type(keystone_context_t *context, struct json_object *service, void *callback_arg)
{
	const char *desired_type = (const char *) callback_arg;
	struct json_object *service_type;

	assert(context != NULL);
	assert(service != NULL);
	assert(callback_arg != NULL);

	if (!json_object_is_type(service, json_type_object)) {
		context->keystone_error("response.access.serviceCatalog[n] is not an object", KSERR_PARSE);
		return CONTINUE;
	}
	if (!json_object_object_get_ex(service, "type", &service_type)) {
		context->keystone_error("response.access.serviceCatalog[n] lacks a 'type' key", KSERR_PARSE);
		return CONTINUE;
	}
	if (!json_object_is_type(service_type, json_type_string)) {
		context->keystone_error("response.access.serviceCatalog[n].type is not a string", KSERR_PARSE);
		return CONTINUE;
	}
	if (0 != strcmp(json_object_get_string(service_type), desired_type)) {
		return CONTINUE; /* Not the service type we're after */
	}

	return STOP; /* Acceptable */
}
Exemplo n.º 3
0
static int json_pointer_set_single_path(
	struct json_object *parent,
	const char *path,
	struct json_object *value)
{
	if (json_object_is_type(parent, json_type_array)) {
		int32_t idx;
		/* RFC (Chapter 4) states that '-' may be used to add new elements to an array */
		if (path[0] == '-' && path[1] == '\0')
			return json_object_array_add(parent, value);
		if (!is_valid_index(parent, path, &idx))
			return -1;
		return json_object_array_put_idx(parent, idx, value);
	}

	/* path replacements should have been done in json_pointer_get_single_path(),
	   and we should still be good here */
	if (json_object_is_type(parent, json_type_object))
		return json_object_object_add(parent, path, value);

	/* Getting here means that we tried to "dereference" a primitive JSON type (like string, int, bool).
	   i.e. add a sub-object to it */
	errno = ENOENT;
	return -1;
}
/**
 * Given a JSON object representing an endpoint of an OpenStack service and a desired endpoint version,
 * if the given endpoint appears to have the given API version, or it has no versionID attribute, return STOP.
 * Otherwise, if the endpoint's version is not the desired version, or the endpoint's version is erroneous, return CONTINUE.
 */
static item_callback_return_t
filter_endpoint_by_version(keystone_context_t *context, json_object *endpoint, void *callback_arg)
{
	unsigned int desired_api_version;
	struct json_object *endpoint_api_version;

	assert(context != NULL);
	assert(endpoint != NULL);
	assert(callback_arg != NULL);

	desired_api_version = *((unsigned int *) callback_arg);
	if (!json_object_is_type(endpoint, json_type_object)) {
		context->keystone_error("response.access.serviceCatalog[n].endpoints[n] is not an object", KSERR_PARSE);
		return CONTINUE;
	}
	if (!json_object_object_get_ex(endpoint, "versionId", &endpoint_api_version)) {
		/* Keystone documentation includes a versionID key, but it is not present in the responses I've seen */
		/* context->keystone_error("response.access.serviceCatalog[n].endpoints[n] lacks a 'versionId' key", KSERR_PARSE); */
		return STOP; /* Take a lack of versionID to mean a catch-all */
	}
	if (!json_object_is_type(endpoint_api_version, json_type_string)) {
		context->keystone_error("response.access.serviceCatalog[n].endpoints[n].versionId is not a string", KSERR_PARSE);
		return CONTINUE; /* Version attribute wrong type */
	}
	if (json_object_get_double(endpoint_api_version) != desired_api_version) {
		return CONTINUE; /* Not the version we're after */
	}

	/* Found the API version we're after */
	return STOP;
}
Exemplo n.º 5
0
Arquivo: ggg.cpp Projeto: koo5/lemon-2
    void draw_item(json_object *o)
    {
	stringstream dummy;
	if(json_object_is_type(o, json_type_boolean))
	{
	    json_object_get_boolean(o)?draw_text("1"):draw_text("0");
	    one_down();
	}
	if(json_object_is_type(o, json_type_double))
	{
	    dummy << json_object_get_double(o);
	    draw_text(dummy.str().c_str());
	    one_down();
	}
	if(json_object_is_type(o, json_type_int))
	{
	    dummy << json_object_get_int(o);
	    draw_text(dummy.str().c_str());
	    one_down();
	}
	if(json_object_is_type(o, json_type_object))
	{
	    one_right();
	    json_object_object_foreach(o, key,val)
	    {
		draw_text(key);
		one_down();
		draw_item(val);
		one_down();
	    }
	    one_left();
	}
/**
 * Retrieve the authentication token and service catalog from a now-complete Keystone JSON response,
 * and store them in the Keystone context structure for later use.
 */
static enum keystone_error
process_keystone_json(keystone_context_t *context, struct json_object *response)
{
	struct json_object *access, *token, *id;

	if (context->pvt.debug) {
		json_object_to_file_ext("/dev/stderr", response, JSON_C_TO_STRING_PRETTY);
	}
	if (!json_object_is_type(response, json_type_object)) {
		context->keystone_error("response is not an object", KSERR_PARSE);
		return KSERR_PARSE; /* Not the expected JSON object */
	}
	/* Everything is in an "access" sub-object */
	if (!json_object_object_get_ex(response, "access", &access)) {
		context->keystone_error("response lacks 'access' key", KSERR_PARSE);
		return KSERR_PARSE; /* Lacking the expected key */
	}
	if (!json_object_is_type(access, json_type_object)) {
		context->keystone_error("response.access is not an object", KSERR_PARSE);
		return KSERR_PARSE; /* Not the expected JSON object */
	}
	/* Service catalog */
	if (!json_object_object_get_ex(access, "serviceCatalog", &context->pvt.services)) {
		context->keystone_error("response.access lacks 'serviceCatalog' key", KSERR_PARSE);
		return KSERR_PARSE;
	}
	if (!json_object_is_type(context->pvt.services, json_type_array)) {
		context->keystone_error("response.access.serviceCatalog not an array", KSERR_PARSE);
		return KSERR_PARSE;
	}
	/* Authentication token */
	if (!json_object_object_get_ex(access, "token", &token)) {
		context->keystone_error("reponse.access lacks 'token' key", KSERR_PARSE);
		return KSERR_PARSE; /* Lacking the expected key */
	}
	if (!json_object_is_type(token, json_type_object)) {
		context->keystone_error("response.access.token is not an object", KSERR_PARSE);
		return KSERR_PARSE; /* Not the expected JSON object */
	}
	if (!json_object_object_get_ex(token, "id", &id)) {
		context->keystone_error("response.access.token lacks 'id' key", KSERR_PARSE);
		return KSERR_PARSE; /* Lacking the expected key */
	}
	if (!json_object_is_type(id, json_type_string)) {
		context->keystone_error("response.access.token.id is not a string", KSERR_PARSE);
		return KSERR_PARSE; /* Not the expected JSON string */
	}
	context->pvt.auth_token = context->allocator(
		context->pvt.auth_token,
		json_object_get_string_len(id)
		+ 1 /* '\0' */
	);
	if (NULL == context->pvt.auth_token) {
		return KSERR_PARSE; /* Allocation failed */
	}
	strcpy(context->pvt.auth_token, json_object_get_string(id));

	return KSERR_SUCCESS;
}
Exemplo n.º 7
0
Arquivo: mraa.c Projeto: fboudra/mraa
mraa_result_t
mraa_add_from_lockfile(const char* imraa_lock_file)
{
    mraa_result_t ret = MRAA_SUCCESS;
    char* buffer = NULL;
    struct stat st;
    int i = 0;
    uint32_t subplat_num = 0;
    int flock = open(imraa_lock_file, O_RDONLY);
    if (flock == -1) {
        syslog(LOG_ERR, "imraa: Failed to open lock file");
        return MRAA_ERROR_INVALID_RESOURCE;
    }
    if (fstat(flock, &st) != 0 || (!S_ISREG(st.st_mode))) {
        close(flock);
        return MRAA_ERROR_INVALID_RESOURCE;
    }
    buffer = mmap(0, st.st_size, PROT_READ, MAP_SHARED, flock, 0);
    close(flock);
    if (buffer == MAP_FAILED) {
        syslog(LOG_ERR, "imraa: lockfile read error");
        return MRAA_ERROR_INVALID_RESOURCE;
    }
    json_object* jobj_lock = json_tokener_parse(buffer);

    struct json_object* ioarray;
    if (json_object_object_get_ex(jobj_lock, "Platform", &ioarray) == true &&
        json_object_is_type(ioarray, json_type_array)) {
        subplat_num = json_object_array_length(ioarray);
        int id = -1;
        const char* uartdev = NULL;
        for (i = 0; i < subplat_num; i++) {
            struct json_object *ioobj = json_object_array_get_idx(ioarray, i);
            json_object_object_foreach(ioobj, key, val) {
                if (strcmp(key, "id") == 0) {
                    id = atoi(json_object_get_string(val));
                } else if (strcmp(key, "uart") == 0) {
                    uartdev = json_object_get_string(val);
                }
            }
            if (id != -1 && id != MRAA_NULL_PLATFORM && id != MRAA_UNKNOWN_PLATFORM && uartdev != NULL) {
                if (mraa_add_subplatform(id, uartdev) == MRAA_SUCCESS) {
                    syslog(LOG_NOTICE, "imraa: automatically added subplatform %d, %s", id, uartdev);
                } else {
                    syslog(LOG_ERR, "imraa: Failed to add subplatform (%d on %s) from lockfile", id, uartdev);
                }
                id = -1;
                uartdev = NULL;
            }
        }
        if (json_object_object_get_ex(jobj_lock, "IO", &ioarray) == true &&
            json_object_is_type(ioarray, json_type_array)) {
	    /* assume we have declared IO so we are preinitialised and wipe the
	     * advance func array
             */
            memset(plat->adv_func, 0, sizeof(mraa_adv_func_t));
        }
    }
Exemplo n.º 8
0
static int
extract_field_values(string_list *values, json_object *obj,
                     const string_list *field_path, int value_type)
{
    string_list_item *item = NULL;
    char string_value[MAX_INT_STR_LEN];
    struct array_list *list_val = NULL;
    json_object *val = NULL;
    int i, integer_value, boolean_value;
    int status = U1DB_OK;
    val = obj;
    if (val == NULL)
        goto finish;
    for (item = field_path->head; item != NULL; item = item->next)
    {
        val = json_object_object_get(val, item->data);
        if (val == NULL)
            goto finish;
    }
    if (json_object_is_type(val, json_type_string) && value_type ==
            json_type_string) {
        if ((status = append(values, json_object_get_string(val))) != U1DB_OK)
            goto finish;
    } else if (json_object_is_type(val, json_type_int) && value_type ==
            json_type_int) {
        integer_value = json_object_get_int(val);
        snprintf(string_value, MAX_INT_STR_LEN, "%d", integer_value);
        if (status != U1DB_OK)
            goto finish;
        if ((status = append(values, string_value)) != U1DB_OK)
            goto finish;
    } else if (json_object_is_type(val, json_type_boolean) &&
               value_type == json_type_boolean) {
        boolean_value = json_object_get_boolean(val);
        if (boolean_value) {
            status = append(values, "1");
            if (status != U1DB_OK)
                goto finish;
        } else {
            status = append(values, "0");
            if (status != U1DB_OK)
                goto finish;
        }
    } else if (json_object_is_type(val, json_type_array)) {
        // TODO: recursively check the types
        list_val = json_object_get_array(val);
        for (i = 0; i < list_val->length; i++)
        {
            if ((status = append(values, json_object_get_string(
                                array_list_get_idx(
                                    list_val, i)))) != U1DB_OK)
                goto finish;
        }
    }
finish:
    return status;
}
Exemplo n.º 9
0
static gboolean
update_brush_setting_from_json_object(MyPaintBrush *self,
                                      char *setting_name,
                                      json_object *setting_obj)
{
    MyPaintBrushSetting setting_id = mypaint_brush_setting_from_cname(setting_name);

    if (!(setting_id >= 0 && setting_id < MYPAINT_BRUSH_SETTINGS_COUNT)) {
        fprintf(stderr, "Warning: Unknown setting_id: %d for setting: %s\n",
                setting_id, setting_name);
        return FALSE;
    }

    if (!json_object_is_type(setting_obj, json_type_object)) {
        fprintf(stderr, "Warning: Wrong type for setting: %s\n", setting_name);
        return FALSE;
    }

    // Base value
    json_object *base_value_obj = NULL;
    if (! obj_get(setting_obj, "base_value", &base_value_obj)) {
        fprintf(stderr, "Warning: No 'base_value' field for setting: %s\n", setting_name);
        return FALSE;
    }
    const double base_value = json_object_get_double(base_value_obj);
    mypaint_brush_set_base_value(self, setting_id, base_value);

    // Inputs
    json_object *inputs = NULL;
    if (! obj_get(setting_obj, "inputs", &inputs)) {
        fprintf(stderr, "Warning: No 'inputs' field for setting: %s\n", setting_name);
        return FALSE;
    }
    json_object_object_foreach(inputs, input_name, input_obj) {
        MyPaintBrushInput input_id = mypaint_brush_input_from_cname(input_name);

        if (!json_object_is_type(input_obj, json_type_array)) {
            fprintf(stderr, "Warning: Wrong inputs type for setting: %s\n", setting_name);
            return FALSE;
        }

        const int number_of_mapping_points = json_object_array_length(input_obj);

        mypaint_brush_set_mapping_n(self, setting_id, input_id, number_of_mapping_points);

        for (int i=0; i<number_of_mapping_points; i++) {
            json_object *mapping_point = json_object_array_get_idx(input_obj, i);

            json_object *x_obj = json_object_array_get_idx(mapping_point, 0);
            const float x = json_object_get_double(x_obj);
            json_object *y_obj = json_object_array_get_idx(mapping_point, 1);
            const float y = json_object_get_double(y_obj);

            mypaint_brush_set_mapping_point(self, setting_id, input_id, i, x, y);
        }
    }
Exemplo n.º 10
0
int pv_get_json (struct sip_msg* msg,  pv_param_t* pvp, pv_value_t* val)
{

	pv_json_t * var ;
	json_t * obj;
	json_name * id = (json_name *) pvp->pvn.u.dname;
	UNUSED(id);


	if( expand_tag_list( msg, ((json_name *)pvp->pvn.u.dname)->tags ) < 0)
	{
		LM_ERR("Cannot expand variables in path\n");
		return pv_get_null( msg, pvp, val);
	}


	var = get_pv_json(pvp);

	if( var == NULL )
	{
		/* this is not an error - we simply came across a json spec
		 * pointing a json var which was never set/init */
		LM_DBG("Variable named:%.*s not found\n",id->name.len,id->name.s);
		return pv_get_null( msg, pvp, val);
	}

	obj = get_object(var, pvp, NULL, 0);
	memset(val, 0, sizeof(pv_value_t));

	if( obj == NULL )
		return pv_get_null( msg, pvp, val);

	if( json_object_is_type(obj, json_type_int) )
	{
		val->rs.s = sint2str(json_object_get_int(obj), &val->rs.len);
		val->ri = json_object_get_int(obj);;
		val->flags |= PV_VAL_INT|PV_TYPE_INT|PV_VAL_STR;

	}
	else if( json_object_is_type(obj, json_type_string))
	{
		val->flags = PV_VAL_STR;
		val->rs.s = (char*)json_object_get_string( obj );
#if JSON_LIB_VERSION >= 10
		val->rs.len = json_object_get_string_len( obj );
#else
		val->rs.len = strlen(val->rs.s);
#endif
	} else {
		val->flags = PV_VAL_STR;
		val->rs.s = (char*)json_object_to_json_string( obj );
		val->rs.len = strlen(val->rs.s);
	}

	return 0;
}
Exemplo n.º 11
0
static gboolean xr_call_unserialize_response_json(xr_call* call, const char* buf, int len)
{
    struct json_tokener* t;
    struct json_object* r;
    int i;

    t = json_tokener_new();
    r = json_tokener_parse_ex(t, (char*)buf, len);
    json_tokener_free(t);

    if (r == NULL)
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Invalid JSON object.");
        return FALSE;
    }

    struct json_object* error = json_object_object_get(r, "error");
    if (error && !json_object_is_type(error, json_type_null))
    {
        if (json_object_is_type(error, json_type_object))
        {
            struct json_object* code = json_object_object_get(error, "code");
            struct json_object* message = json_object_object_get(error, "message");
            if (code && message && json_object_is_type(code, json_type_int) && json_object_is_type(message, json_type_string))
                xr_call_set_error(call, json_object_get_int(code), "%s", json_object_get_string(message));
            else
                xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Invalid error object.");
        }
        else
            xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Invalid error object.");

        json_object_put(r);
        return FALSE;
    }

    struct json_object* result = json_object_object_get(r, "result");
    if (result == NULL || json_object_is_type(result, json_type_null))
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Null result.");
        json_object_put(r);
        return FALSE;
    }

    xr_value* v = _xr_value_unserialize_json(result);
    if (v == NULL)
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Invalid result.");
        json_object_put(r);
        return FALSE;
    }

    xr_call_set_retval(call, v);
    json_object_put(r);
    return TRUE;
}
Exemplo n.º 12
0
bool validateUSBButtonRowData(json_object* entries, const char* rowStr, bool curResult)
{
  bool result = curResult;

  int pos = 0;

  json_object* row = NULL;
  json_object* item = NULL;

  if (json_object_object_get_ex(entries, rowStr, &row))
  {
    if (!json_object_is_type(row, json_type_array))
    {
      log_err("'%s' needs to be of type array", rowStr);
      result = false;
    }
    else
    {
      if (json_object_array_length(row) != USBBTN_ROW_SIZE)
      {
        log_err("'%s' array size was %i, but needs to be %i",
                rowStr, json_object_array_length(row),
                USBBTN_ROW_SIZE);
        result = false;
      }
      else
      {
        for (pos = 0; pos < USBBTN_ROW_SIZE; ++pos)
        {
          item = json_object_array_get_idx(row, pos);

          if (!json_object_is_type(item, json_type_string))
          {
            log_err("'%s' 'index %i' needs to be of type string",
                    rowStr, pos);
            result = false;
          }
        }
      }
    }
  }
  else
  {
    log_err("'%s' is not defined in the configuration",
            rowStr);
    result = false;
  }

  return result;
}
Exemplo n.º 13
0
boolean CJSONEntry::isInteger() const
{
    if ( isEmpty() )
        return false;

    return json_object_is_type(m_object, json_type_int) ? true : false;
}
Exemplo n.º 14
0
boolean CJSONEntry::isFloat() const
{
    if ( isEmpty() )
        return false;

    return json_object_is_type(m_object, json_type_double) ? true : false;
}
Exemplo n.º 15
0
json_object *cli_jsonobj(json_object *obj, const char *key)
{
    json_type objty;
    json_object *newobj;

    if (obj && key && json_object_object_get_ex(obj, key, &newobj))
        return json_object_is_type(newobj, json_type_object) ? newobj : NULL;

    newobj = json_object_new_object();
    if (!(newobj))
        return NULL;

    if (obj) {
        objty = json_object_get_type(obj);

        if (key && objty == json_type_object) {
            json_object_object_add(obj, key, newobj);
            if (!json_object_object_get_ex(obj, key, &newobj))
                return NULL;
        } else if (objty == json_type_array) {
            json_object_array_add(obj, newobj);
        }
    }

    return newobj;
}
Exemplo n.º 16
0
json_object *cli_jsonarray(json_object *obj, const char *key)
{
    json_type objty;
    json_object *newobj;

    /* First check to see if this key exists */
    if (obj && key && json_object_object_get_ex(obj, key, &newobj)) {
        return json_object_is_type(newobj, json_type_array) ? newobj : NULL;
    }

    newobj = json_object_new_array();
    if (!(newobj))
        return NULL;

    if (obj) {
        objty = json_object_get_type(obj);

        if (key && objty == json_type_object) {
            json_object_object_add(obj, key, newobj);
            if (!json_object_object_get_ex(obj, key, &newobj))
                return NULL;
        } else if (objty == json_type_array) {
            json_object_array_add(obj, newobj);
        }
    }

    return newobj;
}
Exemplo n.º 17
0
boolean CJSONEntry::isBoolean() const
{
    if ( isEmpty() )
        return false;
    
    return json_object_is_type(m_object, json_type_boolean) ? true : false;
}
Exemplo n.º 18
0
bool OGRCouchDBDataSource::IsError(json_object* poAnswerObj,
                                  const char* pszErrorMsg)
{
    if ( poAnswerObj == NULL ||
        !json_object_is_type(poAnswerObj, json_type_object) )
    {
        return false;
    }

    json_object* poError = CPL_json_object_object_get(poAnswerObj, "error");
    json_object* poReason = CPL_json_object_object_get(poAnswerObj, "reason");

    const char* pszError = json_object_get_string(poError);
    const char* pszReason = json_object_get_string(poReason);
    if (pszError != NULL)
    {
        CPLError(CE_Failure, CPLE_AppDefined,
                 "%s : %s, %s",
                 pszErrorMsg,
                 pszError,
                 pszReason ? pszReason : "");

        return true;
    }

    return false;
}
Exemplo n.º 19
0
struct json_object *
pubnub_decrypt_array(const char *cipher_key, struct json_object *message_list)
{
	int msg_n = json_object_array_length(message_list);
	struct json_object *newlist = json_object_new_array();

	for (int i = 0; i < msg_n; i++) {
		struct json_object *msg = json_object_array_get_idx(message_list, i);
		if (!json_object_is_type(msg, json_type_string)) {
			DBGMSG("decrypt fail: message not a string\n");
error:
			/* Format error. This is a most stringent approach. */
			json_object_put(newlist);
			return NULL;
		}

		DBGMSG("decrypting %s\n", json_object_get_string(msg));
		struct json_object *newmsg = pubnub_decrypt(cipher_key, json_object_get_string(msg));
		if (!newmsg) {
			DBGMSG("decrypt fail: message cannot be decrypted\n");
			goto error;
		}

		json_object_array_add(newlist, newmsg);
	}

	return newlist;
}
Exemplo n.º 20
0
mraa_result_t
mraa_init_json_platform_size_check(json_object* jobj_platform,
                                   const char* obj_key,
                                   mraa_board_t* board,
                                   init_plat_func_t func,
                                   int range)
{
    json_object* jobj_temp = NULL;
    mraa_result_t ret = MRAA_SUCCESS;
    int array_length = 0;
    if (json_object_object_get_ex(jobj_platform, obj_key, &jobj_temp)) {
        // Make sure the value for the key is an array
        if (!json_object_is_type(jobj_temp, json_type_array)) {
            syslog(LOG_ERR, "init_json_platform: json key \"%s\" should be an array", obj_key);
            return MRAA_ERROR_INVALID_RESOURCE;
        }
        // make sure we don't have more than our range
        array_length = json_object_array_length(jobj_temp);
        if (array_length > range) {
            syslog(LOG_ERR,
                   "init_json_platform: The size of the %s array given was %d, max was: %d",
                   obj_key, array_length, range);
            return MRAA_ERROR_INVALID_RESOURCE;
        }
        ret = mraa_init_json_platform_loop(jobj_platform, obj_key, board, func);
        if (ret != MRAA_SUCCESS) {
            return ret;
        }
        return MRAA_SUCCESS;
    }
    syslog(LOG_NOTICE, "init_json_platform: %s wasn't found in the json file", obj_key);
    return MRAA_ERROR_NO_DATA_AVAILABLE;
}
Exemplo n.º 21
0
mraa_result_t
mraa_init_json_platform_loop(json_object* jobj_platform, const char* obj_key, mraa_board_t* board, init_plat_func_t func)
{
    mraa_result_t ret = MRAA_SUCCESS;
    int i = 0, array_length = 0;
    json_object *jobj_temp = NULL, *jobj_io = NULL;
    if (json_object_object_get_ex(jobj_platform, obj_key, &jobj_temp)) {
        array_length = json_object_array_length(jobj_temp);
        for (i = 0; i < array_length; i++) {
            // Get the json object at position i
            jobj_io = json_object_array_get_idx(jobj_temp, i);
            // Check to see it's the right type
            if (!json_object_is_type(jobj_io, json_type_object)) {
                syslog(LOG_ERR, "init_json_platform: One of more of the elements in the \"%s\" "
                                "array where not JSON objects",
                       obj_key);
                return MRAA_ERROR_INVALID_RESOURCE;
            }
            ret = (*func)(jobj_io, board, i);
            if (ret != MRAA_SUCCESS) {
                return ret;
            }
        }
    } else {
        syslog(LOG_ERR, "init_json_platform: No \"%s\" info found in json file", obj_key);
        ret = MRAA_ERROR_NO_DATA_AVAILABLE;
    }
    return ret;
}
Exemplo n.º 22
0
static int json_pointer_get_single_path(struct json_object *obj, char *path, struct json_object **value)
{
	if (json_object_is_type(obj, json_type_array)) {
		int32_t idx;
		if (!is_valid_index(obj, path, &idx))
			return -1;
		obj = json_object_array_get_idx(obj, idx);
		if (obj) {
			if (value)
				*value = obj;
			return 0;
		}
		/* Entry not found */
		errno = ENOENT;
		return -1;
	}

	/* RFC states that we first must eval all ~1 then all ~0 */
	string_replace_all_occurrences_with_char(path, "~1", '/');
	string_replace_all_occurrences_with_char(path, "~0", '~');

	if (!json_object_object_get_ex(obj, path, value)) {
		errno = ENOENT;
		return -1;
	}

	return 0;
}
/**
 * Given a JSON object representing an OpenStack service endpoint, return its URL of the given type, if any.
 * If the service endpoint has no URL
 */
static const char *
endpoint_url(keystone_context_t *context, struct json_object *endpoint, enum openstack_service_endpoint_url_type endpoint_url_type)
{
	struct json_object *endpoint_public_url;
	const char *url_val;
	const char *url_type_name;

	assert(context != NULL);
	assert(endpoint != NULL);
	assert(endpoint_url_type < ELEMENTSOF(openstack_service_endpoint_url_type_names));
	assert(openstack_service_endpoint_url_type_names[(unsigned int) endpoint_url_type] != NULL);

	url_type_name = openstack_service_endpoint_url_type_names[(unsigned int) endpoint_url_type];

	if (json_object_object_get_ex(endpoint, url_type_name, &endpoint_public_url)) {
		if (json_object_is_type(endpoint_public_url, json_type_string)) {
			url_val = json_object_get_string(endpoint_public_url);
		} else {
			context->keystone_error("response.access.serviceCatalog[n].endpoints[n] URL is not a string", KSERR_PARSE);
			url_val = NULL;
		}
	} else {
		context->keystone_error("response.access.serviceCatalog[n].endpoints[n] lacks a URL key of the requested type", KSERR_PARSE);
		url_val = NULL;
	}

	return url_val;
}
Exemplo n.º 24
0
std::map<std::string, std::vector<std::string>> newsblur_api::mk_feeds_to_tags(
json_object * folders)
{
	std::map<std::string, std::vector<std::string>> result;
	array_list * tags = json_object_get_array(folders);
	int tags_len = array_list_length(tags);
	for (int i = 0; i < tags_len; ++i) {
		json_object * tag_to_feed_ids = json_object_array_get_idx(folders, i);

		if (!json_object_is_type(tag_to_feed_ids, json_type_object))
			// "folders" array contains not only dictionaries describing
			// folders but also numbers, which are IDs of feeds that don't
			// belong to any folder. This check skips these IDs.
			continue;

		json_object_object_foreach(tag_to_feed_ids, key, feeds_with_tag_obj) {
			std::string std_key(key);
			array_list * feeds_with_tag_arr = json_object_get_array(feeds_with_tag_obj);
			int feeds_with_tag_len = array_list_length(feeds_with_tag_arr);
			for (int j = 0; j < feeds_with_tag_len; ++j) {
				json_object * feed_id_obj = json_object_array_get_idx(feeds_with_tag_obj, j);
				std::string feed_id(json_object_get_string(feed_id_obj));
				result[feed_id].push_back(std_key);
			}
		}
	}
Exemplo n.º 25
0
boolean CJSONEntry::isNull() const
{
    if ( isEmpty() )
        return true;

    return json_object_is_type(m_object, json_type_null) ? true : false;
}
Exemplo n.º 26
0
static inline int
ln_addTags_Syslog(struct json_object *taglist, es_str_t **str)
{
    int r = 0;
    struct json_object *tagObj;
    int needComma = 0;
    const char *tagCstr;
    int i;

    assert(json_object_is_type(taglist, json_type_array));

    CHKR(es_addBuf(str, " event.tags=\"", 13));
    for (i = json_object_array_length(taglist) - 1; i >= 0; i--) {
        if(needComma)
            es_addChar(str, ',');
        else
            needComma = 1;
        CHKN(tagObj = json_object_array_get_idx(taglist, i));
        CHKN(tagCstr = json_object_get_string(tagObj));
        CHKR(es_addBuf(str, (char*)tagCstr, strlen(tagCstr)));
    }
    es_addChar(str, '"');

done:
    return r;
}
Exemplo n.º 27
0
boolean CJSONEntry::isObject()
{
    if ( isEmpty() )
        return false;

    return json_object_is_type(m_object, json_type_object) ? true : false;
}
Exemplo n.º 28
0
int
ln_fmtEventToRFC5424(struct json_object *json, es_str_t **str)
{
    int r = -1;
    struct json_object *tags;

    assert(json != NULL);
    assert(json_object_is_type(json, json_type_object));
    if((*str = es_newStr(256)) == NULL)
        goto done;

    es_addBuf(str, "[cee@115", 8);

    if(json_object_object_get_ex(json, "event.tags", &tags)) {
        CHKR(ln_addTags_Syslog(tags, str));
    }
    struct json_object_iterator it = json_object_iter_begin(json);
    struct json_object_iterator itEnd = json_object_iter_end(json);
    while (!json_object_iter_equal(&it, &itEnd)) {
        char *const name = (char*)json_object_iter_peek_name(&it);
        if (strcmp(name, "event.tags")) {
            es_addChar(str, ' ');
            ln_addField_Syslog(name, json_object_iter_peek_value(&it), str);
        }
        json_object_iter_next(&it);
    }
    es_addChar(str, ']');

done:
    return r;
}
Exemplo n.º 29
0
bool OGRCouchDBDataSource::IsOK(json_object* poAnswerObj,
                                const char* pszErrorMsg)
{
    if ( poAnswerObj == NULL ||
        !json_object_is_type(poAnswerObj, json_type_object) )
    {
        CPLError(CE_Failure, CPLE_AppDefined, "%s",
                 pszErrorMsg);

        return false;
    }

    json_object* poOK = CPL_json_object_object_get(poAnswerObj, "ok");
    if ( !poOK )
    {
        IsError(poAnswerObj, pszErrorMsg);

        return false;
    }

    const char* pszOK = json_object_get_string(poOK);
    if ( !pszOK || !CPLTestBool(pszOK) )
    {
        CPLError(CE_Failure, CPLE_AppDefined, "%s", pszErrorMsg);

        return false;
    }

    return true;
}
Exemplo n.º 30
0
static int
evaluate_index_and_insert_into_db(void *context, const char *expression,
                                  transformation *tr)
{
    struct evaluate_index_context *ctx;
    string_list *values = NULL;
    string_list_item *item = NULL;
    int status = U1DB_OK;

    ctx = (struct evaluate_index_context *)context;
    if (ctx->obj == NULL || !json_object_is_type(ctx->obj, json_type_object)) {
        return U1DB_INVALID_JSON;
    }
    if (status != U1DB_OK)
        goto finish;
    if (status != U1DB_OK)
        goto finish;
    if ((status = init_list(&values)) != U1DB_OK)
        goto finish;
    status = apply_transformation(tr, ctx->obj, values);
    for (item = values->head; item != NULL; item = item->next)
    {
        if ((status = add_to_document_fields(ctx->db, ctx->doc_id, expression,
                        item->data)) != U1DB_OK)
            goto finish;
    }
finish:
    destroy_list(values);
    return status;
}