Re: Defining custom structs in skeleton

From: Date: Fri, 24 Sep 2004 00:31:53 +0000
Subject: Re: Defining custom structs in skeleton
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-1378@lists.php.net to get a copy of this message
> I am currently trying to get a C librabry into a PHP extension but I am > having problems when 'making' the auto-generated extension files. > I think the problem comes from the way I'm trying to use data types. > > It seems like the problem is the special data types definitions in > libssh. For example, I want to import this function: > SSH_SESSION *ssh_connect(SSH_OPTIONS *options); > I've found libssh on freshmeat pointing to 0xbadc0de.com but that doesn't seem to be any site there. Can you tell me where you got libssh from? I'm definately interrested in bringing this into PHP and would be only too happy to lend a hand. > if (session) { > >>> ZEND_FETCH_RESOURCE(???, ???, session, session_id, "???", > ???_rsrc_id); } > This is one of the less transparent aspect of PHP data types to wrap ones head around, but basicly a "Resource" datatype is just an integer which points to a lookup table in the engine that contains the real data. In order to use resources you need to first declare a list entry for it in your MINIT method: static int le_ssh_session; static void php_ssh_session_dtor(SSH_SESSION *data TSRMLS_DC) { /* do "cleanup" stuff which should occur when the session var goes out of scope (e.g. ssh_session_close()) */ } PHP_MINIT_FUNCTION(ssh) { le_ssh_session = zend_register_list_destructors_ex(php_ssh_session_dtor, NULL, "SSH Session", module_number); } Then when you create an SSH Session, you can bind it to a resource variable: PHP_FUNCTION(ssh_session_create) { SSH_SESSION *data; ssh_session_create(&data); ZEND_REGISTER_RESOURCE(return_value, data, le_ssh_session); } And get it back in another function later on: PHP_FUNCTION(ssh_channel_open) { zval *zsession; SSH_SESSION *session; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsession) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(session, SSH_SESSION*, &zsession, -1, "SSH Session", le_ssh_session); /* Do something with session to open a channel... blah blah blah*/ } That said, I *DO* want to drive home function naming. If you're planning on putting this into PECL you'll want to make sure you abide by PHP's naming conventions (the ones that aren't followed all that consistently in the core, but at least we can keep siberia clean). And prefix all your userspace function names with ssh_ (e.g. ssh_connect(), ssh_session_new(), ssh_channel_open(), etc...) -Sara

« previous php.pecl.dev (#1378) next »