001 /**
002 * Copyright (C) 2010, Skype Limited
003 *
004 * All intellectual property rights, including but not limited to copyrights,
005 * trademarks and patents, as well as know how and trade secrets contained in,
006 * relating to, or arising from the internet telephony software of
007 * Skype Limited (including its affiliates, "Skype"), including without
008 * limitation this source code, Skype API and related material of such
009 * software proprietary to Skype and/or its licensors ("IP Rights") are and
010 * shall remain the exclusive property of Skype and/or its licensors.
011 * The recipient hereby acknowledges and agrees that any unauthorized use of
012 * the IP Rights is a violation of intellectual property laws.
013 *
014 * Skype reserves all rights and may take legal action against infringers of
015 * IP Rights.
016 *
017 * The recipient agrees not to remove, obscure, make illegible or alter any
018 * notices or indications of the IP Rights and/or Skype's rights and
019 * ownership thereof.
020 */
021
022 package com.skype.ipc;
023
024 import java.io.IOException;
025
026 import com.skype.util.Log;
027
028 public class Response extends AbstractTaggedInputMessage
029 {
030 private static final String TAG="Response";
031 private int myrid;
032 private boolean err_call;
033
034 // null response object, used for returning an error condition, like when there is no runtime conneciton
035 Response() {
036 super(null);
037 err_call = true;
038 }
039
040 public Response(Transport in,int rid) throws IOException
041 {
042 super(in);
043 err_call=false;
044 myrid=rid;
045 // Check for N response
046 try {
047 if(ioTransport.peek()=='N')
048 {
049 // ERR_CALL
050 ioTransport.read(); // the 'N'
051 int c=ioTransport.read();
052 while(c==']')
053 {
054 c=ioTransport.read();
055 }
056 if(c!='z')
057 {
058 Log.e(TAG,"Invalid response 'N' with unknown extra byte=0x"+ Integer.toHexString(c) +".");
059 invalid=true;
060 return;
061 }
062 else
063 {
064 err_call=true;
065 invalid=true;
066 return;
067 }
068 }
069 } catch (IOException e) {
070 Log.e(TAG,"IOException while checking response (rid="+myrid+") validity.");
071 invalid=true;
072 return;
073 }
074 // Decode parms
075 try {
076 while(DecodeNextParm()==true) {};
077 } catch (IOException e) {
078 Log.e(TAG,"IOException while decoding response (rid="+myrid+") validity.");
079 invalid=true;
080 }
081 }
082
083 public int GetRid()
084 {
085 return myrid;
086 }
087
088 public boolean isErrCall()
089 {
090 return err_call;
091 }
092
093 private boolean DecodeNextParm() throws IOException
094 {
095 int kind=ioTransport.read();
096 while(kind==']')
097 {
098 kind=ioTransport.read();
099 }
100 if(kind=='z')
101 {
102 return false;
103 }
104 int tag=ioTransport.read();
105 addParm(tag, decodeOneOfKind(kind));
106 return true;
107 }
108
109 }