You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

perl.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <syslog.h>
  7. #include <glib.h>
  8. #include <EXTERN.h> /* from the Perl distribution */
  9. #include <perl.h> /* from the Perl distribution */
  10. #include "url.h"
  11. #include "main.h"
  12. #include "perl.h"
  13. extern PerlInterpreter *my_perl;
  14. int
  15. perl_call_header_filter (const char *function, struct worker_task *task)
  16. {
  17. int result;
  18. dSP;
  19. ENTER;
  20. SAVETMPS;
  21. PUSHMARK (SP);
  22. XPUSHs (sv_2mortal (newSViv (PTR2IV (task))));
  23. PUTBACK;
  24. call_pv (function, G_SCALAR);
  25. SPAGAIN;
  26. result = POPi;
  27. msg_debug ("header_filter: call of %s with returned mark %d\n", function, result);
  28. PUTBACK;
  29. FREETMPS;
  30. LEAVE;
  31. return result;
  32. }
  33. int
  34. perl_call_mime_filter (const char *function, struct worker_task *task)
  35. {
  36. int result;
  37. dSP;
  38. ENTER;
  39. SAVETMPS;
  40. PUSHMARK (SP);
  41. XPUSHs (sv_2mortal (newSViv (PTR2IV (task))));
  42. PUTBACK;
  43. call_pv (function, G_SCALAR);
  44. SPAGAIN;
  45. result = POPi;
  46. msg_debug ("mime_filter: call of %s returned mark %d\n", function, result);
  47. PUTBACK;
  48. FREETMPS;
  49. LEAVE;
  50. return result;
  51. }
  52. int
  53. perl_call_message_filter (const char *function, struct worker_task *task)
  54. {
  55. int result;
  56. dSP;
  57. ENTER;
  58. SAVETMPS;
  59. PUSHMARK (SP);
  60. XPUSHs (sv_2mortal (newSViv (PTR2IV (task))));
  61. PUTBACK;
  62. call_pv (function, G_SCALAR);
  63. SPAGAIN;
  64. result = POPi;
  65. msg_debug ("message_filter: call of %s returned mark %d\n", function, result);
  66. PUTBACK;
  67. FREETMPS;
  68. LEAVE;
  69. return result;
  70. }
  71. int
  72. perl_call_url_filter (const char *function, struct worker_task *task)
  73. {
  74. int result;
  75. dSP;
  76. ENTER;
  77. SAVETMPS;
  78. PUSHMARK (SP);
  79. XPUSHs (sv_2mortal (newSViv (PTR2IV (task))));
  80. PUTBACK;
  81. call_pv (function, G_SCALAR);
  82. SPAGAIN;
  83. result = POPi;
  84. msg_debug ("url_filter: call of %s for url returned mark %d\n", function, result);
  85. PUTBACK;
  86. FREETMPS;
  87. LEAVE;
  88. return result;
  89. }
  90. int
  91. perl_call_chain_filter (const char *function, struct worker_task *task, int *marks, unsigned int number)
  92. {
  93. int result, i;
  94. AV *av;
  95. dSP;
  96. ENTER;
  97. SAVETMPS;
  98. av = newAV();
  99. av_extend (av, number);
  100. for (i = 0; i < number; i ++) {
  101. av_push (av, sv_2mortal (newSViv (marks[i])));
  102. }
  103. PUSHMARK (SP);
  104. XPUSHs (sv_2mortal (newSViv (PTR2IV (task))));
  105. XPUSHs (sv_2mortal ((SV *)AvARRAY (av)));
  106. PUTBACK;
  107. call_pv (function, G_SCALAR);
  108. SPAGAIN;
  109. result = POPi;
  110. msg_debug ("chain_filter: call of %s returned mark %d\n", function, result);
  111. PUTBACK;
  112. FREETMPS;
  113. av_undef (av);
  114. LEAVE;
  115. return result;
  116. }
  117. void perl_call_memcached_callback (memcached_ctx_t *ctx, memc_error_t error, void *data)
  118. {
  119. struct {
  120. SV *callback;
  121. struct worker_task *task;
  122. } *callback_data = data;
  123. dSP;
  124. ENTER;
  125. SAVETMPS;
  126. PUSHMARK (SP);
  127. XPUSHs (sv_2mortal (newSViv (PTR2IV (callback_data->task))));
  128. XPUSHs (sv_2mortal (newSViv (error)));
  129. XPUSHs (sv_2mortal (newSVpv (ctx->param->buf, ctx->param->bufsize)));
  130. PUTBACK;
  131. call_sv (callback_data->callback, G_SCALAR);
  132. /* Set save point */
  133. callback_data->task->save.saved = 0;
  134. process_filters (callback_data->task);
  135. SPAGAIN;
  136. FREETMPS;
  137. LEAVE;
  138. }