chibipub

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 53e870e117cf2985eca8a6247b62fb1f4f0ff8b4
parent 46c3f95e36432af593b18ed0a6acd007026fda6e
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  8 Jan 2021 09:35:01 -0800

dynamic hostname

Diffstat:
Msrc/wolfsocks.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 60 insertions(+), 6 deletions(-)

diff --git a/src/wolfsocks.c b/src/wolfsocks.c @@ -34,15 +34,49 @@ static void error(char *msg) exit(1); } +static inline const char *get_hostname() +{ + return getenv("WOLFSOCKS_HOST"); +} + + #define SCHEMA "https://" -#define HOST "ee509bbf0a5f.ngrok.io" static void init_test_webfinger(struct webfinger *finger) { - finger->acct = "jb55@" HOST; - finger->alias = SCHEMA HOST "/alias"; - finger->profile_page = SCHEMA HOST "/profile"; - finger->self = SCHEMA HOST "/"; + static unsigned char buf[512]; + struct cursor c; + make_cursor(buf, buf+sizeof(buf), &c); + + const char *host = get_hostname(); + assert(host); + + finger->acct = (char*)c.p; + + assert( + push_str(&c, "jb55@") && push_c_str(&c, host) + ); + + finger->alias = (char*)c.p; + + assert( + push_str(&c, SCHEMA) && push_str(&c, host) && + push_c_str(&c, "/alias") + ); + + finger->profile_page = (char*)c.p; + + assert( + push_str(&c, SCHEMA) && push_str(&c, host) && + push_c_str(&c, "/profile") + ); + + finger->self = (char*)c.p; + + assert( + push_str(&c, SCHEMA) && push_str(&c, host) && + push_c_str(&c, "/") + ); } static inline void write_status(struct http_req *req, const char *status) @@ -202,7 +236,18 @@ struct profile static void test_profile(struct profile *p) { - p->id = SCHEMA HOST "/"; + static unsigned char buf[128]; + struct cursor c; + make_cursor(buf, buf + sizeof(buf), &c); + + const char *host = get_hostname(); + assert(host); + + p->id = (char*)c.p; + assert( + push_str(&c, SCHEMA) && push_str(&c, host) && push_c_str(&c, "/") + ); + p->type = "Person"; p->username = "jb55"; p->name = "William Casarin"; @@ -392,8 +437,17 @@ void run_http_server() free(arena); } +static void load_config() +{ + if (!get_hostname()) { + printf("WOLFSOCKS_HOST env not set\n"); + exit(2); + } +} + int main(int argc, char *argv[]) { + load_config(); run_http_server(); return 0;