本文整理汇总了C++中efree函数的典型用法代码示例。如果您正苦于以下问题:C++ efree函数的具体用法?C++ efree怎么用?C++ efree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了efree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: LIBSSH2_FREE_FUNC
/* {{{ php_ssh2_free_cb
* Wrap efree()
*/
static LIBSSH2_FREE_FUNC(php_ssh2_free_cb)
{
efree(ptr);
}
开发者ID:php,项目名称:pecl-networking-ssh2,代码行数:7,代码来源:ssh2.c
示例2: _php_intlrbbi_constructor_body
static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
{
zval *object = getThis();
char *rules;
size_t rules_len;
zend_bool compiled = 0;
UErrorCode status = U_ZERO_ERROR;
intl_error_reset(NULL);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b",
&rules, &rules_len, &compiled) == FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"rbbi_create_instance: bad arguments", 0);
Z_OBJ_P(return_value) = NULL;
return;
}
// instantiation of ICU object
RuleBasedBreakIterator *rbbi;
if (!compiled) {
UnicodeString rulesStr;
UParseError parseError = UParseError();
if (intl_stringFromChar(rulesStr, rules, rules_len, &status)
== FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"rbbi_create_instance: rules were not a valid UTF-8 string",
0);
RETURN_NULL();
}
rbbi = new RuleBasedBreakIterator(rulesStr, parseError, status);
intl_error_set_code(NULL, status);
if (U_FAILURE(status)) {
char *msg;
smart_str parse_error_str;
parse_error_str = intl_parse_error_to_string(&parseError);
spprintf(&msg, 0, "rbbi_create_instance: unable to create "
"RuleBasedBreakIterator from rules (%s)", parse_error_str.s? parse_error_str.s->val : "");
smart_str_free(&parse_error_str);
intl_error_set_custom_msg(NULL, msg, 1);
efree(msg);
delete rbbi;
Z_OBJ_P(return_value) = NULL;
return;
}
} else { // compiled
#if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 48
rbbi = new RuleBasedBreakIterator((uint8_t*)rules, rules_len, status);
if (U_FAILURE(status)) {
intl_error_set(NULL, status, "rbbi_create_instance: unable to "
"create instance from compiled rules", 0);
Z_OBJ_P(return_value) = NULL;
return;
}
#else
intl_error_set(NULL, U_UNSUPPORTED_ERROR, "rbbi_create_instance: "
"compiled rules require ICU >= 4.8", 0);
Z_OBJ_P(return_value) = NULL;
return;
#endif
}
breakiterator_object_create(return_value, rbbi, 0);
}
开发者ID:AmesianX,项目名称:php-src,代码行数:65,代码来源:rulebasedbreakiterator_methods.cpp
示例3: destroy
void cshadows::unload (sshadow *singleton) {
destroy(&singleton->convexhull, efree, spoint);
destroy(&singleton->shape, efree, ssilhouette);
efree(singleton);
}
开发者ID:nardinan,项目名称:eagle,代码行数:5,代码来源:cshadows.cpp
示例4: MYSQLND_METHOD
/* {{{ mysqlnd_res_meta::set_mode */
static void
MYSQLND_METHOD(mysqlnd_debug, set_mode)(MYSQLND_DEBUG * self, const char * const mode)
{
unsigned int mode_len = strlen(mode), i;
enum mysqlnd_debug_parser_state state = PARSER_WAIT_MODIFIER;
self->flags = 0;
self->nest_level_limit = 0;
if (self->file_name && self->file_name != mysqlnd_debug_default_trace_file) {
efree(self->file_name);
self->file_name = NULL;
}
if (zend_hash_num_elements(&self->not_filtered_functions)) {
zend_hash_destroy(&self->not_filtered_functions);
zend_hash_init(&self->not_filtered_functions, 0, NULL, NULL, 0);
}
for (i = 0; i < mode_len; i++) {
switch (mode[i]) {
case 'O':
case 'A':
self->flags |= MYSQLND_DEBUG_FLUSH;
case 'a':
case 'o':
if (mode[i] == 'a' || mode[i] == 'A') {
self->flags |= MYSQLND_DEBUG_APPEND;
}
if (i + 1 < mode_len && mode[i+1] == ',') {
unsigned int j = i + 2;
while (j < mode_len) {
if (mode[j] == ':') {
break;
}
j++;
}
if (j > i + 2) {
self->file_name = estrndup(mode + i + 2, j - i - 2);
}
i = j;
} else {
if (!self->file_name)
self->file_name = (char *) mysqlnd_debug_default_trace_file;
}
state = PARSER_WAIT_COLON;
break;
case ':':
#if 0
if (state != PARSER_WAIT_COLON) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Consecutive semicolons at position %u", i);
}
#endif
state = PARSER_WAIT_MODIFIER;
break;
case 'f': /* limit output to these functions */
if (i + 1 < mode_len && mode[i+1] == ',') {
unsigned int j = i + 2;
i++;
while (j < mode_len) {
if (mode[j] == ':') {
/* function names with :: */
if ((j + 1 < mode_len) && mode[j+1] == ':') {
j += 2;
continue;
}
}
if (mode[j] == ',' || mode[j] == ':') {
if (j > i + 2) {
char func_name[1024];
unsigned int func_name_len = MIN(sizeof(func_name) - 1, j - i - 1);
memcpy(func_name, mode + i + 1, func_name_len);
func_name[func_name_len] = '\0';
zend_hash_add_empty_element(&self->not_filtered_functions,
func_name, func_name_len + 1);
i = j;
}
if (mode[j] == ':') {
break;
}
}
j++;
}
i = j;
} else {
#if 0
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"Expected list of functions for '%c' found none", mode[i]);
#endif
}
state = PARSER_WAIT_COLON;
break;
case 'D':
case 'd':
case 'g':
case 'p':
/* unsupported */
if ((i + 1) < mode_len && mode[i+1] == ',') {
i+= 2;
while (i < mode_len) {
//.........这里部分代码省略.........
开发者ID:browniebraun,项目名称:php-src,代码行数:101,代码来源:mysqlnd_debug.c
示例5: mempool_free_puddles
/**
* Go through the freelists and free puddles with no used chunks.
*
* @return
* Number of freed puddles.
*/
static size_t
mempool_free_puddles (mempool_struct *pool)
{
size_t chunksize_real, nrof_arrays, i, j, freed;
mempool_chunk_struct *last_free, *chunk;
mempool_puddle_struct *puddle, *next_puddle;
HARD_ASSERT(pool != NULL);
if (pool->flags & MEMPOOL_BYPASS_POOLS) {
return 0;
}
freed = 0;
for (i = 0; i < MEMPOOL_NROF_FREELISTS; i++) {
chunksize_real = sizeof(mempool_chunk_struct) + (pool->chunksize << i);
nrof_arrays = pool->expand_size >> i;
/* Free empty puddles and setup puddle-local freelists */
for (puddle = pool->puddlelist[i], pool->puddlelist[i] = NULL;
puddle != NULL; puddle = next_puddle) {
next_puddle = puddle->next;
/* Count free chunks in puddle, and set up a local freelist */
puddle->first_free = puddle->last_free = NULL;
puddle->nrof_free = 0;
for (j = 0; j < nrof_arrays; j++) {
chunk = (mempool_chunk_struct *)
(((char *) puddle->first_chunk) + chunksize_real * j);
/* Find free chunks. */
if (CHUNK_FREE(MEM_USERDATA(chunk))) {
if (puddle->nrof_free == 0) {
puddle->first_free = chunk;
puddle->last_free = chunk;
chunk->next = NULL;
} else {
chunk->next = puddle->first_free;
puddle->first_free = chunk;
}
puddle->nrof_free++;
}
}
/* Can we actually free this puddle? */
if (puddle->nrof_free == nrof_arrays ||
(deiniting && pool == pool_puddle)) {
/* Yup. Forget about it. */
efree(puddle->first_chunk);
if (!deiniting || pool != pool_puddle) {
mempool_return(pool_puddle, puddle);
}
pool->nrof_free[i] -= nrof_arrays;
pool->nrof_allocated[i] -= nrof_arrays;
freed++;
} else {
/* Nope, keep this puddle: put it back into the tracking list */
puddle->next = pool->puddlelist[i];
pool->puddlelist[i] = puddle;
}
}
/* Sort the puddles by amount of free chunks. It will let us set up the
* freelist so that the chunks from the fullest puddles are used first.
* This should (hopefully) help us free some of the lesser-used puddles
* earlier. */
pool->puddlelist[i] = sort_linked_list(pool->puddlelist[i], 0,
sort_puddle_by_nrof_free, NULL, NULL, NULL);
/* Finally: restore the global freelist */
pool->freelist[i] = &end_marker;
last_free = &end_marker;
for (puddle = pool->puddlelist[i]; puddle != NULL;
puddle = puddle->next) {
if (puddle->nrof_free > 0) {
if (pool->freelist[i] == &end_marker) {
pool->freelist[i] = puddle->first_free;
} else {
last_free->next = puddle->first_free;
}
puddle->last_free->next = &end_marker;
last_free = puddle->last_free;
}
}
}
return freed;
//.........这里部分代码省略.........
开发者ID:atrinik,项目名称:atrinik,代码行数:101,代码来源:mempool.c
示例6: phar_parse_url
/**
* Open a phar file for streams API
*/
php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options) /* {{{ */
{
php_url *resource;
char *arch = NULL, *entry = NULL, *error;
int arch_len, entry_len;
if (strlen(filename) < 7 || strncasecmp(filename, "phar://", 7)) {
return NULL;
}
if (mode[0] == 'a') {
if (!(options & PHP_STREAM_URL_STAT_QUIET)) {
php_stream_wrapper_log_error(wrapper, options, "phar error: open mode append not supported");
}
return NULL;
}
if (phar_split_fname(filename, strlen(filename), &arch, &arch_len, &entry, &entry_len, 2, (mode[0] == 'w' ? 2 : 0)) == FAILURE) {
if (!(options & PHP_STREAM_URL_STAT_QUIET)) {
if (arch && !entry) {
php_stream_wrapper_log_error(wrapper, options, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", filename, arch);
arch = NULL;
} else {
php_stream_wrapper_log_error(wrapper, options, "phar error: invalid url or non-existent phar \"%s\"", filename);
}
}
return NULL;
}
resource = ecalloc(1, sizeof(php_url));
resource->scheme = estrndup("phar", 4);
resource->host = arch;
resource->path = entry;
#if MBO_0
if (resource) {
fprintf(stderr, "Alias: %s\n", alias);
fprintf(stderr, "Scheme: %s\n", resource->scheme);
/* fprintf(stderr, "User: %s\n", resource->user);*/
/* fprintf(stderr, "Pass: %s\n", resource->pass ? "***" : NULL);*/
fprintf(stderr, "Host: %s\n", resource->host);
/* fprintf(stderr, "Port: %d\n", resource->port);*/
fprintf(stderr, "Path: %s\n", resource->path);
/* fprintf(stderr, "Query: %s\n", resource->query);*/
/* fprintf(stderr, "Fragment: %s\n", resource->fragment);*/
}
#endif
if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) {
phar_archive_data *pphar = NULL, *phar;
if (PHAR_G(request_init) && PHAR_G(phar_fname_map.u.flags) && NULL == (pphar = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), arch, arch_len))) {
pphar = NULL;
}
if (PHAR_G(readonly) && (!pphar || !pphar->is_data)) {
if (!(options & PHP_STREAM_URL_STAT_QUIET)) {
php_stream_wrapper_log_error(wrapper, options, "phar error: write operations disabled by the php.ini setting phar.readonly");
}
php_url_free(resource);
return NULL;
}
if (phar_open_or_create_filename(resource->host, arch_len, NULL, 0, 0, options, &phar, &error) == FAILURE)
{
if (error) {
if (!(options & PHP_STREAM_URL_STAT_QUIET)) {
php_stream_wrapper_log_error(wrapper, options, "%s", error);
}
efree(error);
}
php_url_free(resource);
return NULL;
}
if (phar->is_persistent && FAILURE == phar_copy_on_write(&phar)) {
if (error) {
spprintf(&error, 0, "Cannot open cached phar '%s' as writeable, copy on write failed", resource->host);
if (!(options & PHP_STREAM_URL_STAT_QUIET)) {
php_stream_wrapper_log_error(wrapper, options, "%s", error);
}
efree(error);
}
php_url_free(resource);
return NULL;
}
} else {
if (phar_open_from_filename(resource->host, arch_len, NULL, 0, options, NULL, &error) == FAILURE)
{
if (error) {
if (!(options & PHP_STREAM_URL_STAT_QUIET)) {
php_stream_wrapper_log_error(wrapper, options, "%s", error);
}
efree(error);
}
php_url_free(resource);
return NULL;
}
}
return resource;
}
开发者ID:20uf,项目名称:php-src,代码行数:97,代码来源:stream.c
示例7: wmain
int wmain(int argc, wchar_t **wcargv)
{
char** argv;
#else
int
main(int argc, char** argv)
{
#endif
int eargv_size;
int eargc_base; /* How many arguments in the base of eargv. */
char* emulator;
char* basename;
char* def_emu_lookup_path;
char scriptname[PMAX];
char** last_opt;
char** first_opt;
#ifdef __WIN32__
int i;
int len;
/* Convert argv to utf8 */
argv = emalloc((argc+1) * sizeof(char*));
for (i=0; i<argc; i++) {
len = WideCharToMultiByte(CP_UTF8, 0, wcargv[i], -1, NULL, 0, NULL, NULL);
argv[i] = emalloc(len*sizeof(char));
WideCharToMultiByte(CP_UTF8, 0, wcargv[i], -1, argv[i], len, NULL, NULL);
}
argv[argc] = NULL;
#endif
/*
* Allocate the argv vector to be used for arguments to Erlang.
* Arrange for starting to pushing information in the middle of
* the array, to allow easy addition of commands in the beginning.
*/
eargv_size = argc*4+1000+LINEBUFSZ/2;
eargv_base = (char **) emalloc(eargv_size*sizeof(char*));
eargv = eargv_base;
eargc = 0;
eargc_base = eargc;
eargv = eargv + eargv_size/2;
eargc = 0;
/* Determine basename of the executable */
for (basename = argv[0]+strlen(argv[0]);
basename > argv[0] && !(IS_DIRSEP(basename[-1]));
--basename)
;
first_opt = argv;
last_opt = argv;
#ifdef __WIN32__
if ( (_stricmp(basename, "escript.exe") == 0)
||(_stricmp(basename, "escript") == 0)) {
#else
if (strcmp(basename, "escript") == 0) {
#endif
def_emu_lookup_path = argv[0];
/*
* Locate all options before the script name.
*/
while (argc > 1 && argv[1][0] == '-') {
argc--;
argv++;
last_opt = argv;
}
if (argc <= 1) {
error("Missing filename\n");
}
strncpy(scriptname, argv[1], sizeof(scriptname));
scriptname[sizeof(scriptname)-1] = '\0';
argc--;
argv++;
} else {
char *absname = find_prog(argv[0]);
#ifdef __WIN32__
int len = strlen(absname);
if (len >= 4 && _stricmp(absname+len-4, ".exe") == 0) {
absname[len-4] = '\0';
}
#endif
erts_snprintf(scriptname, sizeof(scriptname), "%s.escript",
absname);
efree(absname);
def_emu_lookup_path = scriptname;
}
/* Determine path to emulator */
emulator = get_env("ESCRIPT_EMULATOR");
if (emulator == NULL) {
emulator = get_default_emulator(def_emu_lookup_path);
}
if (strlen(emulator) >= PMAX)
error("Value of environment variable ESCRIPT_EMULATOR is too large");
//.........这里部分代码省略.........
开发者ID:HansN,项目名称:otp,代码行数:101,代码来源:escript.c
示例8: dom_xpath_ext_function_php
//.........这里部分代码省略.........
curns->prefix = xmlStrdup((xmlChar *) node->children);
}
if (node->children) {
node = xmlNewDocNode(node->doc, NULL, (xmlChar *) node->children, node->name);
} else {
node = xmlNewDocNode(node->doc, NULL, (xmlChar *) "xmlns", node->name);
}
node->type = XML_NAMESPACE_DECL;
node->parent = nsparent;
node->ns = curns;
}
child = php_dom_create_object(node, &ret, NULL, child, (dom_object *)intern TSRMLS_CC);
add_next_index_zval(args[i], child);
}
}
}
break;
default:
ZVAL_STRING(args[i], (char *)xmlXPathCastToString(obj), 1);
}
xmlXPathFreeObject(obj);
fci.params[i] = &args[i];
}
fci.size = sizeof(fci);
fci.function_table = EG(function_table);
obj = valuePop(ctxt);
if (obj->stringval == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Handler name must be a string");
xmlXPathFreeObject(obj);
if (fci.param_count > 0) {
for (i = 0; i < nargs - 1; i++) {
zval_ptr_dtor(&args[i]);
}
efree(args);
efree(fci.params);
}
return;
}
INIT_PZVAL(&handler);
ZVAL_STRING(&handler, obj->stringval, 1);
xmlXPathFreeObject(obj);
fci.function_name = &handler;
fci.symbol_table = NULL;
fci.object_ptr = NULL;
fci.retval_ptr_ptr = &retval;
fci.no_separation = 0;
if (!zend_make_callable(&handler, &callable TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", callable);
} else if ( intern->registerPhpFunctions == 2 && zend_hash_exists(intern->registered_phpfunctions, callable, strlen(callable) + 1) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not allowed to call handler '%s()'.", callable);
/* Push an empty string, so that we at least have an xslt result... */
valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
} else {
result = zend_call_function(&fci, NULL TSRMLS_CC);
if (result == FAILURE) {
if (Z_TYPE(handler) == IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", Z_STRVAL_P(&handler));
}
/* retval is == NULL, when an exception occured, don't report anything, because PHP itself will handle that */
} else if (retval == NULL) {
} else {
if (retval->type == IS_OBJECT && instanceof_function( Z_OBJCE_P(retval), dom_node_class_entry TSRMLS_CC)) {
xmlNode *nodep;
dom_object *obj;
if (intern->node_list == NULL) {
ALLOC_HASHTABLE(intern->node_list);
zend_hash_init(intern->node_list, 0, NULL, ZVAL_PTR_DTOR, 0);
}
zval_add_ref(&retval);
zend_hash_next_index_insert(intern->node_list, &retval, sizeof(zval *), NULL);
obj = (dom_object *)zend_object_store_get_object(retval TSRMLS_CC);
nodep = dom_object_get_node(obj);
valuePush(ctxt, xmlXPathNewNodeSet(nodep));
} else if (retval->type == IS_BOOL) {
valuePush(ctxt, xmlXPathNewBoolean(retval->value.lval));
} else if (retval->type == IS_OBJECT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object cannot be converted to a XPath-string");
valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
} else {
convert_to_string_ex(&retval);
valuePush(ctxt, xmlXPathNewString( Z_STRVAL_P(retval)));
}
zval_ptr_dtor(&retval);
}
}
efree(callable);
zval_dtor(&handler);
if (fci.param_count > 0) {
for (i = 0; i < nargs - 1; i++) {
zval_ptr_dtor(&args[i]);
}
efree(args);
efree(fci.params);
}
}
开发者ID:NobleGaz,项目名称:PHP,代码行数:101,代码来源:xpath.c
示例9: ZEND_METHOD
/* {{{ proto mixed Closure::call(object to [, mixed parameter] [, mixed ...] )
Call closure, binding to a given object with its class as the scope */
ZEND_METHOD(Closure, call)
{
zval *zclosure, *newthis, closure_result;
zend_closure *closure;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;
zval *my_params;
int my_param_count = 0;
zend_function my_function;
zend_object *newobj;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o*", &newthis, &my_params, &my_param_count) == FAILURE) {
return;
}
zclosure = getThis();
closure = (zend_closure *) Z_OBJ_P(zclosure);
if (closure->func.common.fn_flags & ZEND_ACC_STATIC) {
zend_error(E_WARNING, "Cannot bind an instance to a static closure");
return;
}
if (closure->func.type == ZEND_INTERNAL_FUNCTION) {
/* verify that we aren't binding internal function to a wrong object */
if ((closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0 &&
closure->func.common.scope &&
!instanceof_function(Z_OBJCE_P(newthis), closure->func.common.scope)) {
zend_error(E_WARNING, "Cannot bind function %s::%s to object of class %s", ZSTR_VAL(closure->func.common.scope->name), ZSTR_VAL(closure->func.common.function_name), ZSTR_VAL(Z_OBJCE_P(newthis)->name));
return;
}
}
newobj = Z_OBJ_P(newthis);
if (newobj->ce != closure->func.common.scope && newobj->ce->type == ZEND_INTERNAL_CLASS) {
/* rebinding to internal class is not allowed */
zend_error(E_WARNING, "Cannot bind closure to object of internal class %s", ZSTR_VAL(newobj->ce->name));
return;
}
/* This should never happen as closures will always be callable */
if (zend_fcall_info_init(zclosure, 0, &fci, &fci_cache, NULL, NULL) != SUCCESS) {
ZEND_ASSERT(0);
}
fci.retval = &closure_result;
fci.params = my_params;
fci.param_count = my_param_count;
fci.object = fci_cache.object = newobj;
fci_cache.initialized = 1;
if (fci_cache.function_handler->common.fn_flags & ZEND_ACC_GENERATOR) {
zval new_closure;
zend_create_closure(&new_closure, fci_cache.function_handler, Z_OBJCE_P(newthis), closure->called_scope, newthis);
closure = (zend_closure *) Z_OBJ(new_closure);
fci_cache.function_handler = &closure->func;
} else {
memcpy(&my_function, fci_cache.function_handler, fci_cache.function_handler->type == ZEND_USER_FUNCTION ? sizeof(zend_op_array) : sizeof(zend_internal_function));
/* use scope of passed object */
my_function.common.scope = Z_OBJCE_P(newthis);
fci_cache.function_handler = &my_function;
/* Runtime cache relies on bound scope to be immutable, hence we need a separate rt cache in case scope changed */
if (ZEND_USER_CODE(my_function.type) && closure->func.common.scope != Z_OBJCE_P(newthis)) {
my_function.op_array.run_time_cache = emalloc(my_function.op_array.cache_size);
memset(my_function.op_array.run_time_cache, 0, my_function.op_array.cache_size);
}
}
if (zend_call_function(&fci, &fci_cache) == SUCCESS && Z_TYPE(closure_result) != IS_UNDEF) {
ZVAL_COPY_VALUE(return_value, &closure_result);
}
if (fci_cache.function_handler->common.fn_flags & ZEND_ACC_GENERATOR) {
/* copied upon generator creation */
--GC_REFCOUNT(&closure->std);
} else if (ZEND_USER_CODE(my_function.type) && closure->func.common.scope != Z_OBJCE_P(newthis)) {
efree(my_function.op_array.run_time_cache);
}
}
开发者ID:lvniu,项目名称:php-src,代码行数:83,代码来源:zend_closures.c
示例10: ftp_getdata
//.........这里部分代码省略.........
data = ecalloc(1, sizeof(*data));
data->listener = -1;
data->fd = -1;
data->type = ftp->type;
sa = (struct sockaddr *) &ftp->localaddr;
/* bind/listen */
if ((fd = socket(sa->sa_family, SOCK_STREAM, 0)) == SOCK_ERR) {
php_error_docref(NULL, E_WARNING, "socket() failed: %s (%d)", strerror(errno), errno);
goto bail;
}
/* passive connection handler */
if (ftp->pasv) {
/* clear the ready status */
ftp->pasv = 1;
/* connect */
/* Win 95/98 seems not to like size > sizeof(sockaddr_in) */
size = php_sockaddr_size(&ftp->pasvaddr);
tv.tv_sec = ftp->timeout_sec;
tv.tv_usec = 0;
if (php_connect_nonb(fd, (struct sockaddr*) &ftp->pasvaddr, size, &tv) == -1) {
php_error_docref(NULL, E_WARNING, "php_connect_nonb() failed: %s (%d)", strerror(errno), errno);
goto bail;
}
data->fd = fd;
ftp->data = data;
return data;
}
/* active (normal) connection */
/* bind to a local address */
php_any_addr(sa->sa_family, &addr, 0);
size = php_sockaddr_size(&addr);
if (bind(fd, (struct sockaddr*) &addr, size) != 0) {
php_error_docref(NULL, E_WARNING, "bind() failed: %s (%d)", strerror(errno), errno);
goto bail;
}
if (getsockname(fd, (struct sockaddr*) &addr, &size) != 0) {
php_error_docref(NULL, E_WARNING, "getsockname() failed: %s (%d)", strerror(errno), errno);
goto bail;
}
if (listen(fd, 5) != 0) {
php_error_docref(NULL, E_WARNING, "listen() failed: %s (%d)", strerror(errno), errno);
goto bail;
}
data->listener = fd;
#if HAVE_IPV6 && HAVE_INET_NTOP
if (sa->sa_family == AF_INET6) {
/* need to use EPRT */
char eprtarg[INET6_ADDRSTRLEN + sizeof("|x||xxxxx|")];
char out[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &((struct sockaddr_in6*) sa)->sin6_addr, out, sizeof(out));
snprintf(eprtarg, sizeof(eprtarg), "|2|%s|%hu|", out, ntohs(((struct sockaddr_in6 *) &addr)->sin6_port));
if (!ftp_putcmd(ftp, "EPRT", eprtarg)) {
goto bail;
}
if (!ftp_getresp(ftp) || ftp->resp != 200) {
goto bail;
}
ftp->data = data;
return data;
}
#endif
/* send the PORT */
ipbox.ia[0] = ((struct sockaddr_in*) sa)->sin_addr;
ipbox.s[2] = ((struct sockaddr_in*) &addr)->sin_port;
snprintf(arg, sizeof(arg), "%u,%u,%u,%u,%u,%u", ipbox.c[0], ipbox.c[1], ipbox.c[2], ipbox.c[3], ipbox.c[4], ipbox.c[5]);
if (!ftp_putcmd(ftp, "PORT", arg)) {
goto bail;
}
if (!ftp_getresp(ftp) || ftp->resp != 200) {
goto bail;
}
ftp->data = data;
return data;
bail:
if (fd != -1) {
closesocket(fd);
}
efree(data);
return NULL;
}
开发者ID:20uf,项目名称:php-src,代码行数:101,代码来源:ftp.c
示例11: data_accept
/* {{{ data_accept
*/
databuf_t*
data_accept(databuf_t *data, ftpbuf_t *ftp)
{
php_sockaddr_storage addr;
socklen_t size;
#ifdef HAVE_FTP_SSL
SSL_CTX *ctx;
zend_long ssl_ctx_options = SSL_OP_ALL;
int err, res;
zend_bool retry;
#endif
if (data->fd != -1) {
goto data_accepted;
}
size = sizeof(addr);
data->fd = my_accept(ftp, data->listener, (struct sockaddr*) &addr, &size);
closesocket(data->listener);
data->listener = -1;
if (data->fd == -1) {
efree(data);
return NULL;
}
data_accepted:
#ifdef HAVE_FTP_SSL
/* now enable ssl if we need to */
if (ftp->use_ssl && ftp->use_ssl_for_data) {
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx == NULL) {
php_error_docref(NULL, E_WARNING, "data_accept: failed to create the SSL context");
return 0;
}
#if OPENSSL_VERSION_NUMBER >= 0x0090605fL
ssl_ctx_options &= ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
#endif
SSL_CTX_set_options(ctx, ssl_ctx_options);
data->ssl_handle = SSL_new(ctx);
if (data->ssl_handle == NULL) {
php_error_docref(NULL, E_WARNING, "data_accept: failed to create the SSL handle");
SSL_CTX_free(ctx);
return 0;
}
SSL_set_fd(data->ssl_handle, data->fd);
if (ftp->old_ssl) {
SSL_copy_session_id(data->ssl_handle, ftp->ssl_handle);
}
do {
res = SSL_connect(data->ssl_handle);
err = SSL_get_error(data->ssl_handle, res);
switch (err) {
case SSL_ERROR_NONE:
retry = 0;
break;
case SSL_ERROR_ZERO_RETURN:
retry = 0;
SSL_shutdown(data->ssl_handle);
break;
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE: {
php_pollfd p;
int i;
p.fd = ftp->fd;
p.events = (err == SSL_ERROR_WANT_READ) ? (POLLIN|POLLPRI) : POLLOUT;
p.revents = 0;
i = php_poll2(&p, 1, 300);
retry = i > 0;
}
break;
default:
php_error_docref(NULL, E_WARNING, "data_accept: SSL/TLS handshake failed");
SSL_shutdown(data->ssl_handle);
SSL_free(data->ssl_handle);
return 0;
}
} while (retry);
data->ssl_active = 1;
}
#endif
//.........这里部分代码省略.........
开发者ID:20uf,项目名称:php-src,代码行数:101,代码来源:ftp.c
示例12: check_fileupload_varname
/* {{{ SAPI_UPLOAD_VARNAME_FILTER_FUNC
*/
static int check_fileupload_varname(char *varname)
{
char *index, *prev_index = NULL, *var;
unsigned int var_len, total_len, depth = 0;
TSRMLS_FETCH();
var = estrdup(varname);
/* Normalize the variable name */
normalize_varname(var);
/* Find length of variable name */
index = strchr(var, '[');
total_len = strlen(var);
var_len = index ? index-var : total_len;
/* Drop this variable if it exceeds the varname/total length limit */
if (SUHOSIN_G(max_varname_length) && SUHOSIN_G(max_varname_length) < var_len) {
suhosin_log(S_FILES, "configured request variable name length limit exceeded - dropped variable '%s'", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
if (SUHOSIN_G(max_totalname_length) && SUHOSIN_G(max_totalname_length) < total_len) {
suhosin_log(S_FILES, "configured request variable total name length limit exceeded - dropped variable '%s'", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
if (SUHOSIN_G(max_post_name_length) && SUHOSIN_G(max_post_name_length) < var_len) {
suhosin_log(S_FILES, "configured POST variable name length limit exceeded - dropped variable '%s'", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
if (SUHOSIN_G(max_post_totalname_length) && SUHOSIN_G(max_post_totalname_length) < var_len) {
suhosin_log(S_FILES, "configured POST variable total name length limit exceeded - dropped variable '%s'", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
/* Find out array depth */
while (index) {
unsigned int index_length;
depth++;
index = strchr(index+1, '[');
if (prev_index) {
index_length = index ? index - 1 - prev_index - 1: strlen(prev_index);
if (SUHOSIN_G(max_array_index_length) && SUHOSIN_G(max_array_index_length) < index_length) {
suhosin_log(S_FILES, "configured request variable array index length limit exceeded - dropped variable '%s'", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
if (SUHOSIN_G(max_post_array_index_length) && SUHOSIN_G(max_post_array_index_length) < index_length) {
suhosin_log(S_FILES, "configured POST variable array index length limit exceeded - dropped variable '%s'", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
prev_index = index;
}
}
/* Drop this variable if it exceeds the array depth limit */
if (SUHOSIN_G(max_array_depth) && SUHOSIN_G(max_array_depth) < depth) {
suhosin_log(S_FILES, "configured request variable array depth limit exceeded - dropped variable '%s'", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
if (SUHOSIN_G(max_post_array_depth) && SUHOSIN_G(max_post_array_depth) < depth) {
suhosin_log(S_FILES, "configured POST variable array depth limit exceeded - dropped variable '%s'", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
/* Drop this variable if it is one of GLOBALS, _GET, _POST, ... */
/* This is to protect several silly scripts that do globalizing themself */
if (is_protected_varname(var, var_len)) {
suhosin_log(S_FILES, "tried to register forbidden variable '%s' through FILE variables", var);
if (!SUHOSIN_G(simulation)) {
goto return_failure;
}
}
efree(var);
return SUCCESS;
return_failure:
//.........这里部分代码省略.........
开发者ID:Tyrael,项目名称:suhosin,代码行数:101,代码来源:ufilter.c
示例13: memcpy
//.........这里部分代码省略.........
return server;
}
}
/* Create a new entry for this server and add it to the list.
**/
server = (httpserverinfo *)emalloc(sizeof(httpserverinfo));
/* +3 for the ://, +1 for the trailing /, +1 for the terminating null
**/
server->baseurl = (char *)emalloc(methodlen + serverportlen + 5);
/* These 4 lines to avoid a call to non ANSI snprintf . May not be the
best way but it ensures no buffer overruns */
memcpy (server->baseurl,method,methodlen);
memcpy (server->baseurl+methodlen,"://",3);
memcpy (server->baseurl+methodlen+3,serverport,serverportlen);
strcpy (server->baseurl+methodlen+3+serverportlen,"/");
server->lastretrieval = 0;
server->robotrules = 0;
server->next = servers;
servers = server;
/* Only http(s) servers can full rules, all the other ones just get dummies
** (this is useful for holding last retrieval)
**
** http://info.webcrawler.com/mak/projects/robots/norobots.html holds what
** many people consider the official web exclusion rules. Unfortunately,
** the rules are not consistent about how records are formed. One line
** states "the file consists of one or more records separated by one or more
** blank lines" while another states "the record starts with one or more User-agent
** lines, followed by one or more Disallow lines."
**
** So, does a blank line after a User-agent line end a record? The spec is
** unclear on this matter. If the next legal line afer the blank line is
** a Disallow line, the blank line should most likely be ignored. But what
** if the next line is another User-agent line? For example:
**
** User-agent: MooBot
**
** User-agent: CreepySpider
** Disallow: /cgi-bin
**
** One interpretation (based on blank lines termination records) is that MooBot
** may visit any location (since there are no Disallows for it). Another
** interpretation (based on records needing both User-agent and Disallow lines)
** is that MooBot may not visit /cgi-bin
**
** While poking around, I found at least one site (www.sun.com) that uses blank
** lines within records. Because of that, I have decided to rely on records
** having both User-agent and Disallow lines (the second interpretation above).
**/
if (strncmp(server->baseurl, "http", 4) == 0) {
if((int)(strlen(server->baseurl)+20)>=lenbuffer) {
lenbuffer=strlen(server->baseurl)+20+200;
buffer=erealloc(buffer,lenbuffer+1);
}
sprintf(buffer, "%srobots.txt", server->baseurl);
file_prefix = emalloc( strlen(idx->tmpdir) + MAXPIDLEN + strlen("/[email protected]+fill") );
sprintf(file_prefix, "%s/[email protected]%ld", idx->tmpdir, (long) lgetpid());
if (get(sw,contenttype, &last_modified, &server->lastretrieval, file_prefix, buffer) == 200)
{
char *robots_buffer;
int filelen;
int bytes_read;
if((int)(strlen(idx->tmpdir)+MAXPIDLEN+30)>=lenbuffer) {
lenbuffer=strlen(idx->tmpdir)+MAXPIDLEN+30+200;
buffer=erealloc(buffer,lenbuffer+1);
}
sprintf(buffer, "%s/[email protected]%ld.contents", idx->tmpdir, (long)lgetpid());
fp = fopen(buffer, F_READ_TEXT);
filelen = getsize(buffer);
robots_buffer = emalloc( filelen + 1 );
*robots_buffer = '\0';
bytes_read = fread(robots_buffer, 1, filelen, fp);
robots_buffer[bytes_read] = '\0';
parserobotstxt( robots_buffer, bytes_read, server );
efree( robots_buffer );
//parserobotstxt(fp, server);
fclose(fp); /* Have to close before unlink on Windows */
}
efree( file_prefix );
cmdf(unlink, "%s/[email protected]%ld.response", idx->tmpdir, lgetpid());
cmdf(unlink, "%s/[email protected]%ld.contents", idx->tmpdir, lgetpid());
cmdf(unlink, "%s/[email protected]%ld.links", idx->tmpdir, lgetpid());
}
return server;
}
开发者ID:OS2World,项目名称:APP-INTERNET-Swish-e,代码行数:101,代码来源:httpserver.c
示例14: parserobotstxt
static void parserobotstxt(char *robots_buffer, int buflen, httpserverinfo *server)
{
char *buffer;
char *bufend = robots_buffer + buflen -1; // last char of string
char *next_start = robots_buffer;
enum {START, USERAGENT, DISALLOW} state = START;
enum {SPECIFIC, GENERIC, SKIPPING} useragentstate = SKIPPING;
char *p;
int len;
robotrules *entry;
robotrules *entry2;
server->useragent = 0;
buffer = NULL;
while ( (buffer = next_line( &next_start, bufend ) ) )
{
if ( strchr( buffer, '#' ) )
*(strchr( buffer, '#' )) = '\0';
if ((*buffer == '#') || (*buffer == '\0'))
continue;
if (strncasecmp(buffer, useragent, sizeof(useragent) - 1) == 0) {
switch (state) {
case DISALLOW:
/* Since we found our specific user-agent, we can
** skip the rest of the file.
**/
if (useragentstate == SPECIFIC) {
return;
}
useragentstate = SKIPPING;
/* explict fallthrough */
case START:
case USERAGENT:
state = USERAGENT;
if (useragentstate != SPECIFIC) {
p = isolatevalue(buffer, useragent, &len);
if ((len == (sizeof(swishspider) - 1)) &&
(strncasecmp(p, swishspider, sizeof(swishspider) - 1) == 0) ) {
useragentstate = SPECIFIC;
/* We might have already parsed generic rules,
** so clean them up if necessary.
*/
if (server->useragent) {
efree(server->useragent);
}
for (entry = server->robotrules; entry; ) {
entry2 = entry->next;
efree(entry);
entry = entry2;
}
server->robotrules = 0;
server->useragent = (char *)emalloc(len + 1);
strncpy(server->useragent, p, len);
*(server->useragent + len) = '\0';
}
else if ((len == 1) && (*p == '*')) {
useragentstate = GENERIC;
server->useragent = (char *)emalloc(2);
strcpy(server->useragent, "*"); /* emalloc'd 2 bytes, no safestrcpy */
}
}
break;
}
}
if (strncasecmp(buffer, disallow, sizeof(disallow) - 1) == 0) {
state = DISALLOW;
if (useragentstate != SKIPPING) {
p = isolatevalue(buffer, disallow, &len);
if (len) {
entry = (robotrules *)emalloc(sizeof(robotrules));
entry->next = server->robotrules;
server->robotrules = entry;
entry->disallow = (char *)emalloc(len + 1);
strncpy(entry->disallow, p, len);
*(entry->disallow + len) = '\0';
}
}
}
}
}
开发者ID:OS2World,项目名称:APP-INTERNET-Swish-e,代码行数:99,代码来源:httpserver.c
示例15: grapheme_strrpos_utf16
/* {{{ grapheme_strrpos_utf16 - strrpos using utf16 */
int
grapheme_strrpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned char*needle, int32_t needle_len, int32_t offset, int f_ignore_case TSRMLS_DC)
{
UChar *uhaystack, *puhaystack, *uhaystack_end, *uneedle;
int32_t uhaystack_len, uneedle_len;
UErrorCode status;
unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE];
UBreakIterator* bi = NULL;
int ret_pos, pos;
/* convert the strings to UTF-16. */
uhaystack = NULL;
uhaystack_len = 0;
status = U_ZERO_ERROR;
intl_convert_utf8_to_utf16(&uhaystack, &uhaystack_len, (char *) haystack, haystack_len, &status );
if ( U_FAILURE( status ) ) {
/* Set global error code. */
intl_error_set_code( NULL, status TSRMLS_CC );
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC );
if (uhaystack) {
efree( uhaystack );
}
return -1;
}
if ( f_ignore_case ) {
grapheme_intl_case_fold(&uhaystack, &uhaystack, &uhaystack_len, &status );
}
/* get a pointer to the haystack taking into account the offset */
bi = NULL;
status = U_ZERO_ERROR;
bi = grapheme_get_break_iterator(u_break_iterator_buffer, &status TSRMLS_CC );
puhaystack = grapheme_get_haystack_offset(bi, uhaystack, uhaystack_len, offset);
if ( NULL == puhaystack ) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 TSRMLS_CC );
if (uhaystack) {
efree( uhaystack );
}
ubrk_close (bi);
return -1;
}
uneedle = NULL;
uneedle_len = 0;
status = U_ZERO_ERROR;
intl_convert_utf8_to_utf16(&uneedle, &uneedle_len, (char *) needle, needle_len, &status );
if ( U_FAILURE( status ) ) {
/* Set global error code. */
intl_error_set_code( NULL, status TSRMLS_CC );
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 TSRMLS_CC );
if (uhaystack) {
efree( uhaystack );
}
if (uneedle) {
efree( uneedle );
}
ubrk_close (bi);
return -1;
}
if ( f_ignore_case ) {
grapheme_intl_case_fold(&uneedle, &uneedle, &uneedle_len, &status );
}
ret_pos = -1; /* -1 represents 'not found' */
/* back up until there's needle_len characters to compare */
uhaystack_end = uhaystack + uhaystack_len;
pos = ubrk_last(bi);
puhaystack = uhaystack + pos;
while ( uhaystack_end - puhaystack < uneedle_len ) {
pos = ubrk_previous(bi);
if ( UBRK_DONE == pos ) {
break;
}
puhaystack = uhaystack + pos;
}
/* is there enough haystack left to hold the needle? */
if ( ( uhaystack_end - puhaystack ) < uneedle_len ) {
/* not enough, not found */
goto exit;
}
while ( UBRK_DONE != pos ) {
//.........这里部分代码省略.........
开发者ID:dreamsxin,项目名称:php-utf8,代码行数:101,代码来源:grapheme_util.c
示例16: find_prog
static char *
find_prog(char *origpath)
{
wchar_t relpath[PMAX];
wchar_t abspath[PMAX];
if (strlen(origpath) >= PMAX)
error("Path too long");
MultiByteToWideChar(CP_UTF8, 0, origpath, -1, relpath, PMAX);
if (wcsstr(relpath, LDIRSEPSTR) == NULL) {
/* Just a base name */
int sz;
wchar_t *envpath;
sz = GetEnvironmentVariableW(L"PATH", NULL, 0);
if (sz) {
/* Try to find the executable in the path */
wchar_t dir[PMAX];
wchar_t *beg;
wchar_t *end;
HANDLE dir_handle; /* Handle to directory. */
wchar_t wildcard[PMAX]; /* Wildcard to search for. */
WIN32_FIND_DATAW find_data; /* Data found by FindFirstFile() or FindNext(). */
BOOL look_for_sep = TRUE;
envpath = (wchar_t *) emalloc(sz * sizeof(wchar_t*));
GetEnv
|
请发表评论