wez Thu Jan 30 10:42:49 2003 EDT Modified files: /embed/php-irssi channel.c ext-irssi.c genobjdefs.php nick.c php-irssi-obj.c php-irssi.h server.c typemap.php /embed/php-irssi/examples users.php Log: Generate more properties. Remove hand-coded property accessors. Update examples.
Index: embed/php-irssi/channel.c diff -u embed/php-irssi/channel.c:1.1 embed/php-irssi/channel.c:1.2 --- embed/php-irssi/channel.c:1.1 Thu Jan 30 04:04:35 2003 +++ embed/php-irssi/channel.c Thu Jan 30 10:42:47 2003 @@ -14,9 +14,12 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: channel.c,v 1.1 2003/01/30 09:04:35 wez Exp $ + $Id: channel.c,v 1.2 2003/01/30 15:42:47 wez Exp $ */ #include "php-irssi.h" +#define PHP_IRSSI_PROTOS_ONLY +#include "php-irssi-obj-defs.h" + /* ---------- Channel functions */ /* Given a channel record, create a channel object */ @@ -50,28 +53,35 @@ return channel_find(server, ref->idents[IDX_CHANNEL]); } +/* Handle property reads */ -/* Returns an array of nick objects corresponding to each person on this channel */ -PHP_FUNCTION(channel_get_nicks) +int php_irssi_CHANNEL_REC_prop_reader(char *member, int type, zval **retval, void +*obj TSRMLS_DC) { - GSList *list, *tmp; - zval *obj; - CH_FETCH(); - - list = nicklist_getnicks(channel); - array_init(return_value); + PHP_IRSSI_CHANNEL_REC_PROP_READER_HEAD(); - if (list) { - for (tmp = list; tmp != NULL; tmp = tmp->next) { - MAKE_STD_ZVAL(obj); - php_irssi_export_NICK(obj, channel, (NICK_REC*)tmp->data); - add_next_index_zval(return_value, obj); + if (strcmp(member, "nicks") == 0) { + GSList *list, *tmp; + zval *zobj; + + list = nicklist_getnicks(channel); + array_init(*retval); + + 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); } - g_slist_free(list); + return SUCCESS; + } - + + PHP_IRSSI_CHANNEL_REC_PROP_READER_FOOT(); } + PHP_FUNCTION(channel_nick_find) { char *nick; @@ -111,79 +121,6 @@ } else { RETURN_NULL(); } - -} - -PHP_FUNCTION(channel_get_name) -{ - CH_FETCH(); - - RETURN_STRING(channel->name, 1); -} - -PHP_FUNCTION(channel_get_topic) -{ - CH_FETCH(); - - RETURN_STRING(channel->topic, 1); -} - -PHP_FUNCTION(channel_get_topic_by) -{ - CH_FETCH(); - - RETURN_STRING(channel->topic_by, 1); -} - -PHP_FUNCTION(channel_get_modes) -{ - CH_FETCH(); - - array_init(return_value); - - add_assoc_bool(return_value, "no_modes", channel->no_modes); - add_assoc_long(return_value, "limit", channel->limit); - if (channel->mode) - add_assoc_string(return_value, "mode", channel->mode, 1); - else - add_assoc_null(return_value, "mode"); - - if (channel->key) - add_assoc_string(return_value, "key", channel->key, 1); - else - add_assoc_null(return_value, "key"); - -} - -PHP_FUNCTION(channel_get_status) -{ - CH_FETCH(); - - array_init(return_value); - - add_assoc_bool(return_value, "chanop", channel->chanop); - add_assoc_bool(return_value, "names_got", channel->names_got); - add_assoc_bool(return_value, "wholist", channel->wholist); - add_assoc_bool(return_value, "synced", channel->synced); - add_assoc_bool(return_value, "joined", channel->joined); - add_assoc_bool(return_value, "left", channel->left); - add_assoc_bool(return_value, "kicked", channel->kicked); - add_assoc_bool(return_value, "session_rejoin", channel->session_rejoin); - add_assoc_bool(return_value, "destroying", channel->destroying); -} - -PHP_FUNCTION(channel_get_own_nick) -{ - CH_FETCH(); - - php_irssi_export_NICK(return_value, channel, channel->ownnick); -} - -PHP_FUNCTION(channel_get_server) -{ - CH_FETCH(); - - php_irssi_export_SERVER(return_value, channel->server TSRMLS_CC); } PHP_FUNCTION(channel_send) @@ -201,16 +138,8 @@ } function_entry php_irssi_CHANNEL_funcs[] = { - PHP_NAMED_FE(get_nicks, PHP_FN(channel_get_nicks), NULL) PHP_NAMED_FE(nick_find, PHP_FN(channel_nick_find), NULL) PHP_NAMED_FE(nick_find_mask, PHP_FN(channel_nick_find_mask), NULL) - PHP_NAMED_FE(get_name, PHP_FN(channel_get_name), NULL) - PHP_NAMED_FE(get_topic, PHP_FN(channel_get_topic), NULL) - PHP_NAMED_FE(get_topic_by, PHP_FN(channel_get_topic_by), NULL) - PHP_NAMED_FE(get_modes, PHP_FN(channel_get_modes), NULL) - PHP_NAMED_FE(get_status, PHP_FN(channel_get_status), NULL) - PHP_NAMED_FE(get_own_nick, PHP_FN(channel_get_own_nick), NULL) - PHP_NAMED_FE(get_server, PHP_FN(channel_get_server), NULL) PHP_NAMED_FE(send, PHP_FN(channel_send), NULL) NULL, NULL, NULL }; Index: embed/php-irssi/ext-irssi.c diff -u embed/php-irssi/ext-irssi.c:1.2 embed/php-irssi/ext-irssi.c:1.3 --- embed/php-irssi/ext-irssi.c:1.2 Thu Jan 30 04:04:35 2003 +++ embed/php-irssi/ext-irssi.c Thu Jan 30 10:42:47 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: ext-irssi.c,v 1.2 2003/01/30 09:04:35 wez Exp $ + $Id: ext-irssi.c,v 1.3 2003/01/30 15:42:47 wez Exp $ */ #include "php-irssi.h" #include "php-signals-list.h" /* generated by php during make */ @@ -40,14 +40,14 @@ HashTable *bound_signals; -void php_irssi_export_GList(zval *val, GSList *the_list TSRMLS_DC) +void php_irssi_export_GList(zval *val, GSList *the_list, int type TSRMLS_DC) { - zval *str; + zval *tmp; array_init(val); for (; the_list != NULL; the_list = the_list->next) { - MAKE_STD_ZVAL(str); - ZVAL_STRING(val, (char*)the_list->data, 1); + php_irssi_C_to_PHP(&tmp, type, the_list->data); + add_next_index_zval(val, tmp); } } @@ -119,7 +119,7 @@ ZVAL_LONG(val, *(ulong *)args[i]); break; case PIAT_ARRAY_OF_STRING: - php_irssi_export_GList(val, (GSList*)args[i] TSRMLS_CC); + php_irssi_export_GList(val, (GSList*)args[i], +PIAT_STRING TSRMLS_CC); break; default: ZVAL_NULL(val); Index: embed/php-irssi/genobjdefs.php diff -u embed/php-irssi/genobjdefs.php:1.3 embed/php-irssi/genobjdefs.php:1.4 --- embed/php-irssi/genobjdefs.php:1.3 Thu Jan 30 07:12:20 2003 +++ embed/php-irssi/genobjdefs.php Thu Jan 30 10:42:47 2003 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: genobjdefs.php,v 1.3 2003/01/30 12:12:20 wez Exp $ + $Id: genobjdefs.php,v 1.4 2003/01/30 15:42:47 wez Exp $ */ /* We build three sets of tables: @@ -32,11 +32,11 @@ foreach ($objects_to_scan as $filename => $data) { - list($iclass, $pclass) = $data; $obj_props = array(); $obj_methods = array(); + $prop_reader = array(); $source = file_get_contents($top_srcdir . DIRECTORY_SEPARATOR . $filename); @@ -65,25 +65,47 @@ if (strlen($stmt) == 0) continue; - if (match_decl($stmt, $name, $handler)) { + if (match_decl($stmt, $name, $handler, true)) { $obj_props[] = array($handler, $name); } } /* Emit code */ + printf("#ifndef PHP_IRSSI_PROTOS_ONLY\n"); printf("struct php_irssi_class_props php_irssi_%s_props[] = {\n", $iclass); foreach ($obj_props as $data) { list($handler, $name) = $data; - if ($handler == "PIAT_BOOL") + if ($handler == "PIAT_BOOL") { + + $prop_reader[] = "if (strcmp(member, \"$name\") == 0) { +ZVAL_BOOL(*retval, (($iclass*)obj)->$name); return SUCCESS; }"; + continue; + } printf("{ \"%s\", %d, %s, offset_of(%s, %s) },\n", $name, strlen($name), $handler, $iclass, $name); } printf("{ NULL, 0, 0, 0 }\n};\n\n"); + printf("#endif /* PHP_IRSSI_PROTOS_ONLY */\n"); $obj_bind[] = array($iclass, $pclass); + $label = preg_replace('/_.*/', '', $iclass); + + printf("#define PHP_IRSSI_%s_PROP_READER_HEAD() \\\n" . + "\t%s *%s = (%s*)obj;\\\n" . + "\tMAKE_STD_ZVAL(*retval);\\\n" . + "\t%s\n\n", + $iclass, + $iclass, strtolower($label), + $iclass, implode("\\\n\t", $prop_reader)); + printf("#define PHP_IRSSI_%s_PROP_READER_FOOT() \\\n" . + "\tFREE_ZVAL(*retval);\\\n" . + "\treturn FAILURE;\n\n", + $iclass); + + printf("extern int php_irssi_%s_prop_reader(char *member, int type, zval +**retval, void *obj TSRMLS_DC);\n\n", + $iclass); } foreach ($obj_bind as $data) { @@ -92,15 +114,21 @@ printf("void *php_irssi_resolve_to_%s(struct php_irssi_obj_ref *ref);\n", $iclass); printf("extern function_entry php_irssi_%s_funcs[];\n", $label); + + echo "\n"; } +printf("#ifndef PHP_IRSSI_PROTOS_ONLY\n"); printf("\nstatic struct php_irssi_obj_bind php_irssi_object_bindings[] = {\n"); foreach ($obj_bind as $data) { list($iclass, $pclass) = $data; $label = preg_replace('/_.*/', '', $iclass); - printf("{ \"%s\", 0, php_irssi_%s_props, php_irssi_resolve_to_%s, \"%s\", php_irssi_%s_funcs, NULL, NULL },\n", $label, $iclass, $iclass, $pclass, $label); + printf("{ \"%s\", 0, php_irssi_%s_props, php_irssi_resolve_to_%s, \"%s\", +php_irssi_%s_funcs,\n" . + "\tphp_irssi_%s_prop_reader, NULL, NULL },\n", + $label, $iclass, $iclass, $pclass, $label, $iclass); } printf("{ NULL, 0, NULL }\n};\n\n"); + printf("#endif /* PHP_IRSSI_PROTOS_ONLY */\n"); ?> Index: embed/php-irssi/nick.c diff -u embed/php-irssi/nick.c:1.2 embed/php-irssi/nick.c:1.3 --- embed/php-irssi/nick.c:1.2 Thu Jan 30 04:57:18 2003 +++ embed/php-irssi/nick.c Thu Jan 30 10:42:47 2003 @@ -14,9 +14,12 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: nick.c,v 1.2 2003/01/30 09:57:18 wez Exp $ + $Id: nick.c,v 1.3 2003/01/30 15:42:47 wez Exp $ */ #include "php-irssi.h" +#define PHP_IRSSI_PROTOS_ONLY +#include "php-irssi-obj-defs.h" + /* ---------- Nick functions */ void *php_irssi_resolve_to_NICK_REC(struct php_irssi_obj_ref *ref) @@ -54,6 +57,17 @@ return nicklist_find(*channel, ref->idents[IDX_NICK]); } +/* Handle property reads */ + +int php_irssi_NICK_REC_prop_reader(char *member, int type, zval **retval, void *obj +TSRMLS_DC) +{ + PHP_IRSSI_NICK_REC_PROP_READER_HEAD(); + + PHP_IRSSI_NICK_REC_PROP_READER_FOOT(); +} + + + /* Given a nick record, create a PHP nick object */ void php_irssi_export_NICK(zval *obj, CHANNEL_REC *cr, NICK_REC *nr TSRMLS_DC) { @@ -66,59 +80,9 @@ ref->idents[IDX_NICK] = estrdup(nr->nick); } } - -PHP_FUNCTION(nick_get_nick) -{ - NK_FETCH(); - - RETURN_STRING(nick->nick, 1); -} - -PHP_FUNCTION(nick_get_host) -{ - NK_FETCH(); - - RETURN_STRING(nick->host, 1); -} - -PHP_FUNCTION(nick_get_realname) -{ - NK_FETCH(); - - RETURN_STRING(nick->realname, 1); -} - -PHP_FUNCTION(nick_get_server_status) -{ - NK_FETCH(); - - array_init(return_value); - - add_assoc_bool(return_value, "gone", nick->gone); - add_assoc_bool(return_value, "serverop", nick->serverop); - add_assoc_long(return_value, "last_check", nick->last_check); -} - -PHP_FUNCTION(nick_get_channel_status) -{ - NK_FETCH(); - - array_init(return_value); - - add_assoc_bool(return_value, "send_massjoin", nick->send_massjoin); - add_assoc_bool(return_value, "op", nick->op); - add_assoc_bool(return_value, "halfop", nick->halfop); - add_assoc_bool(return_value, "voice", nick->voice); -} - function_entry php_irssi_NICK_funcs[] = { - PHP_NAMED_FE(get_nick, PHP_FN(nick_get_nick), NULL) - PHP_NAMED_FE(get_host, PHP_FN(nick_get_host), NULL) - PHP_NAMED_FE(get_realname, PHP_FN(nick_get_realname), NULL) - PHP_NAMED_FE(get_server_status, PHP_FN(nick_get_server_status), NULL) - PHP_NAMED_FE(get_channel_status, PHP_FN(nick_get_channel_status), NULL) NULL, NULL, NULL }; Index: embed/php-irssi/php-irssi-obj.c diff -u embed/php-irssi/php-irssi-obj.c:1.2 embed/php-irssi/php-irssi-obj.c:1.3 --- embed/php-irssi/php-irssi-obj.c:1.2 Thu Jan 30 07:12:20 2003 +++ embed/php-irssi/php-irssi-obj.c Thu Jan 30 10:42:47 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: php-irssi-obj.c,v 1.2 2003/01/30 12:12:20 wez Exp $ + $Id: php-irssi-obj.c,v 1.3 2003/01/30 15:42:47 wez Exp $ */ #include "php-irssi.h" #include "php-irssi-obj-defs.h" @@ -57,7 +57,7 @@ ZVAL_LONG(val, *(ulong *)arg); break; case PIAT_ARRAY_OF_STRING: - php_irssi_export_GList(val, (GSList*)arg TSRMLS_CC); + php_irssi_export_GList(val, (GSList*)arg, PIAT_STRING +TSRMLS_CC); break; case PIAT_NICK: /* We need some context for a NICK */ @@ -85,14 +85,22 @@ member = &tmp_member; } + /* found the binding; process it */ + arg = ref->binding->resolve(ref); + /* look for property binding */ if (zend_hash_find(ref->binding->hprops, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &props) == FAILURE) { + + /* call custom handler */ + if (SUCCESS == ref->binding->readprop(Z_STRVAL_P(member), type, +&retval, arg TSRMLS_CC)) { + return retval; + } + zend_error(E_NOTICE,"Undefined property: %s", Z_STRVAL_P(member)); + return EG(uninitialized_zval_ptr); } - /* found the binding; process it */ - arg = ref->binding->resolve(ref); php_irssi_C_to_PHP(&retval, (*props)->proptype, arg + (*props)->offset); return retval; Index: embed/php-irssi/php-irssi.h diff -u embed/php-irssi/php-irssi.h:1.2 embed/php-irssi/php-irssi.h:1.3 --- embed/php-irssi/php-irssi.h:1.2 Thu Jan 30 07:12:20 2003 +++ embed/php-irssi/php-irssi.h Thu Jan 30 10:42:47 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: php-irssi.h,v 1.2 2003/01/30 12:12:20 wez Exp $ + $Id: php-irssi.h,v 1.3 2003/01/30 15:42:47 wez Exp $ */ #define MODULE_NAME "php/core" @@ -75,6 +75,9 @@ void *(*resolve)(struct php_irssi_obj_ref *ref); const char *classname; /* name of PHP class */ function_entry *functable; + + int (*readprop)(char *member, int type, zval **retval, void *obj TSRMLS_DC); + /* --- runtime --- */ HashTable *hprops; /* hashed version of proptable */ HashTable *hfuncs; /* hashed version of functable */ Index: embed/php-irssi/server.c diff -u embed/php-irssi/server.c:1.1 embed/php-irssi/server.c:1.2 --- embed/php-irssi/server.c:1.1 Thu Jan 30 04:04:35 2003 +++ embed/php-irssi/server.c Thu Jan 30 10:42:47 2003 @@ -14,10 +14,13 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: server.c,v 1.1 2003/01/30 09:04:35 wez Exp $ + $Id: server.c,v 1.2 2003/01/30 15:42:47 wez Exp $ */ #include "php-irssi.h" +#define PHP_IRSSI_PROTOS_ONLY +#include "php-irssi-obj-defs.h" + /* ---------- Server functions */ /* Given a server record, create a server object */ @@ -42,6 +45,28 @@ return NULL; } +/* Handle property reads */ + +int php_irssi_SERVER_REC_prop_reader(char *member, int type, zval **retval, void *obj +TSRMLS_DC) +{ + 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); + } + return SUCCESS; + } + + PHP_IRSSI_SERVER_REC_PROP_READER_FOOT(); +} + PHP_FUNCTION(server_privmsg) { @@ -109,27 +134,11 @@ } -PHP_FUNCTION(server_get_channel_list) -{ - GSList *tmp; - zval *obj; - SV_FETCH(); - - array_init(return_value); - for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { - MAKE_STD_ZVAL(obj); - php_irssi_export_CHANNEL(obj, (CHANNEL_REC*)tmp->data); - add_next_index_zval(return_value, obj); - } - -} - function_entry php_irssi_SERVER_funcs[] = { PHP_NAMED_FE(privmsg, PHP_FN(server_privmsg), NULL) PHP_NAMED_FE(send_cmd, PHP_FN(server_send_cmd), NULL) PHP_NAMED_FE(send_cmd_now, PHP_FN(server_send_cmd_now), NULL) PHP_NAMED_FE(channels_join, PHP_FN(server_channels_join), NULL) - PHP_NAMED_FE(get_channels, PHP_FN(server_get_channel_list), NULL) NULL, NULL, NULL }; Index: embed/php-irssi/typemap.php diff -u embed/php-irssi/typemap.php:1.2 embed/php-irssi/typemap.php:1.3 --- embed/php-irssi/typemap.php:1.2 Thu Jan 30 07:12:20 2003 +++ embed/php-irssi/typemap.php Thu Jan 30 10:42:47 2003 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: typemap.php,v 1.2 2003/01/30 12:12:20 wez Exp $ + $Id: typemap.php,v 1.3 2003/01/30 15:42:47 wez Exp $ */ /* This array describes the functions that can be used to convert between @@ -34,6 +34,9 @@ "unsigned int" => array("PIAT_INT", false), "ulong" => array("PIAT_ULONG", false), "GList * of char*" => array("PIAT_ARRAY_OF_STRING", false), + + /* aliases */ + "STRUCT_SERVER_REC" => array("PIAT_SERVER", true), ); /* fixup the marshal array to include supported objects */ Index: embed/php-irssi/examples/users.php diff -u embed/php-irssi/examples/users.php:1.1 embed/php-irssi/examples/users.php:1.2 --- embed/php-irssi/examples/users.php:1.1 Thu Jan 30 08:58:22 2003 +++ embed/php-irssi/examples/users.php Thu Jan 30 10:42:48 2003 @@ -6,10 +6,10 @@ foreach ($servers as $server) { echo $server->tag.':'; - $channels = $server->get_channels(); + $channels = $server->channels; foreach ($channels as $channel) { echo ' '.$channel->name.':'; - $nicks = $channel->get_nicks(); + $nicks = $channel->nicks; foreach ($nicks as $nick) { echo ' '.$nick->nick; }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php