public Boolean Register(TSIP_Action.TSIP_ActionConfig actionConfig)
        {
            if (this.Stack == null || !this.Stack.IsValid)
            {
                TSK_Debug.Error("Invalid stack");
                return(false);
            }

            if (!this.Stack.IsRunning)
            {
                TSK_Debug.Error("Stack not running");
                return(false);
            }

            TSIP_Action action = new TSIP_Action(TSIP_Action.tsip_action_type_t.tsip_atype_register);

            action.AddConfig(actionConfig);
            TSIP_Dialog dialog;

            if ((dialog = this.Stack.LayerDialog.FindDialogBySessionId(this.Id)) == null)
            {
                dialog = this.Stack.LayerDialog.CreateDialog(TSIP_Dialog.tsip_dialog_type_t.REGISTER, this);
            }

            if (dialog == null)
            {
                TSK_Debug.Error("Failed to create new dialog");
                return(false);
            }

            return(dialog.ExecuteAction((Int32)action.Type, null, action));
        }
        public TSIP_Stack(TSIP_Uri domainName, String privateIdentity, TSIP_Uri publicIdentity, String proxyHost, ushort proxyPort)
        {
            mSipSessions = new Dictionary <Int64, TSip_Session>();
            mHeaders     = new List <TSK_Param>();

            if (domainName == null || String.IsNullOrEmpty(privateIdentity) || publicIdentity == null)
            {
                TSK_Debug.Error("Invalid parameter");
                goto bail;
            }

            mRealm             = domainName;
            mPrivateIdentity   = privateIdentity;
            mPublicIdentity    = publicIdentity;
            mPreferredIdentity = mPublicIdentity;
            mProxyHost         = String.IsNullOrEmpty(proxyHost) ? domainName.Host : proxyHost;
            mProxyPort         = proxyPort == 0 ? (ushort)5060 : proxyPort;

            /* === Default values === */
            mLocalIP   = TNET_Socket.TNET_SOCKET_HOST_ANY;
            mLocalPort = TNET_Socket.TNET_SOCKET_PORT_ANY;
            mProxyType = TNET_Socket.tnet_socket_type_t.tnet_socket_type_udp_ipv4;

            mLayerDialog    = new TSIP_DialogLayer(this);
            mLayerTransac   = new TSIP_TransacLayer(this);
            mLayerTransport = new TSIP_TransportLayer(this);


            mValid = true;



            bail :;
        }
        public static String Serialize(TSIP_Uri uri, Boolean with_params, Boolean with_quote)
        {
            String ret = String.Empty;

            if (uri != null)
            {
                if (with_quote)
                {
                    if (uri.DisplayName != null)
                    {
                        ret += String.Format("\"{0}\"", uri.DisplayName);
                    }

                    ret += "<";
                    ret += _InternalSerialize(uri, with_params);
                    ret += ">";
                }
                else
                {
                    ret += _InternalSerialize(uri, with_params);
                }
            }
            else
            {
                TSK_Debug.Error("Invalid parameter");
            }
            return(ret);
        }
Exemple #4
0
        internal TSIP_Dialog CreateDialog(TSIP_Dialog.tsip_dialog_type_t type, TSip_Session sipSession)
        {
            TSIP_Dialog dialog = null;

            switch (type)
            {
            case TSIP_Dialog.tsip_dialog_type_t.REGISTER:
            {
                dialog = new TSIP_DialogRegister(sipSession as TSIP_SessionRegister);
                break;
            }

            default:
            {
                TSK_Debug.Error("{0} not support as dialog type", type);
                break;
            }
            }

            if (dialog != null && !mDialogs.ContainsKey(dialog.Id))
            {
                mMutex.WaitOne();
                mDialogs.Add(dialog.Id, dialog);
                mMutex.ReleaseMutex();
            }

            return(dialog);
        }
Exemple #5
0
        public IntPtr ConnectTo(String host, ushort port, TNET_Socket.tnet_socket_type_t type)
        {
            if (!mStarted)
            {
                TSK_Debug.Error("Transport not started");
                return(IntPtr.Zero);
            }

            if (this.Type != type)
            {
                TSK_Debug.Error("Master/destination types mismatch [{0}/{1}]", this.Type, type);
                return(IntPtr.Zero);
            }

            EndPoint endpoint = TNET_Socket.CreateEndPoint(host, port);

            if (endpoint != null)
            {
                //var args = new SocketAsyncEventArgs();
                //args.RemoteEndPoint = endpoint;
                //args.Completed += this.SocketAsyncEventArgs_Callback;
                // args.SetBuffer(buffer, 0, buffer.Length);

                return(IntPtr.Zero);
            }

            return(IntPtr.Zero);
        }
        public Boolean ExecuteAction(Int32 fsmActionId, TSIP_Message message, TSIP_Action action)
        {
            if (this.StateMachine != null)
            {
                return(this.StateMachine.ExecuteAction(fsmActionId, this, message, this, message, action));
            }

            TSK_Debug.Error("Invalid FSM");

            return(false);
        }
