1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010-2025 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 <mailutils/mailutils.h>
#include "mu.h"
char wicket_docstring[] = N_("scan wickets for matching URLs");
static char wicket_args_doc[] = N_("URL");
static char *wicket_file = "~/.mu-tickets";
static int wicket_verbose = 1;
static void
clear_wicket_verbose (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
wicket_verbose = 0;
}
static struct mu_option wicket_options[] = {
{ "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
N_("use FILE instead of ~/.mu-tickets"),
mu_c_string, &wicket_file },
{ "verbose", 'v', NULL, MU_OPTION_DEFAULT,
N_("increase output verbosity"),
mu_c_string, &wicket_verbose },
{ "quiet", 'q', NULL, MU_OPTION_DEFAULT,
N_("suppress any output"),
mu_c_string, NULL, clear_wicket_verbose },
{ NULL }
};
static int
wicket_match (mu_stream_t stream, const char *str)
{
int rc, ret;
mu_url_t u, url;
struct mu_locus_point loc;
int flags = MU_URL_PARSE_ALL;
if (wicket_verbose > 2)
flags &= ~MU_URL_PARSE_HIDEPASS;
rc = mu_url_create (&u, str);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_url_create", 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.mu_file = wicket_file;
loc.mu_line = 0;
rc = mu_wicket_stream_match_url (stream, &loc, u, flags, &url);
switch (rc)
{
case 0:
ret = 0;
if (wicket_verbose)
{
mu_printf ("%s: %s:%d", str, loc.mu_file, loc.mu_line);
if (wicket_verbose > 1)
mu_printf (": %s", mu_url_to_string (url));
mu_printf ("\n");
}
break;
case MU_ERR_NOENT:
if (wicket_verbose)
mu_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
main (int argc, char **argv)
{
mu_stream_t stream;
int rc, i, exit_code;
mu_action_getopt (&argc, &argv, wicket_options, wicket_docstring,
wicket_args_doc);
if (argc == 0)
{
mu_error (_("not enough arguments"));
return 1;
}
wicket_file = mu_tilde_expansion (wicket_file, MU_HIERARCHY_DELIMITER, 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;
}
|