本文整理汇总了C++中json_integer函数的典型用法代码示例。如果您正苦于以下问题:C++ json_integer函数的具体用法?C++ json_integer怎么用?C++ json_integer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_integer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: json_object
json_t *CreateJSONHeader(Packet *p, int direction_sensitive, char *event_type)
{
char timebuf[64];
char srcip[46], dstip[46];
Port sp, dp;
json_t *js = json_object();
if (unlikely(js == NULL))
return NULL;
CreateIsoTimeString(&p->ts, timebuf, sizeof(timebuf));
srcip[0] = '\0';
dstip[0] = '\0';
if (direction_sensitive) {
if ((PKT_IS_TOSERVER(p))) {
if (PKT_IS_IPV4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), dstip, sizeof(dstip));
}
sp = p->sp;
dp = p->dp;
} else {
if (PKT_IS_IPV4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), dstip, sizeof(dstip));
}
sp = p->dp;
dp = p->sp;
}
} else {
if (PKT_IS_IPV4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), dstip, sizeof(dstip));
}
sp = p->sp;
dp = p->dp;
}
char proto[16];
if (SCProtoNameValid(IP_GET_IPPROTO(p)) == TRUE) {
strlcpy(proto, known_proto[IP_GET_IPPROTO(p)], sizeof(proto));
} else {
snprintf(proto, sizeof(proto), "%03" PRIu32, IP_GET_IPPROTO(p));
}
/* time & tx */
json_object_set_new(js, "timestamp", json_string(timebuf));
/* sensor id */
if (sensor_id >= 0)
json_object_set_new(js, "sensor_id", json_integer(sensor_id));
/* pcap_cnt */
if (p->pcap_cnt != 0) {
json_object_set_new(js, "pcap_cnt", json_integer(p->pcap_cnt));
}
if (event_type) {
json_object_set_new(js, "event_type", json_string(event_type));
}
/* vlan */
if (p->vlan_idx > 0) {
json_t *js_vlan;
switch (p->vlan_idx) {
case 1:
json_object_set_new(js, "vlan",
json_integer(VLAN_GET_ID1(p)));
break;
case 2:
js_vlan = json_array();
if (unlikely(js != NULL)) {
json_array_append_new(js_vlan,
json_integer(VLAN_GET_ID1(p)));
json_array_append_new(js_vlan,
json_integer(VLAN_GET_ID2(p)));
json_object_set_new(js, "vlan", js_vlan);
}
break;
default:
/* shouldn't get here */
break;
}
}
/* tuple */
json_object_set_new(js, "src_ip", json_string(srcip));
switch(p->proto) {
case IPPROTO_ICMP:
break;
//.........这里部分代码省略.........
开发者ID:yanjinjin,项目名称:btds,代码行数:101,代码来源:output-json.c
示例2: lua_gettop
//----------------------------------------------------------------//
json_t* MOAIHarness::ConvertStackIndexToJSON(lua_State * L, int idx, bool shallow, std::vector<const void*> * carried_references)
{
// Check to see if idx is negative.
if (idx < 0)
idx = lua_gettop(L) + (idx + 1);
// What we do is going to be based on what is located at
// the specified index.
switch (lua_type(L, idx))
{
case LUA_TNIL:
return json_null();
case LUA_TNUMBER:
return json_real(lua_tonumber(L, idx));
case LUA_TSTRING:
return json_string(lua_tostring(L, idx));
case LUA_TBOOLEAN:
return (lua_toboolean(L, idx) == 0) ? json_false() : json_true();
case LUA_TFUNCTION:
// Todo: fix pointer encoding for datapairs so that this will work
// correctly on 64 bit systems
return json_datapair("function", json_integer((int)lua_topointer(L, idx)));
case LUA_TUSERDATA:
return json_datapair("userdata", json_integer((int)lua_topointer(L, idx)));
case LUA_TTHREAD:
return json_datapair("thread", json_integer((int)lua_topointer(L, idx)));
case LUA_TLIGHTUSERDATA:
return json_datapair("lightuserdata", json_integer((int)lua_topointer(L, idx)));
case LUA_TTABLE:
// Unlike other data values, table must be recursively evaluated. In addition
// we must check for circular references since it's possible they may occur.
char s[LUAI_MAXNUMBER2STR];
std::vector<const void*> * references = (carried_references == NULL) ? new std::vector<const void*>() : carried_references;
json_t* holder = shallow ? json_array() : json_object();
lua_pushnil(L);
while (lua_next(L, idx) != 0)
{
// Key is at index -2
// Value is at index -1
json_t* key = NULL;
json_t* value = NULL;
// Safely convert the key into a string if needed (we
// can't use lua_tostring with lua_next).
if (lua_isnumber(L, -2))
{
lua_Number n = lua_tonumber(L, -2);
if (shallow)
{
key = json_real(n);
}
else
{
lua_number2str(s, n);
key = json_string((const char*)&s);
}
}
else if (lua_isboolean(L, -2))
{
key = json_string(lua_toboolean(L, -2) ? "true" : "false");
}
else if (!lua_isstring(L, -2))
{
int type = lua_type(L, -2);
key = json_datapair(lua_typename(L, type), json_integer((int)lua_topointer(L, -2)));
}
else
key = json_string(lua_tostring(L, -2));
// If only a shallow result is requested, just add the key to an array
if (shallow)
{
json_array_append_new(holder, key);
lua_pop(L, 1);
continue;
}
// Recursively convert the value ONLY if it doesn't
// appear in our references vector.
bool evaluate = true;
if (lua_type(L, -1) == LUA_TTABLE)
{
const void* ptr = lua_topointer(L, -1);
for (std::vector<const void*>::iterator it = references->begin(); it != references->end(); ++it)
{
if (*it == ptr)
{
evaluate = false;
break;
}
}
}
// Now evaluate the value if we should.
if (evaluate)
{
if (lua_type(L, -1) == LUA_TTABLE)
references->insert(references->end(), lua_topointer(L, -1));
value = MOAIHarness::ConvertStackIndexToJSON(L, -1, shallow, references);
//.........这里部分代码省略.........
开发者ID:Limingming2,项目名称:meyume-moai-1-6,代码行数:101,代码来源:MOAIHarness.cpp
示例3: ccmd_list_games
static void
ccmd_list_games(json_t * params)
{
char filename[1024];
int completed, limit, show_all, count, i, fd;
struct gamefile_info *files;
enum nh_log_status status;
struct nh_game_info gi;
json_t *jarr, *jobj;
if (json_unpack
(params, "{si,si*}", "completed", &completed, "limit", &limit) == -1)
exit_client("Bad parameters for list_games");
if (json_unpack(params, "{si*}", "show_all", &show_all) == -1)
show_all = 0;
/* step 1: get a list of files from the db. */
files =
db_list_games(completed, show_all ? 0 : user_info.uid, limit, &count);
jarr = json_array();
/* step 2: get extra info for each file. */
for (i = 0; i < count; i++) {
if (completed)
snprintf(filename, 1024, "%s/completed/%s", settings.workdir,
files[i].filename);
else
snprintf(filename, 1024, "%s/save/%s/%s", settings.workdir,
user_info.username, files[i].filename);
fd = open(filename, O_RDWR);
if (fd == -1) {
log_msg("Game file %s could not be opened in ccmd_list_games.",
files[i].filename);
continue;
}
status = nh_get_savegame_status(fd, &gi);
jobj =
json_pack("{si,si,si,ss,ss,ss,ss,ss}", "gameid", files[i].gid,
"status", status, "playmode", gi.playmode, "plname",
gi.name, "plrole", gi.plrole, "plrace", gi.plrace,
"plgend", gi.plgend, "plalign", gi.plalign);
if (status == LS_SAVED) {
json_object_set_new(jobj, "level_desc", json_string(gi.level_desc));
json_object_set_new(jobj, "moves", json_integer(gi.moves));
json_object_set_new(jobj, "depth", json_integer(gi.depth));
json_object_set_new(jobj, "has_amulet",
json_integer(gi.has_amulet));
} else if (status == LS_DONE) {
json_object_set_new(jobj, "death", json_string(gi.death));
json_object_set_new(jobj, "moves", json_integer(gi.moves));
json_object_set_new(jobj, "depth", json_integer(gi.depth));
}
json_array_append_new(jarr, jobj);
free((void *)files[i].username);
free((void *)files[i].filename);
close(fd);
}
free(files);
client_msg("list_games", json_pack("{so}", "games", jarr));
}
开发者ID:clockfort,项目名称:bingehack4,代码行数:64,代码来源:clientcmd.c
示例4: main
int main()
{
json_t *json;
char *result;
/* Encode an empty object/array, add an item, encode again */
json = json_object();
result = json_dumps(json, 0);
if(!result || strcmp(result, "{}"))
fail("json_dumps failed");
free(result);
json_object_set_new(json, "foo", json_integer(5));
result = json_dumps(json, 0);
if(!result || strcmp(result, "{\"foo\": 5}"))
fail("json_dumps failed");
free(result);
json_decref(json);
json = json_array();
result = json_dumps(json, 0);
if(!result || strcmp(result, "[]"))
fail("json_dumps failed");
free(result);
json_array_append_new(json, json_integer(5));
result = json_dumps(json, 0);
if(!result || strcmp(result, "[5]"))
fail("json_dumps failed");
free(result);
json_decref(json);
/* Construct a JSON object/array with a circular reference:
object: {"a": {"b": {"c": <circular reference to $.a>}}}
array: [[[<circular reference to the $[0] array>]]]
Encode it, remove the circular reference and encode again.
*/
json = json_object();
json_object_set_new(json, "a", json_object());
json_object_set_new(json_object_get(json, "a"), "b", json_object());
json_object_set(json_object_get(json_object_get(json, "a"), "b"), "c",
json_object_get(json, "a"));
if(json_dumps(json, 0))
fail("json_dumps encoded a circular reference!");
json_object_del(json_object_get(json_object_get(json, "a"), "b"), "c");
result = json_dumps(json, 0);
if(!result || strcmp(result, "{\"a\": {\"b\": {}}}"))
fail("json_dumps failed!");
free(result);
json_decref(json);
json = json_array();
json_array_append_new(json, json_array());
json_array_append_new(json_array_get(json, 0), json_array());
json_array_append(json_array_get(json_array_get(json, 0), 0),
json_array_get(json, 0));
if(json_dumps(json, 0))
fail("json_dumps encoded a circular reference!");
json_array_remove(json_array_get(json_array_get(json, 0), 0), 0);
result = json_dumps(json, 0);
if(!result || strcmp(result, "[[[]]]"))
fail("json_dumps failed!");
free(result);
json_decref(json);
return 0;
}
开发者ID:derdewey,项目名称:jansson,代码行数:80,代码来源:test_dump.c
示例5: AlertJsonDecoderEvent
static int AlertJsonDecoderEvent(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
{
int i;
char timebuf[64];
json_t *js;
if (p->alerts.cnt == 0)
return TM_ECODE_OK;
CreateIsoTimeString(&p->ts, timebuf, sizeof(timebuf));
for (i = 0; i < p->alerts.cnt; i++) {
MemBufferReset(aft->json_buffer);
const PacketAlert *pa = &p->alerts.alerts[i];
if (unlikely(pa->s == NULL)) {
continue;
}
char *action = "allowed";
if (pa->action & (ACTION_REJECT|ACTION_REJECT_DST|ACTION_REJECT_BOTH)) {
action = "blocked";
} else if ((pa->action & ACTION_DROP) && EngineModeIsIPS()) {
action = "blocked";
}
char buf[(32 * 3) + 1];
PrintRawLineHexBuf(buf, sizeof(buf), GET_PKT_DATA(p), GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
js = json_object();
if (js == NULL)
return TM_ECODE_OK;
json_t *ajs = json_object();
if (ajs == NULL) {
json_decref(js);
return TM_ECODE_OK;
}
/* time & tx */
json_object_set_new(js, "timestamp", json_string(timebuf));
/* tuple */
//json_object_set_new(js, "srcip", json_string(srcip));
//json_object_set_new(js, "sp", json_integer(p->sp));
//json_object_set_new(js, "dstip", json_string(dstip));
//json_object_set_new(js, "dp", json_integer(p->dp));
//json_object_set_new(js, "proto", json_integer(proto));
json_object_set_new(ajs, "action", json_string(action));
json_object_set_new(ajs, "gid", json_integer(pa->s->gid));
json_object_set_new(ajs, "signature_id", json_integer(pa->s->id));
json_object_set_new(ajs, "rev", json_integer(pa->s->rev));
json_object_set_new(ajs, "signature",
json_string((pa->s->msg) ? pa->s->msg : ""));
json_object_set_new(ajs, "category",
json_string((pa->s->class_msg) ? pa->s->class_msg : ""));
json_object_set_new(ajs, "severity", json_integer(pa->s->prio));
if (p->tenant_id > 0)
json_object_set_new(ajs, "tenant_id", json_integer(p->tenant_id));
/* alert */
json_object_set_new(js, "alert", ajs);
OutputJSONBuffer(js, aft->file_ctx, &aft->json_buffer);
json_object_clear(js);
json_decref(js);
}
return TM_ECODE_OK;
}
开发者ID:P1sec,项目名称:suricata,代码行数:71,代码来源:output-json-alert.c
示例6: vGenPASP2PCONFCREATEMsg
/*====================================================================
* 函数名 : vGenPASP2PCONFCREATEMsg
* 功能 : PAS上报创建点对点会议信息消息
* 算法实现 :
* 参数说明 : vpd 要上报的设备
* 返回值说明: 成功 生成的消息
* 失败 NULL
* ----------------------------------------------------------------------
* 修改记录:
* 日 期 版本 修改人 走读人 修改记录
* 2015/1/26 v1.0 YLI 创建
* ====================================================================*/
json_t * vGenPASP2PCONFCREATEMsg(VPD vpd)
{
json_t *root;
json_t *p2pconfinfo;
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"));
/*p2pconfinfo*/
p2pconfinfo = json_object();
//confe164
json_object_set(p2pconfinfo,"confe164",json_string("e164"));
//confname
json_object_set(p2pconfinfo,"confname",json_string("Share"));
//bitrate
json_object_set(p2pconfinfo,"bitrate",json_string("Share"));
//begintime
json_object_set(p2pconfinfo,"begintime",json_string(saLocalTime));
//duration
json_object_set(p2pconfinfo,"duration",json_integer(1));
//caller
json_object_set(p2pconfinfo,"caller",
json_pack("{s:s,s:s,s:s,s:s}",
"devtype",vpd.saDevType,
"devname","sm",
"deve164","e164",
"devguid",vpd.saDevId));
//callee
json_object_set(p2pconfinfo,"callee",
json_pack("{s:s,s:s,s:s,s:s}",
"devtype",vpd.saDevType,
"devname","sm",
"deve164","e164",
"devguid",vpd.saDevId));
//endtime
memset(saLocalTime,0x00,sizeof saLocalTime);
GetLocalTime(saLocalTime);
json_object_set(p2pconfinfo,"endtime",json_string(saLocalTime));
json_decref(p2pconfinfo);
json_object_set(root,"p2pconfinfo",p2pconfinfo);
return root;
}
开发者ID:github188,项目名称:Ptl,代码行数:95,代码来源:ptlgenmsg.c
示例7: json_object
//.........这里部分代码省略.........
json_string(tmp)) == FAILUER)
{
json_decref(root);
vLogErr("devid set error!!!");
return NULL;
}
//devtype
if(getenv("APP_PROFILE_PATH") == NULL)
{
json_decref(root);
vLogErr("devtypes config file path error,please check evn value!!!");
return NULL;
}
strcpy(saCfgPath,getenv("APP_PROFILE_PATH"));
strcat(saCfgPath,"/devtypes.json");
jt = tPflGetJsonObj(saCfgPath,K_DEVTYPE_KEY);
if (jt == NULL)
{
json_decref(root);
vLogErr("devtypes file open error,please check devtypes.json is exist!!!");
return NULL;
}
if (json_is_array(jt))
{
size = json_array_size(jt);
n = rand()%size;
if (json_object_set(root,"devtype",
json_array_get(jt,n)) == FAILUER)
{
json_decref(root);
vLogErr("devtype set error!!!");
return NULL;
}
}
/*mt_info*/
mt_info = json_object();
//devver
if (json_object_set(mt_info,"devver",
json_string("123")) == FAILUER)
{
json_decref(root);
vLogErr("devver set error!!!");
return NULL;
}
//devname
json_object_set(mt_info,"devname",json_string("truelink"));
//netinfo
netinfo = json_object();
json_object_set(netinfo,"ip",
json_string(_gstrpShm->rc.nSrvIP));
json_object_set(netinfo,"dns",
json_string("172.16.0.65"));
json_object_set(mt_info,"netinfo",netinfo);
//aps_addr
aps_addr = json_object();
json_object_set(aps_addr,"domain",
json_string("fdaf"));
json_object_set(aps_addr,"ip",
json_string(_gstrpShm->rc.nSrvIP));
json_object_set(mt_info,"aps_addr",aps_addr);
//oem
json_object_set(mt_info,"oem",json_string("dfd"));
//os
json_object_set(mt_info,"os",json_string("Centos 6.4"));
//cpu_num
json_object_set(mt_info,"cpu_num",json_integer(4));
//cpu_type
//cpu_freq
json_decref(jt);
jt = GetCpuInfo();
json_object_foreach(jt,key,value)
{
if(strncmp(key,"cpuMHz",6) == 0)
{
json_object_set(mt_info,"cpu_freq",value);
}
if (strncmp(key,"modelname",9) == 0)
{
json_object_set(mt_info,"cpu_type",value);
}
}
json_decref(jt);
jt = GetMemInfo();
//memory
json_object_foreach(jt,key,value)
{
if(strncmp(key,"MemTotal",8) == 0)
{
json_object_set(mt_info,"memory",value);
}
}
json_object_set(root,"mt_info",mt_info);
json_decref(mt_info);
return root;
}
开发者ID:github188,项目名称:Ptl,代码行数:101,代码来源:ptlgenmsg.c
示例8: json_object_get
static json_t *member_data_to_json(const json_t *member, const qeocore_data_t *data)
{
json_t *json_data = NULL;
json_t *id = json_object_get(member, KEY_ID); // Mandatory
json_t *type = json_object_get(member, KEY_QEO_TYPE_CODE); // Mandatory
if ((NULL == id) || (!json_is_integer(id)) ||
(NULL == type) || (!json_is_integer(type))) {
return json_data;
}
qeocore_member_id_t qeo_member_id = (qeocore_member_id_t) json_integer_value(id);
qeocore_typecode_t qeoTypeCode = (qeocore_typecode_t) json_integer_value(type);
switch (qeoTypeCode) {
case QEOCORE_TYPECODE_BOOLEAN:
{
qeo_boolean_t bool_value = 0;
if (QEO_OK == qeocore_data_get_member(data, qeo_member_id, &bool_value)) {
json_data = bool_value ? (json_true()) : (json_false());
}
}
break;
case QEOCORE_TYPECODE_INT8:
{
int8_t int_value;
if (QEO_OK == qeocore_data_get_member(data, qeo_member_id, &int_value)) {
json_data = json_integer(int_value);
}
}
break;
case QEOCORE_TYPECODE_INT16:
{
int16_t int_value;
if (QEO_OK == qeocore_data_get_member(data, qeo_member_id, &int_value)) {
json_data = json_integer(int_value);
}
}
break;
case QEOCORE_TYPECODE_INT32:
{
int32_t int_value;
if (QEO_OK == qeocore_data_get_member(data, qeo_member_id, &int_value)) {
json_data = json_integer(int_value);
}
}
break;
case QEOCORE_TYPECODE_INT64:
{
int64_t int_value;
if (QEO_OK == qeocore_data_get_member(data, qeo_member_id, &int_value)) {
char *char_value = NULL;
if (-1 != asprintf(&char_value, "%" PRId64 "", int_value)) {
json_data = json_string(char_value);
free(char_value);
}
}
}
break;
case QEOCORE_TYPECODE_FLOAT32:
{
float float_value;
if (QEO_OK == qeocore_data_get_member(data, qeo_member_id, &float_value)) {
json_data = json_real(float_value);
}
}
break;
case QEOCORE_TYPECODE_STRING:
{
char *char_value;
if (QEO_OK == qeocore_data_get_member(data, qeo_member_id, &char_value)) {
json_data = json_string(char_value);
free(char_value);
}
}
break;
case QEOCORE_TYPECODE_STRUCT:
{
qeocore_data_t *qeo_data = NULL;
do {
json_t *item = json_object_get(member, KEY_ITEM);
if (NULL == item) {
qeo_log_e("NULL == item");
break;
}
if (!json_is_object(item)) {
qeo_log_e("not an object");
break;
}
if (QEO_OK != qeocore_data_get_member(data, qeo_member_id, &qeo_data)) {
qeo_log_e("qeocore_data_get_member failed");
//.........这里部分代码省略.........
开发者ID:JianlongCao,项目名称:qeo-core,代码行数:101,代码来源:json_types_util.c
示例9: FileWriteJsonRecord
/**
* \internal
* \brief Write meta data on a single line json record
*/
static void FileWriteJsonRecord(JsonFileLogThread *aft, const Packet *p, const File *ff) {
MemBuffer *buffer = (MemBuffer *)aft->buffer;
json_t *js = CreateJSONHeader((Packet *)p, 0, "file"); //TODO const
if (unlikely(js == NULL))
return;
/* reset */
MemBufferReset(buffer);
json_t *hjs = json_object();
if (unlikely(hjs == NULL)) {
json_decref(js);
return;
}
json_object_set_new(hjs, "url", LogFileMetaGetUri(p, ff));
json_object_set_new(hjs, "hostname", LogFileMetaGetHost(p, ff));
json_object_set_new(hjs, "http_refer", LogFileMetaGetReferer(p, ff));
json_object_set_new(hjs, "http_user_agent", LogFileMetaGetUserAgent(p, ff));
json_object_set_new(js, "http", hjs);
json_t *fjs = json_object();
if (unlikely(fjs == NULL)) {
json_decref(hjs);
json_decref(js);
return;
}
char *s = BytesToString(ff->name, ff->name_len);
json_object_set_new(fjs, "filename", json_string(s));
if (s != NULL)
SCFree(s);
if (ff->magic)
json_object_set_new(fjs, "magic", json_string((char *)ff->magic));
else
json_object_set_new(fjs, "magic", json_string("unknown"));
switch (ff->state) {
case FILE_STATE_CLOSED:
json_object_set_new(fjs, "state", json_string("CLOSED"));
#ifdef HAVE_NSS
if (ff->flags & FILE_MD5) {
size_t x;
int i;
char *s = SCMalloc(256);
if (likely(s != NULL)) {
for (i = 0, x = 0; x < sizeof(ff->md5); x++) {
i += snprintf(&s[i], 255-i, "%02x", ff->md5[x]);
}
json_object_set_new(fjs, "md5", json_string(s));
SCFree(s);
}
}
#endif
break;
case FILE_STATE_TRUNCATED:
json_object_set_new(fjs, "state", json_string("TRUNCATED"));
break;
case FILE_STATE_ERROR:
json_object_set_new(fjs, "state", json_string("ERROR"));
break;
default:
json_object_set_new(fjs, "state", json_string("UNKNOWN"));
break;
}
json_object_set_new(fjs, "stored",
(ff->flags & FILE_STORED) ? json_true() : json_false());
json_object_set_new(fjs, "size", json_integer(ff->size));
json_object_set_new(js, "file", fjs);
OutputJSONBuffer(js, aft->filelog_ctx->file_ctx, buffer);
json_object_del(js, "file");
json_object_del(js, "http");
json_object_clear(js);
json_decref(js);
}
开发者ID:awick,项目名称:suricata,代码行数:80,代码来源:output-json-file.c
示例10: json_integer
static json_t *json_integer_copy(json_t *integer)
{
return json_integer(json_integer_value(integer));
}
开发者ID:dcollien,项目名称:Humperdink-C,代码行数:4,代码来源:value.c
示例11: data
Json::Json( int64_t v ): data(json_integer(v))
{
}
开发者ID:kibae,项目名称:defer.io,代码行数:3,代码来源:JSON.cpp
示例12: throw
void AsisScript::pre_judge() throw (Exception)
{
ScriptProps::Property& service_prop = type_spec_props->get_property("service");
if (!service_prop.Evaluable::finished())
throw_error_v(ErrorScriptFmtError,"asis producer script service should be determinated");
ScriptProps::Property& resource_prop = type_spec_props->get_property("resource");
if (!resource_prop.Evaluable::finished())
throw_error_v(ErrorScriptFmtError,"asis producer script resource should be determinated");
json_t* svc_value = service_prop.compile();
json_t* res_value = resource_prop.compile();
JsonWrap svc_wrap(svc_value,1);
JsonWrap res_wrap(res_value,1);
if ( !svc_value || !json_is_string(svc_value) || !strlen(json_string_value(svc_value)))
throw_error_v(ErrorScriptFmtError,"asis producer script service should be string value");
if ( !res_value || !json_is_string(res_value) || !strlen(json_string_value(res_value)))
throw_error_v(ErrorScriptFmtError,"asis producer script resource should be string value");
mlt_profile prof = mlt_profile_clone(MltLoader::global_profile);
mlt_producer tmp_prod = mlt_factory_producer(prof, json_string_value(svc_value), json_string_value(res_value));
MltSvcWrap prod_wrap(mlt_producer_service(tmp_prod), 1);
if (tmp_prod == NULL) {
throw_error_v(ErrorRuntimeLoadFailed, "producer %s load failed", json_string_value(svc_value));
}
if ( mlt_props ) {
ScriptProps::PropIter it = mlt_props->begin();
for ( ; it!=mlt_props->end(); it++) {
if ( it->second->Evaluable::finished() ) {
json_t* prop_v = it->second->compile();
JsonWrap prop_wrap(prop_v, 1);
switch(prop_v->type) {
case JSON_INTEGER:
mlt_properties_set_int64(mlt_producer_properties(tmp_prod),
it->first.c_str(), json_integer_value(prop_v));
break;
case JSON_REAL:
mlt_properties_set_double(mlt_producer_properties(tmp_prod),
it->first.c_str(), json_real_value(prop_v));
break;
case JSON_STRING:
mlt_properties_set(mlt_producer_properties(tmp_prod),
it->first.c_str(), json_string_value(prop_v));
break;
case JSON_TRUE:
mlt_properties_set_int(mlt_producer_properties(tmp_prod),
it->first.c_str(), 1);
break;
case JSON_FALSE:
mlt_properties_set_int(mlt_producer_properties(tmp_prod),
it->first.c_str(), 0);
break;
default:
throw_error_v(ErrorRuntimeLoadFailed, "producer %s load failed. %s prop invalid",
json_string_value(svc_value), it->first.c_str());
}
}
}
}
int in = mlt_producer_get_in(tmp_prod);
int out = mlt_producer_get_out(tmp_prod);
set_frame_range(in, out);
if ( !mlt_props.get()) {
mlt_props.reset(new ScriptProps(*this, NULL));
}
json_t* jv = json_integer(in);
mlt_props->add_property("in", jv);
json_decref(jv);
jv = json_integer(out);
mlt_props->add_property("out", jv);
json_decref(jv);
string uuid = Vm::uuid();
type_spec_props->add_property("uuid", JsonWrap(json_string(uuid.c_str()),1).h);
prod_wrap.obj = NULL;
MltLoader::push_mlt_registry(mlt_producer_service(tmp_prod), uuid.c_str());
}
开发者ID:amongll,项目名称:AVFX,代码行数:84,代码来源:VEditProducerScript.cpp
示例13: JANUS_LOG
/* Thread to handle incoming messages */
static void *janus_streaming_handler(void *data) {
JANUS_LOG(LOG_VERB, "Joining thread\n");
janus_streaming_message *msg = NULL;
int error_code = 0;
char *error_cause = calloc(1024, sizeof(char));
if(error_cause == NULL) {
JANUS_LOG(LOG_FATAL, "Memory error!\n");
return NULL;
}
while(initialized && !stopping) {
if(!messages || (msg = g_queue_pop_head(messages)) == NULL) {
usleep(50000);
continue;
}
janus_streaming_session *session = (janus_streaming_session *)msg->handle->plugin_handle;
if(!session) {
JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
janus_streaming_message_free(msg);
continue;
}
if(session->destroy) {
janus_streaming_message_free(msg);
continue;
}
/* Handle request */
error_code = 0;
JANUS_LOG(LOG_VERB, "Handling message: %s\n", msg->message);
if(msg->message == NULL) {
JANUS_LOG(LOG_ERR, "No message??\n");
error_code = JANUS_STREAMING_ERROR_NO_MESSAGE;
sprintf(error_cause, "%s", "No message??");
goto error;
}
json_error_t error;
json_t *root = json_loads(msg->message, 0, &error);
if(!root) {
JANUS_LOG(LOG_ERR, "JSON error: on line %d: %s\n", error.line, error.text);
error_code = JANUS_STREAMING_ERROR_INVALID_JSON;
sprintf(error_cause, "JSON error: on line %d: %s", error.line, error.text);
goto error;
}
if(!json_is_object(root)) {
JANUS_LOG(LOG_ERR, "JSON error: not an object\n");
error_code = JANUS_STREAMING_ERROR_INVALID_JSON;
sprintf(error_cause, "JSON error: not an object");
goto error;
}
json_t *request = json_object_get(root, "request");
if(!request) {
JANUS_LOG(LOG_ERR, "Missing element (request)\n");
error_code = JANUS_STREAMING_ERROR_MISSING_ELEMENT;
sprintf(error_cause, "Missing element (request)");
goto error;
}
if(!json_is_string(request)) {
JANUS_LOG(LOG_ERR, "Invalid element (request should be a string)\n");
error_code = JANUS_STREAMING_ERROR_INVALID_ELEMENT;
sprintf(error_cause, "Invalid element (request should be a string)");
goto error;
}
const char *request_text = json_string_value(request);
json_t *result = NULL;
char *sdp_type = NULL, *sdp = NULL;
if(!strcasecmp(request_text, "list")) {
result = json_object();
json_t *list = json_array();
JANUS_LOG(LOG_VERB, "Request for the list of mountpoints\n");
/* Return a list of all available mountpoints */
GList *mountpoints_list = g_hash_table_get_values(mountpoints);
GList *m = mountpoints_list;
while(m) {
janus_streaming_mountpoint *mp = (janus_streaming_mountpoint *)m->data;
json_t *ml = json_object();
json_object_set_new(ml, "id", json_integer(mp->id));
json_object_set_new(ml, "description", json_string(mp->description));
json_object_set_new(ml, "type", json_string(mp->streaming_type == janus_streaming_type_live ? "live" : "on demand"));
json_array_append_new(list, ml);
m = m->next;
}
json_object_set_new(result, "list", list);
g_list_free(mountpoints_list);
} else if(!strcasecmp(request_text, "watch")) {
json_t *id = json_object_get(root, "id");
if(id && !json_is_integer(id)) {
JANUS_LOG(LOG_ERR, "Invalid element (id should be an integer)\n");
error_code = JANUS_STREAMING_ERROR_INVALID_ELEMENT;
sprintf(error_cause, "Invalid element (id should be an integer)");
goto error;
}
gint64 id_value = json_integer_value(id);
janus_streaming_mountpoint *mp = g_hash_table_lookup(mountpoints, GINT_TO_POINTER(id_value));
if(mp == NULL) {
JANUS_LOG(LOG_VERB, "No such mountpoint/stream %"SCNu64"\n", id_value);
error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT;
sprintf(error_cause, "No such mountpoint/stream %"SCNu64"", id_value);
goto error;
}
JANUS_LOG(LOG_VERB, "Request to watch mountpoint/stream %"SCNu64"\n", id_value);
session->stopping = FALSE;
//.........这里部分代码省略.........
开发者ID:michaelsharpe,项目名称:janus-gateway,代码行数:101,代码来源:janus_streaming.c
示例14: vGenMCUINFOMsg
/*====================================================================
* 函数名 : vGenMCUINFOMsg
* 功能 : 12.1 MCU上报逻辑服务器基本信息消息
* 算法实现 :
* 参数说明 : vpd 要上报的设备
* 返回值说明: 成功 生成的消息
* 失败 NULL
* ----------------------------------------------------------------------
* 修改记录:
* 日 期 版本 修改人 走读人 修改记录
* 2015/1/26 v1.0 YLI 创建
* ====================================================================*/
json_t * vGenMCUINFOMsg(VPD vpd)
{
json_t *root;
json_t *mcuinfo;
int res;
char saLocalTime[256];
root = json_object();
//eventid
if (json_object_set(root,"eventid",
json_string("EV_MCU_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;
}
//pidchange
json_object_set(root,"pidchange",json_false());
//version
json_object_set(root,"version",json_string("1.06"));
//belongphy
json_object_set(root,"belongphy",json_string("1123"));
/*mcuinfo*/
mcuinfo = json_object();
//traditionconfcount
json_object_set(mcuinfo,"traditionconfcount",json_integer(123));
//portconfcount
json_object_set(mcuinfo,"portconfcount",json_integer(123));
//spttraditionconfcount
json_object_set(mcuinfo,"spttraditionconfcount",json_integer(123));
//sptportconfcount
json_object_set(mcuinfo,"sptportconfcount",json_integer(123));
//multiconfmtcount
json_object_set(mcuinfo,"multiconfmtcount",json_integer(123));
//connectedmpcd
json_object_set(mcuinfo,"connectedmpcd",json_true());
//connectedbmc
json_object_set(mcuinfo,"connectedbmc",json_true());
//connectednucount
json_object_set(mcuinfo,"connectednucount",json_integer(123));
//connectedmpcount
json_object_set(mcuinfo,"connectedmpcount",json_integer(123));
//connectedmpcadaptcount
json_object_set(mcuinfo,"connectedmpcadaptcount",json_integer(123));
//connectedprscount
json_object_set(mcuinfo,"connectedprscount",json_integer(123));
//connectednuinfo
res = json_object_set(mpcdinfo,"connectednuinfo",
json_pack("[{s:b,s:s},{s:b,s:s}]",
"connectedstate",1,
"connectedip",_gstrpShm->rc.nSrvIP,
"connectedstate",1,
"connectedip",_gstrpShm->rc.nSrvIP));
if (res == FAILUER)
{
json_decref(root);
vLogErr("connectednuinfo set error!!!");
return NULL;
}
//connectedmpinfo
//.........这里部分代码省略.........
开发者ID:github188,项目名称:Ptl,代码行数:101,代码来源:ptlgenmsg.c
示例15: run_tests
/* Call the simple functions not covered by other tests of the public API */
static void run_tests()
{
json_t *value;
value = json_boolean(1);
if(!json_is_true(value))
fail("json_boolean(1) failed");
json_decref(value);
value = json_boolean(-123);
if(!json_is_true(value))
fail("json_boolean(-123) failed");
json_decref(value);
value = json_boolean(0);
if(!json_is_false(value))
fail("json_boolean(0) failed");
json_decref(value);
value = json_integer(1);
if(json_typeof(value) != JSON_INTEGER)
fail("json_typeof failed");
if(json_is_object(value))
fail("json_is_object failed");
if(json_is_array(value))
fail("json_is_array failed");
if(json_is_string(value))
fail("json_is_string failed");
if(!json_is_integer(value))
fail("json_is_integer failed");
if(json_is_real(value))
fail("json_is_real failed");
if(!json_is_number(value))
fail("json_is_number failed");
if(json_is_true(value))
fail("json_is_true failed");
if(json_is_false(value))
fail("json_is_false failed");
if(json_is_boolean(value))
fail("json_is_boolean failed");
if(json_is_null(value))
fail("json_is_null failed");
json_decref(value);
value = json_string("foo");
if(!value)
fail("json_string failed");
if(strcmp(json_string_value(value), "foo"))
fail("invalid string value");
if (json_string_length(value) != 3)
fail("invalid string length");
if(json_string_set(value, "barr"))
fail("json_string_set failed");
if(strcmp(json_string_value(value), "barr"))
fail("invalid string value");
if (json_string_length(value) != 4)
fail("invalid string length");
if(json_string_setn(value, "hi\0ho", 5))
fail("json_string_set failed");
if(memcmp(json_string_value(value), "hi\0ho\0", 6))
fail("invalid string value");
if (json_string_length(value) != 5)
fail("invalid string length");
json_decref(value);
value = json_string(NULL);
if(value)
fail("json_string(NULL) failed");
/* invalid UTF-8 */
value = json_string("a\xefz");
if(value)
fail("json_string(<invalid utf-8>) failed");
value = json_string_nocheck("foo");
if(!value)
fail("json_string_nocheck failed");
if(strcmp(json_string_value(value), "foo"))
fail("invalid string value");
if (json_string_length(value) != 3)
fail("invalid string length");
if(json_string_set_nocheck(value, "barr"))
//.........这里部分代码省略.........
开发者ID:Alucard014,项目名称:obs-studio,代码行数:101,代码来源:test_simple.c
示例16: vGenPFMINFONETCARDMsg
/*================================================
|
请发表评论