Blame src/netops.h

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