Exemplo n.º 1
0
        private static String _InternalSerialize(TSIP_Uri uri, Boolean with_params)
        {
            /* sip:alice:[email protected]:65535 */
            String uriString = String.Format("{0}:{1}{2}{3}{4}{5}{6}{7}{8}{9}",
                                             uri.Scheme != null ? uri.Scheme : "sip", /* default scheme is sip: */

                                             uri.UserName != null ? uri.UserName : "",

                                             uri.Password != null ? ":" : "",
                                             uri.Password != null ? uri.Password : "",

                                             uri.Host != null ? (uri.UserName != null ? "@" : "") : "",
                                             uri.HostType == tsip_host_type_t.IPv6 ? "[" : "",
                                             uri.Host != null ? uri.Host : "",
                                             uri.HostType == tsip_host_type_t.IPv6 ? "]" : "",

                                             uri.Port != 0 ? ":" : "",
                                             uri.Port != 0 ? uri.Port.ToString() : ""
                                             );

            /* Params */
            if (with_params && uri.Params.Count > 0)
            {
                uriString += ";";
                uriString += TSK_Param.ToString(uri.Params, ';');
            }

            return(uriString);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        internal TSIP_Uri GetProxyCSCFUri(Boolean lr)
        {
            TSIP_Uri uri = null;

            if (mLayerTransport != null && mLayerTransport.Transports.Count > 0)
            {
                TSIP_Transport transport = mLayerTransport.Transports[0];
                if (transport != null)
                {
                    Boolean ipv6      = TNET_Socket.IsIPv6Type(transport.Type);
                    Boolean quote_ip  = (ipv6 && !String.IsNullOrEmpty(mProxyHost) && mProxyHost.Contains(":")) /* IPv6 IP string?*/;
                    String  uriString = String.Format("{0}:{1}{2}{3}:{4};{5};transport={6}",
                                                      transport.Scheme,
                                                      quote_ip ? "[" : "",
                                                      mProxyHost,
                                                      quote_ip ? "]" : "",
                                                      mProxyPort,
                                                      lr ? "lr" : "",
                                                      transport.Protocol
                                                      );
                    uri = TSIP_ParserUri.Parse(uriString);
                }
            }
            return(uri);
        }
Exemplo n.º 4
0
        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: ;
        }
Exemplo n.º 5
0
 public TSIP_Request(String method, TSIP_Uri requestUri, TSIP_Uri fromUri, TSIP_Uri toUri, String callId, Int32 cseq)
     : base(tsip_message_type_t.Request)
 {
     /* RFC 3261 8.1.1 Generating the Request
      *          A valid SIP request formulated by a UAC MUST, at a minimum, contain
      *          the following header fields: To, From, CSeq, Call-ID, Max-Forwards,
      *          and Via; all of these header fields are mandatory in all SIP
      *          requests.  These six header fields are the fundamental building
      *          blocks of a SIP message, as they jointly provide for most of the
      *          critical message routing services including the addressing of
      *          messages, the routing of responses, limiting message propagation,
      *          ordering of messages, and the unique identification of transactions.
      *          These header fields are in addition to the mandatory request line,
      *          which contains the method, Request-URI, and SIP version.
      */
     this.Method = method;
     this.Uri    = requestUri;
     this.AddHeaders(new TSIP_Header[]
     {
         toUri == null ? null : new TSIP_HeaderTo(toUri.DisplayName, toUri, null),
         fromUri == null ? null : new TSIP_HeaderFrom(fromUri.DisplayName, fromUri, null),
         /* Via will be added by the transport layer */
         new TSIP_HeaderCSeq((uint)cseq, method),
         String.IsNullOrEmpty(callId) ? null : new TSIP_HeaderCallId(callId),
         new TSIP_HeaderMaxForwards(TSIP_HeaderMaxForwards.TSIP_HEADER_MAX_FORWARDS_DEFAULT),
         /* Content-Length is mandatory for TCP. If both from and to are not null this means that it's a valid request */
         toUri != null && fromUri != null ? new TSIP_HeaderContentLength(0) : null,
     }
                     );
 }
Exemplo n.º 6
0
        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 :;
        }
Exemplo n.º 7
0
        internal TSIP_Uri GetContactUri(String protocol)
        {
            TSIP_Uri uri = null;

            foreach (TSIP_Transport transport in mLayerTransport.Transports)
            {
                if (String.Equals(transport.Protocol, protocol, StringComparison.InvariantCultureIgnoreCase))
                {
                    if ((uri = transport.GetUri(false)) != null)
                    {
                        uri.UserName = mPublicIdentity.UserName;
                        break;
                    }
                }
            }
            return(uri);
        }
Exemplo n.º 8
0
 // internal construction used to create server-side session
 protected TSip_Session(TSIP_Stack stack, TSIP_Message message)
     : this(stack)
 {
     if (message != null)
     {
         /* From: */
         if (message.From != null && message.From.Uri != null)
         { /* MUST be not null */
             mUriFrom = message.From.Uri;
         }
         /* To: */
         if (message.To != null && message.To.Uri != null)
         { /* MUST be not null */
             mUriTo = message.To.Uri;
         }
     }
 }
