From 0c3da2df869877f618dc1dfe335bee5ae92b8e74 Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Sun, 19 Apr 2020 03:43:27 +0200 Subject: [PATCH] Cleanup: Simplify client_complete Instead of using a "have" variable which makes it a bit confusing to understand whats going on, use a do {} while (0) and break from it instead. --- src/client.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/client.c b/src/client.c index 617e7312..65e0d43c 100644 --- a/src/client.c +++ b/src/client.c @@ -124,50 +124,41 @@ void client_complete(client_t *client) { const char *header; long long unsigned int scannumber; - int have = 0; - if (!have) { + do { header = httpp_getvar(client->parser, "content-length"); if (header) { if (sscanf(header, "%llu", &scannumber) == 1) { client->request_body_length = scannumber; - have = 1; + break; } } - } - if (!have) { if (client->parser->req_type == httpp_req_source) { client->request_body_length = -1; /* streaming */ - have = 1; + break; } - } - if (!have) { header = httpp_getvar(client->parser, "transfer-encoding"); if (header) { if (strcasecmp(header, "identity") != 0) { client->request_body_length = -1; /* streaming */ - have = 1; + break; } } - } - if (!have) { if (client->parser->req_type == httpp_req_put) { /* As we don't know yet, we asume this PUT is in streaming mode */ client->request_body_length = -1; /* streaming */ - have = 1; + break; } - } - if (!have) { if (client->parser->req_type == httpp_req_none) { /* We are a client. If the server did not tell us, we asume streaming. */ client->request_body_length = -1; /* streaming */ - have = 1; + break; } - } + } while (0); ICECAST_LOG_DEBUG("Client %p has request_body_length=%zi", client, client->request_body_length); }