Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
nsapi.c File Reference
#include "php.h"
#include "php_variables.h"
#include "ext/standard/info.h"
#include "php_ini.h"
#include "php_globals.h"
#include "SAPI.h"
#include "php_main.h"
#include "php_version.h"
#include "TSRM.h"
#include "ext/standard/php_standard.h"
#include <sys/types.h>
#include <sys/stat.h>
#include "nsapi.h"

Go to the source code of this file.

Classes

struct  nsapi_request_context
struct  nsapi_equiv

Defines

#define NSAPI   1
#define RTLD_DEFAULT   NULL
#define XP_UNIX
#define NSAPI_PUBLIC   PHPAPI
#define NSLS_D   struct nsapi_request_context *request_context
#define NSLS_DC   , NSLS_D
#define NSLS_C   request_context
#define NSLS_CC   , NSLS_C
#define NSG(v)   (request_context->v)
#define NSAPI_G(v)   TSRMG(nsapi_globals_id, zend_nsapi_globals *, v)

Typedefs

typedef struct
nsapi_request_context 
nsapi_request_context
typedef struct nsapi_equiv nsapi_equiv
typedef int(* nsapi_servact_prototype )(Session *sn, Request *rq)

Functions

static void nsapi_free (void *addr)
 PHP_MINIT_FUNCTION (nsapi)
 PHP_MSHUTDOWN_FUNCTION (nsapi)
 PHP_RINIT_FUNCTION (nsapi)
 PHP_RSHUTDOWN_FUNCTION (nsapi)
 PHP_MINFO_FUNCTION (nsapi)
 PHP_FUNCTION (nsapi_virtual)
 PHP_FUNCTION (nsapi_request_headers)
 PHP_FUNCTION (nsapi_response_headers)
static void php_nsapi_init_dynamic_symbols (void)
static void php_nsapi_init_globals (zend_nsapi_globals *nsapi_globals)
static int sapi_nsapi_ub_write (const char *str, unsigned int str_length TSRMLS_DC)
static void sapi_nsapi_flush (void *server_context)
static int php_nsapi_remove_header (sapi_header_struct *sapi_header TSRMLS_DC)
static int sapi_nsapi_header_handler (sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC)
static int sapi_nsapi_send_headers (sapi_headers_struct *sapi_headers TSRMLS_DC)
static int sapi_nsapi_read_post (char *buffer, uint count_bytes TSRMLS_DC)
static char * sapi_nsapi_read_cookies (TSRMLS_D)
static void sapi_nsapi_register_server_variables (zval *track_vars_array TSRMLS_DC)
static void nsapi_log_message (char *message)
static time_t sapi_nsapi_get_request_time (TSRMLS_D)
static int php_nsapi_startup (sapi_module_struct *sapi_module)
static struct stat * sapi_nsapi_get_stat (TSRMLS_D)
static void nsapi_php_ini_entries (NSLS_D TSRMLS_DC)
void NSAPI_PUBLIC php5_close (void *vparam)
int NSAPI_PUBLIC php5_init (pblock *pb, Session *sn, Request *rq)
int NSAPI_PUBLIC php5_execute (pblock *pb, Session *sn, Request *rq)
int NSAPI_PUBLIC php5_auth_trans (pblock *pb, Session *sn, Request *rq)

Variables

static nsapi_equiv nsapi_reqpb []
static size_t nsapi_reqpb_size = sizeof(nsapi_reqpb)/sizeof(nsapi_reqpb[0])
static nsapi_equiv nsapi_vars []
static size_t nsapi_vars_size = sizeof(nsapi_vars)/sizeof(nsapi_vars[0])
static nsapi_equiv nsapi_client []
static size_t nsapi_client_size = sizeof(nsapi_client)/sizeof(nsapi_client[0])
static char * nsapi_exclude_from_ini_entries [] = { "fn", "type", "method", "directive", "code", "reason", "script", "bucket", NULL }
long read_timeout
const zend_function_entry nsapi_functions []
zend_module_entry nsapi_module_entry
nsapi_servact_prototype nsapi_servact_uri2path = NULL
nsapi_servact_prototype nsapi_servact_pathchecks = NULL
nsapi_servact_prototype nsapi_servact_fileinfo = NULL
nsapi_servact_prototype nsapi_servact_service = NULL
static sapi_module_struct nsapi_sapi_module

Class Documentation

struct nsapi_request_context

Definition at line 93 of file nsapi.c.

Class Members
int fixed_script
short http_error
char * path_info
pblock * pb
int read_post_bytes
Request * rq
Session * sn
struct nsapi_equiv

