xpath multiple match, int main, etc
This commit is contained in:
parent
303f4a35a8
commit
5c938febf4
6 changed files with 36 additions and 23 deletions
|
|
@ -109,7 +109,7 @@ install-include: clixon_backend.h clixon_backend_handle.h clixon_backend_transac
|
||||||
|
|
||||||
# Just link test programs
|
# Just link test programs
|
||||||
test.c :
|
test.c :
|
||||||
echo "main(){}" > $@
|
echo "int main(){}" > $@
|
||||||
|
|
||||||
test: test.c $(LIBOBJ)
|
test: test.c $(LIBOBJ)
|
||||||
$(CC) $(INCLUDES) $(LDFLAGS) $< $(LIBOBJ) -L. -l:$(MYLIB) $(LIBS) -o $@
|
$(CC) $(INCLUDES) $(LDFLAGS) $< $(LIBOBJ) -L. -l:$(MYLIB) $(LIBS) -o $@
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,7 @@ main(int argc, char **argv)
|
||||||
int sockfamily;
|
int sockfamily;
|
||||||
|
|
||||||
/* In the startup, logs to stderr & syslog and debug flag set later */
|
/* In the startup, logs to stderr & syslog and debug flag set later */
|
||||||
|
|
||||||
clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR|CLICON_LOG_SYSLOG);
|
clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR|CLICON_LOG_SYSLOG);
|
||||||
/* Initiate CLICON handle */
|
/* Initiate CLICON handle */
|
||||||
if ((h = backend_handle_init()) == NULL)
|
if ((h = backend_handle_init()) == NULL)
|
||||||
|
|
@ -343,10 +344,13 @@ main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
* Here we have the debug flag settings, use that.
|
||||||
* Syslogs also to stderr, but later turn stderr off in daemon mode.
|
* Syslogs also to stderr, but later turn stderr off in daemon mode.
|
||||||
* error only to syslog. debug to syslog
|
* error only to syslog. debug to syslog
|
||||||
|
* XXX: if started in a start-daemon script, there will be irritating
|
||||||
|
* double syslogs until fork below.
|
||||||
*/
|
*/
|
||||||
clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR|CLICON_LOG_SYSLOG);
|
clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, CLICON_LOG_SYSLOG);
|
||||||
clicon_debug_init(debug, NULL);
|
clicon_debug_init(debug, NULL);
|
||||||
|
|
||||||
/* Find and read configfile */
|
/* Find and read configfile */
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ uninstall:
|
||||||
|
|
||||||
# Just link test programs
|
# Just link test programs
|
||||||
test.c :
|
test.c :
|
||||||
echo "main(){}" > $@
|
echo "int main(){}" > $@
|
||||||
|
|
||||||
test: test.c $(LIBOBJ)
|
test: test.c $(LIBOBJ)
|
||||||
$(CC) $(INCLUDES) $(LDFLAGS) $< $(LIBOBJ) -L. -l:$(MYLIB) $(LIBS) -o $@
|
$(CC) $(INCLUDES) $(LDFLAGS) $< $(LIBOBJ) -L. -l:$(MYLIB) $(LIBS) -o $@
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,8 @@ str2cvec(char *string,
|
||||||
clicon_debug(1, "error cvec_add %s", strerror(errno));
|
clicon_debug(1, "error cvec_add %s", strerror(errno));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
while ((strlen(s) > 0) && isblank(*s))
|
||||||
|
s++;
|
||||||
cv_name_set(cv, s);
|
cv_name_set(cv, s);
|
||||||
cv_string_set(cv, valu);
|
cv_string_set(cv, valu);
|
||||||
free(valu);
|
free(valu);
|
||||||
|
|
|
||||||
|
|
@ -432,7 +432,8 @@ request_process(clicon_handle h,
|
||||||
/* If present, check credentials */
|
/* If present, check credentials */
|
||||||
if (plugin_credentials(h, r, &auth) < 0)
|
if (plugin_credentials(h, r, &auth) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
clicon_debug(1, "%s credentials ok 1", __FUNCTION__);
|
clicon_debug(1, "%s credentials ok auth:%d (should be 1)",
|
||||||
|
__FUNCTION__, auth);
|
||||||
if (auth == 0)
|
if (auth == 0)
|
||||||
goto done;
|
goto done;
|
||||||
clicon_debug(1, "%s credentials ok 2", __FUNCTION__);
|
clicon_debug(1, "%s credentials ok 2", __FUNCTION__);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
* Limited XML XPATH and XSLT functions.
|
* Limited XML XPATH and XSLT functions.
|
||||||
* NOTE: there is a main function at the end of this file where you can test out
|
* NOTE: there is a main function at the end of this file where you can test out
|
||||||
* different xpath expressions.
|
* different xpath expressions.
|
||||||
|
* Look at the end of the file for a test unit program
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
https://www.w3.org/TR/xpath/
|
https://www.w3.org/TR/xpath/
|
||||||
|
|
@ -449,10 +450,12 @@ xpath_expr(char *predicate_expression,
|
||||||
if ((x = xml_find(xv, e_a)) != NULL &&
|
if ((x = xml_find(xv, e_a)) != NULL &&
|
||||||
(xml_type(x) == CX_ATTR)){
|
(xml_type(x) == CX_ATTR)){
|
||||||
if (!e_v || strcmp(xml_value(x), e_v) == 0){
|
if (!e_v || strcmp(xml_value(x), e_v) == 0){
|
||||||
clicon_debug(2, "%s %x %x", __FUNCTION__, flags, xml_flag(xv, flags));
|
clicon_debug(2, "%s %x %x", __FUNCTION__, flags, xml_flag(xv, flags));
|
||||||
if (flags==0x0 || xml_flag(xv, flags))
|
if (flags==0x0 || xml_flag(xv, flags)){
|
||||||
if (cxvec_append(xv, &vec, &veclen) < 0)
|
if (cxvec_append(xv, &vec, &veclen) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
break; /* xv added */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -483,11 +486,14 @@ xpath_expr(char *predicate_expression,
|
||||||
}
|
}
|
||||||
for (i=0; i<*vec0len; i++){
|
for (i=0; i<*vec0len; i++){
|
||||||
xv = (*vec0)[i];
|
xv = (*vec0)[i];
|
||||||
if ((x = xml_find(xv, tag)) != NULL &&
|
/* Check if more may match,... */
|
||||||
(xml_type(x) == CX_ELMNT)){
|
x = NULL;
|
||||||
|
while ((x = xml_child_each(xv, x, CX_ELMNT)) != NULL) {
|
||||||
|
if (strcmp(tag, xml_name(x)) != 0)
|
||||||
|
continue;
|
||||||
if ((val = xml_body(x)) != NULL &&
|
if ((val = xml_body(x)) != NULL &&
|
||||||
strcmp(val, e) == 0){
|
strcmp(val, e) == 0){
|
||||||
clicon_debug(2, "%s %x %x", __FUNCTION__, flags, xml_flag(xv, flags));
|
clicon_debug(2, "%s %x %x", __FUNCTION__, flags, xml_flag(xv, flags));
|
||||||
if (flags==0x0 || xml_flag(xv, flags))
|
if (flags==0x0 || xml_flag(xv, flags))
|
||||||
if (cxvec_append(xv, &vec, &veclen) < 0)
|
if (cxvec_append(xv, &vec, &veclen) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -508,13 +514,13 @@ xpath_expr(char *predicate_expression,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Given vec0, add matches to vec1
|
/*! Given vec0, add matches to vec1
|
||||||
* @param[in] xe
|
* @param[in] xe XPATH in structured (parsed) form
|
||||||
* @param[in] descendants0
|
* @param[in] descendants0
|
||||||
* @param[in] vec0
|
* @param[in] vec0 vector of XML trees
|
||||||
* @param[in] vec0len
|
* @param[in] vec0len length of XML trees
|
||||||
* @param[in] flags
|
* @param[in] flags if != 0, only match xml nodes matching flags
|
||||||
* @param[out] vec1
|
* @param[out] vec2 Result XML node vector
|
||||||
* @param[out] vec1len
|
* @param[out] vec2len Length of result vector.
|
||||||
* XXX: Kommer in i funktionen med vec0, resultatet appendas i vec1
|
* XXX: Kommer in i funktionen med vec0, resultatet appendas i vec1
|
||||||
* vec0 --> vec
|
* vec0 --> vec
|
||||||
* Det är nog bra om vec0 inte ändras, är input parameter
|
* Det är nog bra om vec0 inte ändras, är input parameter
|
||||||
|
|
@ -673,12 +679,12 @@ xpath_split(char *xpathstr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Process single xpath expression on xml tree
|
/*! Process single xpath expression on xml tree
|
||||||
* @param[in] xpath
|
* @param[in] xpath string with XPATH syntax
|
||||||
* @param[in] vec0
|
* @param[in] vec0 vector of XML trees
|
||||||
* @param[in] vec0len
|
* @param[in] vec0len length of XML trees
|
||||||
* @param[in] flags
|
* @param[in] flags if != 0, only match xml nodes matching flags
|
||||||
* @param[out] vec
|
* @param[out] vec2 Result XML node vector
|
||||||
* @param[out] veclen
|
* @param[out] vec2len Length of result vector.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xpath_exec(char *xpath,
|
xpath_exec(char *xpath,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue