internal static NameAddressHeader FromNative(osip_from_t *native)
        {
            var header = new NameAddressHeader
            {
                DisplayName = Marshal.PtrToStringAnsi(native->displayname),
                Url         = native->url != osip_uri_t.Null
                    ? SipUri.FromNative(native->url)
                    : null
            };

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

            for (int i = 0; i < size; i++)
            {
                osip_uri_param_t *param = (osip_uri_param_t *)NativeMethods.osip_list_get(&native->gen_params, i);
                header.Parameters.Add(GenericParameter.FromNative(param));
            }

            return(header);
        }
Exemple #2
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);
        }
Exemple #3
0
 public static bool TryParse(string str, out SipUri uri)
 {
     return(TryParseCore(str, out uri).EnsureSuccess());
 }