Пример #1
0
// blocks until response is read
PDU SmppClient::readPduResponse(const uint32_t &sequence, const uint32_t &commandId)
{
	uint32_t response = GENERIC_NACK | commandId;
	list<PDU>::iterator it = pdu_queue.begin();

	while (it != pdu_queue.end()) {
		PDU pdu = (*it);

		if (pdu.getSequenceNo() == sequence && pdu.getCommandId() == response) {
			it = pdu_queue.erase(it);
			return pdu;
		}
		it++;
	}

	while (true) {
		PDU pdu = readPdu(true);
		if (!pdu.null) {
			if ((pdu.getSequenceNo() == sequence
					&& (pdu.getCommandId() == response || pdu.getCommandId() == GENERIC_NACK))
					|| (pdu.getSequenceNo() == 0 && pdu.getCommandId() == GENERIC_NACK)) return pdu;
		}
	}

	PDU pdu;
	return pdu;
}
Пример #2
0
PDU SmppClient::sendCommand(PDU &pdu)
{
	sendPdu(pdu);

	PDU resp = readPduResponse(pdu.getSequenceNo(), pdu.getCommandId());

	switch (resp.getCommandStatus()) {
		case smpp::ESME_RINVPASWD:
			throw smpp::InvalidPasswordException(smpp::getEsmeStatus(resp.getCommandStatus()));
			break;
		case smpp::ESME_RINVSYSID:
			throw smpp::InvalidSystemIdException(smpp::getEsmeStatus(resp.getCommandStatus()));
			break;
		case smpp::ESME_RINVSRCADR:
			throw smpp::InvalidSourceAddressException(smpp::getEsmeStatus(resp.getCommandStatus()));
			break;
		case smpp::ESME_RINVDSTADR:
			throw smpp::InvalidDestinationAddressException(smpp::getEsmeStatus(resp.getCommandStatus()));
			break;
	}

	if (resp.getCommandStatus() != smpp::ESME_ROK) throw smpp::SmppException(
			smpp::getEsmeStatus(resp.getCommandStatus()));

	return resp;
}
Пример #3
0
SMS SmppClient::readSms()
{
	// see if we're bound correct.
	checkState(BOUND_RX);

	// if  there are any messages in the queue pop the first usable one off and return it
	if (!pdu_queue.empty()) return parseSms();

	// fill queue until we get a DELIVER_SM command
	try {
		bool b = false;

		while (!b) {
			PDU pdu = readPdu(true);

			if (pdu.getCommandId() == ENQUIRE_LINK) {
				PDU resp = PDU(ENQUIRE_LINK_RESP, 0, pdu.getSequenceNo());
				sendPdu(resp);
				continue;
			}

			if (pdu.null) {
				break;
			}

			if (!pdu.null) pdu_queue.push_back(pdu); // save pdu for reading later
			b = pdu.getCommandId() == DELIVER_SM;
		}
	} catch (std::exception &e) {
		throw smpp::TransportException(e.what());
	}

	return parseSms();
}
Пример #4
0
void smpp::SmppClient::enquireLinkRespond()
{
	list<PDU>::iterator it = pdu_queue.begin();

	while (it != pdu_queue.end()) {
		PDU pdu = (*it);
		if (pdu.getCommandId() == ENQUIRE_LINK) {
			PDU resp = PDU(ENQUIRE_LINK_RESP, 0, pdu.getSequenceNo());
			sendCommand(resp);
		}
		it++;
	}

	PDU pdu = readPdu(false);

	if (!pdu.null && pdu.getCommandId() == ENQUIRE_LINK) {
		PDU resp = PDU(ENQUIRE_LINK_RESP, 0, pdu.getSequenceNo());
		sendPdu(resp);
	}
}