summaryrefslogtreecommitdiffstats
path: root/perl.c
blob: 78a2c7670dd9b165c767b5ee0fff3de85a52d235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>

#include <glib.h>

#include <EXTERN.h>               /* from the Perl distribution     */
#include <perl.h>                 /* from the Perl distribution     */

#include "url.h"
#include "main.h"
#include "perl.h"

extern PerlInterpreter *my_perl;

int
call_header_filter (const char *function, const char *header_name, const char *header_value)
{
	int result;
	dSP;

	ENTER;
	SAVETMPS;

	PUSHMARK (SP);
	XPUSHs (sv_2mortal (newSVpv (header_name, 0)));
	XPUSHs (sv_2mortal (newSVpv (header_value, 0)));
	PUTBACK;
	
	call_pv (function, G_SCALAR);

	SPAGAIN;

	result = POPi;
	msg_debug ("header_filter: call of %s with header %s returned mark %d\n", function, header_name, result);

	PUTBACK;
	FREETMPS;
	LEAVE;

	return result;
}

int
call_mime_filter (const char *function, GByteArray *content)
{
	int result;
	dSP;

	ENTER;
	SAVETMPS;

	PUSHMARK (SP);
	XPUSHs (sv_2mortal (newSVpv (content->data, content->len)));
	PUTBACK;
	
	call_pv (function, G_SCALAR);

	SPAGAIN;

	result = POPi;
	msg_debug ("mime_filter: call of %s returned mark %d\n", function, result);

	PUTBACK;
	FREETMPS;
	LEAVE;

	return result;
}

int
call_message_filter (const char *function, GByteArray *content)
{
	int result;
	dSP;

	ENTER;
	SAVETMPS;

	PUSHMARK (SP);
	XPUSHs (sv_2mortal (newSVpv (content->data, content->len)));
	PUTBACK;
	
	call_pv (function, G_SCALAR);

	SPAGAIN;

	result = POPi;
	msg_debug ("message_filter: call of %s returned mark %d\n", function, result);

	PUTBACK;
	FREETMPS;
	LEAVE;

	return result;
}

int
call_url_filter (const char *function, struct uri *uri)
{
	int result;
	dSP;

	ENTER;
	SAVETMPS;
	
	/* URL:
	 * url,
	 * host,
	 * data
	 */
	PUSHMARK (SP);
	XPUSHs (sv_2mortal (newSVpv (uri->string, 0)));
	XPUSHs (sv_2mortal (newSVpv (uri->host, uri->hostlen)));
	XPUSHs (sv_2mortal (newSVpv (uri->data, uri->datalen)));
	PUTBACK;
	
	call_pv (function, G_SCALAR);

	SPAGAIN;

	result = POPi;
	msg_debug ("url_filter: call of %s for url '%s' returned mark %d\n", function, uri->string, result);

	PUTBACK;
	FREETMPS;
	LEAVE;

	return result;
}

int
call_chain_filter (const char *function, GArray *results)
{
	int result, i;

	dSP;

	ENTER;
	SAVETMPS;
	PUSHMARK (SP);
	for (i = 0; i < results->len; i ++) {
		XPUSHs (sv_2mortal (newSViv (g_array_index (results, int, i))));
	}
	PUTBACK;
	
	call_pv (function, G_SCALAR);

	SPAGAIN;

	result = POPi;
	msg_debug ("chain_filter: call of %s returned mark %d\n", function, result);

	PUTBACK;
	FREETMPS;
	LEAVE;


	return result;
}