Esempio n. 1
0
json_t *janus_videocall_query_session(janus_plugin_session *handle) {
	if(g_atomic_int_get(&stopping) || !g_atomic_int_get(&initialized)) {
		return NULL;
	}	
	janus_videocall_session *session = (janus_videocall_session *)handle->plugin_handle;
	if(!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return NULL;
	}
	/* Provide some generic info, e.g., if we're in a call and with whom */
	json_t *info = json_object();
	json_object_set_new(info, "state", json_string(session->peer ? "incall" : "idle"));
	json_object_set_new(info, "username", session->username ? json_string(session->username) : NULL);
	if(session->peer) {
		json_object_set_new(info, "peer", session->peer->username ? json_string(session->peer->username) : NULL);
		json_object_set_new(info, "audio_active", session->audio_active ? json_true() : json_false());
		json_object_set_new(info, "video_active", session->video_active ? json_true() : json_false());
		json_object_set_new(info, "bitrate", json_integer(session->bitrate));
		json_object_set_new(info, "slowlink_count", json_integer(session->slowlink_count));
	}
	if(session->arc || session->vrc) {
		json_t *recording = json_object();
		if(session->arc && session->arc->filename)
			json_object_set_new(recording, "audio", json_string(session->arc->filename));
		if(session->vrc && session->vrc->filename)
			json_object_set_new(recording, "video", json_string(session->vrc->filename));
		json_object_set_new(info, "recording", recording);
	}
	json_object_set_new(info, "destroyed", json_integer(session->destroyed));
	return info;
}
Esempio n. 2
0
json_t *ParameterInfoWriter::write()
{
    json_t *p = json_object();

    json_object_set(p, "name", json_string(name.c_str()));

    json_object_set(p, "type", json_string(fullTypeName.c_str()));

    json_object_set(p, "hasdefault",
                    attr.hasDefault ? json_true() : json_false());

    if (attr.hasDefault)
    {
        json_object_set(p, "defaultvalue", json_string(defaultArg.c_str()));
    }

    json_object_set(p, "isvarargs",
                    attr.isVarArgs ? json_true() : json_false());

    if (templateInfo)
    {
        json_object_set(p, "templatetypes", MemberInfoWriter::writeTemplateTypeInfo(templateInfo));
    }
    else
    {
        json_object_set(p, "templatetypes", json_null());
    }

    return p;
}
Esempio n. 3
0
wbBool wbSolution(wbArg_t arg, void * data, int rows, int columns) {
    int ii;
    char * type;
    wbBool res;
    json_t * msg;
    char * expectedOutputFile;
    char * outputFile;
    json_t * inputFileArray;

    expectedOutputFile = wbArg_getExpectedOutputFile(arg);
    outputFile = wbArg_getOutputFile(arg);
    type = wbArg_getType(arg);

    wbAssert(type != NULL);
    wbAssert(expectedOutputFile != NULL);
    wbAssert(outputFile != NULL);

    res = wbSolution(expectedOutputFile, outputFile, type, data, rows, columns);

#if 1
    if (res) {
        _solution_correctQ = json_object();

        msg = json_string("Solution is correct.");

        json_object_set(_solution_correctQ, "CorrectQ", json_true());
        json_object_set(_solution_correctQ, "Message", msg);
    } else {
        msg = _solution_correctQ;
        _solution_correctQ = json_object();
        json_object_set(_solution_correctQ, "CorrectQ", json_false());
        json_object_set(_solution_correctQ, "Message", msg);
    }
#else
    if (res) {
        _solution_correctQ = json_true();
    } else {
        _solution_correctQ = json_false();
    }
#endif

    inputFileArray = json_array();

    for (ii = 0; ii < wbArg_getInputCount(arg); ii++) {
        char * file = wbArg_getInputFile(arg, ii);
        if (file != NULL) {
            json_array_append(inputFileArray, json_string(file));
        }
    }

    /*
    json_object_set(_solution_correctQ, "InputFiles", inputFileArray);
    json_object_set(_solution_correctQ, "ExpectedOutput", json_string(expectedOutputFile));
    json_object_set(_solution_correctQ, "OutputFile", json_string(outputFile));
    */

    return res;
}
Esempio n. 4
0
void AssemblyWriter::writeToString(utString& out)
{
    json_t *json = json_object();

    json_object_set(json, "type", json_string("ASSEMBLY"));
    json_object_set(json, "name", json_string(name.c_str()));
    json_object_set(json, "version", json_string(version.c_str()));
    json_object_set(json, "uid", json_string(uid.c_str()));
    json_object_set(json, "loomconfig", json_string(loomConfig.c_str()));

#ifdef LOOM_ENABLE_JIT
    json_object_set(json, "jit", json_true());
#else
    json_object_set(json, "jit", json_false());
#endif

    json_object_set(json, "debugbuild", LSCompiler::isDebugBuild() ? json_true() : json_false());

    // references

    json_t *refArray = json_array();

    json_object_set(json, "references", refArray);

    for (UTsize i = 0; i < references.size(); i++)
    {
        utString assemblyName = references.at(i);

        json_t *ro = json_object();

        json_object_set(ro, "name", json_string(assemblyName.c_str()));

        json_array_append(refArray, ro);
    }

    // modules

    json_t *moduleArray = json_array();

    json_object_set(json, "modules", moduleArray);

    for (UTsize i = 0; i < modules.size(); i++)
    {
        json_t *mjson = modules[i]->write();
        json_array_append(moduleArray, mjson);
    }

    out = json_dumps(json, JSON_INDENT(3) | JSON_SORT_KEYS | JSON_PRESERVE_ORDER | JSON_COMPACT);
}
Esempio n. 5
0
int cometd_dump_message(void * output, cometd_message * message, json_dump_callback_t callback) {
	json_t * root = json_object();
	json_object_set_new(root, CHANNEL_FIELD, json_string_nocheck(message->channel));
	if (message->id)
		json_object_set_new(root, ID_FIELD, json_string_nocheck(message->id));
	if (message->clientId)
		json_object_set_new(root, CLIENT_ID_FIELD, json_string_nocheck(message->clientId));
	json_object_set_new(root, SUCCESSFUL_FIELD, message->successful ? json_true() : json_false());
	json_object_set_new(root, VERSION_FIELD, json_string_nocheck(message->version));
	if (message->supportedConnectionTypes)
		json_object_set(root, SUPPORTED_CONNECTION_TYPES_FIELD, message->supportedConnectionTypes);
	if (message->connectionType)
		json_object_set_new(root, CONNECTION_TYPE_FIELD, json_string_nocheck(message->connectionType));
	if (message->data)
		json_object_set(root, DATA_FIELD, message->data);
	if (message->ext)
		json_object_set(root, EXT_FIELD, message->ext);
	if (message->advice.present) {
		if (message->advice.sourceAdvice)
			json_object_set_new(root, ADVICE_FIELD, message->advice.sourceAdvice);
		else {
			json_t * advice = json_object();
			if (message->advice.reconnect)
				json_object_set_new(advice, RECONNECT_FIELD, json_string_nocheck(message->advice.reconnect));
			json_object_set_new(advice, INTERVAL_FIELD, json_integer(message->advice.interval));
			json_object_set(root, DATA_FIELD, message->data);
			json_object_set_new(root, ADVICE_FIELD, advice);
		}
	}
	int result = json_dump_callback(root, callback, output, 0);
	json_decref(root);
	return result;
}
Esempio n. 6
0
/**
 * connects the device
 */
json_t * b_device_connect (json_t * device, void ** device_ptr) {
  char * param;
  json_t * j_param;
  
  if (device_ptr != NULL) {
    // Allocating *device_ptr for further use
    *device_ptr = (json_t *)json_pack("{s{sisi}s{sisi}s{sisi}s{s{sssfsos[sss]}s{sssfsos[sss]}}}",
                             "switches", "sw1", 0, "sw2", 1,
                             "dimmers", "di1", 42, "di2", 5,
                             "dimmers_values", "di1", 42, "di2", 5,
                             "heaters", 
                               "he1", "mode", "auto", "command", 18.0, "on", json_true(), "availableModes",
                                  "auto", "manual", "off",
                               "he2", "mode", "manual", "command", 20.0, "on", json_false(), "availableModes",
                                  "auto", "manual", "off");
  }
  
  if (o_strstr(json_string_value(json_object_get(json_object_get(device, "options"), "device_specified")), "batman") == NULL) {
    param = msprintf("%s says I'm batman with the alert_url %s", json_string_value(json_object_get(device, "name")), json_string_value(json_object_get(json_object_get(device, "options"), "alert_url")));
    j_param = json_pack("{sis{ss}}", "result", WEBSERVICE_RESULT_OK, "options", "device_specified", param);
    o_free(param);
  } else {
    j_param = json_pack("{si}", "result", WEBSERVICE_RESULT_OK);
  }
  return j_param;
}
Esempio n. 7
0
json_t *playlist_to_json_set_collaborative(sp_playlist *playlist,
                                           json_t *object) {
  bool collaborative = sp_playlist_is_collaborative(playlist);
  json_object_set_new(object, "collaborative",
                      collaborative ? json_true() : json_false());
  return object;
}
Esempio n. 8
0
//----------------------------------------------------------------//
json_t* _luaToJSON ( lua_State* L, int idx ) {
	
	switch ( lua_type ( L, idx )) {
		
		case LUA_TBOOLEAN: {
		
			bool value = lua_toboolean ( L, idx ) == 0 ? false : true;
			return value ? json_true () : json_false ();
		}
		case LUA_TTABLE: {
			
			return lua_objlen ( L, idx ) ? _luaToJSONArray ( L, idx ) : _luaToJSONObject ( L, idx );
		}
		case LUA_TSTRING: {
			
			cc8* str = lua_tostring ( L, idx );
			return json_string ( str );
		}
		case LUA_TNUMBER: {
		
			double real = lua_tonumber ( L, idx );
			return json_real ( real );
		}
		
		case LUA_TLIGHTUSERDATA: {
		
			return json_null ();
		}
	};

	return 0;
}
Esempio n. 9
0
json_t* nonstring(char* arg)
{
    json_t* temp;
    char* endptr;
    if (!strcmp(arg, "null") || !strcmp(arg, "n"))
        {return json_null();}
    if (!strcmp(arg, "true") || !strcmp(arg, "t"))
        {return json_true();}
    if (!strcmp(arg, "false") || !strcmp(arg, "f"))
        {return json_false();}
    if (!strcmp(arg, "array") || !strcmp(arg, "[]"))
        {return json_array();}
    if (!strcmp(arg, "object") || !strcmp(arg, "{}"))
        {return json_object();}
    errno = 0;
    temp = json_integer(strtol(arg, &endptr, 10));
    if (!errno && *endptr=='\0')
        {return temp;}
    errno = 0;
    temp = json_real(strtod(arg, &endptr));
    if (!errno && *endptr=='\0')
        {return temp;}
    arg_err("parse error: illegal nonstring on arg %i, \"%s\"");
    return json_null();
}
Esempio n. 10
0
/*====================================================================
 * 函数名    : vGenPASINFOMsg
 * 功能      : PAS上报逻辑服务器业务信息消息
 * 算法实现  : 
 * 参数说明  : vpd 要上报的设备
 * 返回值说明: 成功 生成的消息
 *			   失败 NULL             
 * ----------------------------------------------------------------------
 * 修改记录:
 * 日  期        版本        修改人        走读人        修改记录
 * 2015/1/26       v1.0        YLI                          创建
 * ====================================================================*/
json_t * vGenPASINFOMsg(VPD vpd)
{
	json_t *root;
	char saLocalTime[256];

	root = json_object();
	//eventid
	if (json_object_set(root,"eventid",
		json_string("EV_PAS_INFO")) == FAILUER)
	{
		json_decref(root);
		vLogErr("eventid set error!!!");
		return NULL;
	}
	//devid
	if (json_object_set(root,"devid",
		json_string(vpd.saDevId)) == FAILUER)
	{
		json_decref(root);
		vLogErr("devtype set error!!!");
		return NULL;
	}
	//devtype
	if (json_object_set(root,"devtype",
		json_string(vpd.saDevType)) == FAILUER)
	{
		json_decref(root);
		vLogErr("devtype set error!!!");
		return NULL;
	}
	//rpttime
	memset(saLocalTime,0x00,sizeof saLocalTime);
	GetLocalTime(saLocalTime);
	if (json_object_set(root,"rpttime",
		json_string(saLocalTime)) == FAILUER)
	{
		json_decref(root);
		vLogErr("rpttime set error!!!");
		return NULL;
	}
	//version
	json_object_set(root,"version",json_string("1.06"));
	//pidchange
	json_object_set(root,"pidchange",json_false());
	//belongphy
	json_object_set(root,"belongphy",json_string("1123"));
	/*pasinfo*/
	json_object_set(root,"pasinfo",
		json_pack("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i}",
			"maxcallcount",10000,
			"maxonlinecount",10000,
			"curonlinecount",10000,
			"siponlinecount",10000,
			"h323onlinecount",10000,
			"monitoronlinecount",10,
			"callingcount",100,
			"confmtcount",100));
	return root;
}
json_t *janus_source_query_session(janus_plugin_session *handle) {
	if (g_atomic_int_get(&stopping) || !g_atomic_int_get(&initialized)) {
		return NULL;
	}
	janus_source_session *session = (janus_source_session *)handle->plugin_handle;
	if (!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return NULL;
	}
	/* In the source plugin, every session is the same: we just provide some configure info */
	json_t *info = json_object();
	json_object_set_new(info, "audio_active", session->audio_active ? json_true() : json_false());
	json_object_set_new(info, "video_active", session->video_active ? json_true() : json_false());
	json_object_set_new(info, "bitrate", json_integer(session->bitrate));
	json_object_set_new(info, "slowlink_count", json_integer(session->slowlink_count));
	json_object_set_new(info, "destroyed", json_integer(session->destroyed));
	return info;
}
Esempio n. 12
0
void JSON::setBoolean(const char *key, bool value)
{
    if (!_json)
    {
        return;
    }

    json_object_set_new(_json, key, value ? json_true() : json_false());
}
Esempio n. 13
0
json_t *bunser(const char *buf, const char *end, int *needed,
               json_error_t *jerr)
{
    json_int_t ival;

    switch (buf[0]) {
    case BSER_INT8:
    case BSER_INT16:
    case BSER_INT32:
    case BSER_INT64:
        if (!bunser_int(buf, end - buf, needed, &ival)) {
            snprintf(jerr->text, sizeof(jerr->text),
                     "invalid integer encoding");
            return NULL;
        }
        return json_integer(ival);

    case BSER_STRING:
    {
        const char *start;
        json_int_t len;

        if (!bunser_string(buf, end - buf, needed, &start, &len)) {
            snprintf(jerr->text, sizeof(jerr->text),
                     "invalid string encoding");
            return NULL;
        }

        return json_string_binary(start, len);
    }

    case BSER_REAL:
        *needed = sizeof(double) + 1;
        return json_real(*(double*)(buf+1));
    case BSER_TRUE:
        *needed = 1;
        return json_true();
    case BSER_FALSE:
        *needed = 1;
        return json_false();
    case BSER_NULL:
        *needed = 1;
        return json_null();
    case BSER_ARRAY:
        return bunser_array(buf, end, needed, jerr);
    case BSER_TEMPLATE:
        return bunser_template(buf, end, needed, jerr);
    case BSER_OBJECT:
        return bunser_object(buf, end, needed, jerr);
    default:
        snprintf(jerr->text, sizeof(jerr->text),
                 "invalid bser encoding type %02x", (int)buf[0]);
        return NULL;
    }

    return NULL;
}
Esempio n. 14
0
json_t *ConstructorInfoWriter::write()
{
    json_t *json = json_object();

    json_object_set(json, "type", json_string("CONSTRUCTOR"));
    json_object_set(json, "defaultconstructor", defaultConstructor ? json_true() : json_false());

    MethodBaseWriter::write(json);

    return json;
}
Esempio n. 15
0
void JSON::setArrayBoolean(int index, bool value)
{
    if (!isArray())
    {
        return;
    }

    expandArray(index + 1);

    json_array_set(_json, index, value ? json_true() : json_false());
}
Esempio n. 16
0
static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error)
{
    json_t *json;

    switch(lex->token) {
        case TOKEN_STRING: {
            json = json_string_nocheck(lex->value.string);
            break;
        }

        case TOKEN_INTEGER: {
            json = json_integer(lex->value.integer);
            break;
        }

        case TOKEN_REAL: {
            json = json_real(lex->value.real);
            break;
        }

        case TOKEN_TRUE:
            json = json_true();
            break;

        case TOKEN_FALSE:
            json = json_false();
            break;

        case TOKEN_NULL:
            json = json_null();
            break;

        case '{':
            json = parse_object(lex, flags, error);
            break;

        case '[':
            json = parse_array(lex, flags, error);
            break;

        case TOKEN_INVALID:
            error_set(error, lex, "invalid token");
            return NULL;

        default:
            error_set(error, lex, "unexpected token");
            return NULL;
    }

    if(!json)
        return NULL;

    return json;
}
Esempio n. 17
0
//native Handle:json_false();
static cell_t Native_json_false(IPluginContext *pContext, const cell_t *params) {
	json_t *result = json_false();

	Handle_t hndlResult = g_pHandleSys->CreateHandle(htJanssonObject, result, pContext->GetIdentity(), myself->GetIdentity(), NULL);

	if(hndlResult == BAD_HANDLE) {
		pContext->ThrowNativeError("Could not create <False> handle.");
	}

	return hndlResult;
}
Esempio n. 18
0
/*!
 * \brief Get the \ref json_mem block for a pointer allocated via
 * ast_json_malloc().
 *
 * This function properly handles Jansson singletons (null, true, false), and
 * \c NULL.
 *
 * \param p Pointer, usually to a \c json_t or \ref ast_json.
 * \return \ref json_mem object with extra allocation info.
 */
