Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

pop3: Code tidy up before the introduction of authentication code

Moved EOB definition into header file.

Switched the logic around in pop3_endofresp() to allow for the
introduction of auth-mechanism detection.

Repositioned second and third function variables where they will fit
within the 78 character line limit.

Tidied up some comments.
  • Loading branch information...
commit c6495bccbf7485d9088e994bf27cb2efd3b29d47 1 parent f95f19e
Steve Holme authored May 27, 2012

Showing 2 changed files with 45 additions and 61 deletions. Show diff stats Hide diff stats

  1. 84  lib/pop3.c
  2. 22  lib/pop3.h
84  lib/pop3.c
@@ -207,26 +207,24 @@ static const struct Curl_handler Curl_handler_pop3s_proxy = {
207 207
 #endif
208 208
 #endif
209 209
 
210  
-/* function that checks for a pop3 status code at the start of the given
211  
-   string */
212  
-static int pop3_endofresp(struct pingpong *pp,
213  
-                          int *resp)
  210
+/* Function that checks for an ending pop3 status code at the start of the
  211
+   given string */
  212
+static int pop3_endofresp(struct pingpong *pp, int *resp)
214 213
 {
215 214
   char *line = pp->linestart_resp;
216 215
   size_t len = pp->nread_resp;
217 216
 
218  
-  if(((len >= 3) && !memcmp("+OK", line, 3)) ||
219  
-     ((len >= 4) && !memcmp("-ERR", line, 4))) {
220  
-    *resp = line[1]; /* O or E */
221  
-    return TRUE;
222  
-  }
  217
+  if((len < 3 || memcmp("+OK", line, 3)) && 
  218
+     (len < 4 || memcmp("-ERR", line, 4)))
  219
+  return FALSE; /* Nothing for us */
  220
+
  221
+  *resp = line[1]; /* O or E */
223 222
 
224  
-  return FALSE; /* nothing for us */
  223
+  return TRUE;
225 224
 }
226 225
 
227 226
 /* This is the ONLY way to change POP3 state! */
228  
-static void state(struct connectdata *conn,
229  
-                  pop3state newstate)
  227
+static void state(struct connectdata *conn, pop3state newstate)
230 228
 {
231 229
 #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
232 230
   /* for debug purposes */
@@ -267,8 +265,7 @@ static CURLcode pop3_state_user(struct connectdata *conn)
267 265
 }
268 266
 
269 267
 /* For the POP3 "protocol connect" and "doing" phases only */
270  
-static int pop3_getsock(struct connectdata *conn,
271  
-                        curl_socket_t *socks,
  268
+static int pop3_getsock(struct connectdata *conn, curl_socket_t *socks,
272 269
                         int numsocks)
273 270
 {
274 271
   return Curl_pp_getsock(&conn->proto.pop3c.pp, socks, numsocks);
@@ -283,7 +280,7 @@ static void pop3_to_pop3s(struct connectdata *conn)
283 280
 #define pop3_to_pop3s(x) Curl_nop_stmt
284 281
 #endif
285 282
 
286  
-/* for the initial server greeting */
  283
+/* For the initial server greeting */
287 284
 static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
288 285
                                             int pop3code,
289 286
                                             pop3state instate)
@@ -311,7 +308,7 @@ static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
311 308
   return result;
312 309
 }
313 310
 
314  
-/* for STARTTLS responses */
  311
+/* For STARTTLS responses */
315 312
 static CURLcode pop3_state_starttls_resp(struct connectdata *conn,
316 313
                                          int pop3code,
317 314
                                          pop3state instate)
@@ -345,7 +342,7 @@ static CURLcode pop3_state_starttls_resp(struct connectdata *conn,
345 342
   return result;
346 343
 }
347 344
 
348  
-/* for USER responses */
  345
+/* For USER responses */
349 346
 static CURLcode pop3_state_user_resp(struct connectdata *conn,
350 347
                                      int pop3code,
351 348
                                      pop3state instate)
@@ -372,7 +369,7 @@ static CURLcode pop3_state_user_resp(struct connectdata *conn,
372 369
   return result;
373 370
 }
374 371
 
375  
-/* for PASS responses */
  372
+/* For PASS responses */
376 373
 static CURLcode pop3_state_pass_resp(struct connectdata *conn,
377 374
                                      int pop3code,
378 375
                                      pop3state instate)
@@ -392,7 +389,7 @@ static CURLcode pop3_state_pass_resp(struct connectdata *conn,
392 389
   return result;
393 390
 }
394 391
 
395  
-/* for the command response */
  392
+/* For the command response */
396 393
 static CURLcode pop3_state_command_resp(struct connectdata *conn,
397 394
                                         int pop3code,
398 395
                                         pop3state instate)
@@ -447,7 +444,7 @@ static CURLcode pop3_state_command_resp(struct connectdata *conn,
447 444
   return result;
448 445
 }
449 446
 
450  
-/* start the DO phase for the command */
  447
+/* Start the DO phase for the command */
451 448
 static CURLcode pop3_command(struct connectdata *conn)
452 449
 {
453 450
   CURLcode result = CURLE_OK;
@@ -537,7 +534,7 @@ static CURLcode pop3_statemach_act(struct connectdata *conn)
537 534
   return result;
538 535
 }
539 536
 
540  
-/* called repeatedly until done from multi.c */
  537
+/* Called repeatedly until done from multi.c */
541 538
 static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done)
