* xmlNodeGetBaseSafe: * @doc: the document the node pertains to * @cur: the node being checked * @baseOut: pointer to base * * Searches for the BASE URL. The code should work on both XML * and HTML document even if base mechanisms are completely different. * It returns the base as defined in RFC 2396 sections * 5.1.1. Base URI within Document Content * and * 5.1.2. Base URI from the E
| 5383 | * memory allocation failed. |
| 5384 | */ |
| 5385 | int |
| 5386 | xmlNodeGetBaseSafe(const xmlDoc *doc, const xmlNode *cur, xmlChar **baseOut) { |
| 5387 | xmlChar *ret = NULL; |
| 5388 | xmlChar *base, *newbase; |
| 5389 | int res; |
| 5390 | |
| 5391 | if (baseOut == NULL) |
| 5392 | return(1); |
| 5393 | *baseOut = NULL; |
| 5394 | if ((cur == NULL) && (doc == NULL)) |
| 5395 | return(1); |
| 5396 | if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| 5397 | return(1); |
| 5398 | if (doc == NULL) |
| 5399 | doc = cur->doc; |
| 5400 | |
| 5401 | if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { |
| 5402 | cur = doc->children; |
| 5403 | while ((cur != NULL) && (cur->name != NULL)) { |
| 5404 | if (cur->type != XML_ELEMENT_NODE) { |
| 5405 | cur = cur->next; |
| 5406 | continue; |
| 5407 | } |
| 5408 | if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) { |
| 5409 | cur = cur->children; |
| 5410 | continue; |
| 5411 | } |
| 5412 | if (!xmlStrcasecmp(cur->name, BAD_CAST "head")) { |
| 5413 | cur = cur->children; |
| 5414 | continue; |
| 5415 | } |
| 5416 | if (!xmlStrcasecmp(cur->name, BAD_CAST "base")) { |
| 5417 | if (xmlNodeGetAttrValue(cur, BAD_CAST "href", NULL, &ret) < 0) |
| 5418 | return(-1); |
| 5419 | if (ret == NULL) |
| 5420 | return(1); |
| 5421 | goto found; |
| 5422 | } |
| 5423 | cur = cur->next; |
| 5424 | } |
| 5425 | return(0); |
| 5426 | } |
| 5427 | |
| 5428 | while (cur != NULL) { |
| 5429 | if (cur->type == XML_ENTITY_DECL) { |
| 5430 | xmlEntityPtr ent = (xmlEntityPtr) cur; |
| 5431 | |
| 5432 | if (ent->URI == NULL) |
| 5433 | break; |
| 5434 | xmlFree(ret); |
| 5435 | ret = xmlStrdup(ent->URI); |
| 5436 | if (ret == NULL) |
| 5437 | return(-1); |
| 5438 | goto found; |
| 5439 | } |
| 5440 | if (cur->type == XML_ELEMENT_NODE) { |
| 5441 | if (xmlNodeGetAttrValue(cur, BAD_CAST "base", XML_XML_NAMESPACE, |
| 5442 | &base) < 0) { |
no test coverage detected