Esempio n. 1
0
int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS) {
    /*/ returns 1 as long or a result identifier as resource on success  or 0 as long on failure /*/
    int number_of_arguments=2;
    zval ** arguments[2];
    zval * queryresult_zval=NULL;
    zval * num_fields_zval=NULL;

    // db_name is not used in this function
    arguments[0]=dbx_handle;
    arguments[1]=sql_statement;
    dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_exec", &queryresult_zval, number_of_arguments, arguments);
    /*/ odbc_query returns a bool for failure, or a result_identifier for success /*/
    if (!queryresult_zval || queryresult_zval->type!=IS_RESOURCE) {
        if (queryresult_zval) zval_ptr_dtor(&queryresult_zval);
        return 0;
        }
    MAKE_STD_ZVAL(num_fields_zval);
    ZVAL_LONG(num_fields_zval, 0);
    if (!dbx_odbc_getcolumncount(&num_fields_zval, &queryresult_zval, INTERNAL_FUNCTION_PARAM_PASSTHRU)) {
        FREE_ZVAL(num_fields_zval);
        if (queryresult_zval) zval_ptr_dtor(&queryresult_zval);
        return 0;
        }
    if (num_fields_zval->value.lval==0) {
        (*rv)->type=IS_BOOL;
        (*rv)->value.lval=1; /*/ success, but no data /*/
        FREE_ZVAL(num_fields_zval);
        if (queryresult_zval) zval_ptr_dtor(&queryresult_zval);
        return 1;
        }
    FREE_ZVAL(num_fields_zval);
    MOVE_RETURNED_TO_RV(rv, queryresult_zval);
    return 1;
    }
Esempio n. 2
0
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops)
{
	while (elements-- > 0) {
		zval *key, *data, **old_data;

		ALLOC_INIT_ZVAL(key);

		if (!php_var_unserialize2(&key, p, max, NULL TSRMLS_CC)) {
			zval_dtor(key);
			FREE_ZVAL(key);
			return 0;
		}

		if (Z_TYPE_P(key) != IS_LONG && Z_TYPE_P(key) != IS_STRING) {
			zval_dtor(key);
			FREE_ZVAL(key);
			return 0;
		}

		ALLOC_INIT_ZVAL(data);

		if (!php_var_unserialize2(&data, p, max, var_hash TSRMLS_CC)) {
			zval_dtor(key);
			FREE_ZVAL(key);
			zval_dtor(data);
			FREE_ZVAL(data);
			return 0;
		}

		switch (Z_TYPE_P(key)) {
		case IS_LONG:
            if (objprops) {
                /* show a warning for not compatible */
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "got integer prop. %d", Z_LVAL_P(key));
            }
			if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) {
				var_push_dtor(var_hash, old_data);
			}
			zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL);
			break;
		case IS_STRING:
			if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
				var_push_dtor(var_hash, old_data);
			}
			zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
			break;
		}
		
		
		zval_dtor(key);
		FREE_ZVAL(key);

		if (elements && *(*p-1) != ';' && *(*p-1) != '}') {
			(*p)--;
			return 0;
		}
	}

	return 1;
}
int dbx_pgsql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS) {
    /* returns array[0..columncount-1] as strings on success or 0 
	   as long on failure */
    int number_of_arguments=2;
	int save_error_reporting=0;
    zval ** arguments[2];
    zval * zval_row=NULL;
    zval * returned_zval=NULL;
	
    MAKE_STD_ZVAL(zval_row);
    ZVAL_LONG(zval_row, row_number);
    arguments[0]=result_handle;
    arguments[1]=&zval_row;

    if (EG(error_reporting) & E_WARNING){
		save_error_reporting = EG(error_reporting);
		EG(error_reporting) &= ~E_WARNING;
	}
    dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_fetch_array", &returned_zval, number_of_arguments, arguments);
	if (save_error_reporting) {
		EG(error_reporting) = save_error_reporting;
	}
    if (!returned_zval || returned_zval->type!=IS_ARRAY) {
        if (returned_zval) zval_ptr_dtor(&returned_zval);
        FREE_ZVAL(zval_row);
        return 0;
	}
    FREE_ZVAL(zval_row);
    MOVE_RETURNED_TO_RV(rv, returned_zval);
    return 1;
}
Esempio n. 4
0
/** {{{ public ZeRecorder::fetch()
 */
PHP_METHOD(ze_recorder, fetch) {
	zval *   self        = NULL;
	zval *   stmt        = NULL;
	long     style       = 0;
	zval *   style_z     = NULL;
	zval *   success     = NULL;
	zval *   row         = NULL;

	/* PDO::FETCH_ASSOC */
	style   =   2;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l"
							 , &style
							 ) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	/* call execute */
	/* call fetch */

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);

	do {
		if (!stmt || Z_TYPE_P(stmt) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.fetch.stmt.not_object");
			break;
		}

		zend_call_method(&stmt, Z_OBJCE_P(stmt), NULL, ZEND_STRL("execute"), &success, 0, NULL, NULL TSRMLS_CC);

		if (!success || EG(exception)) {
			zval_dtor(success);
			FREE_ZVAL(success);
			break;
		}

		convert_to_boolean(success);

		if (Z_BVAL_P(success) == 1) {
			ALLOC_INIT_ZVAL(style_z);
			ZVAL_LONG(style_z, style);
			zend_call_method(&stmt, NULL, NULL, ZEND_STRL("fetch"), &row, 1, style_z, NULL TSRMLS_CC);
			zval_dtor(style_z);
			FREE_ZVAL(style_z);
		}

		zval_dtor(success);
		FREE_ZVAL(success);

	} while (0);

	if (row) {
		RETURN_ZVAL(row, 1, 1);
	} else {
		RETURN_FALSE;
	}
}
Esempio n. 5
0
int dbx_odbc_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS) {
    /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/
    int number_of_arguments;
    zval ** arguments[2];
    zval * num_fields_zval=NULL;
    zval * fetch_row_result_zval=NULL;
    zval * field_result_zval=NULL;
    zval * field_index_zval;
    zval * returned_zval=NULL;
    long field_index;
    long field_count=-1;

    /*/ get # fields /*/
    MAKE_STD_ZVAL(num_fields_zval);
    ZVAL_LONG(num_fields_zval, 0);
    if (!dbx_odbc_getcolumncount(&num_fields_zval, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU)) {
        return 0;
        }
    field_count=num_fields_zval->value.lval;
    FREE_ZVAL(num_fields_zval);
    /*/ fetch row /*/
    number_of_arguments=1;
    arguments[0]=result_handle;
    dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_fetch_row", &fetch_row_result_zval, number_of_arguments, arguments);
    if (!fetch_row_result_zval || fetch_row_result_zval->type!=IS_BOOL) {
        if (fetch_row_result_zval) zval_ptr_dtor(&fetch_row_result_zval);
        return 0;
        }
    if (fetch_row_result_zval->value.lval==0) {
        (*rv)->type=IS_LONG;
        (*rv)->value.lval=0; /*/ ok, no more rows /*/
        zval_ptr_dtor(&fetch_row_result_zval);
        return 0;
        }
    zval_ptr_dtor(&fetch_row_result_zval);
    /*/ fill array with field results... /*/
    MAKE_STD_ZVAL(returned_zval);
    if (array_init(returned_zval) != SUCCESS) {
        zend_error(E_ERROR, "dbx_odbc_getrow: unable to create result-array...");
        FREE_ZVAL(returned_zval);
        return 0;
        }
    MAKE_STD_ZVAL(field_index_zval);
    ZVAL_LONG(field_index_zval, 0);
    number_of_arguments=2;
    for (field_index=0; field_index<field_count; ++field_index) {
        ZVAL_LONG(field_index_zval, field_index+1);
        arguments[0]=result_handle;
        arguments[1]=&field_index_zval;
        dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_result", &field_result_zval, number_of_arguments, arguments);
        zend_hash_index_update(returned_zval->value.ht, field_index, (void *)&(field_result_zval), sizeof(zval *), NULL);
        }
    FREE_ZVAL(field_index_zval);

    MOVE_RETURNED_TO_RV(rv, returned_zval);
    return 1;
    }
