X-Git-Url: https://git.rapsys.eu/bbcode/blobdiff_plain/c6546ba7c986db18ac9e22d17b1d7075b8f3416c..ce9c1a4bde38195ec32f7cd10ac4196f1d2a125d:/bbcode.c diff --git a/bbcode.c b/bbcode.c index 8c15a10..f6dd39a 100644 --- a/bbcode.c +++ b/bbcode.c @@ -14,10 +14,9 @@ ZEND_DECLARE_MODULE_GLOBALS(bbcode) */ typedef struct _bbcode_object { - /*zval *tag; - zval *smiley; - zval *flag;*/ - zend_long flag; + HashTable *tag; + HashTable *smiley; + zval flag; zend_object std; } bbcode_object; @@ -76,12 +75,23 @@ enum { * TODO: Set it in an ini ? */ #define BBCODE_DEFAULT_FLAG BBCODE_QUOTE_DOUBLE|BBCODE_QUOTE_SIMPLE|BBCODE_QUOTE_ESCAPE|BBCODE_CORRECT_AUTO|BBCODE_CORRECT_REOPEN|BBCODE_SMILEY_ON|BBCODE_CLOSE_AUTO|BBCODE_REMOVE_EMPTY +/*static inline bbcode_object *bbcode_object_from_zend_object(zend_object *obj) { + return (bbcode_object *)((char*)(obj) - XtOffsetOf(bbcode_object, std)); +}*/ + +static inline bbcode_object* bbcode_fetch(zend_object *obj) { + return (bbcode_object *)((char *)obj - XtOffsetOf(bbcode_object, std)); +} + +#define Z_BBCODE_P(zv) bbcode_fetch(Z_OBJ_P((zv))) + static void bbcode_destroy(bbcode_object *obj TSRMLS_DC); static void bbcode_free(bbcode_object *obj TSRMLS_DC); static zend_object *bbcode_clone(zval *obj TSRMLS_DC); static zend_object *bbcode_create(zend_class_entry *ce TSRMLS_DC); -/* BBCode object destroy call */ +/* {{{ static void bbcode_destroy(bbcode_object *obj TSRMLS_DC) { + * BBCode object destroy call */ static void bbcode_destroy(bbcode_object *obj TSRMLS_DC) { //zend_objects_destroy_object(&obj->std); zend_objects_destroy_object((zend_object *)obj); @@ -94,8 +104,10 @@ static void bbcode_destroy(bbcode_object *obj TSRMLS_DC) { //efree(obj); } +/* }}} */ -/* BBCode object free call */ +/* {{{ static void bbcode_free(bbcode_object *obj TSRMLS_DC) { + * BBCode object free call */ static void bbcode_free(bbcode_object *obj TSRMLS_DC) { /*if (obj->flag) { @@ -105,130 +117,101 @@ static void bbcode_free(bbcode_object *obj TSRMLS_DC) { //efree(obj); zend_object_std_dtor((zend_object *)obj); } +/* }}} */ -static zend_object *bbcode_clone(zval *obj TSRMLS_DC) { - - bbcode_object *oldobj = (bbcode_object *)((char *)obj - XtOffsetOf(bbcode_object, std)); - - bbcode_object *newobj = ecalloc(1, sizeof(bbcode_object) + zend_object_properties_size(Z_OBJCE_P(obj))); - - zend_object_std_init(&newobj->std, Z_OBJCE_P(obj) TSRMLS_CC); - object_properties_init(&newobj->std, Z_OBJCE_P(obj) TSRMLS_CC); - - //newobj->std.handlers = &bbcode_handlers; - - zend_objects_clone_members(&newobj->std, &oldobj->std); - -#if 0 - bbcode_object *oldobj = (bbcode_object *)((char *)obj - XtOffsetOf(bbcode_object, std)); - zend_object *newobj_val = bbcode_create(Z_OBJCE_P(obj) TSRMLS_CC); - bbcode_object *newobj = (bbcode_object *)((char *)newobj_val - XtOffsetOf(bbcode_object, std)); - - zend_objects_clone_members(&newobj->std, &oldobj->std); -#endif - - /*XXX: clone flag member*/ - newobj->flag = oldobj->flag; - - /* TODO: clone the members of bbcode_object - newobj->buffer = oldobj->buffer; - newobj->length = oldobj->length; - - if (oldobj->flag) { - newobj->buffer = emalloc(oldobj->length); - memcpy(newobj->buffer, oldobj->buffer, oldobj->length); - }*/ - - return &newobj->std; -} +/* {{{ static zend_object *bbcode_clone(zval *obj) { + * BBCode object clone call */ +static zend_object *bbcode_clone(zval *obj) { -#if 0 -static zend_object_value bbcode_clone(zval *obj TSRMLS_DC) -{ - bbcode_object *oldobj = zend_object_store_get_object(obj TSRMLS_CC); - zend_object_value newobj_val = array_buffer_create_object(Z_OBJCE_P(obj) TSRMLS_CC); - bbcode_object *newobj = zend_object_store_get_object_by_handle(newobj_val.handle TSRMLS_CC); + zend_object *oldobj = Z_OBJ_P(obj); + zend_object *newobj = bbcode_create(oldobj->ce); - zend_objects_clone_members(&newobj->std, &oldobj->std); + zend_objects_clone_members(newobj, oldobj); - /* TODO: clone the members of bbcode_object - newobj->buffer = oldobj->buffer; - newobj->length = oldobj->length; + /*Retrieve from zend object old bbcode*/ + bbcode_object *bboldobj = Z_BBCODE_P(obj); + /*Retrieve from zend object new bbcode*/ + bbcode_object *bbnewobj = bbcode_fetch(newobj); - if (oldobj->flag) { - newobj->buffer = emalloc(oldobj->length); - memcpy(newobj->buffer, oldobj->buffer, oldobj->length); - }*/ + /*Restore object member values*/ + /*TODO: deal with the other one*/ + Z_LVAL(bbnewobj->flag) = Z_LVAL(bboldobj->flag); - return newobj_val; + return newobj; } -#endif +/* }}} */ +/* {{{ static zend_object *bbcode_create(zend_class_entry *ce TSRMLS_DC) { + * BBCode object create call */ static zend_object *bbcode_create(zend_class_entry *ce TSRMLS_DC) { - bbcode_object *obj = ecalloc(1, sizeof(bbcode_object) + zend_object_properties_size(ce));//emalloc(sizeof(bbcode_object)); - obj->flag = 0; - //memset(obj, 0, sizeof(bbcode_object)); + bbcode_object *obj = (bbcode_object *)ecalloc(1, sizeof(bbcode_object) + zend_object_properties_size(ce));//emalloc(sizeof(bbcode_object)); zend_object_std_init(&obj->std, ce TSRMLS_CC); object_properties_init(&obj->std, ce TSRMLS_CC); - /**/ - memcpy(&bbcode_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); bbcode_handlers.offset = XtOffsetOf(bbcode_object, std); bbcode_handlers.dtor_obj = (zend_object_dtor_obj_t) bbcode_destroy; bbcode_handlers.free_obj = (zend_object_free_obj_t) bbcode_free; bbcode_handlers.clone_obj = (zend_object_clone_obj_t) bbcode_clone; - //bbcode_handlers.offset = XtOffsetOf(bbcode_object, std); - //bbcode_handlers.dtor_obj = (zend_object_dtor_obj_t) bbcode_destroy; - //bbcode_handlers.free_obj = (zend_object_free_obj_t) bbcode_free; - //bbcode_handlers.clone_obj = (zend_object_clone_obj_t) bbcode_clone; - - - /*retval.handle = zend_object_store_put( - obj, - (zend_objects_store_dtor_t) zend_objects_destroy_object, - (zend_objects_free_object_storage_t) bbcode_free, - NULL TSRMLS_CC - ); - retval.handlers = &bbcode_handlers; - - return retval;*/ obj->std.handlers = &bbcode_handlers; - return &obj->std; -} + Z_LVAL(obj->flag) = 0; -static inline bbcode_object* bbcode_fetch(zend_object *obj) { - return (bbcode_object *)((char *)obj - XtOffsetOf(bbcode_object, std)); + return &obj->std; } +/* }}} */ -/* {{{ PHP_METHOD(BBCode::__construct) { - */ +/* {{{ ZEND_BEGIN_ARG_INFO_EX(bbcode_construct_arginfo) */ ZEND_BEGIN_ARG_INFO_EX(bbcode_construct_arginfo, 0, 0, 1) ZEND_ARG_ARRAY_INFO(0, tag, 1) ZEND_ARG_ARRAY_INFO(0, smiley, 1) ZEND_ARG_INFO(0, flag) ZEND_END_ARG_INFO() +/* }}} */ +/* {{{ ZEND_BEGIN_ARG_INFO_EX(bbcode_parse_arginfo) */ +ZEND_BEGIN_ARG_INFO_EX(bbcode_parse_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, str) +ZEND_END_ARG_INFO() +/* }}} */ +/* { { { PHP_METHOD(BBCode, __construct) { + */ PHP_METHOD(BBCode, __construct) { - zend_array *tag; - zend_array *smiley; - zend_long flag = BBCODE_DEFAULT_FLAG; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|al", &tag, &smiley, &flag) == FAILURE) { + HashTable *tag = NULL; + HashTable *smiley = NULL; + long flag = BBCODE_DEFAULT_FLAG; + +/*TODO: init tag with [ + '' => [ ? ] +]*/ +/* TODO: init smiley with default list + * TODO: use prefix in an ini parameter ? ini_setable ? + * TODO: make sure it's not really a global and per-app param ? + * */ + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|Hl", &tag, &smiley, &flag) == FAILURE) { return; } - bbcode_object *obj = bbcode_fetch(Z_OBJ_P(getThis())); + //bbcode_object *obj = bbcode_fetch(Z_OBJ_P(getThis())); + bbcode_object *obj = Z_BBCODE_P(getThis()); assert(obj != NULL); + //TODO: set tag and smiley + if (flag) { - obj->flag = (zend_long) flag; + Z_LVAL(obj->flag) = flag; + } + + if (smiley) { + obj->smiley = smiley; } + obj->tag = tag; + //obj = zend_object_store_get_object(getThis() TSRMLS_CC); //if (error) { //ZVAL_NULL(this); @@ -242,10 +225,18 @@ PHP_METHOD(BBCode, __destruct) { } /* }}} */ -/* {{{ PHP_METHOD(BBCode, __toString) { +/* {{{ PHP_METHOD(BBCode, parse) { */ -PHP_METHOD(BBCode, __toString) { - //TODO: +PHP_METHOD(BBCode, parse) { + zend_string *str = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { + return; + } + + //TODO: apply the parsing on string + + RETURN_STR(str); } /* }}} */ @@ -256,7 +247,7 @@ PHP_METHOD(BBCode, __toString) { const zend_function_entry bbcode_methods[] = { PHP_ME(BBCode, __construct, bbcode_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(BBCode, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) - PHP_ME(BBCode, __toString, NULL, ZEND_ACC_PUBLIC) + PHP_ME(BBCode, parse, bbcode_parse_arginfo, ZEND_ACC_PUBLIC) PHP_FE_END }; /* }}} */