summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-21 18:27:30 +0200
committerdefault <nobody@localhost>2022-09-21 18:27:30 +0200
commite7c886beb77a570cdac02bc36077e247618e2e20 (patch)
treeb308aa531635b9237699abadb541d1a99cab7d4a
parent7efb6d5833c20a82ccb4bf2c89e5ce43831db540 (diff)
More httpd work.
-rw-r--r--Makefile4
-rw-r--r--httpd.c8
-rw-r--r--main.c43
-rw-r--r--snac.h2
4 files changed, 53 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index cc3fc0b..2a47479 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CFLAGS=-g -Wall
all: snac
-snac: snac.o main.o data.o http.o
+snac: snac.o main.o data.o http.o httpd.o
$(CC) -L/usr/local/lib *.o -lcurl -lcrypto -o $@
.c.o:
@@ -19,3 +19,5 @@ main.o: main.c snac.h xs.h
data.o: data.c snac.h xs.h xs_json.h xs_openssl.h
http.o: http.c snac.h xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h
+
+httpd.o: http.c snac.h xs.h xs_encdec.h xs_socket.h xs_httpd.h
diff --git a/httpd.c b/httpd.c
index 3d4975e..5fd8bbf 100644
--- a/httpd.c
+++ b/httpd.c
@@ -2,11 +2,8 @@
/* copyright (c) 2022 grunfink - MIT license */
#include "xs.h"
-#include "xs_io.h"
#include "xs_encdec.h"
#include "xs_json.h"
-#include "xs_curl.h"
-#include "xs_openssl.h"
#include "xs_socket.h"
#include "xs_httpd.h"
@@ -23,6 +20,11 @@ void httpd_connection(int rs)
req = xs_httpd_request(f);
+ {
+ xs *j = xs_json_dumps_pp(req, 4);
+ printf("%s\n", j);
+ }
+
fclose(f);
}
diff --git a/main.c b/main.c
index ec3dbf6..9ea17b2 100644
--- a/main.c
+++ b/main.c
@@ -7,8 +7,50 @@
#include "snac.h"
+int usage(void)
+{
+ printf("usage:\n");
+ return 1;
+}
+
+
int main(int argc, char *argv[])
{
+ char *cmd;
+ char *basedir;
+ int argi = 1;
+
+ argc--;
+ if (argc < argi)
+ return usage();
+
+ cmd = argv[argi++];
+
+ if (strcmp(cmd, "init") == 0) {
+ return 0;
+ }
+
+ if (argc < argi)
+ return usage();
+
+ basedir = argv[argi++];
+
+ if (!srv_open(basedir)) {
+ srv_log(xs_fmt("error opening database at %s", basedir));
+ return 1;
+ }
+
+ if (strcmp(cmd, "httpd") == 0) {
+ httpd();
+ return 0;
+ }
+
+ return 0;
+}
+
+
+#if 0
+{
snac snac;
printf("%s\n", tid(0));
@@ -85,3 +127,4 @@ int main(int argc, char *argv[])
return 0;
}
+#endif
diff --git a/snac.h b/snac.h
index ee5cd22..0aaeeed 100644
--- a/snac.h
+++ b/snac.h
@@ -67,3 +67,5 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
d_char *headers,
d_char *body, int b_size,
int *status, d_char **payload, int *p_size);
+
+void httpd(void);