[PHP-DEV] CVS update: php31/sapi From: shane (php-dev <email protected>)
Date: 05/31/98

Date: Sunday May 31, 1998 @ 18:10
Author: shane

Update of /repository/php31/sapi
In directory asf:/tmp/cvs-serv618/sapi

Modified Files:
        cgi_sapi.c sapi.h
Log Message:
Working to get a non-thread safe cgi version to compile again.

Index: php31/sapi/cgi_sapi.c
diff -c php31/sapi/cgi_sapi.c:1.6 php31/sapi/cgi_sapi.c:1.7
*** php31/sapi/cgi_sapi.c:1.6 Sun May 31 16:23:32 1998
--- php31/sapi/cgi_sapi.c Sun May 31 18:10:52 1998
***************
*** 15,83 ****
  #include "tls.h"
  #include "snprintf.h"
  
  #define SAPI_FUNC_VARS \
          php3_globals_struct *php3_globals=(php3_globals_struct *)php3_globals_var;\
          struct sapi_request_info *sapi_info=(struct sapi_request_info *)php3_globals->sapi_rqst
  
- /* for cgi this can be global */
- struct sapi_request_info sapi_info;
  
  /* sapi functions */
! int sapi_readclient(void *php3_globals_var, char *buf, int size, int len){
          return fread(buf, size, len, stdin);
  }
  
! char *sapi_getenv(void *php3_globals_var, char *string){
          return getenv(string);
  }
  
! int sapi_insert_header(void *php3_globals_var, char *header){
          puts(header);
          return puts("\015\012");
  }
  
! int sapi_send_header(void *php3_globals_var){
          return puts("\015\012");
  }
  
! int sapi_flush(void *php3_globals_var){
          return fflush(stdout);
  }
  
! int sapi_puts(void *php3_globals_var, char *string){
          return puts(string);
  }
  
! int sapi_putc(void *php3_globals_var, char c){
          return putc(c,stdout);
  }
  
! int sapi_writeclient(void *php3_globals_var, char *string, int len){
          return fwrite(string,len,1,stdout);
  }
  
! void sapi_log(void *php3_globals_var, char *message){
          fprintf(stderr,message);
  }
  
! void sapi_print_info(void *php3_globals_var){
  }
! void sapi_block(void *php3_globals_var){
  }
! void sapi_unblock(void *php3_globals_var){
  }
! void sapi_reqister_cleanup(void *php3_globals_var, void *arg1, void *arg2, void *arg3){
  }
! void sapi_request_shutdown(void *php3_globals_var){
  }
  
  #if defined(CRASH_DETECTION)
  /******************************************************************************
  /* crash detection logging
  /*****************************************************************************/
