commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. mu-1-2-90-separate-argp-cfg


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. mu-1-2-90-separate-argp-cfg-314-g968b981
Date: Tue, 11 Aug 2009 16:53:32 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=968b981b080a2c84445de6bd0df67b265c5fdf28

The branch, master has been updated
       via  968b981b080a2c84445de6bd0df67b265c5fdf28 (commit)
      from  6e40542e56205ebcaa607db2092076db8287292a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 968b981b080a2c84445de6bd0df67b265c5fdf28
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Aug 11 19:53:19 2009 +0300

    Improve command line and error handling in pop3d.
    
    * pop3d/pop3d.h: Remove unused includes.
    (ABORT): New state.
    (pop3d_command_handler_t, struct pop3d_command): New types.
    (pop3d_find_command): New function.
    (pop3d_stat,pop3d_top,pop3d_uidl,pop3d_user,pop3d_apop)
    (pop3d_auth,pop3d_capa,pop3d_dele,pop3d_list,pop3d_noop)
    (pop3d_quit,pop3d_retr,pop3d_rset): Remove const from
    the arguments. Functions are free to modify it.
    (pop3d_parse_command): New function.
    
    * pop3d/cmd.c: New file.
    * pop3d/Makefile.am: Link in cmd.o
    * pop3d/apop.c: Use pop3d_parse_command to parse commands
    * pop3d/auth.c: Likewise.
    * pop3d/extra.c (pop3d_args, pop3d_cmd): Remove.
    (pop3d_parse_command): New function.
    (pop3d_abquit): use pop3d_error_string to convert error numbers to
    messages.
    * pop3d/pop3d.c (cb_bulletin_db): Protect by #ifdef USE_DBM
    (pop3d_mainloop): Change loop condition.
    Use pop3d_parse_command to parse commands,
    pop3d_find_command to lookup handlers in the command table
    and pop3d_error_string to convert error numbers to
    messages.
    (main): Call enable_stls if necessary.
    
    * pop3d/capa.c, pop3d/dele.c, pop3d/list.c,
    pop3d/noop.c, pop3d/quit.c, pop3d/retr.c,
    pop3d/rset.c, pop3d/stat.c, pop3d/stls.c,
    pop3d/top.c, pop3d/uidl.c, pop3d/user.c: Remove const
    qualifier from the command handler argument.

-----------------------------------------------------------------------

Summary of changes:
 pop3d/Makefile.am |    1 +
 pop3d/apop.c      |   21 +++-------
 pop3d/auth.c      |    8 +--
 pop3d/capa.c      |    8 +--
 pop3d/cmd.c       |  109 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 pop3d/dele.c      |    9 ++--
 pop3d/extra.c     |   74 +++++++----------------------------
 pop3d/list.c      |   10 ++---
 pop3d/noop.c      |    8 +--
 pop3d/pop3d.c     |   93 ++++++++-------------------------------------
 pop3d/pop3d.h     |   87 ++++++++++++++---------------------------
 pop3d/quit.c      |   10 ++---
 pop3d/retr.c      |    9 ++--
 pop3d/rset.c      |    6 +--
 pop3d/stat.c      |    5 +-
 pop3d/stls.c      |   14 ++++---
 pop3d/top.c       |   14 ++----
 pop3d/uidl.c      |    9 ++--
 pop3d/user.c      |   21 ++--------
 19 files changed, 229 insertions(+), 287 deletions(-)
 create mode 100644 pop3d/cmd.c

diff --git a/pop3d/Makefile.am b/pop3d/Makefile.am
index a194658..8a3418c 100644
--- a/pop3d/Makefile.am
+++ b/pop3d/Makefile.am
@@ -30,6 +30,7 @@ pop3d_SOURCES =\
  auth.c\
  bulletin.c\
  capa.c\
+ cmd.c\
  dele.c\
  expire.c\
  extra.c\
diff --git a/pop3d/apop.c b/pop3d/apop.c
index 80dde15..51a8349 100644
--- a/pop3d/apop.c
+++ b/pop3d/apop.c
@@ -1,5 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007 Free Software Foundation, 
Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007,
+   2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
@@ -144,9 +143,9 @@ pop3d_apopuser (const char *user)
 }
 
 int
