Пример #1
0
struct json_object* dbus_array_json(DBusMessageIter *iter)
{
        struct json_object *jarray, *tmp;
        DBusMessageIter array;

        jarray = json_object_new_array();
        array = *iter;

        while (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_INVALID ) {
                tmp = dbus_to_json(&array);
                json_object_array_add(jarray, tmp);
                dbus_message_iter_next(&array);
        }

        return jarray;
}
Пример #2
0
void pa_format_info_set_prop_string_array(pa_format_info *f, const char *key, const char **values, int n_values) {
    json_object *o;
    int i;

    pa_assert(f);
    pa_assert(key);

    o = json_object_new_array();

    for (i = 0; i < n_values; i++)
        json_object_array_add(o, json_object_new_string(values[i]));

    pa_proplist_sets(f->plist, key, json_object_to_json_string(o));

    json_object_put(o);
}
Пример #3
0
OSStatus MICOAddSector(json_object* sectorArray, char* const name,  json_object *menuArray)
{
  OSStatus err;
  json_object *object;
  err = kNoErr;

  object = json_object_new_object();
  require_action(object, exit, err = kNoMemoryErr);
  json_object_object_add(object, "N", json_object_new_string(name));      
  json_object_object_add(object, "T", json_object_new_string("sector"));
  json_object_object_add(object, "C", menuArray);
  json_object_array_add(sectorArray, object);

exit:
  return err;
}
Пример #4
0
OSStatus MICOAddSwitchCellToSector(json_object* menus, char* const name,  boolean switcher, char* const privilege)
{
  OSStatus err;
  json_object *object;
  err = kNoErr;

  object = json_object_new_object();
  require_action(object, exit, err = kNoMemoryErr);
  json_object_object_add(object, "N", json_object_new_string(name));      
  json_object_object_add(object, "C", json_object_new_boolean(switcher));
  json_object_object_add(object, "P", json_object_new_string(privilege)); 
  json_object_array_add(menus, object);

exit:
  return err;
}
Пример #5
0
json_object * kvspath_request_json (int64_t id)
{
    json_object *o = json_object_new_object ();
    json_object *ar = json_object_new_array ();
    json_object *v = json_object_new_int64 (id);

    if (!o || !ar || !v) {
        Jput (o);
        Jput (ar);
        Jput (v);
        return (NULL);
    }
    json_object_array_add (ar, v);
    json_object_object_add (o, "ids", ar);
    return (o);
}
Пример #6
0
static int extract_raw_pdescs (flux_t h, int64_t j, int64_t n, JSON jcb)
{
    int rc = -1;
    int64_t i = 0;
    char hnm[20] = {'\0'};
    const char *cmd = NULL;
    zhash_t *eh = NULL; /* hash holding a set of unique exec_names */
    zhash_t *hh = NULL; /* hash holding a set of unique host_names */
    JSON o = NULL, po = NULL;
    JSON pa = Jnew_ar ();
    JSON hns = Jnew_ar ();
    JSON ens = Jnew_ar ();

    if (!(eh = zhash_new ()) || !(hh = zhash_new ())) 
        oom ();
    for (i=0; i < (int) n; i++) {
        int64_t eix = 0, hix = 0;
        int64_t pid = 0, nid = 0;

        if (extract_raw_pdesc (h, j, i, &o) != 0) 
            goto done;
        if (!fetch_rank_pdesc (o, &pid, &nid, &cmd)) 
            goto done;

        eix = build_name_array (eh, cmd, ens);
        /* FIXME: we need a hostname service */
        snprintf (hnm, 20, "%ld", nid); 
        hix = build_name_array (hh, hnm, hns);
        po = build_parray_elem (pid, eix, hix); 
        json_object_array_add (pa, po);
        po = NULL;
        Jput (o);
        o = NULL;
    }
    add_pdescs_to_jcb (&hns, &ens, &pa, jcb);
    rc = 0;    

done:
    if (o) Jput (o);
    if (po) Jput (po);
    if (pa) Jput (pa); 
    if (hns) Jput (hns);
    if (ens) Jput (ens);
    zhash_destroy (&eh);
    zhash_destroy (&hh);
    return rc;    
} 
Пример #7
0
////////////////////////////////////////
// { "ipv4Addresses": [ "172.17.133.3", "172.17.133.4", "172.17.133.5" ] }
void requestIpv4Addresses(void)
{
    log_notice("requestIpv4Addresses");

    struct ifaddrs* paddrs;
    if(getifaddrs(&paddrs) < 0)
    {
        log_err("get_ipv4_addresses:getifaddrs, err: [%s]", strerror(errno));
        return;
    }

    json_object* jarray = json_object_new_array();
    for(struct ifaddrs* pifa = paddrs; pifa != NULL; pifa = pifa->ifa_next)
    {
        if((NULL == pifa->ifa_addr) || (AF_INET != pifa->ifa_addr->sa_family))
        {
            continue; // skip non ipv4 addresses
        }

        if(IFF_LOOPBACK == (pifa->ifa_flags & IFF_LOOPBACK))
        {
            continue; // skip loopback interfaces
        }

        if((IFF_UP != (pifa->ifa_flags & IFF_UP)) || (IFF_RUNNING != (pifa->ifa_flags & IFF_RUNNING)))
        {
            continue; // skip interfaces that are not up and running
        }

        struct sockaddr_in* paddr = (struct sockaddr_in*)pifa->ifa_addr;
        // struct sockaddr_in* pmask = (struct sockaddr_in*)pifa->ifa_netmask;

        // an ipv4 address we care about
        const char* ip = inet_ntoa(paddr->sin_addr);
        log_debug("adding ipv4 address: %s", ip);
        json_object_array_add(jarray, json_object_new_string(ip));
    }
    freeifaddrs(paddrs);

    // serialize & send the ipv4 addresses back
    json_object* jobject = json_object_new_object();
    json_object_object_add(jobject, "ipv4Addresses", jarray);
    const char* str = json_object_to_json_string(jobject);
    ws_send_text(str);
    json_object_put(jarray);
    json_object_put(jobject);
}
Пример #8
0
void Adapter::json( json_object *entry ) const
{
  json_object_object_add( entry, "name", json_object_new_string( name.c_str( )));
  json_object_object_add( entry, "id",   json_object_new_int( GetKey( )));
  json_object_object_add( entry, "path", json_object_new_string( uid.c_str( )));
  json_object_object_add( entry, "present", json_object_new_int( IsPresent( )));
  json_object *a = json_object_new_array();

  for( std::vector<Frontend *>::const_iterator it = frontends.begin( ); it != frontends.end( ); it++ )
  {
    json_object *entry = json_object_new_object( );
    (*it)->json( entry );
    json_object_array_add( a, entry );
  }

  json_object_object_add( entry, "frontends", a );
}
Пример #9
0
json_object* OGRGMELineCoordsToGeoJSON( OGRLineString* poLine )
{
    json_object* pjoCoords = json_object_new_array();

    const int nCount = poLine->getNumPoints();
    for( int i = 0; i < nCount; ++i )
    {
        json_object* pjoPoint = NULL;
        if( poLine->getCoordinateDimension() == 2 )
            pjoPoint = OGRGMECoordsToGeoJSON( poLine->getX(i), poLine->getY(i) );
        else
            pjoPoint = OGRGMECoordsToGeoJSON( poLine->getX(i), poLine->getY(i), poLine->getZ(i) );
        json_object_array_add( pjoCoords, pjoPoint );
    }

    return pjoCoords;
}
Пример #10
0
static struct json_object *list_namespaces(struct ndctl_region *region,
		struct json_object *container, struct json_object *jnamespaces,
		bool continue_array)
{
	struct ndctl_namespace *ndns;

	ndctl_namespace_foreach(region, ndns) {
		struct json_object *jndns;

		/* are we emitting namespaces? */
		if (!list.namespaces)
			break;

		if (!list.idle && !util_namespace_active(ndns))
			continue;

		if (!jnamespaces) {
			jnamespaces = json_object_new_array();
			if (!jnamespaces) {
				fail("\n");
				continue;
			}

			if (container)
				json_object_object_add(container, "namespaces",
						jnamespaces);
		}

		jndns = util_namespace_to_json(ndns);
		if (!jndns) {
			fail("\n");
			continue;
		}

		json_object_array_add(jnamespaces, jndns);
	}

	/*
	 * We we are collecting namespaces anonymously across the
	 * platform / bus
	 */
	if (continue_array)
		return jnamespaces;
	return NULL;
}
Пример #11
0
static void xr_call_serialize_request_json(xr_call* call, char** buf, int* len)
{
    GSList* i;
    struct json_object *r, *params;

    r = json_object_new_object();
    json_object_object_add(r, "method", json_object_new_string(call->method));
    json_object_object_add(r, "params", params = json_object_new_array());
    json_object_object_add(r, "id", json_object_new_string("1"));

    for (i = call->params; i; i = i->next)
        json_object_array_add(params, _xr_value_serialize_json(i->data));

    *buf = g_strdup(json_object_to_json_string(r));
    *len = strlen(*buf);

    json_object_put(r);
}
Пример #12
0
OGRErr OGRGMELayer::BatchDelete()
{
    json_object *pjoBatchDelete = json_object_new_object();
    json_object *pjoGxIds = json_object_new_array();
    std::vector<long>::const_iterator fit;
    CPLDebug("GME", "BatchDelete() - <%d>", (int)oListOfDeletedFeatures.size() );
    if (oListOfDeletedFeatures.size() == 0) {
        CPLDebug("GME", "Empty list, not doing BatchDelete");
        return OGRERR_NONE;
    }
    for ( fit = oListOfDeletedFeatures.begin(); fit != oListOfDeletedFeatures.end(); fit++)
    {
        long nFID = *fit;
        if (nFID > 0) {
            CPLString osGxId(omnosIdToGMEKey[nFID]);
            CPLDebug("GME", "Deleting feature %ld -> '%s'", nFID, osGxId.c_str());
            json_object *pjoGxId = json_object_new_string(osGxId.c_str());
            omnosIdToGMEKey.erase(nFID);
            json_object_array_add( pjoGxIds, pjoGxId );
        }
    }
    oListOfDeletedFeatures.clear();
    if (json_object_array_length(pjoGxIds) == 0)
        return OGRERR_FAILURE;
    json_object_object_add( pjoBatchDelete, "gx_ids", pjoGxIds );
    const char *body =
        json_object_to_json_string_ext(pjoBatchDelete,
                                       JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);

/* -------------------------------------------------------------------- */
/*      POST changes                                                    */
/* -------------------------------------------------------------------- */
    CPLString osRequest = "tables/" + osTableId + "/features/batchDelete";
    CPLHTTPResult *poBatchDeleteResult = poDS->PostRequest(osRequest, body);
    if (poBatchDeleteResult) {
        CPLDebug("GME", "batchDelete returned %d", poBatchDeleteResult->nStatus);
        return OGRERR_NONE;
    }
    else {
        CPLDebug("GME", "batchPatch failed, NULL was returned.");
        CPLError(CE_Failure, CPLE_AppDefined, "Server error for batchDelete");
        return OGRERR_FAILURE;
    }
}
Пример #13
0
OGRErr OGRGMELayer::BatchRequest(const char *pszMethod, std::map<int, OGRFeature *> &omnpoFeatures)
{
    json_object *pjoBatchDoc = json_object_new_object();
    json_object *pjoFeatures = json_object_new_array();
    std::map<int, OGRFeature *>::const_iterator fit;
    CPLDebug("GME", "BatchRequest('%s', <%d>)", pszMethod, (int)omnpoFeatures.size() );
    if (omnpoFeatures.size() == 0) {
        CPLDebug("GME", "Empty map, not doing '%s'", pszMethod);
        return OGRERR_NONE;
    }
    for ( fit = omnpoFeatures.begin(); fit != omnpoFeatures.end(); fit++)
    {
        long nFID = fit->first;
        OGRFeature *poFeature = fit->second;
        CPLDebug("GME", "Processing feature: %ld", nFID );
        json_object *pjoFeature = OGRGMEFeatureToGeoJSON(poFeature);

        if (pjoFeature != NULL)
            json_object_array_add( pjoFeatures, pjoFeature );
        delete poFeature;
    }
    omnpoFeatures.clear();
    if (json_object_array_length(pjoFeatures) == 0)
        return OGRERR_FAILURE;
    json_object_object_add( pjoBatchDoc, "features", pjoFeatures );
    const char *body =
        json_object_to_json_string_ext(pjoBatchDoc,
                                       JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);

/* -------------------------------------------------------------------- */
/*      POST changes                                                    */
/* -------------------------------------------------------------------- */
    CPLString osRequest = "tables/" + osTableId + "/features/" + pszMethod;
    CPLHTTPResult *psBatchResult = poDS->PostRequest(osRequest, body);
    if (psBatchResult) {
        CPLDebug("GME", "%s returned %d", pszMethod, psBatchResult->nStatus);
        return OGRERR_NONE;
    }
    else {
        CPLDebug("GME", "%s failed, NULL was returned.", pszMethod );
        CPLError(CE_Failure, CPLE_AppDefined, "Server error for %s", pszMethod);
        return OGRERR_FAILURE;
    }
}
Пример #14
0
telebot_error_e telebot_send_mediagroup_photo_files(telebot_handler_t handle, long long int chat_id,
        char **photos, int count, bool disable_notification,
        int reply_to_message_id, char *reply_markup)
{
	
	int i;
	json_object *jsonarr, *jsonobj;
	char *str, *mediajson;
	char **filenames;
	telebot_hdata_t * _handle = (telebot_hdata_t *)handle;	
		
    if (_handle == NULL)
        return TELEBOT_ERROR_NOT_SUPPORTED;

    if (photos == NULL) return TELEBOT_ERROR_INVALID_PARAMETER;
    
	jsonarr = json_object_new_array();	
	
	filenames = calloc(count, sizeof(char*));
	if (filenames == NULL) return TELEBOT_ERROR_OUT_OF_MEMORY;
	
	
	for(i=0; i<count; i++) {
		filenames[i] = strdup(basename(photos[i]));
		asprintf(&str,"attach://%s", filenames[i]);		
		jsonobj = json_object_new_object();
		
		json_object_object_add(jsonobj, "type", json_object_new_string("photo"));
		json_object_object_add(jsonobj, "media", json_object_new_string(str));
		json_object_array_add(jsonarr,jsonobj);
		
		free(str);
	}
	
	mediajson = strdup(json_object_to_json_string_ext(jsonarr, JSON_C_TO_STRING_PLAIN));

	telebot_error_e ret = telebot_core_send_mediagroup_photo_files(_handle->core_h, chat_id, mediajson,
			filenames, photos, count, disable_notification, reply_to_message_id, reply_markup);

	json_object_put(jsonarr);
	tb_sfree_zcnt(_handle->core_h->resp_data, _handle->core_h->resp_size);

	return ret;
}
Пример #15
0
OSStatus add_service(json_object* services, 
                     const char* type_name,  const char* type_content, 
                     const char* iid_name,  int iid_value,
                     const char* properties_name,  json_object *properties)
{
  OSStatus err;
  json_object *object;
  err = kNoErr;
  
  object = json_object_new_object();
  require_action(object, exit, err = kNoResourcesErr);
  json_object_object_add(object, type_name, json_object_new_string(type_content));
  json_object_object_add(object, iid_name, json_object_new_int(iid_value));
  json_object_object_add(object, properties_name, properties);
  json_object_array_add(services, object);
  
exit:
  return err;
}
Пример #16
0
json_object * CLuaArguments::WriteToJSONArray ( bool bSerialize )
{
    json_object * my_array = json_object_new_array();
    vector < CLuaArgument* > ::const_iterator iter = m_Arguments.begin ();
    for ( ; iter != m_Arguments.end () ; iter++ )
    {
        CLuaArgument* pArgument = *iter;
        json_object * object = pArgument->WriteToJSONObject ( bSerialize );
        if ( object )
        {
            json_object_array_add(my_array, object);
        }
        else
        {
            break;
        }
    }
	return my_array;
}
Пример #17
0
void cgi_print_result(logo_recv_fileServ_t* recv_data,const char* filename,uint32_t pic_type,uint32_t branchtype,int result,uint32_t reason_id)
{	
	struct json_object *my_object;
	struct json_object *sub_array;
	my_object = json_object_new_object();
	sub_array = json_object_new_array();
	char str_tmp[512] = {0};
	uint32_t i =0,j=0;
	if(result == FAIL){
		json_object_object_add(my_object,"result",json_object_new_string("fail"));
		json_object_object_add(my_object,"filename",json_object_new_string(filename));
		json_object_object_add(my_object,"reason",json_object_new_int(reason_id));
		goto PRINT_END;
	}
	if(recv_data == NULL){
		json_object_object_add(my_object,"result",json_object_new_string("fail"));
		json_object_object_add(my_object,"filename",json_object_new_string(filename));
		json_object_object_add(my_object,"reason",json_object_new_int(reason_id));
		goto PRINT_END;
	}
	json_object_object_add(my_object,"result",json_object_new_string("success"));
	json_object_object_add(my_object,"filename",json_object_new_string(filename));
	json_object_object_add(my_object,"hostid",json_object_new_int(recv_data->hostid));
	json_object_object_add(my_object,"lloccode",json_object_new_string(recv_data->old_lloccode));
	json_object_object_add(my_object,"Thumbcnt",json_object_new_int(recv_data->Thumbcnt));
	if(recv_data->Thumbcnt == 0){
		goto PRINT_END;
	}
	for(i = 0;i < recv_data->Thumbcnt && i < CNT_MAX; i++){
		char lloccode[LLOCCODE_LEN+1] = {0};
		UNPKG_STR(recv_data->new_lloccodes,lloccode,j,LLOCCODE_LEN);
		sprintf(str_tmp,"%s",lloccode);
		json_object_array_add(sub_array, json_object_new_string(str_tmp));

	}
	json_object_object_add(my_object,"new_lloccode",sub_array);
PRINT_END:
	fprintf(cgiOut,"%s\n",json_object_to_json_string(my_object));
	json_object_put(sub_array);
	json_object_put(my_object);
	return ;
}
Пример #18
0
/* Write hash list to session file */
hash_stat session_write_hashlist(FILE *sessionfile)
{
#ifdef HAVE_JSON_JSON_H

    json_object *jobj;
    json_object *jchild;
    struct hash_list_s *mylist;
    char buff[1024];

    if (get_cracked_num()==get_hashes_num()) return(hash_ok);
    if (get_hashes_num()>100000) 
    {
	hash_list_node = json_object_new_array();
	json_object_object_add(root_node,"hashlist", hash_list_node);
	return(hash_ok);
    }

    hash_list_node = json_object_new_array();
    pthread_mutex_lock(&listmutex);
    mylist = hash_list;
    while ((mylist)&&(mylist->username))
    {
	jchild = json_object_new_object();
	jobj = json_object_new_string(mylist->username);
	json_object_object_add(jchild,"username", jobj);
	str2hex(mylist->hash, buff, hash_ret_len);
	jobj = json_object_new_string(buff);
	json_object_object_add(jchild,"hash", jobj);
	jobj = json_object_new_string(mylist->salt);
	json_object_object_add(jchild,"salt", jobj);
	jobj = json_object_new_string(mylist->salt);
	json_object_object_add(jchild,"salt", jobj);
	jobj = json_object_new_string(mylist->salt2);
	json_object_object_add(jchild,"salt2", jobj);
	json_object_array_add(hash_list_node,jchild);
	mylist = mylist->next;
    }
    pthread_mutex_unlock(&listmutex);
    json_object_object_add(root_node,"hashlist", hash_list_node);
#endif
    return hash_ok;
}
Пример #19
0
int resrc_flow_list_serialize (JSON o, resrc_flow_list_t *rfl)
{
    resrc_flow_t *rf;
    int rc = -1;

    if (o && rfl && rfl->list) {
        rc = 0;
        rf = resrc_flow_list_first (rfl);
        while (rf) {
            JSON co = Jnew ();

            if ((rc = resrc_flow_serialize (co, rf)))
                break;
            json_object_array_add (o, co);
            rf = resrc_flow_list_next (rfl);
        }
    }

    return rc;
}
Пример #20
0
std::string TimeZoneService::getTimeZoneRules(const TimeZoneService::TimeZoneEntryList& entries)
{
	TimeZoneResultList totalResult;
	for (TimeZoneEntryList::const_iterator it = entries.begin();
		 it != entries.end(); ++it) {
		TimeZoneResultList r = getTimeZoneRuleOne(*it);
		totalResult.splice(totalResult.end(), r);
	}

	if (totalResult.empty()) {
		return std::string("{\"returnValue\": false, \"errorText\":\"Failed to retrieve results for specified timezones\"}");
	}

	json_object* obj = json_object_new_object();
	json_object_object_add(obj, "returnValue", json_object_new_boolean(true));

	json_object* array = json_object_new_array();
	for (TimeZoneResultList::const_iterator it = totalResult.begin();
		 it != totalResult.end(); ++it) {
		const TimeZoneResult& r = (*it);
		json_object* o = json_object_new_object();
		json_object_object_add(o, "tz", json_object_new_string(r.tz.c_str()));
		json_object_object_add(o, "year", json_object_new_int(r.year));
		json_object_object_add(o, "hasDstChange", json_object_new_boolean(r.hasDstChange));
		json_object_object_add(o, "utcOffset", json_object_new_int(r.utcOffset));
		json_object_object_add(o, "dstOffset", json_object_new_int(r.dstOffset));
		json_object_object_add(o, "dstStart", json_object_new_int(r.dstStart));
		json_object_object_add(o, "dstEnd", json_object_new_int(r.dstEnd));
		json_object_array_add(array, o);
		// printf("Name: %s, Year: %d, hasDstChange: %d, utcOffset: %lld, "
		// 	   "dstOffset: %lld, dstStart: %lld, dstEnd: %lld\n",
		// 	   r.tz.c_str(), r.year, r.hasDstChange,
		// 	   r.utcOffset, r.dstOffset, r.dstStart, r.dstEnd);
	}
	json_object_object_add(obj, "results", array);

	std::string res = json_object_to_json_string(obj);
	json_object_put(obj);
	
    return res;
}
Пример #21
0
json_object* PackageDescription::toJSON() const
{
	json_object* json = NULL;
	if (m_isOldStyle) {
		json = json_object_new_object();
		json_object_object_add(json, (char*) "id",   json_object_new_string((char*) m_id.c_str()));
		json_object_object_add(json, (char*) "version", json_object_new_string(m_version.c_str()));
		json_object_object_add(json, (char*) "size", json_object_new_int((int)m_packageSize));

		json_object* apps = json_object_new_array();
		std::vector<std::string>::const_iterator appIdIt, appIdItEnd;
		for (appIdIt = m_appIds.begin(), appIdItEnd = m_appIds.end(); appIdIt != appIdItEnd; ++appIdIt) {
			json_object_array_add(apps, json_object_new_string((*appIdIt).c_str()));
		}
		json_object_object_add(json, (char*) "apps", apps);

	} else {
		json = json_tokener_parse(m_jsonString.c_str());
		if (!json || is_error(json)) {
			g_warning("%s: Failed to parse '%s' into a JSON string", __PRETTY_FUNCTION__, m_jsonString.c_str());
			return NULL;
		}
		json_object_object_add(json, (char*) "size", json_object_new_int((int)m_packageSize));

		json_object* label = JsonGetObject(json, "icon");
		if (label) {
			std::string icon = json_object_get_string(label);
			json_object_object_del(json, (char*) "icon");
			json_object_object_add(json, (char*) "icon", json_object_new_string((char*) (m_folderPath + "/" + icon).c_str()));
		}

		label = JsonGetObject(json, "miniicon");
		if (label) {
			std::string miniicon = json_object_get_string(label);
			json_object_object_del(json, (char*) "miniicon");
			json_object_object_add(json, (char*) "miniicon", json_object_new_string((char*) (m_folderPath + "/" + miniicon).c_str()));
		}

	}
	return json;
}
Пример #22
0
json_object* OGRGMEGeometryCollectionToGeoJSON(OGRGeometryCollection* poGeometryCollection)

