Privacy updates
authorMark Spencer <markster@digium.com>
Wed, 26 Mar 2003 21:52:26 +0000 (21:52 +0000)
committerMark Spencer <markster@digium.com>
Wed, 26 Mar 2003 21:52:26 +0000 (21:52 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@700 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_privacy.c
configs/privacy.conf.sample [new file with mode: 0755]

index 91194a1..9b5e0c9 100755 (executable)
 #include <asterisk/image.h>
 #include <asterisk/callerid.h>
 #include <asterisk/app.h>
 #include <asterisk/image.h>
 #include <asterisk/callerid.h>
 #include <asterisk/app.h>
+#include <asterisk/config.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
 
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
 
+#define PRIV_CONFIG "privacy.conf"
+
 static char *tdesc = "Require phone number to be entered, if no CallerID sent";
 
 static char *app = "PrivacyManager";
 static char *tdesc = "Require phone number to be entered, if no CallerID sent";
 
 static char *app = "PrivacyManager";
@@ -51,9 +54,13 @@ privacy_exec (struct ast_channel *chan, void *data)
 {
        int res=0;
        int retries;
 {
        int res=0;
        int retries;
+       int maxretries = 3;
+       int x;
+       char *s;
        char phone[10];
        char new_cid[144];
        struct localuser *u;
        char phone[10];
        char new_cid[144];
        struct localuser *u;
+       struct ast_config *cfg;
 
        LOCAL_USER_ADD (u);
        if (chan->callerid)
 
        LOCAL_USER_ADD (u);
        if (chan->callerid)
@@ -71,17 +78,29 @@ privacy_exec (struct ast_channel *chan, void *data)
                                return -1;
                        }
                }
                                return -1;
                        }
                }
-               /*Just a quick sleep*/
-               sleep(1);
+               /*Read in the config file*/
+               cfg = ast_load(PRIV_CONFIG);
+               
                
                /*Play unidentified call*/
                
                /*Play unidentified call*/
-               res = ast_streamfile(chan, "privacy-unident", chan->language);
+               res = ast_safe_sleep(1);
+               if (!res)
+                       res = ast_streamfile(chan, "privacy-unident", chan->language);
                if (!res)
                        res = ast_waitstream(chan, "");
 
                if (!res)
                        res = ast_waitstream(chan, "");
 
+        if (cfg && (s = ast_variable_retrieve(cfg, "general", "maxretries"))) {
+                if (sscanf(s, "%d", &x) == 1) {
+                        maxretries = x;
+                } else {
+                        ast_log(LOG_WARNING, "Invalid max retries argument\n");
+                }
+        }
+                       
                /*Ask for 10 digit number, give 3 attempts*/
                /*Ask for 10 digit number, give 3 attempts*/
-               for (retries = 0; retries < 3; retries++) {
-                       res = ast_app_getdata(chan, "privacy-prompt", phone, sizeof(phone), 0);
+               for (retries = 0; retries < maxretries; retries++) {
+                       if (!res)
+                               res = ast_app_getdata(chan, "privacy-prompt", phone, sizeof(phone), 0);
                        if (res < 0)
                                break;
 
                        if (res < 0)
                                break;
 
@@ -96,7 +115,7 @@ privacy_exec (struct ast_channel *chan, void *data)
                }
                
                /*Got a number, play sounds and send them on their way*/
                }
                
                /*Got a number, play sounds and send them on their way*/
-               if ((retries < 3) && !res) {
+               if ((retries < maxretries) && !res) {
                        res = ast_streamfile(chan, "privacy-thankyou", chan->language);
                        if (!res)
                                res = ast_waitstream(chan, "");
                        res = ast_streamfile(chan, "privacy-thankyou", chan->language);
                        if (!res)
                                res = ast_waitstream(chan, "");
@@ -109,6 +128,8 @@ privacy_exec (struct ast_channel *chan, void *data)
                        if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
                                chan->priority+=100;
                }
                        if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
                                chan->priority+=100;
                }
+               if (cfg) 
+                       ast_destroy(cfg);
        }
 
   LOCAL_USER_REMOVE (u);
        }
 
   LOCAL_USER_REMOVE (u);
diff --git a/configs/privacy.conf.sample b/configs/privacy.conf.sample
new file mode 100755 (executable)
index 0000000..0236bcc
--- /dev/null
@@ -0,0 +1,3 @@
+[general]
+
+maxretries = 2 ;How many chances the caller has to enter their number