Commit ad89881b authored by Pekka Pessi's avatar Pekka Pessi

url.c: allow empty "host" in most of the URL schemas

url.h: added links to supported URL schemas
torture_url.c: added test for an empty host in file:

darcs-hash:20070212144000-65a35-b88b8a1d7f4aa15f3fa47ac6fe5740215235b876.gz
parent f25f0647
......@@ -34,29 +34,32 @@
#ifndef URL_H_TYPES
#define URL_H_TYPES
/** Recognized URL schemes (value of url_t.url_type). */
/** Recognized URL schemes (value of url_t.url_type).
*
* @sa &lt;<a href="http://www.iana.org/assignments/uri-schemes.html">http://www.iana.org/assignments/uri-schemes.html</a>&gt;
*/
enum url_type_e {
url_invalid = -2, /**< Invalid url. */
url_unknown = -1, /**< Unknown scheme. */
url_any = 0, /**< @c "*" */
url_sip, /**< @c "sip:" */
url_sips, /**< @c "sips:" */
url_tel, /**< @c "tel:" */
url_fax, /**< @c "fax:" */
url_modem, /**< @c "modem:" */
url_http, /**< @c "http:" */
url_https, /**< @c "https:" */
url_ftp, /**< @c "ftp:" */
url_file, /**< @c "file:" */
url_rtsp, /**< @c "rtsp:" */
url_rtspu, /**< @c "rtspu:" */
url_mailto, /**< @c "mailto:" */
url_im, /**< @c "im:" (simple instant messaging) */
url_pres, /**< @c "pres:" (simple presence) */
url_cid, /**< @c "cid:" (Content-ID) */
url_msrp, /**< @c "msrp:" (message session relay) */
url_msrps, /**< @c "msrps:" (new in @VERSION_1_12_2) */
url_wv, /**< @c "wv:" (Wireless village) */
url_invalid = -2, /**< Invalid url. */
url_unknown = -1, /**< Unknown scheme. */
url_any = 0, /**< "*" */
url_sip, /**< "sip:". @sa @RFC3261 */
url_sips, /**< "sips:". @sa @RFC3261 */
url_tel, /**< "tel:" @sa RFC3966 */
url_fax, /**< "fax:". @note Obsolete. @sa @RFC2806 */
url_modem, /**< "modem:". @note Obsolete. @sa @RFC2806 */
url_http, /**< "http:". @sa @RFC2616, @RFC3986 */
url_https, /**< "https:". @sa @RFC2618, @RFC3986 */
url_ftp, /**< "ftp:". @sa @RFC1738 */
url_file, /**< "file:" @sa @RFC1738 */
url_rtsp, /**< "rtsp:" @sa @RFC2326 */
url_rtspu, /**< "rtspu:" @sa @RFC2326 */
url_mailto, /**< "mailto:" @sa @RFC2368 */
url_im, /**< "im:" (simple instant messaging). @sa @RFC3860 */
url_pres, /**< "pres:" (simple presence). @sa @RFC3859 */
url_cid, /**< "cid:" (Content-ID). @sa @RFC2392 */
url_msrp, /**< "msrp:" (message session relay) */
url_msrps, /**< "msrps:" (new in @VERSION_1_12_2) */
url_wv, /**< "wv:" (Wireless village) */
_url_none
};
......
......@@ -639,7 +639,7 @@ int test_modem(void)
int test_file(void)
{
/* Test a url with path like file:/foo/bar */
char fileurl[] = "file:/foo/bar";
char fileurl[] = "file:///foo/bar";
url_t file[1] = { URL_INIT_AS(file) };
su_home_t home[1] = { SU_HOME_INIT(home) };
char *tst;
......@@ -653,7 +653,9 @@ int test_file(void)
TEST_1(tst = su_strdup(home, fileurl));
TEST(url_d(url, tst), 0);
TEST_S(url->url_host, "");
file->url_root = '/';
file->url_host = "";
file->url_path = "foo/bar";
TEST(url_cmp(file, url), 0);
TEST(url->url_type, url_file);
......
......@@ -669,10 +669,18 @@ int _url_d(url_t *url, char *s)
else {
n = strcspn(host, ":");
}
if (n == 0 && url->url_type != url_unknown)
return -1;
/* We allow empty host by default */
if (n == 0) switch (url->url_type) {
case url_sip:
case url_sips:
case url_im:
case url_pres:
return -1;
default:
break;
}
if (host[n] == ':') {
char *port = host + n + 1;
url->url_port = port;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment