]> granicus.if.org Git - php/commitdiff
it finally compiles now
authorHarald Radi <phanto@php.net>
Sun, 1 Dec 2002 03:37:49 +0000 (03:37 +0000)
committerHarald Radi <phanto@php.net>
Sun, 1 Dec 2002 03:37:49 +0000 (03:37 +0000)
tests will follow tomorrow

sapi/milter/Makefile.frag
sapi/milter/TODO
sapi/milter/config.m4
sapi/milter/getopt.c [new file with mode: 0644]
sapi/milter/php_milter.c

index efef1e9f856006367a53d16a6c0b274bee5ee659..8dbdf7a8fd089e79e69ed225e0ed2b065247cd35 100644 (file)
@@ -1,7 +1,2 @@
-$(SAPI_MILTER_PATH): $(PHP_GLOBAL_OBJS) $(PHP_MILTER_OBJS)
+$(SAPI_MILTER_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
        $(BUILD_MILTER)
-
-install-milter: $(SAPI_MILTER_PATH)
-       @echo "Installing PHP Milter binary:        $(INSTALL_ROOT)$(bindir)/"
-       @$(INSTALL_CLI)
-
index cd90239270db51803525982c92840649bee81a71..705a1b590330172da6269b1dc98bfb5426bf32fd 100644 (file)
@@ -1,5 +1,7 @@
 add ini setting for smfi_settimeout()
 set xxfi_flags via ini, SMFIF_CHGBODY can have a significant performance impact if set
+parse the file only once instead of per request
+search for libmilter
 stdout to syslog
 testing
 documentation
\ No newline at end of file
index 37f065153abef840d1f2e95e807d2932811887cc..0e4c01c114437e33e990ad9bc688efed857fb296 100644 (file)
@@ -2,38 +2,31 @@ dnl
 dnl $Id$
 dnl
 
-AC_MSG_CHECKING(for milter support)
+AC_MSG_CHECKING(for Milter support)
 AC_ARG_WITH(milter,
-[  --with-milter=DIR       Build PHP as a Milter for use with Sendmail.],[
-  PHP_MILTER=$withval
-],[
-  PHP_MILTER=no
-])
-AC_MSG_RESULT($PHP_MILTER)
-
-if test "$PHP_MILTER" != "no"; then
-  PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/milter/Makefile.frag)
-  PHP_BUILD_THREAD_SAFE
+[  --with-milter=DIR       Build PHP as Milter application],[
+  if test "$withval" = "yes"; then
+        MILTERPATH=/usr
+  else
+        MILTERPATH=$withval
+  fi
+  
   SAPI_MILTER_PATH=sapi/milter/php-milter
   PHP_SUBST(SAPI_MILTER_PATH)
-
-  PHP_SELECT_SAPI(php-milter, program, php_milter.c,,'$(SAPI_MILTER_PATH)')
+  PHP_BUILD_THREAD_SAFE
+  PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/milter/Makefile.frag)
   
-  case $host_alias in
-    *darwin*)
-      BUILD_MILTER="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_MILTER_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_MILTER_PATH)"
-    ;;
-    *)
-      BUILD_MILTER="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_MILTER_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_MILTER_PATH)"
-    ;;
-  esac
-  INSTALL_MILTER="\$(INSTALL) -m 0755 \$(SAPI_MILTER_PATH) \$(INSTALL_ROOT)\$(bindir)/php-milter"
-  PHP_SUBST(BUILD_MILTER)
-  PHP_SUBST(INSTALL_MILTER)
-else
-  PHP_DISABLE_MILTER
-fi
+  PHP_SELECT_SAPI(milter, program, php_milter.c getopt.c,,'$(SAPI_MILTER_PATH)') 
+  PHP_ADD_LIBRARY_WITH_PATH(milter, "$MILTERPATH/lib",)
+  
+  BUILD_MILTER="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_MILTER_PATH)"
 
-dnl ## Local Variables:
-dnl ## tab-width: 4
-dnl ## End:
+  INSTALL_IT="\$(INSTALL) -m 0755 \$(SAPI_MILTER_PATH) \$(bindir)/php-milter"
+  RESULT=yes
+  PHP_SUBST(BUILD_MILTER)
+  PHP_SUBST(FASTCGI_LIBADD)
+  PHP_SUBST(EXT_PROGRAM_LDADD)
+],[
+  RESULT=no
+])
+AC_MSG_RESULT($RES
\ No newline at end of file
diff --git a/sapi/milter/getopt.c b/sapi/milter/getopt.c
new file mode 100644 (file)
index 0000000..f5874d5
--- /dev/null
@@ -0,0 +1,173 @@
+/* Borrowed from Apache NT Port */
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include "php_getopt.h"
+#define OPTERRCOLON (1)
+#define OPTERRNF (2)
+#define OPTERRARG (3)
+
+
+char *ap_php_optarg;
+int ap_php_optind = 1;
+static int ap_php_opterr = 1;
+
+static int
+ap_php_optiserr(int argc, char * const *argv, int oint, const char *optstr,
+         int optchr, int err)
+{
+    if (ap_php_opterr)
+    {
+        fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
+        switch(err)
+        {
+        case OPTERRCOLON:
+            fprintf(stderr, ": in flags\n");
+            break;
+        case OPTERRNF:
+            fprintf(stderr, "option not found %c\n", argv[oint][optchr]);
+            break;
+        case OPTERRARG:
+            fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]);
+            break;
+        default:
+            fprintf(stderr, "unknown\n");
+            break;
+        }
+    }
+    return('?');
+}
+    
+int ap_php_getopt(int argc, char* const *argv, const char *optstr)
+{
+    static int optchr = 0;
+    static int dash = 0; /* have already seen the - */
+
+    char *cp;
+
+    if (ap_php_optind >= argc)
+        return(EOF);
+    if (!dash && (argv[ap_php_optind][0] !=  '-'))
+        return(EOF);
+    if (!dash && (argv[ap_php_optind][0] ==  '-') && !argv[ap_php_optind][1])
+    {
+        /*
+         * use to specify stdin. Need to let pgm process this and
+         * the following args
+         */
+        return(EOF);
+    }
+    if ((argv[ap_php_optind][0] == '-') && (argv[ap_php_optind][1] == '-'))
+    {
+        /* -- indicates end of args */
+        ap_php_optind++;
+        return(EOF);
+    }
+    if (!dash)
+    {
+        assert((argv[ap_php_optind][0] == '-') && argv[ap_php_optind][1]);
+        dash = 1;
+        optchr = 1;
+    }
+
+    /* Check if the guy tries to do a -: kind of flag */
+    assert(dash);
+    if (argv[ap_php_optind][optchr] == ':')
+    {
+        dash = 0;
+        ap_php_optind++;
+        return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRCOLON));
+    }
+    if (!(cp = strchr(optstr, argv[ap_php_optind][optchr])))
+    {
+        int errind = ap_php_optind;
+        int errchr = optchr;
+
+        if (!argv[ap_php_optind][optchr+1])
+        {
+            dash = 0;
+            ap_php_optind++;
+        }
+        else
+            optchr++;
+        return(ap_php_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF));
+    }
+    if (cp[1] == ':')
+    {
+        /* Check for cases where the value of the argument 
+           is in the form -<arg> <val> or in the form -<arg><val> */
+        dash = 0;
+        if(!argv[ap_php_optind][2]) {
+            ap_php_optind++;
+            if (ap_php_optind == argc)
+                return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRARG));
+            ap_php_optarg = argv[ap_php_optind++];
+        }
+        else
+        {
+            ap_php_optarg = &argv[ap_php_optind][2];
+            ap_php_optind++;
+        }
+        return(*cp);
+    }
+    else
+    {
+        if (!argv[ap_php_optind][optchr+1])
+        {
+            dash = 0;
+            ap_php_optind++;
+        }
+        else
+            optchr++;
+        return(*cp);
+    }
+    assert(0);
+    return(0); /* never reached */
+}
+
+#ifdef TESTGETOPT
+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;
+ }
+
+#endif /* TESTGETOPT */
index 152407e861f614d3e2f55f15f6729702f67db979..12d6b7c52f590e0b44ea33616cff484af8d34efb 100644 (file)
@@ -109,8 +109,8 @@ static sfsistat     mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
        php_execute_script(&file_handle TSRMLS_CC);
 
        /* call userland */
-       ZVAL_INIT(function_name);
-       ZVAL_INIT(param[0]);
+       INIT_PZVAL(function_name);
+       INIT_PZVAL(param[0]);
 
        ZVAL_STRING(function_name, "milter_connect", 1);
        ZVAL_STRING(param[0], hostname, 1);
@@ -118,7 +118,7 @@ static sfsistat     mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
        call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -134,8 +134,8 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
-       ZVAL_INIT(param[0]);
+       INIT_PZVAL(function_name);
+       INIT_PZVAL(param[0]);
 
        ZVAL_STRING(function_name, "milter_helo", 1);
        ZVAL_STRING(param[0], helohost, 1);
@@ -143,7 +143,7 @@ static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
        call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -159,8 +159,8 @@ static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