Exemple #7
0
 private Boolean SendBytes(EndPoint toEP, byte[] bytes)
 {
     if (TNET_Socket.IsStreamType(this.Type))
     {
         TSK_Debug.Error("Not implemented");
         return(false);
     }
     else
     {
         return(base.SendTo(toEP, bytes) > 0);
     }
 }
        internal TSIP_Transac CreateTransac(Boolean isClient, TSIP_Message message, TSIP_Dialog dialog)
        {
            TSIP_Transac transac = null;

            if (message != null && message.IsRequest)
            {
                if (isClient)/* Client transaction */
                {
                    if (message.IsINVITE)
                    {
                        // INVITE Client transaction (ICT)
                        TSK_Debug.Error("CreateTransac - not implemented");
                    }
                    else
                    {
                        // NON-INVITE Client transaction (NICT)
                        transac = new TSIP_TransacNICT(mReliable, (Int32)message.CSeq.CSeq, message.CSeq.Method, message.CallId.Value, dialog);
                    }
                }
                else/* Server transaction */
                {
                    if (message.IsINVITE)
                    {
                        // INVITE Server transaction (IST)
                        TSK_Debug.Error("CreateTransac - not implemented");
                    }
                    else
                    {
                        // NON-INVITE Server transaction (NIST)
                        TSK_Debug.Error("CreateTransac - not implemented");
                    }

                    if (transac != null)
                    {
                        /* Copy branch from the message */
                        transac.Branch = message.FirstVia.Branch;
                    }
                }
            }


            mMutex.WaitOne();

            if (transac != null)
            {
                /* Add new transaction */
                mTransactions.Add(transac.Id, transac);
            }

            mMutex.ReleaseMutex();

            return(transac);
        }
 internal Boolean Start()
 {
     foreach (TSIP_Transport transport in mTransports)
     {
         if (!transport.Start())
         {
             TSK_Debug.Error("Failed to start transport [{0}]", transport.Description);
             return(false);
         }
     }
     mRunning = true;
     return(true);
 }
Exemple #10
0
        private Boolean OnCallbackEvent(tsip_transac_event_type_t type, TSIP_Message message)
        {
            Boolean ret = true;

            switch (type)
            {
            case tsip_transac_event_type_t.IncomingMessage:
            {
                if (message != null && message.IsResponse)
                {
                    if ((message as TSIP_Response).Is1xx)
                    {
                        ret = base.ExecuteAction((Int32)FSMAction._1xx, message);
                    }
                    else if ((message as TSIP_Response).Is23456)
                    {
                        ret = base.ExecuteAction((Int32)FSMAction._200_to_699, message);
                    }
                    else
                    {
                        TSK_Debug.Error("Not supported status code: {0}", (message as TSIP_Response).StatusCode);
                    }
                }
                break;
            }

            case tsip_transac_event_type_t.Canceled:
            case tsip_transac_event_type_t.Terminated:
            case tsip_transac_event_type_t.TimedOut:
            default:
            {
                break;
            }

            case tsip_transac_event_type_t.Error:
            {
                ret = base.ExecuteAction((Int32)FSMAction.Error, message);
                break;
            }

            case tsip_transac_event_type_t.TransportError:
            {
                ret = base.ExecuteAction((Int32)FSMAction.TransportError, message);
                break;
            }
            }

            return(ret);
        }
        internal Boolean Stop()
        {
            Boolean ok = true;

            foreach (TSIP_Transport transport in mTransports)
            {
                if (!transport.Start())
                {
                    TSK_Debug.Error("Failed to start transport [{0}]", transport.Description);
                    ok = false;
                }
            }
            mRunning = false;
            return(ok);;
        }
        internal TSIP_Header CreateHeaderAuthorization(TSIP_Request request)
        {
            if (request == null)
            {
                TSK_Debug.Error("Invalid parameter");
                return(null);
            }

            String response, nc = null, uristring;

            if (String.IsNullOrEmpty(uristring = TSIP_Uri.ToString(request.Uri, true, false)))
            {
                TSK_Debug.Error("Failed to parse URI: {0}", request.Uri);
                return(null);
            }

            /* We compute the nc here because @ref tsip_challenge_get_response function will increment it's value. */
            if (mNc > 0)
            {
                nc = THTTP_Auth.GetNonceString(mNc).ToString();
            }
            /* entity_body ==> request-content */
            response = GetResponse(request.Method, uristring, request.Content);

            if (mProxy)
            {
                // FIXME
                TSK_Debug.Error("Proxy-Authorization header not supported yet");
            }
            else
            {
                TSIP_HeaderAuthorization header = new TSIP_HeaderAuthorization();
                header.UserName  = ChallengeUserName;
                header.Scheme    = mScheme;
                header.Realm     = mRealm;
                header.Nonce     = mNonce;
                header.Qop       = mQop;
                header.Algorithm = String.IsNullOrEmpty(mAlgorithm) ? "MD5" : mAlgorithm;
                header.Cnonce    = mNc > 0 ? mCnonce : null;
                header.Uri       = uristring;
                header.Nc        = mNc > 0 ? nc : null;
                header.Response  = response;

                return(header);
            }

            return(null);
        }
Exemple #13
0
 public Int32 SendTo(Int64 localSocket, EndPoint remoteEP, byte[] buffer)
 {
     if (mSockets.ContainsKey(localSocket))
     {
         TNET_Socket socketFrom = mSockets[localSocket];
         if (socketFrom != null)
         {
             return(socketFrom.SendTo(remoteEP, buffer));
         }
     }
     else
     {
         TSK_Debug.Error("Cannot find socket with handle = {0}", localSocket);
     }
     return(-1);
 }
        public static EndPoint CreateEndPoint(String host, ushort port)
        {
            try
            {
#if WINDOWS_PHONE
                return(new DnsEndPoint(host, port));
#else
                return(new IPEndPoint(Dns.GetHostAddresses(host)[0], port));
#endif
            }
            catch (Exception e)
            {
                TSK_Debug.Error("CreateEndPoint failed: {0}", e);
            }
            return(null);
        }
        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);
        }
        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);
        }
        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");
            }
        }
Exemple #19
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);
        }
        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);
        }
        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);
        }
/* #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);
        }
Exemple #24
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);
    }
Exemple #25
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);
        }
 /// <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);
 }
 /// <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);
 }
 /// <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);
 }
 /// <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);
 }
 /// <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);
 }