Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send/receive text message mechanism through MESSAGE message #53

Merged
merged 1 commit into from Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 84 additions & 0 deletions resip/recon/InstantMessage.cxx
@@ -0,0 +1,84 @@
#include "ReconSubsystem.hxx"
#include "InstantMessage.hxx"

#include <rutil/Log.hxx>
#include <rutil/Logger.hxx>

#include <resip/dum/ClientPagerMessage.hxx>
#include <resip/dum/ServerPagerMessage.hxx>
#include <resip/stack/PlainContents.hxx>

#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<resip::Contents> 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.
*
* ====================================================================
*
*
*/

91 changes: 91 additions & 0 deletions resip/recon/InstantMessage.hxx
@@ -0,0 +1,91 @@
#if !defined(InstantMessage_hxx)
#define InstantMessage_hxx

#include <resip/dum/PagerMessageHandler.hxx>

#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<resip::Contents> 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.
*
* ====================================================================
*
*
*/

2 changes: 2 additions & 0 deletions resip/recon/Makefile.am
Expand Up @@ -34,6 +34,7 @@ librecon_la_SOURCES = BridgeMixer.cxx \
DefaultDialogSet.cxx \
DtmfEvent.cxx \
FlowManagerSipXSocket.cxx \
InstantMessage.cxx \
LocalParticipant.cxx \
MediaEvent.cxx \
MediaInterface.cxx \
Expand Down Expand Up @@ -66,6 +67,7 @@ nobase_reconinclude_HEADERS = ReconSubsystem.hxx \
RelatedConversationSet.hxx \
UserAgentServerAuthManager.hxx \
ConversationManagerCmds.hxx \
InstantMessage.hxx \
UserAgentMasterProfile.hxx \
RemoteParticipantDialogSet.hxx \
SipXHelper.hxx \
Expand Down
25 changes: 25 additions & 0 deletions resip/recon/UserAgent.cxx
Expand Up @@ -21,6 +21,9 @@
#include <resip/dum/ClientSubscription.hxx>
#include <resip/dum/ServerSubscription.hxx>
#include <resip/dum/ClientRegistration.hxx>
#include <resip/dum/ClientPagerMessage.hxx>
#include <resip/dum/ServerPagerMessage.hxx>
#include <resip/stack/PlainContents.hxx>
#include <resip/dum/KeepAliveManager.hxx>
#include <resip/dum/AppDialogSet.hxx>
#if defined(USE_SSL)
Expand Down Expand Up @@ -89,6 +92,10 @@ UserAgent::UserAgent(ConversationManager* conversationManager, SharedPtr<UserAge
mDum.addClientSubscriptionHandler("refer", mConversationManager);
mDum.addServerSubscriptionHandler("refer", mConversationManager);

InstantMessage* mInstantMessage = new recon::InstantMessage();
mDum.setServerPagerMessageHandler(mInstantMessage);
mDum.setClientPagerMessageHandler(mInstantMessage);

//mDum.addClientSubscriptionHandler(Symbols::Presence, this);
//mDum.addClientPublicationHandler(Symbols::Presence, this);
//mDum.addOutOfDialogHandler(NOTIFY, this);
Expand Down Expand Up @@ -452,6 +459,24 @@ UserAgent::onSubscriptionNotify(SubscriptionHandle handle, const Data& notifyDat
// Default implementation is to do nothing - application should override this
}

const char*
UserAgent::sendMessage(const NameAddr& destination, const Data& msg, const Mime& mimeType)
{
if(!mDum.getMasterProfile()->isMethodSupported(MESSAGE))
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if MESSAGE wasn't already in the MasterProfile, we wouldn't be able to receive MESSAGE requests. Please log a warning message here when this scenario is detected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this function is for sending messages, it would get here when a MESSAGE is received?

WarningLog (<< "MESSAGE method not detected in list of supported methods, adding it belatedly" );
mDum.getMasterProfile()->addSupportedMethod(MESSAGE);
}

ClientPagerMessageHandle cpmh = mDum.makePagerMessage(destination);
auto_ptr<Contents> msgContent(new PlainContents(msg, mimeType));
cpmh.get()->page(msgContent);
SharedPtr<SipMessage> sipMessage = cpmh.get()->getMessageRequestSharedPtr();
mDum.send(sipMessage);

return sipMessage->header(h_CallId).value().c_str();
}

void
UserAgent::shutdownImpl()
{
Expand Down
8 changes: 8 additions & 0 deletions resip/recon/UserAgent.hxx
Expand Up @@ -3,6 +3,7 @@

#include <boost/function.hpp>

#include "InstantMessage.hxx"
#include "ConversationManager.hxx"
#include "ConversationProfile.hxx"
#include "UserAgentMasterProfile.hxx"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -347,6 +353,8 @@ private:
resip::DialogUsageManager mDum;
resip::InterruptableStackThread mStackThread;
volatile bool mDumShutdown;

InstantMessage* mInstantMessage;
};

}
Expand Down