542 539
 {
543 540
   struct pop3_conn *pop3c = &conn->proto.pop3c;
@@ -563,10 +560,8 @@ static CURLcode pop3_easy_statemach(struct connectdata *conn)
563 560
   return result;
564 561
 }
565 562
 
566  
-/*
567  
- * Allocate and initialize the struct POP3 for the current SessionHandle.  If
568  
- * need be.
569  
- */
  563
+/* Allocate and initialize the POP3 struct for the current SessionHandle if
  564
+   required */
570 565
 static CURLcode pop3_init(struct connectdata *conn)
571 566
 {
572 567
   struct SessionHandle *data = conn->data;
@@ -591,16 +586,18 @@ static CURLcode pop3_init(struct connectdata *conn)
591 586
   return CURLE_OK;
592 587
 }
593 588
 
594  
-/*
595  
- * pop3_connect() should do everything that is to be considered a part of
596  
- * the connection phase.
  589
+/***********************************************************************
  590
+ *
  591
+ * pop3_connect()
  592
+ *
  593
+ * This function should do everything that is to be considered a part of the
  594
+ * connection phase.
597 595
  *
598 596
  * The variable 'done' points to will be TRUE if the protocol-layer connect
599 597
  * phase is done when this function returns, or FALSE is not. When called as
600 598
  * a part of the easy interface, it will always be TRUE.
601 599
  */
602  
-static CURLcode pop3_connect(struct connectdata *conn,
603  
-                             bool *done) /* see description above */
  600
