Search in sources :

Example 1 with SimpleXMLParserDocumentNode

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.

the class UPnPActionInvocationImpl method invoke.

@Override
public UPnPActionArgument[] invoke() throws UPnPException {
    UPnPService service = action.getService();
    String soap_action = service.getServiceType() + "#" + action.getName();
    SimpleXMLParserDocument resp_doc = null;
    try {
        String request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" + "  <s:Body>\n";
        request += "    <u:" + action.getName() + " xmlns:u=\"" + service.getServiceType() + "\">\n";
        for (int i = 0; i < arg_names.size(); i++) {
            String name = (String) arg_names.get(i);
            String value = (String) arg_values.get(i);
            request += "      <" + name + ">" + value + "</" + name + ">\n";
        }
        request += "    </u:" + action.getName() + ">\n";
        request += "  </s:Body>\n" + "</s:Envelope>";
        // try standard POST
        resp_doc = ((UPnPDeviceImpl) action.getService().getDevice()).getUPnP().performSOAPRequest(service, soap_action, request);
        SimpleXMLParserDocumentNode body = resp_doc.getChild("Body");
        SimpleXMLParserDocumentNode faultSection = body.getChild("Fault");
        if (faultSection != null) {
            String faultValue = faultSection.getValue();
            if (faultValue != null && faultValue.length() > 0) {
                throw (new UPnPException("Invoke of '" + soap_action + "' failed - fault reported: " + faultValue, soap_action, action, resp_doc, faultValue, -1));
            }
            SimpleXMLParserDocumentNode faultDetail = faultSection.getChild("detail");
            if (faultDetail != null) {
                SimpleXMLParserDocumentNode error = faultDetail.getChild("UPnPError");
                if (error != null) {
                    int errCodeNumber = -1;
                    String errDescValue = null;
                    SimpleXMLParserDocumentNode errCode = error.getChild("errorCode");
                    if (errCode != null) {
                        String errCodeValue = errCode.getValue();
                        try {
                            errCodeNumber = Integer.parseInt(errCodeValue);
                        } catch (Throwable t) {
                        }
                    }
                    SimpleXMLParserDocumentNode errDesc = error.getChild("errorDescription");
                    if (errDesc != null) {
                        errDescValue = errDesc.getValue();
                        if (errDescValue != null && errDescValue.length() == 0) {
                            errDescValue = null;
                        }
                    }
                    throw (new UPnPException("Invoke of '" + soap_action + "' failed - fault reported: " + errDescValue, soap_action, action, resp_doc, errDescValue, errCodeNumber));
                }
            }
        }
        SimpleXMLParserDocumentNode resp_node = body.getChild(action.getName() + "Response");
        if (resp_node == null) {
            throw (new UPnPException("Invoke of '" + soap_action + "' failed - response missing: " + body.getValue(), soap_action, action, resp_doc, null, -1));
        }
        SimpleXMLParserDocumentNode[] out_nodes = resp_node.getChildren();
        UPnPActionArgument[] resp = new UPnPActionArgument[out_nodes.length];
        for (int i = 0; i < out_nodes.length; i++) {
            resp[i] = new UPnPActionArgumentImpl(out_nodes[i].getName(), out_nodes[i].getValue());
        }
        return (resp);
    } catch (Throwable e) {
        if (e instanceof UPnPException) {
            throw ((UPnPException) e);
        }
        throw new UPnPException("Invoke of '" + soap_action + "' on '" + action.getService().getControlURLs() + "' failed: " + e.getMessage(), e, soap_action, action, resp_doc);
    }
}
Also used : SimpleXMLParserDocument(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument) UPnPActionArgument(com.biglybt.net.upnp.UPnPActionArgument) UPnPService(com.biglybt.net.upnp.UPnPService) UPnPDeviceImpl(com.biglybt.net.upnp.impl.device.UPnPDeviceImpl) SimpleXMLParserDocumentNode(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode) UPnPException(com.biglybt.net.upnp.UPnPException)

Example 2 with SimpleXMLParserDocumentNode

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.

the class UPnPServiceImpl method parseStateVars.

