diff options
Diffstat (limited to 'utils.c')
| -rw-r--r-- | utils.c | 60 |
1 files changed, 59 insertions, 1 deletions
| @@ -101,8 +101,9 @@ static const char *greeting_html = | |||
| 101 | "<html><head>\n" | 101 | "<html><head>\n" |
| 102 | "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n" | 102 | "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n" |
| 103 | "<link rel=\"icon\" type=\"image/x-icon\" href=\"https://%host%/favicon.ico\"/>\n" | 103 | "<link rel=\"icon\" type=\"image/x-icon\" href=\"https://%host%/favicon.ico\"/>\n" |
| 104 | "<style>*{color-scheme:light dark}body{margin:auto;max-width:50em}</style>\n" | ||
| 104 | "<title>Welcome to %host%</title>\n</head>\n" | 105 | "<title>Welcome to %host%</title>\n</head>\n" |
| 105 | "<body style=\"margin: auto; max-width: 50em\">\n" | 106 | "<body>\n" |
| 106 | "%blurb%" | 107 | "%blurb%" |
| 107 | "<p>The following users are part of this community:</p>\n" | 108 | "<p>The following users are part of this community:</p>\n" |
| 108 | "\n" | 109 | "\n" |
| @@ -912,3 +913,60 @@ void import_csv(snac *user) | |||
| 912 | else | 913 | else |
| 913 | snac_log(user, xs_fmt("Cannot open file %s", fn)); | 914 | snac_log(user, xs_fmt("Cannot open file %s", fn)); |
| 914 | } | 915 | } |
| 916 | |||
| 917 | static const struct { | ||
| 918 | const char *proto; | ||
| 919 | unsigned short default_port; | ||
| 920 | } FALLBACK_PORTS[] = { | ||
| 921 | /* caution: https > http, smpts > smtp */ | ||
| 922 | {"https", 443}, | ||
| 923 | {"http", 80}, | ||
| 924 | {"smtps", 465}, | ||
| 925 | {"smtp", 25} | ||
| 926 | }; | ||
| 927 | |||
| 928 | int parse_port(const char *url, const char **errstr) | ||
| 929 | { | ||
| 930 | const char *col, *rcol; | ||
| 931 | int tmp, ret = -1; | ||
| 932 | |||
| 933 | if (errstr) | ||
| 934 | *errstr = NULL; | ||
| 935 | |||
| 936 | if (!(col = strchr(url, ':'))) { | ||
| 937 | if (errstr) | ||
| 938 | *errstr = "bad url"; | ||
| 939 | |||
| 940 | return -1; | ||
| 941 | } | ||
| 942 | |||
| 943 | for (size_t i = 0; i < sizeof(FALLBACK_PORTS) / sizeof(*FALLBACK_PORTS); ++i) { | ||
| 944 | if (memcmp(url, FALLBACK_PORTS[i].proto, strlen(FALLBACK_PORTS[i].proto)) == 0) { | ||
| 945 | ret = FALLBACK_PORTS[i].default_port; | ||
| 946 | break; | ||
| 947 | } | ||
| 948 | } | ||
| 949 | |||
| 950 | if (!(rcol = strchr(col + 1, ':'))) | ||
| 951 | rcol = col; | ||
| 952 | |||
| 953 | if (rcol) { | ||
| 954 | tmp = atoi(rcol + 1); | ||
| 955 | if (tmp == 0) { | ||
| 956 | if (ret != -1) | ||
| 957 | return ret; | ||
| 958 | |||
| 959 | if (errstr) | ||
| 960 | *errstr = strerror(errno); | ||
| 961 | |||
| 962 | return -1; | ||
| 963 | } | ||
| 964 | |||
| 965 | return tmp; | ||
| 966 | } | ||
| 967 | |||
| 968 | if (errstr) | ||
| 969 | *errstr = "unknown protocol"; | ||
| 970 | |||
| 971 | return -1; | ||
| 972 | } | ||