Definition at line 108 of file nsapi.c.

Class Members
const char * env_var
const char * nsapi_eq

Define Documentation

#define NSAPI   1

Definition at line 25 of file nsapi.c.

#define NSAPI_G (   v)    TSRMG(nsapi_globals_id, zend_nsapi_globals *, v)

Definition at line 168 of file nsapi.c.

#define NSAPI_PUBLIC   PHPAPI

Definition at line 74 of file nsapi.c.

#define NSG (   v)    (request_context->v)

Definition at line 81 of file nsapi.c.

#define NSLS_C   request_context

Definition at line 79 of file nsapi.c.

#define NSLS_CC   , NSLS_C

Definition at line 80 of file nsapi.c.

#define NSLS_D   struct nsapi_request_context *request_context

Definition at line 77 of file nsapi.c.

#define NSLS_DC   , NSLS_D

Definition at line 78 of file nsapi.c.

#define RTLD_DEFAULT   NULL

Definition at line 45 of file nsapi.c.

#define XP_UNIX

Definition at line 55 of file nsapi.c.


Typedef Documentation

typedef struct nsapi_equiv nsapi_equiv
typedef int(* nsapi_servact_prototype)(Session *sn, Request *rq)

Definition at line 224 of file nsapi.c.


Function Documentation

static void nsapi_free ( void *  addr) [static]

Definition at line 140 of file nsapi.c.

{
       if (addr != NULL) {
              FREE(addr);
       }
}

Here is the caller graph for this function:

static void nsapi_log_message ( char *  message) [static]

Definition at line 782 of file nsapi.c.

{
       TSRMLS_FETCH();
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);

       if (rc) {
              log_error(LOG_INFORM, pblock_findval("fn", rc->pb), rc->sn, rc->rq, "%s", message);
       } else {
              log_error(LOG_INFORM, "php5", NULL, NULL, "%s", message);
       }
}
static void nsapi_php_ini_entries ( NSLS_D  TSRMLS_DC) [static]

Definition at line 850 of file nsapi.c.

