Skip to content

Commit 3a0a241

Browse files
author
Harald Radi
committed
added remaining functions, still untested, still having problems with config.m4
1 parent 38f5812 commit 3a0a241

File tree

2 files changed

+121
-15
lines changed

2 files changed

+121
-15
lines changed

sapi/milter/EXPERIMENTAL

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
this module is experimental,
2+
its functions may change their names
3+
or move to extension all together
4+
so do not rely to much on them
5+
you have been warned!

sapi/milter/php_milter.c

Lines changed: 116 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
139139

140140
params[0] = &host;
141141

142-
call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
142+
call_user_function(CG(function_table), NULL, function_name, retval, 1, params TSRMLS_CC);
143143

144144
if (Z_TYPE_P(retval) == IS_LONG) {
145145
return Z_LONG_P(retval);
@@ -151,16 +151,27 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
151151
/* envelope sender filter */
152152
static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
153153
{
154-
zval *function_name, *retval;
154+
zval *function_name, *retval, *v, **params[1];
155155
TSRMLS_FETCH();
156156

157157
/* set the milter context for possible use in API functions */
158158
MG(ctx) = ctx;
159159

160160
/* call userland */
161161
ZVAL_INIT(function_name);
162+
ZVAL_INIT(v);
163+
162164
ZVAL_STRING(function_name, "milter_envelope_from", 1);
163-
call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
165+
array_init(v);
166+
167+
while (*argv) {
168+
add_next_index_string(v, *argv, 1);
169+
argv++;
170+
}
171+
172+
params[0] = v;
173+
174+
call_user_function(CG(function_table), NULL, function_name, retval, 1, params TSRMLS_CC);
164175

165176
if (Z_TYPE_P(retval) == IS_LONG) {
166177
return Z_LONG_P(retval);
@@ -172,16 +183,27 @@ static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
172183
/* envelope recipient filter */
173184
static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv)
174185
{
175-
zval *function_name, *retval;
186+
zval *function_name, *retval, *v, **params[1];
176187
TSRMLS_FETCH();
177188

178189
/* set the milter context for possible use in API functions */
179190
MG(ctx) = ctx;
180191

181192
/* call userland */
182193
ZVAL_INIT(function_name);
194+
ZVAL_INIT(v);
195+
183196
ZVAL_STRING(function_name, "milter_envelope_recipient", 1);
184-
call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
197+
array_init(v);
198+
199+
while (*argv) {
200+
add_next_index_string(v, *argv, 1);
201+
argv++;
202+
}
203+
204+
params[0] = v;
205+
206+
call_user_function(CG(function_table), NULL, function_name, retval, 1, params TSRMLS_CC);
185207

186208
if (Z_TYPE_P(retval) == IS_LONG) {
187209
return Z_LONG_P(retval);
@@ -193,16 +215,25 @@ static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv)
193215
/* header filter */
194216
static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
195217
{
196-
zval *function_name, *retval;
218+
zval *function_name, *retval, *f, *v, **params[2];
197219
TSRMLS_FETCH();
198220

199221
/* set the milter context for possible use in API functions */
200222
MG(ctx) = ctx;
201223

202224
/* call userland */
203225
ZVAL_INIT(function_name);
226+
ZVAL_INIT(f);
227+
ZVAL_INIT(v);
228+
204229
ZVAL_STRING(function_name, "milter_header", 1);
205-
call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
230+
ZVAL_STRING(f, headerf, 1);
231+
ZVAL_STRING(v, headerv, 1);
232+
233+
params[0] = f;
234+
params[1] = v;
235+
236+
call_user_function(CG(function_table), NULL, function_name, retval, 2, params TSRMLS_CC);
206237

207238
if (Z_TYPE_P(retval) == IS_LONG) {
208239
return Z_LONG_P(retval);
@@ -235,15 +266,21 @@ static sfsistat mlfi_eoh(SMFICTX *ctx)
235266
/* body block */
236267
static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
237268
{
238-
zval *function_name, *retval;
269+
zval *function_name, *retval, *p, **params[1];;
239270
TSRMLS_FETCH();
240271

241272
/* set the milter context for possible use in API functions */
242273
MG(ctx) = ctx;
243274

244275
/* call userland */
245276
ZVAL_INIT(function_name);
277+
ZVAL_INIT(p);
278+
246279
ZVAL_STRING(function_name, "milter_body", 1);
280+
ZVAL_STRINGL(p, bodyp, len, 1);
281+
282+
params[0] = p;
283+
247284
call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
248285

249286
if (Z_TYPE_P(retval) == IS_LONG) {
@@ -342,37 +379,101 @@ struct smfiDesc smfilter = {
342379
*/
343380
PHP_FUNCTION(smfi_getsymval)
344381
{
345-
// smfi_getsymval();
382+
char *symname, *ret;
383+
int len;
384+
385+
if (zend_parse_parameters(1 TSRMLS_CC, "s", &symname, &len) == SUCCESS) {
386+
if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) {
387+
RETVAL_STRING(ret);
388+
}
389+
}
390+
391+
RETVAL_NULL();
346392
}
347393

348394
PHP_FUNCTION(smfi_setreply)
349395
{
350-
// smfi_setreply();
396+
char *rcode, *xcode, *message;
397+
int len;
398+
399+
if (zend_parse_parameters(3 TSRMLS_CC, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) {
400+
if (smfi_setreply(MG(ctx), rcode, xcode, message) == MI_SUCCESS) {
401+
RETVAL_TRUE();
402+
}
403+
}
404+
405+
RETVAL_FALSE();
351406
}
352407

353408
PHP_FUNCTION(smfi_addheader)
354409
{
355-
// smfi_addheader();
410+
char *f, *v;
411+
int len;
412+
413+
if (zend_parse_parameters(2 TSRMLS_CC, "ss", &f, &len, &v, &len) == SUCCESS) {
414+
if (smfi_addheader(MG(ctx), f, v) == MI_SUCCESS) {
415+
RETVAL_TRUE();
416+
}
417+
}
418+
419+
RETVAL_FALSE();
356420
}
357421

358422
PHP_FUNCTION(smfi_chgheader)
359423
{
360-
// smfi_chgheader();
424+
char *f, *v;
425+
long idx;
426+
int len;
427+
428+
if (zend_parse_parameters(3 TSRMLS_CC, "sls", &f, &len, &idx, &v, &len) == SUCCESS) {
429+
if (smfi_chgheader(MG(ctx), f, idx, v) == MI_SUCCESS) {
430+
RETVAL_TRUE();
431+
}
432+
}
433+
434+
RETVAL_FALSE();
361435
}
362436

363437
PHP_FUNCTION(smfi_addrcpt)
364438
{
365-
// smfi_addrcpt();
439+
char *rcpt;
440+
int len;
441+
442+
if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
443+
if (smfi_addrcpt(MG(ctx), rcpt) == MI_SUCCESS) {
444+
RETVAL_TRUE();
445+
}
446+
}
447+
448+
RETVAL_FALSE();
366449
}
367450

368451
PHP_FUNCTION(smfi_delrcpt)
369452
{
370-
// smfi_delrcpt();
453+
char *rcpt;
454+
int len;
455+
456+
if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
457+
if (smfi_delrcpt(MG(ctx), rcpt) == MI_SUCCESS) {
458+
RETVAL_TRUE();
459+
}
460+
}
461+
462+
RETVAL_FALSE();
371463
}
372464

373465
PHP_FUNCTION(smfi_replacebody)
374466
{
375-
// smfi_replacebody();
467+
char *body;
468+
int len;
469+
470+
if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
471+
if (smfi_replacebody(MG(ctx), body, len) == MI_SUCCESS) {
472+
RETVAL_TRUE();
473+
}
474+
}
475+
476+
RETVAL_FALSE();
376477
}
377478

378479
PHP_MINIT_FUNCTION(milter)

0 commit comments

Comments
 (0)