예제 #1
0
        public static IPAddress GetBestLocalIPAddress(String host, TNET_Socket.tnet_socket_type_t type)
        {
            try
            {
#if WINDOWS_PHONE
                String      localHostNameOrAddress = (host == TNET_Socket.TNET_SOCKET_HOST_ANY) ? "localhost" : host;                      // Not use yet
                IPAddress[] ipAddresses            = new IPAddress[] { TNET_Socket.IsIPv6Type(type) ? IPAddress.IPv6Any : IPAddress.Any }; // FIXME: didn't found how to get local IP on WP7
#else
                String      localHostNameOrAddress = (host == TNET_Socket.TNET_SOCKET_HOST_ANY) ? Dns.GetHostName() : host;
                IPAddress[] ipAddresses            = Dns.GetHostAddresses(localHostNameOrAddress);
#endif
                IPAddress ipAddress = null;
                Boolean   useIPv6   = TNET_Socket.IsIPv6Type(type);
                if (ipAddresses != null && ipAddresses.Length > 0)
                {
                    ipAddress = ipAddresses[0];
                    foreach (IPAddress ia in ipAddresses)
                    {
                        if ((ia.AddressFamily == AddressFamily.InterNetwork && (IPAddress.Loopback.ToString().Equals(ia.ToString()))) ||
                            (ia.AddressFamily == AddressFamily.InterNetworkV6 && (IPAddress.IPv6Loopback.ToString().Equals(ia.ToString()))))
                        {
                            continue;
                        }
                        if ((ia.AddressFamily == AddressFamily.InterNetwork && !useIPv6) || (ia.AddressFamily == AddressFamily.InterNetworkV6 && !ia.IsIPv6LinkLocal && useIPv6))
                        {
                            ipAddress = ia;
                            break;
                        }
                    }
                }

                if (ipAddress == null)
                {
                    TSK_Debug.Error("{0} is an invalid hostname or address", localHostNameOrAddress);
                    ipAddress = TNET_Socket.IsIPv6Type(type) ? IPAddress.IPv6Any : IPAddress.Any;
                }

                return(ipAddress);
            }
            catch (Exception e)
            {
                TSK_Debug.Error("GetBestLocalIPAddress(host={0}) failed: ", host, e);
            }
            return(TNET_Socket.IsIPv6Type(type) ? IPAddress.IPv6Any : IPAddress.Any);
        }
예제 #2
0
        private Boolean OnTerminated()
        {
            TSK_Debug.Info("=== REGISTER Dialog terminated ===");

            /* Cleanup IPSec SAs */
            //if (TSIP_DIALOG_GET_STACK(self)->security.secagree_mech && tsk_striequals(TSIP_DIALOG_GET_STACK(self)->security.secagree_mech, "ipsec-3gpp"))
            //{
            //    tsip_transport_cleanupSAs(TSIP_DIALOG_GET_STACK(self)->layer_transport);
            //}

            /* alert the user */
            TSIP_EventDialog.Signal(TSIP_EventDialog.tsip_dialog_event_type_t.Terminated,
                                    base.SipSession, String.IsNullOrEmpty(base.LastErrorPhrase) ? "Dialog terminated" : base.LastErrorPhrase, base.LastErrorMessage);

            /* Remove from the dialog layer. */
            base.RemoveFromLayer();
            return(true);
        }
예제 #3
0
        internal String GetResponse(String method, String uristring, byte[] entity_body)
        {
            String response = String.Empty;

            if (IsDigest)
            {
                String ha1 = null, ha2;
                String nc = String.Empty;

                /* ===
                 *              Calculate HA1 = MD5(A1) = M5(username:realm:secret)
                 *              In case of AKAv1-MD5 and AKAv2-MD5 the secret must be computed as per RFC 3310 + 3GPP TS 206/7/8/9.
                 *              The resulting AKA RES parameter is treated as a "password"/"secret" when calculating the response directive of RFC 2617.
                 */
                if (IsAKAv1 || IsAKAv2)
                {
                    TSK_Debug.Error("AKAv1 and AKAv2 are not supported yet");
                    return(null);
                }
                else
                {
                    ha1 = THTTP_Auth.GetDigestHA1(ChallengeUserName, mRealm, ChallengePassword);
                }

                /* ===
                 *              HA2
                 */
                ha2 = THTTP_Auth.GetDigestHA2(method, uristring, entity_body, mQop);

                /* RESPONSE */
                if (mNc > 0)
                {
                    nc = THTTP_Auth.GetNonceString(mNc).ToString();
                }
                response = THTTP_Auth.GetDigestResponse(ha1, mNonce, mNc, mCnonce, mQop, ha2);

                if (!String.IsNullOrEmpty(mQop))
                {
                    ++mNc;
                }
            }

            return(response);
        }
예제 #4
0
        internal const Int64 SHUTDOWN_TIMEOUT = 2000; /* miliseconds. */

        internal TSIP_Dialog(tsip_dialog_type_t type, String callId, TSip_Session session)
        {
            mId           = sUniqueId++;
            mRecordRoutes = new List <TSIP_HeaderRecordRoute>();
            mChallenges   = new List <TSIP_Challenge>();

            mPaths          = new List <TSIP_Uri>();
            mServiceRoutes  = new List <TSIP_Uri>();
            mAssociatedUris = new List <TSIP_Uri>();

            mState = tsip_dialog_state_t.Initial;
            mType  = type;

            mCallId     = String.IsNullOrEmpty(callId) ? TSIP_HeaderCallId.RandomCallId() : callId;
            mSipSession = session;

            /* Sets some default values */
            mExpires   = TSip_Session.DEFAULT_EXPIRES;
            mTagLocal  = TSK_String.Random();
            mCSeqValue = (UInt32) new Random().Next();

            /*=== SIP Session ===*/
            if (mSipSession != null)
            {
                mExpires  = mSipSession.Expires;
                mUriLocal = !String.IsNullOrEmpty(callId) /* Server Side */ ? mSipSession.UriTo : mSipSession.UriFrom;
                if (mSipSession.UriTo != null)
                {
                    mUriRemote       = mSipSession.UriTo;
                    mUriRemoteTarget = mSipSession.UriTo;
                }
                else
                {
                    mUriRemote       = mSipSession.UriFrom;
                    mUriRemoteTarget = mSipSession.Stack.Realm;
                }
            }
            else
            {
                TSK_Debug.Error("Invalid Sip Session");
            }
        }
        private void TSIP_Transport_NetworkEvent(object sender, TNET_Transport.TransportEventArgs e)
        {
            if (e.Type != Doubango.tinyNET.TNET_Transport.TransportEventArgs.TransportEventTypes.Data)
            {
                return;
            }

            /* === SigComp === */

            TSIP_Message message = TSIP_ParserMessage.Parse(e.Data, true);

            if (message != null && message.FirstVia != null && message.CSeq != null && message.From != null && message.To != null)
            {
                this.HandleIncomingMessage(message);
            }
            else
            {
                TSK_Debug.Error("Failed to parse message from network");
            }
        }
예제 #6
0
        internal static void TestUriParser()
        {
            int i;

            for (i = 0; i < __Uris.Length; i++)
            {
                TSIP_Uri uri = TSIP_ParserUri.Parse(__Uris[i]);

                TSK_Debug.Info("\n== Parsing {{ {0} }} ==\n", __Uris[i]);

                if (uri != null)
                {
                    TSK_Debug.Info("scheme: {0}", uri.Scheme);
                    TSK_Debug.Info("user-name: {0}", uri.UserName);
                    TSK_Debug.Info("password: {0}", uri.Password);
                    TSK_Debug.Info("host: {0}", uri.Host);
                    TSK_Debug.Info("port: {0}", uri.Port);
                    TSK_Debug.Info("host-type: {0}", uri.HostType == tsip_host_type_t.IPv4 ? "IPv4" : (uri.HostType == tsip_host_type_t.IPv6 ? "IPv6" : (uri.HostType == tsip_host_type_t.Hostname ? "HOSTNAME" : "UNKNOWN")));

                    TSK_Debug.Info("---PARAMS---");

                    /* dump all parameters */
                    foreach (TSK_Param param in uri.Params)
                    {
                        TSK_Debug.Info("-->{0}={1}", param.Name, param.Value);
                    }

                    TSK_Debug.Info("Is-secure: {0}", uri.IsSecure ? "YES" : "NO");

                    TestToString(uri);

                    uri.Dispose();
                }
                else
                {
                    TSK_Debug.Error("INVALID SIP URI");
                }

                TSK_Debug.Info("\n\n");
            }
        }
        /// <summary>
        /// InProgress -> (423) -> InProgress
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean InProgress_2_InProgress_X_423(params Object[] parameters)
        {
            TSIP_Response response = parameters[1] as TSIP_Response;

            /* FIXME
             *  RFC 3261 - 10.2.8 Error Responses
             *
             *  If a UA receives a 423 (Interval Too Brief) response, it MAY retry
             *  the registration after making the expiration interval of all contact
             *  addresses in the REGISTER request equal to or greater than the
             *  expiration interval within the Min-Expires header field of the 423
             *  (Interval Too Brief) response.
             */
            //hdr = (tsip_header_Min_Expires_t*)tsip_message_get_header(message, tsip_htype_Min_Expires);
            //if (hdr)
            //{
            //    TSIP_DIALOG(self)->expires = TSK_TIME_S_2_MS(hdr->value);

            //    if (tsk_striequals(TSIP_DIALOG_GET_STACK(self)->security.secagree_mech, "ipsec-3gpp"))
            //    {
            //        tsip_transport_cleanupSAs(TSIP_DIALOG_GET_STACK(self)->layer_transport);
            //        ret = tsip_dialog_register_send_REGISTER(self, tsk_true);
            //    }
            //    else
            //    {
            //        ret = tsip_dialog_register_send_REGISTER(self, tsk_false);
            //    }
            //}
            //else
            //{
            //    ret = -1;
            //}


            TSK_Debug.Error("Not implemented");
            return(false);
        }
예제 #8
0
        public Int32 SendTo(EndPoint remoteEP, byte[] buffer)
        {
            try
            {
//#if WINDOWS_PHONE
                Int32 ret;
                mSocketEvent.Reset();
                mSendSocketEventArgs.SetBuffer(buffer, 0, buffer.Length);
                mSendSocketEventArgs.RemoteEndPoint = remoteEP;
                ret = mSocket.SendToAsync(mSendSocketEventArgs) ? buffer.Length : -1;
                mSocketEvent.WaitOne(TIMEOUT_MILLISECONDS);

                return(ret);
//#else

//               return mSocket.SendTo(buffer, remoteEP);
//#endif
            }
            catch (Exception e)
            {
                TSK_Debug.Error("SendTo() failed: {0}", e);
            }
            return(-1);
        }
예제 #9
0
        public Boolean Start()
        {
            Boolean ok = false;

            if (mRunning)
            {
                TSK_Debug.Warn("Stack already running");
                ok = true;
                goto bail;
            }

            /* === Transport Layer === */
            /* Adds the default transport to the transport Layer */
            if (!mLayerTransport.AddTransport(mLocalIP, mLocalPort, mProxyType, "SIP Transport"))
            {
                TSK_Debug.Error("Failed to add new transport");
                goto bail;
            }
            /* Starts the transport Layer */
            if (!mLayerTransport.Start())
            {
                TSK_Debug.Error("Failed to start SIP transport layer");
                goto bail;
            }
            // FIXME: Update local IP

            ok       = true;
            mRunning = true;
            TSIP_EventStack.Signal(TSIP_EventStack.tsip_stack_event_type_t.Started, "Stack started");
bail:
            if (!ok)
            {
                mLayerTransport.Stop();
            }
            return(ok);
        }
