Exemple #1
0
/**
 * Add new key - value pair to json object.
 * @param osName Key name.
 * @param pszValue String value.
 *
 * @since GDAL 2.3
 */
void CPLJSONObject::Add(const std::string &osName, const char *pszValue)
{
    if(nullptr == pszValue)
    {
        return;
    }
    std::string objectName;
    CPLJSONObject object = GetObjectByPath( osName, objectName );
    if( object.IsValid() &&
        json_object_get_type(TO_JSONOBJ(object.m_poJsonObject)) ==
            json_type_object )
    {
        json_object *poVal = json_object_new_string( pszValue );
        json_object_object_add( TO_JSONOBJ(object.GetInternalHandle()),
                                           objectName.c_str(), poVal );
    }
}
Exemple #2
0
JSON kp_tget_enc (const char *key, bool dir, bool link)
{
    JSON o = NULL;

    if (!key) {
        errno = EINVAL;
        goto done;
    }
    o = Jnew ();
    json_object_object_add (o, key, NULL);
    if (dir)
        Jadd_bool (o, ".flag_directory", true);
    if (link)
        Jadd_bool (o, ".flag_readlink", true);
done:
    return o;
}
int
noit_rest_eventer_logs(noit_http_rest_closure_t *restc, int n, char **p) {
  char *endptr = NULL;
  const char *since_s, *last_s;
  const char *jsonstr;
  char errbuf[128];
  unsigned long long since;
  int last = 0;
  struct json_object *doc;
  noit_log_stream_t ls;
  noit_http_request *req = noit_http_session_request(restc->http_ctx);
  since_s = noit_http_request_querystring(req, "since");
  if(since_s) since = strtoull(since_s, &endptr, 10);
  last_s = noit_http_request_querystring(req, "last");
  if(last_s) last = atoi(last_s);

  assert(n==1);
  ls = noit_log_stream_find(p[0]);
  if(!ls || strcmp(noit_log_stream_get_type(ls),"memory"))
    goto not_found;

  doc = json_object_new_array();
  if(endptr != since_s)
    noit_log_memory_lines_since(ls, since, json_spit_log, doc);
  else
    noit_log_memory_lines(ls, last, json_spit_log, doc);

  noit_http_response_ok(restc->http_ctx, "application/json");
  jsonstr = json_object_to_json_string(doc);
  noit_http_response_append(restc->http_ctx, jsonstr, strlen(jsonstr));
  noit_http_response_append(restc->http_ctx, "\n", 1);
  json_object_put(doc);
  noit_http_response_end(restc->http_ctx);
  return 0;
 not_found:
  doc = json_object_new_object();
  snprintf(errbuf, sizeof(errbuf), "log '%s' not found", p[0]);
  json_object_object_add(doc, "error", json_object_new_string(errbuf));
  jsonstr = json_object_to_json_string(doc);
  noit_http_response_not_found(restc->http_ctx, "application/json");
  noit_http_response_append(restc->http_ctx, jsonstr, strlen(jsonstr));
  noit_http_response_append(restc->http_ctx, "\n", 1);
  json_object_put(doc);
  noit_http_response_end(restc->http_ctx);
  return 0;
}
static void s_json_to_protocol_info(int io, PACKET *j_parent, C_DMS_IPI **xx)
{
	x_DMS_IPI **pp = (x_DMS_IPI **)xx;
	PACKET *json;
	int len = sizeof(C_DMS_IPI);
	const char *str = "protocol_info";

	if(s_is_both_ok(io, j_parent, (void **)pp, &json, str, len))
	{
		s_add_str_to_json(io, json, "id",				IN_OUT((*pp)->id));
		s_add_str_to_json(io, json, "mime", 			IN_OUT((*pp)->mime));
		s_add_str_to_json(io, json, "label",			IN_OUT((*pp)->label));
		s_add_uin_to_json(io, json, "class",			IN_OUT((*pp)->class));

		if(io)
			json_object_object_add(j_parent, str, json);
	}
struct json_object *call_userflow_sdp(struct call *call)
{
	struct json_object *jobj = NULL;
	struct json_object *jsdp = NULL;

	if (!call)
		return NULL;

	dict_apply(call->users, userflow_sdp_handler, &jsdp);

	if (jsdp) {
		jobj = json_object_new_object();
		json_object_object_add(jobj, "sdp", jsdp);
	}

	return jobj;
}
Exemple #6
0
static int query_state_pair (flux_t *h, int64_t j, json_object **jcb)
{
    json_object *o = NULL;
    int64_t st = (int64_t)J_FOR_RENT;;

    if (extract_raw_state (h, j, &st) < 0) return -1;

    *jcb = Jnew ();
    o = Jnew ();
    /* Old state is unavailable through the query.
     * One should use notification service instead.
     */
    Jadd_int64 (o, JSC_STATE_PAIR_OSTATE, st);
    Jadd_int64 (o, JSC_STATE_PAIR_NSTATE, st);
    json_object_object_add (*jcb, JSC_STATE_PAIR, o);
    return 0;
}
Exemple #7
0
/* kvs.put
 */
JSON kp_tput_enc (const char *key, JSON val, bool link, bool dir)
{
    JSON o = NULL;

    if (!key) {
        errno = EINVAL;
        goto done;
    }
    o = Jnew ();
    json_object_object_add (o, key, val);
    if (dir)
        Jadd_bool (o, ".flag_mkdir", true);
    if (link)
        Jadd_bool (o, ".flag_symlink", true);
done:
    return o;
}
JO calib_result2json(const calib_result&res) {
	// Build json object
	struct json_object *new_obj;
	new_obj = json_object_new_object();		
	
	double est_E_d 	= res.radius_r / res.radius_l; 
	/** XXX ??? */
	double est_E_b 	= res.axle / 0.09;
	json_object_object_add(new_obj, "axle", json_object_new_double(res.axle) );
	json_object_object_add(new_obj, "l_diam", json_object_new_double(res.radius_l*2) );
	json_object_object_add(new_obj, "r_diam", json_object_new_double(res.radius_r*2) );
	json_object_object_add(new_obj, "l_x", json_object_new_double(res.l[0]) );
	json_object_object_add(new_obj, "l_y", json_object_new_double(res.l[1]) );
	json_object_object_add(new_obj, "l_theta", json_object_new_double(res.l[2]) );
	json_object_object_add(new_obj, "E_d", json_object_new_double(est_E_d) );
	json_object_object_add(new_obj, "E_b", json_object_new_double(est_E_b) );
	
	return new_obj;
}
Exemple #9
0
static struct json_object* serialize_var(const struct var* var, int mode){
	struct json_object* json = json_object_new_object();
	if ( mode == SERIALIZE_FULL ){
		json_object_object_add(json, "name", json_object_new_string(var->name));
		json_object_object_add(json, "description", var->description ? json_object_new_string(var->description) : NULL);
		json_object_object_add(json, "options", var->options ? json_tokener_parse(var->options) : NULL);
		json_object_object_add(json, "datatype", json_object_new_int(var->datatype));
	}
	json_object_object_add(json, "handle", json_object_new_int(var->handle));
	json_object_object_add(json, "value", var->store(var));
	return json;
}
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;
}
Exemple #11
0
static
int processor_setup_minute(processor_state_t *self, json_object *request)
{
    // we know that started_at data is valid since we already checked that
    // when determining which processor to call
    int minute = 0;
    json_object *started_at_obj = NULL;
    if (json_object_object_get_ex(request, "started_at", &started_at_obj)) {
        const char *started_at = json_object_get_string(started_at_obj);
        char hours[3] = {started_at[11], started_at[12], '\0'};
        char minutes[3] = {started_at[14], started_at[15], '\0'};
        minute = 60 * atoi(hours) + atoi(minutes);
    }
    json_object *minute_obj = json_object_new_int(minute);
    json_object_object_add(request, "minute", minute_obj);
    // printf("[D] minute: %d\n", minute);
    return minute;
}
Exemple #12
0
bool
BeatBoard::SearchApiService::drizzleResultToJson( std::string& result )
{
  bool ret = false;
  struct json_object *my_object = json_object_new_object();
  struct json_object *my_array = json_object_new_array();
  char label[] = "messages";

  while ( drizzle_row_read(&drizzle_response.result, &drizzle_response.ret) != 0 && drizzle_response.ret == DRIZZLE_RETURN_OK )
  {
    //ret = readDrizzleField( my_object );
    ret = readDrizzleField( my_array );
  }
  json_object_object_add(my_object, label, my_array);
  result = std::string(json_object_to_json_string(my_object));
  json_object_put(my_object);
  return ret;
}
Exemple #13
0
void fcgi_print_result(struct fcgi_recv_fileser* recv_data,int result,uint32_t reason_id)
{
	struct json_object *my_object;
	struct json_object *sub_array;
	uint32_t i = 0;
	my_object = json_object_new_object();
	sub_array = json_object_new_array();
	char str_tmp[32];
	if(result == FAIL){
		json_object_object_add(my_object,"result",json_object_new_string("fail"));
		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,"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,"key",json_object_new_int(recv_data->key));
	json_object_object_add(my_object,"lloccode",json_object_new_string(recv_data->lloccode));
	json_object_object_add(my_object,"cnt",json_object_new_int(recv_data->cnt));
	if(recv_data->cnt == 0){
		goto PRINT_END;
	}
	for(i = 0;i < recv_data->cnt && i < CNT_MAX; i++){
		sprintf(str_tmp,"%u",recv_data->Thumbid[i]);
		json_object_array_add(sub_array, json_object_new_string(str_tmp));
	}
	json_object_object_add(my_object,"thumbid",sub_array);
PRINT_END:
	printf("%s\n",json_object_to_json_string(my_object));
	json_object_put(sub_array);
	json_object_put(my_object);
	return ;
}
Exemple #14
0
int main(int argc, char **argv)
{
  json_tokener *tok;
  json_object *my_string, *my_int, *my_object, *my_array;
  json_object *new_obj;
  int i;

  MC_SET_DEBUG(1);

  my_string = json_object_new_string("\t");
  printf("my_string=%s\n", json_object_get_string(my_string));
  printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
  json_object_put(my_string);

  my_string = json_object_new_string("\\");
  printf("my_string=%s\n", json_object_get_string(my_string));
  printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
  json_object_put(my_string);

  my_string = json_object_new_string("foo");
  printf("my_string=%s\n", json_object_get_string(my_string));
  printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));

  my_int = json_object_new_int(9);
  printf("my_int=%ld\n", json_object_get_int(my_int));
  printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int));

  my_array = json_object_new_array();
  json_object_array_add(my_array, json_object_new_int(1));
  json_object_array_add(my_array, json_object_new_int(2));
  json_object_array_add(my_array, json_object_new_int(3));
  json_object_array_put_idx(my_array, 4, json_object_new_int(5));
  printf("my_array=\n");
  for(i=0; i < json_object_array_length(my_array); i++) {
    json_object *obj = json_object_array_get_idx(my_array, i);
    printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
  }
  printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));    

  my_object = json_object_new_object();
  json_object_object_add(my_object, "abc", json_object_new_int(12));
  json_object_object_add(my_object, "foo", json_object_new_string("bar"));
  json_object_object_add(my_object, "bool0", json_object_new_boolean(0));
  json_object_object_add(my_object, "bool1", json_object_new_boolean(1));
  json_object_object_add(my_object, "baz", json_object_new_string("bang"));
  json_object_object_add(my_object, "baz", json_object_new_string("fark"));
  json_object_object_del(my_object, "baz");
  /*json_object_object_add(my_object, "arr", my_array);*/
  printf("my_object=\n");
  json_object_object_foreach(my_object, key, val) {
    printf("\t%s: %s\n", key, json_object_to_json_string(val));
  }
