app_setcidnum.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. * Oliver Daudey <traveler@xs4all.nl>
  10. *
  11. * This program is free software, distributed under the terms of
  12. * the GNU General Public License
  13. */
  14. #include <asterisk/lock.h>
  15. #include <asterisk/file.h>
  16. #include <asterisk/logger.h>
  17. #include <asterisk/channel.h>
  18. #include <asterisk/pbx.h>
  19. #include <asterisk/module.h>
  20. #include <asterisk/translate.h>
  21. #include <asterisk/image.h>
  22. #include <asterisk/callerid.h>
  23. #include <asterisk/utils.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. static char *tdesc = "Set CallerID Number";
  27. static char *app = "SetCIDNum";
  28. static char *synopsis = "Set CallerID Number";
  29. static char *descrip =
  30. " SetCIDNum(cnum[|a]): Set Caller*ID Number on a call to a new\n"
  31. "value, while preserving the original Caller*ID name. This is\n"
  32. "useful for providing additional information to the called\n"
  33. "party. Sets ANI as well if a flag is used. Always returns 0\n";
  34. STANDARD_LOCAL_USER;
  35. LOCAL_USER_DECL;
  36. static int setcallerid_exec(struct ast_channel *chan, void *data)
  37. {
  38. int res = 0;
  39. char tmp[256] = "";
  40. char oldcid[256] = "", *l, *n;
  41. char newcid[256] = "";
  42. struct localuser *u;
  43. char *opt;
  44. int anitoo = 0;
  45. if (data)
  46. strncpy(tmp, (char *)data, sizeof(tmp) - 1);
  47. opt = strchr(tmp, '|');
  48. if (opt) {
  49. *opt = '\0';
  50. opt++;
  51. if (*opt == 'a')
  52. anitoo = 1;
  53. }
  54. LOCAL_USER_ADD(u);
  55. if (chan->callerid) {
  56. strncpy(oldcid, chan->callerid, sizeof(oldcid) - 1);
  57. ast_callerid_parse(oldcid, &n, &l);
  58. l = tmp;
  59. if (!ast_strlen_zero(l)) {
  60. if (n && !ast_strlen_zero(n))
  61. snprintf(newcid, sizeof(newcid), "\"%s\" <%s>", n, l);
  62. else
  63. strncpy(newcid, tmp, sizeof(newcid) - 1);
  64. } else if (n && !ast_strlen_zero(n)) {
  65. strncpy(newcid, n, sizeof(newcid) - 1);
  66. }
  67. } else
  68. strncpy(newcid, tmp, sizeof(newcid) - 1);
  69. ast_set_callerid(chan, !ast_strlen_zero(newcid) ? newcid : NULL, anitoo);
  70. LOCAL_USER_REMOVE(u);
  71. return res;
  72. }
  73. int unload_module(void)
  74. {
  75. STANDARD_HANGUP_LOCALUSERS;
  76. return ast_unregister_application(app);
  77. }
  78. int load_module(void)
  79. {
  80. return ast_register_application(app, setcallerid_exec, synopsis, descrip);
  81. }
  82. char *description(void)
  83. {
  84. return tdesc;
  85. }
  86. int usecount(void)
  87. {
  88. int res;
  89. STANDARD_USECOUNT(res);
  90. return res;
  91. }
  92. char *key()
  93. {
  94. return ASTERISK_GPL_KEY;
  95. }