Commit 3327a23a 3327a23a49e532c068972a0b2d64021361540f7b by Sergey Poznyakoff

Rewrite URL support.

The purpose is to make it modular and flexible.  URLs are
parsed out as they are created.  Missing URL parts can be
supplied via a "URL hint" at creation time (similar to
the approach used in creating mu_address_t).  Ports
can be specified either as numbers or as service names.
Original port string representation can be retrieved from
the URL, as well as its numeric value.

* libmailutils/url/accessor.h: New file.
* libmailutils/url/copy.c: New file.
* libmailutils/url/create.c: New file.
* libmailutils/url/decode.c: New file.
* libmailutils/url/destroy.c: New file.
* libmailutils/url/dup.c: New file.
* libmailutils/url/expand.c: New file.
* libmailutils/url/flag.c: New file.
* libmailutils/url/get-auth.c: New file.
* libmailutils/url/get-host.c: New file.
* libmailutils/url/get-param.c: New file.
* libmailutils/url/get-path.c: New file.
* libmailutils/url/get-portstr.c: New file.
* libmailutils/url/get-query.c: New file.
* libmailutils/url/get-scheme.c: New file.
* libmailutils/url/get-secret.c: New file.
* libmailutils/url/get-user.c: New file.
* libmailutils/url/match.c: New file.
* libmailutils/url/port.c: New file.
* libmailutils/url/scheme.c: New file.
* libmailutils/url/uplevel.c: New file.
* libmailutils/url/urlstr.c: New file.

* configure.ac (AC_CONFIG_FILES): Add libmailutils/url/Makefile
* libmailutils/Makefile.am (SUBDIRS): Add url.
(libmailutils_la_LIBADD): Link with liburl.
* libmailutils/base/Makefile.am (libbase_la_SOURCES): Remove url.c
* libmailutils/base/url.c: Remove.

* libmailutils/string/Makefile.am (libstring_la_SOURCES): Add xdecode.c
* libmailutils/string/xdecode.c: New file.

* include/mailutils/sys/url.h (_mu_url): Change type to short.
<_get_port>: Change second argument to unsigned.
<_get_portstr>: New method.
* include/mailutils/url.h (MU_URL_SCHEME): New flag.
(MU_URL_PARSE_HEXCODE, MU_URL_PARSE_HIDEPASS)
(MU_URL_PARSE_PORTSRV, MU_URL_PARSE_PORTWC)
(MU_URL_PARSE_PIPE, MU_URL_PARSE_SLASH): New flags.
(mu_url_create_hint, mu_url_copy_hints): New prototypes.
(mu_url_parse): Remove.
(mu_url_get_port): Change second argument to unsigned.
(mu_url_decode_len,mu_url_decode): Remove.
(mu_url_decode): New proto.
(mu_url_sget_portstr, mu_url_aget_portstr)
(mu_url_get_portstr): New protos.

* include/mailutils/util.h (mu_str_url_decode)
(mu_str_url_decode_inline): New protos.
* libproto/pop/mbox.c (pop_open): Port is unsigned.

* libproto/imap/folder.c: Use MU_URL_SCHEME in url_may_have.
* libproto/maildir/folder.c: Likewise.
* libproto/mailer/prog.c: Likewise.
* libproto/mailer/remote.c: Likewise.
* libproto/mailer/sendmail.c: Likewise.
* libproto/mailer/smtp.c: Likewise.
* libproto/mbox/folder.c: Likewise.
* libproto/mh/folder.c: Likewise.
* libproto/nntp/folder.c: Likewise.
* libproto/pop/folder.c: Likewise.

* imap4d/imap4d.c: Remove calls to mu_url_parse.
* libmailutils/base/registrar.c: Likewise.
* libmailutils/base/wicket.c: Likewise.
* libmailutils/mailbox/folder.c: Likewise.
* libmailutils/mailbox/mailbox.c: Likewise.
* libmailutils/mailer/mailer.c: Likewise.
* libmailutils/tests/url-parse.c: Likewise.
* libmailutils/tests/wicket.c: Likewise.
* libproto/mailer/smtp_auth.c: Likewise.
* maidag/deliver.c: Likewise.
* mu/wicket.c: Likewise.

* libmailutils/mime/mimehdr.c (mu_mimehdr_decode_param): Use
mu_str_url_decode, instead of mu_url_decode.
* libmailutils/stream/tcp.c (_tcp_instance)<port>: Change type
to unsigned short. All uses updated.
(mu_tcp_stream_create_with_source_ip)
(mu_tcp_stream_create_with_source_host)
(mu_tcp_stream_create): Port is unsigned.
* include/mailutils/stream.h (mu_tcp_stream_create_with_source_ip)
(mu_tcp_stream_create_with_source_host)
(mu_tcp_stream_create): Port is unsigned.
* include/mailutils/cpp/url.h (get_port): Return unsigned.
* libmu_cpp/url.cc (get_port): Return unsigned.
(parse): Empty function. Schedule for removal.
* python/libmu_py/url.c (api_url_parse): Empty function.
Schedule for removal.
(api_url_get_port): Port is unsigned.

* libmailutils/base/wicket.c (mu_wicket_file_match_url)
(mu_wicket_file_match_url): New parameter: parse_flags.
* mu/wicket.c (wicket_match): Use parse_flags to control
whether or not to show the plaintext password.