void WebAppBase::createActivity()
{
	if (!m_page)
		return;

	// Setup an activity for this app if it is the top level app
	if (m_page->parent())
		return;

	LSError lsError;
	LSErrorInit(&lsError);

	json_object* payload = json_object_new_object();
	json_object* activityObj = json_object_new_object();
	json_object_object_add(activityObj, (char*) "name",
						   json_object_new_string(m_appId.c_str()));
	json_object_object_add(activityObj, (char*) "description",
						   json_object_new_string(m_processId.c_str()));
	json_object* activityTypeObj = json_object_new_object();
	json_object_object_add(activityTypeObj, (char*) "foreground",
						   json_object_new_boolean(true));
	json_object_object_add(activityObj, (char*) "type",
						   activityTypeObj);	

	json_object_object_add(payload, "activity", activityObj);
	json_object_object_add(payload, "subscribe", json_object_new_boolean(true));
	json_object_object_add(payload, "start", json_object_new_boolean(true));
	json_object_object_add(payload, "replace", json_object_new_boolean(true));

	if (!LSCallFromApplication(WebAppManager::instance()->m_servicePrivate,
							   "palm://com.palm.activitymanager/create",
							   json_object_to_json_string(payload),
							   m_page->getIdentifier(),
							   WebAppManager::activityManagerCallback,
							   this, &m_activityManagerToken, &lsError)) {
		g_critical("%s: %d. Failed in calling activity manager create: %s",
				   __PRETTY_FUNCTION__, __LINE__, lsError.message);
		LSErrorFree(&lsError);
	}

	json_object_put(payload);
}
json_object* EASPolicy::toNewJSON() const
{
	json_object* policy = json_object_new_object();

	json_object_object_add(policy, "devicePasswordEnabled", json_object_new_boolean(m_passwordRequired));
	json_object_object_add(policy, "minDevicePasswordLength", json_object_new_int(m_minLength));
	json_object_object_add(policy, "maxDevicePasswordFailedAttempts", json_object_new_int(m_maxRetries));
	json_object_object_add(policy, "alphanumericDevicePasswordRequired", json_object_new_boolean(m_isAlphaNumeric));
	json_object_object_add(policy, "allowSimpleDevicePassword", json_object_new_boolean(m_allowSimplePassword));

	json_object_object_add(policy, "maxInactivityTimeDeviceLock", json_object_new_int(m_inactivityInSeconds));

	if (!m_id.empty()) {
	    json_object_object_add(policy, "_id", json_object_new_string(m_id.c_str()));
	}
	if (m_isDevicePolicy)
	    json_object_object_add(policy, "_kind", json_object_new_string("com.palm.securitypolicy.device:1"));

	return policy;
}
void EASPolicyManager::save()
{
	if (!m_service) {
		g_warning ("Service handle not available yet, cannot query device policy");
		return;
	}

	LSError lserror;
	LSErrorInit (&lserror);

	if (m_callToken) {
		g_debug ("Cancelling call token %lu", m_callToken);
		if (LSCallCancel (m_service, m_callToken, &lserror)) {
			g_warning ("Unable to cancel call with token %lu error message %s", m_callToken, lserror.message);
		}
		m_callToken = 0;
	}

	json_object* policyJson = m_aggregate->toNewJSON();
	json_object_object_add(policyJson, "status", getPolicyStatus());
	gchar* policyStr = g_strdup_printf ("{ \"objects\":[%s]}", json_object_to_json_string (policyJson));
	g_message ("%s: Writing device policy %s to mojodb", __func__, policyStr);

	if (m_aggregate->m_id.empty()) {

	    if (!LSCallOneReply (m_service, "palm://com.palm.db/put", policyStr, 
							 &EASPolicyManager::cbDevicePolicySaved, this, NULL, &lserror)) 
		{
			g_warning ("%s: Failed at %s with message %s", __func__, lserror.func, lserror.message);
			LSErrorFree (&lserror);
	    }
	}
	else {

	    if (!LSCallOneReply (m_service, "palm://com.palm.db/merge", policyStr, 
				    &EASPolicyManager::cbDevicePolicySaved, this, NULL, &lserror)) {
			g_warning ("%s: Failed at %s with message %s", __func__, lserror.func, lserror.message);
			LSErrorFree (&lserror);
	    }
	}

	json_object_put (policyJson);
	g_free (policyStr);
}
Exemple #18
0
json_object* Flow::processJson(ProcessInfo *proc) {
  json_object *inner;
  
  inner = json_object_new_object();
  json_object_object_add(inner, "cpu_id", json_object_new_int64(proc->cpu_id));
  json_object_object_add(inner, "pid", json_object_new_int64(proc->pid));
  json_object_object_add(inner, "father_pid", json_object_new_int64(proc->father_pid));
  json_object_object_add(inner, "name", json_object_new_string(proc->name));
  json_object_object_add(inner, "father_name", json_object_new_string(proc->father_name));
  json_object_object_add(inner, "user_name", json_object_new_string(proc->user_name));
  
  return(inner);
}
Exemple #19
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;
    }
}
Exemple #20
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;
    }
}
Exemple #21
0
int32_t AcdCallDataCollection::get_call_data_by_plat(string& data)
{
    SingleRWLocker s(&_lock, true);
    string fail_str = "{\"result\":\"-1\",\"data\":\"memory error\"}";
    json_object *root = json_object_new_object();
    if (root == NULL) {
        acd_tool::m_logger.WriteLog(LOG_LEVEL_WARNING, __FILE__, __LINE__, __FUNCTION__,
            "new root json object failed");
        data = fail_str;
        return -1;
    }
    json_object *calldata = json_object_new_object();
    if (calldata == NULL) {
        acd_tool::m_logger.WriteLog(LOG_LEVEL_WARNING, __FILE__, __LINE__, __FUNCTION__,
            "new calldata json object failed");
        data = fail_str;
        json_object_put(root);
        return -1;
    }
    json_object_object_add(calldata, "OutCallNum", json_object_new_int(_cc_call_data.outbound_call_num));
    json_object_object_add(calldata, "OutAnsNum", json_object_new_int(_cc_call_data.outbound_ans_num));
    json_object_object_add(calldata, "OutCallTime", json_object_new_int(_cc_call_data.outbound_call_time));
    json_object_object_add(calldata, "InAnsNum", json_object_new_int(_cc_call_data.inbound_ans_num));
    json_object_object_add(calldata, "InCallNum", json_object_new_int(_cc_call_data.inbound_ans_num));
    json_object_object_add(calldata, "InCallTime", json_object_new_int(_cc_call_data.inbound_call_time));
    json_object_object_add(calldata, "InAlertTime", json_object_new_int(_cc_call_data.inbound_alerting_time));
    json_object_object_add(root, "result", json_object_new_string("0"));
    json_object_object_add(root, "data", calldata);
    data = json_object_to_json_string(root);
    //acd_tool::m_logger.WriteLog(LOG_LEVEL_NOTICE, __FILE__, __LINE__, __FUNCTION__,
    //    "get cc call data success, data(%s)", data.c_str());
    acd_tool::m_logger.WriteLog(LOG_LEVEL_NOTICE, __FILE__, __LINE__, __FUNCTION__,
        "get cc call data success");
    json_object_put(root);
    return 0;
}
Exemple #22
0
int SchemaJsonResponseFormatter::writeData(const GenericAnswer* ans,
                                           FILE* output) const {
    const SchemaAnswset& answSet = *((const SchemaAnswset*)ans);
    json_object* json_doc, *schemata;

    json_doc = json_object_new_object();
    schemata = json_object_new_array();

    /* Total number of formulae considered
     * (some schemata might have been dropped) */
    json_object_object_add(json_doc, "total",
                           json_object_new_int(answSet.total));
    json_object_object_add(json_doc, "size",
                           json_object_new_int(answSet.schemata.size()));

    for (const ExprSchema& exprSch : answSet.schemata) {
        json_object* schema = json_object_new_object();

        json_object_object_add(
            schema, "cmmlSchema",
            json_object_new_string(exprSch.root->toString().c_str()));
        json_object_object_add(schema, "coverage",
                               json_object_new_int(exprSch.coverage));

        json_object* formulae = json_object_new_array();
        for (const uint32_t f_id : exprSch.formulae) {
            json_object_array_add(formulae, json_object_new_int(f_id));
        }
        json_object_object_add(schema, "formulae", formulae);

        json_object* subst = json_object_new_array();
        for (const string& xref : exprSch.subst) {
            json_object_array_add(subst, json_object_new_string(xref.c_str()));
        }
        json_object_object_add(schema, "subst", subst);

        json_object_array_add(schemata, schema);
    }
    json_object_object_add(json_doc, "schemata", schemata);

    string json_string = json_object_to_json_string(json_doc);
    fwrite(json_string.c_str(), json_string.size(), 1, output);

    json_object_put(json_doc);
    return json_string.size();
}
Exemple #23
0
json_object *cli_jsonobj(json_object *obj, const char *key)
{
    json_object *newobj;

    if (obj && key && json_object_object_get_ex(obj, key, &newobj))
        return json_object_is_type(newobj, json_type_object) ? newobj : NULL;

    newobj = json_object_new_object();
    if (!(newobj))
        return NULL;

    if (obj && key) {
        json_object_object_add(obj, key, newobj);
        if (!json_object_object_get_ex(obj, key, &newobj))
            return NULL;
    }

    return newobj;
}
Exemple #24
0
static int query_rdesc (flux_t *h, int64_t j, json_object **jcb)
{
    json_object *o = NULL;
    int64_t nnodes = -1;
    int64_t ntasks = -1;
    int64_t walltime = -1;

    if (extract_raw_nnodes (h, j, &nnodes) < 0) return -1;
    if (extract_raw_ntasks (h, j, &ntasks) < 0) return -1;
    if (extract_raw_walltime (h, j, &walltime) < 0) return -1;

    *jcb = Jnew ();
    o = Jnew ();
    Jadd_int64 (o, JSC_RDESC_NNODES, nnodes);
    Jadd_int64 (o, JSC_RDESC_NTASKS, ntasks);
    Jadd_int64 (o, JSC_RDESC_WALLTIME, walltime);
    json_object_object_add (*jcb, JSC_RDESC, o);
    return 0;
}
json_object* EASPolicy::toJSON() const
{
	json_object* policy = json_object_new_object();

	json_object* password = json_object_new_object();
	json_object_object_add(password, "enabled", json_object_new_boolean(m_passwordRequired));
	json_object_object_add(password, "minLength", json_object_new_int(m_minLength));
	json_object_object_add(password, "maxRetries", json_object_new_int(m_maxRetries));
	json_object_object_add(password, "alphaNumeric", json_object_new_boolean(m_isAlphaNumeric));
	if (m_passwordRequired && !m_isAlphaNumeric) {
		json_object_object_add(password, "allowSimplePassword", json_object_new_boolean(m_allowSimplePassword));
	}

	json_object_object_add (policy, "password", password);

	json_object_object_add(policy, "inactivityInSeconds", json_object_new_int(m_inactivityInSeconds));

	json_object_object_add(policy, "id", json_object_new_string(m_id.c_str()));

	return policy;
}
Exemple #26
0
static rsRetVal
addCtrForReporting(json_object *to, const uchar* field_name, intctr_t value) {
	json_object *v = NULL;
	DEFiRet;

	/*We should migrate libfastjson to support uint64_t in addition to int64_t.
	  Although no counter is likely to grow to int64 max-value, this is theoritically
	  incorrect (as intctr_t is uint64)*/
	CHKmalloc(v = json_object_new_int64((int64_t) value));

	json_object_object_add(to, (const char*) field_name, v);
finalize_it:
	if (iRet != RS_RET_OK) {
		if (v != NULL) {
			json_object_put(v);
		}
	}
	RETiRet;
}
static void s_add_llg_to_json(int io, PACKET *json, char *key, long long *val)
{
	if(io)
	{
		char temp[256];
		sprintf(temp, "%lld", *val);
		json_object_object_add(json, key, json_object_new_string(temp));
	}
	else
	{
		struct json_object *obj = json_object_object_get(json, key);
		if(obj)
		{
			const char *str = json_object_get_string(obj);
			if(str)
				sscanf(str, "%lld", val);
		}
	}
}
Exemple #28
0
/* Make init JSON string */
char *si_init_json(void){
	json_object *jo, *ji;
	const char *result;
	char *jsonstr;

	jo = json_object_new_object();
	ji = json_object_new_string("init");

	json_object_object_add(jo, "init", ji);
	result = json_object_to_json_string(jo);

	if((jsonstr = (char *) malloc(strlen(result)+1)) == NULL){
		json_object_put(jo);
		return NULL;
	}
	strcpy(jsonstr, result);
	json_object_put(jo);
	return jsonstr;
}
Exemple #29
0
static void init (struct afb_req request) {        /* AFB_SESSION_CHECK */

    mediaCtxHandleT *ctx = afb_req_context_get(request);
    json_object *jresp;

    /* create a private client context */
    if (!ctx) {
        ctx = initMediaCtx();
        afb_req_context_set (request, ctx, free);
    }

    /* initialize server connection */
    if (!ctx->media_server)
      _rygel_init (ctx);

    jresp = json_object_new_object ();
    json_object_object_add (jresp, "init", json_object_new_string ("success"));
    afb_req_success (request, jresp, "Media - Initialized");
}
Exemple #30
0
static
void processor_setup_allocated_memory(processor_state_t *self, json_object *request)
{
    json_object *allocated_memory_obj;
    if (json_object_object_get_ex(request, "allocated_memory", &allocated_memory_obj))
        return;
    json_object *allocated_objects_obj;
    if (!json_object_object_get_ex(request, "allocated_objects", &allocated_objects_obj))
        return;
    json_object *allocated_bytes_obj;
    if (json_object_object_get_ex(request, "allocated_bytes", &allocated_bytes_obj)) {
        long allocated_objects = json_object_get_int64(allocated_objects_obj);
        long allocated_bytes = json_object_get_int64(allocated_bytes_obj);
        // assume 64bit ruby
        long allocated_memory = allocated_bytes + allocated_objects * 40;
        json_object_object_add(request, "allocated_memory", json_object_new_int64(allocated_memory));
        // printf("[D] allocated memory: %lu\n", allocated_memory);
    }
}