コード例 #1
0
ファイル: path.c プロジェクト: Asquera/libgit2
int git_path_fromurl(git_buf *local_path_out, const char *file_url)
{
	int offset = 0, len;

	assert(local_path_out && file_url);

	if (git__prefixcmp(file_url, "file://") != 0)
		return error_invalid_local_file_uri(file_url);

	offset += 7;
	len = (int)strlen(file_url);

	if (offset < len && file_url[offset] == '/')
		offset++;
	else if (offset < len && git__prefixcmp(file_url + offset, "localhost/") == 0)
		offset += 10;
	else
		return error_invalid_local_file_uri(file_url);

	if (offset >= len || file_url[offset] == '/')
		return error_invalid_local_file_uri(file_url);

#ifndef _MSC_VER
	offset--;	/* A *nix absolute path starts with a forward slash */
#endif

	git_buf_clear(local_path_out);

	return git__percent_decode(local_path_out, file_url + offset);
}
コード例 #2
0
ファイル: path.c プロジェクト: CodeSmithyIDE/libgit2
static void check_percent_decoding(const char *expected_result, const char *input)
{
	git_buf buf = GIT_BUF_INIT;

	cl_git_pass(git__percent_decode(&buf, input));
	cl_assert_equal_s(expected_result, git_buf_cstr(&buf));

	git_buf_dispose(&buf);
}
コード例 #3
0
int git_path_fromurl(git_buf *local_path_out, const char *file_url)
{
	int offset;

	assert(local_path_out && file_url);

	if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
		file_url[offset] == '\0' || file_url[offset] == '/')
		return error_invalid_local_file_uri(file_url);

#ifndef GIT_WIN32
	offset--;	/* A *nix absolute path starts with a forward slash */
#endif

	git_buf_clear(local_path_out);
	return git__percent_decode(local_path_out, file_url + offset);
}
コード例 #4
0
ファイル: path.c プロジェクト: DJHartley/libgit2
int git_path_fromurl(git_buf *local_path_out, const char *file_url)
{
	int error = GIT_SUCCESS, offset = 0, len;

	assert(local_path_out && file_url);

	if (git__prefixcmp(file_url, "file://") != 0)
		return git__throw(GIT_EINVALIDPATH,
			"Parsing of '%s' failed. A file Uri is expected (ie. with 'file://' scheme).",
			file_url);

	offset += 7;
	len = strlen(file_url);

	if (offset < len && file_url[offset] == '/')
		offset++;
	else if (offset < len && git__prefixcmp(file_url + offset, "localhost/") == 0)
		offset += 10;
	else
		return git__throw(GIT_EINVALIDPATH,
			"Parsing of '%s' failed. A local file Uri is expected.", file_url);

	if (offset >= len || file_url[offset] == '/')
		return git__throw(GIT_EINVALIDPATH, 
			"Parsing of '%s' failed. Invalid file Uri format.", file_url);

#ifndef _MSC_VER
	offset--;	/* A *nix absolute path starts with a forward slash */
#endif

	git_buf_clear(local_path_out);

	error = git__percent_decode(local_path_out, file_url + offset);
	if (error < GIT_SUCCESS)
		return git__rethrow(error, "Parsing of '%s' failed.", file_url);

	return error;
}