Remove some gotos
This commit is contained in:
@ -191,7 +191,8 @@ int http_parse_request(char *buf, http_req *req) {
|
||||
|
||||
if (req->version[0] == 0) {
|
||||
pos1 = (char *) strchr(ptr, ' ') + 1;
|
||||
if (pos1 == NULL) goto err_hdr_fmt;
|
||||
if (pos1 == NULL)
|
||||
return http_error(HTTP_ERROR_HEADER_MALFORMED);
|
||||
|
||||
if (pos1 - ptr - 1 >= sizeof(req->method))
|
||||
return http_error(HTTP_ERROR_HEADER_MALFORMED);
|
||||
@ -203,10 +204,8 @@ int http_parse_request(char *buf, http_req *req) {
|
||||
snprintf(req->method, sizeof(req->method), "%.*s", (int) (pos1 - ptr - 1), ptr);
|
||||
|
||||
pos2 = (char *) strchr(pos1, ' ') + 1;
|
||||
if (pos2 == NULL) {
|
||||
err_hdr_fmt:
|
||||
if (pos2 == NULL)
|
||||
return http_error(HTTP_ERROR_HEADER_MALFORMED);
|
||||
}
|
||||
|
||||
if (memcmp(pos2, "HTTP/", 5) != 0 || memcmp(pos2 + 8, "\r\n", 2) != 0)
|
||||
return http_error(HTTP_ERROR_INVALID_VERSION);
|
||||
|
@ -52,22 +52,20 @@ int mpmc_init(mpmc_t *ctx, int n_workers, int buf_size, void (*consumer)(void *o
|
||||
|
||||
int mpmc_queue(mpmc_t *ctx, void *obj) {
|
||||
// wait for buffer to be emptied
|
||||
try_again_1:
|
||||
if (sem_wait(&ctx->free) != 0) {
|
||||
while (sem_wait(&ctx->free) != 0) {
|
||||
if (errno == EINTR) {
|
||||
errno = 0;
|
||||
goto try_again_1;
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// lock wr field
|
||||
try_again_2:
|
||||
if (sem_wait(&ctx->lck_wr) != 0) {
|
||||
while (sem_wait(&ctx->lck_wr) != 0) {
|
||||
if (errno == EINTR) {
|
||||
errno = 0;
|
||||
goto try_again_2;
|
||||
continue;
|
||||
} else {
|
||||
sem_post(&ctx->free);
|
||||
return -1;
|
||||
|
@ -105,19 +105,19 @@ proxy_ctx_t *proxy_get_by_conf(host_config_t *conf) {
|
||||
n++;
|
||||
}
|
||||
|
||||
try_again_1:
|
||||
if (sem_wait(&available[n]) != 0) {
|
||||
while (sem_wait(&available[n]) != 0) {
|
||||
if (errno == EINTR) {
|
||||
goto try_again_1;
|
||||
errno = 0;
|
||||
continue;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
try_again_2:
|
||||
if (sem_wait(&lock) != 0) {
|
||||
while (sem_wait(&lock) != 0) {
|
||||
if (errno == EINTR) {
|
||||
goto try_again_2;
|
||||
errno = 0;
|
||||
continue;
|
||||
} else {
|
||||
sem_post(&available[n]);
|
||||
return NULL;
|
||||
@ -269,24 +269,28 @@ int proxy_response_header(http_req *req, http_res *res, host_config_t *conf) {
|
||||
const char *location = http_get_header_field(&res->hdr, "Location");
|
||||
if (location != NULL) {
|
||||
char *hostnames[] = {conf->name, conf->proxy.hostname};
|
||||
int found = 0;
|
||||
|
||||
for (int i = 0; i < sizeof(hostnames) / sizeof(hostnames[0]); i++) {
|
||||
char *hostname = hostnames[i];
|
||||
found = 1;
|
||||
|
||||
p_len = snprintf(buf1, sizeof(buf1), "http://%s/", hostname);
|
||||
if (strncmp(location, buf1, p_len) == 0) goto match;
|
||||
if (strstarts(location, buf1)) break;
|
||||
|
||||
p_len = snprintf(buf1, sizeof(buf1), "https://%s/", hostname);
|
||||
if (strncmp(location, buf1, p_len) == 0) goto match;
|
||||
if (strstarts(location, buf1)) break;
|
||||
|
||||
p_len = snprintf(buf1, sizeof(buf1), "http://%s:%i/", hostname, conf->proxy.port);
|
||||
if (strncmp(location, buf1, p_len) == 0) goto match;
|
||||
if (strstarts(location, buf1)) break;
|
||||
|
||||
p_len = snprintf(buf1, sizeof(buf1), "https://%s:%i/", hostname, conf->proxy.port);
|
||||
if (strncmp(location, buf1, p_len) == 0) goto match;
|
||||
if (strstarts(location, buf1)) break;
|
||||
|
||||
found = 0;
|
||||
}
|
||||
|
||||
if (0) {
|
||||
match:
|
||||
if (found) {
|
||||
strcpy(buf1, location + p_len - 1);
|
||||
http_remove_header_field(&res->hdr, "Location", HTTP_REMOVE_ALL);
|
||||
http_add_header_field(&res->hdr, "Location", buf1);
|
||||
|
Reference in New Issue
Block a user