cvs: pecl /Net_Gopher config.m4 gopher_fopen_wrapper.c gopher_fopen_wrapper.h package.xml
| From: | Sara Golemon | Date: | Thu, 17 Jul 2003 03:11:32 +0000 |
| Subject: | cvs: pecl /Net_Gopher config.m4 gopher_fopen_wrapper.c gopher_fopen_wrapper.h package.xml | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-367@lists.php.net to get a copy of this message | ||
pollita Wed Jul 16 23:11:32 2003 EDT
Added files:
/pecl/Net_Gopher config.m4 gopher_fopen_wrapper.c
gopher_fopen_wrapper.h package.xml
Log:
Initial Commit
Index: pecl/Net_Gopher/config.m4 +++ pecl/Net_Gopher/config.m4 PHP_ARG_ENABLE(gopher, whether to enable the gopher stream wrapper, [ --enable-gopher Enable PHP gopher:// wrapper.]) if test "$PHP_GOPHER" == "yes"; then AC_DEFINE(WITH_GOPHER, 1, [Whether you want gopher]) PHP_NEW_EXTENSION(gopher, gopher_fopen_wrapper.c, $ext_shared,,) fi Index: pecl/Net_Gopher/gopher_fopen_wrapper.c +++ pecl/Net_Gopher/gopher_fopen_wrapper.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <pollita@php.net> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #if WITH_GOPHER #include "gopher_fopen_wrapper.h" #include "php_globals.h" #include "php_network.h" #include "ext/standard/url.h" #include "ext/standard/info.h" #include <sys/socket.h> function_entry gopher_functions[] = { PHP_FE(gopher_parsedir, NULL) {NULL, NULL, NULL} }; zend_module_entry gopher_module_entry = { STANDARD_MODULE_HEADER, "gopher", gopher_functions, PHP_MINIT(gopher), PHP_MSHUTDOWN(gopher), NULL, /* RINIT */ NULL, /* RSHUTDOWN */ PHP_MINFO(gopher), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_GOPHER ZEND_GET_MODULE(gopher) #endif /* {{{ proto array gopher_parsedir(string dirent) Returns an array containing the directory reference described in dirent */ PHP_FUNCTION(gopher_parsedir) { char *dirent = NULL; int dirent_len = 0; char *p, *t; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dirent, &dirent_len) == FAILURE) { WRONG_PARAM_COUNT; } if (dirent_len < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string passed"); RETURN_FALSE; } array_init(return_value); switch (dirent[0]) { case 'i': /* Informative */ add_assoc_long(return_value, "type", GOPHER_INFO); dirent++; p = strtok_r(dirent, "\t", &t); if (p) { add_assoc_string(return_value, "info", p, 1); } break; case '0': case '4': case '5': case '6': case '9': case 'h': if (dirent[0] == '0') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_DOCUMENT); } if (dirent[0] == '4') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_BINHEX); } if (dirent[0] == '5') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_DOSBINARY); } if (dirent[0] == '6') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_UUENCODED); } if (dirent[0] == '9') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_BINARY); } if (dirent[0] == 'h') { /* HTTP */ add_assoc_long(return_value, "type", GOPHER_HTTP); } dirent++; p = strtok_r(dirent, "\t", &t); if (p) { add_assoc_string(return_value, "title", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "path", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "host", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "port", p, 1); } break; case '1': /* Directory */ add_assoc_long(return_value, "type", GOPHER_DIRECTORY); dirent++; p = strtok_r(dirent, "\t", &t); if (p) { add_assoc_string(return_value, "title", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "path", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "host", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "port", p, 1); } break; default: add_assoc_long(return_value, "type", GOPHER_UNKNOWN); add_assoc_stringl(return_value, "data", dirent + 1, dirent_len - 1, 1); } } /* }}} */ /* {{{ php_stream_url_wrap_gopher */ php_stream * php_stream_url_wrap_gopher(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { php_stream *stream = NULL; php_url *resource = NULL; resource = php_url_parse((char *) path); if (!resource || !resource->scheme || !resource->host) { goto connect_errexit; } if (strcasecmp("gopher", resource->scheme)) { goto connect_errexit; } /* use port 70 if one wasn't specified */ if (resource->port == 0) { resource->port = 70; } stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, NULL, 0); if (stream == NULL) { goto connect_errexit; } php_stream_context_set(stream, context); php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); if (resource->path) { php_stream_write_string(stream, resource->path); } php_stream_write_string(stream, "\r\n"); php_url_free(resource); return stream; connect_errexit: if (resource) { php_url_free(resource); } if (stream) { php_stream_close(stream); } return NULL; } /* }}} */ /* {{{ php_stream_gopher_stat */ static int php_stream_gopher_stat(php_stream_wrapper *wrapper, php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) { /* For now, we return with a failure code to prevent the underlying * file's details from being used instead. */ return -1; } /* }}} */ static php_stream_wrapper_ops gopher_stream_wops = { php_stream_url_wrap_gopher, NULL, /* stream_close */ php_stream_gopher_stat, NULL, /* stat_url */ NULL, /* opendir */ "GOPHER", NULL /* unlink */ }; PHPAPI php_stream_wrapper php_stream_gopher_wrapper = { &gopher_stream_wops, NULL, 1 /* is_url */ }; PHP_MINIT_FUNCTION(gopher) { REGISTER_LONG_CONSTANT("GOPHER_INFO", GOPHER_INFO, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_UNKNOWN", GOPHER_UNKNOWN, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_DOCUMENT", GOPHER_DOCUMENT, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_DIRECTORY", GOPHER_DIRECTORY, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_BINHEX", GOPHER_BINHEX, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_DOSBINARY", GOPHER_DOSBINARY, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_UUENCODED", GOPHER_UUENCODED, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_BINARY", GOPHER_BINARY, CONST_CS | CONST_PERSISTENT ); return php_register_url_stream_wrapper("gopher", &php_stream_gopher_wrapper TSRMLS_CC);; } PHP_MSHUTDOWN_FUNCTION(gopher) { return php_unregister_url_stream_wrapper("gopher" TSRMLS_CC); } PHP_MINFO_FUNCTION(gopher) { php_info_print_table_start(); php_info_print_table_row(2, "Gopher Wrapper", "enabled"); php_info_print_table_end(); } #endif /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */ Index: pecl/Net_Gopher/gopher_fopen_wrapper.h +++ pecl/Net_Gopher/gopher_fopen_wrapper.h /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <pollita@php.net> | +----------------------------------------------------------------------+ */ #ifndef PHP_GOPHER_H #define PHP_GOPHER_H #if WITH_GOPHER #define GOPHER_UNKNOWN -1 #define GOPHER_DOCUMENT 0 #define GOPHER_DIRECTORY 1 #define GOPHER_BINHEX 4 #define GOPHER_DOSBINARY 5 #define GOPHER_UUENCODED 6 #define GOPHER_BINARY 9 #define GOPHER_HTTP 254 #define GOPHER_INFO 255 extern zend_module_entry gopher_module_entry; #define phpext_gopher_ptr &gopher_module_entry PHP_MINIT_FUNCTION(gopher); PHP_MSHUTDOWN_FUNCTION(gopher); PHP_MINFO_FUNCTION(gopher); PHP_FUNCTION(gopher_parsedir); #else #define phpext_gopher_ptr NULL #endif /* WITH_GOPHER */ #endif /* PHP_GOPHER_H */ Index: pecl/Net_Gopher/package.xml +++ pecl/Net_Gopher/package.xml <package version="1.0"> <name>Net_Gopher</name> <summary>fopen wrapper for the gopher protocol</summary> <description> fopen wrapper for retreiving documents via the gopher protocol. Includes additional function for parsing gopher directory entries. </description> <license>PHP</license> <maintainers> <maintainer> <user>pollita</user> <name>Sara Golemon</name> <email>pollita@php.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1</version> <state>beta</state> <date>2003-07-06</date> <notes>Initial Release</notes> <filelist> <file role="src" name="config.m4"/> <file role="src" name="gopher_fopen_wrapper.c"/> <file role="src" name="gopher_fopen_wrapper.h"/> </filelist> </release> <deps> <dep type="php" rel="ge">4.3.0</dep> </deps> </package>
Index: pecl/Net_Gopher/config.m4 +++ pecl/Net_Gopher/config.m4 PHP_ARG_ENABLE(gopher, whether to enable the gopher stream wrapper, [ --enable-gopher Enable PHP gopher:// wrapper.]) if test "$PHP_GOPHER" == "yes"; then AC_DEFINE(WITH_GOPHER, 1, [Whether you want gopher]) PHP_NEW_EXTENSION(gopher, gopher_fopen_wrapper.c, $ext_shared,,) fi Index: pecl/Net_Gopher/gopher_fopen_wrapper.c +++ pecl/Net_Gopher/gopher_fopen_wrapper.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <pollita@php.net> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #if WITH_GOPHER #include "gopher_fopen_wrapper.h" #include "php_globals.h" #include "php_network.h" #include "ext/standard/url.h" #include "ext/standard/info.h" #include <sys/socket.h> function_entry gopher_functions[] = { PHP_FE(gopher_parsedir, NULL) {NULL, NULL, NULL} }; zend_module_entry gopher_module_entry = { STANDARD_MODULE_HEADER, "gopher", gopher_functions, PHP_MINIT(gopher), PHP_MSHUTDOWN(gopher), NULL, /* RINIT */ NULL, /* RSHUTDOWN */ PHP_MINFO(gopher), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_GOPHER ZEND_GET_MODULE(gopher) #endif /* {{{ proto array gopher_parsedir(string dirent) Returns an array containing the directory reference described in dirent */ PHP_FUNCTION(gopher_parsedir) { char *dirent = NULL; int dirent_len = 0; char *p, *t; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dirent, &dirent_len) == FAILURE) { WRONG_PARAM_COUNT; } if (dirent_len < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string passed"); RETURN_FALSE; } array_init(return_value); switch (dirent[0]) { case 'i': /* Informative */ add_assoc_long(return_value, "type", GOPHER_INFO); dirent++; p = strtok_r(dirent, "\t", &t); if (p) { add_assoc_string(return_value, "info", p, 1); } break; case '0': case '4': case '5': case '6': case '9': case 'h': if (dirent[0] == '0') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_DOCUMENT); } if (dirent[0] == '4') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_BINHEX); } if (dirent[0] == '5') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_DOSBINARY); } if (dirent[0] == '6') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_UUENCODED); } if (dirent[0] == '9') { /* Normal File */ add_assoc_long(return_value, "type", GOPHER_BINARY); } if (dirent[0] == 'h') { /* HTTP */ add_assoc_long(return_value, "type", GOPHER_HTTP); } dirent++; p = strtok_r(dirent, "\t", &t); if (p) { add_assoc_string(return_value, "title", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "path", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "host", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "port", p, 1); } break; case '1': /* Directory */ add_assoc_long(return_value, "type", GOPHER_DIRECTORY); dirent++; p = strtok_r(dirent, "\t", &t); if (p) { add_assoc_string(return_value, "title", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "path", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "host", p, 1); } p = strtok_r(NULL, "\t", &t); if (p) { add_assoc_string(return_value, "port", p, 1); } break; default: add_assoc_long(return_value, "type", GOPHER_UNKNOWN); add_assoc_stringl(return_value, "data", dirent + 1, dirent_len - 1, 1); } } /* }}} */ /* {{{ php_stream_url_wrap_gopher */ php_stream * php_stream_url_wrap_gopher(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { php_stream *stream = NULL; php_url *resource = NULL; resource = php_url_parse((char *) path); if (!resource || !resource->scheme || !resource->host) { goto connect_errexit; } if (strcasecmp("gopher", resource->scheme)) { goto connect_errexit; } /* use port 70 if one wasn't specified */ if (resource->port == 0) { resource->port = 70; } stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, NULL, 0); if (stream == NULL) { goto connect_errexit; } php_stream_context_set(stream, context); php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); if (resource->path) { php_stream_write_string(stream, resource->path); } php_stream_write_string(stream, "\r\n"); php_url_free(resource); return stream; connect_errexit: if (resource) { php_url_free(resource); } if (stream) { php_stream_close(stream); } return NULL; } /* }}} */ /* {{{ php_stream_gopher_stat */ static int php_stream_gopher_stat(php_stream_wrapper *wrapper, php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) { /* For now, we return with a failure code to prevent the underlying * file's details from being used instead. */ return -1; } /* }}} */ static php_stream_wrapper_ops gopher_stream_wops = { php_stream_url_wrap_gopher, NULL, /* stream_close */ php_stream_gopher_stat, NULL, /* stat_url */ NULL, /* opendir */ "GOPHER", NULL /* unlink */ }; PHPAPI php_stream_wrapper php_stream_gopher_wrapper = { &gopher_stream_wops, NULL, 1 /* is_url */ }; PHP_MINIT_FUNCTION(gopher) { REGISTER_LONG_CONSTANT("GOPHER_INFO", GOPHER_INFO, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_UNKNOWN", GOPHER_UNKNOWN, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_DOCUMENT", GOPHER_DOCUMENT, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_DIRECTORY", GOPHER_DIRECTORY, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_BINHEX", GOPHER_BINHEX, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_DOSBINARY", GOPHER_DOSBINARY, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_UUENCODED", GOPHER_UUENCODED, CONST_CS | CONST_PERSISTENT ); REGISTER_LONG_CONSTANT("GOPHER_BINARY", GOPHER_BINARY, CONST_CS | CONST_PERSISTENT ); return php_register_url_stream_wrapper("gopher", &php_stream_gopher_wrapper TSRMLS_CC);; } PHP_MSHUTDOWN_FUNCTION(gopher) { return php_unregister_url_stream_wrapper("gopher" TSRMLS_CC); } PHP_MINFO_FUNCTION(gopher) { php_info_print_table_start(); php_info_print_table_row(2, "Gopher Wrapper", "enabled"); php_info_print_table_end(); } #endif /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */ Index: pecl/Net_Gopher/gopher_fopen_wrapper.h +++ pecl/Net_Gopher/gopher_fopen_wrapper.h /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <pollita@php.net> | +----------------------------------------------------------------------+ */ #ifndef PHP_GOPHER_H #define PHP_GOPHER_H #if WITH_GOPHER #define GOPHER_UNKNOWN -1 #define GOPHER_DOCUMENT 0 #define GOPHER_DIRECTORY 1 #define GOPHER_BINHEX 4 #define GOPHER_DOSBINARY 5 #define GOPHER_UUENCODED 6 #define GOPHER_BINARY 9 #define GOPHER_HTTP 254 #define GOPHER_INFO 255 extern zend_module_entry gopher_module_entry; #define phpext_gopher_ptr &gopher_module_entry PHP_MINIT_FUNCTION(gopher); PHP_MSHUTDOWN_FUNCTION(gopher); PHP_MINFO_FUNCTION(gopher); PHP_FUNCTION(gopher_parsedir); #else #define phpext_gopher_ptr NULL #endif /* WITH_GOPHER */ #endif /* PHP_GOPHER_H */ Index: pecl/Net_Gopher/package.xml +++ pecl/Net_Gopher/package.xml <package version="1.0"> <name>Net_Gopher</name> <summary>fopen wrapper for the gopher protocol</summary> <description> fopen wrapper for retreiving documents via the gopher protocol. Includes additional function for parsing gopher directory entries. </description> <license>PHP</license> <maintainers> <maintainer> <user>pollita</user> <name>Sara Golemon</name> <email>pollita@php.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1</version> <state>beta</state> <date>2003-07-06</date> <notes>Initial Release</notes> <filelist> <file role="src" name="config.m4"/> <file role="src" name="gopher_fopen_wrapper.c"/> <file role="src" name="gopher_fopen_wrapper.h"/> </filelist> </release> <deps> <dep type="php" rel="ge">4.3.0</dep> </deps> </package>