summaryrefslogtreecommitdiff
path: root/src/util/dom-str.c
blob: 73bfe633ff93dbf17690d7846951b6ea6be7a597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * This file is part of LibNSLayout
 * Licensed under the ISC License, http://opensource.org/licenses/ISC
 * Copyright 2015 Michael Drake <tlsa@netsurf-browser.org>
 */

/** \file src/util/dom-str.c
 * Layout object handling
 */

#include <stdio.h>

#include "util/dom-str.h"
#include "util/util.h"

dom_string *nsl_dom_str_node_inserted;
dom_string *nsl_dom_str_node_removed;
dom_string *nsl_dom_str_subtree_modified;
dom_string *nsl_dom_str_attr_modified;
dom_string *nsl_dom_str_characterdata_modified;


/* Exported function, documented in src/util/dom-str.h */
nslayout_error nsl_dom_str_init(void)
{
	nslayout_error err;
	dom_exception exc;

	exc = dom_string_create((const uint8_t *)"DOMNodeInserted",
			SLEN("DOMNodeInserted"),
			&nsl_dom_str_node_inserted);
	if (exc != DOM_NO_ERR) {
		goto out;
	}
	exc = dom_string_create((const uint8_t *)"DOMNodeRemoved",
			SLEN("DOMNodeRemoved"),
			&nsl_dom_str_node_removed);
	if (exc != DOM_NO_ERR) {
		goto out;
	}
	exc = dom_string_create((const uint8_t *)"DOMSubtreeModified",
			SLEN("DOMSubtreeModified"),
			&nsl_dom_str_subtree_modified);
	if (exc != DOM_NO_ERR) {
		goto out;
	}
	exc = dom_string_create((const uint8_t *)"DOMAttrModified",
			SLEN("DOMAttrModified"),
			&nsl_dom_str_attr_modified);
	if (exc != DOM_NO_ERR) {
		goto out;
	}
	exc = dom_string_create((const uint8_t *)"DOMCharacterDataModified",
			SLEN("DOMCharacterDataModified"),
			&nsl_dom_str_characterdata_modified);
	if (exc != DOM_NO_ERR) {
		goto out;
	}

	err = NSLAYOUT_OK;
out:
	if (exc != DOM_NO_ERR) {
		printf("Failed to initialise dom_str!\n");
		nsl_dom_str_fini();
		err = NSL_DOM_ERR(exc);
	}

	return err;
}


/* Exported function, documented in src/util/dom-str.h */
nslayout_error nsl_dom_str_fini(void)
{
	dom_string_unref(nsl_dom_str_node_inserted);
	dom_string_unref(nsl_dom_str_node_removed);
	dom_string_unref(nsl_dom_str_subtree_modified);
	dom_string_unref(nsl_dom_str_attr_modified);
	dom_string_unref(nsl_dom_str_characterdata_modified);

	return NSLAYOUT_OK;
}