├── README ├── ccvita.php ├── tests └── 001.phpt ├── config.m4 ├── php_ccvita.h └── ccvita.c /README: -------------------------------------------------------------------------------- 1 | PHP扩展开发 2 | -------------------------------------------------------------------------------- /ccvita.php: -------------------------------------------------------------------------------- 1 | "; 3 | 4 | if(!extension_loaded('ccvita')) { 5 | dl('ccvita.' . PHP_SHLIB_SUFFIX); 6 | } 7 | $module = 'ccvita'; 8 | $functions = get_extension_funcs($module); 9 | echo "Functions available in the test extension:$br\n"; 10 | foreach($functions as $func) { 11 | echo $func."$br\n"; 12 | } 13 | echo "$br\n"; 14 | $function = 'confirm_' . $module . '_compiled'; 15 | if (extension_loaded($module)) { 16 | $str = $function($module); 17 | } else { 18 | $str = "Module $module is not compiled into PHP"; 19 | } 20 | echo "$str\n"; 21 | ?> 22 | -------------------------------------------------------------------------------- /tests/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for ccvita presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 20 | --EXPECT-- 21 | ccvita extension is available 22 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension ccvita 3 | 4 | dnl Comments in this file start with the string 'dnl'. 5 | dnl Remove where necessary. This file will not work 6 | dnl without editing. 7 | 8 | dnl If your extension references something external, use with: 9 | 10 | PHP_ARG_WITH(ccvita, for ccvita support, 11 | Make sure that the comment is aligned: 12 | [ --with-ccvita Include ccvita support]) 13 | 14 | dnl Otherwise use enable: 15 | 16 | dnl PHP_ARG_ENABLE(ccvita, whether to enable ccvita support, 17 | dnl Make sure that the comment is aligned: 18 | dnl [ --enable-ccvita Enable ccvita support]) 19 | 20 | if test "$PHP_CCVITA" != "no"; then 21 | dnl Write more examples of tests here... 22 | 23 | dnl # --with-ccvita -> check with-path 24 | dnl SEARCH_PATH="/usr/local /usr" # you might want to change this 25 | dnl SEARCH_FOR="/include/ccvita.h" # you most likely want to change this 26 | dnl if test -r $PHP_CCVITA/$SEARCH_FOR; then # path given as parameter 27 | dnl CCVITA_DIR=$PHP_CCVITA 28 | dnl else # search default path list 29 | dnl AC_MSG_CHECKING([for ccvita files in default path]) 30 | dnl for i in $SEARCH_PATH ; do 31 | dnl if test -r $i/$SEARCH_FOR; then 32 | dnl CCVITA_DIR=$i 33 | dnl AC_MSG_RESULT(found in $i) 34 | dnl fi 35 | dnl done 36 | dnl fi 37 | dnl 38 | dnl if test -z "$CCVITA_DIR"; then 39 | dnl AC_MSG_RESULT([not found]) 40 | dnl AC_MSG_ERROR([Please reinstall the ccvita distribution]) 41 | dnl fi 42 | 43 | dnl # --with-ccvita -> add include path 44 | dnl PHP_ADD_INCLUDE($CCVITA_DIR/include) 45 | 46 | dnl # --with-ccvita -> check for lib and symbol presence 47 | dnl LIBNAME=ccvita # you may want to change this 48 | dnl LIBSYMBOL=ccvita # you most likely want to change this 49 | 50 | dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 51 | dnl [ 52 | dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $CCVITA_DIR/lib, CCVITA_SHARED_LIBADD) 53 | dnl AC_DEFINE(HAVE_CCVITALIB,1,[ ]) 54 | dnl ],[ 55 | dnl AC_MSG_ERROR([wrong ccvita lib version or lib not found]) 56 | dnl ],[ 57 | dnl -L$CCVITA_DIR/lib -lm 58 | dnl ]) 59 | dnl 60 | dnl PHP_SUBST(CCVITA_SHARED_LIBADD) 61 | 62 | PHP_NEW_EXTENSION(ccvita, ccvita.c, $ext_shared) 63 | fi 64 | -------------------------------------------------------------------------------- /php_ccvita.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2011 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: | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id: header 310447 2011-04-23 21:14:10Z bjori $ */ 20 | 21 | #ifndef PHP_CCVITA_H 22 | #define PHP_CCVITA_H 23 | 24 | extern zend_module_entry ccvita_module_entry; 25 | #define phpext_ccvita_ptr &ccvita_module_entry 26 | 27 | #ifdef PHP_WIN32 28 | # define PHP_CCVITA_API __declspec(dllexport) 29 | #elif defined(__GNUC__) && __GNUC__ >= 4 30 | # define PHP_CCVITA_API __attribute__ ((visibility("default"))) 31 | #else 32 | # define PHP_CCVITA_API 33 | #endif 34 | 35 | #ifdef ZTS 36 | #include "TSRM.h" 37 | #endif 38 | 39 | PHP_MINIT_FUNCTION(ccvita); 40 | PHP_MSHUTDOWN_FUNCTION(ccvita); 41 | PHP_RINIT_FUNCTION(ccvita); 42 | PHP_RSHUTDOWN_FUNCTION(ccvita); 43 | PHP_MINFO_FUNCTION(ccvita); 44 | 45 | PHP_FUNCTION(confirm_ccvita_compiled); /* For testing, remove later. */ 46 | PHP_FUNCTION(ccvita_string); 47 | 48 | /* 49 | Declare any global variables you may need between the BEGIN 50 | and END macros here: 51 | 52 | ZEND_BEGIN_MODULE_GLOBALS(ccvita) 53 | long global_value; 54 | char *global_string; 55 | ZEND_END_MODULE_GLOBALS(ccvita) 56 | */ 57 | 58 | /* In every utility function you add that needs to use variables 59 | in php_ccvita_globals, call TSRMLS_FETCH(); after declaring other 60 | variables used by that function, or better yet, pass in TSRMLS_CC 61 | after the last function argument and declare your utility function 62 | with TSRMLS_DC after the last declared argument. Always refer to 63 | the globals in your function as CCVITA_G(variable). You are 64 | encouraged to rename these macros something shorter, see 65 | examples in any other php module directory. 66 | */ 67 | 68 | #ifdef ZTS 69 | #define CCVITA_G(v) TSRMG(ccvita_globals_id, zend_ccvita_globals *, v) 70 | #else 71 | #define CCVITA_G(v) (ccvita_globals.v) 72 | #endif 73 | 74 | #endif /* PHP_CCVITA_H */ 75 | 76 | 77 | /* 78 | * Local variables: 79 | * tab-width: 4 80 | * c-basic-offset: 4 81 | * End: 82 | * vim600: noet sw=4 ts=4 fdm=marker 83 | * vim<600: noet sw=4 ts=4 84 | */ 85 | -------------------------------------------------------------------------------- /ccvita.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2011 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: | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id: header 310447 2011-04-23 21:14:10Z bjori $ */ 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 "php_ccvita.h" 29 | 30 | /* If you declare any globals in php_ccvita.h uncomment this: 31 | ZEND_DECLARE_MODULE_GLOBALS(ccvita) 32 | */ 33 | 34 | /* True global resources - no need for thread safety here */ 35 | static int le_ccvita; 36 | 37 | /* {{{ ccvita_functions[] 38 | * 39 | * Every user visible function must have an entry in ccvita_functions[]. 40 | */ 41 | const zend_function_entry ccvita_functions[] = { 42 | PHP_FE(confirm_ccvita_compiled, NULL) /* For testing, remove later. */ 43 | PHP_FE(ccvita_string, NULL) 44 | PHP_FE_END /* Must be the last line in ccvita_functions[] */ 45 | }; 46 | /* }}} */ 47 | 48 | /* {{{ ccvita_module_entry 49 | */ 50 | zend_module_entry ccvita_module_entry = { 51 | #if ZEND_MODULE_API_NO >= 20010901 52 | STANDARD_MODULE_HEADER, 53 | #endif 54 | "ccvita", 55 | ccvita_functions, 56 | PHP_MINIT(ccvita), 57 | PHP_MSHUTDOWN(ccvita), 58 | PHP_RINIT(ccvita), /* Replace with NULL if there's nothing to do at request start */ 59 | PHP_RSHUTDOWN(ccvita), /* Replace with NULL if there's nothing to do at request end */ 60 | PHP_MINFO(ccvita), 61 | #if ZEND_MODULE_API_NO >= 20010901 62 | "0.1", /* Replace with version number for your extension */ 63 | #endif 64 | STANDARD_MODULE_PROPERTIES 65 | }; 66 | /* }}} */ 67 | 68 | #ifdef COMPILE_DL_CCVITA 69 | ZEND_GET_MODULE(ccvita) 70 | #endif 71 | 72 | /* {{{ PHP_INI 73 | */ 74 | /* Remove comments and fill if you need to have entries in php.ini 75 | PHP_INI_BEGIN() 76 | STD_PHP_INI_ENTRY("ccvita.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_ccvita_globals, ccvita_globals) 77 | STD_PHP_INI_ENTRY("ccvita.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_ccvita_globals, ccvita_globals) 78 | PHP_INI_END() 79 | */ 80 | /* }}} */ 81 | 82 | /* {{{ php_ccvita_init_globals 83 | */ 84 | /* Uncomment this function if you have INI entries 85 | static void php_ccvita_init_globals(zend_ccvita_globals *ccvita_globals) 86 | { 87 | ccvita_globals->global_value = 0; 88 | ccvita_globals->global_string = NULL; 89 | } 90 | */ 91 | /* }}} */ 92 | 93 | /* {{{ PHP_MINIT_FUNCTION 94 | */ 95 | PHP_MINIT_FUNCTION(ccvita) 96 | { 97 | /* If you have INI entries, uncomment these lines 98 | REGISTER_INI_ENTRIES(); 99 | */ 100 | return SUCCESS; 101 | } 102 | /* }}} */ 103 | 104 | /* {{{ PHP_MSHUTDOWN_FUNCTION 105 | */ 106 | PHP_MSHUTDOWN_FUNCTION(ccvita) 107 | { 108 | /* uncomment this line if you have INI entries 109 | UNREGISTER_INI_ENTRIES(); 110 | */ 111 | return SUCCESS; 112 | } 113 | /* }}} */ 114 | 115 | /* Remove if there's nothing to do at request start */ 116 | /* {{{ PHP_RINIT_FUNCTION 117 | */ 118 | PHP_RINIT_FUNCTION(ccvita) 119 | { 120 | return SUCCESS; 121 | } 122 | /* }}} */ 123 | 124 | /* Remove if there's nothing to do at request end */ 125 | /* {{{ PHP_RSHUTDOWN_FUNCTION 126 | */ 127 | PHP_RSHUTDOWN_FUNCTION(ccvita) 128 | { 129 | return SUCCESS; 130 | } 131 | /* }}} */ 132 | 133 | /* {{{ PHP_MINFO_FUNCTION 134 | */ 135 | PHP_MINFO_FUNCTION(ccvita) 136 | { 137 | php_info_print_table_start(); 138 | php_info_print_table_header(2, "ccvita support", "enabled"); 139 | php_info_print_table_end(); 140 | 141 | /* Remove comments if you have entries in php.ini 142 | DISPLAY_INI_ENTRIES(); 143 | */ 144 | } 145 | /* }}} */ 146 | 147 | 148 | /* Remove the following function when you have succesfully modified config.m4 149 | so that your module can be compiled into PHP, it exists only for testing 150 | purposes. */ 151 | 152 | /* Every user-visible function in PHP should document itself in the source */ 153 | /* {{{ proto string confirm_ccvita_compiled(string arg) 154 | Return a string to confirm that the module is compiled in */ 155 | PHP_FUNCTION(confirm_ccvita_compiled) 156 | { 157 | char *arg = NULL; 158 | int arg_len, len; 159 | char *strg; 160 | 161 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { 162 | return; 163 | } 164 | 165 | len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "ccvita", arg); 166 | RETURN_STRINGL(strg, len, 0); 167 | } 168 | /* }}} */ 169 | /* The previous line is meant for vim and emacs, so it can correctly fold and 170 | unfold functions in source code. See the corresponding marks just before 171 | function definition, where the functions purpose is also documented. Please 172 | follow this convention for the convenience of others editing your code. 173 | */ 174 | 175 | /* {{{ proto string ccvita_string(string str) 176 | */ 177 | PHP_FUNCTION(ccvita_string) 178 | { 179 | char *str = NULL; 180 | int argc = ZEND_NUM_ARGS(); 181 | int str_len; 182 | char *result; 183 | 184 | if (zend_parse_parameters(argc TSRMLS_CC, "s", &str, &str_len) == FAILURE) 185 | return; 186 | 187 | str_len = spprintf(&result, 0, "Link", str); 188 | RETURN_STRINGL(result, str_len, 0); 189 | } 190 | /* }}} */ 191 | 192 | 193 | /* 194 | * Local variables: 195 | * tab-width: 4 196 | * c-basic-offset: 4 197 | * End: 198 | * vim600: noet sw=4 ts=4 fdm=marker 199 | * vim<600: noet sw=4 ts=4 200 | */ 201 | --------------------------------------------------------------------------------