[srm-cvs] CVS Update: - Make 2nd parameter to the constructor optional

From: <d.rethans[@]jdimedia.nl>
Date: Fri Apr 26 2002 - 09:10:44 CEST

Date: Fri Apr 26 09:10:43 CEST 2002
User: Derick Rethans
Directory: php_srm

Log Message:
 [1.50]
 - Make 2nd parameter to the constructor optional
 - Clean up the code to connect to SRM
 
Modified files:
           php_srm/srm.c (version: 1.40)

[FILE: /php_srm/srm.c]

--- php_srm/srm.c:1.39 Sun Feb 10 20:20:20 2002 GMT
+++ php_srm/srm.c Fri Apr 26 05:10:42 2002 GMT
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: cvstemp,v 1.39 2002/02/10 21:20:20 sterling Exp $ */
+/* $Id: cvstemp,v 1.40 2002/04/26 07:10:42 derick Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -757,56 +757,60 @@
         efree(connect_data);
 }
 
-/* {{{ proto resource srm_connect (string hostname, int port)
- This function connects to the SRM deamon on hostname:port */
+/* {{{ proto resource srm_connect (string host [, int port])
+ This function connects to the SRM deamon */
 PHP_FUNCTION(srm_connect)
 {
- struct srm_host_t host;
+ struct srm_host_t hostinfo;
+ char *host;
+ srm_ui16 port;
         connect_data_t *connect_data;
- zval **hostname;
- zval **port;
         srm_value *sret_val;
- int argc = ZEND_NUM_ARGS();
         int ret;
 
         /* Start session automatically. */
         php_session_start(TSRMLS_C);
 
- if (argc != 2 || zend_get_parameters_ex(argc, &hostname, &port) == FAILURE) {
- WRONG_PARAM_COUNT;
+ /* Set defaults */
+ hostinfo.host = NULL;
+ hostinfo.port = 7777;
+ hostinfo.family = AF_UNIX;
+
+ /* Parse parameters */
+ if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
+ &host, &port) == FAILURE) {
+ return;
         }
+ hostinfo.host = host;
 
- convert_to_long_ex (port);
- convert_to_string_ex (hostname);
- host.host = Z_STRVAL_PP (hostname);
- host.port = Z_LVAL_PP (port);
-
- /* If the host begins with '/', assume it's a UNIX domain socket */
- if(host.host[0] == '/') {
- host.family = AF_UNIX;
+ /* If the host does not begin with '/', assume it's a TCP/IP socket */
+ if (hostinfo.host[0] != '/') {
+ hostinfo.family = AF_INET;
         } else {
- host.family = AF_INET;
+ hostinfo.port = port;
         }
 
         /* If there is no session started, abort the connect */
         if (PS(id) == NULL) {
                 php_error (E_ERROR,
                         "There is no active session. Use session_start() before "
- "this call to srm_connect.",
- Z_STRVAL_PP(hostname), Z_LVAL_PP(port));
+ "this call to srm_connect.");
                 RETURN_FALSE;
         }
 
- /* Allocte connect_data strucy, and copy the PHP SID if needed */
+ /* Allocte connect_data struct, and copy the PHP SID */
         connect_data = ecalloc (sizeof (connect_data_t), 1);
- /* Copy SID */
         memcpy (connect_data->sess_key, PS(id), 32);
 
- sret_val = srm_connect (host, 0, 0, connect_data);
+ sret_val = srm_connect (hostinfo, 0, 0, connect_data);
 
         if (SRM_IS_ERROR (sret_val)) {
+ if (hostinfo.host[0] == '/') {
+ php_error (E_WARNING, "Couldn't connect to SRM on srm:%s", hostinfo.host);
+ } else {
+ php_error (E_WARNING, "Couldn't connect to SRM on srm://%s:%d", hostinfo.host, hostinfo.port);
+ }
                 efree (connect_data); /* Only free when not registering as resource */
- php_error (E_WARNING, "Couldn't connect to SRM on srm://%s:%d", Z_STRVAL_PP(hostname), Z_LVAL_PP(port));
                 RETURN_FALSE;
         }
 
Received on Fri Apr 26 10:07:09 2002

This archive was generated by hypermail 2.1.8 : Tue Jan 06 2009 - 04:00:03 CET