[Freeswitch-svn] [commit] r2634 - freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php

Freeswitch SVN docelmo at freeswitch.org
Mon Sep 11 01:13:35 EDT 2006


Author: docelmo
Date: Mon Sep 11 01:13:35 2006
New Revision: 2634

Modified:
   freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php/Makefile
   freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php/mod_php.c

Log:
PHP Works with Error checking

Modified: freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php/Makefile
==============================================================================
--- freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php/Makefile	(original)
+++ freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php/Makefile	Mon Sep 11 01:13:35 2006
@@ -10,7 +10,7 @@
 all:	depends $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PHPMOD).$(DYNAMIC_LIB_EXTEN)
 
 depends:
-	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install php-5.1.6.tar.gz --prefix=$(PREFIX) --enable-embed=static --enable-static --with-pic --with-mysql --with-curl
+	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install php-5.1.6.tar.gz --prefix=$(PREFIX) --enable-embed=shared --enable-shared --with-pic --with-mysql --with-curl
 %.o:  %.c
 	$(CC) $(LCFLAGS) $(CFLAGS) -c $< -o $@
 

Modified: freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php/mod_php.c
==============================================================================
--- freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php/mod_php.c	(original)
+++ freeswitch/branches/docelmo/trunk/src/mod/languages/mod_php/mod_php.c	Mon Sep 11 01:13:35 2006
@@ -1,4 +1,4 @@
-/* 
+/*
  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
  *
@@ -22,7 +22,7 @@
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
- * 
+ *
  * Anthony Minessale II <anthmct at yahoo.com>
  * Brian Fertig <brian.fertig at convergencetek.com>
  *
@@ -30,11 +30,6 @@
  *
  */
 
-#if !defined(ZTS)
-#error "ZTS Needs to be defined."
-#endif
-
-
 #ifndef _REENTRANT
 #define _REENTRANT
 #endif
@@ -44,147 +39,14 @@
 #endif
 
 #include <sapi/embed/php_embed.h>
-//#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 <switch.h>
 
 const char modname[] = "mod_php";
 
-static void php_function(switch_core_session_t *session, char *data)
+static int sapi_mod_php_ub_write(const char *str, unsigned int str_length TSRMLS_DC)
 {
-	char *uuid = switch_core_session_get_uuid(session);
-	uint32_t ulen = strlen(uuid);
-	uint32_t len = strlen((char *) data) + ulen + 2;
-	char *mydata = switch_core_session_alloc(session, len);
-	int argc, retval;
-	char *argv[5];
-	char php_code[1024]; 
-	void*** tsrm_ls = NULL;
-	
-	
-	snprintf(mydata, len, "%s %s", uuid, data);
 
-	argc = 1; //switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-
-	//sprintf(php_code, "$uuid=\"%s\"; include(\"%s\");\n", argv[0], argv[1]);
-	sprintf(php_code, "include('%s');", argv[1]);
-
-	zend_file_handle script;
-	script.type = ZEND_HANDLE_FP;
-	script.filename = data;
-	script.opened_path = NULL;
-	script.free_filename = 0;
-	script.handle.fp = fopen(script.filename, "rb");	
-
-	//php_embed_init(argc, argv, &tsrm_ls);
-	if (php_request_startup(TSRMLS_C) == FAILURE) {
-		return;
-        }
-
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting Script %s\n",data);
-
-	retval = php_execute_script(&script TSRMLS_CC);	
-	php_request_shutdown(NULL);
-
-        return;
-
-
-	//PHP_EMBED_START_BLOCK(argc, argv);
-		//void*** tsrm_ls = NULL;
-		//zend_error_cb = myapp_php_error_cb;
-		//zend_eval_string(php_code, NULL, "MOD_PHP" TSRMLS_CC);
-//		zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, &script);
-		//if (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, &script) == SUCCESS)
-		    //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "There was a problem with the file\n");
-		//PHP_EMBED_END_BLOCK();
-//	php_embed_shutdown(tsrm_ls);
-		
-
-	//}else{
-	//    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "There was a problem with the file\n");	   
-	//}
-
-
-}
-
-static const switch_application_interface_t php_application_interface = {
-	/*.interface_name */ "php",
-	/*.application_function */ php_function
-};
-
-static switch_loadable_module_interface_t php_module_interface = {
-	/*.module_name */ modname,
-	/*.endpoint_interface */ NULL,
-	/*.timer_interface */ NULL,
-	/*.dialplan_interface */ NULL,
-	/*.codec_interface */ NULL,
-	/*.application_interface */ &php_application_interface,
-	/*.api_interface */ NULL,
-	/*.file_interface */ NULL,
-	/*.speech_interface */ NULL,
-	/*.directory_interface */ NULL
-};
-
-/*SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
-{
-	// connect my internal structure to the blank pointer passed to me 
-	*module_interface = &php_module_interface;
-	
-	sapi_startup(&mod_php_sapi_module);
-        mod_php_sapi_module.startup(&mod_php_sapi_module);
-
-
-	//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
-
-	// indicate that the module should continue to be loaded 
-	return SWITCH_STATUS_SUCCESS;
-}
-*/
-
-/*
-  Called when the system shuts down
-  SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
-  {
-  return SWITCH_STATUS_SUCCESS;
-  }
-*/
-
-/*
-  If it exists, this is called in it's own thread when the module-load completes
-  SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
-  {
-  return SWITCH_STATUS_SUCCESS;
-  }
-*/
-
-
-zend_module_entry mod_php_module_entry = {
-        STANDARD_MODULE_HEADER,
-        "mod_php",
-        NULL,
-        NULL,
-        NULL,
-        NULL,
-        NULL,
-        NULL,
-        NO_VERSION_YET,
-        STANDARD_MODULE_PROPERTIES
-};
-
-
-static int sapi_mod_php_ub_write(const char *str, unsigned int str_length TSRMLS_DC)
-{ // This function partly based on code from asterisk_php
-
   FILE *fp = fopen("mod_php.log", "a");
   fwrite(str, str_length, sizeof(char), fp);
   fclose(fp);
@@ -217,7 +79,7 @@
 }
 
 
