diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | httpd.c | 8 | ||||
| -rw-r--r-- | main.c | 43 | ||||
| -rw-r--r-- | snac.h | 2 |
4 files changed, 53 insertions, 4 deletions
| @@ -2,7 +2,7 @@ CFLAGS=-g -Wall | |||
| 2 | 2 | ||
| 3 | all: snac | 3 | all: snac |
| 4 | 4 | ||
| 5 | snac: snac.o main.o data.o http.o | 5 | snac: snac.o main.o data.o http.o httpd.o |
| 6 | $(CC) -L/usr/local/lib *.o -lcurl -lcrypto -o $@ | 6 | $(CC) -L/usr/local/lib *.o -lcurl -lcrypto -o $@ |
| 7 | 7 | ||
| 8 | .c.o: | 8 | .c.o: |
| @@ -19,3 +19,5 @@ main.o: main.c snac.h xs.h | |||
| 19 | data.o: data.c snac.h xs.h xs_json.h xs_openssl.h | 19 | data.o: data.c snac.h xs.h xs_json.h xs_openssl.h |
| 20 | 20 | ||
| 21 | http.o: http.c snac.h xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h | 21 | http.o: http.c snac.h xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h |
| 22 | |||
| 23 | httpd.o: http.c snac.h xs.h xs_encdec.h xs_socket.h xs_httpd.h | ||
| @@ -2,11 +2,8 @@ | |||
| 2 | /* copyright (c) 2022 grunfink - MIT license */ | 2 | /* copyright (c) 2022 grunfink - MIT license */ |
| 3 | 3 | ||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_io.h" | ||
| 6 | #include "xs_encdec.h" | 5 | #include "xs_encdec.h" |
| 7 | #include "xs_json.h" | 6 | #include "xs_json.h" |
| 8 | #include "xs_curl.h" | ||
| 9 | #include "xs_openssl.h" | ||
| 10 | #include "xs_socket.h" | 7 | #include "xs_socket.h" |
| 11 | #include "xs_httpd.h" | 8 | #include "xs_httpd.h" |
| 12 | 9 | ||
| @@ -23,6 +20,11 @@ void httpd_connection(int rs) | |||
| 23 | 20 | ||
| 24 | req = xs_httpd_request(f); | 21 | req = xs_httpd_request(f); |
| 25 | 22 | ||
| 23 | { | ||
| 24 | xs *j = xs_json_dumps_pp(req, 4); | ||
| 25 | printf("%s\n", j); | ||
| 26 | } | ||
| 27 | |||
| 26 | fclose(f); | 28 | fclose(f); |
| 27 | } | 29 | } |
| 28 | 30 | ||
| @@ -7,8 +7,50 @@ | |||
| 7 | 7 | ||
| 8 | #include "snac.h" | 8 | #include "snac.h" |
| 9 | 9 | ||
| 10 | int usage(void) | ||
| 11 | { | ||
| 12 | printf("usage:\n"); | ||
| 13 | return 1; | ||
| 14 | } | ||
| 15 | |||
| 16 | |||
| 10 | int main(int argc, char *argv[]) | 17 | int main(int argc, char *argv[]) |
| 11 | { | 18 | { |
| 19 | char *cmd; | ||
| 20 | char *basedir; | ||
| 21 | int argi = 1; | ||
| 22 | |||
| 23 | argc--; | ||
| 24 | if (argc < argi) | ||
| 25 | return usage(); | ||
| 26 | |||
| 27 | cmd = argv[argi++]; | ||
| 28 | |||
| 29 | if (strcmp(cmd, "init") == 0) { | ||
| 30 | return 0; | ||
| 31 | } | ||
| 32 | |||
| 33 | if (argc < argi) | ||
| 34 | return usage(); | ||
| 35 | |||
| 36 | basedir = argv[argi++]; | ||
| 37 | |||
| 38 | if (!srv_open(basedir)) { | ||
| 39 | srv_log(xs_fmt("error opening database at %s", basedir)); | ||
| 40 | return 1; | ||
| 41 | } | ||
| 42 | |||
| 43 | if (strcmp(cmd, "httpd") == 0) { | ||
| 44 | httpd(); | ||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | |||
| 48 | return 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | #if 0 | ||
| 53 | { | ||
| 12 | snac snac; | 54 | snac snac; |
| 13 | 55 | ||
| 14 | printf("%s\n", tid(0)); | 56 | printf("%s\n", tid(0)); |
| @@ -85,3 +127,4 @@ int main(int argc, char *argv[]) | |||
| 85 | 127 | ||
| 86 | return 0; | 128 | return 0; |
| 87 | } | 129 | } |
| 130 | #endif | ||
| @@ -67,3 +67,5 @@ d_char *http_signed_request(snac *snac, char *method, char *url, | |||
| 67 | d_char *headers, | 67 | d_char *headers, |
| 68 | d_char *body, int b_size, | 68 | d_char *body, int b_size, |
| 69 | int *status, d_char **payload, int *p_size); | 69 | int *status, d_char **payload, int *p_size); |
| 70 | |||
| 71 | void httpd(void); | ||