perlvdb_oohelpers.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * $Id: perlvdb_oohelpers.c 770 2007-01-22 10:16:34Z bastian $
  3. *
  4. * Perl virtual database module interface
  5. *
  6. * Copyright (C) 2007 Collax GmbH
  7. * (Bastian Friedrich <[email protected]>)
  8. *
  9. * This file is part of Kamailio, a free SIP server.
  10. *
  11. * Kamailio is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version
  15. *
  16. * Kamailio is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. */
  26. #include "perlvdb_oohelpers.h"
  27. #include "../../mem/mem.h"
  28. SV *perlvdb_perlmethod(SV *class,
  29. const char* method,
  30. SV *param1,
  31. SV *param2,
  32. SV *param3,
  33. SV *param4) {
  34. I32 res;
  35. SV *retval = NULL;
  36. dSP;
  37. ENTER;
  38. SAVETMPS;
  39. PUSHMARK(SP);
  40. /* passed stack:
  41. * class, and optionally parameters
  42. */
  43. XPUSHs(class);
  44. if (param1) {
  45. XPUSHs(param1);
  46. }
  47. if (param2) {
  48. XPUSHs(param2);
  49. }
  50. if (param3) {
  51. XPUSHs(param3);
  52. }
  53. if (param4) {
  54. XPUSHs(param4);
  55. }
  56. PUTBACK;
  57. res = call_method(method, G_SCALAR | G_EVAL);
  58. SPAGAIN;
  59. if (res == 0) {
  60. retval = &PL_sv_undef;
  61. } else if (res == 1) {
  62. retval = POPs;
  63. } else {
  64. /* More than one result in Scalar context??? */
  65. LM_CRIT("got more than one result from scalar method!");
  66. while (res--) { /* Try to clean stack. This
  67. should never happen anyway.*/
  68. retval = POPs;
  69. }
  70. }
  71. SPAGAIN;
  72. // if (sv_isobject(retval))
  73. SvREFCNT_inc(retval);
  74. FREETMPS;
  75. LEAVE;
  76. return retval;
  77. }