pv_core.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2009 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * pv_core.c - pvars needed in the core, e.g. $?, $retcode
  20. *
  21. * Note: in general please avoid adding pvars directly to the core, unless
  22. * absolutely necessary (use/create a new module instead).
  23. */
  24. /*!
  25. * \file
  26. * \brief SIP-router core ::
  27. * \ingroup core
  28. * Module: \ref core
  29. */
  30. #include "pv_core.h"
  31. #include "pvar.h"
  32. #include "str.h"
  33. static int pv_get_retcode(struct sip_msg*, pv_param_t*, pv_value_t*);
  34. static pv_export_t core_pvs[] = {
  35. /* return code, various synonims */
  36. { STR_STATIC_INIT("?"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
  37. { STR_STATIC_INIT("rc"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
  38. { STR_STATIC_INIT("retcode"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
  39. { {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
  40. };
  41. /* ugly hack to get the return code, needed because the PVs do not know (yet)
  42. about the script context */
  43. extern int _last_returned_code;
  44. static int pv_get_retcode(struct sip_msg* msg, pv_param_t* p, pv_value_t* res)
  45. {
  46. /* FIXME: as soon as PVs support script context, use it instead of the
  47. return in global variable hack */
  48. return pv_get_sintval(msg, p, res, _last_returned_code);
  49. }
  50. /** register built-in core pvars.
  51. * should be called before parsing the config script.
  52. * @return 0 on success
  53. */
  54. int pv_register_core_vars(void)
  55. {
  56. return register_pvars_mod("core", core_pvs);
  57. }
  58. /* vi: set ts=4 sw=4 tw=79:ai:cindent: */