S32 LLUriParser::normalize()
{
	mNormalizedTmp = mTmpScheme;
	if (!mRes)
	{
		mRes = uriNormalizeSyntaxExA(&mUri, URI_NORMALIZE_SCHEME | URI_NORMALIZE_HOST);

		if (!mRes)
		{
			S32 chars_required;
			mRes = uriToStringCharsRequiredA(&mUri, &chars_required);

			if (!mRes)
			{
				chars_required++;
				std::vector<char> label_buf(chars_required);
				mRes = uriToStringA(&label_buf[0], &mUri, chars_required, nullptr);

				if (!mRes)
				{
					mNormalizedUri = &label_buf[mTmpScheme ? 7 : 0];
					mTmpScheme = false;
				}
			}
		}
	}

	if(mTmpScheme)
	{
		mNormalizedUri = mNormalizedUri.substr(7);
		mTmpScheme = false;
	}

	return mRes;
}
Esempio n. 2
0
struct PP_Var
ppb_url_util_dev_resolve_relative_to_url(struct PP_Var base_url, struct PP_Var relative_string,
                                         struct PP_URLComponents_Dev *components)
{
    reset_components(components);
    struct PP_Var var = PP_MakeNull();

    if (base_url.type != PP_VARTYPE_STRING) {
        trace_warning("%s, base_url is not a string\n", __func__);
        return PP_MakeNull();
    }

    if (relative_string.type != PP_VARTYPE_STRING) {
        trace_warning("%s, relative_string is not a string\n", __func__);
        return PP_MakeNull();
    }

    const char *s_base_url = ppb_var_var_to_utf8(base_url, NULL);
    const char *s_relative_string = ppb_var_var_to_utf8(relative_string, NULL);

    UriParserStateA ups;
    UriUriA uri_base, uri_rel, uri_result;

    ups.uri = &uri_base;
    if (uriParseUriA(&ups, s_base_url) != URI_SUCCESS) {
        trace_warning("%s, can't parse s_base_url\n", __func__);
        goto err_1;
    }

    ups.uri = &uri_rel;
    if (uriParseUriA(&ups, s_relative_string) != URI_SUCCESS) {
        trace_warning("%s, can't parse s_relative_string\n", __func__);
        goto err_2;
    }

    if (uriAddBaseUriA(&uri_result, &uri_rel, &uri_base) != URI_SUCCESS) {
        trace_warning("%s, can't merge base and rel\n", __func__);
        goto err_3;
    }

    int len;
    uriToStringCharsRequiredA(&uri_result, &len);
    len++;
    char *str = malloc(len);
    uriToStringA(str, &uri_result, len, NULL);
    var = ppb_var_var_from_utf8_z(str);
    free(str);

    if (components)
        parse_url_string(str, components);

err_3:  uriFreeUriMembersA(&uri_result);
err_2:  uriFreeUriMembersA(&uri_rel);
err_1:  uriFreeUriMembersA(&uri_base);
    return var;
}
Esempio n. 3
0
int uri_scope_get_document_length(UriScope const *u)
{
	UriUriA *uri = uri_scope_get_uri_unsafe(u);
	int result = 0;

	UriTextRangeA fragment = uri->fragment;
	uri->fragment = (UriTextRangeA){};

	if (URI_SUCCESS != uriToStringCharsRequiredA(uri, &result))
	{
		uri->fragment = fragment;
		return -1;
	}
	uri->fragment = fragment;
	return result + 1;
}
Esempio n. 4
0
char *uri2string(UriUriA *uri)
{
	char *uri_str = NULL;
	int length = 0;

	if (!uri)
		return NULL;

	if (uriToStringCharsRequiredA(uri, &length) != URI_SUCCESS)
		return NULL;

	if ((uri_str = string_alloc(length)) == NULL)
		return NULL;

	length++;
	if (uriToStringA(uri_str, uri, length, NULL) != URI_SUCCESS) {
		string_free(uri_str);
		return NULL;
	}

	return uri_str;
}