cvs: embed /php-irssi TODO php-core.c

[email protected] ("Tal Peer") Sat, 01 Mar 2003 18:26:35 -0000
Newsgroups php.embed.cvs
Message-ID <cvstal1046543194@cvsserver>
tal		Sat Mar  1 13:26:35 2003 EDT

  Modified files:              
    /embed/php-irssi	php-core.c TODO 
  Log:
  - Implemented /php set
  - Introduced php_set_ini_entry for easily setting ini entries
  - Made CLIENTCRAP messages more consistent
  - Cleaned up the code a bit
  
  
Index: embed/php-irssi/php-core.c
diff -u embed/php-irssi/php-core.c:1.9 embed/php-irssi/php-core.c:1.10
--- embed/php-irssi/php-core.c:1.9	Sun Feb  2 16:05:26 2003
+++ embed/php-irssi/php-core.c	Sat Mar  1 13:23:46 2003
@@ -14,7 +14,7 @@
   +----------------------------------------------------------------------+
   | Author: Wez Furlong <[email protected]>                                    |
   +----------------------------------------------------------------------+
-  $Id: php-core.c,v 1.9 2003/02/02 21:05:26 wez Exp $
+  $Id: php-core.c,v 1.10 2003/03/01 18:23:46 tal Exp $
 */
 #define MODULE_NAME "php/core"
 #include "common.h"
@@ -104,6 +104,20 @@
 
 }
 
+static int php_set_ini_entry(char *entry, char *value)
+{
+	int retval;
+
+	retval = zend_alter_ini_entry(entry, strlen(entry)+1, value, strlen(value)+1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
+	if (retval == SUCCESS) {
+		printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: INI entry %s successfully set to %s", entry, value);
+	} else {
+		printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: failed setting INI entry %s to %s", entry, value);
+	}
+
+	return retval;
+}
+
 static void init_php(void)
 {
 	int retval;
@@ -146,31 +160,36 @@
 /* Handler for "/php exec" command */
 static void cmd_php_exec(const char *data)
 {
-	active_win = active_win;
-
 	switch (php_eval_string("php/irssi:exec", "%s", data)) {
 		case EVAL_RET_OK:
 			break;
 		case EVAL_RET_ERROR:
-			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php command failed");
+			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: exec failed");
 			break;
 		case EVAL_RET_BAIL:
 		default:
-			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php command bailed out status=%d", EG(exit_status));
+			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: bailed out status=%d", EG(exit_status));
 	}
 }
 
 /* Handler for "/php set" command */
 static void cmd_php_set(const char *data)
-{
-	/* FIXME */
+{	
+	char *val;
+	char *entry;
+	
+	entry = estrdup(data);
+	entry = strtok(entry, " ");
+	val   = strtok(NULL, " ");
+
+	php_set_ini_entry(entry, val);
+	
+	efree(entry);
 }
 
 /* Handler for "/php help" command */
 static void cmd_php_help(const char *data)
-{
-	active_win = active_win;
-	
+{	
 	printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "PHP Module:");
 	printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "/php exec <string_to_evaluate>");
 	printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "/php load <file>");
@@ -180,9 +199,7 @@
 
 /* Handler for "/php version" command */
 static void cmd_php_version(const char *data)
-{
-	active_win = active_win;
-	
+{	
 	printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "PHP Module For Irssi v%s", PHP_IRSSI_VERSION);
 	printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "PHP v%s", PHP_VERSION);
 }
@@ -190,23 +207,21 @@
 /* Handler for "/php load" command */
 static void cmd_php_load(const char *data)
 {
-	active_win = active_win;
-
 	switch (php_eval_string("php/irssi:load", "include('%s');", data)) {
 		case EVAL_RET_OK:
 			break;
 		case EVAL_RET_ERROR:
-			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php failed loading %s", data);
+			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: failed loading %s", data);
 		case EVAL_RET_BAIL:
 		default:
-			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php bailed out status=%d", EG(exit_status));
+			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: bailed out status=%d", EG(exit_status));
 	}
 }
 
 /* default "php error" signal handler */
 static void error_handler(char *message)
 {
-	printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php error: %s", message);
+	printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: error: %s", message);
 }
 
 /* default "php output" signal handler */
@@ -218,20 +233,18 @@
 /* autorun any .php scripts found in the users scripts/autorun dir */
 static void do_autorun(void)
 {
-	active_win = active_win;
-
 	switch (php_eval_string("php/irssi:autoload",
 				"foreach(glob('%s/scripts/autorun/*.php') as $_autorun_name) { include $_autorun_name; }",
 				get_irssi_dir())) {
 		case EVAL_RET_OK:
-			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php autoload completed");
+			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: autoload completed");
 			break;
 		case EVAL_RET_ERROR:
-			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php autoload failed");
+			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: autoload failed");
 			break;
 		case EVAL_RET_BAIL:
 		default:
-			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php autoload bailed out status=%d", EG(exit_status));
+			printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: autoload bailed out status=%d", EG(exit_status));
 	}
 }
 
@@ -247,6 +260,8 @@
 /* Module init: called by irssi when the user types "/load php" */
 void php_core_init(void)
 {
+	char *include_path = NULL;
+	
 	init_php();
 
 	signal_php_output = signal_get_uniq_id("php output");
@@ -261,7 +276,11 @@
 	command_bind("php version", NULL, (SIGNAL_FUNC)cmd_php_version);
 	command_bind("php set", NULL, (SIGNAL_FUNC)cmd_php_set);
 	
-	php_eval_string("php/irssi:init", "set_include_path('%s/scripts:%s');", get_irssi_dir(), SCRIPTDIR);
+	/* XXX: We need to make that changeable... */
+	sprintf(include_path, "%s/scripts:%s", get_irssi_dir(), SCRIPTDIR);
+	printtext_window(active_win, MSGLEVEL_CLIENTCRAP, "-!- php: setting include_path to %s", include_path);
+	
+	php_set_ini_entry("include_path", include_path);
 	
 	if (irssi_init_finished) {
 		/* if the module is being loaded manually execute autorun directly */
Index: embed/php-irssi/TODO
diff -u embed/php-irssi/TODO:1.5 embed/php-irssi/TODO:1.6
--- embed/php-irssi/TODO:1.5	Thu Feb  6 12:38:02 2003
+++ embed/php-irssi/TODO	Sat Mar  1 13:23:48 2003
@@ -1,6 +1,6 @@
 TODO:
 ====================================
-$Id: TODO,v 1.5 2003/02/06 17:38:02 tal Exp $
+$Id: TODO,v 1.6 2003/03/01 18:23:48 tal Exp $
 
 o Improve genobjdefs.php so that it can find a structure definition in a
 header file with more junk (when compared with the *-rec.h headers).
@@ -46,8 +46,6 @@
 o Expose even more stuff!
 
 o Add multiple arguments support for /php load
-
-o Implement /php set ;)
 
 o Line buffer PHP output before triggering the output or error signals, so
 that the output doesn't look like crapola.