Back to index

php5  5.3.10
php_stream_transport.h
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Wez Furlong <wez@thebrainroom.com>                           |
00016   +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: php_stream_transport.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 #ifdef PHP_WIN32
00021 #include "config.w32.h"
00022 #include <Ws2tcpip.h>
00023 #endif
00024 
00025 #if HAVE_SYS_SOCKET_H
00026 # include <sys/socket.h>
00027 #endif
00028 
00029 typedef php_stream *(php_stream_transport_factory_func)(const char *proto, long protolen,
00030               char *resourcename, long resourcenamelen,
00031               const char *persistent_id, int options, int flags,
00032               struct timeval *timeout,
00033               php_stream_context *context STREAMS_DC TSRMLS_DC);
00034 typedef php_stream_transport_factory_func *php_stream_transport_factory;
00035 
00036 BEGIN_EXTERN_C()
00037 PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC);
00038 PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC);
00039 
00040 #define STREAM_XPORT_CLIENT               0
00041 #define STREAM_XPORT_SERVER               1
00042 
00043 #define STREAM_XPORT_CONNECT              2
00044 #define STREAM_XPORT_BIND                 4
00045 #define STREAM_XPORT_LISTEN               8
00046 #define STREAM_XPORT_CONNECT_ASYNC 16
00047 
00048 /* Open a client or server socket connection */
00049 PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options,
00050               int flags, const char *persistent_id,
00051               struct timeval *timeout,
00052               php_stream_context *context,
00053               char **error_string,
00054               int *error_code
00055               STREAMS_DC TSRMLS_DC);
00056 
00057 #define php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode) \
00058        _php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode STREAMS_CC TSRMLS_CC)
00059 
00060 /* Bind the stream to a local address */
00061 PHPAPI int php_stream_xport_bind(php_stream *stream,
00062               const char *name, long namelen,
00063               char **error_text
00064               TSRMLS_DC);
00065 
00066 /* Connect to a remote address */
00067 PHPAPI int php_stream_xport_connect(php_stream *stream,
00068               const char *name, long namelen,
00069               int asynchronous,
00070               struct timeval *timeout,
00071               char **error_text,
00072               int *error_code
00073               TSRMLS_DC);
00074 
00075 /* Prepare to listen */
00076 PHPAPI int php_stream_xport_listen(php_stream *stream,
00077               int backlog,
00078               char **error_text
00079               TSRMLS_DC);
00080 
00081 /* Get the next client and their address as a string, or the underlying address
00082  * structure.  You must efree either of these if you request them */
00083 PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client,
00084               char **textaddr, int *textaddrlen,
00085               void **addr, socklen_t *addrlen,
00086               struct timeval *timeout,
00087               char **error_text
00088               TSRMLS_DC);
00089 
00090 /* Get the name of either the socket or it's peer */
00091 PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer,
00092               char **textaddr, int *textaddrlen,
00093               void **addr, socklen_t *addrlen
00094               TSRMLS_DC);
00095 
00096 enum php_stream_xport_send_recv_flags {
00097        STREAM_OOB = 1,
00098        STREAM_PEEK = 2
00099 };
00100 
00101 /* Similar to recv() system call; read data from the stream, optionally
00102  * peeking, optionally retrieving OOB data */
00103 PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t buflen,
00104               long flags, void **addr, socklen_t *addrlen,
00105               char **textaddr, int *textaddrlen TSRMLS_DC);
00106 
00107 /* Similar to send() system call; send data to the stream, optionally
00108  * sending it as OOB data */
00109 PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t buflen,
00110               long flags, void *addr, socklen_t addrlen TSRMLS_DC);
00111 
00112 typedef enum {
00113        STREAM_SHUT_RD,
00114        STREAM_SHUT_WR,
00115        STREAM_SHUT_RDWR
00116 } stream_shutdown_t;
00117 
00118 /* Similar to shutdown() system call; shut down part of a full-duplex
00119  * connection */
00120 PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how TSRMLS_DC);
00121 END_EXTERN_C()
00122 
00123 
00124 /* Structure definition for the set_option interface that the above functions wrap */
00125 
00126 typedef struct _php_stream_xport_param {
00127        enum {
00128               STREAM_XPORT_OP_BIND, STREAM_XPORT_OP_CONNECT,
00129               STREAM_XPORT_OP_LISTEN, STREAM_XPORT_OP_ACCEPT,
00130               STREAM_XPORT_OP_CONNECT_ASYNC,
00131               STREAM_XPORT_OP_GET_NAME,
00132               STREAM_XPORT_OP_GET_PEER_NAME,
00133               STREAM_XPORT_OP_RECV,
00134               STREAM_XPORT_OP_SEND,
00135               STREAM_XPORT_OP_SHUTDOWN
00136        } op;
00137        unsigned int want_addr:1;
00138        unsigned int want_textaddr:1;
00139        unsigned int want_errortext:1;
00140        unsigned int how:2;
00141 
00142        struct {
00143               char *name;
00144               long namelen;
00145               int backlog;
00146               struct timeval *timeout;
00147               struct sockaddr *addr;
00148               socklen_t addrlen;
00149               char *buf;
00150               size_t buflen;
00151               long flags;
00152        } inputs;
00153        struct {
00154               php_stream *client;
00155               int returncode;
00156               struct sockaddr *addr;
00157               socklen_t addrlen;
00158               char *textaddr;
00159               long textaddrlen;
00160 
00161               char *error_text;
00162               int error_code;
00163        } outputs;
00164 } php_stream_xport_param;
00165 
00166 
00167 /* These functions provide crypto support on the underlying transport */
00168 typedef enum {
00169        STREAM_CRYPTO_METHOD_SSLv2_CLIENT,
00170        STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
00171        STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
00172        STREAM_CRYPTO_METHOD_TLS_CLIENT,
00173        STREAM_CRYPTO_METHOD_SSLv2_SERVER,
00174        STREAM_CRYPTO_METHOD_SSLv3_SERVER,
00175        STREAM_CRYPTO_METHOD_SSLv23_SERVER,
00176        STREAM_CRYPTO_METHOD_TLS_SERVER
00177 } php_stream_xport_crypt_method_t;
00178 
00179 BEGIN_EXTERN_C()
00180 PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream TSRMLS_DC);
00181 PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRMLS_DC);
00182 END_EXTERN_C()
00183 
00184 typedef struct _php_stream_xport_crypto_param {
00185        enum {
00186               STREAM_XPORT_CRYPTO_OP_SETUP,
00187               STREAM_XPORT_CRYPTO_OP_ENABLE
00188        } op;
00189        struct {
00190               int activate;
00191               php_stream_xport_crypt_method_t method;
00192               php_stream *session;
00193        } inputs;
00194        struct {
00195               int returncode;
00196        } outputs;
00197 } php_stream_xport_crypto_param;
00198 
00199 BEGIN_EXTERN_C()
00200 PHPAPI HashTable *php_stream_xport_get_hash(void);
00201 PHPAPI php_stream_transport_factory_func php_stream_generic_socket_factory;
00202 END_EXTERN_C()
00203 
00204 /*
00205  * Local variables:
00206  * tab-width: 4
00207  * c-basic-offset: 4
00208  * End:
00209  * vim600: noet sw=4 ts=4 fdm=marker
00210  * vim<600: noet sw=4 ts=4
00211  */