aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/widget-encodings.c
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-09-15 10:39:11 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-09-15 10:39:11 -0800
commit407d90105f2c8c702e7f39bcb583899afe437a6b (patch)
treef317c9ae4fed4dfc83909089a3e0f4c1ac99c366 /src/widget-encodings.c
parent3b98763bd4531c71127b1debfe707882152623f4 (diff)
downloadbindletools-407d90105f2c8c702e7f39bcb583899afe437a6b.tar.gz
bindletools-407d90105f2c8c702e7f39bcb583899afe437a6b.tar.bz2
bindletools-407d90105f2c8c702e7f39bcb583899afe437a6b.tar.xz
bindletools-407d90105f2c8c702e7f39bcb583899afe437a6b.zip
bindletools: refactoring bindle_encodings_action_decode()
Diffstat (limited to 'src/widget-encodings.c')
-rw-r--r--src/widget-encodings.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/widget-encodings.c b/src/widget-encodings.c
index 70de289..b529101 100644
--- a/src/widget-encodings.c
+++ b/src/widget-encodings.c
@@ -424,12 +424,10 @@ bindle_encodings_action_decode(
424 bindle_state_t * state; 424 bindle_state_t * state;
425 size_t pos; 425 size_t pos;
426 size_t off; 426 size_t off;
427 size_t chunk_size; 427 size_t buff_len;
428 int fullbuff;
429 428
430 state = cnf->state; 429 state = cnf->state;
431 430 buff_len = state->buff_len;
432 fullbuff = (state->buff_size == state->buff_len) ? BNDL_YES : BNDL_NO;
433 431
434 // strip newlines 432 // strip newlines
435 for(pos = 0, off = 0; (pos < state->buff_len); pos++) 433 for(pos = 0, off = 0; (pos < state->buff_len); pos++)
@@ -443,17 +441,11 @@ bindle_encodings_action_decode(
443 state->buff[pos-off] = state->buff[pos]; 441 state->buff[pos-off] = state->buff[pos];
444 }; 442 };
445 state->buff_len -= off; 443 state->buff_len -= off;
446 state->buff[state->buff_len] = '\0'; 444 if (buff_len != state->buff_len)
445 return(0);
447 446
448 // decode data 447 // decode data
449 chunk_size = state->buff_len; 448 if ((len = bindle_decode(method, state->res, state->res_size, state->buff, buff_len)) == -1)
450 if (fullbuff == BNDL_YES)
451 {
452 chunk_size = (state->buff_len / state->chunk_size) * state->chunk_size;
453 if ( (chunk_size > state->buff_len) || (chunk_size < state->chunk_size) )
454 return(0);
455 };
456 if ((len = bindle_decode(method, state->res, state->res_size, state->buff, chunk_size)) == -1)
457 { 449 {
458 fprintf(stderr, "%s: bindle_decode(): %s\n", cnf->prog_name, strerror(errno)); 450 fprintf(stderr, "%s: bindle_decode(): %s\n", cnf->prog_name, strerror(errno));
459 return(-1); 451 return(-1);
@@ -461,11 +453,7 @@ bindle_encodings_action_decode(
461 if (len == 0) 453 if (len == 0)
462 return(0); 454 return(0);
463 write(state->fdout, state->res, (size_t)len); 455 write(state->fdout, state->res, (size_t)len);
464 456 state->buff_len = 0;
465 // shift unencoded data
466 for(pos = chunk_size; (pos < state->buff_len); pos++)
467 state->buff[pos-chunk_size] = state->buff[pos];
468 state->buff_len -= chunk_size;
469 457
470 return(0); 458 return(0);
471} 459}