Example #1
0
/**
	json 2 protocol4
*/
int json_decode_protocol4 (protocol4* self, json_t* root) 
{
  json_error_t error;

	if (!root) {
		  fprintf(stderr, "error: on line %d: %s\n", error.line, error.text);
		  return 1;
	}

	if (!json_is_object(root)) {
		  fprintf(stderr, "error: root is not an object\n");
			json_decref(root);
			json_decref(root);
		  return 1;
	}

	json_t *network, *address, *magic;

  network = json_object_get(root, "network");
  address = json_object_get(root, "address");
  magic = json_object_get(root, "magic");

  if(!json_is_number(network) ||  !json_is_number(address) || !json_is_number(magic)) {
      fprintf(stderr, "error: something is not a number\n");
      json_decref(root);
      return 1;
  }

	self->network = json_number_value(network);
	self->address = json_number_value(address);
	self->magic = json_number_value(magic);
	
	return 0;
} 
Example #2
0
client_data_t * extract_json_summary(json_t *node, client_data_t *client) {
	json_t *subnode, *subnode2;
	size_t i;
	
	/* Single data */
	client->summary.uptime = json_ulong_obj(node, "uptime");
	client->summary.time   = json_ulong_obj(node, "time");
	
	/* Sub data */
	subnode = json_object_get(node, "memory");
	json_check_object(subnode);
	
	client->summary.ram_total  = json_ulonglong_obj(subnode, "ram_total");
	client->summary.ram_used   = json_ulonglong_obj(subnode, "ram_used");
	client->summary.swap_total = json_ulonglong_obj(subnode, "swap_total");
	client->summary.swap_free  = json_ulonglong_obj(subnode, "swap_free");

	
	subnode = json_object_get(node, "battery");
	json_check_object(subnode);
	
	client->summary.battery_full   = json_ulong_obj(subnode, "charge_full");
	client->summary.battery_now    = json_ulong_obj(subnode, "charge_now");
	client->summary.battery_load   = json_ulong_obj(subnode, "load");
	client->summary.battery_status = json_ulong_obj(subnode, "status");
	
	
	subnode = json_object_get(node, "cpu_usage");
	json_check_array(subnode);
	
	client->summary.cpu_count = json_array_size(subnode) - 1;
	client->summary.cpu_usage = (long) json_number_value(json_array_get(subnode, 0));
	
	
	subnode = json_object_get(node, "loadavg");
	json_check_array(subnode);
	
	for(i = 0; i < json_array_size(subnode) && i < 3; i++)
		client->summary.loadavg[i] = (float) json_number_value(json_array_get(subnode, i));
	
	subnode = json_object_get(node, "sensors");
	json_check_object(subnode);
	
	subnode2 = json_object_get(subnode, "cpu");
	json_check_object(subnode2);
	
	client->summary.sensors_cpu_avg  = json_ulong_obj(subnode2, "average");
	client->summary.sensors_cpu_crit = json_ulong_obj(subnode2, "critical");
	
	subnode2 = json_object_get(subnode, "hdd");
	json_check_object(subnode2);
	
	client->summary.sensors_hdd_peak = json_ulong_obj(subnode2, "peak");
	client->summary.sensors_hdd_avg  = json_ulong_obj(subnode2, "average");
	
	return client;
}
Example #3
0
static void run_tests()
{
    json_t *integer, *real;
    json_int_t i;
    double d;

    integer = json_integer(5);
    real = json_real(100.1);

    if(!integer)
        fail("unable to create integer");
    if(!real)
        fail("unable to create real");

    i = json_integer_value(integer);
    if(i != 5)
        fail("wrong integer value");

    d = json_real_value(real);
    if(d != 100.1)
        fail("wrong real value");

    d = json_number_value(integer);
    if(d != 5.0)
        fail("wrong number value");
    d = json_number_value(real);
    if(d != 100.1)
        fail("wrong number value");

    json_decref(integer);
    json_decref(real);

#ifdef NAN
    real = json_real(NAN);
    if(real != NULL)
        fail("could construct a real from NaN");

    real = json_real(1.0);
    if(json_real_set(real, NAN) != -1)
        fail("could set a real to NaN");

    if(json_real_value(real) != 1.0)
        fail("real value changed unexpectedly");

    json_decref(real);
#endif

#ifdef INFINITY
    test_inifity();
#endif
}
Example #4
0
cxBool cxJsonPushValue(json_t *value)
{
    if(json_is_integer(value)){
        lua_pushinteger(gL,(int)json_integer_value(value));
    }else if(json_is_string(value)){
        lua_pushstring(gL, json_string_value(value));
    }else if(json_is_number(value)){
        lua_pushnumber(gL, json_number_value(value));
    }else if(json_is_true(value)){
        lua_pushboolean(gL, 1);
    }else if(json_is_false(value)){
        lua_pushboolean(gL, 0);
    }else if(json_is_null(value)){
        lua_pushnil(gL);
    }else if(json_is_real(value)){
        lua_pushnumber(gL, json_real_value(value));
    }else if(json_is_object(value)){
        cxJsonPushObject(value);
    }else if(json_is_array(value)){
        cxJsonPushArray(value);
    }else{
        return false;
    }
    return true;
}
Example #5
0
static cxDouble jsonToDouble(json_t *v,cxDouble dv)
{
    CX_RETURN(v == NULL,dv);
    v = jsonParseRegisterValue(v);
    if(json_is_string(v)){
        return atof(json_string_value(v));
    }
    return json_number_value(v);
}
Example #6
0
static cxInt jsonToInt(json_t *v,cxInt dv)
{
    CX_RETURN(v == NULL,dv);
    v = jsonParseRegisterValue(v);
    if(json_is_string(v)){
        return atoi(json_string_value(v));
    }
    return (cxInt)json_number_value(v);
}
Example #7
0
/* Encode field header based on LTYPE and field number defined in the field structure.
 * Call this from the callback before writing out field contents. */
