r3614 jmb - in /trunk/dom: bindings/xml/ include/dom/bootstrap/ include/dom/core/ src/core/ src/utils/
by netsurf@semichrome.net
Author: jmb
Date: Sun Sep 30 22:10:50 2007
New Revision: 3614
URL: http://source.netsurf-browser.org?rev=3614&view=rev
Log:
DOM Strings are now capable of containing either UTF-8 or UTF-16 encoded data.
The charset used for strings within a document is specified at document creation time. Whilst it is possible to mix charsets within a document, it's not recommended.
Things that need fixing:
+ dom_string_get_data() doesn't return the charset. Better would be to permit
the client to request a charset for the data to be returned in.
+ Interned node name strings will break if the document is UTF-16
(dom_document_create()). In fact, these could quite happily be globals,
rather than allocating a set for each document.
+ Other usage of dom string constructors need checking for sanity
+ DOM Strings need to gain more utility APIs (such as getting the character
length of a string, string concatenation etc).
Added:
trunk/dom/src/utils/charset_errors.h
trunk/dom/src/utils/utf16.c
trunk/dom/src/utils/utf16.h
trunk/dom/src/utils/utf8.c
trunk/dom/src/utils/utf8.h
Modified:
trunk/dom/bindings/xml/xmlbinding.c
trunk/dom/bindings/xml/xmlparser.c
trunk/dom/include/dom/bootstrap/implpriv.h
trunk/dom/include/dom/core/implementation.h
trunk/dom/include/dom/core/string.h
trunk/dom/src/core/document.c
trunk/dom/src/core/document.h
trunk/dom/src/core/implementation.c
trunk/dom/src/core/string.c
trunk/dom/src/utils/Makefile
trunk/dom/src/utils/namespace.c
Modified: trunk/dom/bindings/xml/xmlbinding.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.c?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.c (original)
+++ trunk/dom/bindings/xml/xmlbinding.c Sun Sep 30 22:10:50 2007
@@ -39,6 +39,7 @@
struct dom_string *qname,
struct dom_document_type *doctype,
struct dom_document **doc,
+ dom_string_charset charset,
dom_alloc alloc, void *pw);
static dom_exception xml_dom_implementation_get_feature(
struct dom_implementation *impl,
@@ -237,6 +238,7 @@
* \param qname The qualified name of the document element
* \param doctype The type of document to create
* \param doc Pointer to location to receive result
+ * \param charset The charset to use for strings in the document
* \param alloc Memory (de)allocation function
* \param pw Pointer to client-specific private data
* \return DOM_NO_ERR on success,
@@ -273,13 +275,14 @@
struct dom_string *qname,
struct dom_document_type *doctype,
struct dom_document **doc,
+ dom_string_charset charset,
dom_alloc alloc, void *pw)
{
struct dom_document *d;
dom_exception err;
/* Create document object */
- err = dom_document_create(impl, alloc, pw, &d);
+ err = dom_document_create(impl, charset, alloc, pw, &d);
if (err != DOM_NO_ERR)
return err;
Modified: trunk/dom/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.c?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.c (original)
+++ trunk/dom/bindings/xml/xmlparser.c Sun Sep 30 22:10:50 2007
@@ -182,6 +182,7 @@
/* Create key for user data registration */
err = dom_string_create_from_ptr_no_doc((dom_alloc) alloc, pw,
+ DOM_STRING_UTF8,
(const uint8_t *) "__xmlnode", SLEN("__xmlnode"),
&parser->udkey);
if (err != DOM_NO_ERR) {
@@ -194,6 +195,7 @@
/* Get DOM implementation */
/* Create a string representation of the features we want */
err = dom_string_create_from_ptr_no_doc((dom_alloc) alloc, pw,
+ DOM_STRING_UTF8,
(const uint8_t *) "XML", SLEN("XML"), &features);
if (err != DOM_NO_ERR) {
dom_string_unref(parser->udkey);
@@ -327,6 +329,7 @@
/* qname */ NULL,
/* doctype */ NULL,
&doc,
+ DOM_STRING_UTF8,
(dom_alloc) parser->alloc,
parser->pw);
if (err != DOM_NO_ERR) {
Modified: trunk/dom/include/dom/bootstrap/implpriv.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implpri...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implpriv.h (original)
+++ trunk/dom/include/dom/bootstrap/implpriv.h Sun Sep 30 22:10:50 2007
@@ -29,10 +29,10 @@
#include <dom/core/exceptions.h>
#include <dom/functypes.h>
+#include <dom/core/string.h>
struct dom_document;
struct dom_document_type;
-struct dom_string;
/**
* DOM Implementation
@@ -94,6 +94,7 @@
* \param qname The qualified name of the document element
* \param doctype The type of document to create
* \param doc Pointer to location to receive result
+ * \param charset The charset to use for strings in the document
* \param alloc Memory (de)allocation function
* \param pw Pointer to client-specific private data
* \return DOM_NO_ERR on success,
@@ -129,6 +130,7 @@
struct dom_string *qname,
struct dom_document_type *doctype,
struct dom_document **doc,
+ dom_string_charset charset,
dom_alloc alloc, void *pw);
/**
@@ -249,7 +251,12 @@
/* Create a DOM document */
dom_exception dom_document_create(struct dom_implementation *impl,
- dom_alloc alloc, void *pw, struct dom_document **doc);
+ dom_string_charset charset, dom_alloc alloc, void *pw,
+ struct dom_document **doc);
+
+/* Set a document's buffer */
+void dom_document_set_buffer(struct dom_document *doc, uint8_t *buffer,
+ size_t buffer_len);
/* Create a DOM document type */
dom_exception dom_document_type_create(struct dom_string *qname,
Modified: trunk/dom/include/dom/core/implementation.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/implementati...
==============================================================================
--- trunk/dom/include/dom/core/implementation.h (original)
+++ trunk/dom/include/dom/core/implementation.h Sun Sep 30 22:10:50 2007
@@ -12,11 +12,11 @@
#include <dom/core/exceptions.h>
#include <dom/functypes.h>
+#include <dom/core/string.h>
struct dom_document;
struct dom_document_type;
struct dom_implementation;
-struct dom_string;
void dom_implementation_ref(struct dom_implementation *impl);
void dom_implementation_unref(struct dom_implementation *impl);
@@ -37,6 +37,7 @@
struct dom_string *namespace, struct dom_string *qname,
struct dom_document_type *doctype,
struct dom_document **doc,
+ dom_string_charset charset,
dom_alloc alloc, void *pw);
dom_exception dom_implementation_get_feature(
Modified: trunk/dom/include/dom/core/string.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/string.h?rev...
==============================================================================
--- trunk/dom/include/dom/core/string.h (original)
+++ trunk/dom/include/dom/core/string.h Sun Sep 30 22:10:50 2007
@@ -17,6 +17,11 @@
struct dom_document;
struct dom_string;
+typedef enum {
+ DOM_STRING_UTF8,
+ DOM_STRING_UTF16
+} dom_string_charset;
+
/* Claim a reference on a DOM string */
void dom_string_ref(struct dom_string *str);
/* Release a reference on a DOM string */
@@ -34,7 +39,8 @@
/* Create a DOM string from a string of characters that does not belong
* to a document */
dom_exception dom_string_create_from_ptr_no_doc(dom_alloc alloc, void *pw,
- const uint8_t *ptr, size_t len, struct dom_string **str);
+ dom_string_charset charset, const uint8_t *ptr, size_t len,
+ struct dom_string **str);
/* Get a pointer to the string of characters within a DOM string */
dom_exception dom_string_get_data(struct dom_string *str,
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3614&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Sun Sep 30 22:10:50 2007
@@ -56,6 +56,8 @@
struct dom_document {
struct dom_node base; /**< Base node */
+ dom_string_charset charset; /**< Charset of strings in document */
+
struct dom_implementation *impl; /**< Owning implementation */
struct dom_doc_nl *nodelists; /**< List of active nodelists */
@@ -73,10 +75,11 @@
/**
* Create a Document
*
- * \param impl The DOM implementation owning the document
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
- * \param doc Pointer to location to receive created document
+ * \param impl The DOM implementation owning the document
+ * \param charset The charset used for strings in the document
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \param doc Pointer to location to receive created document
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
*
* ::impl will have its reference count increased.
@@ -84,7 +87,8 @@
* The returned document will already be referenced.
*/
dom_exception dom_document_create(struct dom_implementation *impl,
- dom_alloc alloc, void *pw, struct dom_document **doc)
+ dom_string_charset charset, dom_alloc alloc, void *pw,
+ struct dom_document **doc)
{
static const char *names[DOM_NODE_TYPE_COUNT + 1] = {
NULL, /* Unused */
@@ -110,6 +114,7 @@
return DOM_NO_MEM_ERR;
/* Set up document allocation context - must be first */
+ d->charset = charset;
d->alloc = alloc;
d->pw = pw;
@@ -994,6 +999,35 @@
}
/**
+ * Set the document buffer pointer
+ *
+ * \param doc Document to set buffer pointer of
+ * \param buffer Pointer to buffer
+ * \param buffer_len Length of buffer, in bytes
+ *
+ * By calling this, ownership of the buffer is transferred to the document.
+ * It should be called once per document node.
+ */
+void dom_document_set_buffer(struct dom_document *doc, uint8_t *buffer,
+ size_t buffer_len)
+{
+ UNUSED(doc);
+ UNUSED(buffer);
+ UNUSED(buffer_len);
+}
+
+/**
+ * Retrieve the character set used to encode strings in the document
+ *
+ * \param doc The document to get the charset of
+ * \return The charset in use
+ */
+dom_string_charset dom_document_get_charset(struct dom_document *doc)
+{
+ return doc->charset;
+}
+
+/**
* (De)allocate memory with a document's context
*
* \param doc The document context to allocate from
Modified: trunk/dom/src/core/document.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.h?rev=3614&...
==============================================================================
--- trunk/dom/src/core/document.h (original)
+++ trunk/dom/src/core/document.h Sun Sep 30 22:10:50 2007
@@ -12,18 +12,21 @@
#include <stddef.h>
#include <dom/core/node.h>
+#include <dom/core/string.h>
struct dom_document;
struct dom_namednodemap;
struct dom_node;
struct dom_nodelist;
-struct dom_string;
/* Destroy a document */
void dom_document_destroy(struct dom_document *doc);
/* Get base of document buffer */
const uint8_t *dom_document_get_base(struct dom_document *doc);
+
+/* Get the document character set */
+dom_string_charset dom_document_get_charset(struct dom_document *doc);
/* (De)allocate memory */
void *dom_document_alloc(struct dom_document *doc, void *ptr, size_t size);
Modified: trunk/dom/src/core/implementation.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/implementation.c?rev...
==============================================================================
--- trunk/dom/src/core/implementation.c (original)
+++ trunk/dom/src/core/implementation.c Sun Sep 30 22:10:50 2007
@@ -94,6 +94,7 @@
* \param qname The qualified name of the document element
* \param doctype The type of document to create
* \param doc Pointer to location to receive result
+ * \param charset The charset to use for strings in the document
* \param alloc Memory (de)allocation function
* \param pw Pointer to client-specific private data
* \return DOM_NO_ERR on success,
@@ -126,10 +127,11 @@
struct dom_string *namespace, struct dom_string *qname,
struct dom_document_type *doctype,
struct dom_document **doc,
+ dom_string_charset charset,
dom_alloc alloc, void *pw)
{
return impl->create_document(impl, namespace, qname, doctype, doc,
- alloc, pw);
+ charset, alloc, pw);
}
/**
Modified: trunk/dom/src/core/string.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/string.c?rev=3614&r1...
==============================================================================
--- trunk/dom/src/core/string.c (original)
+++ trunk/dom/src/core/string.c Sun Sep 30 22:10:50 2007
@@ -5,6 +5,7 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
+#include <ctype.h>
#include <inttypes.h>
#include <string.h>
@@ -12,6 +13,8 @@
#include "core/document.h"
#include "utils/utils.h"
+#include "utils/utf8.h"
+#include "utils/utf16.h"
/**
* A DOM string
@@ -27,6 +30,8 @@
DOM_STRING_OFFSET,
DOM_STRING_PTR_NODOC
} type; /**< String type */
+
+ dom_string_charset charset; /**< Charset of string */
union {
uint8_t *ptr;
@@ -49,7 +54,8 @@
};
static struct dom_string empty_string = {
- .type = DOM_STRING_CONST_PTR,
+ .type = DOM_STRING_CONST_PTR,
+ .charset = DOM_STRING_UTF8,
.data.ptr = NULL,
.len = 0,
.ctx.doc = NULL,
@@ -116,6 +122,8 @@
ret->type = DOM_STRING_OFFSET;
+ ret->charset = dom_document_get_charset(doc);
+
ret->data.offset = off;
ret->len = len;
@@ -161,6 +169,8 @@
ret->type = DOM_STRING_PTR;
+ ret->charset = dom_document_get_charset(doc);
+
memcpy(ret->data.ptr, ptr, len);
ret->len = len;
@@ -200,6 +210,8 @@
ret->type = DOM_STRING_CONST_PTR;
+ ret->charset = dom_document_get_charset(doc);
+
ret->data.cptr = ptr;
ret->len = len;
@@ -217,11 +229,12 @@
* Create a DOM string from a string of characters that does not belong
* to a document
*
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
- * \param ptr Pointer to string of characters
- * \param len Length, in bytes, of string of characters
- * \param str Pointer to location to receive result
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \param charset The charset of the string
+ * \param ptr Pointer to string of characters
+ * \param len Length, in bytes, of string of characters
+ * \param str Pointer to location to receive result
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
*
* The returned string will already be referenced, so there is no need
@@ -231,7 +244,8 @@
* returned DOM string.
*/
dom_exception dom_string_create_from_ptr_no_doc(dom_alloc alloc, void *pw,
- const uint8_t *ptr, size_t len, struct dom_string **str)
+ dom_string_charset charset, const uint8_t *ptr, size_t len,
+ struct dom_string **str)
{
struct dom_string *ret;
@@ -246,6 +260,8 @@
}
ret->type = DOM_STRING_PTR_NODOC;
+
+ ret->charset = charset;
memcpy(ret->data.ptr, ptr, len);
@@ -324,10 +340,35 @@
if (err != DOM_NO_ERR)
return 1; /* arbitrary */
- if (l1 != l2)
- return 1; /* arbitrary */
-
- return strncmp((const char *) d1, (const char *) d2, l1);
+ while (l1 > 0 && l2 > 0) {
+ uint32_t c1, c2;
+ size_t cl1, cl2;
+ charset_error err;
+
+ err = (s1->charset == DOM_STRING_UTF8)
+ ? _dom_utf8_to_ucs4(d1, l1, &c1, &cl1)
+ : _dom_utf16_to_ucs4(d1, l1, &c1, &cl1);
+ if (err != CHARSET_OK) {
+ }
+
+ err = (s2->charset == DOM_STRING_UTF8)
+ ? _dom_utf8_to_ucs4(d2, l2, &c2, &cl2)
+ : _dom_utf16_to_ucs4(d2, l2, &c2, &cl2);
+ if (err != CHARSET_OK) {
+ }
+
+ if (c1 != c2) {
+ return (int)(c1 - c2);
+ }
+
+ d1 += cl1;
+ d2 += cl2;
+
+ l1 -= cl1;
+ l2 -= cl2;
+ }
+
+ return (int)(l1 - l2);
}
/**
@@ -354,9 +395,35 @@
if (err != DOM_NO_ERR)
return 1; /* arbitrary */
- if (l1 != l2)
- return 1; /* arbitrary */
-
- return strncasecmp((const char *) d1, (const char *) d2, l1);
-}
-
+ while (l1 > 0 && l2 > 0) {
+ uint32_t c1, c2;
+ size_t cl1, cl2;
+ charset_error err;
+
+ err = (s1->charset == DOM_STRING_UTF8)
+ ? _dom_utf8_to_ucs4(d1, l1, &c1, &cl1)
+ : _dom_utf16_to_ucs4(d1, l1, &c1, &cl1);
+ if (err != CHARSET_OK) {
+ }
+
+ err = (s2->charset == DOM_STRING_UTF8)
+ ? _dom_utf8_to_ucs4(d2, l2, &c2, &cl2)
+ : _dom_utf16_to_ucs4(d2, l2, &c2, &cl2);
+ if (err != CHARSET_OK) {
+ }
+
+ /** \todo improved lower-casing algorithm */
+ if (tolower(c1) != tolower(c2)) {
+ return (int)(tolower(c1) - tolower(c2));
+ }
+
+ d1 += cl1;
+ d2 += cl2;
+
+ l1 -= cl1;
+ l2 -= cl2;
+ }
+
+ return (int)(l1 - l2);
+}
+
Modified: trunk/dom/src/utils/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/src/utils/Makefile?rev=3614&r...
==============================================================================
--- trunk/dom/src/utils/Makefile (original)
+++ trunk/dom/src/utils/Makefile Sun Sep 30 22:10:50 2007
@@ -22,7 +22,7 @@
CFLAGS += -I$(CURDIR)
# Objects
-OBJS = namespace
+OBJS = namespace utf8 utf16
.PHONY: clean debug distclean export release setup test
Added: trunk/dom/src/utils/charset_errors.h
URL: http://source.netsurf-browser.org/trunk/dom/src/utils/charset_errors.h?re...
==============================================================================
--- trunk/dom/src/utils/charset_errors.h (added)
+++ trunk/dom/src/utils/charset_errors.h Sun Sep 30 22:10:50 2007
@@ -1,0 +1,19 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_utils_charset_errors_h_
+#define dom_utils_charset_errors_h_
+
+typedef enum {
+ CHARSET_OK, /**< No error */
+ CHARSET_BADPARM, /**< Bad parameters to argument */
+ CHARSET_NEEDDATA, /**< Insufficient data for operation */
+ CHARSET_INVALID /**< Invalid input data */
+} charset_error;
+
+#endif
+
Modified: trunk/dom/src/utils/namespace.c
URL: http://source.netsurf-browser.org/trunk/dom/src/utils/namespace.c?rev=361...
==============================================================================
--- trunk/dom/src/utils/namespace.c (original)
+++ trunk/dom/src/utils/namespace.c Sun Sep 30 22:10:50 2007
@@ -29,6 +29,7 @@
dom_exception err;
err = dom_string_create_from_ptr_no_doc(alloc, pw,
+ DOM_STRING_UTF8,
(const uint8_t *) "http://www.w3.org/XML/1998/namespace",
SLEN("http://www.w3.org/XML/1998/namespace"),
&xml);
@@ -37,6 +38,7 @@
}
err = dom_string_create_from_ptr_no_doc(alloc, pw,
+ DOM_STRING_UTF8,
(const uint8_t *) "http://www.w3.org/2000/xmlns",
SLEN("http://www.w3.org/2000/xmlns"),
&xmlns);
Added: trunk/dom/src/utils/utf16.c
URL: http://source.netsurf-browser.org/trunk/dom/src/utils/utf16.c?rev=3614&vi...
==============================================================================
--- trunk/dom/src/utils/utf16.c (added)
+++ trunk/dom/src/utils/utf16.c Sun Sep 30 22:10:50 2007
@@ -1,0 +1,239 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+/** \file
+ * UTF-16 manipulation functions (implementation).
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "utils/utf16.h"
+
+/**
+ * Convert a UTF-16 sequence into a single UCS4 character
+ *
+ * \param s The sequence to process
+ * \param len Length of sequence
+ * \param ucs4 Pointer to location to receive UCS4 character (host endian)
+ * \param clen Pointer to location to receive byte length of UTF-16 sequence
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf16_to_ucs4(const uint8_t *s, size_t len,
+ uint32_t *ucs4, size_t *clen)
+{
+ const uint16_t *ss = (const uint16_t *) (const void *) s;
+
+ if (s == NULL || ucs4 == NULL || clen == NULL)
+ return CHARSET_BADPARM;
+
+ if (len < 2)
+ return CHARSET_NEEDDATA;
+
+ if (*ss < 0xD800 || *ss > 0xDFFF) {
+ *ucs4 = *ss;
+ *clen = 2;
+ } else if (0xD800 <= *ss && *ss <= 0xBFFF) {
+ if (len < 4)
+ return CHARSET_NEEDDATA;
+
+ if (0xDC00 <= ss[1] && ss[1] <= 0xE000) {
+ *ucs4 = (((s[0] >> 6) & 0x1f) + 1) |
+ ((s[0] & 0x3f) | (s[1] & 0x3ff));
+ *clen = 4;
+ } else {
+ return CHARSET_INVALID;
+ }
+ }
+
+ return CHARSET_OK;
+}
+
+/**
+ * Convert a single UCS4 character into a UTF-16 sequence
+ *
+ * \param ucs4 The character to process (0 <= c <= 0x7FFFFFFF) (host endian)
+ * \param s Pointer to 4 byte long output buffer
+ * \param len Pointer to location to receive length of multibyte sequence
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf16_from_ucs4(uint32_t ucs4, uint8_t *s,
+ size_t *len)
+{
+ uint16_t *ss = (uint16_t *) (void *) s;
+ uint32_t l = 0;
+
+ if (s == NULL || len == NULL)
+ return CHARSET_BADPARM;
+ else if (ucs4 < 0x10000) {
+ *ss = (uint16_t) ucs4;
+ l = 2;
+ } else if (ucs4 < 0x110000) {
+ ss[0] = 0xD800 | (((ucs4 >> 16) & 0x1f) - 1) | (ucs4 >> 10);
+ ss[1] = 0xDC00 | (ucs4 & 0x3ff);
+ l = 4;
+ } else {
+ return CHARSET_INVALID;
+ }
+
+ *len = l;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Calculate the length (in characters) of a bounded UTF-16 string
+ *
+ * \param s The string
+ * \param max Maximum length
+ * \param len Pointer to location to receive length of string
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf16_length(const uint8_t *s, size_t max,
+ size_t *len)
+{
+ const uint16_t *ss = (const uint16_t *) (const void *) s;
+ const uint16_t *end = (const uint16_t *) (const void *) (s + max);
+ int l = 0;
+
+ if (s == NULL || len == NULL)
+ return CHARSET_BADPARM;
+
+ while (ss < end) {
+ if (*ss < 0xD800 || 0xDFFF < *ss)
+ ss++;
+ else
+ ss += 2;
+
+ l++;
+ }
+
+ *len = l;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Calculate the length (in bytes) of a UTF-16 character
+ *
+ * \param s Pointer to start of character
+ * \param len Pointer to location to receive length
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf16_char_byte_length(const uint8_t *s,
+ size_t *len)
+{
+ const uint16_t *ss = (const uint16_t *) (const void *) s;
+
+ if (s == NULL || len == NULL)
+ return CHARSET_BADPARM;
+
+ if (*ss < 0xD800 || 0xDFFF < *ss)
+ *len = 2;
+ else
+ *len = 4;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Find previous legal UTF-16 char in string
+ *
+ * \param s The string
+ * \param off Offset in the string to start at
+ * \param prevoff Pointer to location to receive offset of first byte of
+ * previous legal character
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf16_prev(const uint8_t *s, uint32_t off,
+ uint32_t *prevoff)
+{
+ const uint16_t *ss = (const uint16_t *) (const void *) s;
+
+ if (s == NULL || prevoff == NULL)
+ return CHARSET_BADPARM;
+
+ if (off < 2)
+ *prevoff = 0;
+ else if (ss[-1] < 0xDC00 || ss[-1] > 0xDFFF)
+ *prevoff = off - 2;
+ else
+ *prevoff = (off < 4) ? 0 : off - 4;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Find next legal UTF-16 char in string
+ *
+ * \param s The string (assumed valid)
+ * \param len Maximum offset in string
+ * \param off Offset in the string to start at
+ * \param nextoff Pointer to location to receive offset of first byte of
+ * next legal character
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf16_next(const uint8_t *s, uint32_t len,
+ uint32_t off, uint32_t *nextoff)
+{
+ const uint16_t *ss = (const uint16_t *) (const void *) s;
+
+ if (s == NULL || off >= len || nextoff == NULL)
+ return CHARSET_BADPARM;
+
+ if (len - off < 4)
+ *nextoff = len;
+ else if (ss[1] < 0xD800 || ss[1] > 0xDBFF)
+ *nextoff = off + 2;
+ else
+ *nextoff = (len - off < 6) ? len : off + 4;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Find next legal UTF-16 char in string
+ *
+ * \param s The string (assumed to be of dubious validity)
+ * \param len Maximum offset in string
+ * \param off Offset in the string to start at
+ * \param nextoff Pointer to location to receive offset of first byte of
+ * next legal character
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf16_next_paranoid(const uint8_t *s,
+ uint32_t len, uint32_t off, uint32_t *nextoff)
+{
+ const uint16_t *ss = (const uint16_t *) (const void *) s;
+
+ if (s == NULL || off >= len || nextoff == NULL)
+ return CHARSET_BADPARM;
+
+ while (1) {
+ if (len - off < 4) {
+ return CHARSET_NEEDDATA;
+ } else if (ss[1] < 0xD800 || ss[1] > 0xDFFF) {
+ *nextoff = off + 2;
+ break;
+ } else if (ss[1] >= 0xD800 && ss[1] <= 0xDBFF) {
+ if (len - off < 6)
+ return CHARSET_NEEDDATA;
+
+ if (ss[2] >= 0xDC00 && ss[2] <= 0xDFFF) {
+ *nextoff = off + 4;
+ break;
+ } else {
+ ss++;
+ off += 2;
+ }
+ }
+ }
+
+ return CHARSET_OK;
+}
+
Added: trunk/dom/src/utils/utf16.h
URL: http://source.netsurf-browser.org/trunk/dom/src/utils/utf16.h?rev=3614&vi...
==============================================================================
--- trunk/dom/src/utils/utf16.h (added)
+++ trunk/dom/src/utils/utf16.h Sun Sep 30 22:10:50 2007
@@ -1,0 +1,38 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+/** \file
+ * UTF-16 manipulation functions (interface).
+ */
+
+#ifndef dom_utils_utf16_h_
+#define dom_utils_utf16_h_
+
+#include <inttypes.h>
+
+#include "utils/charset_errors.h"
+
+inline charset_error _dom_utf16_to_ucs4(const uint8_t *s, size_t len,
+ uint32_t *ucs4, size_t *clen);
+inline charset_error _dom_utf16_from_ucs4(uint32_t ucs4, uint8_t *s,
+ size_t *len);
+
+inline charset_error _dom_utf16_length(const uint8_t *s, size_t max,
+ size_t *len);
+inline charset_error _dom_utf16_char_byte_length(const uint8_t *s,
+ size_t *len);
+
+inline charset_error _dom_utf16_prev(const uint8_t *s, uint32_t off,
+ uint32_t *prevoff);
+inline charset_error _dom_utf16_next(const uint8_t *s, uint32_t len,
+ uint32_t off, uint32_t *nextoff);
+
+inline charset_error _dom_utf16_next_paranoid(const uint8_t *s,
+ uint32_t len, uint32_t off, uint32_t *nextoff);
+
+#endif
+
Added: trunk/dom/src/utils/utf8.c
URL: http://source.netsurf-browser.org/trunk/dom/src/utils/utf8.c?rev=3614&vie...
==============================================================================
--- trunk/dom/src/utils/utf8.c (added)
+++ trunk/dom/src/utils/utf8.c Sun Sep 30 22:10:50 2007
@@ -1,0 +1,368 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+/** \file
+ * UTF-8 manipulation functions (implementation).
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "utils/utf8.h"
+
+/** Number of continuation bytes for a given start byte */
+static const uint8_t numContinuations[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
+};
+
+/**
+ * Convert a UTF-8 multibyte sequence into a single UCS4 character
+ *
+ * Encoding of UCS values outside the UTF-16 plane has been removed from
+ * RFC3629. This function conforms to RFC2279, however.
+ *
+ * \param s The sequence to process
+ * \param len Length of sequence
+ * \param ucs4 Pointer to location to receive UCS4 character (host endian)
+ * \param clen Pointer to location to receive byte length of UTF-8 sequence
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf8_to_ucs4(const uint8_t *s, size_t len,
+ uint32_t *ucs4, size_t *clen)
+{
+ if (s == NULL || ucs4 == NULL || clen == NULL)
+ return CHARSET_BADPARM;
+
+ if (len == 0)
+ return CHARSET_NEEDDATA;
+
+ if (*s < 0x80) {
+ *ucs4 = *s;
+ *clen = 1;
+ } else if ((*s & 0xE0) == 0xC0) {
+ if (len < 2)
+ return CHARSET_NEEDDATA;
+ else if ((*(s+1) & 0xC0) != 0x80)
+ return CHARSET_INVALID;
+ else {
+ *ucs4 = ((*s & 0x1F) << 6) | (*(s+1) & 0x3F);
+ *clen = 2;
+ }
+ } else if ((*s & 0xF0) == 0xE0) {
+ if (len < 3)
+ return CHARSET_NEEDDATA;
+ else if ((*(s+1) & 0xC0) != 0x80 ||
+ (*(s+2) & 0xC0) != 0x80)
+ return CHARSET_INVALID;
+ else {
+ *ucs4 = ((*s & 0x0F) << 12) |
+ ((*(s+1) & 0x3F) << 6) |
+ (*(s+2) & 0x3F);
+ *clen = 3;
+ }
+ } else if ((*s & 0xF8) == 0xF0) {
+ if (len < 4)
+ return CHARSET_NEEDDATA;
+ else if ((*(s+1) & 0xC0) != 0x80 ||
+ (*(s+2) & 0xC0) != 0x80 ||
+ (*(s+3) & 0xC0) != 0x80)
+ return CHARSET_INVALID;
+ else {
+ *ucs4 = ((*s & 0x0F) << 18) |
+ ((*(s+1) & 0x3F) << 12) |
+ ((*(s+2) & 0x3F) << 6) |
+ (*(s+3) & 0x3F);
+ *clen = 4;
+ }
+ } else if ((*s & 0xFC) == 0xF8) {
+ if (len < 5)
+ return CHARSET_NEEDDATA;
+ else if ((*(s+1) & 0xC0) != 0x80 ||
+ (*(s+2) & 0xC0) != 0x80 ||
+ (*(s+3) & 0xC0) != 0x80 ||
+ (*(s+4) & 0xC0) != 0x80)
+ return CHARSET_INVALID;
+ else {
+ *ucs4 = ((*s & 0x0F) << 24) |
+ ((*(s+1) & 0x3F) << 18) |
+ ((*(s+2) & 0x3F) << 12) |
+ ((*(s+3) & 0x3F) << 6) |
+ (*(s+4) & 0x3F);
+ *clen = 5;
+ }
+ } else if ((*s & 0xFE) == 0xFC) {
+ if (len < 6)
+ return CHARSET_NEEDDATA;
+ else if ((*(s+1) & 0xC0) != 0x80 ||
+ (*(s+2) & 0xC0) != 0x80 ||
+ (*(s+3) & 0xC0) != 0x80 ||
+ (*(s+4) & 0xC0) != 0x80 ||
+ (*(s+5) & 0xC0) != 0x80)
+ return CHARSET_INVALID;
+ else {
+ *ucs4 = ((*s & 0x0F) << 28) |
+ ((*(s+1) & 0x3F) << 24) |
+ ((*(s+2) & 0x3F) << 18) |
+ ((*(s+3) & 0x3F) << 12) |
+ ((*(s+4) & 0x3F) << 6) |
+ (*(s+5) & 0x3F);
+ *clen = 6;
+ }
+ } else {
+ return CHARSET_INVALID;
+ }
+
+ return CHARSET_OK;
+}
+
+/**
+ * Convert a single UCS4 character into a UTF-8 multibyte sequence
+ *
+ * Encoding of UCS values outside the UTF-16 plane has been removed from
+ * RFC3629. This function conforms to RFC2279, however.
+ *
+ * \param ucs4 The character to process (0 <= c <= 0x7FFFFFFF) (host endian)
+ * \param s Pointer to 6 byte long output buffer
+ * \param len Pointer to location to receive length of multibyte sequence
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf8_from_ucs4(uint32_t ucs4, uint8_t *s,
+ size_t *len)
+{
+ uint32_t l = 0;
+
+ if (s == NULL || len == NULL)
+ return CHARSET_BADPARM;
+ else if (ucs4 < 0x80) {
+ *s = (uint8_t) ucs4;
+ l = 1;
+ } else if (ucs4 < 0x800) {
+ *s = 0xC0 | ((ucs4 >> 6) & 0x1F);
+ *(s+1) = 0x80 | (ucs4 & 0x3F);
+ l = 2;
+ } else if (ucs4 < 0x10000) {
+ *s = 0xE0 | ((ucs4 >> 12) & 0xF);
+ *(s+1) = 0x80 | ((ucs4 >> 6) & 0x3F);
+ *(s+2) = 0x80 | (ucs4 & 0x3F);
+ l = 3;
+ } else if (ucs4 < 0x200000) {
+ *s = 0xF0 | ((ucs4 >> 18) & 0x7);
+ *(s+1) = 0x80 | ((ucs4 >> 12) & 0x3F);
+ *(s+2) = 0x80 | ((ucs4 >> 6) & 0x3F);
+ *(s+3) = 0x80 | (ucs4 & 0x3F);
+ l = 4;
+ } else if (ucs4 < 0x4000000) {
+ *s = 0xF8 | ((ucs4 >> 24) & 0x3);
+ *(s+1) = 0x80 | ((ucs4 >> 18) & 0x3F);
+ *(s+2) = 0x80 | ((ucs4 >> 12) & 0x3F);
+ *(s+3) = 0x80 | ((ucs4 >> 6) & 0x3F);
+ *(s+4) = 0x80 | (ucs4 & 0x3F);
+ l = 5;
+ } else if (ucs4 <= 0x7FFFFFFF) {
+ *s = 0xFC | ((ucs4 >> 30) & 0x1);
+ *(s+1) = 0x80 | ((ucs4 >> 24) & 0x3F);
+ *(s+2) = 0x80 | ((ucs4 >> 18) & 0x3F);
+ *(s+3) = 0x80 | ((ucs4 >> 12) & 0x3F);
+ *(s+4) = 0x80 | ((ucs4 >> 6) & 0x3F);
+ *(s+5) = 0x80 | (ucs4 & 0x3F);
+ l = 6;
+ } else {
+ return CHARSET_INVALID;
+ }
+
+ *len = l;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Calculate the length (in characters) of a bounded UTF-8 string
+ *
+ * \param s The string
+ * \param max Maximum length
+ * \param len Pointer to location to receive length of string
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf8_length(const uint8_t *s, size_t max,
+ size_t *len)
+{
+ const uint8_t *end = s + max;
+ int l = 0;
+
+ if (s == NULL || len == NULL)
+ return CHARSET_BADPARM;
+
+ while (s < end) {
+ if ((*s & 0x80) == 0x00)
+ s += 1;
+ else if ((*s & 0xE0) == 0xC0)
+ s += 2;
+ else if ((*s & 0xF0) == 0xE0)
+ s += 3;
+ else if ((*s & 0xF8) == 0xF0)
+ s += 4;
+ else if ((*s & 0xFC) == 0xF8)
+ s += 5;
+ else if ((*s & 0xFE) == 0xFC)
+ s += 6;
+ else
+ return CHARSET_INVALID;
+ l++;
+ }
+
+ *len = l;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Calculate the length (in bytes) of a UTF-8 character
+ *
+ * \param s Pointer to start of character
+ * \param len Pointer to location to receive length
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf8_char_byte_length(const uint8_t *s,
+ size_t *len)
+{
+ if (s == NULL || len == NULL)
+ return CHARSET_BADPARM;
+
+ *len = numContinuations[s[0]] + 1 /* Start byte */;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Find previous legal UTF-8 char in string
+ *
+ * \param s The string
+ * \param off Offset in the string to start at
+ * \param prevoff Pointer to location to receive offset of first byte of
+ * previous legal character
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf8_prev(const uint8_t *s, uint32_t off,
+ uint32_t *prevoff)
+{
+ if (s == NULL || prevoff == NULL)
+ return CHARSET_BADPARM;
+
+ while (off != 0 && (s[--off] & 0xC0) == 0x80)
+ /* do nothing */;
+
+ *prevoff = off;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Find next legal UTF-8 char in string
+ *
+ * \param s The string (assumed valid)
+ * \param len Maximum offset in string
+ * \param off Offset in the string to start at
+ * \param nextoff Pointer to location to receive offset of first byte of
+ * next legal character
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf8_next(const uint8_t *s, uint32_t len,
+ uint32_t off, uint32_t *nextoff)
+{
+ if (s == NULL || off >= len || nextoff == NULL)
+ return CHARSET_BADPARM;
+
+ /* Skip current start byte (if present - may be mid-sequence) */
+ if (s[off] < 0x80 || (s[off] & 0xC0) == 0xC0)
+ off++;
+
+ while (off < len && (s[off] & 0xC0) == 0x80)
+ off++;
+
+ *nextoff = off;
+
+ return CHARSET_OK;
+}
+
+/**
+ * Find next legal UTF-8 char in string
+ *
+ * \param s The string (assumed to be of dubious validity)
+ * \param len Maximum offset in string
+ * \param off Offset in the string to start at
+ * \param nextoff Pointer to location to receive offset of first byte of
+ * next legal character
+ * \return CHARSET_OK on success, appropriate error otherwise
+ */
+inline charset_error _dom_utf8_next_paranoid(const uint8_t *s, uint32_t len,
+ uint32_t off, uint32_t *nextoff)
+{
+ bool valid;
+
+ if (s == NULL || off >= len || nextoff == NULL)
+ return CHARSET_BADPARM;
+
+ /* Skip current start byte (if present - may be mid-sequence) */
+ if (s[off] < 0x80 || (s[off] & 0xC0) == 0xC0)
+ off++;
+
+ while (1) {
+ /* Find next possible start byte */
+ while (off < len && (s[off] & 0xC0) == 0x80)
+ off++;
+
+ /* Ran off end of data */
+ if (off == len || off + numContinuations[s[off]] >= len)
+ return CHARSET_NEEDDATA;
+
+ /* Found if start byte is ascii,
+ * or next n bytes are valid continuations */
+ valid = true;
+
+ switch (numContinuations[s[off]]) {
+ case 5:
+ valid &= ((s[off + 5] & 0xC0) == 0x80);
+ case 4:
+ valid &= ((s[off + 4] & 0xC0) == 0x80);
+ case 3:
+ valid &= ((s[off + 3] & 0xC0) == 0x80);
+ case 2:
+ valid &= ((s[off + 2] & 0xC0) == 0x80);
+ case 1:
+ valid &= ((s[off + 1] & 0xC0) == 0x80);
+ case 0:
+ valid &= (s[off + 0] < 0x80);
+ }
+
+ if (valid)
+ break;
+
+ /* Otherwise, skip this (invalid) start byte and try again */
+ off++;
+ }
+
+ *nextoff = off;
+
+ return CHARSET_OK;
+}
+
Added: trunk/dom/src/utils/utf8.h
URL: http://source.netsurf-browser.org/trunk/dom/src/utils/utf8.h?rev=3614&vie...
==============================================================================
--- trunk/dom/src/utils/utf8.h (added)
+++ trunk/dom/src/utils/utf8.h Sun Sep 30 22:10:50 2007
@@ -1,0 +1,38 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+/** \file
+ * UTF-8 manipulation functions (interface).
+ */
+
+#ifndef dom_utils_utf8_h_
+#define dom_utils_utf8_h_
+
+#include <inttypes.h>
+
+#include "utils/charset_errors.h"
+
+inline charset_error _dom_utf8_to_ucs4(const uint8_t *s, size_t len,
+ uint32_t *ucs4, size_t *clen);
+inline charset_error _dom_utf8_from_ucs4(uint32_t ucs4, uint8_t *s,
+ size_t *len);
+
+inline charset_error _dom_utf8_length(const uint8_t *s, size_t max,
+ size_t *len);
+inline charset_error _dom_utf8_char_byte_length(const uint8_t *s,
+ size_t *len);
+
+inline charset_error _dom_utf8_prev(const uint8_t *s, uint32_t off,
+ uint32_t *prevoff);
+inline charset_error _dom_utf8_next(const uint8_t *s, uint32_t len,
+ uint32_t off, uint32_t *nextoff);
+
+inline charset_error _dom_utf8_next_paranoid(const uint8_t *s, uint32_t len,
+ uint32_t off, uint32_t *nextoff);
+
+#endif
+
15 years, 11 months
r3612 rjek - /trunk/netsurf/gtk/gtk_options.c
by netsurf@semichrome.net
Author: rjek
Date: Sun Sep 30 01:55:55 2007
New Revision: 3612
URL: http://source.netsurf-browser.org?rev=3612&view=rev
Log:
Tweaks to nsgtk's proxy option saving
Modified:
trunk/netsurf/gtk/gtk_options.c
Modified: trunk/netsurf/gtk/gtk_options.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_options.c?rev=361...
==============================================================================
--- trunk/netsurf/gtk/gtk_options.c (original)
+++ trunk/netsurf/gtk/gtk_options.c Sun Sep 30 01:55:55 2007
@@ -122,6 +122,7 @@
void nsgtk_options_load(void) {
char b[20];
+ int proxytype = 0;
SET_ENTRY(entryHomePageURL,
option_homepage_url ? option_homepage_url : "");
@@ -129,7 +130,22 @@
SET_CHECK(checkDisplayRecentURLs, option_url_suggestion);
SET_CHECK(checkSendReferer, option_send_referer);
- SET_COMBO(comboProxyType, option_http_proxy_auth);
+ switch (option_http_proxy_auth) {
+ case OPTION_HTTP_PROXY_AUTH_NONE:
+ proxytype = 1;
+ break;
+ case OPTION_HTTP_PROXY_AUTH_BASIC:
+ proxytype = 2;
+ break;
+ case OPTION_HTTP_PROXY_AUTH_NTLM:
+ proxytype = 3;
+ break;
+ }
+
+ if (option_http_proxy == false)
+ proxytype = 0;
+
+ SET_COMBO(comboProxyType, proxytype);
SET_ENTRY(entryProxyHost,
option_http_proxy_host ? option_http_proxy_host : "");
snprintf(b, 20, "%d", option_http_proxy_port);
@@ -177,20 +193,26 @@
GET_CHECK(checkDisplayRecentURLs, option_url_suggestion);
GET_COMBO(comboProxyType, i);
- option_http_proxy = (i > 0) ? true : false;
+ LOG(("proxy type: %d", i));
switch (i)
{
case 0:
+ option_http_proxy = false;
+ option_http_proxy_auth = OPTION_HTTP_PROXY_AUTH_NONE;
case 1:
+ option_http_proxy = true;
option_http_proxy_auth = OPTION_HTTP_PROXY_AUTH_NONE;
break;
case 2:
+ option_http_proxy = true;
option_http_proxy_auth = OPTION_HTTP_PROXY_AUTH_BASIC;
break;
case 3:
+ option_http_proxy = true;
option_http_proxy_auth = OPTION_HTTP_PROXY_AUTH_NTLM;
break;
default:
+ option_http_proxy = false;
option_http_proxy_auth = OPTION_HTTP_PROXY_AUTH_NONE;
break;
}
15 years, 11 months
r3611 rjek - /trunk/netsurf/gtk/gtk_options.c
by netsurf@semichrome.net
Author: rjek
Date: Sun Sep 30 01:31:50 2007
New Revision: 3611
URL: http://source.netsurf-browser.org?rev=3611&view=rev
Log:
Make loading/saving of memory cache size option work in nsgtk
Modified:
trunk/netsurf/gtk/gtk_options.c
Modified: trunk/netsurf/gtk/gtk_options.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_options.c?rev=361...
==============================================================================
--- trunk/netsurf/gtk/gtk_options.c (original)
+++ trunk/netsurf/gtk/gtk_options.c Sun Sep 30 01:31:50 2007
@@ -157,7 +157,7 @@
SET_SPIN(spinDefaultSize, option_font_size / 10);
SET_SPIN(spinMinimumSize, option_font_min_size / 10);
- SET_SPIN(spinMemoryCacheSize, option_memory_cache_size);
+ SET_SPIN(spinMemoryCacheSize, option_memory_cache_size >> 20);
SET_SPIN(spinDiscCacheAge, option_disc_cache_age);
}
@@ -224,6 +224,9 @@
GET_SPIN(spinMinimumSize, option_font_min_size);
option_font_min_size *= 10;
+ GET_SPIN(spinMemoryCacheSize, option_memory_cache_size);
+ option_memory_cache_size <<= 20;
+
options_write(options_file_location);
nsgtk_reflow_all_windows();
}
15 years, 11 months
r3610 jmb - /trunk/dom/src/core/characterdata.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Sep 30 00:44:36 2007
New Revision: 3610
URL: http://source.netsurf-browser.org?rev=3610&view=rev
Log:
Implement dom_characterdata_get_data()
Implement dom_characterdata_set_data()
Modified:
trunk/dom/src/core/characterdata.c
Modified: trunk/dom/src/core/characterdata.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.c?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.c (original)
+++ trunk/dom/src/core/characterdata.c Sun Sep 30 00:44:36 2007
@@ -10,6 +10,7 @@
#include "core/characterdata.h"
#include "core/document.h"
+#include "core/node.h"
#include "utils/utils.h"
/**
@@ -63,10 +64,14 @@
dom_exception dom_characterdata_get_data(struct dom_characterdata *cdata,
struct dom_string **data)
{
- UNUSED(cdata);
- UNUSED(data);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *c = (struct dom_node *) cdata;
+
+ if (c->value != NULL) {
+ dom_string_ref(c->value);
+ }
+ *data = c->value;
+
+ return DOM_NO_ERR;
}
/**
@@ -84,10 +89,20 @@
dom_exception dom_characterdata_set_data(struct dom_characterdata *cdata,
struct dom_string *data)
{
- UNUSED(cdata);
- UNUSED(data);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *c = (struct dom_node *) cdata;
+
+ if (_dom_node_readonly(c)) {
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ if (c->value != NULL) {
+ dom_string_unref(c->value);
+ }
+
+ dom_string_ref(data);
+ c->value = data;
+
+ return DOM_NO_ERR;
}
/**
15 years, 11 months
r3609 jmb - /trunk/dom/src/core/namednodemap.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Sep 30 00:35:22 2007
New Revision: 3609
URL: http://source.netsurf-browser.org?rev=3609&view=rev
Log:
Implement dom_namednodemap_get_named_item_ns()
Implement dom_namednodemap_set_named_item_ns()
Implement dom_namednodemap_remove_named_item_ns()
Modified:
trunk/dom/src/core/namednodemap.c
Modified: trunk/dom/src/core/namednodemap.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/namednodemap.c?rev=3...
==============================================================================
--- trunk/dom/src/core/namednodemap.c (original)
+++ trunk/dom/src/core/namednodemap.c Sun Sep 30 00:35:22 2007
@@ -385,12 +385,38 @@
struct dom_namednodemap *map, struct dom_string *namespace,
struct dom_string *localname, struct dom_node **node)
{
- UNUSED(map);
- UNUSED(namespace);
- UNUSED(localname);
- UNUSED(node);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *cur;
+
+ /** \todo ensure XML feature is supported */
+
+ switch (map->type) {
+ case DOM_ATTRIBUTE_NODE:
+ cur = dom_element_get_first_attribute(
+ (struct dom_element *) map->head);
+ break;
+ case DOM_NOTATION_NODE:
+ case DOM_ENTITY_NODE:
+ /** \todo handle notation and entity nodes */
+ default:
+ return DOM_NOT_SUPPORTED_ERR;
+ break;
+ }
+
+ for (; cur != NULL; cur = cur->next) {
+ if (((namespace == NULL && cur->namespace == NULL) ||
+ (namespace != NULL &&
+ dom_string_cmp(cur->namespace, namespace) == 0)) &&
+ dom_string_cmp(cur->name, localname) == 0) {
+ break;
+ }
+ }
+
+ if (cur != NULL) {
+ dom_node_ref(cur);
+ }
+ *node = cur;
+
+ return DOM_NO_ERR;
}
/**
@@ -426,11 +452,47 @@
struct dom_namednodemap *map, struct dom_node *arg,
struct dom_node **node)
{
- UNUSED(map);
- UNUSED(arg);
- UNUSED(node);
-
- return DOM_NOT_SUPPORTED_ERR;
+ dom_exception err;
+
+ /** \todo ensure XML feature is supported */
+
+ /* Ensure arg and map belong to the same document */
+ if (arg->owner != map->owner)
+ return DOM_WRONG_DOCUMENT_ERR;
+
+ /* Ensure map is writable */
+ if (_dom_node_readonly(map->head))
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+
+ /* Ensure arg isn't attached to another element */
+ if (arg->type == DOM_ATTRIBUTE_NODE && arg->parent != NULL &&
+ arg->parent != map->head)
+ return DOM_INUSE_ATTRIBUTE_ERR;
+
+ /* Ensure arg is permitted in the map */
+ if (arg->type != map->type)
+ return DOM_HIERARCHY_REQUEST_ERR;
+
+ /* Now delegate to the container-specific function.
+ * NamedNodeMaps are live, so this is fine. */
+ switch (map->type) {
+ case DOM_ATTRIBUTE_NODE:
+ err = dom_element_set_attribute_node_ns(
+ (struct dom_element *) map->head,
+ (struct dom_attr *) arg,
+ (struct dom_attr **) node);
+ break;
+ case DOM_NOTATION_NODE:
+ case DOM_ENTITY_NODE:
+ /** \todo handle notation and entity nodes */
+ default:
+ err = DOM_NOT_SUPPORTED_ERR;
+ break;
+ }
+
+ /* Reference counting is handled by the container-specific call */
+
+ return err;
}
/**
@@ -456,12 +518,46 @@
struct dom_namednodemap *map, struct dom_string *namespace,
struct dom_string *localname, struct dom_node **node)
{
- UNUSED(map);
- UNUSED(namespace);
- UNUSED(localname);
- UNUSED(node);
-
- return DOM_NOT_SUPPORTED_ERR;
+ dom_exception err;
+
+ /** \todo ensure XML feature is supported */
+
+ /* Ensure map is writable */
+ if (_dom_node_readonly(map->head))
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+
+ /* Now delegate to the container-specific function.
+ * NamedNodeMaps are live, so this is fine. */
+ switch (map->type) {
+ case DOM_ATTRIBUTE_NODE:
+ {
+ struct dom_attr *attr;
+
+ err = dom_element_get_attribute_node_ns(
+ (struct dom_element *) map->head,
+ namespace, localname, &attr);
+ if (err == DOM_NO_ERR) {
+ err = dom_element_remove_attribute_node(
+ (struct dom_element *) map->head,
+ attr, (struct dom_attr **) node);
+ if (err == DOM_NO_ERR) {
+ /* No longer want attr */
+ dom_node_unref((struct dom_node *) attr);
+ }
+ }
+ }
+ break;
+ case DOM_NOTATION_NODE:
+ case DOM_ENTITY_NODE:
+ /** \todo handle notation and entity nodes */
+ default:
+ err = DOM_NOT_SUPPORTED_ERR;
+ break;
+ }
+
+ /* Reference counting is handled by the container-specific call */
+
+ return err;
}
/**
15 years, 11 months
r3608 jmb - /trunk/dom/src/core/element.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Sep 29 23:45:52 2007
New Revision: 3608
URL: http://source.netsurf-browser.org?rev=3608&view=rev
Log:
Implement dom_element_get_attribute_ns()
Implement dom_element_set_attribute_ns()
Implement dom_element_remove_attribute_ns()
Implement dom_element_get_attribute_node_ns()
Implement dom_element_set_attribute_node_ns()
Implement dom_element_has_attribute_ns()
Modified:
trunk/dom/src/core/element.c
Modified: trunk/dom/src/core/element.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/element.c?rev=3608&r...
==============================================================================
--- trunk/dom/src/core/element.c (original)
+++ trunk/dom/src/core/element.c Sat Sep 29 23:45:52 2007
@@ -16,6 +16,7 @@
#include "core/document.h"
#include "core/element.h"
#include "core/node.h"
+#include "utils/namespace.h"
#include "utils/utils.h"
/**
@@ -504,7 +505,7 @@
* Retrieve an attribute from an element by namespace/localname
*
* \param element The element to retrieve attribute from
- * \param namespace The attribute's namespace URI
+ * \param namespace The attribute's namespace URI, or NULL
* \param localname The attribute's local name
* \param value Pointer to location to receive attribute's value
* \return DOM_NO_ERR on success,
@@ -521,12 +522,27 @@
struct dom_string *namespace, struct dom_string *localname,
struct dom_string **value)
{
- UNUSED(element);
- UNUSED(namespace);
- UNUSED(localname);
- UNUSED(value);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *a = (struct dom_node *) element->attributes;
+
+ /** \todo ensure implementation supports XML */
+
+ /* Search attributes, looking for namespace/localname pair */
+ for (; a != NULL; a = a->next) {
+ if (((namespace == NULL && a->namespace == NULL) ||
+ (namespace != NULL &&
+ dom_string_cmp(a->namespace, namespace) == 0)) &&
+ dom_string_cmp(a->name, localname) == 0)
+ break;
+ }
+
+ /* Fill in value */
+ if (a == NULL) {
+ *value = NULL;
+ } else {
+ dom_attr_get_value(((struct dom_attr *) a), value);
+ }
+
+ return DOM_NO_ERR;
}
/**
@@ -562,12 +578,100 @@
struct dom_string *namespace, struct dom_string *qname,
struct dom_string *value)
{
- UNUSED(element);
- UNUSED(namespace);
- UNUSED(qname);
- UNUSED(value);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *e = (struct dom_node *) element;
+ struct dom_node *a = (struct dom_node *) element->attributes;
+ struct dom_string *prefix, *localname;
+ dom_exception err;
+
+ /** \todo ensure XML feature is supported */
+
+ /* Validate name */
+ err = _dom_namespace_validate_qname(qname, namespace);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ /* Ensure element can be written to */
+ if (_dom_node_readonly(e)) {
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ /* Decompose QName */
+ err = _dom_namespace_split_qname(qname, e->owner, &prefix, &localname);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ /* Search for existing attribute with same namespace/localname */
+ for (; a != NULL; a = a->next) {
+ if (((namespace == NULL && a->namespace == NULL) ||
+ (namespace != NULL &&
+ dom_string_cmp(a->namespace, namespace) == 0)) &&
+ dom_string_cmp(a->name, localname) == 0)
+ break;
+ }
+
+ if (a != NULL) {
+ /* Found an existing attribute, so replace its prefix & value */
+ dom_exception err;
+
+ err = dom_node_set_prefix(a, prefix);
+ if (err != DOM_NO_ERR) {
+ if (prefix != NULL) {
+ dom_string_unref(prefix);
+ }
+ dom_string_unref(localname);
+ return err;
+ }
+
+ err = dom_attr_set_value((struct dom_attr *) a, value);
+ if (err != DOM_NO_ERR) {
+ if (prefix != NULL) {
+ dom_string_unref(prefix);
+ }
+ dom_string_unref(localname);
+ return err;
+ }
+ } else {
+ /* No existing attribute, so create one */
+ dom_exception err;
+ struct dom_attr *attr;
+
+ err = dom_attr_create(e->owner, localname,
+ namespace, prefix, &attr);
+ if (err != DOM_NO_ERR) {
+ if (prefix != NULL) {
+ dom_string_unref(prefix);
+ }
+ dom_string_unref(localname);
+ return err;
+ }
+
+ /* Set its value */
+ err = dom_attr_set_value(attr, value);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) attr);
+
+ if (prefix != NULL) {
+ dom_string_unref(prefix);
+ }
+ dom_string_unref(localname);
+ return err;
+ }
+
+ a = (struct dom_node *) attr;
+
+ /* And insert it into the element */
+ a->previous = NULL;
+ a->next = (struct dom_node *) element->attributes;
+
+ if (a->next != NULL)
+ a->next->previous = a;
+
+ element->attributes = attr;
+ }
+
+ return DOM_NO_ERR;
}
/**
@@ -587,11 +691,43 @@
dom_exception dom_element_remove_attribute_ns(struct dom_element *element,
struct dom_string *namespace, struct dom_string *localname)
{
- UNUSED(element);
- UNUSED(namespace);
- UNUSED(localname);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *e = (struct dom_node *) element;
+ struct dom_node *a = (struct dom_node *) element->attributes;
+
+ /** \todo ensure XML feature is supported */
+
+ /* Ensure element can be written to */
+ if (_dom_node_readonly(e))
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+
+ /* Search for existing attribute with same namespace/localname */
+ for (; a != NULL; a = a->next) {
+ if (((namespace == NULL && a->namespace == NULL) ||
+ (namespace != NULL &&
+ dom_string_cmp(a->namespace, namespace) == 0)) &&
+ dom_string_cmp(a->name, localname) == 0)
+ break;
+ }
+
+ /* Detach attr node from list */
+ if (a != NULL) {
+ if (a->previous != NULL)
+ a->previous->next = a->next;
+ else
+ element->attributes = (struct dom_attr *) a->next;
+
+ if (a->next != NULL)
+ a->next->previous = a->previous;
+
+ a->previous = a->next = a->parent = NULL;
+
+ /* And destroy attr */
+ dom_node_unref(a);
+ }
+
+ /** \todo defaulted attribute handling */
+
+ return DOM_NO_ERR;
}
/**
@@ -615,12 +751,24 @@
struct dom_string *namespace, struct dom_string *localname,
struct dom_attr **result)
{
- UNUSED(element);
- UNUSED(namespace);
- UNUSED(localname);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *a = (struct dom_node *) element->attributes;
+
+ /** \todo ensure XML feature is supported */
+
+ /* Search attributes, looking for namespace/localname */
+ for (; a != NULL; a = a->next) {
+ if (((namespace == NULL && a->namespace == NULL) ||
+ (namespace != NULL &&
+ dom_string_cmp(a->namespace, namespace) == 0)) &&
+ dom_string_cmp(a->name, localname) == 0)
+ break;
+ }
+
+ if (a != NULL)
+ dom_node_ref(a);
+ *result = (struct dom_attr *) a;
+
+ return DOM_NO_ERR;
}
/**
@@ -648,11 +796,81 @@
dom_exception dom_element_set_attribute_node_ns(struct dom_element *element,
struct dom_attr *attr, struct dom_attr **result)
{
- UNUSED(element);
- UNUSED(attr);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *e = (struct dom_node *) element;
+ struct dom_node *a = (struct dom_node *) attr;
+ struct dom_attr *prev = NULL;
+
+ /** \todo ensure XML feature is supported */
+
+ /* Ensure element and attribute belong to the same document */
+ if (e->owner != a->owner)
+ return DOM_WRONG_DOCUMENT_ERR;
+
+ /* Ensure element can be written to */
+ if (_dom_node_readonly(e))
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+
+ /* Ensure attribute isn't attached to another element */
+ if (a->parent != NULL && a->parent != e)
+ return DOM_INUSE_ATTRIBUTE_ERR;
+
+ /* Attach attr to element, if not already attached */
+ if (a->parent == NULL) {
+
+ /* Search for existing attribute with same namespace/localname */
+ prev = element->attributes;
+ while (prev != NULL) {
+ struct dom_node *p = (struct dom_node *) prev;
+
+ if (((a->namespace == NULL && p->namespace == NULL) ||
+ (a->namespace != NULL &&
+ dom_string_cmp(a->namespace,
+ p->namespace) == 0)) &&
+ dom_string_cmp(a->name, p->name) == 0)
+ break;
+
+ prev = (struct dom_attr *) p->next;
+ }
+
+ a->parent = e;
+
+ if (prev != NULL) {
+ /* Found an existing attribute, so replace it */
+ struct dom_node *p = (struct dom_node *) prev;
+
+ a->previous = p->previous;
+ a->next = p->next;
+
+ if (a->previous != NULL)
+ a->previous->next = a;
+ else
+ element->attributes = attr;
+
+ if (a->next != NULL)
+ a->next->previous = a;
+
+ /* Invalidate existing attribute's location info */
+ p->next = NULL;
+ p->previous = NULL;
+ p->parent = NULL;
+ } else {
+ /* No existing attribute, so insert at front of list */
+ a->previous = NULL;
+ a->next = (struct dom_node *) element->attributes;
+
+ if (a->next != NULL)
+ a->next->previous = a;
+
+ element->attributes = attr;
+ }
+ }
+
+ if (prev != NULL)
+ dom_node_ref((struct dom_node *) prev);
+
+ *result = prev;
+
+ return DOM_NO_ERR;
}
/**
@@ -677,6 +895,8 @@
struct dom_element *element, struct dom_string *namespace,
struct dom_string *localname, struct dom_nodelist **result)
{
+ /** \todo ensure XML feature is supported */
+
return dom_document_get_nodelist(element->base.owner,
(struct dom_node *) element, NULL,
namespace, localname, result);
@@ -724,12 +944,22 @@
struct dom_string *namespace, struct dom_string *localname,
bool *result)
{
- UNUSED(element);
- UNUSED(namespace);
- UNUSED(localname);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *a = (struct dom_node *) element->attributes;
+
+ /** \todo ensure XML feature is supported */
+
+ /* Search attributes, looking for namespace/localname */
+ for (; a != NULL; a = a->next) {
+ if (((namespace == NULL && a->namespace == NULL) ||
+ (namespace != NULL &&
+ dom_string_cmp(a->namespace, namespace) == 0)) &&
+ dom_string_cmp(a->name, localname) == 0)
+ break;
+ }
+
+ *result = (a != NULL);
+
+ return DOM_NO_ERR;
}
/**
15 years, 11 months
r3607 tlsa - /trunk/netsurf/!NetSurf/Resources/CSS,f79
by netsurf@semichrome.net
Author: tlsa
Date: Sat Sep 29 12:51:10 2007
New Revision: 3607
URL: http://source.netsurf-browser.org?rev=3607&view=rev
Log:
Add rule to make it visually clearer that a menu is available on SELECT elements. (This will have no effect until :after and content: are implemented.)
Modified:
trunk/netsurf/!NetSurf/Resources/CSS,f79
Modified: trunk/netsurf/!NetSurf/Resources/CSS,f79
URL: http://source.netsurf-browser.org/trunk/netsurf/%21NetSurf/Resources/CSS%...
==============================================================================
--- trunk/netsurf/!NetSurf/Resources/CSS,f79 (original)
+++ trunk/netsurf/!NetSurf/Resources/CSS,f79 Sat Sep 29 12:51:10 2007
@@ -170,6 +170,7 @@
height: 1.5em; text-align: left; border-width: medium;
border-color: #d9d9d9; border-style: inset;
overflow: hidden; padding: 0 2px; }
+select:after { content: "\25bc"; border-left:4px ridge #d9d9d9; }
textarea { background-color: #fff; color: #000; text-align: left;
border-width: 1px; border-color: #000; border-style: solid;
15 years, 11 months
r3606 jmb - in /trunk/dom: bindings/xml/xmlbinding.c include/dom/bootstrap/implpriv.h include/dom/bootstrap/init_fini.h src/bootstrap/init_fini.c test/lib/testobject.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Sep 29 02:41:23 2007
New Revision: 3606
URL: http://source.netsurf-browser.org?rev=3606&view=rev
Log:
dom_initialise() and dom_finalise() are now completely public, rather than hidden away in a header only meant for inclusion by bindings. Client applications are responsible for initialisation and finalisation of the dom library. This must happen before/after (respectively) any call to a dom library or dom binding library function.
The reason for this change is that, if multiple bindings are required, then the dom library should still only be initialised/finalised once. Only the client can enforce this sensibly.
Added:
trunk/dom/include/dom/bootstrap/init_fini.h
Modified:
trunk/dom/bindings/xml/xmlbinding.c
trunk/dom/include/dom/bootstrap/implpriv.h
trunk/dom/src/bootstrap/init_fini.c
trunk/dom/test/lib/testobject.c
Modified: trunk/dom/bindings/xml/xmlbinding.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.c?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.c (original)
+++ trunk/dom/bindings/xml/xmlbinding.c Sat Sep 29 02:41:23 2007
@@ -385,10 +385,6 @@
{
dom_exception err;
- err = dom_initialise(alloc, pw);
- if (err != DOM_NO_ERR)
- return XML_NOMEM;
-
err = dom_register_source(&xml_dom_impl_src, (dom_alloc) alloc, pw);
if (err != DOM_NO_ERR)
return XML_NOMEM;
@@ -403,13 +399,6 @@
*/
xml_error xml_dom_binding_finalise(void)
{
- dom_exception err;
-
- err = dom_finalise();
- if (err != DOM_NO_ERR) {
- /** \todo Do something about it */
- }
-
return XML_OK;
}
Modified: trunk/dom/include/dom/bootstrap/implpriv.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implpri...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implpriv.h (original)
+++ trunk/dom/include/dom/bootstrap/implpriv.h Sat Sep 29 02:41:23 2007
@@ -17,10 +17,6 @@
*
* The DocumentType implementation includes this as it needs the declaration
* of dom_document_type_create.
- *
- * The DOM library's core initialisation/finalisation implementation also
- * includes this as it needs the declaration of dom_initialise and
- * dom_finalise.
*
* No other client should be including this.
*/
@@ -247,12 +243,6 @@
dom_alloc alloc, void *pw);
};
-/* Initialise the DOM library */
-dom_exception dom_initialise(dom_alloc alloc, void *pw);
-
-/* Finalise the DOM library */
-dom_exception dom_finalise(void);
-
/* Register a source with the DOM library */
dom_exception dom_register_source(struct dom_implementation_source *source,
dom_alloc alloc, void *pw);
Added: trunk/dom/include/dom/bootstrap/init_fini.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/init_fi...
==============================================================================
--- trunk/dom/include/dom/bootstrap/init_fini.h (added)
+++ trunk/dom/include/dom/bootstrap/init_fini.h Sat Sep 29 02:41:23 2007
@@ -1,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_bootstrap_init_fini_h_
+#define dom_bootstrap_init_fini_h_
+
+#include <dom/functypes.h>
+#include <dom/core/exceptions.h>
+
+/* Initialise the DOM library */
+dom_exception dom_initialise(dom_alloc alloc, void *pw);
+
+/* Finalise the DOM library */
+dom_exception dom_finalise(void);
+
+#endif
+
Modified: trunk/dom/src/bootstrap/init_fini.c
URL: http://source.netsurf-browser.org/trunk/dom/src/bootstrap/init_fini.c?rev...
==============================================================================
--- trunk/dom/src/bootstrap/init_fini.c (original)
+++ trunk/dom/src/bootstrap/init_fini.c Sat Sep 29 02:41:23 2007
@@ -5,9 +5,13 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
-#include <dom/bootstrap/implpriv.h>
+#include <stdbool.h>
+
+#include <dom/bootstrap/init_fini.h>
#include "utils/namespace.h"
+
+static bool __initialised;
/**
* Initialise the dom library
@@ -16,14 +20,22 @@
* \param pw Pointer to client-specific private data
* \return DOM_NO_ERR on success.
*
- * This should be invoked by the binding's initialiser and must be
- * the first DOM library method called.
+ * This must be the first DOM library method called.
*/
dom_exception dom_initialise(dom_alloc alloc, void *pw)
{
dom_exception err;
+ /* Ensure we only initialise once */
+ if (__initialised) {
+ return DOM_NO_ERR;
+ }
+
err = _dom_namespace_initialise(alloc, pw);
+
+ if (err == DOM_NO_ERR) {
+ __initialised = true;
+ }
return err;
}
@@ -33,14 +45,20 @@
*
* \return DOM_NO_ERR on success.
*
- * This should be invoked by the binding's finaliser and must be
- * the last DOM library method called.
+ * This must be the last DOM library method called.
*/
dom_exception dom_finalise(void)
{
dom_exception err;
+ /* Ensure we only finalise once */
+ if (__initialised == false) {
+ return DOM_NO_ERR;
+ }
+
err = _dom_namespace_finalise();
+
+ __initialised = false;
return err;
}
Modified: trunk/dom/test/lib/testobject.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testobject.c?rev=360...
==============================================================================
--- trunk/dom/test/lib/testobject.c (original)
+++ trunk/dom/test/lib/testobject.c Sat Sep 29 02:41:23 2007
@@ -7,6 +7,8 @@
#include <stdio.h>
#include <stdlib.h>
+
+#include <dom/bootstrap/init_fini.h>
#include "bindings/xml/xmlbinding.h"
#include "bindings/xml/xmlparser.h"
@@ -42,6 +44,8 @@
}
if (xml_parser_initialised == false) {
+ assert(dom_initialise(myrealloc, NULL) == DOM_NO_ERR);
+
assert(xml_dom_binding_initialise(myrealloc, NULL) == XML_OK);
atexit(test_object_cleanup);
@@ -119,7 +123,9 @@
void test_object_cleanup(void)
{
- if (xml_parser_initialised)
+ if (xml_parser_initialised) {
xml_dom_binding_finalise();
+ dom_finalise();
+ }
}
15 years, 11 months
r3605 jmb - in /trunk/dom: bindings/xml/xmlbinding.c bindings/xml/xmlbinding.h test/lib/testobject.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Sep 29 02:12:08 2007
New Revision: 3605
URL: http://source.netsurf-browser.org?rev=3605&view=rev
Log:
Add finalisation method to libxml-libdom.
Ensure testcases clean up after themselves by calling xml_dom_binding_finalise()
Modified:
trunk/dom/bindings/xml/xmlbinding.c
trunk/dom/bindings/xml/xmlbinding.h
trunk/dom/test/lib/testobject.c
Modified: trunk/dom/bindings/xml/xmlbinding.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.c?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.c (original)
+++ trunk/dom/bindings/xml/xmlbinding.c Sat Sep 29 02:12:08 2007
@@ -396,3 +396,21 @@
return XML_OK;
}
+/**
+ * Finalise the XML DOM binding
+ *
+ * \return XML_OK on success.
+ */
+xml_error xml_dom_binding_finalise(void)
+{
+ dom_exception err;
+
+ err = dom_finalise();
+ if (err != DOM_NO_ERR) {
+ /** \todo Do something about it */
+ }
+
+ return XML_OK;
+}
+
+
Modified: trunk/dom/bindings/xml/xmlbinding.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.h?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.h (original)
+++ trunk/dom/bindings/xml/xmlbinding.h Sat Sep 29 02:12:08 2007
@@ -14,4 +14,7 @@
/* Initialise the XML DOM binding */
xml_error xml_dom_binding_initialise(xml_alloc alloc, void *pw);
+/* Finalise the XML DOM binding */
+xml_error xml_dom_binding_finalise(void);
+
#endif
Modified: trunk/dom/test/lib/testobject.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testobject.c?rev=360...
==============================================================================
--- trunk/dom/test/lib/testobject.c (original)
+++ trunk/dom/test/lib/testobject.c Sat Sep 29 02:12:08 2007
@@ -15,16 +15,18 @@
#include "testobject.h"
#include "utils.h"
+static bool xml_parser_initialised;
+
struct TestObject {
xml_parser *parser;
struct dom_document *doc;
};
+static void test_object_cleanup(void);
+
TestObject *test_object_create(int argc, char **argv,
const char *uri, bool will_be_modified)
{
- static bool xml_parser_initialised;
-
char fnbuf[1024];
#define CHUNK_SIZE 4096
uint8_t buf[CHUNK_SIZE];
@@ -41,6 +43,8 @@
if (xml_parser_initialised == false) {
assert(xml_dom_binding_initialise(myrealloc, NULL) == XML_OK);
+
+ atexit(test_object_cleanup);
xml_parser_initialised = true;
}
@@ -113,4 +117,9 @@
return "text/xml";
}
+void test_object_cleanup(void)
+{
+ if (xml_parser_initialised)
+ xml_dom_binding_finalise();
+}
15 years, 11 months