Click here to Skip to main content
15,889,096 members
Articles / Desktop Programming / MFC

An SMPPLIB with COM Support

Rate me:
Please Sign up or sign in to vote.
4.94/5 (25 votes)
27 Oct 20039 min read 332.1K   5.5K   87  
It is an SMPP implementation of v3.3 and v3.4 ( partial support). You can use it to connect to SMSC and send/receive SMS.
// SmppTransmitter.cpp: implementation of the CSmppTransmitter class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "SMPPAPI.h"
#include "EsmeTransmitter.h"
#include "smpppacket.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

#ifdef SMPPAPI_EVALUATION
	uint32 CEsmeTransmitter::m_eval_counter = 1;
#endif

CEsmeTransmitter::CEsmeTransmitter()
{
}

CEsmeTransmitter::~CEsmeTransmitter()
{

}

int CEsmeTransmitter::bind(CString sysid, CString passwd, CString systype, CSmppAddress &addrrange)
{
	bool ret = 1;

	m_system_id = sysid;
	m_password = passwd;
	m_system_type = systype;

	m_address_range = addrrange;

	if (open())
	{
		CBindTransmitter	pak;

		pak.setSystemId(sysid);
		pak.setPassword(passwd);
		pak.setSystemType(systype);

		pak.setSourceRange(addrrange);

		if(sendPacket(pak))
			ret = 0;
	}

	return ret;
}

int CEsmeTransmitter::submitMessage(CSubmitSM &pak)
{
	#ifdef SMPPAPI_EVALUATION
		m_eval_counter++;
		if (m_eval_counter > 200)
			return 1;
	#endif

	sendPacket(pak);

	return 0;
}

int CEsmeTransmitter::submitMessage(CString msg, CString dst, uint32 ton, uint32 npi)
{
	CSmppAddress dst_addr(ton, npi, dst);

	return submitMessage(msg, dst_addr);
}

int CEsmeTransmitter::submitMessage(CString msg, CSmppAddress &dst)
{
	CSubmitSM s;

	s.setMessage( (PBYTE) msg.GetBuffer(0), msg.GetLength());
	msg.ReleaseBuffer();

	s.setDestination(dst);
	s.setSource(m_address_range);

	return submitMessage(s);

}

int CEsmeTransmitter::submitMessage(PBYTE msg, uint32 msglen, uint32 enc, CSmppAddress &dst, uint32 esm)
{
		CSubmitSM s;

		s.setMessage(msg, msglen);
		s.setDestination(dst);
		s.setSource(m_address_range);
		s.setDataCoding(enc);
		s.setEsmClass(esm);

		return submitMessage(s);

}

void CEsmeTransmitter::parse_packet(PBYTE pby, int nsz)
{

	if (nsz < 16)
		return;

	uint32 cmdId = readInt(pby);

	TRACE1("CommandId is %x", cmdId);

	int cmdStatus = readInt(pby+4);
	int seqNum = readInt(pby+8);

	switch (cmdId)
	{
		case SMPP_GENERIC_NACK:
		{
			CGenericNack* ppak;
			ppak = new CGenericNack();
			ppak->loadPacket(pby, nsz);

			//call back
			if (m_pProcessPacket != NULL)
			{
				m_pProcessPacket(ppak, m_Param);
			}

			delete ppak;
		}
			break;

		case SMPP_SPECIAL_LINKCLOSE:
		{
			CLinkClose* ppak;
			ppak = new CLinkClose();
			ppak->loadPacket(pby, nsz);

			//call back
			if (m_pProcessPacket != NULL)
			{
				m_pProcessPacket(ppak, m_Param);
			}

			delete ppak;
		}
			break;

		case SMPP_BIND_TRANSMITTER_RESP:
		{
			CBindTransmitterResp* ppak;
			ppak = new CBindTransmitterResp();
			ppak->loadPacket(pby, nsz);

			//call back
			if (m_pProcessPacket != NULL)
			{
				m_pProcessPacket(ppak, m_Param);
			}

			delete ppak;
		}
			break;

		case SMPP_SUBMIT_SM_RESP:
		{
			CSubmitSMResp* ppak;
			ppak = new CSubmitSMResp();
			ppak->loadPacket(pby, nsz);

			//call back
			if (m_pProcessPacket != NULL)
			{
				m_pProcessPacket(ppak, m_Param);
			}

			delete ppak;
		}
			break;

		case SMPP_QUERY_SM_RESP:
		{
			CQuerySMResp* ppak;
			ppak = new CQuerySMResp();
			ppak->loadPacket(pby, nsz);

			//call back
			if (m_pProcessPacket != NULL)
			{
				m_pProcessPacket(ppak, m_Param);
			}

			delete ppak;
		}
			break;

		case SMPP_ENQUIRE_LINK:
		{
			CEnquireLink* ppak;
			ppak = new CEnquireLink();
			ppak->loadPacket(pby, nsz);

			//call back
			if (m_pProcessPacket != NULL)
			{
				m_pProcessPacket(ppak, m_Param);
			}

			delete ppak;
		}
			break;

		case SMPP_ENQUIRE_LINK_RESP:
		{
			CEnquireLinkResp* ppak;
			ppak = new CEnquireLinkResp();
			ppak->loadPacket(pby, nsz);

			//call back
			if (m_pProcessPacket != NULL)
			{
				m_pProcessPacket(ppak, m_Param);
			}

			delete ppak;
		}
			break;

		case SMPP_UNBIND_RESP:
		{
			CUnbindResp* ppak;
			ppak = new CUnbindResp();
			ppak->loadPacket(pby, nsz);

			//call back
			if (m_pProcessPacket != NULL)
			{
				m_pProcessPacket(ppak, m_Param);
			}

			delete ppak;
		}
			break;

		default:
			break;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Hong Kong Hong Kong
I'm a guy situated in Hong Kong with some knowledges in Java, VC++, C#, database, client-server, distributed, and mutithreaded computing and so on. I've been working in various companies as engineer, consultant, programmer.

Lately I was mainly working in banking & financial industries. Personally, I'm working on a trading application on my own now.

Comments and Discussions