示例#1
0
        internal TSIP_Dialog CreateDialog(TSIP_Dialog.tsip_dialog_type_t type, TSip_Session sipSession)
        {
            TSIP_Dialog dialog = null;

            switch (type)
            {
            case TSIP_Dialog.tsip_dialog_type_t.REGISTER:
            {
                dialog = new TSIP_DialogRegister(sipSession as TSIP_SessionRegister);
                break;
            }

            default:
            {
                TSK_Debug.Error("{0} not support as dialog type", type);
                break;
            }
            }

            if (dialog != null && !mDialogs.ContainsKey(dialog.Id))
            {
                mMutex.WaitOne();
                mDialogs.Add(dialog.Id, dialog);
                mMutex.ReleaseMutex();
            }

            return(dialog);
        }
        internal TSIP_Dialog CreateDialog(TSIP_Dialog.tsip_dialog_type_t type, TSip_Session sipSession)
        {
            TSIP_Dialog dialog = null;

            switch (type)
            {
                case TSIP_Dialog.tsip_dialog_type_t.REGISTER:
                    {
                        dialog = new TSIP_DialogRegister(sipSession as TSIP_SessionRegister);
                        break;
                    }

                default:
                    {
                        TSK_Debug.Error("{0} not support as dialog type", type);
                        break;
                    }
            }

            if (dialog != null && !mDialogs.ContainsKey(dialog.Id))
            {
                mMutex.WaitOne();
                mDialogs.Add(dialog.Id, dialog);
                mMutex.ReleaseMutex();
            }

            return dialog;
        }
示例#3
0
 private static Boolean IsNotSilentHangup(Object self, Object message)
 {
     return(!TSIP_DialogRegister.IsSilentHangup(self, message));
 }
 private static Boolean IsRegistering(Object self, Object message)
 {
     return(!TSIP_DialogRegister.IsUnregistering(self, message));
 }
