From: Urban Wallasch Date: Sun, 18 Apr 2021 12:23:51 +0000 (+0200) Subject: * Return a 403 response code when appropriate, adjusted kaoupload.c accordingly. X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=e2f5195b057e4bc93a95152b4d2780b9d622defe;p=kaotools.git * Return a 403 response code when appropriate, adjusted kaoupload.c accordingly. --- diff --git a/kaoupload.c b/kaoupload.c index 6f4734c..2171a31 100644 --- a/kaoupload.c +++ b/kaoupload.c @@ -160,11 +160,10 @@ static size_t write_memory_cb( void *contents, size_t size, size_t nmemb, void * #define RESP_COMPLETE "Upload complete, " #define RESP_SKIP "Skip-to-position: " #define RESP_MISMATCH "Partfile initial sequence mismatch" -#define RESP_NOPERM "

No permission!

" static int upload_chunk( CURL *curl, struct file_info_t *fi, off_t csize ) { int res = -1; - int response_code; + long http_code; ssize_t br; char url[2048]; void *chunk; @@ -213,11 +212,11 @@ static int upload_chunk( CURL *curl, struct file_info_t *fi, off_t csize ) { } curl_easy_getinfo( curl, CURLINFO_SPEED_UPLOAD_T, &fi->speed ); - curl_easy_getinfo( curl, CURLINFO_RESPONSE_CODE, &response_code ); + curl_easy_getinfo( curl, CURLINFO_RESPONSE_CODE, &http_code ); // puts(reply.memory); - switch ( response_code ) { + switch ( http_code ) { case 200: // simplest case, uploaded one chunk if ( 0 == strncmp( reply.memory, RESP_HAVE, strlen( RESP_HAVE ) ) ) { @@ -234,10 +233,6 @@ static int upload_chunk( CURL *curl, struct file_info_t *fi, off_t csize ) { if ( completed == fi->coff && 0 == fi->remn ) res = 0; } - else if ( NULL != strstr( reply.memory, RESP_NOPERM ) ) { - // this really should be a 401 or 403 ... - err( "no permission, check credentials!", 0 ); - } else fprintf( stderr, "ERROR: unexpected response: %s", reply.memory ); break; @@ -261,7 +256,8 @@ static int upload_chunk( CURL *curl, struct file_info_t *fi, off_t csize ) { err( "response code 428 w/o 'Skip-to-position'", 0 ); break; default: - fprintf( stderr, "REMOTE ERROR: %d: %s\n", response_code, reply.memory ); + fprintf( stderr, "REMOTE ERROR: %ld %s", http_code, + 100 > reply.size ? reply.memory : ( 403 == http_code ? "Forbidden" : "" ) ); break; }