Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 14 Aug 2005 11:35:07 +0000 (11:35 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 14 Aug 2005 11:35:07 +0000 (11:35 +0000)
- add validity checks for $dsn_return, $dsn_notify and $smtp_use_tls
- add framework to check values for DT_STR variables for validity
- add strtok() wrapper to convert string into list2_t

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@401 e385b8ad-14ed-0310-8656-cc95a2468c6d

init.c
lib/list.c
lib/list.h
mutt_libesmtp.c
mutt_libesmtp.h
sendlib.c

diff --git a/init.c b/init.c
index 76bb085..a00f1f7 100644 (file)
--- a/init.c
+++ b/init.c
 #include "mutt_ssl.h"
 #endif
 
+#if defined (USE_LIBESMTP) && (defined (USE_SSL) || defined (USE_GNUTLS))
+#include "mutt_libesmtp.h"
+#endif
+
 #include "mx.h"
 #include "init.h"
 
@@ -60,6 +64,23 @@ char* CurRCFile = NULL;
 /* for synonym warning reports: current rc line */
 int CurRCLine = 0;
 
+/* prototypes for checking for special vars */
+static int check_dsn_return (const char*);
+static int check_dsn_notify (const char*);
+
+static struct {
+  const char* name;
+  int (*check) (const char*);
+} SpecialVars[] = {
+  { "dsn_notify", check_dsn_notify },
+  { "dsn_return", check_dsn_return },
+#if defined (USE_LIBESMTP) && (defined (USE_SSL) || defined (USE_GNUTLS))
+  { "smtp_use_tls", mutt_libesmtp_check_usetls },
+#endif
+  /* last */
+  { NULL,         NULL }
+};
+
 /* for synonym warning reports: adds synonym to end of list */
 static void syn_add (int n, int o) {
   syn_t* tmp = mem_malloc (sizeof (syn_t));
@@ -976,6 +997,47 @@ static void mutt_restore_default (struct option_t *p)
     set_option (OPTREDRAWTREE);
 }
 
+/* check whether value for $dsn_return would be valid */
+static int check_dsn_return (const char* val) {
+  if (val && *val && str_ncmp (val, "hdrs", 4) != 0 &&
+      str_ncmp (val, "full", 4) != 0)
+    return (0);
+  return (1);
+}
+
+/* check whether value for $dsn_notify would be valid */
+static int check_dsn_notify (const char* val) {
+  list2_t* list = NULL;
+  int i = 0, rc = 1;
+
+  if (!val || !*val)
+    return (1);
+  list = list_from_str (val, ",");
+  if (list_empty (list))
+    return (1);
+
+  for (i = 0; i < list->length; i++)
+    if (str_ncmp (list->data[i], "never", 5) != 0 &&
+        str_ncmp (list->data[i], "failure", 7) != 0 &&
+        str_ncmp (list->data[i], "delay", 5) != 0 &&
+        str_ncmp (list->data[i], "success", 7) != 0) {
+      rc = 0;
+      break;
+    }
+  list_del (&list, (list_del_t*) _mem_free);
+  return (rc);
+}
+
+static int check_special (const char* name, const char* val) {
+  int i = 0;
+
+  for (i = 0; SpecialVars[i].name; i++) {
+    if (str_cmp (SpecialVars[i].name, name) == 0)
+      return (SpecialVars[i].check (val));
+  }
+  return (1);
+}
+
 static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
                       BUFFER * err)
 {
@@ -1110,9 +1172,17 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
           *((char **) MuttVars[idx].data) = str_dup (scratch);
         }
         else if (DTYPE (MuttVars[idx].type) == DT_STR) {
-          *((char **) MuttVars[idx].data) = str_dup (tmp->data);
-          if (str_cmp (MuttVars[idx].option, "charset") == 0)
-            mutt_set_charset (Charset);
+          /* see if the value may only be a certain value... */
+          if (check_special (MuttVars[idx].option, tmp->data)) {
+            *((char **) MuttVars[idx].data) = str_dup (tmp->data);
+            if (str_cmp (MuttVars[idx].option, "charset") == 0)
+              mutt_set_charset (Charset);
+          } else {
+            /* ... and abort if it fails */
+            snprintf (err->data, err->dsize, "'%s' is invalid for $%s",
+                      tmp->data, MuttVars[idx].option);
+            return (-1);
+          }
         }
         else {
           *((ADDRESS **) MuttVars[idx].data) =
index a454c8f..1dd865f 100644 (file)
@@ -13,6 +13,7 @@
 #include "list.h"
 
 #include "mem.h"
+#include "str.h"
 
 list2_t* list_new (void) {
   return (mem_calloc (1, sizeof (list2_t)));
@@ -109,3 +110,19 @@ int list_lookup (list2_t* l, int (*cmp) (const void*, const void*), const void*
       return (i);
   return (-1);
 }
+
+list2_t* list_from_str (const char* str, const char* delim) {
+  list2_t* ret = NULL;
+  char* tmp = NULL, *p = NULL;
+
+  if (!str || !*str || !delim || !*delim)
+    return (NULL);
+
+  tmp = str_dup (str);
+  for (p = strtok (tmp, delim); p; p = strtok (NULL, delim)) {
+    list_push_back (&ret, str_dup (p));
+  }
+  mem_free (&tmp);
+  return (ret);
+}
+
index 20f4c60..1f409ea 100644 (file)
@@ -69,4 +69,9 @@ list2_t* list_dup (list2_t*, void* (*dup) (void*));
  */
 int list_lookup (list2_t*, int (*cmp) (const void*, const void*), const void*);
 
+/*
+ * dumb-splits string at boundary characters into list
+ */
+list2_t* list_from_str (const char* str, const char* delim);
+
 #endif /* !_LIB_LIST_H */
index 31a4b8e..7b3ada3 100644 (file)
@@ -279,13 +279,22 @@ static void do_dsn_ret (smtp_message_t message) {
     smtp_dsn_set_ret (message, Ret_FULL);
 }
 
+#if defined (USE_LIBESMTP) && (defined (USE_SSL) || defined (USE_GNUTLS))
+int mutt_libesmtp_check_usetls (const char* val) {
+  if (str_ncmp (val, "enabled", 7) != 0 &&
+      str_ncmp (val, "required", 8) != 0)
+    return (0);
+  return (1);
+}
+#endif
+
 /*
- * mutt_invoke_libesmtp
+ * mutt_libesmtp_invoke
  *   Sends a mail message to the provided recipients using libesmtp.
  *   Returns 0 upon success, -1 upon failure (and prints an error
  *   message).
  */
-int mutt_invoke_libesmtp (ADDRESS * from,       /* the sender */
+int mutt_libesmtp_invoke (ADDRESS * from,       /* the sender */
                           ADDRESS * to, ADDRESS * cc, ADDRESS * bcc,    /* recips */
                           const char *msg,      /* file containing message */
                           int eightbit)
index d813b3a..99d67da 100644 (file)
@@ -7,12 +7,16 @@
  * please see the file GPL in the top level source directory.
  */
 
-#if !defined(LIBESMTP_H)
-#define LIBESMTP_H
+#ifndef _MUTT_LIBESMTP_H
+#define _MUTT_LIBESMTP_H
 
-int mutt_invoke_libesmtp (ADDRESS * from,       /* the sender */
+#if defined (USE_LIBESMTP) && (defined (USE_SSL) || defined (USE_GNUTLS))
+int mutt_libesmtp_check_usetls (const char*);
+#endif
+
+int mutt_libesmtp_invoke (ADDRESS * from,       /* the sender */
                           ADDRESS * to, ADDRESS * cc, ADDRESS * bcc,    /* recips */
                           const char *msg,      /* file containing message */
                           int eightbit);        /* message contains 8bit chars */
 
-#endif /* !defined(LIBESMTP_H) */
+#endif /* !_MUTT_LIBESMTP_H */
index 0c1757b..05191c9 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2079,7 +2079,7 @@ int mutt_invoke_mta (ADDRESS * from,    /* the sender */
 {                               /* message contains 8bit chars */
 #ifdef USE_LIBESMTP
   if (SmtpHost)
-    return mutt_invoke_libesmtp (from, to, cc, bcc, msg, eightbit);
+    return mutt_libesmtp_invoke (from, to, cc, bcc, msg, eightbit);
 #endif
 
   return mutt_invoke_sendmail (from, to, cc, bcc, msg, eightbit);