int xml_tree_get_next_attribute( struct xml_private_tree *xml_tree, char *name, char *value, int maxlen ) { if (xml_tree->traverse_attrib != 0) { xml_strncpy(name, xml_tree->traverse_attrib->name, maxlen); xml_strncpy(value, xml_tree->traverse_attrib->value, maxlen); xml_tree->traverse_attrib = xml_tree->traverse_attrib->nxt; return 1; } else { name[0] = '\0'; value[0] = '\0'; return 0; } }
void xml_tree_start_traverse( struct xml_private_tree **xml_tree, Xml_object *roottag, char *tag, char *contents, int maxlen ) { *xml_tree = (struct xml_private_tree *)calloc(1,sizeof(struct xml_private_tree)); (*xml_tree)->traverse_node = roottag; if (roottag != 0) { xml_strncpy(tag, (*xml_tree)->traverse_node->tag, maxlen); xml_strncpy(contents, (*xml_tree)->traverse_node->contents, maxlen); (*xml_tree)->traverse_attrib = roottag->attributes; } (*xml_tree)->traverse_parent = 0; }
int xml_tree_get_next_tag( struct xml_private_tree *xml_tree, char *tag, char *contents, int maxlen ) { if (xml_tree==0) {printf("Error: xml_tree_get_next_tag called on empty tree, or beyond tree.\n"); tag[0] = '\0'; contents[0] = '\0'; return 0; } if (xml_tree->traverse_node != 0) xml_tree->traverse_node = xml_tree->traverse_node->nxt; if (xml_tree->traverse_node != 0) { xml_strncpy(tag, xml_tree->traverse_node->tag, maxlen); xml_strncpy(contents, xml_tree->traverse_node->contents, maxlen); xml_tree->traverse_attrib = xml_tree->traverse_node->attributes; return 1; } else { tag[0] = '\0'; contents[0] = '\0'; return 0; } }
int xml_tree_descend_to_child( struct xml_private_tree **xml_tree, char *tag, char *contents, int maxlen ) { struct xml_private_tree *newitem; if ((*xml_tree)->traverse_node->children != 0) { newitem = (struct xml_private_tree *)calloc(1,sizeof(struct xml_private_tree)); newitem->traverse_node = (*xml_tree)->traverse_node->children; newitem->traverse_attrib = newitem->traverse_node->attributes; newitem->traverse_parent = *xml_tree; xml_strncpy(tag, newitem->traverse_node->tag, maxlen); xml_strncpy(contents, newitem->traverse_node->contents, maxlen); *xml_tree = newitem; return 1; } else { tag[0] = '\0'; contents[0] = '\0'; return 0; } }
/******************************************************************** * build a prefix map using the xmplns directives in a message. * * \param msg the message in progrss * \param attrs the the top-level attrs list (e;g, rpc_in_attrs) * \return status *********************************************************************/ static status_t build_prefix_map_from_xmlns_directives( xml_msg_hdr_t* msg, xml_attrs_t* attrs ) { xmlns_id_t invid = xmlns_inv_id(); xml_attr_t *attr = (xml_attr_t *)xml_first_attr(attrs); for ( ; attr; attr = (xml_attr_t *)xml_next_attr(attr)) { /* make sure this is an XMLNS attribute with or wo a prefix */ if (xml_strncmp(XMLNS, attr->attr_qname, XMLNS_LEN)) { continue; } /* find the namespace associated with the prefix note: it is not an error to have extra xmlns decls in the <rpc>elem; still need to make sure not to reuse the prefix anyway */ xmlns_t *nsrec = def_reg_find_ns(attr->attr_val); /* check if this attribute has a prefix */ if (attr->attr_qname == attr->attr_name) { /* no prefix in the name so this must be the default namespace */ if ( !nsrec ) { /* the default namespace is not one of ours, so it will not be * used in the reply */ attr->attr_xmlns_ns = invid; } else { attr->attr_xmlns_ns = nsrec->ns_id; } continue; } /* there is a prefix, so get the prefix len. * The entire prefix was saved as the attr_name */ uint32 plen = xml_strlen(attr->attr_name); /* get a new prefix map */ xmlns_pmap_t *newpmap = xmlns_new_pmap(plen+1); if (!newpmap) { return ERR_INTERNAL_MEM; } /* save the prefix and the xmlns ID */ xml_strncpy(newpmap->nm_pfix, attr->attr_name, plen); if ( !nsrec ) { newpmap->nm_id = invid; attr->attr_xmlns_ns = invid; } else { newpmap->nm_id = nsrec->ns_id; attr->attr_xmlns_ns = nsrec->ns_id; } newpmap->nm_topattr = TRUE; add_pmap(msg, newpmap); } return NO_ERR; }
static int match_nodes( const mxml_char_t * path, size_t *path_len, mxml_node *n, LIST_TYPE lst ) { #define XPATH_MAX_LEN 128 mxml_char_t buffer [XPATH_MAX_LEN]; const mxml_char_t * slash_ptr = xml_strchr( path, (mxml_char_t)('/') ); const size_t length = slash_ptr ? (size_t)(slash_ptr - path) : 0; match m; if ( length >= XPATH_MAX_LEN ) return -1; memset( buffer, 0, XPATH_MAX_LEN * sizeof( mxml_char_t ) ); //* if ( length ) xml_strncpy( buffer, path, length ); else xml_strcpy( buffer, path ); init_str( &m.value ); init_str( &m.pred.cond_value ); init_str( &m.pred.value ); if ( 0 == identify_match( buffer, &m ) ) { if ( 0 != xpath_match( lst, n, &m ) ) return -1; else { *path_len = length; return 0; } } //*/ return -1; #undef XPATH_MAX_LEN }
/******************************************************************** * FUNCTION set_initial_transaction_id * * Set the last_transaction_id for the running config * Will check for sys:transaction-id leaf in config->root * * RETURNS: * status *********************************************************************/ static status_t set_initial_transaction_id (void) { cfg_template_t *cfg = cfg_get_config_id(NCX_CFGID_RUNNING); if (cfg == NULL) { return ERR_NCX_CFG_NOT_FOUND; } if (cfg->root == NULL) { return ERR_NCX_EMPTY_VAL; } agt_profile_t *profile = agt_get_profile(); status_t res = NO_ERR; boolean foundfile = FALSE; /* figure out which transaction ID file to use */ if (profile->agt_startup_txid_file == NULL) { /* search for the default startup-cfg.xml filename */ xmlChar *fname = ncxmod_find_data_file(NCX_DEF_STARTUP_TXID_FILE, FALSE, &res); if (fname == NULL || res != NO_ERR || *fname == 0) { /* need to set the default startup transaction ID file name */ log_debug("\nSetting initial transaction ID file to default"); if (fname) { m__free(fname); } res = NO_ERR; fname = agt_get_startup_filespec(&res); if (fname == NULL || res != NO_ERR) { if (res == NO_ERR) { res = ERR_NCX_OPERATION_FAILED; } log_error("\nFailed to set initial transaction ID file (%s)", get_error_string(res)); if (fname) { m__free(fname); } return res; } /* get dir part and append the TXID file name to it */ uint32 fnamelen = xml_strlen(fname); xmlChar *str = &fname[fnamelen - 1]; while (str >= fname && *str && *str != NCX_PATHSEP_CH) { str--; } if (*str != NCX_PATHSEP_CH) { log_error("\nFailed to set initial transaction ID file"); m__free(fname); return ERR_NCX_INVALID_VALUE; } /* copy base filespec + 1 for the path-sep-ch */ uint32 baselen = (uint32)(str - fname) + 1; uint32 newlen = baselen + xml_strlen(NCX_DEF_STARTUP_TXID_FILE); xmlChar *newstr = m__getMem(newlen + 1); if (newstr == NULL) { m__free(fname); return ERR_INTERNAL_MEM; } str = newstr; str += xml_strncpy(str, fname, baselen); xml_strcpy(str, NCX_DEF_STARTUP_TXID_FILE); m__free(fname); profile->agt_startup_txid_file = newstr; // pass off memory here } else { foundfile = TRUE; profile->agt_startup_txid_file = fname; // pass off memory here } } /* initialize the starting transaction ID in the config module */ res = agt_cfg_init_transactions(profile->agt_startup_txid_file, foundfile); if (res != NO_ERR) { log_error("\nError: cfg-init transaction ID failed (%s)", get_error_string(res)); } return res; } /* set_initial_transaction_id */