Back to index

php5  5.3.10
Defines | Functions | Variables
php_milter.c File Reference
#include "php.h"
#include "php_globals.h"
#include "php_variables.h"
#include "zend_modules.h"
#include "SAPI.h"
#include <stdio.h>
#include "zend.h"
#include "zend_extensions.h"
#include "php_ini.h"
#include "php_main.h"
#include "fopen_wrappers.h"
#include "ext/standard/php_standard.h"
#include "zend_compile.h"
#include "zend_execute.h"
#include "zend_highlight.h"
#include "zend_indent.h"
#include "libmilter/mfapi.h"
#include "php_getopt.h"

Go to the source code of this file.

Defines

#define OPTSTRING   "ac:d:Def:hnp:vVz:?"
#define MG(v)   TSRMG(milter_globals_id, zend_milter_globals *, v)
#define IS_NONE   "%s(): This function must not be called outside of a milter callback function's scope"
#define NOT_EOM   "%s(): This function can only be used inside the milter_eom callback's scope"
#define NOT_INIT   "%s(): This function can only be used inside the milter_init callback's scope"
#define MLFI_NONE   0
#define MLFI_CONNECT   1
#define MLFI_HELO   2
#define MLFI_ENVFROM   3
#define MLFI_ENVRCPT   4
#define MLFI_HEADER   5
#define MLFI_EOH   6
#define MLFI_BODY   7
#define MLFI_EOM   8
#define MLFI_ABORT   9
#define MLFI_CLOSE   10
#define MLFI_INIT   11

Functions

