Verify extension is correct
authorMark Spencer <markster@digium.com>
Sat, 16 Aug 2003 15:31:18 +0000 (15:31 +0000)
committerMark Spencer <markster@digium.com>
Sat, 16 Aug 2003 15:31:18 +0000 (15:31 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1350 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_agent.c

index aeb8677..6128965 100755 (executable)
@@ -983,12 +983,35 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
                                        if (!p->chan) {
                                                if (callbackmode) {
                                                        char tmpchan[256] = "";
+                                                       int pos = 0;
                                                        /* Retrieve login chan */
-                                                       if (exten) {
-                                                               strncpy(tmpchan, exten, sizeof(tmpchan) - 1);
-                                                               res = 0;
-                                                       } else
-                                                               res = ast_app_getdata(chan, "agent-newlocation", tmpchan, sizeof(tmpchan) - 1, 0);
+                                                       for (;;) {
+                                                               if (exten) {
+                                                                       strncpy(tmpchan, exten, sizeof(tmpchan) - 1);
+                                                                       res = 0;
+                                                               } else
+                                                                       res = ast_app_getdata(chan, "agent-newlocation", tmpchan+pos, sizeof(tmpchan) - 2, 0);
+                                                               if (!strlen(tmpchan) || ast_exists_extension(chan, context && strlen(context) ? context : "default", tmpchan,
+                                                                                       1, NULL))
+                                                                       break;
+                                                               if (exten) {
+                                                                       ast_log(LOG_WARNING, "Extension '%s' is not valid for automatic login of agent '%s'\n", exten, p->agent);
+                                                                       exten = NULL;
+                                                                       pos = 0;
+                                                               } else {
+                                                                       res = ast_streamfile(chan, "invalid", chan->language);
+                                                                       if (!res)
+                                                                               res = ast_waitstream(chan, AST_DIGIT_ANY);
+                                                                       if (res > 0) {
+                                                                               tmpchan[0] = res;
+                                                                               tmpchan[1] = '\0';
+                                                                               pos = 1;
+                                                                       } else {
+                                                                               tmpchan[0] = '\0';
+                                                                               pos = 0;
+                                                                       }
+                                                               }
+                                                       }
                                                        if (!res) {
                                                                if (context && strlen(context) && strlen(tmpchan))
                                                                        snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context);