summaryrefslogtreecommitdiff
path: root/toxav/rtp.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-08-31 20:40:20 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-02 11:02:56 +0100
commita9fbdaf46b23db5c598bf33d6bc5c4555b06e674 (patch)
treee7894501bd010d9904fe0069fc1b8121d2da4040 /toxav/rtp.c
parent6f42eadc54e81be50b7a817c72b0cf4d7ec5feb4 (diff)
Do not use `else` after `return`.
http://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r--toxav/rtp.c164
1 files changed, 82 insertions, 82 deletions
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,
268 */ 268 */
269 if (chloss(session, header)) { 269 if (chloss(session, header)) {
270 return 0; 270 return 0;
271 } else {
272 /* Message is not late; pick up the latest parameters */
273 session->rsequnum = ntohs(header->sequnum);
274 session->rtimestamp = ntohl(header->timestamp);
275 } 271 }
276 272
273 /* Message is not late; pick up the latest parameters */
274 session->rsequnum = ntohs(header->sequnum);
275 session->rtimestamp = ntohl(header->timestamp);
276
277 bwc_add_recv(session->bwc, length); 277 bwc_add_recv(session->bwc, length);
278 278
279 /* Invoke processing of active multiparted message */ 279 /* Invoke processing of active multiparted message */
@@ -296,69 +296,43 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data,
296 } 296 }
297 297
298 return session->mcb (session->cs, new_message(length, data, length)); 298 return session->mcb (session->cs, new_message(length, data, length));
299 } else { 299 }
300 /* The message is sent in multiple parts */
301
302 if (session->mp) {
303 /* There are 2 possible situations in this case:
304 * 1) being that we got the part of already processing message.
305 * 2) being that we got the part of a new/old message.
306 *
307 * We handle them differently as we only allow a single multiparted
308 * processing message
309 */
310
311 if (session->mp->header.sequnum == ntohs(header->sequnum) &&
312 session->mp->header.timestamp == ntohl(header->timestamp)) {
313 /* First case */
314
315 /* Make sure we have enough allocated memory */
316 if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) ||
317 session->mp->header.tlen <= ntohs(header->cpart)) {
318 /* There happened to be some corruption on the stream;
319 * continue wihtout this part
320 */
321 return 0;
322 }
323
324 memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader),
325 length - sizeof(struct RTPHeader));
326 300
327 session->mp->len += length - sizeof(struct RTPHeader); 301 /* The message is sent in multiple parts */
328 302
329 bwc_add_recv(session->bwc, length); 303 if (session->mp) {
304 /* There are 2 possible situations in this case:
305 * 1) being that we got the part of already processing message.
306 * 2) being that we got the part of a new/old message.
307 *
308 * We handle them differently as we only allow a single multiparted
309 * processing message
310 */
330 311
331 if (session->mp->len == session->mp->header.tlen) { 312 if (session->mp->header.sequnum == ntohs(header->sequnum) &&
332 /* Received a full message; now push it for the further 313 session->mp->header.timestamp == ntohl(header->timestamp)) {
333 * processing. 314 /* First case */
334 */
335 if (session->mcb) {
336 session->mcb (session->cs, session->mp);
337 } else {
338 free(session->mp);
339 }
340 315
341 session->mp = NULL; 316 /* Make sure we have enough allocated memory */
342 } 317 if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) ||
343 } else { 318 session->mp->header.tlen <= ntohs(header->cpart)) {
344 /* Second case */ 319 /* There happened to be some corruption on the stream;
320 * continue wihtout this part
321 */
322 return 0;
323 }
345 324
346 if (session->mp->header.timestamp > ntohl(header->timestamp)) { 325 memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader),
347 /* The received message part is from the old message; 326 length - sizeof(struct RTPHeader));
348 * discard it.
349 */
350 return 0;
351 }
352 327
353 /* Measure missing parts of the old message */ 328 session->mp->len += length - sizeof(struct RTPHeader);
354 bwc_add_lost(session->bwc,
355 (session->mp->header.tlen - session->mp->len) +
356 329
357 /* Must account sizes of rtp headers too */ 330 bwc_add_recv(session->bwc, length);
358 ((session->mp->header.tlen - session->mp->len) /
359 MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) );
360 331
361 /* Push the previous message for processing */ 332 if (session->mp->len == session->mp->header.tlen) {
333 /* Received a full message; now push it for the further
334 * processing.
335 */
362 if (session->mcb) { 336 if (session->mcb) {
363 session->mcb (session->cs, session->mp); 337 session->mcb (session->cs, session->mp);
364 } else { 338 } else {
@@ -366,40 +340,66 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data,
366 } 340 }
367 341
368 session->mp = NULL; 342 session->mp = NULL;
369 goto NEW_MULTIPARTED;
370 } 343 }
371 } else { 344 } else {
372 /* In this case threat the message as if it was received in order 345 /* Second case */
373 */
374
375 /* This is also a point for new multiparted messages */
376NEW_MULTIPARTED:
377 346
378 /* Only allow messages which have arrived in order; 347 if (session->mp->header.timestamp > ntohl(header->timestamp)) {
379 * drop late messages 348 /* The received message part is from the old message;
380 */ 349 * discard it.
381 if (chloss(session, header)) { 350 */
382 return 0; 351 return 0;
383 } else {
384 /* Message is not late; pick up the latest parameters */
385 session->rsequnum = ntohs(header->sequnum);
386 session->rtimestamp = ntohl(header->timestamp);
387 } 352 }
388 353
389 bwc_add_recv(session->bwc, length); 354 /* Measure missing parts of the old message */
355 bwc_add_lost(session->bwc,
356 (session->mp->header.tlen - session->mp->len) +
357
358 /* Must account sizes of rtp headers too */
359 ((session->mp->header.tlen - session->mp->len) /
360 MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) );
390 361
391 /* Again, only store message if handler is present 362 /* Push the previous message for processing */
392 */
393 if (session->mcb) { 363 if (session->mcb) {
394 session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); 364 session->mcb (session->cs, session->mp);
365 } else {
366 free(session->mp);
367 }
395 368
396 /* Reposition data if necessary */ 369 session->mp = NULL;
397 if (ntohs(header->cpart)) { 370 goto NEW_MULTIPARTED;
398 ; 371 }
399 } 372 } else {
373 /* In this case threat the message as if it was received in order
374 */
375
376 /* This is also a point for new multiparted messages */
377NEW_MULTIPARTED:
378
379 /* Only allow messages which have arrived in order;
380 * drop late messages
381 */
382 if (chloss(session, header)) {
383 return 0;
384 }
385
386 /* Message is not late; pick up the latest parameters */
387 session->rsequnum = ntohs(header->sequnum);
388 session->rtimestamp = ntohl(header->timestamp);
400 389
401 memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len); 390 bwc_add_recv(session->bwc, length);
391
392 /* Again, only store message if handler is present
393 */
394 if (session->mcb) {
395 session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length);
396
397 /* Reposition data if necessary */
398 if (ntohs(header->cpart)) {
399 ;
402 } 400 }
401
402 memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len);
403 } 403 }
404 } 404 }
405 405