{
       struct pb_entry *entry;
       register int i,j,ok;

       for (i=0; i < NSG(pb)->hsize; i++) {
              entry=NSG(pb)->ht[i];
              while (entry) {
                     /* exclude standard entries given to "Service" which should not go into ini entries */
                     ok=1;
                     for (j=0; nsapi_exclude_from_ini_entries[j]; j++) {
                            ok&=(strcasecmp(entry->param->name, nsapi_exclude_from_ini_entries[j])!=0);
                     }

                     if (ok) {
                            /* change the ini entry */
                            if (zend_alter_ini_entry(entry->param->name, strlen(entry->param->name)+1,
                             entry->param->value, strlen(entry->param->value),
                             PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE)==FAILURE) {
                                   log_error(LOG_WARN, pblock_findval("fn", NSG(pb)), NSG(sn), NSG(rq), "Cannot change php.ini key \"%s\" to \"%s\"", entry->param->name, entry->param->value);
                            }
                     }
                     entry=entry->next;
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int NSAPI_PUBLIC php5_auth_trans ( pblock *  pb,
Session *  sn,
Request *  rq 
)

Definition at line 1093 of file nsapi.c.

{
       /* This is a DO NOTHING function that allows authentication
        * information
        * to be passed through to PHP scripts.
        */
       return REQ_PROCEED;
}
void NSAPI_PUBLIC php5_close ( void *  vparam)

Definition at line 877 of file nsapi.c.

{
       if (nsapi_sapi_module.shutdown) {
              nsapi_sapi_module.shutdown(&nsapi_sapi_module);
       }

       if (nsapi_sapi_module.php_ini_path_override) {
              free(nsapi_sapi_module.php_ini_path_override);
       }
       
#ifdef PHP_WIN32
       if (nsapi_dll) {
              free(nsapi_dll);
              nsapi_dll = NULL;
       }
#endif 

       sapi_shutdown();
       tsrm_shutdown();

       log_error(LOG_INFORM, "php5_close", NULL, NULL, "Shutdown PHP Module");
}

Here is the call graph for this function:

Here is the caller graph for this function:

int NSAPI_PUBLIC php5_execute ( pblock *  pb,
Session *  sn,
Request *  rq 
)

Definition at line 964 of file nsapi.c.

{
       int retval;
       nsapi_request_context *request_context;
       zend_file_handle file_handle = {0};
       struct stat *fst;

       char *path_info;
       char *query_string    = pblock_findval("query", rq->reqpb);
       char *uri             = pblock_findval("uri", rq->reqpb);
       char *request_method  = pblock_findval("method", rq->reqpb);
       char *content_type    = pblock_findval("content-type", rq->headers);
       char *content_length  = pblock_findval("content-length", rq->headers);
       char *directive       = pblock_findval("Directive", pb);
       int error_directive   = (directive && !strcasecmp(directive, "error"));
       int fixed_script      = 1;

       /* try to use script parameter -> Error or Service for directory listing */
       char *path_translated = pblock_findval("script", pb);

       TSRMLS_FETCH();

       /* if script parameter is missing: normal use as Service SAF  */
       if (!path_translated) {
              path_translated = pblock_findval("path", rq->vars);
              path_info       = pblock_findval("path-info", rq->vars);
              fixed_script = 0;
              if (error_directive) {
                     /* go to next error directive if script parameter is missing */
                     log_error(LOG_WARN, pblock_findval("fn", pb), sn, rq, "Missing 'script' parameter");
                     return REQ_NOACTION;
              }
       } else {
              /* in error the path_info is the uri to the requested page */
              path_info = pblock_findval("uri", rq->reqpb);
       }

       /* check if this uri was included in an other PHP script with nsapi_virtual()
          by looking for a request context in the current thread */
       if (SG(server_context)) {
              /* send 500 internal server error */
              log_error(LOG_WARN, pblock_findval("fn", pb), sn, rq, "Cannot make nesting PHP requests with nsapi_virtual()");
              if (error_directive) {
                     return REQ_NOACTION;
              } else {
                     protocol_status(sn, rq, 500, NULL);
                     return REQ_ABORTED;
              }
       }

       request_context = (nsapi_request_context *)pool_malloc(sn->pool, sizeof(nsapi_request_context));
       if (!request_context) {
              log_error(LOG_CATASTROPHE, pblock_findval("fn", pb), sn, rq, "Insufficient memory to process PHP request!");
              return REQ_ABORTED;
       }
       request_context->pb = pb;
       request_context->sn = sn;
       request_context->rq = rq;
       request_context->read_post_bytes = 0;
       request_context->fixed_script = fixed_script;
       request_context->http_error = (error_directive) ? rq->status_num : 0;
       request_context->path_info = path_info;

       SG(server_context) = request_context;
       SG(request_info).query_string = query_string;
       SG(request_info).request_uri = uri;
       SG(request_info).request_method = request_method;
       SG(request_info).path_translated = path_translated;
       SG(request_info).content_type = content_type;
       SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0);
       SG(sapi_headers).http_response_code = (error_directive) ? rq->status_num : 200;
       
       nsapi_php_ini_entries(NSLS_C TSRMLS_CC);

       if (!PG(safe_mode)) php_handle_auth_data(pblock_findval("authorization", rq->headers) TSRMLS_CC);

       file_handle.type = ZEND_HANDLE_FILENAME;
       file_handle.filename = SG(request_info).path_translated;
       file_handle.free_filename = 0;
       file_handle.opened_path = NULL;

       fst = request_stat_path(SG(request_info).path_translated, rq);
       if (fst && S_ISREG(fst->st_mode)) {
              if (php_request_startup(TSRMLS_C) == SUCCESS) {
                     php_execute_script(&file_handle TSRMLS_CC);
                     php_request_shutdown(NULL);
                     retval=REQ_PROCEED;
              } else {
                     /* send 500 internal server error */
                     log_error(LOG_WARN, pblock_findval("fn", pb), sn, rq, "Cannot prepare PHP engine!");
                     if (error_directive) {
                            retval=REQ_NOACTION;
                     } else {
                            protocol_status(sn, rq, 500, NULL);
                            retval=REQ_ABORTED;
                     }
              }
       } else {
              /* send 404 because file not found */
              log_error(LOG_WARN, pblock_findval("fn", pb), sn, rq, "Cannot execute PHP script: %s (File not found)", SG(request_info).path_translated);
              if (error_directive) {
                     retval=REQ_NOACTION;
              } else {
                     protocol_status(sn, rq, 404, NULL);
                     retval=REQ_ABORTED;
              }
       }

       pool_free(sn->pool, request_context);
       SG(server_context) = NULL;

       return retval;
}

Here is the call graph for this function:

int NSAPI_PUBLIC php5_init ( pblock *  pb,
Session *  sn,
Request *  rq 
)

Definition at line 911 of file nsapi.c.

{
       php_core_globals *core_globals;
       char *strval;
       int threads=128; /* default for server */

       /* fetch max threads from NSAPI and initialize TSRM with it */
       threads=conf_getglobals()->Vpool_maxthreads;
       if (threads<1) {
              threads=128; /* default for server */
       }
       tsrm_startup(threads, 1, 0, NULL);

       core_globals = ts_resource(core_globals_id);

       /* look if php_ini parameter is given to php5_init */
       if (strval = pblock_findval("php_ini", pb)) {
              nsapi_sapi_module.php_ini_path_override = strdup(strval);
       }
       
#ifdef PHP_WIN32
       /* look if server_lib parameter is given to php5_init
        * (this disables the automatic search for the newest ns-httpdXX.dll) */
       if (strval = pblock_findval("server_lib", pb)) {
              nsapi_dll = strdup(strval);
       }
#endif 

       /* start SAPI */
       sapi_startup(&nsapi_sapi_module);
       nsapi_sapi_module.startup(&nsapi_sapi_module);

       daemon_atrestart(&php5_close, NULL);

       log_error(LOG_INFORM, pblock_findval("fn", pb), sn, rq, "Initialized PHP Module (%d threads expected)", threads);
       return REQ_PROCEED;
}

Here is the call graph for this function:

PHP_FUNCTION ( nsapi_virtual  )

Definition at line 332 of file nsapi.c.

{
       int uri_len,rv;
       char *uri,*value;
       Request *rq;
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uri, &uri_len) == FAILURE) {
              return;
       }

       if (!nsapi_servact_service) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - Sub-requests not supported on this platform", uri);
              RETURN_FALSE;
       } else if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - Sub-requests do not work with zlib.output_compression", uri);
              RETURN_FALSE;
       } else {
              php_end_ob_buffers(1 TSRMLS_CC);
              php_header(TSRMLS_C);

              /* do the sub-request */
              /* thanks to Chris Elving from Sun for this code sniplet */
              if ((rq = request_restart_internal(uri, NULL)) == NULL) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - Internal request creation failed", uri);
                     RETURN_FALSE;
              }

              /* insert host of current request to get page from same vhost */
              param_free(pblock_remove("host", rq->headers));
              if (value = pblock_findval("host", rc->rq->headers)) {
                     pblock_nvinsert("host", value, rq->headers);
              }

              /* go through the normal request stages as given in obj.conf,
                 but leave out the logging/error section */
              do {
                     rv = (*nsapi_servact_uri2path)(rc->sn, rq);
                     if (rv != REQ_PROCEED) {
                            continue;
                     }

                     rv = (*nsapi_servact_pathchecks)(rc->sn, rq);
                     if (rv != REQ_PROCEED) {
                            continue;
                     }

                     rv = (*nsapi_servact_fileinfo)(rc->sn, rq);
                     if (rv != REQ_PROCEED) {
                            continue;
                     }

                     rv = (*nsapi_servact_service)(rc->sn, rq);
              } while (rv == REQ_RESTART);

              if (rq->status_num != 200) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include uri '%s' - HTTP status code %d during subrequest", uri, rq->status_num);
                     request_free(rq);
                     RETURN_FALSE;
              }

              request_free(rq);

              RETURN_TRUE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( nsapi_request_headers  )

