summaryrefslogtreecommitdiff
path: root/parser.y
diff options
context:
space:
mode:
authorJosé Fonseca <jrfonseca@users.sourceforge.net>2003-10-04 23:31:05 +0000
committerJosé Fonseca <jrfonseca@users.sourceforge.net>2003-10-04 23:31:05 +0000
commitf8f226f65276f1c645eff2d6edb48c8d6caf2256 (patch)
treea87215ee0d45e96382569e79f246079e5baa277d /parser.y
parentc9aab90ba7b3b2974a51f5b4d7e422fbfca51ff4 (diff)
Version bump.
New 'default' keyword for indentities (Vitezslav Batrla). Documentation updates.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y45
1 files changed, 31 insertions, 14 deletions
diff --git a/parser.y b/parser.y
index 61eb173..fdbb769 100644
--- a/parser.y
+++ b/parser.y
@@ -20,20 +20,33 @@
#include "xmalloc.h"
-/* parser reads these */
+/** Path name of dot file */
+static const char *rcfile = NULL;
-static const char *rcfile = NULL; /* path name of dot file */
-
-/* parser sets these */
-int yydebug; /* in case we didn't generate with -- debug */
+int yydebug; /**< in case we didn't generate with -- debug */
static identity_t *identity = NULL;
+/**
+ * Utility macro to set the default identity, if one isn't set yet.
+ *
+ * It's necessary for compatability with older configurations files where the
+ * default identity was defined in a global section, instead of defined by the
+ * 'default' or the first defined identity, if no 'default' keyword is given.
+ */
+#define SET_DEFAULT_IDENTITY \
+do { \
+ if(!default_identity) \
+ default_identity = identity; \
+} while(0)
+
/* using Bison, this arranges that yydebug messages will show actual tokens */
extern char * yytext;
#define YYPRINT(fp, type, val) fprintf(fp, " = \"%s\"", yytext)
void yyerror (const char *s);
+
+
%}
%union {
@@ -41,7 +54,7 @@ void yyerror (const char *s);
char *sval;
}
-%token IDENTITY HOSTNAME USERNAME PASSWORD STARTTLS CERTIFICATE_PASSPHRASE MDA
+%token IDENTITY DEFAULT HOSTNAME USERNAME PASSWORD STARTTLS CERTIFICATE_PASSPHRASE MDA
%token MAP
@@ -80,14 +93,15 @@ statement_list : statement
;
/* future global options should also have the form SET <name> optmap <value> */
-statement : HOSTNAME map STRING { identity->host = xstrdup($3); }
- | USERNAME map STRING { identity->user = xstrdup($3); }
- | PASSWORD map STRING { identity->pass = xstrdup($3); }
- | STARTTLS map DISABLED { identity->starttls = Starttls_DISABLED; }
- | STARTTLS map ENABLED { identity->starttls = Starttls_ENABLED; }
- | STARTTLS map REQUIRED { identity->starttls = Starttls_REQUIRED; }
- | CERTIFICATE_PASSPHRASE map STRING { identity->certificate_passphrase = xstrdup($3); }
+statement : HOSTNAME map STRING { identity->host = xstrdup($3); SET_DEFAULT_IDENTITY; }
+ | USERNAME map STRING { identity->user = xstrdup($3); SET_DEFAULT_IDENTITY; }
+ | PASSWORD map STRING { identity->pass = xstrdup($3); SET_DEFAULT_IDENTITY; }
+ | STARTTLS map DISABLED { identity->starttls = Starttls_DISABLED; SET_DEFAULT_IDENTITY; }
+ | STARTTLS map ENABLED { identity->starttls = Starttls_ENABLED; SET_DEFAULT_IDENTITY; }
+ | STARTTLS map REQUIRED { identity->starttls = Starttls_REQUIRED; SET_DEFAULT_IDENTITY; }
+ | CERTIFICATE_PASSPHRASE map STRING { identity->certificate_passphrase = xstrdup($3); SET_DEFAULT_IDENTITY; }
| MDA map STRING { mda = xstrdup($3); }
+ | DEFAULT { default_identity = identity; }
;
%%
@@ -174,10 +188,13 @@ void rcfile_parse(const char *_rcfile)
success:
/* Configuration file opened */
- identity = default_identity;
+ identity = identity_new();
+ identity_add(identity);
yyparse(); /* parse entire file */
+ SET_DEFAULT_IDENTITY;
+
fclose(yyin); /* not checking this should be safe, file mode was r */
rcfile = NULL;