Add Masquerade manager event which trips when a masquerade happens (issue #7840 repor...
[asterisk/asterisk.git] / funcs / func_callerid.c
index 056999e..6068739 100644 (file)
  * 
  */
 
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/module.h"
 #include "asterisk/channel.h"
 #include "asterisk/pbx.h"
@@ -42,6 +43,7 @@ static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
 {
        char *opt = data;
 
+       /* XXX we are not always clearing the buffer. Is this correct ? */
        if (strchr(opt, '|')) {
                char name[80], num[80];
 
@@ -57,13 +59,13 @@ static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
 
                        ast_copy_string(buf, num, len);
                } else {
-                       ast_log(LOG_ERROR, "Unknown callerid data type.\n");
+                       ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
                }
        } else {
                if (!strncasecmp("all", data, 3)) {
                        snprintf(buf, len, "\"%s\" <%s>",
-                                chan->cid.cid_name ? chan->cid.cid_name : "",
-                                chan->cid.cid_num ? chan->cid.cid_num : "");
+                                S_OR(chan->cid.cid_name, ""),
+                                S_OR(chan->cid.cid_num, ""));
                } else if (!strncasecmp("name", data, 4)) {
                        if (chan->cid.cid_name) {
                                ast_copy_string(buf, chan->cid.cid_name, len);
@@ -86,7 +88,7 @@ static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
                                ast_copy_string(buf, chan->cid.cid_rdnis, len);
                        }
                } else {
-                       ast_log(LOG_ERROR, "Unknown callerid data type.\n");
+                       ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
                }
        }
 
@@ -116,14 +118,14 @@ static int callerid_write(struct ast_channel *chan, char *cmd, char *data,
                /* do we need to lock chan here? */
                if (chan->cid.cid_dnid)
                        free(chan->cid.cid_dnid);
-               chan->cid.cid_dnid = ast_strlen_zero(value) ? NULL : strdup(value);
+               chan->cid.cid_dnid = ast_strdup(value);
        } else if (!strncasecmp("rdnis", data, 5)) {
                /* do we need to lock chan here? */
                if (chan->cid.cid_rdnis)
                        free(chan->cid.cid_rdnis);
-               chan->cid.cid_rdnis = ast_strlen_zero(value) ? NULL : strdup(value);
+               chan->cid.cid_rdnis = ast_strdup(value);
        } else {
-               ast_log(LOG_ERROR, "Unknown callerid data type.\n");
+               ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
        }
 
        return 0;
@@ -141,29 +143,14 @@ static struct ast_custom_function callerid_function = {
        .write = callerid_write,
 };
 
-static char *tdesc = "Caller ID related dialplan function";
-
-int unload_module(void)
+static int unload_module(void)
 {
        return ast_custom_function_unregister(&callerid_function);
 }
 
-int load_module(void)
+static int load_module(void)
 {
        return ast_custom_function_register(&callerid_function);
 }
 
-char *description(void)
-{
-       return tdesc;
-}
-
-int usecount(void)
-{
-       return 0;
-}
-
-char *key()
-{
-       return ASTERISK_GPL_KEY;
-}
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Caller ID related dialplan function");