author | Frank Zschockelt <lm@freakysoft.de> |
Mon, 13 May 2019 22:09:10 +0200 | |
changeset 739 | 4a32df98ff8c |
parent 736 | 97f3ff94976f |
permissions | -rw-r--r-- |
516
4dd3aa6b83e5
Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents:
515
diff
changeset
|
1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
1 | 2 |
/* |
99
81e9d035de02
2004-10-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
84
diff
changeset
|
3 |
* Copyright (C) 2003 Imendio AB |
1 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU Lesser General Public License as |
|
7 |
* published by the Free Software Foundation; either version 2 of the |
|
8 |
* License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
* Lesser General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU Lesser General Public |
|
690
7ccf2113ec5f
Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents:
664
diff
changeset
|
16 |
* License along with this program; if not, see <https://www.gnu.org/licenses> |
1 | 17 |
*/ |
18 |
||
19 |
#include <config.h> |
|
20 |
#include <string.h> |
|
21 |
||
168
ac1affcd5d22
2006-09-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
153
diff
changeset
|
22 |
#include <glib.h> |
ac1affcd5d22
2006-09-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
153
diff
changeset
|
23 |
|
1 | 24 |
#include "lm-debug.h" |
25 |
#include "lm-internals.h" |
|
26 |
#include "lm-message-node.h" |
|
27 |
#include "lm-parser.h" |
|
28 |
||
29 |
#define SHORT_END_TAG "/>" |
|
30 |
#define XML_MAX_DEPTH 5 |
|
31 |
||
32 |
#define LM_PARSER(o) ((LmParser *) o) |
|
33 |
||
34 |
struct LmParser { |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
35 |
LmParserMessageFunction function; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
36 |
gpointer user_data; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
37 |
GDestroyNotify notify; |
607 | 38 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
39 |
LmMessageNode *cur_root; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
40 |
LmMessageNode *cur_node; |
607 | 41 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
42 |
GMarkupParser *m_parser; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
43 |
GMarkupParseContext *context; |
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
44 |
gchar *incomplete; /* incomplete utf-8 character |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
45 |
found at the end of buffer */ |
1 | 46 |
}; |
47 |
||
48 |
||
49 |
/* Used while parsing */ |
|
50 |
static void parser_start_node_cb (GMarkupParseContext *context, |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
51 |
const gchar *node_name, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
52 |
const gchar **attribute_names, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
53 |
const gchar **attribute_values, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
54 |
gpointer user_data, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
55 |
GError **error); |
1 | 56 |
static void parser_end_node_cb (GMarkupParseContext *context, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
57 |
const gchar *node_name, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
58 |
gpointer user_data, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
59 |
GError **error); |
1 | 60 |
static void parser_text_cb (GMarkupParseContext *context, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
61 |
const gchar *text, |
607 | 62 |
gsize text_len, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
63 |
gpointer user_data, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
64 |
GError **error); |
1 | 65 |
static void parser_error_cb (GMarkupParseContext *context, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
66 |
GError *error, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
67 |
gpointer user_data); |
1 | 68 |
|
69 |
static void |
|
70 |
parser_start_node_cb (GMarkupParseContext *context, |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
71 |
const gchar *node_name, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
72 |
const gchar **attribute_names, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
73 |
const gchar **attribute_values, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
74 |
gpointer user_data, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
75 |
GError **error) |
607 | 76 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
77 |
LmParser *parser; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
78 |
gint i; |
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
79 |
const gchar *node_name_unq; |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
80 |
const gchar *xmlns = NULL; |
607 | 81 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
82 |
parser = LM_PARSER (user_data);; |
607 | 83 |
|
1 | 84 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
85 |
/* parser->cur_depth++; */ |
1 | 86 |
|
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
87 |
//strip namespace prefix other than "stream:" from node_name |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
88 |
node_name_unq = strrchr(node_name, ':'); |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
89 |
if (!node_name_unq || !strncmp(node_name, "stream:", 7)) |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
90 |
node_name_unq = node_name; |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
91 |
else |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
92 |
++node_name_unq; |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
93 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
94 |
if (!parser->cur_root) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
95 |
/* New toplevel element */ |
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
96 |
parser->cur_root = _lm_message_node_new (node_name_unq); |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
97 |
parser->cur_node = parser->cur_root; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
98 |
} else { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
99 |
LmMessageNode *parent_node; |
607 | 100 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
101 |
parent_node = parser->cur_node; |
607 | 102 |
|
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
103 |
parser->cur_node = _lm_message_node_new (node_name_unq); |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
104 |
_lm_message_node_add_child_node (parent_node, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
105 |
parser->cur_node); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
106 |
} |
1 | 107 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
108 |
for (i = 0; attribute_names[i]; ++i) { |
607 | 109 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_PARSER, |
110 |
"ATTRIBUTE: %s = %s\n", |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
111 |
attribute_names[i], |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
112 |
attribute_values[i]); |
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
113 |
//FIXME: strip namespace suffix from xmlns: attribute if exists |
607 | 114 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
115 |
lm_message_node_set_attributes (parser->cur_node, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
116 |
attribute_names[i], |
607 | 117 |
attribute_values[i], |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
118 |
NULL); |
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
119 |
if (!strncmp(attribute_names[i], "xmlns:", 6)) |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
120 |
xmlns = attribute_values[i]; |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
121 |
} |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
122 |
if (xmlns && !lm_message_node_get_attribute(parser->cur_node, "xmlns")) { |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
123 |
lm_message_node_set_attribute (parser->cur_node, "xmlns", xmlns); |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
124 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_PARSER, |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
125 |
"ATTRIBUTE: %s = %s\n", |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
126 |
"xmlns", xmlns); |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
127 |
} |
607 | 128 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
129 |
if (strcmp ("stream:stream", node_name) == 0) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
130 |
parser_end_node_cb (context, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
131 |
"stream:stream", |
607 | 132 |
user_data, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
133 |
error); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
134 |
} |
1 | 135 |
} |
136 |
||
137 |
static void |
|
138 |
parser_end_node_cb (GMarkupParseContext *context, |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
139 |
const gchar *node_name, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
140 |
gpointer user_data, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
141 |
GError **error) |
1 | 142 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
143 |
LmParser *parser; |
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
144 |
const gchar *node_name_unq; |
607 | 145 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
146 |
parser = LM_PARSER (user_data); |
607 | 147 |
|
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
148 |
node_name_unq = strrchr(node_name, ':'); |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
149 |
if (!node_name_unq || !strncmp(node_name, "stream:", 7)) |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
150 |
node_name_unq = node_name; |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
151 |
else |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
152 |
++node_name_unq; |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
153 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
154 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_PARSER, |
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
155 |
"Trying to close node: %s\n", node_name_unq); |
1 | 156 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
157 |
if (!parser->cur_node) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
158 |
/* FIXME: LM-1 should look at this */ |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
159 |
return; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
160 |
} |
607 | 161 |
|
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
162 |
//cur_node->name doesn't have namespace prefix anymore, node_name does. |
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
163 |
if (strcmp (parser->cur_node->name, node_name_unq) != 0) { |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
164 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_PARSER, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
165 |
"Trying to close node that isn't open: %s", |
623
d20813955632
Workaround for parser to support prefixed tag names
Hermitifier <quantifier666@gmail.com>
parents:
622
diff
changeset
|
166 |
node_name_unq); |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
167 |
return; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
168 |
} |
1 | 169 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
170 |
if (parser->cur_node == parser->cur_root) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
171 |
LmMessage *m; |
607 | 172 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
173 |
m = _lm_message_new_from_node (parser->cur_root); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
174 |
|
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
175 |
if (!m) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
176 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_PARSER, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
177 |
"Couldn't create message: %s\n", |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
178 |
parser->cur_root->name); |
602
3bcd644fe1ba
[PATCH] Drop stanzas when failing to convert them to LmMessages.
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
518
diff
changeset
|
179 |
} else { |
3bcd644fe1ba
[PATCH] Drop stanzas when failing to convert them to LmMessages.
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
518
diff
changeset
|
180 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_PARSER, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
181 |
"Have a new message\n"); |
602
3bcd644fe1ba
[PATCH] Drop stanzas when failing to convert them to LmMessages.
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
518
diff
changeset
|
182 |
if (parser->function) { |
3bcd644fe1ba
[PATCH] Drop stanzas when failing to convert them to LmMessages.
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
518
diff
changeset
|
183 |
(* parser->function) (parser, m, parser->user_data); |
3bcd644fe1ba
[PATCH] Drop stanzas when failing to convert them to LmMessages.
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
518
diff
changeset
|
184 |
} |
664
f57b1b61e1fe
Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents:
623
diff
changeset
|
185 |
lm_message_unref (m); |
f57b1b61e1fe
Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents:
623
diff
changeset
|
186 |
} |
1 | 187 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
188 |
lm_message_node_unref (parser->cur_root); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
189 |
parser->cur_node = parser->cur_root = NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
190 |
} else { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
191 |
LmMessageNode *tmp_node; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
192 |
tmp_node = parser->cur_node; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
193 |
parser->cur_node = parser->cur_node->parent; |
84
7ae7b690aa89
2004-05-28 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
57
diff
changeset
|
194 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
195 |
lm_message_node_unref (tmp_node); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
196 |
} |
1 | 197 |
} |
198 |
||
199 |
static void |
|
200 |
parser_text_cb (GMarkupParseContext *context, |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
201 |
const gchar *text, |
607 | 202 |
gsize text_len, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
203 |
gpointer user_data, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
204 |
GError **error) |
1 | 205 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
206 |
LmParser *parser; |
607 | 207 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
208 |
g_return_if_fail (user_data != NULL); |
607 | 209 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
210 |
parser = LM_PARSER (user_data); |
607 | 211 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
212 |
if (parser->cur_node && strcmp (text, "") != 0) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
213 |
lm_message_node_set_value (parser->cur_node, text); |
607 | 214 |
} |
1 | 215 |
} |
216 |
||
217 |
static void |
|
218 |
parser_error_cb (GMarkupParseContext *context, |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
219 |
GError *error, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
220 |
gpointer user_data) |
1 | 221 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
222 |
g_return_if_fail (user_data != NULL); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
223 |
g_return_if_fail (error != NULL); |
607 | 224 |
|
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
225 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
226 |
"Parsing failed: %s\n", error->message); |
1 | 227 |
} |
228 |
||
229 |
LmParser * |
|
607 | 230 |
lm_parser_new (LmParserMessageFunction function, |
231 |
gpointer user_data, |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
232 |
GDestroyNotify notify) |
1 | 233 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
234 |
LmParser *parser; |
607 | 235 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
236 |
parser = g_new0 (LmParser, 1); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
237 |
if (!parser) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
238 |
return NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
239 |
} |
607 | 240 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
241 |
parser->m_parser = g_new0 (GMarkupParser, 1); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
242 |
if (!parser->m_parser) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
243 |
g_free (parser); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
244 |
return NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
245 |
} |
1 | 246 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
247 |
parser->function = function; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
248 |
parser->user_data = user_data; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
249 |
parser->notify = notify; |
607 | 250 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
251 |
parser->m_parser->start_element = parser_start_node_cb; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
252 |
parser->m_parser->end_element = parser_end_node_cb; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
253 |
parser->m_parser->text = parser_text_cb; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
254 |
parser->m_parser->error = parser_error_cb; |
1 | 255 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
256 |
parser->context = g_markup_parse_context_new (parser->m_parser, 0, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
257 |
parser, NULL); |
1 | 258 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
259 |
parser->cur_root = NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
260 |
parser->cur_node = NULL; |
1 | 261 |
|
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
262 |
parser->incomplete = NULL; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
263 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
264 |
return parser; |
1 | 265 |
} |
266 |
||
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
267 |
static gchar * |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
268 |
_lm_parser_make_valid (const gchar *buffer, gchar **incomplete) |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
269 |
{ |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
270 |
GString *string; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
271 |
const gchar *remainder, *invalid; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
272 |
gint remaining_bytes, valid_bytes; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
273 |
gunichar code; /*error code for invalid character*/ |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
274 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
275 |
g_return_val_if_fail (buffer != NULL, NULL); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
276 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
277 |
string = NULL; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
278 |
remainder = buffer; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
279 |
remaining_bytes = strlen (buffer); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
280 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
281 |
while (remaining_bytes != 0) |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
282 |
{ |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
283 |
if (g_utf8_validate (remainder, remaining_bytes, &invalid)) |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
284 |
break; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
285 |
valid_bytes = invalid - remainder; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
286 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
287 |
if (string == NULL) |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
288 |
string = g_string_sized_new (remaining_bytes); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
289 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
290 |
g_string_append_len (string, remainder, valid_bytes); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
291 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
292 |
remainder = g_utf8_find_next_char(invalid, NULL); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
293 |
remaining_bytes -= valid_bytes + (remainder - invalid); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
294 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
295 |
code = g_utf8_get_char_validated (invalid, -1); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
296 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
297 |
if (code == -1) { |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
298 |
/* A complete but invalid codepoint */ |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
299 |
/* append U+FFFD REPLACEMENT CHARACTER */ |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
300 |
g_string_append (string, "\357\277\275"); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
301 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE, "invalid character!\n"); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
302 |
} else if (code == -2) { |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
303 |
/* Beginning of what could be a character */ |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
304 |
*incomplete = g_strdup (invalid); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
305 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE, |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
306 |
"incomplete character: %s\n", *incomplete); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
307 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
308 |
g_assert (remaining_bytes == 0); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
309 |
g_assert (*(g_utf8_find_next_char(invalid, NULL)) == '\0'); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
310 |
} |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
311 |
} |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
312 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
313 |
if (string == NULL) |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
314 |
return g_strdup (buffer); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
315 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
316 |
g_string_append (string, remainder); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
317 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
318 |
g_assert (g_utf8_validate (string->str, -1, NULL)); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
319 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
320 |
return g_string_free (string, FALSE); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
321 |
} |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
322 |
|
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
323 |
|
399
b5ebdc9d8152
Added a boolean return value from LmParser::parse to be able to check whether it was successful
Mikael Hallendal <micke@imendio.com>
parents:
188
diff
changeset
|
324 |
gboolean |
1 | 325 |
lm_parser_parse (LmParser *parser, const gchar *string) |
326 |
{ |
|
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
327 |
gboolean parsed; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
328 |
gchar *valid, *completed; |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
329 |
g_return_val_if_fail (parser != NULL, FALSE); |
607 | 330 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
331 |
if (!parser->context) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
332 |
parser->context = g_markup_parse_context_new (parser->m_parser, 0, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
333 |
parser, NULL); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
334 |
} |
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
335 |
if (parser->incomplete) { |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
336 |
completed = g_strdup_printf("%s%s", parser->incomplete, string); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
337 |
g_free(parser->incomplete); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
338 |
parser->incomplete = NULL; |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
339 |
} else { |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
340 |
completed = g_strdup(string); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
341 |
} |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
342 |
valid = _lm_parser_make_valid (completed, &parser->incomplete); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
343 |
g_free(completed); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
344 |
if (g_markup_parse_context_parse (parser->context, valid, |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
345 |
(gssize)strlen (valid), NULL)) { |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
346 |
parsed = TRUE; |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
347 |
} else { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
348 |
g_markup_parse_context_free (parser->context); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
349 |
parser->context = NULL; |
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
350 |
parsed = FALSE; |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
351 |
} |
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
352 |
g_free(valid); |
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
353 |
return parsed; |
1 | 354 |
} |
355 |
||
356 |
void |
|
357 |
lm_parser_free (LmParser *parser) |
|
358 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
359 |
if (parser->notify) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
360 |
(* parser->notify) (parser->user_data); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
361 |
} |
153
b2324df84971
2006-06-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
140
diff
changeset
|
362 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
363 |
if (parser->context) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
364 |
g_markup_parse_context_free (parser->context); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
365 |
} |
622
2fd864a27f9b
Protect GMarkup parser against invalid unicode characters
Hermitifier <quantifier666@gmail.com>
parents:
607
diff
changeset
|
366 |
g_free (parser->incomplete); |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
367 |
g_free (parser->m_parser); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
368 |
g_free (parser); |
1 | 369 |
} |
370 |