예제 #1
0
파일: ssh.c 프로젝트: Nemchinovrp/sonic-pi
static int git_ssh_extract_url_parts(
	char **host,
	char **username,
	const char *url)
{
	char *colon, *at;
	const char *start;

	colon = strchr(url, ':');


	at = strchr(url, '@');
	if (at) {
		start = at + 1;
		*username = git__substrdup(url, at - url);
		GITERR_CHECK_ALLOC(*username);
	} else {
		start = url;
		*username = NULL;
	}

	if (colon == NULL || (colon < start)) {
		giterr_set(GITERR_NET, "malformed URL");
		return -1;
	}

	*host = git__substrdup(start, colon - start);
	GITERR_CHECK_ALLOC(*host);

	return 0;
}
예제 #2
0
파일: ssh.c 프로젝트: dmgctrl/libgit2
static int git_ssh_extract_url_parts(
	char **host,
	char **username,
	const char *url)
{
	char *colon, *at;
	const char *start;
    
    colon = strchr(url, ':');
	
	if (colon == NULL) {
		giterr_set(GITERR_NET, "Malformed URL: missing :");
		return -1;
	}
	
	at = strchr(url, '@');
	if (at) {
		start = at+1;
		*username = git__substrdup(url, at - url);
	} else {
		start = url;
		*username = git__strdup(default_user);
	}
	
	*host = git__substrdup(start, colon - start);
	
	return 0;
}
예제 #3
0
파일: netops.c 프로젝트: aep/libgit2
int gitno_extract_url_parts(
		char **host,
		char **port,
		char **username,
		char **password,
		const char *url,
		const char *default_port)
{
	char *colon, *slash, *at, *end;
	const char *start;

	/*
	 *
	 * ==> [user[:pass]@]hostname.tld[:port]/resource
	 */

	colon = strchr(url, ':');
	slash = strchr(url, '/');
	at = strchr(url, '@');

	if (slash == NULL) {
		giterr_set(GITERR_NET, "Malformed URL: missing /");
		return -1;
	}

	start = url;
	if (at && at < slash) {
		start = at+1;
		*username = git__substrdup(url, at - url);
	}

	if (colon && colon < at) {
		git__free(*username);
		*username = git__substrdup(url, colon-url);
		*password = git__substrdup(colon+1, at-colon-1);
		colon = strchr(at, ':');
	}

	if (colon == NULL) {
		*port = git__strdup(default_port);
	} else {
		*port = git__substrdup(colon + 1, slash - colon - 1);
	}
	GITERR_CHECK_ALLOC(*port);

	end = colon == NULL ? slash : colon;

	*host = git__substrdup(start, end - start);
	GITERR_CHECK_ALLOC(*host);

	return 0;
}
예제 #4
0
파일: revparse.c 프로젝트: Arhzi/libgit2
int git_revparse(
	git_revspec *revspec,
	git_repository *repo,
	const char *spec)
{
	const char *dotdot;
	int error = 0;

	assert(revspec && repo && spec);

	memset(revspec, 0x0, sizeof(*revspec));

	if ((dotdot = strstr(spec, "..")) != NULL) {
		char *lstr;
		const char *rstr;
		revspec->flags = GIT_REVPARSE_RANGE;

		/*
		 * Following git.git, don't allow '..' because it makes command line
		 * arguments which can be either paths or revisions ambiguous when the
		 * path is almost certainly intended. The empty range '...' is still
		 * allowed.
		 */
		if (!git__strcmp(spec, "..")) {
			giterr_set(GITERR_INVALID, "Invalid pattern '..'");
			return GIT_EINVALIDSPEC;
		}

		lstr = git__substrdup(spec, dotdot - spec);
		rstr = dotdot + 2;
		if (dotdot[2] == '.') {
			revspec->flags |= GIT_REVPARSE_MERGE_BASE;
			rstr++;
		}

		error = git_revparse_single(
			&revspec->from,
			repo,
			*lstr == '\0' ? "HEAD" : lstr);

		if (!error) {
			error = git_revparse_single(
				&revspec->to,
				repo,
				*rstr == '\0' ? "HEAD" : rstr);
		}

		git__free((void*)lstr);
	} else {
		revspec->flags = GIT_REVPARSE_SINGLE;
		error = git_revparse_single(&revspec->from, repo, spec);
	}

	return error;
}
예제 #5
0
static char *extract_trimmed(const char *ptr, size_t len)
{
	while (len && is_crud((unsigned char)ptr[0])) {
		ptr++; len--;
	}

	while (len && is_crud((unsigned char)ptr[len - 1])) {
		len--;
	}

	return git__substrdup(ptr, len);
}
예제 #6
0
static char *extract_trimmed(const char *ptr, size_t len)
{
	while (len && git__isspace(ptr[0])) {
		ptr++; len--;
	}

	while (len && git__isspace(ptr[len - 1])) {
		len--;
	}

	return git__substrdup(ptr, len);
}
예제 #7
0
/* based on gitno_extract_url_parts, keep c&p copy here until https://github.com/libgit2/libgit2/pull/2492 gets merged or forever ;)*/
static int extract_url_parts(
	char **host,
	char **port,
	char **path,
	char **username,
	char **password,
	const char *url,
	const char *default_port)
{
	struct http_parser_url u = { 0 };
	const char *_host, *_port, *_path, *_userinfo;

	if (http_parser_parse_url(url, strlen(url), false, &u)) {
		giterr_set(GITERR_NET, "Malformed URL '%s'", url);
		return GIT_EINVALIDSPEC;
	}

	_host = url + u.field_data[UF_HOST].off;
	_port = url + u.field_data[UF_PORT].off;
	_path = url + u.field_data[UF_PATH].off;
	_userinfo = url + u.field_data[UF_USERINFO].off;

	if (u.field_set & (1 << UF_HOST)) {
		*host = git__substrdup(_host, u.field_data[UF_HOST].len);
		GITERR_CHECK_ALLOC(*host);
	}

	if (u.field_set & (1 << UF_PORT)) {
		*port = git__substrdup(_port, u.field_data[UF_PORT].len);
	} else if (default_port) {
		*port = git__strdup(default_port);
		GITERR_CHECK_ALLOC(*port);
	} else {
		*port = NULL;
	}

	if (u.field_set & (1 << UF_PATH)) {
		*path = git__substrdup(_path, u.field_data[UF_PATH].len);
		GITERR_CHECK_ALLOC(*path);
	} else {
		giterr_set(GITERR_NET, "invalid url, missing path");
		return GIT_EINVALIDSPEC;
	}

	if (u.field_set & (1 << UF_USERINFO)) {
		const char *colon = memchr(_userinfo, ':', u.field_data[UF_USERINFO].len);
		if (colon) {
			*username = unescape(git__substrdup(_userinfo, colon - _userinfo));
			*password = unescape(git__substrdup(colon + 1, u.field_data[UF_USERINFO].len - (colon + 1 - _userinfo)));
			GITERR_CHECK_ALLOC(*password);
		} else {
			*username = git__substrdup(_userinfo, u.field_data[UF_USERINFO].len);
		}
		GITERR_CHECK_ALLOC(*username);

	}

	return 0;
}
int git_revparse(
	git_revspec *revspec,
	git_repository *repo,
	const char *spec)
{
	const char *dotdot;
	int error = 0;

	assert(revspec && repo && spec);

	memset(revspec, 0x0, sizeof(*revspec));

	if ((dotdot = strstr(spec, "..")) != NULL) {
		char *lstr;
		const char *rstr;
		revspec->flags = GIT_REVPARSE_RANGE;

		lstr = git__substrdup(spec, dotdot - spec);
		rstr = dotdot + 2;
		if (dotdot[2] == '.') {
			revspec->flags |= GIT_REVPARSE_MERGE_BASE;
			rstr++;
		}

		if ((error = git_revparse_single(&revspec->from, repo, lstr)) < 0) {
			return error;
		}

		if ((error = git_revparse_single(&revspec->to, repo, rstr)) < 0) {
			return error;
		}

		git__free((void*)lstr);
	} else {
		revspec->flags = GIT_REVPARSE_SINGLE;
		error = git_revparse_single(&revspec->from, repo, spec);
	}

	return error;
}