static int mlfi_init ()
static sfsistat mlfi_connect (SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
static sfsistat mlfi_helo (SMFICTX *ctx, char *helohost)
static sfsistat mlfi_envfrom (SMFICTX *ctx, char **argv)
static sfsistat mlfi_envrcpt (SMFICTX *ctx, char **argv)
static sfsistat mlfi_header (SMFICTX *ctx, char *headerf, char *headerv)
static sfsistat mlfi_eoh (SMFICTX *ctx)
static sfsistat mlfi_body (SMFICTX *ctx, u_char *bodyp, size_t len)
static sfsistat mlfi_eom (SMFICTX *ctx)
static sfsistat mlfi_abort (SMFICTX *ctx)
static sfsistat mlfi_close (SMFICTX *ctx)
 PHP_FUNCTION (smfi_setflags)
 PHP_FUNCTION (smfi_settimeout)
 PHP_FUNCTION (smfi_getsymval)
 PHP_FUNCTION (smfi_setreply)
 PHP_FUNCTION (smfi_addheader)
 PHP_FUNCTION (smfi_chgheader)
 PHP_FUNCTION (smfi_addrcpt)
 PHP_FUNCTION (smfi_delrcpt)
 PHP_FUNCTION (smfi_replacebody)
 PHP_MINIT_FUNCTION (milter)
 PHP_MINFO_FUNCTION (milter)
static int sapi_milter_ub_write (const char *str, uint str_length TSRMLS_DC)
static void sapi_milter_flush (void *server_context)
static void sapi_milter_register_variables (zval *track_vars_array TSRMLS_DC)
static int sapi_milter_post_read (char *buf, uint count_bytes TSRMLS_DC)
static char * sapi_milter_read_cookies (TSRMLS_D)
static int sapi_milter_send_headers (sapi_headers_struct *sapi_headers TSRMLS_DC)
static int php_milter_startup (sapi_module_struct *sapi_module)
static void php_milter_usage (char *argv0)
static void define_command_line_ini_entry (char *arg)
int main (int argc, char *argv[])

Variables

char * ap_php_optarg
int ap_php_optind
static int flag_debug = 0
static char * filename = NULL
SMFICTX * ctx
int state
int initialized
static const zend_function_entry milter_functions []
static zend_module_entry php_milter_module
static sapi_module_struct milter_sapi_module

Define Documentation

#define IS_NONE   "%s(): This function must not be called outside of a milter callback function's scope"

Definition at line 72 of file php_milter.c.

#define MG (   v)    TSRMG(milter_globals_id, zend_milter_globals *, v)

Definition at line 70 of file php_milter.c.

#define MLFI_ABORT   9

Definition at line 85 of file php_milter.c.

#define MLFI_BODY   7

Definition at line 83 of file php_milter.c.

#define MLFI_CLOSE   10

Definition at line 86 of file php_milter.c.

#define MLFI_CONNECT   1

Definition at line 77 of file php_milter.c.

#define MLFI_ENVFROM   3

Definition at line 79 of file php_milter.c.

#define MLFI_ENVRCPT   4

Definition at line 80 of file php_milter.c.

#define MLFI_EOH   6

Definition at line 82 of file php_milter.c.

#define MLFI_EOM   8

Definition at line 84 of file php_milter.c.

#define MLFI_HEADER   5

Definition at line 81 of file php_milter.c.

#define MLFI_HELO   2

Definition at line 78 of file php_milter.c.

#define MLFI_INIT   11

Definition at line 87 of file php_milter.c.

#define MLFI_NONE   0

Definition at line 76 of file php_milter.c.

#define NOT_EOM   "%s(): This function can only be used inside the milter_eom callback's scope"

Definition at line 73 of file php_milter.c.

#define NOT_INIT   "%s(): This function can only be used inside the milter_init callback's scope"

Definition at line 74 of file php_milter.c.

#define OPTSTRING   "ac:d:Def:hnp:vVz:?"

Definition at line 69 of file php_milter.c.


Function Documentation

static void define_command_line_ini_entry ( char *  arg) [static]

Definition at line 971 of file php_milter.c.

{
       char *name, *value;

       name = arg;
       value = strchr(arg, '=');
       if (value) {
              *value = 0;
              value++;
       } else {
              value = "1";
       }
       zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 989 of file php_milter.c.

{
    char *sock = NULL;
       int dofork = 0;

       int exit_status = SUCCESS;
       int c;
/* temporary locals */
       int orig_optind=ap_php_optind;
       char *orig_optarg=ap_php_optarg;
       int interactive=0;
       char *param_error=NULL;
/* end of temporary locals */

       void ***tsrm_ls;

#ifdef HAVE_SIGNAL_H
#if defined(SIGPIPE) && defined(SIG_IGN)
       signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
                                                        that sockets created via fsockopen()
                                                        don't kill PHP if the remote site
                                                        closes it.  in apache|apxs mode apache
                                                        does that for us!  thies@thieso.net
                                                        20000419 */
#endif
#endif


       tsrm_startup(1, 1, 0, NULL);
       sapi_startup(&milter_sapi_module);
       
       while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
              switch (c) {
              case 'c':
                     milter_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
                     break;
              case 'n':
                     milter_sapi_module.php_ini_ignore = 1;
                     break;
              }
       }
       ap_php_optind = orig_optind;
       ap_php_optarg = orig_optarg;

       milter_sapi_module.executable_location = argv[0];

       tsrm_ls = ts_resource(0);

       sapi_module.startup(&milter_sapi_module);

       zend_first_try {
              while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
                     switch (c) {
                     case '?':
                            php_output_startup();
                            php_output_activate(TSRMLS_C);
                            SG(headers_sent) = 1;
                            php_milter_usage(argv[0]);
                            php_end_ob_buffers(1 TSRMLS_CC);
                            exit(1);
                            break;
                     }
              }
              ap_php_optind = orig_optind;
              ap_php_optarg = orig_optarg;

        /* Set some CLI defaults */
              SG(options) |= SAPI_OPTION_NO_CHDIR;
              zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
              zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);

              zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */

              while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
                     switch (c) {

                     case 'a':     /* interactive mode */
                            printf("Interactive mode enabled\n\n");
                            interactive=1;
                            break;

                     case 'C': /* don't chdir to the script directory */
                            /* This is default so NOP */
                            break;
                     case 'd': /* define ini entries on command line */
                            define_command_line_ini_entry(ap_php_optarg);
                            break;

                     case 'D': /* daemon */
                            dofork = 1;
                            break;

                     case 'e': /* enable extended info output */
                            CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
                            break;

                     case 'f': /* parse file */
                            filename = ap_php_optarg;
                            break;

                     case 'h': /* help & quit */
                     case '?':
                            php_output_startup();
                            php_output_activate(TSRMLS_C);
                            SG(headers_sent) = 1;
                            php_milter_usage(argv[0]);
                            php_end_ob_buffers(1 TSRMLS_CC);
                            exit(1);
                            break;

                     case 'p': /* socket */
                            sock = strdup(ap_php_optarg);
                            break;

                     case 'v': /* show php version & quit */
                            if (php_request_startup(TSRMLS_C)==FAILURE) {
                                   zend_ini_deactivate(TSRMLS_C);
                                   php_module_shutdown(TSRMLS_C);
                                   sapi_shutdown();
                                   tsrm_shutdown();

                                   exit(1);
                            }
                            SG(headers_sent) = 1;
                            SG(request_info).no_headers = 1;
                            php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2012 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
                            php_end_ob_buffers(1 TSRMLS_CC);
                            exit(1);
                            break;

                     case 'V': /* verbose */
                            flag_debug = atoi(ap_php_optarg);
                            break;

                     case 'z': /* load extension file */
                            zend_load_extension(ap_php_optarg);
                            break;

                     default:
                            break;
                     }
              }

              if (param_error) {
                     SG(headers_sent) = 1;
                     SG(request_info).no_headers = 1;
                     PUTS(param_error);
                     exit(1);
              }

              CG(interactive) = interactive;

              /* only set script_file if not set already and not in direct mode and not at end of parameter list */
              if (argc > ap_php_optind && !filename) {
                     filename=argv[ap_php_optind];
                     ap_php_optind++;
              }

              /* check if file exists, exit else */
              
              if (dofork) {
                     switch(fork()) {
                            case -1: /* Uh-oh, we have a problem forking. */
                                   fprintf(stderr, "Uh-oh, couldn't fork!\n");
                                   exit(errno);
                                   break;
                            case 0: /* Child */
                                   break;
                            default: /* Parent */
                                   exit(0);
                     }
              }
                     
              if (sock) {
                     struct stat junk;
                     if (stat(sock,&junk) == 0) unlink(sock);
              }

              openlog("php-milter", LOG_PID, LOG_MAIL);
              
              if ((exit_status = mlfi_init())) {
                     syslog(1, "mlfi_init failed.");
                     closelog();
                     goto err;
              }

              smfi_setconn(sock);
              if (smfi_register(smfilter) == MI_FAILURE) {
                     syslog(1, "smfi_register failed.");
                     fprintf(stderr, "smfi_register failed\n");
                     closelog();
                     goto err;
              } else {
                     exit_status = smfi_main();
              }                    

              closelog();

              if (milter_sapi_module.php_ini_path_override) {
                     free(milter_sapi_module.php_ini_path_override);
              }

       } zend_catch {
              exit_status = EG(exit_status);
       } zend_end_try();

err:
       php_module_shutdown(TSRMLS_C);
       sapi_shutdown();
       tsrm_shutdown();

       exit(exit_status);
}

Here is the call graph for this function:

static sfsistat mlfi_abort ( SMFICTX *  ctx) [static]

Definition at line 492 of file php_milter.c.

{
       zval function_name, retval;
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       ZVAL_STRING(&function_name, "milter_abort", 0);
       
       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_ABORT;
       
       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);

       MG(state) = MLFI_NONE;
       
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }

       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static sfsistat mlfi_body ( SMFICTX *  ctx,
u_char bodyp,
size_t  len 
) [static]

Definition at line 427 of file php_milter.c.

{
       zval function_name, retval, *param[1];
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       
       ALLOC_ZVAL(param[0]);
       INIT_PZVAL(param[0]);

       ZVAL_STRING(&function_name, "milter_body", 0);
       ZVAL_STRINGL(param[0], (char*)bodyp, len, 1); /*alex*/
       
       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_BODY;
       
       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

       MG(state) = MLFI_NONE;
       
       zval_ptr_dtor(param);       

       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }

       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static sfsistat mlfi_close ( SMFICTX *  ctx) [static]

Definition at line 521 of file php_milter.c.

{
       int ret = SMFIS_CONTINUE;
       zval function_name, retval;
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       ZVAL_STRING(&function_name, "milter_close", 0);
       
       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_CLOSE;
       
       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);

       MG(state) = MLFI_NONE;
       
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              ret = Z_LVAL(retval);
       }
       
       php_request_shutdown((void *) 0);

       return ret;
}

Here is the call graph for this function:

static sfsistat mlfi_connect ( SMFICTX *  ctx,
char *  hostname,
_SOCK_ADDR *  hostaddr 
) [static]

Definition at line 177 of file php_milter.c.

{
       zend_file_handle file_handle;
       zval function_name, retval, *param[1];
       int status;
       TSRMLS_FETCH();

       /* request startup */
       if (php_request_startup(TSRMLS_C)==FAILURE) {
              SG(headers_sent) = 1;
              SG(request_info).no_headers = 1;
              php_request_shutdown((void *) 0);

              return SMFIS_TEMPFAIL;
       }
       
       /* disable headers */
       SG(headers_sent) = 1;
       SG(request_info).no_headers = 1;
       
       if (filename == NULL) {
              php_printf("No input file specified");
              return SMFIS_TEMPFAIL;
       }
       
       if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) {
              php_printf("Could not open input file: %s\n", filename);
              return SMFIS_TEMPFAIL;
       }

       file_handle.type = ZEND_HANDLE_FP;
       file_handle.filename = filename;
       file_handle.free_filename = 0;
       file_handle.opened_path = NULL;

       php_execute_script(&file_handle TSRMLS_CC);
       
       /* call userland */
       INIT_ZVAL(function_name);

       ALLOC_ZVAL(param[0]);
       INIT_PZVAL(param[0]);

       ZVAL_STRING(&function_name, "milter_connect", 0);
       ZVAL_STRING(param[0], hostname, 1);

       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_CONNECT;

       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

       MG(state) = MLFI_NONE;
       zval_ptr_dtor(param);
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }
       
       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static sfsistat mlfi_envfrom ( SMFICTX *  ctx,
char **  argv 
) [static]

Definition at line 277 of file php_milter.c.

{
       zval function_name, retval, *param[1];
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       
       ALLOC_ZVAL(param[0]);
       INIT_PZVAL(param[0]);

       ZVAL_STRING(&function_name, "milter_envfrom", 0);
       array_init(param[0]);

       while (*argv) {
              add_next_index_string(param[0], *argv, 1);
              argv++;
       }

       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_ENVFROM;
       
       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

       MG(state) = MLFI_NONE;
       zval_ptr_dtor(param);
       
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }

       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static sfsistat mlfi_envrcpt ( SMFICTX *  ctx,
char **  argv 
) [static]

Definition at line 317 of file php_milter.c.

{
       zval function_name, retval, *param[1];
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       
       ALLOC_ZVAL(param[0]);
       INIT_PZVAL(param[0]);

       ZVAL_STRING(&function_name, "milter_envrcpt", 0);
       array_init(param[0]);

       while (*argv) {
              add_next_index_string(param[0], *argv, 1);
              argv++;
       }

       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_ENVRCPT;
       
       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

       MG(state) = MLFI_NONE;
       
       zval_ptr_dtor(param);
       
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }

       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static sfsistat mlfi_eoh ( SMFICTX *  ctx) [static]

Definition at line 398 of file php_milter.c.

{
       zval function_name, retval;
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       ZVAL_STRING(&function_name, "milter_eoh", 0);

       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_EOH;
       
       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);

       MG(state) = MLFI_NONE;
       
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }

       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static sfsistat mlfi_eom ( SMFICTX *  ctx) [static]

Definition at line 463 of file php_milter.c.

{
       zval function_name, retval;
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       ZVAL_STRING(&function_name, "milter_eom", 0);
       
       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_EOM;

       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);

       MG(state) = MLFI_NONE;
       
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }

       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static sfsistat mlfi_header ( SMFICTX *  ctx,
char *  headerf,
char *  headerv 
) [static]

Definition at line 358 of file php_milter.c.

{
       zval function_name, retval, *param[2];
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       
       ALLOC_ZVAL(param[0]);
       ALLOC_ZVAL(param[1]);
       INIT_PZVAL(param[0]);
       INIT_PZVAL(param[1]);
       
       ZVAL_STRING(&function_name, "milter_header", 0);
       ZVAL_STRING(param[0], headerf, 1);
       ZVAL_STRING(param[1], headerv, 1);

       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_HEADER;
       
       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param TSRMLS_CC);

       MG(state) = MLFI_NONE;
       
       zval_ptr_dtor(&param[0]);
       zval_ptr_dtor(&param[1]);   
       
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }
       
       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static sfsistat mlfi_helo ( SMFICTX *  ctx,
char *  helohost 
) [static]

Definition at line 242 of file php_milter.c.

{
       zval function_name, retval, *param[1];
       int status;
       TSRMLS_FETCH();

       /* call userland */
       INIT_ZVAL(function_name);
       
       ALLOC_ZVAL(param[0]);
       INIT_PZVAL(param[0]);

       ZVAL_STRING(&function_name, "milter_helo", 0);
       ZVAL_STRING(param[0], helohost, 1);

       /* set the milter context for possible use in API functions */
       MG(ctx) = ctx;
       MG(state) = MLFI_HELO;
       
       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

       MG(state) = MLFI_NONE;
       zval_ptr_dtor(param);
       
       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              return Z_LVAL(retval);
       }
       
       return SMFIS_CONTINUE;
}

Here is the call graph for this function:

static int mlfi_init ( ) [static]

Definition at line 110 of file php_milter.c.

{
       int ret = 0;
       zend_file_handle file_handle;
       zval function_name, retval;
       int status;
       TSRMLS_FETCH();

       /* request startup */
       if (php_request_startup(TSRMLS_C)==FAILURE) {
              SG(headers_sent) = 1;
              SG(request_info).no_headers = 1;
              php_request_shutdown((void *) 0);

              return -1;
       }
       
       /* disable headers */
       SG(headers_sent) = 1;
       SG(request_info).no_headers = 1;
        
       if (filename == NULL) {
              php_printf("No input file specified");
              return SMFIS_TEMPFAIL;
       }

       if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) {
              php_printf("Could not open input file: %s\n", filename);
              return SMFIS_TEMPFAIL;
       }

       file_handle.type = ZEND_HANDLE_FP;
       file_handle.filename = filename;
       file_handle.free_filename = 0;
       file_handle.opened_path = NULL;

       php_execute_script(&file_handle TSRMLS_CC);
       
       /* call userland */
       INIT_ZVAL(function_name);

       ZVAL_STRING(&function_name, "milter_init", 0);

       /* set the milter context for possible use in API functions */
       MG(state) = MLFI_INIT;

       status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);

       MG(state) = MLFI_NONE;
       MG(initialized) = 1;

       if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
              ret = Z_LVAL(retval);
       }
       
       php_request_shutdown((void *) 0);
       
       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_FUNCTION ( smfi_setflags  )

Definition at line 575 of file php_milter.c.

{
       long flags;
       
       /* valid only in the init callback */
       if (MG(state) != MLFI_INIT) {
              php_error(E_WARNING, NOT_INIT, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(1 TSRMLS_CC, "l", &flags) == SUCCESS) {
              flags = flags & (SMFIF_ADDHDRS|SMFIF_CHGHDRS|SMFIF_CHGBODY|SMFIF_ADDRCPT|SMFIF_DELRCPT);
              smfilter.xxfi_flags = flags;
       }      
}

Here is the call graph for this function:

PHP_FUNCTION ( smfi_settimeout  )

Definition at line 591 of file php_milter.c.

{
       long timeout;
       
       /* valid only in the init callback */
       if (MG(state) != MLFI_INIT) {
              php_error(E_WARNING, NOT_INIT, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(1 TSRMLS_CC, "l", &timeout) == SUCCESS) {
              smfi_settimeout(timeout);
       }      
}

Here is the call graph for this function:

PHP_FUNCTION ( smfi_getsymval  )

Definition at line 606 of file php_milter.c.

{
       char *symname, *ret;
       int len;

       /* valid in any callback */
       if (MG(state) == MLFI_NONE) {
              php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &symname, &len) == SUCCESS) {
              if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) {
                     RETURN_STRING(ret, 1);
              }
       }

       RETURN_NULL();
}

Here is the call graph for this function:

PHP_FUNCTION ( smfi_setreply  )

Definition at line 627 of file php_milter.c.

{
       char *rcode, *xcode, *message;
       int len;
       
       /* valid in any callback */
       if (MG(state) == MLFI_NONE) {
              php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(3 TSRMLS_CC, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) {
              if (smfi_setreply(MG(ctx), rcode, xcode, message) == MI_SUCCESS) {
                     RETURN_TRUE;
              }
       }
       
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( smfi_addheader  )

Definition at line 647 of file php_milter.c.

{
       char *f, *v;
       int len;
       
       /* valid only in milter_eom */
       if (MG(state) != MLFI_EOM) {
              php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(2 TSRMLS_CC, "ss", &f, &len, &v, &len) == SUCCESS) {
              if (smfi_addheader(MG(ctx), f, v) == MI_SUCCESS) {
                     RETURN_TRUE;
              }
       }
       
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( smfi_chgheader  )

Definition at line 667 of file php_milter.c.

{
       char *f, *v;
       long idx;
       int len;
       
       /* valid only in milter_eom */
       if (MG(state) != MLFI_EOM) {
              php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(3 TSRMLS_CC, "sls", &f, &len, &idx, &v, &len) == SUCCESS) {
              if (smfi_chgheader(MG(ctx), f, idx, v) == MI_SUCCESS) {
                     RETURN_TRUE;
              }
       }
       
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( smfi_addrcpt  )

Definition at line 688 of file php_milter.c.

{
       char *rcpt;
       int len;
       
       /* valid only in milter_eom */
       if (MG(state) != MLFI_EOM) {
              php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
              if (smfi_addrcpt(MG(ctx), rcpt) == MI_SUCCESS) {
                     RETURN_TRUE;
              }
       }
       
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( smfi_delrcpt  )

Definition at line 708 of file php_milter.c.

{
       char *rcpt;
       int len;
       
       /* valid only in milter_eom */
       if (MG(state) != MLFI_EOM) {
              php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &rcpt, &len) == SUCCESS) {
              if (smfi_delrcpt(MG(ctx), rcpt) == MI_SUCCESS) {
                     RETURN_TRUE;
              }
       }
       
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( smfi_replacebody  )

Definition at line 729 of file php_milter.c.

{
       char *body;
       int len;
       
       /* valid only in milter_eom */
       if (MG(state) != MLFI_EOM) {
              php_error(E_WARNING, NOT_EOM, get_active_function_name(TSRMLS_C));
       } else if (zend_parse_parameters(1 TSRMLS_CC, "s", &body, &len) == SUCCESS) {
              if (smfi_replacebody(MG(ctx), (u_char*)body, len) == MI_SUCCESS) {
                     RETURN_TRUE;
              }
       }
       
       RETURN_FALSE;
}

Here is the call graph for this function:

static int php_milter_startup ( sapi_module_struct *  sapi_module) [static]

Definition at line 887 of file php_milter.c.

Here is the call graph for this function:

static void php_milter_usage ( char *  argv0) [static]

Definition at line 940 of file php_milter.c.

{
       char *prog;

       prog = strrchr(argv0, '/');
       if (prog) {
              prog++;
       } else {
              prog = "php-milter";
       }

       printf(     "Usage: %s [options] [-f] <file> [args...]\n"
                   "       %s [options] [-- args...]\n"
                            "  -a               Run interactively\n"
                            "  -c <path>|<file> Look for php.ini file in this directory\n"
                            "  -n               No php.ini file will be used\n"
                            "  -d foo[=bar]     Define INI entry foo with value 'bar'\n"
                            "  -D               run as daemon\n"
                            "  -e               Generate extended information for debugger/profiler\n"
                            "  -f <file>        Parse <file>.\n"
                            "  -h               This help\n"
                            "  -p <socket>      path to create socket\n"
                            "  -v               Version number\n"
                            "  -V <n>           set debug level to n (1 or 2).\n"
                            "  -z <file>        Load Zend extension <file>.\n"
                            "  args...          Arguments passed to script. Use -- args when first argument \n"
                            "                   starts with - or script is read from stdin\n"
                            , prog, prog);
}

Here is the caller graph for this function:

PHP_MINFO_FUNCTION ( milter  )

Definition at line 773 of file php_milter.c.

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( milter  )

Definition at line 749 of file php_milter.c.

{
       REGISTER_LONG_CONSTANT("SMFIS_CONTINUE",  SMFIS_CONTINUE,      CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("SMFIS_REJECT",           SMFIS_REJECT, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("SMFIS_DISCARD",          SMFIS_DISCARD,       CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("SMFIS_ACCEPT",           SMFIS_ACCEPT, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("SMFIS_TEMPFAIL",  SMFIS_TEMPFAIL,      CONST_CS | CONST_PERSISTENT);

       REGISTER_LONG_CONSTANT("SMFIF_ADDHDRS",          SMFIF_ADDHDRS,       CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("SMFIF_CHGHDRS",          SMFIF_CHGHDRS,       CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("SMFIF_CHGBODY",          SMFIF_CHGBODY,       CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("SMFIF_ADDRCPT",          SMFIF_ADDRCPT,       CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("SMFIF_DELRCPT",          SMFIF_DELRCPT,       CONST_CS | CONST_PERSISTENT);

       ZEND_INIT_MODULE_GLOBALS(milter, NULL, NULL);

       MG(state) = MLFI_NONE;
       MG(initialized) = 0;
       return SUCCESS;
}
static void sapi_milter_flush ( void *  server_context) [static]

Definition at line 863 of file php_milter.c.

{
}
static int sapi_milter_post_read ( char *  buf,
uint count_bytes  TSRMLS_DC 
) [static]

Definition at line 872 of file php_milter.c.

{
       return 0;
}
static char* sapi_milter_read_cookies ( TSRMLS_D  ) [static]

Definition at line 877 of file php_milter.c.

{
       return NULL;
}
static void sapi_milter_register_variables ( zval *track_vars_array  TSRMLS_DC) [static]

Definition at line 867 of file php_milter.c.

{
       php_register_variable ("SERVER_SOFTWARE", "Sendmail Milter", track_vars_array TSRMLS_CC);
}

Here is the call graph for this function:

static int sapi_milter_send_headers ( sapi_headers_struct *sapi_headers  TSRMLS_DC) [static]

Definition at line 882 of file php_milter.c.

static int sapi_milter_ub_write ( const char *  str,
uint str_length  TSRMLS_DC 
) [static]

Definition at line 858 of file php_milter.c.

{
       return str_length;
}

Variable Documentation

Definition at line 13 of file getopt.c.

Definition at line 14 of file getopt.c.

SMFICTX* ctx

Definition at line 99 of file php_milter.c.

char* filename = NULL [static]

Definition at line 95 of file php_milter.c.

int flag_debug = 0 [static]

Definition at line 94 of file php_milter.c.

Definition at line 101 of file php_milter.c.

Initial value:

Definition at line 826 of file php_milter.c.

sapi_module_struct milter_sapi_module [static]

Definition at line 898 of file php_milter.c.

zend_module_entry php_milter_module [static]
Initial value:

Definition at line 842 of file php_milter.c.

Definition at line 100 of file php_milter.c.