static inline struct json_mem *to_json_mem(void *p)
{
	struct json_mem *mem;
	/* Avoid ref'ing the singleton values */
	if (p == NULL || p == json_null() || p == json_true() ||
		p == json_false()) {
		return NULL;
	}
	mem = (struct json_mem *)((char *) (p) - sizeof(*mem));
	ast_assert(mem->magic == JSON_MAGIC);
	return mem;
}
    boost::any configuration_parser::convert_json(json_t* _val) {
        switch( json_typeof( _val )) {
            case JSON_INTEGER:
            return boost::any((int)json_integer_value(_val));

            case JSON_STRING:
            return boost::any(std::string(json_string_value(_val)));

            case JSON_REAL:
            return boost::any(json_real_value(_val));

            case JSON_TRUE:
            return boost::any(json_true());
            
            case JSON_FALSE:
            return boost::any(json_false());

            case JSON_NULL:
            return boost::any(std::string("NULL"));

            case JSON_ARRAY:
            {
                std::vector<boost::any> vector;
                size_t  idx = 0;
                json_t* element = NULL;
                json_array_foreach(_val, idx, element) {
                    try {
                        vector.push_back(convert_json(element));
                    } catch (const irods::exception& e) {
                        irods::log(e);
                    }
                }
                return boost::any(vector);
            }

            case JSON_OBJECT:
            {
                std::unordered_map<std::string, boost::any> map;
                const char* key = NULL;
                json_t*     subval = NULL;
                json_object_foreach( _val, key, subval ) {
                    try {
                        map.insert(std::pair<std::string, boost::any>(std::string(key), convert_json(subval)));
                    } catch (const irods::exception& e) {
                        irods::log(e);
                    }
                }
                return boost::any(map);
            }
        }
        THROW( -1, (boost::format("unhandled type in json_typeof: %d") % json_typeof(_val) ).str());

    } // parse_json_object
