| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflhttp.h" char * build_full_url (const char *uri, const char *base_uri)
If the specified URI string does not start with a URL schema or a directory delimiter, we add the path of the base URI, and return the resulting full URI. This is provided as a freshly- allocated string which the caller must free using mem_free() when finished. If the specified URI is already a full URI, returns a fresh copy of that URI.
{ char *full_uri, /* Formatted full URI */ *slash; /* Find delimiter in path */ int base_len, /* Length of base part of URI */ uri_len; /* and the rest of uri */ if (is full url (uri) || uri [0] == '/') return (mem_strdup (uri)); else { /* Find last slash in base URI */ slash = strrchr (base_uri, '/'); if (slash) { uri_len = strlen (uri); base_len = ++slash - base_uri; full_uri = mem_alloc (base_len + uri_len + 1); if (full_uri) { memcpy (full_uri, base_uri, base_len); strncpy (full_uri + base_len, uri, (uri_len + 1)); } } else full_uri = xstrcpy (NULL, "/", uri, NULL); return (full_uri); } }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |