RheiaConfigurationManager::RheiaConfigurationManager():m_doc(NULL),m_root(NULL) { xmlInitParser(); /* Create xpath evaluation context */ xmlXPathInit(); }
void cloudfs_init() { LIBXML_TEST_VERSION xmlXPathInit(); curl_global_init(CURL_GLOBAL_ALL); pthread_mutex_init(&pool_mut, NULL); curl_version_info_data *cvid = curl_version_info(CURLVERSION_NOW); // CentOS/RHEL 5 get stupid mode, because they have a broken libcurl if (cvid->version_num == RHEL5_LIBCURL_VERSION) { debugf("RHEL5 mode enabled."); rhel5_mode = 1; } if (!strncasecmp(cvid->ssl_version, "openssl", 7)) { #ifdef HAVE_OPENSSL int i; ssl_lockarray = (pthread_mutex_t *)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); for (i = 0; i < CRYPTO_num_locks(); i++) pthread_mutex_init(&(ssl_lockarray[i]), NULL); CRYPTO_set_id_callback((unsigned long (*)())thread_id); CRYPTO_set_locking_callback((void (*)())lock_callback); #endif } else if (!strncasecmp(cvid->ssl_version, "nss", 3)) { // allow https to continue working after forking (for RHEL/CentOS 6) setenv("NSS_STRICT_NOFORK", "DISABLED", 1); } }
void Init_fastxml() { if (xmlHasFeature(XML_WITH_TREE) == 0) rb_raise( rb_eRuntimeError, "libxml not built with tree support" ); if (xmlHasFeature(XML_WITH_XPATH) == 0) rb_raise( rb_eRuntimeError, "libxml not built with xpath support" ); s_readlines = rb_intern("readlines"); s_to_s = rb_intern("to_s"); xmlInitParser(); xmlXPathInit(); xsltInit(); rb_mFastXml = rb_define_module( "FastXml" ); rb_define_const( rb_mFastXml, "LIBXML_VERSION", rb_str_new2( LIBXML_DOTTED_VERSION ) ); /* setting symbols */ rb_sValidateDtd = ID2SYM( rb_intern("validate") ); rb_sForgivingParse = ID2SYM( rb_intern("forgiving") ); rb_sHtmlParse = ID2SYM( rb_intern("html") ); Init_fastxml_doc(); /* Doc */ Init_fastxml_node(); /* Node */ Init_fastxml_nodelist(); /* NodeList */ Init_fastxml_attrlist(); /* AttrList */ /* pull in the ruby side of things */ rb_require( "fastxml/fastxml_lib" ); // ruby-side methods for the FastXml classes rb_require( "fastxml/fastxml_helpers" ); // FastXml and FastHtml methods }
/* Get sha1file */ static void get_sha1(const char *ident) { char *path = NULL; char xpath[SIZE]; xmlXPathContextPtr xml_context = NULL; xmlXPathObjectPtr xmlobject; (void)crv_strncpy(xpath, "/database/file[@id='", sizeof(xpath)); (void)crv_strncat(xpath, ident, sizeof(xpath)); (void)crv_strncat(xpath, "']" , sizeof(xpath)); path = crv_strdup(xpath); xmlXPathInit(); xml_context = xmlXPathNewContext (xmldoc); xmlobject = xmlXPathEval (path, xml_context); crv_free(path); if ((xmlobject->type == XPATH_NODESET) ) { int j; xmlNodePtr node; for (j = 0; j < xmlobject->nodesetval->nodeNr; j++) { node = xmlobject->nodesetval->nodeTab[j]; xmlChar *Sha1 = xmlGetProp(node, "sha1"); sha1 = crv_strdup(Sha1); xmlFree (Sha1); } } xmlXPathFreeObject (xmlobject); xmlXPathFreeContext (xml_context); }
static bool libxml_ctor(error_t **UNUSED(error)) { xmlInitParser(); xmlXPathInit(); return TRUE; }
/* * This function inits the parser and gets the total number of LPs to create */ void rn_xml_init() { #if RN_XML_DEBUG printf("Reading in XML topology file: %s\n\n", g_rn_xml_topology); #endif xmlXPathInit(); document_network = xmlReadFile(g_rn_xml_topology, NULL , 0); if(!document_network) tw_error(TW_LOC, "Parsing of network topology file %s failed!", g_rn_xml_topology); ctxt = xmlXPathNewContext(document_network); if(!ctxt) tw_error(TW_LOC, "Could not create network topology XML context!"); /* read in the XML network topology */ rn_xml_topology(); if(g_rn_xml_link_topology != NULL) { document_links = xmlReadFile(g_rn_xml_link_topology, NULL ,0); if(!document_links) tw_error(TW_LOC, "Parsing of link topology file %s failed!", g_rn_xml_link_topology); ctxt_links = xmlXPathNewContext(document_links); if(!ctxt_links) tw_error(TW_LOC, "Unable to create model XML context!"); /* read in the XML link topology */ rn_xml_link_topology(); xmlXPathFreeContext(ctxt_links); } if(NULL != g_rn_xml_model && 0 != strcmp(g_rn_xml_model, "")) { document_model = xmlReadFile(g_rn_xml_model, NULL, 0); if(!document_model) tw_error(TW_LOC, "Parsing of model file %s failed!", g_rn_xml_model); ctxt_model = xmlXPathNewContext(document_model); if(!ctxt_model) tw_error(TW_LOC, "Unable to create model XML context!"); rn_xml_model(); xmlXPathFreeContext(ctxt_model); } }
void parse_config() { FILE *f = NULL; fprintf(stderr,"Reading configuration file: \"%s\" ...\n",config_path); if( (f=fopen (config_path, "r")) == NULL ) { perror("fopen"); exit(1); } LIBXML_TEST_VERSION; /* create a parser context */ ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { fprintf(stderr, "Failed to allocate parser context\n"); fclose(f); return; } /* parse the file, activating the DTD validation option */ doc = xmlCtxtReadFile(ctxt, config_path, NULL, XML_PARSE_DTDVALID); /* check if parsing suceeded */ if (doc == NULL) { fprintf(stderr, "Failed to parse %s\n", config_path); } else { /* check if validation suceeded */ if (ctxt->valid == 0) fprintf(stderr, "Failed to validate %s\n", config_path); /* free up the resulting document */ else { xmlXPathInit(); xpctxt= xmlXPathNewContext(doc); } } autoconf(); get_mail(); init_syslog(); parse_routers(); parse_actions(); #ifdef _COUNTERMEASURES_ parse_countermeasures(); #endif free_xml(); fclose(f); fprintf(stderr," Done.\n"); }
/* Get Info server */ static void get_server_info(const char *ident) { char *path = NULL; char xpath[SIZE]; xmlXPathContextPtr xml_context = NULL; xmlXPathObjectPtr xmlobject; long lval; char *ep; (void)crv_strncpy(xpath, "/database/file[@id='", sizeof(xpath)); (void)crv_strncat(xpath, ident, sizeof(xpath)); (void)crv_strncat(xpath, "']/server" , sizeof(xpath)); path = crv_strdup(xpath); xmlXPathInit(); xml_context = xmlXPathNewContext (xmldoc); xmlobject = xmlXPathEval (path, xml_context); crv_free(path); if ((xmlobject->type == XPATH_NODESET) ) { int j; xmlNodePtr node; for (j = 0; j < xmlobject->nodesetval->nodeNr; j++) { node = xmlobject->nodesetval->nodeTab[j]; xmlChar *Host = xmlGetProp(node, "host"); if (Host != NULL) { server = crv_strdup(Host); } xmlChar *Port = xmlGetProp(node, "port"); if (Port != NULL) { lval = strtol(Port, &ep, 10); if (Port[0] == '\0' || *ep != '\0') { fprintf(stderr, "%s%s", Port, " is not a number"); return; } port = lval; } xmlFree (Host); xmlFree (Port); } } xmlXPathFreeObject (xmlobject); xmlXPathFreeContext (xml_context); }
/** * Retourne le premier produit du catalogue (sinon NULL) **/ xmlNodePtr obtenir_premier_produit(xmlDocPtr doc) { xmlXPathContextPtr ctxt; xmlXPathObjectPtr xpathRes; xmlNodePtr n = NULL; xmlXPathInit(); if (NULL != (ctxt = xmlXPathNewContext(doc))) { xpathRes = xmlXPathEvalExpression(BAD_CAST "/catalogue/produit[position()=1]", ctxt); if (xpathRes && XPATH_NODESET == xpathRes->type && xpathRes->nodesetval->nodeNr == 1) { n = xpathRes->nodesetval->nodeTab[0]; } xmlXPathFreeObject(xpathRes); xmlXPathFreeContext(ctxt); } return n; }
/** * @arg str the XPath expression * @arg ctxt the XPath context * @arg pctxt pointer to a XPath Parser context pointer * * Evaluate the XPath expression in the given context. The XPath Parser * context is saved in pctxt, so that it can be accessed from another thread. * Especially the error state is interesting, since it can be used to stop a * never ending evaluation. * * Taken from xpath.c in libxml2-2.6.16. * * @return the xmlXPathObjectPtr resulting from the evaluation or NULL. * The caller has to free the object. */ xmlXPathObjectPtr my_xmlXPathEvalExpression(const xmlChar *str, xmlXPathContextPtr ctxt, xmlXPathParserContextPtr *pctxt) { xmlXPathObjectPtr res, tmp; int stack = 0; xmlXPathInit(); // it is nice that gcc gives no warning anymore, // but the bad thing is that *pctxt normally is still NULL at this point CHECK_CONTEXT(ctxt,*pctxt) g_mutex_lock(find_nodeset_pcontext_mutex); //g_printerr("Allocating parser context\n"); *pctxt = xmlXPathNewParserContext(str, ctxt); g_mutex_unlock(find_nodeset_pcontext_mutex); xmlXPathEvalExpr(*pctxt); if (*(*pctxt)->cur != 0) { xmlXPatherror(*pctxt, __FILE__, __LINE__, XPATH_EXPR_ERROR); res = NULL; } else { res = valuePop(*pctxt); } do { tmp = valuePop(*pctxt); if (tmp != NULL) { xmlXPathFreeObject(tmp); stack++; } } while (tmp != NULL); if ((stack != 0) && (res != NULL)) { xmlGenericError(xmlGenericErrorContext, "xmlXPathEvalExpression: %d object left on the stack\n", stack); } g_mutex_lock(find_nodeset_pcontext_mutex); xmlXPathFreeParserContext(*pctxt); *pctxt = NULL; //g_printerr("Freed parser context\n"); g_mutex_unlock(find_nodeset_pcontext_mutex); return(res); }
int main() { // Initialisation de l'environnement XPath xmlXPathInit(); // Création du contexte xmlXPathContextPtr ctxt = xmlXPathNewContext( doc ); // doc est un xmlDocPtr représentant notre catalogue if ( ctxt == NULL ) { fprintf( stderr, "Erreur lors de la création du contexte XPath\n" ); exit( -1 ); } // Evaluation de l'expression XPath xmlXPathObjectPtr xpathRes = xmlXPathEvalExpression( "/catalogue/produit[prix<10]/intitule/text()", ctxt ); if ( xpathRes == NULL ) { fprintf( stderr, "Erreur sur l'expression XPath\n" ); exit( -1 ); } // Manipulation du résultat if ( xpathRes->type == XPATH_NODESET ) { int i; printf( "Produits dont le prix est inférieur à 10 Euros :\n" ); for ( i = 0; i < xpathRes->nodesetval->nodeNr; i++ ) { xmlNodePtr n = xpathRes->nodesetval->nodeTab[i]; if ( n->type == XML_TEXT_NODE || n->type == XML_CDATA_SECTION_NODE ) { printf( "- %s\n", n->content ); } } } // Libération de la mémoire xmlXPathFreeObject( xpathRes ); xmlXPathFreeContext( ctxt ); }
int xmlGetXPathString (const char *str, const char * expr, char * rc, const int len) { xmlDocPtr doc; xmlNodePtr cur; xmlXPathContextPtr ctx; xmlXPathObjectPtr path; xmlChar *xmlRC; doc = xmlParseMemory(str, strlen(str)); xmlXPathInit(); ctx = xmlXPathNewContext(doc); path = xmlXPathEvalExpression((const xmlChar *)expr, ctx); cur = path->nodesetval->nodeTab[0]; if (cur != NULL) { xmlRC = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); snprintf(rc, len, "%s\n", xmlRC); xmlFree(xmlRC); xmlFreeDoc(doc); xmlCleanupParser(); xmlXPathFreeObject(path); xmlXPathFreeContext(ctx); return(0); } else { fprintf(stderr,"error in obtaining XPath %s\n", expr); xmlFreeDoc(doc); xmlCleanupParser(); xmlXPathFreeObject(path); xmlXPathFreeContext(ctx); rc[0] = 0x00; return(1); } }
int main(int argc, char argv) { xmlDocPtr doc; xmlXPathContextPtr ctxt; xmlXPathObjectPtr xpathRes; if (2 != argc) { fprintf(stderr, usage %s [FICHIER À PARSER]n, argv[0]); return EXIT_FAILURE; } if (NULL == (doc = xmlParseFile(argv[1]))) { fprintf(stderr, Échec de xmlParseFile()n); return EXIT_FAILURE; } xmlXPathInit(); if (NULL == (ctxt = xmlXPathNewContext(doc))) { fprintf(stderr, Erreur lors de la création du contexte XPathn); return EXIT_FAILURE; } if (NULL == (xpathRes = xmlXPathEvalExpression(BAD_CAST message[@index = '1'], ctxt))) { fprintf(stderr, Erreur sur l'expression XPathn); return EXIT_FAILURE; }
config_t * config_load(const char *config_file) { config_t *c; c = malloc(sizeof(*c)); if (!c) return NULL; /* Analyse du fichier */ c->doc = xmlParseFile(config_file); if (!c->doc) { free(c); return NULL; } /* Recherche du noeud racine */ c->root = xmlDocGetRootElement(c->doc); xmlXPathInit(); c->context = xmlXPathNewContext(c->doc); return c; }
/** * Parses the response and fills in the supplied list with entries (if any) * * @param pResponse Pointer to the response received. * @param pList Pointer to the pointer to the list to populate. * @param pForecast Pointer to the pointer to the forecast to retrieve. * * @return 0 on success, -1 on failure * * @note If the pList pointer is NULL or the pForecast pointer is NULL, * nothing is done and failure is returned. Otherwise, the appropriate * pointer is set based on the name of the XML element: * 'Result' for GList (pList) * 'channel' for Forecast (pForecast) */ static gint parseResponse(gpointer pResponse, GList ** pList, gpointer * pForecast) { int iLocation = (pList)?1:0; xmlDocPtr pDoc = xmlReadMemory(CONSTCHAR_P(pResponse), strlen(pResponse), "", NULL, 0); if (!pDoc) { // failed LXW_LOG(LXW_ERROR, "yahooutil::parseResponse(): Failed to parse response %s", CONSTCHAR_P(pResponse)); return -1; } xmlNodePtr pRoot = xmlDocGetRootElement(pDoc); // the second part of the if can be broken out if (!pRoot || !xmlStrEqual(pRoot->name, CONSTXMLCHAR_P("query"))) { // failed LXW_LOG(LXW_ERROR, "yahooutil::parseResponse(): Failed to retrieve root %s", CONSTCHAR_P(pResponse)); xmlFreeDoc(pDoc); return -1; } // use xpath to find /query/results/Result xmlXPathInit(); xmlXPathContextPtr pXCtxt = xmlXPathNewContext(pDoc); const char * pczExpression = "/query/results/channel"; if (iLocation) { xmlXPathRegisterNs(pXCtxt, CONSTXMLCHAR_P("ns1"), CONSTXMLCHAR_P("http://where.yahooapis.com/v1/schema.rng")); pczExpression = "///ns1:place"; } // have some results... xmlNodeSetPtr pNodeSet = evaluateXPathExpression(pXCtxt, pczExpression); if (!pNodeSet) { // error, or no results found -- failed xmlXPathFreeContext(pXCtxt); xmlFreeDoc(pDoc); return -1; } int iCount = 0; int iSize = pNodeSet->nodeNr; gint iRetVal = 0; for (; iCount < iSize; ++iCount) { if (pNodeSet->nodeTab) { xmlNodePtr pNode = pNodeSet->nodeTab[iCount]; if (pNode && pNode->type == XML_ELEMENT_NODE) { if (xmlStrEqual(pNode->name, CONSTXMLCHAR_P("place"))) { gpointer pEntry = processResultNode(pNode); if (pEntry && pList) { *pList = g_list_prepend(*pList, pEntry); } } else if (xmlStrEqual(pNode->name, CONSTXMLCHAR_P("channel"))) { ForecastInfo * pEntry = NULL; gboolean bNewed = FALSE; /* Check if forecast is allocated, if not, * allocate and populate */ if (pForecast) { if (*pForecast) { pEntry = (ForecastInfo *)*pForecast; } else { pEntry = (ForecastInfo *)g_try_new0(ForecastInfo, 1); bNewed = TRUE; } if (!pEntry) { iRetVal = -1; } else { *pForecast = processChannelNode(pNode, pEntry); if (!*pForecast) { /* Failed, forecast is freed by caller */ /* Unless it was just newed... */ if (bNewed) { g_free(pEntry); } iRetVal = -1; } } }// end else if pForecast }// end else if 'channel' }// end if element }// end if nodeTab }// end for noteTab size xmlXPathFreeNodeSet(pNodeSet); xmlXPathFreeContext(pXCtxt); xmlFreeDoc(pDoc); return iRetVal; }
int globus_i_gram_get_tg_gateway_user( gss_ctx_id_t context, globus_gsi_cred_handle_t peer_cred, char ** gateway_user) { #if HAVE_LIBXML2 OM_uint32 maj_stat, min_stat; gss_buffer_set_t data_set; ASN1_UTF8STRING * asn1_str; char * assertion_string; unsigned char * p; long pl; xmlDocPtr doc; xmlXPathContextPtr xpath_ctx; xmlXPathObjectPtr xresult; int rc; ASN1_OBJECT * asn1_desired_object = NULL; int cert_count; int found_index; int chain_index; X509 *cert; X509_EXTENSION * extension; ASN1_OCTET_STRING *asn1_oct_string; STACK_OF(X509) *chain = NULL; *gateway_user = NULL; if (context == GSS_C_NO_CONTEXT && peer_cred != NULL) { globus_result_t result; /* This basically duplicates the gss_inquire_sec_context_by_oid(), but * instead uses a gsi credential object */ rc = GLOBUS_SUCCESS; asn1_desired_object = ASN1_OBJECT_new(); if (asn1_desired_object == NULL) { rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED; goto no_extension_in_cred_chain; } asn1_desired_object->length = globus_l_saml_oid_desc.length; asn1_desired_object->data = globus_l_saml_oid_desc.elements; result = globus_gsi_cred_get_cert_chain(peer_cred, &chain); if (result != GLOBUS_SUCCESS) { char * msg; msg = globus_error_print_friendly( globus_error_peek(result)); globus_gram_protocol_error_7_hack_replace_message( msg); free(msg); rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; goto no_extension_in_cred_chain; } cert_count = sk_X509_num(chain); found_index = -1; for (chain_index = 0; chain_index < cert_count; chain_index++) { cert = sk_X509_value(chain, chain_index); found_index = X509_get_ext_by_OBJ(cert, asn1_desired_object, found_index); if (found_index >= 0) { extension = X509_get_ext(cert, found_index); if (extension == NULL) { rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; globus_gram_protocol_error_7_hack_replace_message( "Unable to extract SAML assertion extension from certificate chain"); goto no_extension_in_cred_chain; } asn1_oct_string = X509_EXTENSION_get_data(extension); if (asn1_oct_string == NULL) { rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; globus_gram_protocol_error_7_hack_replace_message( "Unable to extract SAML assertion extension from certificate chain"); goto no_extension_in_cred_chain; } p = asn1_oct_string->data; asn1_str = d2i_ASN1_UTF8STRING(NULL, (void *)&p, asn1_oct_string->length); if (asn1_str == NULL) { rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; globus_gram_protocol_error_7_hack_replace_message( "Unable to convert SAML assertion text from DER to UTF8"); goto no_extension_in_cred_chain; } assertion_string = malloc(asn1_str->length + 1); if (assertion_string == NULL) { rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED; goto no_extension_in_cred_chain; } memcpy(assertion_string, asn1_str->data, asn1_str->length); assertion_string[asn1_str->length] = 0; break; } } if (chain_index == cert_count) { goto no_extension_in_cred_chain; } } else if (context == GSS_C_NO_CONTEXT) { rc = GLOBUS_SUCCESS; goto no_context; } else { maj_stat = gss_inquire_sec_context_by_oid( &min_stat, context, globus_saml_oid, &data_set); if (GSS_ERROR(maj_stat)) { globus_gram_protocol_error_7_hack_replace_message( "Error extracting SAML assertion"); rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; goto inquire_failed; } /* We'll process only the first SAML assertion bound in the X.509 chain */ if (data_set->count < 1) { rc = GLOBUS_SUCCESS; goto empty_data_set; } p = data_set->elements[0].value; pl = data_set->elements[0].length; /* Convert DER-Encoded string to UTF8 */ asn1_str = d2i_ASN1_UTF8STRING(NULL, (void *) &p, pl); if (!asn1_str) { globus_gram_protocol_error_7_hack_replace_message( "Error decoding SAML assertion"); rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; goto utfstring_failed; } assertion_string = malloc(asn1_str->length + 1); if (assertion_string == NULL) { rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED; goto assertion_string_malloc_failed; } memcpy(assertion_string, asn1_str->data, asn1_str->length); assertion_string[asn1_str->length] = 0; } /* Parse SAML assertion */ doc = xmlParseDoc(BAD_CAST assertion_string); if (doc == NULL) { globus_gram_protocol_error_7_hack_replace_message( "Error parsing SAML assertion"); rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; goto parse_assertion_failed; } xmlXPathInit(); /* Use XPATH to extract Issuer */ xpath_ctx = xmlXPathNewContext(doc); if (xpath_ctx == NULL) { rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED; goto xpath_ctx_init_failed; } rc = xmlXPathRegisterNs( xpath_ctx, (xmlChar *) "s", (xmlChar *) "urn:oasis:names:tc:SAML:1.0:assertion"); if (rc != 0) { rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED; goto xpath_register_ns_failed; } xresult = xmlXPathEvalExpression( (const xmlChar *) "string(/s:Assertion/@Issuer)", xpath_ctx); if (xresult == NULL) { globus_gram_protocol_error_7_hack_replace_message( "Error processing SAML assertion: no \"Issuer\" attribute"); rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; goto xpath_eval_issuer_failed; } if (! globus_l_tg_saml_assertion_is_self_issued( context, (const char *) xresult->stringval)) { /* Ignore non-self issued assertions */ rc = GLOBUS_SUCCESS; goto non_self_issued; } xmlXPathFreeObject(xresult); /* Use XPATH to extract the sender-vouches, self-issued, TG principal name * Subject attribute from the Assertion's AuthenticationStatement */ xresult = xmlXPathEvalExpression( (const xmlChar *) "string(/s:Assertion/s:AuthenticationStatement/s:Subject[string(s:SubjectConfirmation/s:ConfirmationMethod) = 'urn:oasis:names:tc:SAML:1.0:cm:sender-vouches' and s:NameIdentifier/@Format = 'http://teragrid.org/names/nameid-format/principalname']/s:NameIdentifier[1])", xpath_ctx); if (xresult == NULL) { globus_gram_protocol_error_7_hack_replace_message( "Error processing SAML assertion: no teragrid principal"); rc = GLOBUS_GRAM_PROTOCOL_ERROR_AUTHORIZATION; goto get_gateway_name_failed; } if (xresult != NULL && xresult->stringval != NULL && *(xresult->stringval) != 0) { *gateway_user = strdup((char *) xresult->stringval); } get_gateway_name_failed: non_self_issued: if (xresult != NULL) { xmlXPathFreeObject(xresult); } xpath_eval_issuer_failed: xpath_register_ns_failed: xmlXPathFreeContext(xpath_ctx); xpath_ctx_init_failed: xmlFreeDoc(doc); parse_assertion_failed: free(assertion_string); assertion_string_malloc_failed: ASN1_UTF8STRING_free(asn1_str); utfstring_failed: empty_data_set: gss_release_buffer_set(&min_stat, &data_set); inquire_failed: no_extension_in_cred_chain: no_context: if (asn1_desired_object != NULL) { ASN1_OBJECT_free(asn1_desired_object); } if (chain != NULL) { sk_X509_free(chain); } return rc; #else *gateway_user = NULL; return GLOBUS_SUCCESS; #endif /* HAVE_LIBXML2 */ }
void parse_config_xml(Parameters ¶ms, const std::string &fname) { static bool initxml = false; if(!initxml) { xmlInitParser(); xmlXPathInit(); atexit(xmlCleanupParser); initxml = true; } xmlDoc *doc = NULL; xmlXPathContext *ctx = NULL; try { doc = xmlParseFile(fname.c_str()); if(!doc) throw std::runtime_error("Syntax error in "+fname); if(!doc->children) throw std::runtime_error("Semantic error in "+fname); ctx = xmlXPathNewContext(doc); if(!ctx) throw std::runtime_error("Unable to create XPath context"); params.fname0 = get_data(ctx, "//project/images/@image1",params.fname0); params.fname1 = get_data(ctx, "//project/images/@image2",params.fname1); // circumvent MdiEditor's notion that relative files must begin with '/' if(!params.fname0.empty() && (params.fname0[0] == '/' || params.fname0[0] == '\\')) params.fname0 = params.fname0.substr(1); if(!params.fname1.empty() && (params.fname1[0] == '/' || params.fname1[0]=='\\')) params.fname1 = params.fname1.substr(1); int slash = fname.find_last_of("/\\"); std::string root_path; if(slash != fname.npos) { root_path = fname.substr(0,slash+1); // root_path includes final slash params.fname0 = root_path + params.fname0; params.fname1 = root_path + params.fname1; } std::string base = "/project/layers"; params.w_tps = get_data(ctx, base+"/l0/parameters/weight/@tps", params.w_tps); params.w_ssim = get_data(ctx, base+"/l0/parameters/weight/@ssim", params.w_ssim); params.w_ui = get_data(ctx, base+"/l0/parameters/weight/@ui", params.w_ui); params.ssim_clamp = 1-get_data(ctx, base+"/l0/parameters/weight/@ssimclamp", 1-params.ssim_clamp); int bound; switch(params.bcond) { case BCOND_NONE: bound = 0; break; case BCOND_CORNER: bound = 1; break; case BCOND_BORDER: bound = 2; break; } bound = get_data(ctx, base+"/l0/parameters/boundary/@lock", bound); switch(bound) { case 0: params.bcond = BCOND_NONE; break; case 1: params.bcond = BCOND_CORNER; break; case 2: params.bcond = BCOND_BORDER; break; default: throw std::runtime_error("Bad boundary value"); } params.eps = get_data(ctx, base+"/l0/parameters/debug/@eps", params.eps); params.start_res = get_data(ctx, base+"/l0/parameters/debug/@startres", params.start_res); params.max_iter = get_data(ctx, base+"/l0/parameters/debug/@iternum", params.max_iter); params.max_iter_drop_factor = get_data(ctx, base+"/l0/parameters/debug/@dropfactor", params.max_iter_drop_factor); std::string pts0 = get_data(ctx, base+"/l0/parameters/points/@image1", ""); std::string pts1 = get_data(ctx, base+"/l0/parameters/points/@image2", ""); if(!pts0.empty()) { params.ui_points.clear(); std::istringstream ss0(pts0), ss1(pts1); while(ss0 && ss1) { ConstraintPoint cpt; float2 pt; ss0 >> pt.x >> pt.y; cpt.lp = make_double2(pt.x, pt.y); ss1 >> pt.x >> pt.y; cpt.rp = make_double2(pt.x, pt.y); if(ss0 && ss1) params.ui_points.push_back(cpt); } if(ss0.eof() && !ss1.eof() || !ss0.eof() && ss1.eof()) throw std::runtime_error("Control point parsing error"); } xmlXPathFreeContext(ctx); xmlFreeDoc(doc); }