! void sapi_debug_log(void *php3_globals_var, char *message){
! SAPI_FUNC_VARS;
          char log_message[256];
                  
  #if MSVC5
          snprintf(log_message,256,"pid=%d:%s script='%s'",message,sapi_info->filename,GetCurrentThreadId());
--- 15,90 ----
  #include "tls.h"
  #include "snprintf.h"
  
+ /* for cgi this can be global */
+ struct sapi_request_info *sapi_info;
+
+ #ifdef THREAD_SAFE
  #define SAPI_FUNC_VARS \
          php3_globals_struct *php3_globals=(php3_globals_struct *)php3_globals_var;\
          struct sapi_request_info *sapi_info=(struct sapi_request_info *)php3_globals->sapi_rqst
+ #else
+ #define SAPI_FUNC_VARS
+ /* for non-thread safe static compiles */
+ struct sapi_request_info *sapi_rqst;
+ #endif
  
  
  /* sapi functions */
! int sapi_readclient(SAPI_GLOBAL_INCLUDE char *buf, int size, int len){
          return fread(buf, size, len, stdin);
  }
  
! char *sapi_getenv(SAPI_GLOBAL_INCLUDE char *string){
          return getenv(string);
  }
  
! int sapi_insert_header(SAPI_GLOBAL_INCLUDE char *header){
          puts(header);
          return puts("\015\012");
  }
  
! int sapi_send_header(SAPI_GLOBAL_INCLUDE_V){
          return puts("\015\012");
  }
  
! int sapi_flush(SAPI_GLOBAL_INCLUDE_V){
          return fflush(stdout);
  }
  
! int sapi_puts(SAPI_GLOBAL_INCLUDE char *string){
          return puts(string);
  }
  
! int sapi_putc(SAPI_GLOBAL_INCLUDE char c){
          return putc(c,stdout);
  }
  
! int sapi_writeclient(SAPI_GLOBAL_INCLUDE char *string, int len){
          return fwrite(string,len,1,stdout);
  }
  
! void sapi_log(SAPI_GLOBAL_INCLUDE char *message){
          fprintf(stderr,message);
  }
  
! void sapi_print_info(SAPI_GLOBAL_INCLUDE_V){
  }
! void sapi_block(SAPI_GLOBAL_INCLUDE_V){
  }
! void sapi_unblock(SAPI_GLOBAL_INCLUDE_V){
  }
! void sapi_reqister_cleanup(SAPI_GLOBAL_INCLUDE void *arg1, void *arg2, void *arg3){
  }
! void sapi_request_shutdown(SAPI_GLOBAL_INCLUDE_V){
  }
  
  #if defined(CRASH_DETECTION)
  /******************************************************************************
  /* crash detection logging
  /*****************************************************************************/
! void sapi_debug_log(SAPI_GLOBAL_INCLUDE char *message){
          char log_message[256];
+ SAPI_FUNC_VARS;
                  
  #if MSVC5
          snprintf(log_message,256,"pid=%d:%s script='%s'",message,sapi_info->filename,GetCurrentThreadId());
***************
*** 89,101 ****
  /******************************************************************************
  /* code from main.c in hash_environment()
  /*****************************************************************************/
! void sapi_hash_server_env(void *php3_globals_var){
! SAPI_FUNC_VARS;
          pval tmp;
-
          /* Build the special-case PHP_SELF variable for the CGI version */
          char *sn, *pi;
          int l = 0;
  
          sn = sapi_info->script_name;
          pi = sapi_info->path_info;
--- 96,107 ----
  /******************************************************************************
  /* code from main.c in hash_environment()
  /*****************************************************************************/
! void sapi_hash_server_env(SAPI_GLOBAL_INCLUDE_V){
          pval tmp;
          /* Build the special-case PHP_SELF variable for the CGI version */
          char *sn, *pi;
          int l = 0;
+ SAPI_FUNC_VARS;
  
          sn = sapi_info->script_name;
          pi = sapi_info->path_info;
***************
*** 110,171 ****
          tmp.value.str.val = emalloc(l + 1);
          tmp.value.str.len = _php3_sprintf(tmp.value.str.val, "%s%s", (sn ? sn : ""), (pi ? pi : "")); /* SAFE */
          tmp.type = IS_STRING;
          hash_update(&php3_globals->symbol_table, "PHP_SELF", sizeof("PHP_SELF"), (void *) & tmp, sizeof(pval), NULL);
  }
  
  void sapi_init(void)
  {
          char *buf;
  
          /* for cgi we dont use request id's */
! sapi_info.scid=NULL;
  
! if (!sapi_info.rqst_filename){
! sapi_info.rqst_filename=NULL;
          }
! sapi_info.filename=NULL;
! if (!sapi_info.path_info){
! sapi_info.path_info = getenv("PATH_INFO");
! }
! sapi_info.path_translated = getenv("PATH_TRANSLATED");
! if (!sapi_info.query_string){
! sapi_info.query_string = getenv("QUERY_STRING");
! }
! sapi_info.current_user = NULL;
! sapi_info.current_user_length=0;
! sapi_info.request_method = getenv("REQUEST_METHOD");
! sapi_info.script_name = getenv("SCRIPT_NAME");
          buf = getenv("CONTENT_LENGTH");
! sapi_info.content_length = (buf ? atoi(buf) : 0);
! sapi_info.content_type = getenv("CONTENT_TYPE");
! sapi_info.cookies = getenv("HTTP_COOKIE");
! sapi_info.script_filename = getenv("SCRIPT_FILENAME");
!
! sapi_info.aborted=0;
!
! sapi_info.puts=sapi_puts;
! sapi_info.putc=sapi_putc;
! sapi_info.getenv=sapi_getenv;
! sapi_info.writeclient=sapi_writeclient;
! sapi_info.flush=sapi_flush;
! sapi_info.insert_header=sapi_insert_header;
! sapi_info.send_header=sapi_send_header;
! sapi_info.readclient=sapi_readclient;
! sapi_info.block_alarms=sapi_block;
! sapi_info.unblock_alarms=sapi_unblock;
! sapi_info.log=sapi_log;
! sapi_info.info=sapi_print_info;
!
! sapi_info.hash_server_env=sapi_hash_server_env;
! sapi_info.register_cleanup=sapi_reqister_cleanup;
! sapi_info.request_shutdown=sapi_request_shutdown;
  #if defined(CRASH_DETECTION)
! sapi_info.debug_log=sapi_debug_log;
  #endif
  
          /* Hack for annoying servers that do not set SCRIPT_FILENAME for us */
! if (!sapi_info.script_filename) {
! sapi_info.script_filename = sapi_info.argv0;
          }
  #if WIN32|WINNT
          /* FIXME WHEN APACHE NT IS FIXED */
--- 116,185 ----
          tmp.value.str.val = emalloc(l + 1);
          tmp.value.str.len = _php3_sprintf(tmp.value.str.val, "%s%s", (sn ? sn : ""), (pi ? pi : "")); /* SAFE */
          tmp.type = IS_STRING;
+ #ifdef THREAD_SAFE
          hash_update(&php3_globals->symbol_table, "PHP_SELF", sizeof("PHP_SELF"), (void *) & tmp, sizeof(pval), NULL);
+ #else
+ hash_update(&symbol_table, "PHP_SELF", sizeof("PHP_SELF"), (void *) & tmp, sizeof(pval), NULL);
+ #endif
  }
  
  void sapi_init(void)
  {
          char *buf;
+ sapi_info=malloc(sizeof(struct sapi_request_info));
+ #ifndef THREAD_SAFE
+ sapi_rqst=sapi_info;
+ #endif
  
          /* for cgi we dont use request id's */
! sapi_info->scid=NULL;
  
! if (!sapi_info->rqst_filename){
! sapi_info->rqst_filename=NULL;
          }
! sapi_info->filename=NULL;
! if (!sapi_info->path_info){
! sapi_info->path_info = getenv("PATH_INFO");
! }
! sapi_info->path_translated = getenv("PATH_TRANSLATED");
! if (!sapi_info->query_string){
! sapi_info->query_string = getenv("QUERY_STRING");
! }
! sapi_info->current_user = NULL;
! sapi_info->current_user_length=0;
! sapi_info->request_method = getenv("REQUEST_METHOD");
! sapi_info->script_name = getenv("SCRIPT_NAME");
          buf = getenv("CONTENT_LENGTH");
! sapi_info->content_length = (buf ? atoi(buf) : 0);
! sapi_info->content_type = getenv("CONTENT_TYPE");
! sapi_info->cookies = getenv("HTTP_COOKIE");
! sapi_info->script_filename = getenv("SCRIPT_FILENAME");
!
! sapi_info->aborted=0;
!
! sapi_info->puts=sapi_puts;
! sapi_info->sputc=sapi_putc;
! sapi_info->getenv=sapi_getenv;
! sapi_info->writeclient=sapi_writeclient;
! sapi_info->flush=sapi_flush;
! sapi_info->insert_header=sapi_insert_header;
! sapi_info->send_header=sapi_send_header;
! sapi_info->readclient=sapi_readclient;
! sapi_info->block_alarms=sapi_block;
! sapi_info->unblock_alarms=sapi_unblock;
! sapi_info->log=sapi_log;
! sapi_info->info=sapi_print_info;
!
! sapi_info->hash_server_env=sapi_hash_server_env;
! sapi_info->register_cleanup=sapi_reqister_cleanup;
! sapi_info->request_shutdown=sapi_request_shutdown;
  #if defined(CRASH_DETECTION)
! sapi_info->debug_log=sapi_debug_log;
  #endif
  
          /* Hack for annoying servers that do not set SCRIPT_FILENAME for us */
! if (!sapi_info->script_filename) {
! sapi_info->script_filename = sapi_info->argv0;
          }
  #if WIN32|WINNT
          /* FIXME WHEN APACHE NT IS FIXED */
***************
*** 173,182 ****
             script filename to php.exe thus makes us parse php.exe instead of file.php
             requires we get the info from path translated. This can be removed at
             such a time taht apache nt is fixed */
! else if (sapi_info.path_translated) {
! sapi_info.script_filename = strdup(sapi_info.path_translated);
          } else {
! sapi_info.script_filename = NULL;
          }
  #endif
  
--- 187,196 ----
             script filename to php.exe thus makes us parse php.exe instead of file.php
             requires we get the info from path translated. This can be removed at
             such a time taht apache nt is fixed */
! else if (sapi_info->path_translated) {
! sapi_info->script_filename = strdup(sapi_info->path_translated);
          } else {
! sapi_info->script_filename = NULL;
          }
  #endif
  
***************
*** 188,212 ****
             Notice that this means that we don't need to efree() it in
             php3_destroy_request_info()! */
  #if DISCARD_PATH
! if (sapi_info.script_filename) {
! sapi_info.rqst_filename = strdup(sapi_info.script_filename);
          } else {
! sapi_info.rqst_filename = NULL;
          }
  #else
! if (sapi_info.path_translated) {
! sapi_info.rqst_filename = strdup(sapi_info.path_translated);
          } else {
! sapi_info.rqst_filename = NULL;
          }
  #endif
  }
  
  void sapi_end(void){
! if(sapi_info.argv0)free(sapi_info.argv0);
! if(sapi_info.ini_path)free(sapi_info.ini_path);
! if(sapi_info.script_filename)free(sapi_info.script_filename);
! if(sapi_info.rqst_filename)free(sapi_info.rqst_filename);
  }
  
  /* php cgi functions */
--- 202,226 ----
             Notice that this means that we don't need to efree() it in
             php3_destroy_request_info()! */
  #if DISCARD_PATH
! if (sapi_info->script_filename) {
! sapi_info->rqst_filename = strdup(sapi_info->script_filename);
          } else {
! sapi_info->rqst_filename = NULL;
          }
  #else
! if (sapi_info->path_translated) {
! sapi_info->rqst_filename = strdup(sapi_info->path_translated);
          } else {
! sapi_info->rqst_filename = NULL;
          }
  #endif
  }
  
  void sapi_end(void){
! if(sapi_info->argv0)free(sapi_info->argv0);
! if(sapi_info->ini_path)free(sapi_info->ini_path);
! if(sapi_info->script_filename)free(sapi_info->script_filename);
! if(sapi_info->rqst_filename)free(sapi_info->rqst_filename);
  }
  
  /* php cgi functions */
***************
*** 251,263 ****
   
          wVersionRequested = MAKEWORD( 2, 0 );
  #endif
! sapi_info.cgi=0;
! sapi_info.quiet_mode=0;
! sapi_info.preprocess=0;
! sapi_info.info_only=0;
! sapi_info.display_source_mode = 0;
! sapi_info.rqst_filename=NULL;
! sapi_info.filename=NULL;
  
          /* Make sure we detect we are a cgi - a bit redundancy here,
             but the default case is that we have to check only the first one. */
--- 265,277 ----
   
          wVersionRequested = MAKEWORD( 2, 0 );
  #endif
! sapi_info->cgi=0;
! sapi_info->quiet_mode=0;
! sapi_info->preprocess=0;
! sapi_info->info_only=0;
! sapi_info->display_source_mode = 0;
! sapi_info->rqst_filename=NULL;
! sapi_info->filename=NULL;
  
          /* Make sure we detect we are a cgi - a bit redundancy here,
             but the default case is that we have to check only the first one. */
***************
*** 267,273 ****
                  || getenv("REQUEST_METHOD")) {
                  cgi = 1;
                  if (argc > 1)
! sapi_info.argv0 = strdup(argv[1]);
  #if FORCE_CGI_REDIRECT
                  if (!getenv("REDIRECT_STATUS")) {
                          if (php3_header())
--- 281,287 ----
                  || getenv("REQUEST_METHOD")) {
                  cgi = 1;
                  if (argc > 1)
! sapi_info->argv0 = strdup(argv[1]);
  #if FORCE_CGI_REDIRECT
                  if (!getenv("REDIRECT_STATUS")) {
                          if (php3_header())
***************
*** 298,331 ****
          }
  #endif
          if (!cgi) { /* never execute the arguments if you are a CGI */
! sapi_info.argv0 = NULL;
                  while ((c = getopt(argc, argv, "f:qvishpe?v")) != -1) {
                          switch (c) {
                                  case 'f':
! sapi_info.rqst_filename = strdup(optarg);
                                                  /* break missing intentionally */
                                  case 'q':
! sapi_info.quiet_mode=1;
                                          break;
                                  case 'v':
                                          printf("%s\n", PHP_VERSION);
                                          exit(1);
                                          break;
                                  case 'i':
! sapi_info.info_only=1;
                                          break;
                                  case 'p': /* preprocess */
! sapi_info.preprocess=1;
! sapi_info.quiet_mode=1;
                                          break;
                                  case 'e': /* execute preprocessed script */
! sapi_info.preprocess=2;
                                          break;
                                  case 's':
! sapi_info.display_source_mode = 1;
                                          break;
                                  case 'c':
! sapi_info.ini_path = strdup(optarg);
                                          break;
                                  case 'h':
                                  case '?':
--- 312,345 ----
          }
  #endif
          if (!cgi) { /* never execute the arguments if you are a CGI */
! sapi_info->argv0 = NULL;
                  while ((c = getopt(argc, argv, "f:qvishpe?v")) != -1) {
                          switch (c) {
                                  case 'f':
! sapi_info->rqst_filename = strdup(optarg);
                                                  /* break missing intentionally */
                                  case 'q':
! sapi_info->quiet_mode=1;
                                          break;
                                  case 'v':
                                          printf("%s\n", PHP_VERSION);
                                          exit(1);
                                          break;
                                  case 'i':
! sapi_info->info_only=1;
                                          break;
                                  case 'p': /* preprocess */
! sapi_info->preprocess=1;
! sapi_info->quiet_mode=1;
                                          break;
                                  case 'e': /* execute preprocessed script */
! sapi_info->preprocess=2;
                                          break;
                                  case 's':
! sapi_info->display_source_mode = 1;
                                          break;
                                  case 'c':
! sapi_info->ini_path = strdup(optarg);
                                          break;
                                  case 'h':
                                  case '?':
***************
*** 340,348 ****
                  }
          }
  
! if ((sapi_info.path_info=getenv("PATH_INFO"))) {
! sapi_info.cgi = 1;
! } else if (!(sapi_info.query_string=getenv("QUERY_STRING"))) {
                  for(i=arg,len=0; i<argc; i++) {
                          len+=strlen(argv[i])+1;
                  }
--- 354,362 ----
                  }
          }
  
! if ((sapi_info->path_info=getenv("PATH_INFO"))) {
! sapi_info->cgi = 1;
! } else if (!(sapi_info->query_string=getenv("QUERY_STRING"))) {
                  for(i=arg,len=0; i<argc; i++) {
                          len+=strlen(argv[i])+1;
                  }
***************
*** 353,370 ****
                          strcat(s,argv[i]);
                          if (i<(argc-1)) strcat(s,"+");
                  }
! sapi_info.query_string = s;
          }
  
! if (sapi_info.rqst_filename == NULL && !sapi_info.cgi && argc > arg) {
! sapi_info.rqst_filename = strdup(argv[arg]);
! } else if (sapi_info.cgi) {
! sapi_info.rqst_filename=NULL;
          }
  
                  sapi_init();
  
! ret=php3_sapi_main(&sapi_info);
  
  #if WIN32|WINNT
          /*close down sockets*/
--- 367,384 ----
                          strcat(s,argv[i]);
                          if (i<(argc-1)) strcat(s,"+");
                  }
! sapi_info->query_string = s;
          }
  
! if (sapi_info->rqst_filename == NULL && !sapi_info->cgi && argc > arg) {
! sapi_info->rqst_filename = strdup(argv[arg]);
! } else if (sapi_info->cgi) {
! sapi_info->rqst_filename=NULL;
          }
  
                  sapi_init();
  
! ret=php3_sapi_main(sapi_info);
  
  #if WIN32|WINNT
          /*close down sockets*/
Index: php31/sapi/sapi.h
diff -c php31/sapi/sapi.h:1.5 php31/sapi/sapi.h:1.6
*** php31/sapi/sapi.h:1.5 Sun May 31 15:44:06 1998
--- php31/sapi/sapi.h Sun May 31 18:10:53 1998
***************
*** 13,18 ****
--- 13,30 ----
  #ifndef _PHP3_SAPI_H_
  #define _PHP3_SAPI_H_
  
+ #ifdef THREAD_SAFE
+ #define SAPI_GLOBAL_INCLUDE void *php3_globals_var,
+ #define SAPI_GLOBAL_INCLUDE_V void *php3_globals_var
+ #define SAPI_GLOBAL_PASS php3_globals,
+ #define SAPI_GLOBAL_PASS_V php3_globals
+ #else
+ #define SAPI_GLOBAL_INCLUDE
+ #define SAPI_GLOBAL_INCLUDE_V void
+ #define SAPI_GLOBAL_PASS
+ #define SAPI_GLOBAL_PASS_V
+ #endif
+
  struct sapi_request_info{
          void *scid; /* request identifier */
          char *rqst_filename; /*we need to estrdup this to filename later*/
***************
*** 33,113 ****
          /*handling headers*/
          char *headers; /*pointer to header list*/
          char *http_status; /* such as 401 Access Denied, needed for isapi*/
! int (*insert_header)(void *php3_globals, char *); /*insert header into a list*/
! int (*send_header)(void *php3_globals); /*write headers to client*/
  
          /* io functions */
! int (*readclient)(void *php3_globals, char *, int , int );
! void (*info)(void *php3_globals);
! void (*puts)(void *php3_globals, char *);
! void (*putc)(void *php3_globals, char);
! char *(*getenv)(void *php3_globals, char *);
! int (*writeclient)(void *php3_globals, char *, int);
! void (*flush)(void *php3_globals); /*flush writes to client*/
! void (*log)(void *php3_globals, char *); /*use server error log*/
  
          /* signal and thread functions */
! void (*block_alarms)(void *php3_globals); /*signal blocking*/
! void (*unblock_alarms)(void *php3_globals); /*signal blocking*/
  
          /* FIXME these functions need definet work */
! void (*hash_server_env)(void *php3_globals);
          /* so far, apache specific */
! void (*register_cleanup)(void *php3_globals, void *, void *, void *);
  
          /* so far, fhttpd specific */
! void (*request_shutdown)(void *php3_globals);
  
          /* output debug information somewhere */
  #if defined(CRASH_DETECTION)
! void (*debug_log)(void *php3_globals,char *log_message);
  #endif
  };
  
! #if !SAPI_INTERFACE
! #if !defined(COMPILE_DL)
! #define PUTS(a) GLOBAL(sapi_rqst)->puts(php3_globals,(a))
! #define PUTC(a) GLOBAL(sapi_rqst)->putc(php3_globals,(a))
! #define PHPWRITE(a,n) GLOBAL(sapi_rqst)->writeclient(php3_globals,(a),(n))
! #define BLOCK_INTERRUPTIONS if(GLOBAL(sapi_rqst))GLOBAL(sapi_rqst)->block_alarms(php3_globals)
! #define UNBLOCK_INTERRUPTIONS if(GLOBAL(sapi_rqst))GLOBAL(sapi_rqst)->unblock_alarms(php3_globals)
  #endif
  #endif
  
  /*emulates puts*/
! extern int sapi_puts(void *php3_globals, char *);
  
  /*emulates putc*/
! extern int sapi_putc(void *php3_globals, char);
  
  /*emulates getenv*/
! extern char *sapi_getenv(void *php3_globals, char *);
  
  /*writes a string to the client*/
! extern int sapi_writeclient(void *php3_globals, char *, int);
  
  /*flushes any writes to the client*/
! extern int sapi_flush(void *php3_globals);
  
  /*sends a header to the client, adds \n\r to the end*/
! extern int sapi_insert_header(void *php3_globals, char *header);
! extern int sapi_send_header(void *php3_globals);
  
  /*reads info from the client, used to get post*/
! extern int sapi_readclient(void *php3_globals, char *buf, int size, int len);
  
  /*signal blocking so a signal doesnt interrupt us in a bad place (used in apache) */
! extern void sapi_block(void *php3_globals);
! extern void sapi_unblock(void *php3_globals);
  
  /*logs messages to servers error log*/
! extern void sapi_log(void *php3_globals, char *log_message);
  
  /* this is the main function in main.c Initialization
   * may be required before calling this function.
   */
  extern PHPAPI int php3_sapi_main(struct sapi_request_info *sapi_info);
  
! extern void sapi_print_info(void *php3_globals);
  
  #endif
--- 45,131 ----
          /*handling headers*/
          char *headers; /*pointer to header list*/
          char *http_status; /* such as 401 Access Denied, needed for isapi*/
! int (*insert_header)(SAPI_GLOBAL_INCLUDE char *); /*insert header into a list*/
! int (*send_header)(SAPI_GLOBAL_INCLUDE_V); /*write headers to client*/
  
          /* io functions */
! int (*readclient)(SAPI_GLOBAL_INCLUDE char *, int , int );
! void (*info)(SAPI_GLOBAL_INCLUDE_V);
! void (*puts)(SAPI_GLOBAL_INCLUDE char *);
! void (*sputc)(SAPI_GLOBAL_INCLUDE char);
! char *(*getenv)(SAPI_GLOBAL_INCLUDE char *);
! int (*writeclient)(SAPI_GLOBAL_INCLUDE char *, int);
! void (*flush)(SAPI_GLOBAL_INCLUDE); /*flush writes to client*/
! void (*log)(SAPI_GLOBAL_INCLUDE char *); /*use server error log*/
  
          /* signal and thread functions */
! void (*block_alarms)(SAPI_GLOBAL_INCLUDE_V); /*signal blocking*/
! void (*unblock_alarms)(SAPI_GLOBAL_INCLUDE_V); /*signal blocking*/
  
          /* FIXME these functions need definet work */
! void (*hash_server_env)(SAPI_GLOBAL_INCLUDE_V);
          /* so far, apache specific */
! void (*register_cleanup)(SAPI_GLOBAL_INCLUDE void *, void *, void *);
  
          /* so far, fhttpd specific */
! void (*request_shutdown)(SAPI_GLOBAL_INCLUDE_V);
  
          /* output debug information somewhere */
  #if defined(CRASH_DETECTION)
! void (*debug_log)(SAPI_GLOBAL_INCLUDE char *log_message);
  #endif
  };
  
! #ifndef THREAD_SAFE
! extern struct sapi_request_info *sapi_rqst;
  #endif
+
+ #if defined(COMPILE_DL)
+ # define PUTS(a) php3_printf("%s",a)
+ # define PUTC(a) PUTS(a)
+ # define PHPWRITE(a,n) php3_write((a),(n))
+ #else
+ # define PUTS(a) GLOBAL(sapi_rqst)->puts(SAPI_GLOBAL_PASS a)
+ # define PUTC(a) GLOBAL(sapi_rqst)->sputc(SAPI_GLOBAL_PASS a)
+ # define PHPWRITE(a,n) GLOBAL(sapi_rqst)->writeclient(SAPI_GLOBAL_PASS(a),(n))
+ # define BLOCK_INTERRUPTIONS if(GLOBAL(sapi_rqst))GLOBAL(sapi_rqst)->block_alarms(SAPI_GLOBAL_PASS_V)
+ # define UNBLOCK_INTERRUPTIONS if(GLOBAL(sapi_rqst))GLOBAL(sapi_rqst)->unblock_alarms(SAPI_GLOBAL_PASS_V)
  #endif
  
  /*emulates puts*/
! extern int sapi_puts(SAPI_GLOBAL_INCLUDE char *);
  
  /*emulates putc*/
! extern int sapi_putc(SAPI_GLOBAL_INCLUDE char);
  
  /*emulates getenv*/
! extern char *sapi_getenv(SAPI_GLOBAL_INCLUDE char *);
  
  /*writes a string to the client*/
! extern int sapi_writeclient(SAPI_GLOBAL_INCLUDE char *, int);
  
  /*flushes any writes to the client*/
! extern int sapi_flush(SAPI_GLOBAL_INCLUDE_V);
  
  /*sends a header to the client, adds \n\r to the end*/
! extern int sapi_insert_header(SAPI_GLOBAL_INCLUDE char *header);
! extern int sapi_send_header(SAPI_GLOBAL_INCLUDE_V);
  
  /*reads info from the client, used to get post*/
! extern int sapi_readclient(SAPI_GLOBAL_INCLUDE char *buf, int size, int len);
  
  /*signal blocking so a signal doesnt interrupt us in a bad place (used in apache) */
! extern void sapi_block(SAPI_GLOBAL_INCLUDE_V);
! extern void sapi_unblock(SAPI_GLOBAL_INCLUDE_V);
  
  /*logs messages to servers error log*/
! extern void sapi_log(SAPI_GLOBAL_INCLUDE char *log_message);
  
  /* this is the main function in main.c Initialization
   * may be required before calling this function.
   */
  extern PHPAPI int php3_sapi_main(struct sapi_request_info *sapi_info);
  
! extern void sapi_print_info(SAPI_GLOBAL_INCLUDE_V);
  
  #endif