static void* ac_json_80211_ofdmcontrol_createmessageelement(struct json_object* jsonparent, uint16_t radioid) {
	struct json_object* jsonitem;
	struct capwap_80211_ofdmcontrol_element* ofdmcontrol;

	ofdmcontrol = (struct capwap_80211_ofdmcontrol_element*)capwap_alloc(sizeof(struct capwap_80211_ofdmcontrol_element));
	memset(ofdmcontrol, 0, sizeof(struct capwap_80211_ofdmcontrol_element));
	ofdmcontrol->radioid = radioid;

	/* */
	jsonitem = compat_json_object_object_get(jsonparent, "CurrentChan");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		ofdmcontrol->currentchannel = (uint8_t)json_object_get_int(jsonitem);
	} else {
		capwap_free(ofdmcontrol);
		return NULL;
	}

	jsonitem = compat_json_object_object_get(jsonparent, "BandSupport");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		ofdmcontrol->bandsupport = (uint8_t)json_object_get_int(jsonitem) & CAPWAP_OFDMCONTROL_BAND_MASK;
	} else {
		capwap_free(ofdmcontrol);
		return NULL;
	}

	jsonitem = compat_json_object_object_get(jsonparent, "TIThreshold");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		ofdmcontrol->tithreshold = (uint32_t)json_object_get_int(jsonitem);
	} else {
		capwap_free(ofdmcontrol);
		return NULL;
	}

	return ofdmcontrol;
}
static void* ac_json_80211_wtpradiofailalarm_createmessageelement(struct json_object* jsonparent, uint16_t radioid) {
	struct json_object* jsonitem;
	struct capwap_80211_wtpradiofailalarm_element* wtpradiofailalarm;

	wtpradiofailalarm = (struct capwap_80211_wtpradiofailalarm_element*)capwap_alloc(sizeof(struct capwap_80211_wtpradiofailalarm_element));
	memset(wtpradiofailalarm, 0, sizeof(struct capwap_80211_wtpradiofailalarm_element));
	wtpradiofailalarm->radioid = radioid;

	/* */
	jsonitem = compat_json_object_object_get(jsonparent, "Type");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		wtpradiofailalarm->type = (uint8_t)json_object_get_int(jsonitem);
	} else {
		capwap_free(wtpradiofailalarm);
		return NULL;
	}

	/* */
	jsonitem = compat_json_object_object_get(jsonparent, "Status");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		wtpradiofailalarm->status = (uint8_t)json_object_get_int(jsonitem);
	} else {
		capwap_free(wtpradiofailalarm);
		return NULL;
	}

	return wtpradiofailalarm;
}
Beispiel #3
0
static int init(const char *config_file,const char *orderid_file)
{	
	
	int fd_order;
	request = ghttp_request_new();
	my_object = json_object_from_file(config_file); 
	machine_id = json_object_get_int(json_object_object_get(my_object,MACHINE_ID));
	info_version = json_object_get_int(json_object_object_get(my_object,INFO_VERSION));
	format_qrcode = json_object_get_string(json_object_object_get(my_object,ENCODE_FORMAT));
	fd_order=open(orderid_file,O_RDWR);
	if(fd_order==-1)
	{
		int order_id=0;
		fd_order=open(orderid_file,O_RDWR|O_CREAT,0666);
		write(fd_order,(void*)&order_id,sizeof(unsigned int));
		lseek(fd_order,0,SEEK_SET);
	}
	
	p_order_id=(unsigned int*)mmap(NULL,sizeof(unsigned int),PROT_READ|PROT_WRITE,MAP_SHARED,fd_order,0);
	if(p_order_id==-1)
		return -3;
	
	ghttp_set_uri(request, json_object_get_string(json_object_object_get(my_object,HOST)));
	ghttp_prepare(request);
	ghttp_set_sync(request, ghttp_async);
	ghttp_set_type(request, ghttp_type_post);
	ghttp_set_header(request, http_hdr_Connection, "keep-alive");

	http_request(REQ_REGISTER);
	while(http_response_process((void*)config_file)==-1);
	ghttp_flush_response_buffer(request);
	return 0;
}
Beispiel #4
0
static int http_response_process(void * arg)
{
	struct json_object *resp; 
	if(ghttp_process(request)==ghttp_done)
	{
		resp=json_tokener_parse(ghttp_get_body(request));
		resp_ret.type=json_object_get_int(json_object_object_get(resp,RESP_TYPE));
		resp_ret.result=json_object_get_int(json_object_object_get(resp,RESP_RESULT));
		if(resp_ret.type==REQ_REGISTER)
		{
			json_object_object_del(resp, RESP_TYPE);
			json_object_to_file((char *)arg,resp);
		}
		else
		{
			if((resp_ret.type==REQ_SUBMIT)&&(!resp_ret.result))
			{
				sprintf(qrcode_buf,format_qrcode,machine_id,*p_order_id,info_version);
				pid_t pid=vfork();
				if(!pid)
					execlp("qrencode","qrencode","-s 6","-m 2","-lH","-oqrcode.png",qrcode_buf,0);
				else
					wait(NULL);
			}
		}
		json_object_put(resp);
		return 0;
	}
	else
		return -1;

}
Beispiel #5
0
static int process_msg(void *msg,int len)
{
    char *body = (char *)msg + HEADER_LEN;
    json_object *jmsg = json_tokener_parse(body);
    if(!jmsg)
	return -1;
    json_object *jsccmd = json_util_get(jmsg,"cmd");
    if(!jsccmd)
	return -1;
    int sccmd = json_object_get_int(jsccmd);
    
    json_object *jcmcmd = json_util_get(jmsg,"msg.cmd");
    int cmcmd = json_object_get_int(jcmcmd);

    switch(sccmd){
	case MSGID_RESPONSE_EXECPROC:
	    switch (cmcmd){
		case MSGID_REQUEST_NEWACCOUNT:
		    sc_logic_createaccount(jmsg);
		    break;
		case MSGID_REQUEST_LOGIN:
		    sc_logic_login(jmsg);
		    break;
	    }
	    break;
    }

    json_object_put(jmsg);

    return 0;
}
Beispiel #6
0
telebot_error_e telebot_parser_get_audio(struct json_object *obj,
        telebot_audio_t *audio)
{
    if (obj == NULL)
        return TELEBOT_ERROR_INVALID_PARAMETER;

    if (audio == NULL)
        return TELEBOT_ERROR_INVALID_PARAMETER;
    memset(audio, 0, sizeof(telebot_audio_t));

    struct json_object *file_id;
    if (json_object_object_get_ex(obj, "file_id", &file_id)) {
        snprintf(audio->file_id, TELEBOT_FILE_ID_SIZE, "%s",
                json_object_get_string(file_id));
        json_object_put(file_id);
    }
    else {
        ERR("Object is not audio type, file_id not found");
        return TELEBOT_ERROR_OPERATION_FAILED;
    }

    struct json_object *duration;
    if (json_object_object_get_ex(obj, "duration", &duration)){
        audio->duration = json_object_get_int(duration);
        json_object_put(duration);
    }
    else {
        ERR("Object is not audio type, duration not found");
        return TELEBOT_ERROR_OPERATION_FAILED;
    }

    struct json_object *performer;
    if (json_object_object_get_ex(obj, "performer", &performer)) {
        snprintf(audio->performer, TELEBOT_AUDIO_PERFORMER_SIZE, "%s",
                json_object_get_string(performer));
        json_object_put(performer);
    }

    struct json_object *title;
    if (json_object_object_get_ex(obj, "title", &title)) {
        snprintf(audio->title, TELEBOT_AUDIO_TITLE_SIZE, "%s",
                json_object_get_string(title));
        json_object_put(title);
    }

    struct json_object *mime_type;
    if (json_object_object_get_ex(obj, "mime_type", &mime_type)) {
        snprintf(audio->mime_type, TELEBOT_AUDIO_MIME_TYPE_SIZE, "%s",
                json_object_get_string(mime_type));
        json_object_put(mime_type);
    }

    struct json_object *file_size;
    if (json_object_object_get_ex(obj, "file_size", &file_size)) {
        audio->file_size = json_object_get_int(file_size);
        json_object_put(file_size);
    }

    return TELEBOT_ERROR_NONE;
}
Beispiel #7
0
static void pretty_print_output(json_object *o) {
	json_object *name, *rect, *focused, *active, *ws, *scale;
	json_object_object_get_ex(o, "name", &name);
	json_object_object_get_ex(o, "rect", &rect);
	json_object_object_get_ex(o, "focused", &focused);
	json_object_object_get_ex(o, "active", &active);
	json_object_object_get_ex(o, "current_workspace", &ws);
	json_object_object_get_ex(o, "scale", &scale);
	json_object *x, *y, *width, *height;
	json_object_object_get_ex(rect, "x", &x);
	json_object_object_get_ex(rect, "y", &y);
	json_object_object_get_ex(rect, "width", &width);
	json_object_object_get_ex(rect, "height", &height);
	printf(
		"Output %s%s%s\n"
		"  Geometry: %dx%d @ %d,%d\n"
		"  Scale factor: %dx\n"
		"  Workspace: %s\n\n",
		json_object_get_string(name),
		json_object_get_boolean(focused) ? " (focused)" : "",
		!json_object_get_boolean(active) ? " (inactive)" : "",
		json_object_get_int(width), json_object_get_int(height),
		json_object_get_int(x), json_object_get_int(y),
		json_object_get_int(scale),
		json_object_get_string(ws)
	);
}
bool Bitmaszyna::lasttrades(string market)
{    
    struct json_object *json,*jtmp,*jtmp2;
    struct array_list *arr;
    int i;

    curl_mutex.lock();
    trades.clear();
    if (getTickerData(market+"/transactions.json",&json))
    {
        arr=json_object_get_array(json);
        for(i=0;i<arr->length;i++)
        {
            Offer offer;
            jtmp=(struct json_object *)array_list_get_idx(arr,i);
            json_object_object_get_ex(jtmp,"date",&jtmp2);
            offer.time=json_object_get_int64(jtmp2);
            json_object_object_get_ex(jtmp,"price",&jtmp2);
            offer.price=json_object_get_double(jtmp2);
            json_object_object_get_ex(jtmp,"amount",&jtmp2);
            offer.amount=json_object_get_double(jtmp2);
            json_object_object_get_ex(jtmp,"type",&jtmp2);
            offer.type=json_object_get_int(jtmp2);
            json_object_object_get_ex(jtmp,"type",&jtmp2);
            offer.id=json_object_get_int(jtmp2);
            trades.push_back(offer);
        }
        json_object_put(json);
        curl_mutex.unlock();
        return(true);
    }
    curl_mutex.unlock();
    return(false);
}
Beispiel #9
0
static int cli_lacp_getpartnerinterface(void *c_sys, int argc, cli_args_t *args)
{
	short unsigned int *pusportpriority;
	unsigned char *pucstate;
	short unsigned int *puskey;
	unsigned char *pucsystemid;
	long unsigned int *pulmaclen;
	int port = port_to_num(args[0].value);

#if 0
	LACP_GetAggPortPartnerPortPriority(port, pusportpriority);
	usleep(10000);
	LACP_GetAggPortPartnerState(port, pucstate);
	usleep(10000);
	LACP_GetAggPortPartnerOperKey(port, puskey);
	usleep(10000);
	LACP_GetAggPortPartnerSystemId(port, pucsystemid, pulmaclen);
	return 0;
#endif

#if 1
	processFlag_dislacp = 1;
	LACP_GetAggPortPartnerPortPriority(port, pusportpriority);
	struct json_object *new_obj1 = NULL;
	new_obj1 = json_tokener_parse(msg_lacp->msg);
	struct json_object *obj1 = json_object_object_get(new_obj1, "PortPartnerPortPriority");
	printf("  PortPartnerPortPriority        :%d\n", json_object_get_int(obj1));
	json_object_put(obj1);
	json_object_put(new_obj1);	
	processFlag_dislacp = 1;
	LACP_GetAggPortPartnerState(port, pucstate);
	struct json_object *new_obj2 = NULL;
	new_obj2 = json_tokener_parse(msg_lacp->msg);
	struct json_object *obj2 = json_object_object_get(new_obj2, "PortPartnerState");
	printf("  PortPartnerState               :%d\n", json_object_get_int(obj2));
	json_object_put(obj2);
	json_object_put(new_obj2);	
	processFlag_dislacp = 1;
	LACP_GetAggPortPartnerOperKey(port, puskey);
	struct json_object *new_obj3 = NULL;
	new_obj3 = json_tokener_parse(msg_lacp->msg);
	struct json_object *obj3 = json_object_object_get(new_obj3, "PortPartnerOperKey");
	printf("  PortPartnerOperKey             :%d\n", json_object_get_int(obj3));
	json_object_put(obj3);
	json_object_put(new_obj3);	
	processFlag_dislacp = 1;
	LACP_GetAggPortPartnerSystemId(port, pucsystemid, pulmaclen);
	struct json_object *new_obj4 = NULL;
	new_obj4 = json_tokener_parse(msg_lacp->msg);
	struct json_object *obj4 = json_object_object_get(new_obj4, "PortPartnerSystemId");

	printf("  PortPartnerSystemId            :%d\n", json_object_get_int(obj4));
	json_object_put(obj4);
	json_object_put(new_obj4);	
	processFlag_dislacp = 0;
	return 0;
#endif
}
OSStatus ConfigIncommingJsonMessage( const char *input, mico_Context_t * const inContext )
{
  OSStatus err = kNoErr;
  json_object *new_obj;
  config_delegate_log_trace();

  new_obj = json_tokener_parse(input);
  require_action(new_obj, exit, err = kUnknownErr);
  config_delegate_log("Recv config object=%s", json_object_to_json_string(new_obj));
  mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex);
  json_object_object_foreach(new_obj, key, val) {
    if(!strcmp(key, "Device Name")){
      strncpy(inContext->flashContentInRam.micoSystemConfig.name, json_object_get_string(val), maxNameLen);
    }else if(!strcmp(key, "RF power save")){
      inContext->flashContentInRam.micoSystemConfig.rfPowerSaveEnable = json_object_get_boolean(val);
    }else if(!strcmp(key, "MCU power save")){
      inContext->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable = json_object_get_boolean(val);
    }else if(!strcmp(key, "Bonjour")){
      inContext->flashContentInRam.micoSystemConfig.bonjourEnable = json_object_get_boolean(val);
    }else if(!strcmp(key, "Wi-Fi")){
      strncpy(inContext->flashContentInRam.micoSystemConfig.ssid, json_object_get_string(val), maxSsidLen);
      inContext->flashContentInRam.micoSystemConfig.channel = 0;
      memset(inContext->flashContentInRam.micoSystemConfig.bssid, 0x0, 6);
      inContext->flashContentInRam.micoSystemConfig.security = SECURITY_TYPE_AUTO;
      memcpy(inContext->flashContentInRam.micoSystemConfig.key, inContext->flashContentInRam.micoSystemConfig.user_key, maxKeyLen);
      inContext->flashContentInRam.micoSystemConfig.keyLength = inContext->flashContentInRam.micoSystemConfig.user_keyLength;
    }else if(!strcmp(key, "Password")){
      inContext->flashContentInRam.micoSystemConfig.security = SECURITY_TYPE_AUTO;
      strncpy(inContext->flashContentInRam.micoSystemConfig.key, json_object_get_string(val), maxKeyLen);
      strncpy(inContext->flashContentInRam.micoSystemConfig.user_key, json_object_get_string(val), maxKeyLen);
      inContext->flashContentInRam.micoSystemConfig.keyLength = strlen(inContext->flashContentInRam.micoSystemConfig.key);
      inContext->flashContentInRam.micoSystemConfig.user_keyLength = strlen(inContext->flashContentInRam.micoSystemConfig.key);
    }else if(!strcmp(key, "DHCP")){
      inContext->flashContentInRam.micoSystemConfig.dhcpEnable   = json_object_get_boolean(val);
    }else if(!strcmp(key, "IP address")){
      strncpy(inContext->flashContentInRam.micoSystemConfig.localIp, json_object_get_string(val), maxIpLen);
    }else if(!strcmp(key, "Net Mask")){
      strncpy(inContext->flashContentInRam.micoSystemConfig.netMask, json_object_get_string(val), maxIpLen);
    }else if(!strcmp(key, "Gateway")){
      strncpy(inContext->flashContentInRam.micoSystemConfig.gateWay, json_object_get_string(val), maxIpLen);
    }else if(!strcmp(key, "DNS Server")){
      strncpy(inContext->flashContentInRam.micoSystemConfig.dnsServer, json_object_get_string(val), maxIpLen);
    }else if(!strcmp(key, "Connect SPP Server")){
      inContext->flashContentInRam.appConfig.remoteServerEnable = json_object_get_boolean(val);
    }else if(!strcmp(key, "SPP Server")){
      strncpy(inContext->flashContentInRam.appConfig.remoteServerDomain, json_object_get_string(val), 64);
    }else if(!strcmp(key, "SPP Server Port")){
      inContext->flashContentInRam.appConfig.remoteServerPort = json_object_get_int(val);
    }else if(!strcmp(key, "Baurdrate")){
      inContext->flashContentInRam.appConfig.USART_BaudRate = json_object_get_int(val);
    }
  }
  json_object_put(new_obj);
  mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex);

