1 /**
2  * @file
3  * Parse and identify different URL schemes
4  *
5  * @authors
6  * Copyright (C) 2000-2002,2004 Thomas Roessler <roessler@does-not-exist.org>
7  *
8  * @copyright
9  * This program is free software: you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License as published by the Free Software
11  * Foundation, either version 2 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef MUTT_EMAIL_URL_H
24 #define MUTT_EMAIL_URL_H
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 #include "mutt/lib.h"
29 
30 /**
31  * enum UrlScheme - All recognised Url types
32  */
33 enum UrlScheme
34 {
35   U_UNKNOWN, ///< Url wasn't recognised
36   U_FILE,    ///< Url is file://
37   U_POP,     ///< Url is pop://
38   U_POPS,    ///< Url is pops://
39   U_IMAP,    ///< Url is imap://
40   U_IMAPS,   ///< Url is imaps://
41   U_NNTP,    ///< Url is nntp://
42   U_NNTPS,   ///< Url is nntps://
43   U_SMTP,    ///< Url is smtp://
44   U_SMTPS,   ///< Url is smtps://
45   U_MAILTO,  ///< Url is mailto://
46   U_NOTMUCH, ///< Url is notmuch://
47 };
48 
49 #define U_NO_FLAGS       0
50 #define U_PATH          (1 << 1)
51 
52 /**
53  * struct UrlQuery - Parsed Query String
54  *
55  * The arguments in a URL are saved in a linked list.
56  */
57 struct UrlQuery
58 {
59   char *name;                     ///< Query name
60   char *value;                    ///< Query value
61   STAILQ_ENTRY(UrlQuery) entries; ///< Linked list
62 };
63 STAILQ_HEAD(UrlQueryList, UrlQuery);
64 
65 /**
66  * struct Url - A parsed URL `proto://user:password@host:port/path?a=1&b=2`
67  */
68 struct Url
69 {
70   enum UrlScheme scheme;             ///< Scheme, e.g. #U_SMTPS
71   char *user;                        ///< Username
72   char *pass;                        ///< Password
73   char *host;                        ///< Host
74   unsigned short port;               ///< Port
75   char *path;                        ///< Path
76   struct UrlQueryList query_strings; ///< List of query strings
77   char *src;                         ///< Raw URL string
78 };
79 
80 enum UrlScheme url_check_scheme(const char *s);
81 void           url_free        (struct Url **ptr);
82 struct Url    *url_parse       (const char *src);
83 int            url_pct_decode  (char *s);
84 void           url_pct_encode  (char *buf, size_t buflen, const char *src);
85 int            url_tobuffer    (struct Url *url, struct Buffer *dest, uint8_t flags);
86 int            url_tostring    (struct Url *url, char *buf, size_t buflen, uint8_t flags);
87 
88 #endif /* MUTT_EMAIL_URL_H */
89