diff options
| author | Nakidai <nakidai@disroot.org> | 2024-09-27 19:17:40 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-09-27 19:17:40 +0300 |
| commit | 34fc96bd1451d6f8dfa1add742dab6e5269ec411 (patch) | |
| tree | 26d55a701c84ca2f97eacb49b5ff3829e60e14be | |
| parent | b3e4889f3d1bbf3a860e36e021e8d46d75446522 (diff) | |
| download | cptc-34fc96bd1451d6f8dfa1add742dab6e5269ec411.tar.gz cptc-34fc96bd1451d6f8dfa1add742dab6e5269ec411.zip | |
Autogenerate root on build
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Makefile | 10 | ||||
| -rw-r--r-- | cptc.h | 1 | ||||
| -rw-r--r-- | requestHandler.c | 14 | ||||
| -rw-r--r-- | utils/Makefile | 8 | ||||
| -rw-r--r-- | utils/convert.c | 9 |
6 files changed, 32 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore index 405c16a..ac0b5b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ compile_flags.txt *.o cptc +root.c +utils/convert diff --git a/Makefile b/Makefile index 5fa2be0..498fd08 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ OBJS += cptc.o OBJS += main.o OBJS += requestHandler.o OBJS += downloadAvatar.o +OBJS += root.o CFLAGS += $(shell curl-config --cflags) CFLAGS += -std=c11 @@ -12,10 +13,19 @@ RM = rm -f all: cptc +utils/%: + make -C utils + +root.c: utils/convert README + echo "const char *CPTC_root = \"$$(cat README | utils/convert)\";" > $@ + cptc: $(OBJS) $(CC) -o $@ $^ $(LDFLAGS) clean: $(RM) cptc *.o + make -C utils clean cptc: $(OBJS) + +.PHONY: all utils clean diff --git a/cptc.h b/cptc.h index cfbffec..2eaa14f 100644 --- a/cptc.h +++ b/cptc.h @@ -11,6 +11,7 @@ enum CPTC_Method }; extern const char *CPTC_token; +extern const char *CPTC_root; void CPTC(const char *address, in_port_t port); void CPTC_requestHandler(int fd); diff --git a/requestHandler.c b/requestHandler.c index 211947f..47ccc60 100644 --- a/requestHandler.c +++ b/requestHandler.c @@ -27,16 +27,6 @@ static const char *image_gif = "Content-Type: image/gif\r\n"; static const char *end = "\r\n"; -static const char *root = "\ -CPTC (https://github.com/nakidai/cptc)\n\ ---------------------------------------\n\ -PetTheCord but rewritten in the C cuz some people was annoying me about that a\n\ -lot.\n\ -\n\ -Paths:\n\ -/ Show this text\n\ -/<UID>.* Return a gif that pets given UID\n"; - static bool isnumber(const char *s) { for (const char *cp = s; *cp != '\0' && *cp != '.'; ++cp) @@ -86,13 +76,13 @@ void CPTC_requestHandler(int fd) if (strlen(path) == 1) { char *length = malloc(sizeof(*length) * 32); - snprintf(length, 32, content_length, strlen(root)); + snprintf(length, 32, content_length, strlen(CPTC_root)); strcpy(response, ok); strcat(response, text_plain); strcat(response, length); strcat(response, end); send(fd, response, strlen(response), 0); - send(fd, root, strlen(root), 0); + send(fd, CPTC_root, strlen(CPTC_root), 0); free(length); return; } diff --git a/utils/Makefile b/utils/Makefile new file mode 100644 index 0000000..711ac68 --- /dev/null +++ b/utils/Makefile @@ -0,0 +1,8 @@ +RM = rm -f + +all: convert + +clean: + $(RM) convert + +.PHONY: all clean diff --git a/utils/convert.c b/utils/convert.c new file mode 100644 index 0000000..2fc711e --- /dev/null +++ b/utils/convert.c @@ -0,0 +1,9 @@ +#include <stdio.h> + + +int main(void) +{ + int c; + while ((c = getchar()) >= 0) + printf("\\x%X", c); +} |