-       ZVAL_INIT(param[0]);
+       INIT_PZVAL(function_name);
+       INIT_PZVAL(param[0]);
 
        ZVAL_STRING(function_name, "milter_envelope_from", 1);
        array_init(param[0]);
@@ -173,7 +173,7 @@ static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
        call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -189,8 +189,8 @@ static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
-       ZVAL_INIT(param[0]);
+       INIT_PZVAL(function_name);
+       INIT_PZVAL(param[0]);
 
        ZVAL_STRING(function_name, "milter_envelope_recipient", 1);
        array_init(param[0]);
@@ -203,7 +203,7 @@ static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv)
        call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -219,9 +219,9 @@ static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
-       ZVAL_INIT(param[0]);
-       ZVAL_INIT(param[1]);
+       INIT_PZVAL(function_name);
+       INIT_PZVAL(param[0]);
+       INIT_PZVAL(param[1]);
        
        ZVAL_STRING(function_name, "milter_header", 1);
        ZVAL_STRING(param[0], headerf, 1);
@@ -230,7 +230,7 @@ static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
        call_user_function(CG(function_table), NULL, function_name, retval, 2, param TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -246,12 +246,12 @@ static sfsistat mlfi_eoh(SMFICTX *ctx)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
+       INIT_PZVAL(function_name);
        ZVAL_STRING(function_name, "milter_eoh", 1);
        call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -267,8 +267,8 @@ static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
-       ZVAL_INIT(param[0]);
+       INIT_PZVAL(function_name);
+       INIT_PZVAL(param[0]);
 
        ZVAL_STRING(function_name, "milter_body", 1);
        ZVAL_STRINGL(param[0], bodyp, len, 1);
@@ -276,7 +276,7 @@ static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
        call_user_function(CG(function_table), NULL, function_name, retval, 1, param TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -292,12 +292,12 @@ static sfsistat mlfi_eom(SMFICTX *ctx)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
+       INIT_PZVAL(function_name);
        ZVAL_STRING(function_name, "milter_eom", 1);
        call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -313,12 +313,12 @@ static sfsistat mlfi_abort(SMFICTX *ctx)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
+       INIT_PZVAL(function_name);
        ZVAL_STRING(function_name, "milter_abort", 1);
        call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               return Z_LONG_P(retval);
+               return Z_LVAL_P(retval);
        } else {
                return SMFIS_CONTINUE;
        }
@@ -335,12 +335,12 @@ static sfsistat mlfi_close(SMFICTX *ctx)
        MG(ctx) = ctx;
        
        /* call userland */
-       ZVAL_INIT(function_name);
+       INIT_PZVAL(function_name);
        ZVAL_STRING(function_name, "milter_close", 1);
        call_user_function(CG(function_table), NULL, function_name, retval, 0, NULL TSRMLS_CC);
 
        if (Z_TYPE_P(retval) == IS_LONG) {
-               ret = Z_LONG_P(retval);
+               ret = Z_LVAL_P(retval);
        }
        
        php_request_shutdown((void *) 0);
@@ -627,7 +627,7 @@ static void php_milter_usage(char *argv0)
                                "  -e               Generate extended information for debugger/profiler\n"
                                "  -f <file>        Parse <file>.\n"
                                "  -h               This help\n"
-                               "  -p               path to create socket\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"
@@ -671,8 +671,7 @@ int main(int argc, char *argv[])
        char *param_error=NULL;
 /* end of temporary locals */
 
-       TSRMLS_FETCH();
-
+       void ***tsrm_ls;
 
 #ifdef HAVE_SIGNAL_H
 #if defined(SIGPIPE) && defined(SIG_IGN)
@@ -704,6 +703,8 @@ int main(int argc, char *argv[])
 
        milter_sapi_module.executable_location = argv[0];
 
+       tsrm_ls = ts_resource(0);
+
        sapi_module.startup(&milter_sapi_module);
 
        zend_first_try {
@@ -774,7 +775,7 @@ int main(int argc, char *argv[])
                                break;
 
                        case 'p': /* socket */
-                               sock = strdup(optarg);
+                               sock = strdup(ap_php_optarg);
                                break;
 
                        case 'v': /* show php version & quit */
@@ -794,7 +795,7 @@ int main(int argc, char *argv[])
                                break;
 
                        case 'V': /* verbose */
-                               flag_debug = atoi(optarg);
+                               flag_debug = atoi(ap_php_optarg);
                                break;
 
                        case 'z': /* load extension file */
@@ -886,7 +887,6 @@ int main(int argc, char *argv[])
                        fprintf(stderr, "smfi_register failed\n");
 //                             exit_status = EX_UNAVAILABLE;
                } else {
-                       debug(1, "smfi_register succeeded");
                        exit_status = smfi_main();
                }