* doc/texinfo/url.texi: Update.
1 parent 6203ae65
Showing 62 changed files with 1601 additions and 166 deletions
...@@ -1387,6 +1387,7 @@ AC_CONFIG_FILES([ ...@@ -1387,6 +1387,7 @@ AC_CONFIG_FILES([
1387 libmailutils/server/Makefile 1387 libmailutils/server/Makefile
1388 libmailutils/string/Makefile 1388 libmailutils/string/Makefile
1389 libmailutils/stream/Makefile 1389 libmailutils/stream/Makefile
1390 libmailutils/url/Makefile
1390 libmailutils/Makefile 1391 libmailutils/Makefile
1391 messages/Makefile 1392 messages/Makefile
1392 mh/Makefile 1393 mh/Makefile
......
...@@ -186,7 +186,7 @@ for any particular scheme. ...@@ -186,7 +186,7 @@ for any particular scheme.
186 @deftypefun int mu_url_get_host (const mu_url_t, char *, size_t, size_t *) 186 @deftypefun int mu_url_get_host (const mu_url_t, char *, size_t, size_t *)
187 @end deftypefun 187 @end deftypefun
188 188
189 @deftypefun int mu_url_get_port (const mu_url_t, long *) 189 @deftypefun int mu_url_get_port (const mu_url_t, unsigned *)
190 @end deftypefun 190 @end deftypefun
191 191
192 @deftypefun int mu_url_get_path (const mu_url_t, char *, size_t, size_t *) 192 @deftypefun int mu_url_get_path (const mu_url_t, char *, size_t, size_t *)
......
...@@ -172,7 +172,7 @@ parse_preauth_scheme (mu_debug_t debug, const char *scheme, mu_url_t url) ...@@ -172,7 +172,7 @@ parse_preauth_scheme (mu_debug_t debug, const char *scheme, mu_url_t url)
172 else if (strcmp (scheme, "ident") == 0) 172 else if (strcmp (scheme, "ident") == 0)
173 { 173 {
174 struct servent *sp; 174 struct servent *sp;
175 long n; 175 unsigned n;
176 if (url && mu_url_get_port (url, &n) == 0) 176 if (url && mu_url_get_port (url, &n) == 0)
177 ident_port = (short) n; 177 ident_port = (short) n;
178 else if ((sp = getservbyname ("auth", "tcp"))) 178 else if ((sp = getservbyname ("auth", "tcp")))
...@@ -219,13 +219,6 @@ cb_preauth (mu_debug_t debug, void *data, mu_config_value_t *val) ...@@ -219,13 +219,6 @@ cb_preauth (mu_debug_t debug, void *data, mu_config_value_t *val)
219 mu_diag_funcall (MU_DIAG_ERROR, "mu_url_create", val->v.string, rc); 219 mu_diag_funcall (MU_DIAG_ERROR, "mu_url_create", val->v.string, rc);
220 return 1; 220 return 1;
221 } 221 }
222 rc = mu_url_parse (url);
223 if (rc)
224 {
225 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
226 "%s: %s", val->v.string, mu_strerror (rc));
227 return 1;
228 }
229 222
230 rc = mu_url_aget_scheme (url, &scheme); 223 rc = mu_url_aget_scheme (url, &scheme);
231 if (rc) 224 if (rc)
......
...@@ -78,8 +78,10 @@ int mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename); ...@@ -78,8 +78,10 @@ int mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename);
78 78
79 struct mu_debug_locus; 79 struct mu_debug_locus;
80 int mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc, 80 int mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
81 mu_url_t url, mu_url_t *pticket_url); 81 mu_url_t url, int parse_flags,
82 mu_url_t *pticket_url);
82 int mu_wicket_file_match_url (const char *name, mu_url_t url, 83 int mu_wicket_file_match_url (const char *name, mu_url_t url,
84 int parse_flags,
83 mu_url_t *pticket_url); 85 mu_url_t *pticket_url);
84 86
85 87
......
...@@ -42,7 +42,7 @@ class Url ...@@ -42,7 +42,7 @@ class Url
42 ~Url (); 42 ~Url ();
43 43
44 void parse (); 44 void parse ();
45 long get_port (); 45 unsigned get_port ();
46 std::string get_scheme (); 46 std::string get_scheme ();
47 std::string get_user (); 47 std::string get_user ();
48 std::string get_auth (); 48 std::string get_auth ();
......
...@@ -176,14 +176,14 @@ int mu_streamref_create_abridged (mu_stream_t *pref, mu_stream_t str, ...@@ -176,14 +176,14 @@ int mu_streamref_create_abridged (mu_stream_t *pref, mu_stream_t str,
176 int mu_streamref_create (mu_stream_t *pref, mu_stream_t str); 176 int mu_streamref_create (mu_stream_t *pref, mu_stream_t str);
177 177
178 int mu_tcp_stream_create_with_source_ip (mu_stream_t *stream, 178 int mu_tcp_stream_create_with_source_ip (mu_stream_t *stream,
179 const char *host, int port, 179 const char *host, unsigned port,
180 unsigned long source_ip, 180 unsigned long source_ip,
181 int flags); 181 int flags);
182 int mu_tcp_stream_create_with_source_host (mu_stream_t *stream, 182 int mu_tcp_stream_create_with_source_host (mu_stream_t *stream,
183 const char *host, int port, 183 const char *host, unsigned port,
184 const char *source_host, 184 const char *source_host,
185 int flags); 185 int flags);
186 int mu_tcp_stream_create (mu_stream_t *stream, const char *host, int port, 186 int mu_tcp_stream_create (mu_stream_t *stream, const char *host, unsigned port,
187 int flags); 187 int flags);
188 188
189 /* Transcript output levels */ 189 /* Transcript output levels */
......
...@@ -35,7 +35,8 @@ struct _mu_url ...@@ -35,7 +35,8 @@ struct _mu_url
35 mu_secret_t secret; 35 mu_secret_t secret;
36 char *auth; 36 char *auth;
37 char *host; 37 char *host;
38 long port; 38 short port;
39 char *portstr;
39 char *path; 40 char *path;
40 char **fvpairs; 41 char **fvpairs;
41 int fvcount; 42 int fvcount;
...@@ -53,7 +54,8 @@ struct _mu_url ...@@ -53,7 +54,8 @@ struct _mu_url
53 int (*_get_secret) (const mu_url_t, mu_secret_t *); 54 int (*_get_secret) (const mu_url_t, mu_secret_t *);
54 int (*_get_auth) (const mu_url_t, char *, size_t, size_t *); 55 int (*_get_auth) (const mu_url_t, char *, size_t, size_t *);
55 int (*_get_host) (const mu_url_t, char *, size_t, size_t *); 56 int (*_get_host) (const mu_url_t, char *, size_t, size_t *);
56 int (*_get_port) (const mu_url_t, long *); 57 int (*_get_port) (const mu_url_t, unsigned *);
58 int (*_get_portstr)(const mu_url_t, char *, size_t, size_t *);
57 int (*_get_path) (const mu_url_t, char *, size_t, size_t *); 59 int (*_get_path) (const mu_url_t, char *, size_t, size_t *);
58 int (*_get_query) (const mu_url_t, char *, size_t, size_t *); 60 int (*_get_query) (const mu_url_t, char *, size_t, size_t *);
59 int (*_uplevel) (const mu_url_t, mu_url_t *); 61 int (*_uplevel) (const mu_url_t, mu_url_t *);
......
...@@ -25,14 +25,15 @@ ...@@ -25,14 +25,15 @@
25 extern "C" { 25 extern "C" {
26 #endif 26 #endif
27 27
28 #define MU_URL_USER 0x0001 /* Has a user part */ 28 #define MU_URL_SCHEME 0x0001
29 #define MU_URL_SECRET 0x0002 /* Has a secret (password) part */ 29 #define MU_URL_USER 0x0002 /* Has a user part */
30 #define MU_URL_AUTH 0x0004 /* Has auth part */ 30 #define MU_URL_SECRET 0x0004 /* Has a secret (password) part */
31 #define MU_URL_HOST 0x0008 /* Has host part */ 31 #define MU_URL_AUTH 0x0008 /* Has auth part */
32 #define MU_URL_PORT 0x0010 /* Has port part */ 32 #define MU_URL_HOST 0x0010 /* Has host part */
33 #define MU_URL_PATH 0x0020 /* Has path */ 33 #define MU_URL_PORT 0x0020 /* Has port part */
34 #define MU_URL_PARAM 0x0040 /* Has parameters */ 34 #define MU_URL_PATH 0x0040 /* Has path */
35 #define MU_URL_QUERY 0x0080 /* Has query */ 35 #define MU_URL_PARAM 0x0080 /* Has parameters */
36 #define MU_URL_QUERY 0x0100 /* Has query */
36 37
37 #define MU_URL_CRED (MU_URL_USER | MU_URL_SECRET | MU_URL_AUTH) 38 #define MU_URL_CRED (MU_URL_USER | MU_URL_SECRET | MU_URL_AUTH)
38 /* Has some of authentication credentials */ 39 /* Has some of authentication credentials */
...@@ -45,6 +46,28 @@ extern "C" { ...@@ -45,6 +46,28 @@ extern "C" {
45 MU_URL_PARAM | \ 46 MU_URL_PARAM | \
46 MU_URL_QUERY) 47 MU_URL_QUERY)
47 48
49 /* Parser flags */
50 #define MU_URL_PARSE_HEXCODE 0x0001 /* Decode % notations (RFC 1738,
51 section 2.2) */
52 #define MU_URL_PARSE_HIDEPASS 0x0002 /* Hide password in the URL */
53 #define MU_URL_PARSE_PORTSRV 0x0004 /* Use getservbyname to determine
54 port number */
55 #define MU_URL_PARSE_PORTWC 0x0008 /* Allow wildcard (*) as a port
56 number (for tickets) */
57 #define MU_URL_PARSE_PIPE 0x0010 /* Translate "| ..." to
58 "prog://..." */
59 #define MU_URL_PARSE_SLASH 0x0020 /* Translate "/..." to
60 "file:///..." */
61
62 #define MU_URL_PARSE_DEFAULT \
63 (MU_URL_PARSE_HEXCODE|MU_URL_PARSE_HIDEPASS|MU_URL_PARSE_PORTSRV|\
64 MU_URL_PARSE_PIPE|MU_URL_PARSE_SLASH)
65 #define MU_URL_PARSE_ALL (MU_URL_PARSE_DEFAULT|MU_URL_PARSE_PORTWC)
66
67 int mu_url_create_hint (mu_url_t *purl, const char *str, int flags,
68 mu_url_t hint);
69 int mu_url_copy_hints (mu_url_t url, mu_url_t hint);
70
48 int mu_url_create (mu_url_t *, const char *name); 71 int mu_url_create (mu_url_t *, const char *name);
49 int mu_url_dup (mu_url_t old_url, mu_url_t *new_url); 72 int mu_url_dup (mu_url_t old_url, mu_url_t *new_url);
50 int mu_url_uplevel (mu_url_t url, mu_url_t *upurl); 73 int mu_url_uplevel (mu_url_t url, mu_url_t *upurl);
...@@ -53,7 +76,6 @@ int mu_url_get_flags (mu_url_t, int *); ...@@ -53,7 +76,6 @@ int mu_url_get_flags (mu_url_t, int *);
53 int mu_url_has_flag (mu_url_t, int); 76 int mu_url_has_flag (mu_url_t, int);
54 77
55 void mu_url_destroy (mu_url_t *); 78 void mu_url_destroy (mu_url_t *);
56 int mu_url_parse (mu_url_t);
57 79
58 int mu_url_sget_scheme (const mu_url_t, const char **); 80 int mu_url_sget_scheme (const mu_url_t, const char **);
59 int mu_url_aget_scheme (const mu_url_t, char **); 81 int mu_url_aget_scheme (const mu_url_t, char **);
...@@ -80,7 +102,11 @@ int mu_url_get_path (const mu_url_t, char *, size_t, size_t *); ...@@ -80,7 +102,11 @@ int mu_url_get_path (const mu_url_t, char *, size_t, size_t *);
80 int mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv); 102 int mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv);
81 int mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv); 103 int mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv);
82 104
83 int mu_url_get_port (const mu_url_t, long *); 105 int mu_url_sget_portstr (const mu_url_t, const char **);
106 int mu_url_aget_portstr (const mu_url_t, char **);
107 int mu_url_get_portstr (const mu_url_t, char *, size_t, size_t *);
108
109 int mu_url_get_port (const mu_url_t, unsigned *);
84 110
85 int mu_url_sget_fvpairs (const mu_url_t url, size_t *fvc, char ***fvp); 111 int mu_url_sget_fvpairs (const mu_url_t url, size_t *fvc, char ***fvp);
86 int mu_url_aget_fvpairs (const mu_url_t url, size_t *pfvc, char ***pfvp); 112 int mu_url_aget_fvpairs (const mu_url_t url, size_t *pfvc, char ***pfvp);
...@@ -101,11 +127,9 @@ int mu_url_is_same_path (mu_url_t, mu_url_t); ...@@ -101,11 +127,9 @@ int mu_url_is_same_path (mu_url_t, mu_url_t);
101 int mu_url_is_same_host (mu_url_t, mu_url_t); 127 int mu_url_is_same_host (mu_url_t, mu_url_t);
102 int mu_url_is_same_port (mu_url_t, mu_url_t); 128 int mu_url_is_same_port (mu_url_t, mu_url_t);
103 129
104 char *mu_url_decode_len (const char *s, size_t len);
105 char *mu_url_decode (const char *s);
106
107 int mu_url_matches_ticket (mu_url_t ticket, mu_url_t url, int *wcn); 130 int mu_url_matches_ticket (mu_url_t ticket, mu_url_t url, int *wcn);
108 int mu_url_init (mu_url_t url, int port, const char *scheme); 131
132 int mu_url_decode (mu_url_t url);
109 133
110 #ifdef __cplusplus 134 #ifdef __cplusplus
111 } 135 }
......
...@@ -42,7 +42,8 @@ int mu_unre_set_regex (const char *str, int caseflag, char **errp); ...@@ -42,7 +42,8 @@ int mu_unre_set_regex (const char *str, int caseflag, char **errp);
42 int mu_unre_subject (const char *subject, const char **new_subject); 42 int mu_unre_subject (const char *subject, const char **new_subject);
43 int mu_is_proto (const char *p); 43 int mu_is_proto (const char *p);
44 int mu_mh_delim (const char *str); 44 int mu_mh_delim (const char *str);
45 45 void mu_str_url_decode_inline (char *str);
46 int mu_str_url_decode (char **ptr, const char *s);
46 47
47 /* ----------------------- */ 48 /* ----------------------- */
48 /* Date & time functions */ 49 /* Date & time functions */
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 # <http://www.gnu.org/licenses/>. 17 # <http://www.gnu.org/licenses/>.
18 18
19 SUBDIRS = auth base address cfg diag filter mailbox mailer mime\ 19 SUBDIRS = auth base address cfg diag filter mailbox mailer mime\
20 server string stream . tests 20 server string stream url . tests
21 21
22 lib_LTLIBRARIES = libmailutils.la 22 lib_LTLIBRARIES = libmailutils.la
23 23
...@@ -36,7 +36,8 @@ libmailutils_la_LIBADD = \ ...@@ -36,7 +36,8 @@ libmailutils_la_LIBADD = \
36 mime/libmime.la\ 36 mime/libmime.la\
37 server/libserver.la\ 37 server/libserver.la\
38 string/libstring.la\ 38 string/libstring.la\
39 stream/libstream.la 39 stream/libstream.la\
40 url/liburl.la
40 41
41 libmailutils_la_LDFLAGS = -version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@ 42 libmailutils_la_LDFLAGS = -version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
42 43
......
...@@ -61,7 +61,6 @@ libbase_la_SOURCES = \ ...@@ -61,7 +61,6 @@ libbase_la_SOURCES = \
61 tempfile.c\ 61 tempfile.c\
62 ticket.c\ 62 ticket.c\
63 tilde.c\ 63 tilde.c\
64 url.c\
65 usremail.c\ 64 usremail.c\
66 vartab.c\ 65 vartab.c\
67 version.c\ 66 version.c\
......
...@@ -220,9 +220,7 @@ mu_registrar_lookup (const char *name, int flags, ...@@ -220,9 +220,7 @@ mu_registrar_lookup (const char *name, int flags,
220 rc = mu_url_create (&url, name); 220 rc = mu_url_create (&url, name);
221 if (rc) 221 if (rc)
222 return rc; 222 return rc;
223 rc = mu_url_parse (url); 223 rc = mu_registrar_lookup_url (url, flags, precord, pflags);
224 if (rc == 0)
225 rc = mu_registrar_lookup_url (url, flags, precord, pflags);
226 mu_url_destroy (&url); 224 mu_url_destroy (&url);
227 return rc; 225 return rc;
228 } 226 }
......
...@@ -180,7 +180,9 @@ file_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge, ...@@ -180,7 +180,9 @@ file_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
180 180
181 if (!ft->tickurl) 181 if (!ft->tickurl)
182 { 182 {
183 int rc = mu_wicket_file_match_url (ft->filename, url, &ft->tickurl); 183 int rc = mu_wicket_file_match_url (ft->filename, url,
184 MU_URL_PARSE_ALL,
185 &ft->tickurl);
184 if (rc) 186 if (rc)
185 return rc; 187 return rc;
186 } 188 }
...@@ -245,7 +247,8 @@ _file_wicket_get_ticket (mu_wicket_t wicket, void *data, ...@@ -245,7 +247,8 @@ _file_wicket_get_ticket (mu_wicket_t wicket, void *data,
245 247
246 int 248 int
247 mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc, 249 mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
248 mu_url_t url, mu_url_t *pticket_url) 250 mu_url_t url, int parse_flags,
251 mu_url_t *pticket_url)
249 { 252 {
250 int rc; 253 int rc;
251 mu_url_t u = NULL; 254 mu_url_t u = NULL;
...@@ -270,20 +273,13 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc, ...@@ -270,20 +273,13 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
270 if (*p == 0 || *p == '#') 273 if (*p == 0 || *p == '#')
271 continue; 274 continue;
272 275
273 if ((err = mu_url_create (&u, p)) != 0) 276 if ((err = mu_url_create_hint (&u, p, parse_flags, NULL)) != 0)
274 { 277 {
275 /* Skip erroneous entry */ 278 /* Skip erroneous entry */
276 mu_error (_("%s:%u: cannot create URL: %s"), 279 mu_error (_("%s:%u: cannot create URL: %s"),
277 loc->file, loc->line, mu_strerror (err)); 280 loc->file, loc->line, mu_strerror (err));
278 continue; 281 continue;
279 } 282 }
280 if ((err = mu_url_parse (u)) != 0)
281 {
282 mu_error (_("%s:%u: cannot parse URL: %s"),
283 loc->file, loc->line, mu_strerror (err));
284 mu_url_destroy (&u);
285 continue;
286 }
287 283
288 if (!mu_url_has_flag (u, MU_URL_USER|MU_URL_SECRET)) 284 if (!mu_url_has_flag (u, MU_URL_USER|MU_URL_SECRET))
289 { 285 {
...@@ -326,6 +322,7 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc, ...@@ -326,6 +322,7 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
326 322
327 int 323 int
328 mu_wicket_file_match_url (const char *name, mu_url_t url, 324 mu_wicket_file_match_url (const char *name, mu_url_t url,
325 int parse_flags,
329 mu_url_t *pticket_url) 326 mu_url_t *pticket_url)
330 { 327 {
331 mu_stream_t stream; 328 mu_stream_t stream;
...@@ -337,7 +334,8 @@ mu_wicket_file_match_url (const char *name, mu_url_t url, ...@@ -337,7 +334,8 @@ mu_wicket_file_match_url (const char *name, mu_url_t url,
337 return rc; 334 return rc;
338 loc.file = name; 335 loc.file = name;
339 loc.line = 0; 336 loc.line = 0;
340 rc = mu_wicket_stream_match_url (stream, &loc, url, pticket_url); 337 rc = mu_wicket_stream_match_url (stream, &loc, url, parse_flags,
338 pticket_url);
341 mu_stream_close (stream); 339 mu_stream_close (stream);
342 mu_stream_destroy (&stream); 340 mu_stream_destroy (&stream);
343 return rc; 341 return rc;
......
...@@ -157,9 +157,7 @@ mu_folder_create (mu_folder_t *pfolder, const char *name) ...@@ -157,9 +157,7 @@ mu_folder_create (mu_folder_t *pfolder, const char *name)
157 rc = mu_url_create (&url, name); 157 rc = mu_url_create (&url, name);
158 if (rc) 158 if (rc)
159 return rc; 159 return rc;
160 rc = mu_url_parse (url); 160 rc = mu_folder_create_from_record (pfolder, url, NULL);
161 if (rc == 0)
162 rc = mu_folder_create_from_record (pfolder, url, NULL);
163 if (rc) 161 if (rc)
164 mu_url_destroy (&url); 162 mu_url_destroy (&url);
165 return rc; 163 return rc;
......
...@@ -185,9 +185,7 @@ _create_mailbox (mu_mailbox_t *pmbox, const char *name) ...@@ -185,9 +185,7 @@ _create_mailbox (mu_mailbox_t *pmbox, const char *name)
185 status = mu_url_create (&url, name); 185 status = mu_url_create (&url, name);
186 if (status) 186 if (status)
187 return status; 187 return status;
188 status = mu_url_parse (url); 188 status = _create_mailbox0 (pmbox, url, name);
189 if (status == 0)
190 status = _create_mailbox0 (pmbox, url, name);
191 if (status) 189 if (status)
192 mu_url_destroy (&url); 190 mu_url_destroy (&url);
193 return status; 191 return status;
...@@ -224,9 +222,7 @@ mu_mailbox_create_from_record (mu_mailbox_t *pmbox, mu_record_t record, ...@@ -224,9 +222,7 @@ mu_mailbox_create_from_record (mu_mailbox_t *pmbox, mu_record_t record,
224 rc = mu_url_create (&url, name); 222 rc = mu_url_create (&url, name);
225 if (rc) 223 if (rc)
226 return rc; 224 return rc;
227 rc = mu_url_parse (url); 225 rc = _mailbox_create_from_record (pmbox, record, url, name);
228 if (rc == 0)
229 rc = _mailbox_create_from_record (pmbox, record, url, name);
230 if (rc) 226 if (rc)
231 mu_url_destroy (&url); 227 mu_url_destroy (&url);
232 return rc; 228 return rc;
......
...@@ -168,9 +168,7 @@ mu_mailer_create (mu_mailer_t * pmailer, const char *name) ...@@ -168,9 +168,7 @@ mu_mailer_create (mu_mailer_t * pmailer, const char *name)
168 status = mu_url_create (&url, name); 168 status = mu_url_create (&url, name);
169 if (status) 169 if (status)
170 return status; 170 return status;
171 status = mu_url_parse (url); 171 status = mu_mailer_create_from_url (pmailer, url);
172 if (status == 0)
173 status = mu_mailer_create_from_url (pmailer, url);
174 if (status) 172 if (status)
175 mu_url_destroy (&url); 173 mu_url_destroy (&url);
176 return status; 174 return status;
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
29 #include <mailutils/message.h> 29 #include <mailutils/message.h>
30 #include <mailutils/header.h> 30 #include <mailutils/header.h>
31 #include <mailutils/stream.h> 31 #include <mailutils/stream.h>
32 #include <mailutils/url.h> /* FIXME: for mu_url_decode, which should
33 be renamed! */
34 #include <mailutils/mime.h> 32 #include <mailutils/mime.h>
35 #include <mailutils/filter.h> 33 #include <mailutils/filter.h>
36 #include <mailutils/util.h> 34 #include <mailutils/util.h>
...@@ -480,9 +478,9 @@ mu_mimehdr_decode_param (const char *value, int flags, ...@@ -480,9 +478,9 @@ mu_mimehdr_decode_param (const char *value, int flags,
480 } 478 }
481 else 479 else
482 { 480 {
483 decoded = mu_url_decode (value); 481 rc = mu_str_url_decode (&decoded, value);
484 if (!decoded) 482 if (rc)
485 return ENOMEM; 483 return rc;
486 484
487 if ((flags & MU_MIMEHDR_CSINFO) 485 if ((flags & MU_MIMEHDR_CSINFO)
488 && (lang = strchr (decoded, '\'')) 486 && (lang = strchr (decoded, '\''))
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
27 #include <stdlib.h> 27 #include <stdlib.h>
28 #include <string.h> 28 #include <string.h>
29 #include <unistd.h> 29 #include <unistd.h>
30 #include <limits.h>
30 31
31 #include <sys/socket.h> 32 #include <sys/socket.h>
32 #include <sys/types.h> 33 #include <sys/types.h>
...@@ -52,7 +53,7 @@ struct _tcp_instance ...@@ -52,7 +53,7 @@ struct _tcp_instance
52 struct _mu_stream stream; 53 struct _mu_stream stream;
53 int fd; 54 int fd;
54 char *host; 55 char *host;
55 int port; 56 unsigned short port;
56 int state; 57 int state;
57 unsigned long address; 58 unsigned long address;
58 unsigned long source_addr; 59 unsigned long source_addr;
...@@ -304,7 +305,7 @@ _create_tcp_stream (int flags) ...@@ -304,7 +305,7 @@ _create_tcp_stream (int flags)
304 305
305 int 306 int
306 mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream, 307 mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream,
307 const char *host, int port, 308 const char *host, unsigned port,
308 unsigned long source_ip, 309 unsigned long source_ip,
309 int flags) 310 int flags)
310 { 311 {
...@@ -315,7 +316,7 @@ mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream, ...@@ -315,7 +316,7 @@ mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream,
315 if (host == NULL) 316 if (host == NULL)
316 return MU_ERR_TCP_NO_HOST; 317 return MU_ERR_TCP_NO_HOST;
317 318
318 if (port < 1) 319 if (port > USHRT_MAX)
319 return MU_ERR_TCP_NO_PORT; 320 return MU_ERR_TCP_NO_PORT;
320 321
321 tcp = _create_tcp_stream (flags | MU_STREAM_RDWR); 322 tcp = _create_tcp_stream (flags | MU_STREAM_RDWR);
...@@ -341,7 +342,7 @@ mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream, ...@@ -341,7 +342,7 @@ mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream,
341 342
342 int 343 int
343 mu_tcp_stream_create_with_source_host (mu_stream_t *stream, 344 mu_tcp_stream_create_with_source_host (mu_stream_t *stream,
344 const char *host, int port, 345 const char *host, unsigned port,
345 const char *source_host, 346 const char *source_host,
346 int flags) 347 int flags)
347 { 348 {
...@@ -354,7 +355,7 @@ mu_tcp_stream_create_with_source_host (mu_stream_t *stream, ...@@ -354,7 +355,7 @@ mu_tcp_stream_create_with_source_host (mu_stream_t *stream,
354 } 355 }
355 356
356 int 357 int
357 mu_tcp_stream_create (mu_stream_t *stream, const char *host, int port, 358 mu_tcp_stream_create (mu_stream_t *stream, const char *host, unsigned port,
358 int flags) 359 int flags)
359 { 360 {
360 return mu_tcp_stream_create_with_source_ip (stream, host, port, 361 return mu_tcp_stream_create_with_source_ip (stream, host, port,
......
...@@ -34,6 +34,7 @@ libstring_la_SOURCES = \ ...@@ -34,6 +34,7 @@ libstring_la_SOURCES = \
34 asprintf.c\ 34 asprintf.c\
35 muctype.c\ 35 muctype.c\
36 vasnprintf.c\ 36 vasnprintf.c\
37 mkfilename.c 37 mkfilename.c\
38 xdecode.c
38 39
39 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils 40 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
3 2010 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #if HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <string.h>
24 #include <mailutils/errno.h>
25 #include <mailutils/util.h>
26
27 /* From RFC 1738, section 2.2 */
28 void
29 mu_str_url_decode_inline (char *s)
30 {
31 char *d;
32
33 d = strchr (s, '%');
34 if (!d)
35 return;
36
37 for (s = d; *s; )
38 {
39 if (*s != '%')
40 {
41 *d++ = *s++;
42 }
43 else
44 {
45 unsigned long ul = 0;
46
47 s++;
48
49 /* don't check return value, it's correctly coded, or it's not,
50 in which case we just skip the garbage, this is a decoder,
51 not an AI project */
52
53 mu_hexstr2ul (&ul, s, 2);
54
55 s += 2;
56
57 *d++ = (char) ul;
58 }
59 }
60
61 *d = 0;
62 }
63
64 int
65 mu_str_url_decode (char **ptr, const char *s)
66 {
67 char *d = strdup (s);
68 if (!d)
69 return ENOMEM;
70 mu_str_url_decode_inline (d);
71 *ptr = d;
72 return 0;
73 }
...@@ -77,7 +77,7 @@ int ...@@ -77,7 +77,7 @@ int
77 main () 77 main ()
78 { 78 {
79 char str[1024]; 79 char str[1024];
80 long port = 0; 80 unsigned port = 0;
81 mu_url_t u = NULL; 81 mu_url_t u = NULL;
82 82
83 while (fgets (str, sizeof (str), stdin) != NULL) 83 while (fgets (str, sizeof (str), stdin) != NULL)
...@@ -95,11 +95,6 @@ main () ...@@ -95,11 +95,6 @@ main ()
95 str, rc, mu_strerror (rc)); 95 str, rc, mu_strerror (rc));
96 exit (1); 96 exit (1);
97 } 97 }
98 if ((rc = mu_url_parse (u)) != 0)
99 {
100 fprintf (stderr, "%s\n", mu_errname (rc));
101 continue;
102 }
103 98
104 GET_AND_PRINT (scheme, u, buf, rc); 99 GET_AND_PRINT (scheme, u, buf, rc);
105 GET_AND_PRINT (user, u, buf, rc); 100 GET_AND_PRINT (user, u, buf, rc);
...@@ -127,7 +122,7 @@ main () ...@@ -127,7 +122,7 @@ main ()
127 mu_error ("cannot get %s: %s", "port", mu_strerror (rc)); 122 mu_error ("cannot get %s: %s", "port", mu_strerror (rc));
128 exit (1); 123 exit (1);
129 } 124 }
130 printf ("port %ld\n", port); 125 printf ("port %hu\n", port);
131 126
132 GET_AND_PRINT (path, u, buf, rc); 127 GET_AND_PRINT (path, u, buf, rc);
133 print_fvpairs (u); 128 print_fvpairs (u);
......
...@@ -38,15 +38,10 @@ match_string (const char *str) ...@@ -38,15 +38,10 @@ match_string (const char *str)
38 str, rc, mu_strerror (rc)); 38 str, rc, mu_strerror (rc));
39 return; 39 return;
40 } 40 }
41 if ((rc = mu_url_parse (u)) != 0)
42 {
43 fprintf (stderr, "%s\n", mu_errname (rc));
44 return;
45 }
46 MU_ASSERT (mu_stream_seek (stream, 0, MU_SEEK_SET, NULL)); 41 MU_ASSERT (mu_stream_seek (stream, 0, MU_SEEK_SET, NULL));
47 loc.file = name; 42 loc.file = name;
48 loc.line = 0; 43 loc.line = 0;
49 rc = mu_wicket_stream_match_url (stream, &loc, u, &url); 44 rc = mu_wicket_stream_match_url (stream, &loc, u, MU_URL_PARSE_ALL, &url);
50 switch (rc) 45 switch (rc)
51 { 46 {
52 case 0: 47 case 0:
......
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2010 Free Software Foundation, Inc.
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 3 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General
15 # Public License along with this library. If not, see
16 # <http://www.gnu.org/licenses/>.
17
18 noinst_LTLIBRARIES = liburl.la
19
20 liburl_la_SOURCES = \
21 accessor.h\
22 copy.c\
23 create.c\
24 decode.c\
25 destroy.c\
26 dup.c\
27 expand.c\
28 flag.c\
29 get-auth.c\
30 get-host.c\
31 get-param.c\
32 get-path.c\
33 get-portstr.c\
34 get-query.c\
35 get-scheme.c\
36 get-secret.c\
37 get-user.c\
38 match.c\
39 port.c\
40 scheme.c\
41 uplevel.c\
42 urlstr.c
43
44 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
45
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/errno.h>
31 #include <mailutils/util.h>
32 #include <mailutils/cstr.h>
33 #include <mailutils/sys/url.h>
34
35 /* General accessors: */
36 #define AC2(a,b) a ## b
37 #define METHOD(pfx,part) AC2(pfx,part)
38 #define AC4(a,b,c,d) a ## b ## c ## d
39 #define ACCESSOR(action,field) AC4(mu_url_,action,_,field)
40
41 /* Define a `static get' accessor */
42 int
43 ACCESSOR(sget,URL_PART) (mu_url_t url, char const **sptr)
44 {
45 if (url == NULL)
46 return EINVAL;
47 if (!url->URL_PART)
48 {
49 if (url->METHOD(_get_,URL_PART))
50 {
51 size_t n;
52 char *buf;
53
54 int status = url->METHOD(_get_,URL_PART) (url, NULL, 0, &n);
55 if (status)
56 return status;
57
58 buf = malloc (n + 1);
59 if (!buf)
60 return ENOMEM;
61
62 status = url->METHOD(_get_,URL_PART) (url, buf, n + 1, NULL);
63 if (status)
64 return status;
65
66 if (buf[0])
67 {
68 /* FIXME */
69 status = mu_str_url_decode (&url->URL_PART, buf);
70 if (status)
71 {
72 free (buf);
73 return status;
74 }
75 }
76 else
77 url->URL_PART = buf;
78 if (!url->URL_PART)
79 return ENOMEM;
80 }
81 else
82 return MU_ERR_NOENT;
83 }
84 *sptr = url->URL_PART;
85 return 0;
86 }
87
88 /* Define a `get' accessor */
89 int
90 ACCESSOR(get,URL_PART) (mu_url_t url, char *buf, size_t len, size_t *n)
91 {
92 size_t i;
93 const char *str;
94 int status = ACCESSOR(sget, URL_PART) (url, &str);
95
96 if (status)
97 return status;
98
99 i = mu_cpystr (buf, str, len);
100 if (n)
101 *n = i;
102 return 0;
103 }
104
105 /* Define an `allocated get' accessor */
106 int
107 ACCESSOR(aget, URL_PART) (mu_url_t url, char **buf)
108 {
109 const char *str;
110 int status = ACCESSOR(sget, URL_PART) (url, &str);
111
112 if (status)
113 return status;
114
115 if (str)
116 {
117 *buf = strdup (str);
118 if (!*buf)
119 status = ENOMEM;
120 }
121 else
122 *buf = NULL;
123 return status;
124 }
125
126 /* Define a comparator */
127 int
128 ACCESSOR(is_same,URL_PART) (mu_url_t url1, mu_url_t url2)
129 {
130 const char *s1, *s2;
131 int status1, status2;
132
133 status1 = ACCESSOR(sget, URL_PART) (url1, &s1);
134 if (status1 && status1 != MU_ERR_NOENT)
135 return 0;
136 status2 = ACCESSOR(sget, URL_PART) (url2, &s2);
137 if (status2 && status2 != MU_ERR_NOENT)
138 return 0;
139
140 if (status1 || status2)
141 return status1 == status2; /* Both fields are missing */
142 return mu_c_strcasecmp (s1, s2) == 0;
143 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <string.h>
24 #ifdef HAVE_STRINGS_H
25 # include <strings.h>
26 #endif
27
28 #include <mailutils/types.h>
29 #include <mailutils/argcv.h>
30 #include <mailutils/secret.h>
31 #include <mailutils/util.h>
32 #include <mailutils/sys/url.h>
33
34 struct copy_tab
35 {
36 int mask;
37 int (*fun) (mu_url_t, mu_url_t, size_t);
38 size_t off;
39 };
40
41 static int
42 _url_copy_str (mu_url_t dest_url, mu_url_t src_url, size_t off)
43 {
44 char **dest = (char**) ((char*) dest_url + off);
45 char *src = *(char**) ((char*) src_url + off);
46 char *p = strdup (src);
47 if (!p)
48 return ENOMEM;
49 *dest = p;
50 return 0;
51 }
52
53 static int
54 _url_copy_secret (mu_url_t dest, mu_url_t src, size_t off)
55 {
56 return mu_secret_dup (src->secret, &dest->secret);
57 }
58
59 static int
60 _url_copy_port (mu_url_t dest, mu_url_t src, size_t off)
61 {
62 if (src->portstr)
63 {
64 dest->portstr = strdup (src->portstr);
65 if (!dest->portstr)
66 return ENOMEM;
67 }
68 dest->port = src->port;
69 return 0;
70 }
71
72 static char **
73 argcv_copy (size_t argc, char **argv)
74 {
75 size_t i;
76 char **nv = calloc (argc + 1, sizeof (nv[0]));
77 if (!nv)
78 return NULL;
79 for (i = 0; i < argc; i++)
80 if ((nv[i] = strdup (argv[i])) == NULL)
81 {
82 mu_argcv_free (i, nv);
83 free (nv);
84 return NULL;
85 }
86 return nv;
87 }
88
89 static int
90 _url_copy_param (mu_url_t dest, mu_url_t src, size_t off)
91 {
92 if ((dest->fvpairs = argcv_copy (src->fvcount, src->fvpairs)) == NULL)
93 return ENOMEM;
94 dest->fvcount = src->fvcount;
95 return 0;
96 }
97
98 static int
99 _url_copy_query (mu_url_t dest, mu_url_t src, size_t off)
100 {
101 if ((dest->qargv = argcv_copy (src->qargc, src->qargv)) == NULL)
102 return ENOMEM;
103 dest->qargc = src->qargc;
104 return 0;
105 }
106
107 static struct copy_tab copy_tab[] = {
108 { MU_URL_SCHEME, _url_copy_str, mu_offsetof (struct _mu_url, scheme) },
109 { MU_URL_USER, _url_copy_str, mu_offsetof (struct _mu_url, user) },
110 { MU_URL_SECRET, _url_copy_secret, 0 },
111 { MU_URL_AUTH, _url_copy_str, mu_offsetof (struct _mu_url, auth) },
112 { MU_URL_HOST, _url_copy_str, mu_offsetof (struct _mu_url, host) },
113 { MU_URL_PORT, _url_copy_port, 0 },
114 { MU_URL_PATH, _url_copy_str, mu_offsetof (struct _mu_url, path) },
115 { MU_URL_PARAM, _url_copy_param, 0 },
116 { MU_URL_QUERY, _url_copy_query, 0 }
117 };
118
119 int
120 mu_url_copy_hints (mu_url_t url, mu_url_t hint)
121 {
122 int i;
123
124 if (!url)
125 return EINVAL;
126 if (!hint)
127 return 0;
128 for (i = 0; i < MU_ARRAY_SIZE (copy_tab); i++)
129 {
130 if (!(url->flags & copy_tab[i].mask) &&
131 (hint->flags & copy_tab[i].mask))
132 {
133 int rc = copy_tab[i].fun (url, hint, copy_tab[i].off);
134 if (rc)
135 return rc;
136 url->flags |= copy_tab[i].mask;
137 }
138 }
139 return 0;
140 }
141
142
143
144
145
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/util.h>
31 #include <mailutils/secret.h>
32 #include <mailutils/sys/url.h>
33
34 struct decode_tab
35 {
36 int mask;
37 int (*fun) (mu_url_t, size_t);
38 size_t off;
39 };
40
41 static int
42 _url_dec_str (mu_url_t url, size_t off)
43 {
44 char **pptr = (char**) ((char*) url + off);
45 mu_str_url_decode_inline (*pptr);
46 return 0;
47 }
48
49 static int
50 _url_dec_param (mu_url_t url, size_t off)
51 {
52 int i;
53
54 for (i = 0; i < url->fvcount; i++)
55 mu_str_url_decode_inline (url->fvpairs[i]);
56 return 0;
57 }
58
59 static int
60 _url_dec_query (mu_url_t url, size_t off)
61 {
62 int i;
63
64 for (i = 0; i < url->qargc; i++)
65 mu_str_url_decode_inline (url->qargv[i]);
66 return 0;
67 }
68
69 static int
70 _url_dec_secret (mu_url_t url, size_t off)
71 {
72 char *pass;
73 mu_secret_t newsec;
74 int rc;
75
76 rc = mu_str_url_decode (&pass, mu_secret_password (url->secret));
77 if (rc)
78 return rc;
79 rc = mu_secret_create (&newsec, pass, strlen (pass));
80 memset (pass, 0, strlen (pass));
81 free (pass);
82 if (rc)
83 return rc;
84 mu_secret_destroy (&url->secret);
85 url->secret = newsec;
86 return 0;
87 }
88
89 static struct decode_tab decode_tab[] = {
90 { MU_URL_SCHEME, _url_dec_str, mu_offsetof (struct _mu_url, scheme) },
91 { MU_URL_USER, _url_dec_str, mu_offsetof (struct _mu_url, user) },
92 { MU_URL_SECRET, _url_dec_secret },
93 { MU_URL_AUTH, _url_dec_str, mu_offsetof (struct _mu_url, auth) },
94 { MU_URL_HOST, _url_dec_str, mu_offsetof (struct _mu_url, host) },
95 { MU_URL_PATH, _url_dec_str, mu_offsetof (struct _mu_url, path) },
96 { MU_URL_PARAM, _url_dec_param, 0 },
97 { MU_URL_QUERY, _url_dec_query, 0 }
98 };
99
100 int
101 mu_url_decode (mu_url_t url)
102 {
103 int i;
104
105 if (!url)
106 return EINVAL;
107 for (i = 0; i < MU_ARRAY_SIZE (decode_tab); i++)
108 {
109 if (url->flags & decode_tab[i].mask)
110 {
111 int rc = decode_tab[i].fun (url, decode_tab[i].off);
112 if (rc)
113 return rc;
114 }
115 }
116 return 0;
117 }
118
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/argcv.h>
31 #include <mailutils/secret.h>
32 #include <mailutils/errno.h>
33 #include <mailutils/sys/url.h>
34
35 void
36 mu_url_destroy (mu_url_t * purl)
37 {
38 if (purl && *purl)
39 {
40 mu_url_t url = (*purl);
41
42 if (url->_destroy)
43 url->_destroy (url);
44
45 if (url->name)
46 free (url->name);
47
48 if (url->scheme)
49 free (url->scheme);
50
51 if (url->user)
52 free (url->user);
53
54 mu_secret_destroy (&url->secret);
55
56 if (url->auth)
57 free (url->auth);
58
59 if (url->host)
60 free (url->host);
61
62 if (url->path)
63 free (url->path);
64
65 if (url->fvcount)
66 mu_argcv_free (url->fvcount, url->fvpairs);
67
68 mu_argcv_free (url->qargc, url->qargv);
69
70 free (url);
71
72 *purl = NULL;
73 }
74 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/util.h>
31 #include <mailutils/sys/url.h>
32
33 int
34 mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
35 {
36 int rc;
37 mu_url_t url = calloc (1, sizeof (*url));
38
39 if (!url)
40 return ENOMEM;
41 url->name = strdup (old_url->name);
42 if (!url->name)
43 {
44 free (url);
45 return ENOMEM;
46 }
47
48 rc = mu_url_copy_hints (url, old_url);
49 if (rc)
50 {
51 mu_url_destroy (&url);
52 return rc;
53 }
54 *new_url = url;
55 return 0;
56 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #ifdef HAVE_STRINGS_H
27 # include <strings.h>
28 #endif
29
30 #include <mailutils/types.h>
31 #include <mailutils/util.h>
32 #include <mailutils/errno.h>
33 #include <mailutils/argcv.h>
34 #include <mailutils/sys/url.h>
35
36 /* Default mailbox path generator */
37 static char *
38 _url_path_default (const char *spooldir, const char *user, int unused)
39 {
40 return mu_make_file_name (spooldir, user);
41 }
42
43 /* Hashed indexing */
44 static char *
45 _url_path_hashed (const char *spooldir, const char *user, int param)
46 {
47 int i;
48 int ulen = strlen (user);
49 char *mbox;
50 unsigned hash;
51
52 if (param > ulen)
53 param = ulen;
54 for (i = 0, hash = 0; i < param; i++)
55 hash += user[i];
56
57 mbox = malloc (ulen + strlen (spooldir) + 5);
58 sprintf (mbox, "%s/%02X/%s", spooldir, hash % 256, user);
59 return mbox;
60 }
61
62 static int transtab[] = {
63 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
64 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
65 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
66 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f',
67 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
68 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
69 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd',
70 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
71 'm', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
72 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
73 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
74 'x', 'y', 'z', 'b', 'c', 'd', 'e', 'f',
75 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
76 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
77 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
78 'x', 'y', 'z', 'b', 'c', 'd', 'e', 'f',
79 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
80 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
81 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
82 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
83 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
84 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
85 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e',
86 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
87 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
88 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
89 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
90 'y', 'z', 'b', 'c', 'd', 'e', 'f', 'g',
91 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
92 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
93 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
94 'y', 'z', 'b', 'c', 'd', 'e', 'f', 'g'
95 };
96
97 /* Forward Indexing */
98 static char *
99 _url_path_index (const char *spooldir, const char *iuser, int index_depth)
100 {
101 const unsigned char* user = (const unsigned char*) iuser;
102 int i, ulen = strlen (iuser);
103 char *mbox, *p;
104
105 if (ulen == 0)
106 return NULL;
107
108 mbox = malloc (ulen + strlen (spooldir) + 2*index_depth + 2);
109 strcpy (mbox, spooldir);
110 p = mbox + strlen (mbox);
111 for (i = 0; i < index_depth && i < ulen; i++)
112 {
113 *p++ = '/';
114 *p++ = transtab[ user[i] ];
115 }
116 for (; i < index_depth; i++)
117 {
118 *p++ = '/';
119 *p++ = transtab[ user[ulen-1] ];
120 }
121 *p++ = '/';
122 strcpy (p, iuser);
123 return mbox;
124 }
125
126 /* Reverse Indexing */
127 static char *
128 _url_path_rev_index (const char *spooldir, const char *iuser, int index_depth)
129 {
130 const unsigned char* user = (const unsigned char*) iuser;
131 int i, ulen = strlen (iuser);
132 char *mbox, *p;
133
134 if (ulen == 0)
135 return NULL;
136
137 mbox = malloc (ulen + strlen (spooldir) + 2*index_depth + 1);
138 strcpy (mbox, spooldir);
139 p = mbox + strlen (mbox);
140 for (i = 0; i < index_depth && i < ulen; i++)
141 {
142 *p++ = '/';
143 *p++ = transtab[ user[ulen - i - 1] ];
144 }
145 for (; i < index_depth; i++)
146 {
147 *p++ = '/';
148 *p++ = transtab[ user[0] ];
149 }
150 *p++ = '/';
151 strcpy (p, iuser);
152 return mbox;
153 }
154
155 static int
156 rmselector (const char *p, void *data MU_ARG_UNUSED)
157 {
158 return strncmp (p, "type=", 5) == 0
159 || strncmp (p, "user=", 5) == 0
160 || strncmp (p, "param=", 6) == 0;
161 }
162
163 int
164 mu_url_expand_path (mu_url_t url)
165 {
166 size_t i;
167 char *user = NULL;
168 int param = 0;
169 char *p;
170 char *(*fun) (const char *, const char *, int) = _url_path_default;
171
172 if (url->fvcount == 0)
173 return 0;
174
175 for (i = 0; i < url->fvcount; i++)
176 {
177 p = url->fvpairs[i];
178 if (strncmp (p, "type=", 5) == 0)
179 {
180 char *type = p + 5;
181
182 if (strcmp (type, "hash") == 0)
183 fun = _url_path_hashed;
184 else if (strcmp (type, "index") == 0)
185 fun = _url_path_index;
186 else if (strcmp (type, "rev-index") == 0)
187 fun = _url_path_rev_index;
188 else
189 return MU_ERR_NOENT;
190 }
191 else if (strncmp (p, "user=", 5) == 0)
192 {
193 user = p + 5;
194 }
195 else if (strncmp (p, "param=", 6) == 0)
196 {
197 param = strtoul (p + 6, NULL, 0);
198 }
199 }
200
201 if (user)
202 {
203 char *p = fun (url->path, user, param);
204 if (p)
205 {
206 free (url->path);
207 url->path = p;
208 }
209 mu_argcv_remove (&url->fvcount, &url->fvpairs, rmselector, NULL);
210 }
211 else
212 return MU_ERR_NOENT;
213
214 return 0;
215 }
216
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <mailutils/sys/url.h>
24
25 int
26 mu_url_get_flags (mu_url_t url, int *pf)
27 {
28 if (!url || !pf)
29 return EINVAL;
30 *pf = url->flags;
31 return 0;
32 }
33
34 int
35 mu_url_has_flag (mu_url_t url, int flags)
36 {
37 if (!url)
38 return 0;
39 return url->flags & flags;
40 }
1 #define URL_PART auth
2 #include "accessor.h"
3
1 #define URL_PART host
2 #include "accessor.h"
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/errno.h>
31 #include <mailutils/argcv.h>
32 #include <mailutils/sys/url.h>
33
34 /* field-value pairs accessors */
35 int
36 mu_url_sget_fvpairs (const mu_url_t url, size_t *fvc, char ***fvp)
37 {
38 if (url == NULL)
39 return EINVAL;
40 /* FIXME: no _get_fvpairs method, but the method stuff needs to be rewritten
41 anyway */
42 *fvc = url->fvcount;
43 *fvp = url->fvpairs;
44 return 0;
45 }
46
47 int
48 mu_url_sget_param (const mu_url_t url, const char *param, const char **val)
49 {
50 size_t fvc;
51 char **fvp;
52 int status = mu_url_sget_fvpairs (url, &fvc, &fvp);
53
54 if (status)
55 return status;
56
57 if (fvc)
58 {
59 size_t i;
60
61 for (i = 0; i < fvc; i++)
62 {
63 const char *p;
64 char *q;
65
66 for (p = param, q = fvp[i]; *p && *q && *p == *q; p++, q++)
67 ;
68 if (*p == 0)
69 {
70 if (*q == 0)
71 {
72 if (val)
73 *val = q;
74 return 0;
75 }
76 else if (*q == '=')
77 {
78 if (val)
79 *val = q + 1;
80 return 0;
81 }
82 }
83 }
84 }
85
86 return MU_ERR_NOENT;
87 }
88
89 int
90 mu_url_aget_fvpairs (const mu_url_t url, size_t *pfvc, char ***pfvp)
91 {
92 size_t fvc, i;
93 char **fvp;
94 char **fvcopy;
95
96 int rc = mu_url_sget_fvpairs (url, &fvc, &fvp);
97 if (rc)
98 return rc;
99
100 fvcopy = calloc (fvc + 1, sizeof (fvcopy[0]));
101 if (!fvcopy)
102 return errno;
103 for (i = 0; i < fvc; i++)
104 {
105 if (!(fvcopy[i] = strdup (fvp[i])))
106 {
107 mu_argcv_free (i, fvcopy);
108 return errno;
109 }
110 }
111 fvcopy[i] = NULL;
112 *pfvc = fvc;
113 *pfvp = fvcopy;
114 return 0;
115 }
116
117 int
118 mu_url_aget_param (const mu_url_t url, const char *param, char **val)
119 {
120 const char *s;
121 int status = mu_url_sget_param (url, param, &s);
122
123 if (status == 0)
124 {
125 *val = strdup (s);
126 if (!*val)
127 status = ENOMEM;
128 }
129 return status;
130 }
131
1 #define URL_PART path
2 #include "accessor.h"
1 #define URL_PART portstr
2 #include "accessor.h"
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/errno.h>
31 #include <mailutils/argcv.h>
32 #include <mailutils/sys/url.h>
33
34 int
35 mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv)
36 {
37 if (url == NULL)
38 return EINVAL;
39 /* See FIXME below */
40 *qc = url->qargc;
41 *qv = url->qargv;
42 return 0;
43 }
44
45 int
46 mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv)
47 {
48 size_t qargc, i;
49 char **qargv;
50 char **qcopy;
51
52 int rc = mu_url_sget_fvpairs (url, &qargc, &qargv);
53 if (rc)
54 return rc;
55
56 qcopy = calloc (qargc + 1, sizeof (qcopy[0]));
57 if (!qcopy)
58 return errno;
59 for (i = 0; i < qargc; i++)
60 {
61 if (!(qcopy[i] = strdup (qargv[i])))
62 {
63 mu_argcv_free (i, qcopy);
64 return errno;
65 }
66 }
67 qcopy[i] = NULL;
68 *qc = qargc;
69 *qv = qcopy;
70 return 0;
71 }
72
1 #define URL_PART scheme
2 #include "accessor.h"
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/errno.h>
31 #include <mailutils/secret.h>
32 #include <mailutils/sys/url.h>
33
34 int
35 mu_url_get_secret (const mu_url_t url, mu_secret_t *psecret)
36 {
37 if (url->_get_secret)
38 return url->_get_secret (url, psecret);
39 if (url->secret == NULL)
40 return MU_ERR_NOENT;
41 mu_secret_ref (url->secret);
42 *psecret = url->secret;
43 return 0;
44 }
1 #define URL_PART user
2 #include "accessor.h"
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/cstr.h>
31 #include <mailutils/sys/url.h>
32
33 #define is_wildcard(s) ((s)[0] == '*' && s[1] == 0)
34
35 #define WEIGHT_SCHEME 3
36 #define WEIGHT_USER 4
37 #define WEIGHT_HOST 2
38 #define WEIGHT_PORT 1
39
40 int
41 mu_url_matches_ticket (mu_url_t ticket, mu_url_t url, int *pwc)
42 {
43 int wcnt = 0;
44
45 if (is_wildcard (ticket->scheme))
46 wcnt += WEIGHT_SCHEME;
47 else if (mu_c_strcasecmp (ticket->scheme, url->scheme))
48 return 0;
49
50 if (ticket->flags & MU_URL_HOST)
51 {
52 if (is_wildcard (ticket->host))
53 wcnt += WEIGHT_HOST;
54 else if (url->flags & MU_URL_HOST)
55 {
56 if (mu_c_strcasecmp (ticket->host, url->host))
57 /* FIXME: Compare IP addresses */
58 return 0;
59 }
60 else
61 return 0;
62 }
63 else
64 wcnt += WEIGHT_HOST;
65
66 if (ticket->flags & MU_URL_PORT)
67 {
68 if (is_wildcard (ticket->portstr))
69 wcnt += WEIGHT_PORT;
70 else if (url->port & MU_URL_PORT)
71 {
72 if (ticket->port != url->port)
73 return 0;
74 else
75 wcnt += WEIGHT_PORT;
76 }
77 }
78 else
79 wcnt += WEIGHT_PORT;
80
81 if (ticket->flags & MU_URL_USER)
82 {
83 if (is_wildcard (ticket->user))
84 wcnt += WEIGHT_USER;
85
86 /* If ticket has a user or pass, but url doesn't, that's OK, we were
87 looking for this info. But if url does have a user/pass, it
88 must match the ticket. */
89 else if (url->flags & MU_URL_USER)
90 {
91 if (strcmp (ticket->user, url->user))
92 return 0;
93 }
94 }
95 else
96 wcnt += WEIGHT_USER;
97
98 /* Guess it matches. */
99 if (pwc)
100 *pwc = wcnt;
101 return 1;
102 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/cstr.h>
31 #include <mailutils/sys/url.h>
32
33 int
34 mu_url_get_port (const mu_url_t url, unsigned *pport)
35 {
36 if (url == NULL)
37 return EINVAL;
38 if (url->_get_port)
39 return url->_get_port (url, pport);
40 *pport = url->port;
41 return 0;
42 }
43
44 int
45 mu_url_is_same_port (mu_url_t url1, mu_url_t url2)
46 {
47 unsigned p1 = 0, p2 = 0;
48
49 mu_url_get_port (url1, &p1);
50 mu_url_get_port (url2, &p2);
51 return (p1 == p2);
52 }
53
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/cstr.h>
31 #include <mailutils/sys/url.h>
32
33 int
34 mu_url_set_scheme (mu_url_t url, const char *scheme)
35 {
36 char *p;
37 if (!url || !scheme)
38 return EINVAL;
39 p = realloc (url->scheme, strlen (scheme) + 1);
40 if (!p)
41 return ENOMEM;
42 strcpy (url->scheme, scheme);
43 return 0;
44 }
45
46 int
47 mu_url_is_scheme (mu_url_t url, const char *scheme)
48 {
49 if (url && scheme && url->scheme
50 && mu_c_strcasecmp (url->scheme, scheme) == 0)
51 return 1;
52
53 return 0;
54 }
55
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_STRINGS_H
26 # include <strings.h>
27 #endif
28
29 #include <mailutils/types.h>
30 #include <mailutils/errno.h>
31 #include <mailutils/sys/url.h>
32
33 int
34 mu_url_uplevel (mu_url_t url, mu_url_t *upurl)
35 {
36 int rc;
37 char *p;
38 mu_url_t new_url;
39
40 if (url->_uplevel)
41 return url->_uplevel (url, upurl);
42
43 if (!url->path)
44 return MU_ERR_NOENT;
45 p = strrchr (url->path, '/');
46
47 rc = mu_url_dup (url, &new_url);
48 if (rc == 0)
49 {
50 if (!p || p == url->path)
51 {
52 free (new_url->path);
53 new_url->path = NULL;
54 }
55 else
56 {
57 size_t size = p - url->path;
58 new_url->path = realloc (new_url->path, size + 1);
59 if (!new_url->path)
60 {
61 mu_url_destroy (&new_url);
62 return ENOMEM;
63 }
64 memcpy (new_url->path, url->path, size);
65 new_url->path[size] = 0;
66 }
67 *upurl = new_url;
68 }
69 return rc;
70 }
71
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stdlib.h>
22 #include <mailutils/types.h>
23 #include <mailutils/sys/url.h>
24
25 const char *
26 mu_url_to_string (const mu_url_t url)
27 {
28 if (url == NULL || url->name == NULL)
29 return "";
30 return url->name;
31 }
...@@ -54,19 +54,17 @@ Url :: ~Url () ...@@ -54,19 +54,17 @@ Url :: ~Url ()
54 void 54 void
55 Url :: parse () 55 Url :: parse ()
56 { 56 {
57 int status = mu_url_parse (url); 57 /* FIXME: Remove */
58 if (status)
59 throw Exception ("Url::parse", status);
60 } 58 }
61 59
62 long 60 unsigned
63 Url :: get_port () 61 Url :: get_port ()
64 { 62 {
65 long port; 63 unsigned port;
66 int status = mu_url_get_port (url, &port); 64 int status = mu_url_get_port (url, &port);
67 if (status) 65 if (status)
68 throw Exception ("Url::get_port", status); 66 throw Exception ("Url::get_port", status);
69 return port; 67 return (unsigned short) port;
70 } 68 }
71 69
72 std::string 70 std::string
......
...@@ -67,7 +67,7 @@ static struct _mu_record _imap_record = ...@@ -67,7 +67,7 @@ static struct _mu_record _imap_record =
67 MU_IMAP_PRIO, 67 MU_IMAP_PRIO,
68 MU_IMAP_SCHEME, 68 MU_IMAP_SCHEME,
69 MU_RECORD_DEFAULT, 69 MU_RECORD_DEFAULT,
70 MU_URL_CRED | MU_URL_INET | MU_URL_PATH, 70 MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH,
71 MU_URL_HOST, 71 MU_URL_HOST,
72 _url_imap_init, /* url entry. */ 72 _url_imap_init, /* url entry. */
73 _mailbox_imap_init, /* Mailbox entry. */ 73 _mailbox_imap_init, /* Mailbox entry. */
...@@ -91,7 +91,7 @@ static struct _mu_record _imaps_record = ...@@ -91,7 +91,7 @@ static struct _mu_record _imaps_record =
91 MU_IMAP_PRIO, 91 MU_IMAP_PRIO,
92 MU_IMAPS_SCHEME, 92 MU_IMAPS_SCHEME,
93 MU_RECORD_DEFAULT, 93 MU_RECORD_DEFAULT,
94 MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM, 94 MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM,
95 MU_URL_HOST, 95 MU_URL_HOST,
96 _url_imaps_init, /* url entry. */ 96 _url_imaps_init, /* url entry. */
97 _mailbox_imaps_init, /* Mailbox entry. */ 97 _mailbox_imaps_init, /* Mailbox entry. */
...@@ -629,7 +629,7 @@ folder_imap_open (mu_folder_t folder, int flags) ...@@ -629,7 +629,7 @@ folder_imap_open (mu_folder_t folder, int flags)
629 { 629 {
630 f_imap_t f_imap = folder->data; 630 f_imap_t f_imap = folder->data;
631 const char *host; 631 const char *host;
632 long port = f_imap->imaps ? MU_IMAPS_PORT : MU_IMAP_PORT; 632 unsigned port = f_imap->imaps ? MU_IMAPS_PORT : MU_IMAP_PORT;
633 int status = 0; 633 int status = 0;
634 634
635 /* If we are already open for business, noop. */ 635 /* If we are already open for business, noop. */
......
...@@ -99,7 +99,7 @@ static struct _mu_record _maildir_record = ...@@ -99,7 +99,7 @@ static struct _mu_record _maildir_record =
99 MU_MAILDIR_PRIO, 99 MU_MAILDIR_PRIO,
100 MU_MAILDIR_SCHEME, 100 MU_MAILDIR_SCHEME,
101 MU_RECORD_LOCAL, 101 MU_RECORD_LOCAL,
102 MU_URL_PATH, 102 MU_URL_SCHEME | MU_URL_PATH,
103 MU_URL_PATH, 103 MU_URL_PATH,
104 mu_url_expand_path, /* Url init. */ 104 mu_url_expand_path, /* Url init. */
105 _mailbox_maildir_init, /* Mailbox init. */ 105 _mailbox_maildir_init, /* Mailbox init. */
......
...@@ -47,7 +47,7 @@ static struct _mu_record _prog_record = ...@@ -47,7 +47,7 @@ static struct _mu_record _prog_record =
47 MU_RECORD_DEFAULT, 47 MU_RECORD_DEFAULT,
48 /* FIXME: MU_URL_USER could be used to request running with this 48 /* FIXME: MU_URL_USER could be used to request running with this
49 user privileges. */ 49 user privileges. */
50 MU_URL_PATH | MU_URL_QUERY, 50 MU_URL_SCHEME | MU_URL_PATH | MU_URL_QUERY,
51 MU_URL_PATH, 51 MU_URL_PATH,
52 _url_prog_init, /* url init. */ 52 _url_prog_init, /* url init. */
53 _mu_mailer_mailbox_init, /* Mailbox entry. */ 53 _mu_mailer_mailbox_init, /* Mailbox entry. */
......
...@@ -76,7 +76,7 @@ static struct _mu_record _mu_remote_smtp_record = { ...@@ -76,7 +76,7 @@ static struct _mu_record _mu_remote_smtp_record = {
76 MU_SMTP_PRIO, 76 MU_SMTP_PRIO,
77 "remote+smtp", 77 "remote+smtp",
78 MU_RECORD_DEFAULT, 78 MU_RECORD_DEFAULT,
79 MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM, 79 MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM,
80 MU_URL_HOST, 80 MU_URL_HOST,
81 _url_remote_smtp_init, /* url init. */ 81 _url_remote_smtp_init, /* url init. */
82 _mu_mailer_mailbox_init, /* Mailbox init. */ 82 _mu_mailer_mailbox_init, /* Mailbox init. */
...@@ -108,7 +108,7 @@ static struct _mu_record _mu_remote_sendmail_record = ...@@ -108,7 +108,7 @@ static struct _mu_record _mu_remote_sendmail_record =
108 MU_SENDMAIL_PRIO, 108 MU_SENDMAIL_PRIO,
109 "remote+sendmail", 109 "remote+sendmail",
110 MU_RECORD_DEFAULT, 110 MU_RECORD_DEFAULT,
111 MU_URL_PATH, 111 MU_URL_SCHEME | MU_URL_PATH,
112 MU_URL_PATH, 112 MU_URL_PATH,
113 _url_remote_sendmail_init, /* url init. */ 113 _url_remote_sendmail_init, /* url init. */
114 _mu_mailer_mailbox_init, /* Mailbox entry. */ 114 _mu_mailer_mailbox_init, /* Mailbox entry. */
...@@ -137,7 +137,7 @@ static struct _mu_record _mu_remote_prog_record = ...@@ -137,7 +137,7 @@ static struct _mu_record _mu_remote_prog_record =
137 MU_PROG_PRIO, 137 MU_PROG_PRIO,
138 "remote+prog", 138 "remote+prog",
139 MU_RECORD_DEFAULT, 139 MU_RECORD_DEFAULT,
140 MU_URL_CRED | MU_URL_PATH | MU_URL_QUERY, 140 MU_URL_SCHEME | MU_URL_CRED | MU_URL_PATH | MU_URL_QUERY,
141 MU_URL_PATH, 141 MU_URL_PATH,
142 _url_remote_prog_init, /* url init. */ 142 _url_remote_prog_init, /* url init. */
143 _mu_mailer_mailbox_init, /* Mailbox entry. */ 143 _mu_mailer_mailbox_init, /* Mailbox entry. */
......
...@@ -271,9 +271,9 @@ static struct _mu_record _sendmail_record = ...@@ -271,9 +271,9 @@ static struct _mu_record _sendmail_record =
271 MU_SENDMAIL_PRIO, 271 MU_SENDMAIL_PRIO,
272 MU_SENDMAIL_SCHEME, 272 MU_SENDMAIL_SCHEME,
273 MU_RECORD_DEFAULT, 273 MU_RECORD_DEFAULT,
274 MU_URL_PATH, 274 MU_URL_SCHEME | MU_URL_PATH,
275 0, /* Nothing is required in the URL, except scheme. Missing path means 275 MU_URL_SCHEME, /* Nothing is required in the URL, except scheme.
276 using PATH_SENDMAIL. */ 276 Missing path means using PATH_SENDMAIL. */
277 _url_sendmail_init, /* url init. */ 277 _url_sendmail_init, /* url init. */
278 _mu_mailer_mailbox_init, /* Mailbox entry. */ 278 _mu_mailer_mailbox_init, /* Mailbox entry. */
279 _mu_mailer_sendmail_init, /* Mailer entry. */ 279 _mu_mailer_sendmail_init, /* Mailer entry. */
......
...@@ -65,7 +65,7 @@ static struct _mu_record _smtp_record = { ...@@ -65,7 +65,7 @@ static struct _mu_record _smtp_record = {
65 MU_SMTP_PRIO, 65 MU_SMTP_PRIO,
66 MU_SMTP_SCHEME, 66 MU_SMTP_SCHEME,
67 MU_RECORD_DEFAULT, 67 MU_RECORD_DEFAULT,
68 MU_URL_CRED | MU_URL_INET | MU_URL_PARAM, 68 MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PARAM,
69 MU_URL_HOST, 69 MU_URL_HOST,
70 _url_smtp_init, /* url init. */ 70 _url_smtp_init, /* url init. */
71 _mu_mailer_mailbox_init, /* Mailbox init. */ 71 _mu_mailer_mailbox_init, /* Mailbox init. */
...@@ -113,7 +113,7 @@ static int ...@@ -113,7 +113,7 @@ static int
113 smtp_open (mu_mailer_t mailer, int flags) 113 smtp_open (mu_mailer_t mailer, int flags)
114 { 114 {
115 const char *host, *auth; 115 const char *host, *auth;
116 long port; 116 unsigned port;
117 struct _smtp_mailer *smtp_mailer = mailer->data; 117 struct _smtp_mailer *smtp_mailer = mailer->data;
118 int rc; 118 int rc;
119 size_t parmc = 0; 119 size_t parmc = 0;
......
...@@ -77,15 +77,6 @@ _mu_smtp_fixup_params (mu_smtp_t smtp) ...@@ -77,15 +77,6 @@ _mu_smtp_fixup_params (mu_smtp_t smtp)
77 return rc; 77 return rc;
78 } 78 }
79 79
80 rc = mu_url_parse (url);
81 if (rc)
82 {
83 mu_diag_output (MU_DIAG_ERROR, "cannot parse URL: %s",
84 mu_strerror (rc));
85 mu_url_destroy (&url);
86 return rc;
87 }
88
89 if (!(flags & _HAS_USERNAME)) 80 if (!(flags & _HAS_USERNAME))
90 { 81 {
91 rc = mu_url_sget_user (url, &str); 82 rc = mu_url_sget_user (url, &str);
......
...@@ -101,7 +101,7 @@ static struct _mu_record _mbox_record = ...@@ -101,7 +101,7 @@ static struct _mu_record _mbox_record =
101 MU_MBOX_PRIO, 101 MU_MBOX_PRIO,
102 MU_MBOX_SCHEME, 102 MU_MBOX_SCHEME,
103 MU_RECORD_LOCAL, 103 MU_RECORD_LOCAL,
104 MU_URL_PATH, 104 MU_URL_SCHEME | MU_URL_PATH,
105 MU_URL_PATH, 105 MU_URL_PATH,
106 mu_url_expand_path, /* URL init. */ 106 mu_url_expand_path, /* URL init. */
107 _mailbox_mbox_init, /* Mailbox init. */ 107 _mailbox_mbox_init, /* Mailbox init. */
......
...@@ -139,7 +139,7 @@ static struct _mu_record _mh_record = ...@@ -139,7 +139,7 @@ static struct _mu_record _mh_record =
139 MU_MH_PRIO, 139 MU_MH_PRIO,
140 MU_MH_SCHEME, 140 MU_MH_SCHEME,
141 MU_RECORD_LOCAL, 141 MU_RECORD_LOCAL,
142 MU_URL_PATH, 142 MU_URL_SCHEME | MU_URL_PATH,
143 MU_URL_PATH, 143 MU_URL_PATH,
144 mu_url_expand_path, /* Url init. */ 144 mu_url_expand_path, /* Url init. */
145 _mailbox_mh_init, /* Mailbox init. */ 145 _mailbox_mh_init, /* Mailbox init. */
......
...@@ -46,7 +46,7 @@ static struct _mu_record _nntp_record = ...@@ -46,7 +46,7 @@ static struct _mu_record _nntp_record =
46 MU_NNTP_PRIO, 46 MU_NNTP_PRIO,
47 MU_NNTP_URL_SCHEME, 47 MU_NNTP_URL_SCHEME,
48 MU_RECORD_DEFAULT, 48 MU_RECORD_DEFAULT,
49 MU_URL_CRED | MU_URL_INET | MU_URL_PATH, 49 MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH,
50 MU_URL_HOST, 50 MU_URL_HOST,
51 _nntp_url_init, /* Url init. */ 51 _nntp_url_init, /* Url init. */
52 _nntp_mailbox_init, /* Mailbox init. */ 52 _nntp_mailbox_init, /* Mailbox init. */
...@@ -104,7 +104,7 @@ nntp_folder_open (mu_folder_t folder, int flags) ...@@ -104,7 +104,7 @@ nntp_folder_open (mu_folder_t folder, int flags)
104 f_nntp_t f_nntp = folder->data; 104 f_nntp_t f_nntp = folder->data;
105 mu_stream_t carrier = NULL; 105 mu_stream_t carrier = NULL;
106 const char *host; 106 const char *host;
107 long port = MU_NNTP_DEFAULT_PORT; /* default nntp port. */ 107 unsigned port = MU_NNTP_DEFAULT_PORT; /* default nntp port. */
108 int status = 0; 108 int status = 0;
109 109
110 /* If we are already open for business, noop. */ 110 /* If we are already open for business, noop. */
......
...@@ -48,7 +48,7 @@ static struct _mu_record _pop_record = ...@@ -48,7 +48,7 @@ static struct _mu_record _pop_record =
48 MU_POP_PRIO, 48 MU_POP_PRIO,
49 MU_POP_SCHEME, 49 MU_POP_SCHEME,
50 MU_RECORD_DEFAULT, 50 MU_RECORD_DEFAULT,
51 MU_URL_CRED | MU_URL_INET | MU_URL_PARAM, 51 MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PARAM,
52 MU_URL_HOST, 52 MU_URL_HOST,
53 _url_pop_init, /* Url init. */ 53 _url_pop_init, /* Url init. */
54 _mailbox_pop_init, /* Mailbox init. */ 54 _mailbox_pop_init, /* Mailbox init. */
...@@ -69,7 +69,7 @@ static struct _mu_record _pops_record = ...@@ -69,7 +69,7 @@ static struct _mu_record _pops_record =
69 MU_POP_PRIO, 69 MU_POP_PRIO,
70 MU_POPS_SCHEME, 70 MU_POPS_SCHEME,
71 MU_RECORD_DEFAULT, 71 MU_RECORD_DEFAULT,
72 MU_URL_CRED | MU_URL_INET, 72 MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET,
73 MU_URL_HOST, 73 MU_URL_HOST,
74 _url_pops_init, /* Url init. */ 74 _url_pops_init, /* Url init. */
75 _mailbox_pops_init, /* Mailbox init. */ 75 _mailbox_pops_init, /* Mailbox init. */
......
...@@ -105,7 +105,7 @@ pop_open (mu_mailbox_t mbox, int flags) ...@@ -105,7 +105,7 @@ pop_open (mu_mailbox_t mbox, int flags)
105 struct _pop3_mailbox *mpd = mbox->data; 105 struct _pop3_mailbox *mpd = mbox->data;
106 int status; 106 int status;
107 const char *host; 107 const char *host;
108 long port = mpd->pops ? MU_POPS_PORT : MU_POP_PORT; 108 unsigned port = mpd->pops ? MU_POPS_PORT : MU_POP_PORT;
109 mu_stream_t stream; 109 mu_stream_t stream;
110 110
111 /* Sanity checks. */ 111 /* Sanity checks. */
......
...@@ -385,13 +385,6 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp) ...@@ -385,13 +385,6 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp)
385 auth->mailbox, mu_strerror (status)); 385 auth->mailbox, mu_strerror (status));
386 return exit_code = EX_UNAVAILABLE; 386 return exit_code = EX_UNAVAILABLE;
387 } 387 }
388 status = mu_url_parse (url);
389 if (status)
390 {
391 maidag_error (_("error parsing URL %s: %s"),
392 auth->mailbox, mu_strerror (status));
393 return exit_code = EX_UNAVAILABLE;
394 }
395 } 388 }
396 389
397 status = mu_mailbox_create_from_url (&mbox, url); 390 status = mu_mailbox_create_from_url (&mbox, url);
...@@ -437,14 +430,6 @@ deliver_to_url (mu_message_t msg, char *dest_id, char **errp) ...@@ -437,14 +430,6 @@ deliver_to_url (mu_message_t msg, char *dest_id, char **errp)
437 mu_strerror (status)); 430 mu_strerror (status));
438 return EX_NOUSER; 431 return EX_NOUSER;
439 } 432 }
440 status = mu_url_parse (url);
441 if (status)
442 {
443 maidag_error (_("%s: cannot parse url: %s"), dest_id,
444 mu_strerror (status));
445 mu_url_destroy (&url);
446 return EX_NOUSER;
447 }
448 status = mu_url_sget_user (url, &name); 433 status = mu_url_sget_user (url, &name);
449 if (status == MU_ERR_NOENT) 434 if (status == MU_ERR_NOENT)
450 name = NULL; 435 name = NULL;
......
...@@ -75,6 +75,10 @@ wicket_match (mu_stream_t stream, const char *str) ...@@ -75,6 +75,10 @@ wicket_match (mu_stream_t stream, const char *str)
75 int rc, ret; 75 int rc, ret;
76 mu_url_t u, url; 76 mu_url_t u, url;
77 struct mu_debug_locus loc; 77 struct mu_debug_locus loc;
78 int flags = MU_URL_PARSE_ALL;
79
80 if (wicket_verbose > 2)
81 flags &= ~MU_URL_PARSE_HIDEPASS;
78 82
79 rc = mu_url_create (&u, str); 83 rc = mu_url_create (&u, str);
80 if (rc) 84 if (rc)
...@@ -82,12 +86,6 @@ wicket_match (mu_stream_t stream, const char *str) ...@@ -82,12 +86,6 @@ wicket_match (mu_stream_t stream, const char *str)
82 mu_diag_funcall (MU_DIAG_ERROR, "mu_url_create", str, rc); 86 mu_diag_funcall (MU_DIAG_ERROR, "mu_url_create", str, rc);
83 return 2; 87 return 2;
84 } 88 }
85 rc = mu_url_parse (u);
86 if (rc)
87 {
88 mu_diag_funcall (MU_DIAG_ERROR, "mu_url_parse", str, rc);
89 return 2;
90 }
91 89
92 rc = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL); 90 rc = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
93 if (rc) 91 if (rc)
...@@ -97,7 +95,7 @@ wicket_match (mu_stream_t stream, const char *str) ...@@ -97,7 +95,7 @@ wicket_match (mu_stream_t stream, const char *str)
97 } 95 }
98 loc.file = wicket_file; 96 loc.file = wicket_file;
99 loc.line = 0; 97 loc.line = 0;
100 rc = mu_wicket_stream_match_url (stream, &loc, u, &url); 98 rc = mu_wicket_stream_match_url (stream, &loc, u, flags, &url);
101 switch (rc) 99 switch (rc)
102 { 100 {
103 case 0: 101 case 0:
...@@ -106,27 +104,7 @@ wicket_match (mu_stream_t stream, const char *str) ...@@ -106,27 +104,7 @@ wicket_match (mu_stream_t stream, const char *str)
106 { 104 {
107 printf ("%s: %s:%d", str, loc.file, loc.line); 105 printf ("%s: %s:%d", str, loc.file, loc.line);
108 if (wicket_verbose > 1) 106 if (wicket_verbose > 1)
109 { 107 printf (": %s", mu_url_to_string (url));
110 printf (": %s", mu_url_to_string (url));
111 if (wicket_verbose > 2)
112 {
113 mu_secret_t s;
114 rc = mu_url_get_secret (url, &s);
115 if (rc == 0)
116 {
117 printf (": %s", mu_secret_password (s));
118 mu_secret_password_unref (s);
119 mu_secret_unref (s);
120 }
121 else if (rc == MU_ERR_NOENT)
122 printf (": [%s]", _("no password"));
123 else
124 {
125 printf (": [error: %s]", mu_strerror (rc));
126 ret = 2;
127 }
128 }
129 }
130 putchar ('\n'); 108 putchar ('\n');
131 } 109 }
132 break; 110 break;
......
...@@ -102,6 +102,7 @@ api_url_destroy (PyObject *self, PyObject *args) ...@@ -102,6 +102,7 @@ api_url_destroy (PyObject *self, PyObject *args)
102 return _ro (Py_None); 102 return _ro (Py_None);
103 } 103 }
104 104
105 /* FIXME: Remove */
105 static PyObject * 106 static PyObject *
106 api_url_parse (PyObject *self, PyObject *args) 107 api_url_parse (PyObject *self, PyObject *args)
107 { 108 {
...@@ -111,22 +112,21 @@ api_url_parse (PyObject *self, PyObject *args) ...@@ -111,22 +112,21 @@ api_url_parse (PyObject *self, PyObject *args)
111 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url)) 112 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
112 return NULL; 113 return NULL;
113 114
114 status = mu_url_parse (py_url->url); 115 return _ro (0);
115 return _ro (PyInt_FromLong (status));
116 } 116 }
117 117
118 static PyObject * 118 static PyObject *
119 api_url_get_port (PyObject *self, PyObject *args) 119 api_url_get_port (PyObject *self, PyObject *args)
120 { 120 {
121 int status; 121 int status;
122 long port; 122 unsigned port;
123 PyUrl *py_url; 123 PyUrl *py_url;
124 124
125 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url)) 125 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
126 return NULL; 126 return NULL;
127 127
128 status = mu_url_get_port (py_url->url, &port); 128 status = mu_url_get_port (py_url->url, &port);
129 return status_object (status, PyInt_FromLong (port)); 129 return status_object (status, PyInt_FromLong ((long)port));
130 } 130 }
131 131
132 static PyObject * 132 static PyObject *
......