mirror of
https://git.swurl.xyz/swirl/pacebin.git
synced 2024-11-22 12:59:19 +02:00
add compile option to disable custom links
This commit is contained in:
parent
4f164ddc67
commit
0ec0db6ccf
5
Makefile
5
Makefile
|
@ -4,8 +4,9 @@ systemd_dir=${DESTDIR}${confdir}/systemd/system
|
||||||
nginx_dir=${DESTDIR}${confdir}/nginx
|
nginx_dir=${DESTDIR}${confdir}/nginx
|
||||||
bindir=${DESTDIR}${prefix}/bin
|
bindir=${DESTDIR}${prefix}/bin
|
||||||
|
|
||||||
CC := gcc
|
DISABLE_CUSTOM_LINKS ?= 0
|
||||||
CFLAGS := -O2
|
CC ?= gcc
|
||||||
|
CFLAGS := -O2 -DDISABLE_CUSTOM_LINKS=${DISABLE_CUSTOM_LINKS} ${CFLAGS}
|
||||||
|
|
||||||
BIN := pacebin
|
BIN := pacebin
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ To build this project, you'll need a libc implementation (only tested with glibc
|
||||||
git clone https://git.swurl.xyz/swirl/pacebin && cd pacebin
|
git clone https://git.swurl.xyz/swirl/pacebin && cd pacebin
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Compile:
|
2. Now, you need to compile. When compiling, you can optionally choose to disable the ability to use custom links for pastes. This can easily be done by setting `DISABLE_CUSTOM_LINKS` to 1; i.e. `make DISABLE_CUSTOM_LINKS=1`. Defaults to 0, enabling them.
|
||||||
```bash
|
```bash
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
9
main.c
9
main.c
|
@ -104,6 +104,10 @@ void trim(char *str) {
|
||||||
memmove(str, _str, len + 1);
|
memmove(str, _str, len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DISABLE_CUSTOM_LINKS == 1
|
||||||
|
void handle_post(struct mg_connection *nc, char *content, char *host) {
|
||||||
|
char *short_link = gen_random_link();
|
||||||
|
#else
|
||||||
void handle_post(struct mg_connection *nc, char *content, char *host, char *link) {
|
void handle_post(struct mg_connection *nc, char *content, char *host, char *link) {
|
||||||
char *short_link;
|
char *short_link;
|
||||||
if (strlen(link) == 0) {
|
if (strlen(link) == 0) {
|
||||||
|
@ -117,6 +121,7 @@ void handle_post(struct mg_connection *nc, char *content, char *host, char *link
|
||||||
if (paste_exists(short_link)) {
|
if (paste_exists(short_link)) {
|
||||||
return mg_http_reply(nc, 500, "", "a paste named %s already exists", short_link);
|
return mg_http_reply(nc, 500, "", "a paste named %s already exists", short_link);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
FILE *url = get_paste_file(short_link, "w+");
|
FILE *url = get_paste_file(short_link, "w+");
|
||||||
fputs(content, url);
|
fputs(content, url);
|
||||||
|
@ -165,7 +170,11 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p, void *f) {
|
||||||
char *body = strdup(hm->body.ptr);
|
char *body = strdup(hm->body.ptr);
|
||||||
|
|
||||||
if (strncmp(hm->method.ptr, "POST", hm->method.len) == 0) {
|
if (strncmp(hm->method.ptr, "POST", hm->method.len) == 0) {
|
||||||
|
#if DISABLE_CUSTOM_LINKS == 1
|
||||||
|
handle_post(nc, body, host); // FIXME: return 400 on bad Content-Type
|
||||||
|
#else
|
||||||
handle_post(nc, body, host, uri); // FIXME: return 400 on bad Content-Type
|
handle_post(nc, body, host, uri); // FIXME: return 400 on bad Content-Type
|
||||||
|
#endif
|
||||||
} else if (strncmp(hm->method.ptr, "DELETE", hm->method.len) == 0) {
|
} else if (strncmp(hm->method.ptr, "DELETE", hm->method.len) == 0) {
|
||||||
handle_delete(nc, uri, body);
|
handle_delete(nc, uri, body);
|
||||||
} else if (strncmp(hm->method.ptr, "GET", hm->method.len) == 0) {
|
} else if (strncmp(hm->method.ptr, "GET", hm->method.len) == 0) {
|
||||||
|
|
Loading…
Reference in New Issue