static int checkreturn pb_encode_tag_for_field(pb_ostream_t *stream, const json_t *field) { // type,tag
    int wiretype;
    json_t *type = json_object_get(field, "type");
    json_t *tag = json_object_get(field, "tag");

    wiretype = pb__get_constant_type(json_string_value(type));

    return pb_encode_tag(stream, wiretype, json_number_value(tag));
}
Example #8
0
/**
	json 2 protocol5
*/
int json_decode_protocol5 (protocol5* self, json_t* root) 
{
  json_error_t error;

	if (!root) {
		  fprintf(stderr, "error: on line %d: %s\n", error.line, error.text);
		  return 1;
	}

	if (!json_is_object(root)) {
		  fprintf(stderr, "error: root is not an object\n");
			json_decref(root);
			json_decref(root);
		  return 1;
	}

	json_t *network, *address, *broadcast, *state, *dimmer;

  network = json_object_get(root, "network");
  address = json_object_get(root, "address");
  broadcast = json_object_get(root, "broadcast");
  state = json_object_get(root, "state");
  dimmer = json_object_get(root, "dimmer");

  if(!json_is_number(network) || !json_is_number(address) || !json_is_number(broadcast) || 
		 !json_is_number(state) || !json_is_number(dimmer))
  {
      fprintf(stderr, "error: something is not a number\n");
      json_decref(root);
      return 1;
  }

	self->network = json_number_value(network);
	self->address = json_number_value(address);
	self->broadcast = json_number_value(broadcast);
	self->state = json_number_value(state);
	self->dimmer = json_number_value(dimmer);
	
	return 0;
} 
Example #9
0
bool w_perf_finish(w_perf_t *perf) {
  gettimeofday(&perf->time_end, NULL);
  w_timeval_sub(perf->time_end, perf->time_begin, &perf->duration);
#ifdef HAVE_SYS_RESOURCE_H
  getrusage(RUSAGE_SELF, &perf->usage_end);

  // Compute the delta for the usage
  w_timeval_sub(perf->usage_end.ru_utime, perf->usage_begin.ru_utime,
                &perf->usage.ru_utime);
  w_timeval_sub(perf->usage_end.ru_stime, perf->usage_begin.ru_stime,
                &perf->usage.ru_stime);

#define DIFFU(n) perf->usage.n = perf->usage_end.n - perf->usage_begin.n
  DIFFU(ru_maxrss);
  DIFFU(ru_ixrss);
  DIFFU(ru_idrss);
  DIFFU(ru_minflt);
  DIFFU(ru_majflt);
  DIFFU(ru_nswap);
  DIFFU(ru_inblock);
  DIFFU(ru_oublock);
  DIFFU(ru_msgsnd);
  DIFFU(ru_msgrcv);
  DIFFU(ru_nsignals);
  DIFFU(ru_nvcsw);
  DIFFU(ru_nivcsw);
#undef DIFFU
#endif

  if (!perf->will_log) {
    if (perf->wall_time_elapsed_thresh == 0) {
      json_t *thresh = cfg_get_json(NULL, "perf_sampling_thresh");
      if (thresh) {
        if (json_is_number(thresh)) {
          perf->wall_time_elapsed_thresh = json_number_value(thresh);
        } else {
          json_unpack(thresh, "{s:f}", perf->description,
                    &perf->wall_time_elapsed_thresh);
        }
      }
    }

    if (perf->wall_time_elapsed_thresh > 0 &&
        w_timeval_diff(perf->time_begin, perf->time_end) >
            perf->wall_time_elapsed_thresh) {
      perf->will_log = true;
    }
  }

  return perf->will_log;
}
Example #10
0
json_t* OBSAPIMessageHandler::HandleSetVolume(OBSAPIMessageHandler* handler, json_t* message)
{
    json_t* channel = json_object_get(message, "channel");
    json_t* volume = json_object_get(message, "volume");
    json_t* finalValue = json_object_get(message, "final");

    if(volume == NULL)
    {
        return GetErrorResponse("Volume not specified.");
    }

    if(!json_is_number(volume))
    {
        return GetErrorResponse("Volume not number.");
    }
    
    float val = (float) json_number_value(volume);
    val = min(1.0f, max(0.0f, val));

    if(finalValue == NULL)
    {
        return GetErrorResponse("Final not specified.");
    }
    
    if(!json_is_boolean(finalValue))
    {
        return GetErrorResponse("Final is not a boolean.");
    }

    if(channel != NULL && json_typeof(channel) == JSON_STRING)
    {
        const char* channelVal = json_string_value(channel);
        if(stricmp(channelVal, "desktop") == 0)
        {
            OBSSetDesktopVolume(val, json_is_true(finalValue));
        }
        else if(stricmp(channelVal, "microphone") == 0)
        {
            OBSSetMicVolume(val, json_is_true(finalValue));
        }
        else
        {
            return GetErrorResponse("Invalid channel specified.");
        }
    }
    else
    {
        return GetErrorResponse("Channel not specified.");
    }
    return GetOkResponse();
}
Example #11
0
bool ParseResponse(const string & serverResponse, vector<m2::PointD> & outPoints)
{
  try
  {
    my::Json parser(serverResponse.c_str());

    json_t const * countries = json_object_get(parser.get(), "used_mwms");
    size_t pointsCount = json_array_size(countries);
    outPoints.reserve(pointsCount);
    for (size_t i = 0; i < pointsCount; ++i)
    {
      json_t * pointArray = json_array_get(countries, i);
      outPoints.push_back({json_number_value(json_array_get(pointArray, 0)),
                           json_number_value(json_array_get(pointArray, 1))});
    }
    return !outPoints.empty();
  }
  catch (my::Json::Exception&)
  {
    return false;
  }
  return false;
}
Example #12
0
void on_request_gate_cb(pc_request_t *req, int status, json_t *resp) {
    if (status == -1) {
        printf("Fail to send request to server.\n");
    } else if (status == 0) {
        connectorHost = json_string_value(json_object_get(resp, "host"));
        connectorPort = json_number_value(json_object_get(resp, "port"));
        pc_client_t *client = pc_client_new();

        struct sockaddr_in address;

        memset(&address, 0, sizeof(struct sockaddr_in));
        address.sin_family = AF_INET;
        address.sin_port = htons(connectorPort);
        address.sin_addr.s_addr = inet_addr(connectorHost);

        // add pomelo events listener
        pc_add_listener(client, "disconnect", on_disconnect);
        pc_add_listener(client, "onChat", on_chat);
        pc_add_listener(client, "onAdd", on_add);
        pc_add_listener(client, "onLeave", on_leave);

        printf("try to connect to connector server %s %d\n", connectorHost, connectorPort);
        // try to connect to server.
        if (pc_client_connect(client, &address)) {
            printf("fail to connect connector server.\n");
            pc_client_destroy(client);
            return ;
        }

        const char *route = "connector.entryHandler.enter";
        json_t *msg = json_object();
        json_t *str = json_string(user);
        json_t *channel_str = json_string(channel);
        json_object_set_new(msg, "username", str);
        json_object_set_new(msg, "rid", channel_str);

        pc_request_t *request = pc_request_new();
        printf("%s %s\n", user, channel);
        pc_request(client, request, route, msg, on_request_connector_cb);
    }

    // release relative resource with pc_request_t
    json_t *pc_msg = req->msg;
    pc_client_t *pc_client = req->client;
    json_decref(pc_msg);
    pc_request_destroy(req);

    pc_client_stop(pc_client);
}
Example #13
0
void BinWriter::writeType(json_t *jtype)
{
    TypeIndex *tindex = new TypeIndex;

    typeIndexes.push_back(tindex);

    tindex->position = bytes.getPosition();

    utString package = json_string_value(json_object_get(jtype, "package"));
    utString name    = json_string_value(json_object_get(jtype, "name"));

    utString fullname = package;
    fullname += ".";
    fullname += name;

    tindex->iFullName = poolString(fullname.c_str());

    int itype        = poolJString(json_object_get(jtype, "type"));
    int ipackagename = poolString(package.c_str());
    int iname        = poolString(name.c_str());

    json_t *jtypeid = json_object_get(jtype, "typeid");
    assert(jtypeid && json_is_number(jtypeid));

    int itypeid = (int)json_number_value(jtypeid);

    int isource     = -1;
    int ilinenumber = -1;

    json_t *jsource = json_object_get(jtype, "source");

    if (jsource && json_is_string(jsource))
    {
        isource     = poolString(json_string_value(jsource));
        ilinenumber = (int)json_integer_value(json_object_get(jtype, "line"));
    }

    bytes.writeInt(itype);
    bytes.writeInt(ipackagename);
    bytes.writeInt(iname);
    bytes.writeInt(itypeid);
    bytes.writeInt(isource);
    bytes.writeInt(ilinenumber);

    writeClass(jtype);

    tindex->length = bytes.getPosition() - tindex->position;
}
Example #14
0
double JSON::getArrayNumber(int index)
{
    if (!isArray())
    {
        return 0.f;
    }

    json_t *jobject = json_array_get(_json, index);

    if (!jobject || !json_is_number(jobject))
    {
        return 0.f;
    }

    return (double)json_number_value(jobject);
}
Example #15
0
double JSON::getNumber(const char *key)
{
    if (!_json)
    {
        return 0;
    }

    json_t *jreal = json_object_get(_json, key);

    if (!jreal)
    {
        return 0;
    }

    return (double)json_number_value(jreal);
}
Example #16
0
//native Float:json_number_value(Handle:hNumber);
static cell_t Native_json_number_value(IPluginContext *pContext, const cell_t *params) {
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

	// Param 1
	json_t *object;
	Handle_t hndlObject = static_cast<Handle_t>(params[1]);
	if ((err=g_pHandleSys->ReadHandle(hndlObject, htJanssonObject, &sec, (void **)&object)) != HandleError_None)
    {
        return pContext->ThrowNativeError("Invalid <Real> handle %x (error %d)", hndlObject, err);
    }

	return sp_ftoc(json_number_value(object));
}
Example #17
0
bool watchman_perf_sample::finish() {
  gettimeofday(&time_end, nullptr);
  w_timeval_sub(time_end, time_begin, &duration);
#ifdef HAVE_SYS_RESOURCE_H
  getrusage(RUSAGE_SELF, &usage_end);

  // Compute the delta for the usage
  w_timeval_sub(usage_end.ru_utime, usage_begin.ru_utime, &usage.ru_utime);
  w_timeval_sub(usage_end.ru_stime, usage_begin.ru_stime, &usage.ru_stime);

#define DIFFU(n) usage.n = usage_end.n - usage_begin.n
  DIFFU(ru_maxrss);
  DIFFU(ru_ixrss);
  DIFFU(ru_idrss);
  DIFFU(ru_minflt);
  DIFFU(ru_majflt);
  DIFFU(ru_nswap);
  DIFFU(ru_inblock);
  DIFFU(ru_oublock);
  DIFFU(ru_msgsnd);
  DIFFU(ru_msgrcv);
  DIFFU(ru_nsignals);
  DIFFU(ru_nvcsw);
  DIFFU(ru_nivcsw);
#undef DIFFU
#endif

  if (!will_log) {
    if (wall_time_elapsed_thresh == 0) {
      auto thresh = cfg_get_json("perf_sampling_thresh");
      if (thresh) {
        if (json_is_number(thresh)) {
          wall_time_elapsed_thresh = json_number_value(thresh);
        } else {
          json_unpack(thresh, "{s:f}", description, &wall_time_elapsed_thresh);
        }
      }
    }

    if (wall_time_elapsed_thresh > 0 &&
        w_timeval_diff(time_begin, time_end) > wall_time_elapsed_thresh) {
      will_log = true;
    }
  }

  return will_log;
}
Example #18
0
static bool stratum_set_difficulty(struct stratum_ctx *sctx, json_t *params)
{
	double diff;

	diff = json_number_value(json_array_get(params, 0));
	if (diff == 0)
		return false;

	pthread_mutex_lock(&sctx->work_lock);
	sctx->next_diff = diff;
	pthread_mutex_unlock(&sctx->work_lock);

	if (opt_debug)
		applog(LOG_DEBUG, "Stratum difficulty set to %g", diff);

	return true;
}
Example #19
0
map_table_t *json_to_map(bombyx_env_t *env, json_t *json)
{
    size_t index;
    json_t *value;
    const char *key;
    map_table_t *map;

    // TODO: minimum map size (100?)

    if (json_is_object(json))
    {
        map = map_table_create(json_object_size(json));
        json_object_foreach(json, key, value)
        {
            var v = {0};
            if (json_is_object(value))
            {
                // process recursively
                v.type = VAR_MAP;
                v.data = json_to_map(env, value);
                v.data_size = sizeof(map_table_t);
            }
            else if (json_is_array(value))
            {
                v.type = VAR_ARRAY;
                v.data = json_to_array(env, value);
                v.data_size = sizeof(array_t);
            }
            else if (json_is_string(value))
            {
                v.type = VAR_STRING;
                v.data = strdup(json_string_value(value));
                v.data_size = json_string_length(value) + 1;
            }
            else if (json_is_number(value))
            {
                v.type = VAR_DOUBLE;
                v.data = challoc(env->pool_of_doubles);
                v.data_size = sizeof(double);
                *(double *)v.data = json_number_value(value);
            }
            map_add(env, map, (char *)key, v);
        }
    }
Example #20
0
int osd_object_get_id(json_object_t obj)
{
        int id = -1;
        json_object_t v = json_object_get(obj, "id");
        if (json_isnull(v)) {
                log_err("OpenSensorData: Object has no ID"); 
                return -1;
        }
        if (json_isstring(v)) {
                id = atoi(json_string_value(v));
        } else if (json_isnumber(v)) {
                id = json_number_value(v);
        } else {
                log_err("OpenSensorData: ID value is not a string nor a number!"); 
                return -1;
        }
        
        return id;
}
Example #21
0
File: build.c Project: IlariaD/ssm
ssm_var_t *ssm_var_new(json_t *jparameters, ssm_nav_t *nav)
{
    gsl_matrix *m = gsl_matrix_calloc(nav->theta_all->length, nav->theta_all->length);


    int i,j, index;
    ssm_it_parameters_t *it = nav->theta_all;
    json_t *jresource = json_object_get(jparameters, "resources");

    for(index=0; index< json_array_size(jresource); index++){
        json_t *el = json_array_get(jresource, index);

        const char* name = json_string_value(json_object_get(el, "name"));
        if (strcmp(name, "covariance") == 0) {

            json_t *values = json_object_get(el, "data");

            for(i=0; i<it->length; i++){
                for(j=0; j<it->length; j++){
                    json_t *jcov_i = json_object_get(values, it->p[i]->name);
                    if(jcov_i){
                        json_t *jcov_ij = json_object_get(jcov_i, it->p[j]->name);
                        if(jcov_ij){
                            if(json_is_number(jcov_ij)) {
                                gsl_matrix_set(m, i, j, json_number_value(jcov_ij));
                            } else {
                                char str[SSM_STR_BUFFSIZE];
                                snprintf(str, SSM_STR_BUFFSIZE, "error: parameters.covariance.%s.%s is not a number\n", it->p[i]->name, it->p[j]->name);
                                ssm_print_err(str);
                                exit(EXIT_FAILURE);
                            }
                        }
                    }
                }
            }

            break;
        }
    }

    return m;
}
Example #22
0
// gets a json value from a key
int json_object_get_double(json_t *object, char *key, double **value)
{
  double *value_return = NULL;

  int exit_code = 0;

  check_not_null(object);
  check_not_null(key);
  check_not_null(value);

  json_t *json_number_peek = json_object_get(object, key);
  if (json_number_peek == NULL)
  {
    *value = NULL;
    goto cleanup;
  }

  int json_typeof_result = json_typeof(json_number_peek);
  if (json_typeof_result != JSON_INTEGER && json_typeof_result != JSON_REAL)
  {
    *value = NULL;
    goto cleanup;
  }

  double value_peek = json_number_value(json_number_peek);
  check_result(malloc_memcpy_double(&value_return, &value_peek), 0);

  *value = value_return;

  goto cleanup;

error:

  if (value_return != NULL) { free(value_return); }

  exit_code = -1;

cleanup:

  return exit_code;
}
void Stimulus3DShaderDemo::receive_json_message(const std::string& topic_name,
                                                const std::string& json_message) {
    json_t *root;
    json_error_t error;

    root = json_loads(json_message.c_str(), 0, &error);
    if(!root) {
        throw std::runtime_error("error in json");
    }

    json_t *data_json = json_object_get(root, "data");
    if (data_json==NULL) {
        throw std::runtime_error("key not in JSON");
    }
    if(!json_is_number(data_json)){
        throw std::runtime_error("error in json");
    }
    _example_param = json_number_value( data_json );
    example_param_uniform->set(_example_param);

}
Example #24
0
/*
 * parse (optional) timestamp from payload
 */
static apr_byte_t oidc_jose_get_timestamp(apr_pool_t *pool, json_t *json,
		const char *claim_name, apr_byte_t is_mandatory, double *result,
		oidc_jose_error_t *err) {
	*result = OIDC_JWT_CLAIM_TIME_EMPTY;
	json_t *v = json_object_get(json, claim_name);
	if (v != NULL) {
		if (json_is_number(v)) {
			*result = json_number_value(v);
		} else if (is_mandatory) {
			oidc_jose_error(err,
					"mandatory JSON key \"%s\" was found but the type is not a number",
					claim_name);
			return FALSE;
		}
	} else if (is_mandatory) {
		oidc_jose_error(err, "mandatory JSON key \"%s\" could not be found",
				claim_name);
		return FALSE;
	}
	return TRUE;
}
Example #25
0
char *
build_hello_rsp (char *sub, json_t *hellorsp)
{

    uint8_t *nonce = malloc (32);

    gcry_create_nonce (nonce, 32);

    char *bnonce;
    int nl = base64url_encode_alloc (nonce, 32, &bnonce);

    time_t current_time;
    current_time = time(NULL);

    json_t *obj = json_object();

    double msg_id = json_number_value( json_object_get (hellorsp, "msg_id"));

    const char *snonce = json_string_value( json_object_get (hellorsp, "jti"));

    json_object_set_new(obj, "jti", json_string(bnonce));
    json_object_set_new(obj, "sub", json_string(sub));
    json_object_set_new(obj, "snonce", json_string(snonce));
    json_object_set_new(obj, "Version", json_integer(1));
    json_object_set_new(obj, "msg_id", json_integer(msg_id + 1));

    json_object_set_new(obj, "iat", json_integer (current_time));
    json_object_set_new(obj, "exp", json_integer (current_time + 60 * 5));


    char * jwt = jwt_encode_old (obj, ES256, hard_sign);

    assert (NULL != jwt);

    return jwt;
}
Example #26
0
/* Call the simple functions not covered by other tests of the public API */
int main()
{
    json_t *value;

    value = json_integer(1);
    if(json_typeof(value) != JSON_INTEGER)
        fail("json_typeof failed");

    if(json_is_object(value))
        fail("json_is_object failed");

    if(json_is_array(value))
        fail("json_is_array failed");

    if(json_is_string(value))
        fail("json_is_string failed");

    if(!json_is_integer(value))
        fail("json_is_integer failed");

    if(json_is_real(value))
        fail("json_is_real failed");

    if(!json_is_number(value))
        fail("json_is_number failed");

    if(json_is_true(value))
        fail("json_is_true failed");

    if(json_is_false(value))
        fail("json_is_false failed");

    if(json_is_boolean(value))
        fail("json_is_boolean failed");

    if(json_is_null(value))
        fail("json_is_null failed");

    json_decref(value);


    value = json_string("foo");
    if(!value)
        fail("json_string failed");
    if(strcmp(json_string_value(value), "foo"))
        fail("invalid string value");

    if(json_string_set(value, "bar"))
        fail("json_string_set failed");
    if(strcmp(json_string_value(value), "bar"))
        fail("invalid string value");

    json_decref(value);

    value = json_string(NULL);
    if(value)
        fail("json_string(NULL) failed");

    /* invalid UTF-8  */
    value = json_string("a\xefz");
    if(value)
        fail("json_string(<invalid utf-8>) failed");

    value = json_string_nocheck("foo");
    if(!value)
        fail("json_string_nocheck failed");
    if(strcmp(json_string_value(value), "foo"))
        fail("invalid string value");

    if(json_string_set_nocheck(value, "bar"))
        fail("json_string_set_nocheck failed");
    if(strcmp(json_string_value(value), "bar"))
        fail("invalid string value");

    json_decref(value);

    /* invalid UTF-8 */
    value = json_string_nocheck("qu\xff");
    if(!value)
        fail("json_string_nocheck failed");
    if(strcmp(json_string_value(value), "qu\xff"))
        fail("invalid string value");

    if(json_string_set_nocheck(value, "\xfd\xfe\xff"))
        fail("json_string_set_nocheck failed");
    if(strcmp(json_string_value(value), "\xfd\xfe\xff"))
        fail("invalid string value");

    json_decref(value);


    value = json_integer(123);
    if(!value)
        fail("json_integer failed");
    if(json_integer_value(value) != 123)
        fail("invalid integer value");
    if(json_number_value(value) != 123.0)
        fail("invalid number value");

    if(json_integer_set(value, 321))
        fail("json_integer_set failed");
    if(json_integer_value(value) != 321)
        fail("invalid integer value");
    if(json_number_value(value) != 321.0)
        fail("invalid number value");

    json_decref(value);

    value = json_real(123.123);
    if(!value)
        fail("json_real failed");
    if(json_real_value(value) != 123.123)
        fail("invalid integer value");
    if(json_number_value(value) != 123.123)
        fail("invalid number value");

    if(json_real_set(value, 321.321))
        fail("json_real_set failed");
    if(json_real_value(value) != 321.321)
        fail("invalid real value");
    if(json_number_value(value) != 321.321)
        fail("invalid number value");

    json_decref(value);

    value = json_true();
    if(!value)
        fail("json_true failed");
    json_decref(value);

    value = json_false();
    if(!value)
        fail("json_false failed");
    json_decref(value);

    value = json_null();
    if(!value)
        fail("json_null failed");
    json_decref(value);

    /* Test reference counting on singletons (true, false, null) */
    value = json_true();
    if(value->refcount != (size_t)-1)
      fail("refcounting true works incorrectly");
    json_decref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting true works incorrectly");
    json_incref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting true works incorrectly");

    value = json_false();
    if(value->refcount != (size_t)-1)
      fail("refcounting false works incorrectly");
    json_decref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting false works incorrectly");
    json_incref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting false works incorrectly");

    value = json_null();
    if(value->refcount != (size_t)-1)
      fail("refcounting null works incorrectly");
    json_decref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting null works incorrectly");
    json_incref(value);
    if(value->refcount != (size_t)-1)
      fail("refcounting null works incorrectly");

    return 0;
}
Example #27
0
int delete_route(char *address, int netmask)
{
    struct rtnl_handle rth = { .fd = -1 };

    if (rtnl_open(&rth, 0) < 0) {
        exit(1);
    }

    struct iplink_req req;

    memset(&req, 0, sizeof(req));
    req.n.nlmsg_len    = NLMSG_LENGTH(sizeof(struct rtmsg));
    req.n.nlmsg_flags  = NLM_F_REQUEST | NLM_F_ACK;
    req.n.nlmsg_type   = RTM_DELROUTE;
    req.rtm.rtm_family = AF_UNSPEC;
    req.rtm.rtm_table  = RT_TABLE_MAIN;
    req.rtm.rtm_scope  = RT_SCOPE_NOWHERE;

    inet_prefix dst;

    get_prefix(&dst, address, req.rtm.rtm_family);
    req.rtm.rtm_family = dst.family;

    if (req.rtm.rtm_family == AF_UNSPEC) {
        req.rtm.rtm_family = AF_INET;
    }

    req.rtm.rtm_dst_len = netmask;
    if (dst.bytelen) {
        addattr_l(&req.n, sizeof(req), RTA_DST, &dst.data, dst.bytelen);
    }

    ll_init_map(&rth);

    struct nlmsghdr *answer;
    int              errnum = rtnl_talkE(&rth, &req.n, 0, 0, &answer, NULL, NULL);
    if (errnum < 0) {
        exit(2);
    }

    if (answer) {
        switch (errnum) {
            case 0: // Success
                fprintf(stderr, "delete route to %s\n", address);
                break;

            case 3: // No such device
                // fprintf(stderr, "already deleted.\n");
                break;

            default:
                fprintf(stderr, "ERROR!\terrno: %d\n", errnum);
                perror("Netlink");
                exit(2);
                break;
        }
    } else {
        fprintf(stderr, "Something Wrong!\n");
        exit(2);
    }

    return 0;
}

int delete_all_route()
{
    struct rtnl_handle rth = { .fd = -1 };

    if (rtnl_open(&rth, 0) < 0) {
        exit(1);
    }

    int preferred_family = AF_PACKET;

    if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETROUTE) < 0) {
        perror("Cannot send dump request");
        exit(1);
    }

    struct nlmsg_list *rinfo = NULL;

    if (rtnl_dump_filter(&rth, store_nlmsg, &rinfo, NULL, NULL) < 0) {
        fprintf(stderr, "Dump terminated\n");
        exit(1);
    }

    struct nlmsg_list *r, *n;

    for (r = rinfo; r; r = n) {
        n = r->next;
        struct nlmsghdr *nlhdr = &(r->h);

        if (nlhdr->nlmsg_type != RTM_NEWROUTE && nlhdr->nlmsg_type != RTM_DELROUTE) {
            fprintf(stderr, "Not a route: %08x %08x %08x\n", nlhdr->nlmsg_len, nlhdr->nlmsg_type, nlhdr->nlmsg_flags);

            return 0;
        }

        struct rtmsg *rtm = NLMSG_DATA(nlhdr);
        int           len = nlhdr->nlmsg_len - NLMSG_LENGTH(sizeof(*rtm));

        if (len < 0) {
            fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);

            return -1;
        }

        // Analyze rtattr Message
        struct rtattr *tb[RTA_MAX + 1];
        parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len);

        char dst_address[64] = "";
        char abuf[256];
        int  host_len = calc_host_len(rtm);

        if (tb[RTA_DST]) {
            if (rtm->rtm_dst_len != host_len) {
                sprintf(dst_address, "%s/%d", rt_addr_n2a(rtm->rtm_family, RTA_PAYLOAD(tb[RTA_DST]), RTA_DATA(tb[RTA_DST]), abuf, sizeof(abuf)), rtm->rtm_dst_len);
            } else {
                sprintf(dst_address, "%s", format_host(rtm->rtm_family, RTA_PAYLOAD(tb[RTA_DST]), RTA_DATA(tb[RTA_DST]), abuf, sizeof(abuf)));
            }
        } else if (rtm->rtm_dst_len) {
            sprintf(dst_address, "0/%d", rtm->rtm_dst_len);
        } else {
            sprintf(dst_address, "default");
        }

        if (strncmp(dst_address, "127.0.0.0", 9) != 0 && strcmp(dst_address, "ff00::") != 0) {
            delete_route((char *) dst_address, rtm->rtm_dst_len);
        }
    }

    printf("delete all routes.\n\n");
    free(r);
    rtnl_close(&rth);

    return 0;
}

