static int fast_message_init(xmlNodePtr node, struct fast_message *msg) { struct fast_field *field; int nr_fields; xmlChar *prop; int pmap_bit; int ret = 1; if (xmlStrcmp(node->name, (const xmlChar *)"template")) goto exit; prop = xmlGetProp(node, (const xmlChar *)"id"); if (prop != NULL) msg->tid = strtol((char *)prop, NULL, 10); else msg->tid = 0; xmlFree(prop); prop = xmlGetProp(node, (const xmlChar *)"reset"); if (prop != NULL && !xmlStrcmp(prop, (const xmlChar *)"T")) fast_msg_add_flags(msg, FAST_MSG_FLAGS_RESET); xmlFree(prop); nr_fields = xmlChildElementCount(node); msg->fields = calloc(nr_fields, sizeof(struct fast_field)); if (!msg->fields) goto exit; msg->nr_fields = 0; pmap_bit = 1; node = node->xmlChildrenNode; while (node != NULL) { if (node->type != XML_ELEMENT_NODE) { node = node->next; continue; } field = msg->fields + msg->nr_fields; if (fast_field_init(node, field)) goto exit; if (pmap_required(field)) field->pmap_bit = pmap_bit++; msg->nr_fields++; node = node->next; } ret = 0; exit: return ret; }
static void xml_end_list(pcmk__output_t *out) { char *buf = NULL; xml_private_t *priv = out->priv; xmlNodePtr node; CRM_ASSERT(priv != NULL); node = g_queue_pop_tail(priv->parent_q); buf = crm_strdup_printf("%lu", xmlChildElementCount(node)); xmlSetProp(node, (pcmkXmlStr) "count", (pcmkXmlStr) buf); free(buf); }
int fast_micex_template(struct fast_session *self, const char *xml) { struct fast_message *msg; xmlNodePtr node; xmlDocPtr doc; int ret = 1; doc = xmlParseFile(xml); if (doc == NULL) goto exit; node = xmlDocGetRootElement(doc); if (node == NULL) goto exit; if (xmlStrcmp(node->name, (const xmlChar *)"templates")) goto free; if (xmlChildElementCount(node) > FAST_TEMPLATE_MAX_NUMBER) goto free; node = node->xmlChildrenNode; while (node != NULL) { if (node->type != XML_ELEMENT_NODE) { node = node->next; continue; } msg = self->rx_messages + self->nr_messages; if (fast_message_init(node, msg)) goto free; self->nr_messages++; node = node->next; } ret = 0; free: xmlFreeDoc(doc); exit: return ret; }
unsigned long drivers_parse_from_xml_file(Driver** d, const char* filename) { xmlDoc* doc; xmlNode* xml_root; xmlNode* curr_driver; unsigned long n_drivers; unsigned int i; *d = NULL; doc = xmlReadFile(filename, NULL, 0); if(doc == NULL) goto PARSE_ERROR; xml_root = xmlDocGetRootElement(doc); n_drivers = xmlChildElementCount(xml_root); *d = malloc(sizeof(Driver) * n_drivers * 3); //TODO: Fix 3 for(i=0,curr_driver = xml_root->xmlChildrenNode; curr_driver != NULL; curr_driver = curr_driver->next) { int driver_parse_res; if(!xmlStrcmp(curr_driver->name,(xmlChar*) "driver")) { driver_parse_res = driver_from_xml( &((*d)[i]), curr_driver ); if(driver_parse_res == 0) goto PARSE_ERROR; i++; } } xmlFreeDoc(doc); return i; PARSE_ERROR: xmlFreeDoc(doc); free(*d); *d = NULL; return 0; }
static int fast_sequence_init(xmlNodePtr node, struct fast_field *field) { struct fast_sequence *seq; struct fast_message *msg; struct fast_field *orig; xmlNodePtr tmp; int i, ret = 1; int nr_fields; int pmap_bit; field->ptr_value = calloc(1, sizeof(struct fast_sequence)); if (!field->ptr_value) goto exit; seq = field->ptr_value; nr_fields = xmlChildElementCount(node); node = node->xmlChildrenNode; while (node && node->type != XML_ELEMENT_NODE) node = node->next; if (xmlStrcmp(node->name, (const xmlChar *)"length")) goto exit; if (fast_field_init(node, &seq->length)) goto exit; if (!field_is_mandatory(field)) seq->length.presence = FAST_PRESENCE_OPTIONAL; node = node->next; orig = field; for (i = 0; i < FAST_SEQUENCE_ELEMENTS; i++) { msg = seq->elements + i; tmp = node; msg->fields = calloc(nr_fields, sizeof(struct fast_field)); if (!msg->fields) goto exit; msg->nr_fields = 0; pmap_bit = 0; while (tmp != NULL) { if (tmp->type != XML_ELEMENT_NODE) { tmp = tmp->next; continue; } field = msg->fields + msg->nr_fields; if (fast_field_init(tmp, field)) goto exit; if (pmap_required(field)) { field_add_flags(orig, FAST_FIELD_FLAGS_PMAPREQ); field->pmap_bit = pmap_bit++; } msg->nr_fields++; tmp = tmp->next; } } ret = 0; exit: return ret; }
static int fast_message_init(xmlNodePtr node, struct fast_message *msg) { struct fast_field *field; int nr_fields; xmlChar *prop; int ret = 1; if (xmlStrcmp(node->name, (const xmlChar *)"template")) goto exit; prop = xmlGetProp(node, (const xmlChar *)"id"); if (prop != NULL) msg->tid = strtol((char *)prop, NULL, 10); else msg->tid = 0; xmlFree(prop); prop = xmlGetProp(node, (const xmlChar *)"name"); if (prop != NULL) strncpy(msg->name, (const char *)prop, sizeof(msg->name)); else strncpy(msg->name, (const char *)"", sizeof(msg->name)); xmlFree(prop); prop = xmlGetProp(node, (const xmlChar *)"reset"); if (prop != NULL && !xmlStrcmp(prop, (const xmlChar *)"T")) fast_msg_add_flags(msg, FAST_MSG_FLAGS_RESET); xmlFree(prop); nr_fields = xmlChildElementCount(node); msg->fields = calloc(nr_fields, sizeof(struct fast_field)); if (!msg->fields) goto exit; msg->nr_fields = 0; msg->ghtab = g_hash_table_new(g_str_hash, g_str_equal); if (!msg->ghtab) goto exit; node = node->xmlChildrenNode; while (node != NULL) { if (node->type != XML_ELEMENT_NODE) { node = node->next; continue; } field = msg->fields + msg->nr_fields; if (fast_field_init(node, field)) goto exit; if (strlen(field->name)) g_hash_table_insert(msg->ghtab, field->name, field); msg->nr_fields++; node = node->next; } ret = 0; exit: return ret; }
char * xml_node_get_text(struct xml_node_ctx *ctx, xml_node_t *node) { if (xmlChildElementCount((xmlNodePtr) node) > 0) return NULL; return (char *) xmlNodeGetContent((xmlNodePtr) node); }
/** * print_xpath_nodes: * nodes: the nodes set. * output: the output file handle. * * Print the node content to the file */ static int print_xpath_nodes(xmlDocPtr doc, xmlNodeSetPtr nodes, FILE *output) { int ret = 0; int size; int i; xmlNodePtr cur; xmlChar *node_child_value_string = NULL; assert(output); size = (nodes) ? nodes->nodeNr : 0; for (i = 0; i < size; ++i) { assert(nodes->nodeTab[i]); if (nodes->nodeTab[i]->type == XML_NAMESPACE_DECL) { fprintf(stderr, "ERR:%s\n", "This executable does not support xml namespacing\n"); ret = -1; goto end; } else if (nodes->nodeTab[i]->type == XML_ELEMENT_NODE) { cur = nodes->nodeTab[i]; if (xmlChildElementCount(cur) == 0) { if (xmlNodeIsText(cur->children)) { node_child_value_string = xmlNodeListGetString(doc, cur->children, 1); if (node_exist) { fprintf(output, "true\n"); } else if (opt_verbose) { fprintf(output, "%s;%s;\n", cur->name, node_child_value_string); } else { fprintf(output, "%s\n", node_child_value_string); } xmlFree(node_child_value_string); } else { /* We don't want to print non-final element */ if (node_exist) { fprintf(output, "true\n"); } else { fprintf(stderr, "ERR:%s\n", "Xpath expression return non-final xml element"); ret = -1; goto end; } } } else { if (node_exist) { fprintf(output, "true\n"); } else { /* We don't want to print non-final element */ fprintf(stderr, "ERR:%s\n", "Xpath expression return non-final xml element"); ret = -1; goto end; } } } else { cur = nodes->nodeTab[i]; if (node_exist) { fprintf(output, "true\n"); } else if (opt_verbose) { fprintf(output, "%s;%s;\n", cur->parent->name, cur->content); } else { fprintf(output, "%s\n", cur->content); } } } /* Command Success */ ret = 0; end: return ret; }