示例#5
0
        // this function is only called if no transaction match
        // for responses, the transaction will always match
        internal Boolean HandleIncomingMessage(TSIP_Message message)
        {
            TSIP_Dialog  dialog  = null;
            TSIP_Transac transac = null;
            Boolean      cid_matched;
            Boolean      ret = false;

            dialog = this.FindDialog(message.CallId.Value,
                                     message.IsResponse ? message.To.Tag : message.From.Tag,
                                     message.IsResponse ? message.From.Tag : message.To.Tag,
                                     message.IsRequest ? (message as TSIP_Request).RequestType : TSIP_Message.tsip_request_type_t.NONE,
                                     out cid_matched);

            if (dialog != null)
            {
                if (message.IsCANCEL || message.IsACK)
                {
                    ret = dialog.RaiseCallback(TSIP_Dialog.tsip_dialog_event_type_t.I_MSG, message);
                    goto bail;
                }
                else
                {
                    transac = mStack.LayerTransac.CreateTransac(false, message, dialog);
                }
            }
            else
            {
                if (message.IsRequest)
                {
                    TSIP_Dialog newdialog = null;

                    switch ((message as TSIP_Request).RequestType)
                    {
                    case TSIP_Message.tsip_request_type_t.REGISTER:
                    {
                        /* incoming REGISTER */
                        TSIP_SessionRegister session = new TSIP_SessionRegister(mStack, message);
                        newdialog = new TSIP_DialogRegister(session, message.CallId == null ? null : message.CallId.Value);
                        break;
                    }
                    }

                    // for new dialog, create a new transac and start it later
                    if (newdialog != null)
                    {
                        transac = mStack.LayerTransac.CreateTransac(false, message, newdialog);
                        this.AddDialog(newdialog);
                    }
                }
            }

            if (transac != null)
            {
                ret = transac.Start((message as TSIP_Request));
            }
            else if (message.IsRequest) /* No transaction match for the SIP request */
            {
                TSIP_Response response = null;

                if (cid_matched) /* We are receiving our own message. */
                {
                    response = new TSIP_Response(482, "Loop Detected (Check your iFCs)", (message as TSIP_Request));
                    if (String.IsNullOrEmpty(response.To.Tag))/* Early dialog? */
                    {
                        response.To.Tag = "doubango";
                    }
                }
                else
                {
                    switch ((message as TSIP_Request).RequestType)
                    {
                    case TSIP_Message.tsip_request_type_t.OPTIONS:     // Hacked to work on Tiscali IMS networks
                    case TSIP_Message.tsip_request_type_t.INFO:
                    {
                        response = new TSIP_Response(405, "Method Not Allowed", (message as TSIP_Request));
                        break;
                    }

                    default:
                    {
                        response = new TSIP_Response(481, "Dialog/Transaction Does Not Exist", (message as TSIP_Request));
                        break;
                    }
                    }
                }

                if (response != null)
                {
                    // send the response
                    ret = mStack.LayerTransport.SendMessage(response.FirstVia != null ? response.FirstVia.Branch : "no-branch", response);
                }
            }

bail:
            return(ret);
        }
        // this function is only called if no transaction match
        // for responses, the transaction will always match
        internal Boolean HandleIncomingMessage(TSIP_Message message)
        {
            TSIP_Dialog dialog = null;
            TSIP_Transac transac = null;
            Boolean cid_matched;
            Boolean ret = false;

            dialog = this.FindDialog(message.CallId.Value,
                message.IsResponse ? message.To.Tag : message.From.Tag,
                message.IsResponse ? message.From.Tag : message.To.Tag,
                message.IsRequest ? (message as TSIP_Request).RequestType : TSIP_Message.tsip_request_type_t.NONE,
                out cid_matched);

            if (dialog != null)
            {
                if (message.IsCANCEL || message.IsACK)
                {
                    ret = dialog.RaiseCallback(TSIP_Dialog.tsip_dialog_event_type_t.I_MSG, message);
                    goto bail;
                }
                else
                {
                    transac = mStack.LayerTransac.CreateTransac(false, message, dialog);
                }
            }
            else
            {
                if (message.IsRequest)
                {
                    TSIP_Dialog newdialog = null;

                    switch ((message as TSIP_Request).RequestType)
                    {
                        case TSIP_Message.tsip_request_type_t.REGISTER:
                            {
                                /* incoming REGISTER */
                                TSIP_SessionRegister session = new TSIP_SessionRegister(mStack, message);
                                newdialog = new TSIP_DialogRegister(session, message.CallId == null ? null : message.CallId.Value);
                                break;
                            }
                    }

                    // for new dialog, create a new transac and start it later
                    if (newdialog != null)
                    {
                        transac = mStack.LayerTransac.CreateTransac(false, message, newdialog);
                        this.AddDialog(newdialog);
                    }
                }
            }

            if (transac != null)
            {
                ret = transac.Start((message as TSIP_Request));
            }
            else if (message.IsRequest) /* No transaction match for the SIP request */
            {
                TSIP_Response response = null;

                if (cid_matched) /* We are receiving our own message. */
                {
                    response = new TSIP_Response(482, "Loop Detected (Check your iFCs)", (message as TSIP_Request));
                    if (String.IsNullOrEmpty(response.To.Tag))/* Early dialog? */
                    {
                        response.To.Tag = "doubango";
                    }
                }
                else
                {
                    switch ((message as TSIP_Request).RequestType)
                    {
                        case TSIP_Message.tsip_request_type_t.OPTIONS: // Hacked to work on Tiscali IMS networks
                        case TSIP_Message.tsip_request_type_t.INFO:
                            {
                                response = new TSIP_Response(405, "Method Not Allowed", (message as TSIP_Request));
                                break;
                            }
                        default:
                            {
                                response = new TSIP_Response(481, "Dialog/Transaction Does Not Exist", (message as TSIP_Request));
                                break;
                            }
                    }
                }

                if (response != null)
                {
                    // send the response
                    ret = mStack.LayerTransport.SendMessage(response.FirstVia != null ? response.FirstVia.Branch : "no-branch", response);
                }
            }

            bail:
            return ret;
        }