cpl_log.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser 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. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. *
  28. * History:
  29. * -------
  30. * 2003-09-22: created (bogdan)
  31. *
  32. */
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include "cpl_log.h"
  36. #include "../../mem/mem.h"
  37. #include "../../dprint.h"
  38. static str cpl_logs[MAX_LOG_NR];
  39. static int nr_logs;
  40. void reset_logs()
  41. {
  42. nr_logs = 0;
  43. }
  44. void append_log( int nr, ...)
  45. {
  46. va_list ap;
  47. int i;
  48. if ( nr_logs+nr>MAX_LOG_NR ) {
  49. LOG(L_ERR,"ERROR:cpl-c:append_log: no more space fr logging\n");
  50. return;
  51. }
  52. va_start(ap, nr);
  53. for(i=0;i<nr;i++,nr_logs++) {
  54. cpl_logs[nr_logs].s = va_arg(ap, char *);
  55. cpl_logs[nr_logs].len = va_arg(ap, int );
  56. }
  57. va_end(ap);
  58. }
  59. void compile_logs( str *log)
  60. {
  61. int i;
  62. char *p;
  63. log->s = 0;
  64. log->len = 0;
  65. if (nr_logs==0)
  66. /* no logs */
  67. return;
  68. /* compile the total len */
  69. for(i=0;i<nr_logs;i++)
  70. log->len += cpl_logs[i].len;
  71. /* get a buffer */
  72. log->s = (char*)pkg_malloc(log->len);
  73. if (log->s==0) {
  74. LOG(L_ERR,"ERROR:cpl-c:compile_logs: no more pkg mem\n");
  75. log->len = 0;
  76. return;
  77. }
  78. /*copy all logs into buffer */
  79. p = log->s;
  80. for(i=0;i<nr_logs;i++) {
  81. memcpy( p, cpl_logs[i].s, cpl_logs[i].len);
  82. p += cpl_logs[i].len;
  83. }
  84. return;
  85. }