├── .gitignore ├── CREDITS ├── EXPERIMENTAL ├── README.md ├── config.m4 ├── module.c ├── module.h └── src ├── connection.c ├── connection.h ├── host.c ├── host.h ├── hs.c ├── hs.h ├── index.c ├── index.h ├── result.c └── result.h /.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | *.lo 3 | *.la 4 | .libs 5 | acinclude.m4 6 | aclocal.m4 7 | autom4te.cache 8 | build 9 | config.guess 10 | config.h 11 | config.h.in 12 | config.log 13 | config.nice 14 | config.status 15 | config.sub 16 | configure 17 | configure.in 18 | include 19 | install-sh 20 | libtool 21 | ltmain.sh 22 | Makefile 23 | Makefile.fragments 24 | Makefile.global 25 | Makefile.objects 26 | missing 27 | mkinstalldirs 28 | modules 29 | run-tests.php 30 | tests/*/*.diff 31 | tests/*/*.out 32 | tests/*/*.php 33 | tests/*/*.exp 34 | tests/*/*.log 35 | tests/*/*.sh 36 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | handlersocket -------------------------------------------------------------------------------- /EXPERIMENTAL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krakjoe/HandlerSocket/cab47a48bfa13eda7ef024618bedeca89b43b3aa/EXPERIMENTAL -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HandlerSocket 2 | ============= 3 | 4 | **NOTE: DO NOT USE THIS YET. I DO NOT KNOW IF IT WILL BE FINISHED !!** 5 | 6 | __WIP__: This is a WIP PHP 7 [HandlerSocket](http://yoshinorimatsunobu.blogspot.co.uk/search/label/handlersocket) extension 7 | 8 | API 9 | === 10 | *Also WIP ...* 11 | 12 | ```php 13 | namespace HandlerSocket { 14 | 15 | class Host { 16 | 17 | public function __construct(string $address); 18 | } 19 | 20 | class Connection { 21 | 22 | public function __construct(Host $host, int $port = 9998); 23 | 24 | public function authenticate(string $secret) : bool; 25 | 26 | public function openIndex(int $id, 27 | string $db, 28 | string $tbl, 29 | array $cols = [], 30 | int $type = INDEX::PRIMARY) : Index; 31 | } 32 | 33 | class Match { 34 | const EQ; 35 | const LT; 36 | const LTE; 37 | const GT; 38 | const GTE; 39 | 40 | public function __construct(int $op = MATCH::EQ, ... $match); 41 | } 42 | 43 | class Limit { 44 | 45 | public function __construct(int $offset, int $len = 0); 46 | } 47 | 48 | class In { 49 | 50 | public function __construct(); 51 | } 52 | 53 | class Filter { 54 | 55 | public function __construct(int $filter = FILTER::FILTER, int $op = MATCH::EQ); 56 | 57 | const FILTER; 58 | const WHILE; 59 | } 60 | 61 | class Mod { 62 | 63 | public function __construct(int $op = MOD::UPDATE, ... $update); 64 | } 65 | 66 | class Index { 67 | 68 | public function find(Match $match, Limit $limit = null, In $in = null, Filter $filter = null) : Result; 69 | 70 | public function modify(Match $match, Limit $limit = null, In $in = null, Filter $filter = null, Mod $mod = null) : Result; 71 | 72 | public function insert(array $data) : Result; 73 | 74 | const PRIMARY; 75 | } 76 | 77 | 78 | class Result { 79 | 80 | } 81 | } 82 | ``` 83 | 84 | Example 85 | ====== 86 | *Also WIP ...* 87 | 88 | ```php 89 | openIndex(1, "hs", "test", [ 97 | "name", 98 | "email", 99 | "created" 100 | ]); 101 | 102 | /* SELECT name,email,created FROM hs.test WHERE id = 1; */ 103 | $result = $index->find(1); 104 | 105 | var_dump($host, $connection, $index, $result, $result->name); 106 | ?> 107 | ``` 108 | 109 | TODO 110 | ==== 111 | 112 | - everything 113 | - no really, everything ... 114 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension HandlerSocket 3 | 4 | PHP_ARG_ENABLE(handlersocket, whether to enable HandlerSocket support, 5 | [ --enable-handlersocket Enable HandlerSocket support]) 6 | 7 | if test "$PHP_HANDLERSOCKET" != "no"; then 8 | PHP_NEW_EXTENSION(handlersocket, module.c src/host.c src/connection.c src/index.c src/match.c src/result.c src/hs.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) 9 | fi 10 | -------------------------------------------------------------------------------- /module.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "php.h" 26 | #include "php_ini.h" 27 | #include "ext/standard/info.h" 28 | #include "module.h" 29 | 30 | ZEND_DECLARE_MODULE_GLOBALS(handlersocket) 31 | 32 | #include "src/host.h" 33 | #include "src/connection.h" 34 | #include "src/index.h" 35 | #include "src/match.h" 36 | #include "src/result.h" 37 | 38 | /* {{{ php_handlersocket_init_globals 39 | */ 40 | static void php_handlersocket_init_globals(zend_handlersocket_globals *hsg) 41 | { 42 | memset(hsg, 0, sizeof(zend_handlersocket_globals)); 43 | } 44 | /* }}} */ 45 | 46 | /* {{{ PHP_MINIT_FUNCTION 47 | */ 48 | PHP_MINIT_FUNCTION(handlersocket) 49 | { 50 | ZEND_INIT_MODULE_GLOBALS(handlersocket, php_handlersocket_init_globals, NULL); 51 | 52 | PHP_MINIT(host)(INIT_FUNC_ARGS_PASSTHRU); 53 | PHP_MINIT(connection)(INIT_FUNC_ARGS_PASSTHRU); 54 | PHP_MINIT(index)(INIT_FUNC_ARGS_PASSTHRU); 55 | PHP_MINIT(match)(INIT_FUNC_ARGS_PASSTHRU); 56 | PHP_MINIT(result)(INIT_FUNC_ARGS_PASSTHRU); 57 | 58 | return SUCCESS; 59 | } 60 | /* }}} */ 61 | 62 | /* {{{ PHP_MSHUTDOWN_FUNCTION 63 | */ 64 | PHP_MSHUTDOWN_FUNCTION(handlersocket) 65 | { 66 | return SUCCESS; 67 | } 68 | /* }}} */ 69 | 70 | /* {{{ PHP_RINIT_FUNCTION 71 | */ 72 | PHP_RINIT_FUNCTION(handlersocket) 73 | { 74 | #if defined(COMPILE_DL_HANDLERSOCKET) && defined(ZTS) 75 | ZEND_TSRMLS_CACHE_UPDATE(); 76 | #endif 77 | 78 | HSG(delim) = zend_string_init(ZEND_STRL(","), 0); 79 | HSG(sep) = zend_string_init(ZEND_STRL("\t"), 0); 80 | HSG(space) = zend_string_init(ZEND_STRL(" "), 0); 81 | HSG(primary)= zend_string_init(ZEND_STRL("PRIMARY"), 0); 82 | 83 | return SUCCESS; 84 | } 85 | /* }}} */ 86 | 87 | /* {{{ PHP_RSHUTDOWN_FUNCTION 88 | */ 89 | PHP_RSHUTDOWN_FUNCTION(handlersocket) 90 | { 91 | zend_string_release(HSG(delim)); 92 | zend_string_release(HSG(sep)); 93 | zend_string_release(HSG(space)); 94 | zend_string_release(HSG(primary)); 95 | 96 | return SUCCESS; 97 | } 98 | /* }}} */ 99 | 100 | /* {{{ PHP_MINFO_FUNCTION 101 | */ 102 | PHP_MINFO_FUNCTION(handlersocket) 103 | { 104 | php_info_print_table_start(); 105 | php_info_print_table_header(2, "HandlerSocket support", "enabled"); 106 | php_info_print_table_end(); 107 | } 108 | /* }}} */ 109 | 110 | /* {{{ handlersocket_module_entry 111 | */ 112 | zend_module_entry handlersocket_module_entry = { 113 | STANDARD_MODULE_HEADER, 114 | PHP_HANDLERSOCKET_EXTNAME, 115 | NULL, 116 | PHP_MINIT(handlersocket), 117 | PHP_MSHUTDOWN(handlersocket), 118 | PHP_RINIT(handlersocket), 119 | PHP_RSHUTDOWN(handlersocket), 120 | PHP_MINFO(handlersocket), 121 | PHP_HANDLERSOCKET_VERSION, 122 | STANDARD_MODULE_PROPERTIES 123 | }; 124 | /* }}} */ 125 | 126 | #ifdef COMPILE_DL_HANDLERSOCKET 127 | #ifdef ZTS 128 | ZEND_TSRMLS_CACHE_DEFINE(); 129 | #endif 130 | ZEND_GET_MODULE(handlersocket) 131 | #endif 132 | 133 | /* 134 | * Local variables: 135 | * tab-width: 4 136 | * c-basic-offset: 4 137 | * End: 138 | * vim600: noet sw=4 ts=4 fdm=marker 139 | * vim<600: noet sw=4 ts=4 140 | */ 141 | -------------------------------------------------------------------------------- /module.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifndef PHP_MODULE_H 22 | #define PHP_MODULE_H 23 | 24 | extern zend_module_entry handlersocket_module_entry; 25 | #define phpext_handlersocket_ptr &handlersocket_module_entry 26 | 27 | #define PHP_HANDLERSOCKET_EXTNAME "HandlerSocket" 28 | #define PHP_HANDLERSOCKET_VERSION "0.0.1" 29 | 30 | #ifdef PHP_WIN32 31 | # define PHP_HANDLERSOCKET_API __declspec(dllexport) 32 | #elif defined(__GNUC__) && __GNUC__ >= 4 33 | # define PHP_HANDLERSOCKET_API __attribute__ ((visibility("default"))) 34 | #else 35 | # define PHP_HANDLERSOCKET_API 36 | #endif 37 | 38 | #ifdef ZTS 39 | #include "TSRM.h" 40 | #endif 41 | 42 | ZEND_BEGIN_MODULE_GLOBALS(handlersocket) 43 | zend_string *delim; 44 | zend_string *sep; 45 | zend_string *space; 46 | zend_string *primary; 47 | ZEND_END_MODULE_GLOBALS(handlersocket) 48 | 49 | #define HSG(v) ZEND_MODULE_GLOBALS_ACCESSOR(handlersocket, v) 50 | 51 | #if defined(ZTS) && defined(COMPILE_DL_HANDLERSOCKET) 52 | ZEND_TSRMLS_CACHE_EXTERN(); 53 | #endif 54 | 55 | #endif /* PHP_MODULE_H */ 56 | 57 | 58 | /* 59 | * Local variables: 60 | * tab-width: 4 61 | * c-basic-offset: 4 62 | * End: 63 | * vim600: noet sw=4 ts=4 fdm=marker 64 | * vim<600: noet sw=4 ts=4 65 | */ 66 | -------------------------------------------------------------------------------- /src/connection.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | #ifndef HAVE_HS_CONNECTION 21 | #define HAVE_HS_CONNECTION 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include "config.h" 25 | #endif 26 | 27 | #include "php.h" 28 | #include "hs.h" 29 | 30 | #include "../module.h" 31 | 32 | ZEND_EXTERN_MODULE_GLOBALS(handlersocket); 33 | 34 | zend_object_handlers HandlerSocket_Connection_handlers; 35 | zend_class_entry *HandlerSocket_Connection_ce; 36 | 37 | /* {{{ proto Connection Connection::__construct(Host host [, int port = 9998]) */ 38 | PHP_METHOD(Connection, __construct) { 39 | zval *host = NULL; 40 | zend_long port = 9998; 41 | 42 | if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O|l", &host, HandlerSocket_Host_ce, &port) != SUCCESS) { 43 | return; 44 | } 45 | 46 | php_hs_connect(host, port, getThis()); 47 | } 48 | 49 | ZEND_BEGIN_ARG_INFO_EX(php_hs_connection_construct_arginfo, 0, 0, 1) 50 | ZEND_ARG_OBJ_INFO(0, host, HandlerSocket\\Host, 0) 51 | ZEND_END_ARG_INFO() /* }}} */ 52 | 53 | /* {{{ proto Connection::openIndex(int id, string db, string tbl, array cols = [], string name = INDEX::PRIMARY) : Index */ 54 | PHP_METHOD(Connection, openIndex) { 55 | zend_long id = -1; 56 | zend_string *db = NULL; 57 | zend_string *tbl = NULL; 58 | zval *cols = NULL, _cols; 59 | zend_string *name = PHP_INDEX_PRIMARY; 60 | 61 | if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "lSSa|l", &id, &db, &tbl, &cols, &name) != SUCCESS) { 62 | return; 63 | } 64 | 65 | php_hs_index(getThis(), id, db, tbl, cols, name, return_value); 66 | } 67 | 68 | ZEND_BEGIN_ARG_INFO_EX(php_hs_connection_openIndex_arginfo, 0, 0, 4) 69 | ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0) 70 | ZEND_ARG_TYPE_INFO(0, db, IS_STRING, 0) 71 | ZEND_ARG_TYPE_INFO(0, tbl, IS_STRING, 0) 72 | ZEND_ARG_TYPE_INFO(0, cols, IS_ARRAY, 1) 73 | ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 1) 74 | ZEND_END_ARG_INFO() /* }}} */ 75 | 76 | /* {{{ proto Connection::authenticate(string secret) : bool */ 77 | PHP_METHOD(Connection, authenticate) { 78 | zend_string *secret = NULL; 79 | 80 | if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "S", &secret) != SUCCESS) { 81 | return; 82 | } 83 | 84 | php_hs_authenticate(getThis(), secret, return_value); 85 | } 86 | 87 | ZEND_BEGIN_ARG_INFO_EX(php_hs_connection_authenticate_arginfo, 0, 0, 1) 88 | ZEND_ARG_TYPE_INFO(0, db, IS_STRING, 0) 89 | ZEND_END_ARG_INFO() /* }}} */ 90 | 91 | /* {{{ */ 92 | zend_function_entry php_hs_connection_methods[] = { 93 | PHP_ME(Connection, __construct, php_hs_connection_construct_arginfo, ZEND_ACC_PUBLIC) 94 | PHP_ME(Connection, authenticate, php_hs_connection_authenticate_arginfo, ZEND_ACC_PUBLIC) 95 | PHP_ME(Connection, openIndex, php_hs_connection_openIndex_arginfo, ZEND_ACC_PUBLIC) 96 | PHP_FE_END 97 | }; /* }}} */ 98 | 99 | /* {{{ */ 100 | static inline zend_object* php_hs_connection_create(zend_class_entry *ce) { 101 | php_hs_connection_t *c = (php_hs_connection_t*) 102 | ecalloc(1, sizeof(php_hs_connection_t) + zend_object_properties_size(ce)); 103 | 104 | zend_object_std_init(&c->std, ce); 105 | object_properties_init(&c->std, ce); 106 | 107 | c->std.handlers = &HandlerSocket_Connection_handlers; 108 | 109 | return &c->std; 110 | } 111 | 112 | static inline void php_hs_connection_free(zend_object *o) { 113 | php_hs_close(o); 114 | } /* }}} */ 115 | 116 | /* {{{ */ 117 | PHP_MINIT_FUNCTION(connection) { 118 | zend_class_entry ce; 119 | 120 | memcpy(&HandlerSocket_Connection_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 121 | 122 | HandlerSocket_Connection_handlers.offset = XtOffsetOf(php_hs_connection_t, std); 123 | HandlerSocket_Connection_handlers.free_obj = php_hs_connection_free; 124 | 125 | INIT_NS_CLASS_ENTRY(ce, "HandlerSocket", "Connection", php_hs_connection_methods); 126 | HandlerSocket_Connection_ce = zend_register_internal_class(&ce); 127 | HandlerSocket_Connection_ce->create_object = php_hs_connection_create; 128 | } /* }}} */ 129 | #endif 130 | -------------------------------------------------------------------------------- /src/connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | #ifndef HAVE_HS_CONNECTION_H 21 | #define HAVE_HS_CONNECTION_H 22 | 23 | typedef struct _hs_connection_t { 24 | zval host; 25 | zend_long port; 26 | php_stream *stream; 27 | zend_object std; 28 | } php_hs_connection_t; 29 | 30 | #define php_hs_connection_fetch_from(o) (php_hs_connection_t*) ((char*) o - XtOffsetOf(php_hs_connection_t, std)) 31 | #define php_hs_connection_fetch(z) php_hs_connection_fetch_from(Z_OBJ_P(z)) 32 | 33 | PHP_MINIT_FUNCTION(connection); 34 | 35 | extern zend_class_entry *HandlerSocket_Connection_ce; 36 | #endif 37 | -------------------------------------------------------------------------------- /src/host.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | #ifndef HAVE_HS_HOST 21 | #define HAVE_HS_HOST 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include "config.h" 25 | #endif 26 | 27 | #include "php.h" 28 | #include "hs.h" 29 | 30 | #include "../module.h" 31 | 32 | zend_object_handlers HandlerSocket_Host_handlers; 33 | zend_class_entry *HandlerSocket_Host_ce; 34 | 35 | /* {{{ proto Host Host::__construct(string address) */ 36 | PHP_METHOD(Host, __construct) { 37 | zend_string *address = NULL; 38 | 39 | if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "S", &address) != SUCCESS) { 40 | return; 41 | } 42 | 43 | php_hs_host(address, getThis()); 44 | } 45 | 46 | ZEND_BEGIN_ARG_INFO_EX(php_hs_host_construct_arginfo, 0, 0, 1) 47 | ZEND_ARG_TYPE_INFO(0, address, IS_STRING, 0) 48 | ZEND_END_ARG_INFO() /* }}} */ 49 | 50 | /* {{{ */ 51 | zend_function_entry php_hs_host_methods[] = { 52 | PHP_ME(Host, __construct, php_hs_host_construct_arginfo, ZEND_ACC_PUBLIC) 53 | PHP_FE_END 54 | }; /* }}} */ 55 | 56 | /* {{{ */ 57 | static inline zend_object* php_hs_host_create(zend_class_entry *ce) { 58 | php_hs_host_t *h = (php_hs_host_t*) 59 | ecalloc(1, sizeof(php_hs_host_t) + zend_object_properties_size(ce)); 60 | 61 | zend_object_std_init(&h->std, ce); 62 | object_properties_init(&h->std, ce); 63 | 64 | h->std.handlers = &HandlerSocket_Host_handlers; 65 | 66 | return &h->std; 67 | } 68 | 69 | static inline void php_hs_host_free(zend_object *o) { 70 | php_hs_host_t *h = php_hs_host_fetch_from(o); 71 | 72 | if (h->address) { 73 | zend_string_release(h->address); 74 | } 75 | 76 | zend_object_std_dtor(o); 77 | } /* }}} */ 78 | 79 | /* {{{ */ 80 | PHP_MINIT_FUNCTION(host) { 81 | zend_class_entry ce; 82 | 83 | memcpy(&HandlerSocket_Host_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 84 | 85 | HandlerSocket_Host_handlers.offset = XtOffsetOf(php_hs_host_t, std); 86 | HandlerSocket_Host_handlers.free_obj = php_hs_host_free; 87 | 88 | INIT_NS_CLASS_ENTRY(ce, "HandlerSocket", "Host", php_hs_host_methods); 89 | HandlerSocket_Host_ce = zend_register_internal_class(&ce); 90 | HandlerSocket_Host_ce->create_object = php_hs_host_create; 91 | } /* }}} */ 92 | 93 | /* {{{ */ 94 | char *php_hs_host_string(zval *host) { 95 | php_hs_host_t *h = 96 | php_hs_host_fetch(host); 97 | return ZSTR_VAL(h->address); 98 | } /* }}} */ 99 | #endif 100 | -------------------------------------------------------------------------------- /src/host.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | #ifndef HAVE_HS_HOST_H 21 | #define HAVE_HS_HOST_H 22 | 23 | typedef struct _hs_host_t { 24 | zend_string *address; 25 | zend_object std; 26 | } php_hs_host_t; 27 | 28 | #define php_hs_host_fetch_from(o) (php_hs_host_t*) ((char*) o - XtOffsetOf(php_hs_host_t, std)) 29 | #define php_hs_host_fetch(z) php_hs_host_fetch_from(Z_OBJ_P(z)) 30 | 31 | PHP_MINIT_FUNCTION(host); 32 | 33 | extern zend_class_entry *HandlerSocket_Host_ce; 34 | 35 | char* php_hs_host_string(zval *host); 36 | #endif 37 | -------------------------------------------------------------------------------- /src/hs.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifndef PHP_HS 22 | #define PHP_HS 23 | 24 | #include "php.h" 25 | #include "hs.h" 26 | 27 | #include "../module.h" 28 | 29 | ZEND_EXTERN_MODULE_GLOBALS(handlersocket) 30 | 31 | #include "../module.h" 32 | 33 | #define php_hs_write(c, f, ...) php_stream_printf((c)->stream, f, __VA_ARGS__) 34 | #define php_hs_ok(c) do { \ 35 | char buffer[128]; \ 36 | \ 37 | if (!php_stream_gets((c)->stream, buffer, sizeof(buffer))) { \ 38 | zend_throw_exception_ex(NULL, 0, \ 39 | "failed to read from connection"); \ 40 | return; \ 41 | } \ 42 | \ 43 | if (sscanf(buffer, "0\t1\n") != SUCCESS) { \ 44 | zend_throw_exception_ex(NULL, 0, \ 45 | "protocol error"); \ 46 | return; \ 47 | } \ 48 | } while (0) 49 | 50 | php_hs_host_t* php_hs_host(zend_string *address, zval *result) { 51 | php_hs_host_t *h = php_hs_host_fetch(result); 52 | 53 | if (!address) { 54 | return NULL; 55 | } 56 | 57 | h->address = zend_string_copy(address); 58 | 59 | return h; 60 | } 61 | 62 | php_hs_connection_t* php_hs_connect(zval *host, zend_long port, zval *result) { 63 | zend_string *name = strpprintf(0, "%s:%ld", php_hs_host_string(host), port), 64 | *errstr = NULL; 65 | struct timeval tv; 66 | int _errno = SUCCESS; 67 | php_hs_connection_t *c = php_hs_connection_fetch(result); 68 | 69 | c->stream = php_stream_xport_create(ZSTR_VAL(name), ZSTR_LEN(name), 70 | REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, 71 | NULL, /* persistent key (char*) */ 72 | &tv, NULL, &errstr, &_errno); 73 | zend_string_release(name); 74 | 75 | if (_errno == SUCCESS && c->stream) { 76 | ZVAL_COPY(&c->host, host); 77 | c->port = port; 78 | return c; 79 | } 80 | 81 | zend_throw_exception_ex(NULL, 0, 82 | "error occured while negotiating connection: %d: %s", _errno, ZSTR_VAL(errstr)); 83 | zend_string_release(errstr); 84 | return NULL; 85 | } 86 | 87 | void php_hs_authenticate(zval *connection, zend_string *secret, zval *result) { 88 | php_hs_connection_t *c = php_hs_connection_fetch(connection); 89 | 90 | ZVAL_FALSE(result); 91 | 92 | php_hs_write(c, 93 | "A\t1\t%s\n", ZSTR_VAL(secret)); 94 | php_hs_ok(c); 95 | 96 | ZVAL_TRUE(result); 97 | } 98 | 99 | php_hs_index_t *php_hs_index(zval *connection, zend_long id, zend_string *db, zend_string *tbl, zval *cols, zend_string *name, zval *result) { 100 | php_hs_index_t *i = NULL; 101 | php_hs_connection_t *c = php_hs_connection_fetch(connection); 102 | zval _cols; 103 | 104 | object_init_ex(result, HandlerSocket_Index_ce); 105 | 106 | i = php_hs_index_fetch(result); 107 | 108 | php_implode(HSG(delim), cols, &_cols); 109 | 110 | if (name == PHP_INDEX_PRIMARY) 111 | name = HSG(primary); 112 | 113 | php_hs_write(c, 114 | "P\t%ld\t%s\t%s\t%s\t%s\n", 115 | id, 116 | ZSTR_VAL(db), 117 | ZSTR_VAL(tbl), 118 | ZSTR_VAL(name), 119 | Z_STRVAL(_cols)); 120 | 121 | zval_ptr_dtor(&_cols); 122 | 123 | php_hs_ok(c); 124 | 125 | ZVAL_COPY(&i->connection, connection); 126 | i->id = id; 127 | i->db = zend_string_copy(db); 128 | i->tbl = zend_string_copy(tbl); 129 | i->name = zend_string_copy(name); 130 | ZVAL_COPY(&i->cols, cols); 131 | 132 | return i; 133 | } 134 | 135 | static inline php_hs_result_t* php_hs_result_from(zval *index, char *buffer, size_t length, zval *result) { 136 | php_hs_result_t *r = php_hs_result_fetch(result); 137 | long limit = 0; 138 | zend_string *response; 139 | 140 | limit = atol(&buffer[2]); 141 | 142 | if (!limit) { 143 | return; 144 | } 145 | 146 | response = zend_string_init( 147 | &buffer[4], length-5, 0); 148 | array_init_size(&r->fields, limit); 149 | php_explode( 150 | HSG(sep), response, &r->fields); 151 | zend_string_release(response); 152 | 153 | ZVAL_COPY(&r->index, index); 154 | 155 | if (Z_ARRVAL(r->fields)->nTableSize) { 156 | zval *member; 157 | zend_long idx; 158 | zend_string *k; 159 | php_hs_index_t *i = php_hs_index_fetch(&r->index); 160 | 161 | rebuild_object_properties(&r->std); 162 | 163 | ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(r->fields), idx, k, member) { 164 | zval *key = zend_hash_index_find( 165 | Z_ARRVAL(i->cols), idx); 166 | 167 | if (Z_TYPE_P(key) != IS_STRING) 168 | continue; 169 | 170 | if (zend_hash_update(r->std.properties, Z_STR_P(key), member)) 171 | Z_TRY_ADDREF_P(member); 172 | } ZEND_HASH_FOREACH_END(); 173 | } 174 | 175 | return r; 176 | } 177 | 178 | php_hs_result_t* php_hs_find(zval *index, zval *match, zval *result) { 179 | php_hs_index_t *i = php_hs_index_fetch(index); 180 | php_hs_connection_t *r = php_hs_connection_fetch(&i->connection); 181 | php_hs_match_t *m = php_hs_match_fetch(match); 182 | 183 | char buffer[8192]; 184 | size_t length = 0; 185 | 186 | object_init_ex(result, HandlerSocket_Result_ce); 187 | 188 | php_stream_printf( 189 | r->stream, 190 | "%ld\t%s\t1\t%s\n", 191 | i->id, 192 | php_hs_op(m->op), 193 | ZSTR_VAL(m->match)); 194 | 195 | if (!php_stream_get_line(r->stream, buffer, sizeof(buffer), &length)) { 196 | return NULL; 197 | } 198 | 199 | if (buffer[0] != '0') { 200 | return; 201 | } 202 | 203 | return php_hs_result_from(index, buffer, length, result); 204 | } 205 | 206 | void php_hs_close(zend_object *o) { 207 | php_hs_connection_t *c = php_hs_connection_fetch_from(o); 208 | 209 | if (Z_TYPE(c->host) != IS_UNDEF) { 210 | zval_ptr_dtor(&c->host); 211 | } 212 | 213 | if (c->stream) { 214 | php_stream_close(c->stream); 215 | } 216 | 217 | zend_object_std_dtor(o); 218 | } 219 | 220 | #endif /* PHP_HS */ 221 | 222 | /* 223 | * Local variables: 224 | * tab-width: 4 225 | * c-basic-offset: 4 226 | * End: 227 | * vim600: noet sw=4 ts=4 fdm=marker 228 | * vim<600: noet sw=4 ts=4 229 | */ 230 | -------------------------------------------------------------------------------- /src/hs.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifndef PHP_HS_H 22 | #define PHP_HS_H 23 | 24 | #include "host.h" 25 | #include "connection.h" 26 | #include "index.h" 27 | #include "match.h" 28 | #include "result.h" 29 | 30 | php_hs_host_t* php_hs_host(zend_string *address, zval *result); 31 | 32 | php_hs_connection_t* php_hs_connect(zval *host, zend_long port, zval *result); 33 | 34 | void php_hs_authenticate(zval *connection, zend_string *secret, zval *result); 35 | 36 | php_hs_index_t* php_hs_index(zval *connection, zend_long id, zend_string *db, zend_string *tbl, zval *cols, zend_string *name, zval *result); 37 | 38 | php_hs_result_t* php_hs_find(zval *index, zval *match, zval *result); 39 | 40 | void php_hs_close(zend_object *object); 41 | 42 | #endif /* PHP_HS_H */ 43 | 44 | 45 | /* 46 | * Local variables: 47 | * tab-width: 4 48 | * c-basic-offset: 4 49 | * End: 50 | * vim600: noet sw=4 ts=4 fdm=marker 51 | * vim<600: noet sw=4 ts=4 52 | */ 53 | -------------------------------------------------------------------------------- /src/index.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | #ifndef HAVE_HS_INDEX 21 | #define HAVE_HS_INDEX 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include "config.h" 25 | #endif 26 | 27 | #include "php.h" 28 | #include "hs.h" 29 | 30 | #include "../module.h" 31 | 32 | 33 | #include "zend_operators.h" 34 | 35 | ZEND_EXTERN_MODULE_GLOBALS(handlersocket); 36 | 37 | zend_object_handlers HandlerSocket_Index_handlers; 38 | zend_class_entry *HandlerSocket_Index_ce; 39 | 40 | /* {{{ proto Index Index::__construct() */ 41 | PHP_METHOD(Index, __construct) { 42 | 43 | } 44 | 45 | ZEND_BEGIN_ARG_INFO_EX(php_hs_index_construct_arginfo, 0, 0, 0) 46 | ZEND_END_ARG_INFO() /* }}} */ 47 | 48 | /* {{{ proto Index Index::find(Match match, int op = INDEX::EQ) */ 49 | PHP_METHOD(Index, find) { 50 | zval *match = NULL; 51 | 52 | zend_long op = HS_EQ; 53 | 54 | if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &match, HandlerSocket_Match_ce) != SUCCESS) { 55 | return; 56 | } 57 | 58 | php_hs_find(getThis(), match, return_value); 59 | } 60 | 61 | ZEND_BEGIN_ARG_INFO_EX(php_hs_index_find_arginfo, 0, 0, 1) 62 | ZEND_ARG_INFO(0, data) 63 | ZEND_ARG_TYPE_INFO(0, op, IS_LONG, 0) 64 | ZEND_END_ARG_INFO() /* }}} */ 65 | 66 | /* {{{ */ 67 | zend_function_entry php_hs_index_methods[] = { 68 | PHP_ME(Index, __construct, php_hs_index_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) 69 | PHP_ME(Index, find, php_hs_index_find_arginfo, ZEND_ACC_PUBLIC) 70 | PHP_FE_END 71 | }; /* }}} */ 72 | 73 | /* {{{ */ 74 | static inline zend_object* php_hs_index_create(zend_class_entry *ce) { 75 | php_hs_index_t *i = (php_hs_index_t*) 76 | ecalloc(1, sizeof(php_hs_index_t) + zend_object_properties_size(ce)); 77 | 78 | zend_object_std_init(&i->std, ce); 79 | object_properties_init(&i->std, ce); 80 | 81 | i->std.handlers = &HandlerSocket_Index_handlers; 82 | 83 | return &i->std; 84 | } 85 | 86 | static inline void php_hs_index_free(zend_object *o) { 87 | php_hs_index_t *i = php_hs_index_fetch_from(o); 88 | 89 | if (i->db) { 90 | zend_string_release(i->db); 91 | } 92 | 93 | if (i->tbl) { 94 | zend_string_release(i->tbl); 95 | } 96 | 97 | if (i->name) { 98 | zend_string_release(i->name); 99 | } 100 | 101 | if (Z_TYPE(i->cols) != IS_UNDEF) { 102 | zval_ptr_dtor(&i->cols); 103 | } 104 | 105 | if (Z_TYPE(i->connection) != IS_UNDEF) { 106 | zval_ptr_dtor(&i->connection); 107 | } 108 | 109 | zend_object_std_dtor(o); 110 | } /* }}} */ 111 | 112 | /* {{{ */ 113 | PHP_MINIT_FUNCTION(index) { 114 | zend_class_entry ce; 115 | 116 | memcpy(&HandlerSocket_Index_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 117 | 118 | HandlerSocket_Index_handlers.offset = XtOffsetOf(php_hs_index_t, std); 119 | HandlerSocket_Index_handlers.free_obj = php_hs_index_free; 120 | 121 | INIT_NS_CLASS_ENTRY(ce, "HandlerSocket", "Index", php_hs_index_methods); 122 | HandlerSocket_Index_ce = zend_register_internal_class(&ce); 123 | HandlerSocket_Index_ce->create_object = php_hs_index_create; 124 | 125 | zend_declare_class_constant_string(HandlerSocket_Index_ce, ZEND_STRL("PRIMARY"), "PRIMARY"); 126 | } /* }}} */ 127 | #endif 128 | -------------------------------------------------------------------------------- /src/index.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | #ifndef HAVE_HS_INDEX_H 21 | #define HAVE_HS_INDEX_H 22 | 23 | typedef struct _hs_index_t { 24 | zval connection; 25 | zend_long id; 26 | zend_string *db; 27 | zend_string *tbl; 28 | zend_string *name; 29 | zval cols; 30 | zend_object std; 31 | } php_hs_index_t; 32 | 33 | #define php_hs_index_fetch_from(o) (php_hs_index_t*) ((char*) o - XtOffsetOf(php_hs_index_t, std)) 34 | #define php_hs_index_fetch(z) php_hs_index_fetch_from(Z_OBJ_P(z)) 35 | 36 | PHP_MINIT_FUNCTION(index); 37 | 38 | extern zend_class_entry *HandlerSocket_Index_ce; 39 | 40 | #define PHP_INDEX_PRIMARY ((zend_string*)-1) 41 | #endif 42 | -------------------------------------------------------------------------------- /src/result.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | #ifndef HAVE_HS_RESULT 21 | #define HAVE_HS_RESULT 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include "config.h" 25 | #endif 26 | 27 | #include "php.h" 28 | #include "hs.h" 29 | 30 | #include "../module.h" 31 | 32 | #include "zend_operators.h" 33 | 34 | ZEND_EXTERN_MODULE_GLOBALS(handlersocket); 35 | 36 | zend_object_handlers HandlerSocket_Result_handlers; 37 | zend_class_entry *HandlerSocket_Result_ce; 38 | 39 | /* {{{ proto Result Result::__construct() */ 40 | PHP_METHOD(Result, __construct) { 41 | 42 | } 43 | 44 | ZEND_BEGIN_ARG_INFO_EX(php_hs_result_construct_arginfo, 0, 0, 0) 45 | ZEND_END_ARG_INFO() /* }}} */ 46 | 47 | /* {{{ */ 48 | zend_function_entry php_hs_result_methods[] = { 49 | PHP_ME(Result, __construct, php_hs_result_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) 50 | PHP_FE_END 51 | }; /* }}} */ 52 | 53 | /* {{{ */ 54 | static inline zend_object* php_hs_result_create(zend_class_entry *ce) { 55 | php_hs_result_t *r = (php_hs_result_t*) 56 | ecalloc(1, sizeof(php_hs_result_t) + zend_object_properties_size(ce)); 57 | 58 | zend_object_std_init(&r->std, ce); 59 | object_properties_init(&r->std, ce); 60 | 61 | r->std.handlers = &HandlerSocket_Result_handlers; 62 | 63 | return &r->std; 64 | } 65 | 66 | static inline HashTable* php_hs_result_debug(zval *object, int *is_temp) { 67 | php_hs_result_t *r = php_hs_result_fetch(object); 68 | php_hs_index_t *i = php_hs_index_fetch(&r->index); 69 | HashTable *t; 70 | 71 | ALLOC_HASHTABLE(t); 72 | *is_temp = 1; 73 | zend_hash_init(t, 2, NULL, ZVAL_PTR_DTOR, 0); 74 | 75 | if (zend_hash_str_update(t, ":index:", sizeof(":index:"), &i->cols)) 76 | Z_ADDREF(i->cols); 77 | 78 | if (zend_hash_str_update(t, ":fields:", sizeof(":fields:"), &r->fields)) 79 | Z_ADDREF(r->fields); 80 | 81 | return t; 82 | } 83 | 84 | static inline void php_hs_result_free(zend_object *o) { 85 | php_hs_result_t *r = php_hs_result_fetch_from(o); 86 | 87 | if (Z_TYPE(r->fields) != IS_UNDEF) { 88 | zval_ptr_dtor(&r->fields); 89 | } 90 | 91 | if (Z_TYPE(r->index) != IS_UNDEF) { 92 | zval_ptr_dtor(&r->index); 93 | } 94 | 95 | zend_object_std_dtor(o); 96 | } /* }}} */ 97 | 98 | /* {{{ */ 99 | PHP_MINIT_FUNCTION(result) { 100 | zend_class_entry ce; 101 | 102 | memcpy(&HandlerSocket_Result_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 103 | 104 | HandlerSocket_Result_handlers.offset = XtOffsetOf(php_hs_result_t, std); 105 | HandlerSocket_Result_handlers.free_obj = php_hs_result_free; 106 | HandlerSocket_Result_handlers.get_debug_info = php_hs_result_debug; 107 | 108 | INIT_NS_CLASS_ENTRY(ce, "HandlerSocket", "Result", php_hs_result_methods); 109 | HandlerSocket_Result_ce = zend_register_internal_class(&ce); 110 | HandlerSocket_Result_ce->create_object = php_hs_result_create; 111 | } /* }}} */ 112 | #endif 113 | -------------------------------------------------------------------------------- /src/result.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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: krakjoe | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | #ifndef HAVE_HS_RESULT_H 21 | #define HAVE_HS_RESULT_H 22 | 23 | typedef struct _hs_result_t { 24 | zend_long count; 25 | zval fields; 26 | zval index; 27 | zend_object std; 28 | } php_hs_result_t; 29 | 30 | #define php_hs_result_fetch_from(o) (php_hs_result_t*) ((char*) o - XtOffsetOf(php_hs_result_t, std)) 31 | #define php_hs_result_fetch(z) php_hs_result_fetch_from(Z_OBJ_P(z)) 32 | 33 | PHP_MINIT_FUNCTION(result); 34 | 35 | extern zend_class_entry *HandlerSocket_Result_ce; 36 | #endif 37 | --------------------------------------------------------------------------------