Exemplo n.º 9
0
        protected TSip_Session(TSIP_Stack stack)
        {
            mId      = sUniqueId++;
            mStack   = stack;
            mCaps    = new List <TSK_Param>();
            mHeaders = new List <TSK_Param>();
            mExpires = TSip_Session.DEFAULT_EXPIRES;

            /* From */
            mUriFrom = mStack.PublicIdentity;

            /* to */
            /* To value will be set by the dialog (whether to use as Request-URI). */

            if (mStack != null)
            {
                mStack.AddSession(this);
            }
        }
Exemplo n.º 10
0
 internal static void TestToString(TSIP_Uri uri)
 {
     TSK_Debug.Info("uri_to_string={0}", uri);
 }
Exemplo n.º 11
0
        public static TSIP_Uri Clone(TSIP_Uri uri, Boolean with_params, Boolean with_quote)
        {
            String uriString = TSIP_Uri.Serialize(uri, with_params, with_params);

            return(TSIP_ParserUri.Parse(uriString));
        }
Exemplo n.º 12
0
 public static String ToString(TSIP_Uri uri, Boolean with_params, Boolean with_quote)
 {
     return(TSIP_Uri.Serialize(uri, with_params, with_quote));
 }
Exemplo n.º 13
0
        private static String _InternalSerialize(TSIP_Uri uri, Boolean with_params)
        {
            /* sip:alice:[email protected]:65535 */
               String uriString = String.Format("{0}:{1}{2}{3}{4}{5}{6}{7}{8}{9}",
                uri.Scheme!=null ? uri.Scheme : "sip", /* default scheme is sip: */

                uri.UserName!=null ? uri.UserName : "",

                uri.Password!=null ? ":" : "",
                uri.Password!=null ? uri.Password : "",

                uri.Host!=null ? (uri.UserName!=null ? "@" : "") : "",
                uri.HostType == tsip_host_type_t.IPv6 ? "[" : "",
                uri.Host!=null ? uri.Host : "",
                uri.HostType == tsip_host_type_t.IPv6 ? "]" : "",

                uri.Port!=0 ? ":" : "",
                uri.Port!=0 ? uri.Port.ToString() : ""
                );

            /* Params */
            if(with_params && uri.Params.Count > 0){
                uriString += ";";
                uriString += TSK_Param.ToString(uri.Params, ';');
            }

            return uriString;
        }
Exemplo n.º 14
0
 public TSIP_Uri Clone(Boolean with_params, Boolean with_quote)
 {
     return(TSIP_Uri.Clone(this, with_params, with_quote));
 }
Exemplo n.º 15
0
 public TSIP_Uri Clone()
 {
     return(TSIP_Uri.Clone(this, true, true));
 }
Exemplo n.º 16
0
 public String ToString(Boolean with_params, Boolean with_quote)
 {
     return(TSIP_Uri.Serialize(this, with_params, with_quote));
 }
Exemplo n.º 17
0
 public String Serialize()
 {
     return(TSIP_Uri.Serialize(this, true, true));
 }
Exemplo n.º 18
0
        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;
        }
Exemplo n.º 19
0
 public static String ToString(TSIP_Uri uri, Boolean with_params, Boolean with_quote)
 {
     return TSIP_Uri.Serialize(uri, with_params, with_quote);
 }
Exemplo n.º 20
0
 public TSIP_Request(String method, TSIP_Uri requestUri, TSIP_Uri fromUri, TSIP_Uri toUri, String callId, Int32 cseq)
     : base(tsip_message_type_t.Request)
 {
     /* RFC 3261 8.1.1 Generating the Request
         A valid SIP request formulated by a UAC MUST, at a minimum, contain
         the following header fields: To, From, CSeq, Call-ID, Max-Forwards,
         and Via; all of these header fields are mandatory in all SIP
         requests.  These six header fields are the fundamental building
         blocks of a SIP message, as they jointly provide for most of the
         critical message routing services including the addressing of
         messages, the routing of responses, limiting message propagation,
         ordering of messages, and the unique identification of transactions.
         These header fields are in addition to the mandatory request line,
         which contains the method, Request-URI, and SIP version.
     */
     this.Method = method;
     this.Uri = requestUri;
     this.AddHeaders(new TSIP_Header[]
         {
             toUri == null ? null : new TSIP_HeaderTo(toUri.DisplayName, toUri, null),
             fromUri == null ? null : new TSIP_HeaderFrom(fromUri.DisplayName, fromUri, null),
             /* Via will be added by the transport layer */
             new TSIP_HeaderCSeq((uint)cseq, method),
             String.IsNullOrEmpty(callId) ? null : new TSIP_HeaderCallId(callId),
             new TSIP_HeaderMaxForwards(TSIP_HeaderMaxForwards.TSIP_HEADER_MAX_FORWARDS_DEFAULT),
             /* Content-Length is mandatory for TCP. If both from and to are not null this means that it's a valid request */
            toUri != null && fromUri != null ? new TSIP_HeaderContentLength(0) : null,
         }
     );
 }
Exemplo n.º 21
0
 public static TSIP_Uri Clone(TSIP_Uri uri, Boolean with_params, Boolean with_quote)
 {
     String uriString = TSIP_Uri.Serialize(uri, with_params, with_params);
     return TSIP_ParserUri.Parse(uriString);
 }