exit:
  return err; 
}
Beispiel #11
0
/*************
* Check for time limit.
* Returns number of seconds remaining on schedule, 0 if none,
* -1 if not found
**************/
time_t get_time_limit(struct json_object *json_obj, char *key) {
    int bcount, tcount, i, j; 
    time_t tb_begin, tb_end, now_ticks, remain = NOTFOUND;
    int mult = 60/PERIOD;
    struct json_object *profiles;

    if(json_obj == NULL)
        return NOTFOUND;

    time_t t_time = time(NULL);
    struct tm *now = localtime(&t_time);
    now_ticks = now_secs(now);

    profiles = json_object_object_get(json_obj, "profiles");

    if(profiles == NULL) {
        return NOTFOUND;
    }

    if(json_object_is_type(profiles, json_type_array)) {
        bcount = json_object_array_length(profiles);
        for(i=0; i<bcount; i++) {
            struct json_object *profile = json_object_array_get_idx(profiles, i);
            if(profile == NULL) 
                break;
            char *id = get_field_as_string(profile, "id");
            if(id == NULL)
                break;
            if(strncasecmp(key, id, strlen(key)) == 0) {
                log_msg(LOG_DEBUG, "Found profile for: %s\n", id);
                remain = EXPIRED;
                struct json_object *tb = json_object_object_get(profile, "tb");
                if(tb == NULL)
                    break;
                struct json_object *today = json_object_array_get_idx(tb, now->tm_wday);
                if(today == NULL)
                    break;
                tcount = json_object_array_length(today) - 1;
                for(j=tcount; j>=0; j--) {
                    struct json_object *hblock = json_object_array_get_idx(today, j);
                    if(hblock == NULL)
                        break;
                    tb_begin = json_object_get_int(json_object_array_get_idx(hblock, 0)) * 60 * 60/mult;
                    tb_end = tb_begin + json_object_get_int(json_object_array_get_idx(hblock, 1)) * 60 * 60/mult;
                    if((now_ticks > tb_begin) && (now_ticks < tb_end)) {
                        remain = tb_end - now_ticks;
                        log_msg(LOG_DEBUG, "Found time block for %s, %d, %d, time left: %d\n", id, tb_begin, tb_end, remain);
                        break;
                    }
                }
                free(id);
            }
        }
    } 
    json_object_put(profiles);
    return remain;
}
Beispiel #12
0
telebot_error_e telebot_parser_get_sticker(struct json_object *obj,
        telebot_sticker_t *sticker)
{
    if (obj == NULL)
        return TELEBOT_ERROR_INVALID_PARAMETER;

    if (sticker == NULL)
        return TELEBOT_ERROR_INVALID_PARAMETER;
    memset(sticker, 0, sizeof(telebot_sticker_t));

    struct json_object *file_id;
    if (json_object_object_get_ex(obj, "file_id", &file_id)) {
        snprintf(sticker->file_id, TELEBOT_FILE_ID_SIZE, "%s",
                json_object_get_string(file_id));
        json_object_put(file_id);
    }
    else {
        ERR("Object is not sticker type, file_id not found");
        return TELEBOT_ERROR_OPERATION_FAILED;
    }

    struct json_object *width;
    if (json_object_object_get_ex(obj, "width", &width)){
        sticker->width = json_object_get_int(width);
        json_object_put(width);
    }
    else {
        ERR("Object is not sticker type, width not found");
        return TELEBOT_ERROR_OPERATION_FAILED;
    }

    struct json_object *height;
    if (json_object_object_get_ex(obj, "height", &height)){
        sticker->height = json_object_get_int(height);
        json_object_put(height);
    }
    else {
        ERR("Object is not sticker type, height not found");
        return TELEBOT_ERROR_OPERATION_FAILED;
    }

    struct json_object *thumb;
    if (json_object_object_get_ex(obj, "thumb", &thumb)) {
        if (telebot_parser_get_photo(thumb, &(sticker->thumb)) !=
                TELEBOT_ERROR_NONE)
            ERR("Failed to get <thumb> from sticker object");
        json_object_put(thumb);
    }

    struct json_object *file_size;
    if (json_object_object_get_ex(obj, "file_size", &file_size)) {
        sticker->file_size = json_object_get_int(file_size);
        json_object_put(file_size);
    }

    return TELEBOT_ERROR_NONE;
}
Beispiel #13
0
int pv_get_json (struct sip_msg* msg,  pv_param_t* pvp, pv_value_t* val)
{

	pv_json_t * var ;
	json_t * obj;
	json_name * id = (json_name *) pvp->pvn.u.dname;
	UNUSED(id);


	if( expand_tag_list( msg, ((json_name *)pvp->pvn.u.dname)->tags ) < 0)
	{
		LM_ERR("Cannot expand variables in path\n");
		return pv_get_null( msg, pvp, val);
	}


	var = get_pv_json(pvp);

	if( var == NULL )
	{
		/* this is not an error - we simply came across a json spec
		 * pointing a json var which was never set/init */
		LM_DBG("Variable named:%.*s not found\n",id->name.len,id->name.s);
		return pv_get_null( msg, pvp, val);
	}

	obj = get_object(var, pvp, NULL, 0);
	memset(val, 0, sizeof(pv_value_t));

	if( obj == NULL )
		return pv_get_null( msg, pvp, val);

	if( json_object_is_type(obj, json_type_int) )
	{
		val->rs.s = sint2str(json_object_get_int(obj), &val->rs.len);
		val->ri = json_object_get_int(obj);;
		val->flags |= PV_VAL_INT|PV_TYPE_INT|PV_VAL_STR;

	}
	else if( json_object_is_type(obj, json_type_string))
	{
		val->flags = PV_VAL_STR;
		val->rs.s = (char*)json_object_get_string( obj );
#if JSON_LIB_VERSION >= 10
		val->rs.len = json_object_get_string_len( obj );
#else
		val->rs.len = strlen(val->rs.s);
#endif
	} else {
		val->flags = PV_VAL_STR;
		val->rs.s = (char*)json_object_to_json_string( obj );
		val->rs.len = strlen(val->rs.s);
	}

	return 0;
}
Beispiel #14
0
int kpfs_node_get_root_path()
{
	char *response = NULL;
	json_object *jobj = NULL;
	off_t quota_used = 0;
	long quota_total = 0;
	off_t max_file_size = 0;
	int len = 512;
	char *user_name = NULL;
	char *user_id = NULL;
	char *p = NULL;

	response = (char *)kpfs_api_account_info();
	KPFS_FILE_LOG("access [/] %s:\n", response);

	p = strstr(response, KPFS_ID_QUOTA_TOTAL);
	if (p) {
		sscanf(p, KPFS_ID_QUOTA_TOTAL "\": " CURL_FORMAT_OFF_T ",", &quota_total);
	}

	jobj = json_tokener_parse(response);
	if (NULL == jobj || is_error(jobj)) {
		KPFS_FILE_LOG("%s:%d, json_tokener_parse return error.\n", __FUNCTION__, __LINE__);
		KPFS_SAFE_FREE(response);
		return -1;
	}
	json_object_object_foreach(jobj, key, val) {
		if (!strcmp(key, KPFS_ID_QUOTA_USED)) {
			quota_used = (off_t) json_object_get_double(val);;
		} else if (!strcmp(key, KPFS_ID_MAX_FILE_SIZE)) {
			if (json_type_int == json_object_get_type(val)) {
				max_file_size = (off_t) json_object_get_int(val);
			}
		} else if (!strcmp(key, KPFS_ID_USER_ID)) {
			if (json_type_int == json_object_get_type(val)) {
				user_id = calloc(len, 1);
				snprintf(user_id, len, "%d", json_object_get_int(val));
			}
		} else if (!strcmp(key, KPFS_ID_USER_NAME)) {
			if (json_type_string == json_object_get_type(val)) {
				user_name = calloc(len, 1);
				snprintf(user_name, len, "%s", json_object_get_string(val));
			}
		}
	}
	json_object_put(jobj);
	KPFS_SAFE_FREE(response);

	kpfs_util_account_info_store(user_name, user_id, quota_total, quota_used, max_file_size);

	if (NULL == kpfs_node_root_create(user_id, user_name, quota_used))
		return -1;

	return 0;
}
Beispiel #15
0
void ttrss_api::fetch_feeds_per_category(struct json_object * cat, std::vector<tagged_feedurl>& feeds) {
	const char * cat_name = NULL;
	struct json_object * cat_title_obj = NULL;
	int cat_id;

	if (cat) {
		struct json_object * cat_id_obj = json_object_object_get(cat, "id");
		cat_id = json_object_get_int(cat_id_obj);

		// ignore special categories, for now
		if(cat_id < 0)
			return;

		cat_title_obj = json_object_object_get(cat, "title");
		cat_name = json_object_get_string(cat_title_obj);
		LOG(LOG_DEBUG, "ttrss_api::fetch_feeds_per_category: id = %d title = %s", cat_id, cat_name);
	}
	else {
		// As uncategorized is a category itself (id = 0) and the default value
		// for a getFeeds is id = 0, the feeds in uncategorized will appear twice
		return;
	}

	std::map<std::string, std::string> args;
	if (cat)
		args["cat_id"] = utils::to_string<int>(cat_id);
	struct json_object * feed_list_obj = run_op("getFeeds", args);

	if (!feed_list_obj)
		return;

	struct array_list * feed_list = json_object_get_array(feed_list_obj);

	int feed_list_size = array_list_length(feed_list);

	for (int j=0;j<feed_list_size;j++) {
		struct json_object * feed = (struct json_object *)array_list_get_idx(feed_list, j);

		int feed_id = json_object_get_int(json_object_object_get(feed, "id"));
		const char * feed_title = json_object_get_string(json_object_object_get(feed, "title"));
		const char * feed_url = json_object_get_string(json_object_object_get(feed, "feed_url"));

		std::vector<std::string> tags;
		tags.push_back(std::string("~") + feed_title);
		if (cat_name) {
			tags.push_back(cat_name);
		}
		feeds.push_back(tagged_feedurl(utils::strprintf("%s#%d", feed_url, feed_id), tags));

		// TODO: cache feed_id -> feed_url (or feed_url -> feed_id ?)
	}

	json_object_put(feed_list_obj);

}
gboolean mmsvc_core_msg_json_deserialize_len(char *key, char* buf, int *parse_len, void *data, mused_msg_parse_err_e *err)
{
	int type;
	json_object *val, *jobj;

	g_return_val_if_fail(key != NULL, FALSE);
	g_return_val_if_fail(buf != NULL, FALSE);
	g_return_val_if_fail(data != NULL, FALSE);
	g_return_val_if_fail(parse_len != NULL, FALSE);

	jobj = _mmsvc_core_msg_json_tokener_parse_len(buf, parse_len, err);
	g_return_val_if_fail(jobj != NULL, FALSE);

	val = _mmsvc_core_msg_json_find_obj(jobj, key);
	if (!val) {
		LOGE("\"%s\" key is not founded", key);
		return FALSE;
	}

	type = json_object_get_type(val);
	switch (type) {
	case json_type_null:
		LOGD("json_type_null\n");
		break;
	case json_type_boolean:
		LOGD("json_type_boolean (%s)          value: %d", key, json_object_get_boolean(val));
		break;
	case json_type_double:
		*(double *)data = json_object_get_double(val);
		LOGD("json_type_double (%s)          value: %p", key, (double *)data);
		break;
	case json_type_int:
		*(int *)data = json_object_get_int(val);
		LOGD("json_type_int (%s)          value: %p", key, (int *)data);
		break;
	case json_type_object:
		LOGD("json_type_object (%s)          value: %d", key, json_object_get_object(val));
		break;
	case json_type_string:
		strncpy((char *)data, json_object_get_string(val), strlen(json_object_get_string(val)));
		LOGD("json_type_string (%s)          value: %s", key, (char *)data);
		break;
	case json_type_array:
		LOGD("json_type_array (%s)", key);
		int i, len;
		int *int_data = (int *)data;
		len = json_object_array_length(val);
		for (i = 0; i < len; i++)
			int_data[i] = json_object_get_int(json_object_array_get_idx(val, i));
		break;
	}
	json_object_put(jobj);
	return TRUE;
}
Beispiel #17
0
/* Parses the given JSON String 
 * Returns
 *  - 0 on success and all the arguments will be pointing to parsed data
 *  - 1 on failure and garbage elsewhere
 */
