]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
pop3: use the protocol handler ->write_resp
authorDaniel Stenberg <daniel@haxx.se>
Mon, 26 Aug 2024 08:39:28 +0000 (10:39 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 26 Aug 2024 12:59:50 +0000 (14:59 +0200)
Remove the "hardcoded" logic for the pop3 transfer handler and instead
use the generic protocol handler write_resp function.

Remove the check for 'data->req.ignorebody' because I cannot find a code
flow where this is set for POP3.

Closes #14684

lib/pop3.c
lib/pop3.h
lib/transfer.c

index 4cf1782ac1cbfae469bcd83c0c37a39f8a396b22..47271252e8b01ebdd8f6331cc9b7a2fc784b1387 100644 (file)
@@ -107,6 +107,11 @@ static CURLcode pop3_continue_auth(struct Curl_easy *data, const char *mech,
 static CURLcode pop3_cancel_auth(struct Curl_easy *data, const char *mech);
 static CURLcode pop3_get_message(struct Curl_easy *data, struct bufref *out);
 
+/* This function scans the body after the end-of-body and writes everything
+ * until the end is found */
+static CURLcode pop3_write(struct Curl_easy *data,
+                           const char *str, size_t nread, bool is_eos);
+
 /*
  * POP3 protocol handler.
  */
@@ -125,7 +130,7 @@ const struct Curl_handler Curl_handler_pop3 = {
   ZERO_NULL,                        /* domore_getsock */
   ZERO_NULL,                        /* perform_getsock */
   pop3_disconnect,                  /* disconnect */
-  ZERO_NULL,                        /* write_resp */
+  pop3_write,                       /* write_resp */
   ZERO_NULL,                        /* write_resp_hd */
   ZERO_NULL,                        /* connection_check */
   ZERO_NULL,                        /* attach connection */
@@ -155,7 +160,7 @@ const struct Curl_handler Curl_handler_pop3s = {
   ZERO_NULL,                        /* domore_getsock */
   ZERO_NULL,                        /* perform_getsock */
   pop3_disconnect,                  /* disconnect */
-  ZERO_NULL,                        /* write_resp */
+  pop3_write,                       /* write_resp */
   ZERO_NULL,                        /* write_resp_hd */
   ZERO_NULL,                        /* connection_check */
   ZERO_NULL,                        /* attach connection */
@@ -948,8 +953,8 @@ static CURLcode pop3_state_command_resp(struct Curl_easy *data,
       pp->nfinal = 0; /* done */
 
       if(!data->req.no_body) {
-        result = Curl_pop3_write(data, Curl_dyn_ptr(&pp->recvbuf),
-                                 Curl_dyn_len(&pp->recvbuf));
+        result = pop3_write(data, Curl_dyn_ptr(&pp->recvbuf),
+                            Curl_dyn_len(&pp->recvbuf), FALSE);
         if(result)
           return result;
       }
@@ -1447,12 +1452,13 @@ static CURLcode pop3_parse_custom_request(struct Curl_easy *data)
 
 /***********************************************************************
  *
- * Curl_pop3_write()
+ * pop3_write()
  *
  * This function scans the body after the end-of-body and writes everything
  * until the end is found.
  */
-CURLcode Curl_pop3_write(struct Curl_easy *data, const char *str, size_t nread)
+static CURLcode pop3_write(struct Curl_easy *data, const char *str,
+                           size_t nread, bool is_eos)
 {
   /* This code could be made into a special function in the handler struct */
   CURLcode result = CURLE_OK;
@@ -1462,6 +1468,7 @@ CURLcode Curl_pop3_write(struct Curl_easy *data, const char *str, size_t nread)
   bool strip_dot = FALSE;
   size_t last = 0;
   size_t i;
+  (void)is_eos;
 
   /* Search through the buffer looking for the end-of-body marker which is
      5 bytes (0d 0a 2e 0d 0a). Note that a line starting with a dot matches
index e8e98db04b6237ed79c9cb06d0baefd57dacef4a..3d08dafa198a567cea6f8cc47a5ab8c028d4b21a 100644 (file)
@@ -90,9 +90,4 @@ extern const struct Curl_handler Curl_handler_pop3s;
 #define POP3_EOB "\x0d\x0a\x2e\x0d\x0a"
 #define POP3_EOB_LEN 5
 
-/* This function scans the body after the end-of-body and writes everything
- * until the end is found */
-CURLcode Curl_pop3_write(struct Curl_easy *data,
-                         const char *str, size_t nread);
-
 #endif /* HEADER_CURL_POP3_H */
index 46fde236d82a2c164ba1f44a12e2482cd05b7f65..489fd4fe89f2c1a1848fa4fad930739d6822bbb3 100644 (file)
@@ -1186,15 +1186,7 @@ CURLcode Curl_xfer_write_resp(struct Curl_easy *data,
       int cwtype = CLIENTWRITE_BODY;
       if(is_eos)
         cwtype |= CLIENTWRITE_EOS;
-
-#ifndef CURL_DISABLE_POP3
-      if(blen && data->conn->handler->protocol & PROTO_FAMILY_POP3) {
-        result = data->req.ignorebody? CURLE_OK :
-                 Curl_pop3_write(data, buf, blen);
-      }
-      else
-#endif /* CURL_DISABLE_POP3 */
-        result = Curl_client_write(data, cwtype, buf, blen);
+      result = Curl_client_write(data, cwtype, buf, blen);
     }
   }