Esempio n. 6
0
static void php_value_free(php_value *pv) {
    if (pv) {
        if (pv->value != NULL) {
            zval_dtor(pv->value);
            FREE_ZVAL(pv->value);
        }
        xfree(pv);
    }
}
Esempio n. 7
0
static PHP_RSHUTDOWN_FUNCTION(protobuf) {
  zend_hash_destroy(upb_def_to_php_obj_map);
  FREE_HASHTABLE(upb_def_to_php_obj_map);

  zend_hash_destroy(ce_to_php_obj_map);
  FREE_HASHTABLE(ce_to_php_obj_map);

  if (generated_pool_php != NULL) {
    zval_dtor(generated_pool_php);
    FREE_ZVAL(generated_pool_php);
  }
}
Esempio n. 8
0
static PHP_FUNCTION(hastur_ia_ia)
{
    zval **params[2];
    char *text;
    int text_len;
    zval *text_zval;
    zval *name_zval;
    zval *handler_zval;
    zval *retval_ptr;
    int i;

    MAKE_STD_ZVAL(handler_zval);
    MAKE_STD_ZVAL(name_zval);
    MAKE_STD_ZVAL(text_zval);
    ZVAL_STRING(handler_zval, handler, 1);
    ZVAL_STRING(name_zval, god_name, 1);
    params[0] = &text_zval;
    params[1] = &name_zval;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &text, &text_len) == FAILURE) {
        RETURN_FALSE;
    }
    ZVAL_STRINGL(text_zval, text, text_len, 1);
    char *ntext = Z_STRVAL_P(text_zval);
    for (i = 0; i < text_len; i++) {
        if (strncmp(ntext + i, "flag", 4) == 0) {
            strncpy(ntext + i, "iaia", 4);
        }
    }

    if (call_user_function_ex(EG(function_table), NULL, handler_zval,
                              &retval_ptr, 2, params, 0, NULL TSRMLS_CC) == SUCCESS) {
        if (retval_ptr) {
            COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
        }
    }

    FREE_ZVAL(handler_zval);
    FREE_ZVAL(name_zval);
}
Esempio n. 9
0
int dbx_odbc_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) {
    /*/ returns column-type as string on success or 0 as long on failure /*/
    int number_of_arguments=2;
    zval ** arguments[2];
    zval * zval_column_index;
    zval * returned_zval=NULL;

    MAKE_STD_ZVAL(zval_column_index);
    ZVAL_LONG(zval_column_index, column_index+1);
    arguments[0]=result_handle;
    arguments[1]=&zval_column_index;
    dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_field_type", &returned_zval, number_of_arguments, arguments);
    /*/ odbc_field_name returns a string /*/
    if (!returned_zval || returned_zval->type!=IS_STRING) {
        if (returned_zval) zval_ptr_dtor(&returned_zval);
        FREE_ZVAL(zval_column_index);
        return 0;
        }
    FREE_ZVAL(zval_column_index);
    MOVE_RETURNED_TO_RV(rv, returned_zval);
    return 1;
    }
Esempio n. 10
0
static void
SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) {
  swig_object_wrapper *value=NULL;
  /*
   * First test for Null pointers.  Return those as PHP native NULL
   */
  if (!ptr ) {
    ZVAL_NULL(z);
    return;
  }
  if (type->clientdata) {
    if (! (*(int *)(type->clientdata)))
      zend_error(E_ERROR, "Type: %s failed to register with zend",type->name);
    value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper));
    value->ptr=ptr;
    value->newobject=newobject;
    if (newobject <= 1) {
      /* Just register the pointer as a resource. */
      ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
    } else {
      /*
       * Wrap the resource in an object, the resource will be accessible
       * via the "_cPtr" member. This is currently only used by
       * directorin typemaps.
       */
      value->newobject = 0;
      zval *resource;
      MAKE_STD_ZVAL(resource);
      ZEND_REGISTER_RESOURCE(resource, value, *(int *)(type->clientdata));
      zend_class_entry **ce = NULL;
      zval *classname;
      MAKE_STD_ZVAL(classname);
      /* _p_Foo -> Foo */
      ZVAL_STRING(classname, (char*)type->name+3, 1);
      /* class names are stored in lowercase */
      php_strtolower(Z_STRVAL_PP(&classname), Z_STRLEN_PP(&classname));
      if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &ce TSRMLS_CC) != SUCCESS) {
        /* class does not exist */
        object_init(z);
      } else {
        object_init_ex(z, *ce);
      }
      Z_SET_REFCOUNT_P(z, 1);
      Z_SET_ISREF_P(z);
      zend_hash_update(HASH_OF(z), (char*)"_cPtr", sizeof("_cPtr"), (void*)&resource, sizeof(zval), NULL);
      FREE_ZVAL(classname);
    }
    return;
  }
  zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
}
Esempio n. 11
0
/* {{{ void seaslog_init_buffer(TSRMLS_D)*/
void seaslog_init_buffer(TSRMLS_D)
{
	if (SEASLOG_G(use_buffer)) {
        if (!SL_globals.started) {
            if (SL_globals.log_buffer) {
                    zval_dtor(SL_globals.log_buffer);
                    FREE_ZVAL(SL_globals.log_buffer);
            }
            MAKE_STD_ZVAL(SL_globals.log_buffer);
            array_init(SL_globals.log_buffer);
            SL_globals.started = 1;
        }
	}
}
Esempio n. 12
0
static double microtime(TSRMLS_D) {
    zval *t;
    zval *func,*return_as_double;
    zval **args[1];
    double dt;

    MAKE_STD_ZVAL(func);
    ZVAL_STRING(func, "microtime", 0);

    MAKE_STD_ZVAL(return_as_double);
    ZVAL_BOOL(return_as_double, 1);
    args[0]=&return_as_double;

    if(call_user_function_ex(EG(function_table), NULL, func, &t, 1, args, 0,NULL TSRMLS_CC) != SUCCESS) {
        dt=0;
    } else {
        dt=Z_DVAL_P(t);
    }
    FREE_ZVAL(func);
    FREE_ZVAL(t);
    FREE_ZVAL(return_as_double);
    return dt;
}
Esempio n. 13
0
VALUE php_value_call(int argc, VALUE *argv, VALUE self) {
    char *is_callable_error;
    zend_fcall_info fci;
    zend_fcall_info_cache fcc;
    zval ***call_args;
    zval **zval_array;
    zval *retval_ptr = NULL;
    int i, call_result;
    VALUE args, retval;

    rb_scan_args(argc, argv, "*", &args);

    if (zend_fcall_info_init(get_zval(self), 0, &fci, &fcc, NULL, &is_callable_error TSRMLS_CC) == FAILURE) {
        VALUE err = rb_str_new2(is_callable_error);
        efree(is_callable_error);
        rb_raise(rb_eRuntimeError, "no callable: %s", err);
    }

    zval_array = (zval**)malloc(sizeof(zval*) * argc);
    call_args = (zval***)malloc(sizeof(zval**) * argc);
    for(i=0; i<argc; ++i) {
        zval_array[i] = value_to_zval(RARRAY_PTR(args)[i]);
        call_args[i] = &zval_array[i];
    }

    fci.retval_ptr_ptr = &retval_ptr;
    fci.param_count = argc;
    fci.params = call_args;

    call_result = zend_call_function(&fci, &fcc TSRMLS_CC);
    retval = new_php_embed_value(retval_ptr);

    free(call_args);

    for(i=0; i<argc-1; ++i) {
        zval_dtor(zval_array[i]);
        FREE_ZVAL(zval_array[i]);
    }
    free(zval_array);

    if (FAILURE == call_result) {
        rb_raise(rb_eRuntimeError, "function call fairure");
    }

    return retval;
}
Esempio n. 14
0
void php_zmq_pollset_clear(php_zmq_pollset *set, zend_bool reinit TSRMLS_DC)
{
	if (set->alloc_size > 0) {
		efree(set->php_items);
		efree(set->items);
	}

	set->items      = NULL;
	set->php_items  = NULL;
	set->alloc_size = 0;

	if (reinit) {
		zval_dtor(set->errors);
		FREE_ZVAL(set->errors);

		php_zmq_pollset_init(set);
	}
}
Esempio n. 15
0
/** {{{ public ZeRecorder::exec()
 */
PHP_METHOD(ze_recorder, exec) {
	zval *   self        = NULL;
	zval *   stmt        = NULL;
	zval *   success     = NULL;
	zval *   row_count    = NULL;

	/* call execute */
	/* call rowCount */

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);

	do {
		if (!stmt || Z_TYPE_P(stmt) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.exec.stmt.not_object");
			break;
		}

		zend_call_method(&stmt, Z_OBJCE_P(stmt), NULL, ZEND_STRL("execute"), &success, 0, NULL, NULL TSRMLS_CC);

		if (!success || EG(exception)) {
			break;
		}

		convert_to_boolean(success);

		if (Z_BVAL_P(success) == 1) {
			zend_call_method(&stmt, NULL, NULL, ZEND_STRL("rowCount"), &row_count, 0, NULL, NULL TSRMLS_CC);
		}

		zval_dtor(success);
		FREE_ZVAL(success);

	} while (0);

	if (row_count) {
		 convert_to_long(row_count);
		 RETURN_ZVAL(row_count, 1, 1);
	} else {
		RETURN_FALSE;
	}

}
Esempio n. 16
0
/** {{{ public ZeRecorder::lastId()
 */
