From 975d9c90af8537bf59f93fe5b0d94026271f79ea Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 5 Feb 2012 10:24:19 +0000 Subject: Implement HTMLDocument constructor/destructor svn path=/trunk/libdom/; revision=13420 --- src/html/html_document.c | 54 ++++++++++++++++++++++++++++++++++++++---------- src/html/html_document.h | 1 - 2 files changed, 43 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/html/html_document.c b/src/html/html_document.c index d716901..394eac8 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -14,35 +14,67 @@ #include "utils/utils.h" /* Create a HTMLDocument */ -dom_exception dom_html_document_create(dom_msg msg, void *msg_pw, +dom_exception dom_html_document_create( dom_events_default_action_fetcher daf, dom_ui_handler *ui, dom_html_document **doc) { - *doc = malloc(sizeof(dom_html_document)); - if (*doc == NULL) + dom_exception error; + dom_html_document *result; + + result = malloc(sizeof(dom_html_document)); + if (result == NULL) return DOM_NO_MEM_ERR; - return _dom_html_document_initialise(*doc, msg, msg_pw, daf, ui); + error = _dom_html_document_initialise(*doc, daf, ui); + if (error != DOM_NO_ERR) { + free(result); + return error; + } + + *doc = result; + return DOM_NO_ERR; } /* Initialise a HTMLDocument */ dom_exception _dom_html_document_initialise(dom_html_document *doc, - dom_msg msg, void *msg_pw, dom_events_default_action_fetcher daf, dom_ui_handler *ui) { - UNUSED(doc); - UNUSED(msg); - UNUSED(msg_pw); - UNUSED(daf); + dom_exception error; + UNUSED(ui); + error = _dom_document_initialise(&doc->base, daf); + if (error != DOM_NO_ERR) + return error; + + doc->title = NULL; + doc->referer = NULL; + doc->domain = NULL; + doc->url = NULL; + doc->cookie = NULL; + return DOM_NO_ERR; } /* Finalise a HTMLDocument */ -void _dom_html_document_finalise(dom_html_document *doc); +void _dom_html_document_finalise(dom_html_document *doc) +{ + dom_string_unref(doc->cookie); + dom_string_unref(doc->url); + dom_string_unref(doc->domain); + dom_string_unref(doc->referer); + dom_string_unref(doc->title); + + _dom_document_finalise(&doc->base); +} + /* Destroy a HTMLDocument */ -void _dom_html_document_destroy(dom_html_document *doc); +void _dom_html_document_destroy(dom_html_document *doc) +{ + _dom_html_document_finalise(doc); + + free(doc); +} /* Parse a data chunk into the HTMLDocument */ dom_exception dom_html_document_write_data(uint8_t *data, size_t len); diff --git a/src/html/html_document.h b/src/html/html_document.h index 658836b..ad3ff6d 100644 --- a/src/html/html_document.h +++ b/src/html/html_document.h @@ -27,7 +27,6 @@ struct dom_html_document { /* Initialise a HTMLDocument */ dom_exception _dom_html_document_initialise(dom_html_document *doc, - dom_msg msg, void *msg_pw, dom_events_default_action_fetcher daf, dom_ui_handler *ui); /* Finalise a HTMLDocument */ void _dom_html_document_finalise(dom_html_document *doc); -- cgit v1.2.3