blob: 5cd23b62664287ba6567621c983b3c3e5704cacc [file] [log] [blame]
Jean-Paul Calderonee0fcf512012-02-13 09:10:15 -05001/*
2 * session.c
3 *
4 * Copyright (C) Jean-Paul Calderone
5 * Copyright (C) Alejandro Alvarez Ayllon
6 * See LICENSE for details.
7 *
8 * SSL Session object data structures and functions.
9 *
10 */
11#include <Python.h>
12#define SSL_MODULE
13#include "ssl.h"
14
15static char ssl_Session_doc[] = "\n\
16Session() -> Session instance\n\
17\n\
18";
19
20/*
21 * Initialize an already-constructed Session instance.
22 */
23static ssl_SessionObj *ssl_Session_init(ssl_SessionObj *self) {
24 /*
25 self->sess = d2i_SSL_SESSION(NULL, &buffer, len);
26
27 if (!self->sess) {
28 exception_from_error_queue(ssl_Error);
29 return NULL;
30 }
31 */
32 return self;
33
34}
35
36
37/*
38 * Create a Session object
39 */
40static PyObject*
41ssl_Session_new(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) {
42 ssl_SessionObj *self;
43
44 if (!PyArg_ParseTuple(args, ":Session")) {
45 return NULL;
46 }
47
48 self = PyObject_New(ssl_SessionObj, &ssl_Session_Type);
49 if (self == NULL) {
50 return NULL;
51 }
52
53 return (PyObject *)ssl_Session_init(self);
54}
55
56/*
57 * Member methods in the Session object
58 * ADD_METHOD(name) expands to a correct PyMethodDef declaration
59 * { 'name', (PyCFunction)ssl_Session_name, METH_VARARGS }
60 * for convenience
61 * ADD_ALIAS(name,real) creates an "alias" of the ssl_Session_real
62 * function with the name 'name'
63 */
64#define ADD_METHOD(name) { #name, (PyCFunction)ssl_Session_##name, METH_VARARGS, ssl_Session_##name##_doc }
65static PyMethodDef ssl_Session_methods[] = {
66#if 0
67 ADD_METHOD(asn1),
68 ADD_METHOD(get_time),
69 ADD_METHOD(get_timeout),
70#ifdef SSL_SESSION_hash
71 ADD_METHOD(hash),
72#endif
73 ADD_METHOD(set_time),
74 ADD_METHOD(set_timeout),
75#endif
76 { NULL, NULL }
77};
78#undef ADD_METHOD
79
80/*
81 * The Python Session type definition.
82 */
83PyTypeObject ssl_Session_Type = {
84 PyOpenSSL_HEAD_INIT(&PyType_Type, 0)
85 "OpenSSL.SSL.Session",
86 sizeof(ssl_SessionObj),
87 0,
88 NULL, // (destructor)ssl_Session_dealloc, /* tp_dealloc */
89 NULL, /* print */
90 NULL, /* tp_getattr */
91 NULL, /* setattr */
92 NULL, /* compare */
93 NULL, /* repr */
94 NULL, /* as_number */
95 NULL, /* as_sequence */
96 NULL, /* as_mapping */
97 NULL, /* hash */
98 NULL, /* call */
99 NULL, /* str */
100 NULL, /* getattro */
101 NULL, /* setattro */
102 NULL, /* as_buffer */
103 Py_TPFLAGS_DEFAULT, // Py_TPFLAGS_HAVE_GC, /* tp_flags */
104 ssl_Session_doc, /* tp_doc */
105 NULL, // (traverseproc)ssl_Session_traverse, /* tp_traverse */
106 NULL, // (inquiry)ssl_Session_clear, /* tp_clear */
107 NULL, /* tp_richcompare */
108 0, /* tp_weaklistoffset */
109 NULL, /* tp_iter */
110 NULL, /* tp_iternext */
111 ssl_Session_methods, /* tp_methods */
112 NULL, /* tp_members */
113 NULL, /* tp_getset */
114 NULL, /* tp_base */
115 NULL, /* tp_dict */
116 NULL, /* tp_descr_get */
117 NULL, /* tp_descr_set */
118 0, /* tp_dictoffset */
119 NULL, /* tp_init */
120 NULL, /* tp_alloc */
121 ssl_Session_new, /* tp_new */
122};
123
124/*
125 * Initialize the Session part of the SSL sub module
126 *
127 * Arguments: dict - The OpenSSL.SSL module
128 * Returns: 1 for success, 0 otherwise
129 */
130int
131init_ssl_session(PyObject *module) {
132
133 if (PyType_Ready(&ssl_Session_Type) < 0) {
134 return 0;
135 }
136
137 /* PyModule_AddObject steals a reference.
138 */
139 Py_INCREF((PyObject *)&ssl_Session_Type);
140 if (PyModule_AddObject(module, "Session", (PyObject *)&ssl_Session_Type) < 0) {
141 return 0;
142 }
143
144 return 1;
145}
146