+static CURLcode pop3_connect(struct connectdata *conn, bool *done)
604 601
 {
605 602
   CURLcode result;
606 603
   struct pop3_conn *pop3c = &conn->proto.pop3c;
@@ -698,11 +695,8 @@ static CURLcode pop3_done(struct connectdata *conn, CURLcode status,
698 695
  * This is the actual DO function for POP3. Get a file/directory according to
699 696
  * the options previously setup.
700 697
  */
701  
-
702  
-static
703  
-CURLcode pop3_perform(struct connectdata *conn,
704  
-                     bool *connected,  /* connect status after PASV / PORT */
705  
-                     bool *dophase_done)
  698
+static CURLcode pop3_perform(struct connectdata *conn, bool *connected,
  699
+                             bool *dophase_done)
706 700
 {
707 701
   /* this is POP3 and no proxy */
708 702
   CURLcode result = CURLE_OK;
@@ -785,7 +779,6 @@ static CURLcode pop3_do(struct connectdata *conn, bool *done)
785 779
  * This should be called before calling sclose().  We should then wait for the
786 780
  * response from the server before returning. The calling code should then try
787 781
  * to close the connection.
788  
- *
789 782
  */
790 783
 static CURLcode pop3_quit(struct connectdata *conn)
791 784
 {
@@ -861,8 +854,7 @@ static CURLcode pop3_parse_custom_request(struct connectdata *conn)
861 854
 }
862 855
 
863 856
 /* call this when the DO phase has completed */
864  
-static CURLcode pop3_dophase_done(struct connectdata *conn,
865  
-                                  bool connected)
  857
+static CURLcode pop3_dophase_done(struct connectdata *conn, bool connected)
866 858
 {
867 859
   struct FTP *pop3 = conn->data->state.proto.pop3;
868 860
 
@@ -876,8 +868,7 @@ static CURLcode pop3_dophase_done(struct connectdata *conn,
876 868
 }
877 869
 
878 870
 /* called from multi.c while DOing */
879  
-static CURLcode pop3_doing(struct connectdata *conn,
880  
-                               bool *dophase_done)
  871
+static CURLcode pop3_doing(struct connectdata *conn, bool *dophase_done)
881 872
 {
882 873
   CURLcode result;
883 874
   result = pop3_multi_statemach(conn, dophase_done);
@@ -899,7 +890,6 @@ static CURLcode pop3_doing(struct connectdata *conn,
899 890
  *
900 891
  * Performs all commands done before a regular transfer between a local and a
901 892
  * remote host.
902  
- *
903 893
  */
904 894
 static CURLcode pop3_regular_transfer(struct connectdata *conn,
905 895
                                       bool *dophase_done)
@@ -951,11 +941,9 @@ static CURLcode pop3_setup_connection(struct connectdata * conn)
951 941
 #endif
952 942
     }
953 943
 
954  
-    /*
955  
-     * We explicitly mark this connection as persistent here as we're doing
956  
-     * POP3 over HTTP and thus we accidentally avoid setting this value
957  
-     * otherwise.
958  
-     */
  944
+    /* We explicitly mark this connection as persistent here as we're doing
  945
+       POP3 over HTTP and thus we accidentally avoid setting this value
  946
+       otherwise. */
959 947
     conn->bits.close = FALSE;
960 948
 #else
961 949
     failf(data, "POP3 over http proxy requires HTTP support built-in!");
@@ -968,10 +956,6 @@ static CURLcode pop3_setup_connection(struct connectdata * conn)
968 956
   return CURLE_OK;
969 957
 }
970 958
 
971  
-/* this is the 5-bytes End-Of-Body marker for POP3 */
972  
-#define POP3_EOB "\x0d\x0a\x2e\x0d\x0a"
973  
-#define POP3_EOB_LEN 5
974  
-
975 959
 /*
976 960
  * This function scans the body after the end-of-body and writes everything
977 961
  * until the end is found.
22  lib/pop3.h
@@ -26,15 +26,15 @@
26 26
  * POP3 unique setup
27 27
  ***************************************************************************/
28 28
 typedef enum {
29  
-  POP3_STOP,        /* do nothing state, stops the state machine */
30  
-  POP3_SERVERGREET, /* waiting for the initial greeting immediately after
31  
-                       a connect */
  29
+  POP3_STOP,         /* do nothing state, stops the state machine */
  30
+  POP3_SERVERGREET,  /* waiting for the initial greeting immediately after
  31
+                        a connect */
32 32
   POP3_USER,
33 33
   POP3_PASS,
34 34
   POP3_STARTTLS,
35 35
   POP3_COMMAND,
36 36
   POP3_QUIT,
37  
-  POP3_LAST  /* never used */
  37
+  POP3_LAST          /* never used */
38 38
 } pop3state;
39 39
 
40 40
 /* pop3_conn is used for struct connection-oriented data in the connectdata
@@ -52,12 +52,12 @@ struct pop3_conn {
52 52
 extern const struct Curl_handler Curl_handler_pop3;
53 53
 extern const struct Curl_handler Curl_handler_pop3s;
54 54
 
55  
-/*
56  
- * This function scans the body after the end-of-body and writes everything
57  
- * until the end is found.
58  
- */
59  
-CURLcode Curl_pop3_write(struct connectdata *conn,
60  
-                         char *str,
61  
-                         size_t nread);
  55
+/* This is the 5-bytes End-Of-Body marker for POP3 */
  56
+#define POP3_EOB "\x0d\x0a\x2e\x0d\x0a"
  57
+#define POP3_EOB_LEN 5
  58
+
  59
+/* This function scans the body after the end-of-body and writes everything
  60
+ * until the end is found */
  61
+CURLcode Curl_pop3_write(struct connectdata *conn, char *str, size_t nread);
62 62
 
63 63
 #endif /* HEADER_CURL_POP3_H */

0 notes on commit c6495bc

Please sign in to comment.
Something went wrong with that request. Please try again.