Commit 686a7344 686a73448881868fbbf0a6d9d83fa3fc6fc692af by Sergey Poznyakoff

New `mu' mode: wicket.

* mu/wicket.c: New file.
* mu/mu.h (mutool_wicket): New proto.
* mu/mu.c (mutool_action_tab): Add an entry for wicket mode.
* mu/Makefile.am (mu_SOURCES): Add wicket.c
* .gitignore: Update.
1 parent be1380d7
......@@ -23,6 +23,7 @@ config.h.in
config.log
config.status
configure
core
git-describe
git-describe.h
libtool
......
......@@ -32,7 +32,8 @@ mu_SOURCES = \
flt2047.c\
$(POP_C)\
query.c\
shell.c
shell.c\
wicket.c
mu_LDADD = \
${MU_APP_LIBRARIES}\
......
......@@ -33,6 +33,7 @@ Commands are:\n\
mu filter - filter program\n\
mu 2047 - decode/encode message headers as per RFC 2047\n\
mu acl - test access control lists\n\
mu wicket - find matching URL in wicket\n\
\n\
Try `mu COMMAND --help' to get help on a particular COMMAND.\n\
\n\
......@@ -106,6 +107,7 @@ struct mutool_action_tab mutool_action_tab[] = {
{ "2047", mutool_flt2047 },
{ "query", mutool_query },
{ "acl", mutool_acl },
{ "wicket", mutool_wicket },
{ NULL }
};
......
......@@ -35,6 +35,7 @@ int mutool_flt2047 (int argc, char **argv);
int mutool_info (int argc, char **argv);
int mutool_query (int argc, char **argv);
int mutool_acl (int argc, char **argv);
int mutool_wicket (int argc, char **argv);
extern char *mutool_shell_prompt;
extern mu_vartab_t mutool_prompt_vartab;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 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/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <mailutils/mailutils.h>
#include <mailutils/libcfg.h>
#include <argp.h>
static char wicket_doc[] = N_("mu wicket - find matching URL in wicket");
static char wicket_args_doc[] = N_("NAME");
static struct argp_option wicket_options[] = {
{ "file", 'f', N_("FILE"), 0, N_("use FILE instead of ~/.mu-tickets") },
{ "verbose", 'v', NULL, 0, N_("increase output verbosity") },
{ "quiet", 'q', NULL, 0, N_("suppress any output") },
{ NULL }
};
static char *wicket_file = "~/.mu-tickets";
static int wicket_verbose = 1;
static error_t
wicket_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'f':
wicket_file = arg;
break;
case 'v':
wicket_verbose++;
break;
case 'q':
wicket_verbose = 0;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp wicket_argp = {
wicket_options,
wicket_parse_opt,
wicket_args_doc,
wicket_doc,
NULL,
NULL,
NULL
};
static int
wicket_match (mu_stream_t stream, const char *str)
{
int rc, ret;
mu_url_t u, url;
struct mu_debug_locus loc;
rc = mu_url_create (&u, str);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_url_create", str, rc);
return 2;
}
rc = mu_url_parse (u);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_url_parse", str, rc);
return 2;
}
rc = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_stream_seek", "0", rc);
return 2;
}
loc.file = wicket_file;
loc.line = 0;
rc = mu_wicket_stream_match_url (stream, &loc, u, &url);
switch (rc)
{
case 0:
ret = 0;
if (wicket_verbose)
{
printf ("%s: %s:%d", str, loc.file, loc.line);
if (wicket_verbose > 1)
{
printf (": %s", mu_url_to_string (url));
if (wicket_verbose > 2)
{
mu_secret_t s;
rc = mu_url_get_secret (url, &s);
if (rc == 0)
{
printf (": %s", mu_secret_password (s));
mu_secret_password_unref (s);
mu_secret_unref (s);
}
else if (rc == MU_ERR_NOENT)
printf (": [%s]", _("no password"));
else
{
printf (": [error: %s]", mu_strerror (rc));
ret = 2;
}
}
}
putchar ('\n');
}
break;
case MU_ERR_NOENT:
if (wicket_verbose)
printf ("%s: %s\n", str, _("not found"));
ret = 1;
break;
default:
mu_diag_funcall (MU_DIAG_ERROR, "mu_wicket_stream_match_url", str, rc);
ret = 2;
}
return ret;
}
int
mutool_wicket (int argc, char **argv)
{
mu_stream_t stream;
int rc, i, exit_code;
if (argp_parse (&wicket_argp, argc, argv, ARGP_IN_ORDER, &i, NULL))
return 1;
argc -= i;
argv += i;
if (argc == 0)
{
mu_error (_("not enough arguments"));
return 1;
}
wicket_file = mu_tilde_expansion (wicket_file, "/", NULL);
if (!wicket_file)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_tilde_expansion", wicket_file,
ENOMEM);
return 2;
}
rc = mu_file_stream_create (&stream, wicket_file, MU_STREAM_READ);
if (rc)
{
mu_error (_("cannot open input file %s: %s"), wicket_file,
mu_strerror (rc));
return 1;
}
exit_code = 0;
for (i = 0; i < argc; i++)
{
rc = wicket_match (stream, argv[i]);
if (rc)
{
if (exit_code < rc)
exit_code = rc;
if (!wicket_verbose)
break;
}
}
mu_stream_destroy (&stream);
return exit_code;
}