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

Date: Saturday June 27, 1998 @ 16:52
Author: shane

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

Modified Files:
        isapi_sapi.c nsapi_sapi.c phpsapi_nsapi.dsp
Log Message:
Preliminary NSAPI work. This gets nsapi compiling and linking, but there is a lot of work
to do on it before its worth even trying to load into a netscape server.

Index: php31/sapi/isapi_sapi.c
diff -c php31/sapi/isapi_sapi.c:1.20 php31/sapi/isapi_sapi.c:1.21
*** php31/sapi/isapi_sapi.c:1.20 Fri Jun 26 18:05:49 1998
--- php31/sapi/isapi_sapi.c Sat Jun 27 16:52:12 1998
***************
*** 292,299 ****
          sapi_info->content_type = lpEcb->lpszContentType;
          sapi_info->cookies = _sapi_getenv(lpEcb,"HTTP_COOKIE");
  
- sapi_info->aborted=0;
-
          sapi_info->puts=sapi_puts;
          sapi_info->sputc=sapi_putc;
          sapi_info->getenv=sapi_getenv;
--- 292,297 ----
Index: php31/sapi/nsapi_sapi.c
diff -c php31/sapi/nsapi_sapi.c:1.1.1.1 php31/sapi/nsapi_sapi.c:1.2
*** php31/sapi/nsapi_sapi.c:1.1.1.1 Tue May 26 22:27:04 1998
--- php31/sapi/nsapi_sapi.c Sat Jun 27 16:52:12 1998
***************
*** 30,48 ****
  
  
  /* FIXME BIG TIME. This is by no means complete! */
!
  #include "php.h"
  #include "language-parser.tab.h"
  #include "main.h"
  #include "control_structures.h"
  #include "php3_list.h"
  #include "modules.h"
! #include "functions/file.h"
! #include "functions/head.h"
! #include "functions/post.h"
! #include "functions/head.h"
! #include "functions/type.h"
  #include "highlight.h"
  
  /*netscape headers*/
  #include "base/pblock.h"
--- 30,49 ----
  
  
  /* FIXME BIG TIME. This is by no means complete! */
! #include "tls.h"
  #include "php.h"
  #include "language-parser.tab.h"
  #include "main.h"
  #include "control_structures.h"
  #include "php3_list.h"
  #include "modules.h"
! #include "ext/standard/file.h"
! #include "head.h"
! #include "ext/standard/post.h"
! #include "head.h"
! #include "ext/standard/type.h"
  #include "highlight.h"
+ #include "snprintf.h"
  
  /*netscape headers*/
  #include "base/pblock.h"
***************
*** 65,71 ****
  #define WIN32_LEAN_AND_MEAN
  #include <windows.h>
  #include <stdio.h>
- #define DLLEXPORT __declspec(dllexport)
  #endif /* XP_WIN32 */
  
  struct ns_request_info{
--- 66,71 ----
***************
*** 74,124 ****
          Request *rq;
  };
  
! int sapi_readclient(void *scid, char *buf, int size, int len){
! struct ns_request_info *ns_rqst=(struct ns_request_info *)scid;
! return net_read (ns_rqst->sn->csd, buf, size, 10);
  }
  
! char *sapi_getenv(void *scid, char *string){
! struct ns_request_info *ns_rqst=(struct ns_request_info *)scid;
  }
  
! /* FIXME */
! void sapi_header(void *scid, char *header){
! struct ns_request_info *ns_rqst=(struct ns_request_info *)scid;
! pblock_remove("content-type",nsrq->srvhdrs);
! pblock_nvinsert("content-type","text/html",nsrq->srvhdrs);
! protocol_status(nssn,nsrq,PROTOCOL_OK,NULL);
! if (protocol_start_response(nssn,nsrq)==REQ_NOACTION)
! return REQ_PROCEED;
  }
  
! void sapi_flush(void *scid){
! struct ns_request_info *ns_rqst=(struct ns_request_info *)scid;
  }
  
! void sapi_puts(void *scid, char *string){
! struct ns_request_info *ns_rqst=(struct ns_request_info *)scid;
! puts(string);
  }
  
! void sapi_putc(void *scid, char c){
! struct ns_request_info *ns_rqst=(struct ns_request_info *)scid;
! net_write(ns_rqst->sn->csd, &c, 1);
  }
  
! int sapi_writeclient(void *scid, char *string, int len){
! struct ns_request_info *ns_rqst=(struct ns_request_info *)scid;
! return net_write(ns_rqst->sn->csd, s, size);
  }
  
