Exemplo n.º 1
0
        private void sipService_onMessagingEvent(object sender, MessagingEventArgs e)
        {
            switch (e.Type)
            {
                case MessagingEventTypes.INCOMING:
                    Win32ServiceManager.SharedManager.Dispatcher.Invoke((System.Threading.ThreadStart)delegate
                    {
                        MediaActionHanler.ReceiveShortMessage(e.GetExtra(MessagingEventArgs.EXTRA_REMOTE_PARTY) as String,
                            e.Payload, e.GetExtra(MessagingEventArgs.EXTRA_CONTENT_TYPE) as String);
                    }, null);

                    break;

                default:
                    break;
            }
        }
Exemplo n.º 2
0
            public override int ondata(T140CallbackData pData)
            {
                tmedia_t140_data_type_t pDataType = pData.getType();
                switch (pDataType)
                {
                    case tmedia_t140_data_type_t.tmedia_t140_data_type_utf8:
                        {
                            uint size = pData.getSize();
                            if (size > 0)
                            {
                                IntPtr ptr = Marshal.AllocHGlobal((int)size);
                                if (ptr != IntPtr.Zero)
                                {
                                    uint s;
                                    if ((s = pData.getData(ptr, size)) != 0)
                                    {
                                        byte[] content = new byte[(int)s];
                                        Marshal.Copy(ptr, content, 0, (int)s);
                                        MessagingEventArgs eargs = new MessagingEventArgs(mSession.Id, MessagingEventTypes.INCOMING, "T.140", content);
                                        eargs
                                            .AddExtra(MessagingEventArgs.EXTRA_REMOTE_PARTY, mSession.RemotePartyUri)
                                            .AddExtra(MessagingEventArgs.EXTRA_CONTENT_TYPE, ContentType.TEXT_PLAIN);
                                        mSession.Stack.SipService.RaiseEvent(eargs);
                                    }
                                    Marshal.FreeHGlobal(ptr);
                                }
                            }
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }

                return 0;
            }
Exemplo n.º 3
0
            /// <summary>
            /// Messaging events
            /// </summary>
            /// <param name="e"></param>
            /// <returns></returns>
            public override int OnMessagingEvent(MessagingEvent e)
            {
                tsip_message_event_type_t type = e.getType();

                switch (type)
                {
                    case tsip_message_event_type_t.tsip_ao_message:
                        break;

                    case tsip_message_event_type_t.tsip_i_message:
                        {
                            SipMessage message = e.getSipMessage();
                            MessagingSession session = e.getSession();
                            uint sessionId;

                            if (session == null)
                            {
                                /* "Server-side-session" e.g. Initial MESSAGE sent by the remote party */
                                session = e.takeSessionOwnership();
                            }

                            if (session == null)
                            {
                                LOG.Error("Failed to take session ownership");
                            }

                            if (message == null)
                            {
                                LOG.Error("Invalid message");

                                session.reject();
                                session.Dispose();
                                return 0;
                            }

                            sessionId = session.getId();
                            String from = message.getSipHeaderValue("f");
                            String contentType = message.getSipHeaderValue("c");
                            byte[] bytes = message.getSipContent();
                            byte[] content = null;

                            if (bytes == null || bytes.Length == 0)
                            {
                                LOG.Error("Invalid MESSAGE");
                                session.reject();
                                session.Dispose();
                                return 0;
                            }

                            // Send 200 OK
                            session.accept();
                            session.Dispose();

                            if (String.Equals(contentType, ContentType.SMS_3GPP, StringComparison.InvariantCultureIgnoreCase))
                            {
                                /* ==== 3GPP SMSIP  === */
                                byte[] buffer = (bytes.Clone() as byte[]);
                                SMSData smsData = SMSEncoder.decode(buffer, (uint)buffer.Length, false);
                                if (smsData != null){
                                    twrap_sms_type_t smsType = smsData.getType();
                                    if (smsType == twrap_sms_type_t.twrap_sms_type_rpdata){
                                        /* === We have received a RP-DATA message === */
                                        long payLength = smsData.getPayloadLength();
                                        String SMSC = message.getSipHeaderValue("P-Asserted-Identity");
                                        String SMSCPhoneNumber;
                                        String origPhoneNumber = smsData.getOA();

                                        /* Destination address */
                                        if(origPhoneNumber != null){
                                            from = UriUtils.GetValidSipUri(origPhoneNumber);
                                        }
                                        else if((origPhoneNumber = UriUtils.GetValidPhoneNumber(from)) == null){
                                            LOG.Error("Invalid destination address");
                                            return 0;
                                        }

                                        /* SMS Center
                                         * 3GPP TS 24.341 - 5.3.2.4	Sending a delivery report
                                         * The address of the IP-SM-GW is received in the P-Asserted-Identity header in the SIP MESSAGE
                                         * request including the delivered short message.
                                         * */
                                        if((SMSCPhoneNumber = UriUtils.GetValidPhoneNumber(SMSC)) == null){
                                            SMSC = this.sipService.manager.ConfigurationService.Get(Configuration.ConfFolder.RCS, Configuration.ConfEntry.SMSC, Configuration.DEFAULT_RCS_SMSC);
                                            if((SMSCPhoneNumber = UriUtils.GetValidPhoneNumber(SMSC)) == null){
                                                LOG.Error("Invalid IP-SM-GW address");
                                                return 0;
                                            }
                                        }

                                        if (payLength > 0) {
                                            /* Send RP-ACK */
                                            RPMessage rpACK = SMSEncoder.encodeACK(smsData.getMR(), SMSCPhoneNumber, origPhoneNumber, false);
                                            if (rpACK != null){
                                                long ack_len = rpACK.getPayloadLength();
                                                if (ack_len > 0){
                                                    buffer = new byte[(int)ack_len];
                                                    long len = rpACK.getPayload(buffer, (uint)buffer.Length);

                                                    MessagingSession m = new MessagingSession(this.sipService.SipStack);
                                                    m.setToUri(SMSC);
                                                    m.addHeader("Content-Type", ContentType.SMS_3GPP);
                                                    m.addHeader("Content-Transfer-Encoding", "binary");
                                                    m.addCaps("+g.3gpp.smsip");
                                                    m.send(buffer, (uint)len);
                                                    m.Dispose();
                                                }
                                                rpACK.Dispose();
                                            }

                                            /* Get ascii content */
                                            content = new byte[(int)payLength];
                                            smsData.getPayload(content, (uint)content.Length);
                                        }
                                        else{
                                            /* Send RP-ERROR */
                                            RPMessage rpError = SMSEncoder.encodeError(smsData.getMR(), SMSCPhoneNumber, origPhoneNumber, false);
                                            if (rpError != null){
                                                long err_len = rpError.getPayloadLength();
                                                if (err_len > 0){
                                                    buffer = new byte[(int)err_len];
                                                    long len = rpError.getPayload(buffer, (uint)buffer.Length);

                                                    MessagingSession m = new MessagingSession(this.sipService.SipStack);
                                                    m.setToUri(SMSC);
                                                    m.addHeader("Content-Type", ContentType.SMS_3GPP);
                                                    m.addHeader("Transfer-Encoding", "binary");
                                                    m.addCaps("+g.3gpp.smsip");
                                                    m.send(buffer, (uint)len);
                                                    m.Dispose();
                                                }
                                                rpError.Dispose();
                                            }
                                        }
                                    }
                                    else{
                                        /* === We have received any non-RP-DATA message === */
                                        if(smsType == twrap_sms_type_t.twrap_sms_type_ack){
                                            /* Find message from the history (by MR) an update it's status */
                                            LOG.Debug("RP-ACK");
                                        }
                                        else if(smsType == twrap_sms_type_t.twrap_sms_type_error){
                                            /* Find message from the history (by MR) an update it's status */
                                            LOG.Debug("RP-ERROR");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                /* ==== text/plain or any other  === */
                                content = bytes;
                            }

                            /* Alert the user a,d add the message to the history */
                            if (content != null)
                            {
                                MessagingEventArgs eargs = new MessagingEventArgs(sessionId, MessagingEventTypes.INCOMING, e.getPhrase(), content);
                                eargs
                                    .AddExtra(MessagingEventArgs.EXTRA_CODE, e.getCode())
                                    .AddExtra(MessagingEventArgs.EXTRA_REMOTE_PARTY, from)
                                    .AddExtra(MessagingEventArgs.EXTRA_CONTENT_TYPE, contentType == null ? ContentType.UNKNOWN : contentType);
                                EventHandlerTrigger.TriggerEvent<MessagingEventArgs>(this.sipService.onMessagingEvent, this.sipService, eargs);
                            }
                            break;
                        }
                }

                return 0;
            }