From 7dac246b2cb24c8e4649b54250cbdb4d2a6bc04d Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Tue, 18 Mar 2008 15:22:29 +0000 Subject: [PATCH] early media announcement with call continuation in b2b mode option git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@812 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/early_announce/EarlyAnnounce.cpp | 69 +++++++++++++-------- apps/early_announce/EarlyAnnounce.h | 6 +- apps/early_announce/etc/early_announce.conf | 6 ++ doc/Readme.early_announce | 21 ++++++- 4 files changed, 72 insertions(+), 30 deletions(-) diff --git a/apps/early_announce/EarlyAnnounce.cpp b/apps/early_announce/EarlyAnnounce.cpp index 387be796..aab2d44c 100644 --- a/apps/early_announce/EarlyAnnounce.cpp +++ b/apps/early_announce/EarlyAnnounce.cpp @@ -54,6 +54,8 @@ string EarlyAnnounceFactory::AnnouncePath; string EarlyAnnounceFactory::AnnounceFile; #endif +bool EarlyAnnounceFactory::ContinueB2B = false; + EarlyAnnounceFactory::EarlyAnnounceFactory(const string& _app_name) : AmSessionFactory(_app_name) { @@ -138,6 +140,12 @@ int EarlyAnnounceFactory::onLoad() // get application specific global parameters configureModule(cfg); + if (cfg.hasParameter("continue_b2b") && + cfg.getParameter("continue_b2b") == "yes") { + ContinueB2B = true; + DBG("early_announce in b2bua mode.\n"); + } + #ifdef USE_MYSQL /* Get default audio from MySQL */ @@ -303,6 +311,7 @@ AmSession* EarlyAnnounceFactory::onInvite(const AmSipRequest& req) EarlyAnnounceDialog::EarlyAnnounceDialog(const string& filename) : filename(filename) { + set_sip_relay_only(false); } EarlyAnnounceDialog::~EarlyAnnounceDialog() @@ -342,37 +351,45 @@ void EarlyAnnounceDialog::process(AmEvent* event) (audio_event->event_id == AmAudioEvent::cleared)) { DBG("AmAudioEvent::cleared\n"); - unsigned int code_i = 404; - string reason = "Not Found"; - - string iptel_app_param = getHeader(localreq.hdrs, PARAM_HDR); - if (iptel_app_param.length()) { - string code = get_header_keyvalue(iptel_app_param,"Final-Reply-Code"); - if (code.length() && str2i(code, code_i)) { - ERROR("while parsing Final-Reply-Code parameter\n"); - } - reason = get_header_keyvalue(iptel_app_param,"Final-Reply-Reason"); - } else { - string code = getHeader(localreq.hdrs,"P-Final-Reply-Code"); - if (code.length() && str2i(code, code_i)) { - ERROR("while parsing P-Final-Reply-Code\n"); - } - string h_reason = getHeader(localreq.hdrs,"P-Final-Reply-Reason"); - if (h_reason.length()) { - INFO("Use of P-Final-Reply-Code/P-Final-Reply-Reason is deprecated. "); - INFO("Use '%s: Final-Reply-Code=;" - "Final-Reply-Reason=' instead.\n",PARAM_HDR); - reason = h_reason; + + if (!EarlyAnnounceFactory::ContinueB2B) { + unsigned int code_i = 404; + string reason = "Not Found"; + + string iptel_app_param = getHeader(localreq.hdrs, PARAM_HDR); + if (iptel_app_param.length()) { + string code = get_header_keyvalue(iptel_app_param,"Final-Reply-Code"); + if (code.length() && str2i(code, code_i)) { + ERROR("while parsing Final-Reply-Code parameter\n"); + } + reason = get_header_keyvalue(iptel_app_param,"Final-Reply-Reason"); + } else { + string code = getHeader(localreq.hdrs,"P-Final-Reply-Code"); + if (code.length() && str2i(code, code_i)) { + ERROR("while parsing P-Final-Reply-Code\n"); + } + string h_reason = getHeader(localreq.hdrs,"P-Final-Reply-Reason"); + if (h_reason.length()) { + INFO("Use of P-Final-Reply-Code/P-Final-Reply-Reason is deprecated. "); + INFO("Use '%s: Final-Reply-Code=;" + "Final-Reply-Reason=' instead.\n",PARAM_HDR); + reason = h_reason; + } } - } - DBG("Replying with code %d %s\n", code_i, reason.c_str()); - dlg.reply(localreq, code_i, reason); + DBG("Replying with code %d %s\n", code_i, reason.c_str()); + dlg.reply(localreq, code_i, reason); - setStopped(); + setStopped(); + } else { + set_sip_relay_only(true); + recvd_req.insert(std::make_pair(localreq.cseq,localreq)); + + relayEvent(new B2BSipRequestEvent(localreq,true)); + } return; } - AmSession::process(event); + AmB2BCallerSession::process(event); } diff --git a/apps/early_announce/EarlyAnnounce.h b/apps/early_announce/EarlyAnnounce.h index b4912daf..ce510f9b 100644 --- a/apps/early_announce/EarlyAnnounce.h +++ b/apps/early_announce/EarlyAnnounce.h @@ -32,7 +32,7 @@ #include #endif -#include "AmSession.h" +#include "AmB2BSession.h" #include "AmAudioFile.h" #include "AmConfigReader.h" @@ -54,6 +54,8 @@ public: static string AnnounceFile; #endif + static bool ContinueB2B; + EarlyAnnounceFactory(const string& _app_name); int onLoad(); @@ -61,7 +63,7 @@ public: }; /** \brief session logic implementation for early_announce sessions */ -class EarlyAnnounceDialog : public AmSession +class EarlyAnnounceDialog : public AmB2BCallerSession { AmAudioFile wav_file; string filename; diff --git a/apps/early_announce/etc/early_announce.conf b/apps/early_announce/etc/early_announce.conf index 584982b2..f2ce52d6 100644 --- a/apps/early_announce/etc/early_announce.conf +++ b/apps/early_announce/etc/early_announce.conf @@ -5,3 +5,9 @@ announce_path=/usr/local/lib/sems/audio/ #CFGOPTION_SEMS_ANNOUNCEMENT default_announce=default_en.wav #ENDCFGOPTION + +# +# continue the call in B2BUA mode ? [yes | no] +# +# default: +# continue_b2b=no diff --git a/doc/Readme.early_announce b/doc/Readme.early_announce index 4b3ee6dd..f21ce8ed 100644 --- a/doc/Readme.early_announce +++ b/doc/Readme.early_announce @@ -9,12 +9,27 @@ The annoucement server plays a wav file to the caller in an early session: it replies to an invite with 183 Session Progress (with SDP), then sends the announcement and finally replies the request with a response (by default -404 Not found ). +404 Not found ), or, if b2bua mode is set, continues the call +to request-URI in b2bua more. -Session Parameters: +No b2bua mode: Final Reply sent +------------------------------- +Session Parameters (no b2bua mode): Final-Reply-Code integer (e.g. Final-Reply-Code=405 ) Final-Reply-Reason string (e.g. Final-Reply-Reason=Prohibited) +e.g. + append_hf("P-App-Param: Final-Reply-Code=405;Final-Reply-Reason=Prohibited;\r\n"); + +b2bua mode +---------- +If continue_b2b=yes is set in early_announce.conf, then the INVITE +is sent in a b2bua session to the original request-URI. From then on, +the call is continued as normal b2bua call, i.e. all requests and replies +are relayed into the other leg. + +Announcement file played from file system +----------------------------------------- If early_announce application was compiled WITHOUT -DUSE_MYSQL option, it searches for files to play following these rules: @@ -26,6 +41,8 @@ Example sems (early_announce.conf) configuration for file system audio: announce_path=wav/ default_announce=default_en.wav +Announcement file from MySQL DB +------------------------------- If early_announce application was compiled with -DUSE_MYSQL option, it supports third Session Parameter