protected void parseStateVars(SimpleXMLParserDocumentNode action_list) {
    state_vars = new ArrayList();
    SimpleXMLParserDocumentNode[] kids = action_list.getChildren();
    for (int i = 0; i < kids.length; i++) {
        state_vars.add(new UPnPStateVariableImpl(this, kids[i]));
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleXMLParserDocumentNode(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode)

Example 3 with SimpleXMLParserDocumentNode

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.

the class UPnPServiceImpl method parseActions.

protected void parseActions(SimpleXMLParserDocumentNode action_list) {
    actions = new ArrayList();
    SimpleXMLParserDocumentNode[] kids = action_list.getChildren();
    for (int i = 0; i < kids.length; i++) {
        actions.add(new UPnPActionImpl(this, kids[i]));
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleXMLParserDocumentNode(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode)

Example 4 with SimpleXMLParserDocumentNode

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.

the class RSSItemImpl method getLink.

@Override
public URL getLink() {
    SimpleXMLParserDocumentNode link_node = node.getChild("link");
    if (link_node != null) {
        try {
            String value = "";
            if (is_atom) {
                SimpleXMLParserDocumentAttribute attr = link_node.getAttribute("href");
                if (attr == null) {
                    return (null);
                }
                value = attr.getValue().trim();
            } else {
                value = link_node.getValue().trim();
            }
            if (value.length() == 0) {
                return (null);
            }
            if (value.startsWith("//")) {
                value = "http:" + value;
            }
            return (new URL(value));
        } catch (Throwable e) {
            Debug.printStackTrace(e);
            return (null);
        }
    }
    return (null);
}
Also used : SimpleXMLParserDocumentAttribute(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentAttribute) SimpleXMLParserDocumentNode(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode) URL(java.net.URL)

Example 5 with SimpleXMLParserDocumentNode

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.

the class TOTorrentXMLDeserialiser method decodeRoot.

protected TOTorrent decodeRoot(SimpleXMLParserDocument doc) throws TOTorrentException {
    String root_name = doc.getName();
    if (root_name.equalsIgnoreCase("TORRENT")) {
        TOTorrentImpl torrent = new TOTorrentImpl();
        SimpleXMLParserDocumentNode[] kids = doc.getChildren();
        URL announce_url = null;
        byte[] torrent_hash = null;
        byte[] torrent_hash_override = null;
        for (int i = 0; i < kids.length; i++) {
            SimpleXMLParserDocumentNode kid = kids[i];
            String name = kid.getName();
            if (name.equalsIgnoreCase("ANNOUNCE_URL")) {
                try {
                    announce_url = new URL(kid.getValue());
                } catch (MalformedURLException e) {
                    throw (new TOTorrentException("ANNOUNCE_URL malformed", TOTorrentException.RT_DECODE_FAILS));
                }
            } else if (name.equalsIgnoreCase("ANNOUNCE_LIST")) {
                SimpleXMLParserDocumentNode[] set_nodes = kid.getChildren();
                TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
                TOTorrentAnnounceURLSet[] sets = new TOTorrentAnnounceURLSet[set_nodes.length];
                for (int j = 0; j < sets.length; j++) {
                    SimpleXMLParserDocumentNode[] url_nodes = set_nodes[j].getChildren();
                    URL[] urls = new URL[url_nodes.length];
                    for (int k = 0; k < urls.length; k++) {
                        try {
                            urls[k] = new URL(url_nodes[k].getValue());
                        } catch (MalformedURLException e) {
                            throw (new TOTorrentException("ANNOUNCE_LIST malformed", TOTorrentException.RT_DECODE_FAILS));
                        }
                    }
                    sets[j] = group.createAnnounceURLSet(urls);
                }
                group.setAnnounceURLSets(sets);
            } else if (name.equalsIgnoreCase("COMMENT")) {
                torrent.setComment(readLocalisableString(kid));
            } else if (name.equalsIgnoreCase("CREATED_BY")) {
                torrent.setCreatedBy(readLocalisableString(kid));
            } else if (name.equalsIgnoreCase("CREATION_DATE")) {
                torrent.setCreationDate(readGenericLong(kid).longValue());
            } else if (name.equalsIgnoreCase("TORRENT_HASH")) {
                torrent_hash = readGenericBytes(kid);
            } else if (name.equalsIgnoreCase("TORRENT_HASH_OVERRIDE")) {
                torrent_hash_override = readGenericBytes(kid);
            } else if (name.equalsIgnoreCase("INFO")) {
                decodeInfo(kid, torrent);
            } else {
                mapEntry entry = readGenericMapEntry(kid);
                torrent.addAdditionalProperty(entry.name, entry.value);
            }
        }
        if (announce_url == null) {
            throw (new TOTorrentException("ANNOUNCE_URL missing", TOTorrentException.RT_DECODE_FAILS));
        }
        torrent.setAnnounceURL(announce_url);
        if (torrent_hash_override != null) {
            try {
                torrent.setHashOverride(torrent_hash_override);
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
        if (torrent_hash != null) {
            if (!Arrays.equals(torrent.getHash(), torrent_hash)) {
                throw (new TOTorrentException("Hash differs - declared TORRENT_HASH and computed hash differ. If this really is the intent (unlikely) then remove the TORRENT_HASH element", TOTorrentException.RT_DECODE_FAILS));
            }
        }
        return (torrent);
    } else {
        throw (new TOTorrentException("Invalid root element", TOTorrentException.RT_DECODE_FAILS));
    }
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) MalformedURLException(java.net.MalformedURLException) SimpleXMLParserDocumentNode(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode) URL(java.net.URL) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)

Aggregations

SimpleXMLParserDocumentNode (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode)11 URL (java.net.URL)5 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 SimpleXMLParserDocument (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument)3 SimpleXMLParserDocumentAttribute (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentAttribute)3 ArrayList (java.util.ArrayList)3 UPnPException (com.biglybt.net.upnp.UPnPException)2 WebResult (com.biglybt.core.metasearch.impl.web.WebResult)1 TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)1 UPnPActionArgument (com.biglybt.net.upnp.UPnPActionArgument)1 UPnPService (com.biglybt.net.upnp.UPnPService)1 UPnPDeviceImpl (com.biglybt.net.upnp.impl.device.UPnPDeviceImpl)1 UPnPMSException (com.biglybt.net.upnpms.UPnPMSException)1 RSSChannel (com.biglybt.pif.utils.xml.rss.RSSChannel)1 RSSFeed (com.biglybt.pif.utils.xml.rss.RSSFeed)1 RSSItem (com.biglybt.pif.utils.xml.rss.RSSItem)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MalformedURLException (java.net.MalformedURLException)1 Matcher (java.util.regex.Matcher)1