예제 #10
0
 /// <summary>
 /// Completed -> (300-699) -> Completed
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Completed_2_Completed_X_300_to_699(params Object[] parameters)
 {
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #11
0
 /// <summary>
 /// Proceeding -> (1xx) -> Proceeding
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Proceeding_2_Proceeding_X_1xx(params Object[] parameters)
 {
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #12
0
 /// <summary>
 /// Calling -> (timerB) -> Terminated
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Calling_2_Terminated_X_timerB(params Object[] parameters)
 {
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #13
0
        //--------------------------------------------------------
        //				== STATE MACHINE BEGIN ==
        //--------------------------------------------------------

        /// <summary>
        /// Started -> (send) -> Calling
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean Started_2_Calling_X_send(params Object[] parameters)
        {
            TSK_Debug.Error("Not implemented");
            return(false);
        }
예제 #14
0
        private Boolean UpdateChallenges(TSIP_Response response, Boolean acceptNewVector)
        {
            Boolean ret = true;
            TSIP_HeaderWWWAuthenticate WWW_Authenticate;

            // TSIP_HeaderProxyAuthenticate Proxy_Authenticate;

            /* RFC 2617 - HTTP Digest Session
             *
             *	(A) The client response to a WWW-Authenticate challenge for a protection
             *          space starts an authentication session with that protection space.
             *          The authentication session lasts until the client receives another
             *          WWW-Authenticate challenge from any server in the protection space.
             *
             *          (B) The server may return a 401 response with a new nonce value, causing the client
             *          to retry the request; by specifying stale=TRUE with this response,
             *          the server tells the client to retry with the new nonce, but without
             *          prompting for a new username and password.
             */
            /* RFC 2617 - 1.2 Access Authentication Framework
             *  The realm directive (case-insensitive) is required for all authentication schemes that issue a challenge.
             */

            /* FIXME: As we perform the same task ==> Use only one loop.
             */

            for (int i = 0; (WWW_Authenticate = (TSIP_HeaderWWWAuthenticate)response.GetHeaderAtIndex(TSIP_Header.tsip_header_type_t.WWW_Authenticate, i)) != null; i++)
            {
                Boolean isnew = true;

                foreach (TSIP_Challenge challenge in mChallenges)
                {
                    //if(challenge.IProxy)
                    //{
                    //    continue;
                    //}

                    if (String.Equals(challenge.Realm, WWW_Authenticate.Realm, StringComparison.InvariantCultureIgnoreCase) && (WWW_Authenticate.Stale || acceptNewVector))
                    {
                        /*== (B) ==*/
                        if (!(ret = challenge.Update(WWW_Authenticate.Scheme,
                                                     WWW_Authenticate.Realm,
                                                     WWW_Authenticate.Nonce,
                                                     WWW_Authenticate.Opaque,
                                                     WWW_Authenticate.Algorithm,
                                                     WWW_Authenticate.Qop)))
                        {
                            return(ret);
                        }
                        else
                        {
                            isnew = false;
                            continue;
                        }
                    }
                    else
                    {
                        TSK_Debug.Error("Failed to handle new challenge");
                        return(false);
                    }
                }

                if (isnew)
                {
                    TSIP_Challenge challenge;
                    if ((challenge = new TSIP_Challenge(this.Stack,
                                                        false,
                                                        WWW_Authenticate.Scheme,
                                                        WWW_Authenticate.Realm,
                                                        WWW_Authenticate.Nonce,
                                                        WWW_Authenticate.Opaque,
                                                        WWW_Authenticate.Algorithm,
                                                        WWW_Authenticate.Qop)) != null)
                    {
                        mChallenges.Add(challenge);
                    }
                    else
                    {
                        TSK_Debug.Error("Failed to handle new challenge");
                        return(false);
                    }
                }
            }

            return(ret);
        }
예제 #15
0
/* #line 124 "./ragel/tsip_parser_uri.rl" */

    public static TSIP_Uri Parse(String data)
    {
        if (String.IsNullOrEmpty(data))
        {
            return(null);
        }

        int cs  = 0;
        int p   = 0;
        int pe  = data.Length;
        int eof = pe;

        int ts = 0, te = 0;
        int act = 0;

        TSIP_Uri uri = TSIP_Uri.Create(tsip_uri_type_t.Unknown);

        int tag_start = 0;


/* #line 395 "../Parsers/TSIP_ParserUri.cs" */
        {
            cs  = tsip_machine_parser_uri_start;
            ts  = -1;
            te  = -1;
            act = 0;
        }

/* #line 145 "./ragel/tsip_parser_uri.rl" */

/* #line 405 "../Parsers/TSIP_ParserUri.cs" */
        {
            sbyte _klen;
            short _trans;
            sbyte _acts;
            sbyte _nacts;
            short _keys;

            if (p == pe)
            {
                goto _test_eof;
            }
            if (cs == 0)
            {
                goto _out;
            }
_resume:
            _acts  = _tsip_machine_parser_uri_from_state_actions[cs];
            _nacts = _tsip_machine_parser_uri_actions[_acts++];
            while (_nacts-- > 0)
            {
                switch (_tsip_machine_parser_uri_actions[_acts++])
                {
                case 12:
/* #line 1 "./ragel/tsip_parser_uri.rl" */
                { ts = p; }
                break;

/* #line 426 "../Parsers/TSIP_ParserUri.cs" */
                default: break;
                }
            }

            _keys  = _tsip_machine_parser_uri_key_offsets[cs];
            _trans = (short)_tsip_machine_parser_uri_index_offsets[cs];

            _klen = _tsip_machine_parser_uri_single_lengths[cs];
            if (_klen > 0)
            {
                short _lower = _keys;
                short _mid;
                short _upper = (short)(_keys + _klen - 1);
                while (true)
                {
                    if (_upper < _lower)
                    {
                        break;
                    }

                    _mid = (short)(_lower + ((_upper - _lower) >> 1));
                    if (data[p] < _tsip_machine_parser_uri_trans_keys[_mid])
                    {
                        _upper = (short)(_mid - 1);
                    }
                    else if (data[p] > _tsip_machine_parser_uri_trans_keys[_mid])
                    {
                        _lower = (short)(_mid + 1);
                    }
                    else
                    {
                        _trans += (short)(_mid - _keys);
                        goto _match;
                    }
                }
                _keys  += (short)_klen;
                _trans += (short)_klen;
            }

            _klen = _tsip_machine_parser_uri_range_lengths[cs];
            if (_klen > 0)
            {
                short _lower = _keys;
                short _mid;
                short _upper = (short)(_keys + (_klen << 1) - 2);
                while (true)
                {
                    if (_upper < _lower)
                    {
                        break;
                    }

                    _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1));
                    if (data[p] < _tsip_machine_parser_uri_trans_keys[_mid])
                    {
                        _upper = (short)(_mid - 2);
                    }
                    else if (data[p] > _tsip_machine_parser_uri_trans_keys[_mid + 1])
                    {
                        _lower = (short)(_mid + 2);
                    }
                    else
                    {
                        _trans += (short)((_mid - _keys) >> 1);
                        goto _match;
                    }
                }
                _trans += (short)_klen;
            }

_match:
            _trans = (short)_tsip_machine_parser_uri_indicies[_trans];
_eof_trans:
            cs = _tsip_machine_parser_uri_trans_targs[_trans];

            if (_tsip_machine_parser_uri_trans_actions[_trans] == 0)
            {
                goto _again;
            }

            _acts  = _tsip_machine_parser_uri_trans_actions[_trans];
            _nacts = _tsip_machine_parser_uri_actions[_acts++];
            while (_nacts-- > 0)
            {
                switch (_tsip_machine_parser_uri_actions[_acts++])
                {
                case 0:
/* #line 36 "./ragel/tsip_parser_uri.rl" */
                {
                    tag_start = p;
                }
                break;

                case 1:
/* #line 41 "./ragel/tsip_parser_uri.rl" */
                { uri.Scheme = "sip"; uri.Type = tsip_uri_type_t.Sip; }
                break;

                case 2:
/* #line 42 "./ragel/tsip_parser_uri.rl" */
                { uri.Scheme = "sips"; uri.Type = tsip_uri_type_t.Sips; }
                break;

                case 3:
/* #line 43 "./ragel/tsip_parser_uri.rl" */
                { uri.Scheme = "tel"; uri.Type = tsip_uri_type_t.Tel; }
                break;

                case 4:
/* #line 46 "./ragel/tsip_parser_uri.rl" */
                { uri.HostType = tsip_host_type_t.IPv4; }
                break;

                case 5:
/* #line 47 "./ragel/tsip_parser_uri.rl" */
                { uri.HostType = tsip_host_type_t.IPv6; }
                break;

                case 6:
/* #line 48 "./ragel/tsip_parser_uri.rl" */
                { uri.HostType = tsip_host_type_t.Hostname; }
                break;

                case 7:
/* #line 54 "./ragel/tsip_parser_uri.rl" */
                {
                    uri.UserName = TSK_RagelState.Parser.GetString(data, p, tag_start);
                }
                break;

                case 8:
/* #line 58 "./ragel/tsip_parser_uri.rl" */
                {
                    uri.Password = TSK_RagelState.Parser.GetString(data, p, tag_start);
                }
                break;

                case 9:
/* #line 70 "./ragel/tsip_parser_uri.rl" */
                {
                    TSK_Param param = TSK_RagelState.Parser.GetParam(data, p, tag_start);
                    if (param != null)
                    {
                        uri.Params.Add(param);
                    }
                }
                break;

                case 10:
/* #line 84 "./ragel/tsip_parser_uri.rl" */
                { { cs = 26; if (true)
                    {
                        goto _again;
                    }
                  } }
                  break;

                case 13:
/* #line 1 "./ragel/tsip_parser_uri.rl" */
                { te = p + 1; }
                break;

                case 14:
/* #line 97 "./ragel/tsip_parser_uri.rl" */
                { te = p + 1; {
                      uri.Host = TSK_RagelState.Scanner.GetString(data, ts, te);
                      if (uri.HostType == tsip_host_type_t.IPv6)
                      {
                          uri.Host = TSK_String.UnQuote(uri.Host, '[', ']');
                      }
                  } }
                  break;

                case 15:
/* #line 88 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {
                      if (TSK_String.Contains(data.Substring(te), (pe - te), "@"))
                      {
                          { cs = 18; if (true)
                    {
                        goto _again;
                    }
                          }
                      }
                  } }
                  break;

                case 16:
/* #line 94 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; { } }
                break;

                case 17:
/* #line 97 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {
                      uri.Host = TSK_RagelState.Scanner.GetString(data, ts, te);
                      if (uri.HostType == tsip_host_type_t.IPv6)
                      {
                          uri.Host = TSK_String.UnQuote(uri.Host, '[', ']');
                      }
                  } }
                  break;

                case 18:
/* #line 105 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {
                      ts++;
                      uri.Port = (ushort)TSK_RagelState.Scanner.GetInt32(data, ts, te);
                  } }
                  break;

                case 19:
/* #line 110 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {  } }
                break;

                case 20:
/* #line 111 "./ragel/tsip_parser_uri.rl" */
                { te = p; p--; {  } }
                break;

                case 21:
/* #line 94 "./ragel/tsip_parser_uri.rl" */
                { { p = ((te)) - 1; } { } }
                break;

                case 22:
/* #line 97 "./ragel/tsip_parser_uri.rl" */
                { { p = ((te)) - 1; } {
                      uri.Host = TSK_RagelState.Scanner.GetString(data, ts, te);
                      if (uri.HostType == tsip_host_type_t.IPv6)
                      {
                          uri.Host = TSK_String.UnQuote(uri.Host, '[', ']');
                      }
                  } }
                  break;

                case 23:
/* #line 110 "./ragel/tsip_parser_uri.rl" */
                { { p = ((te)) - 1; } {  } }
                break;

/* #line 615 "../Parsers/TSIP_ParserUri.cs" */
                default: break;
                }
            }

_again:
            _acts  = _tsip_machine_parser_uri_to_state_actions[cs];
            _nacts = _tsip_machine_parser_uri_actions[_acts++];
            while (_nacts-- > 0)
            {
                switch (_tsip_machine_parser_uri_actions[_acts++])
                {
                case 11:
/* #line 1 "./ragel/tsip_parser_uri.rl" */
                { ts = -1; }
                break;

/* #line 629 "../Parsers/TSIP_ParserUri.cs" */
                default: break;
                }
            }

            if (cs == 0)
            {
                goto _out;
            }
            if (++p != pe)
            {
                goto _resume;
            }
            _test_eof : {}
            if (p == eof)
            {
                if (_tsip_machine_parser_uri_eof_trans[cs] > 0)
                {
                    _trans = (short)(_tsip_machine_parser_uri_eof_trans[cs] - 1);
                    goto _eof_trans;
                }
            }

            _out : {}
        }

/* #line 146 "./ragel/tsip_parser_uri.rl" */

        if (cs <
/* #line 653 "../Parsers/TSIP_ParserUri.cs" */
            26
/* #line 147 "./ragel/tsip_parser_uri.rl" */
            )
        {
            TSK_Debug.Error("Failed to parse SIP/SIPS/TEL URI");
            uri.Dispose();
            return(null);
        }

        return(uri);
    }
예제 #16
0
/* #line 95 "./ragel/tsip_parser_header_Call_ID.rl" */

        public static TSIP_HeaderCallId Parse(String data)
        {
            int cs  = 0;
            int p   = 0;
            int pe  = data.Length;
            int eof = pe;
            TSIP_HeaderCallId hdr_call_id = new TSIP_HeaderCallId();

            int tag_start = 0;



/* #line 171 "../Headers/TSIP_HeaderCallId.cs" */
            {
                cs = tsip_machine_parser_header_Call_ID_start;
            }

/* #line 108 "./ragel/tsip_parser_header_Call_ID.rl" */

/* #line 178 "../Headers/TSIP_HeaderCallId.cs" */
            {
                sbyte _klen;
                sbyte _trans;
                sbyte _acts;
                sbyte _nacts;
                sbyte _keys;

                if (p == pe)
                {
                    goto _test_eof;
                }
                if (cs == 0)
                {
                    goto _out;
                }
_resume:
                _keys  = _tsip_machine_parser_header_Call_ID_key_offsets[cs];
                _trans = (sbyte)_tsip_machine_parser_header_Call_ID_index_offsets[cs];

                _klen = _tsip_machine_parser_header_Call_ID_single_lengths[cs];
                if (_klen > 0)
                {
                    sbyte _lower = _keys;
                    sbyte _mid;
                    sbyte _upper = (sbyte)(_keys + _klen - 1);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (sbyte)(_lower + ((_upper - _lower) >> 1));
                        if (data[p] < _tsip_machine_parser_header_Call_ID_trans_keys[_mid])
                        {
                            _upper = (sbyte)(_mid - 1);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Call_ID_trans_keys[_mid])
                        {
                            _lower = (sbyte)(_mid + 1);
                        }
                        else
                        {
                            _trans += (sbyte)(_mid - _keys);
                            goto _match;
                        }
                    }
                    _keys  += (sbyte)_klen;
                    _trans += (sbyte)_klen;
                }

                _klen = _tsip_machine_parser_header_Call_ID_range_lengths[cs];
                if (_klen > 0)
                {
                    sbyte _lower = _keys;
                    sbyte _mid;
                    sbyte _upper = (sbyte)(_keys + (_klen << 1) - 2);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (sbyte)(_lower + (((_upper - _lower) >> 1) & ~1));
                        if (data[p] < _tsip_machine_parser_header_Call_ID_trans_keys[_mid])
                        {
                            _upper = (sbyte)(_mid - 2);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Call_ID_trans_keys[_mid + 1])
                        {
                            _lower = (sbyte)(_mid + 2);
                        }
                        else
                        {
                            _trans += (sbyte)((_mid - _keys) >> 1);
                            goto _match;
                        }
                    }
                    _trans += (sbyte)_klen;
                }

_match:
                _trans = (sbyte)_tsip_machine_parser_header_Call_ID_indicies[_trans];
                cs     = _tsip_machine_parser_header_Call_ID_trans_targs[_trans];

                if (_tsip_machine_parser_header_Call_ID_trans_actions[_trans] == 0)
                {
                    goto _again;
                }

                _acts  = _tsip_machine_parser_header_Call_ID_trans_actions[_trans];
                _nacts = _tsip_machine_parser_header_Call_ID_actions[_acts++];
                while (_nacts-- > 0)
                {
                    switch (_tsip_machine_parser_header_Call_ID_actions[_acts++])
                    {
                    case 0:
/* #line 31 "./ragel/tsip_parser_header_Call_ID.rl" */
                    {
                        tag_start = p;
                    }
                    break;

                    case 1:
/* #line 35 "./ragel/tsip_parser_header_Call_ID.rl" */
                    {
                        hdr_call_id.Id = TSK_RagelState.Parser.GetString(data, p, tag_start);
                    }
                    break;

                    case 2:
/* #line 39 "./ragel/tsip_parser_header_Call_ID.rl" */
                    {
                    }
                    break;

/* #line 269 "../Headers/TSIP_HeaderCallId.cs" */
                    default: break;
                    }
                }

_again:
                if (cs == 0)
                {
                    goto _out;
                }
                if (++p != pe)
                {
                    goto _resume;
                }
                _test_eof : {}
                _out      : {}
            }