PHP_METHOD(ze_recorder, lastId) {
	zval *   self        = NULL;
	zval *   conn        = NULL;
	char *   name        = NULL;
	int      name_len    = 0;
	zval *   name_z      = NULL;
	zval *   lastid      = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s"
							 , &name, &name_len
							 ) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	/* call lastInsertId */

	self = getThis();

	conn = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_PDO_DBH), 0 TSRMLS_CC);

	do {
		if (!conn || Z_TYPE_P(conn) != IS_OBJECT) {

			ze_error(E_ERROR TSRMLS_CC, "recorder.lastId.conn.not_object");
			break;
		}

		ALLOC_INIT_ZVAL(name_z);
		ZVAL_STRINGL(name_z, name, name_len, 1);
		zend_call_method(&conn, NULL, NULL, ZEND_STRL("lastInsertId"), &lastid, 1, name_z, NULL TSRMLS_CC);
		zval_dtor(name_z);
		FREE_ZVAL(name_z);

	} while (0);


	if (lastid) {
		 convert_to_long(lastid);
		 RETURN_ZVAL(lastid, 1, 1);
	} else {
		RETURN_FALSE;
	}
}
Esempio n. 17
0
VALUE php_value_obj_equal(VALUE self, VALUE rhs) {
    zval *lhs_zv;
    zval *rhs_zv;
    zval *result;
    int cmp_ret;

    lhs_zv = get_zval(self);
    if (lhs_zv == NULL) {
        return Qnil;
    }

    if (cPhpEmbedValue == CLASS_OF(rhs)) {
        rhs_zv = get_zval(rhs);
    } else {
        rhs_zv = value_to_zval(rhs);
    }

    MAKE_STD_ZVAL(result);
    compare_function(result, lhs_zv, rhs_zv TSRMLS_CC);
    cmp_ret = Z_LVAL_P(result);
    FREE_ZVAL(result);

    return cmp_ret == 0 ? Qtrue : Qfalse;
}
Esempio n. 18
0
php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context, int redirect_max, int header_init STREAMS_DC TSRMLS_DC)
{
    php_stream *stream = NULL;
    php_url *resource = NULL;
    int use_ssl;
    char *scratch = NULL;
    char *tmp = NULL;
    char *ua_str = NULL;
    zval **ua_zval = NULL, **tmpzval = NULL;
    int scratch_len = 0;
    int body = 0;
    char location[HTTP_HEADER_BLOCK_SIZE];
    zval **response_header = NULL;
    int reqok = 0;
    char *http_header_line = NULL;
    char tmp_line[128];
    size_t chunk_size = 0, file_size = 0;
    int eol_detect, have_header = 0;

    if (redirect_max < 1) {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Circular redirect, aborting.");
        return NULL;
    }

    if (strpbrk(mode, "aw+")) {
        php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP wrapper does not support writeable connections.");
        return NULL;
    }

    resource = php_url_parse(path);
    if (resource == NULL) {
        return NULL;
    }

    if (strncasecmp(resource->scheme, "http", sizeof("http")) && strncasecmp(resource->scheme, "https", sizeof("https"))) {
        php_url_free(resource);
        return php_stream_open_wrapper_ex(path, mode, ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
    }

    use_ssl = resource->scheme && (strlen(resource->scheme) > 4) && resource->scheme[4] == 's';

    /* choose default ports */
    if (use_ssl && resource->port == 0)
        resource->port = 443;
    else if (resource->port == 0)
        resource->port = 80;

    stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, NULL, 0);
    if (stream == NULL) {
        eol_detect = 0;
        goto out;
    }

    /* avoid problems with auto-detecting when reading the headers -> the headers
     * are always in canonical \r\n format */
    eol_detect = stream->flags & (PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC);
    stream->flags &= ~(PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC);

    php_stream_context_set(stream, context);

    php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0);

#ifdef HAVE_OPENSSL_EXT
    if (use_ssl)	{

        if (context) {
            /* set the CN we expect to be on the remote cert.
             * You still need to have enabled verification (verify_peer) in the context for
             * this to have an effect */
            zval *cn;

            ALLOC_INIT_ZVAL(cn);
            ZVAL_STRING(cn, resource->host, 1);
            php_stream_context_set_option(context, "ssl", "CN_match", cn);
        }

        if (php_stream_sock_ssl_activate(stream, 1) == FAILURE)	{
            php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to activate SSL mode");
            php_stream_close(stream);
            stream = NULL;
            goto out;
        }
    }