Definition at line 402 of file nsapi.c.

{
       register int i;
       struct pb_entry *entry;
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);

       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }
       
       array_init(return_value);

       for (i=0; i < rc->rq->headers->hsize; i++) {
              entry=rc->rq->headers->ht[i];
              while (entry) {
                     if (!PG(safe_mode) || strncasecmp(entry->param->name, "authorization", 13)) {
                            add_assoc_string(return_value, entry->param->name, entry->param->value, 1);
                     }
                     entry=entry->next;
              }
       }
}
PHP_FUNCTION ( nsapi_response_headers  )

Definition at line 428 of file nsapi.c.

{
       register int i;
       struct pb_entry *entry;
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);

       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }
       
       array_init(return_value);

       for (i=0; i < rc->rq->srvhdrs->hsize; i++) {
              entry=rc->rq->srvhdrs->ht[i];
              while (entry) {
                     add_assoc_string(return_value, entry->param->name, entry->param->value, 1);
                     entry=entry->next;
              }
       }
}
PHP_MINFO_FUNCTION ( nsapi  )

Definition at line 312 of file nsapi.c.

{
       php_info_print_table_start();
       php_info_print_table_row(2, "NSAPI Module Revision", "$Revision: 321634 $");
       php_info_print_table_row(2, "Server Software", system_version());
       php_info_print_table_row(2, "Sub-requests with nsapi_virtual()",
        (nsapi_servact_service)?((zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0))?"not supported with zlib.output_compression":"enabled"):"not supported on this platform" );
       php_info_print_table_end();

       DISPLAY_INI_ENTRIES();
}

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( nsapi  )

Definition at line 292 of file nsapi.c.

Here is the call graph for this function:

Definition at line 303 of file nsapi.c.

static void php_nsapi_init_dynamic_symbols ( void  ) [static]

Definition at line 244 of file nsapi.c.

{
       /* find address of internal NSAPI functions */
#ifdef PHP_WIN32
       register int i;
       DL_HANDLE module = NULL;
       if (nsapi_dll) {
              /* try user specified server_lib */
              module = GetModuleHandle(nsapi_dll);
              if (!module) {
                     log_error(LOG_WARN, "php5_init", NULL, NULL, "Cannot find DLL specified by server_lib parameter: %s", nsapi_dll);
              }
       } else {
              /* find a LOADED dll module from nsapi_dlls */
              for (i=0; nsapi_dlls[i]; i++) {
                     if (module = GetModuleHandle(nsapi_dlls[i])) {
                            break;
                     }
              }
       }
       if (!module) return;
#else
       DL_HANDLE module = RTLD_DEFAULT;
#endif
       nsapi_servact_uri2path = (nsapi_servact_prototype)DL_FETCH_SYMBOL(module, "INTservact_uri2path");
       nsapi_servact_pathchecks = (nsapi_servact_prototype)DL_FETCH_SYMBOL(module, "INTservact_pathchecks");
       nsapi_servact_fileinfo = (nsapi_servact_prototype)DL_FETCH_SYMBOL(module, "INTservact_fileinfo");
       nsapi_servact_service = (nsapi_servact_prototype)DL_FETCH_SYMBOL(module, "INTservact_service");
       if (!(nsapi_servact_uri2path && nsapi_servact_pathchecks && nsapi_servact_fileinfo && nsapi_servact_service)) {
              /* not found - could be cause they are undocumented */
              nsapi_servact_uri2path = NULL;
              nsapi_servact_pathchecks = NULL;
              nsapi_servact_fileinfo = NULL;
              nsapi_servact_service = NULL;
       }
}

Here is the caller graph for this function:

static void php_nsapi_init_globals ( zend_nsapi_globals *  nsapi_globals) [static]

Definition at line 284 of file nsapi.c.

{
       nsapi_globals->read_timeout = 60;
}

Here is the caller graph for this function:

static int php_nsapi_remove_header ( sapi_header_struct *sapi_header  TSRMLS_DC) [static]

Definition at line 495 of file nsapi.c.

{
       char *header_name, *p;
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
       
       /* copy the header, because NSAPI needs reformatting and we do not want to change the parameter */
       header_name = pool_strdup(rc->sn->pool, sapi_header->header);

       /* extract name, this works, if only the header without ':' is given, too */
       if (p = strchr(header_name, ':')) {
              *p = 0;
       }
       
       /* header_name to lower case because NSAPI reformats the headers and wants lowercase */
       for (p=header_name; *p; p++) {
              *p=tolower(*p);
       }
       
       /* remove the header */
       param_free(pblock_remove(header_name, rc->rq->srvhdrs));
       pool_free(rc->sn->pool, header_name);
       
       return ZEND_HASH_APPLY_KEEP;
}

Here is the caller graph for this function:

static int php_nsapi_startup ( sapi_module_struct *  sapi_module) [static]

Definition at line 799 of file nsapi.c.

Here is the call graph for this function:

PHP_RINIT_FUNCTION ( nsapi  )
static void sapi_nsapi_flush ( void *  server_context) [static]

Definition at line 472 of file nsapi.c.

{
       nsapi_request_context *rc = (nsapi_request_context *)server_context;
       TSRMLS_FETCH();
       
       if (!rc) {
              /* we have no context, so no flushing needed. This fixes a SIGSEGV on shutdown */
              return;
       }

       if (!SG(headers_sent)) {
              sapi_send_headers(TSRMLS_C);
       }

       /* flushing is only supported in iPlanet servers from version 6.1 on, make it conditional */
#if NSAPI_VERSION >= 302
       if (net_flush(rc->sn->csd) < 0) {
              php_handle_aborted_connection();
       }
#endif
}

Here is the call graph for this function:

static time_t sapi_nsapi_get_request_time ( TSRMLS_D  ) [static]

Definition at line 794 of file nsapi.c.

