Example #1
0
        private static ErrorCode TryParseCore(string str, out CallIdHeader header)
        {
            osip_call_id_t *native = null;
            var             strPtr = Marshal.StringToHGlobalAnsi(str);

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

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

                header = FromNative(native);
                return(errorCode);
            }
            finally
            {
                NativeMethods.osip_call_id_free(native);
                Marshal.FreeHGlobal(strPtr);
            }
        }
Example #2
0
        private static ErrorCode TryParseCore(IntPtr ptr, ulong length, out SipMessage message)
        {
            osip_message_t *native = null;

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

                errorCode = NativeMethods.osip_message_parse(native, ptr, length);
                if (!errorCode.EnsureSuccess())
                {
                    message = null;
                    return(errorCode);
                }

                message = native->status_code == 0
                    ? FromNative <SipRequest>(native)
                    : (SipMessage)FromNative <SipResponse>(native);
                return(errorCode);
            }
            finally
            {
                NativeMethods.osip_message_free(native);
            }
        }
Example #3
0
        private static ErrorCode TryParseCore(string str, out SipBody body)
        {
            osip_body_t *native = null;
            var          strPtr = Marshal.StringToHGlobalAnsi(str);

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

                errorCode = NativeMethods.osip_body_parse(native, strPtr, (ulong)str.Length);
                if (!errorCode.EnsureSuccess())
                {
                    body = null;
                    return(errorCode);
                }

                body = FromNative(native);
                return(errorCode);
            }
            finally
            {
                NativeMethods.osip_body_free(native);
                Marshal.FreeHGlobal(strPtr);
            }
        }
Example #4
0
        private static ErrorCode TryParseCore(string str, out SipUri uri)
        {
            var         strPtr = Marshal.StringToHGlobalAnsi(str);
            osip_uri_t *native = null;

            try
            {
                ErrorCode errorCode = NativeMethods.osip_uri_init(&native);
                if (!errorCode.EnsureSuccess())
                {
                    uri = default;
                    return(errorCode);
                }

                errorCode = NativeMethods.osip_uri_parse(native, strPtr);
                if (!errorCode.EnsureSuccess())
                {
                    uri = default;
                    return(errorCode);
                }

                uri = FromNative(native);
                return(errorCode);
            }
            finally
            {
                NativeMethods.osip_uri_free(native);
                Marshal.FreeHGlobal(strPtr);
            }
        }