! void sapi_block(void *scid){}
! void sapi_unblock(void *scid){}
  
  
  void sapi_init(struct ns_request_info *ns_rqst,struct sapi_request_info *sapi_info)
  {
! char *buf;
  
          /* for cgi we dont use request id's */
          sapi_info->scid=ns_rqst;
--- 74,225 ----
          Request *rq;
  };
  
! #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;\
! struct ns_request_info *ns_rqst=(struct ns_request_info *)sapi_info->scid; \
! pblock *pb=(pblock *)ns_rqst->pb; \
! Session *sn=(Session *)ns_rqst->sn; \
! Request *rq=(Request *)ns_rqst->rq
!
! php3_module_entry *module_info=NULL;
!
!
! int sapi_readclient(SAPI_GLOBAL_INCLUDE char *buf, int len){
! SAPI_FUNC_VARS;
!
! return net_read (ns_rqst->sn->csd, buf, len, 10);
! }
!
! char *sapi_getenv(SAPI_GLOBAL_INCLUDE char *string){
! SAPI_FUNC_VARS;
! /* FIXME!!!!!!!! */
! return string;
  }
  
! /*FIXME need to make nsapi correctly handle redirects and status strings*/
! int sapi_insert_header(SAPI_GLOBAL_INCLUDE char *header){
! char *tempstr=NULL;
! SAPI_FUNC_VARS;
! /*inserts header into a list of headers*/
! /* header is in form of "headername: info"
! need to split into two strings and handle from there
! */
! pblock_remove("content-type",rq->srvhdrs);
! pblock_nvinsert("content-type","text/html",rq->srvhdrs);
! return SUCCESS;
  }
  
! int sapi_send_header(SAPI_GLOBAL_INCLUDE_V){
! SAPI_FUNC_VARS;
! /* this is sending ok on every call. need to figure out how
! we can handle other status codes */
! protocol_status(sn,rq,PROTOCOL_OK,NULL);
! if (protocol_start_response(sn,rq)==REQ_NOACTION)
! return REQ_PROCEED;
  }
  
! void sapi_treat_headers(SAPI_GLOBAL_INCLUDE_V){
! /*see apache for info on this function */
  }
  
! int sapi_puts(SAPI_GLOBAL_INCLUDE char *string){
! SAPI_FUNC_VARS;
! return net_write(sn->csd, string, strlen(string));
  }
  
! int sapi_putc(SAPI_GLOBAL_INCLUDE char c){
! SAPI_FUNC_VARS;
! return net_write(sn->csd, &c, 1);
  }
  
! int sapi_writeclient(SAPI_GLOBAL_INCLUDE char *string, int len){
! SAPI_FUNC_VARS;
! return net_write(sn->csd, string, len);
  }
  
! int sapi_flush(SAPI_GLOBAL_INCLUDE_V){ /* as in flush() */
! return SUCCESS;
! }
! void sapi_log(SAPI_GLOBAL_INCLUDE char *message){
! }
! void sapi_block(SAPI_GLOBAL_INCLUDE_V){ /*signal blocking*/
! }
! void sapi_unblock(SAPI_GLOBAL_INCLUDE_V){ /*signal blocking*/
! }
! void sapi_reqister_cleanup(SAPI_GLOBAL_INCLUDE void *arg1, void *arg2, void *arg3){
! }
! void sapi_request_shutdown(SAPI_GLOBAL_INCLUDE_V){
! }
! int sapi_aborted(SAPI_GLOBAL_INCLUDE_V){
! return 0;
! }
  
