Пример #1
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;
}
Пример #2
0
int main (void)
{
	json_t *root, *value, *persona;
	json_error_t err;
	const char *key;
	void *iter;

	root = json_load_file("prueba.json", 0, &err);
	if (root == NULL) {
		perror("Error: ");
		fprintf(stderr, "Jansson error: %s %d %d\n", err.text,
			err.column, err.line);
		return EXIT_FAILURE;
	}

	persona = json_object_get(root, "persona");
	if (persona == NULL)
		return EXIT_FAILURE;

	iter = json_object_iter(persona);
	while (iter) {
		key = json_object_iter_key(iter);
		value = json_object_iter_value(iter);
		printf ("key del objeto %s\n", key);
		iter = json_object_iter_next(persona, iter);
	}

	json_decref(root);
	return EXIT_SUCCESS;
}
Пример #3
0
/** Parse the exception information from JSON */
static struct jsonException *parseJsonException(json_t *jobj)
{
    const char *key = NULL;
    json_t *value = NULL;
    struct jsonException *exception = NULL;
    void *iter = NULL;
    
    exception = calloc(1, sizeof(*exception));
    if (!exception) {
        return NULL;
    }
    
    iter = json_object_iter(jobj);
    while (iter) {
        key = json_object_iter_key(iter);
        value = json_object_iter_value(iter);
        
        if (!strcmp(key, "exception")) {
            exception->exception = json_string_value(value);
        } else if (!strcmp(key, "javaClassName")) {
            exception->javaClassName = json_string_value(value);
        } else if (!strcmp(key, "message")) {
            exception->message = json_string_value(value);
        }
        
        iter = json_object_iter_next(jobj, iter);
    }
    return exception;
}
Пример #4
0
/** 
 * Parse the exception information which is presented in JSON
 * 
 * @param content   Exception information in JSON
 * @return          jsonException for printing out
 */
static struct jsonException *parseException(const char *content)
{
    json_error_t error;
    size_t flags = 0;
    const char *key = NULL;
    json_t *value;
    json_t *jobj;
    struct jsonException *exception = NULL;
    
    if (!content) {
        return NULL;
    }
    jobj = json_loads(content, flags, &error);
    if (!jobj) {
        fprintf(stderr, "JSon parsing error: on line %d: %s\n",
                error.line, error.text);
        return NULL;
    }
    void *iter = json_object_iter(jobj);
    while(iter)  {
        key = json_object_iter_key(iter);
        value = json_object_iter_value(iter);
        
        if (!strcmp(key, "RemoteException") &&
                    json_typeof(value) == JSON_OBJECT) {
            exception = parseJsonException(value);
            break;
        }
        iter = json_object_iter_next(jobj, iter);
    }
    
    json_decref(jobj);
    return exception;
}
Пример #5
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;
}
Пример #6
0
/**
 * Checks a JSON object contains only allowed keys
 *
 * @param obj JSON object
 * @param allowed_keys A NULL-terminated string array with the allowed keys
 * @param obsolete_keys A NULL-terminated string array with the obsolete_keys
 */
static int check_allowed_keys(json_t* obj, const char* allowed_keys[], const char* obsolete_keys[])
{
    /* obj is a JSON object */
  const char *key = NULL;
  void *iter = json_object_iter(obj);
  const char **allowed = NULL;
  int found = FALSE;
  while(iter) {
    key = json_object_iter_key(iter);
    found = FALSE;
    for (allowed = allowed_keys; allowed && *allowed; allowed++) {
      if (strcmp(*allowed, key) == 0) {
        found = TRUE;
        break;
      }
    }
    for (allowed = obsolete_keys; allowed && *allowed; allowed++) {
      if (strcmp(*allowed, key) == 0) {
        tr_warning("Configuration option [%s] is obsolete!", key);
        found = TRUE;
        break;
      }
    }
    if (!found) {
      tr_err("Invalid configuration item found: %s", key);
      return FALSE;
    }
    iter = json_object_iter_next(obj, iter);
  }
  return TRUE;
}
Пример #7
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;
}
Пример #8
0
static json_t *object_data_to_json(const json_t *typedesc, const qeocore_data_t *data)
{
    json_t  *json_data  = NULL;
    json_t  *properties = json_object_get(typedesc, KEY_PROPERTIES);

    if ((NULL != properties) && (json_is_object(properties))) {
        json_data = json_object();
        const char  *prop_name  = NULL;
        json_t      *prop_value = NULL;
        void        *iter       = json_object_iter(properties);
        while (iter) {
            // Get type name and value
            prop_name   = json_object_iter_key(iter);
            prop_value  = json_object_iter_value(iter);

            json_t *value = member_data_to_json(prop_value, data);
            if (NULL != value) {
                json_object_set_new(json_data, prop_name, value);
            }
            else {
                json_decref(json_data);
                json_data = NULL;
                break;
            }

            iter = json_object_iter_next(properties, iter);
        }
    }
    return json_data;
}
Пример #9
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);
}
Пример #10
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");
}
Пример #11
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;

}
Пример #12
0
Value NDKHelper::getValueFromJson(json_t *obj)
{
    if (obj == NULL) {
        return Value::Null;
    }

    if (json_is_object(obj)) {
        ValueMap valueMap;

        const char *key;
        json_t *value;

        void *iter = json_object_iter(obj);
        while (iter) {
            key = json_object_iter_key(iter);
            value = json_object_iter_value(iter);

            valueMap[key] = NDKHelper::getValueFromJson(value);

            iter = json_object_iter_next(obj, iter);
        }

        return Value(valueMap);
    } else if (json_is_array(obj)) {
        ValueVector valueVector;

        size_t sizeArray = json_array_size(obj);

        for (unsigned int i = 0; i < sizeArray; i++) {
            valueVector.push_back(NDKHelper::getValueFromJson(json_array_get(obj, i)));
        }

        return Value(valueVector);
    } else if (json_is_boolean(obj)) {
        if (json_is_true(obj)) {
            return Value(true);
        } else {
            return Value(false);
        }
    } else if (json_is_integer(obj)) {
        int value = (int) json_integer_value(obj);

        return Value(value);
    } else if (json_is_real(obj)) {
        double value = json_real_value(obj);

        return Value(value);
    } else if (json_is_string(obj)) {
        std::string value = json_string_value(obj);

        return Value(value);
    }

    return Value::Null;
}
Пример #13
0
/**
 * Retrieve file status from the JSON object 
 *
 * @param jobj          JSON object for parsing, which contains 
 *                      file status information
 * @param fileStat      hdfsFileInfo handle to hold file status information
 * @return 0 on success
 */
static int parseJsonForFileStatus(json_t *jobj, hdfsFileInfo *fileStat)
{
    const char *key, *tempstr;
    json_t *value;
    void *iter = NULL;
    
    iter = json_object_iter(jobj);
    while (iter) {
        key = json_object_iter_key(iter);
        value = json_object_iter_value(iter);
        
        if (!strcmp(key, "accessTime")) {
            // json field contains time in milliseconds,
            // hdfsFileInfo is counted in seconds
            fileStat->mLastAccess = json_integer_value(value) / 1000;
        } else if (!strcmp(key, "blockSize")) {
            fileStat->mBlockSize = json_integer_value(value);
        } else if (!strcmp(key, "length")) {
            fileStat->mSize = json_integer_value(value);
        } else if (!strcmp(key, "modificationTime")) {
            fileStat->mLastMod = json_integer_value(value) / 1000;
        } else if (!strcmp(key, "replication")) {
            fileStat->mReplication = json_integer_value(value);
        } else if (!strcmp(key, "group")) {
            fileStat->mGroup = strdup(json_string_value(value));
            if (!fileStat->mGroup) {
                return ENOMEM;
            }
        } else if (!strcmp(key, "owner")) {
            fileStat->mOwner = strdup(json_string_value(value));
            if (!fileStat->mOwner) {
                return ENOMEM;
            }
        } else if (!strcmp(key, "pathSuffix")) {
            fileStat->mName = strdup(json_string_value(value));
            if (!fileStat->mName) {
                return ENOMEM;
            }
        } else if (!strcmp(key, "permission")) {
            tempstr = json_string_value(value);
            fileStat->mPermissions = (short) strtol(tempstr, NULL, 8);
        } else if (!strcmp(key, "type")) {
            tempstr = json_string_value(value);
            if (!strcmp(tempstr, "DIRECTORY")) {
                fileStat->mKind = kObjectKindDirectory;
            } else {
                fileStat->mKind = kObjectKindFile;
            }
        }
        // Go to the next key-value pair in the json object
        iter = json_object_iter_next(jobj, iter);
    }
    return 0;
}
Пример #14
0
struct samba3_user *getsamba3users(void) {
	
