net.h 2.29 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#ifndef INCLUDE_net_h__
#define INCLUDE_net_h__

10
#include "git2_util.h"
11 12 13 14 15 16 17

typedef struct git_net_url {
	char *scheme;
	char *host;
	char *port;
	char *path;
	char *query;
18
	char *fragment;
19 20 21 22 23 24
	char *username;
	char *password;
} git_net_url;

#define GIT_NET_URL_INIT { NULL }

25 26 27
/** Is a given string a url? */
extern bool git_net_str_is_url(const char *str);

28 29 30
/** Duplicate a URL */
extern int git_net_url_dup(git_net_url *out, git_net_url *in);

31
/** Parses a string containing a URL into a structure. */
32 33
extern int git_net_url_parse(git_net_url *url, const char *str);

34 35 36
/** Parses a string containing an SCP style path into a URL structure. */
extern int git_net_url_parse_scp(git_net_url *url, const char *str);

37 38 39 40 41 42
/** Appends a path and/or query string to the given URL */
extern int git_net_url_joinpath(
	git_net_url *out,
	git_net_url *in,
	const char *path);

43 44
/** Ensures that a URL is minimally valid (contains a host, port and path) */
extern bool git_net_url_valid(git_net_url *url);
45

46 47
/** Returns true if the URL is on the default port. */
extern bool git_net_url_is_default_port(git_net_url *url);
48

49 50 51
/** Returns true if the host portion of the URL is an ipv6 address. */
extern bool git_net_url_is_ipv6(git_net_url *url);

52 53 54 55
/* Applies a redirect to the URL with a git-aware service suffix. */
extern int git_net_url_apply_redirect(
	git_net_url *url,
	const char *redirect_location,
56
	bool allow_offsite,
57 58
	const char *service_suffix);

59
/** Swaps the contents of one URL for another.  */
60
extern void git_net_url_swap(git_net_url *a, git_net_url *b);
61

62
/** Places the URL into the given buffer. */
63
extern int git_net_url_fmt(git_str *out, git_net_url *url);
64

65
/** Place the path and query string into the given buffer. */
66
extern int git_net_url_fmt_path(git_str *buf, git_net_url *url);
67

68 69 70 71
/** Determines if the url matches given pattern or pattern list */
extern bool git_net_url_matches_pattern(
	git_net_url *url,
	const char *pattern);
72 73 74
extern bool git_net_url_matches_pattern_list(
	git_net_url *url,
	const char *pattern_list);
75

76
/** Disposes the contents of the structure. */
77
extern void git_net_url_dispose(git_net_url *url);
78 79

#endif