|
|
|
|
@ -60,6 +60,23 @@ bool DLGModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string replaceLineEnds(string input)
|
|
|
|
|
{
|
|
|
|
|
string result;
|
|
|
|
|
size_t last = 0;
|
|
|
|
|
size_t pos;
|
|
|
|
|
while ((pos = input.find("\\r\\n", last)) != string::npos) {
|
|
|
|
|
result += input.substr(last, pos-last);
|
|
|
|
|
result += "\r\n";
|
|
|
|
|
last = pos + 4;
|
|
|
|
|
}
|
|
|
|
|
if (!input.substr(last).empty()) {
|
|
|
|
|
result += input.substr(last);
|
|
|
|
|
result += "\r\n";
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo: convert errors to exceptions
|
|
|
|
|
void replyRequest(DSMSession* sc_sess, AmSession* sess,
|
|
|
|
|
EventParamT* event_params,
|
|
|
|
|
@ -67,6 +84,7 @@ void replyRequest(DSMSession* sc_sess, AmSession* sess,
|
|
|
|
|
const AmSipRequest& req) {
|
|
|
|
|
string code = resolveVars(par1, sess, sc_sess, event_params);
|
|
|
|
|
string reason = resolveVars(par2, sess, sc_sess, event_params);
|
|
|
|
|
string hdrs = replaceLineEnds(resolveVars("$dlg.reply.hdrs", sess, sc_sess, event_params));
|
|
|
|
|
unsigned int code_i;
|
|
|
|
|
if (str2i(code, code_i)) {
|
|
|
|
|
ERROR("decoding reply code '%s'\n", code.c_str());
|
|
|
|
|
@ -74,14 +92,9 @@ void replyRequest(DSMSession* sc_sess, AmSession* sess,
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sc_sess->last_req.get()) {
|
|
|
|
|
ERROR("no last request to reply\n");
|
|
|
|
|
sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL);
|
|
|
|
|
sc_sess->SET_STRERROR("no last request to reply");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DBG("replying with %i %s, hdrs='%s'\n", code_i, reason.c_str(), hdrs.c_str());
|
|
|
|
|
|
|
|
|
|
if (sess->dlg.reply(req, code_i, reason)) {
|
|
|
|
|
if (sess->dlg.reply(req, code_i, reason, "","", hdrs)) {
|
|
|
|
|
sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL);
|
|
|
|
|
sc_sess->SET_STRERROR("error sending reply");
|
|
|
|
|
} else
|
|
|
|
|
@ -90,6 +103,13 @@ void replyRequest(DSMSession* sc_sess, AmSession* sess,
|
|
|
|
|
|
|
|
|
|
CONST_ACTION_2P(DLGReplyAction, ',', true);
|
|
|
|
|
EXEC_ACTION_START(DLGReplyAction) {
|
|
|
|
|
if (!sc_sess->last_req.get()) {
|
|
|
|
|
ERROR("no last request to reply\n");
|
|
|
|
|
sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL);
|
|
|
|
|
sc_sess->SET_STRERROR("no last request to reply");
|
|
|
|
|
EXEC_ACTION_STOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
replyRequest(sc_sess, sess, event_params, par1, par2, *sc_sess->last_req.get());
|
|
|
|
|
} EXEC_ACTION_END;
|
|
|
|
|
|
|
|
|
|
@ -114,7 +134,7 @@ EXEC_ACTION_START(DLGAcceptInviteAction) {
|
|
|
|
|
unsigned int code_i=200;
|
|
|
|
|
string reason = "OK";
|
|
|
|
|
string code = resolveVars(par1, sess, sc_sess, event_params);
|
|
|
|
|
DBG("replying with code %s\n", code.c_str());
|
|
|
|
|
string hdrs = replaceLineEnds(resolveVars("$dlg.reply.hdrs", sess, sc_sess, event_params));
|
|
|
|
|
|
|
|
|
|
if (code.length()) {
|
|
|
|
|
reason = resolveVars(par2, sess, sc_sess, event_params);
|
|
|
|
|
@ -127,6 +147,8 @@ EXEC_ACTION_START(DLGAcceptInviteAction) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DBG("replying with %i %s, hdrs='%s'\n", code_i, reason.c_str(), hdrs.c_str());
|
|
|
|
|
|
|
|
|
|
if (!sc_sess->last_req.get()) {
|
|
|
|
|
ERROR("no last request to reply\n");
|
|
|
|
|
sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL);
|
|
|
|
|
@ -140,9 +162,9 @@ EXEC_ACTION_START(DLGAcceptInviteAction) {
|
|
|
|
|
sess->acceptAudio(sc_sess->last_req.get()->body,
|
|
|
|
|
sc_sess->last_req.get()->hdrs,&sdp_reply);
|
|
|
|
|
if(sess->dlg.reply(*sc_sess->last_req.get(),code_i, reason,
|
|
|
|
|
"application/sdp",sdp_reply) != 0)
|
|
|
|
|
"application/sdp",sdp_reply, hdrs) != 0)
|
|
|
|
|
throw AmSession::Exception(500,"could not send response");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}catch(const AmSession::Exception& e){
|
|
|
|
|
|
|
|
|
|
ERROR("%i %s\n",e.code,e.reason.c_str());
|
|
|
|
|
|