aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksi Lindeman <dec05eba@protonmail.com>2019-05-25 02:48:33 +0200
committerAleksi Lindeman <dec05eba@protonmail.com>2019-05-25 02:48:36 +0200
commit9c52fc54400d706f8f7cdf82d3df2da733862819 (patch)
tree5a4a86ab359e7111c9e4675ef8b8a6b26d0eecdd /src
parent36c6ce46a1abdb08eb9193704b9fce6bc7f3646b (diff)
Cleanup after finished
Diffstat (limited to 'src')
-rw-r--r--src/HtmlSearch.c14
-rw-r--r--src/NodeSearch.c2
-rw-r--r--src/XpathParser.c3
3 files changed, 11 insertions, 8 deletions
diff --git a/src/HtmlSearch.c b/src/HtmlSearch.c
index e59dc1e..c3608dd 100644
--- a/src/HtmlSearch.c
+++ b/src/HtmlSearch.c
@@ -41,7 +41,7 @@ static void find_child_nodes(TidyDoc tdoc, TidyNode node, const QuickMediaNodeSe
} while(0)
/* If we search without param, then it's a match */
- if(!search_data->param_defined) {
+ if(!search_data->param.defined) {
on_match();
continue;
}
@@ -123,8 +123,12 @@ static int quickmedia_html_find_nodes(const char *html_source, QuickMediaNodeSea
int quickmedia_html_find_nodes_xpath(const char *html_source, const char *xpath, QuickMediaHtmlSearchResultCallback result_callback, void *userdata) {
QuickMediaNodeSearch search_data;
- int xpath_result = quickmedia_parse_xpath(xpath, &search_data);
- if(xpath_result != 0)
- return xpath_result;
- return quickmedia_html_find_nodes(html_source, &search_data, result_callback, userdata);
+ quickmedia_node_search_init(&search_data);
+ int result = quickmedia_parse_xpath(xpath, &search_data);
+ if(result != 0)
+ goto cleanup;
+ result = quickmedia_html_find_nodes(html_source, &search_data, result_callback, userdata);
+ cleanup:
+ quickmedia_node_search_deinit(&search_data);
+ return result;
}
diff --git a/src/NodeSearch.c b/src/NodeSearch.c
index 198b8cd..0a36215 100644
--- a/src/NodeSearch.c
+++ b/src/NodeSearch.c
@@ -4,6 +4,7 @@
void quickmedia_node_search_param_init(QuickMediaNodeSearchParam *self) {
self->name = NULL;
self->value = NULL;
+ self->defined = 0;
}
static void quickmedia_node_search_param_deinit(QuickMediaNodeSearchParam *self) {
@@ -17,7 +18,6 @@ void quickmedia_node_search_init(QuickMediaNodeSearch *self) {
self->name = NULL;
self->recursive = 0;
quickmedia_node_search_param_init(&self->param);
- self->param_defined = 0;
self->child = NULL;
}
diff --git a/src/XpathParser.c b/src/XpathParser.c
index 24e1d6e..4326e85 100644
--- a/src/XpathParser.c
+++ b/src/XpathParser.c
@@ -35,6 +35,7 @@ static int xpath_parse_param(QuickMediaXpathParser *self, QuickMediaNodeSearchPa
if(token != QUICKMEDIA_XPATH_TOKEN_CLOSING_BRACKET)
return -4;
+ result->defined = 1;
return 0;
}
@@ -55,8 +56,6 @@ static int xpath_parse_node(QuickMediaXpathParser *self, QuickMediaNodeSearch *r
if(param_result < 0) {
quickmedia_node_search_deinit(result);
return param_result;
- } else if(param_result == 0) {
- result->param_defined = 1;
}
result->child = malloc(sizeof(QuickMediaNodeSearch));