/// <summary> /// Event which fires when a message is received from elsewhere. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void activeSession_MessageReceived(object sender, MessagingEventArgs e) { string msg; try { msg = e.Message; if (msg != null) { msg = msg.Trim(); if (msg.StartsWith("<request>")) { try { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); System.Xml.XmlNode node; doc.LoadXml(msg); node = doc.SelectSingleNode("request/subject"); if (node != null) { this.subject = node.InnerText; this.Text = localize.RTCDLG_TEXTMSG_HELPREQUEST + " " + subject; } node = doc.SelectSingleNode("request/context"); if (node != null) { this.context = node.InnerXml; } } catch { // just ignore an error } } else { // conversationText.Rtf += "\n\\b" + participant.Name + " says:\\b0\n " + e.Message.Trim().Replace( @"\", @"\\" ); conversationText.Text += System.Environment.NewLine + String.Format(localize.RTCDLG_TEXTMSG_SAYS, participant.Name, msg) + System.Environment.NewLine; } } scrollToBottom(); sendText.Focus(); } catch (Exception exp) { conversationText.Text += localize.RTCDLG_ERRMSG_EXCEPTION + " " + exp.Message; } }
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; } }
private async void BackendMessageReceived(object sender, MessagingEventArgs e) { try { if (string.IsNullOrEmpty(e.Tag)) { await this.Transport.Send(e.Message); } else { await this.Transport.Send(e.Tag, e.Message); } } catch (Exception ex) { this.OnDiagnosticMessage($"Transport forwarder messaging error: " + ex.Message); } }
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); }
/// <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); }