* Return a 403 response code when appropriate, adjusted kaoupload.c accordingly.
authorUrban Wallasch <urban.wallasch@freenet.de>
Sun, 18 Apr 2021 12:23:51 +0000 (14:23 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sun, 18 Apr 2021 12:23:51 +0000 (14:23 +0200)
kaoupload.c

index 6f4734cc3fd2efeb6b1e37b6d7c7d877c683a281..2171a31a062e3c73c23328e5e8a021e058330982 100644 (file)
@@ -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     "<x-alert><h1>No permission!</h1></x-alert>"
 
 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;
     }