From 61c0d815694f1009268b3952be75c47b98c65cec Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Mon, 8 Dec 2008 15:24:53 +0000 Subject: [PATCH] support for uid (UserID) / did (DomainID) in voicemail/voicebox/annrecorder which is needed if the platform supports aliases and/or multi domain and the canonical username or domain name can not be determined at the proxy (call control) git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1168 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/annrecorder/AnnRecorder.cpp | 27 ++++++++++++---- apps/voicebox/Voicebox.cpp | 19 +++++++++-- apps/voicemail/AnswerMachine.cpp | 55 ++++++++++++++++++++++++-------- apps/voicemail/AnswerMachine.h | 2 ++ doc/Readme.annrecorder | 3 +- doc/Readme.voicebox | 2 ++ doc/Readme.voicemail | 28 +++++++++++++--- 7 files changed, 108 insertions(+), 28 deletions(-) diff --git a/apps/annrecorder/AnnRecorder.cpp b/apps/annrecorder/AnnRecorder.cpp index e62ce066..2e16d44e 100644 --- a/apps/annrecorder/AnnRecorder.cpp +++ b/apps/annrecorder/AnnRecorder.cpp @@ -133,14 +133,19 @@ void AnnRecorderFactory::getAppParams(const AmSipRequest& req, map 1) && isArgAObject(ret.get(1))) { + MessageDataFile* f = + dynamic_cast(ret.get(1).asObject()); + if (NULL != f) + delete f; + } + return NULL; } diff --git a/apps/voicebox/Voicebox.cpp b/apps/voicebox/Voicebox.cpp index 385b33bd..33969195 100644 --- a/apps/voicebox/Voicebox.cpp +++ b/apps/voicebox/Voicebox.cpp @@ -296,6 +296,9 @@ AmSession* VoiceboxFactory::onInvite(const AmSipRequest& req) string pin; string domain; string language; + string uid; + string did; + string iptel_app_param = getHeader(req.hdrs, PARAM_HDR); @@ -303,11 +306,23 @@ AmSession* VoiceboxFactory::onInvite(const AmSipRequest& req) AmSession::Exception(500, APP_NAME ": parameters not found"); } - user = get_header_keyvalue(iptel_app_param, "usr", "User"); + + // consistently with voicemail application: + // uid overrides user + user = get_header_keyvalue(iptel_app_param, "uid", "UserID"); + if (user.empty()) + user = get_header_keyvalue(iptel_app_param, "usr", "User"); + + // did overrides domain + domain = get_header_keyvalue(iptel_app_param, "did", "DomainID"); + if (domain.empty()) + domain = get_header_keyvalue(iptel_app_param, "dom", "Domain"); + + pin = get_header_keyvalue(iptel_app_param, "pin", "PIN"); - domain = get_header_keyvalue(iptel_app_param, "dom", "Domain"); language = get_header_keyvalue(iptel_app_param,"lng", "Language"); + // checks if (user.empty()) throw AmSession::Exception(500, APP_NAME ": user missing"); diff --git a/apps/voicemail/AnswerMachine.cpp b/apps/voicemail/AnswerMachine.cpp index fba03be6..c50331b7 100644 --- a/apps/voicemail/AnswerMachine.cpp +++ b/apps/voicemail/AnswerMachine.cpp @@ -489,6 +489,8 @@ AmSession* AnswerMachineFactory::onInvite(const AmSipRequest& req) string user; string sender; string typ; + string uid; // user ID + string did; // domain ID int vm_mode = MODE_VOICEMAIL; @@ -534,8 +536,17 @@ AmSession* AnswerMachineFactory::onInvite(const AmSipRequest& req) if (!typ.length()) typ = DEFAULT_TYPE; + uid = get_header_keyvalue(iptel_app_param, "uid", "UserID"); + if (uid.empty()) + uid=user; + + did = get_header_keyvalue(iptel_app_param, "did", "DomainID"); + if (did.empty()) + did=domain; + + // checks - if (user.empty()) + if (uid.empty()) throw AmSession::Exception(500, "voicemail: user missing"); if (sender.empty()) @@ -555,10 +566,12 @@ AmSession* AnswerMachineFactory::onInvite(const AmSipRequest& req) DBG(" Domain: <%s> \n", domain.c_str()); DBG(" Language: <%s> \n", language.c_str()); DBG(" Type: <%s> \n", typ.c_str()); + DBG(" UID: <%s> \n", uid.c_str()); + DBG(" DID: <%s> \n", did.c_str()); FILE* greeting_fp = NULL; if (TryPersonalGreeting) - greeting_fp = getMsgStoreGreeting(typ, user, domain); + greeting_fp = getMsgStoreGreeting(typ, uid, did); #ifdef USE_MYSQL @@ -588,17 +601,17 @@ AmSession* AnswerMachineFactory::onInvite(const AmSipRequest& req) #else string announce_file = add2path(AnnouncePath,2, - domain.c_str(), (user + ".wav").c_str()); + did.c_str(), (uid + ".wav").c_str()); if (file_exists(announce_file)) goto announce_found; if (!language.empty()) { announce_file = add2path(AnnouncePath,3, - domain.c_str(), language.c_str(), DefaultAnnounce.c_str()); + did.c_str(), language.c_str(), DefaultAnnounce.c_str()); if (file_exists(announce_file)) goto announce_found; } announce_file = add2path(AnnouncePath,2, - domain.c_str(), DefaultAnnounce.c_str()); + did.c_str(), DefaultAnnounce.c_str()); if (file_exists(announce_file)) goto announce_found; if (!language.empty()) { @@ -620,17 +633,17 @@ AmSession* AnswerMachineFactory::onInvite(const AmSipRequest& req) // VBOX mode does not need email template if ((vm_mode == MODE_BOX) || (vm_mode == MODE_ANN)) return new AnswerMachineDialog(user, sender, domain, - email, announce_file, greeting_fp, - vm_mode, NULL); - + email, announce_file, uid, did, + greeting_fp, vm_mode, NULL); + if(email.empty()) throw AmSession::Exception(404,"missing email address"); map::iterator tmpl_it; if (!language.empty()) { - tmpl_it = email_tmpl.find(domain + "_" + language); + tmpl_it = email_tmpl.find(did + "_" + language); if(tmpl_it == email_tmpl.end()) { - tmpl_it = email_tmpl.find(domain); + tmpl_it = email_tmpl.find(did); if(tmpl_it == email_tmpl.end()) { tmpl_it = email_tmpl.find(DEFAULT_MAIL_TMPL + "_" + language); @@ -639,7 +652,7 @@ AmSession* AnswerMachineFactory::onInvite(const AmSipRequest& req) } } } else { - tmpl_it = email_tmpl.find(domain); + tmpl_it = email_tmpl.find(did); if(tmpl_it == email_tmpl.end()) tmpl_it = email_tmpl.find(DEFAULT_MAIL_TMPL); } @@ -649,7 +662,9 @@ AmSession* AnswerMachineFactory::onInvite(const AmSipRequest& req) return 0; } return new AnswerMachineDialog(user, sender, domain, - email, announce_file, greeting_fp, + email, announce_file, + uid, did, + greeting_fp, vm_mode, &tmpl_it->second); } @@ -659,6 +674,8 @@ AnswerMachineDialog::AnswerMachineDialog(const string& user, const string& domain, const string& email, const string& announce_file, + const string& uid, + const string& did, FILE* announce_fp, int vm_mode, const EmailTemplate* tmpl) @@ -671,6 +688,8 @@ AnswerMachineDialog::AnswerMachineDialog(const string& user, email_dict["from"] = sender; email_dict["domain"] = domain; email_dict["email"] = email; + email_dict["uid"] = uid; + email_dict["did"] = did; user_timer = AnswerMachineFactory::UserTimer->getInstance(); if(!user_timer){ @@ -920,8 +939,8 @@ void AnswerMachineDialog::saveBox(FILE* fp) { DBG("message name is '%s'\n", msg_name.c_str()); AmArg di_args,ret; - di_args.push(email_dict["domain"].c_str()); // domain - di_args.push(email_dict["user"].c_str()); // user + di_args.push(email_dict["did"].c_str()); // domain + di_args.push(email_dict["uid"].c_str()); // user di_args.push(msg_name.c_str()); // message name AmArg df; MessageDataFile df_arg(fp); @@ -966,6 +985,14 @@ FILE* AnswerMachineFactory::getMsgStoreGreeting(string msgname, user.c_str(), domain.c_str(), msgname.c_str(), MsgStrError(ret.get(0).asInt())); + + if ((ret.size() > 1) && isArgAObject(ret.get(1))) { + MessageDataFile* f = + dynamic_cast(ret.get(1).asObject()); + if (NULL != f) + delete f; + } + return NULL; } diff --git a/apps/voicemail/AnswerMachine.h b/apps/voicemail/AnswerMachine.h index bdcc6e85..5dc8ab3a 100644 --- a/apps/voicemail/AnswerMachine.h +++ b/apps/voicemail/AnswerMachine.h @@ -127,6 +127,8 @@ class AnswerMachineDialog : public AmSession const string& domain, const string& email, const string& announce_file, + const string& uid, + const string& did, FILE* announce_fp, int vm_mode, const EmailTemplate* tmpl); diff --git a/doc/Readme.annrecorder b/doc/Readme.annrecorder index 1ddd0e83..ce6e900c 100644 --- a/doc/Readme.annrecorder +++ b/doc/Readme.annrecorder @@ -25,7 +25,8 @@ App-Params usr User param_user typ Type param_type; defaults to "vm" (for: voicemail) lng Language used for finding default greeting - + did DomainID optional, overrides Domain above + uid UserID optional, overrides User above Flow Diagram ------------ diff --git a/doc/Readme.voicebox b/doc/Readme.voicebox index ec71b183..49e9c444 100644 --- a/doc/Readme.voicebox +++ b/doc/Readme.voicebox @@ -24,6 +24,8 @@ application parameters (App-Param header) PIN pin PIN (will be asked for PIN if not empty) Domain dom Domain (for prompts/storage) Language lng Language (for prompts/storage) + UserID uid optional, overrides User above + DomainID did optional, overrides Domain above Prompts ------- diff --git a/doc/Readme.voicemail b/doc/Readme.voicemail index 06558f00..e5b83d34 100644 --- a/doc/Readme.voicemail +++ b/doc/Readme.voicemail @@ -17,15 +17,16 @@ messages to be played. If file system is used to store audio files, the announcement file to be played is looked for in the following order: - '.wav' - - + '.wav' + + where and is set in voicemail.conf, is the host part of the request URI, the user part of -the request URI, and is the App-Param 'Language' (see below). +the request URI (if not overridden by uid="..." or "usr=..."), and + is the App-Param 'Language' (see below). If MySQL database is used to store audio files, the announcement to be played is looked for first from user_audio table, then from domain_audio @@ -95,6 +96,8 @@ avoid packet fragmentation (UDP). Language lng - optional: language for announcement file/email template Type typ - optional (default: 'vm'): prompt file to play, for user recorded greeting (see annrecorder app) + UserID uid - optional: override user by user id (see Note below) + DomainID did - optional: override domain by domain id (see Note below) Example: @@ -106,6 +109,17 @@ avoid packet fragmentation (UDP). P-App-name: voicemail P-App-Param: eml=user@maildomain.net;mod=both;lng=english;snd=someone@iptel.org;dom=iptel.org; +Using UserID (UID) and DomainID (DID) +------------------------------------- + +If the platform supports aliases and multiple domains, the canonical user name and domain +name may not be available when sending the INVITE request to the voicemail/voicebox server. +Also, domain ID is case insensitive, thus iptel.org and Iptel.org may appear as different +domains to the case sensitive msg_storage engine. +Thus, the user and domain may be overridden by user id and domain id. These values are not +used in the email template, they are used only for selection of the user's voicebox and +personal greeting message. + Voicebox mode ------------- @@ -215,3 +229,9 @@ Following variables are supported: - %from%/%sender% : Sender or remote URI. - %from_user% : remote user. - %from_domain% : remote domain. + + - %vmsg_length% : voice message length in seconds + + - %uid% : user id + - %did% : domain id + - %ts% : unix timestamp (seconds)