app_setcallerid.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * App to set callerid
  5. *
  6. * Copyright (C) 1999, Mark Spencer
  7. *
  8. * Mark Spencer <markster@linux-support.net>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. #include <asterisk/lock.h>
  14. #include <asterisk/file.h>
  15. #include <asterisk/logger.h>
  16. #include <asterisk/channel.h>
  17. #include <asterisk/pbx.h>
  18. #include <asterisk/module.h>
  19. #include <asterisk/translate.h>
  20. #include <asterisk/image.h>
  21. #include <asterisk/callerid.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. static char *app2 = "SetCallerPres";
  25. static char *synopsis2 = "Set CallerID Presentation";
  26. STANDARD_LOCAL_USER;
  27. LOCAL_USER_DECL;
  28. static struct {
  29. int val;
  30. char *name;
  31. } preses[] = {
  32. { AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "allowed_not_screened" },
  33. { AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "allowed_passed_screen" },
  34. { AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, "allowed_failed_screen" },
  35. { AST_PRES_ALLOWED_NETWORK_NUMBER, "allowed" },
  36. { AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED , "prohib_not_screened" },
  37. { AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, "prohib_passed_screen" },
  38. { AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, "prohib_failed_screen" },
  39. { AST_PRES_PROHIB_NETWORK_NUMBER, "prohib" },
  40. { AST_PRES_NUMBER_NOT_AVAILABLE, "unavailable" },
  41. };
  42. static char *descrip2 =
  43. " SetCallerPres(presentation): Set Caller*ID presentation on\n"
  44. "a call to a new value. Sets ANI as well if a flag is used.\n"
  45. "Always returns 0. Valid presentations are:\n"
  46. "\n"
  47. " allowed_not_screened : Presentation Allowed, Not Screened\n"
  48. " allowed_passed_screen : Presentation Allowed, Passed Screen\n"
  49. " allowed_failed_screen : Presentation Allowed, Failed Screen\n"
  50. " allowed : Presentation Allowed, Network Number\n"
  51. " prohib_not_screened : Presentation Prohibited, Not Screened\n"
  52. " prohib_passed_screen : Presentation Prohibited, Passed Screen\n"
  53. " prohib_failed_screen : Presentation Prohibited, Failed Screen\n"
  54. " prohib : Presentation Prohibited, Network Number\n"
  55. " unavailable : Number Unavailable\n"
  56. "\n"
  57. ;
  58. static int setcallerid_pres_exec(struct ast_channel *chan, void *data)
  59. {
  60. int res = 0;
  61. char tmp[256] = "";
  62. struct localuser *u;
  63. int x;
  64. char *opts;
  65. int pres = -1;
  66. if (data)
  67. strncpy(tmp, (char *)data, sizeof(tmp) - 1);
  68. opts = strchr(tmp, '|');
  69. if (opts) {
  70. *opts = '\0';
  71. opts++;
  72. }
  73. for (x=0;x<sizeof(preses) / sizeof(preses[0]);x++) {
  74. if (!strcasecmp(preses[x].name, tmp)) {
  75. pres = preses[x].val;
  76. break;
  77. }
  78. }
  79. if (pres < 0) {
  80. ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n", tmp);
  81. return 0;
  82. }
  83. LOCAL_USER_ADD(u);
  84. chan->callingpres = pres;
  85. LOCAL_USER_REMOVE(u);
  86. return res;
  87. }
  88. static char *tdesc = "Set CallerID Application";
  89. static char *app = "SetCallerID";
  90. static char *synopsis = "Set CallerID";
  91. static char *descrip =
  92. " SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
  93. "value. Sets ANI as well if a flag is used. Always returns 0\n";
  94. static int setcallerid_exec(struct ast_channel *chan, void *data)
  95. {
  96. int res = 0;
  97. char tmp[256] = "";
  98. struct localuser *u;
  99. char *opt;
  100. int anitoo = 0;
  101. if (data)
  102. strncpy(tmp, (char *)data, sizeof(tmp) - 1);
  103. opt = strchr(tmp, '|');
  104. if (opt) {
  105. *opt = '\0';
  106. opt++;
  107. if (*opt == 'a')
  108. anitoo = 1;
  109. }
  110. LOCAL_USER_ADD(u);
  111. ast_set_callerid(chan, strlen(tmp) ? tmp : NULL, anitoo);
  112. LOCAL_USER_REMOVE(u);
  113. return res;
  114. }
  115. int unload_module(void)
  116. {
  117. STANDARD_HANGUP_LOCALUSERS;
  118. ast_unregister_application(app2);
  119. return ast_unregister_application(app);
  120. }
  121. int load_module(void)
  122. {
  123. ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
  124. return ast_register_application(app, setcallerid_exec, synopsis, descrip);
  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. }