+/* }}} */
+
+/* {{{ ZEND_BEGIN_ARG_INFO_EX(bbcode_parse_arginfo) */
+// ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)
+ZEND_BEGIN_ARG_INFO_EX(bbcode_parse_arginfo, 0, 0, 1)
+ // ZEND_ARG_INFO(pass_by_ref, name)
+ ZEND_ARG_INFO(0, str)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+/* {{{ static HashTable *bbcode_gen_child(HashTable *ret, HashTable *tag, zend_string *cur TSRMLS_DC) { */
+static HashTable *bbcode_gen_child(HashTable *ret, HashTable *tag, zend_string *cur TSRMLS_DC) {
+ /* Key string */
+ zend_string *key;
+ /* Value */
+ zval *val;
+
+ /* Iterate on each key val until hash end is reached */
+ ZEND_HASH_FOREACH_STR_KEY_VAL(tag, key, val) {
+ /* Check if key is not a string, value is null or not an array */
+ if (key == NULL || val == NULL || Z_TYPE_P(val) != IS_ARRAY) {
+ /* Return failure, useless to generate a hash when we will trigger an error later */
+ return NULL;
+ }
+
+ /* Init type val */
+ zval *type;
+
+ /* Check that we have no type or that it's not root type */
+ /* XXX: it's not possible to have in child the root tag */
+ if ((type = zend_hash_str_find(Z_ARR_P(val), "type", strlen("type"))) == NULL || Z_LVAL_P(type) != BBCODE_TYPE_ROOT) {
+ /* Check that we are not on cur key */
+ /* XXX: not really required, but it's stupid to allow same tag in child */
+ //if (strcmp(ZSTR_VAL(cur), ZSTR_VAL(key)) != 0) {
+ /* Init parent val */
+ zval *parent;
+
+ /* Init toInsert bool */
+ unsigned char toInsert = 0;
+
+ /* Check if we find parent key */
+ if ((parent = zend_hash_str_find(Z_ARR_P(val), "parent", strlen("parent"))) != NULL) {
+ /* Parent value */
+ zval *pval;
+
+ /* Iterate on each val until hash end is reached */
+ ZEND_HASH_FOREACH_VAL(Z_ARR_P(parent), pval) {
+ /* Check that parent val is a string */
+ if (Z_TYPE_P(pval) != IS_STRING) {
+ return NULL;
+ }
+
+ /* Check that tkey is a string and is identical */
+ if (strcmp(Z_STRVAL_P(pval), ZSTR_VAL(cur)) == 0) {
+ toInsert = 1;
+ }
+ } ZEND_HASH_FOREACH_END();
+ /* No parent key */
+ } else {
+ toInsert = 1;
+ }
+
+ /* Add the key */
+ if (toInsert) {
+ /* Init child val */
+ zval cval;
+
+ /* Set child val */
+ ZVAL_STR(&cval, key);
+
+ /* Insert the child val in return array */
+ ZEND_ASSERT(zend_hash_next_index_insert_new(ret, &cval) != NULL);
+ }
+ //}
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ /* Return value */
+ return ret;
+}
+/* }}} */
+
+/* {{{ static HashTable *bbcode_gen_parent(HashTable *ret, HashTable *tag, zend_string *cur TSRMLS_DC) { */
+static HashTable *bbcode_gen_parent(HashTable *ret, HashTable *tag, zend_string *cur TSRMLS_DC) {
+ /* Key string */
+ zend_string *key;
+ /* Value */
+ zval *val;
+
+ /* Iterate on each key val until hash end is reached */
+ ZEND_HASH_FOREACH_STR_KEY_VAL(tag, key, val) {
+ /* Check if key is not a string, value is null or not an array */
+ if (key == NULL || val == NULL || Z_TYPE_P(val) != IS_ARRAY) {
+ /* Return failure, useless to generate a hash when we will trigger an error later */
+ return NULL;
+ }
+
+ /* Init type val */
+ zval *type;
+
+ /* Check that we have no type or that it's not single type */
+ /* XXX: it's not possible to have in child the root tag */
+ if ((type = zend_hash_str_find(Z_ARR_P(val), "type", strlen("type"))) == NULL || Z_LVAL_P(type) != BBCODE_TYPE_SINGLE) {
+ /* Check that we are not on cur key */
+ /* XXX: not really required, but it's stupid to allow same tag in child */
+ //if (strcmp(ZSTR_VAL(cur), ZSTR_VAL(key)) != 0) {
+ /* Init child val */
+ zval *child;
+
+ /* Init toInsert bool */
+ unsigned char toInsert = 0;
+
+ /* Check if we find child key */
+ if ((child = zend_hash_str_find(Z_ARR_P(val), "child", strlen("child"))) != NULL) {
+ /* Child value */
+ zval *cval;
+
+ /* Iterate on each val until hash end is reached */
+ ZEND_HASH_FOREACH_VAL(Z_ARR_P(child), cval) {
+ /* Check that child val is a string */
+ if (Z_TYPE_P(cval) != IS_STRING) {
+ return NULL;
+ }
+
+ /* Check that tkey is a string and is identical */
+ if (strcmp(Z_STRVAL_P(cval), ZSTR_VAL(cur)) == 0) {
+ toInsert = 1;
+ }
+ } ZEND_HASH_FOREACH_END();
+ /* No child key */
+ } else {
+ toInsert = 1;
+ }
+
+ /* Add the key */
+ if (toInsert) {
+ /* Init parent val */
+ zval pval;
+
+ /* Set parent val */
+ ZVAL_STR(&pval, key);
+
+ /* Insert the parent val in return array */
+ ZEND_ASSERT(zend_hash_next_index_insert_new(ret, &pval) != NULL);
+ }
+ //}
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ /* Return value */
+ return ret;
+}
+/* }}} */
+
+/* {{{ static zend_bool *bbcode_check_tag(HashTable *tag TSRMLS_DC) {
+ * Check that tag hash is valid */
+static zend_string *bbcode_check_tag(HashTable *tag TSRMLS_DC) {
+ /* Key numeric value */
+ zend_long idx;
+ /* Key and root string */
+ zend_string *key, *root = NULL;
+ /* Value */
+ zval *val;
+
+ /* Key position */
+ int pos = 0;
+
+ /* Has a root */
+ int hasRoot = 0;
+
+ /* Iterate on each key val until hash end is reached */
+ ZEND_HASH_FOREACH_KEY_VAL(tag, idx, key, val) {
+ /* Check if key is not a string */
+ if (key == NULL) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key %ld[%d] from argument tag is not an expected string", idx, pos);
+ /* Return failure */
+ return NULL;
+ /* Check that key do not contains a special character */
+ } else if (strchr(ZSTR_VAL(key), '=') != NULL || strchr(ZSTR_VAL(key), '[') != NULL || strchr(ZSTR_VAL(key), ']') != NULL || strchr(ZSTR_VAL(key), '(') != NULL || strchr(ZSTR_VAL(key), ')') != NULL || strchr(ZSTR_VAL(key), '/') != NULL || strchr(ZSTR_VAL(key), '\\') != NULL) {
+ /* Display error about key containing a special char */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key %s[%d] from argument tag contains a special forbidden character: =[]()/\\", ZSTR_VAL(key), pos);
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Check that value exists */
+ if (val == NULL) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d] from argument tag is NULL instead of expected array", ZSTR_VAL(key), pos);
+ /* Return failure */
+ return NULL;
+ /* Check that value is an array */
+ } else if (Z_TYPE_P(val) != IS_ARRAY) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d] from argument tag is %s[%d] instead of expected array", ZSTR_VAL(key), pos, BBCODE_GET_TYPE(Z_TYPE_P(val)), Z_TYPE_P(val));
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Store child tag array */
+ HashTable *ctag = Z_ARR_P(val);
+ /* Child key numeric value */
+ zend_long cidx;
+ /* Child key string */
+ zend_string *ckey;
+ /* Child value */
+ zval *cval;
+
+ /* Buffer */
+ char *buf;
+
+ /* Child key position */
+ int cpos = 0, type, len;
+
+ /* Detect if entry has a type, parent, child, open, close, default or arg key to display error if mandatory field is missing */
+ unsigned char hasType = 0, hasParent = 0, hasChild = 0, hasOpen = 0, hasClose = 0, hasDefault = 0, hasArg = 0;
+
+ /* Iterate on each ckey cval until hash end is reached */
+ ZEND_HASH_FOREACH_KEY_VAL(ctag, cidx, ckey, cval) {
+ /* Check if ckey is a string */
+ if (!ckey) {
+ /* Display error about long ckey */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key %s[%d]/%ld[%d] from argument tag is not an expected string", ZSTR_VAL(key), pos, cidx, cpos);
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Check if ckey is empty */
+ if (ZSTR_LEN(ckey) == 0) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key %s[%d]/%s[%d] from argument tag is empty not one of expected type|parent|child|open|close|default string", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos);
+ /* Return failure */
+ return NULL;
+ /* Check if current ckey is type */
+ } else if (strcmp("type", ZSTR_VAL(ckey)) == 0) {
+ /* Extract type */
+ type = Z_LVAL_P(cval);
+
+ /* Check that current type is valid */
+ if (
+ type != BBCODE_TYPE_ROOT &&
+ type != BBCODE_TYPE_MULTI &&
+ type != BBCODE_TYPE_SINGLE
+ ) {
+ /* Display error about unexpected type value */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value '%d' for key %s[%d]/%s[%d] from argument tag is not one of expected BBCODE::TYPE_(ROOT|MULTI|SINGLE) constant", type, ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos);
+ /* Return failure */
+ return NULL;
+ /* Check if root */
+ } else if (type == BBCODE_TYPE_ROOT) {
+ /* Grow hasRoot */
+ hasRoot++;
+ }
+
+ /* Set hasType */
+ hasType = 1;
+ /* Check if current key is parent */
+ } else if (strcmp("parent", ZSTR_VAL(ckey)) == 0) {
+ /* Check that value exists */
+ if (cval == NULL) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d]/%s[%d] from argument tag is NULL instead of expected array", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos);
+ /* Return failure */
+ return NULL;
+ /* Check that value is an array */
+ } else if (Z_TYPE_P(cval) != IS_ARRAY) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d]/%s[%d] from argument tag is %s[%d] instead of expected array", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos, BBCODE_GET_TYPE(Z_TYPE_P(cval)), Z_TYPE_P(cval));
+ /* Return failure */
+ return NULL;
+ /* Check that value is an non empty array */
+ } else if (zend_array_count(Z_ARR_P(cval)) == 0) {
+ /* Display error about empty parent array */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d]/%s[%d] from argument tag is an empty array instead of expected filled array", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos);
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Parent value */
+ zval *pval;
+
+ /* Child key position */
+ int ppos = 0;
+
+ /* Iterate on each val until hash end is reached */
+ ZEND_HASH_FOREACH_VAL(Z_ARR_P(cval), pval) {
+ /* Check that parent val is a string */
+ /* XXX: pval == NULL case is catched here too */
+ if (Z_TYPE_P(pval) != IS_STRING) {
+ /* Display error about not string */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d]/%s[%d]/[%d] from argument tag is %s[%d] instead of expected string", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos, ppos, BBCODE_GET_TYPE(Z_TYPE_P(pval)), Z_TYPE_P(pval));
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Tag key */
+ zend_string *tkey;
+
+ /* Reset found flag */
+ unsigned char found = 0;
+
+ /* Iterate on each key until hash end is reached */
+ ZEND_HASH_FOREACH_STR_KEY(tag, tkey) {
+ /* Check that tkey is a string and is identical */
+ if (tkey != NULL && strcmp(Z_STRVAL_P(pval), ZSTR_VAL(tkey)) == 0) {
+ /* We found parent value in tag keys*/
+ found = 1;
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ /* Check if we found the key */
+ if (!found) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d]/%s[%d]/%s[%d] from argument tag is not present in tag keys", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos, Z_STRVAL_P(pval), ppos);
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Grow ppos */
+ ppos++;
+ } ZEND_HASH_FOREACH_END();
+
+ /* Set hasParent */
+ hasParent = 1;
+ /* Check if current key is child */
+ } else if (strcmp("child", ZSTR_VAL(ckey)) == 0) {
+ /* Check that value exists */
+ if (cval == NULL) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d]/%s[%d] from argument tag is NULL instead of expected array", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos);
+ /* Return failure */
+ return NULL;
+ /* Check that value is an array */
+ } else if (Z_TYPE_P(cval) != IS_ARRAY) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d]/%s[%d] from argument tag is %s[%d] instead of expected array", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos, BBCODE_GET_TYPE(Z_TYPE_P(cval)), Z_TYPE_P(cval));
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Child value */
+ zval *ccval;
+
+ /* Child key position */
+ int ccpos = 0;
+
+ /* Iterate on each val until hash end is reached */
+ ZEND_HASH_FOREACH_VAL(Z_ARR_P(cval), ccval) {
+ /* Check that child val is a string */
+ /* XXX: ccval == NULL case is catched here too */
+ if (Z_TYPE_P(ccval) != IS_STRING) {
+ /* Display error about not string */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value for key %s[%d]/%s[%d]/[%d] from argument tag is %s[%d] instead of expected string", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos, ccpos, BBCODE_GET_TYPE(Z_TYPE_P(ccval)), Z_TYPE_P(ccval));
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Tag key */
+ zend_string *tkey;
+
+ /* Reset found flag */
+ unsigned char found = 0;
+
+ /* Iterate on each key until hash end is reached */
+ ZEND_HASH_FOREACH_STR_KEY(tag, tkey) {
+ /* Check that tkey is a string and is identical */
+ if (tkey != NULL && strcmp(Z_STRVAL_P(ccval), ZSTR_VAL(tkey)) == 0) {
+ /* We found child value in tag keys*/
+ found = 1;
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ /* Check if we found the key */
+ if (!found) {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Child value %s for key %s[%d]/%s[%d] is not present in tag keys", Z_STRVAL_P(ccval), ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos);
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Grow ccpos */
+ ccpos++;
+ } ZEND_HASH_FOREACH_END();
+
+ /* Set hasChild */
+ hasChild = 1;
+ /* Check if current key is open */
+ } else if (strcmp("open", ZSTR_VAL(ckey)) == 0) {
+ /* Set hasOpen */
+ hasOpen = 1;
+ /* Check if current key is close */
+ } else if (strcmp("close", ZSTR_VAL(ckey)) == 0) {
+ /* Set hasClose */
+ hasClose = 1;
+ /* Check if current key is default */
+ } else if (strcmp("default", ZSTR_VAL(ckey)) == 0) {
+ /* Set hasDefault */
+ hasDefault = 1;
+ /* Check if current key is arg */
+ } else if (strcmp("arg", ZSTR_VAL(ckey)) == 0) {
+ /* Set hasArg */
+ hasArg = 1;
+ /* Check if current key is unknown */
+ } else {
+ /* Display error about long key */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key %s[%d]/%s[%d] from argument tag is not one of expected type|parent|child|open|close|default string", ZSTR_VAL(key), pos, ZSTR_VAL(ckey), cpos);
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Grow cpos */
+ cpos++;
+ } ZEND_HASH_FOREACH_END();
+
+ /* Check if val array is immutable */
+ /* XXX: this strange case happen with empty val array, the zend engine don't initialize a usable hashtable, to avoid triggering a segfault later when using the array, we fix it here */
+ if ((Z_GC_FLAGS_P(val) & GC_IMMUTABLE) == GC_IMMUTABLE) {
+ /* Allocate hash table */
+ /* XXX: this is required to avoid segfault in zend_hash_add when the array is immutable */
+ ALLOC_HASHTABLE(Z_ARR_P(val));
+
+ /* Init hash table */
+ zend_hash_init(Z_ARR_P(val), 0, NULL, ZVAL_PTR_DTOR, 0);
+
+ /* Copy old values in new array */
+ //XXX: disabled for now, array shoudln't need to be copied, immutable flag seems only present on empty arrays
+ //zend_hash_copy(Z_ARR_P(val), ctag, (copy_ctor_func_t) zval_add_ref);
+ }
+
+ /* Check if entry has no type */
+ /* TODO: make depend this code on a parse flag ? */
+ if (!hasType) {
+ /* Type key */
+ zend_string *tkey = zend_string_init("type", strlen("type"), 0);
+
+ /* Type value */
+ zval tval;
+
+ /* Check if key is '' */
+ if (ZSTR_LEN(key) == 0) {
+ /* Set tval value to root */
+ ZVAL_LONG(&tval, (type = BBCODE_TYPE_ROOT));
+
+ /* Grow hasRoot */
+ hasRoot++;
+ /* Check if key is img */
+ } else if (strcmp("img", ZSTR_VAL(key)) == 0) {
+ /* Set tval value to single */
+ ZVAL_LONG(&tval, (type = BBCODE_TYPE_SINGLE));
+ /* Handle other key as multi */
+ } else {
+ /* Set tval value to multi */
+ ZVAL_LONG(&tval, (type = BBCODE_TYPE_MULTI));
+ }
+
+ /* Add new type key */
+ ZEND_ASSERT(zend_hash_add(Z_ARR_P(val), tkey, &tval) != NULL);
+
+ /* Free type key */
+ zend_string_release(tkey);
+
+ /* Set hasType */
+ hasType = 1;
+ }
+
+ /* Check for root type */
+ if (type == BBCODE_TYPE_ROOT) {
+ /* Set root */
+ root = key;
+
+ /* Check if has parent */
+ if (hasParent) {
+ /* Display error about parent entry */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Key %s[%d] from argument tag of type BBCODE::TYPE_ROOT cannot have a parent entry", ZSTR_VAL(key), pos);
+ /* Return failure */
+ return NULL;
+ }
+
+ /* Check if has open entry */
+ if (!hasOpen) {
+ /* Key string */
+ zend_string *mkey = zend_string_init("open", strlen("open"), 0);
+
+ /* Value */
+ zval mval;
+
+ /* Check if tag is empty */
+ if (ZSTR_LEN(key) == 0) {
+ /* Init new value */
+ ZVAL_EMPTY_STRING(&mval);
+ /* Non empty tag */
+ } else {
+ /* Init buffer and length */
+ buf = (char *)malloc((len = strlen("<>") + ZSTR_LEN(key) + (hasArg?strlen("%s"):0))*sizeof(char));
+
+ /* Generate string in */
+ ZEND_ASSERT(sprintf(buf, "<%s%s>", ZSTR_VAL(key), hasArg?"%s":"") == len);
+
+ /* Init new value */
+ ZVAL_STRINGL(&mval, buf, len);
+
+ /* Free buffer */
+ free(buf);
+ }
+
+ /* Add new key */
+ ZEND_ASSERT(zend_hash_add(Z_ARR_P(val), mkey, &mval) != NULL);
+
+ /* Free key */
+ zend_string_release(mkey);
+
+ /* Set hasOpen */
+ hasOpen = 1;
+ }
+
+ /* Check if has close entry */
+ if (!hasClose) {
+ /* Key string */
+ zend_string *mkey = zend_string_init("close", strlen("close"), 0);
+
+ /* Value */
+ zval mval;
+
+ /* Check if tag is empty */
+ if (ZSTR_LEN(key) == 0) {
+ /* Init new value */
+ ZVAL_EMPTY_STRING(&mval);
+ /* Non empty tag */
+ } else {
+ /* Init buffer and length */
+ buf = (char *)malloc((len = strlen("</>") + ZSTR_LEN(key))*sizeof(char));
+
+ /* Generate string in */
+ ZEND_ASSERT(sprintf(buf, "</%s>", ZSTR_VAL(key)) == len);
+
+ /* Init new value */
+ ZVAL_STRINGL(&mval, buf, len);
+
+ /* Free buffer */
+ free(buf);
+ }
+
+ /* Add new key */
+ ZEND_ASSERT(zend_hash_add(Z_ARR_P(val), mkey, &mval) != NULL);
+
+ /* Free key */
+ zend_string_release(mkey);
+
+ /* Set hasClose */
+ hasClose = 1;
+ }
+
+ /* Check if has not default */
+ if (!hasDefault) {
+ /* Key string */
+ zend_string *mkey = zend_string_init("default", strlen("default"), 0);
+
+ /* Value */
+ zval mval;
+
+ /* Set value */
+ ZVAL_STRING(&mval, "%s");
+
+ /* Add new key */
+ ZEND_ASSERT(zend_hash_add(Z_ARR_P(val), mkey, &mval) != NULL);
+
+ /* Free key */
+ zend_string_release(mkey);
+
+ /* Set hasDefault */
+ hasDefault = 1;
+ }
+
+ /* Compute child here */
+ if (!hasChild) {
+ /* Child value */
+ zval cval;
+
+ /* Init new child val array */
+ ZVAL_NEW_ARR(&cval);
+
+ /* Init hash table */
+ zend_hash_init(Z_ARR(cval), 0, NULL, ZVAL_PTR_DTOR, 0);
+
+ /* Compute and set child here */
+ /* XXX: we don't check or trigger error inside this function as these tests are done in current loop */
+ if (bbcode_gen_child(Z_ARR(cval), tag, key) != NULL) {
+ /* Child key string */
+ zend_string *ckey = zend_string_init("child", strlen("child"), 0);
+
+ /* Add new child key */
+ ZEND_ASSERT(zend_hash_add(Z_ARR_P(val), ckey, &cval) != NULL);
+
+ /* Free type key */
+ zend_string_release(ckey);
+
+ /* Set hasChild */
+ hasChild = 1;
+ /* Child generation reached an error case */
+ /* XXX: it will trigger error later */
+ } else {
+ /* Release hash table */
+ zend_array_destroy(Z_ARR(cval));
+ }
+ }
+ /* Check for multi type */
+ } else if (type == BBCODE_TYPE_MULTI) {
+ /* Check if has open entry */
+ if (!hasOpen) {
+ /* Key string */
+ zend_string *mkey = zend_string_init("open", strlen("open"), 0);
+
+ /* Value */
+ zval mval;
+
+ /* Check if tag is empty */
+ if (ZSTR_LEN(key) == 0) {
+ /* Init new value */
+ ZVAL_EMPTY_STRING(&mval);
+ /* Non empty tag */
+ } else {
+ /* Init buffer and length */
+ buf = (char *)malloc((len = strlen("<>") + ZSTR_LEN(key) + (hasArg?strlen("%s"):0))*sizeof(char));
+
+ /* Generate string in */
+ ZEND_ASSERT(sprintf(buf, "<%s%s>", ZSTR_VAL(key), hasArg?"%s":"") == len);
+
+ /* Init new value */
+ ZVAL_STRINGL(&mval, buf, len);