aboutsummaryrefslogtreecommitdiffstats
path: root/src/uri.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uri.c')
-rw-r--r--src/uri.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/src/uri.c b/src/uri.c
index 41e406d9..a7c7a212 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -25,25 +25,25 @@
#include <stdlib.h>
#include <string.h>
-uint8_t*
-serd_file_uri_parse(const uint8_t* const uri, uint8_t** const hostname)
+char*
+serd_file_uri_parse(const char* const uri, char** const hostname)
{
- const uint8_t* path = uri;
+ const char* path = uri;
if (hostname) {
*hostname = NULL;
}
-
- if (!strncmp((const char*)uri, "file://", 7)) {
- const uint8_t* auth = uri + 7;
+ if (!strncmp(uri, "file://", 7)) {
+ const char* auth = uri + 7;
if (*auth == '/') { // No hostname
path = auth;
} else { // Has hostname
- if (!(path = (const uint8_t*)strchr((const char*)auth, '/'))) {
+ if (!(path = strchr(auth, '/'))) {
return NULL;
}
if (hostname) {
- *hostname = (uint8_t*)calloc((size_t)(path - auth + 1), 1);
- memcpy(*hostname, auth, (size_t)(path - auth));
+ const size_t len = (size_t)(path - auth);
+ *hostname = (char*)calloc(len + 1, 1);
+ memcpy(*hostname, auth, len);
}
}
}
@@ -53,14 +53,14 @@ serd_file_uri_parse(const uint8_t* const uri, uint8_t** const hostname)
}
SerdBuffer buffer = {NULL, 0};
- for (const uint8_t* s = path; *s; ++s) {
+ for (const char* s = path; *s; ++s) {
if (*s == '%') {
if (*(s + 1) == '%') {
serd_buffer_sink("%", 1, &buffer);
++s;
} else if (is_hexdig(*(s + 1)) && is_hexdig(*(s + 2))) {
- const uint8_t code[3] = {*(s + 1), *(s + 2), 0};
- const uint8_t c = (uint8_t)strtoul((const char*)code, NULL, 16);
+ const char code[3] = {*(s + 1), *(s + 2), 0};
+ const char c = (char)strtoul(code, NULL, 16);
serd_buffer_sink(&c, 1, &buffer);
s += 2;
} else {
@@ -74,14 +74,14 @@ serd_file_uri_parse(const uint8_t* const uri, uint8_t** const hostname)
}
bool
-serd_uri_string_has_scheme(const uint8_t* utf8)
+serd_uri_string_has_scheme(const char* utf8)
{
// RFC3986: scheme ::= ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
if (!utf8 || !is_alpha(utf8[0])) {
return false; // Invalid scheme initial character, URI is relative
}
- for (uint8_t c = 0; (c = *++utf8) != '\0';) {
+ for (char c = 0; (c = *++utf8) != '\0';) {
if (!is_uri_scheme_char(c)) {
return false;
}
@@ -95,11 +95,11 @@ serd_uri_string_has_scheme(const uint8_t* utf8)
}
SerdStatus
-serd_uri_parse(const uint8_t* const utf8, SerdURI* const out)
+serd_uri_parse(const char* const utf8, SerdURI* const out)
{
*out = SERD_URI_NULL;
- const uint8_t* ptr = utf8;
+ const char* ptr = utf8;
/* See http://tools.ietf.org/html/rfc3986#section-3
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
@@ -107,7 +107,7 @@ serd_uri_parse(const uint8_t* const utf8, SerdURI* const out)
/* S3.1: scheme ::= ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) */
if (is_alpha(*ptr)) {
- for (uint8_t c = *++ptr; true; c = *++ptr) {
+ for (char c = *++ptr; true; c = *++ptr) {
switch (c) {
case '\0':
case '/':
@@ -139,7 +139,7 @@ maybe_authority:
if (*ptr == '/' && *(ptr + 1) == '/') {
ptr += 2;
out->authority.buf = ptr;
- for (uint8_t c = 0; (c = *ptr) != '\0'; ++ptr) {
+ for (char c = 0; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '/':
goto path;
@@ -169,7 +169,7 @@ path:
}
out->path.buf = ptr;
out->path.len = 0;
- for (uint8_t c = 0; (c = *ptr) != '\0'; ++ptr) {
+ for (char c = 0; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '?':
goto query;
@@ -187,7 +187,7 @@ path:
query:
if (*ptr == '?') {
out->query.buf = ++ptr;
- for (uint8_t c = 0; (c = *ptr) != '\0'; ++ptr) {
+ for (char c = 0; (c = *ptr) != '\0'; ++ptr) {
if (c == '#') {
goto fragment;
}
@@ -217,13 +217,11 @@ end:
@param up Set to the number of up-references (e.g. "../") trimmed
@return A pointer to the new start of `path`
*/
-static const uint8_t*
-remove_dot_segments(const uint8_t* const path,
- const size_t len,
- size_t* const up)
+static const char*
+remove_dot_segments(const char* const path, const size_t len, size_t* const up)
{
- const uint8_t* begin = path;
- const uint8_t* const end = path + len;
+ const char* begin = path;
+ const char* const end = path + len;
*up = 0;
while (begin < end) {
@@ -253,7 +251,6 @@ remove_dot_segments(const uint8_t* const path,
return begin;
}
break;
-
case '/':
switch (begin[1]) {
case '.':
@@ -273,7 +270,6 @@ remove_dot_segments(const uint8_t* const path,
}
}
return begin;
-
default:
return begin; // Finished chopping dot components
}
@@ -286,13 +282,13 @@ remove_dot_segments(const uint8_t* const path,
static void
merge(SerdChunk* const base, SerdChunk* const path)
{
- size_t up = 0;
- const uint8_t* begin = remove_dot_segments(path->buf, path->len, &up);
- const uint8_t* end = path->buf + path->len;
+ size_t up = 0;
+ const char* begin = remove_dot_segments(path->buf, path->len, &up);
+ const char* end = path->buf + path->len;
if (base->len) {
// Find the up'th last slash
- const uint8_t* base_last = (base->buf + base->len - 1);
+ const char* base_last = (base->buf + base->len - 1);
++up;
do {
if (*base_last == '/') {