	struct samba3_user *list, *current;
	int count, entry_count;
	json_t *json;
    	json_error_t error;
	const char *key;
	json_t *iterator, *entry, *value;
	char username[64],password[64];
	int type;

	// first create dummy entry
	list = getsamba3user("", "", 0);
	current = list;
	
	//json = json_loads( "[{\"user\":\"peter\",\"pass\":\"test\"},{\"user\":\"chris\",\"pass\":\"test\"}]", &error );
	json = json_loads( nvram_default_get( "samba3_users", "[]"), 0, &error);
	if( !json ) {
		fprintf( stderr, "[JASON] ERROR\n");
	} else {
		entry_count = json_array_size(json);
		for( count = 0; count < entry_count; count++ ) {
			entry = json_array_get( json, count );
			iterator = json_object_iter(entry);

			// reset
			username[0] = 0;
			password[0] = 0;
				
			while(iterator)
			{
				key = json_object_iter_key(iterator);
				value = json_object_iter_value(iterator);
				/* use key and value ... */
				if( !strcmp( key, "user" ) ) {
					strncpy( username, json_string_value( value ),sizeof(username)-1);
				} else if( !strcmp( key, "pass" ) ) {
					strncpy( password, json_string_value( value ),sizeof(password)-1);
				} else if( !strcmp( key, "type" ) ) {
					type = json_integer_value( value );
				}
				iterator = json_object_iter_next(entry, iterator);
			}
			if( username[0] != 0 ) {
				current->next = getsamba3user(username, password, type);
				current = current->next;
			}
		}
	json_array_clear(json);		
	}
		
	return list;
}
		AlgorithmConfig jsonToAlgorithmConfig(/*const*/ json_t* jsonAlgorithmConfig) const {
			JanssonUtil::assertJsonType(jsonAlgorithmConfig, JSON_OBJECT);
			std::map<std::string,std::string> params;
			void* iter = json_object_iter(jsonAlgorithmConfig); // can't have const because of this call
			while (iter) {
				std::string name = std::string(json_object_iter_key(iter));
				std::string val = fromJsonString(json_object_iter_value(iter));
				params[name]=val;
				iter = json_object_iter_next(jsonAlgorithmConfig,iter);
			}
			return AlgorithmConfig(params);
		}
Пример #16
0
/*
 * see if a the Require value matches with a set of provided claims
 */