{
       return REQ_TIME( ((nsapi_request_context *)SG(server_context))->rq );
}
static struct stat* sapi_nsapi_get_stat ( TSRMLS_D  ) [static, read]

Definition at line 807 of file nsapi.c.

{
       return request_stat_path(
              SG(request_info).path_translated,
              ((nsapi_request_context *)SG(server_context))->rq
       );
}
static int sapi_nsapi_header_handler ( sapi_header_struct sapi_header,
sapi_header_op_enum  op,
sapi_headers_struct *sapi_headers  TSRMLS_DC 
) [static]

Definition at line 520 of file nsapi.c.

{
       char *header_name, *header_content, *p;
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);

       switch(op) {
              case SAPI_HEADER_DELETE_ALL:
                     /* this only deletes headers set or overwritten by PHP, headers previously set by NSAPI are left intact */
                     zend_llist_apply(&sapi_headers->headers, (llist_apply_func_t) php_nsapi_remove_header TSRMLS_CC);
                     return 0;

              case SAPI_HEADER_DELETE:
                     /* reuse the zend_llist_apply callback function for this, too */
                     php_nsapi_remove_header(sapi_header TSRMLS_CC);
                     return 0;

              case SAPI_HEADER_ADD:
              case SAPI_HEADER_REPLACE:
                     /* copy the header, because NSAPI needs reformatting and we do not want to change the parameter */
                     header_name = pool_strdup(rc->sn->pool, sapi_header->header);

                     /* split header and align pointer for content */
                     header_content = strchr(header_name, ':');
                     if (header_content) {
                            *header_content = 0;
                            do {
                                   header_content++;
                            } while (*header_content==' ');
                            
                            /* header_name to lower case because NSAPI reformats the headers and wants lowercase */
                            for (p=header_name; *p; p++) {
                                   *p=tolower(*p);
                            }

                            /* if REPLACE, remove first.  "Content-type" is always removed, as SAPI has a bug according to this */
                            if (op==SAPI_HEADER_REPLACE || strcmp(header_name, "content-type")==0) {
                                   param_free(pblock_remove(header_name, rc->rq->srvhdrs));
                            }
                            /* ADD header to nsapi table */
                            pblock_nvinsert(header_name, header_content, rc->rq->srvhdrs);
                     }
                     
                     pool_free(rc->sn->pool, header_name);
                     return SAPI_HEADER_ADD;
                     
              default:
                     return 0;
       }
}

Here is the call graph for this function:

static char* sapi_nsapi_read_cookies ( TSRMLS_D  ) [static]

Definition at line 651 of file nsapi.c.

{
       char *cookie_string;
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);

       cookie_string = pblock_findval("cookie", rc->rq->headers);
       return cookie_string;
}
static int sapi_nsapi_read_post ( char *  buffer,
uint count_bytes  TSRMLS_DC 
) [static]

Definition at line 593 of file nsapi.c.

{
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
       char *read_ptr = buffer, *content_length_str = NULL;
       uint bytes_read = 0;
       int length, content_length = 0;
       netbuf *nbuf = rc->sn->inbuf;

       /*
        *     Yesss!
        */
       count_bytes = MIN(count_bytes, SG(request_info).content_length-rc->read_post_bytes);
       content_length = SG(request_info).content_length;

       if (content_length <= 0) {
              return 0;
       }

       /*
        * Gobble any pending data in the netbuf.
        */
       length = nbuf->cursize - nbuf->pos;
       length = MIN(count_bytes, length);
       if (length > 0) {
              memcpy(read_ptr, nbuf->inbuf + nbuf->pos, length);
              bytes_read += length;
              read_ptr += length;
              content_length -= length;
              nbuf->pos += length;
       }

       /*
        * Read the remaining from the socket.
        */
       while (content_length > 0 && bytes_read < count_bytes) {
              int bytes_to_read = count_bytes - bytes_read;

              if (content_length < bytes_to_read) {
                     bytes_to_read = content_length;
              }

              length = net_read(rc->sn->csd, read_ptr, bytes_to_read, NSAPI_G(read_timeout));

              if (length == IO_ERROR || length == IO_EOF) {
                     break;
              }

              bytes_read += length;
              read_ptr += length;
              content_length -= length;
       }

       if ( bytes_read > 0 ) {
              rc->read_post_bytes += bytes_read;
       }
       return bytes_read;
}
static void sapi_nsapi_register_server_variables ( zval *track_vars_array  TSRMLS_DC) [static]

Definition at line 660 of file nsapi.c.

{
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
       register size_t i;
       int pos;
       char *value,*p;
       char buf[32];
       struct pb_entry *entry;

       for (i = 0; i < nsapi_reqpb_size; i++) {
              value = pblock_findval(nsapi_reqpb[i].nsapi_eq, rc->rq->reqpb);
              if (value) {
                     php_register_variable((char *)nsapi_reqpb[i].env_var, value, track_vars_array TSRMLS_CC);
              }
       }

       for (i=0; i < rc->rq->headers->hsize; i++) {
              entry=rc->rq->headers->ht[i];
              while (entry) {
                     if (!PG(safe_mode) || strncasecmp(entry->param->name, "authorization", 13)) {
                            if (strcasecmp(entry->param->name, "content-length")==0 || strcasecmp(entry->param->name, "content-type")==0) {
                                   value=estrdup(entry->param->name);
                                   pos = 0;
                            } else {
                                   spprintf(&value, 0, "HTTP_%s", entry->param->name);
                                   pos = 5;
                            }
                            if (value) {
                                   for(p = value + pos; *p; p++) {
                                          *p = toupper(*p);
                                          if (!isalnum(*p)) {
                                                 *p = '_';
                                          }
                                   }
                                   php_register_variable(value, entry->param->value, track_vars_array TSRMLS_CC);
                                   efree(value);
                            }
                     }
                     entry=entry->next;
              }
       }

       for (i = 0; i < nsapi_vars_size; i++) {
              value = pblock_findval(nsapi_vars[i].nsapi_eq, rc->rq->vars);
              if (value) {
                     php_register_variable((char *)nsapi_vars[i].env_var, value, track_vars_array TSRMLS_CC);
              }
       }

       for (i = 0; i < nsapi_client_size; i++) {
              value = pblock_findval(nsapi_client[i].nsapi_eq, rc->sn->client);
              if (value) {
                     php_register_variable((char *)nsapi_client[i].env_var, value, track_vars_array TSRMLS_CC);
              }
       }

       if (value = session_dns(rc->sn)) {
              php_register_variable("REMOTE_HOST", value, track_vars_array TSRMLS_CC);
              nsapi_free(value);
       }

       slprintf(buf, sizeof(buf), "%d", conf_getglobals()->Vport);
       php_register_variable("SERVER_PORT", buf, track_vars_array TSRMLS_CC);
       php_register_variable("SERVER_NAME", conf_getglobals()->Vserver_hostname, track_vars_array TSRMLS_CC);

       value = http_uri2url_dynamic("", "", rc->sn, rc->rq);
       php_register_variable("SERVER_URL", value, track_vars_array TSRMLS_CC);
       nsapi_free(value);

       php_register_variable("SERVER_SOFTWARE", system_version(), track_vars_array TSRMLS_CC);
       if (security_active) {
              php_register_variable("HTTPS", "ON", track_vars_array TSRMLS_CC);
       }
       php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC);

       /* DOCUMENT_ROOT */
       if (value = request_translate_uri("/", rc->sn)) {
              pos = strlen(value);
              php_register_variable_safe("DOCUMENT_ROOT", value, pos-1, track_vars_array TSRMLS_CC);
              nsapi_free(value);
       }

       /* PATH_INFO / PATH_TRANSLATED */
       if (rc->path_info) {
              if (value = request_translate_uri(rc->path_info, rc->sn)) {
                     php_register_variable("PATH_TRANSLATED", value, track_vars_array TSRMLS_CC);
                     nsapi_free(value);
              }
              php_register_variable("PATH_INFO", rc->path_info, track_vars_array TSRMLS_CC);
       }

       /* Create full Request-URI & Script-Name */
       if (SG(request_info).request_uri) {
              pos = strlen(SG(request_info).request_uri);
              
              if (SG(request_info).query_string) {
                     spprintf(&value, 0, "%s?%s", SG(request_info).request_uri, SG(request_info).query_string);
                     if (value) {
                            php_register_variable("REQUEST_URI", value, track_vars_array TSRMLS_CC);
                            efree(value);
                     }
              } else {
                     php_register_variable_safe("REQUEST_URI", SG(request_info).request_uri, pos, track_vars_array TSRMLS_CC);
              }

              if (rc->path_info) {
                     pos -= strlen(rc->path_info);
                     if (pos<0) {
                            pos = 0;
                     }
              }
              php_register_variable_safe("SCRIPT_NAME", SG(request_info).request_uri, pos, track_vars_array TSRMLS_CC);
       }
       php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array TSRMLS_CC);

       /* special variables in error mode */
       if (rc->http_error) {
              slprintf(buf, sizeof(buf), "%d", rc->http_error);
              php_register_variable("ERROR_TYPE", buf, track_vars_array TSRMLS_CC);
       }
}