+ /******************************************************************************
+ /* code from main.c in _php3_hashenvironment()
+ /*****************************************************************************/
+ void sapi__php3_hashserver_env(SAPI_GLOBAL_INCLUDE_V){
+ SAPI_FUNC_VARS;
+ pval tmp;
+
+ /* Build the special-case PHP_SELF variable for the CGI version */
+ char *phpsn, *pi;
+ int l = 0;
+
+ phpsn = sapi_info->script_name;
+ pi = sapi_info->path_info;
+ if (sn)
+ l += strlen(phpsn);
+ if (pi)
+ l += strlen(pi);
+ if (pi && sn && !strcmp(pi, phpsn)) {
+ l -= strlen(pi);
+ pi = NULL;
+ }
+ tmp.value.str.val = emalloc(l + 1);
+ tmp.value.str.len = _php3_sprintf(tmp.value.str.val, "%s%s", (phpsn ? phpsn : ""), (pi ? pi : "")); /* SAFE */
+ tmp.type = IS_STRING;
+ _php3_hashupdate(&php3_globals->symbol_table, "PHP_SELF", sizeof("PHP_SELF"), (void *) & tmp, sizeof(pval), NULL);
+ }
+
+ #if defined(CRASH_DETECTION)
+ /******************************************************************************
+ /* crash detection logging
+ /*****************************************************************************/
+ void sapi_debug_log(SAPI_GLOBAL_INCLUDE 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());
+ OutputDebugString(log_message);
+ #endif
+ }
+ #endif
+
+ #define ENTRY_NAME_COLOR "#999999"
+ #define CONTENTS_COLOR "#DDDDDD"
+ #define HEADER_COLOR "#00DDDD"
+
+ void sapi_print_info(SAPI_GLOBAL_INCLUDE_V){
+ int i=0;
+ SAPI_FUNC_VARS;
+
+ sapi_puts(SAPI_GLOBAL_PASS "<center><h2>NSAPI Request Environment</h2></center>");
+ sapi_puts(SAPI_GLOBAL_PASS "<table border=5 width=\"600\">\n");
+ sapi_puts(SAPI_GLOBAL_PASS "<tr><th bgcolor=\"" HEADER_COLOR "\">Variable</th><th bgcolor=\"" HEADER_COLOR "\">Value</th></tr>\n");
+
+ /* print out the server environment table here */
+
+ sapi_puts(SAPI_GLOBAL_PASS "</table>\n");
+
+ }
  
  void sapi_init(struct ns_request_info *ns_rqst,struct sapi_request_info *sapi_info)
  {
! pblock *pb=(pblock *)ns_rqst->pb;
! Session *sn=(Session *)ns_rqst->sn;
! Request *rq=(Request *)ns_rqst->rq;
  
          /* for cgi we dont use request id's */
          sapi_info->scid=ns_rqst;
***************
*** 126,169 ****
          sapi_info->path_info = pblock_findval("path-info",rq->vars);
          sapi_info->path_translated = pblock_findval("path",rq->vars);
          sapi_info->filename = estrdup(sapi_info->path_translated);
! sapi_info->query_string = pblock_findval("query", srq->vars);
          sapi_info->request_method = pblock_findval("method",rq->reqpb);
          sapi_info->script_name = pblock_findval("path",rq->vars);
          sapi_info->content_length = atoi(pblock_findval("content-length",rq->headers));
          sapi_info->content_type = pblock_findval("content-type",rq->srvhdrs);
          request_header("cookie", &(sapi_info->cookies), sn,rq);
          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->header=sapi_header;
          sapi_info->readclient=sapi_readclient;
! sapi_info->block=sapi_block;
! sapi_info->unblock=sapi_unblock;
  }
  
  
! DLLEXPORT void close_nsapi_mod(void *vparam)
  {
          //global shutdown for all php threads
! //for now this will do nothing until we
! //make php thread-safe
  }
  
! DLLEXPORT int init_nsapi_mod(pblock *pb, Session *sn, Request *rq)
  {
          //global initialization for all php threads
! //for now this will do nothing until we
! //make php thread-safe
!
          daemon_atrestart(close_nsapi_mod, NULL);
          return REQ_PROCEED;
  }
  
! DLLEXPORT int nsapi_php_main(pblock *pb, Session *sn, Request *rq)
  {
! struct ns_request_info *ns_rqst=emalloc(sizeof(struct ns_request_info));
          struct sapi_request_info sapi_info;
          
          ns_rqst->pb=pb;
--- 227,296 ----
          sapi_info->path_info = pblock_findval("path-info",rq->vars);
          sapi_info->path_translated = pblock_findval("path",rq->vars);
          sapi_info->filename = estrdup(sapi_info->path_translated);
! sapi_info->query_string = pblock_findval("query", rq->vars);
          sapi_info->request_method = pblock_findval("method",rq->reqpb);
          sapi_info->script_name = pblock_findval("path",rq->vars);
          sapi_info->content_length = atoi(pblock_findval("content-length",rq->headers));
          sapi_info->content_type = pblock_findval("content-type",rq->srvhdrs);
          request_header("cookie", &(sapi_info->cookies), sn,rq);
+
          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->readclient=sapi_readclient;
! sapi_info->blockalarms=sapi_block;
! sapi_info->unblockalarms=sapi_unblock;
! sapi_info->log=sapi_log;
! sapi_info->info=sapi_print_info;
! sapi_info->aborted = sapi_aborted;
!
! sapi_info->insert_header=sapi_insert_header;
! sapi_info->treat_headers=sapi_treat_headers;
! sapi_info->send_header=sapi_send_header;
! sapi_info->headers=NULL;
!
! sapi_info->_php3_hashserver_env=sapi__php3_hashserver_env;
! sapi_info->register_clean=sapi_reqister_cleanup;
! sapi_info->request_shutdown=sapi_request_shutdown;
! #if defined(CRASH_DETECTION)
! sapi_info->debug_log=sapi_debug_log;
! #endif
!
! /*these are used in cgi, what do we do with them now*/
! sapi_info->cgi=0;
! sapi_info->display_source_mode=0;
! sapi_info->preprocess=0;
! sapi_info->info_only=0;
! sapi_info->quiet_mode=0;
!
! /*page stat info*/
! sapi_info->page_uid=0;
! sapi_info->page_inode=0;
! sapi_info->page_mtime=0;
  }
  
  
