diff --git a/apps/Makefile b/apps/Makefile index 38f33769..e0bbced4 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,7 +1,7 @@ COREPATH ?= ../core include $(COREPATH)/Makefile.defs -exclude_modules = mp3 +exclude_modules = mp3 announce_auth modules = $(filter-out $(exclude_modules) \ $(wildcard Makefile*) CVS, \ $(wildcard *) ) diff --git a/apps/announce_auth/Announcement.cpp b/apps/announce_auth/Announcement.cpp new file mode 100644 index 00000000..757e459b --- /dev/null +++ b/apps/announce_auth/Announcement.cpp @@ -0,0 +1,201 @@ +/* + * $Id: Announcement.cpp,v 1.7.8.4 2005/08/31 13:54:29 rco Exp $ + * + * Copyright (C) 2002-2003 Fhg Fokus + * Copyright (C) 2006 iptego GmbH + * + * This file is part of sems, a free SIP media server. + * + * sems is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * For a license to use the sems software under conditions + * other than those described here, or to purchase support for this + * software, please contact iptel.org by e-mail at the following addresses: + * info@iptel.org + * + * sems is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Announcement.h" +#include "AmConfig.h" +#include "AmUtils.h" + +#include "sems.h" +#include "log.h" + +#include "../../core/plug-in/uac_auth/UACAuth.h" +#include "AmUAC.h" +#include "AmPlugIn.h" + +#define MOD_NAME "announce_auth" + +EXPORT_SESSION_FACTORY(AnnounceAuthFactory,MOD_NAME); + +string AnnounceAuthFactory::AnnouncePath; +string AnnounceAuthFactory::AnnounceFile; + +AnnounceAuthFactory::AnnounceAuthFactory(const string& _app_name) + : AmSessionFactory(_app_name) +{ +} + +int AnnounceAuthFactory::onLoad() +{ + AmConfigReader cfg; + if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) + return -1; + + // get application specific global parameters + configureModule(cfg); + + AnnouncePath = cfg.getParameter("announce_path",ANNOUNCE_PATH); + if( !AnnouncePath.empty() + && AnnouncePath[AnnouncePath.length()-1] != '/' ) + AnnouncePath += "/"; + + AnnounceFile = cfg.getParameter("default_announce",ANNOUNCE_FILE); + + string announce_file = AnnouncePath + AnnounceFile; + if(!file_exists(announce_file)){ + ERROR("default file for ann_b2b module does not exist ('%s').\n", + announce_file.c_str()); + return -1; + } + + + auth_realm = cfg.getParameter("auth_realm", ""); + auth_user = cfg.getParameter("auth_user", ""); + auth_pwd = cfg.getParameter("auth_pwd", ""); + + uac_auth_f = AmPlugIn::instance()->getFactory4Seh("uac_auth"); + DBG("uac_auth_f == 0x%.16lX\n",(unsigned long)uac_auth_f); + + dialer.set_dial(cfg.getParameter("dial_ruri","default ruri"), + cfg.getParameter("dial_from","default from"), + cfg.getParameter("dial_fromuri","default fromuri"), + cfg.getParameter("dial_to","default to")); + + dialer.start(); + + return 0; +} + +AmSession* AnnounceAuthFactory::onInvite(const AmSipRequest& req) +{ + string announce_path = AnnouncePath; + string announce_file = announce_path + req.domain + + "/" + req.user + ".wav"; + + DBG("trying '%s'\n",announce_file.c_str()); + if(file_exists(announce_file)) + goto end; + + announce_file = announce_path + req.user + ".wav"; + DBG("trying '%s'\n",announce_file.c_str()); + if(file_exists(announce_file)) + goto end; + + announce_file = AnnouncePath + AnnounceFile; + +end: + AnnouncementDialog* dlg = new AnnouncementDialog(announce_file, + auth_realm, + auth_user, + auth_pwd); + + if (uac_auth_f != NULL) { + DBG("UAC Auth enabled for new announcement session.\n"); + AmSessionEventHandler* h = uac_auth_f->getHandler(dlg); + if (h != NULL ) + dlg->addHandler(h); + } + + return dlg; +} + +AnnouncementDialog::AnnouncementDialog(const string& filename, + const string& auth_realm, + const string& auth_user, + const string& auth_pwd) + : filename(filename), + CredentialHolder(auth_realm, auth_user, auth_pwd) +{ + +} + +AnnouncementDialog::~AnnouncementDialog() +{ +} + +void AnnouncementDialog::onSessionStart(const AmSipRequest& req) +{ + DBG("AnnouncementDialog::onSessionStart\n"); + startSession(); +} + +void AnnouncementDialog::onSessionStart(const AmSipReply& rep) +{ + DBG("AnnouncementDialog::onSessionStart (SEMS originator mode)\n"); + startSession(); +} + +void AnnouncementDialog::startSession(){ + if(wav_file.open(filename,AmAudioFile::Read)) + throw string("AnnouncementDialog::onSessionStart: Cannot open file\n"); + + setOutput(&wav_file); +} + +void AnnouncementDialog::onBye(const AmSipRequest& req) +{ + DBG("onBye: stopSession\n"); + setStopped(); +} + + +void AnnouncementDialog::process(AmEvent* event) +{ + + AmAudioEvent* audio_event = dynamic_cast(event); + if(audio_event && (audio_event->event_id == AmAudioEvent::cleared)){ + dlg.bye(); + setStopped(); + return; + } + + AmSession::process(event); +} + +void DialerThread::set_dial(const string& r, const string& f, + const string& fu, const string& t) { + r_uri = r; + from = f; + from_uri = fu; + to = t; +} + +void DialerThread::run() { + sleep(5); // wait for sems to completely start up + while (!is_stopped()) { + DBG("dialing..."); + AmUAC::dialout("blibla", "announce_auth", + r_uri, from, from_uri, to); + // every 10 minutes + sleep(600); + + } +} + +void DialerThread::on_stop() { + DBG("stopping...\n"); +} diff --git a/apps/announce_auth/Announcement.h b/apps/announce_auth/Announcement.h new file mode 100644 index 00000000..60a3b4f0 --- /dev/null +++ b/apps/announce_auth/Announcement.h @@ -0,0 +1,101 @@ +/* + * $Id: Announcement.h,v 1.6.8.1 2005/06/01 12:00:24 rco Exp $ + * + * Copyright (C) 2002-2003 Fhg Fokus + * Copyright (C) 2006 iptego GmbH + * + * This file is part of sems, a free SIP media server. + * + * sems is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * For a license to use the sems software under conditions + * other than those described here, or to purchase support for this + * software, please contact iptel.org by e-mail at the following addresses: + * info@iptel.org + * + * sems is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _ANNOUNCEAUTH_H_ +#define _ANNOUNCEAUTH_H_ + +#include "AmSession.h" +#include "AmConfigReader.h" + +#include "../../core/plug-in/uac_auth/UACAuth.h" + +#include +using std::string; + +class DialerThread : public AmThread { + string r_uri; + string from; + string from_uri; + string to; +protected: + void run(); + void on_stop(); +public: + void set_dial(const string& r, const string& f, + const string& fu, const string& t); + + +}; + +class AnnounceAuthFactory: public AmSessionFactory +{ + DialerThread dialer; + AmSessionEventHandlerFactory* uac_auth_f; + + string auth_realm; + string auth_user; + string auth_pwd; + +public: + static string AnnouncePath; + static string AnnounceFile; + + AnnounceAuthFactory(const string& _app_name); + + int onLoad(); + AmSession* onInvite(const AmSipRequest& req); +}; + +class AnnouncementDialog : public AmSession, + public CredentialHolder +{ + AmAudioFile wav_file; + string filename; + + public: + AnnouncementDialog(const string& filename, + const string& auth_realm, + const string& auth_user, + const string& auth_pwd); + ~AnnouncementDialog(); + + void onSessionStart(const AmSipRequest& req); + void onSessionStart(const AmSipReply& rep); + void startSession(); + void onBye(const AmSipRequest& req); + void onDtmf(int event, int duration_msec) {} + + void process(AmEvent* event); +}; + + +#endif +// Local Variables: +// mode:C++ +// End: + diff --git a/apps/announce_auth/Makefile b/apps/announce_auth/Makefile new file mode 100644 index 00000000..6d2399f7 --- /dev/null +++ b/apps/announce_auth/Makefile @@ -0,0 +1,7 @@ +plug_in_name = announce_auth + +module_ldflags = +module_cflags = + +COREPATH ?=../../core +include $(COREPATH)/plug-in/Makefile.app_module diff --git a/apps/announce_auth/etc/announce_auth.conf b/apps/announce_auth/etc/announce_auth.conf new file mode 100644 index 00000000..edec3dc0 --- /dev/null +++ b/apps/announce_auth/etc/announce_auth.conf @@ -0,0 +1,19 @@ +#CFGOPTION_SEMS_ANNOUNCEPATH +announce_path=wav/ +#ENDCFGOPTION + +#CFGOPTION_SEMS_ANNOUNCEMENT +default_announce=default_en.wav +#ENDCFGOPTION + +## authentication information +auth_realm=iptel.org +auth_user=myusername +auth_pwd=mypassword + +## dial out to this number +dial_ruri=sip:123@example.com +dial_to= +## from here +dial_from= +dial_fromuri=sip:myusername@iptel.org