osmo-bsc: Add valid field to location command
This commit is contained in:
parent
6d718c054a
commit
fa2218cbc9
|
@ -171,10 +171,11 @@ static void signal_handler(int signal)
|
|||
}
|
||||
|
||||
struct location {
|
||||
unsigned long age;
|
||||
int valid;
|
||||
double lat;
|
||||
double lon;
|
||||
double height;
|
||||
unsigned long age;
|
||||
};
|
||||
|
||||
static struct location myloc;
|
||||
|
@ -182,7 +183,7 @@ static struct location myloc;
|
|||
CTRL_CMD_DEFINE(net_loc, "location");
|
||||
int get_net_loc(struct ctrl_cmd *cmd, void *data)
|
||||
{
|
||||
cmd->reply = talloc_asprintf(cmd, "%lu,%f,%f,%f", myloc.age, myloc.lat, myloc.lon, myloc.height);
|
||||
cmd->reply = talloc_asprintf(cmd, "%lu,%i,%f,%f,%f", myloc.age, myloc.valid, myloc.lat, myloc.lon, myloc.height);
|
||||
if (!cmd->reply) {
|
||||
cmd->reply = "OOM";
|
||||
return CTRL_CMD_ERROR;
|
||||
|
@ -193,7 +194,7 @@ int get_net_loc(struct ctrl_cmd *cmd, void *data)
|
|||
|
||||
int set_net_loc(struct ctrl_cmd *cmd, void *data)
|
||||
{
|
||||
char *saveptr, *lat, *lon, *height, *age, *tmp;
|
||||
char *saveptr, *lat, *lon, *height, *age, *valid, *tmp;
|
||||
|
||||
tmp = talloc_strdup(cmd, cmd->value);
|
||||
if (!tmp)
|
||||
|
@ -201,11 +202,13 @@ int set_net_loc(struct ctrl_cmd *cmd, void *data)
|
|||
|
||||
|
||||
age = strtok_r(tmp, ",", &saveptr);
|
||||
valid = strtok_r(NULL, ",", &saveptr);
|
||||
lat = strtok_r(NULL, ",", &saveptr);
|
||||
lon = strtok_r(NULL, ",", &saveptr);
|
||||
height = strtok_r(NULL, "\0", &saveptr);
|
||||
|
||||
myloc.age = atol(age);
|
||||
myloc.valid = atoi(valid);
|
||||
myloc.lat = atof(lat);
|
||||
myloc.lon = atof(lon);
|
||||
myloc.height = atof(height);
|
||||
|
@ -219,8 +222,9 @@ oom:
|
|||
|
||||
int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data)
|
||||
{
|
||||
char *saveptr, *latstr, *lonstr, *heightstr, *agestr, *tmp;
|
||||
char *saveptr, *latstr, *lonstr, *heightstr, *agestr, *validstr, *tmp;
|
||||
unsigned long age;
|
||||
int valid;
|
||||
double lat, lon, height;
|
||||
|
||||
tmp = talloc_strdup(cmd, value);
|
||||
|
@ -228,21 +232,24 @@ int verify_net_loc(struct ctrl_cmd *cmd, const char *value, void *data)
|
|||
return 1;
|
||||
|
||||
agestr = strtok_r(tmp, ",", &saveptr);
|
||||
validstr = strtok_r(NULL, ",", &saveptr);
|
||||
latstr = strtok_r(NULL, ",", &saveptr);
|
||||
lonstr = strtok_r(NULL, ",", &saveptr);
|
||||
heightstr = strtok_r(NULL, "\0", &saveptr);
|
||||
|
||||
if ((agestr == NULL) || (latstr == NULL) ||
|
||||
if ((agestr == NULL) || (validstr == NULL) || (latstr == NULL) ||
|
||||
(lonstr == NULL) || (heightstr == NULL))
|
||||
return 1;
|
||||
|
||||
age = atol(agestr);
|
||||
valid = atoi(validstr);
|
||||
lat = atof(latstr);
|
||||
lon = atof(lonstr);
|
||||
height = atof(heightstr);
|
||||
talloc_free(tmp);
|
||||
|
||||
if ((age == 0) || (lat < -90) || (lat > 90) || (lon < -180) || (lon > 180))
|
||||
if ((age == 0) || (lat < -90) || (lat > 90) || (lon < -180) ||
|
||||
(lon > 180) || (valid < 0) || (valid > 2))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue