Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:48 2009

## Asterisk developer's documentation

# app_lookupcidname.c

Go to the documentation of this file.

    00001 /*
    00002  * Asterisk -- An open source telephony toolkit.
    00003  *
    00004  * Copyright (C) 1999 - 2005, Digium, Inc.
    00005  *
    00006  * Mark Spencer <markster@digium.com>
    00007  *
    00008  * See http://www.asterisk.org for more information about
    00009  * the Asterisk project. Please do not directly contact
    00010  * any of the maintainers of this project for assistance;
    00011  * the project provides a web site, mailing lists and IRC
    00012  * channels for your use.
    00013  *
    00014  * This program is free software, distributed under the terms of
    00015  * the GNU General Public License Version 2. See the LICENSE file
    00016  * at the top of the source tree.
    00017  */
    00018
    00019 /*! \file
    00020  *
    00021  * \brief App to set callerid name from database, based on directory number
    00022  *
    00023  * \ingroup applications
    00024  */
    00025
    00026 #include <stdlib.h>
    00027 #include <stdio.h>
    00028 #include <string.h>
    00029
    00030 #include "asterisk.h"
    00031
    00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
    00033
    00034 #include "asterisk/lock.h"
    00035 #include "asterisk/file.h"
    00036 #include "asterisk/logger.h"
    00037 #include "asterisk/options.h"
    00038 #include "asterisk/channel.h"
    00039 #include "asterisk/pbx.h"
    00040 #include "asterisk/module.h"
    00041 #include "asterisk/translate.h"
    00042 #include "asterisk/image.h"
    00043 #include "asterisk/callerid.h"
    00044 #include "asterisk/astdb.h"
    00045
    00046 static char *tdesc = "Look up CallerID Name from local database";
    00047
    00048 static char *app = "LookupCIDName";
    00049
    00050 static char *synopsis = "Look up CallerID Name from local database";
    00051
    00052 static char *descrip =
    00053   "  LookupCIDName: Looks up the Caller*ID number on the active\n"
    00054   "channel in the Asterisk database (family 'cidname') and sets the\n"
    00055   "Caller*ID name.  Does nothing if no Caller*ID was received on the\n"
    00056   "channel.  This is useful if you do not subscribe to Caller*ID\n"
    00057   "name delivery, or if you want to change the names on some incoming\n"
    00058   "calls.\n";
    00059
    00060 STANDARD_LOCAL_USER;
    00061
    00062 LOCAL_USER_DECL;
    00063
    00064 static int
    00065 lookupcidname_exec (struct ast_channel *chan, void *data)
    00066 {
    00067   char dbname[64];
    00068   struct localuser *u;
    00069
    00070   LOCAL_USER_ADD (u);
    00071   if (chan->cid.cid_num) {
    00072    if (!ast_db_get ("cidname", chan->cid.cid_num, dbname, sizeof (dbname))) {
    00073       ast_set_callerid (chan, NULL, dbname, NULL);
    00074         if (option_verbose > 2)
    00075           ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID name to %s\n",
    00076              dbname);
    00077    }
    00078   }
    00079   LOCAL_USER_REMOVE (u);
    00080   return 0;
    00081 }
    00082
    00083 int
    00084 unload_module (void)
    00085 {
    00086    int res;
    00087
    00088    res = ast_unregister_application (app);
    00089
    00090    STANDARD_HANGUP_LOCALUSERS;
    00091
    00092    return res;
    00093 }
    00094
    00095 int
    00096 load_module (void)
    00097 {
    00098   return ast_register_application (app, lookupcidname_exec, synopsis,
    00099                descrip);
    00100 }
    00101
    00102 char *
    00103 description (void)
    00104 {
    00105   return tdesc;
    00106 }
    00107
    00108 int
    00109 usecount (void)
    00110 {
    00111   int res;
    00112   STANDARD_USECOUNT (res);
    00113   return res;
    00114 }
    00115
    00116 char *
    00117 key ()
    00118 {
    00119   return ASTERISK_GPL_KEY;
    00120 }