revert debug hard-coded listen address

This commit is contained in:
simon987 2020-04-21 15:52:35 -04:00
parent e436af7b2a
commit 695d9abd83
7 changed files with 21 additions and 28 deletions

View File

@ -119,7 +119,7 @@ binaries (GCC 7+ required).
1. Install compile-time dependencies
```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

View File

@ -11,8 +11,7 @@
#define DEFAULT_ES_URL "http://localhost:9200"
#define DEFAULT_BATCH_SIZE 100
#define DEFAULT_BIND_ADDR "localhost"
#define DEFAULT_PORT "4090"
#define DEFAULT_LISTEN_ADDRESS "localhost:4090"
const char* TESS_DATAPATHS[] = {
"/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;
}
if (args->bind == NULL) {
args->bind = DEFAULT_BIND_ADDR;
}
if (args->port == NULL) {
args->port = DEFAULT_PORT;
if (args->listen_address == NULL) {
args->listen_address = DEFAULT_LISTEN_ADDRESS;
}
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 bind=%s", args->bind)
LOG_DEBUGF("cli.c", "arg port=%s", args->port)
LOG_DEBUGF("cli.c", "arg listen=%s", args->listen_address)
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_pass=%s", args->auth_pass)

View File

@ -42,8 +42,7 @@ typedef struct index_args {
typedef struct web_args {
char *es_url;
char *bind;
char *port;
char *listen_address;
char *credentials;
char auth_user[256];
char auth_pass[256];

View File

@ -7,7 +7,9 @@
void free_response(response_t *resp) {
free(resp->body);
if (resp->body != NULL) {
free(resp->body);
}
free(resp);
}
@ -23,7 +25,7 @@ void http_req_ev(struct mg_connection *nc, int ev, void *ptr) {
int connect_status = *(int *) ptr;
if (connect_status != 0) {
ev_data->done = TRUE;
//TODO: set error
ev_data->resp->status_code = 0;
}
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;
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;
mg_printf(

View File

@ -302,7 +302,7 @@ void sist2_web(web_args_t *args) {
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_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, "port", &web_args->port, "Listen on this port. DEFAULT=4090"),
OPT_STRING(0, "bind", &web_args->listen_address, "Listen on this address. DEFAULT=localhost:4090"),
OPT_STRING(0, "auth", &web_args->credentials, "Basic auth in user:password format"),
OPT_END(),

View File

@ -407,8 +407,10 @@ static void ev_router(struct mg_connection *nc, int ev, void *p) {
if (r->status_code == 200) {
send_response_line(nc, 200, r->size, "Content-Type: application/json");
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 {
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) {
char *tmp = malloc(r->size + 1);
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;
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) {
printf("Failed to create listener\n");
return;
LOG_FATALF("serve.c", "Couldn't bind web server on address %s", listen_address)
}
mg_set_protocol_http_websocket(nc);
for (;;) {
mg_mgr_poll(&mgr, 10);
}
// onion_set_root_handler(o, auth_basic(WebCtx.b64credentials, onion_url_to_handler(urls)));
}

View File

@ -3,6 +3,6 @@
#include "src/sist.h"
void serve(const char *hostname, const char *port);
void serve(const char *listen_address);
#endif