Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
capi.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 <continuity.h>
#include <http.h>

Go to the source code of this file.

Classes

struct  capi_request_context

Defines

#define CONTINUITY   1
#define CAPI_DEBUG
#define NSLS_D   struct capi_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)

Typedefs

typedef struct capi_request_context capi_request_context

Functions

 PHP_MINIT_FUNCTION (continuity)
 PHP_MSHUTDOWN_FUNCTION (continuity)
 PHP_RINIT_FUNCTION (continuity)
 PHP_RSHUTDOWN_FUNCTION (continuity)
 PHP_MINFO_FUNCTION (continuity)
 PHP_FUNCTION (continuity_virtual)
 PHP_FUNCTION (continuity_request_headers)
 PHP_FUNCTION (continuity_response_headers)
static int sapi_capi_ub_write (const char *str, unsigned int str_length TSRMLS_DC)
static int sapi_capi_header_handler (sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
static int sapi_capi_send_headers (sapi_headers_struct *sapi_headers TSRMLS_DC)
static int sapi_capi_read_post (char *buffer, uint count_bytes TSRMLS_DC)
static char * sapi_capi_read_cookies (TSRMLS_D)
static void sapi_capi_register_server_variables (zval *track_vars_array TSRMLS_DC)
static void capi_log_message (char *message)
static int php_capi_startup (sapi_module_struct *sapi_module)
static char * capi_strdup (char *str)
static void capi_free (void *addr)
static void capi_request_ctor (NSLS_D TSRMLS_DC)
static void capi_request_dtor (NSLS_D TSRMLS_DC)
int capi_module_main (NSLS_D TSRMLS_DC)
int phpFinit (lstTset *opt)
int phpFservice (httpTtrans *t, lstTset *opts)

Variables

const zend_function_entry continuity_functions []
zend_module_entry continuity_module_entry
sapi_module_struct capi_sapi_module

Class Documentation

struct capi_request_context

Definition at line 66 of file capi.c.

Class Members
int read_post_bytes
httpTtrans * t

Define Documentation

#define CAPI_DEBUG

Definition at line 28 of file capi.c.

#define CONTINUITY   1

Definition at line 27 of file capi.c.

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

Definition at line 54 of file capi.c.

#define NSLS_C   request_context

Definition at line 52 of file capi.c.

#define NSLS_CC   , NSLS_C

Definition at line 53 of file capi.c.

#define NSLS_D   struct capi_request_context *request_context

Definition at line 50 of file capi.c.

#define NSLS_DC   , NSLS_D

Definition at line 51 of file capi.c.


Typedef Documentation


Function Documentation

static void capi_free ( void *  addr) [static]

Definition at line 406 of file capi.c.

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

Here is the caller graph for this function:

static void capi_log_message ( char *  message) [static]

Definition at line 346 of file capi.c.

{
   TSRMLS_FETCH();
   capi_request_context *rc = (capi_request_context *) SG(server_context);
   logFmsg(0, "mod/php: %s", message);
}
int capi_module_main ( NSLS_D  TSRMLS_DC)

Definition at line 440 of file capi.c.

{
   zend_file_handle file_handle;

   if (php_request_startup(TSRMLS_C) == FAILURE) {
      return FAILURE;
   }
   file_handle.type = ZEND_HANDLE_FILENAME;
   file_handle.filename = SG(request_info).path_translated;
   file_handle.free_filename = 0;
   file_handle.opened_path = NULL;

   php_execute_script(&file_handle TSRMLS_CC);
   php_request_shutdown(NULL);

   return SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void capi_request_ctor ( NSLS_D  TSRMLS_DC) [static]

Definition at line 412 of file capi.c.

{
   char *query_string = lstFset_get(NSG(t->vars), "query");
   char *uri = lstFset_get(NSG(t->vars), "uri");
   char *path_info = lstFset_get(NSG(t->vars), "path-info");
   char *path_translated = lstFset_get(NSG(t->vars), "path");
   char *request_method = lstFset_get(NSG(t->vars), "method");
   char *content_type = lstFset_get(NSG(t->req_hdrs), "content-type");
   char *content_length = lstFset_get(NSG(t->req_hdrs), "content-length");

   SG(request_info).query_string = capi_strdup(query_string);
   SG(request_info).request_uri = capi_strdup(uri);
   SG(request_info).request_method = capi_strdup(request_method);
   SG(request_info).path_translated = capi_strdup(path_translated);
   SG(request_info).content_type = capi_strdup(content_type);
   SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0);
   SG(sapi_headers).http_response_code = 200;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void capi_request_dtor ( NSLS_D  TSRMLS_DC) [static]

Definition at line 431 of file capi.c.

{
   capi_free(SG(request_info).query_string);
   capi_free(SG(request_info).request_uri);
   capi_free(SG(request_info).request_method);
   capi_free(SG(request_info).path_translated);
   capi_free(SG(request_info).content_type);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* capi_strdup ( char *  str) [static]

Definition at line 399 of file capi.c.

{
   if (str != NULL)
      return strFcopy(str);
   return NULL;
}

Here is the caller graph for this function:

static int php_capi_startup ( sapi_module_struct *  sapi_module) [static]

Definition at line 390 of file capi.c.

Here is the call graph for this function:

PHP_FUNCTION ( continuity_virtual  )
PHP_FUNCTION ( continuity_request_headers  )
PHP_FUNCTION ( continuity_response_headers  )
PHP_MINFO_FUNCTION ( continuity  )

Definition at line 110 of file capi.c.

{
        php_info_print_table_start();
        php_info_print_table_row(2, "Continuity Module Revision", "$Revision: 321634 $");
        php_info_print_table_row(2, "Server Version", conFget_build());
#ifdef CONTINUITY_CDPEXT
       php_info_print_table_row(2,"CDP Extensions", "enabled");
#else
       php_info_print_table_row(2,"CDP Extensions", "disabled");
#endif
        php_info_print_table_end();
        
/*        DISPLAY_INI_ENTRIES(); */
}

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( continuity  )

Definition at line 100 of file capi.c.

{
        return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION ( continuity  )

Definition at line 105 of file capi.c.

{
        return SUCCESS;
}
PHP_RINIT_FUNCTION ( continuity  )
PHP_RSHUTDOWN_FUNCTION ( continuity  )
int phpFinit ( lstTset *  opt)

Definition at line 458 of file capi.c.

{
   php_core_globals *core_globals;

   tsrm_startup(128, 1, 0, NULL);
   core_globals = ts_resource(core_globals_id);

   logFmsg(0, "mod/php: PHP Interface v3 (module)");
   logFmsg(0, "mod/php: Copyright (c) 1999-2005 The PHP Group. All rights reserved.");

   sapi_startup(&capi_sapi_module);
   capi_sapi_module.startup(&capi_sapi_module);

   return STATUS_PROCEED;
}

Here is the call graph for this function:

int phpFservice ( httpTtrans *  t,
lstTset *  opts 
)

Definition at line 474 of file capi.c.

{
   int retval;
   capi_request_context *request_context;

   TSRMLS_FETCH();

   request_context = (capi_request_context *) malloc(sizeof(capi_request_context));
   request_context->t = t;
   request_context->read_post_bytes = -1;

   SG(server_context) = request_context;

   capi_request_ctor(NSLS_C TSRMLS_CC);
   retval = capi_module_main(NSLS_C TSRMLS_CC);
   capi_request_dtor(NSLS_C TSRMLS_CC);

   free(request_context);

   /*
    * This call is ostensibly provided to free the memory from PHP/TSRM when
    * the thread terminated, but, it leaks a structure in some hash list
    * according to the developers. Not calling this will leak the entire
    * interpreter, around 100k, but calling it and then terminating the
    * thread will leak the struct (around a k). The only answer with the
    * current TSRM implementation is to reuse the threads that allocate TSRM
    * resources.
    */
   /* ts_free_thread(); */

   if (retval == SUCCESS) {
      return STATUS_EXIT;
   } else {
      return STATUS_ERROR;
   }
}

Here is the call graph for this function:

static int sapi_capi_header_handler ( sapi_header_struct sapi_header,
sapi_headers_struct *sapi_headers  TSRMLS_DC 
) [static]

Definition at line 146 of file capi.c.

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

   lstFset_delete_key(rc->t->res_hdrs, "Content-Type");

   header_name = sapi_header->header;
   header_content = p = strchr(header_name, ':');
   if (p == NULL) {
      return 0;
   }
   *p = 0;
   do {
      header_content++;
   } while (*header_content == ' ');

   lstFset_add(rc->t->res_hdrs, header_name, header_content);

   *p = ':';                /* restore '*p' */

   efree(sapi_header->header);

   return 0;                /* don't use the default SAPI mechanism, CAPI
                             * duplicates this functionality */
}
static char* sapi_capi_read_cookies ( TSRMLS_D  ) [static]

Definition at line 224 of file capi.c.

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

   cookie_string = lstFset_get(rc->t->req_hdrs, "cookie");
   return cookie_string;
}
static int sapi_capi_read_post ( char *  buffer,
uint count_bytes  TSRMLS_DC 
) [static]

Definition at line 198 of file capi.c.

{
   unsigned int max_read, total_read = 0;
   capi_request_context *rc = (capi_request_context *) SG(server_context);

   if (rc->read_post_bytes == -1) {
      max_read = MIN(count_bytes, SG(request_info).content_length);
   } else {
      if (rc->read_post_bytes == 0)
        return 0;
      max_read = MIN(count_bytes, (SG(request_info).content_length - rc->read_post_bytes));
   }

   total_read = httpFread(rc->t, buffer, max_read);

   if (total_read < 0)
      total_read = -1;
   else
      rc->read_post_bytes = total_read;

   return total_read;
}
static void sapi_capi_register_server_variables ( zval *track_vars_array  TSRMLS_DC) [static]

Definition at line 233 of file capi.c.

{
   capi_request_context *rc = (capi_request_context *) SG(server_context);
   size_t i;
   char *value;
   char buf[128];

   /* PHP_SELF and REQUEST_URI */
   value = lstFset_get(rc->t->vars, "uri");
   if (value != NULL) {
      php_register_variable("PHP_SELF", value, track_vars_array TSRMLS_CC);
      php_register_variable("REQUEST_URI", value, track_vars_array TSRMLS_CC);
   }
 
   /* COUNTRY CODE */
   value = lstFset_get(rc->t->vars, "ccode");
   if(value!=NULL)
     php_register_variable("COUNTRY_CODE", value, track_vars_array TSRMLS_CC);

   /* argv */
   value = lstFset_get(rc->t->vars, "query");
   if (value != NULL)
      php_register_variable("argv", value, track_vars_array TSRMLS_CC);

   /* GATEWAY_INTERFACE */
   php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC);

   /* SERVER_NAME and HTTP_HOST */
   value = lstFset_get(rc->t->req_hdrs, "host");
   if (value != NULL) {
      php_register_variable("HTTP_HOST", value, track_vars_array TSRMLS_CC);
      /* TODO: This should probably scrub the port value if one is present. */
      php_register_variable("SERVER_NAME", value, track_vars_array TSRMLS_CC);
   }
   /* SERVER_SOFTWARE */
   value = lstFset_get(rc->t->res_hdrs, "Server");
   if (value != NULL)
      php_register_variable("SERVER_SOFTWARE", value, track_vars_array TSRMLS_CC);

   /* SERVER_PROTOCOL */
   value = lstFset_get(rc->t->vars, "protocol");
   if (value != NULL)
      php_register_variable("SERVER_PROTOCOL", value, track_vars_array TSRMLS_CC);

   /* REQUEST_METHOD */
   value = lstFset_get(rc->t->vars, "method");
   if (value != NULL)
      php_register_variable("REQUEST_METHOD", value, track_vars_array TSRMLS_CC);

   /* QUERY_STRING */
   value = lstFset_get(rc->t->vars, "query");
   if (value != NULL)
      php_register_variable("QUERY_STRING", value, track_vars_array TSRMLS_CC);

   /* DOCUMENT_ROOT */
   value = lstFset_get(rc->t->vars, "docroot");
   if (value != NULL)
      php_register_variable("DOCUMENT_ROOT", value, track_vars_array TSRMLS_CC);

   /* HTTP_ACCEPT */
   value = lstFset_get(rc->t->req_hdrs, "accept");
   if (value != NULL)
      php_register_variable("HTTP_ACCEPT", value, track_vars_array TSRMLS_CC);

   /* HTTP_ACCEPT_CHARSET */
   value = lstFset_get(rc->t->req_hdrs, "accept-charset");
   if (value != NULL)
      php_register_variable("HTTP_ACCEPT_CHARSET", value, track_vars_array TSRMLS_CC);

   /* HTTP_ACCEPT_ENCODING */
   value = lstFset_get(rc->t->req_hdrs, "accept-encoding");
   if (value != NULL)
      php_register_variable("HTTP_ACCEPT_ENCODING", value, track_vars_array TSRMLS_CC);

   /* HTTP_ACCEPT_LANGUAGE */
   value = lstFset_get(rc->t->req_hdrs, "accept-language");
   if (value != NULL)
      php_register_variable("HTTP_ACCEPT_LANGUAGE", value, track_vars_array TSRMLS_CC);

   /* HTTP_CONNECTION */
   value = lstFset_get(rc->t->req_hdrs, "connection");
   if (value != NULL)
      php_register_variable("HTTP_CONNECTION", value, track_vars_array TSRMLS_CC);

   /* HTTP_REFERER */
   value = lstFset_get(rc->t->req_hdrs, "referer");
   if (value != NULL)
      php_register_variable("HTTP_REFERER", value, track_vars_array TSRMLS_CC);

   /* HTTP_USER_AGENT */
   value = lstFset_get(rc->t->req_hdrs, "user-agent");
   if (value != NULL)
      php_register_variable("HTTP_USER_AGENT", value, track_vars_array TSRMLS_CC);

   /* REMOTE_ADDR */
   utlFip_to_str(rc->t->cli_ipv4_addr, buf, sizeof(buf));
   php_register_variable("REMOTE_ADDR", buf, track_vars_array TSRMLS_CC);

   /* REMOTE_PORT */

   /* SCRIPT_FILENAME and PATH_TRANSLATED */
   value = lstFset_get(rc->t->vars, "path");
   if (value != NULL) {
      php_register_variable("SCRIPT_FILENAME", value, track_vars_array TSRMLS_CC);
      php_register_variable("PATH_TRANSLATED", value, track_vars_array TSRMLS_CC);
   }
   /* SERVER_ADMIN */
   /* Not applicable */

   /* SERVER_PORT */

}

Here is the call graph for this function:

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

Definition at line 177 of file capi.c.

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

   /*
    * We could probably just do this in the header_handler. But, I don't know
    * what the implication of doing it there is.
    */

   if (SG(sapi_headers).send_default_content_type) {
      /* lstFset_delete_key(rc->t->res_hdrs, "Content-Type"); */
      lstFset_update(rc->t->res_hdrs, "Content-Type", "text/html");
   }
   httpFset_status(rc->t, SG(sapi_headers).http_response_code, NULL);
   httpFstart_response(rc->t);

   return SAPI_HEADER_SENT_SUCCESSFULLY;

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

Definition at line 130 of file capi.c.

{
   int retval;
   capi_request_context *rc;

   rc = (capi_request_context *) SG(server_context);
   retval = httpFwrite(rc->t, (char *) str, str_length);
   if (retval == -1 || retval == 0)
      php_handle_aborted_connection();
   return retval;
}

Here is the call graph for this function:


Variable Documentation

sapi_module_struct capi_sapi_module

Definition at line 355 of file capi.c.

Initial value:
 {
        {NULL, NULL, NULL}
}

Definition at line 83 of file capi.c.

zend_module_entry continuity_module_entry
Initial value:

Definition at line 87 of file capi.c.