mirror of
https://github.com/simon987/sist2.git
synced 2025-09-12 09:16:52 +00:00
Bug fixes
This commit is contained in:
parent
dd3d6cf99a
commit
f08ddd8658
File diff suppressed because one or more lines are too long
@ -12,7 +12,7 @@ const char *log_levels[] = {
|
||||
"DEBUG", "INFO", "WARNING", "ERROR", "FATAL"
|
||||
};
|
||||
|
||||
void sist_logf(char *filepath, int level, char *format, ...) {
|
||||
void sist_logf(const char *filepath, int level, char *format, ...) {
|
||||
|
||||
static int is_tty = -1;
|
||||
if (is_tty == -1) {
|
||||
@ -61,11 +61,11 @@ void sist_logf(char *filepath, int level, char *format, ...) {
|
||||
|
||||
int ret = write(STDERR_FILENO, log_str, log_len);
|
||||
if (ret == -1) {
|
||||
LOG_FATALF("serialize.c", "Could not write index descriptor: %s", strerror(errno));
|
||||
LOG_FATALF("serialize.c", "Could not write index descriptor: %s", strerror(errno))
|
||||
}
|
||||
}
|
||||
|
||||
void sist_log(char *filepath, int level, char *str) {
|
||||
void sist_log(const char *filepath, int level, char *str) {
|
||||
|
||||
static int is_tty = -1;
|
||||
if (is_tty == -1) {
|
||||
|
@ -39,8 +39,8 @@
|
||||
|
||||
#include "sist.h"
|
||||
|
||||
void sist_logf(char *filepath, int level, char *format, ...);
|
||||
void sist_logf(const char *filepath, int level, char *format, ...);
|
||||
|
||||
void sist_log(char *filepath, int level, char *str);
|
||||
void sist_log(const char *filepath, int level, char *str);
|
||||
|
||||
#endif
|
||||
|
@ -82,7 +82,6 @@ void initialize_scan_context(scan_args_t *args) {
|
||||
// Media
|
||||
ScanCtx.media_ctx.tn_qscale = args->quality;
|
||||
ScanCtx.media_ctx.tn_size = args->size;
|
||||
ScanCtx.media_ctx.content_size = args->content_size;
|
||||
ScanCtx.media_ctx.log = sist_log;
|
||||
ScanCtx.media_ctx.logf = sist_logf;
|
||||
ScanCtx.media_ctx.store = _store;
|
||||
|
@ -59,7 +59,7 @@ void search_index(struct mg_connection *nc) {
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
}
|
||||
|
||||
int javascript(struct mg_connection *nc) {
|
||||
void javascript(struct mg_connection *nc) {
|
||||
send_response_line(nc, 200, sizeof(bundle_js), "Content-Type: application/javascript");
|
||||
mg_send(nc, bundle_js, sizeof(bundle_js));
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
@ -85,7 +85,7 @@ int client_requested_dark_theme(struct http_message *hm) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int style(struct mg_connection *nc, struct http_message *hm) {
|
||||
void style(struct mg_connection *nc, struct http_message *hm) {
|
||||
|
||||
if (client_requested_dark_theme(hm)) {
|
||||
send_response_line(nc, 200, sizeof(bundle_dark_css), "Content-Type: text/css");
|
||||
@ -98,7 +98,7 @@ int style(struct mg_connection *nc, struct http_message *hm) {
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
}
|
||||
|
||||
int img_sprite_skin_flat(struct mg_connection *nc, struct http_message *hm) {
|
||||
void img_sprite_skin_flat(struct mg_connection *nc, struct http_message *hm) {
|
||||
if (client_requested_dark_theme(hm)) {
|
||||
send_response_line(nc, 200, sizeof(sprite_skin_flat_dark_png), "Content-Type: image/png");
|
||||
mg_send(nc, sprite_skin_flat_dark_png, sizeof(sprite_skin_flat_dark_png));
|
||||
@ -113,7 +113,7 @@ int img_sprite_skin_flat(struct mg_connection *nc, struct http_message *hm) {
|
||||
void thumbnail(struct mg_connection *nc, struct http_message *hm, struct mg_str *path) {
|
||||
|
||||
if (path->len != UUID_STR_LEN * 2 + 2) {
|
||||
LOG_DEBUGF("serve.c", "Invalid thumbnail path: %.*s", (int) path->len, path->p);
|
||||
LOG_DEBUGF("serve.c", "Invalid thumbnail path: %.*s", (int) path->len, path->p)
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
return;
|
||||
}
|
||||
@ -129,14 +129,14 @@ void thumbnail(struct mg_connection *nc, struct http_message *hm, struct mg_str
|
||||
uuid_t uuid;
|
||||
int ret = uuid_parse(arg_uuid, uuid);
|
||||
if (ret != 0) {
|
||||
LOG_DEBUGF("serve.c", "Invalid thumbnail UUID: %s", arg_uuid);
|
||||
LOG_DEBUGF("serve.c", "Invalid thumbnail UUID: %s", arg_uuid)
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
return;
|
||||
}
|
||||
|
||||
store_t *store = get_store(arg_index);
|
||||
if (store == NULL) {
|
||||
LOG_DEBUGF("serve.c", "Could not get store for index: %s", arg_index);
|
||||
LOG_DEBUGF("serve.c", "Could not get store for index: %s", arg_index)
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
return;
|
||||
}
|
||||
@ -159,7 +159,7 @@ void search(struct mg_connection *nc, struct http_message *hm) {
|
||||
return;
|
||||
}
|
||||
|
||||
char * body = malloc(hm->body.len + 1);
|
||||
char *body = malloc(hm->body.len + 1);
|
||||
memcpy(body, hm->body.p, hm->body.len);
|
||||
*(body + hm->body.len) = '\0';
|
||||
|
||||
@ -170,23 +170,26 @@ void search(struct mg_connection *nc, struct http_message *hm) {
|
||||
free(body);
|
||||
}
|
||||
|
||||
//TODO
|
||||
//int serve_file_from_url(cJSON *json, index_t *idx, onion_request *req, onion_response *res) {
|
||||
//
|
||||
// const char *path = cJSON_GetObjectItem(json, "path")->valuestring;
|
||||
// const char *name = cJSON_GetObjectItem(json, "name")->valuestring;
|
||||
// const char *ext = cJSON_GetObjectItem(json, "extension")->valuestring;
|
||||
//
|
||||
// char url[8196];
|
||||
// snprintf(url, sizeof(url),
|
||||
// "%s%s/%s%s%s",
|
||||
// idx->desc.rewrite_url, path, name, strlen(ext) == 0 ? "" : ".", ext);
|
||||
//
|
||||
// dyn_buffer_t encoded = url_escape(url);
|
||||
// int ret = onion_shortcut_redirect(encoded.buf, req, res);
|
||||
// dyn_buffer_destroy(&encoded);
|
||||
// return ret;
|
||||
//}
|
||||
int serve_file_from_url(cJSON *json, index_t *idx, struct mg_connection *nc) {
|
||||
|
||||
const char *path = cJSON_GetObjectItem(json, "path")->valuestring;
|
||||
const char *name = cJSON_GetObjectItem(json, "name")->valuestring;
|
||||
const char *ext = cJSON_GetObjectItem(json, "extension")->valuestring;
|
||||
|
||||
char url[8196];
|
||||
snprintf(url, sizeof(url),
|
||||
"%s%s/%s%s%s",
|
||||
idx->desc.rewrite_url, path, name, strlen(ext) == 0 ? "" : ".", ext);
|
||||
|
||||
dyn_buffer_t encoded = url_escape(url);
|
||||
mg_http_send_redirect(
|
||||
nc, 308,
|
||||
(struct mg_str) MG_MK_STR_N(encoded.buf, encoded.cur),
|
||||
(struct mg_str) MG_NULL_STR
|
||||
);
|
||||
dyn_buffer_destroy(&encoded);
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
}
|
||||
|
||||
void serve_file_from_disk(cJSON *json, index_t *idx, struct mg_connection *nc, struct http_message *hm) {
|
||||
|
||||
@ -209,7 +212,7 @@ void serve_file_from_disk(cJSON *json, index_t *idx, struct mg_connection *nc, s
|
||||
mg_http_serve_file(nc, hm, full_path, mg_mk_str(mime), mg_mk_str(disposition));
|
||||
}
|
||||
|
||||
int index_info(struct mg_connection *nc) {
|
||||
void index_info(struct mg_connection *nc) {
|
||||
cJSON *json = cJSON_CreateObject();
|
||||
cJSON *arr = cJSON_AddArrayToObject(json, "indices");
|
||||
|
||||
@ -238,7 +241,7 @@ int index_info(struct mg_connection *nc) {
|
||||
void document_info(struct mg_connection *nc, struct http_message *hm, struct mg_str *path) {
|
||||
|
||||
if (path->len != UUID_STR_LEN + 2) {
|
||||
LOG_DEBUGF("serve.c", "Invalid document_info path: %.*s", (int) path->len, path->p);
|
||||
LOG_DEBUGF("serve.c", "Invalid document_info path: %.*s", (int) path->len, path->p)
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
return;
|
||||
}
|
||||
@ -265,7 +268,7 @@ void document_info(struct mg_connection *nc, struct http_message *hm, struct mg_
|
||||
}
|
||||
|
||||
char *json_str = cJSON_PrintUnformatted(source);
|
||||
send_response_line(nc, 200, (int)strlen(json_str), "Content-Type: application/json");
|
||||
send_response_line(nc, 200, (int) strlen(json_str), "Content-Type: application/json");
|
||||
free(json_str);
|
||||
cJSON_Delete(doc);
|
||||
|
||||
@ -275,7 +278,7 @@ void document_info(struct mg_connection *nc, struct http_message *hm, struct mg_
|
||||
void file(struct mg_connection *nc, struct http_message *hm, struct mg_str *path) {
|
||||
|
||||
if (path->len != UUID_STR_LEN + 2) {
|
||||
LOG_DEBUGF("serve.c", "Invalid file path: %.*s", (int) path->len, path->p);
|
||||
LOG_DEBUGF("serve.c", "Invalid file path: %.*s", (int) path->len, path->p)
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
return;
|
||||
}
|
||||
@ -316,13 +319,12 @@ void file(struct mg_connection *nc, struct http_message *hm, struct mg_str *path
|
||||
if (strlen(idx->desc.rewrite_url) == 0) {
|
||||
serve_file_from_disk(source, idx, nc, hm);
|
||||
} else {
|
||||
//TODO:
|
||||
// serve_file_from_url(source, idx, nc, hm);
|
||||
serve_file_from_url(source, idx, nc);
|
||||
}
|
||||
cJSON_Delete(doc);
|
||||
}
|
||||
|
||||
int status(struct mg_connection *nc) {
|
||||
void status(struct mg_connection *nc) {
|
||||
char *status = elastic_get_status();
|
||||
if (strcmp(status, "open") == 0) {
|
||||
send_response_line(nc, 204, 0, "Content-Type: application/json");
|
||||
@ -335,10 +337,6 @@ int status(struct mg_connection *nc) {
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
void *resp;
|
||||
} req_ctx_t;
|
||||
|
||||
static void ev_router(struct mg_connection *nc, int ev, void *p) {
|
||||
struct mg_str scheme;
|
||||
struct mg_str user_info;
|
||||
@ -383,7 +381,7 @@ static void ev_router(struct mg_connection *nc, int ev, void *p) {
|
||||
} else if (ev == MG_EV_POLL) {
|
||||
if (nc->user_data != NULL) {
|
||||
//Waiting for ES reply
|
||||
subreq_ctx_t *ctx = (subreq_ctx_t*) nc->user_data;
|
||||
subreq_ctx_t *ctx = (subreq_ctx_t *) nc->user_data;
|
||||
mg_mgr_poll(&ctx->mgr, 0);
|
||||
|
||||
if (ctx->ev_data.done == TRUE) {
|
||||
|
2
third-party/libscan
vendored
2
third-party/libscan
vendored
@ -1 +1 @@
|
||||
Subproject commit ec129b84e87550a2bd4361d3a3701c687590992a
|
||||
Subproject commit 23d88d7ea3d830f4aa864fec37b12022b2c8395c
|
Loading…
x
Reference in New Issue
Block a user