MT#61140 DSM: add getters for headers

Introduce getters for headers in requests
and replies:
- `B2B.getHeaderRequest()`
- `B2B.getHeaderReply()`

Change-Id: I1dfc24658a9e044407f95de9507032f1b041b451
mr13.1
Donat Zenichev 2 years ago
parent a8c81152e9
commit bfa8ac09e6

@ -129,6 +129,11 @@ void DSMCall::onInvite(const AmSipRequest& req) {
AmB2BCallerSession::onInvite(req);
}
void DSMCall::onInvite2xx(const AmSipReply& reply) {
last_200_reply = reply;
AmB2BSession::onInvite2xx(reply);
}
void DSMCall::onOutgoingInvite(const string& headers) {
if (!process_invite) {
// re-INVITE sent out
@ -334,6 +339,8 @@ void DSMCall::onSipReply(const AmSipRequest& req,
const AmSipReply& reply,
AmBasicSipDialog::Status old_dlg_status)
{
/* update last reply for further usage with header getters */
last_200_reply = reply;
if (checkVar(DSM_ENABLE_REPLY_EVENTS, DSM_TRUE)) {
map<string, string> params;
@ -938,6 +945,14 @@ void DSMCall::B2BaddHeader(const string& hdr) {
invite_req.hdrs+="\r\n";
}
void DSMCall::B2BgetHeaderRequest(const string& hdr_name, string& out) {
out = getHeader(invite_req.hdrs, hdr_name, true);
}
void DSMCall::B2BgetHeaderReply(const string& hdr_name, string& out) {
out = getHeader(last_200_reply.hdrs, hdr_name, true);
}
void DSMCall::B2BclearHeaders() {
invite_req.hdrs.clear();
}

@ -75,6 +75,7 @@ public:
void onStart();
void onInvite(const AmSipRequest& req);
void onInvite2xx(const AmSipReply& reply);
void onOutgoingInvite(const string& headers);
void onRinging(const AmSipReply& reply);
void onEarlySessionStart();
@ -157,6 +158,8 @@ public:
void B2BclearHeaders();
void B2BaddHeader(const string& hdr);
void B2BremoveHeader(const string& hdr);
void B2BgetHeaderRequest(const string& hdr, string& out);
void B2BgetHeaderReply(const string& hdr, string& out);
};
class DSMCallCalleeSession : public AmB2BCalleeSession,

@ -145,6 +145,8 @@ DSMAction* DSMCoreModule::getAction(const string& from_str) {
DEF_CMD("B2B.sendReinvite", SCB2BReinviteAction);
DEF_CMD("B2B.enableEarlyMediaRelay", SCB2BEnableEarlyMediaRelayAction);
DEF_CMD("B2B.addHeader", SCB2BAddHeaderAction);
DEF_CMD("B2B.getHeaderRequest", SCB2BGetHeaderRequestAction);
DEF_CMD("B2B.getHeaderReply", SCB2BGetHeaderReplyAction);
DEF_CMD("B2B.removeHeader", SCB2BRemoveHeaderAction);
DEF_CMD("B2B.clearHeaders", SCB2BClearHeadersAction);
DEF_CMD("B2B.setHeaders", SCB2BSetHeadersAction);
@ -1548,6 +1550,42 @@ EXEC_ACTION_START(SCB2BAddHeaderAction) {
sc_sess->B2BaddHeader(val);
} EXEC_ACTION_END;
CONST_ACTION_2P(SCB2BGetHeaderRequestAction,',', false);
EXEC_ACTION_START(SCB2BGetHeaderRequestAction) {
string hdr_name = resolveVars(par1, sess, sc_sess, event_params);
string destination_variable = (par2.length() && par2[0] == '$') ? par2.substr(1) : par2;
string result;
if (hdr_name.empty() || destination_variable.empty())
throw DSMException("core", "cause", "parameters missing");
sc_sess->B2BgetHeaderRequest(hdr_name, result);
/* write only if we got something */
if (!result.empty())
sc_sess->var[destination_variable] = result;
else
DBG("No header with name '%s' found.\n", hdr_name.c_str());
} EXEC_ACTION_END;
CONST_ACTION_2P(SCB2BGetHeaderReplyAction,',', false);
EXEC_ACTION_START(SCB2BGetHeaderReplyAction) {
string hdr_name = resolveVars(par1, sess, sc_sess, event_params);
string destination_variable = (par2.length() && par2[0] == '$') ? par2.substr(1) : par2;
string result;
if (hdr_name.empty() || destination_variable.empty())
throw DSMException("core", "cause", "parameters missing");
sc_sess->B2BgetHeaderReply(hdr_name, result);
/* write only if we got something */
if (!result.empty())
sc_sess->var[destination_variable] = result;
else
DBG("No header with name '%s' found.\n", hdr_name.c_str());
} EXEC_ACTION_END;
EXEC_ACTION_START(SCB2BRemoveHeaderAction) {
string val = resolveVars(arg, sess, sc_sess, event_params);
DBG("removing B2B header '%s'\n", val.c_str());

@ -126,6 +126,8 @@ DEF_ACTION_2P(SCB2BReinviteAction);
DEF_ACTION_1P(SCB2BEnableEarlyMediaRelayAction);
DEF_ACTION_1P(SCB2BAddHeaderAction);
DEF_ACTION_2P(SCB2BGetHeaderRequestAction);
DEF_ACTION_2P(SCB2BGetHeaderReplyAction);
DEF_ACTION_1P(SCB2BClearHeadersAction);
DEF_ACTION_2P(SCB2BSetHeadersAction);
DEF_ACTION_1P(SCB2BRemoveHeaderAction);

@ -187,6 +187,12 @@ class DSMSession {
/** release ownership of object from this session instance */
virtual void releaseOwnership(DSMDisposable* d) = 0;
/** get header from request */
virtual void B2BgetHeaderRequest(const string& hdr, string& out) = 0;
/** get header from reply */
virtual void B2BgetHeaderReply(const string& hdr, string& out) = 0;
/* holds variables which are accessed by $varname */
VarMapT var;

@ -221,6 +221,8 @@ NOT_IMPLEMENTED(B2BsetRelayEarlyMediaSDP(bool enabled));
NOT_IMPLEMENTED(B2BsetHeaders(const string& hdr, bool replaceCRLF));
NOT_IMPLEMENTED(B2BclearHeaders());
NOT_IMPLEMENTED(B2BaddHeader(const string& hdr));
NOT_IMPLEMENTED(B2BgetHeaderRequest(const string& hdr, string& out));
NOT_IMPLEMENTED(B2BgetHeaderReply(const string& hdr, string& out));
NOT_IMPLEMENTED(B2BremoveHeader(const string& hdr));
#undef NOT_IMPLEMENTED

@ -90,6 +90,12 @@ class SystemDSM
/** set headers of outgoing INVITE */
void B2BsetHeaders(const string& hdr, bool replaceCRLF);
/** get header from request */
void B2BgetHeaderRequest(const string& hdr, string& out);
/** get header from reply */
void B2BgetHeaderReply(const string& hdr, string& out);
/** set headers of outgoing INVITE */
void B2BclearHeaders();

@ -746,6 +746,8 @@ NOT_IMPLEMENTED(B2BsetRelayEarlyMediaSDP(bool enabled));
NOT_IMPLEMENTED(B2BsetHeaders(const string& hdr, bool replaceCRLF));
NOT_IMPLEMENTED(B2BclearHeaders());
NOT_IMPLEMENTED(B2BaddHeader(const string& hdr));
NOT_IMPLEMENTED(B2BgetHeaderRequest(const string& hdr, string& out));
NOT_IMPLEMENTED(B2BgetHeaderReply(const string& hdr, string& out));
NOT_IMPLEMENTED(B2BremoveHeader(const string& hdr));
#undef NOT_IMPLEMENTED

@ -123,6 +123,8 @@ class SBCDSMInstance
void B2BsetHeaders(const string& hdr, bool replaceCRLF);
void B2BclearHeaders();
void B2BaddHeader(const string& hdr);
void B2BgetHeaderRequest(const string& hdr, string& out);
void B2BgetHeaderReply(const string& hdr, string& out);
void B2BremoveHeader(const string& hdr);
void transferOwnership(DSMDisposable* d);

@ -713,6 +713,9 @@ void AmB2BSession::onSipReply(const AmSipRequest& req, const AmSipReply& reply,
reply.cseq_method.c_str(), reply.code,reply.reason.c_str(),
fwd? "true" : "false", reply.body.getCTStr().c_str());
/* update last reply for further usage with header getters */
last_200_reply = reply;
if (to_tag_reset && !dlg->getRemoteTag().empty() && reply.code >= 180 && reply.code <= 183 ) {
DBG("onSipReply: sess %p received %i reply with remote-tag %s", this, reply.code, reply.to_tag.c_str());
DBG("dlg->getRemoteTag(%s)\n", dlg->getRemoteTag().c_str());
@ -807,6 +810,10 @@ void AmB2BSession::onInvite2xx(const AmSipReply& reply)
{
TransMap::iterator it = relayed_req.find(reply.cseq);
bool req_fwded = it != relayed_req.end();
/* update last reply for further usage with header getters */
last_200_reply = reply;
if(!req_fwded) {
DBG("req not fwded\n");
AmSession::onInvite2xx(reply);
@ -1299,6 +1306,9 @@ void AmB2BCallerSession::onB2BEvent(B2BEvent* ev)
AmSipReply& reply = ((B2BSipReplyEvent*)ev)->reply;
/* update last reply for further usage with header getters */
last_200_reply = reply;
if (getOtherId().empty()) {
DBG("B2BSipReply: other_id empty (reply code=%i; method=%s; callid=%s; from_tag=%s; to_tag=%s; cseq=%i)\n",
reply.code,reply.cseq_method.c_str(),reply.callid.c_str(),reply.from_tag.c_str(),

@ -186,6 +186,8 @@ private:
unsigned int est_invite_cseq;
unsigned int est_invite_other_cseq;
AmSipReply last_200_reply;
/** SUBSCRIBE/NOTIFY handling */
AmSipSubscription* subs;

Loading…
Cancel
Save