cpl_log.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. *
  23. * History:
  24. * -------
  25. * 2003-09-22: created (bogdan)
  26. *
  27. */
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "cpl_log.h"
  31. #include "../../mem/mem.h"
  32. #include "../../dprint.h"
  33. static str cpl_logs[MAX_LOG_NR];
  34. static int nr_logs;
  35. void reset_logs(void)
  36. {
  37. nr_logs = 0;
  38. }
  39. void append_log( int nr, ...)
  40. {
  41. va_list ap;
  42. int i;
  43. if ( nr_logs+nr>MAX_LOG_NR ) {
  44. LM_ERR("no more space for logging\n");
  45. return;
  46. }
  47. va_start(ap, nr);
  48. for(i=0;i<nr;i++,nr_logs++) {
  49. cpl_logs[nr_logs].s = va_arg(ap, char *);
  50. cpl_logs[nr_logs].len = va_arg(ap, int );
  51. }
  52. va_end(ap);
  53. }
  54. void compile_logs( str *log)
  55. {
  56. int i;
  57. char *p;
  58. log->s = 0;
  59. log->len = 0;
  60. if (nr_logs==0)
  61. /* no logs */
  62. return;
  63. /* compile the total len */
  64. for(i=0;i<nr_logs;i++)
  65. log->len += cpl_logs[i].len;
  66. /* get a buffer */
  67. log->s = (char*)pkg_malloc(log->len);
  68. if (log->s==0) {
  69. LM_ERR("no more pkg mem\n");
  70. log->len = 0;
  71. return;
  72. }
  73. /*copy all logs into buffer */
  74. p = log->s;
  75. for(i=0;i<nr_logs;i++) {
  76. memcpy( p, cpl_logs[i].s, cpl_logs[i].len);
  77. p += cpl_logs[i].len;
  78. }
  79. return;
  80. }