diff options
Diffstat (limited to 'src/uri.c')
-rw-r--r-- | src/uri.c | 42 |
1 files changed, 40 insertions, 2 deletions
@@ -17,10 +17,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "config.h" #include "uri.h" #include <glib.h> +#include <assert.h> #include <string.h> bool uri_has_scheme(const char *uri) @@ -32,9 +34,45 @@ bool uri_has_scheme(const char *uri) const char * uri_get_suffix(const char *uri) { - const char *dot = strrchr(g_basename(uri), '.'); + const char *suffix = strrchr(g_basename(uri), '.'); + if (suffix == NULL) + return NULL; + + ++suffix; + + if (strchr(suffix, '/') != NULL) + return NULL; + + return suffix; +} + +static const char * +verify_uri_segment(const char *p) +{ + const char *q; + + if (*p == 0 || *p == '/' || *p == '.') + return NULL; + + q = strchr(p + 1, '/'); + return q != NULL ? q : ""; +} + +bool +uri_safe_local(const char *uri) +{ + while (true) { + uri = verify_uri_segment(uri); + if (uri == NULL) + return false; + + if (*uri == 0) + return true; + + assert(*uri == '/'); - return dot != NULL ? dot + 1 : NULL; + ++uri; + } } char * |