summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Fedoryshchenko <denys.f@collabora.com>2025-12-01 02:46:20 +0200
committerDenys Fedoryshchenko <denys.f@collabora.com>2025-12-01 02:46:20 +0200
commitc5493be157f71e83ed725dc7f768d90321589c8e (patch)
treea6f0389065179f790a06dd4f8d67d55d3ecc29d9
parent63165ee7fd9abec04fb5f497d11ab09e21e10b9b (diff)
downloadaccel-ppp-c5493be157f71e83ed725dc7f768d90321589c8e.tar.gz
accel-ppp-c5493be157f71e83ed725dc7f768d90321589c8e.zip
sstp: Add config option enum for better code readability
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
-rw-r--r--accel-pppd/ctrl/sstp/sstp.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c
index 9239da30..3c831f64 100644
--- a/accel-pppd/ctrl/sstp/sstp.c
+++ b/accel-pppd/ctrl/sstp/sstp.c
@@ -181,7 +181,13 @@ static struct hash_t conf_hash_sha1 = { .len = 0 };
static struct hash_t conf_hash_sha256 = { .len = 0 };
//static int conf_bypass_auth = 0;
static const char *conf_hostname = NULL;
-static int conf_http_mode = -1;
+enum {
+ HTTP_ERR_ALLOW = -1,
+ HTTP_ERR_DENY = 0,
+ HTTP_ERR_REDIRECT = 1,
+ HTTP_ERR_REDIRECT_APPEND = 2,
+};
+static int conf_http_mode = HTTP_ERR_ALLOW;
static const char *conf_http_url = NULL;
static mempool_t conn_pool;
@@ -885,17 +891,17 @@ static int http_recv_request(struct sstp_conn_t *conn, uint8_t *data, int len)
log_ppp_info2("recv [HTTP <%s>]\n", line);
if (vstrsep(line, " ", &method, &request, &proto) < 3) {
- if (conf_http_mode)
+ if (conf_http_mode != HTTP_ERR_DENY)
http_send_response(conn, "HTTP/1.1", "400 Bad Request", NULL);
return -1;
}
if (strncasecmp(proto, "HTTP/1", sizeof("HTTP/1") - 1) != 0) {
- if (conf_http_mode)
+ if (conf_http_mode != HTTP_ERR_DENY)
http_send_response(conn, "HTTP/1.1", "400 Bad Request", NULL);
return -1;
}
if (strcasecmp(method, SSTP_HTTP_METHOD) != 0 && strcasecmp(method, "GET") != 0) {
- if (conf_http_mode)
+ if (conf_http_mode != HTTP_ERR_DENY)
http_send_response(conn, proto, "501 Not Implemented", NULL);
return -1;
}
@@ -917,7 +923,7 @@ static int http_recv_request(struct sstp_conn_t *conn, uint8_t *data, int len)
}
if (host_error) {
- if (conf_http_mode)
+ if (conf_http_mode != HTTP_ERR_DENY)
http_send_response(conn, proto, "404 Not Found", NULL);
return -1;
}
@@ -925,11 +931,11 @@ static int http_recv_request(struct sstp_conn_t *conn, uint8_t *data, int len)
if (strcasecmp(method, SSTP_HTTP_METHOD) != 0 || strcasecmp(request, SSTP_HTTP_URI) != 0) {
if (conf_http_mode > 0) {
if (_asprintf(&line, "Location: %s%s\r\n",
- conf_http_url, (conf_http_mode == 2) ? request : "") < 0)
+ conf_http_url, (conf_http_mode == HTTP_ERR_REDIRECT_APPEND) ? request : "") < 0)
return -1;
http_send_response(conn, proto, "301 Moved Permanently", line);
_free(line);
- } else if (conf_http_mode < 0)
+ } else if (conf_http_mode == HTTP_ERR_ALLOW)
http_send_response(conn, proto, "404 Not Found", NULL);
return -1;
}
@@ -2809,15 +2815,15 @@ static void load_config(void)
opt = conf_get_opt("sstp", "http-error");
if (opt) {
if (strcmp(opt, "deny") == 0)
- conf_http_mode = 0;
+ conf_http_mode = HTTP_ERR_DENY;
else if (strcmp(opt, "allow") == 0)
- conf_http_mode = -1;
+ conf_http_mode = HTTP_ERR_ALLOW;
else if (strstr(opt, "://") != NULL) {
conf_http_url = opt;
opt = strstr(opt, "://") + 3;
while (*opt == '/')
opt++;
- conf_http_mode = strchr(opt, '/') ? 1 : 2;
+ conf_http_mode = strchr(opt, '/') ? HTTP_ERR_REDIRECT : HTTP_ERR_REDIRECT_APPEND;
}
}