6

I've got a base URL and some relative URIs in that document I want to have the absolute path of.

E.g. base = https://example.com/some/path.html?query=string and relative URIs in that document:

In Java you have the class URL accomplishing that:

URL abs = new URL(new URL(basePath), relPath);

But strangely enough I can't find a plain C library or function realizing just that.

Is there a library proving that feature? Or better yet some small self-contained file one can use?

KatieK
  • 13,586
  • 17
  • 76
  • 90
Kijewski
  • 25,517
  • 12
  • 101
  • 143

2 Answers2

4

You can bet this has been written a thousand times in C already. For apache, for example.

Here are some pointers:

libSoup, the http library used by GNOME: http://developer.gnome.org/libsoup/unstable/SoupURI.html#soup-uri-new-with-base

Proposed for Boost libraries: http://cpp-netlib.github.com/

By Google themselves (part of Chrome?): http://code.google.com/p/google-url/

Yet another: http://uriparser.sourceforge.net/

W3C: http://www.w3.org/Library/src/HTParse

URL parsing in libcamel: http://www.google.com/codesearch#KhbZeNk3OGk/camel/camel-url.c

Some more URI parsing APIs, that all seem to not have relative URIs:

GLib, my favorite C library: http://developer.gnome.org/glib/unstable/glib-URI-Functions.html

libedataserver (from Evolution) http://developer.gnome.org/libedataserver/stable/libedataserver-e-url.html

GNet, a glib addon: http://developer.gnome.org/gnet/stable/gnet-uri.html

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
  • 2
    Hard to find libraries though they were "written a thousand times in C already", isn't it? HTParse and uriparser seem nice, the other libraries are either C++ or (libcamel) have a hell of dependencies. I will look further into it later. Thanks! – Kijewski Jan 06 '12 at 15:20
  • Indeed. But reusing foreign C code is often also harder than just writing such a snippet yourself. Their way of handling memory might just not find your way of doing this, unfortunately. The code style differences in C are much more severe than in e.g. Java. I was surprised to see just rather rudimentary URI functions, in glib, btw. – Has QUIT--Anony-Mousse Jan 06 '12 at 16:57
  • I'd go with libsoup, that one is well maintained. Link above. – Has QUIT--Anony-Mousse Jan 06 '12 at 17:03
1

For Windows, you can use CoInternetCombineUrl from Urlmon.dll or UrlCombine from Shlwapi.lib. They do the same AFAIK.

riot_starter
  • 1,218
  • 15
  • 28