35 roxml_strtonum(input, &end);
67 for (i = 0; i < nb; i++) {
72 free(xpath[i].xp_cond);
91 if (tok->
id == req_id) {
96 if (tok->
id == req_id) {
124 if (tok->
id == req_id) {
129 if (tok->
id == req_id) {
164 if (tok->
id == req_id) {
171 if (last_tok == NULL) {
176 last_tok = last_tok->
next;
178 last_tok->
id = req_id;
199 for (i = 0; i < pool_len; i++)
203 table->
ids[req_id] = 0;
220 for (i = ROXML_XPATH_FIRST_ID; i < 255; i++) {
221 if (table->
ids[i] == 0) {
247 int pool1 = 0, pool2 = 0;
249 for (i = 0; i < limit; i++) {
260 if (!pool1 || !pool2) {
261 for (i = 0; i < limit; i++) {
283 for (i = 0; i < *count; i++) {
392 while ((first) && (first != n)) {
411 if (op == ROXML_OPERATOR_ADD)
413 else if (op == ROXML_OPERATOR_SUB)
415 else if (op == ROXML_OPERATOR_MUL)
417 else if (op == ROXML_OPERATOR_DIV)
433 if (op == ROXML_OPERATOR_DIFF)
435 else if (op == ROXML_OPERATOR_EINF)
437 else if (op == ROXML_OPERATOR_INF)
439 else if (op == ROXML_OPERATOR_ESUP)
441 else if (op == ROXML_OPERATOR_SUP)
443 else if (op == ROXML_OPERATOR_EQU)
466 result = strcmp(sa, sb);
468 if (op == ROXML_OPERATOR_DIFF)
469 return (result != 0);
470 else if (op == ROXML_OPERATOR_EINF)
471 return (result <= 0);
472 else if (op == ROXML_OPERATOR_INF)
474 else if (op == ROXML_OPERATOR_ESUP)
475 return (result >= 0);
476 else if (op == ROXML_OPERATOR_SUP)
478 else if (op == ROXML_OPERATOR_EQU)
479 return (result == 0);
499 valid = (condition->
rel == ROXML_OPERATOR_AND);
509 if (xn->
name[0] ==
'*')
514 switch (condition->
func) {
516 iarg2 = roxml_strtonum(condition->
arg2, NULL);
519 case ROXML_FUNC_LAST:
522 case ROXML_FUNC_FIRST:
523 if (condition->
op > 0)
527 case ROXML_FUNC_INTCOMP:
531 iarg1 = roxml_strtonum(sarg1, NULL);
532 iarg2 = roxml_strtonum(condition->
arg2, NULL);
536 case ROXML_FUNC_NSURI:
542 case ROXML_FUNC_STRCOMP:
549 case ROXML_FUNC_LNAME:
551 status = strcmp(sarg1, condition->
arg2) == 0;
554 case ROXML_FUNC_XPATH:
564 if (condition->
rel == ROXML_OPERATOR_OR)
565 valid = valid || status;
566 else if (condition->
rel == ROXML_OPERATOR_AND)
567 valid = valid && status;
571 condition = condition->
next;
577ROXML_STATIC ROXML_INT
void roxml_add_to_set(
node_t *root,
node_t *candidat,
node_t ***ans,
int *nb,
int *max,
582 if ((*nb) >= (*max)) {
583 int new_max = (*max) * 2;
585 memcpy(new_ans, (*ans), *(max) *
sizeof(
node_t *));
590 (*ans)[*nb] = candidat;
599 char *axes = xn->
name;
600 int type = (*candidat)->type;
602 if ((axes == NULL) || (strcmp(
"node()", axes) == 0)) {
604 }
else if (strcmp(
"*", axes) == 0) {
607 }
else if (strcmp(
"comment()", axes) == 0) {
610 }
else if (strcmp(
"processing-instruction()", axes) == 0) {
613 }
else if (strcmp(
"text()", axes) == 0) {
616 }
else if (strcmp(
"", axes) == 0) {
637 ROXML_GET_BASE_BUFFER(intern_buff);
641 ns_len = strlen(name);
643 name[ns_len++] =
':';
650 if (name && strcmp(name, xn->
name) == 0)
653 ROXML_PUT_BASE_BUFFER(intern_buff);
682 memset(xn, 0,
sizeof(empty));
684 valid = roxml_validate_axe_func(root, &candidat, xn);
686 if (xn->
next == NULL)
688 if ((xn->
axes == ROXML_ID_SELF) || (xn->
axes == ROXML_ID_PARENT))
692 valid = roxml_validate_axe_name(candidat, xn);
700 if ((valid == 1) && (path_end))
701 roxml_add_to_set(root, candidat, ans, nb, max, req_id);
721 int *nb,
int *max,
int ignore,
int req_id)
723 int validate_node = 0;
725 if ((req_id == 0) && (*nb > 0))
732 if (ignore == ROXML_DESC_ONLY) {
736 current = current->
sibl;
741 case ROXML_ID_CHILD:{
747 current = current->
sibl;
749 if ((xp->
name == NULL) || (strcmp(xp->
name,
"text()") == 0)
750 || (strcmp(xp->
name,
"node()") == 0)) {
754 current = current->
sibl;
757 if ((xp->
name == NULL) || (strcmp(xp->
name,
"node()") == 0)) {
761 current = current->
sibl;
770 case ROXML_ID_DESC_O_SELF:{
783 case ROXML_ID_PARENT:{
798 attribute = attribute->
sibl;
808 current = current->
prnt;
812 case ROXML_ID_NEXT_SIBL:{
818 current = current->
sibl;
822 case ROXML_ID_PREV_SIBL:{
824 while (current != context) {
828 current = current->
sibl;
833 node_t *current = context;
842 xp->
axes = ROXML_ID_CHILD;
845 xp->
axes = ROXML_ID_NEXT;
847 following = following->
sibl;
849 following = current->
prnt->chld;
850 while (following != current)
851 following = following->
sibl;
852 current = following->
sibl;
857 node_t *current = context;
858 while (current && current->
prnt) {
860 while (preceding != current) {
866 xp->
axes = ROXML_ID_CHILD;
869 xp->
axes = ROXML_ID_PREV;
871 preceding = preceding->
sibl;
873 current = current->
prnt;
883 case ROXML_ID_ANC_O_SELF:{
884 node_t *current = context;
889 current = current->
prnt;
910 req_ids = calloc(index,
sizeof(
int));
914 for (path_id = 0; path_id < index; path_id++) {
917 cur_xpath = &xpath[path_id];
919 if (path_id < index - 1)
920 next_xpath = &xpath[path_id + 1];
922 if ((cur_xpath->
rel == ROXML_OPERATOR_AND) || ((next_xpath) && (next_xpath->
rel == ROXML_OPERATOR_AND))) {
930 roxml_check_node(cur_xpath, root, orig, &node_set, count, &max_answers, ROXML_DIRECT, req_id);
932 if (cur_xpath->
rel == ROXML_OPERATOR_AND)
934 req_ids[path_id] = req_id;
939 for (path_id = 0; path_id < index; path_id++) {
942 if (cur_xpath->
rel == ROXML_OPERATOR_OR) {
945 if (req_ids[path_id] == 0) {
950 roxml_check_node(cur_xpath, root, orig, &node_set, count, &max_answers, ROXML_DIRECT,
961 for (path_id = 0; path_id < index; path_id++)
962 if (req_ids[path_id] != 0)
976 char *full_path_to_find;
986 full_path_to_find = strdup(path);
1001 free(full_path_to_find);
1017 struct _xpath_axes {
1022 struct _xpath_axes xpath_axes[14] = {
1023 {ROXML_ID_PARENT, ROXML_L_PARENT},
1024 {ROXML_ID_PARENT, ROXML_S_PARENT},
1025 {ROXML_ID_SELF, ROXML_L_SELF},
1026 {ROXML_ID_SELF, ROXML_S_SELF},
1027 {ROXML_ID_ATTR, ROXML_L_ATTR},
1028 {ROXML_ID_ATTR, ROXML_S_ATTR},
1029 {ROXML_ID_ANC, ROXML_L_ANC},
1030 {ROXML_ID_ANC_O_SELF, ROXML_L_ANC_O_SELF},
1031 {ROXML_ID_NEXT_SIBL, ROXML_L_NEXT_SIBL},
1032 {ROXML_ID_PREV_SIBL, ROXML_L_PREV_SIBL},
1033 {ROXML_ID_NEXT, ROXML_L_NEXT},
1034 {ROXML_ID_PREV, ROXML_L_PREV},
1035 {ROXML_ID_NS, ROXML_L_NS},
1036 {ROXML_ID_CHILD, ROXML_L_CHILD},
1040 if (axes[0] ==
'/') {
1045 if (axes[0] ==
'/') {
1047 node->
axes = ROXML_ID_DESC_O_SELF;
1048 node->
name = axes + 1;
1050 tmp_node->
axes = ROXML_ID_CHILD;
1051 node->
next = tmp_node;
1052 if (strlen(node->
name) > 0) {
1054 node->
next->next = tmp_node;
1057 }
else if (strncmp(ROXML_L_DESC_O_SELF, axes, strlen(ROXML_L_DESC_O_SELF)) == 0) {
1059 node->
axes = ROXML_ID_DESC_O_SELF;
1060 node->
name = axes + strlen(ROXML_L_DESC_O_SELF);
1061 *offset += strlen(ROXML_L_DESC_O_SELF);
1063 tmp_node->
axes = ROXML_ID_CHILD;
1064 node->
next = tmp_node;
1065 node =
roxml_set_axes(tmp_node, axes + strlen(ROXML_L_DESC_O_SELF), offset);
1066 }
else if (strncmp(ROXML_L_DESC, axes, strlen(ROXML_L_DESC)) == 0) {
1068 node->
axes = ROXML_ID_DESC;
1069 node->
name = axes + strlen(ROXML_L_DESC);
1070 *offset += strlen(ROXML_L_DESC);
1072 tmp_node->
axes = ROXML_ID_CHILD;
1073 node->
next = tmp_node;
1074 node =
roxml_set_axes(tmp_node, axes + strlen(ROXML_L_DESC), offset);
1079 node->
axes = ROXML_ID_CHILD;
1082 for (i = 0; i < 14; i++) {
1083 int len = strlen(xpath_axes[i].name);
1084 if (strncmp(xpath_axes[i].name, axes, len) == 0) {
1085 node->
axes = xpath_axes[i].id;
1086 node->
name = axes + len;
1097 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1107 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1139 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1156 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1169ROXML_INT
int _func_xpath_open_parenthesys(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1173 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1181ROXML_INT
int _func_xpath_close_parenthesys(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1185 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1193ROXML_INT
int _func_xpath_open_brackets(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1198 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1217ROXML_INT
int _func_xpath_close_brackets(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1222 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1243ROXML_INT
int _func_xpath_condition_or(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1251 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1254 len = strlen(ROXML_COND_OR);
1256 if (strncmp(chunk, ROXML_COND_OR, len) == 0) {
1263 cur += strlen(ROXML_COND_OR);
1275 cur += strlen(ROXML_COND_OR);
1292ROXML_INT
int _func_xpath_condition_and(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1300 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1303 len = strlen(ROXML_COND_AND);
1305 if (strncmp(chunk, ROXML_COND_AND, len) == 0) {
1311 cur += strlen(ROXML_COND_AND);
1323 cur += strlen(ROXML_COND_AND);
1346 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1351 cur += strlen(ROXML_PATH_OR);
1365ROXML_INT
int _func_xpath_operators(
roxml_parser_item_t *parser,
char *chunk,
void *data,
int operator,
int operator_bis)
1374 xp_cond->
op =
operator;
1376 chunk[cur - 1] =
'\0';
1377 if (chunk[cur + 1] ==
'=') {
1378 chunk[++cur] =
'\0';
1379 xp_cond->
op = operator_bis;
1382 chunk[++cur] =
'\0';
1384 xp_cond->
arg2 = chunk + cur + 1;
1385 if (xp_cond->
arg2[0] ==
'"') {
1388 }
else if (xp_cond->
arg2[0] ==
'\'') {
1392 if (!xp_cond->
func) {
1393 xp_cond->
func = ROXML_FUNC_INTCOMP;
1395 xp_cond->
func = ROXML_FUNC_STRCOMP;
1403 chunk[cur - 1] =
'\0';
1404 if (chunk[cur + 1] ==
'=') {
1405 chunk[++cur] =
'\0';
1409 chunk[++cur] =
'\0';
1430ROXML_INT
int _func_xpath_operator_equal(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1433 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1435 return _func_xpath_operators(parser, chunk, data, ROXML_OPERATOR_EQU, ROXML_OPERATOR_EQU);
1438ROXML_INT
int _func_xpath_operator_sup(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1441 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1443 return _func_xpath_operators(parser, chunk, data, ROXML_OPERATOR_SUP, ROXML_OPERATOR_ESUP);
1446ROXML_INT
int _func_xpath_operator_inf(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1449 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1451 return _func_xpath_operators(parser, chunk, data, ROXML_OPERATOR_INF, ROXML_OPERATOR_EINF);
1454ROXML_INT
int _func_xpath_operator_diff(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1457 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1459 return _func_xpath_operators(parser, chunk, data, ROXML_OPERATOR_DIFF, ROXML_OPERATOR_DIFF);
1465 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1475 while ((chunk[cur + 1] >=
'0') && (chunk[cur + 1] <=
'9'))
1483ROXML_INT
int _func_xpath_funcs(
roxml_parser_item_t *parser,
char *chunk,
void *data,
int func,
char *name)
1486 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1491 if (strncmp(chunk, name, strlen(name)) == 0) {
1493 cur += strlen(name);
1505 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1507 return _func_xpath_funcs(parser, chunk, data, ROXML_FUNC_POS, ROXML_FUNC_POS_STR);
1513 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1515 return _func_xpath_funcs(parser, chunk, data, ROXML_FUNC_FIRST, ROXML_FUNC_FIRST_STR);
1521 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1523 return _func_xpath_funcs(parser, chunk, data, ROXML_FUNC_LAST, ROXML_FUNC_LAST_STR);
1529 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1531 return _func_xpath_funcs(parser, chunk, data, ROXML_FUNC_NSURI, ROXML_FUNC_NSURI_STR);
1537 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1539 return _func_xpath_funcs(parser, chunk, data, ROXML_FUNC_LNAME, ROXML_FUNC_LNAME_STR);
1542ROXML_INT
int _func_xpath_operator_add(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1545 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1555 chunk[++cur] =
'\0';
1563ROXML_INT
int _func_xpath_operator_subs(
roxml_parser_item_t *parser,
char *chunk,
void *data)
1566 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1576 chunk[++cur] =
'\0';
1587 fprintf(stderr,
"calling func %s chunk %c\n", __func__, chunk[0]);
1618 int bracket_lvl = 1;
1621 while (bracket_lvl > 0) {
1622 if (chunk[cur] ==
'[')
1624 else if (chunk[cur] ==
']')
1633 return cur > 0 ? cur : 1;
ROXML_API node_t * roxml_get_root(node_t *n)
root getter function
#define ROXML_INVALID_DOC
ROXML_API void roxml_release(void *data)
memory cleanning function
ROXML_API int roxml_get_chld_nb(node_t *n)
chlds number getter function
ROXML_API node_t * roxml_get_txt(node_t *n, int nth)
text node getter function
ROXML_API node_t * roxml_get_attr(node_t *n, char *name, int nth)
attribute getter function
ROXML_API int roxml_get_node_position(node_t *n)
node get position function
ROXML_API char * roxml_get_content(node_t *n, char *buffer, int bufsize, int *size)
content getter function
ROXML_API node_t * roxml_get_ns(node_t *n)
namespace getter function
ROXML_API char * roxml_get_name(node_t *n, char *buffer, int size)
name getter function
ROXML_INT int roxml_is_separator(char sep)
separator tester
#define MODE_COMMENT_DQUOTE
#define MODE_COMMENT_QUOTE
#define MODE_COMMENT_NONE
ROXML_INT void * roxml_malloc(int size, int num, int type)
alloc memory function
XML internal memory management module.
ROXML_INT int roxml_parse_line(roxml_parser_item_t *parser, char *line, int len, void *ctx)
line parsing function
ROXML_INT roxml_parser_item_t * roxml_parser_prepare(roxml_parser_item_t *parser)
parser preparation function
ROXML_INT roxml_parser_item_t * roxml_append_parser_item(roxml_parser_item_t *parser, char *key, roxml_parse_func func)
parser item creation function
ROXML_INT void roxml_parser_free(roxml_parser_item_t *parser)
parser table deletion
ROXML_STATIC ROXML_INT int roxml_validate_predicat(xpath_node_t *xn, xpath_cond_t *condition, node_t *candidat)
predicat validation function
ROXML_STATIC ROXML_INT void roxml_free_xcond(xpath_cond_t *xcond)
xpath condition free function
ROXML_STATIC ROXML_INT int roxml_double_cmp(double a, double b, int op)
double comparison function
ROXML_STATIC ROXML_INT int roxml_validate_axes(node_t *root, node_t *candidat, node_t ***ans, int *nb, int *max, xpath_node_t *xn, int req_id)
axe validation function
ROXML_API node_t ** roxml_xpath(node_t *n, char *path, int *nb_ans)
exec path function
ROXML_STATIC ROXML_INT xpath_node_t * roxml_set_axes(xpath_node_t *node, char *axes, int *offset)
axes setter function
ROXML_STATIC ROXML_INT int roxml_get_node_internal_position(node_t *n)
node absolute position get
ROXML_INT void roxml_free_xpath(xpath_node_t *xpath, int nb)
xpath free function
ROXML_STATIC ROXML_INT void roxml_compute_and(node_t *root, node_t **node_set, int *count, int cur_req_id, int prev_req_id)
node set and function
ROXML_STATIC ROXML_INT int roxml_string_cmp(char *sa, char *sb, int op)
string comparison function
ROXML_STATIC ROXML_INT int roxml_parse_xpath(char *path, xpath_node_t **xpath, int context)
xpath parsing function
ROXML_STATIC ROXML_INT int roxml_add_to_pool(node_t *root, node_t *n, int req_id)
add a token top node function
ROXML_INT node_t ** roxml_exec_xpath(node_t *root, node_t *n, xpath_node_t *xpath, int index, int *count)
real xpath execution
ROXML_STATIC ROXML_INT void roxml_release_id(node_t *root, node_t **pool, int pool_len, int req_id)
release id function
ROXML_STATIC ROXML_INT int roxml_in_pool(node_t *root, node_t *n, int req_id)
node pool presence tester function
ROXML_STATIC ROXML_INT void roxml_del_from_pool(node_t *root, node_t *n, int req_id)
pool node delete function
ROXML_STATIC ROXML_INT void roxml_compute_or(node_t *root, node_t **node_set, int *count, int req_id, int glob_id)
node set or function
ROXML_STATIC ROXML_INT double roxml_double_oper(double a, double b, int op)
double operation function
ROXML_STATIC ROXML_INT int roxml_is_number(char *input)
number tester
ROXML_STATIC ROXML_INT int roxml_request_id(node_t *root)
id reservation function
ROXML_STATIC ROXML_INT void roxml_check_node(xpath_node_t *xp, node_t *root, node_t *context, node_t ***ans, int *nb, int *max, int ignore, int req_id)
real xpath validation function
xpath_node_t * first_node
struct _xpath_cond * next
struct _xpath_cond * xp_cond
struct _xpath_cond * cond
struct _xpath_node * next