Logo Search packages:      
Sourcecode: libupnp4 version File versions  Download package

EXPORT_SPEC int UpnpDownloadXmlDoc ( const char *  url,
IXML_Document **  xmlDoc 

Downloads an XML document specified in a URL.

The SDK parses the document and returns it in the form of a DOM document. The application is responsible for freeing the DOM document.

An integer representing one of the following:
  • UPNP_E_SUCCESS: The operation completed successfully.
  • UPNP_E_INVALID_PARAM: Either url or xmlDoc is not a valid pointer.
  • UPNP_E_INVALID_DESC: The XML document was not found or it does not contain a valid XML description.
  • UPNP_E_INVALID_URL: The url is not a valid URL.
  • UPNP_E_OUTOF_MEMORY: There are insufficient resources to download the XML document.
  • UPNP_E_NETWORK_ERROR: A network error occurred.
  • UPNP_E_SOCKET_WRITE: An error or timeout occurred writing to a socket.
  • UPNP_E_SOCKET_READ: An error or timeout occurred reading from a socket.
  • UPNP_E_SOCKET_BIND: An error occurred binding a socket.
  • UPNP_E_SOCKET_CONNECT: An error occurred connecting the socket.
  • UPNP_E_OUTOF_SOCKET: Too many sockets are currently allocated.
url  [in] URL of the XML document.
xmlDoc  [out] A pointer in which to store the XML document.

Definition at line 2587 of file upnpapi.c.

References ixmlFreeDOMString(), ixmlParseBufferEx(), ixmlPrintNode(), UPNP_E_INVALID_DESC, UPNP_E_INVALID_PARAM, UPNP_E_OUTOF_MEMORY, UpnpDownloadUrlItem(), and UpnpPrintf().

      int ret_code;
      char *xml_buf;
      char content_type[LINE_SIZE];

      if (url == NULL || xmlDoc == NULL) {
            return UPNP_E_INVALID_PARAM;

      ret_code = UpnpDownloadUrlItem(url, &xml_buf, content_type);
      if (ret_code != UPNP_E_SUCCESS) {
            UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
                  "Error downloading document, retCode: %d\n", ret_code);
            return ret_code;

      if (strncasecmp(content_type, "text/xml", strlen("text/xml"))) {
            UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, "Not text/xml\n");
            // Linksys WRT54G router returns 
            // "CONTENT-TYPE: application/octet-stream".
            // Let's be nice to Linksys and try to parse document anyway.
            // If the data sended is not a xml file, ixmlParseBufferEx
            // will fail and the function will return UPNP_E_INVALID_DESC too.
#if 0
            return UPNP_E_INVALID_DESC;

      ret_code = ixmlParseBufferEx(xml_buf, xmlDoc);
      if (ret_code != IXML_SUCCESS) {
            if (ret_code == IXML_INSUFFICIENT_MEMORY) {
                  UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
                        "Out of memory, ixml error code: %d\n",
                  return UPNP_E_OUTOF_MEMORY;
            } else {
                  UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
                        "Invalid Description, ixml error code: %d\n",
                  return UPNP_E_INVALID_DESC;
      } else {
#ifdef DEBUG
            xml_buf = ixmlPrintNode((IXML_Node *)*xmlDoc);
            UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
                  "Printing the Parsed xml document \n %s\n", xml_buf);
            UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
                  "****************** END OF Parsed XML Doc *****************\n");
            UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
                  "Exiting UpnpDownloadXmlDoc\n");

            return UPNP_E_SUCCESS;

Generated by  Doxygen 1.6.0   Back to index