/* #line 109 "./ragel/tsip_parser_header_Call_ID.rl" */

            if (cs <
/* #line 286 "../Headers/TSIP_HeaderCallId.cs" */
                17
/* #line 110 "./ragel/tsip_parser_header_Call_ID.rl" */
                )
            {
                TSK_Debug.Error("Failed to parse SIP 'Call-ID' header.");
                hdr_call_id.Dispose();
                hdr_call_id = null;
            }

            return(hdr_call_id);
        }
예제 #17
0
 /// <summary>
 /// Any -> (cancel) -> Terminated
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Any_2_Terminated_X_cancel(params Object[] parameters)
 {/* doubango-specific */
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #18
0
 /// <summary>
 /// Completed --> (recv ACK) --> Confirmed
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Completed_2_Confirmed_ACK(params Object[] parameters)
 {
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #19
0
/* #line 137 "./ragel/tsip_parser_header_Route.rl" */

        public static List <TSIP_HeaderRoute> Parse(String data)
        {
            int cs  = 0;
            int p   = 0;
            int pe  = data.Length;
            int eof = pe;
            List <TSIP_HeaderRoute> hdr_routes = new List <TSIP_HeaderRoute>();
            TSIP_HeaderRoute        curr_route = null;

            int tag_start = 0;



/* #line 324 "../Headers/TSIP_HeaderRoute.cs" */
            {
                cs = tsip_machine_parser_header_Route_start;
            }

/* #line 151 "./ragel/tsip_parser_header_Route.rl" */

/* #line 331 "../Headers/TSIP_HeaderRoute.cs" */
            {
                sbyte _klen;
                short _trans;
                sbyte _acts;
                sbyte _nacts;
                short _keys;

                if (p == pe)
                {
                    goto _test_eof;
                }
                if (cs == 0)
                {
                    goto _out;
                }
_resume:
                _keys  = _tsip_machine_parser_header_Route_key_offsets[cs];
                _trans = (short)_tsip_machine_parser_header_Route_index_offsets[cs];

                _klen = _tsip_machine_parser_header_Route_single_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + _klen - 1);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + ((_upper - _lower) >> 1));
                        if (data[p] < _tsip_machine_parser_header_Route_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 1);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Route_trans_keys[_mid])
                        {
                            _lower = (short)(_mid + 1);
                        }
                        else
                        {
                            _trans += (short)(_mid - _keys);
                            goto _match;
                        }
                    }
                    _keys  += (short)_klen;
                    _trans += (short)_klen;
                }

                _klen = _tsip_machine_parser_header_Route_range_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + (_klen << 1) - 2);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1));
                        if (data[p] < _tsip_machine_parser_header_Route_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 2);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Route_trans_keys[_mid + 1])
                        {
                            _lower = (short)(_mid + 2);
                        }
                        else
                        {
                            _trans += (short)((_mid - _keys) >> 1);
                            goto _match;
                        }
                    }
                    _trans += (short)_klen;
                }

