int main (int argc, char **argv) { int c; extern char *ap_php_optarg; extern int ap_php_optind; int aflg = 0; int bflg = 0; int errflg = 0; char *ofile = NULL; while ((c = ap_php_getopt(argc, argv, "abo:")) != EOF) switch (c) { case 'a': if (bflg) errflg++; else aflg++; break; case 'b': if (aflg) errflg++; else bflg++; break; case 'o': ofile = ap_php_optarg; (void)printf("ofile = %s\n", ofile); break; case '?': errflg++; } if (errflg) { (void)fprintf(stderr, "usage: cmd [-a|-b] [-o <filename>] files...\n"); exit (2); } for ( ; ap_php_optind < argc; ap_php_optind++) (void)printf("%s\n", argv[ap_php_optind]); return 0; }
/* {{{ main */ int main(int argc, char *argv[]) { 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! [email protected] 20000419 */ #endif #endif tsrm_startup(1, 1, 0, NULL); tsrm_ls = ts_resource(0); 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]; sapi_module.startup(&milter_sapi_module); zend_first_try { while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { switch (c) { case '?': php_output_tearup(); SG(headers_sent) = 1; php_milter_usage(argv[0]); php_output_teardown(); 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_tearup(); SG(headers_sent) = 1; php_milter_usage(argv[0]); php_output_teardown(); exit(1); break; case 'p': /* socket */ sock = strdup(ap_php_optarg); break; case 'v': /* show php version & quit */ if (php_request_startup()==FAILURE) { zend_ini_deactivate(); php_module_shutdown(); 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-2014 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); php_output_teardown(); 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); } /* 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(); sapi_shutdown(); tsrm_shutdown(); exit(exit_status); }