cvs: pear /PECL/smbc CREDITS IMPORTANT LICENSE Makefile.in config.m4 package.xml php_smbc.h smbc.c /PECL/smbc/tests 001.phpt 002.phpt
| From: | Jelmer Vernooij | Date: | Thu, 22 Aug 2002 21:44:33 +0000 |
| Subject: | cvs: pear /PECL/smbc CREDITS IMPORTANT LICENSE Makefile.in config.m4 package.xml php_smbc.h smbc.c /PECL/smbc/tests 001.phpt 002.phpt | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-5884@lists.php.net to get a copy of this message | ||
ctrlsoft Thu Aug 22 17:44:33 2002 EDT
Added files:
/pear/PECL/smbc CREDITS IMPORTANT LICENSE Makefile.in config.m4
package.xml php_smbc.h smbc.c
/pear/PECL/smbc/tests 001.phpt 002.phpt
Log:
Add SMB Client PEAR PECL module. Note that this code is GPL'ed (depends
on GPL'ed libsmbclient).
Index: pear/PECL/smbc/Makefile.in +++ pear/PECL/smbc/Makefile.in # $Id: Makefile.in,v 1.1 2002/08/22 21:44:32 ctrlsoft Exp $ LTLIBRARY_NAME = libsmbc.la LTLIBRARY_SOURCES = smbc.c LTLIBRARY_SHARED_NAME = smbc.la LTLIBRARY_SHARED_LIBADD = $(SMBC_SHARED_LIBADD) include $(top_srcdir)/build/dynlib.mk Index: pear/PECL/smbc/config.m4 +++ pear/PECL/smbc/config.m4 dnl dnl $Id: config.m4,v 1.1 2002/08/22 21:44:32 ctrlsoft Exp $ dnl PHP_ARG_WITH(smbc,whether to enable SMB client support, [ --with-smbc Enable SMB client support]) if test "$PHP_SMBC" != "no"; then SEARCH_PATH="/usr/local /usr" SEARCH_FOR="/include/libsmbclient.h" if test -r $PHP_SMBC/; then SMBC_DIR=$PHP_SMBC else AC_MSG_CHECKING([for smbc files in default path]) for i in $SEARCH_PATH ; do if test -r $i/$SEARCH_FOR; then SMBC_DIR=$i AC_MSG_RESULT(found in $i) fi done fi if test -z "$SMBC_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the smbclient library distribution]) fi PHP_ADD_INCLUDE($SMBC_DIR/include) LIBNAME=smbclient LIBSYMBOL=smbc_init PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, [ PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SMBC_DIR/lib, SMBC_SHARED_LIBADD) AC_DEFINE(HAVE_SMBCLIB,1,[ ]) ],[ AC_MSG_ERROR([wrong libsmbclient version or lib not found]) ],[ -L$SMBC_DIR/lib -lm -ldl ]) PHP_SUBST(SMBC_SHARED_LIBADD) PHP_EXTENSION(smbc, $ext_shared) fi Index: pear/PECL/smbc/package.xml +++ pear/PECL/smbc/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "../../../php4/pear/package.dtd"> <package> <name>smbc</name> <summary>SMB Filesharing Client support</summary> <maintainers> <maintainer> <user>ctrlsoft</user> <name>Jelmer Vernooij</name> <email>jelmer@nl.linux.org</email> <role>lead</role> </maintainer> </maintainers> <description> Allows the developer to connect with SMB clients ('windows networks clients') and open/delete/create files and list make or remove directories. </description> <license>GPL</license> <release> <state>beta</state> <version>0.5</version> <date>2002-07-09</date> <notes> Initial release </notes> <filelist> <file role="src" name="config.m4"/> <file role="src" name="smbc.c"/> <file role="src" name="php_smbc.h"/> <file role="src" name="Makefile.in"/> <file role="doc" name="CREDITS"/> <file role="doc" name="LICENSE"/> <file role="doc" name="EXPERIMENTAL"/> <file role="doc" name="README"/> <file role="test" name="tests/001.phpt"/> <file role="test" name="tests/002.phpt"/> </filelist> </release> </package> Index: pear/PECL/smbc/php_smbc.h +++ pear/PECL/smbc/php_smbc.h /* +----------------------------------------------------------------------+ | smbc Module for PHP version 4.0 | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place - Suite 330, Boston, | | MA 02111-1307, USA. | | | | A copy is availble at http://www.gnu.org/copyleft/gpl.txt | +----------------------------------------------------------------------+ | Author: Jelmer Vernooij <jelmer@nl.linux.org> | +----------------------------------------------------------------------+ $Id: php_smbc.h,v 1.1 2002/08/22 21:44:32 ctrlsoft Exp $ */ #ifndef PHP_SMBC_H #define PHP_SMBC_H extern zend_module_entry smbc_module_entry; #define phpext_smbc_ptr &smbc_module_entry #ifdef PHP_WIN32 #define PHP_SMBC_API __declspec(dllexport) #else #define PHP_SMBC_API #endif #ifdef ZTS #include "TSRM.h" #endif PHP_MINIT_FUNCTION(smbc); PHP_MSHUTDOWN_FUNCTION(smbc); PHP_RINIT_FUNCTION(smbc); PHP_RSHUTDOWN_FUNCTION(smbc); PHP_MINFO_FUNCTION(smbc); PHP_FUNCTION(smbc_set_auth); PHP_FUNCTION(smbc_open); PHP_FUNCTION(smbc_create); PHP_FUNCTION(smbc_read); PHP_FUNCTION(smbc_write); PHP_FUNCTION(smbc_lseek); PHP_FUNCTION(smbc_close); PHP_FUNCTION(smbc_unlink); PHP_FUNCTION(smbc_rename); PHP_FUNCTION(smbc_opendir); PHP_FUNCTION(smbc_closedir); PHP_FUNCTION(smbc_readdir); PHP_FUNCTION(smbc_rewinddir); PHP_FUNCTION(smbc_mkdir); PHP_FUNCTION(smbc_rmdir); PHP_FUNCTION(smbc_stat); #ifdef ZTS #define SMBC_G(v) TSRMG(smbc_globals_id, zend_smbc_globals *, v) #else #define SMBC_G(v) (smbc_globals.v) #endif #endif /* PHP_SMBC_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */ Index: pear/PECL/smbc/smbc.c +++ pear/PECL/smbc/smbc.c /* +----------------------------------------------------------------------+ | Smbclient 0.5 Module for PHP version 4.0 | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place - Suite 330, Boston, | | MA 02111-1307, USA. | | | | A copy is availble at http://www.gnu.org/copyleft/gpl.txt | +----------------------------------------------------------------------+ | Author: Jelmer Vernooij <jelmer@nl.linux.org> | +----------------------------------------------------------------------+ $Id: smbc.c,v 1.1 2002/08/22 21:44:32 ctrlsoft Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_smbc.h" #include <libsmbclient.h> //ZEND_DECLARE_MODULE_GLOBALS(smbc) static char *current_username = NULL; static char *current_workgroup = NULL; static char *current_password = NULL; /* True global resources - no need for thread safety here */ static int le_smbcbuf; #define le_smbcbuf_name "SMBC Buffer" function_entry php_smbc_functions[] = { PHP_FE(smbc_set_auth, NULL) PHP_FE(smbc_open, NULL) PHP_FE(smbc_create, NULL) PHP_FE(smbc_read, NULL) PHP_FE(smbc_write, NULL) PHP_FE(smbc_lseek, NULL) PHP_FE(smbc_close, NULL) PHP_FE(smbc_unlink, NULL) PHP_FE(smbc_rename, NULL) PHP_FE(smbc_opendir, NULL) PHP_FE(smbc_closedir, NULL) PHP_FE(smbc_rewinddir, NULL) PHP_FE(smbc_mkdir, NULL) PHP_FE(smbc_rmdir, NULL) PHP_FE(smbc_readdir, NULL) /* PHP_FE(smbc_stat, NULL) FIXME */ {NULL, NULL, NULL} }; static void smbc_destructor_smbcbuf(zend_rsrc_list_entry *rsrc TSRMLS_DC){ } /* {{{ smbc_module_entry */ zend_module_entry smbc_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "smbc", php_smbc_functions, PHP_MINIT(smbc), NULL, NULL, NULL, PHP_MINFO(smbc), #if ZEND_MODULE_API_NO >= 20010901 "0.1", /* Replace with version number for your extension */ #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_SMBC ZEND_GET_MODULE(smbc) #endif void smbc_auth_fn (const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen){ /* Use workgroup from smb.conf if none can be found */ if(current_workgroup) strncpy(workgroup, current_workgroup, wgmaxlen); strncpy(username, current_username, unmaxlen); strncpy(password, current_password, pwmaxlen); } PHP_MINIT_FUNCTION(smbc) { le_smbcbuf = zend_register_list_destructors_ex(smbc_destructor_smbcbuf, NULL, le_smbcbuf_name, module_number); REGISTER_LONG_CONSTANT("SMBC_WORKGROUP", SMBC_WORKGROUP, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_SERVER", SMBC_SERVER, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_FILE_SHARE", SMBC_FILE_SHARE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_PRINTER_SHARE", SMBC_PRINTER_SHARE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_COMMS_SHARE", SMBC_COMMS_SHARE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_IPC_SHARE", SMBC_IPC_SHARE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_DIR", SMBC_DIR, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_FILE", SMBC_FILE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_LINK", SMBC_LINK, CONST_PERSISTENT | CONST_CS); smbc_init(smbc_auth_fn, 10); return SUCCESS; } PHP_MINFO_FUNCTION(smbc) { php_info_print_table_start(); php_info_print_table_row(2, "SMB Client support", "enabled"); php_info_print_table_end(); } /* {{{ proto bool smbc_close(resource fd) Close a file handle */ PHP_FUNCTION(smbc_close) { int fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fd) == FAILURE) { return; } if(smbc_close(fd) < 0){ php_error(E_ERROR, "smbc_close failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto bool smbc_unlink(string url) Unlink specified URL */ PHP_FUNCTION(smbc_unlink) { char *url; int length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &length) == FAILURE) { return; } if(smbc_unlink(url) < 0){ php_error(E_ERROR, "smbc_unlink failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto resource smbc_opendir(string url) Open a directory handle */ PHP_FUNCTION(smbc_opendir) { char *url; int length; int fd; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &length) == FAILURE) { return; } fd = smbc_opendir(url); if(fd < 0){ php_error(E_ERROR, "smbc_opendir failed: %s", strerror(errno)); RETURN_NULL(); } RETURN_LONG(fd); } /* }}} */ /* {{{ proto bool smbc_mkdir(string url, long mode) Create a new directory */ PHP_FUNCTION(smbc_mkdir) { long mode=0755; int length; char *url; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &length, &mode) == FAILURE) { return; } if(smbc_mkdir(url, mode) < 0){ php_error(E_ERROR, "smbc_mkdir failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto bool smbc_rmdir(string url) Remove a directory */ PHP_FUNCTION(smbc_rmdir) { int length; char *url; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &length) == FAILURE) { return; } if(smbc_rmdir(url) < 0){ php_error(E_ERROR, "smbc_rmdir failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto bool smbc_rewinddir(resource fd) Rewind directory handle */ PHP_FUNCTION(smbc_rewinddir) { int fd; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fd) == FAILURE) { return; } if(smbc_lseekdir(fd, 0) == -1){ php_error(E_ERROR, "smbc_rewinddir failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto array smbc_readdir(resource fd) Read next directory entry */ PHP_FUNCTION(smbc_readdir) { int fd; struct smbc_dirent *dirent; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fd) == FAILURE) { return; } if (array_init(return_value) == FAILURE)return; dirent = smbc_readdir(fd); if(!dirent){ if(errno) php_error(E_ERROR, "smbc_readdir failed: %s", strerror(errno)); RETURN_NULL(); } add_next_index_long(return_value,dirent->smbc_type); add_next_index_long(return_value,dirent->dirlen); add_next_index_stringl(return_value,dirent->comment,dirent->commentlen,1); add_next_index_stringl(return_value,dirent->name,dirent->namelen,1); } /* }}} */ /* {{{ proto bool smbc_closedir(resource fd) Close a directory handle */ PHP_FUNCTION(smbc_closedir) { int fd; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fd) == FAILURE) { return; } if(smbc_closedir(fd) < 0){ php_error(E_ERROR, "smbc_closedir failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto bool smbc_rename(string ourl, string nurl) Rename old URL ourl to new URL nurl */ PHP_FUNCTION(smbc_rename) { char *ourl, *nurl; int olength, nlength; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ourl, &olength, &nurl, &nlength) == FAILURE) { return; } if(smbc_rename(ourl,nurl) < 0){ php_error(E_ERROR, "smbc_rename failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto void smbc_set_auth(string username, [string password [, string workgroup]]) Set authorisation info */ PHP_FUNCTION(smbc_set_auth) { int unlen, pwlen, wglen; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ss", ¤t_username, &unlen, ¤t_password, &pwlen, ¤t_workgroup, &wglen) == FAILURE) { return; } } /* }}} */ /* {{{ proto resource smbc_open(string url [, int flags [, int mode)]]) Opens a FTP stream */ PHP_FUNCTION(smbc_open) { char *url; int flags = O_RDWR, mode = 0755; int url_len; int fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &url, &url_len, &flags, &mode) == FAILURE) { return; } fd = smbc_open(url, flags, mode); if(fd < 0){ php_error(E_ERROR, "smbc_open failed: %s", strerror(errno)); RETURN_NULL(); } RETURN_LONG(fd); } /* }}} */ /* {{{ proto string smbc_write(resource fd, string data) Read data from a smb file descriptor */ PHP_FUNCTION(smbc_write) { int fd; long slength; void *data; ssize_t ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &fd, &data, &slength) == FAILURE) { return; } ret = smbc_write(fd, data, slength); if(ret < 0){ php_error(E_ERROR, "smbc_write failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto long smbc_lseek(resource fd, long offset [, int whence]) Seeks on a file pointer */ PHP_FUNCTION(smbc_lseek) { int fd; long offset; long whence = SEEK_SET; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|l", &fd, &offset, &whence) == FAILURE) { return; } RETURN_LONG(smbc_lseek(fd,offset, whence)); } /* }}} */ /* {{{ proto string smbc_read(resource fd [, long size]) Read data from a smb file descriptor */ PHP_FUNCTION(smbc_read) { int fd; long length = 4096; void *data; ssize_t ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &fd, &length) == FAILURE) { return; } data = malloc(length); ret = smbc_read(fd, data, length); if(ret == 0){ RETURN_NULL(); } if(ret < 0){ php_error(E_ERROR, "smbc_read failed: %s", strerror(errno)); return; } RETVAL_STRING(data, 1); free(data); } /* }}} */ /* {{{ proto resource smbc_create(string url [, int mode)]) Opens a FTP stream */ PHP_FUNCTION(smbc_create) { char *url; int mode = 0755; int url_len; int fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &url_len, &mode) == FAILURE) { return; } fd = smbc_creat(url, mode); if(fd < 0){ php_error(E_ERROR, "smbc_create failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_LONG(fd); } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ Index: pear/PECL/smbc/tests/001.phpt +++ pear/PECL/smbc/tests/001.phpt <? /* WARNING: This script can cause major security issues - use with care */ if(!isset($url))$url = "smb://ganieda/c"; echo "<h1>$url</h1>\n"; if(!extension_loaded('smbc')) { dl('smbc.so'); } $fd = smbc_opendir($url); while($file = smbc_readdir($fd)){ echo "<a href=\"$PHP_SELF?url=$url/" . $file[3] . "\">$file[3]</a><br>\n"; } smbc_closedir($fd); ?> Index: pear/PECL/smbc/tests/002.phpt +++ pear/PECL/smbc/tests/002.phpt <? if(!extension_loaded('smbc')) { dl('smbc.so'); } $module = 'smbc'; $functions = get_extension_funcs($module); echo "Functions available in the test extension:<br>\n"; foreach($functions as $func) { echo $func."<br>\n"; } $file1 = "smb://ganieda/c/blaaat.bla"; $file2 = "smb://ganieda/c/blieee.bla"; $dir1 = "smb://ganieda/c/blie"; $dir2 = "smb://ganieda/c"; $testdata = "Blah! FooBar"; $fd = smbc_create($file1); if(!$fd)echo "Can't open file"; smbc_write($fd, $testdata); smbc_close($fd); $fd = smbc_open($file1); if(!$fd)echo "Can't open file"; while($a = smbc_read($fd))echo $a; smbc_close($fd); echo "Rename<br>\n"; smbc_rename($file1, $file2); echo "Unlink<br>\n"; smbc_unlink($file2); echo "Mkdir<br>\n"; smbc_mkdir($dir1); echo "Rmdir<br>\n"; smbc_rmdir($dir1); echo "Opendir<br>\n"; $fd = smbc_opendir($dir2); echo "Readdir<br>\n"; while($file = smbc_readdir($fd)){ echo $file[3]; } smbc_closedir($fd); echo "<br>\n"; ?>
Index: pear/PECL/smbc/Makefile.in +++ pear/PECL/smbc/Makefile.in # $Id: Makefile.in,v 1.1 2002/08/22 21:44:32 ctrlsoft Exp $ LTLIBRARY_NAME = libsmbc.la LTLIBRARY_SOURCES = smbc.c LTLIBRARY_SHARED_NAME = smbc.la LTLIBRARY_SHARED_LIBADD = $(SMBC_SHARED_LIBADD) include $(top_srcdir)/build/dynlib.mk Index: pear/PECL/smbc/config.m4 +++ pear/PECL/smbc/config.m4 dnl dnl $Id: config.m4,v 1.1 2002/08/22 21:44:32 ctrlsoft Exp $ dnl PHP_ARG_WITH(smbc,whether to enable SMB client support, [ --with-smbc Enable SMB client support]) if test "$PHP_SMBC" != "no"; then SEARCH_PATH="/usr/local /usr" SEARCH_FOR="/include/libsmbclient.h" if test -r $PHP_SMBC/; then SMBC_DIR=$PHP_SMBC else AC_MSG_CHECKING([for smbc files in default path]) for i in $SEARCH_PATH ; do if test -r $i/$SEARCH_FOR; then SMBC_DIR=$i AC_MSG_RESULT(found in $i) fi done fi if test -z "$SMBC_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the smbclient library distribution]) fi PHP_ADD_INCLUDE($SMBC_DIR/include) LIBNAME=smbclient LIBSYMBOL=smbc_init PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, [ PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SMBC_DIR/lib, SMBC_SHARED_LIBADD) AC_DEFINE(HAVE_SMBCLIB,1,[ ]) ],[ AC_MSG_ERROR([wrong libsmbclient version or lib not found]) ],[ -L$SMBC_DIR/lib -lm -ldl ]) PHP_SUBST(SMBC_SHARED_LIBADD) PHP_EXTENSION(smbc, $ext_shared) fi Index: pear/PECL/smbc/package.xml +++ pear/PECL/smbc/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "../../../php4/pear/package.dtd"> <package> <name>smbc</name> <summary>SMB Filesharing Client support</summary> <maintainers> <maintainer> <user>ctrlsoft</user> <name>Jelmer Vernooij</name> <email>jelmer@nl.linux.org</email> <role>lead</role> </maintainer> </maintainers> <description> Allows the developer to connect with SMB clients ('windows networks clients') and open/delete/create files and list make or remove directories. </description> <license>GPL</license> <release> <state>beta</state> <version>0.5</version> <date>2002-07-09</date> <notes> Initial release </notes> <filelist> <file role="src" name="config.m4"/> <file role="src" name="smbc.c"/> <file role="src" name="php_smbc.h"/> <file role="src" name="Makefile.in"/> <file role="doc" name="CREDITS"/> <file role="doc" name="LICENSE"/> <file role="doc" name="EXPERIMENTAL"/> <file role="doc" name="README"/> <file role="test" name="tests/001.phpt"/> <file role="test" name="tests/002.phpt"/> </filelist> </release> </package> Index: pear/PECL/smbc/php_smbc.h +++ pear/PECL/smbc/php_smbc.h /* +----------------------------------------------------------------------+ | smbc Module for PHP version 4.0 | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place - Suite 330, Boston, | | MA 02111-1307, USA. | | | | A copy is availble at http://www.gnu.org/copyleft/gpl.txt | +----------------------------------------------------------------------+ | Author: Jelmer Vernooij <jelmer@nl.linux.org> | +----------------------------------------------------------------------+ $Id: php_smbc.h,v 1.1 2002/08/22 21:44:32 ctrlsoft Exp $ */ #ifndef PHP_SMBC_H #define PHP_SMBC_H extern zend_module_entry smbc_module_entry; #define phpext_smbc_ptr &smbc_module_entry #ifdef PHP_WIN32 #define PHP_SMBC_API __declspec(dllexport) #else #define PHP_SMBC_API #endif #ifdef ZTS #include "TSRM.h" #endif PHP_MINIT_FUNCTION(smbc); PHP_MSHUTDOWN_FUNCTION(smbc); PHP_RINIT_FUNCTION(smbc); PHP_RSHUTDOWN_FUNCTION(smbc); PHP_MINFO_FUNCTION(smbc); PHP_FUNCTION(smbc_set_auth); PHP_FUNCTION(smbc_open); PHP_FUNCTION(smbc_create); PHP_FUNCTION(smbc_read); PHP_FUNCTION(smbc_write); PHP_FUNCTION(smbc_lseek); PHP_FUNCTION(smbc_close); PHP_FUNCTION(smbc_unlink); PHP_FUNCTION(smbc_rename); PHP_FUNCTION(smbc_opendir); PHP_FUNCTION(smbc_closedir); PHP_FUNCTION(smbc_readdir); PHP_FUNCTION(smbc_rewinddir); PHP_FUNCTION(smbc_mkdir); PHP_FUNCTION(smbc_rmdir); PHP_FUNCTION(smbc_stat); #ifdef ZTS #define SMBC_G(v) TSRMG(smbc_globals_id, zend_smbc_globals *, v) #else #define SMBC_G(v) (smbc_globals.v) #endif #endif /* PHP_SMBC_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */ Index: pear/PECL/smbc/smbc.c +++ pear/PECL/smbc/smbc.c /* +----------------------------------------------------------------------+ | Smbclient 0.5 Module for PHP version 4.0 | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place - Suite 330, Boston, | | MA 02111-1307, USA. | | | | A copy is availble at http://www.gnu.org/copyleft/gpl.txt | +----------------------------------------------------------------------+ | Author: Jelmer Vernooij <jelmer@nl.linux.org> | +----------------------------------------------------------------------+ $Id: smbc.c,v 1.1 2002/08/22 21:44:32 ctrlsoft Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_smbc.h" #include <libsmbclient.h> //ZEND_DECLARE_MODULE_GLOBALS(smbc) static char *current_username = NULL; static char *current_workgroup = NULL; static char *current_password = NULL; /* True global resources - no need for thread safety here */ static int le_smbcbuf; #define le_smbcbuf_name "SMBC Buffer" function_entry php_smbc_functions[] = { PHP_FE(smbc_set_auth, NULL) PHP_FE(smbc_open, NULL) PHP_FE(smbc_create, NULL) PHP_FE(smbc_read, NULL) PHP_FE(smbc_write, NULL) PHP_FE(smbc_lseek, NULL) PHP_FE(smbc_close, NULL) PHP_FE(smbc_unlink, NULL) PHP_FE(smbc_rename, NULL) PHP_FE(smbc_opendir, NULL) PHP_FE(smbc_closedir, NULL) PHP_FE(smbc_rewinddir, NULL) PHP_FE(smbc_mkdir, NULL) PHP_FE(smbc_rmdir, NULL) PHP_FE(smbc_readdir, NULL) /* PHP_FE(smbc_stat, NULL) FIXME */ {NULL, NULL, NULL} }; static void smbc_destructor_smbcbuf(zend_rsrc_list_entry *rsrc TSRMLS_DC){ } /* {{{ smbc_module_entry */ zend_module_entry smbc_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "smbc", php_smbc_functions, PHP_MINIT(smbc), NULL, NULL, NULL, PHP_MINFO(smbc), #if ZEND_MODULE_API_NO >= 20010901 "0.1", /* Replace with version number for your extension */ #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_SMBC ZEND_GET_MODULE(smbc) #endif void smbc_auth_fn (const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen){ /* Use workgroup from smb.conf if none can be found */ if(current_workgroup) strncpy(workgroup, current_workgroup, wgmaxlen); strncpy(username, current_username, unmaxlen); strncpy(password, current_password, pwmaxlen); } PHP_MINIT_FUNCTION(smbc) { le_smbcbuf = zend_register_list_destructors_ex(smbc_destructor_smbcbuf, NULL, le_smbcbuf_name, module_number); REGISTER_LONG_CONSTANT("SMBC_WORKGROUP", SMBC_WORKGROUP, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_SERVER", SMBC_SERVER, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_FILE_SHARE", SMBC_FILE_SHARE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_PRINTER_SHARE", SMBC_PRINTER_SHARE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_COMMS_SHARE", SMBC_COMMS_SHARE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_IPC_SHARE", SMBC_IPC_SHARE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_DIR", SMBC_DIR, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_FILE", SMBC_FILE, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SMBC_LINK", SMBC_LINK, CONST_PERSISTENT | CONST_CS); smbc_init(smbc_auth_fn, 10); return SUCCESS; } PHP_MINFO_FUNCTION(smbc) { php_info_print_table_start(); php_info_print_table_row(2, "SMB Client support", "enabled"); php_info_print_table_end(); } /* {{{ proto bool smbc_close(resource fd) Close a file handle */ PHP_FUNCTION(smbc_close) { int fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fd) == FAILURE) { return; } if(smbc_close(fd) < 0){ php_error(E_ERROR, "smbc_close failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto bool smbc_unlink(string url) Unlink specified URL */ PHP_FUNCTION(smbc_unlink) { char *url; int length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &length) == FAILURE) { return; } if(smbc_unlink(url) < 0){ php_error(E_ERROR, "smbc_unlink failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto resource smbc_opendir(string url) Open a directory handle */ PHP_FUNCTION(smbc_opendir) { char *url; int length; int fd; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &length) == FAILURE) { return; } fd = smbc_opendir(url); if(fd < 0){ php_error(E_ERROR, "smbc_opendir failed: %s", strerror(errno)); RETURN_NULL(); } RETURN_LONG(fd); } /* }}} */ /* {{{ proto bool smbc_mkdir(string url, long mode) Create a new directory */ PHP_FUNCTION(smbc_mkdir) { long mode=0755; int length; char *url; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &length, &mode) == FAILURE) { return; } if(smbc_mkdir(url, mode) < 0){ php_error(E_ERROR, "smbc_mkdir failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto bool smbc_rmdir(string url) Remove a directory */ PHP_FUNCTION(smbc_rmdir) { int length; char *url; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &length) == FAILURE) { return; } if(smbc_rmdir(url) < 0){ php_error(E_ERROR, "smbc_rmdir failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto bool smbc_rewinddir(resource fd) Rewind directory handle */ PHP_FUNCTION(smbc_rewinddir) { int fd; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fd) == FAILURE) { return; } if(smbc_lseekdir(fd, 0) == -1){ php_error(E_ERROR, "smbc_rewinddir failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto array smbc_readdir(resource fd) Read next directory entry */ PHP_FUNCTION(smbc_readdir) { int fd; struct smbc_dirent *dirent; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fd) == FAILURE) { return; } if (array_init(return_value) == FAILURE)return; dirent = smbc_readdir(fd); if(!dirent){ if(errno) php_error(E_ERROR, "smbc_readdir failed: %s", strerror(errno)); RETURN_NULL(); } add_next_index_long(return_value,dirent->smbc_type); add_next_index_long(return_value,dirent->dirlen); add_next_index_stringl(return_value,dirent->comment,dirent->commentlen,1); add_next_index_stringl(return_value,dirent->name,dirent->namelen,1); } /* }}} */ /* {{{ proto bool smbc_closedir(resource fd) Close a directory handle */ PHP_FUNCTION(smbc_closedir) { int fd; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fd) == FAILURE) { return; } if(smbc_closedir(fd) < 0){ php_error(E_ERROR, "smbc_closedir failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto bool smbc_rename(string ourl, string nurl) Rename old URL ourl to new URL nurl */ PHP_FUNCTION(smbc_rename) { char *ourl, *nurl; int olength, nlength; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ourl, &olength, &nurl, &nlength) == FAILURE) { return; } if(smbc_rename(ourl,nurl) < 0){ php_error(E_ERROR, "smbc_rename failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto void smbc_set_auth(string username, [string password [, string workgroup]]) Set authorisation info */ PHP_FUNCTION(smbc_set_auth) { int unlen, pwlen, wglen; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ss", ¤t_username, &unlen, ¤t_password, &pwlen, ¤t_workgroup, &wglen) == FAILURE) { return; } } /* }}} */ /* {{{ proto resource smbc_open(string url [, int flags [, int mode)]]) Opens a FTP stream */ PHP_FUNCTION(smbc_open) { char *url; int flags = O_RDWR, mode = 0755; int url_len; int fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &url, &url_len, &flags, &mode) == FAILURE) { return; } fd = smbc_open(url, flags, mode); if(fd < 0){ php_error(E_ERROR, "smbc_open failed: %s", strerror(errno)); RETURN_NULL(); } RETURN_LONG(fd); } /* }}} */ /* {{{ proto string smbc_write(resource fd, string data) Read data from a smb file descriptor */ PHP_FUNCTION(smbc_write) { int fd; long slength; void *data; ssize_t ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &fd, &data, &slength) == FAILURE) { return; } ret = smbc_write(fd, data, slength); if(ret < 0){ php_error(E_ERROR, "smbc_write failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto long smbc_lseek(resource fd, long offset [, int whence]) Seeks on a file pointer */ PHP_FUNCTION(smbc_lseek) { int fd; long offset; long whence = SEEK_SET; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|l", &fd, &offset, &whence) == FAILURE) { return; } RETURN_LONG(smbc_lseek(fd,offset, whence)); } /* }}} */ /* {{{ proto string smbc_read(resource fd [, long size]) Read data from a smb file descriptor */ PHP_FUNCTION(smbc_read) { int fd; long length = 4096; void *data; ssize_t ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &fd, &length) == FAILURE) { return; } data = malloc(length); ret = smbc_read(fd, data, length); if(ret == 0){ RETURN_NULL(); } if(ret < 0){ php_error(E_ERROR, "smbc_read failed: %s", strerror(errno)); return; } RETVAL_STRING(data, 1); free(data); } /* }}} */ /* {{{ proto resource smbc_create(string url [, int mode)]) Opens a FTP stream */ PHP_FUNCTION(smbc_create) { char *url; int mode = 0755; int url_len; int fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &url_len, &mode) == FAILURE) { return; } fd = smbc_creat(url, mode); if(fd < 0){ php_error(E_ERROR, "smbc_create failed: %s", strerror(errno)); RETURN_FALSE; } RETURN_LONG(fd); } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ Index: pear/PECL/smbc/tests/001.phpt +++ pear/PECL/smbc/tests/001.phpt <? /* WARNING: This script can cause major security issues - use with care */ if(!isset($url))$url = "smb://ganieda/c"; echo "<h1>$url</h1>\n"; if(!extension_loaded('smbc')) { dl('smbc.so'); } $fd = smbc_opendir($url); while($file = smbc_readdir($fd)){ echo "<a href=\"$PHP_SELF?url=$url/" . $file[3] . "\">$file[3]</a><br>\n"; } smbc_closedir($fd); ?> Index: pear/PECL/smbc/tests/002.phpt +++ pear/PECL/smbc/tests/002.phpt <? if(!extension_loaded('smbc')) { dl('smbc.so'); } $module = 'smbc'; $functions = get_extension_funcs($module); echo "Functions available in the test extension:<br>\n"; foreach($functions as $func) { echo $func."<br>\n"; } $file1 = "smb://ganieda/c/blaaat.bla"; $file2 = "smb://ganieda/c/blieee.bla"; $dir1 = "smb://ganieda/c/blie"; $dir2 = "smb://ganieda/c"; $testdata = "Blah! FooBar"; $fd = smbc_create($file1); if(!$fd)echo "Can't open file"; smbc_write($fd, $testdata); smbc_close($fd); $fd = smbc_open($file1); if(!$fd)echo "Can't open file"; while($a = smbc_read($fd))echo $a; smbc_close($fd); echo "Rename<br>\n"; smbc_rename($file1, $file2); echo "Unlink<br>\n"; smbc_unlink($file2); echo "Mkdir<br>\n"; smbc_mkdir($dir1); echo "Rmdir<br>\n"; smbc_rmdir($dir1); echo "Opendir<br>\n"; $fd = smbc_opendir($dir2); echo "Readdir<br>\n"; while($file = smbc_readdir($fd)){ echo $file[3]; } smbc_closedir($fd); echo "<br>\n"; ?>