... | ... |
@@ -27,6 +27,7 @@ |
27 | 27 |
#include "AmConfig.h" |
28 | 28 |
#include "AmUtils.h" |
29 | 29 |
#include "AmPlugIn.h" |
30 |
+#include "AmUACAuth.h" |
|
30 | 31 |
|
31 | 32 |
#include "sems.h" |
32 | 33 |
#include "log.h" |
... | ... |
@@ -101,29 +102,13 @@ AmSession* AnnouncementFactory::onInvite(const AmSipRequest& req, const string& |
101 | 102 |
AmSession* AnnouncementFactory::onInvite(const AmSipRequest& req, const string& app_name, |
102 | 103 |
AmArg& session_params) |
103 | 104 |
{ |
104 |
- UACAuthCred* cred = NULL; |
|
105 |
- if (session_params.getType() == AmArg::AObject) { |
|
106 |
- AmObject* cred_obj = session_params.asObject(); |
|
107 |
- if (cred_obj) |
|
108 |
- cred = dynamic_cast<UACAuthCred*>(cred_obj); |
|
109 |
- } |
|
110 |
- |
|
111 |
- AmSession* s = new AnnouncementDialog(getAnnounceFile(req), cred); |
|
105 |
+ UACAuthCred* cred = AmUACAuth::unpackCredentials(session_params); |
|
106 |
+ AmSession* s = new AnnouncementDialog(getAnnounceFile(req), cred); |
|
112 | 107 |
|
113 | 108 |
if (NULL == cred) { |
114 | 109 |
WARN("discarding unknown session parameters.\n"); |
115 | 110 |
} else { |
116 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
117 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
118 |
- if (uac_auth_f != NULL) { |
|
119 |
- DBG("UAC Auth enabled for new announcement session.\n"); |
|
120 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(s); |
|
121 |
- if (h != NULL ) |
|
122 |
- s->addHandler(h); |
|
123 |
- } else { |
|
124 |
- ERROR("uac_auth interface not accessible. " |
|
125 |
- "Load uac_auth for authenticated dialout.\n"); |
|
126 |
- } |
|
111 |
+ AmUACAuth::enable(s); |
|
127 | 112 |
} |
128 | 113 |
|
129 | 114 |
return s; |
... | ... |
@@ -209,12 +209,7 @@ AmSession* AnnRecorderFactory::onInvite(const AmSipRequest& req, const string& a |
209 | 209 |
AmSession* AnnRecorderFactory::onInvite(const AmSipRequest& req, const string& app_name, |
210 | 210 |
AmArg& session_params) |
211 | 211 |
{ |
212 |
- UACAuthCred* cred = NULL; |
|
213 |
- if (session_params.getType() == AmArg::AObject) { |
|
214 |
- AmObject* cred_obj = session_params.asObject(); |
|
215 |
- if (cred_obj) |
|
216 |
- cred = dynamic_cast<UACAuthCred*>(cred_obj); |
|
217 |
- } |
|
212 |
+ UACAuthCred* cred = AmUACAuth::unpackCredentials(session_params); |
|
218 | 213 |
|
219 | 214 |
map<string, string> params; |
220 | 215 |
getAppParams(req, params); |
... | ... |
@@ -223,17 +218,7 @@ AmSession* AnnRecorderFactory::onInvite(const AmSipRequest& req, const string& a |
223 | 218 |
if (NULL == cred) { |
224 | 219 |
WARN("discarding unknown session parameters.\n"); |
225 | 220 |
} else { |
226 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
227 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
228 |
- if (uac_auth_f != NULL) { |
|
229 |
- DBG("UAC Auth enabled for new announcement session.\n"); |
|
230 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(s); |
|
231 |
- if (h != NULL ) |
|
232 |
- s->addHandler(h); |
|
233 |
- } else { |
|
234 |
- ERROR("uac_auth interface not accessible. " |
|
235 |
- "Load uac_auth for authenticated dialout.\n"); |
|
236 |
- } |
|
221 |
+ AmUACAuth::enable(s); |
|
237 | 222 |
} |
238 | 223 |
|
239 | 224 |
return s; |
... | ... |
@@ -167,8 +167,9 @@ AmSession* CallBackFactory::onInvite(const AmSipRequest& req, const string& app_ |
167 | 167 |
cred = dynamic_cast<UACAuthCred*>(cred_obj); |
168 | 168 |
} |
169 | 169 |
|
170 |
- AmSession* s = new CallBackDialog(prompts, cred); |
|
171 |
- addAuthHandler(s); |
|
170 |
+ AmSession* s = new CallBackDialog(prompts, cred); |
|
171 |
+ AmUACAuth::enable(s); |
|
172 |
+ |
|
172 | 173 |
return s; |
173 | 174 |
} |
174 | 175 |
|
... | ... |
@@ -315,7 +316,7 @@ void CallBackDialog::process(AmEvent* ev) |
315 | 316 |
// need this to pass credentials... |
316 | 317 |
AmB2ABCalleeSession* CallBackDialog::createCalleeSession() { |
317 | 318 |
CallBackCalleeDialog* sess = new CallBackCalleeDialog(getLocalTag(), connector, cred); |
318 |
- addAuthHandler(sess); |
|
319 |
+ AmUACAuth::enable(sess); |
|
319 | 320 |
return sess; |
320 | 321 |
} |
321 | 322 |
|
... | ... |
@@ -332,17 +333,3 @@ CallBackCalleeDialog::CallBackCalleeDialog(const string& other_tag, |
332 | 333 |
CallBackCalleeDialog::~CallBackCalleeDialog() { |
333 | 334 |
} |
334 | 335 |
|
335 |
- |
|
336 |
-void addAuthHandler(AmSession* s) { |
|
337 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
338 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
339 |
- if (uac_auth_f != NULL) { |
|
340 |
- DBG("UAC Auth enabled for new session.\n"); |
|
341 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(s); |
|
342 |
- if (h != NULL ) |
|
343 |
- s->addHandler(h); |
|
344 |
- } else { |
|
345 |
- ERROR("uac_auth interface not accessible. " |
|
346 |
- "Load uac_auth for authenticated calls.\n"); |
|
347 |
- } |
|
348 |
-} |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
#include "AmAudio.h" |
31 | 31 |
#include "AmPlaylist.h" |
32 | 32 |
#include "AmPromptCollection.h" |
33 |
-#include "ampi/UACAuthAPI.h" |
|
33 |
+#include "AmUACAuth.h" |
|
34 | 34 |
|
35 | 35 |
#include <map> |
36 | 36 |
#include <string> |
... | ... |
@@ -132,7 +132,6 @@ public: |
132 | 132 |
UACAuthCred* getCredentials() { return cred; } |
133 | 133 |
}; |
134 | 134 |
|
135 |
-void addAuthHandler(AmSession* s); |
|
136 | 135 |
#endif |
137 | 136 |
// Local Variables: |
138 | 137 |
// mode:C++ |
... | ... |
@@ -155,24 +155,9 @@ AmSession* Click2DialFactory::onInvite(const AmSipRequest& req, const string& ap |
155 | 155 |
return NULL; |
156 | 156 |
} |
157 | 157 |
|
158 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
159 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
160 |
- if(uac_auth_f != NULL) { |
|
161 |
- DBG("UAC Auth enabled for new announcement session.\n"); |
|
162 |
- AmSessionEventHandler *h = uac_auth_f->getHandler(s); |
|
163 |
- if (h != NULL) { |
|
164 |
- s->addHandler(h); |
|
165 |
- } |
|
166 |
- else { |
|
167 |
- ERROR("Failed to get authentication event handler"); |
|
168 |
- delete s; |
|
169 |
- return NULL; |
|
170 |
- } |
|
171 |
- } |
|
172 |
- else { |
|
173 |
- ERROR("uac_auth interface not accessible. " |
|
174 |
- "Load uac_auth for authenticated dialout.\n"); |
|
175 |
- |
|
158 |
+ if (!AmUACAuth::enable(s)) { |
|
159 |
+ ERROR("Failed to get authentication event handler"); |
|
160 |
+ delete s; |
|
176 | 161 |
return NULL; |
177 | 162 |
} |
178 | 163 |
|
... | ... |
@@ -756,11 +756,7 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req, const string& app_name, |
756 | 756 |
} else if (session_params.getType() == AmArg::Array) { |
757 | 757 |
DBG("session params is array - size %zd\n", session_params.size()); |
758 | 758 |
// Creds |
759 |
- if (session_params.get(0).getType() == AmArg::AObject) { |
|
760 |
- AmObject* cred_obj = session_params.get(0).asObject(); |
|
761 |
- if (cred_obj) |
|
762 |
- cred = dynamic_cast<UACAuthCred*>(cred_obj); |
|
763 |
- } |
|
759 |
+ cred = AmUACAuth::unpackCredentials(session_params.get(0)); |
|
764 | 760 |
// Creds + vars |
765 | 761 |
if (session_params.size()>1 && |
766 | 762 |
session_params.get(1).getType() == AmArg::Struct) { |
... | ... |
@@ -795,17 +791,7 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req, const string& app_name, |
795 | 791 |
if (NULL == cred) { |
796 | 792 |
DBG("outgoing DSM call will not be authenticated.\n"); |
797 | 793 |
} else { |
798 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
799 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
800 |
- if (uac_auth_f != NULL) { |
|
801 |
- DBG("UAC Auth enabled for new DSM session.\n"); |
|
802 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(s); |
|
803 |
- if (h != NULL ) |
|
804 |
- s->addHandler(h); |
|
805 |
- } else { |
|
806 |
- ERROR("uac_auth interface not accessible. " |
|
807 |
- "Load uac_auth for authenticated dialout.\n"); |
|
808 |
- } |
|
794 |
+ AmUACAuth::enable(s); |
|
809 | 795 |
} |
810 | 796 |
|
811 | 797 |
return s; |
... | ... |
@@ -49,91 +49,79 @@ AnnounceAuthFactory::AnnounceAuthFactory(const string& _app_name) |
49 | 49 |
|
50 | 50 |
int AnnounceAuthFactory::onLoad() |
51 | 51 |
{ |
52 |
- AmConfigReader cfg; |
|
53 |
- if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) |
|
54 |
- return -1; |
|
52 |
+ AmConfigReader cfg; |
|
53 |
+ if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) |
|
54 |
+ return -1; |
|
55 | 55 |
|
56 |
- // get application specific global parameters |
|
57 |
- configureModule(cfg); |
|
56 |
+ // get application specific global parameters |
|
57 |
+ configureModule(cfg); |
|
58 | 58 |
|
59 |
- AnnouncePath = cfg.getParameter("announce_path",ANNOUNCE_PATH); |
|
60 |
- if( !AnnouncePath.empty() |
|
61 |
- && AnnouncePath[AnnouncePath.length()-1] != '/' ) |
|
62 |
- AnnouncePath += "/"; |
|
59 |
+ AnnouncePath = cfg.getParameter("announce_path",ANNOUNCE_PATH); |
|
60 |
+ if( !AnnouncePath.empty() |
|
61 |
+ && AnnouncePath[AnnouncePath.length()-1] != '/' ) |
|
62 |
+ AnnouncePath += "/"; |
|
63 | 63 |
|
64 |
- AnnounceFile = cfg.getParameter("default_announce",ANNOUNCE_FILE); |
|
64 |
+ AnnounceFile = cfg.getParameter("default_announce",ANNOUNCE_FILE); |
|
65 | 65 |
|
66 |
- string announce_file = AnnouncePath + AnnounceFile; |
|
67 |
- if(!file_exists(announce_file)){ |
|
68 |
- ERROR("default file for ann_b2b module does not exist ('%s').\n", |
|
69 |
- announce_file.c_str()); |
|
70 |
- return -1; |
|
71 |
- } |
|
66 |
+ string announce_file = AnnouncePath + AnnounceFile; |
|
67 |
+ if(!file_exists(announce_file)){ |
|
68 |
+ ERROR("default file for ann_b2b module does not exist ('%s').\n", |
|
69 |
+ announce_file.c_str()); |
|
70 |
+ return -1; |
|
71 |
+ } |
|
72 | 72 |
|
73 | 73 |
|
74 |
- auth_realm = cfg.getParameter("auth_realm", ""); |
|
75 |
- auth_user = cfg.getParameter("auth_user", ""); |
|
76 |
- auth_pwd = cfg.getParameter("auth_pwd", ""); |
|
74 |
+ auth_realm = cfg.getParameter("auth_realm", ""); |
|
75 |
+ auth_user = cfg.getParameter("auth_user", ""); |
|
76 |
+ auth_pwd = cfg.getParameter("auth_pwd", ""); |
|
77 | 77 |
|
78 |
- uac_auth_f = AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
79 |
- DBG("uac_auth_f == 0x%.16lX\n",(unsigned long)uac_auth_f); |
|
78 |
+ dialer.set_dial(cfg.getParameter("dial_ruri","default ruri"), |
|
79 |
+ cfg.getParameter("dial_from","default from"), |
|
80 |
+ cfg.getParameter("dial_fromuri","default fromuri"), |
|
81 |
+ cfg.getParameter("dial_to","default to")); |
|
80 | 82 |
|
81 |
- dialer.set_dial(cfg.getParameter("dial_ruri","default ruri"), |
|
82 |
- cfg.getParameter("dial_from","default from"), |
|
83 |
- cfg.getParameter("dial_fromuri","default fromuri"), |
|
84 |
- cfg.getParameter("dial_to","default to")); |
|
83 |
+ dialer.start(); |
|
85 | 84 |
|
86 |
- dialer.start(); |
|
87 |
- |
|
88 |
- return 0; |
|
85 |
+ return 0; |
|
89 | 86 |
} |
90 | 87 |
|
91 | 88 |
AmSession* AnnounceAuthFactory::onInvite(const AmSipRequest& req, const string& app_name, |
92 | 89 |
const map<string,string>& app_params) |
93 | 90 |
{ |
94 |
- string announce_path = AnnouncePath; |
|
95 |
- string announce_file = announce_path + req.domain |
|
96 |
- + "/" + req.user + ".wav"; |
|
91 |
+ string announce_path = AnnouncePath; |
|
92 |
+ string announce_file = announce_path + req.domain |
|
93 |
+ + "/" + req.user + ".wav"; |
|
97 | 94 |
|
98 |
- DBG("trying '%s'\n",announce_file.c_str()); |
|
99 |
- if(file_exists(announce_file)) |
|
100 |
- goto end; |
|
95 |
+ DBG("trying '%s'\n",announce_file.c_str()); |
|
96 |
+ if(file_exists(announce_file)) |
|
97 |
+ goto end; |
|
101 | 98 |
|
102 |
- announce_file = announce_path + req.user + ".wav"; |
|
103 |
- DBG("trying '%s'\n",announce_file.c_str()); |
|
104 |
- if(file_exists(announce_file)) |
|
105 |
- goto end; |
|
99 |
+ announce_file = announce_path + req.user + ".wav"; |
|
100 |
+ DBG("trying '%s'\n",announce_file.c_str()); |
|
101 |
+ if(file_exists(announce_file)) |
|
102 |
+ goto end; |
|
106 | 103 |
|
107 |
- announce_file = AnnouncePath + AnnounceFile; |
|
104 |
+ announce_file = AnnouncePath + AnnounceFile; |
|
108 | 105 |
|
109 |
-end: |
|
110 |
- AnnounceAuthDialog* dlg = new AnnounceAuthDialog(announce_file, |
|
111 |
- auth_realm, |
|
112 |
- auth_user, |
|
113 |
- auth_pwd); |
|
114 |
- |
|
115 |
- if (uac_auth_f != NULL) { |
|
116 |
- DBG("UAC Auth enabled for new announcement session.\n"); |
|
117 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(dlg); |
|
118 |
- if (h != NULL ) |
|
119 |
- dlg->addHandler(h); |
|
120 |
- } |
|
121 |
- |
|
122 |
- return dlg; |
|
106 |
+ end: |
|
107 |
+ AnnounceAuthDialog* dlg = |
|
108 |
+ new AnnounceAuthDialog(announce_file,auth_realm, auth_user, auth_pwd); |
|
109 |
+ |
|
110 |
+ AmUACAuth::enable(dlg); |
|
111 |
+ |
|
112 |
+ return dlg; |
|
123 | 113 |
} |
124 | 114 |
|
125 | 115 |
AnnounceAuthDialog::AnnounceAuthDialog(const string& filename, |
126 |
- const string& auth_realm, |
|
127 |
- const string& auth_user, |
|
128 |
- const string& auth_pwd) |
|
129 |
- : filename(filename), |
|
130 |
- credentials(auth_realm, auth_user, auth_pwd) |
|
116 |
+ const string& auth_realm, |
|
117 |
+ const string& auth_user, |
|
118 |
+ const string& auth_pwd) |
|
119 |
+ : filename(filename), credentials(auth_realm, auth_user, auth_pwd) |
|
131 | 120 |
{ |
132 |
- |
|
133 | 121 |
} |
134 | 122 |
|
135 | 123 |
UACAuthCred* AnnounceAuthDialog::getCredentials() { |
136 |
- return &credentials; |
|
124 |
+ return &credentials; |
|
137 | 125 |
} |
138 | 126 |
|
139 | 127 |
AnnounceAuthDialog::~AnnounceAuthDialog() |
... | ... |
@@ -142,63 +130,63 @@ AnnounceAuthDialog::~AnnounceAuthDialog() |
142 | 130 |
|
143 | 131 |
void AnnounceAuthDialog::onSessionStart() |
144 | 132 |
{ |
145 |
- DBG("AnnounceAuthDialog::onSessionStart\n"); |
|
146 |
- startSession(); |
|
133 |
+ DBG("AnnounceAuthDialog::onSessionStart\n"); |
|
134 |
+ startSession(); |
|
147 | 135 |
|
148 |
- AmSession::onSessionStart(); |
|
136 |
+ AmSession::onSessionStart(); |
|
149 | 137 |
} |
150 | 138 |
|
151 | 139 |
void AnnounceAuthDialog::startSession() |
152 | 140 |
{ |
153 |
- // disable DTMF detection - don't use DTMF here |
|
154 |
- setDtmfDetectionEnabled(false); |
|
141 |
+ // disable DTMF detection - don't use DTMF here |
|
142 |
+ setDtmfDetectionEnabled(false); |
|
155 | 143 |
|
156 |
- if(wav_file.open(filename,AmAudioFile::Read)) |
|
157 |
- throw string("AnnounceAuthDialog::onSessionStart: Cannot open file\n"); |
|
144 |
+ if(wav_file.open(filename,AmAudioFile::Read)) |
|
145 |
+ throw string("AnnounceAuthDialog::onSessionStart: Cannot open file\n"); |
|
158 | 146 |
|
159 |
- setOutput(&wav_file); |
|
147 |
+ setOutput(&wav_file); |
|
160 | 148 |
} |
161 | 149 |
|
162 | 150 |
void AnnounceAuthDialog::onBye(const AmSipRequest& req) |
163 | 151 |
{ |
164 |
- DBG("onBye: stopSession\n"); |
|
165 |
- setStopped(); |
|
152 |
+ DBG("onBye: stopSession\n"); |
|
153 |
+ setStopped(); |
|
166 | 154 |
} |
167 | 155 |
|
168 | 156 |
|
169 | 157 |
void AnnounceAuthDialog::process(AmEvent* event) |
170 | 158 |
{ |
171 | 159 |
|
172 |
- AmAudioEvent* audio_event = dynamic_cast<AmAudioEvent*>(event); |
|
173 |
- if(audio_event && (audio_event->event_id == AmAudioEvent::cleared)){ |
|
174 |
- dlg.bye(); |
|
175 |
- setStopped(); |
|
176 |
- return; |
|
177 |
- } |
|
160 |
+ AmAudioEvent* audio_event = dynamic_cast<AmAudioEvent*>(event); |
|
161 |
+ if(audio_event && (audio_event->event_id == AmAudioEvent::cleared)){ |
|
162 |
+ dlg.bye(); |
|
163 |
+ setStopped(); |
|
164 |
+ return; |
|
165 |
+ } |
|
178 | 166 |
|
179 |
- AmSession::process(event); |
|
167 |
+ AmSession::process(event); |
|
180 | 168 |
} |
181 | 169 |
|
182 | 170 |
void DialerThread::set_dial(const string& r, const string& f, |
183 |
- const string& fu, const string& t) { |
|
184 |
- r_uri = r; |
|
185 |
- from = f; |
|
186 |
- from_uri = fu; |
|
187 |
- to = t; |
|
171 |
+ const string& fu, const string& t) { |
|
172 |
+ r_uri = r; |
|
173 |
+ from = f; |
|
174 |
+ from_uri = fu; |
|
175 |
+ to = t; |
|
188 | 176 |
} |
189 | 177 |
|
190 | 178 |
void DialerThread::run() { |
191 |
- sleep(15); // wait for sems to completely start up |
|
192 |
- while (!is_stopped()) { |
|
193 |
- DBG("dialing..."); |
|
194 |
- AmUAC::dialout("blibla", "announce_auth", |
|
195 |
- r_uri, from, from_uri, to); |
|
196 |
- // every 10 minutes |
|
197 |
- sleep(100); |
|
198 |
- |
|
199 |
- } |
|
179 |
+ sleep(15); // wait for sems to completely start up |
|
180 |
+ while (!is_stopped()) { |
|
181 |
+ DBG("dialing..."); |
|
182 |
+ AmUAC::dialout("blibla", "announce_auth", |
|
183 |
+ r_uri, from, from_uri, to); |
|
184 |
+ // every 10 minutes |
|
185 |
+ sleep(100); |
|
186 |
+ |
|
187 |
+ } |
|
200 | 188 |
} |
201 | 189 |
|
202 | 190 |
void DialerThread::on_stop() { |
203 |
- DBG("stopping...\n"); |
|
191 |
+ DBG("stopping...\n"); |
|
204 | 192 |
} |
... | ... |
@@ -30,68 +30,66 @@ |
30 | 30 |
#include "AmSession.h" |
31 | 31 |
#include "AmAudioFile.h" |
32 | 32 |
#include "AmConfigReader.h" |
33 |
- |
|
34 |
-#include "ampi/UACAuthAPI.h" |
|
33 |
+#include "AmUACAuth.h" |
|
35 | 34 |
|
36 | 35 |
#include <string> |
37 | 36 |
using std::string; |
38 | 37 |
|
39 | 38 |
class DialerThread : public AmThread { |
40 |
- string r_uri; |
|
41 |
- string from; |
|
42 |
- string from_uri; |
|
43 |
- string to; |
|
39 |
+ string r_uri; |
|
40 |
+ string from; |
|
41 |
+ string from_uri; |
|
42 |
+ string to; |
|
44 | 43 |
protected: |
45 |
- void run(); |
|
46 |
- void on_stop(); |
|
44 |
+ void run(); |
|
45 |
+ void on_stop(); |
|
47 | 46 |
public: |
48 |
- void set_dial(const string& r, const string& f, |
|
49 |
- const string& fu, const string& t); |
|
47 |
+ void set_dial(const string& r, const string& f, |
|
48 |
+ const string& fu, const string& t); |
|
50 | 49 |
|
51 | 50 |
|
52 | 51 |
}; |
53 | 52 |
|
54 | 53 |
class AnnounceAuthFactory: public AmSessionFactory |
55 | 54 |
{ |
56 |
- DialerThread dialer; |
|
57 |
- AmSessionEventHandlerFactory* uac_auth_f; |
|
55 |
+ DialerThread dialer; |
|
58 | 56 |
|
59 |
- string auth_realm; |
|
60 |
- string auth_user; |
|
61 |
- string auth_pwd; |
|
57 |
+ string auth_realm; |
|
58 |
+ string auth_user; |
|
59 |
+ string auth_pwd; |
|
62 | 60 |
|
63 | 61 |
public: |
64 |
- static string AnnouncePath; |
|
65 |
- static string AnnounceFile; |
|
62 |
+ static string AnnouncePath; |
|
63 |
+ static string AnnounceFile; |
|
66 | 64 |
|
67 |
- AnnounceAuthFactory(const string& _app_name); |
|
65 |
+ AnnounceAuthFactory(const string& _app_name); |
|
68 | 66 |
|
69 |
- int onLoad(); |
|
70 |
- AmSession* onInvite(const AmSipRequest& req, const string& app_name, |
|
71 |
- const map<string,string>& app_params); |
|
67 |
+ int onLoad(); |
|
68 |
+ AmSession* onInvite(const AmSipRequest& req, const string& app_name, |
|
69 |
+ const map<string,string>& app_params); |
|
72 | 70 |
}; |
73 | 71 |
|
74 | 72 |
class AnnounceAuthDialog : public AmSession, |
75 |
- public CredentialHolder |
|
73 |
+ public CredentialHolder |
|
76 | 74 |
{ |
77 |
- AmAudioFile wav_file; |
|
78 |
- string filename; |
|
79 |
- UACAuthCred credentials; |
|
80 |
- |
|
81 |
- public: |
|
82 |
- AnnounceAuthDialog(const string& filename, |
|
83 |
- const string& auth_realm, |
|
84 |
- const string& auth_user, |
|
85 |
- const string& auth_pwd); |
|
86 |
- ~AnnounceAuthDialog(); |
|
87 |
- |
|
88 |
- void onSessionStart(); |
|
89 |
- void startSession(); |
|
90 |
- void onBye(const AmSipRequest& req); |
|
91 |
- void onDtmf(int event, int duration_msec) {} |
|
92 |
- |
|
93 |
- void process(AmEvent* event); |
|
94 |
- inline UACAuthCred* getCredentials(); |
|
75 |
+ AmAudioFile wav_file; |
|
76 |
+ string filename; |
|
77 |
+ UACAuthCred credentials; |
|
78 |
+ |
|
79 |
+public: |
|
80 |
+ AnnounceAuthDialog(const string& filename, |
|
81 |
+ const string& auth_realm, |
|
82 |
+ const string& auth_user, |
|
83 |
+ const string& auth_pwd); |
|
84 |
+ ~AnnounceAuthDialog(); |
|
85 |
+ |
|
86 |
+ void onSessionStart(); |
|
87 |
+ void startSession(); |
|
88 |
+ void onBye(const AmSipRequest& req); |
|
89 |
+ void onDtmf(int event, int duration_msec) {} |
|
90 |
+ |
|
91 |
+ void process(AmEvent* event); |
|
92 |
+ inline UACAuthCred* getCredentials(); |
|
95 | 93 |
}; |
96 | 94 |
|
97 | 95 |
|
... | ... |
@@ -225,25 +225,10 @@ void b2b_connectDialog::onCancel(const AmSipRequest& req) |
225 | 225 |
|
226 | 226 |
AmB2ABCalleeSession* b2b_connectDialog::createCalleeSession() |
227 | 227 |
{ |
228 |
- b2b_connectCalleeSession* sess = new b2b_connectCalleeSession(getLocalTag(), |
|
229 |
- connector, |
|
230 |
- user, password); |
|
228 |
+ b2b_connectCalleeSession* sess = |
|
229 |
+ new b2b_connectCalleeSession(getLocalTag(), connector, user, password); |
|
231 | 230 |
|
232 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
233 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
234 |
- |
|
235 |
- if (NULL != uac_auth_f) { |
|
236 |
- DBG("UAC Auth enabled for new b2b_connect session.\n"); |
|
237 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(sess); |
|
238 |
- if (h != NULL ) |
|
239 |
- sess->addHandler(h); |
|
240 |
- else { |
|
241 |
- ERROR("unable to set SIP UAC auth for new session."); |
|
242 |
- } |
|
243 |
- } else { |
|
244 |
- ERROR("unable to get SIP UAC auth." |
|
245 |
- "(uac_auth module loaded?)\n"); |
|
246 |
- } |
|
231 |
+ AmUACAuth::enable(sess); |
|
247 | 232 |
|
248 | 233 |
return sess; |
249 | 234 |
} |
... | ... |
@@ -98,29 +98,14 @@ AmSession* DtmfTesterFactory::onInvite(const AmSipRequest& req, const string& ap |
98 | 98 |
AmSession* DtmfTesterFactory::onInvite(const AmSipRequest& req, const string& app_name, |
99 | 99 |
AmArg& session_params) |
100 | 100 |
{ |
101 |
- UACAuthCred* cred = NULL; |
|
102 |
- if (session_params.getType() == AmArg::AObject) { |
|
103 |
- AmObject* cred_obj = session_params.asObject(); |
|
104 |
- if (cred_obj) |
|
105 |
- cred = dynamic_cast<UACAuthCred*>(cred_obj); |
|
106 |
- } |
|
101 |
+ UACAuthCred* cred = AmUACAuth::unpackCredentials(session_params); |
|
107 | 102 |
|
108 | 103 |
AmSession* s = new DtmfTesterDialog(getAnnounceFile(req), cred); |
109 | 104 |
|
110 | 105 |
if (NULL == cred) { |
111 | 106 |
WARN("discarding unknown session parameters.\n"); |
112 | 107 |
} else { |
113 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
114 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
115 |
- if (uac_auth_f != NULL) { |
|
116 |
- DBG("UAC Auth enabled for new announcement session.\n"); |
|
117 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(s); |
|
118 |
- if (h != NULL ) |
|
119 |
- s->addHandler(h); |
|
120 |
- } else { |
|
121 |
- ERROR("uac_auth interface not accessible. " |
|
122 |
- "Load uac_auth for authenticated dialout.\n"); |
|
123 |
- } |
|
108 |
+ AmUACAuth::enable(s); |
|
124 | 109 |
} |
125 | 110 |
|
126 | 111 |
return s; |
... | ... |
@@ -32,29 +32,14 @@ AmSession* EarlyRecordFactory::onInvite(const AmSipRequest& req, const string& a |
32 | 32 |
AmSession* EarlyRecordFactory::onInvite(const AmSipRequest& req, const string& app_name, |
33 | 33 |
AmArg& session_params) |
34 | 34 |
{ |
35 |
- UACAuthCred* cred = NULL; |
|
36 |
- if (session_params.getType() == AmArg::AObject) { |
|
37 |
- AmObject* cred_obj = session_params.asObject(); |
|
38 |
- if (cred_obj) |
|
39 |
- cred = dynamic_cast<UACAuthCred*>(cred_obj); |
|
40 |
- } |
|
35 |
+ UACAuthCred* cred = AmUACAuth::unpackCredentials(session_params); |
|
41 | 36 |
|
42 | 37 |
AmSession* s = new EarlyRecordDialog(cred); |
43 | 38 |
|
44 | 39 |
if (NULL == cred) { |
45 | 40 |
WARN("discarding unknown session parameters.\n"); |
46 | 41 |
} else { |
47 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
48 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
49 |
- if (uac_auth_f != NULL) { |
|
50 |
- DBG("UAC Auth enabled for new announcement session.\n"); |
|
51 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(s); |
|
52 |
- if (h != NULL ) |
|
53 |
- s->addHandler(h); |
|
54 |
- } else { |
|
55 |
- ERROR("uac_auth interface not accessible. " |
|
56 |
- "Load uac_auth for authenticated dialout.\n"); |
|
57 |
- } |
|
42 |
+ AmUACAuth::enable(s); |
|
58 | 43 |
} |
59 | 44 |
|
60 | 45 |
return s; |
... | ... |
@@ -176,21 +176,8 @@ AmB2ABCalleeSession* ServiceLineCallerDialog::createCalleeSession() { |
176 | 176 |
ServiceLineCalleeDialog* sess = |
177 | 177 |
new ServiceLineCalleeDialog(getLocalTag(), connector); |
178 | 178 |
|
179 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
180 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
181 |
- |
|
182 |
- if (NULL != uac_auth_f) { |
|
183 |
- DBG("UAC Auth enabled for new serviceline session.\n"); |
|
184 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(sess); |
|
185 |
- if (h != NULL ) |
|
186 |
- sess->addHandler(h); |
|
187 |
- else { |
|
188 |
- ERROR("unable to set SIP UAC auth for new session."); |
|
189 |
- } |
|
190 |
- } else { |
|
191 |
- ERROR("unable to get SIP UAC auth." |
|
192 |
- "(uac_auth module loaded?)\n"); |
|
193 |
- } |
|
179 |
+ AmUACAuth::enable(sess); |
|
180 |
+ |
|
194 | 181 |
return sess; |
195 | 182 |
} |
196 | 183 |
|
... | ... |
@@ -125,8 +125,8 @@ void RegThread::create_registration(RegInfo& ri) { |
125 | 125 |
if (di_f == NULL) { |
126 | 126 |
ERROR("unable to get a registrar_client\n"); |
127 | 127 |
} else { |
128 |
- AmDynInvoke* uac_auth_i = di_f->getInstance(); |
|
129 |
- if (uac_auth_i!=NULL) { |
|
128 |
+ AmDynInvoke* registrar_client_i = di_f->getInstance(); |
|
129 |
+ if (registrar_client_i!=NULL) { |
|
130 | 130 |
|
131 | 131 |
DBG("calling createRegistration\n"); |
132 | 132 |
AmArg di_args, reg_handle; |
... | ... |
@@ -139,7 +139,7 @@ void RegThread::create_registration(RegInfo& ri) { |
139 | 139 |
di_args.push(ri.proxy.c_str()); |
140 | 140 |
di_args.push(ri.contact.c_str()); |
141 | 141 |
|
142 |
- uac_auth_i->invoke("createRegistration", di_args, reg_handle); |
|
142 |
+ registrar_client_i->invoke("createRegistration", di_args, reg_handle); |
|
143 | 143 |
if (reg_handle.size()) |
144 | 144 |
ri.handle = reg_handle.get(0).asCStr(); |
145 | 145 |
} |
... | ... |
@@ -153,12 +153,12 @@ bool RegThread::check_registration(const RegInfo& ri) { |
153 | 153 |
if (di_f == NULL) { |
154 | 154 |
ERROR("unable to get a registrar_client\n"); |
155 | 155 |
} else { |
156 |
- AmDynInvoke* uac_auth_i = di_f->getInstance(); |
|
157 |
- if (uac_auth_i!=NULL) { |
|
156 |
+ AmDynInvoke* registrar_client_i = di_f->getInstance(); |
|
157 |
+ if (registrar_client_i!=NULL) { |
|
158 | 158 |
|
159 | 159 |
AmArg di_args, res; |
160 | 160 |
di_args.push(ri.handle.c_str()); |
161 |
- uac_auth_i->invoke("getRegistrationState", di_args, res); |
|
161 |
+ registrar_client_i->invoke("getRegistrationState", di_args, res); |
|
162 | 162 |
if (res.size()) { |
163 | 163 |
if (!res.get(0).asInt()) |
164 | 164 |
return false; // does not exist |
... | ... |
@@ -383,25 +383,14 @@ AmSession* WebConferenceFactory::onInvite(const AmSipRequest& req, const string& |
383 | 383 |
AmSession* WebConferenceFactory::onInvite(const AmSipRequest& req, const string& app_name, |
384 | 384 |
AmArg& session_params) |
385 | 385 |
{ |
386 |
- UACAuthCred* cred = NULL; |
|
387 |
- if (session_params.getType() == AmArg::AObject) { |
|
388 |
- AmObject* cred_obj = session_params.asObject(); |
|
389 |
- if (cred_obj) |
|
390 |
- cred = dynamic_cast<UACAuthCred*>(cred_obj); |
|
391 |
- } |
|
392 |
- |
|
386 |
+ UACAuthCred* cred = AmUACAuth::unpackCredentials(session_params); |
|
393 | 387 |
AmSession* s = new WebConferenceDialog(prompts, getInstance(), cred); |
394 | 388 |
|
395 |
- AmSessionEventHandlerFactory* uac_auth_f = |
|
396 |
- AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
397 |
- if (uac_auth_f != NULL) { |
|
398 |
- DBG("UAC Auth enabled for new announcement session.\n"); |
|
399 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(s); |
|
400 |
- if (h != NULL ) |
|
401 |
- s->addHandler(h); |
|
389 |
+ if (NULL == cred) { |
|
390 |
+ WARN("discarding unknown session parameters.\n"); |
|
402 | 391 |
} else { |
403 |
- ERROR("uac_auth interface not accessible. Load uac_auth for authenticated dialout.\n"); |
|
404 |
- } |
|
392 |
+ AmUACAuth::enable(s); |
|
393 |
+ } |
|
405 | 394 |
|
406 | 395 |
s->setUri(getAccessUri(req.user)); |
407 | 396 |
|
39 | 39 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,48 @@ |
1 |
+ |
|
2 |
+#include "AmUACAuth.h" |
|
3 |
+ |
|
4 |
+UACAuthCred::UACAuthCred() { } |
|
5 |
+UACAuthCred::UACAuthCred(const string& realm, |
|
6 |
+ const string& user, |
|
7 |
+ const string& pwd) |
|
8 |
+ : realm(realm), user(user), pwd(pwd) { } |
|
9 |
+ |
|
10 |
+ |
|
11 |
+ |
|
12 |
+AmUACAuth::AmUACAuth() { } |
|
13 |
+ |
|
14 |
+AmUACAuth::~AmUACAuth() { } |
|
15 |
+ |
|
16 |
+ |
|
17 |
+UACAuthCred* AmUACAuth::unpackCredentials(const AmArg& arg) { |
|
18 |
+ UACAuthCred* cred = NULL; |
|
19 |
+ if (arg.getType() == AmArg::AObject) { |
|
20 |
+ AmObject* cred_obj = arg.asObject(); |
|
21 |
+ if (cred_obj) |
|
22 |
+ cred = dynamic_cast<UACAuthCred*>(cred_obj); |
|
23 |
+ } |
|
24 |
+ return cred; |
|
25 |
+} |
|
26 |
+ |
|
27 |
+ |
|
28 |
+bool AmUACAuth::enable(AmSession* s) { |
|
29 |
+ bool res = false; |
|
30 |
+ |
|
31 |
+ AmSessionEventHandlerFactory* uac_auth_f = |
|
32 |
+ AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
33 |
+ if (uac_auth_f != NULL) { |
|
34 |
+ AmSessionEventHandler* h = uac_auth_f->getHandler(s); |
|
35 |
+ if (h != NULL ) { |
|
36 |
+ DBG("enabling SIP UAC auth for new session.\n"); |
|
37 |
+ s->addHandler(h); |
|
38 |
+ res = true; |
|
39 |
+ } else { |
|
40 |
+ WARN("trying to get auth handler for invalid session " |
|
41 |
+ "(derived from CredentialHolder?)\n"); |
|
42 |
+ } |
|
43 |
+ } else { |
|
44 |
+ WARN("uac_auth interface not accessible. " |
|
45 |
+ "Load uac_auth for authenticated calls.\n"); |
|
46 |
+ } |
|
47 |
+ return res; |
|
48 |
+} |
0 | 49 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,26 @@ |
1 |
+#ifndef _UACAuth_h_ |
|
2 |
+#define _UACAuth_h_ |
|
3 |
+#include "ampi/UACAuthAPI.h" |
|
4 |
+#include "AmSession.h" |
|
5 |
+#include "AmArg.h" |
|
6 |
+ |
|
7 |
+class AmUACAuth { |
|
8 |
+ protected: |
|
9 |
+ AmUACAuth(); |
|
10 |
+ ~AmUACAuth(); |
|
11 |
+ public: |
|
12 |
+ /** |
|
13 |
+ unpack UAC auth credentials from an AmArg |
|
14 |
+ @return UACAuthCred object, NULL if failed |
|
15 |
+ */ |
|
16 |
+ |
|
17 |
+ static UACAuthCred* unpackCredentials(const AmArg& arg); |
|
18 |
+ |
|
19 |
+ /** |
|
20 |
+ enable SIP UAC authentication |
|
21 |
+ @return true if successful |
|
22 |
+ */ |
|
23 |
+ static bool enable(AmSession* s); |
|
24 |
+ |
|
25 |
+}; |
|
26 |
+#endif |
... | ... |
@@ -46,11 +46,10 @@ class UACAuthCred |
46 | 46 |
string realm; |
47 | 47 |
string user; |
48 | 48 |
string pwd; |
49 |
- UACAuthCred() { } |
|
49 |
+ UACAuthCred(); |
|
50 | 50 |
UACAuthCred(const string& realm, |
51 | 51 |
const string& user, |
52 |
- const string& pwd) |
|
53 |
- : realm(realm), user(user), pwd(pwd) { } |
|
52 |
+ const string& pwd); |
|
54 | 53 |
}; |
55 | 54 |
|
56 | 55 |
class CredentialHolder { |
... | ... |
@@ -1,6 +1,5 @@ |
1 | 1 |
uac_auth Client authentication |
2 | 2 |
|
3 |
- |
|
4 | 3 |
how to use uac_auth |
5 | 4 |
-------------------- |
6 | 5 |
|
... | ... |
@@ -14,30 +13,20 @@ How to |
14 | 13 |
1) provide credentials |
15 | 14 |
* Derive your Session object from CredentialHolder: |
16 | 15 |
|
17 |
- #include "../../core/plug-in/uac_auth/UACAuth.h" |
|
16 |
+ #include "AmUACAuth.h" |
|
18 | 17 |
... |
19 | 18 |
|
20 |
- class AnnouncementDialog : public AmSession, |
|
21 |
- public CredentialHolder |
|
19 |
+ class MyCall : public AmSession, |
|
20 |
+ public CredentialHolder |
|
22 | 21 |
|
23 | 22 |
* set credentials on session creation |
24 | 23 |
AnnouncementDialog::AnnouncementDialog(...) |
25 | 24 |
: CredentialHolder("myrealm", "myuser", "mypwd") |
26 | 25 |
|
27 | 26 |
|
28 |
-2) add uac_auth SessionEventHandler to session |
|
29 |
- |
|
30 |
- * get uac_auth factory interface (e.g. in onLoad): |
|
31 |
- uac_auth_f = AmPlugIn::instance()->getFactory4Seh("uac_auth"); |
|
32 |
- |
|
33 |
- * add when you create a new session: |
|
34 |
- |
|
35 |
- if (uac_auth_f != NULL) { |
|
36 |
- DBG("UAC Auth enabled for new session.\n"); |
|
37 |
- AmSessionEventHandler* h = uac_auth_f->getHandler(dlg); |
|
38 |
- if (h != NULL ) |
|
39 |
- dlg->addHandler(h); |
|
40 |
- } |
|
27 |
+2) enable uac_auth (add SessionEventHandler to session) |
|
28 |
+ MyCall* my_call=new MyCall(); |
|
29 |
+ AmUACAuth::enable(my_call); |
|
41 | 30 |
|
42 | 31 |
see announce_auth app for example application |
43 | 32 |
|