pv_select.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Select Pseudo-variables
  25. */
  26. #include "../../select.h"
  27. #include "pv_select.h"
  28. int pv_parse_select_name(pv_spec_p sp, str *in)
  29. {
  30. select_t *sel = 0;
  31. char c;
  32. char *p;
  33. if (in == NULL || in->s == NULL || sp == NULL)
  34. return -1;
  35. c = in->s[in->len];
  36. in->s[in->len] = '\0';
  37. p = in->s;
  38. if(parse_select(&p, &sel)<0)
  39. {
  40. LM_ERR("invalid select name [%.*s]\n",
  41. in->len, in->s);
  42. in->s[in->len] = c;
  43. return -1;
  44. }
  45. in->s[in->len] = c;
  46. sp->pvp.pvn.u.dname = (void*)sel;
  47. sp->pvp.pvn.type = PV_NAME_OTHER;
  48. return 0;
  49. }
  50. int pv_get_select(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
  51. {
  52. str s = {0, 0};
  53. select_t *sel = 0;
  54. sel = (select_t*)param->pvn.u.dname;
  55. if(sel==0 || run_select(&s, sel, msg)<0 || s.s==0)
  56. return pv_get_null(msg, param, res);
  57. return pv_get_strval(msg, param, res, &s);
  58. }