Blame src/netops.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_netops_h__
Packit ae9e2a
#define INCLUDE_netops_h__
Packit ae9e2a
Packit ae9e2a
#include "posix.h"
Packit ae9e2a
#include "common.h"
Packit ae9e2a
#include "stream.h"
Packit ae9e2a
Packit ae9e2a
#ifdef GIT_OPENSSL
Packit ae9e2a
# include <openssl/ssl.h>
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
typedef struct gitno_ssl {
Packit ae9e2a
#ifdef GIT_OPENSSL
Packit ae9e2a
	SSL *ssl;
Packit ae9e2a
#else
Packit ae9e2a
	size_t dummy;
Packit ae9e2a
#endif
Packit ae9e2a
} gitno_ssl;
Packit ae9e2a
Packit ae9e2a
/* Represents a socket that may or may not be using SSL */
Packit ae9e2a
typedef struct gitno_socket {
Packit ae9e2a
	GIT_SOCKET socket;
Packit ae9e2a
	gitno_ssl ssl;
Packit ae9e2a
} gitno_socket;
Packit ae9e2a
Packit ae9e2a
typedef struct gitno_buffer {
Packit ae9e2a
	char *data;
Packit ae9e2a
	size_t len;
Packit ae9e2a
	size_t offset;
Packit ae9e2a
	int (*recv)(struct gitno_buffer *buffer);
Packit ae9e2a
	void *cb_data;
Packit ae9e2a
} gitno_buffer;
Packit ae9e2a
Packit ae9e2a
/* Flags to gitno_connect */
Packit ae9e2a
enum {
Packit ae9e2a
	/* Attempt to create an SSL connection. */
Packit ae9e2a
	GITNO_CONNECT_SSL = 1,
Packit ae9e2a
};
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Check if the name in a cert matches the wanted hostname
Packit ae9e2a
 *
Packit ae9e2a
 * Check if a pattern from a certificate matches the hostname we
Packit ae9e2a
 * wanted to connect to according to RFC2818 rules (which specifies
Packit ae9e2a
 * HTTP over TLS). Mainly, an asterisk matches anything, but is
Packit ae9e2a
 * limited to a single url component.
Packit ae9e2a
 *
Packit ae9e2a
 * Note that this does not set an error message. It expects the user
Packit ae9e2a
 * to provide the message for the user.
Packit ae9e2a
 */
Packit ae9e2a
int gitno__match_host(const char *pattern, const char *host);
Packit ae9e2a
Packit ae9e2a
void gitno_buffer_setup_fromstream(git_stream *st, gitno_buffer *buf, char *data, size_t len);
Packit ae9e2a
void gitno_buffer_setup_callback(gitno_buffer *buf, char *data, size_t len, int (*recv)(gitno_buffer *buf), void *cb_data);
Packit ae9e2a
int gitno_recv(gitno_buffer *buf);
Packit ae9e2a
Packit ae9e2a
void gitno_consume(gitno_buffer *buf, const char *ptr);
Packit ae9e2a
void gitno_consume_n(gitno_buffer *buf, size_t cons);
Packit ae9e2a
Packit ae9e2a
typedef struct gitno_connection_data {
Packit ae9e2a
	char *host;
Packit ae9e2a
	char *port;
Packit ae9e2a
	char *path;
Packit ae9e2a
	char *user;
Packit ae9e2a
	char *pass;
Packit ae9e2a
	bool use_ssl;
Packit ae9e2a
} gitno_connection_data;
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * This replaces all the pointers in `data` with freshly-allocated strings,
Packit ae9e2a
 * that the caller is responsible for freeing.
Packit ae9e2a
 * `gitno_connection_data_free_ptrs` is good for this.
Packit ae9e2a
 */
Packit ae9e2a
Packit ae9e2a
int gitno_connection_data_from_url(
Packit ae9e2a
		gitno_connection_data *data,
Packit ae9e2a
		const char *url,
Packit ae9e2a
		const char *service_suffix);
Packit ae9e2a
Packit ae9e2a
/* This frees all the pointers IN the struct, but not the struct itself. */
Packit ae9e2a
void gitno_connection_data_free_ptrs(gitno_connection_data *data);
Packit ae9e2a
Packit ae9e2a
int gitno_extract_url_parts(
Packit ae9e2a
		char **host,
Packit ae9e2a
		char **port,
Packit ae9e2a
		char **path,
Packit ae9e2a
		char **username,
Packit ae9e2a
		char **password,
Packit ae9e2a
		const char *url,
Packit ae9e2a
		const char *default_port);
Packit ae9e2a
Packit ae9e2a
#endif