phanto          Sat Nov 30 22:37:50 2002 EDT

  Added files:                 
    /php4/sapi/milter   getopt.c 

  Modified files:              
    /php4/sapi/milter   config.m4 Makefile.frag php_milter.c TODO 
  Log:
  it finally compiles now
  tests will follow tomorrow
  
  
Index: php4/sapi/milter/config.m4
diff -u php4/sapi/milter/config.m4:1.1 php4/sapi/milter/config.m4:1.2
--- php4/sapi/milter/config.m4:1.1      Sat Nov 30 19:21:10 2002
+++ php4/sapi/milter/config.m4  Sat Nov 30 22:37:49 2002
@@ -1,39 +1,32 @@
 dnl
-dnl $Id: config.m4,v 1.1 2002/12/01 00:21:10 phanto Exp $
+dnl $Id: config.m4,v 1.2 2002/12/01 03:37:49 phanto Exp $
 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
Index: php4/sapi/milter/Makefile.frag
diff -u php4/sapi/milter/Makefile.frag:1.1 php4/sapi/milter/Makefile.frag:1.2
--- php4/sapi/milter/Makefile.frag:1.1  Sat Nov 30 19:21:10 2002
+++ php4/sapi/milter/Makefile.frag      Sat Nov 30 22:37:49 2002
@@ -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: php4/sapi/milter/php_milter.c
diff -u php4/sapi/milter/php_milter.c:1.3 php4/sapi/milter/php_milter.c:1.4
--- php4/sapi/milter/php_milter.c:1.3   Sat Nov 30 21:45:30 2002
+++ php4/sapi/milter/php_milter.c       Sat Nov 30 22:37:49 2002
@@ -109,8 +109,8 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
                                "  -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 @@
        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 @@
 
        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 @@
                                break;
 
                        case 'p': /* socket */
-                               sock = strdup(optarg);
+                               sock = strdup(ap_php_optarg);
                                break;
 
                        case 'v': /* show php version & quit */
@@ -794,7 +795,7 @@
                                break;
 
                        case 'V': /* verbose */
-                               flag_debug = atoi(optarg);
+                               flag_debug = atoi(ap_php_optarg);
                                break;
 
                        case 'z': /* load extension file */
@@ -886,7 +887,6 @@
                        fprintf(stderr, "smfi_register failed\n");
 //                             exit_status = EX_UNAVAILABLE;
                } else {
-                       debug(1, "smfi_register succeeded");
                        exit_status = smfi_main();
                }                       
 
Index: php4/sapi/milter/TODO
diff -u php4/sapi/milter/TODO:1.1 php4/sapi/milter/TODO:1.2
--- php4/sapi/milter/TODO:1.1   Sat Nov 30 20:36:26 2002
+++ php4/sapi/milter/TODO       Sat Nov 30 22:37:49 2002
@@ -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

Index: php4/sapi/milter/getopt.c
+++ php4/sapi/milter/getopt.c
/* 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 */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to