app_setcidnum.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. * Oliver Daudey <traveler@xs4all.nl>
  8. *
  9. * See http://www.asterisk.org for more information about
  10. * the Asterisk project. Please do not directly contact
  11. * any of the maintainers of this project for assistance;
  12. * the project provides a web site, mailing lists and IRC
  13. * channels for your use.
  14. *
  15. * This program is free software, distributed under the terms of
  16. * the GNU General Public License Version 2. See the LICENSE file
  17. * at the top of the source tree.
  18. */
  19. /*! \file
  20. *
  21. * \brief App to set callerid number
  22. *
  23. * \ingroup applications
  24. */
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include "asterisk.h"
  29. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  30. #include "asterisk/lock.h"
  31. #include "asterisk/file.h"
  32. #include "asterisk/logger.h"
  33. #include "asterisk/channel.h"
  34. #include "asterisk/pbx.h"
  35. #include "asterisk/module.h"
  36. #include "asterisk/translate.h"
  37. #include "asterisk/image.h"
  38. #include "asterisk/callerid.h"
  39. #include "asterisk/utils.h"
  40. static char *tdesc = "Set CallerID Number";
  41. static char *app = "SetCIDNum";
  42. static char *synopsis = "Set CallerID Number";
  43. static char *descrip =
  44. " SetCIDNum(cnum[|a]): Set Caller*ID Number on a call to a new\n"
  45. "value, while preserving the original Caller*ID name. This is\n"
  46. "useful for providing additional information to the called\n"
  47. "party. Sets ANI as well if a flag is used.\n"
  48. "SetCIDNum has been deprecated in favor of the function\n"
  49. "CALLERID(number)\n";
  50. STANDARD_LOCAL_USER;
  51. LOCAL_USER_DECL;
  52. static int setcallerid_exec(struct ast_channel *chan, void *data)
  53. {
  54. int res = 0;
  55. struct localuser *u;
  56. char *opt;
  57. int anitoo = 0;
  58. char *tmp = NULL;
  59. static int deprecation_warning = 0;
  60. LOCAL_USER_ADD(u);
  61. if (!deprecation_warning) {
  62. ast_log(LOG_WARNING, "SetCIDNum is deprecated, please use Set(CALLERID(number)=value) instead.\n");
  63. deprecation_warning = 1;
  64. }
  65. if (data)
  66. tmp = ast_strdupa(data);
  67. else
  68. tmp = "";
  69. opt = strchr(tmp, '|');
  70. if (opt) {
  71. *opt = '\0';
  72. opt++;
  73. if (*opt == 'a')
  74. anitoo = 1;
  75. }
  76. ast_set_callerid(chan, tmp, NULL, anitoo ? tmp : NULL);
  77. LOCAL_USER_REMOVE(u);
  78. return res;
  79. }
  80. int unload_module(void)
  81. {
  82. int res;
  83. res = ast_unregister_application(app);
  84. STANDARD_HANGUP_LOCALUSERS;
  85. return res;
  86. }
  87. int load_module(void)
  88. {
  89. return ast_register_application(app, setcallerid_exec, synopsis, descrip);
  90. }
  91. char *description(void)
  92. {
  93. return tdesc;
  94. }
  95. int usecount(void)
  96. {
  97. int res;
  98. STANDARD_USECOUNT(res);
  99. return res;
  100. }
  101. char *key()
  102. {
  103. return ASTERISK_GPL_KEY;
  104. }