diff --git a/resip/recon/InstantMessage.cxx b/resip/recon/InstantMessage.cxx new file mode 100644 index 0000000000..d5c9f88fa7 --- /dev/null +++ b/resip/recon/InstantMessage.cxx @@ -0,0 +1,84 @@ +#include "ReconSubsystem.hxx" +#include "InstantMessage.hxx" + +#include +#include + +#include +#include +#include + +#include "ReconSubsystem.hxx" +#include "UserAgent.hxx" + +using namespace recon; +using namespace resip; +using namespace std; + +#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON + +InstantMessage::InstantMessage() +{ + +} + +InstantMessage::~InstantMessage() +{ + +} + +void +InstantMessage::onMessageArrived(resip::ServerPagerMessageHandle handle, const resip::SipMessage& message) +{ + // Default implementation is to do nothing - application should override this +} + +void +InstantMessage::onSuccess(resip::ClientPagerMessageHandle handle, const resip::SipMessage& status) +{ + // Default implementation is to do nothing - application should override this +} + +void +InstantMessage::onFailure(resip::ClientPagerMessageHandle handle, const resip::SipMessage& status, std::auto_ptr contents) +{ + // Default implementation is to do nothing - application should override this +} + +/* ==================================================================== + * + * Copyright 2016 Mateus Bellomo https://mateusbellomo.wordpress.com/ All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. Neither the name of the author(s) nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * ==================================================================== + * + * + */ + diff --git a/resip/recon/InstantMessage.hxx b/resip/recon/InstantMessage.hxx new file mode 100644 index 0000000000..a87f11095e --- /dev/null +++ b/resip/recon/InstantMessage.hxx @@ -0,0 +1,91 @@ +#if !defined(InstantMessage_hxx) +#define InstantMessage_hxx + +#include + +#include "HandleTypes.hxx" + +namespace recon +{ + +/** + This class represents the Instant Message (IM) mechanism. + It was based on RFC 3428: + https://tools.ietf.org/html/rfc3428 + Author: Mateus Bellomo (mateusbellomo AT gmail DOT com) +*/ + +class InstantMessage : public resip::ServerPagerMessageHandler, + public resip::ClientPagerMessageHandler +{ + public: + InstantMessage(); + virtual ~InstantMessage(); + + /////////////////////////////////////////////////////////////////////// + // Pager Message Handlers ///////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////// + + /** + Callback used when received a MESSAGE SIP message + from the server. + @note An application should override this method. + */ + virtual void onMessageArrived(resip::ServerPagerMessageHandle handle, const resip::SipMessage& message); + + /** + Callback used when MESSAGE has been successfully sent + @note An application should override this method. + */ + virtual void onSuccess(resip::ClientPagerMessageHandle handle, const resip::SipMessage& status); + + /** + Callback used when a MESSAGE has been failed to send + @note An application should override this method. Application could re-page the failed contents or just ingore it. + */ + virtual void onFailure(resip::ClientPagerMessageHandle handle, const resip::SipMessage& status, std::auto_ptr contents); + +}; + +} + +#endif + + +/* ==================================================================== + * + * Copyright 2016 Mateus Bellomo https://mateusbellomo.wordpress.com/ All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. Neither the name of the author(s) nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * ==================================================================== + * + * + */ + diff --git a/resip/recon/Makefile.am b/resip/recon/Makefile.am index 9127301298..d5bb3b00fb 100644 --- a/resip/recon/Makefile.am +++ b/resip/recon/Makefile.am @@ -34,6 +34,7 @@ librecon_la_SOURCES = BridgeMixer.cxx \ DefaultDialogSet.cxx \ DtmfEvent.cxx \ FlowManagerSipXSocket.cxx \ + InstantMessage.cxx \ LocalParticipant.cxx \ MediaEvent.cxx \ MediaInterface.cxx \ @@ -66,6 +67,7 @@ nobase_reconinclude_HEADERS = ReconSubsystem.hxx \ RelatedConversationSet.hxx \ UserAgentServerAuthManager.hxx \ ConversationManagerCmds.hxx \ + InstantMessage.hxx \ UserAgentMasterProfile.hxx \ RemoteParticipantDialogSet.hxx \ SipXHelper.hxx \ diff --git a/resip/recon/UserAgent.cxx b/resip/recon/UserAgent.cxx index 35dda3216b..dd4441eeb2 100644 --- a/resip/recon/UserAgent.cxx +++ b/resip/recon/UserAgent.cxx @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include #include #include #if defined(USE_SSL) @@ -89,6 +92,10 @@ UserAgent::UserAgent(ConversationManager* conversationManager, SharedPtrisMethodSupported(MESSAGE)) + { + WarningLog (<< "MESSAGE method not detected in list of supported methods, adding it belatedly" ); + mDum.getMasterProfile()->addSupportedMethod(MESSAGE); + } + + ClientPagerMessageHandle cpmh = mDum.makePagerMessage(destination); + auto_ptr msgContent(new PlainContents(msg, mimeType)); + cpmh.get()->page(msgContent); + SharedPtr sipMessage = cpmh.get()->getMessageRequestSharedPtr(); + mDum.send(sipMessage); + + return sipMessage->header(h_CallId).value().c_str(); +} + void UserAgent::shutdownImpl() { diff --git a/resip/recon/UserAgent.hxx b/resip/recon/UserAgent.hxx index 3363c72385..b949f64478 100644 --- a/resip/recon/UserAgent.hxx +++ b/resip/recon/UserAgent.hxx @@ -3,6 +3,7 @@ #include +#include "InstantMessage.hxx" #include "ConversationManager.hxx" #include "ConversationProfile.hxx" #include "UserAgentMasterProfile.hxx" @@ -264,6 +265,11 @@ public: */ virtual void onSubscriptionTerminated(SubscriptionHandle handle, unsigned int statusCode); + /** + Used to send a MESSAGE SIP message. + */ + const char* sendMessage(const resip::NameAddr& destination, const resip::Data& msg, const resip::Mime& mimeType); + protected: // Shutdown Handler //////////////////////////////////////////////////////////// void onDumCanBeDeleted(); @@ -347,6 +353,8 @@ private: resip::DialogUsageManager mDum; resip::InterruptableStackThread mStackThread; volatile bool mDumShutdown; + + InstantMessage* mInstantMessage; }; }