Beispiel #1
0
//native json_object_update_existing(Handle:hObj, Handle:hOther);
static cell_t Native_json_object_update_existing(IPluginContext *pContext, const cell_t *params) {
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

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

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

	bool bSuccess = (json_object_update_existing(object, other) == 0);
	return bSuccess;
}
Beispiel #2
0
int ast_json_object_update_existing(struct ast_json *object, struct ast_json *other)
{
#if JANSSON_VERSION_HEX >= 0x020300
	return json_object_update_existing((json_t *)object, (json_t *)other);
#else
	struct ast_json_iter *iter = ast_json_object_iter(other);
	int ret = 0;

	if (object == NULL || other == NULL) {
		return -1;
	}

	while (iter != NULL && ret == 0) {
		const char *key = ast_json_object_iter_key(iter);

		if (ast_json_object_get(object, key) != NULL) {
			struct ast_json *value = ast_json_object_iter_value(iter);

			if (!value || ast_json_object_set(object, key, ast_json_ref(value))) {
				ret = -1;
			}
		}
		iter = ast_json_object_iter_next(other, iter);
	}
	return ret;
#endif
}
Beispiel #3
0
static void test_conditional_updates()
{
    json_t *object, *other;

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

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

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

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

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

    json_decref(object);

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

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

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

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

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

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

    json_decref(object);
    json_decref(other);
}
Beispiel #4
0
int la_codec_object_update_existing(la_codec_value_t *object, la_codec_value_t *other)
{
    return json_object_update_existing((json_t *) object, (json_t *) other);
}