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

Date: Friday August 28, 1998 @ 0:09
Author: shane

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

Modified Files:
        wsapi_sapi.c
Log Message:
some work on dl's.
finish up work on wsapi. Working pretty well now, plenty of input from
orielly.

Index: php31/sapi/wsapi_sapi.c
diff -c php31/sapi/wsapi_sapi.c:2.4 php31/sapi/wsapi_sapi.c:2.5
*** php31/sapi/wsapi_sapi.c:2.4 Thu Aug 27 01:01:13 1998
--- php31/sapi/wsapi_sapi.c Fri Aug 28 00:09:39 1998
***************
*** 27,33 ****
          "DOCUMENT_ROOT",
          "GATEWAY_INTERFACE",
          "GMT_OFFSET",
- "SERVER_ADMIN",
          "PATH_INFO",
          "PATH_TRANSLATED",
          "QUERY_STRING",
--- 27,32 ----
***************
*** 37,42 ****
--- 36,42 ----
          "REMOTE_HOST",
          "REMOTE_USER",
          "SCRIPT_NAME",
+ "SERVER_ADMIN",
          "SERVER_NAME",
          "SERVER_PORT",
          "SERVER_PORT_SECURE",
***************
*** 89,102 ****
  char *sapi_getenv(SAPI_GLOBAL_INCLUDE char *string)
  {
          char var[MAX_BUFF_SIZE];
- DWORD dwLen = MAX_BUFF_SIZE;
          BOOL bExits;
          SAPI_FUNC_VARS;
  
          if (!string)
                  return NULL;
  
! bExits = get_server_variable(string, var, dwLen, tp);
  
          if (!bExits)
                  return NULL;
--- 89,102 ----
  char *sapi_getenv(SAPI_GLOBAL_INCLUDE char *string)
  {
          char var[MAX_BUFF_SIZE];
          BOOL bExits;
          SAPI_FUNC_VARS;
  
          if (!string)
                  return NULL;
  
! memset(var,'\0',MAX_BUFF_SIZE);
! bExits = get_server_variable(string, var, MAX_BUFF_SIZE-1, tp);
  
          if (!bExits)
                  return NULL;
***************
*** 107,124 ****
  char *_sapi_getenv(TCTX *tp, char *string)
  {
          char var[MAX_BUFF_SIZE];
- DWORD dwLen = MAX_BUFF_SIZE;
          BOOL bExits;
  
          if (!string)
                  return NULL;
  
! bExits = get_server_variable(string, var, dwLen, tp);
  
          if (!bExits)
                  return NULL;
          else
! return strdup(var);
  }
  
  /*FIXME need to make isapi correctly handle redirects and status strings */
--- 107,124 ----
  char *_sapi_getenv(TCTX *tp, char *string)
  {
          char var[MAX_BUFF_SIZE];
          BOOL bExits;
  
          if (!string)
                  return NULL;
  
! memset(var,'\0',MAX_BUFF_SIZE);
! bExits = get_server_variable(string, var, MAX_BUFF_SIZE-1, tp);
  
          if (!bExits)
                  return NULL;
          else
! return wsapi_strdup(var,tp);
  }
  
  /*FIXME need to make isapi correctly handle redirects and status strings */
***************
*** 135,141 ****
                          if (!strcasecmp(header, "HTTP")) {
                                  *r = '/';
                                  r = strchr(header, ' ');
! strcpy(tp->rsp_status,r+1);
                                  return SUCCESS;
                          }
                          *r = '/';
--- 135,141 ----
                          if (!strcasecmp(header, "HTTP")) {
                                  *r = '/';
                                  r = strchr(header, ' ');
! strncpy(tp->rsp_status,r+1,SML_STRING_LEN-1);
                                  return SUCCESS;
                          }
                          *r = '/';
***************
*** 146,164 ****
                          *r = '\0';
                          if (!strcasecmp(header, "Content-type")) {
                                  *r = ':';
! strcpy(tp->content_type,(r + 2));
                                  return SUCCESS;
                          }else if (!strcasecmp(header, "Location")) {
                                  *r = ':';
                                  sapi_info->http_redirect = 1;
! strcpy(tp->location,(r + 2));
                                  return SUCCESS;
                          }else if (!strcasecmp(header, "Last-modified")) {
                                  *r = ':';
! strcpy(tp->last_modified,(r + 2));
                          }else if (!strcasecmp(header, "Content-encoding")) {
                                  *r = ':';
! strcpy(tp->content_encoding,(r + 2));
                          }else{
                                  char *temp=(r+2);
                                  tp->rsp_xhdr[tp->num_rsp_xhdr].key=wsapi_strdup(header, tp);
--- 146,164 ----
                          *r = '\0';
                          if (!strcasecmp(header, "Content-type")) {
                                  *r = ':';
! strncpy(tp->content_type,(r + 2),MED_STRING_LEN-1);
                                  return SUCCESS;
                          }else if (!strcasecmp(header, "Location")) {
                                  *r = ':';
                                  sapi_info->http_redirect = 1;
! strncpy(tp->location,(r + 2),MAX_STRING_LEN-1);
                                  return SUCCESS;
                          }else if (!strcasecmp(header, "Last-modified")) {
                                  *r = ':';
! strncpy(tp->last_modified,(r + 2),SML_STRING_LEN-1);
                          }else if (!strcasecmp(header, "Content-encoding")) {
                                  *r = ':';
! strncpy(tp->content_encoding,(r + 2),MED_STRING_LEN-1);
                          }else{
                                  char *temp=(r+2);
                                  tp->rsp_xhdr[tp->num_rsp_xhdr].key=wsapi_strdup(header, tp);
***************
*** 185,209 ****
          return SUCCESS;
  }
  
- /* FIXME probably not used in isapi unless we buffer the page */
  int sapi_flush(SAPI_GLOBAL_INCLUDE_V)
  {
          SAPI_FUNC_VARS;
! nflush(tp);
          return SUCCESS;
  }
  
  int sapi_writeclient(SAPI_GLOBAL_INCLUDE unsigned char *string, int len)
  {
          SAPI_FUNC_VARS;
! nwrite(string, len, tp);
          return len;
  }
  
  int sapi_readclient(SAPI_GLOBAL_INCLUDE unsigned char *buf, int len)
  {
          SAPI_FUNC_VARS;
! nread(buf, len, tp);
          return len;
  }
  
--- 185,223 ----
          return SUCCESS;
  }
  
  int sapi_flush(SAPI_GLOBAL_INCLUDE_V)
  {
          SAPI_FUNC_VARS;
! __try
! {
! nflush(tp);
! } __except(EXCEPTION_EXECUTE_HANDLER) {
! return FAILURE;
! }
          return SUCCESS;
  }
  
  int sapi_writeclient(SAPI_GLOBAL_INCLUDE unsigned char *string, int len)
  {
          SAPI_FUNC_VARS;
! __try
! {
! nwrite(string, len, tp);
! } __except(EXCEPTION_EXECUTE_HANDLER) {
! len=0;
! }
          return len;
  }
  
  int sapi_readclient(SAPI_GLOBAL_INCLUDE unsigned char *buf, int len)
  {
          SAPI_FUNC_VARS;
! __try
! {
! nread(buf, len, tp);
! } __except(EXCEPTION_EXECUTE_HANDLER) {
! len=0;
! }
          return len;
  }
  
***************
*** 314,351 ****
  
  struct sapi_request_info *sapi_init(TCTX *tp)
  {
! struct sapi_request_info *sapi_info = malloc(sizeof(struct sapi_request_info));
          char buf[MAX_STRING_LEN];
          int type;
  
          strcpy(buf, tp->url);
          type=url_to_file(buf, TRUE, tp);
          if(type == STD_DOCUMENT) {
! sapi_info->rqst_filename = strdup(buf);
          }
- sapi_info->scid = tp;
- //
- // Shane -- We need to talk about this one. Microsoft has perverted the
- // true meaning of path info and path translated to make up for their
- // mistakes in designing ISAPI. Our customers expect the real path
- // info and path translated here.
- //
- sapi_info->path_info = _sapi_getenv(tp, "PATH_INFO");
- // sapi_info->path_info = tp->path_args;
- // sapi_info->path_translated = tp->url;
- // strcpy(buf, tp->path_args);
- url_to_file(buf, FALSE, tp);
- sapi_info->path_translated = strdup(buf); // *** WHEN FREE()??? ***
- //
- //
          sapi_info->filename = NULL; /* we will estrdup rqst_filename later */
  // sapi_info->query_string = _sapi_getenv(tp, "QUERY_STRING");
          sapi_info->query_string = tp->args;
          sapi_info->current_user = NULL; /*owner of script*/
          sapi_info->current_user_length = 0;
          sapi_info->request_method = tp->method;
! sapi_info->script_name = _sapi_getenv(tp, "SCRIPT_NAME");
! // sapi_info->script_name = tp->script_name;
          sapi_info->content_length = tp->content_length;
          sapi_info->content_type = tp->content_type;
          sapi_info->cookies = _sapi_getenv(tp, "HTTP_COOKIE");
--- 328,359 ----
  
  struct sapi_request_info *sapi_init(TCTX *tp)
  {
! struct sapi_request_info *sapi_info = wsapi_malloc(sizeof(struct sapi_request_info),tp);
          char buf[MAX_STRING_LEN];
          int type;
  
+ sapi_info->scid = tp;
+ sapi_info->path_info = _sapi_getenv(tp, "PATH_INFO");
+ if(sapi_info->path_info){
+ strcpy(buf, sapi_info->path_info);
+ type=url_to_file(buf, TRUE, tp);
+ if(type == STD_DOCUMENT) {
+ sapi_info->path_translated = wsapi_strdup(buf,tp);
+ }
+ }
          strcpy(buf, tp->url);
          type=url_to_file(buf, TRUE, tp);
          if(type == STD_DOCUMENT) {
! sapi_info->rqst_filename = wsapi_strdup(buf,tp);
          }
          sapi_info->filename = NULL; /* we will estrdup rqst_filename later */
  // sapi_info->query_string = _sapi_getenv(tp, "QUERY_STRING");
          sapi_info->query_string = tp->args;
          sapi_info->current_user = NULL; /*owner of script*/
          sapi_info->current_user_length = 0;
          sapi_info->request_method = tp->method;
! sapi_info->script_name = NULL;
! // sapi_info->script_name = _sapi_getenv(tp, "SCRIPT_NAME");
          sapi_info->content_length = tp->content_length;
          sapi_info->content_type = tp->content_type;
          sapi_info->cookies = _sapi_getenv(tp, "HTTP_COOKIE");
***************
*** 391,443 ****
  
  void sapi_shutdown(struct sapi_request_info *sapi_info)
  {
          if (sapi_info->path_info)
! free(sapi_info->path_info);
! if (sapi_info->query_string)
! free(sapi_info->query_string);
          if (sapi_info->script_name)
! free(sapi_info->script_name);
          if (sapi_info->cookies)
! free(sapi_info->cookies);
          if (sapi_info)
! free(sapi_info);
          sapi_info = NULL;
  }
  
  
! /* this is php3_isapi_main()!!! */
  BOOL Process(TCTX *tp)
  {
          int ret = 0;
          struct sapi_request_info *sapi_info;
  #if DEBUG
          char logmessage[80];
! snprintf(logmessage, 79, "%d:isapi_main:connID\n", GetCurrentThreadId());
          OutputDebugString(logmessage);
  #endif
-
  
! sapi_info = sapi_init(tp);
  #if DEBUG
! snprintf(logmessage, 79, "%d:isapi_main:request info set\n", GetCurrentThreadId());
! OutputDebugString(logmessage);
  #endif
! ret = php3_sapi_main(sapi_info, module_info);
  #if DEBUG
! snprintf(logmessage, 79, "%d:isapi_main:php parsed\n", GetCurrentThreadId());
! OutputDebugString(logmessage);
  #endif
  
          /*make sure we free any loose allocations */
! sapi_shutdown(sapi_info);
  #if DEBUG
! snprintf(logmessage, 79, "%d:isapi_main:request info reset\n", GetCurrentThreadId());
          OutputDebugString(logmessage);
  #endif
          if (ret == SUCCESS)
                  return TRUE;
! else
! return FALSE;
  }
  
  
--- 399,477 ----
  
  void sapi_shutdown(struct sapi_request_info *sapi_info)
  {
+ if (sapi_info->path_translated)
+ wsapi_free(sapi_info->path_translated);
          if (sapi_info->path_info)
! wsapi_free(sapi_info->path_info);
! if (sapi_info->rqst_filename)
! wsapi_free(sapi_info->rqst_filename);
          if (sapi_info->script_name)
! wsapi_free(sapi_info->script_name);
          if (sapi_info->cookies)
! wsapi_free(sapi_info->cookies);
          if (sapi_info)
! wsapi_free(sapi_info);
          sapi_info = NULL;
  }
  
  
! /* wsapi_main() */
  BOOL Process(TCTX *tp)
  {
          int ret = 0;
          struct sapi_request_info *sapi_info;
  #if DEBUG
          char logmessage[80];
! snprintf(logmessage, 79, "%d:wsapi_main:Process startup\n", GetCurrentThreadId());
          OutputDebugString(logmessage);
  #endif
  
! __try{
! sapi_info = sapi_init(tp);
! } __except(EXCEPTION_EXECUTE_HANDLER) {
  #if DEBUG
! snprintf(logmessage, 79, "%d:wsapi_main:sapi_init exception\n", GetCurrentThreadId());
! OutputDebugString(logmessage);
  #endif
! __try{
! sapi_shutdown(sapi_info);
! } __except(EXCEPTION_EXECUTE_HANDLER) {
  #if DEBUG
! snprintf(logmessage, 79, "%d:wsapi_main:sapi_init-sapi_shutdown exception\n", GetCurrentThreadId());
! OutputDebugString(logmessage);
  #endif
+ ret=0;
+ }
+ return FALSE;
+ }
+
+ __try{
+ ret = php3_sapi_main(sapi_info, module_info);
+ } __except(EXCEPTION_EXECUTE_HANDLER) {
+ #if DEBUG
+ snprintf(logmessage, 79, "%d:wsapi_main:php3_sapi_main exception\n", GetCurrentThreadId());
+ OutputDebugString(logmessage);
+ #endif
+ ret=0;
+ }
  
          /*make sure we free any loose allocations */
! __try{
! sapi_shutdown(sapi_info);
! } __except(EXCEPTION_EXECUTE_HANDLER) {
! #if DEBUG
! snprintf(logmessage, 79, "%d:wsapi_main:sapi_shutdown exception\n", GetCurrentThreadId());
! OutputDebugString(logmessage);
! #endif
! ret=0;
! }
  #if DEBUG
! snprintf(logmessage, 79, "%d:wsapi_main:return:%d\n", GetCurrentThreadId(),ret);
          OutputDebugString(logmessage);
  #endif
          if (ret == SUCCESS)
                  return TRUE;
! return FALSE;
  }
  
  
***************
*** 453,458 ****
--- 487,493 ----
                                          DWORD ul_reason_for_call,
                                          LPVOID lpReserved)
  {
+ __try{
          switch (ul_reason_for_call) {
                  case DLL_PROCESS_ATTACH:
                          if(_php3_sapi_process_start(module_info))
***************
*** 468,473 ****
--- 503,516 ----
                          return _php3_sapi_process_end();
                          break;
          }
+ } __except(EXCEPTION_EXECUTE_HANDLER) {
+ #if DEBUG
+ char logmessage[80];
+ snprintf(logmessage, 79, "%d:wsapi_dllmain exception\n", GetCurrentThreadId());
+ OutputDebugString(logmessage);
+ #endif
+ return FALSE;
+ }
          return FALSE;
  }
  

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>