Esempio n. 20
0
/**
	Send response data to client.
	Parameters:
		int success: Status about data
		json_t *data: Data for response
		int client_sockfd: connection
*/
void response_data(int success, json_t *data, int client_sockfd) {
	json_t *root = json_object();

	if (success == 1) json_object_set(root, "success", json_true());
	else json_object_set(root, "success", json_false());
	json_object_set(root, "data", data);
	
	char *decode = json_dumps(root, 1);

	write(client_sockfd, decode, 500);

	json_decref(root);
}
Esempio n. 21
0
int32 rf_evt_pack_json(json_t *result, const int32 *evt_types, rf_evt_svc_t *service)
{
	int32 i = 0;
	json_t *types_array = NULL;
	json_t *listener = NULL;
	json_t *status = NULL;

	json_object_add(result, RMM_JSON_ODATA_CONTEXT, json_string(service->links.odata_context));
	json_object_add(result, RMM_JSON_ODATA_ID, json_string(service->links.odata_id));
	add_json_string(result, RMM_JSON_ODATA_TYPE, service->fixed.odata_type);
	add_json_string(result, RMM_JSON_RF_ID, service->fixed.id);
	add_json_string(result, RMM_JSON_RF_NAME, service->fixed.name);

	status = json_object();
	if (status != NULL) {
		add_json_string(status, RMM_JSON_RF_STATUS_STATE, service->fixed.status.state);
		add_json_string(status, RMM_JSON_RF_STATUS_HEALTH, service->fixed.status.health);
	}
	json_object_add(result, RMM_JSON_RF_STATUS, status);

	if (service->fixed.service_enabled)
		json_object_add(result, RMM_JSON_RF_SERVICE_ENABLED, json_true());
	else
		json_object_add(result, RMM_JSON_RF_SERVICE_ENABLED, json_false());

	add_json_integer(result, RMM_JSON_RF_DELIVERY_RETRY, service->fixed.retry);

	add_json_integer(result, RMM_JSON_RF_DELIVERY_RETRY_INTERVAL, service->fixed.retry_interval);


	types_array = json_array();
	if (types_array == NULL)
		return -1;

	for (i = 0;  i < MAX_EVT_ACTION_NUM; i++) {
		if (evt_types[i] == 0)
			continue;

		json_array_add(types_array, json_string((int8 *)rf_evt_msg[i].type_name));
	}
	json_object_add(result, RMM_JSON_RF_SUPPORTED_EVT_TYPES, types_array);

	listener = json_object();
	if (listener == NULL) 
		return -1;

	add_json_string(listener, RMM_JSON_ODATA_ID, service->links.subscriptions);
	json_object_add(result, RMM_JSON_RF_SUBSCRIPTION, listener);

	return 0;
}
Esempio n. 22
0
json_t*
bser2json(bser_t* bser)
{
    if (bser_is_integer(bser)) {
        json_int_t v = bser_integer_value(bser);
        return json_integer(v);
    } else if (bser_is_real(bser)) {
        double v = bser_real_value(bser);
        return json_real(v);
    } else if (bser_is_true(bser)) {
        return json_true();
    } else if (bser_is_false(bser)) {
        return json_false();
    } else if (bser_is_null(bser)) {
        return json_null();
    } else if (bser_is_string(bser)) {
        size_t length;
        const char* str = bser_string_value(bser, &length);
        char* dup = strndup(str, length);
        json_t* string = json_string(dup);
        free(dup);
        return string;
    } else if (bser_is_array(bser)) {
        size_t length = bser_array_size(bser);
        json_t* array = json_array();
        for (int i = 0; i < length; ++i) {
            json_array_append_new(array, bser2json(bser_array_get(bser, i)));
        }
        return array;
    } else if (bser_is_object(bser)) {
        size_t length = bser_object_size(bser);
        json_t* object = json_object();
        for (int i = 0; i < length; ++i) {
            size_t key_length;
            bser_t* key = bser_object_key_at(bser, i);
            assert(bser_is_string(key));
            bser_t* value = bser_object_value_at(bser, i);
            if (!bser_is_no_field(value)) {
                const char* key_chars = bser_string_value(key, &key_length);
                assert(key_chars != NULL && *key_chars != '\0');
                char* key_dup = strndup(key_chars, key_length);
                json_object_set_new(object, key_dup, bser2json(value));
                free(key_dup);
            }
        }
        return object;
    } else {
        return NULL;
    }
}
Esempio n. 23
0
static json_t *pack(scanner_t *s, va_list *ap)
{
    switch(s->token) {
        case '{':
            return pack_object(s, ap);

        case '[':
            return pack_array(s, ap);

        case 's': /* string */
        {
            const char *str = va_arg(*ap, const char *);
            if(!str) {
                set_error(s, "<args>", "NULL string argument");
                return NULL;
            }
            if(!utf8_check_string(str, -1)) {
                set_error(s, "<args>", "Invalid UTF-8 string");
                return NULL;
            }
            return json_string_nocheck(str);
        }

        case 'n': /* null */
            return json_null();

        case 'b': /* boolean */
            return va_arg(*ap, int) ? json_true() : json_false();

        case 'i': /* integer from int */
            return json_integer(va_arg(*ap, int));

        case 'I': /* integer from json_int_t */
            return json_integer(va_arg(*ap, json_int_t));

        case 'f': /* real */
            return json_real(va_arg(*ap, double));

        case 'O': /* a json_t object; increments refcount */
            return json_incref(va_arg(*ap, json_t *));

        case 'o': /* a json_t object; doesn't increment refcount */
            return va_arg(*ap, json_t *);

        default:
            set_error(s, "<format>", "Unexpected format character '%c'",
                      s->token);
            return NULL;
    }
}
Esempio n. 24
0
static json_t *json_serialize_pspec (const GValue *value)
{
    /* Only types in json-glib but G_TYPE_BOXED */
    switch (G_TYPE_FUNDAMENTAL (G_VALUE_TYPE (value))) {
        case G_TYPE_STRING:
            if (!g_value_get_string (value))
        break;
            else 
            return json_string (g_value_get_string (value));
        case G_TYPE_BOOLEAN:
            if (g_value_get_boolean (value))
                return json_true ();
            else return json_false ();
        case G_TYPE_INT:
            return json_integer (g_value_get_int (value));
        case G_TYPE_UINT:
            return json_integer (g_value_get_uint (value));
        case G_TYPE_LONG:
            return json_integer (g_value_get_long (value));
        case G_TYPE_ULONG:
            return json_integer (g_value_get_ulong (value));
        case G_TYPE_INT64:
            return json_integer (g_value_get_int64 (value));
        case G_TYPE_FLOAT:
            return json_real (g_value_get_float (value));
        case G_TYPE_DOUBLE:
            return json_real (g_value_get_double (value));
        case G_TYPE_CHAR:
            return json_integer (g_value_get_schar (value));
        case G_TYPE_UCHAR:
            return json_integer (g_value_get_uchar (value));
        case G_TYPE_ENUM:
            return json_integer (g_value_get_enum (value));
        case G_TYPE_FLAGS:
            return json_integer (g_value_get_flags (value));
        case G_TYPE_NONE:
            break;
        case G_TYPE_OBJECT:
            {
            GObject *object = g_value_get_object (value);
            if (object)
                return json_gobject_serialize (object);
            }
            break;
        defalut:
            g_warning("Unsuppoted type `%s'",g_type_name (G_VALUE_TYPE (value)));
    }
    return json_null(); 
}
Esempio n. 25
0
static json_t* escapeFieldValue (const tagEntryInfo * tag, fieldType ftype, bool returnEmptyStringAsNoValue)
{
	const char *str = renderFieldEscaped (jsonWriter.type, ftype, tag, NO_PARSER_FIELD, NULL);
	if (str)
	{
		unsigned int dt = getFieldDataType(ftype);
		if (dt & FIELDTYPE_STRING)
		{
			if (dt & FIELDTYPE_BOOL && str[0] == '\0')
				return json_false();
			else
				return json_string (str);
		}
		else if (dt & FIELDTYPE_INTEGER)
		{
			long tmp;

			if (strToLong (str, 10, &tmp))
				return json_integer (tmp);
			else
				return NULL;
		}
		else if (dt & FIELDTYPE_BOOL)
		{
			/* TODO: This must be fixed when new boolean field is added.
			   Currently only `file:' field use this. */
			return json_boolean (strcmp ("-", str)); /* "-" -> false */
		}
		AssertNotReached ();
		return NULL;
	}
	else if (returnEmptyStringAsNoValue)
		return json_false();
	else
		return NULL;
}
Esempio n. 26
0
RoundJSONObject* round_json_bool_new(bool value)
{
  RoundJSONObject* obj;

  obj = round_json_object_new();

  if (!obj)
    return NULL;

#if defined(ROUND_USE_JSON_PARSER_JANSSON)
  obj->jsonObj = value ? json_true() : json_false();
#endif

  return obj;
}
Esempio n. 27
0
/* Convert raw TOML value from toml_raw_in() or toml_raw_at() to JSON.
 */