_match:
                _trans = (short)_tsip_machine_parser_header_Route_indicies[_trans];
                cs     = _tsip_machine_parser_header_Route_trans_targs[_trans];

                if (_tsip_machine_parser_header_Route_trans_actions[_trans] == 0)
                {
                    goto _again;
                }

                _acts  = _tsip_machine_parser_header_Route_trans_actions[_trans];
                _nacts = _tsip_machine_parser_header_Route_actions[_acts++];
                while (_nacts-- > 0)
                {
                    switch (_tsip_machine_parser_header_Route_actions[_acts++])
                    {
                    case 0:
/* #line 31 "./ragel/tsip_parser_header_Route.rl" */
                    {
                        tag_start = p;
                    }
                    break;

                    case 1:
/* #line 35 "./ragel/tsip_parser_header_Route.rl" */
                    {
                        if (curr_route == null)
                        {
                            curr_route = new TSIP_HeaderRoute();
                        }
                    }
                    break;

                    case 2:
/* #line 41 "./ragel/tsip_parser_header_Route.rl" */
                    {
                        if (curr_route != null)
                        {
                            curr_route.DisplayName = TSK_RagelState.Parser.GetString(data, p, tag_start);
                            curr_route.DisplayName = TSK_String.UnQuote(curr_route.DisplayName);
                        }
                    }
                    break;

                    case 3:
/* #line 48 "./ragel/tsip_parser_header_Route.rl" */
                    {
                        if (curr_route != null && curr_route.Uri == null)
                        {
                            int len = (int)(p - tag_start);
                            if ((curr_route.Uri = TSIP_ParserUri.Parse(data.Substring(tag_start, len))) != null && !String.IsNullOrEmpty(curr_route.DisplayName))
                            {
                                curr_route.Uri.DisplayName = curr_route.DisplayName;
                            }
                        }
                    }
                    break;

                    case 4:
/* #line 58 "./ragel/tsip_parser_header_Route.rl" */
                    {
                        if (curr_route != null)
                        {
                            curr_route.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, curr_route.Params);
                        }
                    }
                    break;

                    case 5:
/* #line 64 "./ragel/tsip_parser_header_Route.rl" */
                    {
                        if (curr_route != null)
                        {
                            hdr_routes.Add(curr_route);
                            curr_route = null;
                        }
                    }
                    break;

                    case 6:
/* #line 71 "./ragel/tsip_parser_header_Route.rl" */
                    {
                    }
                    break;

/* #line 462 "../Headers/TSIP_HeaderRoute.cs" */
                    default: break;
                    }
                }

