#ifdef HAVE_CONFIG_H #include "config.h" #endif #include #ifdef ZTS #include "TSRM.h" #endif #include #include #include "ext/standard/info.h" #include #include #include #include #include #include #include #include "local_ip_func.h" #include "logger.h" #include "sockopt.h" #include "fastcommon.h" #define MAJOR_VERSION 1 #define MINOR_VERSION 0 #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 }; #undef ZEND_BEGIN_ARG_INFO_EX #define ZEND_BEGIN_ARG_INFO_EX(name, pass_rest_by_reference, return_reference, required_num_args) \ static zend_arg_info name[] = { \ { NULL, 0, NULL, 0, 0, 0, pass_rest_by_reference, return_reference, required_num_args }, #endif // Every user visible function must have an entry in fastcommon_functions[]. zend_function_entry fastcommon_functions[] = { ZEND_FE(fastcommon_version, NULL) ZEND_FE(fastcommon_gethostaddrs, NULL) {NULL, NULL, NULL} /* Must be the last line */ }; zend_module_entry fastcommon_module_entry = { STANDARD_MODULE_HEADER, "fastcommon", fastcommon_functions, PHP_MINIT(fastcommon), PHP_MSHUTDOWN(fastcommon), NULL,//PHP_RINIT(fastcommon), NULL,//PHP_RSHUTDOWN(fastcommon), PHP_MINFO(fastcommon), "1.00", STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_FASTCOMMON ZEND_GET_MODULE(fastcommon) #endif PHP_MINIT_FUNCTION(fastcommon) { log_init(); return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(fastcommon) { log_destroy(); return SUCCESS; } PHP_RINIT_FUNCTION(fastcommon) { return SUCCESS; } PHP_RSHUTDOWN_FUNCTION(fastcommon) { return SUCCESS; } PHP_MINFO_FUNCTION(fastcommon) { char mc_info[64]; sprintf(mc_info, "fastcommon v%d.%02d support", MAJOR_VERSION, MINOR_VERSION); php_info_print_table_start(); php_info_print_table_header(2, mc_info, "enabled"); php_info_print_table_end(); } /* string fastcommon_version() return client library version */ ZEND_FUNCTION(fastcommon_version) { char szVersion[16]; int len; len = sprintf(szVersion, "%d.%02d", MAJOR_VERSION, MINOR_VERSION); RETURN_STRINGL(szVersion, len, 1); } /* array fastcommon_gethostaddrs([string if_alias_prefix]); return false for fail, array for success */ ZEND_FUNCTION(fastcommon_gethostaddrs) { int argc; char *if_alias_prefix; int if_prefix_len; int count; int uniq_count; int i; int k; int alias_count; char ip_addresses[FAST_MAX_LOCAL_IP_ADDRS][IP_ADDRESS_SIZE]; char *uniq_ips[FAST_MAX_LOCAL_IP_ADDRS]; char *if_alias_prefixes[1]; argc = ZEND_NUM_ARGS(); if (argc > 1) { logError("file: "__FILE__", line: %d, " "fastcommon_gethostaddrs parameters count: %d is invalid", __LINE__, argc); RETURN_BOOL(false); } if_alias_prefix = NULL; if (zend_parse_parameters(argc TSRMLS_CC, "|s", &if_alias_prefix, &if_prefix_len) == FAILURE) { logError("file: "__FILE__", line: %d, " "zend_parse_parameters fail!", __LINE__); RETURN_BOOL(false); } if (if_alias_prefix == NULL || if_prefix_len == 0) { alias_count = 0; if_alias_prefixes[0] = NULL; } else { alias_count = 1; if_alias_prefixes[0] = if_alias_prefix; } count = 0; if (gethostaddrs(if_alias_prefixes, alias_count, ip_addresses, FAST_MAX_LOCAL_IP_ADDRS, &count) != 0) { RETURN_BOOL(false); } uniq_count = 0; for (k=0; k