]> diplodocus.org Git - nmh/blobdiff - uip/popsbr.c
folder_realloc.c: Move interface to own file.
[nmh] / uip / popsbr.c
index a9e442bab2ea53243ab2449d62e22791edf1ceca..b3c85d392b639c3bdb83e812e0530e611edca26c 100644 (file)
@@ -5,13 +5,14 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/utils.h>
-#include <h/oauth.h>
-#include <h/netsec.h>
-
-#include <h/popsbr.h>
-#include <h/signals.h>
+#include "h/mh.h"
+#include "sbr/error.h"
+#include "h/utils.h"
+#include "h/oauth.h"
+#include "h/netsec.h"
+
+#include "h/popsbr.h"
+#include "h/signals.h"
 #include "sbr/base64.h"
 
 #define        TRM     "."
@@ -39,7 +40,8 @@ static int pop_sasl_callback(enum sasl_message_type, unsigned const char *,
 static int
 check_mech(char *server_mechs, size_t server_mechs_size)
 {
-  int status, sasl_capability = 0;
+  int status;
+  bool sasl_capability = false;
 
     /*
      * First off, we're going to send the CAPA command to see if we can
@@ -62,7 +64,7 @@ check_mech(char *server_mechs, size_t server_mechs_size)
 
         if (strncasecmp(response, "SASL ", 5) == 0) {
             /* We've seen the SASL capability.  Grab the mech list. */
-            sasl_capability++;
+            sasl_capability = true;
             strncpy(server_mechs, response + 5, server_mechs_size);
         }
     }
@@ -339,25 +341,27 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
                               "for initial challenge response");
                    return NOTOK;
                }
-               netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, NULL);
                rc = netsec_printf(nsc, errstr, "%s\r\n", b64data);
-               netsec_set_snoop_callback(nsc, NULL, NULL);
                free(b64data);
                if (rc != OK)
                    return NOTOK;
-               if (netsec_flush(nsc, errstr) != OK)
+               netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, NULL);
+               rc = netsec_flush(nsc, errstr);
+               netsec_set_snoop_callback(nsc, NULL, NULL);
+               if (rc != OK)
                    return NOTOK;
            } else {
-               netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder,
-                                         &snoopoffset);
-               snoopoffset = 6 + strlen(mech);
                rc = netsec_printf(nsc, errstr, "AUTH %s %s\r\n", mech,
                                   b64data);
                free(b64data);
-               netsec_set_snoop_callback(nsc, NULL, NULL);
                if (rc != OK)
                    return NOTOK;
-               if (netsec_flush(nsc, errstr) != OK)
+               netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder,
+                                         &snoopoffset);
+               snoopoffset = 6 + strlen(mech);
+               rc = netsec_flush(nsc, errstr);
+               netsec_set_snoop_callback(nsc, NULL, NULL);
+               if (rc != OK)
                    return NOTOK;
            }
        } else {
@@ -410,16 +414,18 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
            unsigned char *b64data;
            b64data = mh_xmalloc(BASE64SIZE(indatalen));
            writeBase64raw(indata, indatalen, b64data);
-           netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, NULL);
            rc = netsec_printf(nsc, errstr, "%s\r\n", b64data);
-           netsec_set_snoop_callback(nsc, NULL, NULL);
            free(b64data);
        }
 
        if (rc != OK)
            return NOTOK;
 
-       if (netsec_flush(nsc, errstr) != OK)
+       if (indatalen > 0)
+           netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, NULL);
+       rc = netsec_flush(nsc, errstr);
+       netsec_set_snoop_callback(nsc, NULL, NULL);
+       if (rc != OK)
            return NOTOK;
        break;