mirror of
https://github.com/simon987/sist2.git
synced 2025-04-18 09:46:43 +00:00
revert debug hard-coded listen address
This commit is contained in:
parent
e436af7b2a
commit
695d9abd83
@ -119,7 +119,7 @@ binaries (GCC 7+ required).
|
|||||||
1. Install compile-time dependencies
|
1. Install compile-time dependencies
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
vcpkg install lmdb cjson glib libarchive[core,bzip2,libxml2,lz4,lzma,lzo] pthread tesseract libxml2 ffmpeg zstd
|
vcpkg install lmdb cjson glib libarchive[core,bzip2,libxml2,lz4,lzma,lzo] pthread tesseract libxml2 ffmpeg zstd gtest mongoose
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Build
|
2. Build
|
||||||
|
14
src/cli.c
14
src/cli.c
@ -11,8 +11,7 @@
|
|||||||
#define DEFAULT_ES_URL "http://localhost:9200"
|
#define DEFAULT_ES_URL "http://localhost:9200"
|
||||||
#define DEFAULT_BATCH_SIZE 100
|
#define DEFAULT_BATCH_SIZE 100
|
||||||
|
|
||||||
#define DEFAULT_BIND_ADDR "localhost"
|
#define DEFAULT_LISTEN_ADDRESS "localhost:4090"
|
||||||
#define DEFAULT_PORT "4090"
|
|
||||||
|
|
||||||
const char* TESS_DATAPATHS[] = {
|
const char* TESS_DATAPATHS[] = {
|
||||||
"/usr/share/tessdata/",
|
"/usr/share/tessdata/",
|
||||||
@ -276,12 +275,8 @@ int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
|||||||
args->es_url = DEFAULT_ES_URL;
|
args->es_url = DEFAULT_ES_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->bind == NULL) {
|
if (args->listen_address == NULL) {
|
||||||
args->bind = DEFAULT_BIND_ADDR;
|
args->listen_address = DEFAULT_LISTEN_ADDRESS;
|
||||||
}
|
|
||||||
|
|
||||||
if (args->port == NULL) {
|
|
||||||
args->port = DEFAULT_PORT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->credentials != NULL) {
|
if (args->credentials != NULL) {
|
||||||
@ -316,8 +311,7 @@ int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUGF("cli.c", "arg es_url=%s", args->es_url)
|
LOG_DEBUGF("cli.c", "arg es_url=%s", args->es_url)
|
||||||
LOG_DEBUGF("cli.c", "arg bind=%s", args->bind)
|
LOG_DEBUGF("cli.c", "arg listen=%s", args->listen_address)
|
||||||
LOG_DEBUGF("cli.c", "arg port=%s", args->port)
|
|
||||||
LOG_DEBUGF("cli.c", "arg credentials=%s", args->credentials)
|
LOG_DEBUGF("cli.c", "arg credentials=%s", args->credentials)
|
||||||
LOG_DEBUGF("cli.c", "arg auth_user=%s", args->auth_user)
|
LOG_DEBUGF("cli.c", "arg auth_user=%s", args->auth_user)
|
||||||
LOG_DEBUGF("cli.c", "arg auth_pass=%s", args->auth_pass)
|
LOG_DEBUGF("cli.c", "arg auth_pass=%s", args->auth_pass)
|
||||||
|
@ -42,8 +42,7 @@ typedef struct index_args {
|
|||||||
|
|
||||||
typedef struct web_args {
|
typedef struct web_args {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
char *bind;
|
char *listen_address;
|
||||||
char *port;
|
|
||||||
char *credentials;
|
char *credentials;
|
||||||
char auth_user[256];
|
char auth_user[256];
|
||||||
char auth_pass[256];
|
char auth_pass[256];
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
|
|
||||||
void free_response(response_t *resp) {
|
void free_response(response_t *resp) {
|
||||||
free(resp->body);
|
if (resp->body != NULL) {
|
||||||
|
free(resp->body);
|
||||||
|
}
|
||||||
free(resp);
|
free(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +25,7 @@ void http_req_ev(struct mg_connection *nc, int ev, void *ptr) {
|
|||||||
int connect_status = *(int *) ptr;
|
int connect_status = *(int *) ptr;
|
||||||
if (connect_status != 0) {
|
if (connect_status != 0) {
|
||||||
ev_data->done = TRUE;
|
ev_data->done = TRUE;
|
||||||
//TODO: set error
|
ev_data->resp->status_code = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -79,7 +81,7 @@ subreq_ctx_t *http_req(const char *url, const char *extra_headers, const char *p
|
|||||||
nc->user_data = &ctx->ev_data;
|
nc->user_data = &ctx->ev_data;
|
||||||
mg_set_protocol_http_websocket(nc);
|
mg_set_protocol_http_websocket(nc);
|
||||||
|
|
||||||
ctx->ev_data.resp = malloc(sizeof(response_t));
|
ctx->ev_data.resp = calloc(1, sizeof(response_t));
|
||||||
ctx->ev_data.done = FALSE;
|
ctx->ev_data.done = FALSE;
|
||||||
|
|
||||||
mg_printf(
|
mg_printf(
|
||||||
|
@ -302,7 +302,7 @@ void sist2_web(web_args_t *args) {
|
|||||||
free(abs_path);
|
free(abs_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
serve(args->bind, args->port);
|
serve(args->listen_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -356,8 +356,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
OPT_GROUP("Web options"),
|
OPT_GROUP("Web options"),
|
||||||
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url. DEFAULT=http://localhost:9200"),
|
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url. DEFAULT=http://localhost:9200"),
|
||||||
OPT_STRING(0, "bind", &web_args->bind, "Listen on this address. DEFAULT=localhost"),
|
OPT_STRING(0, "bind", &web_args->listen_address, "Listen on this address. DEFAULT=localhost:4090"),
|
||||||
OPT_STRING(0, "port", &web_args->port, "Listen on this port. DEFAULT=4090"),
|
|
||||||
OPT_STRING(0, "auth", &web_args->credentials, "Basic auth in user:password format"),
|
OPT_STRING(0, "auth", &web_args->credentials, "Basic auth in user:password format"),
|
||||||
|
|
||||||
OPT_END(),
|
OPT_END(),
|
||||||
|
@ -407,8 +407,10 @@ static void ev_router(struct mg_connection *nc, int ev, void *p) {
|
|||||||
if (r->status_code == 200) {
|
if (r->status_code == 200) {
|
||||||
send_response_line(nc, 200, r->size, "Content-Type: application/json");
|
send_response_line(nc, 200, r->size, "Content-Type: application/json");
|
||||||
mg_send(nc, r->body, r->size);
|
mg_send(nc, r->body, r->size);
|
||||||
|
} else if (r->status_code == 0) {
|
||||||
|
sist_log("serve.c", SIST_ERROR, "Could not connect to elasticsearch!");
|
||||||
} else {
|
} else {
|
||||||
sist_log("serve.c", SIST_WARNING, "ElasticSearch error during query");
|
sist_logf("serve.c", SIST_WARNING, "ElasticSearch error during query (%d)", r->status_code);
|
||||||
if (r->size != 0) {
|
if (r->size != 0) {
|
||||||
char *tmp = malloc(r->size + 1);
|
char *tmp = malloc(r->size + 1);
|
||||||
memcpy(tmp, r->body, r->size);
|
memcpy(tmp, r->body, r->size);
|
||||||
@ -430,23 +432,20 @@ static void ev_router(struct mg_connection *nc, int ev, void *p) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void serve(const char *hostname, const char *port) {
|
void serve(const char *listen_address) {
|
||||||
|
|
||||||
printf("Starting web server @ http://%s:%s\n", hostname, port);
|
printf("Starting web server @ http://%s\n", listen_address);
|
||||||
|
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
mg_mgr_init(&mgr, NULL);
|
mg_mgr_init(&mgr, NULL);
|
||||||
|
|
||||||
struct mg_connection *nc = mg_bind(&mgr, "0.0.0.0:8000", ev_router);
|
struct mg_connection *nc = mg_bind(&mgr, listen_address, ev_router);
|
||||||
if (nc == NULL) {
|
if (nc == NULL) {
|
||||||
printf("Failed to create listener\n");
|
LOG_FATALF("serve.c", "Couldn't bind web server on address %s", listen_address)
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
mg_set_protocol_http_websocket(nc);
|
mg_set_protocol_http_websocket(nc);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mg_mgr_poll(&mgr, 10);
|
mg_mgr_poll(&mgr, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// onion_set_root_handler(o, auth_basic(WebCtx.b64credentials, onion_url_to_handler(urls)));
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include "src/sist.h"
|
#include "src/sist.h"
|
||||||
|
|
||||||
void serve(const char *hostname, const char *port);
|
void serve(const char *listen_address);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user