#endif

    if (context && php_stream_context_get_option(context, "http", "method", &tmpzval) == SUCCESS) {
        if (Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval) > 0) {
            scratch_len = strlen(path) + 29 + Z_STRLEN_PP(tmpzval);
            scratch = (char *)emalloc(scratch_len);
            strlcpy(scratch, Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval) + 1);
            strcat(scratch, " ");
        }
    }

    if (!scratch) {
        scratch_len = strlen(path) + 32;
        scratch = (char *)emalloc(scratch_len);
        strcpy(scratch, "GET ");
    }

    /* file */
    if (resource->path && *resource->path)
        strlcat(scratch, resource->path, scratch_len);
    else
        strlcat(scratch, "/", scratch_len);

    /* query string */
    if (resource->query)	{
        strlcat(scratch, "?", scratch_len);
        strlcat(scratch, resource->query, scratch_len);
    }

    /* protocol version we are speaking */
    strlcat(scratch, " HTTP/1.0\r\n", scratch_len);

    /* send it */
    php_stream_write(stream, scratch, strlen(scratch));

    if (context && php_stream_context_get_option(context, "http", "header", &tmpzval) == SUCCESS && Z_STRLEN_PP(tmpzval)) {
        /* Remove newlines and spaces from start and end, php_trim will estrndup() */
        tmp = php_trim(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), NULL, 0, NULL, 3 TSRMLS_CC);
        if (strlen(tmp) > 0) {
            /* Output trimmed headers with \r\n at the end */
            php_stream_write(stream, tmp, strlen(tmp));
            php_stream_write(stream, "\r\n", sizeof("\r\n") - 1);

            /* Make lowercase for easy comparison against 'standard' headers */
            php_strtolower(tmp, strlen(tmp));
            if (strstr(tmp, "user-agent:")) {
                have_header |= HTTP_HEADER_USER_AGENT;
            }
            if (strstr(tmp, "host:")) {
                have_header |= HTTP_HEADER_HOST;
            }
            if (strstr(tmp, "from:")) {
                have_header |= HTTP_HEADER_FROM;
            }
            if (strstr(tmp, "authorization:")) {
                have_header |= HTTP_HEADER_AUTH;
            }
        }
        efree(tmp);
    }

    /* auth header if it was specified */
    if (((have_header & HTTP_HEADER_AUTH) == 0) && resource->user && resource->pass) {
        /* decode the strings first */
        php_url_decode(resource->user, strlen(resource->user));
        php_url_decode(resource->pass, strlen(resource->pass));

        /* scratch is large enough, since it was made large enough for the whole URL */
        strcpy(scratch, resource->user);
        strcat(scratch, ":");
        strcat(scratch, resource->pass);

        tmp = (char *)php_base64_encode((unsigned char*)scratch, strlen(scratch), NULL);

        if (snprintf(scratch, scratch_len, "Authorization: Basic %s\r\n", tmp) > 0) {
            php_stream_write(stream, scratch, strlen(scratch));
            php_stream_notify_info(context, PHP_STREAM_NOTIFY_AUTH_REQUIRED, NULL, 0);
        }

        efree(tmp);
        tmp = NULL;
    }

    /* if the user has configured who they are, send a From: line */
    if (((have_header & HTTP_HEADER_FROM) == 0) && cfg_get_string("from", &tmp) == SUCCESS)	{
        if (snprintf(scratch, scratch_len, "From: %s\r\n", tmp) > 0) {
            php_stream_write(stream, scratch, strlen(scratch));
        }
    }

    /* Send Host: header so name-based virtual hosts work */
    if ((have_header & HTTP_HEADER_HOST) == 0) {
        if ((use_ssl && resource->port != 443) || (!use_ssl && resource->port != 80))	{
            if (snprintf(scratch, scratch_len, "Host: %s:%i\r\n", resource->host, resource->port) > 0) {
                php_stream_write(stream, scratch, strlen(scratch));
            }
        } else {
            if (snprintf(scratch, scratch_len, "Host: %s\r\n", resource->host) > 0) {
                php_stream_write(stream, scratch, strlen(scratch));
            }
        }
    }

    if (context &&
            php_stream_context_get_option(context, "http", "user_agent", &ua_zval) == SUCCESS) {
        ua_str = Z_STRVAL_PP(ua_zval);
    } else if (FG(user_agent)) {
        ua_str = FG(user_agent);
    }

    if (ua_str) {
#define _UA_HEADER "User-Agent: %s\r\n"
        char *ua;
        size_t ua_len;

        ua_len = sizeof(_UA_HEADER) + strlen(ua_str);

        /* ensure the header is only sent if user_agent is not blank */
        if (ua_len > sizeof(_UA_HEADER)) {
            ua = (char *)emalloc(ua_len + 1);
            if ((ua_len = snprintf(ua, ua_len, _UA_HEADER, ua_str)) > 0) {
                ua[ua_len] = 0;
                php_stream_write(stream, ua, ua_len);
            } else {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot construct User-agent header");
            }

            if (ua) {
                efree(ua);
            }
        }
    }

    php_stream_write(stream, "\r\n", sizeof("\r\n")-1);

    /* Request content, such as for POST requests */
    if (context && php_stream_context_get_option(context, "http", "content", &tmpzval) == SUCCESS && Z_STRLEN_PP(tmpzval) > 0) {
        php_stream_write(stream, Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval));
        php_stream_write(stream, "\r\n\r\n", sizeof("\r\n\r\n")-1);
    }

    location[0] = '\0';

    /*
     * We need to read the HTTP response header one-by-one, because
     * the original author did not know about MSG_PEEK.
     * The chunk_size will be reset later, once we have read the
     * header completely.
     */
    if (options & STREAM_WILL_CAST)
        chunk_size = php_stream_set_chunk_size(stream, 1);

    if (!header_init && FAILURE == zend_hash_find(EG(active_symbol_table),
            "http_response_header", sizeof("http_response_header"), (void **) &response_header)) {
        header_init = 1;
    }

    if (header_init) {
        zval *tmp;
        MAKE_STD_ZVAL(tmp);
        array_init(tmp);
        ZEND_SET_SYMBOL(EG(active_symbol_table), "http_response_header", tmp);

        zend_hash_find(EG(active_symbol_table),
                       "http_response_header", sizeof("http_response_header"), (void **) &response_header);
    }


    if (!php_stream_eof(stream)) {
        size_t tmp_line_len;
        /* get response header */

        if (_php_stream_get_line(stream, tmp_line, sizeof(tmp_line) - 1, &tmp_line_len TSRMLS_CC) != NULL) {
            zval *http_response;
            int response_code;

            MAKE_STD_ZVAL(http_response);
            ZVAL_NULL(http_response);

            if (tmp_line_len > 9) {
                response_code = atoi(tmp_line + 9);
            } else {
                response_code = 0;
            }
            switch(response_code) {
            case 200:
            case 302:
            case 301:
                reqok = 1;
                break;
            case 403:
                php_stream_notify_error(context, PHP_STREAM_NOTIFY_AUTH_RESULT,
                                        tmp_line, response_code);
                break;
            default:
                /* safety net in the event tmp_line == NULL */
                if (!tmp_line_len) {
                    tmp_line[0] = '\0';
                }
                php_stream_notify_error(context, PHP_STREAM_NOTIFY_FAILURE,
                                        tmp_line, response_code);
            }

            Z_STRLEN_P(http_response) = tmp_line_len;
            Z_STRVAL_P(http_response) = estrndup(tmp_line, Z_STRLEN_P(http_response));
            if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\n') {
                Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0;
                Z_STRLEN_P(http_response)--;
                if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\r') {
                    Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0;
                    Z_STRLEN_P(http_response)--;
                }
            }
            Z_TYPE_P(http_response) = IS_STRING;
            zend_hash_next_index_insert(Z_ARRVAL_PP(response_header), &http_response, sizeof(zval *), NULL);
        }
    } else {
        php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP request failed, unexpected end of socket!");
        goto out;
    }

    /* read past HTTP headers */

    http_header_line = (char *)emalloc(HTTP_HEADER_BLOCK_SIZE);

    while (!body && !php_stream_eof(stream))	{

        if (php_stream_gets(stream, http_header_line, HTTP_HEADER_BLOCK_SIZE-1) != NULL)	{
            char *p;
            int found_eol = 0;
            int http_header_line_length;

            http_header_line[HTTP_HEADER_BLOCK_SIZE-1] = '\0';

            p = http_header_line;
            while(*p) {
                while(*p == '\n' || *p == '\r')	{
                    *p = '\0';
                    p--;
                    found_eol = 1;
                }
                if (found_eol)
                    break;
                p++;
            }
            http_header_line_length = p-http_header_line+1;

            if (!strncasecmp(http_header_line, "Location: ", 10)) {
                strlcpy(location, http_header_line + 10, sizeof(location));
            } else if (!strncasecmp(http_header_line, "Content-Type: ", 14)) {
                php_stream_notify_info(context, PHP_STREAM_NOTIFY_MIME_TYPE_IS, http_header_line + 14, 0);
            } else if (!strncasecmp(http_header_line, "Content-Length: ", 16)) {
                file_size = atoi(http_header_line + 16);
                php_stream_notify_file_size(context, file_size, http_header_line, 0);
            }

            if (http_header_line[0] == '\0') {
                body = 1;
            } else {
                zval *http_header;

                MAKE_STD_ZVAL(http_header);

                ZVAL_STRINGL(http_header, http_header_line, http_header_line_length, 1);

                zend_hash_next_index_insert(Z_ARRVAL_PP(response_header), &http_header, sizeof(zval *), NULL);
            }
        } else {
            break;
        }
    }

    if (!reqok || location[0] != '\0')	{
        if (location[0] != '\0')
            php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0);

        php_stream_close(stream);
        stream = NULL;

        if (location[0] != '\0')	{

            zval *entry, **entryp;
            char new_path[HTTP_HEADER_BLOCK_SIZE];
            char loc_path[HTTP_HEADER_BLOCK_SIZE];

            *new_path='\0';
            if (strlen(location)<8 || (strncasecmp(location, "http://", sizeof("http://")-1) &&
                                       strncasecmp(location, "https://", sizeof("https://")-1) &&
                                       strncasecmp(location, "ftp://", sizeof("ftp://")-1) &&
                                       strncasecmp(location, "ftps://", sizeof("ftps://")-1)))
            {
                if (*location != '/') {
                    if (*(location+1) != '\0' && resource->path) {
                        char *s = strrchr(resource->path, '/');
                        if (!s) {
                            s = resource->path;
                            if (!s[0]) {
                                efree(s);
                                s = resource->path = estrdup("/");
                            } else {
                                *s = '/';
                            }
                        }
                        s[1] = '\0';
                        if (resource->path && *(resource->path) == '/' && *(resource->path + 1) == '\0') {
                            snprintf(loc_path, sizeof(loc_path) - 1, "%s%s", resource->path, location);
                        } else {
                            snprintf(loc_path, sizeof(loc_path) - 1, "%s/%s", resource->path, location);
                        }
                    } else {
                        snprintf(loc_path, sizeof(loc_path) - 1, "/%s", location);
                    }
                } else {
                    strlcpy(loc_path, location, sizeof(loc_path));
                }
                if ((use_ssl && resource->port != 443) || (!use_ssl && resource->port != 80)) {
                    snprintf(new_path, sizeof(new_path) - 1, "%s://%s:%d%s", resource->scheme, resource->host, resource->port, loc_path);
                } else {
                    snprintf(new_path, sizeof(new_path) - 1, "%s://%s%s", resource->scheme, resource->host, loc_path);
                }
            } else {
                strlcpy(new_path, location, sizeof(new_path));
            }
            stream = php_stream_url_wrap_http_ex(NULL, new_path, mode, options, opened_path, context, --redirect_max, 0 STREAMS_CC TSRMLS_CC);
            if (stream && stream->wrapperdata)	{
                entryp = &entry;
                MAKE_STD_ZVAL(entry);
                ZVAL_EMPTY_STRING(entry);
                zend_hash_next_index_insert(Z_ARRVAL_PP(response_header), entryp, sizeof(zval *), NULL);
                zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream->wrapperdata));
                while (zend_hash_get_current_data(Z_ARRVAL_P(stream->wrapperdata), (void **)&entryp) == SUCCESS) {
                    zval_add_ref(entryp);
                    zend_hash_next_index_insert(Z_ARRVAL_PP(response_header), entryp, sizeof(zval *), NULL);
                    zend_hash_move_forward(Z_ARRVAL_P(stream->wrapperdata));
                }
                zval_dtor(stream->wrapperdata);
                FREE_ZVAL(stream->wrapperdata);
            }
        } else {
            php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP request failed! %s", tmp_line);
        }
    }
out:
    if (http_header_line)
        efree(http_header_line);
    if (scratch)
        efree(scratch);
    php_url_free(resource);

    if (stream) {
        if (header_init) {
            stream->wrapperdata = *response_header;
            zval_add_ref(response_header);
        }
        php_stream_notify_progress_init(context, 0, file_size);
        /* Restore original chunk size now that we're done with headers (if applicable) */
        if (options & STREAM_WILL_CAST)
            php_stream_set_chunk_size(stream, chunk_size);

        /* restore the users auto-detect-line-endings setting */
        stream->flags |= eol_detect;

        /* as far as streams are concerned, we are now at the start of
         * the stream */
        stream->position = 0;
    }

    return stream;
}
Esempio n. 19
0
 //@todo
