コード例 #1
0
        private VATRPCallEvent ParseLinphoneCallLog(IntPtr callLogPtr)
        {
            LinphoneCallDir direction = LinphoneAPI.linphone_call_log_get_dir(callLogPtr);
            IntPtr          tmpPtr    = LinphoneAPI.linphone_call_log_get_remote_address(callLogPtr);

            if (tmpPtr == IntPtr.Zero)
            {
                return(null);
            }

            //  4/11 MITRE-fjr Throws Exception, Added Catch
            try
            {
                tmpPtr = LinphoneAPI.linphone_address_as_string(tmpPtr);

                // 4/11 try ?? LinphoneAddress _linphoneAddress = LinphoneAPI.linphone_address_as_string(tmpPtr);
                if (tmpPtr == IntPtr.Zero)
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.InnerException);
                return(null);
            }



            var remoteParty = Marshal.PtrToStringAnsi(tmpPtr);

            LinphoneAPI.ortp_free(tmpPtr);

            string dn = "", un = "", host = "";
            int    port = 0;

            VATRPCall.ParseSipAddressEx(remoteParty, out dn, out un, out host,
                                        out port);
            if (string.IsNullOrEmpty(un))
            {
                return(null);
            }

            remoteParty = port == 0 ? string.Format("sip:{0}@{1}", un, host) :
                          string.Format("sip:{0}@{1}:{2}", un, host, port);
            var callevent = new VATRPCallEvent("", remoteParty)
            {
                DisplayName = dn,
                Username    = un
            };

            tmpPtr = LinphoneAPI.linphone_call_log_get_call_id(callLogPtr);
            if (tmpPtr != IntPtr.Zero)
            {
                callevent.CallGuid = Marshal.PtrToStringAnsi(tmpPtr);
            }
            callevent.StartTime =
                new DateTime(1970, 1, 1).AddSeconds(LinphoneAPI.linphone_call_log_get_start_date(callLogPtr));
            callevent.EndTime =
                callevent.StartTime.AddSeconds(
                    Convert.ToInt32(LinphoneAPI.linphone_call_log_get_duration(callLogPtr)));
            switch (LinphoneAPI.linphone_call_log_get_status(callLogPtr))
            {
            case LinphoneCallStatus.LinphoneCallSuccess:
            {
                callevent.Status = direction == LinphoneCallDir.LinphoneCallIncoming
                        ? VATRPHistoryEvent.StatusType.Incoming
                        : VATRPHistoryEvent.StatusType.Outgoing;
            }
            break;

            case LinphoneCallStatus.LinphoneCallAborted:
                callevent.Status = VATRPHistoryEvent.StatusType.Failed;
                break;

            case LinphoneCallStatus.LinphoneCallDeclined:
                callevent.Status = VATRPHistoryEvent.StatusType.Rejected;
                break;

            case LinphoneCallStatus.LinphoneCallMissed:
                callevent.Status = VATRPHistoryEvent.StatusType.Missed;
                break;
            }
            return(callevent);
        }