Exemplo n.º 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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 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;
}
Exemplo n.º 5
0
//native Handle:json_object_iter_value(Handle:hIter, String:sValueBuffer[], maxlength);
static cell_t Native_json_object_iter_value(IPluginContext *pContext, const cell_t *params) {
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

	// Param 1
    void *iter;
	Handle_t hndlIterator = static_cast<Handle_t>(params[1]);
	if ((err=g_pHandleSys->ReadHandle(hndlIterator, htJanssonIterator, &sec, (void **)&iter)) != HandleError_None)
    {
        pContext->ThrowNativeError("Invalid <JSON Iterator> handle %x (error %d)", hndlIterator, err);
        return BAD_HANDLE;
    }

    json_t *result = json_object_iter_value(iter);

	// Return
	if(result == NULL) {
		return BAD_HANDLE;
	}

	Handle_t hndlResult = g_pHandleSys->CreateHandle(htJanssonObject, result, pContext->GetIdentity(), myself->GetIdentity(), NULL);
	if(hndlResult == BAD_HANDLE) {
		pContext->ThrowNativeError("Could not create handle for iterator element.");
		return BAD_HANDLE;
	}

	// result is a borrowed reference, we don't know what will happen with it
	// so we increase the reference counter, which enforces the developer to
	// CloseHandle() it.
	json_incref(result);

	return hndlResult;
}
Exemplo n.º 6
0
static json_t *OutputStats2Json(json_t *js, const char *key)
{
    void *iter;

    const char *dot = index(key, '.');
    if (dot == NULL)
        return NULL;

    size_t predot_len = (dot - key) + 1;
    char s[predot_len];
    strlcpy(s, key, predot_len);

    iter = json_object_iter_at(js, s);
    const char *s2 = index(dot+1, '.');

    json_t *value = json_object_iter_value(iter);
    if (value == NULL) {
        value = json_object();
        json_object_set_new(js, s, value);
    }
    if (s2 != NULL) {
        return OutputStats2Json(value, &key[dot-key+1]);
    }
    return value;
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
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");
}
Exemplo n.º 12
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;

}
Exemplo n.º 13
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;
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
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);
		}