Here is the call graph for this function:

static int sapi_nsapi_send_headers ( sapi_headers_struct *sapi_headers  TSRMLS_DC) [static]

Definition at line 570 of file nsapi.c.

{
       int retval;
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);

       if (SG(sapi_headers).send_default_content_type) {
              char *hd;
              param_free(pblock_remove("content-type", rc->rq->srvhdrs));
              hd = sapi_get_default_content_type(TSRMLS_C);
              pblock_nvinsert("content-type", hd, rc->rq->srvhdrs);
              efree(hd);
       }

       protocol_status(rc->sn, rc->rq, SG(sapi_headers).http_response_code, NULL);
       retval = protocol_start_response(rc->sn, rc->rq);

       if (retval == REQ_PROCEED || retval == REQ_NOACTION) {
              return SAPI_HEADER_SENT_SUCCESSFULLY;
       } else {
              return SAPI_HEADER_SEND_FAILED;
       }
}

Here is the call graph for this function:

static int sapi_nsapi_ub_write ( const char *  str,
unsigned int str_length  TSRMLS_DC 
) [static]

Definition at line 455 of file nsapi.c.

{
       int retval;
       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
       
       if (!SG(headers_sent)) {
              sapi_send_headers(TSRMLS_C);
       }

       retval = net_write(rc->sn->csd, (char *)str, str_length);
       if (retval == IO_ERROR /* -1 */ || retval == IO_EOF /* 0 */) {
              php_handle_aborted_connection();
       }
       return retval;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
 {
       { "HTTPS_KEYSIZE",          "keysize" },
       { "HTTPS_SECRETSIZE",       "secret-keysize" },
       { "REMOTE_ADDR",            "ip" },
       { "REMOTE_HOST",            "ip" }
}

Definition at line 129 of file nsapi.c.

size_t nsapi_client_size = sizeof(nsapi_client)/sizeof(nsapi_client[0]) [static]

Definition at line 135 of file nsapi.c.

char* nsapi_exclude_from_ini_entries[] = { "fn", "type", "method", "directive", "code", "reason", "script", "bucket", NULL } [static]

Definition at line 138 of file nsapi.c.

Initial value:
 {
       PHP_FE(nsapi_virtual,       arginfo_nsapi_virtual)                                         
       PHP_FALIAS(virtual, nsapi_virtual, arginfo_nsapi_virtual)                    
       PHP_FE(nsapi_request_headers, arginfo_nsapi_request_headers)          
       PHP_FALIAS(getallheaders, nsapi_request_headers, arginfo_nsapi_request_headers)     
       PHP_FALIAS(apache_request_headers, nsapi_request_headers, arginfo_nsapi_request_headers)   
       PHP_FE(nsapi_response_headers, arginfo_nsapi_response_headers)        
       PHP_FALIAS(apache_response_headers, nsapi_response_headers, arginfo_nsapi_response_headers)       
       {NULL, NULL, NULL}
}

Definition at line 187 of file nsapi.c.

zend_module_entry nsapi_module_entry
Initial value:

Definition at line 201 of file nsapi.c.

Initial value:
 {
       { "QUERY_STRING",           "query" },
       { "REQUEST_LINE",           "clf-request" },
       { "REQUEST_METHOD",         "method" },
       { "PHP_SELF",               "uri" },
       { "SERVER_PROTOCOL", "protocol" }
}

Definition at line 113 of file nsapi.c.

size_t nsapi_reqpb_size = sizeof(nsapi_reqpb)/sizeof(nsapi_reqpb[0]) [static]

Definition at line 120 of file nsapi.c.

sapi_module_struct nsapi_sapi_module [static]

Definition at line 815 of file nsapi.c.

Definition at line 227 of file nsapi.c.

Definition at line 226 of file nsapi.c.

Definition at line 228 of file nsapi.c.

Definition at line 225 of file nsapi.c.

nsapi_equiv nsapi_vars[] [static]
Initial value:
 {
       { "AUTH_TYPE",                     "auth-type" },
       { "CLIENT_CERT",            "auth-cert" },
       { "REMOTE_USER",            "auth-user" }
}

Definition at line 122 of file nsapi.c.

size_t nsapi_vars_size = sizeof(nsapi_vars)/sizeof(nsapi_vars[0]) [static]

Definition at line 127 of file nsapi.c.

Definition at line 163 of file nsapi.c.