예제 #1
0
bool pack_plain_text(const std::string &body,
                       short_msg_p_list::iterator &smsg)
{
	// START OF THE SIP PROCESSING
	osip_message_t *omsg = smsg->parsed;

	// Message body
	if (omsg->bodies.node != 0 && omsg->bodies.node->element != 0) {
		osip_body_t *bod1 = (osip_body_t *)omsg->bodies.node->element;
		osip_free(bod1->body);
		bod1->length = body.length();
		bod1->body = (char *)osip_malloc (bod1->length+1);
		strcpy(bod1->body, body.data());
	}
	// Let them know that parsed part has been changed.
	smsg->parsed_was_changed();

	// It's SC->MS now
	smsg->ms_to_sc = false;

	// Set Content-Type field
	const char *type = "text";
	const char *subtype = "plain";
	osip_free(smsg->parsed->content_type->type);
	osip_free(smsg->parsed->content_type->subtype);
	smsg->parsed->content_type->type = (char *)osip_malloc (strlen(type)+1);
	smsg->parsed->content_type->subtype = (char *)osip_malloc (strlen(subtype)+1);
	strcpy(smsg->parsed->content_type->type, type);
	strcpy(smsg->parsed->content_type->subtype, subtype);

	// Let them know that parsed part has been changed.
	smsg->parsed_was_changed();

	return true;
}
예제 #2
0
파일: smsc.cpp 프로젝트: 0x7678/openbts-uhd
bool pack_sms_for_delivery(short_msg_p_list::iterator &smsg)
{
	bool return_action = true;
	std::string msgtext;

	if (!smsg->need_repack) {
		// Nothing to do.
		return true;
	}

	// Parse message if not parsed yet.
	smsg->parse();

	// Get message text in plain text form
	msgtext = smsg->get_text();

	switch (smsg->content_type) {
	case short_msg::TEXT_PLAIN:
		return_action = pack_text_to_tpdu(msgtext, smsg);
		break;

	case short_msg::VND_3GPP_SMS:
		// No need to recode if it's SC->MS already
		if (smsg->ms_to_sc)
		{
			return_action = recode_tpdu(msgtext, smsg);
		}
		break;

	case short_msg::UNSUPPORTED_CONTENT:
	default:
		LOG(WARN) << "Unsupported SIP-messages content.";
		return false;
	}

	// Successful repack
	if (return_action) {
		smsg->need_repack = false;
	}

	if (ISLOGGING(DEBUG)) {
		// Call make_text_valid() is needed for debug only.
		smsg->make_text_valid();
		LOG(DEBUG) << "Updated SMS message: " << smsg->text;
	}

	return return_action;
}
예제 #3
0
파일: smsc.cpp 프로젝트: 0x7678/openbts-uhd
void pack_tpdu(short_msg_p_list::iterator &smsg)
{
	// Pack RP-DATA to bitstream
	RLFrame RPDU_new(smsg->rp_data->bitsNeeded());
	smsg->rp_data->write(RPDU_new);
	LOG(DEBUG) << "New RLFrame: " << RPDU_new;

	// START OF THE SIP PROCESSING
	osip_message_t *omsg = smsg->parsed;

	// Message body
	osip_body_t *bod1 = (osip_body_t *)omsg->bodies.node->element;
	osip_free(bod1->body);
	ostringstream body_stream;
	RPDU_new.hex(body_stream);
	bod1->length = body_stream.str().length();
	bod1->body = (char *)osip_malloc (bod1->length+1);
	strcpy(bod1->body, body_stream.str().data());

	// Let them know that parsed part has been changed.
	smsg->parsed_was_changed();

	// It's SC->MS now
	smsg->ms_to_sc = false;
}
예제 #4
0
void pack_tpdu(short_msg_p_list::iterator &smsg)
{
	// Pack RP-DATA to bitstream
	RLFrame RPDU_new(BitVector(smsg->rp_data->bitsNeeded()));
	smsg->rp_data->write(RPDU_new);
	LOG(DEBUG) << "New RLFrame: " << RPDU_new;

	// START OF THE SIP PROCESSING
	osip_message_t *omsg = smsg->parsed;

	// Message body
	LOG(DEBUG) << "omsg->bodies.node " << omsg->bodies.node
			<< " omsg->bodies.node->element " << omsg->bodies.node->element;

	// (pat 10-2014) FIXME: This should use base64 rather than hex encoding, but OpenBTS is the only peer and it doesnt care.
	// (harvind 11-2015) I fixed this below.  Now using the encoding in the SIP message.
	if (omsg->bodies.node != 0 && omsg->bodies.node->element != 0) {

		string encoding = "hex";        // (pat) Use hex if other encoding not explicitly specified for backward compatibility.
                static const char *cteHeader = "\r\nContent-Transfer-Encoding";
                char *contentTransferEncoding = strcasestr(smsg->text,cteHeader);
                if (contentTransferEncoding) {
                	char *cp = contentTransferEncoding + strlen(cteHeader);
                        while (isspace(*cp) || *cp == ':') { cp++; }
                        	encoding = smsg->scanWord(cp);
                }

		osip_body_t *bod1 = (osip_body_t *)omsg->bodies.node->element;
		osip_free(bod1->body);
		string errorMessage;
		string packet = RPDU_new.packToString();
		string body_stream = encodeToString(packet.data(),packet.size(),encoding,errorMessage);
		bod1->length = body_stream.size();
		bod1->body = (char *)osip_malloc (bod1->length+1);
		strcpy(bod1->body, body_stream.data());
	} else {
		LOG(DEBUG) << "String length zero";
	}

	// Let them know that parsed part has been changed.
	smsg->parsed_was_changed();
}
예제 #5
0
파일: smsc.cpp 프로젝트: 0x7678/openbts-uhd
void set_to_for_smsc(const char *address, short_msg_p_list::iterator &smsg)
{
	osip_message_t *omsg = smsg->parsed;

	// Set To field
	osip_free(omsg->to->url->username);
	osip_free(omsg->to->displayname);
	omsg->to->url->username = (char *)osip_malloc (strlen(address)+1);
	omsg->to->displayname = (char *)osip_malloc (strlen(omsg->req_uri->username)+1);
	strcpy(omsg->to->url->username, address);
	strcpy(omsg->to->displayname, omsg->req_uri->username);

	// Let them know that parsed part has been changed.
	smsg->parsed_was_changed();
}
예제 #6
0
bool pack_text_to_tpdu(const std::string &body,
                       short_msg_p_list::iterator &smsg)
{
	create_sms_delivery(body, TLUserData(body.data()), smsg);

	// Set Content-Type field
	const char *type = "application";
	const char *subtype = "vnd.3gpp.sms";
	osip_free(smsg->parsed->content_type->type);
	osip_free(smsg->parsed->content_type->subtype);
	smsg->parsed->content_type->type = (char *)osip_malloc (strlen(type)+1);
	smsg->parsed->content_type->subtype = (char *)osip_malloc (strlen(subtype)+1);
	strcpy(smsg->parsed->content_type->type, type);
	strcpy(smsg->parsed->content_type->subtype, subtype);

	// Let them know that parsed part has been changed.
	smsg->parsed_was_changed();

	return true;
}