root/main/streams/php_stream_transport.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. END_EXTERN_C
  2. BEGIN_EXTERN_C

   1 /*
   2   +----------------------------------------------------------------------+
   3   | PHP Version 5                                                        |
   4   +----------------------------------------------------------------------+
   5   | Copyright (c) 1997-2016 The PHP Group                                |
   6   +----------------------------------------------------------------------+
   7   | This source file is subject to version 3.01 of the PHP license,      |
   8   | that is bundled with this package in the file LICENSE, and is        |
   9   | available through the world-wide-web at the following url:           |
  10   | http://www.php.net/license/3_01.txt                                  |
  11   | If you did not receive a copy of the PHP license and are unable to   |
  12   | obtain it through the world-wide-web, please send a note to          |
  13   | license@php.net so we can mail you a copy immediately.               |
  14   +----------------------------------------------------------------------+
  15   | Author: Wez Furlong <wez@thebrainroom.com>                           |
  16   +----------------------------------------------------------------------+
  17 */
  18 
  19 /* $Id$ */
  20 #ifdef PHP_WIN32
  21 #include "config.w32.h"
  22 #include <Ws2tcpip.h>
  23 #endif
  24 
  25 #if HAVE_SYS_SOCKET_H
  26 # include <sys/socket.h>
  27 #endif
  28 
  29 typedef php_stream *(php_stream_transport_factory_func)(const char *proto, size_t protolen,
  30                 const char *resourcename, size_t resourcenamelen,
  31                 const char *persistent_id, int options, int flags,
  32                 struct timeval *timeout,
  33                 php_stream_context *context STREAMS_DC TSRMLS_DC);
  34 typedef php_stream_transport_factory_func *php_stream_transport_factory;
  35 
  36 BEGIN_EXTERN_C()
  37 PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC);
  38 PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC);
  39 
  40 #define STREAM_XPORT_CLIENT                     0
  41 #define STREAM_XPORT_SERVER                     1
  42 
  43 #define STREAM_XPORT_CONNECT            2
  44 #define STREAM_XPORT_BIND                       4
  45 #define STREAM_XPORT_LISTEN                     8
  46 #define STREAM_XPORT_CONNECT_ASYNC      16
  47 
  48 /* Open a client or server socket connection */
  49 PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options,
  50                 int flags, const char *persistent_id,
  51                 struct timeval *timeout,
  52                 php_stream_context *context,
  53                 char **error_string,
  54                 int *error_code
  55                 STREAMS_DC TSRMLS_DC);
  56 
  57 #define php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode) \
  58         _php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode STREAMS_CC TSRMLS_CC)
  59 
  60 /* Bind the stream to a local address */
  61 PHPAPI int php_stream_xport_bind(php_stream *stream,
  62                 const char *name, size_t namelen,
  63                 char **error_text
  64                 TSRMLS_DC);
  65 
  66 /* Connect to a remote address */
  67 PHPAPI int php_stream_xport_connect(php_stream *stream,
  68                 const char *name, size_t namelen,
  69                 int asynchronous,
  70                 struct timeval *timeout,
  71                 char **error_text,
  72                 int *error_code
  73                 TSRMLS_DC);
  74 
  75 /* Prepare to listen */
  76 PHPAPI int php_stream_xport_listen(php_stream *stream,
  77                 int backlog,
  78                 char **error_text
  79                 TSRMLS_DC);
  80 
  81 /* Get the next client and their address as a string, or the underlying address
  82  * structure.  You must efree either of these if you request them */
  83 PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client,
  84                 char **textaddr, int *textaddrlen,
  85                 void **addr, socklen_t *addrlen,
  86                 struct timeval *timeout,
  87                 char **error_text
  88                 TSRMLS_DC);
  89 
  90 /* Get the name of either the socket or it's peer */
  91 PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer,
  92                 char **textaddr, int *textaddrlen,
  93                 void **addr, socklen_t *addrlen
  94                 TSRMLS_DC);
  95 
  96 enum php_stream_xport_send_recv_flags {
  97         STREAM_OOB = 1,
  98         STREAM_PEEK = 2
  99 };
 100 
 101 /* Similar to recv() system call; read data from the stream, optionally
 102  * peeking, optionally retrieving OOB data */
 103 PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t buflen,
 104                 long flags, void **addr, socklen_t *addrlen,
 105                 char **textaddr, int *textaddrlen TSRMLS_DC);
 106 
 107 /* Similar to send() system call; send data to the stream, optionally
 108  * sending it as OOB data */
 109 PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t buflen,
 110                 long flags, void *addr, socklen_t addrlen TSRMLS_DC);
 111 
 112 typedef enum {
 113         STREAM_SHUT_RD,
 114         STREAM_SHUT_WR,
 115         STREAM_SHUT_RDWR
 116 } stream_shutdown_t;
 117 
 118 /* Similar to shutdown() system call; shut down part of a full-duplex
 119  * connection */
 120 PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how TSRMLS_DC);
 121 END_EXTERN_C()
 122 
 123 
 124 /* Structure definition for the set_option interface that the above functions wrap */
 125 
 126 typedef struct _php_stream_xport_param {
 127         enum {
 128                 STREAM_XPORT_OP_BIND, STREAM_XPORT_OP_CONNECT,
 129                 STREAM_XPORT_OP_LISTEN, STREAM_XPORT_OP_ACCEPT,
 130                 STREAM_XPORT_OP_CONNECT_ASYNC,
 131                 STREAM_XPORT_OP_GET_NAME,
 132                 STREAM_XPORT_OP_GET_PEER_NAME,
 133                 STREAM_XPORT_OP_RECV,
 134                 STREAM_XPORT_OP_SEND,
 135                 STREAM_XPORT_OP_SHUTDOWN
 136         } op;
 137         unsigned int want_addr:1;
 138         unsigned int want_textaddr:1;
 139         unsigned int want_errortext:1;
 140         unsigned int how:2;
 141 
 142         struct {
 143                 char *name;
 144                 size_t namelen;
 145                 int backlog;
 146                 struct timeval *timeout;
 147                 struct sockaddr *addr;
 148                 socklen_t addrlen;
 149                 char *buf;
 150                 size_t buflen;
 151                 long flags;
 152         } inputs;
 153         struct {
 154                 php_stream *client;
 155                 int returncode;
 156                 struct sockaddr *addr;
 157                 socklen_t addrlen;
 158                 char *textaddr;
 159                 long textaddrlen;
 160 
 161                 char *error_text;
 162                 int error_code;
 163         } outputs;
 164 } php_stream_xport_param;
 165 
 166 /* Because both client and server streams use the same mechanisms
 167    for encryption we use the LSB to denote clients.
 168 */
 169 typedef enum {
 170         STREAM_CRYPTO_METHOD_SSLv2_CLIENT = (1 << 1 | 1),
 171         STREAM_CRYPTO_METHOD_SSLv3_CLIENT = (1 << 2 | 1),
 172         /* v23 no longer negotiates SSL2 or SSL3 */
 173         STREAM_CRYPTO_METHOD_SSLv23_CLIENT = ((1 << 3) | (1 << 4) | (1 << 5) | 1),
 174         STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT = (1 << 3 | 1),
 175         STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT = (1 << 4 | 1),
 176         STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT = (1 << 5 | 1),
 177         /* tls now equates only to the specific TLSv1 method for BC with pre-5.6 */
 178         STREAM_CRYPTO_METHOD_TLS_CLIENT = (1 << 3 | 1),
 179         STREAM_CRYPTO_METHOD_TLS_ANY_CLIENT = ((1 << 3) | (1 << 4) | (1 << 5) | 1),
 180         STREAM_CRYPTO_METHOD_ANY_CLIENT = ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | 1),
 181         STREAM_CRYPTO_METHOD_SSLv2_SERVER = (1 << 1),
 182         STREAM_CRYPTO_METHOD_SSLv3_SERVER = (1 << 2),
 183         /* v23 no longer negotiates SSL2 or SSL3 */
 184         STREAM_CRYPTO_METHOD_SSLv23_SERVER = ((1 << 3) | (1 << 4) | (1 << 5)),
 185         STREAM_CRYPTO_METHOD_TLSv1_0_SERVER = (1 << 3),
 186         STREAM_CRYPTO_METHOD_TLSv1_1_SERVER = (1 << 4),
 187         STREAM_CRYPTO_METHOD_TLSv1_2_SERVER = (1 << 5),
 188         /* tls equates only to the specific TLSv1 method for BC with pre-5.6 */
 189         STREAM_CRYPTO_METHOD_TLS_SERVER = (1 << 3),
 190         STREAM_CRYPTO_METHOD_TLS_ANY_SERVER = ((1 << 3) | (1 << 4) | (1 << 5)),
 191         STREAM_CRYPTO_METHOD_ANY_SERVER = ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5))
 192 } php_stream_xport_crypt_method_t;
 193 
 194 /* These functions provide crypto support on the underlying transport */
 195 
 196 BEGIN_EXTERN_C()
 197 PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream TSRMLS_DC);
 198 PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRMLS_DC);
 199 END_EXTERN_C()
 200 
 201 typedef struct _php_stream_xport_crypto_param {
 202         enum {
 203                 STREAM_XPORT_CRYPTO_OP_SETUP,
 204                 STREAM_XPORT_CRYPTO_OP_ENABLE
 205         } op;
 206         struct {
 207                 int activate;
 208                 php_stream_xport_crypt_method_t method;
 209                 php_stream *session;
 210         } inputs;
 211         struct {
 212                 int returncode;
 213         } outputs;
 214 } php_stream_xport_crypto_param;
 215 
 216 BEGIN_EXTERN_C()
 217 PHPAPI HashTable *php_stream_xport_get_hash(void);
 218 PHPAPI php_stream_transport_factory_func php_stream_generic_socket_factory;
 219 END_EXTERN_C()
 220 
 221 /*
 222  * Local variables:
 223  * tab-width: 4
 224  * c-basic-offset: 4
 225  * End:
 226  * vim600: noet sw=4 ts=4 fdm=marker
 227  * vim<600: noet sw=4 ts=4
 228  */

/* [<][>][^][v][top][bottom][index][help] */