int parse_json(const char* json_str, int * arg_c, int *live, char * user, char * group, char * command) {
  json_object * jobj;
  json_object *j_tmp;		/* tmp json object to store intermediate values */

  jobj = json_tokener_parse(json_str);
  /* if json parsing has failed */
  if (jobj == NULL) {
    json_object_put(jobj);
    _LOGGER("(ERROR) Json Parsing Failed for JSON String [%s]", json_str);
    return 1;
  }

  /* get command */
  j_tmp = json_object_object_get(jobj, "command");
  if (j_tmp == NULL) {
    json_object_put(jobj);
    return 1;
  }
  strcpy(command, json_object_get_string(j_tmp));

  /* get user */
  j_tmp = json_object_object_get(jobj, "runas_user");
  if (j_tmp == NULL) {
    json_object_put(jobj);
    return 1;
  }
  strcpy(user, json_object_get_string(j_tmp));

  /* get group, if group is missing, it is ok */
  j_tmp = json_object_object_get(jobj, "runas_group");
  if (j_tmp == NULL) {
    group[0] = '\0';
  } else {
    strcpy(group, json_object_get_string(j_tmp));
  }

  /* get argc */
  j_tmp = json_object_object_get(jobj, "argc");
  if (j_tmp == NULL) {
    json_object_put(jobj); 
    return 1;
  }
  *arg_c = json_object_get_int(j_tmp);

  /* get live, if set take it */
  j_tmp = json_object_object_get(jobj, "live");
  if (j_tmp != NULL)   
    *live = json_object_get_int(j_tmp);

  json_object_put(jobj);

  return 0;
}
static int
parse_geojson_coord(json_object *poObj, bool *hasz, POINTARRAY *pa)
{
	POINT4D pt;
	int iType = 0;

	POSTGIS_DEBUGF(3, "parse_geojson_coord called for object %s.", json_object_to_json_string( poObj ) );

	if( json_type_array == json_object_get_type( poObj ) )
	{

		json_object* poObjCoord = NULL;
		const int nSize = json_object_array_length( poObj );
		POSTGIS_DEBUGF(3, "parse_geojson_coord called for array size %d.", nSize );


		// Read X coordinate
		poObjCoord = json_object_array_get_idx( poObj, 0 );
		iType = json_object_get_type(poObjCoord);
		if (iType == json_type_double)
			pt.x = json_object_get_double( poObjCoord );
		else
			pt.x = json_object_get_int( poObjCoord );
		POSTGIS_DEBUGF(3, "parse_geojson_coord pt.x = %f.", pt.x );

		// Read Y coordiante
		poObjCoord = json_object_array_get_idx( poObj, 1 );
		if (iType == json_type_double)
			pt.y = json_object_get_double( poObjCoord );
		else
			pt.y = json_object_get_int( poObjCoord );
		POSTGIS_DEBUGF(3, "parse_geojson_coord pt.y = %f.", pt.y );

		*hasz = false;

		if( nSize == 3 )
		{
			// Read Z coordiante
			poObjCoord = json_object_array_get_idx( poObj, 2 );
			if (iType == 3)
				pt.z = json_object_get_double( poObjCoord );
			else
				pt.z = json_object_get_int( poObjCoord );
			POSTGIS_DEBUGF(3, "parse_geojson_coord pt.z = %f.", pt.z );
			*hasz = true;
		}
	}

	return ptarray_append_point(pa, &pt, LW_FALSE);
}
Beispiel #19
0
bool EASPolicy::fromJSON(json_object* policy)
{
    json_object *prop = 0, *key = 0;

	prop = json_object_object_get(policy, "password");
	if (prop && !is_error(prop)) {
		
		key = json_object_object_get(prop, "enabled");
		m_passwordRequired = json_object_get_boolean(key);
		

		key = json_object_object_get(prop, "minLength");
		if (key)
			m_minLength = json_object_get_int(key);
		else
			m_minLength = 1;

		key = json_object_object_get(prop, "maxRetries");
		if (key)
			m_maxRetries = json_object_get_int(key);
		else
			m_maxRetries = 1;

		key = json_object_object_get(prop, "alphaNumeric");
		m_isAlphaNumeric = json_object_get_boolean(key);
	}
	else {
		m_passwordRequired = false;
		m_minLength = 1;
		m_maxRetries = 1;
		m_isAlphaNumeric = false;
	}

	key = json_object_object_get(policy, "inactivityInSeconds");
	if (key) {
		m_inactivityInSeconds = json_object_get_int(key);
	}
	else {
		m_inactivityInSeconds = 0;
	}

	key = json_object_object_get(policy, "id");
	if (key) {
		char* str = json_object_get_string(key);
		m_id = (str != NULL ? str : "");
	}

	return !m_id.empty();
}
Beispiel #20
0
telebot_error_e telebot_parser_get_photo(struct json_object *obj,
        telebot_photo_t *photo)
{
    if (obj == NULL)
        return TELEBOT_ERROR_INVALID_PARAMETER;

    if (photo == NULL)
        return TELEBOT_ERROR_INVALID_PARAMETER;
    memset(photo, 0, sizeof(telebot_photo_t));

    struct json_object *file_id;
    if (json_object_object_get_ex(obj, "file_id", &file_id)) {
        snprintf(photo->file_id, TELEBOT_FILE_ID_SIZE, "%s",
                json_object_get_string(file_id));
        json_object_put(file_id);
    }
    else {
        ERR("Object is not photo size type, file_id not found");
        return TELEBOT_ERROR_OPERATION_FAILED;
    }

    struct json_object *width;
    if (json_object_object_get_ex(obj, "width", &width)){
        photo->width = json_object_get_int(width);
        json_object_put(width);
    }
    else {
        ERR("Object is not photo size type, width not found");
        return TELEBOT_ERROR_OPERATION_FAILED;
    }

    struct json_object *height;
    if (json_object_object_get_ex(obj, "height", &height)){
        photo->height = json_object_get_int(height);
        json_object_put(height);
    }
    else {
        ERR("Object is not photo size type, height not found");
        return TELEBOT_ERROR_OPERATION_FAILED;
    }

    struct json_object *file_size;
    if (json_object_object_get_ex(obj, "file_size", &file_size)) {
        photo->file_size = json_object_get_int(file_size);
        json_object_put(file_size);
    }

    return TELEBOT_ERROR_NONE;
}
Beispiel #21
0
/* Get punch details - private helper */
void get_json_punch(struct s_punch *punch, json_object *jp){
	enum json_type type;

	json_object_object_foreach(jp, keyp, valp) {
		type = json_object_get_type(valp);
		if(strcmp(keyp, "time") == 0 && type == json_type_int){
			punch->time = json_object_get_int(valp);
		}
		if(strcmp(keyp, "tst") == 0 && type == json_type_int){
			punch->timestat = json_object_get_int(valp);
		}
		if(strcmp(keyp, "cn") == 0 && type == json_type_int){
			punch->cn = json_object_get_int(valp);
		}
	}
static void ParseLineString(OGRLineString* poLS, json_object* poRing,
                            json_object* poArcsDB, ScalingParams* psParams)
{
    int nArcsDB = json_object_array_length(poArcsDB);

    int nArcsRing = json_object_array_length(poRing);
    for(int j=0; j<nArcsRing; j++)
    {
        json_object* poArcId = json_object_array_get_idx(poRing, j);
        if( poArcId != NULL && json_type_int == json_object_get_type(poArcId) )
        {
            int nArcId = json_object_get_int(poArcId);
            int bReverse = FALSE;
            if( nArcId < 0 )
            {
                nArcId = - nArcId - 1;
                bReverse = TRUE;
            }
            if( nArcId < nArcsDB )
            {
                ParseArc(poLS, poArcsDB, nArcId, bReverse, psParams);
            }
        }
    }
}
Beispiel #23
0
static void get_field(json_object *e, const char *path, void *dest)
{
	json_object *fld = NULL;
	enum json_type type;

	fld = json_object_object_get(e, path);
	if (fld) {
		type = json_object_get_type(fld);
		switch (type) {
		case json_type_boolean:
			*(unsigned int *)dest = json_object_get_boolean(fld);
			break;
		case json_type_int:
			*(unsigned int *)dest = json_object_get_int(fld);
			break;
		case json_type_string:
			strcpy(dest, json_object_get_string(fld));
			break;
		case json_type_double:
			*(double *)dest = json_object_get_double(fld);
			break;
		default:
			break;
		}
	}
}
Beispiel #24
0
/*
 * Obtain the datanode REST servers host/port data
 */
static List*
parse_datanodes_response(List *rest_srvrs, StringInfo rest_buf)
{
	struct json_object *whole = json_tokener_parse(rest_buf->data);
	if ((whole == NULL) || is_error(whole))
	{
		elog(ERROR, "Failed to parse datanode list from PXF");
	}
	struct json_object *nodes = json_object_object_get(whole, "regions");
	int length = json_object_array_length(nodes);

	/* obtain host/port data for the REST server running on each HDFS data node */
	for (int i = 0; i < length; i++)
	{
		PxfServer* srv = (PxfServer*)palloc(sizeof(PxfServer));

		struct json_object *js_node = json_object_array_get_idx(nodes, i);
		struct json_object *js_host = json_object_object_get(js_node, "host");
		srv->host = pstrdup(json_object_get_string(js_host));
		struct json_object *js_port = json_object_object_get(js_node, "port");
		srv->port = json_object_get_int(js_port);

		rest_srvrs = lappend(rest_srvrs, srv);
	}

	return rest_srvrs;
}
Beispiel #25
0
void _HKCreateWritePerCharacteristic(struct _hapAccessory_t inHapObject[], HK_Char_ID_t id, json_object *value_obj, bool moreComing, mico_Context_t * const inContext)
{
  struct _hapCharacteristic_t pCharacteristic;
  value_union value;

  if(id.serviceID == 0 || id.characteristicID == 0)
    return;
  
  pCharacteristic = ((inHapObject[id.aid-1]).services[id.serviceID-1]).characteristic[id.characteristicID-1];
  
  if( pCharacteristic.secureWrite == true && id.serviceID && id.characteristicID ){
    switch(pCharacteristic.valueType ){
      case ValueType_bool:
        value.boolValue = json_object_get_boolean(value_obj);
        break;
      case ValueType_int:
        value.intValue = json_object_get_int(value_obj);
        break;
      case ValueType_float:
        value.floatValue = json_object_get_double(value_obj);
        break;
      case ValueType_string:
        value.stringValue = (char *)json_object_get_string(value_obj);
        break;
      case ValueType_date:
        value.stringValue = (char *)json_object_get_string(value_obj);
        break;
      case ValueType_null:
        break;
      default:
        break;
    }      
    HKWriteCharacteristicValue(id.aid, id.serviceID, id.characteristicID, value, moreComing, inContext);    
  }
}
Beispiel #26
0
static void json_value_str(struct json_object *obj, GString *out, int level)
{
	int i;

	switch(json_object_get_type(obj)) {
	case json_type_null:
		g_string_append(out, "(null)");
		break;
	case json_type_boolean:
		g_string_append(out, json_object_get_boolean(obj) ? "true" : "false");
		break;
	case json_type_double:
		g_string_append_printf(out, "%f", json_object_get_double(obj));
		break;
	case json_type_int:
		g_string_append_printf(out, "%d", json_object_get_int(obj));
		break;
	case json_type_string:
		g_string_append_printf(out, "\"%s\"", json_object_get_string(obj));
		break;
	case json_type_object:
		json_object_str(obj, out, level);
		break;
	case json_type_array:
		json_array_str(obj, out, level);
	}
}
Beispiel #27
0
int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v) {
    const char *str;
    json_object *o;

    pa_assert(f);
    pa_assert(key);
    pa_assert(v);

    str = pa_proplist_gets(f->plist, key);
    if (!str)
        return -PA_ERR_NOENTITY;

    o = json_tokener_parse(str);
    if (is_error(o))
        return -PA_ERR_INVALID;

    if (json_object_get_type(o) != json_type_int) {
        json_object_put(o);
        return -PA_ERR_INVALID;
    }

    *v = json_object_get_int(o);
    json_object_put(o);

    return 0;
}
Beispiel #28
0
static void dump_kvs_val (const char *key, const char *json_str)
{
    JSON o = Jfromstr (json_str);
    if (!o) {
        printf ("%s: invalid JSON", key);
        return;
    }
    switch (json_object_get_type (o)) {
    case json_type_null:
        printf ("%s = nil\n", key);
        break;
    case json_type_boolean:
        printf ("%s = %s\n", key, json_object_get_boolean (o)
                ? "true" : "false");
        break;
    case json_type_double:
        printf ("%s = %f\n", key, json_object_get_double (o));
        break;
    case json_type_int:
        printf ("%s = %d\n", key, json_object_get_int (o));
        break;
    case json_type_string:
        printf ("%s = %s\n", key, json_object_get_string (o));
        break;
    case json_type_array:
    case json_type_object:
    default:
        printf ("%s = %s\n", key, Jtostr (o));
        break;
    }
    Jput (o);
}
Beispiel #29
0
    void draw_item(json_object *o)
    {
	stringstream dummy;
	if(json_object_is_type(o, json_type_boolean))
	{
	    json_object_get_boolean(o)?draw_text("1"):draw_text("0");
	    one_down();
	}
	if(json_object_is_type(o, json_type_double))
	{
	    dummy << json_object_get_double(o);
	    draw_text(dummy.str().c_str());
	    one_down();
	}
	if(json_object_is_type(o, json_type_int))
	{
	    dummy << json_object_get_int(o);
	    draw_text(dummy.str().c_str());
	    one_down();
	}
	if(json_object_is_type(o, json_type_object))
	{
	    one_right();
	    json_object_object_foreach(o, key,val)
	    {
		draw_text(key);
		one_down();
		draw_item(val);
		one_down();
	    }
	    one_left();
	}
Beispiel #30
0
static union command_args *unserialize_store_key_req(struct json_object *in,
                                                     uint16_t version) {
    struct json_object *temp;
    union command_args *ret_union =
        (union command_args *) malloc(sizeof(union command_args));
    struct store_key_req *ret = &ret_union->store_key_req;

    if(version != 1)
        goto err_exit;

    if(!json_object_object_get_ex(in, "key_id_accepted", &temp)) {
        LOG(LOG_LVL_CRIT, "Key \"key_id_accepted\" does not exists.");
        goto err_exit;
    }

    ret->key_id_accepted = (uint8_t) json_object_get_int(temp);

    if(!json_object_object_get_ex(in, "key_id", &temp)){
        LOG(LOG_LVL_CRIT, "Key \"key_id\" does not exists.");
        goto err_exit;
    }
    ret->key_id = strdup(json_object_get_string(temp));

    return ret_union;

err_exit:
    free(ret_union);
    return NULL;
}