mirror of
https://github.com/owntracks/recorder.git
synced 2024-11-15 09:58:40 -07:00
fix limit in locations api
This commit is contained in:
parent
de60beb5d6
commit
6523294416
6
http.c
6
http.c
@ -443,6 +443,7 @@ static int dispatch(struct mg_connection *conn, const char *uri)
|
||||
if ((json = lister(u, d, s_lo, s_hi, (limit > 0) ? TRUE : FALSE)) != NULL) {
|
||||
JsonNode *arr, *fields = NULL;
|
||||
char *flds = field(conn, "fields");
|
||||
int i_have = 0;
|
||||
|
||||
if (flds != NULL) {
|
||||
fields = json_splitter(flds, ",");
|
||||
@ -455,6 +456,11 @@ static int dispatch(struct mg_connection *conn, const char *uri)
|
||||
JsonNode *f;
|
||||
json_foreach(f, arr) {
|
||||
locations(f->string_, obj, locs, s_lo, s_hi, otype, limit, fields, NULL, NULL);
|
||||
if (limit) {
|
||||
i_have += limit;
|
||||
if (i_have >= limit)
|
||||
break;
|
||||
}
|
||||
// printf("%s\n", f->string_);
|
||||
}
|
||||
}
|
||||
|
7
ocat.c
7
ocat.c
@ -462,10 +462,17 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
|
||||
if ((json = lister(username, device, s_lo, s_hi, (limit > 0) ? TRUE : FALSE)) != NULL) {
|
||||
int i_have = 0;
|
||||
|
||||
if ((arr = json_find_member(json, "results")) != NULL) { // get array
|
||||
json_foreach(f, arr) {
|
||||
// locations(f->string_, obj, locs, s_lo, s_hi, otype, limit, fields, username, device);
|
||||
locations(f->string_, obj, locs, s_lo, s_hi, otype, limit, fields, NULL, NULL);
|
||||
if (limit) {
|
||||
i_have += limit;
|
||||
if (i_have >= limit)
|
||||
break;
|
||||
}
|
||||
// printf("%s\n", f->string_);
|
||||
}
|
||||
}
|
||||
|
19
storage.c
19
storage.c
@ -722,10 +722,25 @@ static int candidate_line(char *line, void *param)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (limit > 0 && otype == RAW) {
|
||||
} else if (limit > 0 && otype == RAW) {
|
||||
printf("%s\n", line);
|
||||
return (1); /* make it 'count' or tac() will not decrement line counter and continue until EOF */
|
||||
} else if (limit > 0) {
|
||||
/* reading backwards; check time */
|
||||
|
||||
char *p;
|
||||
struct tm tmline;
|
||||
time_t secs;
|
||||
|
||||
if ((p = strptime(line, "%Y-%m-%dT%H:%M:%SZ", &tmline)) == NULL) {
|
||||
fprintf(stderr, "no strptime on %s", line);
|
||||
return (0);
|
||||
}
|
||||
secs = mktime(&tmline);
|
||||
|
||||
if (secs <= s_lo || secs >= s_hi) {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Do we have location line? */
|
||||
|
Loading…
Reference in New Issue
Block a user