-void mod_php_error_handler(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
+/*void mod_php_error_handler(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
 {
         char *buffer;
         int buffer_len;
@@ -255,11 +117,6 @@
 
                 if(PG(log_errors)) {
                         char *log_buffer;
-#ifdef PHP_WIN32
-                        if(type == E_CORE_ERROR || type == E_CORE_WARNING) {
-                                MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE);
-                        }
-#endif
                         spprintf(&log_buffer, 0, "PHP %s:  %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
                         php_log_err(log_buffer TSRMLS_CC);
                         efree(log_buffer);
@@ -269,31 +126,30 @@
                         char *prepend_string = INI_STR("error_prepend_string");
                         char *append_string = INI_STR("error_append_string");
                         char *error_format = "%s\n%s: %s in %s on line %d\n%s";
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, 
-STR_PRINT(append_string));
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
                 }
         }
 
-        /* Bail out if we can't recover */
+        // Bail out if we can't recover 
         switch(type) {
                 case E_CORE_ERROR:
                 case E_ERROR:
-                /*case E_PARSE: the parser would return 1 (failure), we can bail out nicely */
+                //case E_PARSE: the parser would return 1 (failure), we can bail out nicely 
                 case E_COMPILE_ERROR:
                 case E_USER_ERROR:
                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "\nPHP: %s exiting\n", error_filename);
                         EG(exit_status) = 255;
 #if MEMORY_LIMIT
-                        /* restore memory limit */
+                        // restore memory limit 
                         AG(memory_limit) = PG(memory_limit);
 #endif
                         efree(buffer);
                         zend_bailout();
                         return;
-                        break;
+
         }
 
-        /* Log if necessary */
+        // Log if necessary 
         if(PG(track_errors) && EG(active_symbol_table)) {
                 pval *tmp;
 
@@ -305,89 +161,112 @@
                 zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(pval *), NULL);
         }
         efree(buffer);
-}
+}*/
 
-static int sapi_mod_php_header_handler(sapi_header_struct * sapi_header, sapi_headers_struct * sapi_headers TSRMLS_DC)
-{
-        return 0;
-}
 
-static int sapi_mod_php_send_headers(sapi_headers_struct * sapi_headers TSRMLS_DC)
+static void mod_php_log_message(char *message)
 {
-        return SAPI_HEADER_SENT_SUCCESSFULLY;
+         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s\n", message);
 }
 
-static int sapi_mod_php_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-{
-        return 0;
-}
+//typedef void (*sapi_error_function_t)(int type, const char *error_msg, ...);
 
-static int mod_php_startup(sapi_module_struct *sapi_module)
-{
-        if(php_module_startup(sapi_module, &mod_php_module_entry, 1) == FAILURE) {
-                return FAILURE;
-        }
-        return SUCCESS;
-}
 
-static void mod_php_log_message(char *message)
+
+static void php_function(switch_core_session_t *session, char *data)
 {
-         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s\n", message);
-}
+        char *uuid = switch_core_session_get_uuid(session);
+        uint32_t ulen = strlen(uuid);
+        uint32_t len = strlen((char *) data) + ulen + 2;
+        char *mydata = switch_core_session_alloc(session, len);
+        int argc, retval;
+        char *argv[5];
+        char php_code[1024];
+        void*** tsrm_ls = NULL;
 
