cvs: embed /php-irssi Makefile.am channel.c ext-irssi.c genobjdefs.php php-irssi-obj.c php-irssi.h server.c typemap.php window.c
| From: | Wez Furlong | Date: | Sun, 02 Feb 2003 03:27:16 +0000 |
| Subject: | cvs: embed /php-irssi Makefile.am channel.c ext-irssi.c genobjdefs.php php-irssi-obj.c php-irssi.h server.c typemap.php window.c | ||
| Groups: | php.embed.cvs | ||
| Request: | Send a blank email to php-embed-cvs+get-15@lists.php.net to get a copy of this message | ||
wez Sat Feb 1 22:27:16 2003 EDT
Added files:
/embed/php-irssi window.c
Modified files:
/embed/php-irssi Makefile.am channel.c ext-irssi.c genobjdefs.php
php-irssi-obj.c php-irssi.h server.c typemap.php
Log:
Expose the window object.
Refactor some code a little, some a lot.
Index: embed/php-irssi/Makefile.am diff -u embed/php-irssi/Makefile.am:1.4 embed/php-irssi/Makefile.am:1.5 --- embed/php-irssi/Makefile.am:1.4 Sat Feb 1 20:33:45 2003 +++ embed/php-irssi/Makefile.am Sat Feb 1 22:27:16 2003 @@ -18,7 +18,7 @@ $(LIBPHP_CFLAGS) libphp_core_la_SOURCES = \ - php-core.c ext-irssi.c php-irssi-obj.c server.c channel.c nick.c win-item.c + php-core.c ext-irssi.c php-irssi-obj.c server.c channel.c nick.c win-item.c window.c $(libphp_core_la_SOURCES): php-signals-list.h php-irssi-obj-defs.h Index: embed/php-irssi/channel.c diff -u embed/php-irssi/channel.c:1.2 embed/php-irssi/channel.c:1.3 --- embed/php-irssi/channel.c:1.2 Thu Jan 30 10:42:47 2003 +++ embed/php-irssi/channel.c Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: channel.c,v 1.2 2003/01/30 15:42:47 wez Exp $ + $Id: channel.c,v 1.3 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" #define PHP_IRSSI_PROTOS_ONLY @@ -60,22 +60,13 @@ PHP_IRSSI_CHANNEL_REC_PROP_READER_HEAD(); if (strcmp(member, "nicks") == 0) { - GSList *list, *tmp; - zval *zobj; + GSList *list; list = nicklist_getnicks(channel); - array_init(*retval); + php_irssi_export_GList(*retval, list, PIAT_NICK); + g_slist_free(list); - if (list) { - for (tmp = list; tmp != NULL; tmp = tmp->next) { - MAKE_STD_ZVAL(zobj); - php_irssi_export_NICK(zobj, channel, (NICK_REC*)tmp->data); - add_next_index_zval(*retval, zobj); - } - g_slist_free(list); - } return SUCCESS; - } PHP_IRSSI_CHANNEL_REC_PROP_READER_FOOT(); Index: embed/php-irssi/ext-irssi.c diff -u embed/php-irssi/ext-irssi.c:1.8 embed/php-irssi/ext-irssi.c:1.9 --- embed/php-irssi/ext-irssi.c:1.8 Sat Feb 1 20:33:45 2003 +++ embed/php-irssi/ext-irssi.c Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: ext-irssi.c,v 1.8 2003/02/02 01:33:45 wez Exp $ + $Id: ext-irssi.c,v 1.9 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" #include "php-signals-list.h" /* generated by php during make */ @@ -165,20 +165,11 @@ func_name = rec->handler; for (i = 0; i < sigargs->argc; i++) { - int type = sigargs->argtypes[i]; + /* TODO: would be nice to replace this with php_irssi_C_to_PHP(), + * but we need to make some assumptions and optimizations here + * for the NICK records */ MAKE_STD_ZVAL(val); - - /* runtime "inheritance" check */ - if (type == PIAT_WI_ITEM) { - if (IS_SERVER((void*)args[i])) { - type = PIAT_SERVER; - } else if (IS_CHANNEL((void*)args[i])) { - type = PIAT_CHANNEL; - } else if (IS_NICK((void*)args[i])) { - type = PIAT_NICK; - } - } switch(sigargs->argtypes[i]) { case PIAT_STRING: @@ -199,6 +190,12 @@ break; case PIAT_ULONG: ZVAL_LONG(val, *(ulong *)args[i]); + break; + case PIAT_WI_ITEM: + php_irssi_export_WI_ITEM(val, (WI_ITEM_REC*)args[i] TSRMLS_CC); + break; + case PIAT_WINDOW: + php_irssi_export_WINDOW(val, (WINDOW_REC*)args[i] TSRMLS_CC); break; case PIAT_ARRAY_OF_STRING: php_irssi_export_GList(val, (GSList*)args[i], PIAT_STRING TSRMLS_CC); Index: embed/php-irssi/genobjdefs.php diff -u embed/php-irssi/genobjdefs.php:1.5 embed/php-irssi/genobjdefs.php:1.6 --- embed/php-irssi/genobjdefs.php:1.5 Sat Feb 1 20:33:46 2003 +++ embed/php-irssi/genobjdefs.php Sat Feb 1 22:27:16 2003 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: genobjdefs.php,v 1.5 2003/02/02 01:33:46 wez Exp $ + $Id: genobjdefs.php,v 1.6 2003/02/02 03:27:16 wez Exp $ */ /* We build three sets of tables: @@ -30,9 +30,33 @@ $obj_bind = array(); include "typemap.php"; +/* TYPE FOO, BAR -> array( "TYPE FOO", "TYPE BAR" ) */ +function crack_comma_sep_decl($stmt) +{ + $comma = strpos($stmt, ','); + + if ($comma === false) + return array($stmt); + + /* find the first space before the comma */ + $base = substr($stmt, 0, $comma); + + $space = strrpos($base, ' '); + + $type = substr($stmt, 0, $space + 1); + $names = explode(",", substr($stmt, $space + 1)); + + $stmts = array(); + foreach ($names as $name) { + $stmts[] = $type . $name; + } + + return $stmts; +} + foreach ($objects_to_scan as $filename => $data) { - list($iclass, $pclass) = $data; + list($iclass, $pclass, $piat, $srcmatch) = $data; $obj_bind[] = $data; $obj_props = array(); @@ -41,6 +65,11 @@ $source = file_get_contents($top_srcdir . DIRECTORY_SEPARATOR . $filename); + if ($srcmatch) { + preg_match($srcmatch, $source, $matches); + $source = $matches[1]; + } + $rel = dirname($top_srcdir . DIRECTORY_SEPARATOR . $filename); /* chase includes */ @@ -62,12 +91,22 @@ $stmts = explode(";", $source); foreach ($stmts as $stmt) { - $stmt = trim(preg_replace('/\s+/', ' ', $stmt)); - if (strlen($stmt) == 0) - continue; - if (match_decl($stmt, $name, $handler, true)) { - $obj_props[] = array($handler, $name); + $multiple_stmts = crack_comma_sep_decl($stmt); + foreach ($multiple_stmts as $stmt) { + $stmt = trim(preg_replace('/\s+/', ' ', $stmt)); + if (strlen($stmt) == 0) + continue; + + if (match_decl($stmt, $name, $handler, true)) { + $obj_props[] = array($handler, $name); + } else { + /* special hacks */ + if ($stmt == "void *window") { + $obj_props[] = array("PIAT_WINDOW", "window"); + } + + } } } Index: embed/php-irssi/php-irssi-obj.c diff -u embed/php-irssi/php-irssi-obj.c:1.4 embed/php-irssi/php-irssi-obj.c:1.5 --- embed/php-irssi/php-irssi-obj.c:1.4 Sat Feb 1 20:33:46 2003 +++ embed/php-irssi/php-irssi-obj.c Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: php-irssi-obj.c,v 1.4 2003/02/02 01:33:46 wez Exp $ + $Id: php-irssi-obj.c,v 1.5 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" #include "php-irssi-obj-defs.h" @@ -59,6 +59,12 @@ case PIAT_ARRAY_OF_STRING: php_irssi_export_GList(val, (GSList*)arg, PIAT_STRING TSRMLS_CC); break; + case PIAT_WI_ITEM: + php_irssi_export_WI_ITEM(val, (WI_ITEM_REC*)arg TSRMLS_CC); + break; + case PIAT_WINDOW: + php_irssi_export_WINDOW(val, (WINDOW_REC*)arg TSRMLS_CC); + break; case PIAT_NICK: /* We need some context for a NICK */ default: @@ -167,6 +173,8 @@ { struct php_irssi_obj_ref *ref = zend_object_store_get_object(object TSRMLS_CC); + /* FIXME: doesn't seem quite right */ + if (parent) { *class_name = "irssi"; *class_name_len = 5; Index: embed/php-irssi/php-irssi.h diff -u embed/php-irssi/php-irssi.h:1.5 embed/php-irssi/php-irssi.h:1.6 --- embed/php-irssi/php-irssi.h:1.5 Sat Feb 1 20:33:46 2003 +++ embed/php-irssi/php-irssi.h Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: php-irssi.h,v 1.5 2003/02/02 01:33:46 wez Exp $ + $Id: php-irssi.h,v 1.6 2003/02/02 03:27:16 wez Exp $ */ #define MODULE_NAME "php/core" @@ -49,6 +49,7 @@ PIAT_ARRAY_OF_STRING, PIAT_BOOL, PIAT_WI_ITEM, + PIAT_WINDOW, }; struct php_irssi_signal_args { @@ -70,6 +71,7 @@ #endif struct php_irssi_obj_ref; +void php_irssi_export_GList(zval *val, GSList *the_list, int type TSRMLS_DC); #define PHP_IRSSI_INH_WI_ITEM 1 @@ -103,6 +105,9 @@ struct php_irssi_obj_bind *binding; char *idents[PHP_IRSSI_MAX_IDENTS]; int actual_type; /* PIAT_XXX; used mostly for WI_ITEM */ + /* ONLY use this when you are sure that you have hooked into + * irssi so that you KNOW when the pointer becomes stale */ + void *actual_ptr; }; #include "php-irssi-obj.h" @@ -119,4 +124,5 @@ #define NK_FETCH() CHANNEL_REC *channel; NICK_REC *nick = map_nick(getThis(), &channel TSRMLS_CC); if (channel == NULL || nick == NULL) RETURN_NULL(); #define WI_FETCH() WI_ITEM_REC *wi; map_wi_item(getThis() TSRMLS_CC); if (wi == NULL) RETURN_NULL(); +#define WINDOW_FETCH() WINDOW_REC *window; map_window(getThis() TSRMLS_CC); if (window == NULL) RETURN_NULL(); Index: embed/php-irssi/server.c diff -u embed/php-irssi/server.c:1.2 embed/php-irssi/server.c:1.3 --- embed/php-irssi/server.c:1.2 Thu Jan 30 10:42:47 2003 +++ embed/php-irssi/server.c Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: server.c,v 1.2 2003/01/30 15:42:47 wez Exp $ + $Id: server.c,v 1.3 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" @@ -52,15 +52,7 @@ PHP_IRSSI_SERVER_REC_PROP_READER_HEAD(); if (strcmp(member, "channels") == 0) { - GSList *tmp; - zval *zobj; - - array_init(*retval); - for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { - MAKE_STD_ZVAL(zobj); - php_irssi_export_CHANNEL(zobj, (CHANNEL_REC*)tmp->data); - add_next_index_zval(*retval, zobj); - } + php_irssi_export_GList(*retval, server->channels, PIAT_CHANNEL); return SUCCESS; } Index: embed/php-irssi/typemap.php diff -u embed/php-irssi/typemap.php:1.4 embed/php-irssi/typemap.php:1.5 --- embed/php-irssi/typemap.php:1.4 Sat Feb 1 20:33:46 2003 +++ embed/php-irssi/typemap.php Sat Feb 1 22:27:16 2003 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: typemap.php,v 1.4 2003/02/02 01:33:46 wez Exp $ + $Id: typemap.php,v 1.5 2003/02/02 03:27:16 wez Exp $ */ /* This array describes the functions that can be used to convert between @@ -26,6 +26,8 @@ "src/core/channel-rec.h" => array("CHANNEL_REC", "channel", array("PHP_IRSSI_INH_WI_ITEM")), "src/core/nick-rec.h" => array("NICK_REC", "nick"), "src/core/window-item-rec.h" => array("WI_ITEM_REC", "windowitem"), + "src/fe-common/core/fe-windows.h" => array("WINDOW_REC", "window", null, "/struct _WINDOW_REC {([^}]+)}/sm"), + ); $marshal = array( Index: embed/php-irssi/window.c +++ embed/php-irssi/window.c /* +----------------------------------------------------------------------+ | PHP for IRSSI | +----------------------------------------------------------------------+ | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ $Id: window.c,v 1.1 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" #define PHP_IRSSI_PROTOS_ONLY #include "php-irssi-obj-defs.h" /* ---------- Server functions */ void php_irssi_export_WINDOW(zval *obj, WINDOW_REC *window TSRMLS_DC) { struct php_irssi_obj_ref *ref; php_irssi_create_wrapper(&ref, "WINDOW", obj TSRMLS_CC); if (ref) { ref->actual_ptr = window; } } void *php_irssi_resolve_to_WINDOW_REC(struct php_irssi_obj_ref *ref) { return ref->actual_ptr; } WINDOW_REC *map_window(zval *object TSRMLS_DC) { struct php_irssi_obj_ref *ref; ref = php_irssi_ref_from_wrapper(object, "WINDOW" TSRMLS_CC); if (ref) return ref->actual_ptr; return NULL; } /* Handle property reads */ int php_irssi_WINDOW_REC_prop_reader(char *member, int type, zval **retval, void *obj TSRMLS_DC) { PHP_IRSSI_WINDOW_REC_PROP_READER_HEAD(); if (strcmp("items", member) == 0) { php_irssi_export_GList(*retval, window->items, PIAT_WI_ITEM); return SUCCESS; } PHP_IRSSI_WINDOW_REC_PROP_READER_FOOT(); } /* activate and switch to a specific window */ PHP_FUNCTION(window_set_active) { WINDOW_FETCH(); if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } window_set_active(window); } /* gets name of active item in the window, or if no items are active, * returns the name of the window itself */ PHP_FUNCTION(window_get_active_name) { WINDOW_FETCH(); if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } RETVAL_STRING(window_get_active_name(window), 1); } function_entry php_irssi_WINDOW_funcs[] = { PHP_NAMED_FE(set_active, PHP_FN(window_set_active), NULL) PHP_NAMED_FE(get_active_name, PHP_FN(window_get_active_name), NULL) NULL, NULL, NULL }; /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */
Index: embed/php-irssi/Makefile.am diff -u embed/php-irssi/Makefile.am:1.4 embed/php-irssi/Makefile.am:1.5 --- embed/php-irssi/Makefile.am:1.4 Sat Feb 1 20:33:45 2003 +++ embed/php-irssi/Makefile.am Sat Feb 1 22:27:16 2003 @@ -18,7 +18,7 @@ $(LIBPHP_CFLAGS) libphp_core_la_SOURCES = \ - php-core.c ext-irssi.c php-irssi-obj.c server.c channel.c nick.c win-item.c + php-core.c ext-irssi.c php-irssi-obj.c server.c channel.c nick.c win-item.c window.c $(libphp_core_la_SOURCES): php-signals-list.h php-irssi-obj-defs.h Index: embed/php-irssi/channel.c diff -u embed/php-irssi/channel.c:1.2 embed/php-irssi/channel.c:1.3 --- embed/php-irssi/channel.c:1.2 Thu Jan 30 10:42:47 2003 +++ embed/php-irssi/channel.c Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: channel.c,v 1.2 2003/01/30 15:42:47 wez Exp $ + $Id: channel.c,v 1.3 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" #define PHP_IRSSI_PROTOS_ONLY @@ -60,22 +60,13 @@ PHP_IRSSI_CHANNEL_REC_PROP_READER_HEAD(); if (strcmp(member, "nicks") == 0) { - GSList *list, *tmp; - zval *zobj; + GSList *list; list = nicklist_getnicks(channel); - array_init(*retval); + php_irssi_export_GList(*retval, list, PIAT_NICK); + g_slist_free(list); - if (list) { - for (tmp = list; tmp != NULL; tmp = tmp->next) { - MAKE_STD_ZVAL(zobj); - php_irssi_export_NICK(zobj, channel, (NICK_REC*)tmp->data); - add_next_index_zval(*retval, zobj); - } - g_slist_free(list); - } return SUCCESS; - } PHP_IRSSI_CHANNEL_REC_PROP_READER_FOOT(); Index: embed/php-irssi/ext-irssi.c diff -u embed/php-irssi/ext-irssi.c:1.8 embed/php-irssi/ext-irssi.c:1.9 --- embed/php-irssi/ext-irssi.c:1.8 Sat Feb 1 20:33:45 2003 +++ embed/php-irssi/ext-irssi.c Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: ext-irssi.c,v 1.8 2003/02/02 01:33:45 wez Exp $ + $Id: ext-irssi.c,v 1.9 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" #include "php-signals-list.h" /* generated by php during make */ @@ -165,20 +165,11 @@ func_name = rec->handler; for (i = 0; i < sigargs->argc; i++) { - int type = sigargs->argtypes[i]; + /* TODO: would be nice to replace this with php_irssi_C_to_PHP(), + * but we need to make some assumptions and optimizations here + * for the NICK records */ MAKE_STD_ZVAL(val); - - /* runtime "inheritance" check */ - if (type == PIAT_WI_ITEM) { - if (IS_SERVER((void*)args[i])) { - type = PIAT_SERVER; - } else if (IS_CHANNEL((void*)args[i])) { - type = PIAT_CHANNEL; - } else if (IS_NICK((void*)args[i])) { - type = PIAT_NICK; - } - } switch(sigargs->argtypes[i]) { case PIAT_STRING: @@ -199,6 +190,12 @@ break; case PIAT_ULONG: ZVAL_LONG(val, *(ulong *)args[i]); + break; + case PIAT_WI_ITEM: + php_irssi_export_WI_ITEM(val, (WI_ITEM_REC*)args[i] TSRMLS_CC); + break; + case PIAT_WINDOW: + php_irssi_export_WINDOW(val, (WINDOW_REC*)args[i] TSRMLS_CC); break; case PIAT_ARRAY_OF_STRING: php_irssi_export_GList(val, (GSList*)args[i], PIAT_STRING TSRMLS_CC); Index: embed/php-irssi/genobjdefs.php diff -u embed/php-irssi/genobjdefs.php:1.5 embed/php-irssi/genobjdefs.php:1.6 --- embed/php-irssi/genobjdefs.php:1.5 Sat Feb 1 20:33:46 2003 +++ embed/php-irssi/genobjdefs.php Sat Feb 1 22:27:16 2003 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: genobjdefs.php,v 1.5 2003/02/02 01:33:46 wez Exp $ + $Id: genobjdefs.php,v 1.6 2003/02/02 03:27:16 wez Exp $ */ /* We build three sets of tables: @@ -30,9 +30,33 @@ $obj_bind = array(); include "typemap.php"; +/* TYPE FOO, BAR -> array( "TYPE FOO", "TYPE BAR" ) */ +function crack_comma_sep_decl($stmt) +{ + $comma = strpos($stmt, ','); + + if ($comma === false) + return array($stmt); + + /* find the first space before the comma */ + $base = substr($stmt, 0, $comma); + + $space = strrpos($base, ' '); + + $type = substr($stmt, 0, $space + 1); + $names = explode(",", substr($stmt, $space + 1)); + + $stmts = array(); + foreach ($names as $name) { + $stmts[] = $type . $name; + } + + return $stmts; +} + foreach ($objects_to_scan as $filename => $data) { - list($iclass, $pclass) = $data; + list($iclass, $pclass, $piat, $srcmatch) = $data; $obj_bind[] = $data; $obj_props = array(); @@ -41,6 +65,11 @@ $source = file_get_contents($top_srcdir . DIRECTORY_SEPARATOR . $filename); + if ($srcmatch) { + preg_match($srcmatch, $source, $matches); + $source = $matches[1]; + } + $rel = dirname($top_srcdir . DIRECTORY_SEPARATOR . $filename); /* chase includes */ @@ -62,12 +91,22 @@ $stmts = explode(";", $source); foreach ($stmts as $stmt) { - $stmt = trim(preg_replace('/\s+/', ' ', $stmt)); - if (strlen($stmt) == 0) - continue; - if (match_decl($stmt, $name, $handler, true)) { - $obj_props[] = array($handler, $name); + $multiple_stmts = crack_comma_sep_decl($stmt); + foreach ($multiple_stmts as $stmt) { + $stmt = trim(preg_replace('/\s+/', ' ', $stmt)); + if (strlen($stmt) == 0) + continue; + + if (match_decl($stmt, $name, $handler, true)) { + $obj_props[] = array($handler, $name); + } else { + /* special hacks */ + if ($stmt == "void *window") { + $obj_props[] = array("PIAT_WINDOW", "window"); + } + + } } } Index: embed/php-irssi/php-irssi-obj.c diff -u embed/php-irssi/php-irssi-obj.c:1.4 embed/php-irssi/php-irssi-obj.c:1.5 --- embed/php-irssi/php-irssi-obj.c:1.4 Sat Feb 1 20:33:46 2003 +++ embed/php-irssi/php-irssi-obj.c Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: php-irssi-obj.c,v 1.4 2003/02/02 01:33:46 wez Exp $ + $Id: php-irssi-obj.c,v 1.5 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" #include "php-irssi-obj-defs.h" @@ -59,6 +59,12 @@ case PIAT_ARRAY_OF_STRING: php_irssi_export_GList(val, (GSList*)arg, PIAT_STRING TSRMLS_CC); break; + case PIAT_WI_ITEM: + php_irssi_export_WI_ITEM(val, (WI_ITEM_REC*)arg TSRMLS_CC); + break; + case PIAT_WINDOW: + php_irssi_export_WINDOW(val, (WINDOW_REC*)arg TSRMLS_CC); + break; case PIAT_NICK: /* We need some context for a NICK */ default: @@ -167,6 +173,8 @@ { struct php_irssi_obj_ref *ref = zend_object_store_get_object(object TSRMLS_CC); + /* FIXME: doesn't seem quite right */ + if (parent) { *class_name = "irssi"; *class_name_len = 5; Index: embed/php-irssi/php-irssi.h diff -u embed/php-irssi/php-irssi.h:1.5 embed/php-irssi/php-irssi.h:1.6 --- embed/php-irssi/php-irssi.h:1.5 Sat Feb 1 20:33:46 2003 +++ embed/php-irssi/php-irssi.h Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: php-irssi.h,v 1.5 2003/02/02 01:33:46 wez Exp $ + $Id: php-irssi.h,v 1.6 2003/02/02 03:27:16 wez Exp $ */ #define MODULE_NAME "php/core" @@ -49,6 +49,7 @@ PIAT_ARRAY_OF_STRING, PIAT_BOOL, PIAT_WI_ITEM, + PIAT_WINDOW, }; struct php_irssi_signal_args { @@ -70,6 +71,7 @@ #endif struct php_irssi_obj_ref; +void php_irssi_export_GList(zval *val, GSList *the_list, int type TSRMLS_DC); #define PHP_IRSSI_INH_WI_ITEM 1 @@ -103,6 +105,9 @@ struct php_irssi_obj_bind *binding; char *idents[PHP_IRSSI_MAX_IDENTS]; int actual_type; /* PIAT_XXX; used mostly for WI_ITEM */ + /* ONLY use this when you are sure that you have hooked into + * irssi so that you KNOW when the pointer becomes stale */ + void *actual_ptr; }; #include "php-irssi-obj.h" @@ -119,4 +124,5 @@ #define NK_FETCH() CHANNEL_REC *channel; NICK_REC *nick = map_nick(getThis(), &channel TSRMLS_CC); if (channel == NULL || nick == NULL) RETURN_NULL(); #define WI_FETCH() WI_ITEM_REC *wi; map_wi_item(getThis() TSRMLS_CC); if (wi == NULL) RETURN_NULL(); +#define WINDOW_FETCH() WINDOW_REC *window; map_window(getThis() TSRMLS_CC); if (window == NULL) RETURN_NULL(); Index: embed/php-irssi/server.c diff -u embed/php-irssi/server.c:1.2 embed/php-irssi/server.c:1.3 --- embed/php-irssi/server.c:1.2 Thu Jan 30 10:42:47 2003 +++ embed/php-irssi/server.c Sat Feb 1 22:27:16 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: server.c,v 1.2 2003/01/30 15:42:47 wez Exp $ + $Id: server.c,v 1.3 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" @@ -52,15 +52,7 @@ PHP_IRSSI_SERVER_REC_PROP_READER_HEAD(); if (strcmp(member, "channels") == 0) { - GSList *tmp; - zval *zobj; - - array_init(*retval); - for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { - MAKE_STD_ZVAL(zobj); - php_irssi_export_CHANNEL(zobj, (CHANNEL_REC*)tmp->data); - add_next_index_zval(*retval, zobj); - } + php_irssi_export_GList(*retval, server->channels, PIAT_CHANNEL); return SUCCESS; } Index: embed/php-irssi/typemap.php diff -u embed/php-irssi/typemap.php:1.4 embed/php-irssi/typemap.php:1.5 --- embed/php-irssi/typemap.php:1.4 Sat Feb 1 20:33:46 2003 +++ embed/php-irssi/typemap.php Sat Feb 1 22:27:16 2003 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ - $Id: typemap.php,v 1.4 2003/02/02 01:33:46 wez Exp $ + $Id: typemap.php,v 1.5 2003/02/02 03:27:16 wez Exp $ */ /* This array describes the functions that can be used to convert between @@ -26,6 +26,8 @@ "src/core/channel-rec.h" => array("CHANNEL_REC", "channel", array("PHP_IRSSI_INH_WI_ITEM")), "src/core/nick-rec.h" => array("NICK_REC", "nick"), "src/core/window-item-rec.h" => array("WI_ITEM_REC", "windowitem"), + "src/fe-common/core/fe-windows.h" => array("WINDOW_REC", "window", null, "/struct _WINDOW_REC {([^}]+)}/sm"), + ); $marshal = array( Index: embed/php-irssi/window.c +++ embed/php-irssi/window.c /* +----------------------------------------------------------------------+ | PHP for IRSSI | +----------------------------------------------------------------------+ | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Wez Furlong <wez@php.net> | +----------------------------------------------------------------------+ $Id: window.c,v 1.1 2003/02/02 03:27:16 wez Exp $ */ #include "php-irssi.h" #define PHP_IRSSI_PROTOS_ONLY #include "php-irssi-obj-defs.h" /* ---------- Server functions */ void php_irssi_export_WINDOW(zval *obj, WINDOW_REC *window TSRMLS_DC) { struct php_irssi_obj_ref *ref; php_irssi_create_wrapper(&ref, "WINDOW", obj TSRMLS_CC); if (ref) { ref->actual_ptr = window; } } void *php_irssi_resolve_to_WINDOW_REC(struct php_irssi_obj_ref *ref) { return ref->actual_ptr; } WINDOW_REC *map_window(zval *object TSRMLS_DC) { struct php_irssi_obj_ref *ref; ref = php_irssi_ref_from_wrapper(object, "WINDOW" TSRMLS_CC); if (ref) return ref->actual_ptr; return NULL; } /* Handle property reads */ int php_irssi_WINDOW_REC_prop_reader(char *member, int type, zval **retval, void *obj TSRMLS_DC) { PHP_IRSSI_WINDOW_REC_PROP_READER_HEAD(); if (strcmp("items", member) == 0) { php_irssi_export_GList(*retval, window->items, PIAT_WI_ITEM); return SUCCESS; } PHP_IRSSI_WINDOW_REC_PROP_READER_FOOT(); } /* activate and switch to a specific window */ PHP_FUNCTION(window_set_active) { WINDOW_FETCH(); if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } window_set_active(window); } /* gets name of active item in the window, or if no items are active, * returns the name of the window itself */ PHP_FUNCTION(window_get_active_name) { WINDOW_FETCH(); if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } RETVAL_STRING(window_get_active_name(window), 1); } function_entry php_irssi_WINDOW_funcs[] = { PHP_NAMED_FE(set_active, PHP_FN(window_set_active), NULL) PHP_NAMED_FE(get_active_name, PHP_FN(window_get_active_name), NULL) NULL, NULL, NULL }; /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */