Skip to content

Commit b7b5ca5

Browse files
author
Harald Radi
committed
fix build
1 parent aeb6a6c commit b7b5ca5

File tree

1 file changed

+59
-66
lines changed

1 file changed

+59
-66
lines changed

sapi/milter/php_milter.c

Lines changed: 59 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include "php_variables.h"
2525
#include "zend_modules.h"
2626

27+
#ifndef ZTS
28+
#error SRM sapi module is only useable in thread-safe mode
29+
#endif
30+
2731
#include "SAPI.h"
2832

2933
#include <stdio.h>
@@ -60,22 +64,23 @@
6064
#include "libmilter/mfapi.h"
6165

6266
#define OPTSTRING "ac:d:Def:hnp:vVz:?"
63-
#define MG(v) TSRMG(milter_globals_id, milter_globals *, v)
67+
#define MG(v) TSRMG(milter_globals_id, zend_milter_globals *, v)
6468

6569
extern char *ap_php_optarg;
6670
extern int ap_php_optind;
6771

6872
/*********************
6973
* globals
7074
*/
71-
static int milter_globals_id;
7275
static int flag_debug=0;
7376
static zend_file_handle file_handle;
7477

7578
/* per thread */
76-
typedef struct _milter_globals {
79+
ZEND_BEGIN_MODULE_GLOBALS(milter)
7780
SMFICTX *ctx;
78-
} milter_globals;
81+
ZEND_END_MODULE_GLOBALS(milter)
82+
83+
ZEND_DECLARE_MODULE_GLOBALS(milter)
7984

8085
/*********************
8186
* Milter callbacks
@@ -84,7 +89,7 @@ typedef struct _milter_globals {
8489
/* connection info filter */
8590
static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
8691
{
87-
zval *function_name, *retval, *host, **params[1];
92+
zval *function_name, *retval, *param[1];
8893
TSRMLS_FETCH();
8994

9095
/* set the milter context for possible use in API functions */
@@ -105,14 +110,12 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
105110

106111
/* call userland */
107112
ZVAL_INIT(function_name);
108-
ZVAL_INIT(host);
113+
ZVAL_INIT(param[0]);
109114

110115
ZVAL_STRING(function_name, "milter_connect", 1);
111-
ZVAL_STRING(host, hostname, 1);
112-
113-
params[0] = &host;
116+
ZVAL_STRING(param[0], hostname, 1);
114117

115-
call_user_function(CG(function_table), NULL, function_name, retval, 1, params TSRMLS_CC);
118+
call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
116119

117120
if (Z_TYPE_P(retval) == IS_LONG) {
118121
return Z_LONG_P(retval);
@@ -124,22 +127,20 @@ static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
124127
/* SMTP HELO command filter */
125128
static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
126129
{
127-
zval *function_name, *retval, *host, **params[1];
130+
zval *function_name, *retval, *param[1];
128131
TSRMLS_FETCH();
129132

130133
/* set the milter context for possible use in API functions */
131134
MG(ctx) = ctx;
132135

133136
/* call userland */
134137
ZVAL_INIT(function_name);
135-
ZVAL_INIT(host);
138+
ZVAL_INIT(param[0]);
136139

137140
ZVAL_STRING(function_name, "milter_helo", 1);
138-
ZVAL_STRING(host, helohost, 1);
141+
ZVAL_STRING(param[0], helohost, 1);
139142

140-
params[0] = &host;
141-
142-
call_user_function(CG(function_table), NULL, function_name, retval, 1, params TSRMLS_CC);
143+
call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
143144

144145
if (Z_TYPE_P(retval) == IS_LONG) {
145146
return Z_LONG_P(retval);
@@ -151,27 +152,25 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
151152
/* envelope sender filter */
152153
static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
153154
{
154-
zval *function_name, *retval, *v, **params[1];
155+
zval *function_name, *retval, *param[1];
155156
TSRMLS_FETCH();
156157

157158
/* set the milter context for possible use in API functions */
158159
MG(ctx) = ctx;
159160

160161
/* call userland */
161162
ZVAL_INIT(function_name);
162-
ZVAL_INIT(v);
163+
ZVAL_INIT(param[0]);
163164

164165
ZVAL_STRING(function_name, "milter_envelope_from", 1);
165-
array_init(v);
166+
array_init(param[0]);
166167

167168
while (*argv) {
168-
add_next_index_string(v, *argv, 1);
169+
add_next_index_string(param[0], *argv, 1);
169170
argv++;
170171
}
171172

172-
params[0] = v;
173-
174-
call_user_function(CG(function_table), NULL, function_name, retval, 1, params TSRMLS_CC);
173+
call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
175174

176175
if (Z_TYPE_P(retval) == IS_LONG) {
177176
return Z_LONG_P(retval);
@@ -183,27 +182,25 @@ static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
183182
/* envelope recipient filter */
184183
static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv)
185184
{
186-
zval *function_name, *retval, *v, **params[1];
185+
zval *function_name, *retval, *param[1];
187186
TSRMLS_FETCH();
188187

189188
/* set the milter context for possible use in API functions */
190189
MG(ctx) = ctx;
191190

192191
/* call userland */
193192
ZVAL_INIT(function_name);
194-
ZVAL_INIT(v);
193+
ZVAL_INIT(param[0]);
195194

196195
ZVAL_STRING(function_name, "milter_envelope_recipient", 1);
197-
array_init(v);
196+
array_init(param[0]);
198197

199198
while (*argv) {
200-
add_next_index_string(v, *argv, 1);
199+
add_next_index_string(param[0], *argv, 1);
201200
argv++;
202201
}
203202

204-
params[0] = v;
205-
206-
call_user_function(CG(function_table), NULL, function_name, retval, 1, params TSRMLS_CC);
203+
call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
207204

208205
if (Z_TYPE_P(retval) == IS_LONG) {
209206
return Z_LONG_P(retval);
@@ -215,25 +212,22 @@ static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv)
215212
/* header filter */
216213
static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
217214
{
218-
zval *function_name, *retval, *f, *v, **params[2];
215+
zval *function_name, *retval, *param[2];
219216
TSRMLS_FETCH();
220217

221218
/* set the milter context for possible use in API functions */
222219
MG(ctx) = ctx;
223220

224221
/* call userland */
225222
ZVAL_INIT(function_name);
226-
ZVAL_INIT(f);
227-
ZVAL_INIT(v);
223+
ZVAL_INIT(param[0]);
224+
ZVAL_INIT(param[1]);
228225

229226
ZVAL_STRING(function_name, "milter_header", 1);
230-
ZVAL_STRING(f, headerf, 1);
231-
ZVAL_STRING(v, headerv, 1);
227+
ZVAL_STRING(param[0], headerf, 1);
228+
ZVAL_STRING(param[1], headerv, 1);
232229

233-
params[0] = f;
234-
params[1] = v;
235-
236-
call_user_function(CG(function_table), NULL, function_name, retval, 2, params TSRMLS_CC);
230+
call_user_function(CG(function_table), NULL, function_name, retval, 2, param TSRMLS_CC);
237231

238232
if (Z_TYPE_P(retval) == IS_LONG) {
239233
return Z_LONG_P(retval);
@@ -266,22 +260,20 @@ static sfsistat mlfi_eoh(SMFICTX *ctx)
266260
/* body block */
267261
static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
268262
{
269-
zval *function_name, *retval, *p, **params[1];;
263+
zval *function_name, *retval, *param[1];;
270264
TSRMLS_FETCH();
271265

272266
/* set the milter context for possible use in API functions */
273267
MG(ctx) = ctx;
274268

275269
/* call userland */
276270
ZVAL_INIT(function_name);
277-
ZVAL_INIT(p);
271+
ZVAL_INIT(param[0]);
278272

279273
ZVAL_STRING(function_name, "milter_body", 1);
280-
ZVAL_STRINGL(p, bodyp, len, 1);
274+
ZVAL_STRINGL(param[0], bodyp, len, 1);
281275

282-
params[0] = p;
283-
284-
call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
276+
call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
285277

286278
if (Z_TYPE_P(retval) == IS_LONG) {
287279
return Z_LONG_P(retval);
@@ -384,7 +376,7 @@ PHP_FUNCTION(smfi_getsymval)
384376

385377
if (zend_parse_parameters(1 TSRMLS_CC, "s", &symname, &len) == SUCCESS) {
386378
if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) {
387-
RETVAL_STRING(ret);
379+
RETVAL_STRING(ret, 1);
388380
}
389381
}
390382

@@ -398,11 +390,11 @@ PHP_FUNCTION(smfi_setreply)
398390

399391
if (zend_parse_parameters(3 TSRMLS_CC, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) {
400392
if (smfi_setreply(MG(ctx), rcode, xcode, message) == MI_SUCCESS) {
401-
RETVAL_TRUE();
393+
RETVAL_TRUE;
402394
}
403395
}
404396

405-
RETVAL_FALSE();
397+
RETVAL_FALSE;
406398
}
407399

408400
PHP_FUNCTION(smfi_addheader)
@@ -412,11 +404,11 @@ PHP_FUNCTION(smfi_addheader)
412404

413405
if (zend_parse_parameters(2 TSRMLS_CC, "ss", &f, &len, &v, &len) == SUCCESS) {
414406
if (smfi_addheader(MG(ctx), f, v) == MI_SUCCESS) {
415-
RETVAL_TRUE();
407+
RETVAL_TRUE;
416408
}
417409
}
418410

419-
RETVAL_FALSE();
411+
RETVAL_FALSE;
420412
}
421413

422414
PHP_FUNCTION(smfi_chgheader)
@@ -427,11 +419,11 @@ PHP_FUNCTION(smfi_chgheader)
427419

428420
if (zend_parse_parameters(3 TSRMLS_CC, "sls", &f, &len, &idx, &v, &len) == SUCCESS) {
429421
if (smfi_chgheader(MG(ctx), f, idx, v) == MI_SUCCESS) {
430-
RETVAL_TRUE();
422+
RETVAL_TRUE;
431423
}
432424
}
433425

434-
RETVAL_FALSE();
426+
RETVAL_FALSE;
435427
}
436428

437429
PHP_FUNCTION(smfi_addrcpt)
@@ -441,11 +433,11 @@ PHP_FUNCTION(smfi_addrcpt)
441433

442434
if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
443435
if (smfi_addrcpt(MG(ctx), rcpt) == MI_SUCCESS) {
444-
RETVAL_TRUE();
436+
RETVAL_TRUE;
445437
}
446438
}
447439

448-
RETVAL_FALSE();
440+
RETVAL_FALSE;
449441
}
450442

451443
PHP_FUNCTION(smfi_delrcpt)
@@ -455,25 +447,25 @@ PHP_FUNCTION(smfi_delrcpt)
455447

456448
if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
457449
if (smfi_delrcpt(MG(ctx), rcpt) == MI_SUCCESS) {
458-
RETVAL_TRUE();
450+
RETVAL_TRUE;
459451
}
460452
}
461453

462-
RETVAL_FALSE();
454+
RETVAL_FALSE;
463455
}
464456

465457
PHP_FUNCTION(smfi_replacebody)
466458
{
467459
char *body;
468460
int len;
469461

470-
if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
462+
if (zend_parse_parameters(1 TSRMLS_CC, "s", &body, &len) == SUCCESS) {
471463
if (smfi_replacebody(MG(ctx), body, len) == MI_SUCCESS) {
472-
RETVAL_TRUE();
464+
RETVAL_TRUE;
473465
}
474466
}
475467

476-
RETVAL_FALSE();
468+
RETVAL_FALSE;
477469
}
478470

479471
PHP_MINIT_FUNCTION(milter)
@@ -483,11 +475,17 @@ PHP_MINIT_FUNCTION(milter)
483475
REGISTER_LONG_CONSTANT("SMFIS_DISCARD", SMFIS_DISCARD, CONST_CS | CONST_PERSISTENT);
484476
REGISTER_LONG_CONSTANT("SMFIS_ACCEPT", SMFIS_ACCEPT, CONST_CS | CONST_PERSISTENT);
485477
REGISTER_LONG_CONSTANT("SMFIS_TEMPFAIL", SMFIS_TEMPFAIL, CONST_CS | CONST_PERSISTENT);
478+
479+
ZEND_INIT_MODULE_GLOBALS(milter, NULL, NULL);
486480
}
487481

488482
PHP_MINFO_FUNCTION(milter)
489483
{
490-
DISPLAY_INI_ENTRIES();
484+
php_info_print_table_start();
485+
php_info_print_table_header(2, "Milter support", "enabled");
486+
php_info_print_table_end();
487+
488+
// DISPLAY_INI_ENTRIES();
491489
}
492490

493491

@@ -673,7 +671,7 @@ int main(int argc, char *argv[])
673671
char *param_error=NULL;
674672
/* end of temporary locals */
675673

676-
void ***tsrm_ls;
674+
TSRMLS_FETCH();
677675

678676

679677
#ifdef HAVE_SIGNAL_H
@@ -708,8 +706,6 @@ int main(int argc, char *argv[])
708706

709707
sapi_module.startup(&milter_sapi_module);
710708

711-
tsrm_ls = ts_resource(0);
712-
713709
zend_first_try {
714710
while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
715711
switch (c) {
@@ -865,9 +861,6 @@ int main(int argc, char *argv[])
865861
argv[ap_php_optind-1] = file_handle.filename;
866862
SG(request_info).argv=argv+ap_php_optind-1;
867863

868-
/* TSRM is used to allocate a per-thread structure */
869-
ts_allocate_id (&milter_globals_id, sizeof(milter_globals), NULL, NULL);
870-
871864
if (dofork) {
872865
switch(fork()) {
873866
case -1: /* Uh-oh, we have a problem forking. */

0 commit comments

Comments
 (0)