static apr_byte_t oidc_authz_match_claim(request_rec *r,
		const char * const attr_spec, const json_t * const claims) {

	const char *key;
	json_t *val;

	/* if we don't have any claims, they can never match any Require claim primitive */
	if (claims == NULL)
		return FALSE;

	/* loop over all of the user claims */
	void *iter = json_object_iter((json_t*) claims);
	while (iter) {

		key = json_object_iter_key(iter);
		val = json_object_iter_value(iter);

		oidc_debug(r, "evaluating key \"%s\"", (const char * ) key);

		const char *attr_c = (const char *) key;
		const char *spec_c = attr_spec;

		/* walk both strings until we get to the end of either or we find a differing character */
		while ((*attr_c) && (*spec_c) && (*attr_c) == (*spec_c)) {
			attr_c++;
			spec_c++;
		}

		/* The match is a success if we walked the whole claim name and the attr_spec is at a colon. */
		if (!(*attr_c) && (*spec_c) == ':') {

			/* skip the colon */
			spec_c++;

			if (oidc_authz_match_value(r, spec_c, val, key) == TRUE)
				return TRUE;

			/* a tilde denotes a string PCRE match */
		} else if (!(*attr_c) && (*spec_c) == '~') {

			/* skip the tilde */
			spec_c++;

			if (oidc_authz_match_expression(r, spec_c, val) == TRUE)
				return TRUE;
		}

		iter = json_object_iter_next((json_t *) claims, iter);
	}

	return FALSE;
}
Пример #17
0
int parseGFS(const char *response, hdfsFileInfo *fileStat, int printError)
{
    int ret = 0, printFlag;
    json_error_t error;
    size_t flags = 0;
    json_t *jobj, *value;
    const char *key;
    void *iter = NULL;
    
    if (!response || !fileStat) {
        return EIO;
    }
    jobj = json_loads(response, flags, &error);
    if (!jobj) {
        fprintf(stderr, "error while parsing json: on line %d: %s\n",
                error.line, error.text);
        return EIO;
    }
    iter = json_object_iter(jobj);
    key = json_object_iter_key(iter);
    value = json_object_iter_value(iter);
    if (json_typeof(value) == JSON_OBJECT) {
        if (!strcmp(key, "RemoteException")) {
            struct jsonException *exception = parseJsonException(value);
            if (exception) {
                if (printError) {
                    printFlag = PRINT_EXC_ALL;
                } else {
                    printFlag = NOPRINT_EXC_FILE_NOT_FOUND |
                                NOPRINT_EXC_ACCESS_CONTROL |
                                NOPRINT_EXC_PARENT_NOT_DIRECTORY;
                }
                ret = printJsonException(exception, printFlag,
                                         "Calling WEBHDFS GETFILESTATUS");
            } else {
                ret = EIO;
            }
        } else if (!strcmp(key, "FileStatus")) {
            ret = parseJsonForFileStatus(value, fileStat);
        } else {
            ret = EIO;
        }
        
    } else {
        ret = EIO;
    }
    
    json_decref(jobj);
    return ret;
}
Пример #18
0
//## String[] Json.getKeys();
static KMETHOD Json_getKeys(KonohaContext *kctx, KonohaStack *sfp)
{
	json_t* obj = ((struct _kJson *)sfp[0].asObject)->obj;
	kArray *a = (kArray *)KLIB new_kObjectDontUseThis(kctx, CT_StringArray0, 0);
	CHECK_JSON(obj, KReturn(KNULL(Array)));
	const char* key;
	void* iter = json_object_iter(obj);
	while(iter) {
		key = json_object_iter_key(iter);
		iter = json_object_iter_next(obj, iter);
		KLIB kArray_add(kctx, a, KLIB new_kString(kctx, key, strlen(key), StringPolicy_POOL|StringPolicy_ASCII));
	}
	KReturn(a);
}
Пример #19
0
int parseLS(const char *response, hdfsFileInfo **fileStats, int *numOfEntries)
{
    int ret = 0;
    json_error_t error;
    size_t flags = 0;
    json_t *jobj, *value;
    const char *key;
    void *iter = NULL;
    
    if (!response || response[0] == '\0' || !fileStats) {
        return EIO;
    }
    jobj = json_loads(response, flags, &error);
    if (!jobj) {
        fprintf(stderr, "error while parsing json: on line %d: %s\n",
                error.line, error.text);
        return EIO;
    }
    
    iter = json_object_iter(jobj);
    key = json_object_iter_key(iter);
    value = json_object_iter_value(iter);
    if (json_typeof(value) == JSON_OBJECT) {
        if (!strcmp(key, "RemoteException")) {
            struct jsonException *exception = parseJsonException(value);
            if (exception) {
                ret = printJsonException(exception, PRINT_EXC_ALL,
                                         "Calling WEBHDFS GETFILESTATUS");
            } else {
                ret = EIO;
            }
        } else if (!strcmp(key, "FileStatuses")) {
            iter = json_object_iter(value);
            value = json_object_iter_value(iter);
            if (json_is_array(value)) {
                ret = parseJsonArrayForFileStatuses(value, fileStats,
                                                    numOfEntries);
            } else {
                ret = EIO;
            }
        } else {
            ret = EIO;
        }
    } else {
        ret = EIO;
    }
    
    json_decref(jobj);
    return ret;
}
Пример #20
0
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;
		}
	}
Пример #21
0
struct dlna_share *getdlnashares(void)
{

	struct dlna_share *list, *current;
	int count, entry_count;
	json_t *json;
	json_error_t error;
	const char *key;
	json_t *iterator, *entry, *value;
	char mp[64], types;