static int value_to_json (const char *raw, json_t **op)
{
    char *s = NULL;
    int b;
    int64_t i;
    double d;
    toml_timestamp_t ts;
    json_t *obj;

    if (toml_rtos (raw, &s) == 0) {
        obj = json_string (s);
        free (s);
        if (!obj)
            goto nomem;
    }
    else if (toml_rtob (raw, &b) == 0) {
        if (!(obj = b ? json_true () : json_false ()))
            goto nomem;
    }
    else if (toml_rtoi (raw, &i) == 0) {
        if (!(obj = json_integer (i)))
            goto nomem;
    }
    else if (toml_rtod (raw, &d) == 0) {
        if (!(obj = json_real (d)))
            goto nomem;
    }
    else if (toml_rtots (raw, &ts) == 0) {
        time_t t;
        if (tomltk_ts_to_epoch (&ts, &t) < 0
                || !(obj = tomltk_epoch_to_json (t)))
            goto error;
    }
    else {
        errno = EINVAL;
        goto error;
    }
    *op = obj;
    return 0;
nomem:
    errno = ENOMEM;
error:
    return -1;
}
Esempio n. 28
0
/*=========================================================================*\
      Store bool value in repository 
\*=========================================================================*/
int persistSetBool( const char *key, bool value )
{
  json_t *jObj;
    
  DBGMSG( "persistSetBool: (%s)=%s", key, value?"True":"False" ); 

/*------------------------------------------------------------------------*\
    Convert value to JSON
\*------------------------------------------------------------------------*/
  jObj = value ? json_true() : json_false();
  if( !jObj ) {
    logerr( "Cannot convert boolean to JSON: %d", value );
    return -1;
  }
  
/*------------------------------------------------------------------------*\
    Add or replace value in repositiory
\*------------------------------------------------------------------------*/
  return persistSetJSON_new( key, jObj );
}
Esempio n. 29
0
//## void Json.setBool(String key, String value);
static KMETHOD Json_setBool(KonohaContext *kctx, KonohaStack *sfp)
{
	json_t* obj = ((struct _kJson *)sfp[0].asObject)->obj;
	CHECK_JSON(obj, KReturnDefaultObjectValue());
	const char *key = S_text(sfp[1].asString);
	kbool_t bval = sfp[2].boolValue;
	json_t* val;
	if(bval) {
		val = json_true();
	}
	else {
		val = json_false();
	}
	int ret = json_object_set(obj, key, val);
	if(ret < 0) {
		DBG_P("[WARNING] Json set cannnot set target object");
		KReturnDefaultObjectValue();
	}
	KReturnVoid();
}
Esempio n. 30
0
void exit_client(const char *err)
{
    const char *msg = err ? err : "";
    json_t *exit_obj;
    
    if (err)
	log_msg("Client error: %s. Exit.", err);
    
    if (outfd != -1) {
	exit_obj = json_object();
	
	json_object_set_new(exit_obj, "error", err ? json_true() : json_false());
	json_object_set_new(exit_obj, "message", json_string(msg));
	if (can_send_msg)
	    client_msg("server_error", exit_obj);
	else
	    json_decref(exit_obj);
	
	usleep(100); /* try to make sure the server process handles write() before close(). */
	close(infd);
	close(outfd);
	infd = outfd = -1;
    }
    
    termination_flag = 3; /* make sure the command loop exits if nh_exit_game jumps there */
    if (!sigsegv_flag)
	nh_exit_game(EXIT_FORCE_SAVE); /* might not return here */
    nh_lib_exit();
    close_database();
    if (user_info.username)
	free(user_info.username);
    free_config();
    reset_cached_diplaydata();
    end_logging();
    exit(err != NULL);
}