Ejemplo n.º 1
0
        public bool SendBinaryMessage(String text, String SMSC)
        {
            String SMSCPhoneNumber;
            String dstPhoneNumber;
            String dstSipUri = base.ToUri;

            if ((SMSCPhoneNumber = UriUtils.GetValidPhoneNumber(SMSC)) != null && (dstPhoneNumber = UriUtils.GetValidPhoneNumber(dstSipUri)) != null)
            {
                base.ToUri = SMSC;
                this.session.addHeader("Content-Type", ContentType.SMS_3GPP);
                this.session.addHeader("Content-Transfer-Encoding", "binary");
                this.session.addCaps("+g.3gpp.smsip");

                RPMessage rpMessage;
                //if(ServiceManager.getConfigurationService().getBoolean(CONFIGURATION_SECTION.RCS, CONFIGURATION_ENTRY.HACK_SMS, false)){
                //    rpMessage = SMSEncoder.encodeDeliver(++ScreenSMSCompose.SMS_MR, SMSCPhoneNumber, dstPhoneNumber, new String(content));
                //    session.addHeader("P-Asserted-Identity", SMSC);
                //}
                //else{
                rpMessage = SMSEncoder.encodeSubmit(++MyMessagingSession.SMS_MR, SMSCPhoneNumber, dstPhoneNumber, text);
                //}

                long   rpMessageLen  = rpMessage.getPayloadLength();
                byte[] payload       = new byte[(int)rpMessageLen];
                uint   payloadLength = rpMessage.getPayload(payload, (uint)payload.Length);
                bool   ret           = this.session.send(payload, payloadLength);
                rpMessage.Dispose();
                if (MyMessagingSession.SMS_MR >= 255)
                {
                    MyMessagingSession.SMS_MR = 0;
                }

                return(ret);
            }
            else
            {
                LOG.Error(String.Format("SMSC={0} or RemoteUri={1} is invalid", SMSC, dstSipUri));
                return(this.SendTextMessage(text));
            }
        }
Ejemplo n.º 2
0
        public bool SendBinaryMessage(string text, string SMSC)
        {
            bool result;

            if (text == null)
            {
                result = false;
            }
            else
            {
                string dstSipUri = base.ToUri;
                string SMSCPhoneNumber;
                string dstPhoneNumber;
                if ((SMSCPhoneNumber = UriUtils.GetValidPhoneNumber(SMSC)) != null && (dstPhoneNumber = UriUtils.GetValidPhoneNumber(dstSipUri)) != null)
                {
                    base.ToUri = SMSC;
                    this.session.addHeader("Content-Type", "application/vnd.3gpp.sms");
                    this.session.addHeader("Content-Transfer-Encoding", "binary");
                    this.session.addHeader("Contact", string.Format("<{0};transport=udp>", this.fromUri));
                    RPMessage rpMessage = SMSEncoder.encodeSubmit(++MyMessageSession.SMS_MR, SMSCPhoneNumber, dstPhoneNumber, text);
                    bool      ret       = this.session.send(rpMessage.getPayload());
                    rpMessage.Dispose();
                    if (MyMessageSession.SMS_MR >= 255)
                    {
                        MyMessageSession.SMS_MR = 0;
                    }
                    result = ret;
                }
                else
                {
                    MyMessageSession.LOG.Error(string.Format("SMSC={0} or RemoteUri={1} is invalid", SMSC, dstSipUri));
                    result = this.SendTextMessage(text);
                }
            }
            return(result);
        }
Ejemplo 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);
            }