app_setcallerid.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief App to set callerid
  21. *
  22. * \ingroup applications
  23. */
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/lock.h"
  30. #include "asterisk/file.h"
  31. #include "asterisk/logger.h"
  32. #include "asterisk/channel.h"
  33. #include "asterisk/pbx.h"
  34. #include "asterisk/module.h"
  35. #include "asterisk/translate.h"
  36. #include "asterisk/image.h"
  37. #include "asterisk/callerid.h"
  38. static char *app2 = "SetCallerPres";
  39. static char *synopsis2 = "Set CallerID Presentation";
  40. STANDARD_LOCAL_USER;
  41. LOCAL_USER_DECL;
  42. static char *descrip2 =
  43. " SetCallerPres(presentation): Set Caller*ID presentation on a call.\n"
  44. " Valid presentations are:\n"
  45. "\n"
  46. " allowed_not_screened : Presentation Allowed, Not Screened\n"
  47. " allowed_passed_screen : Presentation Allowed, Passed Screen\n"
  48. " allowed_failed_screen : Presentation Allowed, Failed Screen\n"
  49. " allowed : Presentation Allowed, Network Number\n"
  50. " prohib_not_screened : Presentation Prohibited, Not Screened\n"
  51. " prohib_passed_screen : Presentation Prohibited, Passed Screen\n"
  52. " prohib_failed_screen : Presentation Prohibited, Failed Screen\n"
  53. " prohib : Presentation Prohibited, Network Number\n"
  54. " unavailable : Number Unavailable\n"
  55. "\n"
  56. ;
  57. static int setcallerid_pres_exec(struct ast_channel *chan, void *data)
  58. {
  59. struct localuser *u;
  60. int pres = -1;
  61. LOCAL_USER_ADD(u);
  62. pres = ast_parse_caller_presentation(data);
  63. if (pres < 0) {
  64. ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
  65. (char *) data);
  66. LOCAL_USER_REMOVE(u);
  67. return 0;
  68. }
  69. chan->cid.cid_pres = pres;
  70. LOCAL_USER_REMOVE(u);
  71. return 0;
  72. }
  73. static char *tdesc = "Set CallerID Application";
  74. static char *app = "SetCallerID";
  75. static char *synopsis = "Set CallerID";
  76. static char *descrip =
  77. " SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
  78. "value. Sets ANI as well if a flag is used. \n";
  79. static int setcallerid_exec(struct ast_channel *chan, void *data)
  80. {
  81. int res = 0;
  82. char *tmp = NULL;
  83. char name[256];
  84. char num[256];
  85. struct localuser *u;
  86. char *opt;
  87. int anitoo = 0;
  88. if (ast_strlen_zero(data)) {
  89. ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
  90. return 0;
  91. }
  92. LOCAL_USER_ADD(u);
  93. tmp = ast_strdupa(data);
  94. if (!tmp) {
  95. ast_log(LOG_ERROR, "Out of memory\n");
  96. LOCAL_USER_REMOVE(u);
  97. return -1;
  98. }
  99. opt = strchr(tmp, '|');
  100. if (opt) {
  101. *opt = '\0';
  102. opt++;
  103. if (*opt == 'a')
  104. anitoo = 1;
  105. }
  106. ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
  107. ast_set_callerid(chan, num, name, anitoo ? num : NULL);
  108. LOCAL_USER_REMOVE(u);
  109. return res;
  110. }
  111. int unload_module(void)
  112. {
  113. int res;
  114. res = ast_unregister_application(app2);
  115. res |= ast_unregister_application(app);
  116. STANDARD_HANGUP_LOCALUSERS;
  117. return res;
  118. }
  119. int load_module(void)
  120. {
  121. int res;
  122. res = ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
  123. res |= ast_register_application(app, setcallerid_exec, synopsis, descrip);
  124. return res;
  125. }
  126. char *description(void)
  127. {
  128. return tdesc;
  129. }
  130. int usecount(void)
  131. {
  132. int res;
  133. STANDARD_USECOUNT(res);
  134. return res;
  135. }
  136. char *key()
  137. {
  138. return ASTERISK_GPL_KEY;
  139. }