Exemplo n.º 1
0
        internal static AuthorizationHeader FromNative(osip_authorization_t *native)
        {
            var header = new AuthorizationHeader
            {
                AuthenticationType = Marshal.PtrToStringAnsi(native->auth_type),
                Username           = Marshal.PtrToStringAnsi(native->username),
                Realm      = Marshal.PtrToStringAnsi(native->realm),
                Nonce      = Marshal.PtrToStringAnsi(native->nonce),
                Uri        = Marshal.PtrToStringAnsi(native->uri),
                Response   = Marshal.PtrToStringAnsi(native->response),
                Digest     = Marshal.PtrToStringAnsi(native->digest),
                Algorithm  = Marshal.PtrToStringAnsi(native->algorithm),
                CNonce     = Marshal.PtrToStringAnsi(native->cnonce),
                Opaque     = Marshal.PtrToStringAnsi(native->opaque),
                MessageQop = Marshal.PtrToStringAnsi(native->message_qop),
                NonceCount = Marshal.PtrToStringAnsi(native->nonce_count),
                Version    = Marshal.PtrToStringAnsi(native->version),
                TargetName = Marshal.PtrToStringAnsi(native->targetname),
                GssApiData = Marshal.PtrToStringAnsi(native->gssapi_data),
                CRand      = Marshal.PtrToStringAnsi(native->crand),
                CNum       = Marshal.PtrToStringAnsi(native->cnum),
            };

            return(header);
        }
Exemplo n.º 2
0
        private static ErrorCode TryParseCore(string str, out AuthorizationHeader header)
        {
            osip_authorization_t *native = null;
            var strPtr = Marshal.StringToHGlobalAnsi(str);

            try
            {
                ErrorCode errorCode = NativeMethods.osip_authorization_init(&native);
                if (!errorCode.EnsureSuccess())
                {
                    header = null;
                    return(errorCode);
                }

                errorCode = NativeMethods.osip_authorization_parse(native, strPtr);
                if (!errorCode.EnsureSuccess())
                {
                    header = null;
                    return(errorCode);
                }

                header = FromNative(native);
                return(errorCode);
            }
            finally
            {
                NativeMethods.osip_authorization_free(native);
                Marshal.FreeHGlobal(strPtr);
            }
        }
Exemplo n.º 3
0
        public AuthorizationHeader DeepClone()
        {
            osip_authorization_t *native = ToNative();

            try
            {
                return(FromNative(native));
            }
            finally
            {
                NativeMethods.osip_authorization_free(native);
            }
        }
Exemplo n.º 4
0
        public override string ToString()
        {
            IntPtr ptr = IntPtr.Zero;
            osip_authorization_t *native = ToNative();

            try
            {
                NativeMethods.osip_authorization_to_str(native, &ptr).ThrowOnError();
                return(Marshal.PtrToStringAnsi(ptr));
            }
            finally
            {
                NativeMethods.osip_authorization_free(native);
                Marshal.FreeHGlobal(ptr);
            }
        }
