app_forkcdr.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Fork CDR application
  5. * Copyright Anthony Minessale anthmct@yahoo.com
  6. * Development of this app Sponsered/Funded by TAAN Softworks Corp
  7. *
  8. * This program is free software, distributed under the terms of
  9. * the GNU General Public License
  10. */
  11. #include <asterisk/file.h>
  12. #include <asterisk/logger.h>
  13. #include <asterisk/channel.h>
  14. #include <asterisk/pbx.h>
  15. #include <asterisk/cdr.h>
  16. #include <asterisk/module.h>
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include <pthread.h>
  21. static char *tdesc = "Fork The CDR into 2 separate entities.";
  22. static char *app = "ForkCDR";
  23. static char *synopsis =
  24. "Forks the Call Data Record";
  25. static char *descrip =
  26. " ForkCDR(): Causes the Call Data Record to fork an additional\n"
  27. "cdr record starting from the time of the fork call\n";
  28. STANDARD_LOCAL_USER;
  29. LOCAL_USER_DECL;
  30. static void ast_cdr_clone(struct ast_cdr *cdr) {
  31. struct ast_cdr *newcdr = ast_cdr_alloc();
  32. memcpy(newcdr,cdr,sizeof(struct ast_cdr));
  33. newcdr->next = NULL;
  34. ast_cdr_append(cdr,newcdr);
  35. gettimeofday(&newcdr->start, NULL);
  36. memset(&newcdr->answer, 0, sizeof(newcdr->answer));
  37. ast_cdr_add_flag(cdr,AST_CDR_FLAG_CHILD|AST_CDR_FLAG_LOCKED);
  38. }
  39. static void ast_cdr_fork(struct ast_channel *chan) {
  40. if(chan && chan->cdr) {
  41. ast_cdr_clone(chan->cdr);
  42. }
  43. }
  44. static int forkcdr_exec(struct ast_channel *chan, void *data)
  45. {
  46. int res=0;
  47. struct localuser *u;
  48. LOCAL_USER_ADD(u);
  49. ast_cdr_fork(chan);
  50. LOCAL_USER_REMOVE(u);
  51. return res;
  52. }
  53. int unload_module(void)
  54. {
  55. STANDARD_HANGUP_LOCALUSERS;
  56. return ast_unregister_application(app);
  57. }
  58. int load_module(void)
  59. {
  60. return ast_register_application(app, forkcdr_exec, synopsis, descrip);
  61. }
  62. char *description(void)
  63. {
  64. return tdesc;
  65. }
  66. int usecount(void)
  67. {
  68. int res;
  69. STANDARD_USECOUNT(res);
  70. return res;
  71. }
  72. char *key()
  73. {
  74. return ASTERISK_GPL_KEY;
  75. }