myhtml_status_t myhtml_tag_index_add(myhtml_tag_t* tags, myhtml_tag_index_t* idx_tags, myhtml_tree_node_t* node) { myhtml_tag_index_check_size(tags, idx_tags, node->tag_idx); myhtml_tag_index_entry_t* tag = &idx_tags->tags[node->tag_idx]; mcobject_async_status_t mcstatus; myhtml_tag_index_node_t* new_node = mcobject_async_malloc(tags->tag_index, tags->mcobject_node, &mcstatus); if(mcstatus != MCOBJECT_ASYNC_STATUS_OK) return MyHTML_STATUS_TAGS_ERROR_MCOBJECT_MALLOC; myhtml_tag_index_clean_node(new_node); if(tag->first == NULL) { tag->first = new_node; new_node->prev = NULL; } else { tag->last->next = new_node; new_node->prev = tag->last; } new_node->next = NULL; new_node->node = node; tag->last = new_node; tag->count++; return MyHTML_STATUS_OK; }
// incoming buffer void myhtml_incomming_buf_add(myhtml_t* myhtml, myhtml_tree_t* tree, myhtml_incoming_buf_t *current, const char *html, size_t html_size) { tree->incoming_buf = mcobject_async_malloc(myhtml->async_incoming_buf, tree->mcasync_incoming_buf_id, NULL); tree->incoming_buf->size = html_size; tree->incoming_buf->length = 0; tree->incoming_buf->data = html; tree->incoming_buf->offset = tree->global_offset; if(current) current->next = tree->incoming_buf; tree->incoming_buf->prev = current; tree->incoming_buf->next = NULL; }
myhtml_tree_attr_t * myhtml_attribute_add(myhtml_tree_t *tree, myhtml_tree_node_t *node, const char *key, size_t key_len, const char *value, size_t value_len, myhtml_encoding_t encoding) { if(node == NULL) return NULL; if(node->token == NULL) { mcobject_async_status_t mcstatus; node->token = (myhtml_token_node_t*)mcobject_async_malloc(tree->token->nodes_obj, tree->mcasync_token_id, &mcstatus); if(mcstatus) return NULL; myhtml_token_node_clean(node->token); } return myhtml_token_node_attr_append_with_convert_encoding(tree->token, node->token, key, key_len, value, value_len, tree->mcasync_token_id, encoding); }
myhtml_string_t * myhtml_node_text_set_with_charef(myhtml_tree_t* tree, myhtml_tree_node_t *node, const char* text, size_t length, myhtml_encoding_t encoding) { if(node == NULL) return NULL; if(encoding >= MyHTML_ENCODING_LAST_ENTRY) return NULL; if(node->token == NULL) { mcobject_async_status_t mcstatus; node->token = (myhtml_token_node_t*)mcobject_async_malloc(tree->token->nodes_obj, tree->mcasync_token_id, &mcstatus); if(mcstatus) return NULL; myhtml_token_node_clean(node->token); } if(node->token->str.data == NULL) { myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->str, (length + 2)); } else { if(node->token->str.size < length) { mchar_async_free(tree->mchar, node->token->str.node_idx, node->token->str.data); myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->str, length); } else node->token->str.length = 0; } myhtml_data_process_entry_t proc_entry; myhtml_data_process_entry_clean(&proc_entry); proc_entry.encoding = encoding; myhtml_encoding_result_clean(&proc_entry.res); myhtml_data_process(&proc_entry, &node->token->str, text, length); myhtml_data_process_end(&proc_entry, &node->token->str); node->token->raw_begin = 0; node->token->raw_length = 0; return &node->token->str; }
myhtml_string_t * myhtml_node_text_set(myhtml_tree_t* tree, myhtml_tree_node_t *node, const char* text, size_t length, myhtml_encoding_t encoding) { if(node == NULL) return NULL; if(encoding >= MyHTML_ENCODING_LAST_ENTRY) return NULL; if(node->token == NULL) { mcobject_async_status_t mcstatus; node->token = (myhtml_token_node_t*)mcobject_async_malloc(tree->token->nodes_obj, tree->mcasync_token_id, &mcstatus); if(mcstatus) return NULL; myhtml_token_node_clean(node->token); } if(node->token->my_str_tm.data == NULL) { myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->my_str_tm, (length + 2)); } else { if(node->token->my_str_tm.size < length) { mchar_async_free(tree->mchar, node->token->my_str_tm.node_idx, node->token->my_str_tm.data); myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->my_str_tm, length); } else node->token->my_str_tm.length = 0; } if(encoding != MyHTML_ENCODING_UTF_8) { myhtml_string_append_with_convert_encoding(&node->token->my_str_tm, text, length, encoding); } else { myhtml_string_append(&node->token->my_str_tm, text, length); } node->token->begin = 0; node->token->length = node->token->my_str_tm.length; return &node->token->my_str_tm; }
myhtml_string_t * myhtml_node_text_set_with_charef(myhtml_tree_t* tree, myhtml_tree_node_t *node, const char* text, size_t length, myhtml_encoding_t encoding) { if(node == NULL) return NULL; if(encoding >= MyHTML_ENCODING_LAST_ENTRY) return NULL; if(node->token == NULL) { mcobject_async_status_t mcstatus; node->token = (myhtml_token_node_t*)mcobject_async_malloc(tree->token->nodes_obj, tree->mcasync_token_id, &mcstatus); if(mcstatus) return NULL; myhtml_token_node_clean(node->token); } if(node->token->my_str_tm.data == NULL) { myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->my_str_tm, (length + 2)); } else { if(node->token->my_str_tm.size < length) { mchar_async_free(tree->mchar, node->token->my_str_tm.node_idx, node->token->my_str_tm.data); myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->my_str_tm, length); } else node->token->my_str_tm.length = 0; } myhtml_string_char_ref_chunk_t str_chunk = {0, 0, 0, {0}, false, encoding}; myhtml_encoding_result_clean(&str_chunk.res); myhtml_string_append_charef(&str_chunk, &node->token->my_str_tm, text, length); myhtml_string_append_charef_end(&str_chunk, &node->token->my_str_tm); node->token->begin = 0; node->token->length = node->token->my_str_tm.length; return &node->token->my_str_tm; }