diff options
| -rw-r--r-- | utils.c | 68 |
1 files changed, 34 insertions, 34 deletions
| @@ -914,58 +914,58 @@ void import_csv(snac *user) | |||
| 914 | } | 914 | } |
| 915 | 915 | ||
| 916 | static const struct { | 916 | static const struct { |
| 917 | const char *proto; | 917 | const char *proto; |
| 918 | unsigned short default_port; | 918 | unsigned short default_port; |
| 919 | } FALLBACK_PORTS[] = { | 919 | } FALLBACK_PORTS[] = { |
| 920 | /* caution: https > http, smpts > smtp */ | 920 | /* caution: https > http, smpts > smtp */ |
| 921 | {"https", 443}, | 921 | {"https", 443}, |
| 922 | {"http", 80}, | 922 | {"http", 80}, |
| 923 | {"smtps", 465}, | 923 | {"smtps", 465}, |
| 924 | {"smtp", 25} | 924 | {"smtp", 25} |
| 925 | }; | 925 | }; |
| 926 | 926 | ||
| 927 | int parse_port(const char *url, const char **errstr) | 927 | int parse_port(const char *url, const char **errstr) |
| 928 | { | 928 | { |
| 929 | const char *col, *rcol; | 929 | const char *col, *rcol; |
| 930 | int tmp, ret = -1; | 930 | int tmp, ret = -1; |
| 931 | 931 | ||
| 932 | if (errstr) | 932 | if (errstr) |
| 933 | *errstr = NULL; | 933 | *errstr = NULL; |
| 934 | 934 | ||
| 935 | if (!(col = strchr(url, ':'))) { | 935 | if (!(col = strchr(url, ':'))) { |
| 936 | if (errstr) | 936 | if (errstr) |
| 937 | *errstr = "bad url"; | 937 | *errstr = "bad url"; |
| 938 | 938 | ||
| 939 | return -1; | 939 | return -1; |
| 940 | } | 940 | } |
| 941 | 941 | ||
| 942 | for (size_t i = 0; i < sizeof(FALLBACK_PORTS) / sizeof(*FALLBACK_PORTS); ++i) { | 942 | for (size_t i = 0; i < sizeof(FALLBACK_PORTS) / sizeof(*FALLBACK_PORTS); ++i) { |
| 943 | if (memcmp(url, FALLBACK_PORTS[i].proto, strlen(FALLBACK_PORTS[i].proto)) == 0) { | 943 | if (memcmp(url, FALLBACK_PORTS[i].proto, strlen(FALLBACK_PORTS[i].proto)) == 0) { |
| 944 | ret = FALLBACK_PORTS[i].default_port; | 944 | ret = FALLBACK_PORTS[i].default_port; |
| 945 | break; | 945 | break; |
| 946 | } | 946 | } |
| 947 | } | 947 | } |
| 948 | 948 | ||
| 949 | if (!(rcol = strchr(col + 1, ':'))) | 949 | if (!(rcol = strchr(col + 1, ':'))) |
| 950 | rcol = col; | 950 | rcol = col; |
| 951 | 951 | ||
| 952 | if (rcol) { | 952 | if (rcol) { |
| 953 | tmp = atoi(rcol + 1); | 953 | tmp = atoi(rcol + 1); |
| 954 | if (tmp == 0) { | 954 | if (tmp == 0) { |
| 955 | if (ret != -1) | 955 | if (ret != -1) |
| 956 | return ret; | 956 | return ret; |
| 957 | 957 | ||
| 958 | if (errstr) | 958 | if (errstr) |
| 959 | *errstr = strerror(errno); | 959 | *errstr = strerror(errno); |
| 960 | 960 | ||
| 961 | return -1; | 961 | return -1; |
| 962 | } | 962 | } |
| 963 | 963 | ||
| 964 | return tmp; | 964 | return tmp; |
| 965 | } | 965 | } |
| 966 | 966 | ||
| 967 | if (errstr) | 967 | if (errstr) |
| 968 | *errstr = "unknown protocol"; | 968 | *errstr = "unknown protocol"; |
| 969 | 969 | ||
| 970 | return -1; | 970 | return -1; |
| 971 | } | 971 | } |