Compare commits
13 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f641dccda | ||
|
|
bceed896bb | ||
|
|
c52d52df2a | ||
|
|
6468c28652 | ||
|
|
0b7db033c5 | ||
|
|
c2c5440b21 | ||
|
|
47e6204e08 | ||
|
|
40dfb78ef2 | ||
|
|
bd471e4113 | ||
|
|
67cbd21fc4 | ||
|
|
48c211fc64 | ||
|
|
5c93649473 | ||
|
|
fbcf5b1464 |
12 changed files with 60 additions and 60 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -4,5 +4,8 @@ cosmopolitan
|
||||||
|
|
||||||
feuille
|
feuille
|
||||||
feuille.com
|
feuille.com
|
||||||
|
feuille.com.dbg
|
||||||
|
|
||||||
cgi/feuille.cgi
|
cgi/feuille.cgi
|
||||||
|
|
||||||
|
.ccls-cache
|
||||||
|
|
|
||||||
42
Makefile
42
Makefile
|
|
@ -10,18 +10,21 @@ TARGET$(COSMO) = feuille
|
||||||
SRC = feuille.c util.c server.c bin.c
|
SRC = feuille.c util.c server.c bin.c
|
||||||
OBJ = $(SRC:%.c=%.o)
|
OBJ = $(SRC:%.c=%.o)
|
||||||
|
|
||||||
|
|
||||||
all: $(TARGET) feuille.1 cgi
|
all: $(TARGET) feuille.1 cgi
|
||||||
|
|
||||||
run: $(TARGET)
|
run: $(TARGET)
|
||||||
./$(TARGET)
|
./$(TARGET)
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@printf "%-8s $(OBJ)\n" "rm"
|
@printf "%-8s $(OBJ)\n" "rm"
|
||||||
@rm -f $(OBJ)
|
@rm -f $(OBJ)
|
||||||
|
|
||||||
distclean:
|
distclean:
|
||||||
@printf "%-8s feuille feuille.com $(OBJ)\n" "rm"
|
@printf "%-8s feuille feuille.com feuille.com.dbg $(OBJ)\n" "rm"
|
||||||
@rm -f feuille feuille.com $(OBJ)
|
@rm -f feuille feuille.com feuille.com.dbg $(OBJ)
|
||||||
|
|
||||||
|
|
||||||
install: $(TARGET) feuille.1
|
install: $(TARGET) feuille.1
|
||||||
@echo "installing executable file to $(PREFIX)/bin"
|
@echo "installing executable file to $(PREFIX)/bin"
|
||||||
|
|
@ -34,37 +37,44 @@ install: $(TARGET) feuille.1
|
||||||
@cp -f feuille.1 $(MAN)/man1
|
@cp -f feuille.1 $(MAN)/man1
|
||||||
@chmod 644 $(MAN)/man1/feuille.1
|
@chmod 644 $(MAN)/man1/feuille.1
|
||||||
|
|
||||||
uninstall: $(PREFIX)/bin/$(TARGET) $(MAN)/man1/feuille.1
|
uninstall:
|
||||||
@echo "removing executable file from $(PREFIX)/bin"
|
@echo "removing executable file from $(PREFIX)/bin"
|
||||||
@rm -f "$(PREFIX)/bin/$(TARGET)"
|
@rm -f "$(PREFIX)/bin/$(TARGET)"
|
||||||
|
|
||||||
@echo "removing manpage from $(MAN)/man1"
|
@echo "removing manpage from $(MAN)/man1"
|
||||||
@rm -f $(MAN)/man1/feuille.1
|
@rm -f $(MAN)/man1/feuille.1
|
||||||
|
|
||||||
feuille.1: feuille.1.md config.mk
|
|
||||||
@printf "%-8s feuille.1.md -o feuille.1\n" "pandoc"
|
|
||||||
@sed "s/{VERSION}/$(VERSION)/g" feuille.1.md | pandoc -s -t man -o feuille.1
|
|
||||||
|
|
||||||
|
# manpage
|
||||||
|
feuille.1: feuille.1.md config.mk
|
||||||
|
@printf "%-8s $@.md -o $@\n" "pandoc"
|
||||||
|
@sed "s/{VERSION}/$(VERSION)/g" $@.md | pandoc -s -t man -o $@
|
||||||
|
|
||||||
|
# standard libc
|
||||||
feuille: $(OBJ)
|
feuille: $(OBJ)
|
||||||
@printf "%-8s $(OBJ) -o feuille\n" "$(CC)"
|
@printf "%-8s $(OBJ) -o $@\n" "$(CC)"
|
||||||
@$(CC) $(OBJ) -o feuille $(LDFLAGS)
|
@$(CC) $(OBJ) -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
# cosmopolitan libc
|
# cosmopolitan libc
|
||||||
feuille.com: cosmopolitan feuille
|
|
||||||
@printf "%-8s feuille -o feuille.com\n" "objcopy"
|
|
||||||
@objcopy -S -O binary feuille feuille.com
|
|
||||||
|
|
||||||
cosmopolitan:
|
cosmopolitan:
|
||||||
@if [ ! -d cosmopolitan ]; then \
|
@if [ ! -d cosmopolitan ]; then \
|
||||||
printf "%-8s https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.2.zip\n" "curl" ;\
|
printf "%-8s https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.2.zip\n" "curl" ;\
|
||||||
curl -sO "https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.2.zip" ;\
|
curl -sO "https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.2.zip" ;\
|
||||||
\
|
\
|
||||||
printf "%-8s cosmopolitan-amalgamation-2.2.zip\n" "unzip" ;\
|
printf "%-8s cosmopolitan-amalgamation-2.2.zip\n" "unzip" ;\
|
||||||
unzip -qf cosmopolitan-amalgamation-2.2.zip -d cosmopolitan ;\
|
unzip -q cosmopolitan-amalgamation-2.2.zip -d cosmopolitan ;\
|
||||||
\
|
\
|
||||||
rm -rf cosmopolitan-amalgamation-* ;\
|
rm -rf cosmopolitan-amalgamation-* ;\
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
feuille.com.dbg: $(OBJ)
|
||||||
|
@printf "%-8s $(OBJ) -o $@\n" "$(CC)"
|
||||||
|
@$(CC) $(OBJ) -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
feuille.com: cosmopolitan feuille.com.dbg
|
||||||
|
@printf "%-8s $@.dbg -o $@\n" "objcopy"
|
||||||
|
@objcopy -S -O binary $@.dbg $@
|
||||||
|
|
||||||
# CGI script
|
# CGI script
|
||||||
ADDR = 127.0.0.1
|
ADDR = 127.0.0.1
|
||||||
PORT = 9999
|
PORT = 9999
|
||||||
|
|
@ -73,9 +83,9 @@ cgi: cgi/feuille.cgi
|
||||||
|
|
||||||
cgi/feuille.cgi: cgi/feuille.cgi.c
|
cgi/feuille.cgi: cgi/feuille.cgi.c
|
||||||
@printf "%-8s cgi/feuille.cgi.c -o cgi/feuille.cgi\n" "$(CC)"
|
@printf "%-8s cgi/feuille.cgi.c -o cgi/feuille.cgi\n" "$(CC)"
|
||||||
@$(CC) cgi/feuille.cgi.c -o cgi/feuille.cgi -std=c99 -O3 -static -Wall -Wextra \
|
@$(CC) $@.c -o $@ -std=c99 -O3 -static -Wall -Wextra \
|
||||||
-DADDR=\"$(ADDR)\" -DPORT=$(PORT) \
|
-DADDR=\"$(ADDR)\" -DPORT=$(PORT) \
|
||||||
$(INCS) $(LIBS)
|
$(INCS) $(LIBS)
|
||||||
|
|
||||||
.SUFFIXES: .c .o
|
.SUFFIXES: .c .o
|
||||||
.c.o:
|
.c.o:
|
||||||
|
|
|
||||||
12
README.md
12
README.md
|
|
@ -8,6 +8,7 @@ code quality, and security.
|
||||||
<summary>Table of Contents</summary>
|
<summary>Table of Contents</summary>
|
||||||
<ol>
|
<ol>
|
||||||
<li><a href="#usage">Usage</a></li>
|
<li><a href="#usage">Usage</a></li>
|
||||||
|
<li><a href="#description">Description</a></li>
|
||||||
<li>
|
<li>
|
||||||
<a href="#installation">Installation</a>
|
<a href="#installation">Installation</a>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
@ -132,7 +133,8 @@ That sould be it. Have fun!
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
* Focuses on speed,
|
* Focuses on speed,
|
||||||
* Multi-threaded (using `fork`)
|
* Handles multiple requests at once (using a pool of `fork`'ed
|
||||||
|
workers)
|
||||||
* Only does what it needs to do
|
* Only does what it needs to do
|
||||||
|
|
||||||
* code quality,
|
* code quality,
|
||||||
|
|
@ -159,7 +161,7 @@ That sould be it. Have fun!
|
||||||
* Works on nearly all POSIX-compliant OSes
|
* Works on nearly all POSIX-compliant OSes
|
||||||
* Can be run in the background and as a service
|
* Can be run in the background and as a service
|
||||||
* IPv6-enabled
|
* IPv6-enabled
|
||||||
* Now with 100% more (Cosmopolitan libc)[http://justine.lol/cosmopolitan/] support!
|
* Now with 100% more [Cosmopolitan libc](http://justine.lol/cosmopolitan/) support!
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
@ -196,11 +198,11 @@ $ sudo make install
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also build using the
|
You can also build using the
|
||||||
(Cosmopolitan libc)[http://justine.lol/cosmopolitan/], which will
|
[Cosmopolitan libc](http://justine.lol/cosmopolitan/), which will
|
||||||
make an executable capable of running on Linux, OpenBSD, FreeBSD,
|
make an executable capable of running on Linux, OpenBSD, FreeBSD,
|
||||||
Mac... out of the box. To do so, build with the `COSMO` flag.
|
Mac... out of the box. To do so, build with the `COSMO` flag.
|
||||||
It will produce `feuille` and `feuille.com`, the former being the
|
It will produce `feuille.com.dbg` and `feuille.com`, the former being
|
||||||
debug binary, and the former the portable one.
|
the debug binary, and the latter the portable one.
|
||||||
|
|
||||||
If you wish to make a debug build, you can set `DEBUG` to whatever
|
If you wish to make a debug build, you can set `DEBUG` to whatever
|
||||||
comes to your mind.
|
comes to your mind.
|
||||||
|
|
|
||||||
5
arg.h
5
arg.h
|
|
@ -31,8 +31,7 @@
|
||||||
* by 20h
|
* by 20h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ARG_H_
|
#pragma once
|
||||||
#define _ARG_H_
|
|
||||||
|
|
||||||
#ifndef COSMOPOLITAN
|
#ifndef COSMOPOLITAN
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -79,5 +78,3 @@ extern char *argv0;
|
||||||
(brk_ = 1, (argv[0][i_+1] != '\0')?\
|
(brk_ = 1, (argv[0][i_+1] != '\0')?\
|
||||||
(&argv[0][i_+1]) :\
|
(&argv[0][i_+1]) :\
|
||||||
(argc--, argv++, argv[0])))
|
(argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
5
bin.h
5
bin.h
|
|
@ -11,8 +11,7 @@
|
||||||
* <https://basedwa.re/tmtt/feuille/src/branch/main/LICENSE>.
|
* <https://basedwa.re/tmtt/feuille/src/branch/main/LICENSE>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _BIN_H_
|
#pragma once
|
||||||
#define _BIN_H_
|
|
||||||
|
|
||||||
#include "feuille.h"
|
#include "feuille.h"
|
||||||
|
|
||||||
|
|
@ -21,5 +20,3 @@ int write_paste(char *, unsigned long, char *);
|
||||||
|
|
||||||
char *generate_id(int);
|
char *generate_id(int);
|
||||||
char *create_url(char *);
|
char *create_url(char *);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# feuille version
|
# feuille version
|
||||||
VERSION = 2.1.0
|
VERSION = 2.1.4
|
||||||
|
|
||||||
# paths (customize them to fit your system)
|
# paths (customize them to fit your system)
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
|
|
@ -41,4 +41,4 @@ CFLAGS$(DEBUG) = -O3 -Wall -Wextra -Wno-sign-compare $(CCFLAGS)
|
||||||
LDFLAGS$(DEBUG) = -s $(CLDFLAGS)
|
LDFLAGS$(DEBUG) = -s $(CLDFLAGS)
|
||||||
|
|
||||||
# static build (uncomment)
|
# static build (uncomment)
|
||||||
#LD_FLAGS += -static
|
#LDFLAGS += -static
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
. ftr VB CB
|
. ftr VB CB
|
||||||
. ftr VBI CBI
|
. ftr VBI CBI
|
||||||
.\}
|
.\}
|
||||||
.TH "feuille" "1" "November 2022" "feuille 2.1.0" ""
|
.TH "feuille" "1" "November 2022" "feuille 2.1.4" ""
|
||||||
.hy
|
.hy
|
||||||
.SH NAME
|
.SH NAME
|
||||||
.PP
|
.PP
|
||||||
|
|
@ -45,7 +45,7 @@ The difference is minimal, no need to worry about it.
|
||||||
Default: \f[V]131072\f[R]B (128KiB)
|
Default: \f[V]131072\f[R]B (128KiB)
|
||||||
.TP
|
.TP
|
||||||
\f[B]-f\f[R]
|
\f[B]-f\f[R]
|
||||||
Makes \f[B]feuille\f[R] run in the forground.
|
Makes \f[B]feuille\f[R] run in the foreground.
|
||||||
Default: disabled
|
Default: disabled
|
||||||
.TP
|
.TP
|
||||||
\f[B]-h\f[R]
|
\f[B]-h\f[R]
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ and IPv6 addresses (won't work on OpenBSD).
|
||||||
: Default: `131072`B (128KiB)
|
: Default: `131072`B (128KiB)
|
||||||
|
|
||||||
**-f**
|
**-f**
|
||||||
: Makes **feuille** run in the forground.
|
: Makes **feuille** run in the foreground.
|
||||||
: Default: disabled
|
: Default: disabled
|
||||||
|
|
||||||
**-h**
|
**-h**
|
||||||
|
|
|
||||||
28
feuille.c
28
feuille.c
|
|
@ -41,20 +41,20 @@ char *argv0;
|
||||||
|
|
||||||
/* default settings */
|
/* default settings */
|
||||||
Settings settings = {
|
Settings settings = {
|
||||||
.address = "0.0.0.0",
|
.address = "0.0.0.0",
|
||||||
.url = "http://localhost",
|
.url = "http://localhost",
|
||||||
.output = "/var/www/feuille",
|
.output = "/var/www/feuille",
|
||||||
.user = "www",
|
.user = "www",
|
||||||
|
|
||||||
.id_length = 4,
|
.id_length = 4,
|
||||||
.worker_count = 4,
|
.worker_count = 4,
|
||||||
.port = 9999,
|
.port = 9999,
|
||||||
.timeout = 2,
|
.timeout = 2,
|
||||||
.max_size = 1048576, /* = 1MiB = 1024 * 1024 */
|
.max_size = 1048576, /* = 1MiB = 1024 * 1024 */
|
||||||
.buffer_size = 131072, /* = 128KiB = 1024 * 128 */
|
.buffer_size = 131072, /* = 128KiB = 1024 * 128 */
|
||||||
|
|
||||||
.verbose = 0,
|
.verbose = 0,
|
||||||
.foreground = 0
|
.foreground = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/* functions declarations */
|
/* functions declarations */
|
||||||
|
|
@ -389,11 +389,11 @@ int main(int argc, char *argv[])
|
||||||
if (setgid(gid) != 0 || getgid() != gid)
|
if (setgid(gid) != 0 || getgid() != gid)
|
||||||
die(1, "could not switch to group for user `%s'.\n", settings.user);
|
die(1, "could not switch to group for user `%s'.\n", settings.user);
|
||||||
|
|
||||||
#ifndef COSMOPOLITAN
|
#ifndef COSMOPOLITAN
|
||||||
/* initgroups doesn't work on cosmopolitan libc yet */
|
/* initgroups doesn't work on cosmopolitan libc yet */
|
||||||
if (initgroups(settings.user, gid) != 0)
|
if (initgroups(settings.user, gid) != 0)
|
||||||
die(1, "could not initialize other groups for user `%s'.\n", settings.user);
|
die(1, "could not initialize other groups for user `%s'.\n", settings.user);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* switching user */
|
/* switching user */
|
||||||
if (setuid(uid) != 0 || getuid() != uid)
|
if (setuid(uid) != 0 || getuid() != uid)
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,7 @@
|
||||||
* <https://basedwa.re/tmtt/feuille/src/branch/main/LICENSE>.
|
* <https://basedwa.re/tmtt/feuille/src/branch/main/LICENSE>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _FEUILLE_H_
|
#pragma once
|
||||||
#define _FEUILLE_H_
|
|
||||||
|
|
||||||
typedef struct Settings {
|
typedef struct Settings {
|
||||||
char *address;
|
char *address;
|
||||||
|
|
@ -32,5 +31,3 @@ typedef struct Settings {
|
||||||
} Settings;
|
} Settings;
|
||||||
|
|
||||||
extern Settings settings;
|
extern Settings settings;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
5
server.h
5
server.h
|
|
@ -11,8 +11,7 @@
|
||||||
* <https://basedwa.re/tmtt/feuille/src/branch/main/LICENSE>.
|
* <https://basedwa.re/tmtt/feuille/src/branch/main/LICENSE>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _SERVER_H_
|
#pragma once
|
||||||
#define _SERVER_H_
|
|
||||||
|
|
||||||
#include "feuille.h"
|
#include "feuille.h"
|
||||||
|
|
||||||
|
|
@ -23,5 +22,3 @@ void close_connection(int);
|
||||||
|
|
||||||
unsigned long read_paste(int, char **);
|
unsigned long read_paste(int, char **);
|
||||||
int send_response(int, char *);
|
int send_response(int, char *);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
5
util.h
5
util.h
|
|
@ -11,11 +11,8 @@
|
||||||
* <https://basedwa.re/tmtt/feuille/src/branch/main/LICENSE>.
|
* <https://basedwa.re/tmtt/feuille/src/branch/main/LICENSE>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _UTIL_H_
|
#pragma once
|
||||||
#define _UTIL_H_
|
|
||||||
|
|
||||||
void die(int, char *, ...);
|
void die(int, char *, ...);
|
||||||
void error(char *, ...);
|
void error(char *, ...);
|
||||||
void verbose(int, char *, ...);
|
void verbose(int, char *, ...);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
Reference in a new issue