diff options
Diffstat (limited to 'src/input/http_helper.h')
-rw-r--r-- | src/input/http_helper.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/input/http_helper.h b/src/input/http_helper.h index 546a55803..9baa05235 100644 --- a/src/input/http_helper.h +++ b/src/input/http_helper.h @@ -15,11 +15,9 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA * * URL helper functions - * - * $Id: http_helper.h,v 1.3 2004/12/24 01:59:12 dsalt Exp $ */ #ifndef HTTP_HELPER_H @@ -45,6 +43,28 @@ int _x_parse_url (char *url, char **proto, char** host, int *port, * return: * the canonicalised URL (caller must free() it) */ -char *_x_canonicalise_url (const char *base, const char *url); +static inline char *_x_canonicalise_url (const char *base, const char *url) { + + size_t base_length; + char *cut, *ret; + + if ((cut = strstr (url, "://"))) + return strdup (url); + + cut = strstr (base, "://"); + if (url[0] == '/') { + /* absolute - base up to first '/' after "://", then url */ + cut = strchr (cut + 3, '/'); + } + else { + /* relative - base up to & inc. last '/', then url */ + cut = strrchr (cut, '/'); + if (cut) + ++cut; + } + base_length = cut ? (size_t)(cut - base) : strlen (base); + asprintf (&ret, "%.*s%s", (int)base_length, base, url); + return ret; +} #endif /* HTTP_HELPER_H */ |