Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:36

0001 /*
0002  * Copyright (C) the libgit2 contributors. All rights reserved.
0003  *
0004  * This file is part of libgit2, distributed under the GNU GPL v2 with
0005  * a Linking Exception. For full terms see the included COPYING file.
0006  */
0007 #ifndef INCLUDE_sys_git_stream_h__
0008 #define INCLUDE_sys_git_stream_h__
0009 
0010 #include "git2/common.h"
0011 #include "git2/types.h"
0012 #include "git2/proxy.h"
0013 
0014 GIT_BEGIN_DECL
0015 
0016 #define GIT_STREAM_VERSION 1
0017 
0018 /**
0019  * Every stream must have this struct as its first element, so the
0020  * API can talk to it. You'd define your stream as
0021  *
0022  *     struct my_stream {
0023  *             git_stream parent;
0024  *             ...
0025  *     }
0026  *
0027  * and fill the functions
0028  */
0029 typedef struct git_stream {
0030     int version;
0031 
0032     unsigned int encrypted : 1,
0033                  proxy_support : 1;
0034 
0035     /**
0036      * Timeout for read and write operations; can be set to `0` to
0037      * block indefinitely.
0038      */
0039     int timeout;
0040 
0041     /**
0042      * Timeout to connect to the remote server; can be set to `0`
0043      * to use the system defaults. This can be shorter than the
0044      * system default - often 75 seconds - but cannot be longer.
0045      */
0046     int connect_timeout;
0047 
0048     int GIT_CALLBACK(connect)(struct git_stream *);
0049     int GIT_CALLBACK(certificate)(git_cert **, struct git_stream *);
0050     int GIT_CALLBACK(set_proxy)(struct git_stream *, const git_proxy_options *proxy_opts);
0051     ssize_t GIT_CALLBACK(read)(struct git_stream *, void *, size_t);
0052     ssize_t GIT_CALLBACK(write)(struct git_stream *, const char *, size_t, int);
0053     int GIT_CALLBACK(close)(struct git_stream *);
0054     void GIT_CALLBACK(free)(struct git_stream *);
0055 } git_stream;
0056 
0057 typedef struct {
0058     /** The `version` field should be set to `GIT_STREAM_VERSION`. */
0059     int version;
0060 
0061     /**
0062      * Called to create a new connection to a given host.
0063      *
0064      * @param out The created stream
0065      * @param host The hostname to connect to; may be a hostname or
0066      *             IP address
0067      * @param port The port to connect to; may be a port number or
0068      *             service name
0069      * @return 0 or an error code
0070      */
0071     int GIT_CALLBACK(init)(git_stream **out, const char *host, const char *port);
0072 
0073     /**
0074      * Called to create a new connection on top of the given stream.  If
0075      * this is a TLS stream, then this function may be used to proxy a
0076      * TLS stream over an HTTP CONNECT session.  If this is unset, then
0077      * HTTP CONNECT proxies will not be supported.
0078      *
0079      * @param out The created stream
0080      * @param in An existing stream to add TLS to
0081      * @param host The hostname that the stream is connected to,
0082      *             for certificate validation
0083      * @return 0 or an error code
0084      */
0085     int GIT_CALLBACK(wrap)(git_stream **out, git_stream *in, const char *host);
0086 } git_stream_registration;
0087 
0088 /**
0089  * The type of stream to register.
0090  */
0091 typedef enum {
0092     /** A standard (non-TLS) socket. */
0093     GIT_STREAM_STANDARD = 1,
0094 
0095     /** A TLS-encrypted socket. */
0096     GIT_STREAM_TLS = 2
0097 } git_stream_t;
0098 
0099 /**
0100  * Register stream constructors for the library to use
0101  *
0102  * If a registration structure is already set, it will be overwritten.
0103  * Pass `NULL` in order to deregister the current constructor and return
0104  * to the system defaults.
0105  *
0106  * The type parameter may be a bitwise AND of types.
0107  *
0108  * @param type the type or types of stream to register
0109  * @param registration the registration data
0110  * @return 0 or an error code
0111  */
0112 GIT_EXTERN(int) git_stream_register(
0113     git_stream_t type, git_stream_registration *registration);
0114 
0115 #ifndef GIT_DEPRECATE_HARD
0116 
0117 /** @name Deprecated TLS Stream Registration Functions
0118  *
0119  * These functions are retained for backward compatibility.  The newer
0120  * versions of these values should be preferred in all new code.
0121  *
0122  * There is no plan to remove these backward compatibility values at
0123  * this time.
0124  */
0125 /**@{*/
0126 
0127 /**
0128  * @deprecated Provide a git_stream_registration to git_stream_register
0129  * @see git_stream_registration
0130  */
0131 typedef int GIT_CALLBACK(git_stream_cb)(git_stream **out, const char *host, const char *port);
0132 
0133 /**
0134  * Register a TLS stream constructor for the library to use.  This stream
0135  * will not support HTTP CONNECT proxies.  This internally calls
0136  * `git_stream_register` and is preserved for backward compatibility.
0137  *
0138  * This function is deprecated, but there is no plan to remove this
0139  * function at this time.
0140  *
0141  * @deprecated Provide a git_stream_registration to git_stream_register
0142  * @see git_stream_register
0143  */
0144 GIT_EXTERN(int) git_stream_register_tls(git_stream_cb ctor);
0145 
0146 /**@}*/
0147 
0148 #endif
0149 
0150 GIT_END_DECL
0151 
0152 #endif