PHP_METHOD(ze_recorder, bind) {
	zval *   self                = NULL;
	zval *   stmt                = NULL;
	zval *   fields              = NULL;
	zval *   types               = NULL;
	HashTable * keys_table       = NULL;
	HashPosition keys_pointer    = NULL;
	HashTable * fields_table     = NULL;
	HashTable * types_table      = NULL;
	zval ** val                  = NULL;
	zval *  val_copy             = NULL;
	zval ** type                 = NULL;
	zval *  type_copy            = NULL;
	zval *  keys                 = NULL;
	zval ** key                  = NULL;
	int     pos                  = 0;
	zval *  pos_z                = NULL;
	zval ** params[3];

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z"
							, &fields
							, &types
							) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	if (Z_TYPE_P(fields) == IS_OBJECT && Z_OBJ_HT_P(fields)->get_properties != NULL) {
		fields_table = Z_OBJ_HT_P(fields)->get_properties(fields TSRMLS_CC);

	} else if (Z_TYPE_P(fields) == IS_ARRAY) {
		fields_table   = Z_ARRVAL_P(fields);
	}

	if (!fields_table) {
		/* need array or object for '$fields' . */
		ze_error(E_ERROR TSRMLS_CC, "recorder.bind.fields.type");
		return;
	}

	if (types) {
		if (Z_TYPE_P(fields) == IS_OBJECT && Z_OBJ_HT_P(types)->get_properties != NULL) {
			types_table = Z_OBJ_HT_P(types)->get_properties(types TSRMLS_CC);

		} else if (Z_TYPE_P(fields) == IS_ARRAY) {
			types_table    = Z_ARRVAL_P(types);

		}

		if (!types_table){
			/* need array or object for '$types' . */
			ze_error(E_ERROR TSRMLS_CC, "recorder.bind.types.type");
			return;
		}
	}

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);
	keys = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_KEYS), 0 TSRMLS_CC);

	do {

		if (!stmt || Z_TYPE_P(stmt) != IS_OBJECT) {
			 ze_error(E_ERROR TSRMLS_CC, "recorder.bind.stmt.null");
			 break;
		}

		if (!keys || Z_TYPE_P(keys) != IS_ARRAY) {
			 ze_error(E_ERROR TSRMLS_CC, "recorder.bind.keys.is_array");
			 break;
		}

		keys_table = Z_ARRVAL_P(keys);
		pos = 0;

		for (zend_hash_internal_pointer_reset_ex(keys_table, &keys_pointer);
				zend_hash_get_current_data_ex(keys_table,(void**) &key, &keys_pointer) == SUCCESS;
				zend_hash_move_forward_ex(keys_table, &keys_pointer)) {

			if (zend_hash_find(fields_table, Z_STRVAL_PP(key), Z_STRLEN_PP(key) + 1, (void **) &val) == SUCCESS) {
				pos++;
				ALLOC_INIT_ZVAL(pos_z);
				ZVAL_LONG(pos_z, pos);

				val_copy = *val;
				zval_copy_ctor(val_copy);

				if (types_table
					&& zend_hash_find(types_table, Z_STRVAL_PP(key), Z_STRLEN_PP(key) + 1, (void **) &type)  == SUCCESS) {

					type_copy = *type;
					zval_copy_ctor(type_copy);

					params[0] = &pos_z;
					params[1] = &val_copy;
					params[2] = &type_copy;

					ze_call_method(&stmt, NULL, NULL, ZEND_STRL("bindValue"), NULL, 3, params TSRMLS_CC);

				}else{
					zend_call_method(&stmt, NULL, NULL, ZEND_STRL("bindValue"), NULL, 2, pos_z, val_copy TSRMLS_CC);
				}

				zval_dtor(pos_z);
				FREE_ZVAL(pos_z);
			}
		}
	} while (0);

	RETURN_ZVAL(self, 1, 0);
}
Esempio n. 20
0
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops)
{
	while (elements-- > 0) {
		zval *key, *data, **old_data;

		ALLOC_INIT_ZVAL(key);

		if (!php_var_unserialize(&key, p, max, NULL TSRMLS_CC)) {
			zval_dtor(key);
			FREE_ZVAL(key);
			return 0;
		}

		if (Z_TYPE_P(key) != IS_LONG && Z_TYPE_P(key) != IS_STRING) {
			zval_dtor(key);
			FREE_ZVAL(key);
			return 0;
		}

		ALLOC_INIT_ZVAL(data);

		if (!php_var_unserialize(&data, p, max, var_hash TSRMLS_CC)) {
			zval_dtor(key);
			FREE_ZVAL(key);
			zval_dtor(data);
			FREE_ZVAL(data);
			return 0;
		}

		if (!objprops) {
			switch (Z_TYPE_P(key)) {
			case IS_LONG:
				if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) {
					var_push_dtor(var_hash, old_data);
				}
				zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL);
				break;
			case IS_STRING:
				if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
					var_push_dtor(var_hash, old_data);
				}
				zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
				break;
			}
		} else {
			/* object properties should include no integers */
			convert_to_string(key);
			zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
					sizeof data, NULL);
		}
		
		zval_dtor(key);
		FREE_ZVAL(key);

		if (elements && *(*p-1) != ';' && *(*p-1) != '}') {
			(*p)--;
			return 0;
		}
	}

	return 1;
}
Esempio n. 21
0
/** {{{ public ZeStatus::getBrief()
 */
