File: listener.c

package info (click to toggle)
pylibssh2 1.0.0-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 292 kB
  • ctags: 384
  • sloc: ansic: 2,278; python: 573; makefile: 10
file content (173 lines) | stat: -rw-r--r-- 4,980 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*-
 * pylibssh2 - python bindings for libssh2 library
 *
 * Copyright (C) 2005 Keyphrene.com.
 * Copyright (C) 2010 Wallix Inc.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
#include <Python.h>
#define PYLIBSSH2_MODULE
#include "pylibssh2.h"

/* {{{ PYLIBSSH2_Listener_accept
 */
static char PYLIBSSH2_Listener_accept_doc[] = "\n\
\n\
Arguments:\n\
\n\
Returns:\n\
";

static PyObject *
PYLIBSSH2_Listener_accept(PYLIBSSH2_LISTENER *self, PyObject *args)
{
    LIBSSH2_CHANNEL *channel;

    MY_BEGIN_ALLOW_THREADS(self->tstate);
    channel = libssh2_channel_forward_accept(self->listener);
    MY_END_ALLOW_THREADS(self->tstate);

    if (channel == NULL) {
        PyErr_SetString(PYLIBSSH2_Error, "Unable to accept listener on channel.");
        Py_INCREF(Py_None);
        return Py_None;
    }

    return (PyObject *)PYLIBSSH2_Channel_New(channel, 1);
}
/* }}} */

/* {{{ PYLIBSSH2_Listener_cancel
 */
static char PYLIBSSH2_Listener_cancel_doc[] = "\n\
\n\
Arguments:\n\
\n\
Returns:\n\
";

static PyObject *
PYLIBSSH2_Listener_cancel(PYLIBSSH2_LISTENER *self, PyObject *args)
{
    int rc;
    
    MY_BEGIN_ALLOW_THREADS(self->tstate);
    rc = libssh2_channel_forward_cancel(self->listener);
    MY_END_ALLOW_THREADS(self->tstate);

    return Py_BuildValue("i", rc);
}
/* }}} */

/* {{{ PYLIBSSH2_Listener_methods[]
 *
 * ADD_METHOD(name) expands to a correct PyMethodDef declaration
 *  { 'name', (PyCFunction)PYLIBSSH2_Listener_name, METHOD_VARARGS }
 *  for convenience
 */
#define ADD_METHOD(name) \
{ #name, (PyCFunction)PYLIBSSH2_Listener_##name, METH_VARARGS, PYLIBSSH2_Listener_##name##_doc }

struct PyMethodDef PYLIBSSH2_Listener_methods[] = {
    ADD_METHOD(accept),
    ADD_METHOD(cancel),
    { NULL, NULL }
};
#undef ADD_METHOD
/* }}} */

/* {{{ PYLIBSSH2_Listener_New
 */
PYLIBSSH2_LISTENER *
PYLIBSSH2_Listener_New(LIBSSH2_LISTENER *listener, int dealloc)
{
    PYLIBSSH2_LISTENER *self;

    self = PyObject_New(PYLIBSSH2_LISTENER, &PYLIBSSH2_Listener_Type);
    if (self == NULL) {
        return NULL;
    }

    self->listener = listener;
    self->dealloc = dealloc;
    self->tstate = NULL;

    return self;
}
/* }}} */

/* {{{ PYLIBSSH2_Listener_dealloc
 */
static void
PYLIBSSH2_Listener_dealloc(PYLIBSSH2_LISTENER *self)
{
    if (self) {
        PyObject_Del(self);
    }
}
/* }}} */

/* {{{ PYLIBSSH2_Listener_getattr
 */
static PyObject *
PYLIBSSH2_Listener_getattr(PYLIBSSH2_LISTENER *self, char *name)
{
    return Py_FindMethod(PYLIBSSH2_Listener_methods, (PyObject *) self, name);
}
/* }}} */

/* {{{ PYLIBSSH2_Listener_Type
 *
 * see /usr/include/python2.5/object.h line 261
 */
PyTypeObject PYLIBSSH2_Listener_Type = {
    PyObject_HEAD_INIT(NULL)
    0,                                       /* ob_size */
    "Listener",                              /* tp_name */
    sizeof(PYLIBSSH2_LISTENER),              /* tp_basicsize */
    0,                                       /* tp_itemsize */
    (destructor)PYLIBSSH2_Listener_dealloc,  /* tp_dealloc */
    0,                                       /* tp_print */
    (getattrfunc)PYLIBSSH2_Listener_getattr, /* tp_getattr */
    0,                                       /* tp_setattr */
    0,                                       /* tp_compare */
    0,                                       /* tp_repr */
    0,                                       /* tp_as_number */
    0,                                       /* tp_as_sequence */
    0,                                       /* tp_as_mapping */
    0,                                       /* tp_hash  */
    0,                                       /* tp_call */
    0,                                       /* tp_str */
    0,                                       /* tp_getattro */
    0,                                       /* tp_setattro */
    0,                                       /* tp_as_buffer */
    Py_TPFLAGS_DEFAULT,                      /* tp_flags */
    "Listener objects",                      /* tp_doc */
};
/* }}} */

/* {{{ init_libssh2_Listener
 */
int
init_libssh2_Listener(PyObject *dict)
{
    PYLIBSSH2_Listener_Type.ob_type = &PyType_Type;
    Py_XINCREF(&PYLIBSSH2_Listener_Type);
    PyDict_SetItemString(dict, "ListenerType", (PyObject *)&PYLIBSSH2_Listener_Type);

    return 1;
}
/* }}} */