/// <summary>
        /// InProgress --> (401/407/421/494) --> InProgress
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean InProgress_2_InProgress_X_401_407_421_494(params Object[] parameters)
        {
            TSIP_Response response = parameters[1] as TSIP_Response;
            Boolean       ret;

            if (!(ret = base.UpdateWithResponse(response)))
            {
                /* alert the user */
                TSIP_EventRegister.Signal(mUnRegsitering ? TSIP_EventRegister.tsip_register_event_type_t.AO_UNREGISTER : TSIP_EventRegister.tsip_register_event_type_t.AO_REGISTER,
                                          base.SipSession,
                                          response.StatusCode, response.ReasonPhrase, response);

                /* set last error (or info) */
                base.SetLastError((short)response.StatusCode, response.ReasonPhrase, response);

                return(ret);
            }

            /* Ensure 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_ensureTempSAs(TSIP_DIALOG_GET_STACK(self)->layer_transport, response, TSIP_DIALOG(self)->expires);
            //}

            return(this.SendRegister(false));
        }
        /// <summary>
        /// InProgress -> (2xx) -> Terminated
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean InProgress_2_Terminated_X_2xx(params Object[] parameters)
        {
            TSIP_Response response = parameters[1] as TSIP_Response;

            /* Alert the user */
            TSIP_EventRegister.Signal(TSIP_EventRegister.tsip_register_event_type_t.AO_UNREGISTER, base.SipSession,
                                      response.StatusCode, response.ReasonPhrase, response);

            return(true);
        }
        /// <summary>
        /// InProgress -> (1xx) -> InProgress
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean InProgress_2_InProgress_X_1xx(params Object[] parameters)
        {
            TSIP_Response response = parameters[1] as TSIP_Response;

            /* Alert the user (session) */
            TSIP_EventRegister.Signal(TSIP_EventRegister.tsip_register_event_type_t.AO_REGISTER,
                                      base.SipSession, response.StatusCode, response.ReasonPhrase, response);

            return(base.UpdateWithResponse(response));
        }
        /// <summary>
        /// InProgress -> (300-699) -> Terminated
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean InProgress_2_Terminated_X_300_to_699(params Object[] parameters)
        {
            TSIP_Response response = parameters[1] as TSIP_Response;

            base.SetLastError((short)response.StatusCode, response.ReasonPhrase, response);

            /* alert the user */
            TSIP_EventRegister.Signal(mUnRegsitering ? TSIP_EventRegister.tsip_register_event_type_t.AO_UNREGISTER : TSIP_EventRegister.tsip_register_event_type_t.AO_REGISTER,
                                      base.SipSession,
                                      response.StatusCode, response.ReasonPhrase, response);

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Any -> (error) -> Terminated
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean Any_2_Terminated_X_Error(params Object[] parameters)
        {
            TSIP_Response response = parameters[2] as TSIP_Response;

            if (response != null)
            {
                base.SetLastError((short)response.StatusCode, response.ReasonPhrase, response);
                TSIP_EventRegister.Signal(mUnRegsitering ? TSIP_EventRegister.tsip_register_event_type_t.AO_UNREGISTER : TSIP_EventRegister.tsip_register_event_type_t.AO_REGISTER,
                                          base.SipSession, response.StatusCode, response.ReasonPhrase, response);
            }
            else
            {
                TSIP_EventDialog.Signal(TSIP_EventDialog.tsip_dialog_event_type_t.GlobalError, base.SipSession, "Global error", null);
            }

            return(false);
        }
Esempio n. 6
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();


            String mm = "SIP/2.0 200 OK\r\n" +
                        "Via: SIP/2.0/UDP 192.168.0.13:5060;branch=z9hG4bK_56ef1cda-aef6-4d76-ab7e-d148af3b18ac;rport=51049\r\n" +
                        "Record-Route: <sip:192.168.0.10:5060;lr;transport=udp>\r\n" +
                        "To: <sip:[email protected]>\r\n" +
                        "From: <sip:[email protected]>;tag=9bff9c34-35e3-4fa8-8de4-290ce275c981\r\n" +
                        "Call-ID: 272b67b9-08b2-4fce-8f6e-6ccaf5e5ec9a\r\n" +
                        "CSeq: 1990525622 REGISTER\r\n" +
                        "Server: mjsip stack 1.6\r\n" +
                        "Contact: <sip:[email protected]:5060>;expires=10\r\n" +
                        "Content-Length: 0\r\n" +
                        "\r\n";

            /*TSIP_Message message = TSIP_ParserMessage.Parse(UTF8Encoding.UTF8.GetBytes(mm), true);
             * if (message != null)
             * {
             * }*/



            TSIP_Stack sipStack = new TSIP_Stack(
                TSIP_Uri.Create("sip:doubango.org"),
                "004",
                TSIP_Uri.Create("sip:[email protected]"),
                "192.168.0.10", 5060
                );

            // sipStack.Headers.Add(new TSK_Param("User-Agent", "wp-ngn-stack"));
            sipStack.AoRIP   = "192.168.0.13";
            sipStack.AoRPort = 5060;

            sipStack.Callback = delegate(TSIP_Event @event)
            {
                switch (@event.Type)
                {
                case TSIP_Event.tsip_event_type_t.DIALOG:
                {
                    TSIP_EventDialog eventDialog = (@event as TSIP_EventDialog);
                    break;
                }

                case TSIP_Event.tsip_event_type_t.REGISTER:
                {
                    TSIP_EventRegister eventDialog = (@event as TSIP_EventRegister);
                    break;
                }

                default:
                {
                    return(false);
                }
                }
                return(true);
            };


            if (sipStack.Start())
            {
                TSIP_SessionRegister register = new TSIP_SessionRegister(sipStack);
                register.Register();
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //Test_FSM.DefaultTest();

            //TSIP_TransportUDP transportUdp = new TSIP_TransportUDP("192.168.0.13", TNET_Socket.TNET_SOCKET_PORT_ANY, false, "Sip Tansport using UDP");
            //IPEndPoint remoteEP = TNET_Socket.CreateEndPoint("192.168.0.10", 5060);
            // Int32 count = transportUdp.SendTo(remoteEP, Encoding.UTF8.GetBytes("test"));

            //Test_UriParser.TestUriParser();
            //Test_UriParser.TestMessageParser();

            /*List<TSIP_HeaderVia> headers = TSIP_HeaderVia.Parse("Via: SIP/2.0/tcp 127.0.0.1:5082;branch=z9hG4bKc16be5aee32df400d01015675ab911ba,SIP/2.0/udp 127.0.0.1:5082;branch=z9hG4bKeec53b25db240bec92ea250964b8c1fa;received_port_ext=5081;received=192.168.0.13,SIP/2.0/UDP 192.168.0.12:57121;rport=57121;branch=z9hG4bK1274980921982;received_port_ext=5081;received=192.168.0.12\r\n");
             * foreach (TSIP_HeaderVia h in headers)
             * {
             *  Console.WriteLine(h.ToString(true, true, true));
             * }*/

            //TSIP_HeaderTo header = TSIP_HeaderTo.Parse("t:    <sip:[email protected]>;tag= 12345\r\n");
            //if (header != null)
            //{
            //    Console.WriteLine(header.ToString(true, true, true));
            //}

            TSIP_Stack sipStack = new TSIP_Stack(
                TSIP_Uri.Create("sip:doubango.org"),
                "004",
                TSIP_Uri.Create("sip:[email protected]"),
                "192.168.0.10", 5060
                );

            sipStack.LocalIP = "192.168.0.13";//FIXME

            sipStack.Callback = delegate(TSIP_Event @event)
            {
                switch (@event.Type)
                {
                case TSIP_Event.tsip_event_type_t.DIALOG:
                {
                    TSIP_EventDialog eventDialog = (@event as TSIP_EventDialog);
                    break;
                }

                case TSIP_Event.tsip_event_type_t.REGISTER:
                {
                    TSIP_EventRegister eventDialog = (@event as TSIP_EventRegister);
                    break;
                }

                default:
                {
                    return(false);
                }
                }
                return(true);
            };


            if (sipStack.Start())
            {
                TSIP_SessionRegister register = new TSIP_SessionRegister(sipStack);
                register.Register();
            }

            Console.ReadLine();
        }
        /// <summary>
        /// InProgress -> (2xx) -> Connected
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private Boolean InProgress_2_Connected_X_2xx(params Object[] parameters)
        {
            Boolean       ret      = true;
            TSIP_Response response = parameters[1] as TSIP_Response;

            Boolean first_time_to_connect = base.State == tsip_dialog_state_t.Initial;

            /*	- Set P-associated-uriS
             *	- Update service-routes
             *	- Update Pats
             */
            {
                int index;
                // const tsip_header_Path_t *hdr_Path;
                // const tsip_header_Service_Route_t *hdr_Service_Route;
                // const tsip_header_P_Associated_URI_t *hdr_P_Associated_URI_t;
                TSIP_Uri uri;

                /* To avoid memory leaks ==> delete all concerned objects (it worth nothing) */
                //TSK_OBJECT_SAFE_FREE(TSIP_DIALOG_GET_STACK(self)->associated_uris);
                //TSK_OBJECT_SAFE_FREE(TSIP_DIALOG_GET_STACK(self)->service_routes);
                //TSK_OBJECT_SAFE_FREE(TSIP_DIALOG_GET_STACK(self)->paths);

                /* Associated URIs */

                /*for(index = 0; (hdr_P_Associated_URI_t = (const tsip_header_P_Associated_URI_t*)tsip_message_get_headerAt(response, tsip_htype_P_Associated_URI, index)); index++){
                 *  if(!TSIP_DIALOG_GET_STACK(self)->associated_uris){
                 *      TSIP_DIALOG_GET_STACK(self)->associated_uris = tsk_list_create();
                 *  }
                 *  uri = tsk_object_ref(hdr_P_Associated_URI_t->uri);
                 *  tsk_list_push_back_data(TSIP_DIALOG_GET_STACK(self)->associated_uris, (void**)&uri);
                 * }*/

                /*	Service-Route (3GPP TS 24.229)
                 *  store the list of service route values contained in the Service-Route header field and bind the list to the contact
                 *  address used in registration, in order to build a proper preloaded Route header field value for new dialogs and
                 *  standalone transactions when using the respective contact address.
                 */
                /*for(index = 0; (hdr_Service_Route = (const tsip_header_Service_Route_t*)tsip_message_get_headerAt(response, tsip_htype_Service_Route, index)); index++){
                 *  if(!TSIP_DIALOG_GET_STACK(self)->service_routes){
                 *      TSIP_DIALOG_GET_STACK(self)->service_routes = tsk_list_create();
                 *  }
                 *  uri = tsk_object_ref(hdr_Service_Route->uri);
                 *  tsk_list_push_back_data(TSIP_DIALOG_GET_STACK(self)->service_routes, (void**)&uri);
                 * }*/

                /* Paths */

                /*for(index = 0; (hdr_Path = (const tsip_header_Path_t*)tsip_message_get_headerAt(response, tsip_htype_Path, index)); index++){
                 *  if(TSIP_DIALOG_GET_STACK(self)->paths == 0){
                 *      TSIP_DIALOG_GET_STACK(self)->paths = tsk_list_create();
                 *  }
                 *  uri = tsk_object_ref(hdr_Path->uri);
                 *  tsk_list_push_back_data(TSIP_DIALOG_GET_STACK(self)->paths, (void**)&uri);
                 * }*/
            }

            /* 3GPP TS 24.229 - 5.1.1.2 Initial registration */
            if (first_time_to_connect)
            {
                Boolean barred = true;
                //const tsk_list_item_t *item;
                //const tsip_uri_t *uri;
                //const tsip_uri_t *uri_first = 0;

                /*
                 *  b) store as the default public user identity the first URI on the list of URIs present in the P-Associated-URI header
                 *  field and bind it to the respective contact address of the UE and the associated set of security associations or TLS
                 *  session;
                 *  NOTE 4: When using the respective contact address and associated set of security associations or TLS session, the
                 *  UE can utilize additional URIs contained in the P-Associated-URI header field and bound it to the
                 *  respective contact address of the UE and the associated set of security associations or TLS session, e.g. for
                 *  application purposes.
                 *  c) treat the identity under registration as a barred public user identity, if it is not included in the P-Associated-URI
                 *  header field;
                 */
                //tsk_list_foreach(item, TSIP_DIALOG_GET_STACK(self)->associated_uris){
                //    uri = item->data;
                //    if(item == TSIP_DIALOG_GET_STACK(self)->associated_uris->head){
                //        uri_first = item->data;
                //    }
                //    if(!tsk_object_cmp(TSIP_DIALOG_GET_STACK(self)->identity.preferred, uri)){
                //        barred = 0;
                //        break;
                //    }
                //}

                //if(barred && uri_first){
                //    TSK_OBJECT_SAFE_FREE(TSIP_DIALOG_GET_STACK(self)->identity.preferred);
                //    TSIP_DIALOG_GET_STACK(self)->identity.preferred = tsk_object_ref((void*)uri_first);
                //}
            }

            /* Update the dialog state */
            if (!(ret = this.UpdateWithResponse(response)))
            {
                return(ret);
            }

            /* Reset current action */
            base.CurrentAction = null;

            /* Request timeout for dialog refresh (re-registration). */
            this.TimerRefresh.Period = (UInt64)base.GetNewDelay(response);
            this.TimerRefresh.Start();

            /* Alert the user (session) */
            TSIP_EventRegister.Signal(TSIP_EventRegister.tsip_register_event_type_t.AO_REGISTER, base.SipSession,
                                      response.StatusCode, response.ReasonPhrase, response);

            /* Alert the user (dialog) */
            if (first_time_to_connect)
            {
                TSIP_EventDialog.Signal(TSIP_EventDialog.tsip_dialog_event_type_t.Connected, base.SipSession, response.ReasonPhrase, response);
            }

            return(ret);
        }