Commit 8e968a03 8e968a037791bd9747853d1cdbcbd3e27b31d09b by Alain Magloire

url_pop.c include/private/url0.h include/public/url.h

No need for those bloated url_m*() functions.
url_pop parsing playing smart and nuking trailing '/'
1 parent 8b33f2c5
...@@ -55,29 +55,23 @@ struct _url ...@@ -55,29 +55,23 @@ struct _url
55 55
56 int (*_get_scheme) __P ((const url_t, char *scheme, 56 int (*_get_scheme) __P ((const url_t, char *scheme,
57 size_t len, size_t *n)); 57 size_t len, size_t *n));
58 int (*_get_mscheme) __P ((const url_t, char **, size_t *n));
59 58
60 int (*_get_user) __P ((const url_t, char *user, 59 int (*_get_user) __P ((const url_t, char *user,
61 size_t len, size_t *n)); 60 size_t len, size_t *n));
62 int (*_get_muser) __P ((const url_t, char **, size_t *n));
63 61
64 int (*_get_passwd) __P ((const url_t, char *passwd, 62 int (*_get_passwd) __P ((const url_t, char *passwd,
65 size_t len, size_t *n)); 63 size_t len, size_t *n));
66 int (*_get_mpasswd) __P ((const url_t, char **, size_t *n));
67 64
68 int (*_get_host) __P ((const url_t, char *host, 65 int (*_get_host) __P ((const url_t, char *host,
69 size_t len, size_t *n)); 66 size_t len, size_t *n));
70 int (*_get_mhost) __P ((const url_t, char **, size_t *n));
71 67
72 int (*_get_port) __P ((const url_t, long *port)); 68 int (*_get_port) __P ((const url_t, long *port));
73 69
74 int (*_get_path) __P ((const url_t, char *path, 70 int (*_get_path) __P ((const url_t, char *path,
75 size_t len, size_t *n)); 71 size_t len, size_t *n));
76 int (*_get_mpath) __P ((const url_t, char **, size_t *n));
77 72
78 int (*_get_query) __P ((const url_t, char *query, 73 int (*_get_query) __P ((const url_t, char *query,
79 size_t len, size_t *n)); 74 size_t len, size_t *n));
80 int (*_get_mquery) __P ((const url_t, char **, size_t *n));
81 }; 75 };
82 76
83 77
......
...@@ -43,29 +43,23 @@ extern int url_get_id __P ((const url_t, int *id)); ...@@ -43,29 +43,23 @@ extern int url_get_id __P ((const url_t, int *id));
43 43
44 extern int url_get_scheme __P ((const url_t, char *sch, 44 extern int url_get_scheme __P ((const url_t, char *sch,
45 size_t, size_t *)); 45 size_t, size_t *));
46 extern int url_get_mscheme __P ((const url_t, char **, size_t *));
47 46
48 extern int url_get_user __P ((const url_t, char *usr, 47 extern int url_get_user __P ((const url_t, char *usr,
49 size_t, size_t *)); 48 size_t, size_t *));
50 extern int url_get_muser __P ((const url_t, char **, size_t *));
51 49
52 extern int url_get_passwd __P ((const url_t, char *passwd, 50 extern int url_get_passwd __P ((const url_t, char *passwd,
53 size_t, size_t *)); 51 size_t, size_t *));
54 extern int url_get_mpasswd __P ((const url_t, char **, size_t *));
55 52
56 extern int url_get_host __P ((const url_t, char *host, 53 extern int url_get_host __P ((const url_t, char *host,
57 size_t, size_t *)); 54 size_t, size_t *));
58 extern int url_get_mhost __P ((const url_t, char **, size_t *));
59 55
60 extern int url_get_port __P ((const url_t, long *port)); 56 extern int url_get_port __P ((const url_t, long *port));
61 57
62 extern int url_get_path __P ((const url_t, char *path, 58 extern int url_get_path __P ((const url_t, char *path,
63 size_t, size_t *)); 59 size_t, size_t *));
64 extern int url_get_mpath __P ((const url_t, char **, size_t *));
65 60
66 extern int url_get_query __P ((const url_t, char *qeury, 61 extern int url_get_query __P ((const url_t, char *qeury,
67 size_t, size_t *)); 62 size_t, size_t *));
68 extern int url_get_mquery __P ((const url_t, char **, size_t *));
69 63
70 #ifdef __cplusplus 64 #ifdef __cplusplus
71 } 65 }
......
...@@ -138,7 +138,10 @@ url_pop_create (url_t *purl, const char *name) ...@@ -138,7 +138,10 @@ url_pop_create (url_t *purl, const char *name)
138 } 138 }
139 139
140 /* HOST:PORT */ 140 /* HOST:PORT */
141 indexe = strchr (++host_port, ':'); 141 if (*host_port == '@')
142 host_port++;
143
144 indexe = strchr (host_port, ':');
142 if (indexe == NULL) 145 if (indexe == NULL)
143 { 146 {
144 url->host = strdup (host_port); 147 url->host = strdup (host_port);
...@@ -161,6 +164,13 @@ url_pop_create (url_t *purl, const char *name) ...@@ -161,6 +164,13 @@ url_pop_create (url_t *purl, const char *name)
161 url_pop_destroy (&url); 164 url_pop_destroy (&url);
162 return ENOMEM; 165 return ENOMEM;
163 } 166 }
167 else
168 {
169 /* playing smart and nuking any trailing slashes on the host */
170 size_t len = strlen (url->host);
171 if (url->host[len - 1] == '/')
172 url->host[len - 1] = '\0'; /* leak a bit */
173 }
164 174
165 *purl = url; 175 *purl = url;
166 return 0; 176 return 0;
......