* xmlNanoHTTPFetch: * @URL: The URL to load * @filename: the filename where the content should be saved * @contentType: if available the Content-Type information will be * returned at that location * * This function try to fetch the indicated resource via HTTP GET * and save it's content in the file. * * Returns -1 in case of failure, 0 in case of success. The contentTyp
| 1587 | * if provided must be freed by the caller |
| 1588 | */ |
| 1589 | int |
| 1590 | xmlNanoHTTPFetch(const char *URL, const char *filename, char **contentType) { |
| 1591 | void *ctxt = NULL; |
| 1592 | char *buf = NULL; |
| 1593 | int fd; |
| 1594 | int len; |
| 1595 | int ret = 0; |
| 1596 | |
| 1597 | if (filename == NULL) return(-1); |
| 1598 | ctxt = xmlNanoHTTPOpen(URL, contentType); |
| 1599 | if (ctxt == NULL) return(-1); |
| 1600 | |
| 1601 | if (!strcmp(filename, "-")) |
| 1602 | fd = 0; |
| 1603 | else { |
| 1604 | fd = open(filename, O_CREAT | O_WRONLY, 00644); |
| 1605 | if (fd < 0) { |
| 1606 | xmlNanoHTTPClose(ctxt); |
| 1607 | if ((contentType != NULL) && (*contentType != NULL)) { |
| 1608 | xmlFree(*contentType); |
| 1609 | *contentType = NULL; |
| 1610 | } |
| 1611 | return(-1); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | xmlNanoHTTPFetchContent( ctxt, &buf, &len ); |
| 1616 | if ( len > 0 ) { |
| 1617 | if (write(fd, buf, len) == -1) { |
| 1618 | ret = -1; |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | xmlNanoHTTPClose(ctxt); |
| 1623 | close(fd); |
| 1624 | return(ret); |
| 1625 | } |
| 1626 | |
| 1627 | #ifdef LIBXML_OUTPUT_ENABLED |
| 1628 | /** |
no test coverage detected