forked from templateria/php-spf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spf.c
674 lines (548 loc) · 21.1 KB
/
spf.c
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2011 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Pedro Padron <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend_objects.h"
#include "zend_exceptions.h"
#include "php_spf.h"
#include "netinet/in.h"
#include "spf2/spf.h"
#include "spf2/spf_dns_zone.h"
#include "spf2/spf_lib_version.h"
#include "netdb.h"
zend_class_entry *spf_ce_Spf;
zend_class_entry *spf_ce_SpfResponse;
zend_class_entry *spf_ce_SpfException;
static zend_object_handlers spf_object_handlers;
/* {{{ ZEND_BEGIN_ARG_INFO */
ZEND_BEGIN_ARG_INFO(arginfo_Spf___construct, 0)
ZEND_ARG_INFO(0, serverType)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(arginfo_Spf_query, 0, 0, 0)
ZEND_ARG_INFO(0, ip_address)
ZEND_ARG_INFO(0, helo)
ZEND_ARG_INFO(0, sender)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_getResult, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_getHeaderComment, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_getReceivedSpf, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_getReceivedSpfValue, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_getExplanation, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_getSmtpComment, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_hasErrors, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_hasWarnings, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_getErrors, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(arginfo_SpfResponse_getWarnings, 0)
ZEND_END_ARG_INFO();
/* }}} */
#define SPF_REGISTER_CLASS_CONSTANT_LONG(class, name, value) \
zend_declare_class_constant_long(spf_ce_ ## class, name, sizeof(name) - 1, (long) value TSRMLS_CC);
/* True global resources - no need for thread safety here */
static int le_spf;
/* {{{ spf_methods[]
*/
const zend_function_entry spf_methods[] = {
PHP_ME(Spf, __construct, arginfo_Spf___construct, ZEND_ACC_PUBLIC)
PHP_ME(Spf, query, arginfo_Spf_query, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
/* }}} */
const zend_function_entry spf_response_methods[] = {
PHP_ME(SpfResponse, getResult, arginfo_SpfResponse_getResult, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, getHeaderComment, arginfo_SpfResponse_getResult, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, getReceivedSpf, arginfo_SpfResponse_getReceivedSpf, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, getReceivedSpfValue, arginfo_SpfResponse_getReceivedSpfValue, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, getExplanation, arginfo_SpfResponse_getExplanation, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, getSmtpComment, arginfo_SpfResponse_getSmtpComment, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, hasErrors, arginfo_SpfResponse_hasErrors, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, getErrors, arginfo_SpfResponse_hasErrors, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, hasWarnings, arginfo_SpfResponse_hasWarnings, ZEND_ACC_PUBLIC)
PHP_ME(SpfResponse, getWarnings, arginfo_SpfResponse_hasWarnings, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
/* {{{ spf_module_entry
*/
zend_module_entry spf_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"spf",
NULL,
PHP_MINIT(spf),
PHP_MSHUTDOWN(spf),
PHP_RINIT(spf),
PHP_RSHUTDOWN(spf),
PHP_MINFO(spf),
#if ZEND_MODULE_API_NO >= 20010901
"0.1",
#endif
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_SPF
ZEND_GET_MODULE(spf)
#endif
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(spf)
{
memcpy(&spf_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
zend_class_entry ce, ce_response, ce_exception;
INIT_CLASS_ENTRY(ce, "Spf", spf_methods);
ce.create_object = create_spf;
spf_ce_Spf = zend_register_internal_class(&ce TSRMLS_CC);
INIT_CLASS_ENTRY(ce_response, "SpfResponse", spf_response_methods);
ce_response.create_object = create_spf_response;
spf_ce_SpfResponse = zend_register_internal_class(&ce_response TSRMLS_CC);
SPF_REGISTER_CLASS_CONSTANT_LONG(Spf, "TYPE_DNS_RESOLV", SPF_DNS_RESOLV);
SPF_REGISTER_CLASS_CONSTANT_LONG(Spf, "TYPE_DNS_CACHE", SPF_DNS_CACHE);
SPF_REGISTER_CLASS_CONSTANT_LONG(Spf, "TYPE_DNS_ZONE", SPF_DNS_ZONE);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "RESULT_INVALID", SPF_RESULT_INVALID);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "RESULT_NEUTRAL", SPF_RESULT_NEUTRAL);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "RESULT_PASS", SPF_RESULT_PASS);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "RESULT_FAIL", SPF_RESULT_FAIL);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "RESULT_SOFTFAIL", SPF_RESULT_SOFTFAIL);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "RESULT_NONE", SPF_RESULT_NONE);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "RESULT_TEMPERROR", SPF_RESULT_TEMPERROR);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "RESULT_PERMERROR", SPF_RESULT_PERMERROR);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_NO_MEMORY", SPF_E_NO_MEMORY);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_NOT_SPF", SPF_E_NOT_SPF);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_SYNTAX", SPF_E_SYNTAX);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_MOD_W_PREF", SPF_E_MOD_W_PREF);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_CHAR", SPF_E_INVALID_CHAR);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_UNKNOWN_MECH", SPF_E_UNKNOWN_MECH);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_OPT", SPF_E_INVALID_OPT);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_CIDR", SPF_E_INVALID_CIDR);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_MISSING_OPT", SPF_E_MISSING_OPT);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INTERNAL_ERROR", SPF_E_INTERNAL_ERROR);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_ESC", SPF_E_INVALID_ESC);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_VAR", SPF_E_INVALID_VAR);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_BIG_SUBDOM", SPF_E_BIG_SUBDOM);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_DELIM", SPF_E_INVALID_DELIM);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_BIG_STRING", SPF_E_BIG_STRING);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_BIG_MECH", SPF_E_BIG_MECH);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_BIG_MOD", SPF_E_BIG_MOD);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_BIG_DNS", SPF_E_BIG_DNS);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_IP4", SPF_E_INVALID_IP4);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_IP6", SPF_E_INVALID_IP6);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INVALID_PREFIX", SPF_E_INVALID_PREFIX);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_RESULT_UNKNOWN", SPF_E_RESULT_UNKNOWN);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_UNINIT_VAR", SPF_E_UNINIT_VAR);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_MOD_NOT_FOUND", SPF_E_MOD_NOT_FOUND);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_NOT_CONFIG", SPF_E_NOT_CONFIG);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_DNS_ERROR", SPF_E_DNS_ERROR);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_BAD_HOST_IP", SPF_E_BAD_HOST_IP);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_BAD_HOST_TLD", SPF_E_BAD_HOST_TLD);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_MECH_AFTER_ALL", SPF_E_MECH_AFTER_ALL);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_INCLUDE_RETURNED_NONE", SPF_E_INCLUDE_RETURNED_NONE);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_RECURSIVE", SPF_E_RECURSIVE);
SPF_REGISTER_CLASS_CONSTANT_LONG(SpfResponse, "ERROR_MULTIPLE_RECORDS", SPF_E_MULTIPLE_RECORDS);
INIT_CLASS_ENTRY(ce_exception, "SpfException", NULL);
spf_ce_SpfException = zend_register_internal_class_ex(&ce_exception, (zend_class_entry*) zend_exception_get_default(TSRMLS_C) TSRMLS_CC);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(spf)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(spf)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION(spf)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(spf)
{
char version[5];
sprintf(version, "%d.%d.%d", SPF_LIB_VERSION_MAJOR, SPF_LIB_VERSION_MINOR, SPF_LIB_VERSION_PATCH);
php_info_print_table_start();
php_info_print_table_header(2, "spf support", "enabled");
php_info_print_table_row(2, "libspf2 version", version);
php_info_print_table_end();
}
/* }}} */
/* {{{ SPF_SERVER_FROM_OBJECT */
#define SPF_SERVER_FROM_OBJECT(spf_server, object) \
{ \
/* php_spf_object *obj = (php_spf_object*) zend_object_store_get_object(object TSRMLS_CC); */ \
php_spf_object *obj = (php_spf_object*) Z_OBJ_P(object); \
spf_server = obj->spf_server; \
if (!spf_server) { \
zend_throw_exception(spf_ce_SpfException, "Invalid or uninitialized SPF object", 0 TSRMLS_CC); \
RETURN_FALSE; \
} \
}
/* }}} */
/* {{{ SPF_RESPONSE_FROM_OBJECT */
#define SPF_RESPONSE_FROM_OBJECT(intern, object) \
{ \
/* php_spf_response_object *obj = (php_spf_response_object*) zend_object_store_get_object(object TSRMLS_CC); */ \
php_spf_response_object *obj = (php_spf_response_object*) Z_OBJ_P(object); \
intern = obj->spf_response; \
if (!intern) { \
zend_throw_exception(spf_ce_SpfException, "Invalid or uninitialized SPF response", 0 TSRMLS_CC); \
RETURN_FALSE; \
} \
}
/* }}} */
/* {{{ create SpfResponse */
zend_object *create_spf_response(zend_class_entry *class_type TSRMLS_DC)
{
zval *tmp;
// Allocate sizeof(custom) + sizeof(properties table requirements)
php_spf_response_object *intern = ecalloc(1,
sizeof(php_spf_response_object) +
zend_object_properties_size(class_type));
// Allocating:
// struct custom_object {
// void *custom_data;
// zend_object std;
// }
// zval[ce->default_properties_count-1]
memset(intern, 0, sizeof(php_spf_response_object));
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
#if PHP_VERSION_ID < 50399
zend_hash_copy(intern->std.properties,
&class_type->default_properties,
(copy_ctor_func_t) zval_add_ref,
(void *) &tmp,
sizeof(zval*));
#else
object_properties_init((zend_object*) &(intern->std), class_type);
#endif
spf_object_handlers.offset = XtOffsetOf(php_spf_response_object, std);
spf_object_handlers.free_obj = (void (*)(struct _zend_object *))free_spf_response;
intern->std.handlers = &spf_object_handlers;
//intern->std.handle = zend_objects_store_put((zend_object *)intern, zend_objects_destroy_object, free_spf_response TSRMLS_CC);
//intern->std.handlers = zend_get_std_object_handlers();
return &intern->std;
}
/* }}} */
/* {{{ free_spf_response */
void free_spf_response(void *object TSRMLS_DC)
{
php_spf_response_object *intern = (php_spf_response_object*) object;
if (intern->spf_response) {
SPF_response_free(intern->spf_response);
}
efree(object);
}
/* }}} */
/* {{{ create_spf */
zend_object* create_spf(zend_class_entry *class_type TSRMLS_DC)
{
zval *tmp;
// Allocate sizeof(custom) + sizeof(properties table requirements)
php_spf_object *intern = ecalloc(1,
sizeof(php_spf_object) +
zend_object_properties_size(class_type));
// Allocating:
// struct custom_object {
// void *custom_data;
// zend_object std;
// }
// zval[ce->default_properties_count-1]
memset(intern, 0, sizeof(php_spf_object));
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
#if PHP_VERSION_ID < 50399
zend_hash_copy(intern->std.properties,
&class_type->default_properties,
(copy_ctor_func_t) zval_add_ref,
(void *) &tmp,
sizeof(zval*));
#else
object_properties_init((zend_object*) &(intern->std), class_type);
#endif
spf_object_handlers.offset = XtOffsetOf(php_spf_response_object, std);
spf_object_handlers.free_obj = (void (*)(struct _zend_object *))free_spf_response;
intern->std.handlers = &spf_object_handlers;
//intern->std.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, free_spf, NULL TSRMLS_CC);
//intern->std.handlers = zend_get_std_object_handlers();
return &intern->std;
}
/* }}} */
/* {{{ free_spf */
void free_spf(void *object TSRMLS_DC)
{
php_spf_object *spf_object = (php_spf_object*) object;
if (spf_object->spf_server) {
SPF_server_free(spf_object->spf_server);
}
efree(object);
}
/* }}} */
/* {{{ proto void Spf::__construct([int $type[, string $domain[, string $spf]]]) */
PHP_METHOD(Spf, __construct)
{
int server_type = SPF_DNS_CACHE;
int domain_len, spf_len;
char *domain, *spf;
php_spf_object *obj;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lss", &server_type, &domain, &domain_len, &spf, &spf_len) == FAILURE) {
RETURN_FALSE;
}
//obj = (php_spf_object*) zend_object_store_get_object(getThis() TSRMLS_CC);
obj = (php_spf_object*) Z_OBJ_P(getThis());
obj->spf_server = SPF_server_new(server_type, 0);
if (server_type == SPF_DNS_ZONE) {
if (SPF_dns_zone_add_str(obj->spf_server->resolver, domain, ns_t_txt, NETDB_SUCCESS, spf)) {
zend_throw_exception(spf_ce_SpfException, "Invalid SPF record", 0 TSRMLS_CC);
}
}
if (!obj->spf_server) zend_throw_exception(spf_ce_SpfException, "could not initialize spf resource", 0 TSRMLS_CC);
}
/* }}} */
/* {{{ proto SpfResponse Spf::query(string $ip, string $helo, string $sender[, string $recipient]) */
PHP_METHOD(Spf, query)
{
int ip_len, helo_len, sender_len, recipient_len;
char *ip, *helo, *sender, *recipient;
SPF_server_t *spf_server = NULL;
SPF_request_t *spf_request = NULL;
SPF_response_t *spf_response = NULL;
php_spf_response_object *response;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|s", &ip, &ip_len,
&helo, &helo_len, &sender, &sender_len, &recipient, &recipient_len)) {
RETURN_FALSE;
}
SPF_SERVER_FROM_OBJECT(spf_server, getThis());
spf_request = SPF_request_new(spf_server);
if (SPF_request_set_ipv4_str(spf_request, ip)) {
zend_throw_exception(spf_ce_SpfException, "invalid ip address", 0 TSRMLS_CC);
}
if (SPF_request_set_helo_dom(spf_request, helo)) {
zend_throw_exception(spf_ce_SpfException, "invalid HELO domain", 0 TSRMLS_CC);
}
if (SPF_request_set_env_from(spf_request, sender)) {
zend_throw_exception(spf_ce_SpfException, "invalid envelope from", 0 TSRMLS_CC);
}
SPF_request_query_mailfrom(spf_request, &spf_response);
object_init_ex(return_value, spf_ce_SpfResponse);
//response = (php_spf_response_object*) zend_object_store_get_object(return_value TSRMLS_CC);
response = (php_spf_response_object*) Z_OBJ_P(return_value);
response->spf_response = spf_response;
}
/* }}} */
/* {{{ proto string SpfResponse::getResult() */
PHP_METHOD(SpfResponse, getResult)
{
SPF_result_t result;
SPF_response_t *response;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
SPF_RESPONSE_FROM_OBJECT(response, getThis());
result = SPF_response_result(response);
//RETURN_STRING(SPF_strresult(result), 1);
RETURN_STRING(SPF_strresult(result));
}
/* }}} */
/* {{{ proto string SpfResponse::getHeaderComment();
Returns a string containing additional comments to be added to Received-SPF header. */
PHP_METHOD(SpfResponse, getHeaderComment)
{
const char *header_comment;
SPF_response_t *response;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
SPF_RESPONSE_FROM_OBJECT(response, getThis());
header_comment = SPF_response_get_header_comment(response);
if (header_comment == NULL) {
RETURN_NULL();
}
//RETURN_STRING(header_comment, 1);
RETURN_STRING(header_comment);
}
/* }}} */
/* {{{ proto string SpfResponse::getReceivedSpf();
Returns the complete Received-SPF header, including the field name. */
PHP_METHOD(SpfResponse, getReceivedSpf)
{
SPF_response_t *response;
const char *received_spf;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
SPF_RESPONSE_FROM_OBJECT(response, getThis());
received_spf = SPF_response_get_received_spf(response);
if (received_spf == NULL) {
RETURN_NULL();
}
//RETURN_STRING(received_spf, 1);
RETURN_STRING(received_spf);
}
/* }}} */
/* {{{ proto string SpfResponse::getReceivedSpf();
Returns the value of the Received-SPF header. */
PHP_METHOD(SpfResponse, getReceivedSpfValue)
{
SPF_response_t *response;
const char *received_spf_value;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
SPF_RESPONSE_FROM_OBJECT(response, getThis());
received_spf_value = SPF_response_get_received_spf_value(response);
if (received_spf_value == NULL) {
RETURN_NULL();
}
//RETURN_STRING(received_spf_value, 1);
RETURN_STRING(received_spf_value);
}
/* {{{ proto string SpfResponse::getExplanation();
Returns a string containing an explanation of the result. */
PHP_METHOD(SpfResponse, getExplanation)
{
SPF_response_t *response;
const char *explanation;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
SPF_RESPONSE_FROM_OBJECT(response, getThis());
explanation = SPF_response_get_explanation(response);
if (explanation == NULL) {
RETURN_NULL();
}
//RETURN_STRING(explanation, 1);
RETURN_STRING(explanation);
}
/* {{{ proto string SpfResponse::getSmtpComment();
Returns a string containing containing a link to OpenSPF's checker and the reason for the result. */
PHP_METHOD(SpfResponse, getSmtpComment)
{
SPF_response_t *response;
const char *smtp_comment;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
SPF_RESPONSE_FROM_OBJECT(response, getThis());
smtp_comment = SPF_response_get_smtp_comment(response);
if (smtp_comment == NULL) {
RETURN_NULL();
}
//RETURN_STRING(smtp_comment, 1);
RETURN_STRING(smtp_comment);
}
/* {{{ proto boolean SpfResponse::hasErrors();
Returns whether the SPF query has generated errors. */
PHP_METHOD(SpfResponse, hasErrors)
{
SPF_response_t *response;
int errors;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
SPF_RESPONSE_FROM_OBJECT(response, getThis());
errors = SPF_response_errors(response);
if (errors) {
RETURN_TRUE;
}
RETURN_FALSE;
}
/* {{{ proto boolean SpfResponse::hasWarnings();
Returns whether the SPF query has generated warnings. */
PHP_METHOD(SpfResponse, hasWarnings)
{
SPF_response_t *response;
int warnings;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
SPF_RESPONSE_FROM_OBJECT(response, getThis());
warnings = SPF_response_warnings(response);
if (warnings) {
RETURN_TRUE;
}
RETURN_FALSE;
}
/* {{{ proto boolean SpfResponse::getErrors();
Returns an array of error messages indexed by error code. */
PHP_METHOD(SpfResponse, getErrors)
{
int i;
SPF_response_t *response;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
array_init(return_value);
SPF_RESPONSE_FROM_OBJECT(response, getThis());
for (i = 0; i < SPF_response_messages(response); i++) {
SPF_error_t *err = SPF_response_message(response, i);
if (!SPF_error_errorp(err)) {
continue;
}
//add_index_string(return_value, SPF_error_code(err), SPF_error_message(err), 1);
add_index_string(return_value, SPF_error_code(err), SPF_error_message(err));
}
}
/* {{{ proto boolean SpfResponse::getWarnings();
Returns an array of warnings indexed by error code. */
PHP_METHOD(SpfResponse, getWarnings)
{
int i;
SPF_response_t *response;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}
array_init(return_value);
SPF_RESPONSE_FROM_OBJECT(response, getThis());
for (i = 0; i < SPF_response_messages(response); i++) {
SPF_error_t *err = SPF_response_message(response, i);
if (SPF_error_errorp(err)) {
continue;
}
//add_index_string(return_value, SPF_error_code(err), SPF_error_message(err), 1);
add_index_string(return_value, SPF_error_code(err), SPF_error_message(err));
}
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/