    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                    Log.d(TAG,"New response");
    044                    err_call=false;
    045                    myrid=rid;
    046                    // Check for N response
    047                    try {
    048                            if(ioTransport.peek()=='N')
    049                            {
    050                                    // ERR_CALL
    051                                    ioTransport.read(); // the 'N'
    052                                    int c=ioTransport.read();
    053                                    while(c==']')
    054                                    {
    055                                            c=ioTransport.read();
    056                                    }
    057                                    if(c!='z')
    058                                    {
    059                                            Log.e(TAG,"Invalid response 'N' with unknown extra byte=0x"+ Integer.toHexString(c) +".");
    060                                            invalid=true;
    061                                            return;
    062                                    }
    063                                    else
    064                                    {
    065                                            err_call=true;
    066                                            invalid=true;
    067                                            return;
    068                                    }
    069                            }
    070                    } catch (IOException e) {
    071                            Log.e(TAG,"IOException while checking response (rid="+myrid+") validity.");
    072                            invalid=true;
    073                            return;
    074                    }
    075                    // Decode parms
    076                    try {
    077                            while(DecodeNextParm()==true) {};
    078                    } catch (IOException e) {
    079                            Log.e(TAG,"IOException while decoding response (rid="+myrid+") validity.");
    080                            invalid=true;
    081                    }
    082                    Log.d(TAG,"Response rid="+myrid+" decoded. Validity="+(!invalid)+", err_call="+err_call);
    083            }
    084
    085            public int GetRid()
    086            {
    087                    return myrid;
    088            }
    089
    090            public boolean isErrCall()
    091            {
    092                    return err_call;
    093            }
    094
    095            private boolean DecodeNextParm() throws IOException
    096            {
    097                    int kind=ioTransport.read();
    098                    while(kind==']')
    099                    {
    100                            kind=ioTransport.read();
    101                    }
    102                    if(kind=='z')
    103                    {
    104                            return false;
    105                    }
    106                    int tag=ioTransport.read();
    107                    addParm(tag, decodeOneOfKind(kind));
    108                    Log.d(TAG,"Decoded one parm of rid="+myrid+", tag="+tag+", kind='"+(char)(kind&0xff)+"'.");
    109                    return true;
    110            }
    111
    112    }