Exemplo n.º 17
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;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
Arquivo: dlna.c Projeto: ebichu/dd-wrt
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;
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
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 );
    }
}
Exemplo n.º 22
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);
	}
}
Exemplo n.º 23
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);
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
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);
	}
}
Exemplo n.º 26
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);
	}
}
Exemplo n.º 27
0
int
printKeyValJsonObj( json_t *keyValObj ) {
    void *iter;
    const char *key;
    json_t *value;

    printf( "keys: Value Object\n  {\n" );
    iter = json_object_iter( keyValObj );

    while ( iter ) {
        json_type myType;
        char valueStr[NAME_LEN];

        key = json_object_iter_key( iter );
        value = json_object_iter_value( iter );
        myType = json_typeof( value );
        switch ( myType ) {
        case JSON_STRING:
            snprintf( valueStr, NAME_LEN, "%s", json_string_value( value ) );
            break;
        case JSON_INTEGER:
            snprintf( valueStr, NAME_LEN, "%d",
                      ( int ) json_integer_value( value ) );
            break;
        case JSON_REAL:
            snprintf( valueStr, NAME_LEN, "%f",
                      ( float ) json_real_value( value ) );
            break;
        case JSON_TRUE:
            snprintf( valueStr, NAME_LEN, "TRUE" );
            break;
        case JSON_FALSE:
            snprintf( valueStr, NAME_LEN, "FALSE" );
            break;
        default:
            snprintf( valueStr, NAME_LEN, "Unknown json_type: %d", myType );
        }
        printf( "    %s: %s\n", key, valueStr );
        iter = json_object_iter_next( keyValObj, iter );
    }
    printf( "  }\n" );

    return 0;
}
Exemplo n.º 28
0
int cellophane_handshake(WsHandler * ws_handler) {

	json_error_t  json_err;
	json_t *json_ret;
	json_t *value;
	json_t *transport;
	void *iter;
	char * res;
	char *key;
	size_t index;

	fprintf(stderr, "sending web request \n");
	res = cellophane_do_web_request(ws_handler);
	if (res == NULL || strcmp(res,"") == 0){
        return 0;
    }

	cellophane_print_log(ws_handler,LOG_INFO,DEBUG_DIAGNOSTIC, "Curl Response : %s", res);
	json_ret = json_loads(res, 0, &json_err);
	if(json_ret == NULL){
		cellophane_print_log(ws_handler,LOG_ERROR,DEBUG_NONE, "Could not decode trasnport JSON: %d: %s\n", json_err.line, json_err.text);
		return 0;
	}

	free(res);

	cellophane_print_log(ws_handler,LOG_INFO,DEBUG_DIAGNOSTIC,"Json parsed succesfully");
	iter = json_object_iter(json_ret);
	while(iter){
		key = json_object_iter_key(iter);
		value = json_object_iter_value(iter);
		
		if(strcmp(key, "sid") == 0){
			ws_handler->session.sid = strdup(json_string_value(value));
			cellophane_print_log(ws_handler,LOG_INFO,DEBUG_DETAILED,"Session id : %s", ws_handler->session.sid);
		}else if(strcmp(key, "upgrades") == 0){
			index = json_array_size(value);
			if(index > 0){
				ws_handler->session.supported_transports = (char **) malloc(index * sizeof(char*));
				json_array_foreach(value, index, transport){
					ws_handler->session.supported_transports[index] = strdup(json_string_value(transport));
				}
			}
Exemplo n.º 29
0
static size_t
write_object(json_t* json, stream_t* stream)
{
    uint8_t tag = BSER_TAG_OBJECT;
    size_t bytes = 0;

    assert(json_is_object(json));

    if (stream->write(stream, &tag, SIZE_U8) == SIZE_U8) {
        size_t total_bytes = SIZE_U8;

        json_t* length_node = json_integer(json_object_size(json));
        size_t integer_length = write_integer(length_node, stream);
        total_bytes += integer_length;
        json_decref(length_node);

        if (integer_length > 0) {
            size_t val_bytes = 1;
            void *iter = json_object_iter(json);

            while (iter != NULL && val_bytes > 0) {
                val_bytes = 0;

                json_t* key_node = json_string(json_object_iter_key(iter));
                size_t key_bytes = write_string(key_node, stream);
                total_bytes += key_bytes;
                json_decref(key_node);

                if (key_bytes > 0) {
                    json_t* value = json_object_iter_value(iter);
                    val_bytes = write_json(value, stream);
                    total_bytes += val_bytes;
                }
                iter = json_object_iter_next(json, iter);
            }
            if (iter == NULL) {
                bytes = total_bytes;
            }
        }
    }
    return bytes;
}
Exemplo n.º 30
0
QMap<QString, QVariant> mapFromJSON(json_t *json, json_error_t *error)
{
    QMap<QString, QVariant> dict;
    void *member;
    const char *key;
    json_t *value;

    for (member = json_object_iter(json); member; member = json_object_iter_next(json, member)) {
        key = json_object_iter_key(member);
        value = json_object_iter_value(member);

        QString k = QString::fromUtf8(key);
        QVariant v;

        // json_is_object(const json_t *json)
        // json_is_array(const json_t *json)
        // json_is_string(const json_t *json)
        // json_is_integer(const json_t *json)
        // json_is_real(const json_t *json)
        // json_is_true(const json_t *json)
        // json_is_false(const json_t *json)
        // json_is_null(const json_t *json)
        if (json_is_object(value)) {
            v = mapFromJSON(json, NULL);
        } else if (json_is_array(value)) {
            v = listFromJSON(value);
        } else if (json_is_string(value)) {
            v = QString::fromUtf8(json_string_value(value));
        } else if (json_is_integer(value)) {
            v = json_integer_value(value);
        } else if (json_is_real(value)) {
            v = json_real_value(value);
        } else if (json_is_boolean(value)) {
            v = json_is_true(value);
        }

        if (v.isValid()) {
            dict[k] = v;
        }
    }
    return dict;
}