PHP_METHOD(ze_status, getBrief) {
	zval *  self      = NULL;
	zval *  brief     = NULL;
	zval *  name_z    = NULL;
	char *  name      = NULL;
	int     name_len  = 0;
	zval ** msg_pp    = NULL;
	zval *  msg_p     = NULL;
	zval *  msg       = NULL;
	zval *  is_debug  = NULL;
	char *  debug_msg = NULL;
	int     len       = 0;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s"
							, &name, &name_len
							) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	self = getThis();

	brief = zend_read_property(ze_status_ce, self, ZEND_STRL(ZE_BRIEF), 1 TSRMLS_CC);
	
	if (!brief) {
		RETURN_NULL();
	}

	do {
		if (Z_TYPE_P(brief) == IS_ARRAY && name_len) {
			if (zend_hash_find(Z_ARRVAL_P(brief), name, name_len + 1, (void **) &msg_pp) == SUCCESS) {
				ALLOC_INIT_ZVAL(msg);
				*msg = **msg_pp;
				break;
			}
		} else if (Z_TYPE_P(brief) == IS_OBJECT && name_len) {
			msg_p = zend_read_property(Z_OBJCE_P(brief), brief, name, name_len , 1 TSRMLS_CC);
			ALLOC_INIT_ZVAL(msg);
			*msg = *msg_p;
			break;
		} else if (Z_TYPE_P(brief) == IS_STRING) {
			ALLOC_INIT_ZVAL(msg);
			*msg = *brief;
			break;
		}

	} while(0);

	if (!msg) {
		RETURN_NULL();
	}
	
	zval_copy_ctor(msg);
	
	ALLOC_INIT_ZVAL(is_debug);
	if (zend_get_constant(ZEND_STRL(ZE_DEBUG), is_debug TSRMLS_CC)) {
		convert_to_boolean(is_debug);
		name_z = zend_read_property(ze_status_ce, self, ZEND_STRL(ZE_NAME), 0 TSRMLS_CC);

		if (Z_BVAL_P(is_debug) && Z_TYPE_P(name_z) == IS_STRING) {
			len = spprintf(&debug_msg, len, "[%s]%s", Z_STRVAL_P(name_z), Z_STRVAL_P(msg));
			zval_dtor(msg);
			FREE_ZVAL(msg);
			ALLOC_INIT_ZVAL(msg);
			ZVAL_STRINGL(msg, debug_msg, len, 1);
			efree(debug_msg);
		}
	}
	FREE_ZVAL(is_debug);
	
	RETURN_ZVAL(msg, 1, 1);
}
Esempio n. 22
0
void php_handler(struct network *net, struct trigger *trig, struct irc_data *data, struct dcc_session *dcc, const char *dccbuf)
{
	zval *func;
	zval *netw;
	zval *nick;
	zval *uhost;
	zval *hand;
	zval *chan;
	zval *arg;
	zval *ret;
	zval *idx;
	zval *php_args[10]; /* may need changed */
#ifdef WANT_PHP_OBJECT_TRIGGERS
	zend_object *network;
	zend_object *irc_data;
	zend_object *trigger;
#endif /* WANT_PHP_OBJECT_TRIGGERS */

	/* We have to create the arguments for the called function as zvals */
	TSRMLS_FETCH();

	switch (trig->type)
	{
#ifdef WANT_PHP_OBJECT_TRIGGERS
		case TRIG_OPUB:
			/* Create stdClass objects */
			zend_object_std_init(&network,  class_type TSRMLS_CC);
			zend_object_std_init(&irc_data, class_type TSRMLS_CC);
			zend_object_std_init(&trigger,  class_type TSRMLS_CC);
			
			/* Give them default properties */
			zend_hash_copy(network.properties,  &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
			zend_hash_copy(irc_data.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
			zend_hash_copy(trigger.properties,  &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
			break;
#endif /* WANT_PHP_OBJECT_TRIGGERS */
		case TRIG_PUB:
			MAKE_STD_ZVAL(func);
			MAKE_STD_ZVAL(netw);
			MAKE_STD_ZVAL(nick);
			MAKE_STD_ZVAL(uhost);
			MAKE_STD_ZVAL(hand);
			MAKE_STD_ZVAL(chan);
			MAKE_STD_ZVAL(arg);

			ALLOC_INIT_ZVAL(ret);

			ZVAL_STRING(func, trig->command, 1);
			ZVAL_STRING(netw, net->label, 1);
			ZVAL_STRING(nick, data->prefix->nick, 1);
			ZVAL_STRING(uhost, data->prefix->host, 1);

			ZVAL_STRING(hand, "*", 1);
			ZVAL_STRING(chan, data->c_params[0], 1);
			ZVAL_STRING(arg, troll_makearg(data->rest_str,trig->mask), 1);

			php_args[0] = netw;
			php_args[1] = nick;
			php_args[2] = uhost;
			php_args[3] = hand;
			php_args[4] = chan;
			php_args[5] = arg;

			zend_try
			{
				if (call_user_function(CG(function_table), NULL, func, ret, 6, php_args TSRMLS_CC) != SUCCESS)
					troll_debug(LOG_WARN,"Error calling function\n");
				else
					FREE_ZVAL(ret);     
			} zend_end_try();

			/*if (netw)  FREE_ZVAL(netw);
				if (nick)  FREE_ZVAL(nick);
				if (uhost) FREE_ZVAL(uhost);
				if (hand)  FREE_ZVAL(hand);
				if (chan)  FREE_ZVAL(chan);
				if (arg)   FREE_ZVAL(arg);*/

			break;
		case TRIG_PUBM:
			MAKE_STD_ZVAL(func);
			MAKE_STD_ZVAL(netw);
			MAKE_STD_ZVAL(nick);
			MAKE_STD_ZVAL(uhost);
			MAKE_STD_ZVAL(hand);
			MAKE_STD_ZVAL(chan);
			MAKE_STD_ZVAL(arg);

			ALLOC_INIT_ZVAL(ret);

			ZVAL_STRING(func, trig->command, 1);
			ZVAL_STRING(netw, net->label, 1);
			ZVAL_STRING(nick, data->prefix->nick, 1);
			ZVAL_STRING(uhost, data->prefix->host, 1);
			ZVAL_STRING(hand, "*", 1);
			ZVAL_STRING(chan, data->c_params[0], 1);
			ZVAL_STRING(arg, data->rest_str, 1);

			php_args[0] = netw;
			php_args[1] = nick;
			php_args[2] = uhost;
			php_args[3] = hand;
			php_args[4] = chan;
			php_args[5] = arg;

			zend_try
			{
				if (call_user_function(CG(function_table), NULL, func, ret, 6, php_args TSRMLS_CC) != SUCCESS)
					troll_debug(LOG_WARN,"Error calling function\n");
				else
					FREE_ZVAL(ret);
			} zend_end_try();

			/* if (netw)  FREE_ZVAL(netw);
				 if (nick)  FREE_ZVAL(nick);
				 if (uhost) FREE_ZVAL(uhost);
				 if (hand)  FREE_ZVAL(hand);
				 if (chan)  FREE_ZVAL(chan);
				 if (arg)   FREE_ZVAL(arg); */

			break;
		case TRIG_MSG:
			MAKE_STD_ZVAL(func);
			MAKE_STD_ZVAL(netw);
			MAKE_STD_ZVAL(nick);
			MAKE_STD_ZVAL(uhost);
			MAKE_STD_ZVAL(hand);
			MAKE_STD_ZVAL(arg);

			ALLOC_INIT_ZVAL(ret);

			ZVAL_STRING(func, trig->command, 1);
			ZVAL_STRING(netw, net->label, 1);
			ZVAL_STRING(nick, data->prefix->nick, 1);
			ZVAL_STRING(uhost, data->prefix->host, 1);
			ZVAL_STRING(hand, "*", 1);
			ZVAL_STRING(arg, troll_makearg(data->rest_str,trig->mask), 1);

			php_args[0] = netw;
			php_args[1] = nick;
			php_args[2] = uhost;
			php_args[3] = hand;
			php_args[4] = arg;

			if (call_user_function(CG(function_table), NULL, func, ret, 5, php_args TSRMLS_CC) != SUCCESS)
				troll_debug(LOG_WARN,"Error calling function\n");
			else
				FREE_ZVAL(ret);

			/* if (netw)  FREE_ZVAL(netw);
				 if (nick)  FREE_ZVAL(nick);
				 if (uhost) FREE_ZVAL(uhost);
				 if (hand)  FREE_ZVAL(hand);
				 if (arg)   FREE_ZVAL(arg); */

			break;
		case TRIG_TOPC:
			MAKE_STD_ZVAL(func);
			MAKE_STD_ZVAL(netw);
			MAKE_STD_ZVAL(nick);
			MAKE_STD_ZVAL(uhost);
			MAKE_STD_ZVAL(hand);
			MAKE_STD_ZVAL(arg);

			ALLOC_INIT_ZVAL(ret);

			ZVAL_STRING(func, trig->command, 1);
			ZVAL_STRING(netw, net->label, 1);
			ZVAL_STRING(nick, data->prefix->nick, 1);
			ZVAL_STRING(uhost, data->prefix->host, 1);
			ZVAL_STRING(hand, "*", 1);
			ZVAL_STRING(arg, data->rest_str, 1);

			php_args[0] = netw;
			php_args[1] = nick;
			php_args[2] = uhost;
			php_args[3] = hand;
			php_args[4] = arg;

			if (call_user_function(CG(function_table), NULL, func, ret, 5, php_args TSRMLS_CC) != SUCCESS)
				troll_debug(LOG_WARN,"Error calling function\n");
			else
				FREE_ZVAL(ret);

			/* if (netw)  FREE_ZVAL(netw);
				 if (nick)  FREE_ZVAL(nick);
				 if (uhost) FREE_ZVAL(uhost);
				 if (hand)  FREE_ZVAL(hand);
				 if (arg)   FREE_ZVAL(arg); */

			break;

		case TRIG_MSGM:
			MAKE_STD_ZVAL(func);
			MAKE_STD_ZVAL(netw);
			MAKE_STD_ZVAL(nick);
			MAKE_STD_ZVAL(uhost);
			MAKE_STD_ZVAL(hand);
			MAKE_STD_ZVAL(arg);

			ALLOC_INIT_ZVAL(ret);

			ZVAL_STRING(func, trig->command, 1);
			ZVAL_STRING(netw, net->label, 1);
			ZVAL_STRING(nick, data->prefix->nick, 1);
			ZVAL_STRING(uhost, data->prefix->host, 1);
			ZVAL_STRING(hand, "*", 1);
			ZVAL_STRING(arg, data->rest_str, 1);

			php_args[0] = netw;
			php_args[1] = nick;
			php_args[2] = uhost;
			php_args[3] = hand;
			php_args[4] = arg;

			if (call_user_function(CG(function_table), NULL, func, ret, 5, php_args TSRMLS_CC) != SUCCESS)
				troll_debug(LOG_WARN,"Error calling function\n");
			else
				FREE_ZVAL(ret);

			/* if (netw)  FREE_ZVAL(netw);
				 if (nick)  FREE_ZVAL(nick);
				 if (uhost) FREE_ZVAL(uhost);
				 if (hand)  FREE_ZVAL(hand);
				 if (arg)   FREE_ZVAL(arg); */

			break;
		case TRIG_JOIN:
			break;
		case TRIG_PART:
			break;
		case TRIG_SIGN:
			break;
		case TRIG_DCC:
			/* $net, $handle, $idx, $text */
			MAKE_STD_ZVAL(func);
			MAKE_STD_ZVAL(netw);
			MAKE_STD_ZVAL(hand);
			MAKE_STD_ZVAL(idx);
			MAKE_STD_ZVAL(arg);

			ALLOC_INIT_ZVAL(ret);      

			ZVAL_STRING(func, trig->command, 1);
			ZVAL_STRING(netw, dcc->net->label, 1);
			ZVAL_STRING(hand, dcc->user->username, 1);
			ZVAL_LONG(idx, dcc->id);
			ZVAL_STRING(arg, dccbuf, 1);

			php_args[0] = hand;
			php_args[1] = netw;
			php_args[2] = idx;
			php_args[3] = arg;

			if (call_user_function(CG(function_table), NULL, func, ret, 4, php_args TSRMLS_CC) != SUCCESS)
				troll_debug(LOG_WARN,"Error calling function\n");
			else
				FREE_ZVAL(ret);

			/*if (hand)  FREE_ZVAL(hand);
				if (idx)   FREE_ZVAL(idx);
				if (arg)   FREE_ZVAL(arg);*/

			break;
	}
}
Esempio n. 23
0
zval *value_to_zval(VALUE v) {
    zval *zv;
    MAKE_STD_ZVAL(zv);

    switch (TYPE(v)) {
        case T_FALSE:
            ZVAL_FALSE(zv);
            return zv;
        case T_TRUE:
            ZVAL_TRUE(zv);
            return zv;
        case T_UNDEF:
        case T_NIL:
            ZVAL_NULL(zv);
            return zv;
        case T_FIXNUM:
            ZVAL_LONG(zv, rb_fix2int(v));
            return zv;
        case T_BIGNUM:
            ZVAL_LONG(zv, rb_big2long(v)); // FIXME: bignum over long
            return zv;
        case T_FLOAT:
            ZVAL_DOUBLE(zv, RFLOAT_VALUE(v));
            return zv;
        case T_ARRAY:
            {
                int i;
                array_init(zv);
                for(i=0;i<RARRAY_LEN(v);++i) {
                    zval *add = value_to_zval(RARRAY_PTR(v)[i]);
                    zend_hash_next_index_insert(Z_ARRVAL_P(zv), &add, sizeof(zval *), NULL);
                }
                return zv;
            }
        case T_HASH:
            {
                array_init(zv);
                rb_hash_foreach(v, hash_to_zval, (VALUE)zv);
                return zv;
            }
        case T_SYMBOL:
            {
                VALUE symbol_str = rb_sym_to_s(v);
                ZVAL_STRINGL(zv, StringValuePtr(symbol_str), RSTRING_LEN(symbol_str), 1);
                return zv;
            }
        case T_STRING:
            {
                ZVAL_STRINGL(zv, StringValuePtr(v), RSTRING_LEN(v), 1);
                return zv;
            }
        default:
            {
                if (CLASS_OF(v) == cPhpEmbedValue) {
                    php_value* pv;
                    Data_Get_Struct(v, php_value, pv);
                    MAKE_COPY_ZVAL(&pv->value, zv);
                    return zv;
                }
            }
            FREE_ZVAL(zv);
            rb_raise(rb_eRuntimeError, "no implemented");
    }
}
Esempio n. 24
0
File: jam.c Progetto: brzuchal/jam
/* event must be initialized with MAKE_STD_ZVAL or similar and array_init before sending here */
void php_jam_capture_error_ex(zval *event, int type, const char *error_filename, const uint error_lineno, zend_bool free_event, const char *format, va_list args TSRMLS_DC)
{
	zval **ppzval;
	va_list args_cp;
	int len;
	char *buffer;
	char uuid_str[PHP_JAM_UUID_LEN + 1];
	
	TSRMLS_FETCH();
	
	/* Generate unique identifier */
	if (!php_jam_generate_uuid(uuid_str)) {
		php_jam_original_error_cb(E_WARNING TSRMLS_CC, "Failed to generate uuid");
		return;
	}

	/* Capture superglobals */
	if (JAM_G(log_get)) {
		_add_assoc_zval_helper(event, "_GET", sizeof("_GET") TSRMLS_CC);
	}
	
	if (JAM_G(log_post)) {
		_add_assoc_zval_helper(event, "_POST", sizeof("_POST") TSRMLS_CC);
	}
	
	if (JAM_G(log_cookie)) {
		_add_assoc_zval_helper(event, "_COOKIE", sizeof("_COOKIE") TSRMLS_CC);
	}
	
	if (JAM_G(log_session)) {
		_add_assoc_zval_helper(event, "_SESSION", sizeof("_SESSION") TSRMLS_CC);
	}
	
	if (JAM_G(log_server)) {
		_add_assoc_zval_helper(event, "_SERVER", sizeof("_SERVER") TSRMLS_CC);
	}
	
	if (JAM_G(log_env)) {
		_add_assoc_zval_helper(event, "_ENV", sizeof("_ENV") TSRMLS_CC);
	}
	
	if (JAM_G(log_files)) {
		_add_assoc_zval_helper(event, "_FILES", sizeof("_FILES") TSRMLS_CC);
	}
	
	/* Capture backtrace */
	if (JAM_G(log_backtrace)) {
		zval *btrace;
		ALLOC_INIT_ZVAL(btrace);
#if PHP_API_VERSION <= PHP_5_3_X_API_NO
		zend_fetch_debug_backtrace(btrace, 0, 0 TSRMLS_CC);
#else
// TODO: introduce a directive for the amount of stack frames returned instead of hard coded 1000?
		zend_fetch_debug_backtrace(btrace, 0, 0 TSRMLS_CC,1000);
#endif
		add_assoc_zval(event, "backtrace", btrace);
	}
	
	va_copy(args_cp, args);
	len = vspprintf(&buffer, PG(log_errors_max_len), format, args_cp);
	va_end(args_cp);

	add_assoc_string(event,	"error_message", buffer, 0);
	add_assoc_string(event,	"filename",	(char *)error_filename, 1);
	
	add_assoc_long(event, "line_number", error_lineno);
	add_assoc_long(event, "error_type", type);
	
	/*
		Set the last logged uuid into _SERVER
	*/
	add_assoc_string(event, "jam_event_uuid", uuid_str, 1);
	add_assoc_long(event, "jam_event_time", time(NULL));

	/*
		Set the last logged uuid into _SERVER
	*/
	if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &ppzval) == SUCCESS) {
		add_assoc_string(*ppzval, "jam_last_uuid", uuid_str, 1);
	}

	/* Send to backend */
	php_jam_storage_store_all(uuid_str, event, type, error_filename, error_lineno TSRMLS_CC);
	
	if (free_event) {
		zval_dtor(event);
		FREE_ZVAL(event);
	}
}
Esempio n. 25
0
/** {{{ public ZeRecorder::getInt()
 */
PHP_METHOD(ze_recorder, getInt) {
	zval *   self        = NULL;
	zval *   stmt        = NULL;
	zval *   success     = NULL;
	zval *   row         = NULL;
	long     style       = 0;
	zval *   style_z     = NULL;
	long     count       = 0;
	zval **  count_z     = NULL;


	/* PDO::FETCH_NUM */
	style   =   3;

	/* call execute */
	/* call fetch */

	self = getThis();

	stmt = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), 0 TSRMLS_CC);
	do {
		if (!stmt) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.fetch.stmt.null");
			break;
		}

		if (Z_TYPE_P(stmt) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.fetch.stmt.not_object");
			break;
		}

		zend_call_method(&stmt, Z_OBJCE_P(stmt), NULL, ZEND_STRL("execute"), &success, 0, NULL, NULL TSRMLS_CC);

		if (!success || EG(exception)) {
			break;
		}

		convert_to_boolean(success);

		if (Z_BVAL_P(success) == 1) {
			ALLOC_INIT_ZVAL(style_z);
			ZVAL_LONG(style_z, style);
			zend_call_method(&stmt, NULL, NULL, ZEND_STRL("fetch"), &row, 1, style_z, NULL TSRMLS_CC);
			zval_dtor(style_z);
			FREE_ZVAL(style_z);
		}

		zval_dtor(success);
		FREE_ZVAL(success);

		if (!row) {
			break;
		}

		if (Z_TYPE_P(row) == IS_ARRAY
				&& zend_hash_has_more_elements(Z_ARRVAL_P(row)) == SUCCESS
				&& zend_hash_get_current_data(Z_ARRVAL_P(row), (void **) &count_z) == SUCCESS) {

				convert_to_long_ex(count_z);
				count = Z_LVAL_PP(count_z);

				zval_dtor(*count_z);
				FREE_ZVAL(*count_z);
			}

		zval_dtor(row);
		FREE_ZVAL(row);
	} while (0);

	RETURN_LONG(count);
}
Esempio n. 26
0
/* {{{ writes a property to a thread in the appropriate way */
void pthreads_write_property(PTHREADS_WRITE_PROPERTY_PASSTHRU_D) {
	PTHREAD pthreads = PTHREADS_FETCH_FROM(object);
	zval *mstring = NULL;
	zend_bool nulled = 0;
	zend_bool locked;
	
	if (member == NULL || Z_TYPE_P(member) == IS_NULL) {
	    /* for anonymous members, 
	        we acquire the lock and increment a counter
	        we do not store any additional information or perform any lookups */
		pthreads_lock_acquire(pthreads->store->lock, &locked TSRMLS_CC);
		{
			if (member == NULL) {
			    MAKE_STD_ZVAL(member);
			    
			    nulled = 1;
			}
			
			ZVAL_LONG(member, pthreads->store->next++);
		}
		pthreads_lock_release(pthreads->store->lock, locked TSRMLS_CC);
	}

	if (Z_TYPE_P(member) != IS_STRING) {
		ALLOC_ZVAL(mstring);
		*mstring = *member;
		zval_copy_ctor(
			mstring
		);
		INIT_PZVAL(mstring);
		convert_to_string(mstring);
		if(nulled) 
			FREE_ZVAL(member);
		member = mstring;
#if PHP_VERSION_ID > 50399
		key = NULL;
#endif
	}

	if (Z_TYPE_P(member)==IS_STRING) {
		switch(Z_TYPE_P(value)){
			case IS_STRING:
			case IS_LONG:
			case IS_ARRAY:
			case IS_OBJECT:
			case IS_NULL:
			case IS_DOUBLE:
			case IS_RESOURCE:
			case IS_BOOL: {
				if (pthreads_store_write(pthreads->store, Z_STRVAL_P(member), Z_STRLEN_P(member), &value TSRMLS_CC)!=SUCCESS){
					zend_error(
						E_WARNING, 
						"pthreads failed to write member %s::$%s", 
						Z_OBJCE_P(object)->name, Z_STRVAL_P(member)
					);
				}
			} break;
			
			default: {
				zend_error(
					E_WARNING, 
					"pthreads detected an attempt to use an unsupported kind of data for %s::$%s", 
					Z_OBJCE_P(object)->name, Z_STRVAL_P(member)
				);
			}
		}
	} else zend_error(
		E_WARNING,
		"pthreads detected an attempt to use an unsupported kind of key in %s", 
		Z_OBJCE_P(object)->name
	);

	if (mstring != NULL) {
		zval_ptr_dtor(&mstring);
	}
}
Esempio n. 27
0
/* {{{ php_tmpl_dtor_tag */
inline void php_tmpl_dtor_tag(zval** zval_ptr) {
t_tmpl_tag* tag = (t_tmpl_tag*)Z_STRVAL_PP(zval_ptr);
	TAG_DESTROY(tag);
	FREE_ZVAL(*zval_ptr);
}
Esempio n. 28
0
/* {{{ proto void run()
 */
