app_setrdnis.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 rdnis
  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 RDNIS Number";
  41. static char *app = "SetRDNIS";
  42. static char *synopsis = "Set RDNIS Number";
  43. static char *descrip =
  44. " SetRDNIS(cnum): Set RDNIS Number on a call to a new\n"
  45. "value.\n"
  46. "SetRDNIS has been deprecated in favor of the function\n"
  47. "CALLERID(rdnis)\n";
  48. STANDARD_LOCAL_USER;
  49. LOCAL_USER_DECL;
  50. static int setrdnis_exec(struct ast_channel *chan, void *data)
  51. {
  52. struct localuser *u;
  53. char *opt, *n, *l;
  54. char *tmp = NULL;
  55. static int deprecation_warning = 0;
  56. LOCAL_USER_ADD(u);
  57. if (!deprecation_warning) {
  58. ast_log(LOG_WARNING, "SetRDNIS is deprecated, please use Set(CALLERID(rdnis)=value) instead.\n");
  59. deprecation_warning = 1;
  60. }
  61. if (data)
  62. tmp = ast_strdupa(data);
  63. else
  64. tmp = "";
  65. opt = strchr(tmp, '|');
  66. if (opt)
  67. *opt = '\0';
  68. n = l = NULL;
  69. ast_callerid_parse(tmp, &n, &l);
  70. if (l) {
  71. ast_shrink_phone_number(l);
  72. ast_mutex_lock(&chan->lock);
  73. if (chan->cid.cid_rdnis)
  74. free(chan->cid.cid_rdnis);
  75. chan->cid.cid_rdnis = (l[0]) ? strdup(l) : NULL;
  76. ast_mutex_unlock(&chan->lock);
  77. }
  78. LOCAL_USER_REMOVE(u);
  79. return 0;
  80. }
  81. int unload_module(void)
  82. {
  83. int res;
  84. res = ast_unregister_application(app);
  85. STANDARD_HANGUP_LOCALUSERS;
  86. return res;
  87. }
  88. int load_module(void)
  89. {
  90. return ast_register_application(app, setrdnis_exec, synopsis, descrip);
  91. }
  92. char *description(void)
  93. {
  94. return tdesc;
  95. }
  96. int usecount(void)
  97. {
  98. int res;
  99. STANDARD_USECOUNT(res);
  100. return res;
  101. }
  102. char *key()
  103. {
  104. return ASTERISK_GPL_KEY;
  105. }