{
    if ( NULL == poGeometryCollection )
        return NULL;

    /* Generate "geometries" object. */
    json_object* pjoGeometries = NULL;
    pjoGeometries = json_object_new_array();

    for( int i = 0; i < poGeometryCollection->getNumGeometries(); ++i ) {
        OGRGeometry* poGeometry = poGeometryCollection->getGeometryRef( i );
        json_object* pjoGeometry = NULL;
        pjoGeometry = OGRGMEGeometryToGeoJSON( poGeometry );
        if ( NULL != poGeometry )
            json_object_array_add( pjoGeometries, pjoGeometry );
        else
            CPLError( CE_Failure, CPLE_AppDefined, "GME: Ignoring NULL geometry" );
    }
    return pjoGeometries;
}
Пример #23
0
OSStatus MICOAddFloatCellToSector(json_object* menus, char* const name,  float content, char* const privilege, json_object* secectionArray)
{
  OSStatus err;
  json_object *object;
  err = kNoErr;

  object = json_object_new_object();
  require_action(object, exit, err = kNoMemoryErr);
  json_object_object_add(object, "N", json_object_new_string(name));      

  json_object_object_add(object, "C", json_object_new_double(content));
  json_object_object_add(object, "P", json_object_new_string(privilege)); 

  if(secectionArray)
    json_object_object_add(object, "S", secectionArray); 

  json_object_array_add(menus, object);

exit:
  return err;  
}
Пример #24
0
json_object* OGRGMEMultiPolygonToGeoJSON( OGRMultiPolygon* poGeometry )
{
    CPLAssert( NULL != poGeometry );

    /* Generate "coordinates" object for 2D or 3D dimension. */
    json_object* pjoCoordinates = NULL;
    pjoCoordinates = json_object_new_array();

    for( int i = 0; i < poGeometry->getNumGeometries(); ++i )
    {
        OGRGeometry* poGeom = poGeometry->getGeometryRef( i );
        CPLAssert( NULL != poGeom );
        OGRPolygon* poPoly = static_cast<OGRPolygon*>(poGeom);

        json_object* pjoPoly = NULL;
        pjoPoly = OGRGMEPolygonToGeoJSON( poPoly );

        json_object_array_add( pjoCoordinates, pjoPoly );
    }

    return pjoCoordinates;
}
Пример #25
0
json_object* OGRGeoJSONWriteLineCoords( OGRLineString* poLine, int nCoordPrecision )
{
    json_object* poObjPoint = NULL;
    json_object* poObjCoords = json_object_new_array();

    const int nCount = poLine->getNumPoints();
    for( int i = 0; i < nCount; ++i )
    {
        if( poLine->getCoordinateDimension() == 2 )
            poObjPoint = OGRGeoJSONWriteCoords( poLine->getX(i), poLine->getY(i), nCoordPrecision );
        else
            poObjPoint = OGRGeoJSONWriteCoords( poLine->getX(i), poLine->getY(i), poLine->getZ(i), nCoordPrecision );
        if( poObjPoint == NULL )
        {
            json_object_put(poObjCoords);
            return NULL;
        }
        json_object_array_add( poObjCoords, poObjPoint );
    }
    
    return poObjCoords;
}
Пример #26
0
/* adding an object does NOT increment reference count */
int cli_json_addowner(json_object *owner, json_object *child, const char *key, int idx)
{
    json_type objty;
    if (NULL == owner) {
        cli_dbgmsg("json: no owner object specified to cli_json_addowner\n");
        return CL_ENULLARG;
    }

    if (NULL == child) {
        cli_dbgmsg("json: no child object specified to cli_json_addowner\n");
        return CL_ENULLARG;
    }
    objty = json_object_get_type(owner);

    if (objty == json_type_object) {
        if (NULL == key) {
            cli_dbgmsg("json: null string specified as key to cli_addowner\n");
            return CL_ENULLARG;
        }
        json_object_object_add(owner, key, child);
    }
    else if (objty == json_type_array) {
        if (idx < 0 || NULL == json_object_array_get_idx(owner, idx))
            json_object_array_add(owner, child);
        else if (0 != json_object_array_put_idx(owner, idx, child)) {
            /* this shouldn't be possible */
            cli_dbgmsg("json: cannot delete idx %d of owner array\n", idx);
            return CL_BREAK;
        }
    }
    else {
        cli_dbgmsg("json: no owner object cannot hold ownership\n");
        return CL_EARG;
    }

    /* increment reference count */
    json_object_get(child);
    return CL_SUCCESS;
}
Пример #27
0
json_object *hostspec_collect_cpu() {
  json_object *obj = json_object_new_array();
  assert(obj);

  FILE *fp = fopen("/proc/cpuinfo", "r");
  if (!fp) {
    ULOG_ERR("Unable to open /proc/cpuinfo: %s\n", strerror(errno));
    goto error;
  }

  char buf[1024], *p;
  json_object *obj_proc = NULL;
  while ((p = fgets(buf, sizeof buf, fp))) {
    chomp(p);

    if (begin_with(p, "processor\t")) {
      obj_proc = json_object_new_object();
      json_object_array_add(obj, obj_proc);
    }

    // Only send the model name for now: this should work for x86/amd64/arm/mips
    if (obj_proc) {
      if (begin_with(p, "cpu model\t") || begin_with(p, "model name\t")) {
        json_object_object_add(obj_proc, "model_name", json_object_new_string(after_colon(p)));
      }
    }
  }

  fclose(fp);
  return obj;

error:
  if (fp) {
    fclose(fp);
  }

  json_object_put(obj);
  return NULL;
}
Пример #28
0
PUBLIC int  get_bus_config_bus_driving_data(char *buf, int size){
	int sta_count,ret;
	if( size <= 1024){
		return RET_ERROR;
	}
	json_object *new_obj = NULL, *arr_obj=NULL;
	new_obj = json_object_new_array();
	
	for (sta_count = 0; sta_count < BUS_STA_MX_COUNT ; sta_count ++){
		arr_obj = json_object_new_object();
		json_object_object_add(arr_obj, "id", json_object_new_int(sta_count));

		json_object_object_add(arr_obj, "st", json_object_new_int(bus_sta_status[sta_count] ));
		json_object_array_add(new_obj, arr_obj);
	}
	snprintf(buf, size, "%s",json_object_to_json_string(new_obj));
	ret = json_object_put(new_obj);
	WEB_STRACE(" ret:%d ,info NULL: %d, arr_obj :%d\n", ret,(new_obj == NULL)? 1:0,
		(arr_obj == NULL) ?1:0);
	
	return RET_OK;
}
Пример #29
0
int ConnectDb::packageData(string & ret)
{
	json_object *rootobj = json_object_new_object();	 //创建一个JSON对象
	json_object *arryobj = json_object_new_array();		//创建一个json数组对象
	JsonObjGuard JsonGuard(rootobj);

	while (DBCommand.FetchNext()) 
	{
		json_object *obj = json_object_new_object();
		int filec = DBCommand.FieldCount();
		for(int i=1;i<filec+1;i++)
		{
			json_object_object_add(obj,DBCommand[i].Name(),json_object_new_string(DBCommand[i].asString()));	
		}
		json_object_array_add(arryobj,obj);  
	}
	json_object_object_add(rootobj,"data",arryobj);
	ret= json_object_to_json_string(rootobj);
	AC_INFO("%s\n",ret.c_str());
	return 1;

}
Пример #30
0
int cli_jsonstr(json_object *obj, const char* key, const char* s)
{
    json_type objty;
    json_object *fpobj;
    if (NULL == obj) {
        cli_dbgmsg("json: null 'obj' specified to cli_jsonstr\n");
        return CL_ENULLARG;
    }
    objty = json_object_get_type(obj);

    if (objty == json_type_object) {
        if (NULL == key) {
            cli_dbgmsg("json: null string specified as 'key' to cli_jsonstr\n");
            return CL_ENULLARG;
        }
    }
    else if (objty != json_type_array) {
        return CL_EARG;
    }

    if (NULL == s) {
        cli_dbgmsg("json: null string specified as 's' to  cli_jsonstr\n");
        return CL_ENULLARG;
    }

    fpobj = json_object_new_string(s);
    if (NULL == fpobj) {
        cli_errmsg("json: no memory for json string object\n");
        return CL_EMEM;
    }

    if (objty == json_type_object)
        json_object_object_add(obj, key, fpobj);
    else if (objty == json_type_array)
        json_object_array_add(obj, fpobj);

    return CL_SUCCESS;
}