PHP_METHOD(slightphp, run)
{
		zval *zone=NULL;
		zval *page=NULL;
		zval *entry=NULL;

		zval **token;
		zval *path_array;

		//{{{
		int isPart;
		zval * path = NULL;
		if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &path) != FAILURE) {
				if (Z_TYPE_P(path)!= IS_STRING){
						RETURN_FALSE;
				}
				isPart = 1;
		}else{
			isPart = 0;
			path = zend_read_static_property(slightphp_ce_ptr,"pathInfo",sizeof("pathInfo")-1,1 TSRMLS_CC);
			int s = Z_STRLEN_P(path);
			if(s==0){
				zend_is_auto_global("_SERVER", sizeof("_SERVER") - 1 TSRMLS_CC);
				if(zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), 
							"PATH_INFO", sizeof("PATH_INFO"), (void **) &token) == SUCCESS
				){
					path = *token;
				}else if(zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), 
							"PATH_INFO", sizeof("PATH_INFO"), (void **) &token) == SUCCESS
				){
					path = *token;
				}
			}
		}
		//}}}

		MAKE_STD_ZVAL(path_array);
		array_init(path_array);

		if (path){
				//{{{
				zval quotedFlag;
				regex_t re;
				char	*regex;
				regmatch_t subs[1];
				int err,size;
				char *strp = Z_STRVAL_P(path);
				char *endp = strp + Z_STRLEN_P(path);
				zval *splitFlag = zend_read_static_property(slightphp_ce_ptr,"splitFlag",sizeof("splitFlag")-1,1 TSRMLS_CC);

				if(preg_quote(splitFlag,&quotedFlag)>0){
						spprintf(&regex,0,"[%s\\/]",Z_STRVAL(quotedFlag));
				}else{
						spprintf(&regex,0,"[\\/]");
				}
				err = regcomp(&re, regex, REG_ICASE);
				if (err) {
				}else{
						while (!(err = regexec(&re, strp, 1, subs, 0))) {
								if (subs[0].rm_so == 0 && subs[0].rm_eo) {
										//ignore empty string 
										strp += subs[0].rm_eo;
								}else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) {
								}else{
										size = subs[0].rm_so;
										add_next_index_stringl(path_array, strp, size, 1);
										strp += size;

								}
						}
						if (!err || err == REG_NOMATCH) {
								size = endp - strp;
								if(size>0) add_next_index_stringl(path_array, strp, size, 1);
						}
						regfree(&re);
				}
				efree(regex);
				//}}}
				int n_elems = zend_hash_num_elements(Z_ARRVAL_P(path_array));
				if(zend_hash_index_find(Z_ARRVAL_P(path_array), 0, (void **)&token) != FAILURE) {
						zone = *token;
				}
				if(zend_hash_index_find(Z_ARRVAL_P(path_array), 1, (void **)&token) != FAILURE) {
						page = *token;
				}
				if(zend_hash_index_find(Z_ARRVAL_P(path_array), 2, (void **)&token) != FAILURE) {
						entry = *token;
				}

		}
		if(!zone){
				zone = zend_read_static_property(slightphp_ce_ptr,"defaultZone",sizeof("defaultZone")-1,1 TSRMLS_CC);
				zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&zone,sizeof(zval*),NULL);
		}
		if(!page){
				page = zend_read_static_property(slightphp_ce_ptr,"defaultPage",sizeof("defaultPage")-1,1 TSRMLS_CC);
				zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&page,sizeof(zval*),NULL);
		}
		if(!entry){
				entry = zend_read_static_property(slightphp_ce_ptr,"defaultEntry",sizeof("defaultEntry")-1,1 TSRMLS_CC);
				zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&entry,sizeof(zval*),NULL);
		}
		//{{{
		zval *zoneAlias = zend_read_static_property(slightphp_ce_ptr,"zoneAlias",sizeof("zoneAlias")-1,1 TSRMLS_CC);
		if(zoneAlias && Z_TYPE_P(zoneAlias)==IS_ARRAY){
				char *string_key;uint str_key_len;ulong num_key;
				HashPosition pos;
				zval **entry2;
				zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zoneAlias), &pos);
				while (zend_hash_get_current_data_ex(Z_ARRVAL_P(zoneAlias), (void **)&entry2, &pos) == SUCCESS) {
						if(strcmp(Z_STRVAL_PP(entry2) ,Z_STRVAL_P(zone))==0){
								switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(zoneAlias), &string_key, &str_key_len, &num_key, 0, &pos)) {
										case HASH_KEY_IS_STRING:
												ZVAL_STRING(zone,string_key,1);
												break;
								}
						}
						zend_hash_move_forward_ex(Z_ARRVAL_P(zoneAlias), &pos);
				}
				if(entry2)zval_ptr_dtor(entry2);
				if(string_key)efree(string_key);
		}
		//if(zoneAlias)FREE_ZVAL(zoneAlias);
		//}}}
		if(!isPart){
				zend_update_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,zone TSRMLS_CC);
				zend_update_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,page TSRMLS_CC);
				zend_update_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,entry TSRMLS_CC);
		}else{
				if(
								strcmp(Z_STRVAL_P(zone),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,1 TSRMLS_CC)))==0 
								&&
								strcmp(Z_STRVAL_P(page),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,1 TSRMLS_CC)))==0 
								&&
								strcmp(Z_STRVAL_P(entry),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,1 TSRMLS_CC)))==0 
				  ){
						debug("part ignored [%s]",Z_STRVAL_P(path));
						return;
				}
		}


		zval *appDir = zend_read_static_property(slightphp_ce_ptr,"appDir",sizeof("appDir")-1,1 TSRMLS_CC);

		zval *params[1];
		params[0]=path_array;


		if(slightphp_load(appDir,zone,page TSRMLS_CC) == SUCCESS){
				if(slightphp_run(zone,page,entry,return_value,1,params TSRMLS_CC)==SUCCESS){
						if(path_array)FREE_ZVAL(path_array);
						RETURN_ZVAL(return_value,1,0);
				};
		}
		if(path_array)FREE_ZVAL(path_array);
		RETURN_FALSE;
}
Esempio n. 29
0
/** {{{ public ZeRecorder::query($sql = null, $args = null, $_ = null)
 */
