/** * Change working URI * * @v uri New working URI, or NULL */ void churi ( struct uri *uri ) { struct uri *new_uri; new_uri = resolve_uri ( cwuri, uri ); uri_put ( cwuri ); cwuri = new_uri; }
static int test_resolve ( const char *base_uri_string, const char *relative_uri_string, const char *resolved_uri_string ) { struct uri *base_uri = NULL; struct uri *relative_uri = NULL; struct uri *resolved_uri = NULL; char buf[URI_MAX_LEN]; size_t len; int rc; /* Parse URIs */ base_uri = parse_uri ( base_uri_string ); if ( ! base_uri ) { rc = -ENOMEM; goto done; } relative_uri = parse_uri ( relative_uri_string ); if ( ! relative_uri ) { rc = -ENOMEM; goto done; } /* Resolve URI */ resolved_uri = resolve_uri ( base_uri, relative_uri ); if ( ! resolved_uri ) { rc = -ENOMEM; goto done; } /* Compare result */ len = unparse_uri ( buf, sizeof ( buf ), resolved_uri, URI_ALL ); if ( strcmp ( buf, resolved_uri_string ) != 0 ) { printf ( "Resolution of \"%s\"+\"%s\" produced \"%s\"\n", base_uri_string, relative_uri_string, buf ); rc = -EINVAL; goto done; } rc = 0; done: uri_put ( base_uri ); uri_put ( relative_uri ); uri_put ( resolved_uri ); if ( rc ) { printf ( "URI resolution of \"%s\"+\"%s\" failed: %s\n", base_uri_string, relative_uri_string, strerror ( rc ) ); } return rc; }
void FeedParser::parse_depends(XmlReader& xml, Dependencies& depends) { while (xml.start_element()) { std::string name = xml.name(); if (name == "if") { depends.start_if(xml.attribute("test", project_ns)); parse_depends(xml, depends); depends.end_if(); } else if (name == "elseif") { depends.start_elseif(xml.attribute("test", project_ns)); parse_depends(xml, depends); depends.end_if(); } else if (name == "else") { depends.start_else(); parse_depends(xml, depends); depends.end_if(); } else if (name == "depends") { std::string dep = resolve_uri(spec.id, xml.attribute("href", project_ns)); depends.depends(Spec(dep.c_str())); } else if (name == "conflicts") { std::string dep = resolve_uri(spec.id, xml.attribute("href", project_ns)); depends.conflicts(Spec(dep.c_str())); } xml.skip(); } }
/** * Open URI * * @v intf Data transfer interface * @v uri URI * @ret rc Return status code * * The URI will be regarded as being relative to the current working * URI (see churi()). */ int xfer_open_uri ( struct interface *intf, struct uri *uri ) { struct uri_opener *opener; struct uri *resolved_uri; int rc; /* Resolve URI */ resolved_uri = resolve_uri ( cwuri, uri ); if ( ! resolved_uri ) { rc = -ENOMEM; goto err_resolve_uri; } /* Find opener which supports this URI scheme */ opener = xfer_uri_opener ( resolved_uri->scheme ); if ( ! opener ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open " "unsupported URI scheme \"%s\"\n", INTF_DBG ( intf ), resolved_uri->scheme ); rc = -ENOTSUP; goto err_opener; } /* Call opener */ DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening %s URI\n", INTF_DBG ( intf ), resolved_uri->scheme ); if ( ( rc = opener->open ( intf, resolved_uri ) ) != 0 ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " could not open: " "%s\n", INTF_DBG ( intf ), strerror ( rc ) ); goto err_open; } err_open: err_opener: uri_put ( resolved_uri ); err_resolve_uri: return rc; }