pv_stats.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * \file
  24. * \brief Implementation for Stats Pseudo-variables
  25. */
  26. #include "../../lib/kcore/statistics.h"
  27. #include "../../ver.h"
  28. #include "pv_stats.h"
  29. /**
  30. *
  31. */
  32. int pv_parse_stat_name(pv_spec_p sp, str *in)
  33. {
  34. if (in == NULL || in->s == NULL || sp == NULL)
  35. return -1;
  36. sp->pvp.pvn.type = PV_NAME_INTSTR;
  37. sp->pvp.pvn.u.isname.type = AVP_NAME_STR;
  38. sp->pvp.pvn.u.isname.name.s = *in;
  39. return 0;
  40. }
  41. /**
  42. *
  43. */
  44. int pv_get_stat(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
  45. {
  46. stat_var *stat;
  47. stat = get_stat(&param->pvn.u.isname.name.s);
  48. if (stat == NULL) {
  49. LM_WARN("No stat variable ``%.*s''\n",
  50. param->pvn.u.isname.name.s.len, param->pvn.u.isname.name.s.s);
  51. return pv_get_null(msg, param, res);
  52. }
  53. return pv_get_uintval(msg, param, res,
  54. (unsigned int)get_stat_val(stat));
  55. }
  56. /**
  57. *
  58. */
  59. int pv_parse_sr_version_name(pv_spec_p sp, str *in)
  60. {
  61. if(sp==NULL || in==NULL || in->len<=0)
  62. return -1;
  63. switch(in->len)
  64. {
  65. case 3:
  66. if(strncmp(in->s, "num", 3)==0)
  67. sp->pvp.pvn.u.isname.name.n = 0;
  68. else goto error;
  69. break;
  70. case 4:
  71. if(strncmp(in->s, "full", 4)==0)
  72. sp->pvp.pvn.u.isname.name.n = 1;
  73. else if(strncmp(in->s, "hash", 4)==0)
  74. sp->pvp.pvn.u.isname.name.n = 2;
  75. else goto error;
  76. break;
  77. default:
  78. goto error;
  79. }
  80. sp->pvp.pvn.type = PV_NAME_INTSTR;
  81. sp->pvp.pvn.u.isname.type = 0;
  82. return 0;
  83. error:
  84. LM_ERR("unknown PV version name %.*s\n", in->len, in->s);
  85. return -1;
  86. }
  87. /**
  88. *
  89. */
  90. int pv_get_sr_version(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
  91. {
  92. if(param==NULL)
  93. return -1;
  94. switch(param->pvn.u.isname.name.n)
  95. {
  96. case 1:
  97. return pv_get_strzval(msg, param, res, (char*)full_version);
  98. case 2:
  99. return pv_get_strzval(msg, param, res, (char*)ver_id);
  100. default:
  101. return pv_get_strzval(msg, param, res, (char*)ver_version);
  102. }
  103. }