Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Replaced old UPNP library with Weupnp. UPNP should work now, at least it does on my network. UPNP code in YaCy can still be improved though (see TODO comment: make port on gateway configurable or find free one).
Marc Nause477be17c513b
diff --git a/.classpath b/.classpathindex 56214500b..2cbfa9d44 100644--- a/.classpath+++ b/.classpath@@ -1,90 +1,91 @@-<?xml version="1.0" encoding="UTF-8"?>-<classpath>- <classpathentry kind="src" path="source"/>- <classpathentry excluding="api/|env/|processing/domaingraph/applet/|yacy/|api/bookmarks/|api/ymarks/|api/bookmarks/posts/|api/bookmarks/tags/|api/bookmarks/xbel/|solr/|gsa/|solr/collection1/" kind="src" path="htroot"/>- <classpathentry excluding="bookmarks/|ymarks/|bookmarks/posts/|bookmarks/tags/|bookmarks/xbel/" kind="src" path="htroot/api"/>- <classpathentry kind="src" path="htroot/env"/>- <classpathentry kind="src" path="htroot/yacy"/>- <classpathentry excluding="posts/|tags/|xbel/" kind="src" path="htroot/api/bookmarks"/>- <classpathentry kind="src" path="htroot/api/ymarks"/>- <classpathentry kind="src" path="htroot/api/bookmarks/posts"/>- <classpathentry kind="src" path="htroot/api/bookmarks/tags"/>- <classpathentry kind="src" path="htroot/api/bookmarks/xbel"/>- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>- <classpathentry kind="lib" path="lib/commons-logging-1.1.3.jar"/>- <classpathentry kind="lib" path="lib/J7Zip-modified.jar"/>- <classpathentry kind="lib" path="lib/webcat-0.1-swf.jar"/>- <classpathentry kind="lib" path="lib/commons-jxpath-1.3.jar"/>- <classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>- <classpathentry kind="lib" path="lib/jakarta-oro-2.0.8.jar"/>- <classpathentry kind="lib" path="lib/apache-mime4j-0.6.jar"/>- <classpathentry kind="lib" path="lib/commons-fileupload-1.2.2.jar"/>- <classpathentry kind="lib" path="lib/json-simple-1.1.1.jar"/>- <classpathentry kind="lib" path="lib/xercesImpl.jar"/>- <classpathentry kind="lib" path="lib/xml-apis.jar"/>- <classpathentry kind="lib" path="lib/geronimo-stax-api_1.0_spec-1.0.1.jar"/>- <classpathentry kind="lib" path="lib/commons-compress-1.8.jar"/>- <classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>- <classpathentry kind="lib" path="lib/jaudiotagger-2.0.4-20111207.115108-15.jar"/>- <classpathentry kind="lib" path="lib/commons-codec-1.7.jar"/>- <classpathentry kind="lib" path="lib/jcl-over-slf4j-1.7.2.jar"/>- <classpathentry kind="lib" path="lib/wstx-asl-3.2.9.jar"/>- <classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.2.jar"/>- <classpathentry kind="lib" path="lib/log4j-over-slf4j-1.7.2.jar"/>- <classpathentry kind="lib" path="lib/httpclient-4.3.4.jar"/>- <classpathentry kind="lib" path="lib/httpcore-4.3.2.jar"/>- <classpathentry kind="lib" path="lib/httpmime-4.3.4.jar"/>- <classpathentry kind="lib" path="lib/noggit-0.5.jar"/>- <classpathentry kind="lib" path="lib/metadata-extractor-2.6.2.jar"/>- <classpathentry kind="lib" path="lib/jcifs-1.3.17.jar"/>- <classpathentry kind="lib" path="lib/guava-16.0.1.jar"/>- <classpathentry kind="lib" path="lib/spatial4j-0.4.1.jar"/>- <classpathentry kind="lib" path="lib/zookeeper-3.4.6.jar"/>- <classpathentry kind="lib" path="lib/org.restlet.jar"/>- <classpathentry kind="lib" path="lib/fontbox-1.8.6.jar"/>- <classpathentry kind="lib" path="lib/jempbox-1.8.6.jar"/>- <classpathentry kind="lib" path="lib/pdfbox-1.8.6.jar"/>- <classpathentry kind="lib" path="lib/bcmail-jdk15-1.46.jar"/>- <classpathentry kind="lib" path="lib/bcprov-jdk15-1.46.jar"/>- <classpathentry kind="lib" path="lib/poi-3.10-FINAL-20140208.jar"/>- <classpathentry kind="lib" path="lib/poi-scratchpad-3.10-FINAL-20140208.jar"/>- <classpathentry kind="lib" path="lib/commons-io-2.3.jar"/>- <classpathentry kind="lib" path="lib/slf4j-api-1.7.6.jar"/>- <classpathentry kind="lib" path="lib/lucene-analyzers-common-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-analyzers-phonetic-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-classification-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-codecs-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-core-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-facet-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-grouping-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-highlighter-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-join-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-memory-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-misc-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-queries-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-queryparser-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-spatial-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/lucene-suggest-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/solr-core-4.9.0.jar"/>- <classpathentry kind="lib" path="lib/solr-solrj-4.9.0.jar"/>- <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>- <classpathentry kind="lib" path="lib/icu4j-core.jar"/>- <classpathentry kind="lib" path="lib/htmllexer.jar"/>- <classpathentry kind="lib" path="lib/jsoup-1.6.3.jar"/>- <classpathentry kind="lib" path="lib/jetty-client-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-continuation-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-deploy-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-http-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-io-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-jmx-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-proxy-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-security-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-server-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-servlet-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-servlets-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-util-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-webapp-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/jetty-xml-9.2.1.v20140609.jar"/>- <classpathentry kind="lib" path="lib/javax.servlet-api-3.1.0.jar"/>- <classpathentry kind="output" path="gen"/>-</classpath>+<?xml version="1.0" encoding="UTF-8"?>+<classpath>+ <classpathentry kind="src" path="source"/>+ <classpathentry excluding="api/|env/|processing/domaingraph/applet/|yacy/|api/bookmarks/|api/ymarks/|api/bookmarks/posts/|api/bookmarks/tags/|api/bookmarks/xbel/|solr/|gsa/|solr/collection1/" kind="src" path="htroot"/>+ <classpathentry excluding="bookmarks/|ymarks/|bookmarks/posts/|bookmarks/tags/|bookmarks/xbel/" kind="src" path="htroot/api"/>+ <classpathentry kind="src" path="htroot/env"/>+ <classpathentry kind="src" path="htroot/yacy"/>+ <classpathentry excluding="posts/|tags/|xbel/" kind="src" path="htroot/api/bookmarks"/>+ <classpathentry kind="src" path="htroot/api/ymarks"/>+ <classpathentry kind="src" path="htroot/api/bookmarks/posts"/>+ <classpathentry kind="src" path="htroot/api/bookmarks/tags"/>+ <classpathentry kind="src" path="htroot/api/bookmarks/xbel"/>+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>+ <classpathentry kind="lib" path="lib/commons-logging-1.1.3.jar"/>+ <classpathentry kind="lib" path="lib/J7Zip-modified.jar"/>+ <classpathentry kind="lib" path="lib/webcat-0.1-swf.jar"/>+ <classpathentry kind="lib" path="lib/commons-jxpath-1.3.jar"/>+ <classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>+ <classpathentry kind="lib" path="lib/jakarta-oro-2.0.8.jar"/>+ <classpathentry kind="lib" path="lib/apache-mime4j-0.6.jar"/>+ <classpathentry kind="lib" path="lib/commons-fileupload-1.2.2.jar"/>+ <classpathentry kind="lib" path="lib/json-simple-1.1.1.jar"/>+ <classpathentry kind="lib" path="lib/xercesImpl.jar"/>+ <classpathentry kind="lib" path="lib/xml-apis.jar"/>+ <classpathentry kind="lib" path="lib/geronimo-stax-api_1.0_spec-1.0.1.jar"/>+ <classpathentry kind="lib" path="lib/commons-compress-1.8.jar"/>+ <classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>+ <classpathentry kind="lib" path="lib/jaudiotagger-2.0.4-20111207.115108-15.jar"/>+ <classpathentry kind="lib" path="lib/commons-codec-1.7.jar"/>+ <classpathentry kind="lib" path="lib/jcl-over-slf4j-1.7.2.jar"/>+ <classpathentry kind="lib" path="lib/wstx-asl-3.2.9.jar"/>+ <classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.2.jar"/>+ <classpathentry kind="lib" path="lib/log4j-over-slf4j-1.7.2.jar"/>+ <classpathentry kind="lib" path="lib/httpclient-4.3.4.jar"/>+ <classpathentry kind="lib" path="lib/httpcore-4.3.2.jar"/>+ <classpathentry kind="lib" path="lib/httpmime-4.3.4.jar"/>+ <classpathentry kind="lib" path="lib/noggit-0.5.jar"/>+ <classpathentry kind="lib" path="lib/metadata-extractor-2.6.2.jar"/>+ <classpathentry kind="lib" path="lib/jcifs-1.3.17.jar"/>+ <classpathentry kind="lib" path="lib/guava-16.0.1.jar"/>+ <classpathentry kind="lib" path="lib/spatial4j-0.4.1.jar"/>+ <classpathentry kind="lib" path="lib/zookeeper-3.4.6.jar"/>+ <classpathentry kind="lib" path="lib/org.restlet.jar"/>+ <classpathentry kind="lib" path="lib/fontbox-1.8.6.jar"/>+ <classpathentry kind="lib" path="lib/jempbox-1.8.6.jar"/>+ <classpathentry kind="lib" path="lib/pdfbox-1.8.6.jar"/>+ <classpathentry kind="lib" path="lib/bcmail-jdk15-1.46.jar"/>+ <classpathentry kind="lib" path="lib/bcprov-jdk15-1.46.jar"/>+ <classpathentry kind="lib" path="lib/poi-3.10-FINAL-20140208.jar"/>+ <classpathentry kind="lib" path="lib/poi-scratchpad-3.10-FINAL-20140208.jar"/>+ <classpathentry kind="lib" path="lib/commons-io-2.3.jar"/>+ <classpathentry kind="lib" path="lib/slf4j-api-1.7.6.jar"/>+ <classpathentry kind="lib" path="lib/lucene-analyzers-common-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-analyzers-phonetic-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-classification-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-codecs-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-core-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-facet-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-grouping-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-highlighter-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-join-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-memory-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-misc-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-queries-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-queryparser-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-spatial-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/lucene-suggest-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/solr-core-4.9.0.jar"/>+ <classpathentry kind="lib" path="lib/solr-solrj-4.9.0.jar"/>+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>+ <classpathentry kind="lib" path="lib/icu4j-core.jar"/>+ <classpathentry kind="lib" path="lib/htmllexer.jar"/>+ <classpathentry kind="lib" path="lib/jsoup-1.6.3.jar"/>+ <classpathentry kind="lib" path="lib/jetty-client-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-continuation-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-deploy-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-http-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-io-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-jmx-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-proxy-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-security-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-server-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-servlet-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-servlets-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-util-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-webapp-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/jetty-xml-9.2.1.v20140609.jar"/>+ <classpathentry kind="lib" path="lib/javax.servlet-api-3.1.0.jar"/>+ <classpathentry kind="lib" path="lib/weupnp-0.1.2.jar"/>+ <classpathentry kind="output" path="gen"/>+</classpath>diff --git a/build.xml b/build.xmlindex c939e4806..6a8a2ca80 100644--- a/build.xml+++ b/build.xml@@ -231,6 +231,7 @@<pathelement location="${lib}/solr-solrj-4.9.0.jar" /><pathelement location="${lib}/spatial4j-0.4.1.jar" /><pathelement location="${lib}/webcat-0.1-swf.jar" />+ <pathelement location="${lib}/weupnp-0.1.2.jar" /><pathelement location="${lib}/wstx-asl-3.2.9.jar" /><pathelement location="${lib}/xercesImpl.jar" /><pathelement location="${lib}/xml-apis.jar" />diff --git a/lib/weupnp-0.1.2.jar b/lib/weupnp-0.1.2.jarnew file mode 100644index 000000000..43daf9ff2Binary files /dev/null and b/lib/weupnp-0.1.2.jar differdiff --git a/lib/weupnp.license b/lib/weupnp.licensenew file mode 100644index 000000000..b1e3ef363--- /dev/null+++ b/lib/weupnp.license@@ -0,0 +1,67 @@++GNU LESSER GENERAL PUBLIC LICENSE++Version 3, 29 June 2007++Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>++Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.++This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.+0. Additional Definitions.++As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.++“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.++An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.++A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.++The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.++The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.+1. Exception to Section 3 of the GNU GPL.++You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.+2. Conveying Modified Versions.++If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:++ a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or+ b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.++3. Object Code Incorporating Material from Library Header Files.++The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:++ a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.+ b) Accompany the object code with a copy of the GNU GPL and this license document.++4. Combined Works.++You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:++ a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.+ b) Accompany the Combined Work with a copy of the GNU GPL and this license document.+ c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.+ d) Do one of the following:+ 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.+ 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.+ e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)++5. Combined Libraries.++You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:++ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.+ b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.++6. Revised Versions of the GNU Lesser General Public License.++The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.++Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.++If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.+diff --git a/source/net/yacy/upnp/Discovery.java b/source/net/yacy/upnp/Discovery.javadeleted file mode 100644index 90df0f7f3..000000000--- a/source/net/yacy/upnp/Discovery.java+++ /dev/null@@ -1,256 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--import java.net.*;-import java.io.*;-import java.util.*;--import net.yacy.upnp.devices.*;--import org.apache.commons.logging.*;--/**- * Class to discover an UPNP device on the network.</br>- * A multicast socket will be created to discover devices, the binding port for this socket is set to 1901,- * if this is causing a problem you can use the net.yacy.upnp.Discovery.bindPort system property- * to specify another port.- * The discovery methods only accept matching device description and broadcast message response IP- * to avoid a security flaw with the protocol. If you are not happy with such behaviour- * you can set the net.yacy.upnp.ddos.matchip system property to false to avoid this check.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class Discovery {-- private final static Log log = LogFactory.getLog( Discovery.class );-- public final static String ROOT_DEVICES = "upnp:rootdevice";- public final static String ALL_DEVICES = "ssdp:all";-- public static final int DEFAULT_MX = 3;- public static final int DEFAULT_TTL = 4;- public static final int DEFAULT_TIMEOUT = 1500;- public static final String DEFAULT_SEARCH = ALL_DEVICES;- public static final int DEFAULT_SSDP_SEARCH_PORT = 1901;-- public final static String SSDP_IP = "239.255.255.250";- public final static int SSDP_PORT = 1900;-- /**- * Devices discovering on all network interfaces with default values, all root devices will be searched- * @return an array of UPNP Root device or null if nothing found with the default timeout.- * Null does NOT means that no UPNP device is available on the network. It only means- * that for this default timeout no devices responded or that effectively no devices- * are available at all.- * @throws IOException if some IOException occurs during discovering- */- public static UPNPRootDevice[] discover() throws IOException {- return discover( DEFAULT_TIMEOUT, DEFAULT_TTL, DEFAULT_MX, DEFAULT_SEARCH );- }-- /**- * Devices discovering on all network interfaces with a given root device to search- * @param searchTarget the device URI to search- * @return an array of UPNP Root device that matches the search or null if nothing found with the default timeout.- * Null does NOT means that no UPNP device is available on the network. It only means- * that for this given timeout no devices responded or that effectively no devices- * are available at all.- * @throws IOException if some IOException occurs during discovering- */- public static UPNPRootDevice[] discover( String searchTarget ) throws IOException {- return discover( DEFAULT_TIMEOUT, DEFAULT_TTL, DEFAULT_MX, searchTarget );- }-- /**- * Devices discovering on all network interfaces with a given timeout and a given root device to search- * @param timeOut the time allowed for a device to give a response- * @param searchTarget the device URI to search- * @return an array of UPNP Root device that matches the search or null if nothing found with the given timeout.- * Null does NOT means that no UPNP device is available on the network. It only means- * that for this given timeout no devices responded or that effectively no devices- * are available at all.- * @throws IOException if some IOException occurs during discovering- */- public static UPNPRootDevice[] discover( int timeOut, String searchTarget ) throws IOException {- return discover( timeOut, DEFAULT_TTL, DEFAULT_MX, searchTarget );- }-- /**- * Devices discovering on all network interfaces with a given timeout and a given root device to search, as well as a ttl and mx param- * @param timeOut the timeout for the a device to give a reponse- * @param ttl the UDP socket packets time to live- * @param mx discovery message mx http header field value- * @param searchTarget the device URI to search- * @return an array of UPNP Root device that matches the search or null if nothing found within the given timeout.- * Null return does NOT means that no UPNP device is available on the network. It only means- * that for this given timeout no devices responded or that effectively no devices- * are available at all.- * @throws IOException if some IOException occurs during discovering- */- public static UPNPRootDevice[] discover( int timeOut, int ttl, int mx, String searchTarget ) throws IOException {- return discoverDevices( timeOut, ttl, mx, searchTarget, null );- }-- /**- * Devices discovering with a given timeout and a given root device to search on an given network interface, as well as a ttl and mx param- * @param timeOut the timeout for the a device to give a reponse- * @param ttl the UDP socket packets time to live- * @param mx discovery message mx http header field value- * @param searchTarget the device URI to search- * @param ni the networkInterface where to search devices, null to lookup all interfaces- * @return an array of UPNP Root device that matches the search or null if nothing found within the given timeout.- * Null return does NOT means that no UPNP device is available on the network. It only means- * that for this given timeout no devices responded or that effectively no devices- * are available at all.- * @throws IOException if some IOException occurs during discovering- */- public static UPNPRootDevice[] discover( int timeOut, int ttl, int mx, String searchTarget, NetworkInterface ni ) throws IOException {- return discoverDevices( timeOut, ttl, mx, searchTarget, ni );- }-- private static UPNPRootDevice[] discoverDevices( int timeOut, int ttl, int mx, String searchTarget, NetworkInterface ni ) throws IOException {- if ( searchTarget == null || searchTarget.trim().isEmpty() ) {- throw new IllegalArgumentException( "Illegal searchTarget" );- }-- final Map<String, UPNPRootDevice> devices = new HashMap<String, UPNPRootDevice>();-- DiscoveryResultsHandler handler = new DiscoveryResultsHandler() {-- @Override- public void discoveredDevice( String usn, String udn, String nt, String maxAge, URL location, String firmware ) {- synchronized( devices ) {- if ( ! devices.containsKey( usn ) ) {- try {- UPNPRootDevice device = new UPNPRootDevice( location, maxAge, firmware, usn, udn );- devices.put( usn, device );- } catch (final Exception ex ) {- log.error( "Error occured during upnp root device object creation from location " + location, ex );- }- }- }- }- };-- DiscoveryListener.getInstance().registerResultsHandler( handler, searchTarget );- if ( ni == null ) {- for ( Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements(); ) {- NetworkInterface intf = e.nextElement();- for ( Enumeration<InetAddress> adrs = intf.getInetAddresses(); adrs.hasMoreElements(); ) {- InetAddress adr = adrs.nextElement();- if ( adr instanceof Inet4Address && !adr.isLoopbackAddress() ) {- sendSearchMessage( adr, ttl, mx, searchTarget );- }- }- }- } else {- for ( Enumeration<InetAddress> adrs = ni.getInetAddresses(); adrs.hasMoreElements(); ) {- InetAddress adr = adrs.nextElement();- if ( adr instanceof Inet4Address && !adr.isLoopbackAddress() ) {- sendSearchMessage( adr, ttl, mx, searchTarget );- }- }- }-- try {- Thread.sleep( timeOut );- } catch (final InterruptedException ex ) {- // don't care- }-- DiscoveryListener.getInstance().unRegisterResultsHandler( handler, searchTarget );-- if ( devices.isEmpty() ) {- return null;- }- int j = 0;- UPNPRootDevice[] rootDevices = new UPNPRootDevice[devices.size()];- for ( Iterator<UPNPRootDevice> i = devices.values().iterator(); i.hasNext(); ) {- rootDevices[j++] = i.next();- }- return rootDevices;-- }-- /**- * Sends an SSDP search message on the network- * @param src the sender ip- * @param ttl the time to live- * @param mx the mx field- * @param searchTarget the search target- * @throws IOException if some IO errors occurs during search- */- public static void sendSearchMessage( InetAddress src, int ttl, int mx, String searchTarget ) throws IOException {-- int bindPort = DEFAULT_SSDP_SEARCH_PORT;- String port = System.getProperty( "net.yacy.upnp.Discovery.bindPort" );- if ( port != null ) {- bindPort = Integer.parseInt( port );- }- InetSocketAddress adr = new InetSocketAddress( InetAddress.getByName( Discovery.SSDP_IP ), Discovery.SSDP_PORT );-- java.net.MulticastSocket skt = new java.net.MulticastSocket( null );- skt.bind( new InetSocketAddress( src, bindPort ) );- skt.setTimeToLive( ttl );- StringBuilder packet = new StringBuilder();- packet.append( "M-SEARCH * HTTP/1.1\r\n" );- packet.append( "HOST: 239.255.255.250:1900\r\n" );- packet.append( "MAN: \"ssdp:discover\"\r\n" );- packet.append( "MX: ").append( mx ).append( "\r\n" );- packet.append( "ST: " ).append( searchTarget ).append( "\r\n" ).append( "\r\n" );- if ( log.isDebugEnabled() ) log.debug( "Sending discovery message on 239.255.255.250:1900 multicast address form ip " + src.getHostAddress() + ":\n" + packet.toString() );- String toSend = packet.toString();- byte[] pk = toSend.getBytes();- skt.send( new DatagramPacket( pk, pk.length, adr ) );- skt.disconnect();- skt.close();- }--}diff --git a/source/net/yacy/upnp/DiscoveryAdvertisement.java b/source/net/yacy/upnp/DiscoveryAdvertisement.javadeleted file mode 100644index feeee4572..000000000--- a/source/net/yacy/upnp/DiscoveryAdvertisement.java+++ /dev/null@@ -1,420 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--import java.io.IOException;-import java.net.DatagramPacket;-import java.net.InetAddress;-import java.net.InetSocketAddress;-import java.net.SocketTimeoutException;-import java.net.URL;-import java.util.HashMap;-import java.util.HashSet;-import java.util.Map;-import java.util.Set;--import org.apache.commons.logging.Log;-import org.apache.commons.logging.LogFactory;--/**- * SSDP messages listener Thread, notify registered objects implementing the interface- * DiscoveryEventHandler</br> when a device joins the networks or leaves it.<br/>- * The listener thread is set to only accept matching device description and broadcast message sender IP to- * avoid a security flaw with the protocol. If you are not happy with such behaviour you can set the- * net.yacy.upnp.ddos.matchip system property to false to avoid this check.- *- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class DiscoveryAdvertisement implements Runnable-{-- private final static Log log = LogFactory.getLog(DiscoveryAdvertisement.class);-- private static boolean MATCH_IP = true;-- static {- String prop = System.getProperty("net.yacy.upnp.ddos.matchip");- if ( prop != null && prop.equals("false") ) {- MATCH_IP = false;- }- }-- private static final int DEFAULT_TIMEOUT = 250;-- public final static int EVENT_SSDP_ALIVE = 0;- public final static int EVENT_SSDP_BYE_BYE = 1;-- private final static String NTS_SSDP_ALIVE = "ssdp:alive";- private final static String NTS_SSDP_BYE_BYE = "ssdp:byebye";- private final static String NT_ALL_EVENTS = "DiscoveryAdvertisement:nt:allevents";-- private final Map<String, Set<DiscoveryEventHandler>> byeByeRegistered =- new HashMap<String, Set<DiscoveryEventHandler>>();- private final Map<String, Set<DiscoveryEventHandler>> aliveRegistered =- new HashMap<String, Set<DiscoveryEventHandler>>();- private final Map<String, InetAddress> USNPerIP = new HashMap<String, InetAddress>();-- private final Object REGISTRATION_PROCESS = new Object();-- private final static DiscoveryAdvertisement singleton = new DiscoveryAdvertisement();- private boolean inService = false;- private boolean daemon = true;-- private java.net.MulticastSocket skt;- private DatagramPacket input;-- private DiscoveryAdvertisement() {- }-- public final static DiscoveryAdvertisement getInstance() {- return singleton;- }-- public void setDaemon(boolean daemon) {- this.daemon = daemon;- }-- /**- * Registers an event category sent by UPNP devices- *- * @param notificationEvent the event type, either DiscoveryAdvertisement.EVENT_SSDP_ALIVE or- * DiscoveryAdvertisement.EVENT_SSDP_BYE_BYE- * @param nt the type of device advertisement, upnp:rootdevice will return you all advertisement in- * relation with nt upnp:rootdevice a null value specify that all nt type are wanted- * @param eventHandler the events handler, this objet will receive notifications..- * @throws IOException if an error ocurs when the SSDP events listeners threads starts- */- public void registerEvent(int notificationEvent, String nt, DiscoveryEventHandler eventHandler)- throws IOException {- synchronized ( this.REGISTRATION_PROCESS ) {- if ( !this.inService ) {- startDevicesListenerThread();- }- if ( nt == null ) {- nt = NT_ALL_EVENTS;- }- if ( notificationEvent == EVENT_SSDP_ALIVE ) {- Set<DiscoveryEventHandler> handlers = this.aliveRegistered.get(nt);- if ( handlers == null ) {- handlers = new HashSet<DiscoveryEventHandler>();- this.aliveRegistered.put(nt, handlers);- }- handlers.add(eventHandler);- } else if ( notificationEvent == EVENT_SSDP_BYE_BYE ) {- Set<DiscoveryEventHandler> handlers = this.byeByeRegistered.get(nt);- if ( handlers == null ) {- handlers = new HashSet<DiscoveryEventHandler>();- this.byeByeRegistered.put(nt, handlers);- }- handlers.add(eventHandler);- } else {- throw new IllegalArgumentException("Unknown notificationEvent type");- }- }- }-- /**- * Unregisters an event category sent by UPNP devices- *- * @param notificationEvent the event type, either DiscoveryAdvertisement.EVENT_SSDP_ALIVE or- * DiscoveryAdvertisement.EVENT_SSDP_BYE_BYE- * @param nt the type of device advertisement, upnp:rootdevice will unregister all advertisement in- * relation with nt upnp:rootdevice a null value specify that all nt type are unregistered- * @param eventHandler the events handler that needs to be unregistred.- */- public void unRegisterEvent(int notificationEvent, String nt, DiscoveryEventHandler eventHandler) {- synchronized ( this.REGISTRATION_PROCESS ) {- if ( nt == null ) {- nt = NT_ALL_EVENTS;- }- if ( notificationEvent == EVENT_SSDP_ALIVE ) {- Set<DiscoveryEventHandler> handlers = this.aliveRegistered.get(nt);- if ( handlers != null ) {- handlers.remove(eventHandler);- if ( handlers.isEmpty() ) {- this.aliveRegistered.remove(nt);- }- }- } else if ( notificationEvent == EVENT_SSDP_BYE_BYE ) {- Set<DiscoveryEventHandler> handlers = this.byeByeRegistered.get(nt);- if ( handlers != null ) {- handlers.remove(eventHandler);- if ( handlers.isEmpty() ) {- this.byeByeRegistered.remove(nt);- }- }- } else {- throw new IllegalArgumentException("Unknown notificationEvent type");- }- if ( this.aliveRegistered.isEmpty() && this.byeByeRegistered.isEmpty() ) {- stopDevicesListenerThread();- }- }- }-- private void startDevicesListenerThread() throws IOException {- synchronized ( singleton ) {- if ( !this.inService ) {- this.startMultiCastSocket();- Thread deamon = new Thread(this, "DiscoveryAdvertisement daemon");- deamon.setDaemon(this.daemon);- deamon.start();- // wait for the thread to be started- while ( !this.inService ) {- // let's wait a few ms- try {- Thread.sleep(2);- } catch (final InterruptedException ex ) {- // don t care- }- }- }- }- }-- private void stopDevicesListenerThread() {- synchronized ( singleton ) {- this.inService = false;- }- }-- private void startMultiCastSocket() throws IOException {-- this.skt = new java.net.MulticastSocket(null);- this.skt.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), Discovery.SSDP_PORT));- this.skt.setTimeToLive(Discovery.DEFAULT_TTL);- this.skt.setSoTimeout(DEFAULT_TIMEOUT);- this.skt.joinGroup(InetAddress.getByName(Discovery.SSDP_IP));-- byte[] buf = new byte[2048];- this.input = new DatagramPacket(buf, buf.length);-- }-- @Override- public void run() {- if ( !Thread.currentThread().getName().equals("DiscoveryAdvertisement daemon") ) {- throw new RuntimeException("No right to call this method");- }- this.inService = true;- while ( this.inService ) {- try {- listenBroadCast();- } catch (final SocketTimeoutException ex ) {- // ignoring- } catch (final IOException ioEx ) {- // fail silently- //log.warn("IO Exception during UPNP DiscoveryAdvertisement messages listening thread");- } catch (final Exception ex ) {- // fail silently- //log.warn("Fatal Error during UPNP DiscoveryAdvertisement messages listening thread, thread will exit");- this.inService = false;- this.aliveRegistered.clear();- this.byeByeRegistered.clear();- this.USNPerIP.clear();- }- }-- try {- this.skt.leaveGroup(InetAddress.getByName(Discovery.SSDP_IP));- this.skt.close();- } catch (final Exception ex ) {- // ignoring- }- }-- private void listenBroadCast() throws IOException {-- this.skt.receive(this.input);- InetAddress from = this.input.getAddress();- String received = new String(this.input.getData(), this.input.getOffset(), this.input.getLength());- HttpResponse msg = null;- try {- msg = new HttpResponse(received);- } catch (final IllegalArgumentException ex ) {- // crappy http sent- if ( log.isDebugEnabled() ) {- log.debug("Skipping uncompliant HTTP message " + received);- }- return;- }- String header = msg.getHeader();- if ( header != null && header.startsWith("NOTIFY") ) {- if ( log.isDebugEnabled() ) {- log.debug(received);- }- String ntsField = msg.getHTTPHeaderField("nts");- if ( ntsField == null || ntsField.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) {- log.debug("Skipping SSDP message, missing HTTP header 'ntsField' field");- }- return;- }- if ( ntsField.equals(NTS_SSDP_ALIVE) ) {- String deviceDescrLoc = msg.getHTTPHeaderField("location");- if ( deviceDescrLoc == null || deviceDescrLoc.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) {- log.debug("Skipping SSDP message, missing HTTP header 'location' field");- }- return;- }- URL loc = new URL(deviceDescrLoc);- if ( MATCH_IP ) {- InetAddress locHost = InetAddress.getByName(loc.getHost());- if ( !from.equals(locHost) ) {- log.warn("Discovery message sender IP "- + from- + " does not match device description IP "- + locHost- + " skipping message, set the net.yacy.upnp.ddos.matchip system property"- + " to false to avoid this check");- return;- }- }-- String nt = msg.getHTTPHeaderField("nt");- if ( nt == null || nt.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) {- log.debug("Skipping SSDP message, missing HTTP header 'nt' field");- }- return;- }- String maxAge = msg.getHTTPFieldElement("Cache-Control", "max-age");- if ( maxAge == null || maxAge.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) {- log.debug("Skipping SSDP message, missing HTTP header 'max-age' field");- }- return;- }- String usn = msg.getHTTPHeaderField("usn");- if ( usn == null || usn.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) {- log.debug("Skipping SSDP message, missing HTTP header 'usn' field");- }- return;- }-- this.USNPerIP.put(usn, from);- String udn = usn;- int index = udn.indexOf("::");- if ( index != -1 ) {- udn = udn.substring(0, index);- }- synchronized ( this.REGISTRATION_PROCESS ) {- Set<DiscoveryEventHandler> handlers = this.aliveRegistered.get(NT_ALL_EVENTS);- if ( handlers != null ) {- for ( DiscoveryEventHandler eventHandler : handlers ) {- eventHandler.eventSSDPAlive(usn, udn, nt, maxAge, loc);- }- }- handlers = this.aliveRegistered.get(nt);- if ( handlers != null ) {- for ( DiscoveryEventHandler eventHandler : handlers ) {- eventHandler.eventSSDPAlive(usn, udn, nt, maxAge, loc);- }- }- }- } else if ( ntsField.equals(NTS_SSDP_BYE_BYE) ) {- String usn = msg.getHTTPHeaderField("usn");- if ( usn == null || usn.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) {- log.debug("Skipping SSDP message, missing HTTP header 'usn' field");- }- return;- }- String nt = msg.getHTTPHeaderField("nt");- if ( nt == null || nt.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) {- log.debug("Skipping SSDP message, missing HTTP header 'nt' field");- }- return;- }-- InetAddress originalAliveSenderIp = this.USNPerIP.get(usn);- if ( originalAliveSenderIp != null ) {- // we check that the sender ip of message for the usn- // match the sender ip of the alive message for wich the usn- // has been received- if ( !originalAliveSenderIp.equals(from) ) {- // someone else is trying to say that the usn is leaving- // since IP do not match we skip the message- return;- }- }-- String udn = usn;- int index = udn.indexOf("::");- if ( index != -1 ) {- udn = udn.substring(0, index);- }- synchronized ( this.REGISTRATION_PROCESS ) {- Set<DiscoveryEventHandler> handlers = this.byeByeRegistered.get(NT_ALL_EVENTS);- if ( handlers != null ) {- for ( DiscoveryEventHandler eventHandler : handlers ) {- eventHandler.eventSSDPByeBye(usn, udn, nt);- }- }- handlers = this.byeByeRegistered.get(nt);- if ( handlers != null ) {- for ( DiscoveryEventHandler eventHandler : handlers ) {- eventHandler.eventSSDPByeBye(usn, udn, nt);- }- }- }- } else {- log- .warn("Unvalid NTS field value ("- + ntsField- + ") received in NOTIFY message :"- + received);- }- }- }-}diff --git a/source/net/yacy/upnp/DiscoveryEventHandler.java b/source/net/yacy/upnp/DiscoveryEventHandler.javadeleted file mode 100644index b55ce49d5..000000000--- a/source/net/yacy/upnp/DiscoveryEventHandler.java+++ /dev/null@@ -1,76 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--/**- * Interface for object that want to receive events from the- * DiscoveryAdvertisement thread- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public interface DiscoveryEventHandler {-- /**- * Called when a device joins the network or advertise it is still alive- * @param usn the device USN (udn::nt)- * @param udn the device UDN- * @param nt the device NT- * @param maxAge the device maxAge- * @param location the device location- */- public void eventSSDPAlive( String usn, String udn, String nt, String maxAge, java.net.URL location );-- /**- * Called when a device is leaving the network- * @param usn the device USN (udn::nt)- * @param udn the device UDN- * @param nt the device NT- */- public void eventSSDPByeBye( String usn, String udn, String nt );-}diff --git a/source/net/yacy/upnp/DiscoveryListener.java b/source/net/yacy/upnp/DiscoveryListener.javadeleted file mode 100644index 7f213c6e8..000000000--- a/source/net/yacy/upnp/DiscoveryListener.java+++ /dev/null@@ -1,289 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--import java.io.IOException;-import java.net.DatagramPacket;-import java.net.InetAddress;-import java.net.InetSocketAddress;-import java.net.SocketTimeoutException;-import java.net.URL;-import java.util.HashMap;-import java.util.HashSet;-import java.util.Map;-import java.util.Set;--import org.apache.commons.logging.Log;-import org.apache.commons.logging.LogFactory;--/**- * This class can be used to listen for UPNP devices responses when a search message is sent by a control point- * ( using the net.yacy.upnp.Discovery.sendSearchMessage() method )- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class DiscoveryListener implements Runnable {-- private final static Log log = LogFactory.getLog( DiscoveryListener.class );-- private static boolean MATCH_IP = true;-- static {- String prop = System.getProperty( "net.yacy.upnp.ddos.matchip" );- if ( prop != null && prop.equals( "false" ) ) MATCH_IP = false;- }-- private static final int DEFAULT_TIMEOUT = 250;-- private final Map<String, Set<DiscoveryResultsHandler>> registeredHandlers = new HashMap<String, Set<DiscoveryResultsHandler>>();-- private final Object REGISTRATION_PROCESS = new Object();-- private final static DiscoveryListener singleton = new DiscoveryListener();-- private boolean inService = false;- private boolean daemon = true;-- private java.net.MulticastSocket skt;- private DatagramPacket input;-- private DiscoveryListener() {- }-- public final static DiscoveryListener getInstance() {- return singleton;- }-- /**- * Sets the listener as a daemon thread- * @param daemon daemon thread- */- public void setDaemon( boolean daemon ) {- this.daemon = daemon;- }-- /**- * Registers an SSDP response message handler- * @param resultsHandler the SSDP response message handler- * @param searchTarget the search target- * @throws IOException if some errors occurs during SSDP search response messages listener thread startup- */- public void registerResultsHandler( DiscoveryResultsHandler resultsHandler, String searchTarget ) throws IOException {- synchronized( this.REGISTRATION_PROCESS ) {- if ( !this.inService ) startDevicesListenerThread();- Set<DiscoveryResultsHandler> handlers = this.registeredHandlers.get( searchTarget );- if ( handlers == null ) {- handlers = new HashSet<DiscoveryResultsHandler>();- this.registeredHandlers.put( searchTarget, handlers );- }- handlers.add( resultsHandler );- }- }-- /**- * Unregisters an SSDP response message handler- * @param resultsHandler the SSDP response message handler- * @param searchTarget the search target- */- public void unRegisterResultsHandler( DiscoveryResultsHandler resultsHandler, String searchTarget ) {- synchronized( this.REGISTRATION_PROCESS ) {- Set<DiscoveryResultsHandler> handlers = this.registeredHandlers.get( searchTarget );- if ( handlers != null ) {- handlers.remove( resultsHandler );- if (handlers.isEmpty()) {- this.registeredHandlers.remove( searchTarget );- }- }- if (this.registeredHandlers.isEmpty()) {- stopDevicesListenerThread();- }- }- }-- private void startDevicesListenerThread() throws IOException {- synchronized( singleton ) {- if ( !this.inService ) {-- this.startMultiCastSocket();- Thread deamon = new Thread( this, "DiscoveryListener daemon" );- deamon.setDaemon( this.daemon );- deamon.start();- while ( !this.inService ) {- // wait for the thread to be started let's wait a few ms- try {- Thread.sleep( 2 );- } catch( InterruptedException ex ) {- // don t care- }- }- }- }- }-- private void stopDevicesListenerThread() {- synchronized( singleton ) {- this.inService = false;- }- }-- private void startMultiCastSocket() throws IOException {- int bindPort = Discovery.DEFAULT_SSDP_SEARCH_PORT;- String port = System.getProperty( "net.yacy.upnp.Discovery.bindPort" );- if ( port != null ) {- bindPort = Integer.parseInt( port );- }-- this.skt = new java.net.MulticastSocket( null );- this.skt.bind( new InetSocketAddress( InetAddress.getByName( "0.0.0.0" ), bindPort ) );- this.skt.setTimeToLive( Discovery.DEFAULT_TTL );- this.skt.setSoTimeout( DEFAULT_TIMEOUT );- this.skt.joinGroup( InetAddress.getByName( Discovery.SSDP_IP ) );-- byte[] buf = new byte[2048];- this.input = new DatagramPacket( buf, buf.length );-- }-- @Override-public void run() {- if ( !Thread.currentThread().getName().equals( "DiscoveryListener daemon" ) ) {- throw new RuntimeException( "No right to call this method" );- }- this.inService = true;- while ( this.inService ) {- try {- listenBroadCast();- } catch (final SocketTimeoutException ex ) {- // ignoring- } catch (final IOException ioEx ) {- log.error( "IO Exception during UPNP DiscoveryListener messages listening thread" );- } catch( Exception ex ) {- log.error( "Fatal Error during UPNP DiscoveryListener messages listening thread, thread will exit" );- this.inService = false;- }- }-- try {- this.skt.leaveGroup( InetAddress.getByName( Discovery.SSDP_IP ) );- this.skt.close();- } catch (final Exception ex ) {- // ignoring- }- }-- private void listenBroadCast() throws IOException {-- this.skt.receive( this.input );- InetAddress from = this.input.getAddress();- String received = new String( this.input.getData(), this.input.getOffset(), this.input.getLength() );- HttpResponse msg = null;- try {- msg = new HttpResponse( received );- } catch (final IllegalArgumentException ex ) {- // crappy http sent- if ( log.isDebugEnabled() ) log.debug( "Skipping uncompliant HTTP message " + received );- return;- }- String header = msg.getHeader();- if ( header != null && header.startsWith( "HTTP/1.1 200 OK" ) && msg.getHTTPHeaderField( "st" ) != null ) {- // probably a search repsonse !- String deviceDescrLoc = msg.getHTTPHeaderField( "location" );- if( deviceDescrLoc == null || deviceDescrLoc.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) log.debug( "Skipping SSDP message, missing HTTP header 'location' field" );- return;- }- URL loc = new URL( deviceDescrLoc );- if ( MATCH_IP ) {- InetAddress locHost = InetAddress.getByName( loc.getHost() );- if ( !from.equals( locHost ) ) {- log.warn( "Discovery message sender IP " + from +- " does not match device description IP " + locHost +- " skipping device, set the net.yacy.upnp.ddos.matchip system property" +- " to false to avoid this check" );- return;- }- }- if ( log.isDebugEnabled() ) log.debug( "Processing " + deviceDescrLoc + " device description location" );- String st = msg.getHTTPHeaderField( "st" );- if( st == null || st.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) log.debug( "Skipping SSDP message, missing HTTP header 'st' field" );- return;- }- String usn = msg.getHTTPHeaderField( "usn" );- if( usn == null || usn.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) log.debug( "Skipping SSDP message, missing HTTP header 'usn' field" );- return;- }- String maxAge = msg.getHTTPFieldElement( "Cache-Control", "max-age" );- if( maxAge == null || maxAge.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) log.debug( "Skipping SSDP message, missing HTTP header 'max-age' field" );- return;- }- String server = msg.getHTTPHeaderField( "server" );- if( server == null || server.trim().isEmpty() ) {- if ( log.isDebugEnabled() ) log.debug( "Skipping SSDP message, missing HTTP header 'server' field" );- return;- }-- String udn = usn;- int index = udn.indexOf( "::" );- if ( index != -1 ) udn = udn.substring( 0, index );- synchronized( this.REGISTRATION_PROCESS ) {- Set<DiscoveryResultsHandler> handlers = this.registeredHandlers.get( st );- if ( handlers != null ) {- for ( DiscoveryResultsHandler handler : handlers ) {- handler.discoveredDevice( usn, udn, st, maxAge, loc, server );- }- }- }- } else {- if ( log.isDebugEnabled() ) log.debug( "Skipping uncompliant HTTP message " + received );- }- }-}diff --git a/source/net/yacy/upnp/DiscoveryResultsHandler.java b/source/net/yacy/upnp/DiscoveryResultsHandler.javadeleted file mode 100644index 1462de6e7..000000000--- a/source/net/yacy/upnp/DiscoveryResultsHandler.java+++ /dev/null@@ -1,71 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--/**- * This interface can be use to register against the DiscoveryListener class- * to receive SSDP search responses.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public interface DiscoveryResultsHandler {-- /**- * Method called by the DiscoveryListener class when a search response message has been received from the- * network- * @param usn the device USN- * @param udn the device UDN- * @param nt the device NT- * @param maxAge the message max age- * @param location the device location- * @param firmware the device firmware- */- public void discoveredDevice( String usn, String udn, String nt, String maxAge, java.net.URL location, String firmware );--}diff --git a/source/net/yacy/upnp/HttpResponse.java b/source/net/yacy/upnp/HttpResponse.javadeleted file mode 100644index 1e3a5c1ae..000000000--- a/source/net/yacy/upnp/HttpResponse.java+++ /dev/null@@ -1,143 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--import java.util.*;--/**- * A class to parse an HTTP response message.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class HttpResponse {-- private String header;- private Map<String, String> fields;- private String body;--- /**- * Constructor of the response, will try to parse the raw response data- * @param rawHttpResponse the raw response data- * @throws IllegalArgumentException if some error occurs during parsing- */- protected HttpResponse( String rawHttpResponse ) throws IllegalArgumentException {- if ( rawHttpResponse == null || rawHttpResponse.trim().isEmpty() ) {- throw new IllegalArgumentException( "Empty HTTP response message" );- }- boolean bodyParsing = false;- StringBuilder bodyParsed = new StringBuilder();- fields = new HashMap<String, String>();- String[] lines = rawHttpResponse.split( "\\r\\n" );- this.header = lines[0].trim();-- for ( int i = 1; i < lines.length; i++ ) {-- String line = lines[i];- if ( line.isEmpty() ) {- // line break before body- bodyParsing = true;- } else if ( bodyParsing ) {- // we parse the message body- bodyParsed.append( line ).append( "\r\n" );- } else {- // we parse the header- if ( line.length() > 0 ) {- int delim = line.indexOf( ':' );- if ( delim != -1 ) {- String key = line.substring( 0, delim ).toUpperCase();- String value = line.substring( delim + 1 ).trim();- fields.put( key, value );- } else {- throw new IllegalArgumentException( "Invalid HTTP message header :" + line );- }- }- }- }- if ( bodyParsing ) {- body = bodyParsed.toString();- }- }-- public String getHeader() {- return header;- }-- public String getBody() {- return body;- }-- public String getHTTPFieldElement( String fieldName, String elementName ) throws IllegalArgumentException {- String fieldNameValue = getHTTPHeaderField( fieldName );- if ( fieldName!= null ) {-- StringTokenizer tokenizer = new StringTokenizer( fieldNameValue.trim(), "," );- while (tokenizer.countTokens() > 0) {- String nextToken = tokenizer.nextToken().trim();- if ( nextToken.startsWith( elementName ) ) {- int index = nextToken.indexOf( "=" );- if ( index != -1 ) {- return nextToken.substring( index + 1 ).trim();- }- }- }- }- throw new IllegalArgumentException( "HTTP element field " + elementName + " is not present" );- }-- public String getHTTPHeaderField( String fieldName ) throws IllegalArgumentException {- String field = fields.get( fieldName.toUpperCase() );- if ( field == null ) {- throw new IllegalArgumentException( "HTTP field " + fieldName + " is not present");- }- return field;- }---}diff --git a/source/net/yacy/upnp/JXPathParser.java b/source/net/yacy/upnp/JXPathParser.javadeleted file mode 100644index 6c3b5f4a2..000000000--- a/source/net/yacy/upnp/JXPathParser.java+++ /dev/null@@ -1,96 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--import java.io.ByteArrayInputStream;-import java.io.IOException;-import java.io.InputStream;--import org.apache.commons.jxpath.xml.DOMParser;-import org.apache.commons.jxpath.xml.XMLParser;-import org.apache.commons.logging.Log;-import org.apache.commons.logging.LogFactory;--/**- * Parser to use with JXPath, this is used to fix some problems encountered- * with some UPNP devices returning buggy xml docs...- * This parser acts like a wrapper and make some chars search and replace- * such as 0x0 with 0x20 to produce a valid XML doc.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class JXPathParser implements XMLParser {-- private final static Log log = LogFactory.getLog( JXPathParser.class );-- private char buggyChar = (char)0;-- @Override-public Object parseXML( InputStream in ){- StringBuilder xml = new StringBuilder();- try {- byte[] buffer = new byte[512];- int readen = 0;- while ( ( readen = in.read( buffer ) ) != -1 ) {- xml.append( new String( buffer, 0, readen ) );- }- } catch (final IOException ex ) {- log.error( "IOException occured during XML reception", ex );- return null;- }- String doc = xml.toString();- log.debug( "Readen raw xml doc:\n" + doc );- if ( doc.indexOf( buggyChar ) != -1 ) {- doc = doc.replace( buggyChar, ' ' );- }-- ByteArrayInputStream in2 = new ByteArrayInputStream( doc.getBytes() );- DOMParser parser = new DOMParser();- return parser.parseXML( in2 ) ;- }-}diff --git a/source/net/yacy/upnp/ServiceEventHandler.java b/source/net/yacy/upnp/ServiceEventHandler.javadeleted file mode 100644index babac2d4f..000000000--- a/source/net/yacy/upnp/ServiceEventHandler.java+++ /dev/null@@ -1,70 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--/**- * Interface to implement to receive notifications about state- * variables changes on au UPNP service. The object implementing this interface- * can be used with the ServicesEventing class register method to receive the- * desired notifications.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public interface ServiceEventHandler {-- /**- * Handle a var change, called each time a UPNP service fires a- * state variable eventing message.</br>- * The code implemented in this method can block the thread.- * @param varName the state variable name- * @param newValue the new state variable value- */- public void handleStateVariableEvent( String varName, String newValue );--}diff --git a/source/net/yacy/upnp/ServiceEventMessageParser.java b/source/net/yacy/upnp/ServiceEventMessageParser.javadeleted file mode 100644index af5e0c648..000000000--- a/source/net/yacy/upnp/ServiceEventMessageParser.java+++ /dev/null@@ -1,108 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--import java.util.HashMap;-import java.util.Map;--import org.xml.sax.Attributes;--/**- * Simple SAX handler for UPNP service event message parsing, this message is in SOAP format- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class ServiceEventMessageParser extends org.xml.sax.helpers.DefaultHandler {-- private boolean readPropertyName = false;-- private String currentPropName = null;-- private Map<String, String> changedStateVars = new HashMap<String, String>();-- protected ServiceEventMessageParser() {- }-- public Map<String, String> getChangedStateVars() {- return changedStateVars;- }-- @Override- public void characters( char[] ch, int start, int length ) {- if ( currentPropName != null ) {- String origChars = changedStateVars.get( currentPropName );- String newChars = new String( ch, start, length );- if ( origChars == null ) {- changedStateVars.put( currentPropName, newChars );- } else {- changedStateVars.put( currentPropName, origChars + newChars );- }- }- }-- @Override- public void startElement( String uri, String localName, String qName, Attributes attributes ) {- if ( localName.equals( "property" ) ) {- readPropertyName = true;- } else if ( readPropertyName ) {- currentPropName = localName;- }- }-- @Override- public void endElement( String uri, String localName, String qName ) {- if ( currentPropName != null && localName.equals( currentPropName ) ) {- readPropertyName = false;- currentPropName = null;- }- }--}--diff --git a/source/net/yacy/upnp/ServiceEventSubscription.java b/source/net/yacy/upnp/ServiceEventSubscription.javadeleted file mode 100644index 4de79c2a4..000000000--- a/source/net/yacy/upnp/ServiceEventSubscription.java+++ /dev/null@@ -1,111 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--import java.net.InetAddress;-import java.net.URL;--/**- * This class is used to provide information about a subscription done- * via the ServicesEventing class- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class ServiceEventSubscription {-- private String serviceType = null;- private String serviceId = null;- private URL serviceURL = null;- private String SID = null;- private InetAddress deviceIp = null;- private int durationTime = 0;-- public ServiceEventSubscription( String serviceType, String serviceId, URL serviceURL,- String sid, InetAddress deviceIp, int durationTime ) {- this.serviceType = serviceType;- this.serviceId = serviceId;- this.serviceURL = serviceURL;- SID = sid;- this.deviceIp = deviceIp;- this.durationTime = durationTime;- }-- public InetAddress getDeviceIp() {- return deviceIp;- }-- /**- * Subcription duration in seconds- * @return sub duration time, 0 for an infinite time- */- public int getDurationTime() {- return durationTime;- }-- public String getServiceId() {- return serviceId;- }-- public String getServiceType() {- return serviceType;- }-- public URL getServiceURL() {- return serviceURL;- }-- /**- * The subscription ID returned by the UPNPDevice- * @return subscription id- */- public String getSID() {- return SID;- }--}diff --git a/source/net/yacy/upnp/ServicesEventing.java b/source/net/yacy/upnp/ServicesEventing.javadeleted file mode 100644index 2dfb3deb1..000000000--- a/source/net/yacy/upnp/ServicesEventing.java+++ /dev/null@@ -1,437 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp;--import java.util.*;-import java.io.*;-import java.net.*;--import javax.xml.parsers.SAXParser;-import javax.xml.parsers.SAXParserFactory;--import net.yacy.upnp.services.UPNPService;--import org.apache.commons.logging.*;-import org.xml.sax.InputSource;--/**- * This class can be used with the ServiceEventHandler interface- * to recieve notifications about state variables changes on- * a given UPNP service.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class ServicesEventing implements Runnable {-- private final static Log log = LogFactory.getLog( ServicesEventing.class );-- private final static ServicesEventing singleton = new ServicesEventing();- private boolean inService = false;-- private boolean daemon = true;- private int daemonPort = 9999;-- private ServerSocket server = null;-- private List<Subscription> registered = new ArrayList<Subscription>();-- private ServicesEventing() {- }-- public final static ServicesEventing getInstance() {- return singleton;- }-- /**- * Set the listeniner thread as a daemon, default to true.- * Only works when no more objects are registered.- * @param daemon the new thread type.- */- public void setDaemon( boolean daemon ) {- this.daemon = daemon;- }-- /**- * Sets the listener thread port, default to 9999.- * Only works when no more objects are registered.- * @param daemonPort the new listening port- */- public void setDaemonPort( int daemonPort ) {- this.daemonPort = daemonPort;- }-- /**- * Register state variable events notification for a device service- * @param service the service to register with- * @param handler the registrant object- * @param subscriptionDuration subscription time in seconds, -1 for infinite time- * @return the subscription duration returned by the device, 0 for an infinite duration or -1 if no subscription done- * @throws IOException if some IOException error happens during coms with the device- */- public int register( UPNPService service, ServiceEventHandler handler, int subscriptionDuration ) throws IOException {- ServiceEventSubscription sub = registerEvent( service, handler, subscriptionDuration );- if ( sub != null ) {- return sub.getDurationTime();- }- return -1;- }-- /**- * Register state variable events notification for a device service- * @param service the service to register with- * @param handler the registrant object- * @param subscriptionDuration subscription time in seconds, -1 for infinite time- * @return an ServiceEventSubscription object instance containing all the required info or null if no subscription done- * @throws IOException if some IOException error happens during coms with the device- */- public ServiceEventSubscription registerEvent( UPNPService service, ServiceEventHandler handler, int subscriptionDuration ) throws IOException {-- URL eventingLoc = service.getEventSubURL();-- if ( eventingLoc != null ) {-- if ( !inService ) startServicesEventingThread();- String duration = Integer.toString( subscriptionDuration );- if ( subscriptionDuration == -1 ) {- duration = "infinite";- }-- Subscription sub = lookupSubscriber( service, handler );- if ( sub != null ) {- // allready registered let's try to unregister it- unRegister( service, handler );- }-- StringBuilder packet = new StringBuilder( 64 );- packet.append( "SUBSCRIBE " ).append( eventingLoc.getFile() ).append( " HTTP/1.1\r\n" );- packet.append( "HOST: " ).append( eventingLoc.getHost() ).append( ":" ).append( eventingLoc.getPort() ).append( "\r\n" );- packet.append( "CALLBACK: <http://" ).append( InetAddress.getLocalHost().getHostAddress() ).append( ":" ).append( daemonPort ).append( "" ).append( eventingLoc.getFile() ).append( ">\r\n" );- packet.append( "NT: upnp:event\r\n" );- packet.append( "Connection: close\r\n" );- packet.append( "TIMEOUT: Second-" ).append( duration ).append( "\r\n\r\n" );-- Socket skt = new Socket( eventingLoc.getHost(), eventingLoc.getPort() );- skt.setSoTimeout( 30000 ); // 30 secs timeout according to the specs- if ( log.isDebugEnabled() ) log.debug( packet );- OutputStream out = skt.getOutputStream();- out.write( packet.toString().getBytes() );- out.flush();-- InputStream in = skt.getInputStream();- StringBuilder data = new StringBuilder();- int readen = 0;- byte[] buffer = new byte[256];- while ( ( readen = in.read( buffer ) ) != -1 ) {- data.append( new String( buffer, 0, readen ) );- }- in.close();- out.close();- skt.close();- if ( log.isDebugEnabled() ) log.debug( data.toString() );- if ( data.toString().trim().length() > 0 ) {- HttpResponse resp = new HttpResponse( data.toString() );-- if ( resp.getHeader().startsWith( "HTTP/1.1 200 OK" ) ) {- String sid = resp.getHTTPHeaderField( "SID" );- String actualTimeout = resp.getHTTPHeaderField( "TIMEOUT" );- int durationTime = 0;- // actualTimeout = Second-xxx or Second-infinite- if ( !actualTimeout.equalsIgnoreCase( "Second-infinite" ) ) {- durationTime = Integer.parseInt( actualTimeout.substring( 7 ) );- }- sub = new Subscription();- sub.handler = handler;- sub.sub = new ServiceEventSubscription( service.getServiceType(), service.getServiceId(),- service.getEventSubURL(), sid, skt.getInetAddress(),- durationTime );- synchronized( registered ) {- registered.add( sub );- }- return sub.sub;- }- }- }- return null;-- }-- private Subscription lookupSubscriber( UPNPService service, ServiceEventHandler handler ) {- synchronized( registered ) {- for ( Iterator<Subscription> i = registered.iterator(); i.hasNext(); ) {- Subscription sub = i.next();-- if ( sub.handler == handler &&- sub.sub.getServiceId().hashCode() == service.getServiceId().hashCode() &&- sub.sub.getServiceType().hashCode() == service.getServiceType().hashCode() &&- sub.sub.getServiceURL().equals( service.getEventSubURL() ) ) {- return sub;- }- }- }- return null;- }-- private Subscription lookupSubscriber( String sid, InetAddress deviceIp ) {- synchronized( registered ) {- for ( Iterator<Subscription> i = registered.iterator(); i.hasNext(); ) {- Subscription sub = i.next();-- if ( sub.sub.getSID().equals( sid ) && sub.sub.getDeviceIp().equals( deviceIp ) ) {- return sub;- }- }- }- return null;- }-- private Subscription lookupSubscriber( String sid ) {- synchronized( registered ) {- for ( Iterator<Subscription> i = registered.iterator(); i.hasNext(); ) {- Subscription sub = i.next();-- if ( sub.sub.getSID().equals( sid ) ) {- return sub;- }- }- }- return null;- }-- /**- * Unregisters events notifications from a service- * @param service the service that need to be unregistered- * @param handler the handler that registered for this service- * @return true if unregistered false otherwise ( the given handler never registred for the given service )- * @throws IOException if some IOException error happens during coms with the device- */- public boolean unRegister( UPNPService service, ServiceEventHandler handler ) throws IOException {-- URL eventingLoc = service.getEventSubURL();-- if ( eventingLoc != null ) {-- Subscription sub = lookupSubscriber( service, handler );- if ( sub != null ) {- synchronized( registered ) {- registered.remove( sub );- }- if (registered.isEmpty()) {- stopServicesEventingThread();- }-- StringBuilder packet = new StringBuilder( 64 );- packet.append( "UNSUBSCRIBE " ).append( eventingLoc.getFile() ).append( " HTTP/1.1\r\n" );- packet.append( "HOST: " ).append( eventingLoc.getHost() ).append( ":" ).append( eventingLoc.getPort() ).append( "\r\n" );- packet.append( "SID: " ).append( sub.sub.getSID() ).append( "\r\n\r\n" );- Socket skt = new Socket( eventingLoc.getHost(), eventingLoc.getPort() );- skt.setSoTimeout( 30000 ); // 30 secs timeout according to the specs- if ( log.isDebugEnabled() ) log.debug( packet );- OutputStream out = skt.getOutputStream();- out.write( packet.toString().getBytes() );- out.flush();-- InputStream in = skt.getInputStream();- StringBuilder data = new StringBuilder();- int readen = 0;- byte[] buffer = new byte[256];- while ( ( readen = in.read( buffer ) ) != -1 ) {- data.append( new String( buffer, 0, readen ) );- }- in.close();- out.close();- skt.close();- if ( log.isDebugEnabled() ) log.debug( data.toString() );- if ( data.toString().trim().length() > 0 ) {- HttpResponse resp = new HttpResponse( data.toString() );- if ( resp.getHeader().startsWith( "HTTP/1.1 200 OK" ) ) {- return true;- }- }- }- }- return false;- }--- private void startServicesEventingThread() {- synchronized( singleton ) {- if ( !inService ) {- Thread deamon = new Thread( singleton, "ServicesEventing daemon" );- deamon.setDaemon( daemon );- inService = true;- deamon.start();- }- }- }-- private void stopServicesEventingThread() {- synchronized( singleton ) {- inService = false;- try {- server.close();- } catch (final IOException ex ) {- // should not happen- }- }- }-- @Override-public void run() {- // only the deamon thread is allowed to call such method- if ( !Thread.currentThread().getName().equals( "ServicesEventing daemon" ) ) return;- try {- server = new ServerSocket( daemonPort );- } catch (final IOException ex ) {- log.error( "Error during daemon server socket on port " + daemonPort + " creation", ex );- return;- }- while ( inService ) {- try {- Socket skt = server.accept();- new Thread( new RequestProcessor( skt ) ).start();- } catch (final IOException ioEx ) {- if ( inService ) {- log.error( "IO Exception during UPNP messages listening thread", ioEx );- }- }- }- }-- private class Subscription {- private ServiceEventSubscription sub = null;- private ServiceEventHandler handler = null;- }-- private class RequestProcessor implements Runnable {-- private Socket client;-- private RequestProcessor( Socket client ) {- this.client = client;- }-- @Override- public void run() {- try {- client.setSoTimeout( 30000 );- InputStream in = client.getInputStream();- OutputStream out = client.getOutputStream();-- int readen = 0;- StringBuilder data = new StringBuilder();- byte[] buffer = new byte[256];- boolean EOF = false;- while ( !EOF && ( readen = in.read( buffer ) ) != -1 ) {- data.append( new String( buffer, 0, readen ) );- // avoid a strange behaviour with some impls.. the -1 is never reached and a sockettimeout occurs- // and a 0 byte is sent as the last byte- if ( data.charAt( data.length()-1 ) == (char)0 ) {- EOF = true;- }- }-- String packet = data.toString();- if ( packet.trim().length() > 0 ) {-- if ( packet.indexOf( (char)0 ) != -1 ) packet = packet.replace( (char)0, ' ' );- HttpResponse resp = new HttpResponse( packet );- if ( resp.getHeader().startsWith( "NOTIFY" ) ) {-- String sid = resp.getHTTPHeaderField( "SID" );- InetAddress deviceIp = client.getInetAddress();- String postURL = resp.getHTTPHeaderField( "SID" );- Subscription subscription = null;- if ( sid != null && postURL != null ) {- subscription = lookupSubscriber( sid, deviceIp );- if ( subscription == null ) {- // not found maybe that the IP is not the same- subscription = lookupSubscriber( sid );- }- }- if ( subscription != null ) {- // respond ok- out.write( "HTTP/1.1 200 OK\r\n".getBytes() );- } else {- // unknown sid respond ko- out.write( "HTTP/1.1 412 Precondition Failed\r\n".getBytes() );- }-- out.flush();- in.close();- out.close();- client.close();-- if ( subscription != null ) {- // let's parse it- SAXParserFactory saxParFact = SAXParserFactory.newInstance();- saxParFact.setValidating( false );- saxParFact.setNamespaceAware( true );- SAXParser parser = saxParFact.newSAXParser();- ServiceEventMessageParser msgParser = new ServiceEventMessageParser();- StringReader stringReader = new StringReader( resp.getBody() );- InputSource src = new InputSource( stringReader );- parser.parse( src, msgParser );-- Map<String, String> changedStateVars = msgParser.getChangedStateVars();- for ( Iterator<String> i = changedStateVars.keySet().iterator(); i.hasNext(); ) {- String stateVarName = i.next();- String stateVarNewVal = changedStateVars.get( stateVarName );- subscription.handler.handleStateVariableEvent( stateVarName, stateVarNewVal );- }- }- }- }- } catch (final IOException ioEx ) {- log.error( "IO Exception during client processing thread", ioEx );- } catch( Exception ex ) {- log.error( "Unexpected error during client processing thread", ex );- }- }- }-}diff --git a/source/net/yacy/upnp/devices/DeviceIcon.java b/source/net/yacy/upnp/devices/DeviceIcon.javadeleted file mode 100644index 82d16132a..000000000--- a/source/net/yacy/upnp/devices/DeviceIcon.java+++ /dev/null@@ -1,86 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.devices;--import java.net.*;--/**- * Java Bean for a device icon properties- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class DeviceIcon {-- protected String mimeType;- protected int width;- protected int height;- protected int depth;- protected URL url;-- public String getMimeType() {- return mimeType;- }-- public int getWidth() {- return width;- }-- public int getHeight() {- return height;- }-- public int getDepth() {- return depth;- }-- public URL getUrl() {- return url;- }--}diff --git a/source/net/yacy/upnp/devices/UPNPDevice.java b/source/net/yacy/upnp/devices/UPNPDevice.javadeleted file mode 100644index d1e59a5ea..000000000--- a/source/net/yacy/upnp/devices/UPNPDevice.java+++ /dev/null@@ -1,299 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.devices;--import net.yacy.upnp.services.*;--import java.util.*;-import java.net.*;--import org.apache.commons.logging.Log;-import org.apache.commons.logging.LogFactory;--/**- * This class represents an UPNP device, this device contains a set of services- * that will be needed to access the device functionalities.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class UPNPDevice {-- private final static Log log = LogFactory.getLog( UPNPDevice.class );-- protected String deviceType;- protected String friendlyName;- protected String manufacturer;- protected URL manufacturerURL;- protected URL presentationURL;- protected String modelDescription;- protected String modelName;- protected String modelNumber;- protected String modelURL;- protected String serialNumber;- protected String UDN;- protected String USN;- protected long UPC;-- protected ArrayList<DeviceIcon> deviceIcons;- protected ArrayList<UPNPService> services;- protected ArrayList<UPNPDevice> childDevices;-- protected UPNPDevice parent;-- public URL getManufacturerURL() {- return manufacturerURL;- }-- /**- * Presentation URL- * @return URL the presenation URL, or null if the device does not provide- * such information- */- public URL getPresentationURL() {- return presentationURL;- }-- public String getModelDescription() {- return modelDescription;- }-- public String getModelName() {- return modelName;- }-- public String getModelNumber() {- return modelNumber;- }-- public String getModelURL() {- return modelURL;- }-- public String getSerialNumber() {- return serialNumber;- }-- public String getUDN() {- return UDN;- }-- public String getUSN(){- return USN;- }-- public long getUPC() {- return UPC;- }-- public String getDeviceType() {- return deviceType;- }-- public String getFriendlyName() {- return friendlyName;- }-- public String getManufacturer() {- return manufacturer;- }-- public boolean isRootDevice() {- return this instanceof UPNPRootDevice;- }-- /**- * Access to the device icons definitions- * @return a list containing DeviceIcon objects or null if no icons defined- */- public List<DeviceIcon> getDeviceIcons() {- return deviceIcons;- }-- /**- * Generates a list of all the child ( not only top level, full childrens hierarchy included )- * UPNPDevice objects for this device.- * @return the generated list or null if no child devices bound- */- public ArrayList<UPNPDevice> getChildDevices() {- if ( childDevices == null ) return null;- ArrayList<UPNPDevice> rtrVal = new ArrayList<UPNPDevice>();- for ( Iterator<UPNPDevice> itr = childDevices.iterator(); itr.hasNext(); ) {- UPNPDevice device = itr.next();- rtrVal.add( device );- ArrayList<UPNPDevice> found = device.getChildDevices();- if ( found != null ) {- rtrVal.addAll( found );- }- }- return rtrVal;-- }-- /**- * Generates a list of all the child ( only top level )- * UPNPDevice objects for this device.- * @return the generated list or null if no child devices bound- */- public List<UPNPDevice> getTopLevelChildDevices() {- if ( childDevices == null ) return null;- List<UPNPDevice> rtrVal = new ArrayList<UPNPDevice>();- for ( Iterator<UPNPDevice> itr = childDevices.iterator(); itr.hasNext(); ) {- UPNPDevice device = itr.next();- rtrVal.add( device );- }- return rtrVal;- }-- /**- * Return the parent UPNPDevice, null if the device is an UPNPRootDevice- * @return the parent device instance- */- public UPNPDevice getDirectParent() {- return parent;- }-- /**- * Looks for a child UPNP device definition file,- * the whole devices tree will be searched, starting from the current- * device node.- * @param deviceURI the device URI to search- * @return An UPNPDevice if anything matches or null- */- public UPNPDevice getChildDevice( String deviceURI ) {- if ( log.isDebugEnabled() ) log.debug( "searching for device URI:" + deviceURI );- if ( getDeviceType().equals( deviceURI ) ) return this;- if ( childDevices == null ) return null;- for ( Iterator<UPNPDevice> itr = childDevices.iterator(); itr.hasNext(); ) {- UPNPDevice device = itr.next();- UPNPDevice found = device.getChildDevice( deviceURI );- if ( found != null ) {- return found;- }- }- return null;- }-- /**- * Looks for all UPNP device service definitions objects- * @return A list of all device services- */- public ArrayList<UPNPService> getServices() {- if ( services == null ) return null;- ArrayList<UPNPService> rtrVal = new ArrayList<UPNPService>();- rtrVal.addAll( services );- return rtrVal;- }-- /**- * Looks for a UPNP device service definition object for the given service URI (Type)- * @param serviceURI the URI of the service- * @return A matching UPNPService object or null- */- public UPNPService getService( String serviceURI ) {- if ( services == null ) return null;- if ( log.isDebugEnabled() ) log.debug( "searching for service URI:" + serviceURI );- for ( Iterator<UPNPService> itr = services.iterator(); itr.hasNext(); ) {- UPNPService service = itr.next();- if ( service.getServiceType().equals( serviceURI ) ) {- return service;- }- }- return null;- }-- /**- * Looks for a UPNP device service definition object for the given service ID- * @param serviceURI the ID of the service- * @return A matching UPNPService object or null- */- public UPNPService getServiceByID( String serviceID ) {- if ( services == null ) return null;- if ( log.isDebugEnabled() ) log.debug( "searching for service ID:" + serviceID );- for ( Iterator<UPNPService> itr = services.iterator(); itr.hasNext(); ) {- UPNPService service = itr.next();- if ( service.getServiceId().equals( serviceID ) ) {- return service;- }- }- return null;- }-- /**- * Looks for the all the UPNP device service definition object for the current- * UPNP device object. This method can be used to retreive multiple same kind- * ( same service type ) of services with different services id on a device- * @param serviceURI the URI of the service- * @return A matching List of UPNPService objects or null- */- public List<UPNPService> getServices( String serviceURI ) {- if ( services == null ) return null;- List<UPNPService> rtrVal = new ArrayList<UPNPService>();- if ( log.isDebugEnabled() ) log.debug( "searching for services URI:" + serviceURI );- for ( Iterator<UPNPService> itr = services.iterator(); itr.hasNext(); ) {- UPNPService service = itr.next();- if ( service.getServiceType().equals( serviceURI ) ) {- rtrVal.add( service );- }- }- if ( rtrVal.isEmpty() ) {- return null;- }- return rtrVal;- }-- /**- * The toString return the device type- * @return the device type- */- @Override- public String toString() {- return getDeviceType();- }--}diff --git a/source/net/yacy/upnp/devices/UPNPRootDevice.java b/source/net/yacy/upnp/devices/UPNPRootDevice.javadeleted file mode 100644index 423639031..000000000--- a/source/net/yacy/upnp/devices/UPNPRootDevice.java+++ /dev/null@@ -1,463 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.devices;--import java.net.*;-import java.util.*;-import java.io.*;--import org.apache.commons.jxpath.*;-import org.apache.commons.jxpath.xml.*;-import org.apache.commons.logging.*;--import net.yacy.upnp.JXPathParser;-import net.yacy.upnp.services.*;--/**- * Root UPNP device that is contained in a device definition file.- * Slightly differs from a simple UPNPDevice object.- * This object will contains all the child devices, this is the top- * objet in the UPNP device devices hierarchy.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class UPNPRootDevice extends UPNPDevice {-- private final static Log log = LogFactory.getLog( UPNPRootDevice.class );-- private int specVersionMajor;- private int specVersionMinor;- private URL URLBase;- private long validityTime;- private long creationTime;- private URL deviceDefLoc;- private String deviceDefLocData;- private String vendorFirmware;- private String discoveryUSN;- private String discoveryUDN;-- private DocumentContainer UPNPDevice;-- /**- * Constructor for the root device, constructs itself from- * An xml device definition file provided by the UPNP device via http normally.- * @param deviceDefLoc the location of the XML device definition file- * using "the urn:schemas-upnp-org:device-1-0" namespace- * @param maxAge the maximum age of this UPNP device in secs before considered to be outdated- * @param vendorFirmware the vendor firmware- * @param discoveryUSN the discovery USN used to find and create this device- * @param discoveryUDN the discovery UDN used to find and create this device- * @throws MalformedURLException if the location URL is invalid and cannot be used to populate this root object and its child devices- * IllegalStateException if the device has an unsupported version, currently only version 1.0 is supported- */- public UPNPRootDevice( URL deviceDefLoc, String maxAge, String vendorFirmware, String discoveryUSN, String discoveryUDN ) throws MalformedURLException, IllegalStateException {- this( deviceDefLoc, maxAge );- this.vendorFirmware = vendorFirmware;- this.discoveryUSN = discoveryUSN;- this.discoveryUDN = discoveryUDN;- }-- /**- * Constructor for the root device, constructs itself from- * An xml device definition file provided by the UPNP device via http normally.- * @param deviceDefLoc the location of the XML device definition file- * using "the urn:schemas-upnp-org:device-1-0" namespace- * @param maxAge the maximum age of this UPNP device in secs before considered to be outdated- * @param vendorFirmware the vendor firmware- * @throws MalformedURLException if the location URL is invalid and cannot be used to populate this root object and its child devices- * IllegalStateException if the device has an unsupported version, currently only version 1.0 is supported- */- public UPNPRootDevice( URL deviceDefLoc, String maxAge, String vendorFirmware ) throws MalformedURLException, IllegalStateException {- this( deviceDefLoc, maxAge );- this.vendorFirmware = vendorFirmware;- }-- /**- * Constructor for the root device, constructs itself from- * An xml device definition file provided by the UPNP device via http normally.- * @param deviceDefLoc the location of the XML device definition file- * using "the urn:schemas-upnp-org:device-1-0" namespace- * @param maxAge the maximum age in secs of this UPNP device before considered to be outdated- * @throws MalformedURLException if the location URL is invalid and cannot be used to populate this root object and its child devices- * IllegalStateException if the device has an unsupported version, currently only version 1.0 is supported- */- public UPNPRootDevice( URL deviceDefLoc, String maxAge ) throws MalformedURLException, IllegalStateException {- this.deviceDefLoc = deviceDefLoc;- DocumentContainer.registerXMLParser( DocumentContainer.MODEL_DOM, new JXPathParser() );- UPNPDevice = new DocumentContainer( deviceDefLoc, DocumentContainer.MODEL_DOM );- validityTime = Integer.parseInt( maxAge ) * 1000;- creationTime = System.currentTimeMillis();-- JXPathContext context = JXPathContext.newContext( this );-- // registering this namespace because JxPath 1.3 is namespace aware per default - 2010-07-17 MiB-- context.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");-- Pointer rootPtr = context.getPointer( "UPNPDevice/upnp:root" );- JXPathContext rootCtx = context.getRelativeContext( rootPtr );- rootCtx.setNamespaceContextPointer(rootPtr);- // rootCtx.registerNamespace(null, "urn:schemas-upnp-org:device-1-0");-- specVersionMajor = Integer.parseInt( (String)rootCtx.getValue( "upnp:specVersion/upnp:major" ) );- specVersionMinor = Integer.parseInt( (String)rootCtx.getValue( "upnp:specVersion/upnp:minor" ) );-- if ( !( specVersionMajor == 1 && specVersionMinor == 0 ) ) {- throw new IllegalStateException( "Unsupported device version (" + specVersionMajor + "." + specVersionMinor + ")" );- }- boolean buildURLBase = true;- String base = null;- try {- base = (String)rootCtx.getValue( "upnp:URLBase" );- if ( base != null && base.trim().length() > 0 ) {- URLBase = new URL( base );- if ( log.isDebugEnabled() ) log.debug( "device URLBase " + URLBase );- buildURLBase = false;- }- } catch (final JXPathException ex ) {- // URLBase is not mandatory we assume we use the URL of the device- } catch (final MalformedURLException malformedEx ) {- // crappy urlbase provided- log.warn( "Error occured during device baseURL " + base + " parsing, building it from device default location", malformedEx );- }- if ( buildURLBase ) {- String URL = deviceDefLoc.getProtocol() + "://" + deviceDefLoc.getHost() + ":" + deviceDefLoc.getPort();- String path = deviceDefLoc.getPath();- if ( path != null ) {- int lastSlash = path.lastIndexOf( '/' );- if ( lastSlash != -1 ) {- URL += path.substring( 0, lastSlash );- }- }- URLBase = new URL( URL );- }- Pointer devicePtr = rootCtx.getPointer( "upnp:device" );- JXPathContext deviceCtx = rootCtx.getRelativeContext( devicePtr );- deviceCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");-- fillUPNPDevice( this, null, deviceCtx, URLBase );- }-- /**- * The validity time for this device in milliseconds,- * @return the number of milliseconds remaining before the device object that has been build is considered to- * be outdated, after this delay the UPNP device should resend an advertisement message or a negative value- * if the device is outdated- */- public long getValidityTime() {- long elapsed = System.currentTimeMillis() - creationTime;- return validityTime - elapsed;- }-- /**- * Resets the device validity time- * @param newMaxAge the maximum age in secs of this UPNP device before considered to be outdated- */- public void resetValidityTime( String newMaxAge ) {- validityTime = Integer.parseInt( newMaxAge ) * 1000;- creationTime = System.currentTimeMillis();- }-- /**- * Retreives the device description file location- * @return an URL- */- public URL getDeviceDefLoc() {- return deviceDefLoc;- }-- public int getSpecVersionMajor() {- return specVersionMajor;- }-- public int getSpecVersionMinor() {- return specVersionMinor;- }-- public String getVendorFirmware() {- return vendorFirmware;- }-- public String getDiscoveryUSN() {- return discoveryUSN;- }-- public String getDiscoveryUDN() {- return discoveryUDN;- }-- /**- * URL base acces- * @return URL the URL base, or null if the device does not provide- * such information- */- public URL getURLBase() {- return URLBase;- }-- /**- * Parsing an UPNPdevice description element (<device>) in the description XML file- * @param device the device object that will be populated- * @param parent the device parent object- * @param deviceCtx an XPath context for object population- * @param baseURL the base URL of the UPNP device- * @throws MalformedURLException if some URL provided in the description file is invalid- */- private void fillUPNPDevice( UPNPDevice device, UPNPDevice parent, JXPathContext deviceCtx, URL baseURL ) throws MalformedURLException {-- device.deviceType = getMandatoryData( deviceCtx, "upnp:deviceType" );- if ( log.isDebugEnabled() ) log.debug( "parsing device " + device.deviceType );- device.friendlyName = getMandatoryData( deviceCtx, "upnp:friendlyName" );- device.manufacturer = getNonMandatoryData( deviceCtx, "upnp:manufacturer" );- String base = getNonMandatoryData( deviceCtx, "upnp:manufacturerURL" );- try {- if ( base != null ) device.manufacturerURL = new URL( base );- } catch (final java.net.MalformedURLException ex ) {- // crappy data provided, keep the field null- }- try {- device.presentationURL = getURL( getNonMandatoryData( deviceCtx, "upnp:presentationURL" ), URLBase );- } catch (final java.net.MalformedURLException ex ) {- // crappy data provided, keep the field null- }- device.modelDescription = getNonMandatoryData( deviceCtx, "upnp:modelDescription" );- device.modelName = getMandatoryData( deviceCtx, "upnp:modelName" );- device.modelNumber = getNonMandatoryData( deviceCtx, "upnp:modelNumber" );- device.modelURL = getNonMandatoryData( deviceCtx, "upnp:modelURL" );- device.serialNumber = getNonMandatoryData( deviceCtx, "upnp:serialNumber" );- device.UDN = getMandatoryData( deviceCtx, "upnp:UDN" );- device.USN = UDN.concat( "::" ).concat( deviceType );- String tmp = getNonMandatoryData( deviceCtx, "upnp:UPC" );- if ( tmp != null ) {- try {- device.UPC = Long.parseLong( tmp );- } catch (final Exception ex ) {- // non all numeric field provided, non upnp compliant device- }- }- device.parent = parent;-- fillUPNPServicesList( device, deviceCtx );- fillUPNPDeviceIconsList( device, deviceCtx, URLBase );-- Pointer deviceListPtr;- try {- deviceListPtr = deviceCtx.getPointer( "upnp:deviceList" );- } catch (final JXPathException ex ) {- // no pointers for this device list, this can happen- // if the device has no child devices, simply returning- return;- }- JXPathContext deviceListCtx = deviceCtx.getRelativeContext( deviceListPtr );- deviceListCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");- Double arraySize = (Double)deviceListCtx.getValue( "count( upnp:device )" );- device.childDevices = new ArrayList<UPNPDevice>();- if ( log.isDebugEnabled() ) log.debug( "child devices count is " + arraySize );- for ( int i = 1; i <= arraySize.intValue(); i++ ) {- Pointer devicePtr = deviceListCtx.getPointer( "upnp:device[" + i + "]" );- JXPathContext childDeviceCtx = deviceListCtx.getRelativeContext( devicePtr );- childDeviceCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");- UPNPDevice childDevice = new UPNPDevice();- fillUPNPDevice( childDevice, device, childDeviceCtx, baseURL );- if ( log.isDebugEnabled() ) log.debug( "adding child device " + childDevice.getDeviceType() );- device.childDevices.add( childDevice );- }- }-- private String getMandatoryData( JXPathContext ctx, String ctxFieldName ) {- String value = (String)ctx.getValue( ctxFieldName );- if ( value != null && value.isEmpty() ) {- throw new JXPathException( "Mandatory field " + ctxFieldName + " not provided, uncompliant UPNP device !!" );- }- return value;- }-- private String getNonMandatoryData( JXPathContext ctx, String ctxFieldName ) {- String value = null;- try {- value = (String)ctx.getValue( ctxFieldName );- if ( value != null && value.isEmpty() ) {- value = null;- }- } catch (final JXPathException ex ) {- value = null;- }- return value;- }-- /**- * Parsing an UPNPdevice services list element (<device/serviceList>) in the description XML file- * @param device the device object that will store the services list (UPNPService) objects- * @param deviceCtx an XPath context for object population- * @throws MalformedURLException if some URL provided in the description- * file for a service entry is invalid- */- private void fillUPNPServicesList( UPNPDevice device, JXPathContext deviceCtx ) throws MalformedURLException {- Pointer serviceListPtr = deviceCtx.getPointer( "upnp:serviceList" );- JXPathContext serviceListCtx = deviceCtx.getRelativeContext( serviceListPtr );- serviceListCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");- Double arraySize = (Double)serviceListCtx.getValue( "count( upnp:service )" );- if ( log.isDebugEnabled() ) log.debug( "device services count is " + arraySize );- device.services = new ArrayList<UPNPService>();- for ( int i = 1; i <= arraySize.intValue(); i++ ) {-- Pointer servicePtr = serviceListCtx.getPointer( "upnp:service["+i+"]" );- JXPathContext serviceCtx = serviceListCtx.getRelativeContext( servicePtr );- serviceCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");- // TODO possibility of bugs if deviceDefLoc contains a file name- URL base = URLBase != null ? URLBase : deviceDefLoc;- UPNPService service = new UPNPService( serviceCtx, base, this );- device.services.add( service );- }- }-- /**- * Parsing an UPNPdevice icons list element (<device/iconList>) in the description XML file- * This list can be null- * @param device the device object that will store the icons list (DeviceIcon) objects- * @param deviceCtx an XPath context for object population- * @throws MalformedURLException if some URL provided in the description- * file for an icon URL- */- private void fillUPNPDeviceIconsList( UPNPDevice device, JXPathContext deviceCtx, URL baseURL ) throws MalformedURLException {- Pointer iconListPtr;- try {- iconListPtr = deviceCtx.getPointer( "upnp:iconList" );- } catch (final JXPathException ex ) {- // no pointers for icons list, this can happen- // simply returning- return;- }- JXPathContext iconListCtx = deviceCtx.getRelativeContext( iconListPtr );- iconListCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");- Double arraySize = (Double)iconListCtx.getValue( "count( upnp:icon )" );- if ( log.isDebugEnabled() ) log.debug( "device icons count is " + arraySize );- device.deviceIcons = new ArrayList<DeviceIcon>();- for ( int i = 1; i <= arraySize.intValue(); i++ ) {-- DeviceIcon ico = new DeviceIcon();- ico.mimeType = (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:mimetype" );- ico.width = Integer.parseInt( (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:width" ) );- ico.height = Integer.parseInt( (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:height" ) );- ico.depth = Integer.parseInt( (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:depth" ) );- ico.url = getURL( (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:url" ), baseURL );- if ( log.isDebugEnabled() ) log.debug( "icon URL is " + ico.url );- device.deviceIcons.add( ico );- }- }-- /**- * Parsing an URL from the descriptionXML file- * @param url the string representation fo the URL- * @param baseURL the base device URL, needed if the url param is relative- * @return an URL object defining the url param- * @throws MalformedURLException if the url param or baseURL.toExternalForm() + url- * cannot be parsed to create an URL object- */- public final static URL getURL( String url, URL baseURL ) throws MalformedURLException {- URL rtrVal;- if ( url == null || url.trim().isEmpty() ) return null;- try {- rtrVal = new URL( url );- } catch (final MalformedURLException malEx ) {- // maybe that the url is relative, we add the baseURL and reparse it- // if relative then we take the device baser url root and add the url- if ( baseURL != null ) {- url = url.replace( '\\', '/' );- if ( url.charAt( 0 ) != '/' ) {- // the path is relative to the device baseURL- String externalForm = baseURL.toExternalForm();- if ( !externalForm.endsWith( "/" ) ) {- externalForm += "/";- }- rtrVal = new URL( externalForm + url );- } else {- // the path is not relative- String URLRoot = baseURL.getProtocol() + "://" + baseURL.getHost() + ":" + baseURL.getPort();- rtrVal = new URL( URLRoot + url );- }- } else {- throw malEx;- }- }- return rtrVal;- }-- /**- * Retrieves the device definition XML data- * @return the device definition XML data as a String- */- public String getDeviceDefLocData() {- if ( deviceDefLocData == null ) {- try {- java.io.InputStream in = deviceDefLoc.openConnection().getInputStream();- int readen = 0;- byte[] buff = new byte[512];- StringBuilder strBuff = new StringBuilder();- while( ( readen = in.read( buff ) ) != -1 ) {- strBuff.append( new String( buff, 0, readen ) );- }- in.close();- deviceDefLocData = strBuff.toString();- } catch (final IOException ioEx ) {- return null;- }- }- return deviceDefLocData;- }-- /**- * Used for JXPath parsing, do not use this method- * @return a Container object for Xpath parsing capabilities- */- public Container getUPNPDevice() {- return UPNPDevice;- }--}diff --git a/source/net/yacy/upnp/impls/InternetGatewayDevice.java b/source/net/yacy/upnp/impls/InternetGatewayDevice.javadeleted file mode 100644index 7806f8e6b..000000000--- a/source/net/yacy/upnp/impls/InternetGatewayDevice.java+++ /dev/null@@ -1,504 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.impls;--import java.io.IOException;-import java.net.InetAddress;-import java.net.NetworkInterface;-import java.net.UnknownHostException;-import java.util.HashSet;-import java.util.Set;--import net.yacy.upnp.Discovery;-import net.yacy.upnp.devices.UPNPDevice;-import net.yacy.upnp.devices.UPNPRootDevice;-import net.yacy.upnp.messages.ActionMessage;-import net.yacy.upnp.messages.ActionResponse;-import net.yacy.upnp.messages.StateVariableMessage;-import net.yacy.upnp.messages.StateVariableResponse;-import net.yacy.upnp.messages.UPNPMessageFactory;-import net.yacy.upnp.messages.UPNPResponseException;-import net.yacy.upnp.services.UPNPService;--/**- * This class can be used to access some funtionalities on the- * InternetGatewayDevice on your network without having to know- * anything about the required input/output parameters.- * All device functions are not provided.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class InternetGatewayDevice {-- //private final static Log log = LogFactory.getLog( InternetGatewayDevice.class );-- private final UPNPRootDevice igd;- private UPNPMessageFactory msgFactory;-- public InternetGatewayDevice( UPNPRootDevice igd ) throws UnsupportedOperationException {- this( igd, true, true );- }-- private InternetGatewayDevice( UPNPRootDevice igd, boolean WANIPConnection, boolean WANPPPConnection ) throws UnsupportedOperationException {- this.igd = igd;- UPNPDevice myIGDWANConnDevice = igd.getChildDevice( "urn:schemas-upnp-org:device:WANConnectionDevice:1" );- if ( myIGDWANConnDevice == null ) {- throw new UnsupportedOperationException( "device urn:schemas-upnp-org:device:WANConnectionDevice:1 not supported by IGD device " + igd.getModelName() );- }-- UPNPService wanIPSrv = myIGDWANConnDevice.getService( "urn:schemas-upnp-org:service:WANIPConnection:1" );- UPNPService wanPPPSrv = myIGDWANConnDevice.getService( "urn:schemas-upnp-org:service:WANPPPConnection:1" );-- if ( ( WANIPConnection && WANPPPConnection ) && ( wanIPSrv == null && wanPPPSrv == null ) ) {- throw new UnsupportedOperationException( "Unable to find any urn:schemas-upnp-org:service:WANIPConnection:1 or urn:schemas-upnp-org:service:WANPPPConnection:1 service" );- } else if ( ( WANIPConnection && !WANPPPConnection ) && wanIPSrv == null ) {- throw new UnsupportedOperationException( "Unable to find any urn:schemas-upnp-org:service:WANIPConnection:1 service" );- } else if ( ( !WANIPConnection && WANPPPConnection ) && wanPPPSrv == null ) {- throw new UnsupportedOperationException( "Unable to find any urn:schemas-upnp-org:service:WANPPPConnection:1 service" );- }-- if ( wanIPSrv != null && wanPPPSrv == null ) {- this.msgFactory = UPNPMessageFactory.getNewInstance( wanIPSrv );- } else if ( wanPPPSrv != null && wanIPSrv == null ) {- this.msgFactory = UPNPMessageFactory.getNewInstance( wanPPPSrv );- } else {- // Unable to test the following code since no router implementing both IP and PPP connection on hands..- /*// discover the active WAN interface using the WANCommonInterfaceConfig specs- UPNPDevice wanDevice = igd.getChildDevice( "urn:schemas-upnp-org:device:WANDevice:1" );- UPNPService configService = wanDevice.getService( "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" );- if ( configService != null ) {- // retreive the first active connection- ServiceAction act = configService.getUPNPServiceAction( "GetActiveConnection" );- if ( act != null ) {- UPNPMessageFactory msg = UPNPMessageFactory.getNewInstance( configService );- String deviceContainer = null;- String serviceID = null;- try {- // always lookup for the first index of active connections.- ActionResponse resp = msg.getMessage( "GetActiveConnection" ).setInputParameter( "NewActiveConnectionIndex", 0 ).service();- deviceContainer = resp.getOutActionArgumentValue( "NewActiveConnDeviceContainer" );- serviceID = resp.getOutActionArgumentValue( "NewActiveConnectionServiceID" );- } catch (final IOException ex ) {- // no response returned- } catch (final UPNPResponseException respEx ) {- // should never happen unless the damn thing is bugged- }- if ( deviceContainer != null && deviceContainer.trim().length() > 0 &&- serviceID != null && serviceID.trim().length() > 0 ) {- for ( Iterator i = igd.getChildDevices().iterator(); i.hasNext(); ) {- UPNPDevice dv = (UPNPDevice)i.next();-- if ( deviceContainer.startsWith( dv.getUDN() ) &&- dv.getDeviceType().indexOf( ":WANConnectionDevice:" ) != -1 ) {- myIGDWANConnDevice = dv;- break;- }- }- msgFactory = UPNPMessageFactory.getNewInstance( myIGDWANConnDevice.getServiceByID( serviceID ) );- }- }- }*/- // Doing a tricky test with external IP address, the unactive interface should return a null value or none- if ( testWANInterface( wanIPSrv ) ) {- this.msgFactory = UPNPMessageFactory.getNewInstance( wanIPSrv );- } else if( testWANInterface( wanPPPSrv ) ) {- this.msgFactory = UPNPMessageFactory.getNewInstance( wanPPPSrv );- }- if ( this.msgFactory == null ) {- // Nothing found using WANCommonInterfaceConfig! IP by default- //log.warn( "Unable to detect active WANIPConnection, dfaulting to urn:schemas-upnp-org:service:WANIPConnection:1" );- this.msgFactory = UPNPMessageFactory.getNewInstance( wanIPSrv );- }- }- }-- private static boolean testWANInterface( UPNPService srv ) {- UPNPMessageFactory tmp = UPNPMessageFactory.getNewInstance( srv );-- ActionMessage msg = tmp.getMessage( "GetExternalIPAddress" );- String ipToParse = null;- try {- ipToParse = msg.service().getOutActionArgumentValue( "NewExternalIPAddress" );- } catch (final UPNPResponseException ex ) {- // ok probably not the IP interface- } catch (final IOException ex ) {- // not really normal- //log.warn( "IOException occured during device detection", ex );- }- if ( ipToParse != null && ipToParse.length() > 0 && !ipToParse.equals( "0.0.0.0" ) ) {- try {- return InetAddress.getByName( ipToParse ) != null;- } catch (final UnknownHostException ex ) {- // ok a crappy IP provided, definitly the wrong interface..- }- }- return false;- }-- /**- * Retreives the IDG UNPNRootDevice object- * @return the UNPNRootDevie object bound to this object- */- public UPNPRootDevice getIGDRootDevice() {- return this.igd;- }-- /**- * Lookup all the IGD (IP or PPP) devices on the network. If a device implements both- * IP and PPP, the active service will be used for nat mappings.- * @param timeout the timeout in ms to listen for devices response, -1 for default value- * @return an array of devices to play with or null if nothing found.- * @throws IOException if some IO Exception occurs during discovery- */- public static InternetGatewayDevice[] getDevices( int timeout ) throws IOException {- return lookupDeviceDevices( timeout, Discovery.DEFAULT_TTL, Discovery.DEFAULT_MX, true, true, null );- }-- /**- * Lookup all the IGD (IP urn:schemas-upnp-org:service:WANIPConnection:1, or PPP urn:schemas-upnp-org:service:WANPPPConnection:1)- * devices for a given network interface. If a device implements both- * IP and PPP, the active service will be used for nat mappings.- * @param timeout the timeout in ms to listen for devices response, -1 for default value- * @param ttl the discovery ttl such as {@link net.yacy.upnp.Discovery#DEFAULT_TTL}- * @param mx the discovery mx such as {@link net.yacy.upnp.Discovery#DEFAULT_MX}- * @param ni the network interface where to lookup IGD devices- * @return an array of devices to play with or null if nothing found.- * @throws IOException if some IO Exception occurs during discovery- */- public static InternetGatewayDevice[] getDevices( int timeout, int ttl, int mx, NetworkInterface ni ) throws IOException {- return lookupDeviceDevices( timeout, ttl, mx, true, true, ni );- }-- /**- * Lookup all the IGD IP devices on the network (urn:schemas-upnp-org:service:WANIPConnection:1 service)- * @param timeout the timeout in ms to listen for devices response, -1 for default value- * @return an array of devices to play with or null if nothing found or if found devices- * do not have the urn:schemas-upnp-org:service:WANIPConnection:1 service- * @deprecated use generic {@link #getDevices(int)} or {@link #getDevices(int, int, int, NetworkInterface)} methods since this one is not- * usable with all IGD devices ( will only work with devices implementing the urn:schemas-upnp-org:service:WANIPConnection:1 service )- */- @Deprecated- public static InternetGatewayDevice[] getIPDevices( int timeout ) throws IOException {- return lookupDeviceDevices( timeout, Discovery.DEFAULT_TTL, Discovery.DEFAULT_MX, true, false, null );- }-- /**- * Lookup all the IGD PPP devices on the network (urn:schemas-upnp-org:service:WANPPPConnection:1 service)- * @param timeout the timeout in ms to listen for devices response, -1 for default value- * @return an array of devices to play with or null if nothing found or if found devices- * do not have the urn:schemas-upnp-org:service:WANPPPConnection:1 service- * @deprecated use generic {@link #getDevices(int)} or {@link #getDevices(int, int, int, NetworkInterface)} methods since this one is not- * usable with all IGD devices ( will only work with devices implementing the urn:schemas-upnp-org:service:WANPPPConnection:1 service )- */- @Deprecated- public static InternetGatewayDevice[] getPPPDevices( int timeout ) throws IOException {- return lookupDeviceDevices( timeout, Discovery.DEFAULT_TTL, Discovery.DEFAULT_MX, false, true, null );- }-- private static InternetGatewayDevice[] lookupDeviceDevices( int timeout, int ttl, int mx, boolean WANIPConnection, boolean WANPPPConnection, NetworkInterface ni ) throws IOException {- UPNPRootDevice[] devices = null;- InternetGatewayDevice[] rtrVal = null;- if ( timeout == -1 ) {- devices = Discovery.discover( Discovery.DEFAULT_TIMEOUT, ttl, mx, "urn:schemas-upnp-org:device:InternetGatewayDevice:1", ni );- } else {- devices = Discovery.discover( timeout, ttl, mx, "urn:schemas-upnp-org:device:InternetGatewayDevice:1", ni );- }-- if ( devices != null ) {- Set <InternetGatewayDevice> valid = new HashSet<InternetGatewayDevice>();- for (UPNPRootDevice device : devices) {- try {- valid.add( new InternetGatewayDevice( device, WANIPConnection, WANPPPConnection ) );- } catch (final UnsupportedOperationException ex ) {- // the device is either not IP or PPP- //if ( log.isDebugEnabled() ) log.debug( "UnsupportedOperationException during discovery " + ex.getMessage() );- }- }- if ( valid.isEmpty() ) {- return null;- }- rtrVal = new InternetGatewayDevice[valid.size()];- int i = 0;- for (InternetGatewayDevice internetGatewayDevice : valid) {- rtrVal[i++] = internetGatewayDevice;- }-- }- return rtrVal;- }-- /**- * Retreives the external IP address- * @return a String representing the external IP- * @throws UPNPResponseException if the devices returns an error code- * @throws IOException if some error occurs during communication with the device- */- public String getExternalIPAddress() throws UPNPResponseException, IOException {- ActionMessage msg = this.msgFactory.getMessage( "GetExternalIPAddress" );- return msg.service().getOutActionArgumentValue( "NewExternalIPAddress" );- }-- /**- * Retreives a generic port mapping entry.- * @param newPortMappingIndex the index to lookup in the nat table of the upnp device- * @return an action response Object containing the following fields :- * NewRemoteHost, NewExternalPort, NewProtocol, NewInternalPort,- * NewInternalClient, NewEnabled, NewPortMappingDescription, NewLeaseDuration or null if the index does not exists- * @throws IOException if some error occurs during communication with the device- * @throws UPNPResponseException if some unexpected error occurs on the UPNP device- */- public ActionResponse getGenericPortMappingEntry( int newPortMappingIndex ) throws IOException, UPNPResponseException {-- ActionMessage msg = this.msgFactory.getMessage( "GetGenericPortMappingEntry" );- msg.setInputParameter( "NewPortMappingIndex", newPortMappingIndex );-- try {- return msg.service();- } catch (final UPNPResponseException ex ) {- if ( ex.getDetailErrorCode() == 714 ) {- return null;- }- throw ex;- }-- }-- /**- * Retreives information about a specific port mapping- * @param remoteHost the remote host ip to check, null if wildcard- * @param externalPort the port to check- * @param protocol the protocol for the mapping, either TCP or UDP- * @return an action response Object containing the following fields :- * NewInternalPort, NewInternalClient, NewEnabled, NewPortMappingDescription, NewLeaseDuration or- * null if no such entry exists in the device NAT table- * @throws IOException if some error occurs during communication with the device- * @throws UPNPResponseException if some unexpected error occurs on the UPNP device- */- public ActionResponse getSpecificPortMappingEntry( String remoteHost, int externalPort, String protocol ) throws IOException, UPNPResponseException {- remoteHost = remoteHost == null ? "" : remoteHost;- checkPortMappingProtocol( protocol );- checkPortRange( externalPort );-- ActionMessage msg = this.msgFactory.getMessage( "GetSpecificPortMappingEntry" );- msg.setInputParameter( "NewRemoteHost", remoteHost )- .setInputParameter( "NewExternalPort", externalPort )- .setInputParameter( "NewProtocol", protocol );-- try {- return msg.service();- } catch (final UPNPResponseException ex ) {- if ( ex.getDetailErrorCode() == 714 ) {- return null;- }- throw ex;- }- }-- /**- * Configures a nat entry on the UPNP device.- * @param description the mapping description, null for no description- * @param remoteHost the remote host ip for this entry, null for a wildcard value- * @param internalPort the internal client port where data should be redirected- * @param externalPort the external port to open on the UPNP device an map on the internal client, 0 for a wildcard value- * @param internalClient the internal client ip where data should be redirected- * @param leaseDuration the lease duration in seconds 0 for an infinite time- * @param protocol the protocol, either TCP or UDP- * @return true if the port is mapped false if the mapping is allready done for another internal client- * @throws IOException if some error occurs during communication with the device- * @throws UPNPResponseException if the device does not accept some settings :<br/>- * 402 Invalid Args See UPnP Device Architecture section on Control<br/>- * 501 Action Failed See UPnP Device Architecture section on Control<br/>- * 715 WildCardNotPermittedInSrcIP The source IP address cannot be wild-carded<br/>- * 716 WildCardNotPermittedInExtPort The external port cannot be wild-carded <br/>- * 724 SamePortValuesRequired Internal and External port values must be the same<br/>- * 725 OnlyPermanentLeasesSupported The NAT implementation only supports permanent lease times on port mappings<br/>- * 726 RemoteHostOnlySupportsWildcard RemoteHost must be a wildcard and cannot be a specific IP address or DNS name<br/>- * 727 ExternalPortOnlySupportsWildcard ExternalPort must be a wildcard and cannot be a specific port value- */- public boolean addPortMapping( String description, String remoteHost,- int internalPort, int externalPort,- String internalClient, int leaseDuration,- String protocol ) throws IOException, UPNPResponseException {- remoteHost = remoteHost == null ? "" : remoteHost;- checkPortMappingProtocol( protocol );- if ( externalPort != 0 ) {- checkPortRange( externalPort );- }- checkPortRange( internalPort );- description = description == null ? "" : description;- if ( leaseDuration < 0 ) throw new IllegalArgumentException( "Invalid leaseDuration (" + leaseDuration + ") value" );-- ActionMessage msg = this.msgFactory.getMessage( "AddPortMapping" );- msg.setInputParameter( "NewRemoteHost", remoteHost )- .setInputParameter( "NewExternalPort", externalPort )- .setInputParameter( "NewProtocol", protocol )- .setInputParameter( "NewInternalPort", internalPort )- .setInputParameter( "NewInternalClient", internalClient )- .setInputParameter( "NewEnabled", true )- .setInputParameter( "NewPortMappingDescription", description )- .setInputParameter( "NewLeaseDuration", leaseDuration );- try {- msg.service();- return true;- } catch (final UPNPResponseException ex ) {- if ( ex.getDetailErrorCode() == 718 ) {- return false;- }- throw ex;- }- }-- /**- * Deletes a port mapping on the IDG device- * @param remoteHost the host ip for which the mapping was done, null value for a wildcard value- * @param externalPort the port to close- * @param protocol the protocol for the mapping, TCP or UDP- * @return true if the port has been unmapped correctly otherwise false ( entry does not exists ).- * @throws IOException if some error occurs during communication with the device- * @throws UPNPResponseException if the devices returns an error message- */- public boolean deletePortMapping( String remoteHost, int externalPort, String protocol ) throws IOException, UPNPResponseException {-- remoteHost = remoteHost == null ? "" : remoteHost;- checkPortMappingProtocol( protocol );- checkPortRange( externalPort );- ActionMessage msg = this.msgFactory.getMessage( "DeletePortMapping" );- msg.setInputParameter( "NewRemoteHost", remoteHost )- .setInputParameter( "NewExternalPort", externalPort )- .setInputParameter( "NewProtocol", protocol );- try {- msg.service();- return true;- } catch (final UPNPResponseException ex ) {- if ( ex.getDetailErrorCode() == 714 ) {- return false;- }- throw ex;- }- }-- /**- * Retreives the current number of mapping in the NAT table- * @return the nat table current number of mappings or null if the device does not allow to query state variables- * @throws IOException if some error occurs during communication with the device- * @throws UPNPResponseException if the devices returns an error message with error code other than 404- */- public Integer getNatMappingsCount() throws IOException, UPNPResponseException {-- Integer rtrval = null;- StateVariableMessage natTableSize = this.msgFactory.getStateVariableMessage( "PortMappingNumberOfEntries" );- try {- StateVariableResponse resp = natTableSize.service();- rtrval = new Integer( resp.getStateVariableValue() );- } catch (final UPNPResponseException ex ) {- // 404 can happen if device do not implement state variables queries- if ( ex.getDetailErrorCode() != 404 ) {- throw ex;- }- }- return rtrval;- }-- /**- * Computes the total entries in avaliable in the nat table size, not that this method is not guaranteed to work- * with all upnp devices since it is not an generic IGD command- * @return the number of entries or null if the NAT table size cannot be computed for the device- * @throws IOException if some error occurs during communication with the device- * @throws UPNPResponseException if the devices returns an error message with error code other than 713 or 402- */- public Integer getNatTableSize() throws IOException, UPNPResponseException {-- // first let's look at the first index.. some crappy devices do not start with index 0- // we stop at index 50- int startIndex = -1;- for ( int i = 0; i < 50; i++ ) {- try {- this.getGenericPortMappingEntry( i );- startIndex = i;- break;- } catch (final UPNPResponseException ex ) {- // some devices return the 402 code- if ( ex.getDetailErrorCode() != 713 && ex.getDetailErrorCode() != 402 ) {- throw ex;- }- }- }- if ( startIndex == -1 ) {- // humm nothing found within the first 200 indexes..- // returning null- return null;- }- int size = 0;- while ( true ) {-- try {- this.getGenericPortMappingEntry( startIndex++ );- size++;- } catch (final UPNPResponseException ex ) {- if ( ex.getDetailErrorCode() == 713 || ex.getDetailErrorCode() == 402 ) {- /// ok index unknown- break;- }- throw ex;- }- }- return new Integer( size );- }-- private static void checkPortMappingProtocol( String prot ) throws IllegalArgumentException {- if ( prot == null || ( !prot.equals( "TCP" ) && !prot.equals( "UDP" ) ) )- throw new IllegalArgumentException( "PortMappingProtocol must be either TCP or UDP" );- }-- private static void checkPortRange( int port ) throws IllegalArgumentException {- if ( port < 1 || port > 65535 )- throw new IllegalArgumentException( "Port range must be between 1 and 65535" );- }---}diff --git a/source/net/yacy/upnp/messages/ActionMessage.java b/source/net/yacy/upnp/messages/ActionMessage.javadeleted file mode 100644index cf8318a57..000000000--- a/source/net/yacy/upnp/messages/ActionMessage.java+++ /dev/null@@ -1,426 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.messages;--import java.util.*;-import java.io.*;-import java.net.HttpURLConnection;-import java.net.URL;--import org.apache.commons.logging.Log;-import org.apache.commons.logging.LogFactory;-import org.xml.sax.*;--import net.yacy.upnp.services.*;--import javax.xml.parsers.*;--/**- * Message object for an UPNP action, simply call setInputParameter() to add- * the required action message params and then service() to receive the ActionResponse- * built with the parsed UPNP device SOAP xml response.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class ActionMessage {-- private final static Log log = LogFactory.getLog( ActionMessage.class );-- private UPNPService service;- private ServiceAction serviceAction;- private List<InputParamContainer> inputParameters;-- /**- * Protected constuctor so that only messages factories can build it- * @param service the service for which the- * @param serviceAction- */- protected ActionMessage( UPNPService service, ServiceAction serviceAction ) {- this.service = service;- this.serviceAction = serviceAction;- if ( serviceAction.getInputActionArguments() != null ) {- inputParameters = new ArrayList<InputParamContainer>();- }- }-- /**- * Method to clear all set input parameters so that- * this object can be reused- */- public void clearInputParameters() {- inputParameters.clear();- }-- /**- * Executes the message and retuns the UPNP device response, according to the UPNP specs,- * this method could take up to 30 secs to process ( time allowed for a device to respond to a request )- * @return a response object containing the UPNP parsed response- * @throws IOException if some IOException occurs during message send and reception process- * @throws UPNPResponseException if an UPNP error message is returned from the server- * or if some parsing exception occurs ( detailErrorCode = 899, detailErrorDescription = SAXException message )- */- public ActionResponse service() throws IOException, UPNPResponseException {- ActionResponse rtrVal = null;- UPNPResponseException upnpEx = null;- IOException ioEx = null;- StringBuilder body = new StringBuilder( 256 );-- body.append( "<?xml version=\"1.0\"?>\r\n" );- body.append( "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"" );- body.append( " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" );- body.append( "<s:Body>" );- body.append( "<u:" ).append( serviceAction.getName() ).append( " xmlns:u=\"" ).append( service.getServiceType() ).append( "\">" );-- if ( serviceAction.getInputActionArguments() != null ) {- // this action requires params so we just set them...- for ( Iterator<InputParamContainer> itr = inputParameters.iterator(); itr.hasNext(); ) {- InputParamContainer container = itr.next();- body.append( "<" ).append( container.name ).append( ">" ).append( container.value );- body.append( "</" ).append( container.name ).append( ">" );- }- }- body.append( "</u:" ).append( serviceAction.getName() ).append( ">" );- body.append( "</s:Body>" );- body.append( "</s:Envelope>" );-- if ( log.isDebugEnabled() ) log.debug( "POST prepared for URL " + service.getControlURL() );- URL url = new URL( service.getControlURL().toString() );- HttpURLConnection conn = (HttpURLConnection)url.openConnection();- conn.setDoInput( true );- conn.setDoOutput( true );- conn.setUseCaches( false );- conn.setRequestMethod( "POST" );- HttpURLConnection.setFollowRedirects( false );- //conn.setConnectTimeout( 30000 );- conn.setRequestProperty( "HOST", url.getHost() + ":" + url.getPort() );- conn.setRequestProperty( "CONTENT-TYPE", "text/xml; charset=\"utf-8\"" );- conn.setRequestProperty( "CONTENT-LENGTH", Integer.toString( body.length() ) );- conn.setRequestProperty( "SOAPACTION", "\"" + service.getServiceType() + "#" + serviceAction.getName() + "\"" );- OutputStream out = conn.getOutputStream();- out.write( body.toString().getBytes() );- out.flush();- out.close();- conn.connect();- InputStream input = null;-- if ( log.isDebugEnabled() ) log.debug( "executing query :\n" + body );- try {- input = conn.getInputStream();- } catch (final IOException ex ) {- // java can throw an exception if he error code is 500 or 404 or something else than 200- // but the device sends 500 error message with content that is required- // this content is accessible with the getErrorStream- input = conn.getErrorStream();- }-- if ( input != null ) {- int response = conn.getResponseCode();- String responseBody = getResponseBody( input );- if ( log.isDebugEnabled() ) log.debug( "received response :\n" + responseBody );- SAXParserFactory saxParFact = SAXParserFactory.newInstance();- saxParFact.setValidating( false );- saxParFact.setNamespaceAware( true );- ActionMessageResponseParser msgParser = new ActionMessageResponseParser( serviceAction );- StringReader stringReader = new StringReader( responseBody );- InputSource src = new InputSource( stringReader );- try {- SAXParser parser = saxParFact.newSAXParser();- parser.parse( src, msgParser );- } catch (final ParserConfigurationException confEx ) {- // should never happen- // we throw a runtimeException to notify the env problem- throw new RuntimeException( "ParserConfigurationException during SAX parser creation, please check your env settings:" + confEx.getMessage() );- } catch (final SAXException saxEx ) {- // kind of tricky but better than nothing..- upnpEx = new UPNPResponseException( 899, saxEx.getMessage() );- } finally {- try {- input.close();- } catch (final IOException ex ) {- // ignore- }- }- if ( upnpEx == null ) {- if ( response == HttpURLConnection.HTTP_OK ) {- rtrVal = msgParser.getActionResponse();- } else if ( response == HttpURLConnection.HTTP_INTERNAL_ERROR ) {- upnpEx = msgParser.getUPNPResponseException();- } else {- ioEx = new IOException( "Unexpected server HTTP response:" + response );- }- }- }- try {- out.close();- } catch (final IOException ex ) {- // ignore- }- conn.disconnect();- if ( upnpEx != null ) {- throw upnpEx;- }- if ( rtrVal == null && ioEx == null ) {- ioEx = new IOException( "Unable to receive a response from the UPNP device" );- }- if ( ioEx != null ) {- throw ioEx;- }- return rtrVal;- }-- private String getResponseBody( InputStream in ) throws IOException {- byte[] buffer = new byte[256];- int readen = 0;- StringBuilder content = new StringBuilder( 256 );- while ( ( readen = in.read( buffer ) ) != -1 ) {- content.append( new String( buffer, 0 , readen ) );- }- // some devices add \0 chars at XML message end- // which causes XML parsing errors...- int len = content.length();- while ( content.charAt( len-1 ) == '\0' ) {- len--;- content.setLength( len );- }- return content.toString().trim();- }-- /**- * The list of input parameters that should be accepted by the device service for this message- * @return a list of required input parameters ServiceActionArgument objects for this message- * or null if the message does not require any input params- */- public List<String> getInputParameterNames() {- return serviceAction.getInputActionArgumentsNames();- }-- /**- * The list of output parameters that should be returned by the device service- * @return a list of output parameters ServiceActionArgument objects for this message- * or null if the message does not contains any output params.- */- public List<String> getOutputParameterNames() {- return serviceAction.getOutputActionArgumentsNames();- }-- /**- * Set the value of an input parameter before a message service call. If the param name already- * exists, the param value will be overwritten with the new value provided.- * @param parameterName the parameter name- * @param parameterValue the parameter value as an object, primitive object are handled, all other object- * will be assigned with a call to their toString() method call- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, Object parameterValue ) throws IllegalArgumentException {- if ( parameterValue == null ) {- return setInputParameter( parameterName, "" );- } else if ( parameterValue instanceof Date ) {- return setInputParameter( parameterName, (Date)parameterValue );- } else if ( parameterValue instanceof Boolean ) {- return setInputParameter( parameterName, ((Boolean)parameterValue).booleanValue() );- } else if ( parameterValue instanceof Integer ) {- return setInputParameter( parameterName, ((Integer)parameterValue).intValue() );- } else if ( parameterValue instanceof Byte ) {- return setInputParameter( parameterName, ((Byte)parameterValue).byteValue() );- } else if ( parameterValue instanceof Short ) {- return setInputParameter( parameterName, ((Short)parameterValue).shortValue() );- } else if ( parameterValue instanceof Float ) {- return setInputParameter( parameterName, ((Float)parameterValue).floatValue() );- } else if ( parameterValue instanceof Double ) {- return setInputParameter( parameterName, ((Double)parameterValue).doubleValue() );- } else if ( parameterValue instanceof Long ) {- return setInputParameter( parameterName, ((Long)parameterValue).longValue() );- }- return setInputParameter( parameterName, parameterValue.toString() );- }---- /**- * Set the value of an input parameter before a message service call. If the param name already- * exists, the param value will be overwritten with the new value provided- * @param parameterName the parameter name- * @param parameterValue the string parameter value- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, String parameterValue ) throws IllegalArgumentException {- if ( serviceAction.getInputActionArguments() == null ) throw new IllegalArgumentException( "No input parameters required for this message" );- ServiceActionArgument arg = serviceAction.getInputActionArgument( parameterName );- if ( arg == null ) throw new IllegalArgumentException( "Wrong input argument name for this action:" + parameterName + " available parameters are : " + getInputParameterNames() );- for ( Iterator<InputParamContainer> i = inputParameters.iterator(); i.hasNext(); ) {- InputParamContainer container = i.next();- if ( container.name.equals( parameterName ) ) {- container.value = parameterValue;- return this;- }- }- // nothing found add the new value- InputParamContainer container = new InputParamContainer();- container.name = parameterName;- container.value = parameterValue;- inputParameters.add( container );- return this;- }-- /**- * Set the value of an input parameter before a message service call- * @param parameterName the parameter name- * @param parameterValue the date parameter value, will be automatically translated to the correct- * ISO 8601 date format for the given action input param related state variable- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, Date parameterValue ) throws IllegalArgumentException {- if ( serviceAction.getInputActionArguments() == null ) throw new IllegalArgumentException( "No input parameters required for this message" );- ServiceActionArgument arg = serviceAction.getInputActionArgument( parameterName );- if ( arg == null ) throw new IllegalArgumentException( "Wrong input argument name for this action:" + parameterName + " available parameters are : " + getInputParameterNames() );- ServiceStateVariable linkedVar = arg.getRelatedStateVariable();- if ( linkedVar.getDataType().equals( ServiceStateVariableTypes.TIME ) ) {- return setInputParameter( parameterName, ISO8601Date.getIsoTime( parameterValue ) );- } else if ( linkedVar.getDataType().equals( ServiceStateVariableTypes.TIME_TZ ) ) {- return setInputParameter( parameterName, ISO8601Date.getIsoTimeZone( parameterValue ) );- } else if ( linkedVar.getDataType().equals( ServiceStateVariableTypes.DATE ) ) {- return setInputParameter( parameterName, ISO8601Date.getIsoDate( parameterValue ) );- } else if ( linkedVar.getDataType().equals( ServiceStateVariableTypes.DATETIME ) ) {- return setInputParameter( parameterName, ISO8601Date.getIsoDateTime( parameterValue ) );- } else if ( linkedVar.getDataType().equals( ServiceStateVariableTypes.DATETIME_TZ ) ) {- return setInputParameter( parameterName, ISO8601Date.getIsoDateTimeZone( parameterValue ) );- } else {- throw new IllegalArgumentException( "Related input state variable " + linkedVar.getName() + " is not of an date type" );- }- }--- /**- * Set the value of an input parameter before a message service call- * @param parameterName the parameter name- * @param parameterValue the boolean parameter value- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, boolean parameterValue ) throws IllegalArgumentException {- return setInputParameter( parameterName, parameterValue ? "1" : "0" );- }-- /**- * Set the value of an input parameter before a message service call- * @param parameterName the parameter name- * @param parameterValue the byte parameter value- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, byte parameterValue ) throws IllegalArgumentException {- return setInputParameter( parameterName, Byte.toString( parameterValue ) );- }-- /**- * Set the value of an input parameter before a message service call- * @param parameterName the parameter name- * @param parameterValue the short parameter value- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, short parameterValue ) throws IllegalArgumentException {- return setInputParameter( parameterName, Short.toString( parameterValue ) );- }-- /**- * Set the value of an input parameter before a message service call- * @param parameterName the parameter name- * @param parameterValue the integer parameter value- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, int parameterValue ) throws IllegalArgumentException {- return setInputParameter( parameterName, Integer.toString( parameterValue ) );- }-- /**- * Set the value of an input parameter before a message service call- * @param parameterName the parameter name- * @param parameterValue the long parameter value- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, long parameterValue ) throws IllegalArgumentException {- return setInputParameter( parameterName, Long.toString( parameterValue ) );- }-- /**- * Set the value of an input parameter before a message service call- * @param parameterName the parameter name- * @param parameterValue the float parameter value- * @return the current ActionMessage object instance- * @throws IllegalArgumentException if the provided parameterName is not valid for this message- * or if no input parameters are required for this message- */- public ActionMessage setInputParameter( String parameterName, float parameterValue ) throws IllegalArgumentException {- return setInputParameter( parameterName, Float.toString( parameterValue ) );- }-- /**- * Input params class container- */- private class InputParamContainer {-- private String name;- private String value;-- }--}diff --git a/source/net/yacy/upnp/messages/ActionMessageResponseParser.java b/source/net/yacy/upnp/messages/ActionMessageResponseParser.javadeleted file mode 100644index 727e104ac..000000000--- a/source/net/yacy/upnp/messages/ActionMessageResponseParser.java+++ /dev/null@@ -1,163 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.messages;--import org.apache.commons.logging.Log;-import org.apache.commons.logging.LogFactory;-import org.xml.sax.Attributes;--import net.yacy.upnp.services.*;--/**- * Simple SAX handler for UPNP response message parsing, this message is in SOAP format- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class ActionMessageResponseParser extends org.xml.sax.helpers.DefaultHandler {-- private final static Log log = LogFactory.getLog( ActionMessageResponseParser.class );-- private final static String SOAP_FAULT_EL = "Fault";-- private ServiceAction serviceAction;- private String bodyElementName;- private boolean faultResponse = false;- private UPNPResponseException msgEx;-- private boolean readFaultCode = false;- private boolean readFaultString = false;- private boolean readErrorCode = false;- private boolean readErrorDescription = false;- private boolean parseOutputParams = false;- private ActionResponse result;- private ServiceActionArgument parsedResultOutArg;-- protected ActionMessageResponseParser( ServiceAction serviceAction ) {- this.serviceAction = serviceAction;- bodyElementName = serviceAction.getName() + "Response";- }-- protected UPNPResponseException getUPNPResponseException() {- return msgEx;- }-- protected ActionResponse getActionResponse() {- return result;- }-- @Override- public void characters( char[] ch, int start, int length ) {- if ( parseOutputParams ) {- if ( parsedResultOutArg != null ) {- String origChars = result.getOutActionArgumentValue( parsedResultOutArg.getName() );- String newChars = new String( ch, start, length );- if ( origChars == null ) {- result.addResult( parsedResultOutArg, newChars );- } else {- result.addResult( parsedResultOutArg, origChars + newChars );- }- }- } else if ( readFaultCode ) {- msgEx.faultCode = new String( ch, start, length );- readFaultCode = false;- } else if ( readFaultString ) {- msgEx.faultString = new String( ch, start, length );- readFaultString = false;- } else if ( readErrorCode ) {- String code = new String( ch, start, length );- try {- msgEx.detailErrorCode = Integer.parseInt( code );- } catch (final Throwable ex ) {- log.debug( "Error during returned error code " + code + " parsing" );- }- readErrorCode = false;- } else if ( readErrorDescription ) {- msgEx.detailErrorDescription = new String( ch, start, length );- readErrorDescription = false;- }- }-- @Override- public void startElement( String uri, String localName, String qName, Attributes attributes ) {- if ( parseOutputParams ) {- ServiceActionArgument arg = serviceAction.getActionArgument( localName );- if ( arg != null && arg.getDirection() == ServiceActionArgument.DIRECTION_OUT ) {- parsedResultOutArg = arg;- result.addResult( parsedResultOutArg, null );- } else {- parsedResultOutArg = null;- }- } else if ( faultResponse ) {- if ( localName.equals( "faultcode") ) {- readFaultCode = true;- } else if ( localName.equals( "faultstring" ) ) {- readFaultString = true;- } else if ( localName.equals( "errorCode" ) ) {- readErrorCode = true;- } else if ( localName.equals( "errorDescription" ) ) {- readErrorDescription = true;- }- } else if ( localName.equals( SOAP_FAULT_EL ) ) {- msgEx = new UPNPResponseException();- faultResponse = true;- } else if ( localName.equals( bodyElementName ) ) {- parseOutputParams = true;- result = new ActionResponse();- }- }-- @Override- public void endElement( String uri, String localName, String qName ) {- if ( parsedResultOutArg != null && parsedResultOutArg.getName().equals( localName ) ) {- parsedResultOutArg = null;- } else if ( localName.equals( bodyElementName ) ) {- parseOutputParams = false;- }- }-}diff --git a/source/net/yacy/upnp/messages/ActionResponse.java b/source/net/yacy/upnp/messages/ActionResponse.javadeleted file mode 100644index d25eceb75..000000000--- a/source/net/yacy/upnp/messages/ActionResponse.java+++ /dev/null@@ -1,102 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.messages;--import net.yacy.upnp.services.ServiceActionArgument;--import java.util.*;--/**- * An action respons container Object- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class ActionResponse {-- private Map<String, ServiceActionArgument> outArguments = new HashMap<String, ServiceActionArgument>();- private Map<String, String> outArgumentsVals = new HashMap<String, String>();-- protected ActionResponse() {- }-- public ServiceActionArgument getOutActionArgument( String actionArgumentName ) {- return outArguments.get( actionArgumentName );- }-- public String getOutActionArgumentValue( String actionArgumentName ) {- return outArgumentsVals.get( actionArgumentName );- }-- public Set<String> getOutActionArgumentNames() {- return outArguments.keySet();- }-- /**- * Adds a result to the response, adding an existing result ServiceActionArgument- * will override the ServiceActionArgument value- * @param arg the service action argument- * @param value the arg value- */- protected void addResult( ServiceActionArgument arg, String value ) {- outArguments.put( arg.getName(), arg );- outArgumentsVals.put( arg.getName(), value );- }-- @Override- public String toString() {- StringBuilder rtrVal = new StringBuilder();- for ( Iterator<String> i = outArguments.keySet().iterator(); i.hasNext(); ) {- String name = i.next();- String value = outArgumentsVals.get( name );- rtrVal.append( name ).append( "=" ).append( value );- if ( i.hasNext() ) rtrVal.append( "\n" );- }- return rtrVal.toString();- }--}diff --git a/source/net/yacy/upnp/messages/StateVariableMessage.java b/source/net/yacy/upnp/messages/StateVariableMessage.javadeleted file mode 100644index dca91c638..000000000--- a/source/net/yacy/upnp/messages/StateVariableMessage.java+++ /dev/null@@ -1,204 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.messages;--import org.xml.sax.*;-import javax.xml.parsers.*;-import java.io.*;-import java.net.HttpURLConnection;-import java.net.URL;--import org.apache.commons.logging.Log;-import org.apache.commons.logging.LogFactory;--import net.yacy.upnp.services.*;--/**- * This class is used to create state variable messages to- * comminicate with the device- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class StateVariableMessage {-- private final static Log log = LogFactory.getLog( StateVariableMessage.class );-- private UPNPService service;- private ServiceStateVariable serviceStateVar;-- protected StateVariableMessage( UPNPService service, ServiceStateVariable serviceStateVar ) {- this.service = service;- this.serviceStateVar = serviceStateVar;- }-- /**- * Executes the state variable query and retuns the UPNP device response, according to the UPNP specs,- * this method could take up to 30 secs to process ( time allowed for a device to respond to a request )- * @return a state variable response object containing the variable value- * @throws IOException if some IOException occurs during message send and reception process- * @throws UPNPResponseException if an UPNP error message is returned from the server- * or if some parsing exception occurs ( detailErrorCode = 899, detailErrorDescription = SAXException message )- */- public StateVariableResponse service() throws IOException, UPNPResponseException {- StateVariableResponse rtrVal = null;- UPNPResponseException upnpEx = null;- IOException ioEx = null;- StringBuilder body = new StringBuilder( 256 );-- body.append( "<?xml version=\"1.0\"?>\r\n" );- body.append( "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"" );- body.append( " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" );- body.append( "<s:Body>" );- body.append( "<u:QueryStateVariable xmlns:u=\"urn:schemas-upnp-org:control-1-0\">" );- body.append( "<u:varName>" ).append( serviceStateVar.getName() ).append( "</u:varName>" );- body.append( "</u:QueryStateVariable>" );- body.append( "</s:Body>" );- body.append( "</s:Envelope>" );-- if ( log.isDebugEnabled() ) log.debug( "POST prepared for URL " + service.getControlURL() );- URL url = new URL( service.getControlURL().toString() );- HttpURLConnection conn = (HttpURLConnection)url.openConnection();- conn.setDoInput( true );- conn.setDoOutput( true );- conn.setUseCaches( false );- conn.setRequestMethod( "POST" );- HttpURLConnection.setFollowRedirects( false );- //conn.setConnectTimeout( 30000 );- conn.setRequestProperty( "HOST", url.getHost() + ":" + url.getPort() );- conn.setRequestProperty( "SOAPACTION", "\"urn:schemas-upnp-org:control-1-0#QueryStateVariable\"" );- conn.setRequestProperty( "CONTENT-TYPE", "text/xml; charset=\"utf-8\"" );- conn.setRequestProperty( "CONTENT-LENGTH", Integer.toString( body.length() ) );- OutputStream out = conn.getOutputStream();- out.write( body.toString().getBytes() );- out.flush();- conn.connect();- InputStream input = null;-- if ( log.isDebugEnabled() ) log.debug( "executing query :\n" + body );- try {- input = conn.getInputStream();- } catch (final IOException ex ) {- // java can throw an exception if he error code is 500 or 404 or something else than 200- // but the device sends 500 error message with content that is required- // this content is accessible with the getErrorStream- input = conn.getErrorStream();- }-- if ( input != null ) {- int response = conn.getResponseCode();- String responseBody = getResponseBody( input );- if ( log.isDebugEnabled() ) log.debug( "received response :\n" + responseBody );- SAXParserFactory saxParFact = SAXParserFactory.newInstance();- saxParFact.setValidating( false );- saxParFact.setNamespaceAware( true );- StateVariableResponseParser msgParser = new StateVariableResponseParser( serviceStateVar );- StringReader stringReader = new StringReader( responseBody );- InputSource src = new InputSource( stringReader );- try {- SAXParser parser = saxParFact.newSAXParser();- parser.parse( src, msgParser );- } catch (final ParserConfigurationException confEx ) {- // should never happen- // we throw a runtimeException to notify the env problem- throw new RuntimeException( "ParserConfigurationException during SAX parser creation, please check your env settings:" + confEx.getMessage() );- } catch (final SAXException saxEx ) {- // kind of tricky but better than nothing..- upnpEx = new UPNPResponseException( 899, saxEx.getMessage() );- } finally {- try {- input.close();- } catch (final IOException ex ) {- // ignoring- }- }- if ( upnpEx == null ) {- if ( response == HttpURLConnection.HTTP_OK ) {- rtrVal = msgParser.getStateVariableResponse();- } else if ( response == HttpURLConnection.HTTP_INTERNAL_ERROR ) {- upnpEx = msgParser.getUPNPResponseException();- } else {- ioEx = new IOException( "Unexpected server HTTP response:" + response );- }- }- }- try {- out.close();- } catch (final IOException ex ) {- // ignore- }- conn.disconnect();- if ( upnpEx != null ) {- throw upnpEx;- }- if ( rtrVal == null && ioEx == null ) {- ioEx = new IOException( "Unable to receive a response from the UPNP device" );- }- if ( ioEx != null ) {- throw ioEx;- }- return rtrVal;- }-- private String getResponseBody( InputStream in ) throws IOException {- byte[] buffer = new byte[256];- int readen = 0;- StringBuilder content = new StringBuilder( 256 );- while ( ( readen = in.read( buffer ) ) != -1 ) {- content.append( new String( buffer, 0 , readen ) );- }- // some devices add \0 chars at XML message end- // which causes XML parsing errors...- int len = content.length();- while ( content.charAt( len-1 ) == '\0' ) {- len--;- content.setLength( len );- }- return content.toString().trim();- }-}diff --git a/source/net/yacy/upnp/messages/StateVariableResponse.java b/source/net/yacy/upnp/messages/StateVariableResponse.javadeleted file mode 100644index fa6337dfd..000000000--- a/source/net/yacy/upnp/messages/StateVariableResponse.java+++ /dev/null@@ -1,74 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.messages;--import net.yacy.upnp.services.ServiceStateVariable;--/**- * This class contains data returned by a state variable query response- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class StateVariableResponse {-- protected ServiceStateVariable stateVar;- protected String stateVariableValue;-- protected StateVariableResponse() {- }-- public ServiceStateVariable getStateVar() {- return stateVar;- }-- public String getStateVariableValue() {- return stateVariableValue;- }---}diff --git a/source/net/yacy/upnp/messages/StateVariableResponseParser.java b/source/net/yacy/upnp/messages/StateVariableResponseParser.javadeleted file mode 100644index e9d242f25..000000000--- a/source/net/yacy/upnp/messages/StateVariableResponseParser.java+++ /dev/null@@ -1,157 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.messages;--import org.apache.commons.logging.Log;-import org.apache.commons.logging.LogFactory;-import org.xml.sax.Attributes;-import org.xml.sax.SAXException;--import net.yacy.upnp.services.*;--/**- * Simple SAX handler for UPNP state variable query response message parsing, this message is in SOAP format- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class StateVariableResponseParser extends org.xml.sax.helpers.DefaultHandler {-- private final static Log log = LogFactory.getLog( StateVariableResponseParser.class );-- private final static String SOAP_FAULT_EL = "Fault";-- private ServiceStateVariable stateVar;- private boolean faultResponse = false;- private UPNPResponseException msgEx;-- private boolean readFaultCode = false;- private boolean readFaultString = false;- private boolean readErrorCode = false;- private boolean readErrorDescription = false;- private boolean parseStateVar = false;- private StateVariableResponse result;-- protected StateVariableResponseParser( ServiceStateVariable stateVar ) {- this.stateVar = stateVar;- }-- protected UPNPResponseException getUPNPResponseException() {- return msgEx;- }-- protected StateVariableResponse getStateVariableResponse() {- return result;- }-- @Override-public void characters( char[] ch, int start, int length ) {- if ( parseStateVar ) {- String origChars = result.stateVariableValue;- String newChars = new String( ch, start, length );- if ( origChars == null ) {- result.stateVariableValue = newChars;- } else {- result.stateVariableValue = origChars + newChars;- }- } else if ( readFaultCode ) {- msgEx.faultCode = new String( ch, start, length );- readFaultCode = false;- } else if ( readFaultString ) {- msgEx.faultString = new String( ch, start, length );- readFaultString = false;- } else if ( readErrorCode ) {- String code = new String( ch, start, length );- try {- msgEx.detailErrorCode = Integer.parseInt( code );- } catch (final Throwable ex ) {- log.debug( "Error during returned error code " + code + " parsing" );- }- readErrorCode = false;- } else if ( readErrorDescription ) {- msgEx.detailErrorDescription = new String( ch, start, length );- readErrorDescription = false;- }- }-- @Override-public void startElement( String uri, String localName, String qName, Attributes attributes ) {-- if ( faultResponse ) {- if ( localName.equals( "faultcode") ) {- readFaultCode = true;- } else if ( localName.equals( "faultstring" ) ) {- readFaultString = true;- } else if ( localName.equals( "errorCode" ) ) {- readErrorCode = true;- } else if ( localName.equals( "errorDescription" ) ) {- readErrorDescription = true;- }- } else if ( localName.equals( SOAP_FAULT_EL ) ) {- msgEx = new UPNPResponseException();- faultResponse = true;- } else if ( localName.equals( "return" ) || localName.equals( "varName" ) ) {- // some buggy implementations ( intel sample media server )- // do not use the specs compliant return element name but varName ...- parseStateVar = true;- result = new StateVariableResponse();- result.stateVar = stateVar;- }- }-- @Override-public void endElement( String uri, String localName, String qName ) throws SAXException {- // some buggy implementations ( intel sample media server )- // do not use the specs compliant return element name but varName ...- if ( localName.equals( "return" ) || localName.equals( "varName" ) ) {- parseStateVar = false;- }- }--}-diff --git a/source/net/yacy/upnp/messages/UPNPMessageFactory.java b/source/net/yacy/upnp/messages/UPNPMessageFactory.javadeleted file mode 100644index d9b1e0518..000000000--- a/source/net/yacy/upnp/messages/UPNPMessageFactory.java+++ /dev/null@@ -1,108 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.messages;--import net.yacy.upnp.services.*;--/**- * Factory to create UPNP messages to access and communicate with- * a given UPNPDevice service capabilities- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class UPNPMessageFactory {-- private UPNPService service;-- /**- * Private constructor since this is a factory.- * @param service the UPNPService that will be used to generate messages by thid factory- */- private UPNPMessageFactory( UPNPService service ) {- this.service = service;- }-- /**- * Generate a new factory instance for a given device service definition object- * @param service the UPNP service definition object for messages creation- * @return a new message factory- */- public static UPNPMessageFactory getNewInstance( UPNPService service ) {- return new UPNPMessageFactory( service );- }-- /**- * Creation of a new ActionMessage to communicate with the UPNP device- * @param serviceActionName the name of a service action, this name is case sensitive- * and matches exactly the name provided by the UPNP device in the XML definition file- * @return a ActionMessage object or null if the action is unknown for this service messages factory- */- public ActionMessage getMessage( String serviceActionName ) {- ServiceAction serviceAction = service.getUPNPServiceAction( serviceActionName );- if ( serviceAction != null ) {- return new ActionMessage( service, serviceAction );- }- return null;- }-- /**- * Creation of a new StateVariableMessage to communicate with the UPNP device, for a service state variable query- * @param serviceStateVariable the name of a service state variable, this name is case sensitive- * and matches exactly the name provided by the UPNP device in the XML definition file- * @return a StateVariableMessage object or null if the state variable is unknown for this service mesages factory- */- public StateVariableMessage getStateVariableMessage( String serviceStateVariable ) {- ServiceStateVariable stateVar = service.getUPNPServiceStateVariable( serviceStateVariable );- if ( stateVar != null ) {- return new StateVariableMessage( service, stateVar );- }- return null;- }--}diff --git a/source/net/yacy/upnp/messages/UPNPResponseException.java b/source/net/yacy/upnp/messages/UPNPResponseException.javadeleted file mode 100644index a8652a800..000000000--- a/source/net/yacy/upnp/messages/UPNPResponseException.java+++ /dev/null@@ -1,99 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.messages;--/**- * An exception throws when parsing a message if a SOAP fault- * exception is returned.- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class UPNPResponseException extends Exception {-- private static final long serialVersionUID = 8313107558129180594L;-- protected String faultCode;- protected String faultString;- protected int detailErrorCode;- protected String detailErrorDescription;-- public UPNPResponseException() {- }-- public UPNPResponseException( int detailErrorCode, String detailErrorDescription ) {- this.detailErrorCode = detailErrorCode;- this.detailErrorDescription = detailErrorDescription;- }-- public String getFaultCode() {- return faultCode == null ? "Client" : faultCode ;- }-- public String getFaultString() {- return faultString == null ? "UPnPError" : faultString;- }-- public int getDetailErrorCode() {- return detailErrorCode;- }-- public String getDetailErrorDescription() {- return detailErrorDescription;- }-- @Override- public String getMessage() {- return "Detailed error code :" + detailErrorCode + ", Detailed error description :" + detailErrorDescription;- }-- @Override- public String getLocalizedMessage() {- return getMessage();- }--}diff --git a/source/net/yacy/upnp/services/ISO8601Date.java b/source/net/yacy/upnp/services/ISO8601Date.javadeleted file mode 100644index 45da8b9ca..000000000--- a/source/net/yacy/upnp/services/ISO8601Date.java+++ /dev/null@@ -1,330 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.services;--import java.util.Calendar;-import java.util.Date;-import java.util.GregorianCalendar;-import java.util.NoSuchElementException;-import java.util.StringTokenizer;-import java.util.TimeZone;--/**- * ISO8601 Date implementation taken from org.w3c package and modified- * to work with UPNP date types- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class ISO8601Date {-- private static boolean check(StringTokenizer st, String token) throws NumberFormatException {- try {- if (st.nextToken().equals(token)) {- return true;- }- throw new NumberFormatException("Missing [" + token + "]");- } catch (final NoSuchElementException ex) {- return false;- }- }-- private static Calendar getCalendar( String isodate ) throws NumberFormatException {- // YYYY-MM-DDThh:mm:ss.sTZD or hh:mm:ss.sTZD- // does it contains a date ?- boolean isATime = isodate.indexOf( ':' ) != -1;- boolean isADate = isodate.indexOf( '-' ) != -1 || ( isodate.length() == 4 && !isATime );- if ( isATime && ! isADate ) {- if ( !isodate.toUpperCase().startsWith( "T" ) ) {- isodate = "T" + isodate;- }- }- StringTokenizer st = new StringTokenizer(isodate, "-T:.+Z", true);- Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));- calendar.clear();- if ( isADate ) {- // Year- if (st.hasMoreTokens()) {- int year = Integer.parseInt(st.nextToken());- calendar.set(Calendar.YEAR, year);- } else {- return calendar;- }- // Month- if (check(st, "-") && (st.hasMoreTokens())) {- int month = Integer.parseInt(st.nextToken()) - 1;- calendar.set(Calendar.MONTH, month);- } else {- return calendar;- }- // Day- if (check(st, "-") && (st.hasMoreTokens())) {- int day = Integer.parseInt(st.nextToken());- calendar.set(Calendar.DAY_OF_MONTH, day);- } else {- return calendar;- }- }- // Hour- if ( ( check(st, "T") ) && ( st.hasMoreTokens() ) ) {- int hour = Integer.parseInt(st.nextToken());- calendar.set(Calendar.HOUR_OF_DAY, hour);- } else {- calendar.set(Calendar.HOUR_OF_DAY, 0);- calendar.set(Calendar.MINUTE, 0);- calendar.set(Calendar.SECOND, 0);- calendar.set(Calendar.MILLISECOND, 0);- return calendar;- }- // Minutes- if (check(st, ":") && (st.hasMoreTokens())) {- int minutes = Integer.parseInt(st.nextToken());- calendar.set(Calendar.MINUTE, minutes);- } else {- calendar.set(Calendar.MINUTE, 0);- calendar.set(Calendar.SECOND, 0);- calendar.set(Calendar.MILLISECOND, 0);- return calendar;- }-- //- // Not mandatory now- //-- // Secondes- if (!st.hasMoreTokens()) {- return calendar;- }- String tok = st.nextToken();- if (tok.equals(":")) { // secondes- if (st.hasMoreTokens()) {- int secondes = Integer.parseInt(st.nextToken());- calendar.set(Calendar.SECOND, secondes);- if (!st.hasMoreTokens()) {- return calendar;- }- // frac sec- tok = st.nextToken();- if (tok.equals(".")) {- // bug fixed, thx to Martin Bottcher- String nt = st.nextToken();- while (nt.length() < 3) {- nt += "0";- }- nt = nt.substring(0, 3); // Cut trailing chars..- int millisec = Integer.parseInt(nt);- // int millisec = Integer.parseInt(st.nextToken()) * 10;- calendar.set(Calendar.MILLISECOND, millisec);- if (!st.hasMoreTokens()) {- return calendar;- }- tok = st.nextToken();- } else {- calendar.set(Calendar.MILLISECOND, 0);- }- } else {- throw new NumberFormatException("No secondes specified");- }- } else {- calendar.set(Calendar.SECOND, 0);- calendar.set(Calendar.MILLISECOND, 0);- }- // Timezone- if (!tok.equals("Z")) { // UTC- if (!(tok.equals("+") || tok.equals("-"))) {- throw new NumberFormatException("only Z, + or - allowed");- }- boolean plus = tok.equals("+");- if (!st.hasMoreTokens()) {- throw new NumberFormatException("Missing hour field");- }- int tzhour = Integer.parseInt(st.nextToken());- int tzmin = 0;- if (check(st, ":") && (st.hasMoreTokens())) {- tzmin = Integer.parseInt(st.nextToken());- } else {- throw new NumberFormatException("Missing minute field");- }- if (plus) {- calendar.add(Calendar.HOUR, -tzhour);- calendar.add(Calendar.MINUTE, -tzmin);- } else {- calendar.add(Calendar.HOUR, tzhour);- calendar.add(Calendar.MINUTE, tzmin);- }- }- return calendar;- }-- /**- * Parse the given string in ISO 8601 format and build a Date object.- * @param isodate the date in ISO 8601 format- * @return a Date instance- * @exception InvalidDateException- * if the date is not valid- */- public static Date parse(String isodate) throws NumberFormatException {- Calendar calendar = getCalendar(isodate);- return calendar.getTime();- }-- private static String twoDigit(int i) {- if (i >= 0 && i < 10) {- return "0" + String.valueOf(i);- }- return String.valueOf(i);- }-- /**- * Generate a ISO 8601 date- * @param date a Date instance- * @return a string representing the date in the ISO 8601 format- */- public static String getIsoDate(Date date) {- Calendar calendar = new GregorianCalendar();- calendar.setTime(date);- StringBuilder buffer = new StringBuilder();- buffer.append(calendar.get(Calendar.YEAR));- buffer.append("-");- buffer.append(twoDigit(calendar.get(Calendar.MONTH) + 1));- buffer.append("-");- buffer.append(twoDigit(calendar.get(Calendar.DAY_OF_MONTH)));- return buffer.toString();- }-- /**- * Generate a ISO 8601 date time without timezone- * @param date a Date instance- * @return a string representing the date in the ISO 8601 format- */- public static String getIsoDateTime(Date date) {- Calendar calendar = new GregorianCalendar();- calendar.setTime(date);- StringBuilder buffer = new StringBuilder();- buffer.append(calendar.get(Calendar.YEAR));- buffer.append("-");- buffer.append(twoDigit(calendar.get(Calendar.MONTH) + 1));- buffer.append("-");- buffer.append(twoDigit(calendar.get(Calendar.DAY_OF_MONTH)));- buffer.append("T");- buffer.append(twoDigit(calendar.get(Calendar.HOUR_OF_DAY)));- buffer.append(":");- buffer.append(twoDigit(calendar.get(Calendar.MINUTE)));- buffer.append(":");- buffer.append(twoDigit(calendar.get(Calendar.SECOND)));- buffer.append(".");- buffer.append(twoDigit(calendar.get(Calendar.MILLISECOND) / 10));- return buffer.toString();- }-- /**- * Generate a ISO 8601 date time with timezone- * @param date a Date instance- * @return a string representing the date in the ISO 8601 format- */- public static String getIsoDateTimeZone(Date date) {- Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));- calendar.setTime(date);- StringBuilder buffer = new StringBuilder();- buffer.append(calendar.get(Calendar.YEAR));- buffer.append("-");- buffer.append(twoDigit(calendar.get(Calendar.MONTH) + 1));- buffer.append("-");- buffer.append(twoDigit(calendar.get(Calendar.DAY_OF_MONTH)));- buffer.append("T");- buffer.append(twoDigit(calendar.get(Calendar.HOUR_OF_DAY)));- buffer.append(":");- buffer.append(twoDigit(calendar.get(Calendar.MINUTE)));- buffer.append(":");- buffer.append(twoDigit(calendar.get(Calendar.SECOND)));- buffer.append(".");- buffer.append(twoDigit(calendar.get(Calendar.MILLISECOND) / 10));- buffer.append("Z");- return buffer.toString();- }-- /**- * Generate a ISO 8601 time- * @param date a Date instance- * @return a string representing the date in the ISO 8601 format- */- public static String getIsoTime(Date date) {- Calendar calendar = new GregorianCalendar();- calendar.setTime(date);- StringBuilder buffer = new StringBuilder();- buffer.append(twoDigit(calendar.get(Calendar.HOUR_OF_DAY)));- buffer.append(":");- buffer.append(twoDigit(calendar.get(Calendar.MINUTE)));- buffer.append(":");- buffer.append(twoDigit(calendar.get(Calendar.SECOND)));- buffer.append(".");- buffer.append(twoDigit(calendar.get(Calendar.MILLISECOND) / 10));- return buffer.toString();- }-- /**- * Generate a ISO 8601 time- * @param date a Date instance- * @return a string representing the date in the ISO 8601 format- */- public static String getIsoTimeZone(Date date) {- Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));- calendar.setTime(date);- StringBuilder buffer = new StringBuilder();- buffer.append(twoDigit(calendar.get(Calendar.HOUR_OF_DAY)));- buffer.append(":");- buffer.append(twoDigit(calendar.get(Calendar.MINUTE)));- buffer.append(":");- buffer.append(twoDigit(calendar.get(Calendar.SECOND)));- buffer.append(".");- buffer.append(twoDigit(calendar.get(Calendar.MILLISECOND) / 10));- buffer.append("Z");- return buffer.toString();- }--}diff --git a/source/net/yacy/upnp/services/ServiceAction.java b/source/net/yacy/upnp/services/ServiceAction.javadeleted file mode 100644index bcd98071d..000000000--- a/source/net/yacy/upnp/services/ServiceAction.java+++ /dev/null@@ -1,202 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.services;--import java.util.*;--/**- * An object to represent a service action proposed by an UPNP service- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class ServiceAction {-- protected String name;- protected UPNPService parent;- private List<ServiceActionArgument> orderedActionArguments;- private List<ServiceActionArgument> orderedInputActionArguments;- private List<ServiceActionArgument> orderedOutputActionArguments;- private List<String> orderedInputActionArgumentsNames;- private List<String> orderedOutputActionArgumentsNames;-- protected ServiceAction() {- }-- public UPNPService getParent() {- return parent;- }-- /**- * The action in and out arguments ServiceActionArgument objects list- * @return the list with ServiceActionArgument objects or null if the action has no params- */- public List<ServiceActionArgument> getActionArguments() {- return orderedActionArguments;- }-- /**- * Look for an ServiceActionArgument for a given name- * @param argumentName the argument name- * @return the argument or null if not found or not available- */- public ServiceActionArgument getActionArgument( String argumentName ) {- if ( orderedActionArguments == null ) return null;- for ( Iterator<ServiceActionArgument> i = orderedActionArguments.iterator(); i.hasNext(); ) {- ServiceActionArgument arg = i.next();- if ( arg.getName().equals( argumentName ) ) return arg;- }- return null;- }-- protected void setActionArguments( List<ServiceActionArgument> orderedActionArguments ) {- this.orderedActionArguments = orderedActionArguments;- orderedInputActionArguments = getListForActionArgument( orderedActionArguments, ServiceActionArgument.DIRECTION_IN );- orderedOutputActionArguments = getListForActionArgument( orderedActionArguments, ServiceActionArgument.DIRECTION_OUT );- orderedInputActionArgumentsNames = getListForActionArgumentNames( orderedActionArguments, ServiceActionArgument.DIRECTION_IN );- orderedOutputActionArgumentsNames = getListForActionArgumentNames( orderedActionArguments, ServiceActionArgument.DIRECTION_OUT );- }-- /**- * Return a list containing input ( when a response is sent ) arguments objects- * @return a list containing input arguments ServiceActionArgument objects or null when nothing- * is needed for such operation- */- public List<ServiceActionArgument> getInputActionArguments() {- return orderedInputActionArguments;- }-- /**- * Look for an input ServiceActionArgument for a given name- * @param argumentName the input argument name- * @return the argument or null if not found or not available- */- public ServiceActionArgument getInputActionArgument( String argumentName ) {- if ( orderedInputActionArguments == null ) return null;- for ( Iterator<ServiceActionArgument> i = orderedInputActionArguments.iterator(); i.hasNext(); ) {- ServiceActionArgument arg = i.next();- if ( arg.getName().equals( argumentName ) ) return arg;- }- return null;- }--- /**- * Return a list containing output ( when a response is received ) arguments objects- * @return a list containing output arguments ServiceActionArgument objects or null when nothing- * returned for such operation- */- public List<ServiceActionArgument> getOutputActionArguments() {- return orderedOutputActionArguments;- }-- /**- * Look for an output ServiceActionArgument for a given name- * @param argumentName the input argument name- * @return the argument or null if not found or not available- */- public ServiceActionArgument getOutputActionArgument( String argumentName ) {- if ( orderedOutputActionArguments == null ) return null;- for ( Iterator<ServiceActionArgument> i = orderedOutputActionArguments.iterator(); i.hasNext(); ) {- ServiceActionArgument arg = i.next();- if ( arg.getName().equals( argumentName ) ) return arg;- }- return null;- }-- /**- * Return a list containing input ( when a response is sent ) arguments names- * @return a list containing input arguments names as Strings or null when nothing- * is needed for such operation- */- public List<String> getInputActionArgumentsNames() {- return orderedInputActionArgumentsNames;- }-- /**- * Return a list containing output ( when a response is received ) arguments names- * @return a list containing output arguments names as Strings or null when nothing- * returned for such operation- */- public List<String> getOutputActionArgumentsNames() {- return orderedOutputActionArgumentsNames;- }-- /**- * The action name- * @return The action name- */- public String getName() {- return name;- }-- private List<ServiceActionArgument> getListForActionArgument( List<ServiceActionArgument> args, String direction ) {- if ( args == null ) return null;- List<ServiceActionArgument> rtrVal = new ArrayList<ServiceActionArgument>();- for ( Iterator<ServiceActionArgument> itr = args.iterator(); itr.hasNext(); ) {- ServiceActionArgument actArg = itr.next();- if ( actArg.getDirection() == direction ) {- rtrVal.add( actArg );- }- }- if ( rtrVal.isEmpty() ) rtrVal = null;- return rtrVal;- }-- private List<String> getListForActionArgumentNames( List<ServiceActionArgument> args, String direction ) {- if ( args == null ) return null;- List<String> rtrVal = new ArrayList<String>();- for ( Iterator<ServiceActionArgument> itr = args.iterator(); itr.hasNext(); ) {- ServiceActionArgument actArg = itr.next();- if ( actArg.getDirection() == direction ) {- rtrVal.add( actArg.getName() );- }- }- if ( rtrVal.isEmpty() ) rtrVal = null;- return rtrVal;- }-}diff --git a/source/net/yacy/upnp/services/ServiceActionArgument.java b/source/net/yacy/upnp/services/ServiceActionArgument.javadeleted file mode 100644index 9e8e0bf04..000000000--- a/source/net/yacy/upnp/services/ServiceActionArgument.java+++ /dev/null@@ -1,87 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.services;--/**- * An argument for a service action- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class ServiceActionArgument {-- public final static String DIRECTION_IN = "in";- public final static String DIRECTION_OUT = "out";-- protected ServiceStateVariable relatedStateVariable;- protected String name;- protected String direction;-- /**- * The related service state variable for this ServiceActionArgument- * @return The related service state variable for this ServiceActionArgument- */- public ServiceStateVariable getRelatedStateVariable() {- return relatedStateVariable;- }-- /**- * The argument name- * @return the argument name- */- public String getName() {- return name;- }-- /**- * The argument direction- * @return the argument direction (in|out)- */- public String getDirection() {- return direction;- }-}diff --git a/source/net/yacy/upnp/services/ServiceStateVariable.java b/source/net/yacy/upnp/services/ServiceStateVariable.javadeleted file mode 100644index 188d98c15..000000000--- a/source/net/yacy/upnp/services/ServiceStateVariable.java+++ /dev/null@@ -1,263 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.services;--import java.io.IOException;-import java.net.URI;-import java.util.Date;-import java.util.Set;--import net.yacy.upnp.messages.StateVariableMessage;-import net.yacy.upnp.messages.UPNPMessageFactory;-import net.yacy.upnp.messages.UPNPResponseException;--/**- * Class to contain a service state variable definition- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */--public class ServiceStateVariable implements ServiceStateVariableTypes {-- private StateVariableMessage stateVarMsg = null;-- protected String name;- protected boolean sendEvents;- protected String dataType;- protected String defaultValue;-- protected String minimumRangeValue;- protected String maximumRangeValue;- protected String stepRangeValue;- protected Set<String> allowedvalues;- protected UPNPService parent;-- protected ServiceStateVariable() {- }-- /**- * Call to the UPNP device to retreive the state variable actual value- * @return the state variable actual value on the device, should be never null, an empty string could be returned by the device- * @throws UPNPResponseException if the device throws an exception during query- * @throws IOException if some IO error with device occurs during query- */- public String getValue() throws UPNPResponseException, IOException {- if ( stateVarMsg == null ) {- synchronized( this ) {- if ( stateVarMsg == null ) {- UPNPMessageFactory factory = UPNPMessageFactory.getNewInstance( parent );- stateVarMsg = factory.getStateVariableMessage( name );- }- }- }- return stateVarMsg.service().getStateVariableValue();- }-- /**- * State variable name- * @return the state variable name- */- public String getName() {- return name;- }-- /**- * The parent UPNPService Object- * @return the parent object instance- */- public UPNPService getParent() {- return parent;- }-- /**- * Boolean to indicate if the variable is sending events when value- * of the var is changing. The events can be subscribed via the {@link net.yacy.upnp.ServicesEventing}- * class- * @return true if sending events- */- public boolean isSendEvents() {- return sendEvents;- }-- /**- * The default value of the state variable- * @return the default value representation as an string- */- public String getDefaultValue() {- return defaultValue;- }-- /**- * The variable UPNP data type- * @return the data type- */- public String getDataType() {- return dataType;- }-- /**- * The varialbe JAVA data type (using an UPNP->Java mapping)- * @return the class mapped- */- public Class<?> getDataTypeAsClass() {- return getDataTypeClassMapping( dataType );- }-- /**- * A set of allowed values (String objects) for the variable- * @return the allowed values or null if none- */- public Set<String> getAllowedvalues() {- return allowedvalues;- }-- /**- * The minimum value as a string- * @return the minimum value or null if no restriction- */- public String getMinimumRangeValue() {- return minimumRangeValue;- }-- /**- * The maximum value as a string- * @return the maximum value or null if no restriction- */- public String getMaximumRangeValue() {- return maximumRangeValue;- }-- /**- * The value step range as a string- * @return the value step raqnge or null if no restriction- */- public String getStepRangeValue() {- return stepRangeValue;- }-- public static Class<?> getDataTypeClassMapping( String dataType ) {- int hash = dataType.hashCode();- if ( hash == UI1_INT ) return Short.class;- else if ( hash == UI2_INT ) return Integer.class;- else if ( hash == UI4_INT ) return Long.class;- else if ( hash == I1_INT ) return Byte.class;- else if ( hash == I2_INT ) return Short.class;- else if ( hash == I4_INT ) return Integer.class;- else if ( hash == INT_INT ) return Integer.class;- else if ( hash == R4_INT ) return Float.class;- else if ( hash == R8_INT ) return Double.class;- else if ( hash == NUMBER_INT ) return Double.class;- else if ( hash == FIXED_14_4_INT ) return Double.class;- else if ( hash == FLOAT_INT ) return Float.class;- else if ( hash == CHAR_INT) return Character.class;- else if ( hash == STRING_INT ) return String.class;- else if ( hash == DATE_INT ) return Date.class;- else if ( hash == DATETIME_INT ) return Date.class;- else if ( hash == DATETIME_TZ_INT ) return Date.class;- else if ( hash == TIME_INT ) return Date.class;- else if ( hash == TIME_TZ_INT ) return Date.class;- else if ( hash == BOOLEAN_INT ) return Boolean.class;- else if ( hash == BIN_BASE64_INT ) return String.class;- else if ( hash == BIN_HEX_INT ) return String.class;- else if ( hash == URI_INT ) return URI.class;- else if ( hash == UUID_INT ) return String.class;- return null;- }-- public static String getUPNPDataTypeMapping( String className ) {- if ( className.equals( Short.class.getName() ) || className.equals( "short" )) return I2;- else if ( className.equals( Byte.class.getName() ) || className.equals( "byte" )) return I1;- else if ( className.equals( Integer.class.getName() ) || className.equals( "int" ) ) return INT;- else if ( className.equals( Long.class.getName() ) || className.equals( "long" ) ) return UI4;- else if ( className.equals( Float.class.getName() ) || className.equals( "float" )) return FLOAT;- else if ( className.equals( Double.class.getName() ) || className.equals( "double" ) ) return NUMBER;- else if ( className.equals( Character.class.getName() ) || className.equals( "char" ) ) return CHAR;- else if ( className.equals( String.class.getName() ) || className.equals( "string" ) ) return STRING;- else if ( className.equals( Date.class.getName() ) ) return DATETIME;- else if ( className.equals( Boolean.class.getName() ) || className.equals( "boolean" ) ) return BOOLEAN;- else if ( className.equals( URI.class.getName() ) ) return URI;- return null;- }-- public static Object UPNPToJavaObject( String dataType, String value ) throws Throwable {- if ( value == null ) throw new Exception( "null value" );- if ( dataType == null ) throw new Exception( "null dataType" );- int hash = dataType.hashCode();- if ( hash == UI1_INT ) return new Short( value );- else if ( hash == UI2_INT ) return new Integer( value );- else if ( hash == UI4_INT ) return new Long( value );- else if ( hash == I1_INT ) return new Byte( value );- else if ( hash == I2_INT ) return new Short( value );- else if ( hash == I4_INT ) return new Integer( value );- else if ( hash == INT_INT ) return new Integer( value );- else if ( hash == R4_INT ) return new Float( value );- else if ( hash == R8_INT ) return new Double( value );- else if ( hash == NUMBER_INT ) return new Double( value );- else if ( hash == FIXED_14_4_INT ) return new Double( value );- else if ( hash == FLOAT_INT ) return new Float( value );- else if ( hash == CHAR_INT) return new Character( value.charAt( 0 ) );- else if ( hash == STRING_INT ) return value;- else if ( hash == DATE_INT ) return ISO8601Date.parse( value );- else if ( hash == DATETIME_INT ) return ISO8601Date.parse( value );- else if ( hash == DATETIME_TZ_INT ) return ISO8601Date.parse( value );- else if ( hash == TIME_INT ) return ISO8601Date.parse( value );- else if ( hash == TIME_TZ_INT ) return ISO8601Date.parse( value );- else if ( hash == BOOLEAN_INT ) {- if ( value.equals( "1" ) || value.equalsIgnoreCase( "yes" ) || value.equals( "true" ) ) {- return Boolean.TRUE;- }- return Boolean.FALSE;- }- else if ( hash == BIN_BASE64_INT ) return value;- else if ( hash == BIN_HEX_INT ) return value;- else if ( hash == URI_INT ) return new URI( value );- else if ( hash == UUID_INT ) return value;- throw new Exception( "Unhandled data type " + dataType );- }--}diff --git a/source/net/yacy/upnp/services/ServiceStateVariableTypes.java b/source/net/yacy/upnp/services/ServiceStateVariableTypes.javadeleted file mode 100644index 8ae09a449..000000000--- a/source/net/yacy/upnp/services/ServiceStateVariableTypes.java+++ /dev/null@@ -1,188 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.services;--/**- * Interface to defined allowed values for service state variables data types- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public interface ServiceStateVariableTypes {-- /**- * Unsigned 1 Byte int. Same format as int without leading sign.- */- public final static String UI1 = "ui1";- /**- * Unsigned 2 Byte int. Same format as int without leading sign.- */- public final static String UI2 = "ui2";- /**- * Unsigned 4 Byte int. Same format as int without leading sign.- */- public final static String UI4 = "ui4";- /**- * 1 Byte int. Same format as int.- */- public final static String I1 = "i1";- /**- * 2 Byte int. Same format as int.- */- public final static String I2 = "i2";- /**- * 4 Byte int. Same format as int.- */- public final static String I4 = "i4";- /**- * Fixed point, integer number. May have leading sign. May have leading zeros.- * (No currency symbol.) (No grouping of digits to the left of the decimal, e.g., no commas.)- */- public final static String INT = "int";- /**- * 4 Byte float. Same format as float. Must be between 3.40282347E+38 to 1.17549435E-38.- */- public final static String R4 = "r4";- /**- * 8 Byte float. Same format as float. Must be between -1.79769313486232E308 and -4.94065645841247E-324- * for negative values, and between 4.94065645841247E-324 and 1.79769313486232E308 for positive values,- * i.e., IEEE 64-bit (8-Byte) double.- */- public final static String R8 = "r8";- /**- * Same as r8.- */- public final static String NUMBER = "number";- /**- * Same as r8 but no more than 14 digits to the left of the decimal point and no more than 4 to the right.- */- public final static String FIXED_14_4 = "fixed.14.4";- /**- * Floating point number. Mantissa (left of the decimal) and/or exponent may have a leading sign.- * Mantissa and/or exponent may have leading zeros. Decimal character in mantissa is a period, i.e.,- * whole digits in mantissa separated from fractional digits by period. Mantissa separated from exponent- * by E. (No currency symbol.) (No grouping of digits in the mantissa, e.g., no commas.)- */- public final static String FLOAT = "float";- /**- * Unicode string. One character long.- */- public final static String CHAR = "char";- /**- * Unicode string. No limit on length.- */- public final static String STRING = "string";- /**- * Date in a subset of ISO 8601 format without time data.- */- public final static String DATE = "date";- /**- * Date in ISO 8601 format with optional time but no time zone.- */- public final static String DATETIME = "dateTime";- /**- * Date in ISO 8601 format with optional time and optional time zone.- */- public final static String DATETIME_TZ = "dateTime.tz";- /**- * Time in a subset of ISO 8601 format with no date and no time zone.- */- public final static String TIME = "time";- /**- * Time in a subset of ISO 8601 format with optional time zone but no date.- */- public final static String TIME_TZ = "time.tz";- /**- * 0, false, or no for false; 1, true, or yes for true.- */- public final static String BOOLEAN = "boolean";- /**- * MIME-style Base64 encoded binary BLOB. Takes 3 Bytes, splits them into 4 parts,- * and maps each 6 bit piece to an octet. (3 octets are encoded as 4.) No limit on size.- */- public final static String BIN_BASE64 = "bin.base64";- /**- * Hexadecimal digits representing octets. Treats each nibble as a hex digit and encodes- * as a separate Byte. (1 octet is encoded as 2.) No limit on size.- */- public final static String BIN_HEX = "bin.hex";- /**- * Universal Resource Identifier.- */- public final static String URI = "uri";- /**- * Universally Unique ID. Hexadecimal digits representing octets.- * Optional embedded hyphens are ignored.- */- public final static String UUID = "uuid";-- public final static int UI1_INT = "ui1".hashCode();- public final static int UI2_INT = "ui2".hashCode();- public final static int UI4_INT = "ui4".hashCode();- public final static int I1_INT = "i1".hashCode();- public final static int I2_INT = "i2".hashCode();- public final static int I4_INT = "i4".hashCode();- public final static int INT_INT = "int".hashCode();- public final static int R4_INT = "r4".hashCode();- public final static int R8_INT = "r8".hashCode();- public final static int NUMBER_INT = "number".hashCode();- public final static int FIXED_14_4_INT = "fixed.14.4".hashCode();- public final static int FLOAT_INT = "float".hashCode();- public final static int CHAR_INT = "char".hashCode();- public final static int STRING_INT = "string".hashCode();- public final static int DATE_INT = "date".hashCode();- public final static int DATETIME_INT = "dateTime".hashCode();- public final static int DATETIME_TZ_INT = "dateTime.tz".hashCode();- public final static int TIME_INT = "time".hashCode();- public final static int TIME_TZ_INT = "time.tz".hashCode();- public final static int BOOLEAN_INT = "boolean".hashCode();- public final static int BIN_BASE64_INT = "bin.base64".hashCode();- public final static int BIN_HEX_INT = "bin.hex".hashCode();- public final static int URI_INT = "uri".hashCode();- public final static int UUID_INT = "uuid".hashCode();--}diff --git a/source/net/yacy/upnp/services/UPNPService.java b/source/net/yacy/upnp/services/UPNPService.javadeleted file mode 100644index ba35ff067..000000000--- a/source/net/yacy/upnp/services/UPNPService.java+++ /dev/null@@ -1,332 +0,0 @@-/*- * ============================================================================- * The Apache Software License, Version 1.1- * ============================================================================- *- * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.- *- * Redistribution and use in source and binary forms, with or without modifica-- * tion, are permitted provided that the following conditions are met:- *- * 1. Redistributions of source code must retain the above copyright notice,- * this list of conditions and the following disclaimer.- *- * 2. Redistributions in binary form must reproduce the above copyright notice,- * this list of conditions and the following disclaimer in the documentation- * and/or other materials provided with the distribution.- *- * 3. The end-user documentation included with the redistribution, if any, must- * include the following acknowledgment: "This product includes software- * developed by SuperBonBon Industries (http://www.sbbi.net/)."- * Alternately, this acknowledgment may appear in the software itself, if- * and wherever such third-party acknowledgments normally appear.- *- * 4. The names "UPNPLib" and "SuperBonBon Industries" must not be- * used to endorse or promote products derived from this software without- * prior written permission. For written permission, please contact- * [email protected].- *- * 5. Products derived from this software may not be called- * "SuperBonBon Industries", nor may "SBBI" appear in their name,- * without prior written permission of SuperBonBon Industries.- *- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,- * INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- *- * This software consists of voluntary contributions made by many individuals- * on behalf of SuperBonBon Industries. For more information on- * SuperBonBon Industries, please see <http://www.sbbi.net/>.- */-package net.yacy.upnp.services;--import org.apache.commons.jxpath.*;-import org.apache.commons.jxpath.xml.*;--import java.util.*;-import java.io.IOException;-import java.net.*;--import net.yacy.upnp.JXPathParser;-import net.yacy.upnp.devices.*;--/**- * Representation of an UPNP service- * @author <a href="mailto:[email protected]">SuperBonBon</a>- * @version 1.0- */-public class UPNPService {-- protected String serviceType;- protected String serviceId;- private int specVersionMajor;- private int specVersionMinor;- protected URL SCPDURL;- protected String SCPDURLData;- protected URL controlURL;- protected URL eventSubURL;- protected UPNPDevice serviceOwnerDevice;-- protected Map<String, ServiceAction> UPNPServiceActions;- protected Map<String, ServiceStateVariable> UPNPServiceStateVariables;- private String USN;-- private boolean parsedSCPD = false;- private DocumentContainer UPNPService;-- public UPNPService( JXPathContext serviceCtx, URL baseDeviceURL, UPNPDevice serviceOwnerDevice ) throws MalformedURLException {- this.serviceOwnerDevice = serviceOwnerDevice;- serviceType = (String)serviceCtx.getValue( "upnp:serviceType" );- serviceId = (String)serviceCtx.getValue( "upnp:serviceId" );- SCPDURL = UPNPRootDevice.getURL( (String)serviceCtx.getValue( "upnp:SCPDURL" ), baseDeviceURL );- controlURL = UPNPRootDevice.getURL( (String)serviceCtx.getValue( "upnp:controlURL" ), baseDeviceURL );- eventSubURL = UPNPRootDevice.getURL( (String)serviceCtx.getValue( "upnp:eventSubURL" ), baseDeviceURL );- USN = serviceOwnerDevice.getUDN().concat( "::" ).concat( serviceType );- }-- public String getServiceType() {- return serviceType;- }-- public String getServiceId() {- return serviceId;- }-- public String getUSN(){- return USN;- }-- public URL getSCPDURL() {- return SCPDURL;- }-- public URL getControlURL() {- return controlURL;- }-- public URL getEventSubURL() {- return eventSubURL;- }-- public int getSpecVersionMajor() {- lazyInitiate();- return specVersionMajor;- }-- public int getSpecVersionMinor() {- lazyInitiate();- return specVersionMinor;- }-- public UPNPDevice getServiceOwnerDevice() {- return serviceOwnerDevice;- }-- /**- * Retreives a service action for its given name- * @param actionName the service action name- * @return a ServiceAction object or null if no matching action for this service has been found- */- public ServiceAction getUPNPServiceAction( String actionName ) {- lazyInitiate();- return UPNPServiceActions.get( actionName );- }-- /**- * Retreives a service state variable for its given name- * @param stateVariableName the state variable name- * @return a ServiceStateVariable object or null if no matching state variable has been found- */- public ServiceStateVariable getUPNPServiceStateVariable( String stateVariableName ) {- lazyInitiate();- return UPNPServiceStateVariables.get( stateVariableName );- }-- public Iterator<String> getAvailableActionsName() {- lazyInitiate();- return UPNPServiceActions.keySet().iterator();- }-- public int getAvailableActionsSize() {- lazyInitiate();- return UPNPServiceActions.keySet().size();- }-- public Iterator<String> getAvailableStateVariableName() {- lazyInitiate();- return UPNPServiceStateVariables.keySet().iterator();- }-- public int getAvailableStateVariableSize() {- lazyInitiate();- return UPNPServiceStateVariables.keySet().size();- }-- private void parseSCPD() {- try {- DocumentContainer.registerXMLParser( DocumentContainer.MODEL_DOM, new JXPathParser() );- UPNPService = new DocumentContainer( SCPDURL, DocumentContainer.MODEL_DOM );- JXPathContext context = JXPathContext.newContext( this );- context.registerNamespace("scpdns", "urn:schemas-upnp-org:service-1-0");- Pointer rootPtr = context.getPointer( "UPNPService/scpdns:scpd" );- JXPathContext rootCtx = context.getRelativeContext( rootPtr );- rootCtx.registerNamespace("scpdns", "urn:schemas-upnp-org:service-1-0");-- specVersionMajor = Integer.parseInt( (String)rootCtx.getValue( "scpdns:specVersion/scpdns:major" ) );- specVersionMinor = Integer.parseInt( (String)rootCtx.getValue( "scpdns:specVersion/scpdns:minor" ) );-- parseServiceStateVariables( rootCtx );-- Pointer actionsListPtr = rootCtx.getPointer( "scpdns:actionList" );- JXPathContext actionsListCtx = context.getRelativeContext( actionsListPtr );- actionsListCtx.registerNamespace("scpdns", "urn:schemas-upnp-org:service-1-0");- Double arraySize = (Double)actionsListCtx.getValue( "count( scpdns:action )" );- UPNPServiceActions = new HashMap<String, ServiceAction>();- for ( int i = 1; i <= arraySize.intValue(); i++ ) {- ServiceAction action = new ServiceAction();- action.name = (String)actionsListCtx.getValue( "scpdns:action["+i+"]/scpdns:name" );- action.parent = this;- Pointer argumentListPtr = null;- try {- argumentListPtr = actionsListCtx.getPointer( "scpdns:action["+i+"]/scpdns:argumentList" );- } catch (final JXPathException ex ) {- // there is no arguments list.- }- if ( argumentListPtr != null ) {- JXPathContext argumentListCtx = actionsListCtx.getRelativeContext( argumentListPtr );- argumentListCtx.registerNamespace("scpdns", "urn:schemas-upnp-org:service-1-0");- Double arraySizeArgs = (Double)argumentListCtx.getValue( "count( scpdns:argument )" );-- List<ServiceActionArgument> orderedActionArguments = new ArrayList<ServiceActionArgument>();- for ( int z = 1; z <= arraySizeArgs.intValue(); z++ ) {- ServiceActionArgument arg = new ServiceActionArgument();- arg.name = (String)argumentListCtx.getValue( "scpdns:argument["+z+"]/scpdns:name" );- String direction = (String)argumentListCtx.getValue( "scpdns:argument["+z+"]/scpdns:direction" );- arg.direction = direction.equals( ServiceActionArgument.DIRECTION_IN ) ? ServiceActionArgument.DIRECTION_IN : ServiceActionArgument.DIRECTION_OUT;- String stateVarName = (String)argumentListCtx.getValue( "scpdns:argument["+z+"]/scpdns:relatedStateVariable" );- ServiceStateVariable stateVar = UPNPServiceStateVariables.get( stateVarName );- if ( stateVar == null ) {- throw new IllegalArgumentException( "Unable to find any state variable named " + stateVarName + " for service " + getServiceId() + " action " + action.name + " argument " + arg.name );- }- arg.relatedStateVariable = stateVar;- orderedActionArguments.add( arg );- }-- if ( arraySizeArgs.intValue() > 0 ) {- action.setActionArguments( orderedActionArguments );- }- }-- UPNPServiceActions.put( action.getName(), action );- }- parsedSCPD = true;- } catch (final Throwable t ) {- throw new RuntimeException( "Error during lazy SCDP file parsing at " + SCPDURL, t );- }- }-- private void parseServiceStateVariables( JXPathContext rootContext ) {- Pointer serviceStateTablePtr = rootContext.getPointer( "scpdns:serviceStateTable" );- JXPathContext serviceStateTableCtx = rootContext.getRelativeContext( serviceStateTablePtr );- serviceStateTableCtx.registerNamespace("scpdns", "urn:schemas-upnp-org:service-1-0");- Double arraySize = (Double)serviceStateTableCtx.getValue( "count( scpdns:stateVariable )" );- UPNPServiceStateVariables = new HashMap<String, ServiceStateVariable>();- for ( int i = 1; i <= arraySize.intValue(); i++ ) {- ServiceStateVariable srvStateVar = new ServiceStateVariable();- String sendEventsLcl = null;- try {- sendEventsLcl = (String)serviceStateTableCtx.getValue( "scpdns:stateVariable["+i+"]/scpdns:@sendEvents" );- } catch (final JXPathException defEx ) {- // sendEvents not provided defaulting according to specs to "yes"- sendEventsLcl = "yes";- }- srvStateVar.parent = this;- srvStateVar.sendEvents = sendEventsLcl.equalsIgnoreCase( "no" ) ? false : true;- srvStateVar.name = (String)serviceStateTableCtx.getValue( "scpdns:stateVariable["+i+"]/scpdns:name" );- srvStateVar.dataType = (String)serviceStateTableCtx.getValue( "scpdns:stateVariable["+i+"]/scpdns:dataType" );- try {- srvStateVar.defaultValue = (String)serviceStateTableCtx.getValue( "scpdns:stateVariable["+i+"]/scpdns:defaultValue" );- } catch (final JXPathException defEx ) {- // can happend since default value is not- }- Pointer allowedValuesPtr = null;- try {- allowedValuesPtr = serviceStateTableCtx.getPointer( "scpdns:stateVariable["+i+"]/scpdns:allowedValueList" );- } catch (final JXPathException ex ) {- // there is no allowed values list.- }- if ( allowedValuesPtr != null ) {- JXPathContext allowedValuesCtx = serviceStateTableCtx.getRelativeContext( allowedValuesPtr );- allowedValuesCtx.registerNamespace("scpdns", "urn:schemas-upnp-org:service-1-0");- Double arraySizeAllowed = (Double)allowedValuesCtx.getValue( "count( scpdns:allowedValue )" );- srvStateVar.allowedvalues = new HashSet<String>();- for ( int z = 1; z <= arraySizeAllowed.intValue(); z++ ) {- String allowedValue = (String)allowedValuesCtx.getValue( "scpdns:allowedValue["+z+"]" );- srvStateVar.allowedvalues.add( allowedValue );- }- }-- Pointer allowedValueRangePtr = null;- try {- allowedValueRangePtr = serviceStateTableCtx.getPointer( "scpdns:stateVariable["+i+"]/scpdns:allowedValueRange" );- } catch (final JXPathException ex ) {- // there is no allowed values list, can happen- }- if ( allowedValueRangePtr != null ) {-- srvStateVar.minimumRangeValue = (String)serviceStateTableCtx.getValue( "scpdns:stateVariable["+i+"]/scpdns:allowedValueRange/scpdns:minimum" );- srvStateVar.maximumRangeValue = (String)serviceStateTableCtx.getValue( "scpdns:stateVariable["+i+"]/scpdns:allowedValueRange/scpdns:maximum" );- try {- srvStateVar.stepRangeValue = (String)serviceStateTableCtx.getValue( "scpdns:stateVariable["+i+"]/scpdns:allowedValueRange/scpdns:step" );- } catch (final JXPathException stepEx ) {- // can happend since step is not mandatory- }- }- UPNPServiceStateVariables.put( srvStateVar.getName(), srvStateVar );- }-- }-- private void lazyInitiate() {- if ( !parsedSCPD )- synchronized( this ) {- if ( !parsedSCPD )- parseSCPD();- }- }-- /**- * Used for JXPath parsing, do not use this method- * @return a Container object for Xpath parsing capabilities- */- public Container getUPNPService() {- return UPNPService;- }-- public String getSCDPData() {- if ( SCPDURLData == null ) {- try {-- java.io.InputStream in = SCPDURL.openConnection().getInputStream();- int readen = 0;- byte[] buff = new byte[512];- StringBuilder strBuff = new StringBuilder();- while( ( readen = in.read( buff ) ) != -1 ) {- strBuff.append( new String( buff, 0, readen ) );- }- in.close();- SCPDURLData = strBuff.toString();- } catch (final IOException ioEx ) {- return null;- }- }- return SCPDURLData;- }-}diff --git a/source/net/yacy/upnp/version.properties b/source/net/yacy/upnp/version.propertiesdeleted file mode 100644index d948172d8..000000000--- a/source/net/yacy/upnp/version.properties+++ /dev/null@@ -1,8 +0,0 @@-# please make sur to update those values-# when crating a new release-# especially to create cvs changelogs-release.version=1.0.4-release.version.cvs.tag=V1_0_4-release.version.publish.date=20 Nov 2006-last.release.version.cvs.tag=V1_0_3-last.release.version.publish.date=14 Feb 2006\ No newline at end of filediff --git a/source/net/yacy/utils/UPnP.java b/source/net/yacy/utils/UPnP.javaindex 7cec5d4e3..e6c860248 100644--- a/source/net/yacy/utils/UPnP.java+++ b/source/net/yacy/utils/UPnP.java@@ -27,192 +27,169 @@package net.yacy.utils;import java.io.IOException;-import java.net.MalformedURLException;-import java.net.URL;+import java.net.InetAddress;+import java.util.Map;++import javax.xml.parsers.ParserConfigurationException;-import net.yacy.cora.protocol.Domains;import net.yacy.cora.util.ConcurrentLog;import net.yacy.search.Switchboard;-import net.yacy.search.SwitchboardConstants;-import net.yacy.upnp.DiscoveryAdvertisement;-import net.yacy.upnp.DiscoveryEventHandler;-import net.yacy.upnp.devices.UPNPRootDevice;-import net.yacy.upnp.impls.InternetGatewayDevice;-import net.yacy.upnp.messages.UPNPResponseException;++import org.bitlet.weupnp.GatewayDevice;+import org.bitlet.weupnp.GatewayDiscover;+import org.xml.sax.SAXException;public class UPnP {-- public final static ConcurrentLog log = new ConcurrentLog("UPNP");- private static Switchboard sb = Switchboard.getSwitchboard();-- private final static int discoveryTimeout = 5000; // seconds to receive a response from devices- private static InternetGatewayDevice[] IGDs = null;-++ private static final ConcurrentLog LOG = new ConcurrentLog("UPNP");+ private static final Switchboard SB = Switchboard.getSwitchboard();++ private static Map<InetAddress, GatewayDevice> GATEWAY_DEVICES = null;+// mapping variables- private final static String mappedName = "YaCy";- private final static String mappedProtocol = "TCP";- private static int mappedPort = 0;- private static String localHostIP = null;-- /* Discovery message sender IP /10.100.100.2 does not match device description IP /192.168.1.254 skipping message,- set the net.yacy.upnp.ddos.matchip system property to false to avoid this check- static {- System.setProperty("net.yacy.upnp.ddos.matchip", "false");- } */-- public static boolean setIGDs(InternetGatewayDevice[] igds) {- if(IGDs == null) {- IGDs = igds; // set only once to prevent many same devices by advertisement events- return true;- }- return false;- }-+ private static final String MAPPED_NAME = "YaCy";+ private static final String MAPPED_PROTOCOL = "TCP";+ private static int mappedPort;+private static boolean init() {boolean init = true;+try {- if (IGDs == null) IGDs = InternetGatewayDevice.getDevices(discoveryTimeout);- localHostIP = Domains.myPublicLocalIP().getHostAddress();- if (localHostIP.startsWith("127.")) log.warn("found odd local address: " + localHostIP + "; UPnP may fail");- } catch (final IOException e) {+ if (GATEWAY_DEVICES == null) {+ GATEWAY_DEVICES = new GatewayDiscover().discover();+ }+ } catch (IOException | SAXException | ParserConfigurationException e) {init = false;}- if (IGDs != null) {- for (InternetGatewayDevice IGD : IGDs) {- log.info("found device: " + IGD.getIGDRootDevice().getFriendlyName());+ if (GATEWAY_DEVICES != null) {+ for (final GatewayDevice gatewayDevice : GATEWAY_DEVICES.values()) {+ LOG.info("found device: " + gatewayDevice.getFriendlyName());}} else {- log.info("no device found");+ LOG.info("no device found");init = false;- log.info("listening for device");- Listener.register();}-+return init;}-- private static String getRemoteHost() {- if (sb == null) return null;- return sb.getConfig(SwitchboardConstants.UPNP_REMOTEHOST, "");- }-+/**- * add port mapping for configured port+ * Add port mapping for configured port.*/public static void addPortMapping() {- if (sb == null) return;- addPortMapping(Integer.parseInt(sb.getConfig("port", "0")));+ if (SB == null) {+ return;+ }+ addPortMapping(Integer.parseInt(SB.getConfig("port", "0")));}-+/**- * add TCP port mapping to all IGDs on the network<br/>- * latest port mapping will be removed+ * Add TCP port mapping to all gateway devices on the network.<br/>+ * Latest port mapping will be removed.+ ** @param port*/- public static void addPortMapping(final int port) { //TODO: don't map already mapped port again- if (port < 1) return;- if (mappedPort > 0) deletePortMapping(); // delete old mapping first- if (mappedPort == 0 && ((IGDs != null && localHostIP != null) || init())) {- for (InternetGatewayDevice IGD : IGDs) {+ public static void addPortMapping(final int port) { // TODO: don't map+ // already mapped port+ // again+ if (port < 1) {+ return;+ }++ if (mappedPort > 0) {+ deletePortMapping(); // delete old mapping first+ }++ if (mappedPort == 0 && ((GATEWAY_DEVICES != null) || init())) {++ String localHostIP;+ boolean mapped;+ String msg;+ for (final GatewayDevice gatewayDevice : GATEWAY_DEVICES.values()) {+try {- boolean mapped = IGD.addPortMapping(mappedName, getRemoteHost(), port, port, localHostIP, 0, mappedProtocol);- String msg = "port " + port + " on device "+ IGD.getIGDRootDevice().getFriendlyName();+ localHostIP = toString(gatewayDevice.getLocalAddress());++ mapped = gatewayDevice.addPortMapping(port, port,+ localHostIP, MAPPED_PROTOCOL, MAPPED_NAME);++ msg = "port " + port + " on device "+ + gatewayDevice.getFriendlyName();+if (mapped) {- log.info("mapped " + msg);+ LOG.info("mapped " + msg);mappedPort = port;+ } else {+ LOG.warn("could not map " + msg);}- else log.warn("could not map " + msg);- } catch (final IOException e) {} catch (final UPNPResponseException e) { log.severe("mapping error: " + e.getMessage()); }+ } catch (IOException | SAXException e) {+ LOG.severe("mapping error: " + e.getMessage());+ }}}}-+/**- * delete current port mapping+ * Delete current port mapping.*/public static void deletePortMapping() {- if (mappedPort > 0 && IGDs != null && localHostIP != null) {- for (InternetGatewayDevice IGD : IGDs) {+ if (mappedPort > 0 && GATEWAY_DEVICES != null) {++ boolean unmapped;+ String msg;+ for (final GatewayDevice gatewayDevice : GATEWAY_DEVICES.values()) {+try {- boolean unmapped = IGD.deletePortMapping(getRemoteHost(), mappedPort, mappedProtocol);- String msg = "port " + mappedPort + " on device "+ IGD.getIGDRootDevice().getFriendlyName();- if (unmapped) log.info("unmapped " + msg);- else log.warn("could not unmap " + msg);- } catch (final IOException e) {} catch (final UPNPResponseException e) { log.severe("unmapping error: " + e.getMessage()); }+ unmapped = gatewayDevice.deletePortMapping(mappedPort,+ MAPPED_PROTOCOL);++ msg = "port " + mappedPort + " on device "+ + gatewayDevice.getFriendlyName();++ if (unmapped) {+ LOG.info("unmapped " + msg);+ } else {+ LOG.warn("could not unmap " + msg);+ }++ } catch (SAXException | IOException e) {+ LOG.severe("unmapping error: " + e.getMessage());+ }}+mappedPort = 0; // reset mapped port}}-+/**- * @return mapped port or 0+ * Gets currently mapped port.+ *+ * @return mapped port or 0 if no port is mapped*/public static int getMappedPort() {return mappedPort;}-- public static void main(String[] args) {- deletePortMapping(); // nothing- addPortMapping(40000); // map- addPortMapping(40000); // unmap, map- deletePortMapping(); // unmap- deletePortMapping(); // nothing- }-- /**- * register devices that do not respond to discovery but advertise themselves- */- public static class Listener {-- private final static Handler handler = new Handler();- private final static String devicetype = "urn:schemas-upnp-org:device:InternetGatewayDevice:1";-- public static void register() {- try {- DiscoveryAdvertisement.getInstance().registerEvent(DiscoveryAdvertisement.EVENT_SSDP_ALIVE, devicetype, handler);-// DiscoveryAdvertisement.getInstance().registerEvent(DiscoveryAdvertisement.EVENT_SSDP_BYE_BYE, devicetype, handler);- } catch (final IOException e) {}- }-- public static void unregister() {- DiscoveryAdvertisement.getInstance().unRegisterEvent(DiscoveryAdvertisement.EVENT_SSDP_ALIVE, devicetype, handler);-// DiscoveryAdvertisement.getInstance().unRegisterEvent(DiscoveryAdvertisement.EVENT_SSDP_BYE_BYE, devicetype, handler);- }-- protected static class Handler implements DiscoveryEventHandler {-- @Override- public void eventSSDPAlive(String usn, String udn, String nt, String maxAge, URL location) {- InternetGatewayDevice[] newIGD = { null };- boolean error = false;- String errorMsg = null;- try {- newIGD[0] = new InternetGatewayDevice(new UPNPRootDevice(location, maxAge, "", usn, udn));- } catch (final UnsupportedOperationException e) {- error = true;- errorMsg = e.getMessage();- } catch (final MalformedURLException e) {- error = true;- errorMsg = e.getMessage();- } catch (final IllegalStateException e) {- error = true;- errorMsg = e.getMessage();- }- if (error && errorMsg != null)- log.severe("eventSSDPAlive: " + errorMsg);- if (newIGD[0] == null) return;- log.info("discovered device: " + newIGD[0].getIGDRootDevice().getFriendlyName());- if (UPnP.setIGDs(newIGD) &&- Switchboard.getSwitchboard().getConfigBool(SwitchboardConstants.UPNP_ENABLED, false))- UPnP.addPortMapping();- Listener.unregister();++ private static String toString(final InetAddress inetAddress) {++ final String localHostIP;++ if (inetAddress != null) {++ localHostIP = inetAddress.getHostAddress();++ if (!inetAddress.isSiteLocalAddress()+ || localHostIP.startsWith("127.")) {+ LOG.warn("found odd local address: " + localHostIP+ + "; UPnP may fail");}-- @Override- public void eventSSDPByeBye(String usn, String udn, String nt) {}-+ } else {++ localHostIP = "";+ LOG.warn("unknown local address, UPnP may fail");}-++ return localHostIP;}}