_again:
                if (cs == 0)
                {
                    goto _out;
                }
                if (++p != pe)
                {
                    goto _resume;
                }
                _test_eof : {}
                _out      : {}
            }

/* #line 152 "./ragel/tsip_parser_header_Route.rl" */

            if (cs <
/* #line 479 "../Headers/TSIP_HeaderRoute.cs" */
                92
/* #line 153 "./ragel/tsip_parser_header_Route.rl" */
                )
            {
                TSK_Debug.Error("Failed to parse SIP 'Route' header.");
                hdr_routes.Clear();
                hdr_routes = null;
                curr_route.Dispose();
                curr_route = null;
            }

            return(hdr_routes);
        }
예제 #20
0
/* #line 139 "./ragel/tsip_parser_header_Allow_Events.rl" */

        public static TSIP_HeaderAllowEvents Parse(String data)
        {
            int cs  = 0;
            int p   = 0;
            int pe  = data.Length;
            int eof = pe;
            TSIP_HeaderAllowEvents Allow_Events = new TSIP_HeaderAllowEvents();

            int tag_start = 0;



/* #line 216 "../Headers/TSIP_HeaderAllowEvents.cs" */
            {
                cs = tsip_machine_parser_header_Allow_events_start;
            }

/* #line 152 "./ragel/tsip_parser_header_Allow_Events.rl" */

/* #line 223 "../Headers/TSIP_HeaderAllowEvents.cs" */
            {
                sbyte _klen;
                byte  _trans;
                sbyte _acts;
                sbyte _nacts;
                sbyte _keys;

                if (p == pe)
                {
                    goto _test_eof;
                }
                if (cs == 0)
                {
                    goto _out;
                }
_resume:
                _keys  = _tsip_machine_parser_header_Allow_events_key_offsets[cs];
                _trans = (byte)_tsip_machine_parser_header_Allow_events_index_offsets[cs];

                _klen = _tsip_machine_parser_header_Allow_events_single_lengths[cs];
                if (_klen > 0)
                {
                    sbyte _lower = _keys;
                    sbyte _mid;
                    sbyte _upper = (sbyte)(_keys + _klen - 1);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (sbyte)(_lower + ((_upper - _lower) >> 1));
                        if (data[p] < _tsip_machine_parser_header_Allow_events_trans_keys[_mid])
                        {
                            _upper = (sbyte)(_mid - 1);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Allow_events_trans_keys[_mid])
                        {
                            _lower = (sbyte)(_mid + 1);
                        }
                        else
                        {
                            _trans += (byte)(_mid - _keys);
                            goto _match;
                        }
                    }
                    _keys  += (sbyte)_klen;
                    _trans += (byte)_klen;
                }

                _klen = _tsip_machine_parser_header_Allow_events_range_lengths[cs];
                if (_klen > 0)
                {
                    sbyte _lower = _keys;
                    sbyte _mid;
                    sbyte _upper = (sbyte)(_keys + (_klen << 1) - 2);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (sbyte)(_lower + (((_upper - _lower) >> 1) & ~1));
                        if (data[p] < _tsip_machine_parser_header_Allow_events_trans_keys[_mid])
                        {
                            _upper = (sbyte)(_mid - 2);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Allow_events_trans_keys[_mid + 1])
                        {
                            _lower = (sbyte)(_mid + 2);
                        }
                        else
                        {
                            _trans += (byte)((_mid - _keys) >> 1);
                            goto _match;
                        }
                    }
                    _trans += (byte)_klen;
                }

_match:
                _trans = (byte)_tsip_machine_parser_header_Allow_events_indicies[_trans];
                cs     = _tsip_machine_parser_header_Allow_events_trans_targs[_trans];

                if (_tsip_machine_parser_header_Allow_events_trans_actions[_trans] == 0)
                {
                    goto _again;
                }

                _acts  = _tsip_machine_parser_header_Allow_events_trans_actions[_trans];
                _nacts = _tsip_machine_parser_header_Allow_events_actions[_acts++];
                while (_nacts-- > 0)
                {
                    switch (_tsip_machine_parser_header_Allow_events_actions[_acts++])
                    {
                    case 0:
/* #line 33 "./ragel/tsip_parser_header_Allow_Events.rl" */
                    {
                        tag_start = p;
                    }
                    break;

                    case 1:
/* #line 37 "./ragel/tsip_parser_header_Allow_Events.rl" */
                    {
                        String @event = TSK_RagelState.Parser.GetString(data, p, tag_start);
                        if (!String.IsNullOrEmpty(@event))
                        {
                            Allow_Events.Events.Add(@event);
                        }
                    }
                    break;

                    case 2:
/* #line 45 "./ragel/tsip_parser_header_Allow_Events.rl" */
                    {
                    }
                    break;

/* #line 318 "../Headers/TSIP_HeaderAllowEvents.cs" */
                    default: break;
                    }
                }

_again:
                if (cs == 0)
                {
                    goto _out;
                }
                if (++p != pe)
                {
                    goto _resume;
                }
                _test_eof : {}
                _out      : {}
            }

/* #line 153 "./ragel/tsip_parser_header_Allow_Events.rl" */

            if (cs <
/* #line 335 "../Headers/TSIP_HeaderAllowEvents.cs" */
                25
/* #line 154 "./ragel/tsip_parser_header_Allow_Events.rl" */
                )
            {
                TSK_Debug.Error("Failed to parse SIP 'Allow' header.");
                Allow_Events.Dispose();
                Allow_Events = null;
            }

            return(Allow_Events);
        }
예제 #21
0
 static Boolean test_fsm_onterminated()
 {
     TSK_Debug.Info("FSM in terminal state.");
     return(true);
 }
예제 #22
0
        //--------------------------------------------------------
        //				== STATE MACHINE BEGIN ==
        //--------------------------------------------------------

        /// <summary>
        /// Started --> (INCOMING REQUEST) --> Trying
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean Started_2_Trying_X_request(params Object[] parameters)
        {
            TSK_Debug.Error("Not implemented");
            return(false);
        }
