From a9fbdaf46b23db5c598bf33d6bc5c4555b06e674 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 31 Aug 2016 20:40:20 +0100 Subject: Do not use `else` after `return`. http://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code --- toxav/rtp.c | 164 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 82 insertions(+), 82 deletions(-) (limited to 'toxav/rtp.c') diff --git a/toxav/rtp.c b/toxav/rtp.c index 1556d23d..38e64dd7 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -268,12 +268,12 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, */ if (chloss(session, header)) { return 0; - } else { - /* Message is not late; pick up the latest parameters */ - session->rsequnum = ntohs(header->sequnum); - session->rtimestamp = ntohl(header->timestamp); } + /* Message is not late; pick up the latest parameters */ + session->rsequnum = ntohs(header->sequnum); + session->rtimestamp = ntohl(header->timestamp); + bwc_add_recv(session->bwc, length); /* Invoke processing of active multiparted message */ @@ -296,69 +296,43 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, } return session->mcb (session->cs, new_message(length, data, length)); - } else { - /* The message is sent in multiple parts */ - - if (session->mp) { - /* There are 2 possible situations in this case: - * 1) being that we got the part of already processing message. - * 2) being that we got the part of a new/old message. - * - * We handle them differently as we only allow a single multiparted - * processing message - */ - - if (session->mp->header.sequnum == ntohs(header->sequnum) && - session->mp->header.timestamp == ntohl(header->timestamp)) { - /* First case */ - - /* Make sure we have enough allocated memory */ - if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) || - session->mp->header.tlen <= ntohs(header->cpart)) { - /* There happened to be some corruption on the stream; - * continue wihtout this part - */ - return 0; - } - - memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader), - length - sizeof(struct RTPHeader)); + } - session->mp->len += length - sizeof(struct RTPHeader); + /* The message is sent in multiple parts */ - bwc_add_recv(session->bwc, length); + if (session->mp) { + /* There are 2 possible situations in this case: + * 1) being that we got the part of already processing message. + * 2) being that we got the part of a new/old message. + * + * We handle them differently as we only allow a single multiparted + * processing message + */ - if (session->mp->len == session->mp->header.tlen) { - /* Received a full message; now push it for the further - * processing. - */ - if (session->mcb) { - session->mcb (session->cs, session->mp); - } else { - free(session->mp); - } + if (session->mp->header.sequnum == ntohs(header->sequnum) && + session->mp->header.timestamp == ntohl(header->timestamp)) { + /* First case */ - session->mp = NULL; - } - } else { - /* Second case */ + /* Make sure we have enough allocated memory */ + if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) || + session->mp->header.tlen <= ntohs(header->cpart)) { + /* There happened to be some corruption on the stream; + * continue wihtout this part + */ + return 0; + } - if (session->mp->header.timestamp > ntohl(header->timestamp)) { - /* The received message part is from the old message; - * discard it. - */ - return 0; - } + memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader), + length - sizeof(struct RTPHeader)); - /* Measure missing parts of the old message */ - bwc_add_lost(session->bwc, - (session->mp->header.tlen - session->mp->len) + + session->mp->len += length - sizeof(struct RTPHeader); - /* Must account sizes of rtp headers too */ - ((session->mp->header.tlen - session->mp->len) / - MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) ); + bwc_add_recv(session->bwc, length); - /* Push the previous message for processing */ + if (session->mp->len == session->mp->header.tlen) { + /* Received a full message; now push it for the further + * processing. + */ if (session->mcb) { session->mcb (session->cs, session->mp); } else { @@ -366,40 +340,66 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, } session->mp = NULL; - goto NEW_MULTIPARTED; } } else { - /* In this case threat the message as if it was received in order - */ - - /* This is also a point for new multiparted messages */ -NEW_MULTIPARTED: + /* Second case */ - /* Only allow messages which have arrived in order; - * drop late messages - */ - if (chloss(session, header)) { + if (session->mp->header.timestamp > ntohl(header->timestamp)) { + /* The received message part is from the old message; + * discard it. + */ return 0; - } else { - /* Message is not late; pick up the latest parameters */ - session->rsequnum = ntohs(header->sequnum); - session->rtimestamp = ntohl(header->timestamp); } - bwc_add_recv(session->bwc, length); + /* Measure missing parts of the old message */ + bwc_add_lost(session->bwc, + (session->mp->header.tlen - session->mp->len) + + + /* Must account sizes of rtp headers too */ + ((session->mp->header.tlen - session->mp->len) / + MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) ); - /* Again, only store message if handler is present - */ + /* Push the previous message for processing */ if (session->mcb) { - session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); + session->mcb (session->cs, session->mp); + } else { + free(session->mp); + } - /* Reposition data if necessary */ - if (ntohs(header->cpart)) { - ; - } + session->mp = NULL; + goto NEW_MULTIPARTED; + } + } else { + /* In this case threat the message as if it was received in order + */ + + /* This is also a point for new multiparted messages */ +NEW_MULTIPARTED: + + /* Only allow messages which have arrived in order; + * drop late messages + */ + if (chloss(session, header)) { + return 0; + } + + /* Message is not late; pick up the latest parameters */ + session->rsequnum = ntohs(header->sequnum); + session->rtimestamp = ntohl(header->timestamp); - memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len); + bwc_add_recv(session->bwc, length); + + /* Again, only store message if handler is present + */ + if (session->mcb) { + session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); + + /* Reposition data if necessary */ + if (ntohs(header->cpart)) { + ; } + + memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len); } } -- cgit v1.2.3