! void close_nsapi_mod(void *vparam)
  {
          //global shutdown for all php threads
! //do we use dllmain or this? What about thread start/end?
! //_php3_sapi_process_end();
  }
  
! int init_nsapi_mod(pblock *pb, Session *sn, Request *rq)
  {
          //global initialization for all php threads
! //do we use dllmain or this? What about thread start/end?
! //_php3_sapi_process_start(module_info);
          daemon_atrestart(close_nsapi_mod, NULL);
          return REQ_PROCEED;
  }
  
! int nsapi_php_main(pblock *pb, Session *sn, Request *rq)
  {
! struct ns_request_info *ns_rqst=malloc(sizeof(struct ns_request_info));
          struct sapi_request_info sapi_info;
          
          ns_rqst->pb=pb;
***************
*** 172,185 ****
  
          sapi_init(ns_rqst,&sapi_info);
  
! if (php3_sapi_main(&sapi_info))
! efree(ns_rqst);
                  return REQ_PROCEED; /*SUCCESS*/
          } else {
! efree(ns_rqst);
                  return REQ_ABORTED; /*FAILURE*/
          }
          return REQ_ABORTED; /*FAILURE*/
  }
  
  
--- 299,341 ----
  
          sapi_init(ns_rqst,&sapi_info);
  
! if (php3_sapi_main(&sapi_info,module_info)){
! free(ns_rqst);
                  return REQ_PROCEED; /*SUCCESS*/
          } else {
! free(ns_rqst);
                  return REQ_ABORTED; /*FAILURE*/
          }
+ free(ns_rqst);
          return REQ_ABORTED; /*FAILURE*/
  }
  
  
+ #if WIN32|WINNT
+ /******************************************************************************
+ /* Needed for windows. Initializes thread storage and per thread (module)
+ /* information.
+ /*****************************************************************************/
+
+ BOOL WINAPI DllMain(HANDLE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved)
+ {
+ switch (ul_reason_for_call) {
+ case DLL_PROCESS_ATTACH:
+ return _php3_sapi_process_start(module_info);
+ break;
+ case DLL_THREAD_ATTACH:
+ return _php3_sapi_thread_start(module_info);
+ break;
+ case DLL_THREAD_DETACH:
+ return _php3_sapi_thread_end();
+ break;
+ case DLL_PROCESS_DETACH:
+ return _php3_sapi_process_end();
+ break;
+ }
+ return FALSE;
+ }
+
+ #endif
Index: php31/sapi/phpsapi_nsapi.dsp
diff -c php31/sapi/phpsapi_nsapi.dsp:1.1 php31/sapi/phpsapi_nsapi.dsp:1.2
*** php31/sapi/phpsapi_nsapi.dsp:1.1 Wed May 27 12:09:16 1998
--- php31/sapi/phpsapi_nsapi.dsp Sat Jun 27 16:52:12 1998
***************
*** 64,74 ****
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 1
! # PROP Output_Dir "Debug"
! # PROP Intermediate_Dir "Debug"
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
! # ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
  # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
  # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
  # ADD BASE RSC /l 0x409 /d "_DEBUG"
--- 64,75 ----
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 1
! # PROP Output_Dir "sapi_Debug"
! # PROP Intermediate_Dir "sapi_Debug"
! # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
! # ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "./" /I "../" /I "../main" /I "c:\netscape\suitespot\include" /D "XP_WIN32" /D "MSVC5" /D "CRASH_DETECTION" /D "THREAD_SAFE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
  # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
  # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
  # ADD BASE RSC /l 0x409 /d "_DEBUG"
***************
*** 78,84 ****
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
! # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
  
  !ENDIF
  
--- 79,85 ----
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
! # ADD LINK32 ns-httpd30.lib phpsapi_core.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept /libpath:"c:\php31" /libpath:"c:\netscape\suitespot\lib"
  
  !ENDIF
  
***************
*** 88,94 ****
  # Name "phpsapi_nsapi - Win32 Debug"
  # Begin Source File
  
! SOURCE=.\serverapi\nsapi_sapi.c
  # End Source File
  # End Target
  # End Project
--- 89,95 ----
  # Name "phpsapi_nsapi - Win32 Debug"
  # Begin Source File
  
! SOURCE=.\nsapi_sapi.c
  # End Source File
  # End Target
  # End Project