diff options
Diffstat (limited to 'networking/httppost.c')
-rw-r--r-- | networking/httppost.c | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/networking/httppost.c b/networking/httppost.c index 6b8b533..24f1430 100644 --- a/networking/httppost.c +++ b/networking/httppost.c @@ -50,6 +50,7 @@ char *do_dir(char *dir_name, off_t curr_size, off_t max_size, off_t *lenp); static int copy_chunked(FILE *in_file, FILE *out_file, int *found_okp); static int copy_bytes(FILE *in_file, FILE *out_file, size_t len, int *found_okp); +static int copy_all(FILE *in_file, FILE *out_file, int *found_okp); static void fatal(const char *fmt, ...); // static void fatal_err(const char *fmt, ...); static void report(const char *fmt, ...); @@ -398,6 +399,7 @@ int httppost_main(int argc, char *argv[]) goto err; fprintf(stderr, "httppost: getting reply headers \n"); server_time= 0; + content_length= -1; if (!eat_headers(tcp_file, &chunked, &content_length, &server_time)) goto err; @@ -464,16 +466,24 @@ int httppost_main(int argc, char *argv[]) else out_file= stdout; + fprintf(stderr, "httppost: chunked %d, content_length %d\n", + chunked, content_length); + found_ok= 0; if (chunked) { if (!copy_chunked(tcp_file, out_file, &found_ok)) goto err; } - else if (content_length) + else if (content_length >= 0) { if (!copy_bytes(tcp_file, out_file, content_length, &found_ok)) goto err; } + else + { + if (!copy_all(tcp_file, out_file, &found_ok)) + goto err; + } if (!found_ok) fprintf(stderr, "httppost: reply text was not equal to OK\n"); if ( opt_delete_file == 1 && found_ok) @@ -764,7 +774,6 @@ static int eat_headers(FILE *tcp_file, int *chunked, int *content_length, time_t char buffer[1024]; *chunked= 0; - *content_length= 0; while (fgets(buffer, sizeof(buffer), tcp_file) != NULL) { line= buffer; @@ -1086,6 +1095,8 @@ static int copy_chunked(FILE *in_file, FILE *out_file, int *found_okp) } offset += size; + fprintf(stderr, "httppost: chunk data '%.*s'\n", + (int)size, buffer); for (i= 0; i<size; i++) { if (!okp) @@ -1179,6 +1190,9 @@ static int copy_bytes(FILE *in_file, FILE *out_file, size_t len, int *found_okp) } offset += size; + fprintf(stderr, "httppost: normal data '%.*s'\n", + (int)size, buffer); + for (i= 0; i<size; i++) { if (!okp) @@ -1195,6 +1209,49 @@ static int copy_bytes(FILE *in_file, FILE *out_file, size_t len, int *found_okp) return 1; } +static int copy_all(FILE *in_file, FILE *out_file, int *found_okp) +{ + int i, size; + const char *okp; + char buffer[1024]; + + okp= OK_STR; + + while (!feof(in_file) && !ferror(in_file)) + { + size= fread(buffer, 1, sizeof(buffer), in_file); + if (size <= 0) + break; + if (fwrite(buffer, size, 1, out_file) != 1) + { + report_err("error writing output"); + return 0; + } + + fprintf(stderr, "httppost: all data '%.*s'\n", + (int)size, buffer); + + for (i= 0; i<size; i++) + { + if (!okp) + break; + if (*okp != buffer[i] || *okp == '\0') + { + okp= NULL; + break; + } + okp++; + } + } + if (ferror(in_file)) + { + report_err("error reading input"); + return 0; + } + *found_okp= (okp != NULL && *okp == '\0'); + return 1; +} + static void skip_spaces(const char *cp, char **ncp) { const unsigned char *ucp; |