1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include "parser.h"
#include <stdio.h>
#include <dlfcn.h>
void * handle;
PHP_FUNCTION(parserInit) {
handle = dlopen ("./libparser.so", RTLD_LAZY);
}
PHP_FUNCTION(parserKill) {
dlclose (handle);
}
PHP_FUNCTION(Parse) {
char *str = NULL;
char *result;
int str_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
return;
}
char * (* parse) (char *) = dlsym (handle, "parse");
result = (* parse)(str);
RETURN_STRING(result,1);
}
static function_entry php_sample_functions[] = {
PHP_FE(Parse,NULL)
PHP_FE(parserInit,NULL)
PHP_FE(parserKill,NULL)
{NULL,NULL,NULL}
};
zend_module_entry parser_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER, // Roughly means if PHP Version > 4.2.0
#endif
PHP_PARSER_EXTNAME, // Define PHP extension name
php_sample_functions, /* Functions */
NULL, /* MINIT */
NULL, /* MSHUTDOWN */
NULL, /* RINIT */
NULL, /* RSHUTDOWN */
NULL, /* MINFO */
#if ZEND_MODULE_API_NO >= 20010901
PHP_PARSER_EXTVER, // Roughly means if PHP Version > 4.2.0
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_PARSER
ZEND_GET_MODULE(parser) // Common for all PHP extensions which are build as shared modules
#endif |
Partager