chiark / gitweb /
proxy/tripe-mitm.c: Allow user control over the delimiter.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 13 Sep 2017 09:19:56 +0000 (10:19 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 28 Jun 2018 23:24:44 +0000 (00:24 +0100)
It turns out that `:' was a terrible choice given the syntax of IPv6
addresses.  I probably knew this at the time, even.

proxy/tripe-mitm.8.in
proxy/tripe-mitm.c

index cab0fb2b74cae87d498537d6090a0eb226d5036c..3a91258ce7a77fbd882e7be5ae1112ca18e88b54 100644 (file)
@@ -58,6 +58,9 @@ The command line contains a sequence of directives, each of which has
 the form
 .IB command : arg \c
 .BR : ...
+(The delimiter character can be changed using the
+.B \-d
+command-line option.)
 A list of directives can be stored in a file, one per line, and included
 using the
 .B include
@@ -76,6 +79,12 @@ successfully.
 .B "\-u, \-\-usage"
 Write a usage message to standard output, and exit successfully.
 .TP
+.BI "\-d, \-\-delimiter=" char
+Use
+.I char
+as the delimiter to separate argument names in directives, rather than
+.RB ` : '.
+.TP
 .BI "\-k, \-\-keyring=" file
 Read keys from
 .IR file .
@@ -85,6 +94,14 @@ in the current directory.
 .SS "Directives"
 A directive is ignored if it is empty, or if its first character is a
 .RB ` # '.
+Directives consist of a name followed by zero or more arguments,
+separated by a delimiter character.  The default delimiter is
+.RB ` : ',
+but this can be overridden using the
+.B \-d
+option (see above); this manual uses
+.RB ` : '
+consistently as the delimiter character.
 The following directives are recognized.
 .TP
 .BI peer: name : local-port : remote-addr : remote-port
index ab05a88215b16c72e20313605c517ab30f250e1a..2530f15118a99336a07825b7daba21afcff66b7e 100644 (file)
@@ -97,6 +97,7 @@ static peer peers[2];
 static unsigned npeer = 0;
 static key_file keys;
 static grand *rng;
+static const char *delim = ":";
 
 #define PASS(f, buf, sz) ((f) ? (f)->func((f), (buf), (sz)) : (void)0)
 #define RND(i) (rng->ops->range(rng, (i)))
@@ -568,11 +569,11 @@ static void parse(char *p)
   unsigned c = 0;
   const struct cmdtab *ct;
 
-  p = strtok(p, ":");
+  p = strtok(p, delim);
   if (!p || *p == '#') return;
   do {
     v[c++] = p;
-    p = strtok(0, ":");
+    p = strtok(0, delim);
   } while (p && c < AVMAX - 1);
   v[c] = 0;
   for (ct = cmdtab; ct->name; ct++) {
@@ -590,7 +591,7 @@ static void version(FILE *fp)
   { pquis(fp, "$, TrIPE version " VERSION "\n"); }
 
 static void usage(FILE *fp)
-  { pquis(fp, "Usage: $ [-k KEYRING] DIRECTIVE...\n"); }
+  { pquis(fp, "Usage: $ [-d CHAR] [-k KEYRING] DIRECTIVE...\n"); }
 
 static void help(FILE *fp)
 {
@@ -604,6 +605,7 @@ Options:\n\
 -v, --version          Show the version number.\n\
 -u, --usage            Show terse usage summary.\n\
 \n\
+-d, --delimiter=CHAR   Use CHAR rather than `:' as delimiter.\n\
 -k, --keyring=FILE     Fetch keys from FILE.\n\
 \n\
 Directives:\n\
@@ -638,14 +640,20 @@ int main(int argc, char *argv[])
       { "help",                0,              0,      'h' },
       { "version",     0,              0,      'v' },
       { "usage",       0,              0,      'u' },
+      { "delimiter",   OPTF_ARGREQ,    0,      'd' },
       { "keyring",     OPTF_ARGREQ,    0,      'k' },
       { 0,             0,              0,      0 }
     };
-    if ((i = mdwopt(argc, argv, "hvuk:", opt, 0, 0, 0)) < 0) break;
+    if ((i = mdwopt(argc, argv, "hvud:k:", opt, 0, 0, 0)) < 0) break;
     switch (i) {
       case 'h': help(stdout); exit(0);
       case 'v': version(stdout); exit(0);
       case 'u': usage(stdout); exit(0);
+      case 'd':
+       if (!optarg[0] || optarg[1])
+         die(1, "delimiter must be a single character");
+       delim = optarg;
+       break;
       case 'k': kfname = optarg; break;
       default: f |= f_bogus; break;
     }