Skip to content

Commit

Permalink
Allow time adjustment over HTTP API for cameras without access to a N…
Browse files Browse the repository at this point in the history
…TP server
  • Loading branch information
wberube committed Jun 3, 2024
1 parent 932ff1d commit 928c4a1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef struct {
} osd;

extern osd osds[MAX_OSD];
extern char timefmt[32];

int start_region_handler();
void stop_region_handler();
39 changes: 39 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,45 @@ void *server_thread(void *vargp) {
close_socket_fd(client_fd);
continue;
}

if (equals(uri, "/api/time"))
{
struct timespec t;
if (!empty(query))
{
char *remain;
while (query) {
char *value = split(&query, "&");
if (!value || !*value) continue;
unescape_uri(value);
char *key = split(&value, "=");
if (!key || !*key || !value || !*value) continue;
if (app_config.osd_enable && equals(key, "fmt"))
strncpy(timefmt, value, 32);
else if (equals(key, "ts")) {
long result = strtol(value, &remain, 10);
if (remain == value) continue;
t.tv_sec = result;
clock_settime(CLOCK_REALTIME, &t);
}
}
if (app_config.osd_enable)
for (char id = 0; id < MAX_OSD; id++)
if (strstr(osds[id].text, "$t"))
osds[id].updt = 1;
}
clock_gettime(CLOCK_REALTIME, &t);
int respLen = sprintf(response,
"HTTP/1.1 200 OK\r\n" \
"Content-Type: application/json;charset=UTF-8\r\n" \
"Connection: close\r\n" \
"\r\n" \
"{\"fmt\":\"%s\",\"ts\":%d}",
timefmt, t.tv_sec);
send_to_fd(client_fd, response, respLen);
close_socket_fd(client_fd);
continue;
}

if (app_config.web_enable_static && send_file(client_fd, uri))
continue;
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>

#include "common.h"
Expand Down

0 comments on commit 928c4a1

Please sign in to comment.