// network is unreachableを回避するため、全経路を登録し終えるまでwhileループを回す
void modify_route(json_t *ipRouteEntry_json, int default_flag)
{
    int end = 0;
    while (end == 0) {
				end = 1;
        int i;
        for (i = 0; i < (int) json_array_size(ipRouteEntry_json); i++) {
            json_t *route_json = json_array_get(ipRouteEntry_json, i);
            json_t *linux_json = json_object_get(route_json, "linux");

            struct rtnl_handle rth = { .fd = -1 };

            if (rtnl_open(&rth, 0) < 0) {
                exit(1);
            }

            struct iplink_req req;

            memset(&req, 0, sizeof(req));
            req.n.nlmsg_len   = NLMSG_LENGTH(sizeof(struct rtmsg));
            req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
            req.n.nlmsg_type  = RTM_NEWROUTE;

            req.rtm.rtm_family = AF_UNSPEC;
            req.rtm.rtm_type   = (int) json_number_value(json_object_get(route_json, "ipRouteType"));
            if (req.rtm.rtm_type >= 5) { // 5以降は定義されていない
                req.rtm.rtm_type = 1;
            }
            req.rtm.rtm_protocol = (int) json_number_value(json_object_get(route_json, "ipRouteProto"));
            req.rtm.rtm_scope    = (int) json_number_value(json_object_get(linux_json, "rtm_scope"));
            req.rtm.rtm_table    = (int) json_number_value(json_object_get(linux_json, "rtm_table"));
            req.rtm.rtm_dst_len  = (int) json_number_value(json_object_get(route_json, "ipRouteMask"));

            char       *route_name = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff";
            const char *key;
            json_t     *value;
            json_object_foreach(route_json, key, value) {
                if (strcmp(key, "ipRouteDest") == 0) {
                    inet_prefix dst;
                    route_name = (char *) json_string_value(value);
                    get_prefix(&dst, route_name, req.rtm.rtm_family);
                    if (req.rtm.rtm_family == AF_UNSPEC) {
                        req.rtm.rtm_family = dst.family;
                    }
                    if (dst.bytelen) {
                        addattr_l(&req.n, sizeof(req), RTA_DST, &dst.data, dst.bytelen);
                    }
                }

                if (strcmp(key, "ipRouteIfIndex") == 0) {
                    addattr32(&req.n, sizeof(req), RTA_OIF, json_integer_value(value));
                }

                if (strcmp(key, "ipRouteNextHop") == 0) {
                    inet_prefix addr;
                    get_addr(&addr, (char *) json_string_value(value), req.rtm.rtm_family);
                    if (req.rtm.rtm_family == AF_UNSPEC) {
                        req.rtm.rtm_family = addr.family;
                    }
                    addattr_l(&req.n, sizeof(req), RTA_GATEWAY, &addr.data, addr.bytelen);
                }

                if (strcmp(key, "ipRouteMetric1") == 0) {
                    addattr32(&req.n, sizeof(req), RTA_PRIORITY, json_integer_value(value));
                }

                if (strcmp(key, "ipRouteInfo") == 0) {
                    inet_prefix addr;
                    get_addr(&addr, (char *) json_string_value(value), req.rtm.rtm_family);
                    if (req.rtm.rtm_family == AF_UNSPEC) {
                        req.rtm.rtm_family = addr.family;
                    }
                    addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &addr.data, addr.bytelen);
                }
            }

            ll_init_map(&rth);

            if (req.rtm.rtm_family == AF_UNSPEC) {
                req.rtm.rtm_family = AF_INET;
            }

            struct nlmsghdr *answer;
            int              errnum = rtnl_talkE(&rth, &req.n, 0, 0, &answer, NULL, NULL);
            if (errnum < 0) {
                exit(2);
            }

            if (answer) {
                switch (errnum) {
                    case 0: // Success
                        fprintf(stderr, "arrange route to %s/%d\n", route_name, req.rtm.rtm_dst_len);
                        break;

                    case 17: // File exists
                        // fprintf(stderr, "route already exists.\n");
                        break;

                    case 19: // No such device
                        // fprintf(stderr, "No such device");
                        break;

										case 101: // Network is unreachable
												end = 0;
												break;

                    default:
                        fprintf(stderr, "ERROR!\terrno: %d\n", errnum);
                        perror("Netlink");
                        exit(2);
                        break;
                }
            } else {
                fprintf(stderr, "Something Wrong!\n");
                exit(2);
            }
        }
    }
}

int read_route_file(json_t *routes_json)
{
    // routeの削除
    delete_all_route();

    json_t *ipRouteEntry_json = json_object_get(routes_json, "ipRouteEntry");

    // defaultへの経路はGatewayへの経路が登録されてからでないとnetwork is unreachableになるので
    // defaultへの経路とそうでないものを分ける
    modify_route(ipRouteEntry_json, 0);
    modify_route(ipRouteEntry_json, 1);
    fprintf(stderr, "Success arranging all routes!\n\n");

    return 0;
}
Example #28
0
int schema_traverse(const avro_schema_t schema, json_t *json, json_t *dft,
                    avro_value_t *current_val, int quiet, int strjson, size_t max_str_sz) {

    json = json ? json : dft;
    if (!json) {
        fprintf(stderr, "ERROR: Avro schema does not match JSON\n");
        return 1;
    }

    switch (schema->type) {
    case AVRO_RECORD:
    {
        if (!json_is_object(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON object for Avro record, got something else\n");
            return 1;
        }

        int len = avro_schema_record_size(schema), i;
        for (i=0; i<len; i++) {

            const char *name = avro_schema_record_field_name(schema, i);
            avro_schema_t field_schema = avro_schema_record_field_get_by_index(schema, i);

            json_t *json_val = json_object_get(json, name);
            json_t *dft = avro_schema_record_field_default_get_by_index(schema, i);

            avro_value_t field;
            avro_value_get_by_index(current_val, i, &field, NULL);

            if (schema_traverse(field_schema, json_val, dft, &field, quiet, strjson, max_str_sz))
                return 1;
        }
    } break;

    case AVRO_LINK:
        /* TODO */
        fprintf(stderr, "ERROR: AVRO_LINK is not implemented\n");
        return 1;
        break;

    case AVRO_STRING:
        if (!json_is_string(json)) {
            if (json && strjson) {
                /* -j specified, just dump the remaining json as string */
                char * js = json_dumps(json, JSON_COMPACT|JSON_SORT_KEYS|JSON_ENCODE_ANY);
                if (max_str_sz && (strlen(js) > max_str_sz))
                    js[max_str_sz] = 0; /* truncate the string - this will result in invalid JSON! */
                avro_value_set_string(current_val, js);
                free(js);
                break;
            }
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON string for Avro string, got something else\n");
            return 1;
        } else {
            const char *js = json_string_value(json);
            if (max_str_sz && (strlen(js) > max_str_sz)) {
                /* truncate the string */
                char *jst = malloc(strlen(js));
                strcpy(jst, js);
                jst[max_str_sz] = 0;
                avro_value_set_string(current_val, jst);
                free(jst);
            } else
                avro_value_set_string(current_val, js);
        }
        break;

    case AVRO_BYTES:
        if (!json_is_string(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON string for Avro string, got something else\n");
            return 1;
        }
        /* NB: Jansson uses null-terminated strings, so embedded nulls are NOT
           supported, not even escaped ones */
        const char *s = json_string_value(json);
        avro_value_set_bytes(current_val, (void *)s, strlen(s));
        break;

    case AVRO_INT32:
        if (!json_is_integer(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON integer for Avro int, got something else\n");
            return 1;
        }
        avro_value_set_int(current_val, json_integer_value(json));
        break;

    case AVRO_INT64:
        if (!json_is_integer(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON integer for Avro long, got something else\n");
            return 1;
        }
        avro_value_set_long(current_val, json_integer_value(json));
        break;

    case AVRO_FLOAT:
        if (!json_is_number(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON number for Avro float, got something else\n");
            return 1;
        }
        avro_value_set_float(current_val, json_number_value(json));
        break;

    case AVRO_DOUBLE:
        if (!json_is_number(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON number for Avro double, got something else\n");
            return 1;
        }
        avro_value_set_double(current_val, json_number_value(json));
        break;

    case AVRO_BOOLEAN:
        if (!json_is_boolean(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON boolean for Avro boolean, got something else\n");
            return 1;
        }
        avro_value_set_boolean(current_val, json_is_true(json));
        break;

    case AVRO_NULL:
        if (!json_is_null(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON null for Avro null, got something else\n");
            return 1;
        }
        avro_value_set_null(current_val);
        break;

    case AVRO_ENUM:
        // TODO ???
        break;

    case AVRO_ARRAY:
        if (!json_is_array(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON array for Avro array, got something else\n");
            return 1;
        } else {
            int i, len = json_array_size(json);
            avro_schema_t items = avro_schema_array_items(schema);
            avro_value_t val;
            for (i=0; i<len; i++) {
                avro_value_append(current_val, &val, NULL);
                if (schema_traverse(items, json_array_get(json, i), NULL, &val, quiet, strjson, max_str_sz))
                    return 1;
            }
        }
        break;

    case AVRO_MAP:
        if (!json_is_object(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON object for Avro map, got something else\n");
            return 1;
        } else {
            avro_schema_t values = avro_schema_map_values(schema);
            void *iter = json_object_iter(json);
            avro_value_t val;
            while (iter) {
                avro_value_add(current_val, json_object_iter_key(iter), &val, 0, 0);
                if (schema_traverse(values, json_object_iter_value(iter), NULL, &val, quiet, strjson, max_str_sz))
                    return 1;
                iter = json_object_iter_next(json, iter);
            }
        }
        break;

    case AVRO_UNION:
    {
        int i;
        avro_value_t branch;
        for (i=0; i<avro_schema_union_size(schema); i++) {
            avro_value_set_branch(current_val, i, &branch);
            avro_schema_t type = avro_schema_union_branch(schema, i);
            if (!schema_traverse(type, json, NULL, &branch, 1, strjson, max_str_sz))
                break;
        }
        if (i==avro_schema_union_size(schema)) {
            fprintf(stderr, "ERROR: No type in the Avro union matched the JSON type we got\n");
            return 1;
        }
        break;
    }
    case AVRO_FIXED:
        if (!json_is_string(json)) {
            if (!quiet)
                fprintf(stderr, "ERROR: Expecting JSON string for Avro fixed, got something else\n");
            return 1;
        }
        /* NB: Jansson uses null-terminated strings, so embedded nulls are NOT
           supported, not even escaped ones */
        const char *f = json_string_value(json);
        if (avro_value_set_fixed(current_val, (void *)f, strlen(f))) {
            fprintf(stderr, "ERROR: Setting Avro fixed value FAILED\n");
            return 1;
        }
        break;

    default:
        fprintf(stderr, "ERROR: Unknown type: %d\n", schema->type);
        return 1;
    }
    return 0;
}
Example #29
0
static int gen_jansson_value(yajl_gen gen, json_t *value) {
	json_error_t jerr;
	const char *str;
	size_t len;
	int rc;

	int type = json_typeof(value);
	switch(type) {
	case JSON_OBJECT:
		yajl_gen_map_open(gen);
		gen_jansson_object(gen,value);
		yajl_gen_map_close(gen);
		break;

	case JSON_ARRAY:
		yajl_gen_array_open(gen);
		gen_jansson_array(gen,value);
		yajl_gen_array_close(gen);
		break;

	case JSON_STRING:
		rc = json_unpack_ex(value, &jerr, 0, "s%", &str,&len);
		if(rc != 0) {
			rdlog(LOG_ERR,"Couldn't extract string: %s",jerr.text);
			return 0;
		}
		yajl_gen_string(gen, (const unsigned char *)str, len);
		break;

	case JSON_INTEGER:
		{
			json_int_t i = json_integer_value(value);
			yajl_gen_integer(gen,i);
		}
		break;

	case JSON_REAL:
		{
			double d = json_number_value(value);
			yajl_gen_double(gen,d);
		}
		break;

	case JSON_TRUE:
		yajl_gen_bool(gen,1);
		break;

	case JSON_FALSE:
		yajl_gen_bool(gen,0);
		break;

	case JSON_NULL:
		yajl_gen_null(gen);
		break;

	default:
		rdlog(LOG_ERR,"Unkown jansson type %d",type);
		break;
	};

	return 1;
}
Example #30
0
File: build.c Project: IlariaD/ssm
ssm_nav_t *ssm_nav_new(json_t *jparameters, ssm_options_t *opts)
{
    char str[SSM_STR_BUFFSIZE];

    ssm_nav_t *nav = malloc(sizeof (ssm_nav_t));
    if (nav == NULL) {
        ssm_print_err("Allocation impossible for ssm_nav_t *");
        exit(EXIT_FAILURE);
    }

    nav->implementation = opts->implementation;
    nav->noises_off = opts->noises_off;
    nav->print = opts->print;

    nav->parameters = _ssm_parameters_new(&nav->parameters_length);
    nav->states = _ssm_states_new(&nav->states_length, nav->parameters);
    nav->observed = _ssm_observed_new(&nav->observed_length);

    nav->states_sv = ssm_it_states_sv_new(nav->states);
    nav->states_remainders = ssm_it_states_remainders_new(nav->states);
    nav->states_inc = ssm_it_states_inc_new(nav->states);
    nav->states_sv_inc = ssm_it_states_sv_inc_new(nav->states);
    nav->states_diff = ssm_it_states_diff_new(nav->states);

    nav->par_all = ssm_it_parameters_all_new(nav->parameters);
    nav->par_noise = ssm_it_parameters_noise_new(nav->parameters);
    nav->par_disp = ssm_it_parameters_disp_new(nav->parameters);
    nav->par_icsv = ssm_it_parameters_icsv_new(nav->parameters);
    nav->par_icdiff = ssm_it_parameters_icdiff_new(nav->parameters);

    //theta: we over-allocate the iterators
    nav->theta_all = _ssm_it_parameters_new(nav->par_all->length);
    nav->theta_no_icsv_no_icdiff = _ssm_it_parameters_new(nav->par_all->length);
    nav->theta_icsv_icdiff = _ssm_it_parameters_new(nav->par_all->length);

    //json_t jparameters with diagonal covariance term to 0.0 won't be infered: re-compute length and content
    nav->theta_all->length = 0;
    nav->theta_no_icsv_no_icdiff->length = 0;
    nav->theta_icsv_icdiff->length = 0;


    int index, i;
    json_t *jresource = json_object_get(jparameters, "resources");

    for(index=0; index< json_array_size(jresource); index++){
        json_t *el = json_array_get(jresource, index);

        const char *name = json_string_value(json_object_get(el, "name"));
        if (strcmp(name, "covariance") == 0) {

            json_t *values = json_object_get(el, "data");

            //for all the parameters: if covariance term and covariance term >0.0, fill theta_*
            for(i=0; i<nav->par_all->length; i++){
		json_t *jcov_i = json_object_get(values, nav->par_all->p[i]->name);
                if(jcov_i){
                    json_t *jcov_ii = json_object_get(jcov_i, nav->par_all->p[i]->name);
                    if(jcov_ii){
                        if(!json_is_number(jcov_ii)) {
                            snprintf(str, SSM_STR_BUFFSIZE, "error: parameters.covariance.%s.%s is not a number\n", nav->par_all->p[i]->name, nav->par_all->p[i]->name);
                            ssm_print_err(str);
                            exit(EXIT_FAILURE);
                        }

                        if(json_number_value(jcov_ii) > 0.0){

                            if( ssm_in_par(nav->par_noise, nav->par_all->p[i]->name) ) {
                                if(!(nav->noises_off & SSM_NO_WHITE_NOISE)){
                                    nav->theta_all->p[nav->theta_all->length] = nav->par_all->p[i];
                                    nav->theta_all->p[nav->theta_all->length]->offset_theta = nav->theta_all->length;
                                    nav->theta_all->length += 1;
                                }
                            } else if( ssm_in_par(nav->par_disp, nav->par_all->p[i]->name) ) {
                                if(!(nav->noises_off & SSM_NO_DIFF)){
                                    nav->theta_all->p[nav->theta_all->length] = nav->par_all->p[i];
                                    nav->theta_all->p[nav->theta_all->length]->offset_theta = nav->theta_all->length;
                                    nav->theta_all->length += 1;
                                }
                            } else {
                                nav->theta_all->p[nav->theta_all->length] = nav->par_all->p[i];
                                nav->theta_all->p[nav->theta_all->length]->offset_theta = nav->theta_all->length;
                                nav->theta_all->length += 1;
                            }

                            int in_icsv = ssm_in_par(nav->par_icsv, nav->par_all->p[i]->name);
                            int in_icdiff =ssm_in_par(nav->par_icdiff, nav->par_all->p[i]->name);

                            if(!in_icsv && !in_icdiff){
                                nav->theta_no_icsv_no_icdiff->p[nav->theta_no_icsv_no_icdiff->length] = nav->par_all->p[i];
                                nav->theta_no_icsv_no_icdiff->length += 1;
                            } else if (in_icsv || in_icdiff){
                                if(in_icdiff){
                                    if(!(nav->noises_off & SSM_NO_DIFF)){ //diffusion is allowed
                                        nav->theta_icsv_icdiff->p[nav->theta_icsv_icdiff->length] = nav->par_all->p[i];
                                        nav->theta_icsv_icdiff->length += 1;
                                    } else {
                                        nav->theta_no_icsv_no_icdiff->p[nav->theta_no_icsv_no_icdiff->length] = nav->par_all->p[i];
                                        nav->theta_no_icsv_no_icdiff->length += 1;
                                    }
                                } else {
                                    nav->theta_icsv_icdiff->p[nav->theta_icsv_icdiff->length] = nav->par_all->p[i];
                                    nav->theta_icsv_icdiff->length += 1;
                                }
                            }

                        }


                    }
                }
            }

            break;
        }
    }

    //files (CSV open and print headers)
    if(opts->print & SSM_PRINT_TRACE){
#if SSM_JSON
        nav->trace = stdout;
#else
        snprintf(str, SSM_STR_BUFFSIZE, "%s/trace_%d.csv", opts->root,  opts->id);
        nav->trace = fopen(str, "w");
        ssm_print_header_trace(nav->trace, nav);
#endif
    } else {
        nav->trace = NULL;
    }

    if(opts->print & SSM_PRINT_X){
#if SSM_JSON
        nav->X = stdout;
#else
snprintf(str, SSM_STR_BUFFSIZE, "%s/X_%d.csv", opts->root,  opts->id);
 nav->X = fopen(str, "w");
 ssm_print_header_X(nav->X, nav);
#endif
    } else {
        nav->X = NULL;
    }

    if(opts->print & SSM_PRINT_HAT){
#if SSM_JSON
        nav->hat = stdout;
#else
        snprintf(str, SSM_STR_BUFFSIZE, "%s/hat_%d.csv", opts->root,  opts->id);
        nav->hat = fopen(str, "w");
        ssm_print_header_hat(nav->hat, nav);
#endif
    } else {
        nav->hat = NULL;
    }

    if(opts->print & SSM_PRINT_DIAG){
#if SSM_JSON
        nav->diag = stdout;
#else
        snprintf(str, SSM_STR_BUFFSIZE, "%s/diag_%d.csv", opts->root,  opts->id);
        nav->diag = fopen(str, "w");
        if(opts->algo & (SSM_SMC | SSM_KALMAN)){
            ssm_print_header_pred_res(nav->diag, nav);
        } else if (opts->algo & (SSM_PMCMC | SSM_KMCMC)){
            ssm_print_header_ar(nav->diag);
        } else if (opts->algo & SSM_MIF){
            ssm_mif_print_header_mean_var_theoretical_ess(nav->diag, nav);
        }
#endif
    } else {
        nav->diag = NULL;
    }

    return nav;
}