diff options
Diffstat (limited to '')
| -rw-r--r-- | source/client/request/ContentCodesRequest.java | 65 | ||||
| -rw-r--r-- | source/client/request/DatabasesRequest.java | 121 | ||||
| -rw-r--r-- | source/client/request/LoginRequest.java | 49 | ||||
| -rw-r--r-- | source/client/request/LogoutRequest.java | 42 | ||||
| -rw-r--r-- | source/client/request/NoServerPermissionException.java | 41 | ||||
| -rw-r--r-- | source/client/request/Request.java | 225 | ||||
| -rw-r--r-- | source/client/request/ServerInfoRequest.java | 46 | ||||
| -rw-r--r-- | source/client/request/SingleDatabaseRequest.java | 76 | ||||
| -rw-r--r-- | source/client/request/SongRequest.java | 87 |
9 files changed, 752 insertions, 0 deletions
diff --git a/source/client/request/ContentCodesRequest.java b/source/client/request/ContentCodesRequest.java new file mode 100644 index 0000000..316900d --- /dev/null +++ b/source/client/request/ContentCodesRequest.java @@ -0,0 +1,65 @@ +/* + * Created on May 7, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ +package itunes.client.request; +import itunes.*; + +import java.util.ArrayList; +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class ContentCodesRequest extends Request { + protected ArrayList mdclDataFields; + + public ContentCodesRequest(String server, int port) throws NoServerPermissionException { + super(server, port, "content-codes"); + } + protected void Process() throws NoServerPermissionException{ + super.Process(); + parseMDCL(); + } + + protected void parseMDCL() { + mdclDataFields = new ArrayList(); + for (int i = 0; i < mdclIndexes.size(); i++) { + byte[] mdclData = ((FieldPair)fieldPairs.get(((Integer)mdclIndexes.get(i)).intValue())).value; + mdclDataFields.add(processDataFields(mdclData,0)); + } + } + + public String toString() { + String ret = super.toString(); + for (int i=0; i < mdclDataFields.size();i++) { + ArrayList fps = ((ArrayList)mdclDataFields.get(i)); + for (int j = 0; j < fps.size();j++) { + ret += ((FieldPair)fps.get(j)).toString() + "\n"; + } + } + return ret; + } +} + diff --git a/source/client/request/DatabasesRequest.java b/source/client/request/DatabasesRequest.java new file mode 100644 index 0000000..965a97a --- /dev/null +++ b/source/client/request/DatabasesRequest.java @@ -0,0 +1,121 @@ +/* + * Created on May 6, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + */ +package itunes.client.request; +import itunes.*; +import itunes.client.*; + +import java.util.ArrayList; +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class DatabasesRequest extends Request { + + protected ArrayList mlclDataFields; + protected ArrayList mlitDataFields; + + public DatabasesRequest(String server, int port, int sessionId) throws NoServerPermissionException{ + super(server, port, "databases?session-id="+sessionId); + } + + public DatabasesRequest(String server, int port, String rs) throws NoServerPermissionException{ + super(server, port, rs); + } + protected void Process() throws NoServerPermissionException { + super.Process(); + parseMLCL(); + } + + protected void parseMLCL() { + for (int i = 0; i < mlclIndexes.size(); i++) { + byte[] mlclData = ((FieldPair)fieldPairs.get(((Integer)mlclIndexes.get(i)).intValue())).value; + mlclDataFields = this.processDataFields(mlclData,0); + } + parseMLIT(); + } + + protected void parseMLIT() { + mlitDataFields = new ArrayList(); + for (int i = 0; i < mlitIndexes.size(); i++) { + byte[] mlitData = ((FieldPair)mlclDataFields.get(((Integer)mlitIndexes.get(i)).intValue())).value; + mlitDataFields.add(processDataFields(mlitData,0)); + } + } + + public int getLibraryCount() { + return mlclDataFields.size(); + } + + public int getDbId(int i) { + ArrayList currMlitDataFields = ((ArrayList)mlitDataFields.get(i)); + int index = currMlitDataFields.indexOf(new FieldPair("miid",null,0,0)); + FieldPair fp = (FieldPair)currMlitDataFields.get(index); + return Request.readInt(fp.value,0); + } + + public int getSongCount(int i) { + ArrayList currMlitDataFields = ((ArrayList)mlitDataFields.get(i)); + int index = currMlitDataFields.indexOf(new FieldPair("mimc",null,0,0)); + FieldPair fp = (FieldPair)currMlitDataFields.get(index); + return Request.readInt(fp.value,0); + } + + public ArrayList getDbs() { + ArrayList dbs = new ArrayList(); + for (int i = 0; i < mlitDataFields.size();i++) { + ArrayList fps = ((ArrayList)mlitDataFields.get(i)); + String name=null; + int id=0; + Database d = new Database(); + for (int j = 0; j < fps.size();j++) { + FieldPair fp =((FieldPair)fps.get(j)); + if (fp.name.equals("miid")) { + d.id = Request.readInt(fp.value,0); + } else if (fp.name.equals("minm")) { + d.name = Request.readString(fp.value,0,fp.value.length); + } + } + dbs.add(d); + } + return dbs; + } + + public String toString() { + String ret = super.toString(); + for (int i = 0; i < mlclDataFields.size();i++) { + ret += ((FieldPair)mlclDataFields.get(i)).toString() + "\n"; + } + for (int i=0; i < mlitDataFields.size();i++) { + ArrayList fps = ((ArrayList)mlitDataFields.get(i)); + for (int j = 0; j < fps.size();j++) { + ret += ((FieldPair)fps.get(j)).toString() + "\n"; + } + } + return ret; + } +} diff --git a/source/client/request/LoginRequest.java b/source/client/request/LoginRequest.java new file mode 100644 index 0000000..59b1857 --- /dev/null +++ b/source/client/request/LoginRequest.java @@ -0,0 +1,49 @@ +/* + * Created on May 6, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + */ +package itunes.client.request; + +import itunes.*; + +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class LoginRequest extends Request { + + public LoginRequest(String server, int port) throws NoServerPermissionException { + super(server, port, "login"); + } + + public int getSessionId() { + int index = fieldPairs.indexOf(new FieldPair("mlid",new byte[0],0,0)); + if (index == -1) + return index; + FieldPair fp = (FieldPair)fieldPairs.get(index); + return readInt(fp.value,0); + } +} diff --git a/source/client/request/LogoutRequest.java b/source/client/request/LogoutRequest.java new file mode 100644 index 0000000..c18d9ac --- /dev/null +++ b/source/client/request/LogoutRequest.java @@ -0,0 +1,42 @@ +/* + * Created on May 6, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + */ +package itunes.client.request; + +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class LogoutRequest extends Request { + + protected int sessionId; + + public LogoutRequest(String server, int port, int sid) throws NoServerPermissionException{ + super(server, port,("logout?session-id="+sid)); + } + +} diff --git a/source/client/request/NoServerPermissionException.java b/source/client/request/NoServerPermissionException.java new file mode 100644 index 0000000..b8c179b --- /dev/null +++ b/source/client/request/NoServerPermissionException.java @@ -0,0 +1,41 @@ +/* + * Created on May 8, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + */ +package itunes.client.request; + +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class NoServerPermissionException extends Exception { + + + public NoServerPermissionException() { + super("Error downloading song "); + } + +} diff --git a/source/client/request/Request.java b/source/client/request/Request.java new file mode 100644 index 0000000..2c54972 --- /dev/null +++ b/source/client/request/Request.java @@ -0,0 +1,225 @@ +/* + * Created on May 6, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ +package itunes.client.request; + +import itunes.*; +import itunes.util.Hasher; + +import java.net.*; +import java.io.*; +import java.util.ArrayList; +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public abstract class Request { + public static final int ITUNES_PORT = 3689; + public static boolean debug = false; + protected String server; + protected int port; + public byte[] data; + protected int offset; + protected int expectedLength; + protected String dataType; + protected ArrayList fieldPairs; + protected ArrayList mlitIndexes; + protected ArrayList mlclIndexes; + protected ArrayList mdclIndexes; + protected String requestString; + + + public Request(String server, int port, String rs) throws NoServerPermissionException { + this.server = server; + this.port = port; + dataType = ""; + offset = 0; + fieldPairs = new ArrayList(); + mlitIndexes = new ArrayList(); + mlclIndexes = new ArrayList(); + mdclIndexes = new ArrayList(); + requestString = rs; + Query(); + Process(); + } + + protected void Query() throws NoServerPermissionException { + URL url =null; + try { + url = new URL("http://"+server+":"+port+"/"+requestString); + if (debug) + System.out.println("Processing Request: "+ server+":"+port+"/"+requestString); + URLConnection urlc = url.openConnection(); + String hashCode = Hasher.GenerateHash("/" + requestString,1); + urlc.addRequestProperty("Client-DAAP-Validation", hashCode); + urlc.addRequestProperty("Client-DAAP-Access-Index", "1"); + + DataInputStream in = new DataInputStream(urlc.getInputStream()); + int len = urlc.getContentLength(); + if (len == -1) { + return; + } + data = new byte[len]; + in.readFully(data); + } catch (MalformedURLException e) { + if (debug) + System.out.println("Malformed URL"); + } catch (IOException ioe) { + if (debug) + System.out.println(ioe.getLocalizedMessage()); + throw new NoServerPermissionException(); + } + } + + protected static int readSize(String data) { + return readSize(data, 4); + } + + protected static int readSize(String data, int j) { + String elength = ""; + for (int i = 0; i < j; i++) { + elength += ((int)data.charAt(i)>15?"":"0") + Integer.toHexString((int)data.charAt(i)); + } + return Integer.valueOf(elength,16).intValue(); + } + + protected String dataString(int i) { + return readString(data,offset,i); + } + + public static String readString(byte[] data, int offset, int i) { + String a = ""; + try { + a = new String(data, offset,i,"UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return a; + } + + protected int dataInt() { + return readInt(data, offset,4); + } + + protected static int readInt(byte[] data, int offset) { + int i = 0; + try { + ByteArrayInputStream b = new ByteArrayInputStream(data, offset, 4); + DataInputStream d = new DataInputStream(b); + i = d.readInt(); + } catch (IOException e) { + e.printStackTrace(); + } + return i; + } + + public static int readInt(byte[] data, int offset, int size) { + int i = 0; + try { + ByteArrayInputStream b = new ByteArrayInputStream(data, offset, size); + DataInputStream d = new DataInputStream(b); + int pow = size*2 - 1; + for (int j = 0;j<size;j++) { + int num = (0xFF&d.readByte()); + int up = ((int)Math.pow(16,pow))*(num/16); + pow--; + int down= ((int)Math.pow(16,pow))*(num%16); + i+= up + down; + pow--; + } + } catch (IOException e) { + e.printStackTrace(); + } + return i; + } + + protected void Process() throws NoServerPermissionException { + if (data==null || data.length==0) { + return; + } + dataType= dataString(4); + offset += 4; + int size = dataInt(); + offset += 4; + + fieldPairs = processDataFields(); + } + + protected ArrayList processDataFields(byte[] data, int offset) { + ArrayList fieldPairs = new ArrayList(); + while (offset < data.length) { + String name=""; + name = readString(data,offset,4); + offset +=4; + int size=readInt(data,offset); + offset+=4; + FieldPair fp = new FieldPair(name, data, offset, size); + offset += size; + fieldPairs.add(fp); + if (name.equals("mlcl")) { + mlclIndexes.add(new Integer(fieldPairs.size()-1)); + } else if (name.equals("mlit")) { + mlitIndexes.add(new Integer(fieldPairs.size()-1)); + } else if (name.equals("mdcl")) { + mdclIndexes.add(new Integer(fieldPairs.size()-1)); + } + } + return fieldPairs; + } + + protected ArrayList processDataFields() { + return processDataFields(data,offset); +// ArrayList fieldPairs = new ArrayList(); +// while (offset < data.length) { +// String name=""; +// name = dataString(4); +// offset +=4; +// int size=dataInt(); +// offset+=4; +// FieldPair fp = new FieldPair(name, data, offset, size); +// offset += size; +// fieldPairs.add(fp); +// if (name.equals("mlcl")) { +// mlclIndexes.add(new Integer(fieldPairs.size()-1)); +// } else if (name.equals("mlit")) { +// mlitIndexes.add(new Integer(fieldPairs.size()-1)); +// } else if (name.equals("mdcl")) { +// mdclIndexes.add(new Integer(fieldPairs.size()-1)); +// } +// } +// return fieldPairs; + } + + public String toString() { + String ret = ""; + for (int i = 0; i < fieldPairs.size();i++) { + FieldPair fp = (FieldPair)fieldPairs.get(i); + ret += fp.toString()+"\n"; + } + return ret; + } +} + diff --git a/source/client/request/ServerInfoRequest.java b/source/client/request/ServerInfoRequest.java new file mode 100644 index 0000000..048ed91 --- /dev/null +++ b/source/client/request/ServerInfoRequest.java @@ -0,0 +1,46 @@ +/* + * Created on May 6, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + */ +package itunes.client.request; +import itunes.FieldPair; +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class ServerInfoRequest extends Request { + + public ServerInfoRequest(String server, int port) throws NoServerPermissionException { + super(server,port, "server-info"); + } + public double getServerVersion() { + int index = fieldPairs.indexOf(new FieldPair("mpro",new byte[0],0,0)); + if (index == -1) + return index; + FieldPair fp = (FieldPair)fieldPairs.get(index); + return readInt(fp.value,0,2) + (0.01*readInt(fp.value,2,2)); + } +} diff --git a/source/client/request/SingleDatabaseRequest.java b/source/client/request/SingleDatabaseRequest.java new file mode 100644 index 0000000..2a82935 --- /dev/null +++ b/source/client/request/SingleDatabaseRequest.java @@ -0,0 +1,76 @@ +/* + * Created on May 6, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ +package itunes.client.request; +import itunes.*; +import itunes.client.*; + +import java.util.ArrayList; +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class SingleDatabaseRequest extends DatabasesRequest { + + + public SingleDatabaseRequest(String server, int port, int sessionId, int dbId) throws NoServerPermissionException { + super(server, port, "databases/"+dbId+"/items?session-id="+sessionId+"&meta=dmap.itemid,dmap.itemname,daap.songalbum,daap.songartist,daap.songtracknumber,daap.songuserrating,daap.songgenre,daap.songformat,daap.songtime"); + } + public ArrayList getSongs() { + ArrayList songs = new ArrayList(); + for (int i = 0; i < mlitDataFields.size();i++) { + ArrayList fps = ((ArrayList)mlitDataFields.get(i)); + String name=null; + int id=0; + Song s = new Song(); + for (int j = 0; j < fps.size();j++) { + FieldPair fp =((FieldPair)fps.get(j)); + if (fp.name.equals("miid")) { + s.id = Request.readInt(fp.value,0,4); + } else if (fp.name.equals("minm")) { + s.name = Request.readString(fp.value,0,fp.value.length); + } else if (fp.name.equals("asal")) { + s.album = Request.readString(fp.value,0,fp.value.length); + } else if (fp.name.equals("asar")) { + s.artist = Request.readString(fp.value,0,fp.value.length); + } else if (fp.name.equals("astn")) { + s.track = Request.readInt(fp.value, 0,2); + } else if (fp.name.equals("asgn")) { + s.genre = Request.readString(fp.value,0,fp.value.length); + } else if (fp.name.equals("asur")) { + s.rating = Request.readInt(fp.value,0,1); + } else if (fp.name.equals("asfm")) { + s.format = Request.readString(fp.value,0,fp.value.length); + } else if (fp.name.equals("astm")) { + s.time = Request.readInt(fp.value,0,4); + } + } + songs.add(s); + } + return songs; + } +} + diff --git a/source/client/request/SongRequest.java b/source/client/request/SongRequest.java new file mode 100644 index 0000000..9210280 --- /dev/null +++ b/source/client/request/SongRequest.java @@ -0,0 +1,87 @@ +/* + * Created on May 7, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments +Copyright 2003 Joseph Barnett + +This File is part of "one 2 oh my god" + +"one 2 oh my god" is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +Free Software Foundation; either version 2 of the License, or +your option) any later version. + +"one 2 oh my god" is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with "one 2 oh my god"; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ +package itunes.client.request; +import itunes.util.Hasher; + +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.InputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; + +/** + * @author jbarnett + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class SongRequest extends Request { + protected BufferedInputStream b; + + public SongRequest(String server, int port, int dbId, int songId, String songFmt, int sessionId) throws NoServerPermissionException { + super(server, port, "databases/"+dbId+"/items/"+songId+"."+songFmt+"?session-id="+sessionId); + } + + protected void Query() throws NoServerPermissionException { + URL url =null; + try { + url = new URL("http://"+server+":"+port+"/"+requestString); + if (Request.debug) + System.out.println("Processing Request: "+ server+":"+port+"/"+requestString); + URLConnection urlc = url.openConnection(); + String hashCode = Hasher.GenerateHash("/" + requestString,1); + urlc.addRequestProperty("Client-DAAP-Validation", hashCode); + urlc.addRequestProperty("Client-DAAP-Access-Index", "1"); + int len = urlc.getContentLength(); + b = new BufferedInputStream(urlc.getInputStream()); + if (len == -1) { + return; + } else if (len == 0) { + throw new NoServerPermissionException(); + } + } catch (MalformedURLException e) { + if (Request.debug) + System.out.println("Malformed URL"); + } catch (IOException ioe) { + if (Request.debug) + System.out.println(ioe.getLocalizedMessage()); + throw new NoServerPermissionException(); + } + } + + protected void Process() throws NoServerPermissionException{ + return; + // if (data.length == 0) { + // throw new NoServerPermissionException(); + // } + } + + public InputStream getStream() { + return b; + } +} + |
