/******************************************************************************* * Copyright (c) 2013 Ziver * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ package zutil.net.upnp; import java.util.Map; import java.util.UUID; import zutil.net.http.HttpPrintStream; /** * This class is a UPnP AV Media Server that handles all the * other UPnP services * * @author Ziver */ public class UPnPMediaServer extends UPnPRootDevice{ public static final String RELATIVE_URL = "upnp/rootdev"; private String url; private String uuid; public UPnPMediaServer(String location){ url = location; } public void respond(HttpPrintStream out, Map clientInfo, Map session, Map cookie, Map request) { out.enableBuffering(true); out.setHeader("Content-Type", "text/xml"); out.println(""); out.println(""); out.println(" "); out.println(" 1"); out.println(" 0"); out.println(" "); out.println(" "+url+"");//"+ssdp.getLocation()+" out.println(" "); out.println(" urn:schemas-upnp-org:device:MediaServer:1"); out.println(" ZupNP AV Media Server"); out.println(" Ziver Koc"); out.println(" http://ziver.koc.se"); out.println(""); out.println(" ZupNP Server"); out.println(" UPnP AV Media Server"); out.println(" 0.1"); out.println(" "+getUUID()+""); out.println(" "); out.println(" "); out.println(" urn:schemas-upnp-org:service:ConnectionManager:1"); out.println(" urn:upnp-org:serviceId:CMGR_1-0"); out.println(" CMGR_Control/GetServDesc"); out.println(" CMGR_Control"); out.println(" CMGR_Event"); out.println(" "); out.println(" "); out.println(" urn:schemas-upnp-org:service:ContentDirectory:1"); out.println(" urn:upnp-org:serviceId:CDS_1-0"); out.println(" SCP/ContentDir"); out.println(" Action/ContentDir"); out.println(" Event/ContentDir"); out.println(" "); out.println(" "); out.println(" "); out.println(""); out.flush(); } public long getExpirationTime() { return 60*30; // 30min } public String getLocation() { return url+"RootDesc"; } public String getSearchTarget() { return "upnp:rootdevice"; } public String getUSN() { return getUUID()+"::upnp:rootdevice"; } public String getUUID() { if(uuid==null){ uuid = "uuid:"+UUID.nameUUIDFromBytes( this.getClass().toString().getBytes() ); //(url+Math.random()).getBytes() } return uuid; } }