aboutsummaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorOliver <zen@noreply.codeberg.org>2025-05-21 21:11:47 +0200
committerOliver <zen@noreply.codeberg.org>2025-05-21 21:11:47 +0200
commit979718e3cc5489efdce2acc6f8c86f6d00bb91c7 (patch)
tree7b4936bdb5ea07c7dd617d508c487d70020f0146 /utils.c
parent1b0804bb0da0ef89aef98d9a771d2aa5bfeb34d7 (diff)
parent5059fadf34b79a9f596313b0bd859c1eb89342ae (diff)
Merge pull request 'master refresh' (#8) from grunfink/snac2:master into master
Reviewed-on: https://codeberg.org/zen/snac2/pulls/8
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/utils.c b/utils.c
index 5d54b8b..d50707a 100644
--- a/utils.c
+++ b/utils.c
@@ -101,8 +101,9 @@ static const char *greeting_html =
"<html><head>\n"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n"
"<link rel=\"icon\" type=\"image/x-icon\" href=\"https://%host%/favicon.ico\"/>\n"
+ "<style>*{color-scheme:light dark}body{margin:auto;max-width:50em}</style>\n"
"<title>Welcome to %host%</title>\n</head>\n"
- "<body style=\"margin: auto; max-width: 50em\">\n"
+ "<body>\n"
"%blurb%"
"<p>The following users are part of this community:</p>\n"
"\n"
@@ -912,3 +913,60 @@ void import_csv(snac *user)
else
snac_log(user, xs_fmt("Cannot open file %s", fn));
}
+
+static const struct {
+ const char *proto;
+ unsigned short default_port;
+} FALLBACK_PORTS[] = {
+ /* caution: https > http, smpts > smtp */
+ {"https", 443},
+ {"http", 80},
+ {"smtps", 465},
+ {"smtp", 25}
+};
+
+int parse_port(const char *url, const char **errstr)
+{
+ const char *col, *rcol;
+ int tmp, ret = -1;
+
+ if (errstr)
+ *errstr = NULL;
+
+ if (!(col = strchr(url, ':'))) {
+ if (errstr)
+ *errstr = "bad url";
+
+ return -1;
+ }
+
+ for (size_t i = 0; i < sizeof(FALLBACK_PORTS) / sizeof(*FALLBACK_PORTS); ++i) {
+ if (memcmp(url, FALLBACK_PORTS[i].proto, strlen(FALLBACK_PORTS[i].proto)) == 0) {
+ ret = FALLBACK_PORTS[i].default_port;
+ break;
+ }
+ }
+
+ if (!(rcol = strchr(col + 1, ':')))
+ rcol = col;
+
+ if (rcol) {
+ tmp = atoi(rcol + 1);
+ if (tmp == 0) {
+ if (ret != -1)
+ return ret;
+
+ if (errstr)
+ *errstr = strerror(errno);
+
+ return -1;
+ }
+
+ return tmp;
+ }
+
+ if (errstr)
+ *errstr = "unknown protocol";
+
+ return -1;
+}