Exemplo n.º 5
0
        private static T FromNative <T>(osip_message_t *native) where T : SipMessage, new ()
        {
            var message = new T
            {
                Version = Marshal.PtrToStringAnsi(native->sip_version),
                From    = native->from != osip_from_t.Null
                    ? NameAddressHeader.FromNative(native->from)
                    : null,
                To = native->to != osip_from_t.Null
                    ? NameAddressHeader.FromNative(native->to)
                    : null,
                CallId = native->call_id != osip_call_id_t.Null
                    ? CallIdHeader.FromNative(native->call_id)
                    : null,
                CSeq = native->cseq != osip_cseq_t.Null
                    ? CSeqHeader.FromNative(native->cseq)
                    : null,
                ContentType = native->content_type != osip_content_type_t.Null
                    ? ContentTypeHeader.FromNative(native->content_type)
                    : null,
                MimeVersion = native->mime_version != osip_content_length_t.Null
                    ? ContentLengthHeader.FromNative(native->mime_version)
                    : null
            };

            if (message is SipRequest request)
            {
                request.Method     = Marshal.PtrToStringAnsi(native->sip_method);
                request.RequestUri = native->req_uri != osip_uri_t.Null
                    ? SipUri.FromNative(native->req_uri)
                    : null;
            }
            else if (message is SipResponse response)
            {
                response.StatusCode   = native->status_code;
                response.ReasonPhrase = Marshal.PtrToStringAnsi(native->reason_phrase);
            }

            int size = NativeMethods.osip_list_size(&native->vias);

            for (int i = 0; i < size; i++)
            {
                osip_via_t *header = (osip_via_t *)NativeMethods.osip_list_get(&native->vias, i);
                message.Vias.Add(ViaHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->record_routes);
            for (int i = 0; i < size; i++)
            {
                osip_from_t *header = (osip_from_t *)NativeMethods.osip_list_get(&native->record_routes, i);
                message.RecordRoutes.Add(NameAddressHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->routes);
            for (int i = 0; i < size; i++)
            {
                osip_from_t *header = (osip_from_t *)NativeMethods.osip_list_get(&native->routes, i);
                message.Routes.Add(NameAddressHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->contacts);
            for (int i = 0; i < size; i++)
            {
                osip_from_t *header = (osip_from_t *)NativeMethods.osip_list_get(&native->contacts, i);
                message.Contacts.Add(NameAddressHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->authorizations);
            for (int i = 0; i < size; i++)
            {
                osip_authorization_t *header = (osip_authorization_t *)NativeMethods.osip_list_get(&native->authorizations, i);
                message.Authorizations.Add(AuthorizationHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->www_authenticates);
            for (int i = 0; i < size; i++)
            {
                osip_www_authenticate_t *header = (osip_www_authenticate_t *)NativeMethods.osip_list_get(&native->www_authenticates, i);
                message.WwwAuthenticates.Add(WwwAuthenticateHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->proxy_authenticates);
            for (int i = 0; i < size; i++)
            {
                osip_www_authenticate_t *header = (osip_www_authenticate_t *)NativeMethods.osip_list_get(&native->proxy_authenticates, i);
                message.ProxyAuthenticates.Add(WwwAuthenticateHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->proxy_authorizations);
            for (int i = 0; i < size; i++)
            {
                osip_authorization_t *header = (osip_authorization_t *)NativeMethods.osip_list_get(&native->proxy_authorizations, i);
                message.ProxyAuthorizations.Add(AuthorizationHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->call_infos);
            for (int i = 0; i < size; i++)
            {
                osip_call_info_t *header = (osip_call_info_t *)NativeMethods.osip_list_get(&native->call_infos, i);
                message.CallInfos.Add(CallInfoHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->allows);
            for (int i = 0; i < size; i++)
            {
                osip_content_length_t *header = (osip_content_length_t *)NativeMethods.osip_list_get(&native->allows, i);
                message.Allows.Add(ContentLengthHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->content_encodings);
            for (int i = 0; i < size; i++)
            {
                osip_content_length_t *header = (osip_content_length_t *)NativeMethods.osip_list_get(&native->content_encodings, i);
                message.ContentEncodings.Add(ContentLengthHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->alert_infos);
            for (int i = 0; i < size; i++)
            {
                osip_call_info_t *header = (osip_call_info_t *)NativeMethods.osip_list_get(&native->alert_infos, i);
                message.AlertInfos.Add(CallInfoHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->error_infos);
            for (int i = 0; i < size; i++)
            {
                osip_call_info_t *header = (osip_call_info_t *)NativeMethods.osip_list_get(&native->error_infos, i);
                message.ErrorInfos.Add(CallInfoHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->accepts);
            for (int i = 0; i < size; i++)
            {
                osip_content_type_t *header = (osip_content_type_t *)NativeMethods.osip_list_get(&native->accepts, i);
                message.Accepts.Add(ContentTypeHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->accept_encodings);
            for (int i = 0; i < size; i++)
            {
                osip_accept_encoding_t *header = (osip_accept_encoding_t *)NativeMethods.osip_list_get(&native->accept_encodings, i);
                message.AcceptEncodings.Add(AcceptEncodingHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->accept_languages);
            for (int i = 0; i < size; i++)
            {
                osip_accept_encoding_t *header = (osip_accept_encoding_t *)NativeMethods.osip_list_get(&native->accept_languages, i);
                message.AcceptLanguages.Add(AcceptEncodingHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->authentication_infos);
            for (int i = 0; i < size; i++)
            {
                osip_authentication_info_t *header = (osip_authentication_info_t *)NativeMethods.osip_list_get(&native->authentication_infos, i);
                message.AuthenticationInfos.Add(AuthenticationInfoHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->proxy_authentication_infos);
            for (int i = 0; i < size; i++)
            {
                osip_authentication_info_t *header = (osip_authentication_info_t *)NativeMethods.osip_list_get(&native->proxy_authentication_infos, i);
                message.ProxyAuthenticationInfos.Add(AuthenticationInfoHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->headers);
            for (int i = 0; i < size; i++)
            {
                osip_header_t *header = (osip_header_t *)NativeMethods.osip_list_get(&native->headers, i);
                message.OtherHeaders.Add(GenericHeader.FromNative(header));
            }

            size = NativeMethods.osip_list_size(&native->bodies);
            for (int i = 0; i < size; i++)
            {
                osip_body_t *header = (osip_body_t *)NativeMethods.osip_list_get(&native->bodies, i);
                message.Bodies.Add(SipBody.FromNative(header));
            }

            return(message);
        }
Exemplo n.º 6
0
        private osip_message_t *ToNative()
        {
            osip_message_t *native;

            NativeMethods.osip_message_init(&native).ThrowOnError();

            native->sip_version = Marshal.StringToHGlobalAnsi(Version);
            native->from        = From != null
                    ? From.ToNative()
                    : osip_from_t.Null;

            native->to = To != null
                    ? To.ToNative()
                    : osip_from_t.Null;

            native->call_id = CallId != null
                    ? CallId.ToNative()
                    : osip_call_id_t.Null;

            native->cseq = CSeq != null
                    ? CSeq.ToNative()
                    : osip_cseq_t.Null;

            native->content_type = ContentType != null
                    ? ContentType.ToNative()
                    : osip_content_type_t.Null;

            native->mime_version = MimeVersion != null
                    ? MimeVersion.ToNative()
                    : osip_content_length_t.Null;

            if (this is SipRequest request)
            {
                native->sip_method = native->sip_method = Marshal.StringToHGlobalAnsi(request.Method);
                native->req_uri    = request.RequestUri != null
                    ? request.RequestUri.ToNative()
                    : osip_uri_t.Null;
            }
            else if (this is SipResponse response)
            {
                native->status_code   = response.StatusCode;
                native->reason_phrase = Marshal.StringToHGlobalAnsi(response.ReasonPhrase);
            }

            for (int i = 0; i < Vias.Count; i++)
            {
                osip_via_t *header = Vias[i].ToNative();
                NativeMethods.osip_list_add(&native->vias, header, i).ThrowOnError();
            }

            for (int i = 0; i < RecordRoutes.Count; i++)
            {
                osip_from_t *header = RecordRoutes[i].ToNative();
                NativeMethods.osip_list_add(&native->record_routes, header, i).ThrowOnError();
            }

            for (int i = 0; i < Routes.Count; i++)
            {
                osip_from_t *header = Routes[i].ToNative();
                NativeMethods.osip_list_add(&native->routes, header, i).ThrowOnError();
            }

            for (int i = 0; i < Contacts.Count; i++)
            {
                osip_from_t *header = Contacts[i].ToNative();
                NativeMethods.osip_list_add(&native->contacts, header, i).ThrowOnError();
            }

            for (int i = 0; i < Authorizations.Count; i++)
            {
                osip_authorization_t *header = Authorizations[i].ToNative();
                NativeMethods.osip_list_add(&native->authorizations, header, i).ThrowOnError();
            }

            for (int i = 0; i < WwwAuthenticates.Count; i++)
            {
                osip_www_authenticate_t *header = WwwAuthenticates[i].ToNative();
                NativeMethods.osip_list_add(&native->www_authenticates, header, i).ThrowOnError();
            }

            for (int i = 0; i < ProxyAuthenticates.Count; i++)
            {
                osip_www_authenticate_t *header = ProxyAuthenticates[i].ToNative();
                NativeMethods.osip_list_add(&native->proxy_authenticates, header, i).ThrowOnError();
            }

            for (int i = 0; i < ProxyAuthorizations.Count; i++)
            {
                osip_authorization_t *header = ProxyAuthorizations[i].ToNative();
                NativeMethods.osip_list_add(&native->proxy_authorizations, header, i).ThrowOnError();
            }

            for (int i = 0; i < CallInfos.Count; i++)
            {
                osip_call_info_t *header = CallInfos[i].ToNative();
                NativeMethods.osip_list_add(&native->call_infos, header, i).ThrowOnError();
            }

            for (int i = 0; i < Allows.Count; i++)
            {
                osip_content_length_t *header = Allows[i].ToNative();
                NativeMethods.osip_list_add(&native->allows, header, i).ThrowOnError();
            }

            for (int i = 0; i < ContentEncodings.Count; i++)
            {
                osip_content_length_t *header = ContentEncodings[i].ToNative();
                NativeMethods.osip_list_add(&native->content_encodings, header, i).ThrowOnError();
            }

            for (int i = 0; i < AlertInfos.Count; i++)
            {
                osip_call_info_t *header = AlertInfos[i].ToNative();
                NativeMethods.osip_list_add(&native->alert_infos, header, i).ThrowOnError();
            }

            for (int i = 0; i < ErrorInfos.Count; i++)
            {
                osip_call_info_t *header = ErrorInfos[i].ToNative();
                NativeMethods.osip_list_add(&native->error_infos, header, i).ThrowOnError();
            }

            for (int i = 0; i < Accepts.Count; i++)
            {
                osip_content_type_t *header = Accepts[i].ToNative();
                NativeMethods.osip_list_add(&native->accepts, header, i).ThrowOnError();
            }

            for (int i = 0; i < AcceptEncodings.Count; i++)
            {
                osip_accept_encoding_t *header = AcceptEncodings[i].ToNative();
                NativeMethods.osip_list_add(&native->accept_encodings, header, i).ThrowOnError();
            }

            for (int i = 0; i < AcceptLanguages.Count; i++)
            {
                osip_accept_encoding_t *header = AcceptLanguages[i].ToNative();
                NativeMethods.osip_list_add(&native->accept_languages, header, i).ThrowOnError();
            }

            for (int i = 0; i < AuthenticationInfos.Count; i++)
            {
                osip_authentication_info_t *header = AuthenticationInfos[i].ToNative();
                NativeMethods.osip_list_add(&native->authentication_infos, header, i).ThrowOnError();
            }

            for (int i = 0; i < ProxyAuthenticationInfos.Count; i++)
            {
                osip_authentication_info_t *header = ProxyAuthenticationInfos[i].ToNative();
                NativeMethods.osip_list_add(&native->proxy_authentication_infos, header, i).ThrowOnError();
            }

            for (int i = 0; i < OtherHeaders.Count; i++)
            {
                osip_header_t *header = OtherHeaders[i].ToNative();
                NativeMethods.osip_list_add(&native->headers, header, i).ThrowOnError();
            }

            for (int i = 0; i < Bodies.Count; i++)
            {
                osip_body_t *header = Bodies[i].ToNative();
                NativeMethods.osip_list_add(&native->bodies, header, i).ThrowOnError();
            }

            return(native);
        }
 public static extern ErrorCode osip_authorization_clone(osip_authorization_t *header, osip_authorization_t **dest);
 public static extern void osip_authorization_free(osip_authorization_t *header);
 public static extern ErrorCode osip_authorization_to_str(osip_authorization_t *header, IntPtr *dest);
 public static extern ErrorCode osip_authorization_parse(osip_authorization_t *header, IntPtr hvalue);