CHANNEL(callid): Give dialplan access to the callid.
[asterisk/asterisk.git] / funcs / func_blacklist.c
index c353b20..fdc899b 100644 (file)
  * 
  */
 
-#include "asterisk.h"
+/*** MODULEINFO
+       <support_level>core</support_level>
+ ***/
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#include "asterisk.h"
 
 #include "asterisk/pbx.h"
 #include "asterisk/module.h"
@@ -45,6 +47,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        <para>Uses astdb to check if the Caller*ID is in family <literal>blacklist</literal>.
                        Returns <literal>1</literal> or <literal>0</literal>.</para>
                </description>
+               <see-also>
+                       <ref type="function">DB</ref>
+               </see-also>
        </function>
 
 ***/
@@ -54,12 +59,17 @@ static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data,
        char blacklist[1];
        int bl = 0;
 
-       if (chan->cid.cid_num) {
-               if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist)))
+       if (!chan) {
+               ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+               return -1;
+       }
+
+       if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) {
+               if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.number.str, blacklist, sizeof (blacklist)))
                        bl = 1;
        }
-       if (chan->cid.cid_name) {
-               if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist)))
+       if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
+               if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.name.str, blacklist, sizeof (blacklist)))
                        bl = 1;
        }
 
@@ -67,9 +77,26 @@ static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data,
        return 0;
 }
 
+static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
+{
+       /* 2 bytes is a single integer, plus terminating null */
+       if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
+               if (len > ast_str_size(*str) || len == 0) {
+                       ast_str_make_space(str, len ? len : ast_str_strlen(*str) + 2);
+               }
+       }
+       if (ast_str_size(*str) - ast_str_strlen(*str) >= 2) {
+               int res = blacklist_read(chan, cmd, data, ast_str_buffer(*str) + ast_str_strlen(*str), 2);
+               ast_str_update(*str);
+               return res;
+       }
+       return -1;
+}
+
 static struct ast_custom_function blacklist_function = {
        .name = "BLACKLIST",
        .read = blacklist_read,
+       .read2 = blacklist_read2,
 };
 
 static int unload_module(void)