|
@@ -0,0 +1,512 @@
|
|
1
|
+#include "python_ioin.h"
|
|
2
|
+/**@file python_ioin.c
|
|
3
|
+ * @ingroup lib_ioin
|
|
4
|
+ */
|
|
5
|
+
|
|
6
|
+/**@brief If given object in_stream is NULL set error indicator
|
|
7
|
+ * @return 0 if no error else -1 or -2
|
|
8
|
+ */
|
|
9
|
+static int _check_nullin(PyObject *self);
|
|
10
|
+
|
|
11
|
+/**@brief Request a new buffer size.
|
|
12
|
+ *
|
|
13
|
+ * @param PyObject* self The IoIn instance
|
|
14
|
+ * @param int nreq number of bytes required in buffer
|
|
15
|
+ * @return 0 on error else buffer size
|
|
16
|
+ */
|
|
17
|
+static int pyfcgi_ioin__reqbuf(PyObject *self, int nreq);
|
|
18
|
+
|
|
19
|
+/**@brief Concat two bytes/unicode given IoIn configuration flag
|
|
20
|
+ */
|
|
21
|
+static PyObject* IoIn__Concat(PyObject *self, PyObject *left, PyObject *right);
|
|
22
|
+
|
|
23
|
+PyMethodDef IoIn_methods[] = {
|
|
24
|
+ {"close", (PyCFunction)pyfcgi_ioin_close, METH_FASTCALL, NULL},
|
|
25
|
+ {"fileno", (PyCFunction)pyfcgi_ioin_fileno, METH_FASTCALL, NULL},
|
|
26
|
+ {"flush", (PyCFunction)pyfcgi_ioin_flush, METH_FASTCALL, NULL},
|
|
27
|
+ {"isatty", (PyCFunction)pyfcgi_ioin_isatty, METH_FASTCALL, NULL},
|
|
28
|
+ {"readable", (PyCFunction)pyfcgi_ioin_readable, METH_FASTCALL, NULL},
|
|
29
|
+ {"readline", (PyCFunction)pyfcgi_ioin_readline, METH_FASTCALL, NULL},
|
|
30
|
+ {"readlines", (PyCFunction)pyfcgi_ioin_readlines, METH_FASTCALL, NULL},
|
|
31
|
+ {"seek", (PyCFunction)pyfcgi_ioin_seek, METH_FASTCALL, NULL},
|
|
32
|
+ {"seekable", (PyCFunction)pyfcgi_ioin_seekable, METH_FASTCALL, NULL},
|
|
33
|
+ {"tell", (PyCFunction)pyfcgi_ioin_tell, METH_FASTCALL, NULL},
|
|
34
|
+ {"truncate", (PyCFunction)pyfcgi_ioin_truncate, METH_FASTCALL, NULL},
|
|
35
|
+ {"writable", (PyCFunction)pyfcgi_ioin_writable, METH_FASTCALL, NULL},
|
|
36
|
+ {"writelines", (PyCFunction)pyfcgi_ioin_writelines, METH_FASTCALL, NULL},
|
|
37
|
+ {"read", (PyCFunction)pyfcgi_ioin_read, METH_FASTCALL, NULL},
|
|
38
|
+ {"readall", (PyCFunction)pyfcgi_ioin_readall, METH_FASTCALL, NULL},
|
|
39
|
+ {"readinto", (PyCFunction)pyfcgi_ioin_readinto, METH_FASTCALL, NULL},
|
|
40
|
+ {"write", (PyCFunction)pyfcgi_ioin_write, METH_FASTCALL, NULL},
|
|
41
|
+ {NULL} //Sentinel
|
|
42
|
+};
|
|
43
|
+
|
|
44
|
+PyMemberDef IoIn_members[] = {
|
|
45
|
+ {"closed", T_OBJECT, offsetof(IoIn, closed), READONLY, "True if the stream is closed"},
|
|
46
|
+ {NULL}
|
|
47
|
+};
|
|
48
|
+
|
|
49
|
+PyTypeObject IoInType = {
|
|
50
|
+ PyVarObject_HEAD_INIT(NULL, 0)
|
|
51
|
+ "libpyfcgi.IoIn", /* tp_name */
|
|
52
|
+ sizeof(IoIn), /* tp_basicsize */
|
|
53
|
+ 0, /* tp_itemsize */
|
|
54
|
+ (destructor)pyfcgi_ioin_del, /* tp_dealloc */
|
|
55
|
+ 0, /* tp_print */
|
|
56
|
+ 0, /* tp_getattr */
|
|
57
|
+ 0, /* tp_setattr */
|
|
58
|
+ 0, /* tp_reserved */
|
|
59
|
+ 0, /* tp_repr */
|
|
60
|
+ 0, /* tp_as_number */
|
|
61
|
+ 0, /* tp_as_sequence */
|
|
62
|
+ 0, /* tp_as_mapping */
|
|
63
|
+ 0, /* tp_hash */
|
|
64
|
+ 0, /* tp_call */
|
|
65
|
+ 0, /* tp_str */
|
|
66
|
+ 0, /* tp_getattro */
|
|
67
|
+ 0, /* tp_setattro */
|
|
68
|
+ 0, /* tp_as_buffer */
|
|
69
|
+ Py_TPFLAGS_DEFAULT |
|
|
70
|
+ Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
71
|
+ "RawIo interface to FCGI input stream", /* tp_doc */
|
|
72
|
+ 0, /* tp_traverse */
|
|
73
|
+ 0, /* tp_clear */
|
|
74
|
+ 0, /* tp_richcompare */
|
|
75
|
+ 0, /* tp_weaklistoffset */
|
|
76
|
+ 0, /* tp_iter */
|
|
77
|
+ 0, /* tp_iternext */
|
|
78
|
+ IoIn_methods, /* tp_methods */
|
|
79
|
+ IoIn_members, /* tp_members */
|
|
80
|
+ 0, /* tp_getset */
|
|
81
|
+ 0, /* tp_base */
|
|
82
|
+ 0, /* tp_dict */
|
|
83
|
+ 0, /* tp_descr_get */
|
|
84
|
+ 0, /* tp_descr_set */
|
|
85
|
+ 0, /* tp_dictoffset */
|
|
86
|
+ pyfcgi_ioin_init, /* tp_init */
|
|
87
|
+ 0, /* tp_alloc */
|
|
88
|
+ 0, /* tp_new */
|
|
89
|
+};
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+int pyfcgi_ioin_init(PyObject *self, PyObject *args, PyObject *kwds)
|
|
93
|
+{
|
|
94
|
+ IoIn *ioin = (void*)self;
|
|
95
|
+ ioin->in_stream = NULL;
|
|
96
|
+ ioin->buff = NULL;
|
|
97
|
+ ioin->buff_sz = 0;
|
|
98
|
+ ioin->eof=0;
|
|
99
|
+ ioin->bin=1;
|
|
100
|
+ return 0;
|
|
101
|
+}
|
|
102
|
+
|
|
103
|
+void pyfcgi_ioin_del(IoIn *self)
|
|
104
|
+{
|
|
105
|
+ IoIn *ioin = self;
|
|
106
|
+ if(ioin->buff) { free(ioin->buff); }
|
|
107
|
+ Py_TYPE(self)->tp_free((PyObject*)self);
|
|
108
|
+}
|
|
109
|
+
|
|
110
|
+PyObject* pyfcgi_ioin_close(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
111
|
+{
|
|
112
|
+ if(_check_nullin(self)) { Py_RETURN_NONE; }
|
|
113
|
+ if(argc)
|
|
114
|
+ {
|
|
115
|
+ PyErr_Format(PyExc_ValueError,
|
|
116
|
+ "libpyfcgi.IoIn.close() not expecting any argument but %zd given",
|
|
117
|
+ argc);
|
|
118
|
+ Py_RETURN_NONE;
|
|
119
|
+ }
|
|
120
|
+ if(FCGX_FClose(*((IoIn*)self)->in_stream) < 0)
|
|
121
|
+ {
|
|
122
|
+ PyErr_Format(PyExc_OSError,
|
|
123
|
+ "%A unable to close", self);
|
|
124
|
+ }
|
|
125
|
+ ((IoIn*)self)->closed = Py_True;
|
|
126
|
+ Py_RETURN_NONE;
|
|
127
|
+}
|
|
128
|
+
|
|
129
|
+PyObject* pyfcgi_ioin_fileno(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
130
|
+{
|
|
131
|
+ PyErr_SetString(PyExc_OSError, "libpyfcgi.IoIn has no fileno");
|
|
132
|
+ Py_RETURN_NONE;
|
|
133
|
+}
|
|
134
|
+
|
|
135
|
+PyObject* pyfcgi_ioin_flush(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
136
|
+{
|
|
137
|
+ if(_check_nullin(self)) { Py_RETURN_NONE; }
|
|
138
|
+ if(argc)
|
|
139
|
+ {
|
|
140
|
+ PyErr_Format(PyExc_ValueError,
|
|
141
|
+ "libpyfcgi.IoIn.close() not expecting any argument but %zd given",
|
|
142
|
+ argc);
|
|
143
|
+ Py_RETURN_NONE;
|
|
144
|
+ }
|
|
145
|
+ if(FCGX_FFlush(*((IoIn*)self)->in_stream) < 0)
|
|
146
|
+ {
|
|
147
|
+ PyErr_Format(PyExc_OSError,
|
|
148
|
+ "%A unable to flush", self);
|
|
149
|
+ }
|
|
150
|
+ Py_RETURN_NONE;
|
|
151
|
+}
|
|
152
|
+
|
|
153
|
+PyObject* pyfcgi_ioin_isatty(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
154
|
+{
|
|
155
|
+ return Py_False;
|
|
156
|
+}
|
|
157
|
+
|
|
158
|
+PyObject* pyfcgi_ioin_readable(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
159
|
+{
|
|
160
|
+ return Py_True;
|
|
161
|
+}
|
|
162
|
+
|
|
163
|
+PyObject* pyfcgi_ioin_readline(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
164
|
+{
|
|
165
|
+ int read_n;
|
|
166
|
+ long arg;
|
|
167
|
+ char *ret;
|
|
168
|
+
|
|
169
|
+ if(_check_nullin(self)) { Py_RETURN_NONE; }
|
|
170
|
+ if(argc > 1)
|
|
171
|
+ {
|
|
172
|
+ PyErr_Format(PyExc_ValueError,
|
|
173
|
+ "libpyfcgi.IoIn.close() expecting 0 or 1 argument but %zd given",
|
|
174
|
+ argc);
|
|
175
|
+ Py_RETURN_NONE;
|
|
176
|
+ }
|
|
177
|
+ if(!argc || !argv[0])
|
|
178
|
+ {
|
|
179
|
+ read_n = pyfcgi_ioin__reqbuf(self, 0);
|
|
180
|
+ }
|
|
181
|
+ else
|
|
182
|
+ {
|
|
183
|
+ arg = PyLong_AsLong(argv[0]);
|
|
184
|
+ if(PyErr_Occurred())
|
|
185
|
+ {
|
|
186
|
+ Py_RETURN_NONE;
|
|
187
|
+ }
|
|
188
|
+ read_n = pyfcgi_ioin__reqbuf(self, (arg>INT_MAX)?INT_MAX:arg);
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+ ret = ((IoIn*)self)->buff;
|
|
192
|
+ if(!FCGX_GetLine(ret, read_n, *((IoIn*)self)->in_stream))
|
|
193
|
+ {
|
|
194
|
+ ((IoIn*)self)->eof = 1;
|
|
195
|
+ ret = "";
|
|
196
|
+ }
|
|
197
|
+ return IoIn__FromString(self, ret);
|
|
198
|
+}
|
|
199
|
+
|
|
200
|
+PyObject* pyfcgi_ioin_readlines(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
201
|
+{
|
|
202
|
+ size_t hint, left;
|
|
203
|
+ int read_n, toread;
|
|
204
|
+ size_t sz;
|
|
205
|
+ PyObject *res, *cur_str, *read_str, *tmp;
|
|
206
|
+ char *buff;
|
|
207
|
+
|
|
208
|
+ if(_check_nullin(self)) { Py_RETURN_NONE; }
|
|
209
|
+ if(argc > 1)
|
|
210
|
+ {
|
|
211
|
+ PyErr_Format(PyExc_ValueError,
|
|
212
|
+ "libpyfcgi.IoIn.close() expecting 0 or 1 argument but %zd given",
|
|
213
|
+ argc);
|
|
214
|
+ Py_RETURN_NONE;
|
|
215
|
+ }
|
|
216
|
+ if(!argc || !argv[0])
|
|
217
|
+ {
|
|
218
|
+ hint = 0;
|
|
219
|
+ left = 0;
|
|
220
|
+ }
|
|
221
|
+ else
|
|
222
|
+ {
|
|
223
|
+ hint = PyLong_AsSize_t(argv[0]);
|
|
224
|
+ if(PyErr_Occurred())
|
|
225
|
+ {
|
|
226
|
+ Py_RETURN_NONE;
|
|
227
|
+ }
|
|
228
|
+ left = hint;
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ res = PyList_New(0);
|
|
232
|
+ if(!res)
|
|
233
|
+ {
|
|
234
|
+ Py_RETURN_NONE;
|
|
235
|
+ }
|
|
236
|
+ Py_INCREF(res);
|
|
237
|
+
|
|
238
|
+ read_n = pyfcgi_ioin__reqbuf(self, 0);
|
|
239
|
+ buff = ((IoIn*)self)->buff;
|
|
240
|
+ cur_str = NULL;
|
|
241
|
+
|
|
242
|
+ while((hint && left) || !hint)
|
|
243
|
+ {
|
|
244
|
+ toread = (hint&&((size_t)read_n > left))?(int)left:read_n;
|
|
245
|
+ if(!FCGX_GetLine(buff, toread,
|
|
246
|
+ *((IoIn*)self)->in_stream))
|
|
247
|
+ {
|
|
248
|
+ ((IoIn*)self)->eof = 1;
|
|
249
|
+ break;
|
|
250
|
+ }
|
|
251
|
+ sz = strlen(buff);
|
|
252
|
+ left -= sz;
|
|
253
|
+ read_str = IoIn__FromBuff(self);
|
|
254
|
+ if(!read_str)
|
|
255
|
+ {
|
|
256
|
+ Py_RETURN_NONE;
|
|
257
|
+ }
|
|
258
|
+ Py_INCREF(read_str);
|
|
259
|
+ if(cur_str)
|
|
260
|
+ {
|
|
261
|
+ tmp = IoIn__Concat(self, cur_str, read_str);
|
|
262
|
+ Py_INCREF(tmp);
|
|
263
|
+ cur_str = tmp;
|
|
264
|
+ }
|
|
265
|
+ else
|
|
266
|
+ {
|
|
267
|
+ cur_str = read_str;
|
|
268
|
+ }
|
|
269
|
+
|
|
270
|
+ if(buff[sz-1] == '\n')
|
|
271
|
+ {
|
|
272
|
+ if(PyList_Append(res, cur_str))
|
|
273
|
+ {
|
|
274
|
+ Py_DECREF(cur_str);
|
|
275
|
+ Py_RETURN_NONE;
|
|
276
|
+ }
|
|
277
|
+ Py_DECREF(cur_str);
|
|
278
|
+ cur_str = NULL;
|
|
279
|
+ }
|
|
280
|
+ }
|
|
281
|
+ if(cur_str)
|
|
282
|
+ {
|
|
283
|
+ if(PyList_Append(res, cur_str))
|
|
284
|
+ {
|
|
285
|
+ Py_DECREF(cur_str);
|
|
286
|
+ Py_RETURN_NONE;
|
|
287
|
+ }
|
|
288
|
+ Py_DECREF(cur_str);
|
|
289
|
+ }
|
|
290
|
+ Py_DECREF(res);
|
|
291
|
+ return res;
|
|
292
|
+}
|
|
293
|
+
|
|
294
|
+PyObject* pyfcgi_ioin_read(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
295
|
+{
|
|
296
|
+ size_t left, sz, max;
|
|
297
|
+ long l;
|
|
298
|
+ int read_n, toread;
|
|
299
|
+ PyObject *res, *read_str;
|
|
300
|
+ char *buff;
|
|
301
|
+
|
|
302
|
+ if(_check_nullin(self)) { Py_RETURN_NONE; }
|
|
303
|
+ if(argc > 1)
|
|
304
|
+ {
|
|
305
|
+ PyErr_Format(PyExc_ValueError,
|
|
306
|
+ "libpyfcgi.IoIn.read() expecting at most 1 argument but %zd given",
|
|
307
|
+ argc);
|
|
308
|
+ Py_RETURN_NONE;
|
|
309
|
+ }
|
|
310
|
+
|
|
311
|
+ if(((IoIn*)self)->eof)
|
|
312
|
+ {
|
|
313
|
+ return IoIn__FromString(self, "");
|
|
314
|
+ }
|
|
315
|
+ max = 0;
|
|
316
|
+ if(argc)
|
|
317
|
+ {
|
|
318
|
+ l = PyLong_AsLong(argv[0]);
|
|
319
|
+ if(PyErr_Occurred() || l > 0)
|
|
320
|
+ {
|
|
321
|
+ PyErr_Clear();
|
|
322
|
+ max = PyLong_AsSize_t(argv[0]);
|
|
323
|
+ if(PyErr_Occurred())
|
|
324
|
+ {
|
|
325
|
+ Py_RETURN_NONE;
|
|
326
|
+ }
|
|
327
|
+ }
|
|
328
|
+ }
|
|
329
|
+ left = max;
|
|
330
|
+ read_n = pyfcgi_ioin__reqbuf(self, 0);
|
|
331
|
+ buff = ((IoIn*)self)->buff;
|
|
332
|
+ if(!(res = IoIn__FromString(self, "")))
|
|
333
|
+ {
|
|
334
|
+ Py_RETURN_NONE;
|
|
335
|
+ }
|
|
336
|
+ while((max && left) || !max)
|
|
337
|
+ {
|
|
338
|
+ toread = (max&&((size_t)read_n > left))?(int)left:read_n;
|
|
339
|
+ if(FCGX_GetStr(buff, toread, *((IoIn*)self)->in_stream) < toread)
|
|
340
|
+ {
|
|
341
|
+ ((IoIn*)self)->eof = 1;
|
|
342
|
+ break;
|
|
343
|
+ }
|
|
344
|
+ sz = strlen(buff);
|
|
345
|
+ left -= sz;
|
|
346
|
+ if(!(read_str = IoIn__FromBuff(self)))
|
|
347
|
+ {
|
|
348
|
+ Py_RETURN_NONE;
|
|
349
|
+ }
|
|
350
|
+ Py_INCREF(read_str);
|
|
351
|
+ if(!(res = IoIn__Concat(self, res, read_str)))
|
|
352
|
+ {
|
|
353
|
+ Py_RETURN_NONE;
|
|
354
|
+ }
|
|
355
|
+ Py_INCREF(res);
|
|
356
|
+ }
|
|
357
|
+ Py_DECREF(res);
|
|
358
|
+ return res;
|
|
359
|
+}
|
|
360
|
+
|
|
361
|
+PyObject* pyfcgi_ioin_readall(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
362
|
+{
|
|
363
|
+ if(_check_nullin(self)) { Py_RETURN_NONE; }
|
|
364
|
+ if(argc)
|
|
365
|
+ {
|
|
366
|
+ PyErr_Format(PyExc_ValueError,
|
|
367
|
+ "libpyfcgi.IoIn.readall() not expecting any argument but %zd given",
|
|
368
|
+ argc);
|
|
369
|
+ Py_RETURN_NONE;
|
|
370
|
+ }
|
|
371
|
+ return pyfcgi_ioin_read(self, NULL, 0);
|
|
372
|
+}
|
|
373
|
+
|
|
374
|
+PyObject* pyfcgi_ioin_readinto(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
375
|
+{
|
|
376
|
+ PyObject *b;
|
|
377
|
+ Py_ssize_t max, left, read_n;
|
|
378
|
+ char *buff, *buff_ptr;
|
|
379
|
+ int toread, ret;
|
|
380
|
+
|
|
381
|
+ if(_check_nullin(self)) { Py_RETURN_NONE; }
|
|
382
|
+ if(argc != 1)
|
|
383
|
+ {
|
|
384
|
+ PyErr_Format(PyExc_ValueError,
|
|
385
|
+ "libpyfcgi.IoIn.readinto() expecting 1 argument but %zd given",
|
|
386
|
+ argc);
|
|
387
|
+ Py_RETURN_NONE;
|
|
388
|
+ }
|
|
389
|
+ b = argv[0];
|
|
390
|
+ if(!PyByteArray_Check(b))
|
|
391
|
+ {
|
|
392
|
+ PyErr_Format(PyExc_ValueError,
|
|
393
|
+ "libpyfcgi.IoIn.readinto() expected bytearray as argument but %A given",
|
|
394
|
+ b);
|
|
395
|
+ Py_RETURN_NONE;
|
|
396
|
+ }
|
|
397
|
+ left = max = PyByteArray_Size(b);
|
|
398
|
+ buff = PyByteArray_AsString(b);
|
|
399
|
+ buff_ptr = buff;
|
|
400
|
+ read_n = pyfcgi_ioin__reqbuf(self, 0);
|
|
401
|
+ while(left)
|
|
402
|
+ {
|
|
403
|
+ toread = left>read_n?read_n:left;
|
|
404
|
+ if((ret = FCGX_GetStr(buff_ptr, toread,
|
|
405
|
+ *((IoIn*)self)->in_stream)) < toread)
|
|
406
|
+ {
|
|
407
|
+ ((IoIn*)self)->eof = 1;
|
|
408
|
+ break;
|
|
409
|
+ }
|
|
410
|
+ buff_ptr += ret;
|
|
411
|
+ left -= ret;
|
|
412
|
+
|
|
413
|
+ }
|
|
414
|
+ return b;
|
|
415
|
+}
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+PyObject* pyfcgi_ioin_truncate(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
419
|
+{
|
|
420
|
+ PyErr_SetString(PyExc_OSError, "libpyfcgi.IoIn cannot be truncated");
|
|
421
|
+ Py_RETURN_NONE;
|
|
422
|
+}
|
|
423
|
+
|
|
424
|
+PyObject* pyfcgi_ioin_SeekError(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
425
|
+{
|
|
426
|
+ PyErr_SetString(PyExc_OSError, "libpyfcgi.IoIn is not seekable");
|
|
427
|
+ Py_RETURN_NONE;
|
|
428
|
+}
|
|
429
|
+
|
|
430
|
+PyObject* pyfcgi_ioin_WriteError(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
431
|
+{
|
|
432
|
+ PyErr_SetString(PyExc_OSError, "libpyfcgi.IoIn is not writable");
|
|
433
|
+ Py_RETURN_NONE;
|
|
434
|
+}
|
|
435
|
+
|
|
436
|
+PyObject* pyfcgi_ioin_seekable(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
437
|
+{
|
|
438
|
+ return Py_False;
|
|
439
|
+}
|
|
440
|
+
|
|
441
|
+PyObject* pyfcgi_ioin_writable(PyObject *self, PyObject **argv, Py_ssize_t argc)
|
|
442
|
+{
|
|
443
|
+ return Py_False;
|
|
444
|
+}
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+static int _check_nullin(PyObject *self)
|
|
448
|
+{
|
|
449
|
+ if(!((IoIn*)self)->in_stream)
|
|
450
|
+ {
|
|
451
|
+ PyErr_SetString(PyExc_RuntimeError,
|
|
452
|
+ "pyfcgi.IoIn called in wrong context : FGCI input not set");
|
|
453
|
+ return -1;
|
|
454
|
+ }
|
|
455
|
+ else if(!(*(((IoIn*)self)->in_stream)))
|
|
456
|
+ {
|
|
457
|
+ PyErr_SetString(PyExc_RuntimeError,
|
|
458
|
+ "pyfcgi.IoIn called in wrong context : FGCI input is NULL");
|
|
459
|
+ return -2;
|
|
460
|
+ }
|
|
461
|
+ return 0;
|
|
462
|
+}
|
|
463
|
+
|
|
464
|
+static int pyfcgi_ioin__reqbuf(PyObject *self, int nreq)
|
|
465
|
+{
|
|
466
|
+ IoIn *ioin;
|
|
467
|
+ void *tmp;
|
|
468
|
+ int err;
|
|
469
|
+
|
|
470
|
+ ioin = (IoIn*)self;
|
|
471
|
+
|
|
472
|
+ if(ioin->buff_sz > nreq && ioin->buff)
|
|
473
|
+ {
|
|
474
|
+ return ioin->buff_sz;
|
|
475
|
+ }
|
|
476
|
+
|
|
477
|
+ ioin->buff_sz = ((nreq>>12)+1)<<12;
|
|
478
|
+ if(ioin->buff_sz < nreq) { ioin->buff_sz = nreq; }
|
|
479
|
+
|
|
480
|
+ if(!(tmp = realloc(ioin->buff, ioin->buff_sz)))
|
|
481
|
+ {
|
|
482
|
+ err = errno;
|
|
483
|
+ PyErr_Format(PyExc_OSError,
|
|
484
|
+ "%A error reallocating internal buffer : %s",
|
|
485
|
+ self, strerror(err));
|
|
486
|
+ errno = err;
|
|
487
|
+ return 0;
|
|
488
|
+ }
|
|
489
|
+ ioin->buff = tmp;
|
|
490
|
+ return ioin->buff_sz;
|
|
491
|
+}
|
|
492
|
+
|
|
493
|
+/**@brief Concat two bytes/unicode given IoIn configuration flag
|
|
494
|
+ * @warn Py_DECREF both arguments
|
|
495
|
+ */
|
|
496
|
+static PyObject* IoIn__Concat(PyObject *self, PyObject *left, PyObject *right)
|
|
497
|
+{
|
|
498
|
+ if(((IoIn*)self)->bin)
|
|
499
|
+ {
|
|
500
|
+ PyBytes_Concat(&left, right);
|
|
501
|
+ Py_DECREF(right);
|
|
502
|
+ return left;
|
|
503
|
+ }
|
|
504
|
+ PyObject *res;
|
|
505
|
+ res = PyUnicode_Concat(left, right);
|
|
506
|
+ Py_DECREF(left);
|
|
507
|
+ Py_DECREF(right);
|
|
508
|
+ return res;
|
|
509
|
+}
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|