| 1680 | |
| 1681 | #ifdef LIBXML_OUTPUT_ENABLED |
| 1682 | xmlOutputBufferPtr |
| 1683 | __xmlOutputBufferCreateFilename(const char *URI, |
| 1684 | xmlCharEncodingHandlerPtr encoder, |
| 1685 | int compression) { |
| 1686 | xmlOutputBufferPtr ret; |
| 1687 | xmlURIPtr puri; |
| 1688 | int i = 0; |
| 1689 | char *unescaped = NULL; |
| 1690 | |
| 1691 | xmlInitParser(); |
| 1692 | |
| 1693 | if (URI == NULL) |
| 1694 | return(NULL); |
| 1695 | |
| 1696 | puri = xmlParseURI(URI); |
| 1697 | if (puri != NULL) { |
| 1698 | /* |
| 1699 | * try to limit the damages of the URI unescaping code. |
| 1700 | */ |
| 1701 | if (puri->scheme == NULL) { |
| 1702 | unescaped = xmlURIUnescapeString(URI, 0, NULL); |
| 1703 | if (unescaped == NULL) { |
| 1704 | xmlFreeURI(puri); |
| 1705 | return(NULL); |
| 1706 | } |
| 1707 | URI = unescaped; |
| 1708 | } |
| 1709 | xmlFreeURI(puri); |
| 1710 | } |
| 1711 | |
| 1712 | /* |
| 1713 | * Allocate the Output buffer front-end. |
| 1714 | */ |
| 1715 | ret = xmlAllocOutputBufferInternal(encoder); |
| 1716 | if (ret == NULL) { |
| 1717 | xmlFree(unescaped); |
| 1718 | return(NULL); |
| 1719 | } |
| 1720 | |
| 1721 | /* |
| 1722 | * Try to find one of the output accept method accepting that scheme |
| 1723 | * Go in reverse to give precedence to user defined handlers. |
| 1724 | */ |
| 1725 | for (i = xmlOutputCallbackNr - 1; i >= 0; i--) { |
| 1726 | xmlOutputCallback *cb = &xmlOutputCallbackTable[i]; |
| 1727 | int code; |
| 1728 | |
| 1729 | if (cb->matchcallback == xmlIODefaultMatch) { |
| 1730 | code = xmlOutputDefaultOpen(ret, URI, compression); |
| 1731 | /* TODO: Handle other errors */ |
| 1732 | if (code == XML_ERR_OK) |
| 1733 | break; |
| 1734 | } else if ((cb->matchcallback != NULL) && |
| 1735 | (cb->matchcallback(URI) != 0)) { |
| 1736 | ret->context = cb->opencallback(URI); |
| 1737 | if (ret->context != NULL) { |
| 1738 | ret->writecallback = cb->writecallback; |
| 1739 | ret->closecallback = cb->closecallback; |
no test coverage detected