예제 #23
0
 /// <summary>
 /// Accepted -> (2xx) -> Accepted
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Accepted_2_Accepted_X_2xx(params Object[] parameters)
 {
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #24
0
 /// <summary>
 /// Confirmed --> (timerI) --> Terminated
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Confirmed_2_Terminated_timerI(params Object[] parameters)
 {
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #25
0
 /// <summary>
 /// Any -> (Error) -> Terminated
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Any_2_Terminated_X_Error(params Object[] parameters)
 {
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #26
0
 internal static void TestToString(TSIP_Uri uri)
 {
     TSK_Debug.Info("uri_to_string={0}", uri);
 }
예제 #27
0
 /// <summary>
 /// Accepted --> (Recv ACK) --> Accepted
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private Boolean Accepted_2_Accepted_iACK(params Object[] parameters)
 {/* doubango-specific */
     TSK_Debug.Error("Not implemented");
     return(false);
 }
예제 #28
0
/* #line 133 "./ragel/tsip_parser_header_From.rl" */

        public static TSIP_HeaderFrom Parse(String data)
        {
            int             cs       = 0;
            int             p        = 0;
            int             pe       = data.Length;
            int             eof      = pe;
            TSIP_HeaderFrom hdr_from = new TSIP_HeaderFrom();

            int tag_start = 0;


/* #line 392 "../Headers/TSIP_HeaderFrom.cs" */
            {
                cs = tsip_machine_parser_header_From_start;
            }

/* #line 145 "./ragel/tsip_parser_header_From.rl" */

/* #line 399 "../Headers/TSIP_HeaderFrom.cs" */
            {
                sbyte _klen;
                short _trans;
                sbyte _acts;
                sbyte _nacts;
                short _keys;

                if (p == pe)
                {
                    goto _test_eof;
                }
                if (cs == 0)
                {
                    goto _out;
                }
_resume:
                _keys  = _tsip_machine_parser_header_From_key_offsets[cs];
                _trans = (short)_tsip_machine_parser_header_From_index_offsets[cs];

                _klen = _tsip_machine_parser_header_From_single_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + _klen - 1);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + ((_upper - _lower) >> 1));
                        if (data[p] < _tsip_machine_parser_header_From_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 1);
                        }
                        else if (data[p] > _tsip_machine_parser_header_From_trans_keys[_mid])
                        {
                            _lower = (short)(_mid + 1);
                        }
                        else
                        {
                            _trans += (short)(_mid - _keys);
                            goto _match;
                        }
                    }
                    _keys  += (short)_klen;
                    _trans += (short)_klen;
                }

                _klen = _tsip_machine_parser_header_From_range_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + (_klen << 1) - 2);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1));
                        if (data[p] < _tsip_machine_parser_header_From_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 2);
                        }
                        else if (data[p] > _tsip_machine_parser_header_From_trans_keys[_mid + 1])
                        {
                            _lower = (short)(_mid + 2);
                        }
                        else
                        {
                            _trans += (short)((_mid - _keys) >> 1);
                            goto _match;
                        }
                    }
                    _trans += (short)_klen;
                }

_match:
                _trans = (short)_tsip_machine_parser_header_From_indicies[_trans];
                cs     = _tsip_machine_parser_header_From_trans_targs[_trans];

                if (_tsip_machine_parser_header_From_trans_actions[_trans] == 0)
                {
                    goto _again;
                }

                _acts  = _tsip_machine_parser_header_From_trans_actions[_trans];
                _nacts = _tsip_machine_parser_header_From_actions[_acts++];
                while (_nacts-- > 0)
                {
                    switch (_tsip_machine_parser_header_From_actions[_acts++])
                    {
                    case 0:
/* #line 32 "./ragel/tsip_parser_header_From.rl" */
                    {
                        tag_start = p;
                    }
                    break;

                    case 1:
/* #line 36 "./ragel/tsip_parser_header_From.rl" */
                    {
                        int len = (int)(p - tag_start);
                        if (hdr_from != null && hdr_from.Uri == null)
                        {
                            if ((hdr_from.Uri = TSIP_ParserUri.Parse(data.Substring(tag_start, len))) != null && !String.IsNullOrEmpty(hdr_from.DisplayName))
                            {
                                hdr_from.Uri.DisplayName = hdr_from.DisplayName;
                            }
                        }
                    }
                    break;

                    case 2:
/* #line 45 "./ragel/tsip_parser_header_From.rl" */
                    {
                        hdr_from.DisplayName = TSK_RagelState.Parser.GetString(data, p, tag_start);
                        hdr_from.DisplayName = TSK_String.UnQuote(hdr_from.DisplayName);
                    }
                    break;

                    case 3:
/* #line 50 "./ragel/tsip_parser_header_From.rl" */
                    {
                        hdr_from.Tag = TSK_RagelState.Parser.GetString(data, p, tag_start);
                    }
                    break;

                    case 4:
/* #line 54 "./ragel/tsip_parser_header_From.rl" */
                    {
                        hdr_from.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, hdr_from.Params);
                    }
                    break;

                    case 5:
/* #line 58 "./ragel/tsip_parser_header_From.rl" */
                    {
                    }
                    break;

/* #line 514 "../Headers/TSIP_HeaderFrom.cs" */
                    default: break;
                    }
                }

_again:
                if (cs == 0)
                {
                    goto _out;
                }
                if (++p != pe)
                {
                    goto _resume;
                }
                _test_eof : {}
                _out      : {}
            }

/* #line 146 "./ragel/tsip_parser_header_From.rl" */

            if (cs <
/* #line 531 "../Headers/TSIP_HeaderFrom.cs" */
                108
/* #line 147 "./ragel/tsip_parser_header_From.rl" */
                )
            {
                TSK_Debug.Error("Failed to parse SIP 'From' header.");
                hdr_from.Dispose();
                hdr_from = null;
            }

            return(hdr_from);
        }
/* #line 139 "./ragel/tsip_parser_header_Subscription_State.rl" */

        public static TSIP_HeaderSubscriptionState Parse(String data)
        {
            int cs  = 0;
            int p   = 0;
            int pe  = data.Length;
            int eof = pe;
            TSIP_HeaderSubscriptionState hdr_Subscription_State = new TSIP_HeaderSubscriptionState();

            int tag_start = 0;


/* #line 524 "../Headers/TSIP_HeaderSubscriptionState.cs" */
            {
                cs = tsip_machine_parser_header_Subscription_State_start;
            }

/* #line 151 "./ragel/tsip_parser_header_Subscription_State.rl" */

/* #line 531 "../Headers/TSIP_HeaderSubscriptionState.cs" */
            {
                sbyte _klen;
                short _trans;
                sbyte _acts;
                sbyte _nacts;
                short _keys;

                if (p == pe)
                {
                    goto _test_eof;
                }
                if (cs == 0)
                {
                    goto _out;
                }
_resume:
                _keys  = _tsip_machine_parser_header_Subscription_State_key_offsets[cs];
                _trans = (short)_tsip_machine_parser_header_Subscription_State_index_offsets[cs];

                _klen = _tsip_machine_parser_header_Subscription_State_single_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + _klen - 1);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + ((_upper - _lower) >> 1));
                        if (data[p] < _tsip_machine_parser_header_Subscription_State_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 1);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Subscription_State_trans_keys[_mid])
                        {
                            _lower = (short)(_mid + 1);
                        }
                        else
                        {
                            _trans += (short)(_mid - _keys);
                            goto _match;
                        }
                    }
                    _keys  += (short)_klen;
                    _trans += (short)_klen;
                }

                _klen = _tsip_machine_parser_header_Subscription_State_range_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + (_klen << 1) - 2);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1));
                        if (data[p] < _tsip_machine_parser_header_Subscription_State_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 2);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Subscription_State_trans_keys[_mid + 1])
                        {
                            _lower = (short)(_mid + 2);
                        }
                        else
                        {
                            _trans += (short)((_mid - _keys) >> 1);
                            goto _match;
                        }
                    }
                    _trans += (short)_klen;
                }

