Skip to content

Commit aae3d2d

Browse files
author
Pan
committed
Added string and threads definitions. Updated setup.py. Added session implementation.
1 parent 1763b63 commit aae3d2d

File tree

6 files changed

+78
-2
lines changed

6 files changed

+78
-2
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
ON_WINDOWS = platform.system() == 'Windows'
2424

2525
ext = 'pyx' if USING_CYTHON else 'c'
26-
sources = glob('ssh/*.%s' % (ext,))
26+
sources = glob('ssh/session.%s' % (ext,))
2727
_libs = ['ssh'] if not ON_WINDOWS else [
2828
'Ws2_32', 'libssh', 'user32',
2929
'libeay32MD', 'ssleay32MD',

ssh/c_ssh.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from posix.select cimport fd_set
1919
from posix.types cimport mode_t
2020

2121

22-
cdef extern from "libssh/include/libssh.h" nogil:
22+
cdef extern from "libssh/libssh.h" nogil:
2323
ctypedef unsigned char uint8_t
2424
ctypedef unsigned short uint16_t
2525
ctypedef unsigned int uint32_t

ssh/c_string.pxd

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is part of ssh-python.
2+
# Copyright (C) 2018 Panos Kittenis
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation, version 2.1.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
16+
17+
from c_ssh cimport uint32_t
18+
19+
cdef extern from "libssh/include/string.h" nogil:
20+
struct ssh_string_struct:
21+
uint32_t size;
22+
unsigned char data[1]

ssh/c_threads.pxd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is part of ssh-python.
2+
# Copyright (C) 2018 Panos Kittenis
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation, version 2.1.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
16+
17+
cdef extern from "libssh/include/threads.h" nogil:
18+
int ssh_threads_init();
19+
void ssh_threads_finalize();
20+
const char *ssh_threads_get_type();

ssh/session.pyx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file is part of ssh-python.
2+
# Copyright (C) 2018 Panos Kittenis
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation, version 2.1.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130
16+
17+
from libc.stdlib cimport malloc, free
18+
19+
cimport c_ssh
20+
21+
cdef class Session:
22+
cdef c_ssh.ssh_session _session
23+
24+
def __cinit__(self):
25+
self._session = c_ssh.ssh_new()
26+
if self._session is NULL:
27+
raise MemoryError
28+
29+
def __dealloc__(self):
30+
if self._session is not NULL:
31+
c_ssh.ssh_free(self._session)
32+
self._session = NULL

ssh/ssh.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ cimport c_pki_priv
4141
cimport c_scp
4242
cimport c_sftp
4343
cimport c_ssh2
44+
cimport c_string
45+
cimport c_threads

0 commit comments

Comments
 (0)