+        snprintf(mydata, len, "%s %s", uuid, data);
 
-static char *sapi_mod_php_read_cookies(TSRMLS_D)
-{
-        return NULL;
-}
+        argc = switch_separate_string(mydata, ' ',argv,(sizeof(argv) / sizeof(argv[0])));
 
-static int mod_php_startup(sapi_module_struct *sapi_module);
+        sprintf(php_code, "$uuid=\"%s\"; include(\"%s\");\n", argv[0], argv[1]);
+        //sprintf(php_code, "include('%s');", argv[1]);
 
-sapi_module_struct mod_php_sapi_module = {
-   "mod_php",                                  /* name */
-   "mod_php",                                  /* pretty name */
+        zend_file_handle script;
+        script.type = ZEND_HANDLE_FP;
+        script.filename = data;
+        script.opened_path = NULL;
+        script.free_filename = 0;
+        script.handle.fp = fopen(script.filename, "rb");
 
-   mod_php_startup,                        /* startup */
-   NULL,                 /* shutdown */
+        //if (php_embed_init(argc, argv, &tsrm_ls) == FAILURE) {
+	php_embed_init(argc, argv, &tsrm_ls);
+       //if (php_request_startup(TSRMLS_C) == FAILURE) {
+          //      return;
+        //}
+        php_embed_module.ub_write = sapi_mod_php_ub_write;
+        php_embed_module.log_message = mod_php_log_message;
+        //php_embed_module.sapi_error = (sapi_error_function_t)mod_php_error_handler;
 
-   NULL,                                        /* activate */
-   NULL,                                        /* deactivate */
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting Script %s\n",data);
 
-   sapi_mod_php_ub_write,                      /* unbuffered write */
-   NULL,                                        /* flush */
-   NULL,                                        /* get uid */
-   NULL,                                        /* getenv */
+        retval = php_execute_script(&script TSRMLS_CC);
 
-   php_error,                                   /* error handler */
+/*        php_embed_init(argc, argv, &tsrm_ls);
 
-   sapi_mod_php_header_handler,                /* header handler */
-   sapi_mod_php_send_headers,                  /* send headers handler */
-   NULL,                                        /* send header handler */
+        //PHP_EMBED_START_BLOCK(argc, argv);*/
+        //retval = zend_eval_string(php_code, NULL, "Embedded code" TSRMLS_CC);
+/*        //PHP_EMBED_END_BLOCK(); */
+        php_embed_shutdown(tsrm_ls);
+//        php_request_shutdown(NULL);
 
-   sapi_mod_php_read_post,                     /* read POST data */
-   sapi_mod_php_read_cookies,                  /* read Cookies */
+        return;
 
-   NULL,					/* register server variables */
-   mod_php_log_message,                        /* Log message */
-   NULL,                                        /* Get request time */
 
-   NULL,                                        /* Block interruptions */
-   NULL,                                        /* Unblock interruptions */
 
-   STANDARD_SAPI_MODULE_PROPERTIES
+}
+
+static const switch_application_interface_t php_application_interface = {
+        /*.interface_name */ "php",
+        /*.application_function */ php_function
 };
 
+static switch_loadable_module_interface_t php_module_interface = {
+        /*.module_name */ modname,
+        /*.endpoint_interface */ NULL,
+        /*.timer_interface */ NULL,
+        /*.dialplan_interface */ NULL,
+        /*.codec_interface */ NULL,
+        /*.application_interface */ &php_application_interface,
+        /*.api_interface */ NULL,
+        /*.file_interface */ NULL,
+        /*.speech_interface */ NULL,
+        /*.directory_interface */ NULL
+};
+
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
 {
         /* connect my internal structure to the blank pointer passed to me */
         *module_interface = &php_module_interface;
 
-        sapi_startup(&mod_php_sapi_module);
-        mod_php_sapi_module.startup(&mod_php_sapi_module);
-
-
         //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
 
         /* indicate that the module should continue to be loaded */
         return SWITCH_STATUS_SUCCESS;
 }
+
+/*
+  Called when the system shuts down
+  SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
+  {
+  return SWITCH_STATUS_SUCCESS;
+  }
+*/
+
+/*
+  If it exists, this is called in it's own thread when the module-load completes
+  SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
+  {
+  return SWITCH_STATUS_SUCCESS;
+  }
+*/
+



More information about the Freeswitch-svn mailing list