-pop3d_apop (const char *arg)
+pop3d_apop (char *arg)
 {
-  char *tmp, *user_digest, *user, *password;
+  char *tmp, *password, *user_digest, *user;
   char buf[POP_MAXCMDLEN];
   struct mu_md5_ctx md5context;
   unsigned char md5digest[16];
@@ -157,22 +156,18 @@ pop3d_apop (const char *arg)
   if (strlen (arg) == 0)
     return ERR_BAD_ARGS;
 
-  user = pop3d_cmd (arg);
+  pop3d_parse_command (arg, &user, &user_digest);
   if (strlen (user) > (POP_MAXCMDLEN - APOP_DIGEST))
     {
       mu_diag_output (MU_DIAG_INFO, _("User name too long: %s"), user);
-      free (user);
       return ERR_BAD_ARGS;
     }
-  user_digest = pop3d_args (arg);
 
   password = pop3d_apopuser (user);
   if (password == NULL)
     {
       mu_diag_output (MU_DIAG_INFO, _("Password for `%s' not found in the 
database"),
              user);
-      free (user);
-      free (user_digest);
       return ERR_BAD_LOGIN;
     }
 
@@ -194,14 +189,10 @@ pop3d_apop (const char *arg)
   if (strcmp (user_digest, buf))
     {
       mu_diag_output (MU_DIAG_INFO, _("APOP failed for `%s'"), user);
-      free (user);
-      free (user_digest);
       return ERR_BAD_LOGIN;
     }
 
-  free (user_digest);
   auth_data = mu_get_auth_by_name (user);
-  free (user);
   if (auth_data == NULL)
     return ERR_BAD_LOGIN;
 
diff --git a/pop3d/auth.c b/pop3d/auth.c
index fd343f8..21a8f34 100644
--- a/pop3d/auth.c
+++ b/pop3d/auth.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,16 +12,14 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
 /* AUTH is not yet implemented */
 
 int
-pop3d_auth (const char *arg MU_ARG_UNUSED)
+pop3d_auth (char *arg MU_ARG_UNUSED)
 {
   if (state != AUTHORIZATION)
     return ERR_WRONG_STATE;
diff --git a/pop3d/capa.c b/pop3d/capa.c
index 9b96adb..e003542 100644
--- a/pop3d/capa.c
+++ b/pop3d/capa.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2001, 2003, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2003, 2007, 2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
@@ -28,7 +26,7 @@
   Capabilities available in the AUTHORIZATION state MUST be announced
   in both states.  */
 int
-pop3d_capa (const char *arg)
+pop3d_capa (char *arg)
 {
   if (strlen (arg) != 0)
     return ERR_BAD_ARGS;
diff --git a/pop3d/cmd.c b/pop3d/cmd.c
new file mode 100644
index 0000000..4243cb7
--- /dev/null
+++ b/pop3d/cmd.c
@@ -0,0 +1,109 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2009 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include "pop3d.h"
+
+static struct pop3d_command command_table[] = {
+#ifdef WITH_TLS
+  { "STLS", pop3d_stls },
+# define COMMAND_TABLE_HEAD 1
+#else
+# define COMMAND_TABLE_HEAD 0
+#endif
+  { "RETR", pop3d_retr },
+  { "DELE", pop3d_dele },
+  { "USER", pop3d_user },
+  { "QUIT", pop3d_quit },
+  { "APOP", pop3d_apop },
+  { "AUTH", pop3d_auth },
+  { "STAT", pop3d_stat },
+  { "LIST", pop3d_list },
+  { "NOOP", pop3d_noop },
+  { "RSET", pop3d_rset },
+  { "TOP",  pop3d_top },
+  { "UIDL", pop3d_uidl },
+  { "CAPA", pop3d_capa },
+  { NULL }
+};
+
+static struct pop3d_command *command_table_head =
+         command_table + COMMAND_TABLE_HEAD;
+
+pop3d_command_handler_t
+pop3d_find_command (const char *name)
+{
+  struct pop3d_command *p;
+  for (p = command_table_head; p->name; p++)
+    {
+      if (mu_c_strcasecmp (name, p->name) == 0)
+       return p->handler;
+    }
+  return p->handler;
+}
+
+#ifdef WITH_TLS
+void
+enable_stls ()
+{
+  command_table_head = command_table;
+}
+#endif
+
+struct error_table
+{
+  int code;
+  const char *text;
+};
+
+static struct error_table error_table[] = {
+  { ERR_WRONG_STATE, "Incorrect state" },
+  { ERR_BAD_ARGS, "Invalid arguments" },
+  { ERR_BAD_LOGIN, "Bad login" },
+  { ERR_NO_MESG, "No such message" },
+  { ERR_MESG_DELE, "Message has been deleted" },
+  { ERR_NOT_IMPL, "Not implemented" },
+  { ERR_BAD_CMD, "Invalid command" },
+  { ERR_MBOX_LOCK, "[IN-USE] Mailbox in use" },
+  { ERR_TOO_LONG, "Argument too long" },
+  { ERR_NO_MEM, "Out of memory, quitting" },
+  { ERR_SIGNAL, "Quitting on signal" },
+  { ERR_FILE, "Some deleted messages not removed" },
+  { ERR_NO_IFILE, "No input stream" },
+  { ERR_NO_OFILE, "No output stream" },
+  { ERR_IO, "I/O error" },
+  { ERR_PROTO, "Remote protocol error" },
+  { ERR_TIMEOUT, "Session timed out" },
+  { ERR_UNKNOWN, "Unknown error" },
+  { ERR_MBOX_SYNC, "Mailbox was updated by other process" },
+#ifdef WITH_TLS
+  { ERR_TLS_ACTIVE, "Command not permitted when TLS active" },
+#endif /* WITH_TLS */
+  { ERR_TLS_IO, "TLS I/O error" },
+  { ERR_LOGIN_DELAY,
+    "[LOGIN-DELAY] Attempt to log in within the minimum login delay interval" 
},
+  { ERR_TERMINATE, "Terminating on request" },
+  { 0 }
+};
+
+const char *
+pop3d_error_string (int code)
+{
+  struct error_table *ep;
+  for (ep = error_table; ep->code != 0; ep++)
+    if (ep->code == code)
+      return ep->text;
+  return "unknown error";
+}
diff --git a/pop3d/dele.c b/pop3d/dele.c
index e98a560..88dd834 100644
--- a/pop3d/dele.c
+++ b/pop3d/dele.c
@@ -1,5 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2005, 2007,
+   2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,16 +13,14 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
 /* DELE adds a message number to the list of messages to be deleted on QUIT */
 
 int
-pop3d_dele (const char *arg)
+pop3d_dele (char *arg)
 {
   size_t num;
   mu_message_t msg;
diff --git a/pop3d/extra.c b/pop3d/extra.c
index 808ca3d..054d8c6 100644
--- a/pop3d/extra.c
+++ b/pop3d/extra.c
@@ -22,66 +22,22 @@
 
 static mu_stream_t istream, ostream;
 
-/* Takes a string as input and returns either the remainder of the string
-   after the first space, or a zero length string if no space */
-
-char *
-pop3d_args (const char *cmd)
+void
+pop3d_parse_command (char *cmd, char **pcmd, char **parg)
 {
-  int space = -1, i = 0, len;
-  char *buf;
-
-  len = strlen (cmd) + 1;
-  buf = malloc (len * sizeof (char));
-  if (buf == NULL)
-    pop3d_abquit (ERR_NO_MEM);
-
-  while (space < 0 && i < len)
+  char *p;
+  
+  cmd = mu_str_skip_class (cmd, MU_CTYPE_BLANK);
+  *pcmd = cmd;
+  p = mu_str_skip_class_comp (cmd, MU_CTYPE_SPACE);
+  *p++ = 0;
+  if (*p)
     {
-      if (cmd[i] == ' ')
-       space = i + 1;
-      else if (cmd[i] == '\0' || cmd[i] == '\r' || cmd[i] == '\n')
-       len = i;
-      i++;
+      *parg = p;
+      mu_rtrim_class (p, MU_CTYPE_SPACE);
     }
-
-  if (space < 0)
-    buf[0] = '\0';
   else
-    {
-      for (i = space; i < len; i++)
-       if (cmd[i] == '\0' || cmd[i] == '\r' || cmd[i] == '\n')
-         buf[i - space] = '\0';
-       else
-         buf[i - space] = cmd[i];
-    }
-
-  return buf;
-}
-
-/* This takes a string and returns the string up to the first space or end of
-   the string, whichever occurs first */
-
-char *
-pop3d_cmd (const char *cmd)
-{
-  char *buf;
-  int i = 0, len;
-
-  len = strlen (cmd) + 1;
-  buf = malloc (len * sizeof (char));
-  if (buf == NULL)
-    pop3d_abquit (ERR_NO_MEM);
-
-  for (i = 0; i < len; i++)
-    {
-      if (cmd[i] == ' ' || cmd[i] == '\0' || cmd[i] == '\r' || cmd[i] == '\n')
-       len = i;
-      else
-       buf[i] = cmd[i];
-    }
-  buf[i - 1] = '\0';
-  return buf;
+    *parg = "";
 }
 
 /* This is called if GNU POP3 needs to quit without going to the UPDATE stage.
@@ -105,7 +61,7 @@ pop3d_abquit (int reason)
     {
     case ERR_NO_MEM:
       code = EX_SOFTWARE;
-      pop3d_outf ("-ERR Out of memory, quitting\r\n");
+      pop3d_outf ("-ERR %s\r\n", pop3d_error_string (reason));
       mu_diag_output (MU_DIAG_ERROR, _("Out of memory"));
       break;
 
@@ -121,7 +77,7 @@ pop3d_abquit (int reason)
 
     case ERR_TIMEOUT:
       code = EX_TEMPFAIL;
-      pop3d_outf ("-ERR Session timed out\r\n");
+      pop3d_outf ("-ERR %s\r\n", pop3d_error_string (reason));
       if (state == TRANSACTION)
        mu_diag_output (MU_DIAG_INFO, _("Session timed out for user: %s"),
                        username);
@@ -160,7 +116,7 @@ pop3d_abquit (int reason)
 
     default:
       code = EX_SOFTWARE;
-      pop3d_outf ("-ERR Quitting (reason unknown)\r\n");
+      pop3d_outf ("-ERR Quitting: %s\r\n", pop3d_error_string (reason));
       mu_diag_output (MU_DIAG_ERROR, _("Quitting (numeric reason %d)"),
                      reason);
       break;
diff --git a/pop3d/list.c b/pop3d/list.c
index d53a795..bd20969 100644
--- a/pop3d/list.c
+++ b/pop3d/list.c
@@ -1,6 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005,
-   2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2005, 2007,
+   2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -13,16 +13,14 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
 /* Displays the size of message number arg or all messages (if no arg) */
 
 int
-pop3d_list (const char *arg)
+pop3d_list (char *arg)
 {
   size_t mesgno;
   mu_message_t msg = NULL;
diff --git a/pop3d/noop.c b/pop3d/noop.c
index 1b8f2a0..daa823e 100644
--- a/pop3d/noop.c
+++ b/pop3d/noop.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2001, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2007, 2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,16 +12,14 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
 /* Does nothing */
 
 int
-pop3d_noop (const char *arg)
+pop3d_noop (char *arg)
 {
   if (strlen (arg) != 0)
     return ERR_BAD_ARGS;
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 21d5609..16fa21e 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -117,6 +117,7 @@ cb_bulletin_source (mu_debug_t debug, void *data, 
mu_config_value_t *val)
   return 0;
 }
 
+#ifdef USE_DBM
 static int
 cb_bulletin_db (mu_debug_t debug, void *data, mu_config_value_t *val)
 {
@@ -125,6 +126,7 @@ cb_bulletin_db (mu_debug_t debug, void *data, 
mu_config_value_t *val)
   set_bulletin_db (val->v.string); /* FIXME: Error reporting? */
   return 0;
 }
+#endif
 
 static struct mu_cfg_param pop3d_cfg_param[] = {
   { "undelete", mu_cfg_bool, &undelete_on_startup, 0, NULL,
@@ -327,15 +329,16 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
   /* Lets boogie.  */
   pop3d_outf ("+OK POP3 Ready %s\r\n", md5shared);
 
-  while (state != UPDATE)
+  while (state != UPDATE && state != ABORT)
     {
-      char *buf, *arg, *cmd;
-
+      char *buf;
+      char *arg, *cmd;
+      pop3d_command_handler_t handler;
+      
       pop3d_flush_output ();
       status = OK;
       buf = pop3d_readline (buffer, sizeof (buffer));
-      cmd = pop3d_cmd (buf);
-      arg = pop3d_args (buf);
+      pop3d_parse_command (buf, &cmd, &arg);
 
       /* The mailbox size needs to be check to make sure that we are in
         sync.  Some other applications may not respect the *.lock or
@@ -361,79 +364,13 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
        status = ERR_TOO_LONG;
       else if (strlen (cmd) > 4)
        status = ERR_BAD_CMD;
-      else if (mu_c_strncasecmp (cmd, "RETR", 4) == 0)
-       status = pop3d_retr (arg);
-      else if (mu_c_strncasecmp (cmd, "DELE", 4) == 0)
-       status = pop3d_dele (arg);
-      else if (mu_c_strncasecmp (cmd, "USER", 4) == 0)
-       status = pop3d_user (arg);
-      else if (mu_c_strncasecmp (cmd, "QUIT", 4) == 0)
-       status = pop3d_quit (arg);
-      else if (mu_c_strncasecmp (cmd, "APOP", 4) == 0)
-       status = pop3d_apop (arg);
-      else if (mu_c_strncasecmp (cmd, "AUTH", 4) == 0)
-       status = pop3d_auth (arg);
-      else if (mu_c_strncasecmp (cmd, "STAT", 4) == 0)
-       status = pop3d_stat (arg);
-      else if (mu_c_strncasecmp (cmd, "LIST", 4) == 0)
-       status = pop3d_list (arg);
-      else if (mu_c_strncasecmp (cmd, "NOOP", 4) == 0)
-       status = pop3d_noop (arg);
-      else if (mu_c_strncasecmp (cmd, "RSET", 4) == 0)
-       status = pop3d_rset (arg);
-      else if ((mu_c_strncasecmp (cmd, "TOP", 3) == 0) && (strlen (cmd) == 3))
-       status = pop3d_top (arg);
-      else if (mu_c_strncasecmp (cmd, "UIDL", 4) == 0)
-       status = pop3d_uidl (arg);
-      else if (mu_c_strncasecmp (cmd, "CAPA", 4) == 0)
-       status = pop3d_capa (arg);
-#ifdef WITH_TLS
-      else if ((mu_c_strncasecmp (cmd, "STLS", 4) == 0) && tls_available)
-       {
-         status = pop3d_stls (arg);
-         if (status)
-           {
-             mu_diag_output (MU_DIAG_ERROR, _("Session terminated"));
-             break;
-           }
-       }
-#endif /* WITH_TLS */
+      else if ((handler = pop3d_find_command (cmd)) != NULL)
+       status = handler (arg);
       else
        status = ERR_BAD_CMD;
 
-      if (status == OK)
-       ; /* Everything is good.  */
-      else if (status == ERR_WRONG_STATE)
-       pop3d_outf ("-ERR " BAD_STATE "\r\n");
-      else if (status == ERR_BAD_ARGS)
-       pop3d_outf ("-ERR " BAD_ARGS "\r\n");
-      else if (status == ERR_NO_MESG)
-       pop3d_outf ("-ERR " NO_MESG "\r\n");
-      else if (status == ERR_MESG_DELE)
-       pop3d_outf ("-ERR " MESG_DELE "\r\n");
-      else if (status == ERR_NOT_IMPL)
-       pop3d_outf ("-ERR " NOT_IMPL "\r\n");
-      else if (status == ERR_BAD_CMD)
-       pop3d_outf ("-ERR " BAD_COMMAND "\r\n");
-      else if (status == ERR_BAD_LOGIN)
-       pop3d_outf ("-ERR " BAD_LOGIN "\r\n");
-      else if (status == ERR_MBOX_LOCK)
-       pop3d_outf ("-ERR [IN-USE] " MBOX_LOCK "\r\n");
-      else if (status == ERR_TOO_LONG)
-       pop3d_outf ("-ERR " TOO_LONG "\r\n");
-      else if (status == ERR_FILE)
-       pop3d_outf ("-ERR " FILE_EXP "\r\n");
-#ifdef WITH_TLS
-      else if (status == ERR_TLS_ACTIVE)
-       pop3d_outf ("-ERR " TLS_ACTIVE "\r\n");
-#endif /* WITH_TLS */
-      else if (status == ERR_LOGIN_DELAY)
-       pop3d_outf ("-ERR [LOGIN-DELAY] " LOGIN_DELAY "\r\n");
-      else
-       pop3d_outf ("-ERR unknown error\r\n");
-
-      free (cmd);
-      free (arg);
+      if (status != OK)
+       pop3d_outf ("-ERR %s\r\n", pop3d_error_string (status));
     }
 
   pop3d_bye ();
@@ -553,7 +490,11 @@ main (int argc, char **argv)
 #ifdef WITH_TLS
   tls_available = mu_check_tls_environment ();
   if (tls_available)
-    tls_available = mu_init_tls_libs ();
+    {
+      tls_available = mu_init_tls_libs ();
+      if (tls_available)
+       enable_stls ();
+    }
 #endif /* WITH_TLS */
 
   /* Actually run the daemon.  */
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index 8621270..cadbff5 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -31,44 +31,6 @@
 /* The implementation */
 #define        IMPL            "GNU POP3 Daemon"
 
-/* You can edit the messages the POP server prints out here */
-
-/* A command that doesn't exist */
-#define BAD_COMMAND    "Invalid command"
-
-/* Incorrect number of arguments passed to a command */
-#define BAD_ARGS       "Invalid arguments"
-
-/* Command issued in wrong state */
-#define BAD_STATE      "Incorrect state"
-
-/* An action on a message that doesn't exist */
-#define NO_MESG                "No such message"
-
-/* An action on a message that doesn't exist */
-#define MESG_DELE      "Message has been deleted"
-
-/* A command that is known but not implemented */
-#define NOT_IMPL       "Not implemented"
-
-/* Invalid username or password */
-#define BAD_LOGIN      "Bad login"
-
-/* User authenticated, but mailbox is locked */
-#define MBOX_LOCK      "Mailbox in use"
-
-/* The command argument was > 40 characters */
-#define TOO_LONG       "Argument too long"
-
-/* An error occured when expunging.  */
-#define FILE_EXP        "Some deleted messages not removed"
-
-/* Command not permitted when TLS active. */
-#define TLS_ACTIVE      "Command not permitted when TLS active"
-
-/* Trying to log in within the minimum login delay interval */
-#define LOGIN_DELAY     "Attempt to log in within the minimum login delay 
interval"
-
 /* APOP password file, without .db or .passwd, which are added based on file
    type automatically */
 #define APOP_PASSFILE_NAME "apop"
@@ -183,10 +145,11 @@ extern int expire_on_exit;
 #define POP3_ATTRIBUTE_DELE 0x0001
 #define POP3_ATTRIBUTE_RETR 0x0010
 
-#define INITIAL        -1
+#define INITIAL         -1
 #define AUTHORIZATION  0
 #define TRANSACTION    1
 #define UPDATE         2
+#define ABORT           3
 
 #define OK             0
 #define ERR_WRONG_STATE        1
@@ -214,6 +177,13 @@ extern int expire_on_exit;
 #define ERR_TERMINATE   23
 
 typedef struct mu_pop_server *mu_pop_server_t;
+typedef int (*pop3d_command_handler_t) (char *);
+
+struct pop3d_command
+{
+  const char *name;
+  pop3d_command_handler_t handler;
+};
 
 extern mu_pop_server_t pop3srv;
 extern mu_mailbox_t mbox;
@@ -234,34 +204,38 @@ extern struct mu_auth_data *auth_data;
 extern unsigned int idle_timeout;
 extern int pop3d_transcript;
 
+extern pop3d_command_handler_t pop3d_find_command (const char *name);
+
+extern int pop3d_stat           (char *);
+extern int pop3d_top            (char *);
+extern int pop3d_uidl           (char *);
+extern int pop3d_user           (char *);
+extern int pop3d_apop           (char *);
+extern int pop3d_auth           (char *);
+extern int pop3d_capa           (char *);
+extern int pop3d_dele           (char *);
+extern int pop3d_list           (char *);
+extern int pop3d_noop           (char *);
+extern int pop3d_quit           (char *);
+extern int pop3d_retr           (char *);
+extern int pop3d_rset           (char *);
+
 extern void pop3d_bye           (void);
 extern int pop3d_abquit         (int);
-extern int pop3d_apop           (const char *);
 extern char *pop3d_apopuser     (const char *);
-extern char *pop3d_args         (const char *);
-extern int pop3d_auth           (const char *);
-extern int pop3d_capa           (const char *);
-extern char *pop3d_cmd          (const char *);
-extern int pop3d_dele           (const char *);
-extern int pop3d_list           (const char *);
 extern int pop3d_lock           (void);
-extern int pop3d_noop           (const char *);
-extern int pop3d_quit           (const char *);
-extern int pop3d_retr           (const char *);
-extern int pop3d_rset           (const char *);
 extern void process_cleanup     (void);
 
+extern void pop3d_parse_command (char *cmd, char **pcmd, char **parg);
+
 extern RETSIGTYPE pop3d_master_signal  (int);
 extern RETSIGTYPE pop3d_child_signal  (int);
 
-extern int pop3d_stat           (const char *);
 #ifdef WITH_TLS
-extern int pop3d_stls           (const char *);
+extern int pop3d_stls           (char *);
+extern void enable_stls (void);
 #endif /* WITH_TLS */
-extern int pop3d_top            (const char *);
 extern int pop3d_touchlock      (void);
-extern int pop3d_uidl           (const char *);
-extern int pop3d_user           (const char *);
 extern int pop3d_unlock         (void);
 extern void pop3d_outf          (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 
@@ -291,7 +265,6 @@ extern void deliver_pending_bulletins (void);
 extern void set_bulletin_db (const char *file);
 extern int set_bulletin_source (const char *source);
 extern int pop3d_begin_session (void);
-
-
+extern const char *pop3d_error_string (int code);
 
 #endif /* _POP3D_H */
diff --git a/pop3d/quit.c b/pop3d/quit.c
index b754169..4d8c5a8 100644
--- a/pop3d/quit.c
+++ b/pop3d/quit.c
@@ -1,6 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2005,
-   2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007,
+   2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
@@ -28,7 +26,7 @@
 static void pop3d_fix_mark ();
 
 int
-pop3d_quit (const char *arg)
+pop3d_quit (char *arg)
 {
   int err = OK;
   if (strlen (arg) != 0)
diff --git a/pop3d/retr.c b/pop3d/retr.c
index 47d83ee..2424677 100644
--- a/pop3d/retr.c
+++ b/pop3d/retr.c
@@ -1,5 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2005, 2007,
+   2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,16 +13,14 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
 /* Prints out the specified message */
 
 int
-pop3d_retr (const char *arg)
+pop3d_retr (char *arg)
 {
   size_t mesgno, n;
   char buf[BUFFERSIZE];
diff --git a/pop3d/rset.c b/pop3d/rset.c
index dec4516..de4aeb6 100644
--- a/pop3d/rset.c
+++ b/pop3d/rset.c
@@ -12,16 +12,14 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
 /* Resets the connection so that no messages are marked as deleted */
 
 int
-pop3d_rset (const char *arg)
+pop3d_rset (char *arg)
 {
   size_t i;
   size_t total = 0;
diff --git a/pop3d/stat.c b/pop3d/stat.c
index 4582d73..238bb9e 100644
--- a/pop3d/stat.c
+++ b/pop3d/stat.c
@@ -1,5 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2005, 2007,
+   2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -21,7 +22,7 @@
 /* Prints the number of messages and the total size of all messages */
 
 int
-pop3d_stat (const char *arg)
+pop3d_stat (char *arg)
 {
   size_t mesgno;
   size_t size = 0;
diff --git a/pop3d/stls.c b/pop3d/stls.c
index 20c2c66..a6d0d1e 100644
--- a/pop3d/stls.c
+++ b/pop3d/stls.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2007, 2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
@@ -23,7 +21,7 @@
 #ifdef WITH_TLS
 
 int
-pop3d_stls (const char *arg)
+pop3d_stls (char *arg)
 {
   if (strlen (arg) != 0)
     return ERR_BAD_ARGS;
@@ -40,7 +38,11 @@ pop3d_stls (const char *arg)
   tls_done = pop3d_init_tls_server ();
 
   if (!tls_done)
-    return ERR_UNKNOWN;
+    {
+      mu_diag_output (MU_DIAG_ERROR, _("Session terminated"));
+      state = ABORT;
+      return ERR_UNKNOWN;
+    }
 
   state = AUTHORIZATION;  /* Confirm we're in this state. Necessary for
                             --tls-required to work */
diff --git a/pop3d/top.c b/pop3d/top.c
index ecc2ae5..b9e305b 100644
--- a/pop3d/top.c
+++ b/pop3d/top.c
@@ -12,16 +12,14 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
 /* Prints the header of a message plus a specified number of lines.  */
 
 int
-pop3d_top (const char *arg)
+pop3d_top (char *arg)
 {
   size_t mesgno;
   int lines;
@@ -41,12 +39,10 @@ pop3d_top (const char *arg)
   if (state != TRANSACTION)
     return ERR_WRONG_STATE;
 
-  mesgc = pop3d_cmd (arg);
-  linesc = pop3d_args (arg);
+  pop3d_parse_command (arg, &mesgc, &linesc);
+  
   mesgno = strtoul (mesgc, NULL, 10);
-  lines = strlen (linesc) > 0 ? strtol (linesc, NULL, 10) : -1;
-  free (mesgc);
-  free (linesc);
+  lines = *linesc ? strtol (linesc, NULL, 10) : -1;
 
   if (lines < 0)
     return ERR_BAD_ARGS;
diff --git a/pop3d/uidl.c b/pop3d/uidl.c
index 4e5d51f..7d31fdb 100644
--- a/pop3d/uidl.c
+++ b/pop3d/uidl.c
@@ -1,5 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2005, 2007,
+   2009 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,14 +13,12 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
 int
-pop3d_uidl (const char *arg)
+pop3d_uidl (char *arg)
 {
   size_t mesgno;
   char uidl[128];
diff --git a/pop3d/user.c b/pop3d/user.c
index 50a972c..ca0da51 100644
--- a/pop3d/user.c
+++ b/pop3d/user.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
@@ -89,7 +87,7 @@ pop3d_begin_session ()
 }
 
 int
-pop3d_user (const char *arg)
+pop3d_user (char *arg)
 {
   char *buf, pass[POP_MAXCMDLEN], *tmp, *cmd;
   char buffer[512];
@@ -104,36 +102,27 @@ pop3d_user (const char *arg)
   pop3d_flush_output ();
 
   buf = pop3d_readline (buffer, sizeof (buffer));
-  cmd = pop3d_cmd (buf);
-  tmp = pop3d_args (buf);
+  pop3d_parse_command (buf, &cmd, &tmp);
 
   if (strlen (tmp) > POP_MAXCMDLEN)
-    {
-      free (cmd);
-      free (tmp);
-      return ERR_TOO_LONG;
-    }
+    return ERR_TOO_LONG;
   else
     {
       strncpy (pass, tmp, POP_MAXCMDLEN);
       /* strncpy () is lame, make sure the string is null terminated.  */
       pass[POP_MAXCMDLEN - 1] = '\0';
-      free (tmp);
     }
 
   if (mu_c_strcasecmp (cmd, "PASS") == 0)
     {
       int rc;
 
-      free (cmd);
-
 #ifdef _USE_APOP
       /* Check to see if they have an APOP password. If so, refuse USER/PASS */
       tmp = pop3d_apopuser (arg);
       if (tmp != NULL)
        {
          mu_diag_output (MU_DIAG_INFO, _("APOP user %s tried to log in with 
USER"), arg);
-         free (tmp);
          return ERR_BAD_LOGIN;
        }
 #endif
@@ -159,12 +148,10 @@ pop3d_user (const char *arg)
   else if (mu_c_strcasecmp (cmd, "QUIT") == 0)
     {
       mu_diag_output (MU_DIAG_INFO, _("Possible probe of account `%s'"), arg);
-      free (cmd);
       return pop3d_quit (pass);
     }
   else
     {
-      free (cmd);
       return ERR_BAD_CMD;
     }
 


hooks/post-receive
-- 
GNU Mailutils




reply via email to

[Prev in Thread] Current Thread [Next in Thread]