]> git.proxmox.com Git - libgit2.git/blob - src/netops.h
remote: create FETCH_HEAD with a refspecless remote
[libgit2.git] / src / netops.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_netops_h__
8 #define INCLUDE_netops_h__
9
10 #include "posix.h"
11 #include "common.h"
12
13 #ifdef GIT_SSL
14 # include <openssl/ssl.h>
15 #endif
16
17 struct gitno_ssl {
18 #ifdef GIT_SSL
19 SSL_CTX *ctx;
20 SSL *ssl;
21 #else
22 size_t dummy;
23 #endif
24 };
25
26 typedef struct gitno_ssl gitno_ssl;
27
28 /* Represents a socket that may or may not be using SSL */
29 struct gitno_socket {
30 GIT_SOCKET socket;
31 gitno_ssl ssl;
32 };
33
34 typedef struct gitno_socket gitno_socket;
35
36 struct gitno_buffer {
37 char *data;
38 size_t len;
39 size_t offset;
40 gitno_socket *socket;
41 int (*recv)(struct gitno_buffer *buffer);
42 void *cb_data;
43 };
44
45 typedef struct gitno_buffer gitno_buffer;
46
47 /* Flags to gitno_connect */
48 enum {
49 /* Attempt to create an SSL connection. */
50 GITNO_CONNECT_SSL = 1,
51
52 /* Valid only when GITNO_CONNECT_SSL is also specified.
53 * Indicates that the server certificate should not be validated. */
54 GITNO_CONNECT_SSL_NO_CHECK_CERT = 2,
55 };
56
57 void gitno_buffer_setup(gitno_socket *t, gitno_buffer *buf, char *data, size_t len);
58 void gitno_buffer_setup_callback(gitno_socket *t, gitno_buffer *buf, char *data, size_t len, int (*recv)(gitno_buffer *buf), void *cb_data);
59 int gitno_recv(gitno_buffer *buf);
60
61 void gitno_consume(gitno_buffer *buf, const char *ptr);
62 void gitno_consume_n(gitno_buffer *buf, size_t cons);
63
64 int gitno_connect(gitno_socket *socket, const char *host, const char *port, int flags);
65 int gitno_send(gitno_socket *socket, const char *msg, size_t len, int flags);
66 int gitno_close(gitno_socket *s);
67 int gitno_select_in(gitno_buffer *buf, long int sec, long int usec);
68
69 typedef struct gitno_connection_data {
70 char *host;
71 char *port;
72 char *path;
73 char *user;
74 char *pass;
75 bool use_ssl;
76 } gitno_connection_data;
77
78 /*
79 * This replaces all the pointers in `data` with freshly-allocated strings,
80 * that the caller is responsible for freeing.
81 * `gitno_connection_data_free_ptrs` is good for this.
82 */
83
84 int gitno_connection_data_from_url(
85 gitno_connection_data *data,
86 const char *url,
87 const char *service_suffix);
88
89 /* This frees all the pointers IN the struct, but not the struct itself. */
90 void gitno_connection_data_free_ptrs(gitno_connection_data *data);
91
92 int gitno_extract_url_parts(
93 char **host,
94 char **port,
95 char **username,
96 char **password,
97 const char *url,
98 const char *default_port);
99
100 #endif