Skip to content

Commit

Permalink
@dstogov Fixed PHP7 port. Restored commented reference counting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-E authored and remicollet committed Jun 28, 2018
1 parent aa7c738 commit 073067b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 126 deletions.
14 changes: 7 additions & 7 deletions php_ssh2.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ typedef struct _php_ssh2_sftp_data {
LIBSSH2_SESSION *session;
LIBSSH2_SFTP *sftp;

int session_rsrcid;
zend_resource *session_rsrc;
} php_ssh2_sftp_data;

typedef struct _php_ssh2_listener_data {
LIBSSH2_SESSION *session;
LIBSSH2_LISTENER *listener;

int session_rsrcid;
zend_resource *session_rsrc;
} php_ssh2_listener_data;

#include "libssh2_publickey.h"
Expand All @@ -89,7 +89,7 @@ typedef struct _php_ssh2_pkey_subsys_data {
LIBSSH2_SESSION *session;
LIBSSH2_PUBLICKEY *pkey;

int session_rsrcid;
zend_resource *session_rsrc;
} php_ssh2_pkey_subsys_data;

#define SSH2_FETCH_NONAUTHENTICATED_SESSION(session, zsession) \
Expand Down Expand Up @@ -118,8 +118,8 @@ typedef struct _php_ssh2_channel_data {
char is_blocking;
long timeout;

/* Resource ID */
int session_rsrcid;
/* Resource */
zend_resource *session_rsrc;

/* Allow one stream to be closed while the other is kept open */
unsigned char *refcount;
Expand Down Expand Up @@ -151,8 +151,8 @@ PHP_FUNCTION(ssh2_sftp_realpath);
LIBSSH2_SESSION *php_ssh2_session_connect(char *host, int port, zval *methods, zval *callbacks);
void php_ssh2_sftp_dtor(zend_resource *rsrc);
php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stream_context *context,
LIBSSH2_SESSION **psession, int *presource_id,
LIBSSH2_SFTP **psftp, int *psftp_rsrcid);
LIBSSH2_SESSION **psession, zend_resource **presource,
LIBSSH2_SFTP **psftp, zend_resource **psftp_rsrc);

extern php_stream_ops php_ssh2_channel_stream_ops;

Expand Down
26 changes: 13 additions & 13 deletions ssh2.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,8 @@ PHP_FUNCTION(ssh2_forward_listen)

data = emalloc(sizeof(php_ssh2_listener_data));
data->session = session;
data->session_rsrcid = Z_LVAL_P(zsession);
//TODO Sean-Der
//zend_list_addref(data->session_rsrcid);
data->session_rsrc = Z_RES_P(zsession);
Z_ADDREF_P(zsession);
data->listener = listener;

RETURN_RES(zend_register_resource(data, le_ssh2_listener));
Expand Down Expand Up @@ -810,7 +809,7 @@ PHP_FUNCTION(ssh2_forward_accept)
channel_data->channel = channel;
channel_data->streamid = 0;
channel_data->is_blocking = 0;
channel_data->session_rsrcid = data->session_rsrcid;
channel_data->session_rsrc = data->session_rsrc;
channel_data->refcount = NULL;

stream = php_stream_alloc(&php_ssh2_channel_stream_ops, channel_data, 0, "r+");
Expand All @@ -820,8 +819,12 @@ PHP_FUNCTION(ssh2_forward_accept)
libssh2_channel_free(channel);
RETURN_FALSE;
}
//TODO Sean-Der
//zend_list_addref(channel_data->session_rsrcid);

#if PHP_VERSION_ID < 70300
GC_REFCOUNT(channel_data->session_rsrc)++;
#else
GC_ADDREF(channel_data->session_rsrc);
#endif

php_stream_to_zval(stream, return_value);
}
Expand Down Expand Up @@ -975,9 +978,8 @@ PHP_FUNCTION(ssh2_publickey_init)

data = emalloc(sizeof(php_ssh2_pkey_subsys_data));
data->session = session;
data->session_rsrcid = Z_RES_P(zsession)->handle;
//TODO Sean-Der
//zend_list_addref(data->session_rsrcid);
data->session_rsrc = Z_RES_P(zsession);
Z_ADDREF_P(zsession);
data->pkey = pkey;

RETURN_RES(zend_register_resource(data, le_ssh2_pkey_subsys));
Expand Down Expand Up @@ -1280,8 +1282,7 @@ static void php_ssh2_listener_dtor(zend_resource *rsrc)
LIBSSH2_LISTENER *listener = data->listener;

libssh2_channel_forward_cancel(listener);
// TODO Sean-Der
//zend_list_delete(data->session_rsrcid);
zend_list_delete(data->session_rsrc);
efree(data);
}

Expand All @@ -1291,8 +1292,7 @@ static void php_ssh2_pkey_subsys_dtor(zend_resource *rsrc)
LIBSSH2_PUBLICKEY *pkey = data->pkey;

libssh2_publickey_shutdown(pkey);
// TODO Sean-Der
//zend_list_delete(data->session_rsrcid);
zend_list_delete(data->session_rsrc);
efree(data);
}

Expand Down
Loading

0 comments on commit 073067b

Please sign in to comment.