PHP_METHOD(ze_recorder, query) {
	zval *   self      = NULL;
	zval *   conn      = NULL;
	zval *   stmt      = NULL;
	char *   query     = NULL;
	int      query_len = 0;
	zval *   sql       = NULL;
	zval *   keys      = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s"
				, &query
				, &query_len
				) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	/* call prepare */

	self = getThis();

	conn = zend_read_property(ze_recorder_ce, self, ZEND_STRL(ZE_PDO_DBH), 0 TSRMLS_CC);

	do {
		if (!conn || Z_TYPE_P(conn) != IS_OBJECT) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.query.conn.not_object");
			break;
		}

		MAKE_STD_ZVAL(keys);
		array_init(keys);

		sql = to_indexed(keys, query, query_len);

		if (!sql) {
			ze_error(E_ERROR TSRMLS_CC, "recorder.query.sql.is_empty");
			break;
		}

		zend_call_method(&conn, Z_OBJCE_P(conn), NULL, ZEND_STRL("prepare"), &stmt, 1, sql, NULL TSRMLS_CC);

		if (!stmt || EG(exception)) {
			zval_dtor(keys);
			FREE_ZVAL(keys);
			ze_error(E_ERROR TSRMLS_CC, "recorder.query.stmt.not_object");
			break;
		}
		zend_update_property(ze_recorder_ce, self, ZEND_STRL(ZE_STMT), stmt TSRMLS_CC);
		zend_update_property(ze_recorder_ce, self, ZEND_STRL(ZE_KEYS), keys TSRMLS_CC);

		if (stmt != NULL) {
			zval_ptr_dtor(&stmt);
		}

		if (keys != NULL) {
			zval_ptr_dtor(&keys);
		}

	} while (0);


	if (sql != NULL) {
		zval_dtor(sql);
		FREE_ZVAL(sql);
	}

	RETURN_ZVAL(self, 1, 0);
}