	// first create dummy entry
	list = getdlnashare("", 0);
	current = list;

//      json = json_loads( "[{\"mp\":\"/jffs\",\"label\":\"testshare\",\"perms\":\"rw\",\"public\":0},{\"mp\":\"/mnt\",\"label\":\"othertest\",\"perms\":\"ro\",\"public\":1},{\"label\":\"blah\"}]", &error );
	json = json_loads(nvram_default_get("dlna_shares", "[]"), 0, &error);
	if (!json) {
		fprintf(stderr, "[JASON] ERROR\n");
	} else {
		entry_count = json_array_size(json);
		for (count = 0; count < entry_count; count++) {
			entry = json_array_get(json, count);
			iterator = json_object_iter(entry);

			// reset
			mp[0] = 0;
			types = 0;

			while (iterator) {
				key = json_object_iter_key(iterator);
				value = json_object_iter_value(iterator);
				/* use key and value ... */
				if (!strcmp(key, "mp")) {
					strncpy(mp, json_string_value(value), sizeof(mp) - 1);
				} else if (!strcmp(key, "types")) {
					types = json_integer_value(value);
				}
				iterator = json_object_iter_next(entry, iterator);
			}
			if (mp[0] != 0) {
				current->next = getdlnashare(mp, types);
				current = current->next;
			}
		}
		json_array_clear(json);
	}
	return list;
}
Пример #22
0
const char *JSON::getObjectFirstKey()
{
    if (!_json)
    {
        return "";
    }

    void *iter = json_object_iter(_json);
    if (!iter)
    {
        return "";
    }

    return json_object_iter_key(iter);
}
Пример #23
0
const char *JSON::getObjectNextKey(const char *key)
{
    if (!_json)
    {
        return "";
    }

    void *iter = json_object_iter_next(_json, json_object_iter_at(_json, key));
    if (!iter)
    {
        return "";
    }

    return json_object_iter_key(iter);
}
Пример #24
0
//----------------------------------------------------------------//
void _jsonObjectToLua ( lua_State* L, json_t* json ) {

    assert ( json->type == JSON_OBJECT );

    lua_newtable ( L );

    void* iter = json_object_iter ( json );
    for ( ; iter; iter = json_object_iter_next ( json, iter )) {

        cc8* key = json_object_iter_key ( iter );
        json_t* value = json_object_iter_value ( iter );

        _jsonToLua ( L, value );
        lua_setfield ( L, -2, key );
    }
}
Пример #25
0
static size_t DoJsonEach(KonohaContext *kctx, struct JsonBuf *jsonbuf, void *thunk, void (*doEach)(KonohaContext *, const char *, struct JsonBuf *, void *))
{
	size_t count = 0;
	struct JsonBuf eachbuf = {};
	void *iter = json_object_iter(jsonbuf->jsonobj);
	while(iter != NULL) {
		const char *key = json_object_iter_key(iter);
		json_t *value   = json_object_iter_value(iter);
		SetJsonBuf(&eachbuf, value);
		doEach(kctx, key, &eachbuf, thunk);
		count++;
		iter = json_object_iter_next(jsonbuf->jsonobj, iter);
	}
	FreeJson(kctx, &eachbuf);
	return count;
}
Пример #26
0
ScriptProps::ScriptProps(Script& script, json_t* detail, const vector<string>& spec_props)
	throw(Exception):
	EnumExpandable(script, detail, spec_props)
{
	if (!finished()) return;

	json_t* after_enum_expand = EnumExpandable::expand_context;
	void* it = json_object_iter(after_enum_expand);
	while ( it) {
		const char* pnm = json_object_iter_key(it);
		json_t* v = json_object_iter_value(it);
		Property* pobj = new Property(*this, pnm, v);
		props[pnm].reset(pobj);
		it = json_object_iter_next(after_enum_expand, it);
	}
}
Пример #27
0
void oidc_session_set_filtered_claims(request_rec *r, oidc_session_t *z,
		const char *session_key, const char *claims) {
	oidc_cfg *c = ap_get_module_config(r->server->module_config,
			&auth_openidc_module);

	const char *name;
	json_t *src = NULL, *dst = NULL, *value = NULL;
	void *iter = NULL;
	apr_byte_t is_allowed;

	if (oidc_util_decode_json_object(r, claims, &src) == FALSE)
		return;

	dst = json_object();
	iter = json_object_iter(src);
	while (iter) {
		is_allowed = TRUE;
		name = json_object_iter_key(iter);
		value = json_object_iter_value(iter);

		if ((c->black_listed_claims != NULL)
				&& (apr_hash_get(c->black_listed_claims, name,
						APR_HASH_KEY_STRING) != NULL)) {
			oidc_debug(r, "removing blacklisted claim [%s]: '%s'", session_key,
					name);
			is_allowed = FALSE;
		}

		if ((is_allowed == TRUE) && (c->white_listed_claims != NULL)
				&& (apr_hash_get(c->white_listed_claims, name,
						APR_HASH_KEY_STRING) == NULL)) {
			oidc_debug(r, "removing non-whitelisted claim [%s]: '%s'",
					session_key, name);
			is_allowed = FALSE;
		}

		if (is_allowed == TRUE)
			json_object_set(dst, name, value);

		iter = json_object_iter_next(src, iter);
	}

	char *filtered_claims = oidc_util_encode_json_object(r, dst, JSON_COMPACT);
	json_decref(dst);
	json_decref(src);
	oidc_session_set(r, z, session_key, filtered_claims);
}
Пример #28
0
symbols_t* drakvuf_get_symbols_from_rekall(const char *rekall_profile)
{

    symbols_t *ret = g_malloc0(sizeof(symbols_t));

    json_error_t error;
    json_t *root = json_load_file(rekall_profile, 0, &error);
    if (!root) {
        PRINT_DEBUG("Rekall profile error on line %d: %s\n", error.line, error.text);
        goto err_exit;
    }

    if (!json_is_object(root)) {
        PRINT_DEBUG("Rekall profile: root is not an objet\n");
        goto err_exit;
    }

    json_t *functions = json_object_get(root, "$FUNCTIONS");

    ret->count = json_object_size(functions);
    PRINT_DEBUG("The Rekall profile defines %lu functions\n", ret->count);

    ret->symbols = g_malloc0(sizeof(struct symbol) * ret->count);

    const char *key;
    json_t *value;
    void *iter = json_object_iter(functions);
    int i = 0;
    while (iter) {
        key = json_object_iter_key(iter);
        value = json_object_iter_value(iter);

        ret->symbols[i].name = strdup(key);
        ret->symbols[i].rva = json_integer_value(value);

        /* use key and value ... */
        iter = json_object_iter_next(functions, iter);
        i++;
    }

    return ret;

    err_exit: free(ret);
    return NULL;
}
Пример #29
0
ScriptProps::ScriptProps(Script& script, json_t* detail,
		const char* enum_apply_tag) throw (Exception):
	EnumExpandable(script, detail, enum_apply_tag)
{
	if ( !finished() ) {
		return;
	}

	json_t* after_enum_expand = EnumExpandable::expand_context;
	void* it = json_object_iter(after_enum_expand);
	while ( it) {
		const char* pnm = json_object_iter_key(it);
		json_t* v = json_object_iter_value(it);
		Property* pobj = new Property(*this, pnm, v);
		props.insert( make_pair(string(pnm), std::tr1::shared_ptr<Property>(pobj)) ) ;
		it = json_object_iter_next(after_enum_expand, it);
	}
}
Пример #30
0
void ScriptProps::expand_enum(const char* ename, const char* sname,
		const char* param_tag, const json_t* value) throw (Exception)
{
	EnumExpandable::expand_enum(ename,sname, param_tag, value);
	if ( !finished() ) {
		return;
	}

	json_t* after_enum_expand = EnumExpandable::expand_context;
	void* it = json_object_iter(after_enum_expand);
	while ( it) {
		const char* pnm = json_object_iter_key(it);
		json_t* v = json_object_iter_value(it);
		Property* pobj = new Property(*this, pnm, v);
		props.insert( make_pair(string(pnm), std::tr1::shared_ptr<Property>(pobj)) ) ;
		it = json_object_iter_next(after_enum_expand, it);
	}
}