_match:
                _trans = (short)_tsip_machine_parser_header_Subscription_State_indicies[_trans];
                cs     = _tsip_machine_parser_header_Subscription_State_trans_targs[_trans];

                if (_tsip_machine_parser_header_Subscription_State_trans_actions[_trans] == 0)
                {
                    goto _again;
                }

                _acts  = _tsip_machine_parser_header_Subscription_State_trans_actions[_trans];
                _nacts = _tsip_machine_parser_header_Subscription_State_actions[_acts++];
                while (_nacts-- > 0)
                {
                    switch (_tsip_machine_parser_header_Subscription_State_actions[_acts++])
                    {
                    case 0:
/* #line 31 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        tag_start = p;
                    }
                    break;

                    case 1:
/* #line 35 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.State = TSK_RagelState.Parser.GetString(data, p, tag_start);
                    }
                    break;

                    case 2:
/* #line 39 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.Reason = TSK_RagelState.Parser.GetString(data, p, tag_start);
                    }
                    break;

                    case 3:
/* #line 43 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.Expires = TSK_RagelState.Parser.GetInt32(data, p, tag_start);
                    }
                    break;

                    case 4:
/* #line 47 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.RetryAfter = TSK_RagelState.Parser.GetInt32(data, p, tag_start);
                    }
                    break;

                    case 5:
/* #line 51 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, hdr_Subscription_State.Params);
                    }
                    break;

                    case 6:
/* #line 55 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                    }
                    break;

/* #line 646 "../Headers/TSIP_HeaderSubscriptionState.cs" */
                    default: break;
                    }
                }

_again:
                if (cs == 0)
                {
                    goto _out;
                }
                if (++p != pe)
                {
                    goto _resume;
                }
                _test_eof : {}
                _out      : {}
            }

/* #line 152 "./ragel/tsip_parser_header_Subscription_State.rl" */

            if (cs <
/* #line 663 "../Headers/TSIP_HeaderSubscriptionState.cs" */
                136
/* #line 153 "./ragel/tsip_parser_header_Subscription_State.rl" */
                )
            {
                TSK_Debug.Error("Failed to parse SIP 'Subscription-State' header.");
                hdr_Subscription_State.Dispose();
                hdr_Subscription_State = null;
            }

            return(hdr_Subscription_State);
        }
예제 #30
0
        /// <summary>
        /// Updates the dialog state:
        /// - Authorizations (using challenges from the @a response message)
        /// - State (early, established, disconnected, ...)
        /// - Routes (and Service-Route)
        /// - Target (remote)
        /// - ...
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        protected Boolean UpdateWithResponse(TSIP_Response response)
        {
            if (response == null || response.To == null || response.CSeq == null)
            {
                return(false);
            }
            String tag = response.To.Tag;

            /*
             *	1xx (!100) or 2xx
             */
            /*
             *	401 or 407 or 421 or 494
             */
            if (response.StatusCode == 401 || response.StatusCode == 407 || response.StatusCode == 421 || response.StatusCode == 494)
            {
                Boolean acceptNewVector;

                /* 3GPP IMS - Each authentication vector is used only once.
                 *	==> Re-registration/De-registration ==> Allow 401/407 challenge.
                 */
                acceptNewVector = (response.CSeq.RequestType == TSIP_Message.tsip_request_type_t.REGISTER && this.State == tsip_dialog_state_t.Established);
                return(this.UpdateChallenges(response, acceptNewVector));
            }
            else if (100 < response.StatusCode && response.StatusCode < 300)
            {
                tsip_dialog_state_t state = this.State;

                /* 1xx */
                if (response.StatusCode <= 199)
                {
                    if (String.IsNullOrEmpty(response.To.Tag))
                    {
                        TSK_Debug.Error("Invalid tag  parameter");
                        return(false);
                    }
                    state = tsip_dialog_state_t.Early;
                }
                /* 2xx */
                else
                {
                    state = tsip_dialog_state_t.Established;
                }

                /* Remote target */
                {
                    /*	RFC 3261 12.2.1.2 Processing the Responses
                     *  When a UAC receives a 2xx response to a target refresh request, it
                     *  MUST replace the dialog's remote target URI with the URI from the
                     *  Contact header field in that response, if present.
                     *
                     *  FIXME: Because PRACK/UPDATE sent before the session is established MUST have
                     *  the rigth target URI to be delivered to the UAS ==> Do not not check that we are connected
                     */
                    if (response.CSeq.RequestType != TSIP_Message.tsip_request_type_t.REGISTER && response.Contact != null && response.Contact.Uri != null)
                    {
                        mUriRemoteTarget = response.Contact.Uri.Clone(true, false);
                    }
                }

                /* Route sets */
                {
                    int index;
                    TSIP_HeaderRecordRoute recordRoute;

                    mRecordRoutes.Clear();

                    for (index = 0; (recordRoute = response.GetHeaderAtIndex(TSIP_Header.tsip_header_type_t.Record_Route, index) as TSIP_HeaderRecordRoute) != null; index++)
                    {
                        mRecordRoutes.Insert(0, recordRoute); /* Copy reversed. */
                    }
                }

                /* cseq + tags + ... */
                if (this.State == tsip_dialog_state_t.Established && String.Equals(mTagRemote, tag, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
                else
                {
                    if (response.CSeq.RequestType != TSIP_Message.tsip_request_type_t.REGISTER && response.CSeq.RequestType != TSIP_Message.tsip_request_type_t.PUBLISH)
                    { /* REGISTER and PUBLISH don't establish dialog */
                        mTagRemote = tag;
                    }
#if NEVER_EXECUTE_00    // PRACK and BYE will have same CSeq value ==> Let CSeq value to be incremented by "tsip_dialog_request_new()"
                    self->cseq_value = response->CSeq ? response->CSeq->seq : self->cseq_value;
#endif
                }

                this.State = state;
                return(true);
            }

            return(true);
        }