chiark / gitweb /
codec.pyx: New flag from upstream.
[mLib-python] / defs.pxi
CommitLineData
5b1830f3
MW
1### -*-pyrex-*-
2###
3### Basic definitions, used all over
4###
5### (c) 2005 Straylight/Edgeware
6###
7
8###----- Licensing notice ---------------------------------------------------
9###
10### This file is part of the Python interface to mLib.
11###
12### mLib/Python is free software; you can redistribute it and/or modify
13### it under the terms of the GNU General Public License as published by
14### the Free Software Foundation; either version 2 of the License, or
15### (at your option) any later version.
16###
17### mLib/Python is distributed in the hope that it will be useful,
18### but WITHOUT ANY WARRANTY; without even the implied warranty of
19### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20### GNU General Public License for more details.
21###
22### You should have received a copy of the GNU General Public License
23### along with mLib/Python; if not, write to the Free Software Foundation,
24### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
976d8e49
MW
26###--------------------------------------------------------------------------
27### C library.
579d0169 28
29cdef extern from 'errno.h':
30 int errno
31 enum:
32 EINTR
33 EAGAIN
34cdef extern from 'limits.h':
35 enum:
36 LONG_MAX
37cdef extern from 'math.h':
38 double modf(double x, double *i)
39cdef extern from 'stddef.h':
40 ctypedef int size_t
41cdef extern from 'string.h':
42 void memcpy(void *p, void *q, size_t n)
43 char *strerror(int err)
6a6bd8fa 44 size_t strlen(char *p)
579d0169 45
976d8e49
MW
46###--------------------------------------------------------------------------
47### Unix interface.
579d0169 48
49cdef extern from 'sys/types.h':
50 pass
51cdef extern from 'sys/time.h':
52 struct timeval:
53 int tv_sec
54 int tv_usec
55
56cdef extern from 'sys/socket.h':
57 struct sockaddr:
58 int sa_family
59 enum:
60 AF_INET
61 int getsockname(int fd, sockaddr *pa, size_t *psz)
62 int getpeername(int fd, sockaddr *pa, size_t *psz)
63cdef extern from 'arpa/inet.h':
64 struct in_addr:
65 int s_addr
66 int inet_aton(char *rp, in_addr *ia)
67 char *inet_ntoa(in_addr ia)
68cdef extern from 'netinet/in.h':
69 struct sockaddr_in:
70 int sin_family
71 in_addr sin_addr
72 int sin_port
73 int htons(int x)
74 int htonl(int x)
75 int ntohs(int x)
76 int ntohl(int x)
77cdef extern from 'netdb.h':
78 struct hostent:
79 char *h_name
80 char **h_aliases
81 int h_addrtype
82 int h_length
83 char **h_addr_list
84 char *h_addr
85 int h_errno
86
976d8e49
MW
87###--------------------------------------------------------------------------
88### Python.
579d0169 89
90cdef extern from 'Python.h':
91
ae68e889
MW
92 ctypedef struct PyObject:
93 pass
94 ctypedef struct PyTypeObject:
95 pass
96
579d0169 97 object PyString_FromStringAndSize(char *p, int len)
98 int PyString_AsStringAndSize(obj, char **p, int *len) except -1
99 int PyObject_AsReadBuffer(obj, void **buf, int *len) except -1
100 int PyObject_TypeCheck(obj, ty)
101 object PyInt_FromLong(long i)
102 object PyLong_FromUnsignedLong(unsigned long i)
ae68e889
MW
103 char *PyString_AS_STRING(string)
104 int _PyString_Resize(PyObject **string, int size) except -1
579d0169 105
579d0169 106 void Py_INCREF(PyObject *obj)
107 void Py_DECREF(PyObject *obj)
108
976d8e49
MW
109###--------------------------------------------------------------------------
110### mLib basic stuff.
579d0169 111
112cdef extern from 'mLib/alloc.h':
113 char *xstrdup(char *p)
114 void *xmalloc(size_t sz)
115 void xfree(void *p)
116
117cdef extern from 'mLib/bits.h':
118 ctypedef int uint32
119
120cdef extern from 'mLib/dstr.h':
121 ctypedef struct dstr:
122 char *buf
123 int len
124 void DCREATE(dstr *d)
125 void dstr_destroy(dstr *d)
126
976d8e49
MW
127###--------------------------------------------------------------------------
128### CRC32.
579d0169 129
130cdef extern from 'mLib/crc32.h':
131 uint32 c_crc32 "crc32" (uint32 a, void *p, int sz)
132
976d8e49
MW
133###--------------------------------------------------------------------------
134### Universal hashing.
579d0169 135
136cdef extern from 'mLib/unihash.h':
137 ctypedef struct unihash_info:
138 pass
139 void unihash_setkey(unihash_info *i, uint32 k)
140 uint32 UNIHASH_INIT(unihash_info *i)
141 uint32 unihash_hash(unihash_info *i, uint32 a, void *p, int sz)
142 unihash_info unihash_global
143
976d8e49
MW
144###--------------------------------------------------------------------------
145### Symbol tables.
579d0169 146
147cdef extern from 'mLib/sym.h':
148 ctypedef struct sym_table:
149 pass
150 ctypedef struct sym_base:
151 pass
152 ctypedef struct sym_iter:
153 pass
154 void sym_create(sym_table *t)
155 void sym_destroy(sym_table *t)
156 void *sym_find(sym_table *t, char *n, long l, int sz, unsigned *f)
157 void sym_remove(sym_table *t, void *b)
158 char *SYM_NAME(void *b)
159 int SYM_LEN(void *b)
160 void sym_mkiter(sym_iter *i, sym_table *t)
161 void *sym_next(sym_iter *i)
162
976d8e49
MW
163###--------------------------------------------------------------------------
164### String utilities.
6a6bd8fa
MW
165
166cdef extern from 'mLib/str.h':
167 enum:
168 STRF_QUOTE
95920c4f 169 STRF_PREFIX
6a6bd8fa
MW
170 char *str_qword(char **pp, unsigned f)
171 size_t str_qsplit(char *p, char **v, size_t c, char **rest, unsigned f)
95920c4f 172 int str_matchx(char *p, char *s, unsigned f)
6a6bd8fa
MW
173 void str_sanitize(char *d, char *p, size_t sz)
174
ae68e889
MW
175cdef extern from 'mLib/versioncmp.h':
176 int _versioncmp "versioncmp"(char *va, char *vb)
177
976d8e49
MW
178###--------------------------------------------------------------------------
179### Form-urlencoding functions.
5ce5170c
MW
180
181cdef extern from 'mLib/url.h':
182 struct url_ectx:
183 unsigned f
184 struct url_dctx:
185 char *p
186 unsigned f
187 enum:
188 URLF_STRICT
189 URLF_LAX
190 URLF_SEMI
191 void url_initenc(url_ectx *ctx)
192 void url_enc(url_ectx *ctx, dstr *d, char *name, char *value)
193 void url_initdec(url_dctx *ctx, char *p)
194 int url_dec(url_dctx *ctx, dstr *n, dstr *v)
195
976d8e49
MW
196###--------------------------------------------------------------------------
197### Atom stuff.
579d0169 198
5b1830f3
MW
199## Atoms.
200##
201## Partly written in `real' C.
579d0169 202cdef extern from 'atom.h':
203 ctypedef struct atom:
204 pass
205 ctypedef struct atom_iter:
206 pass
207 ctypedef struct atom_table:
208 pass
209 atom_table *ATOM_GLOBAL
210 void atom_mkiter(atom_iter *i, atom_table *t)
211 atom *atom_next(atom_iter *)
212 void atom_pysetup()
213 atom_pywrap(atom *a)
214 atom_pyintern(obj)
215 atom *ATOM_A(obj)
216 PyTypeObject atom_pytype
217
5b1830f3 218## Association tables.
579d0169 219cdef extern from 'mLib/assoc.h':
220 ctypedef struct assoc_table:
221 pass
222 ctypedef struct assoc_base:
223 pass
224 ctypedef struct assoc_iter:
225 pass
226 void assoc_create(assoc_table *t)
227 void assoc_destroy(assoc_table *t)
228 void *assoc_find(assoc_table *t, atom *a, int sz, unsigned *f)
229 void assoc_remove(assoc_table *t, void *b)
230 atom *ASSOC_ATOM(void *b)
231 void assoc_mkiter(assoc_iter *i, assoc_table *t)
232 void *assoc_next(assoc_iter *i)
233
976d8e49
MW
234###--------------------------------------------------------------------------
235### Double-ended arrays.
579d0169 236
237cdef extern from 'array.h':
238 void da_pysetup()
239 PyTypeObject da_pytype
240 PyTypeObject daiter_pytype
241
976d8e49
MW
242###--------------------------------------------------------------------------
243### Line buffer.
579d0169 244
245cdef extern from 'mLib/lbuf.h':
246 cdef struct lbuf:
247 int f
248 int delim
249 size_t sz
250 enum:
251 LBUF_ENABLE
252 _LBUF_CRLF "LBUF_CRLF"
253 _LBUF_STRICTCRLF "LBUF_STRICTCRLF"
254 void lbuf_flush(lbuf *b, char *p, size_t len)
255 void lbuf_close(lbuf *b)
256 size_t lbuf_free(lbuf *b, char **p)
257 void lbuf_setsize(lbuf *b, size_t sz)
258 void lbuf_enable(lbuf *b)
259 void lbuf_disable(lbuf *b)
260 void lbuf_init(lbuf *b,
5b1830f3 261 void (*func)(char *s, size_t len, void *arg), void *arg)
579d0169 262 void lbuf_destroy(lbuf *b)
263
976d8e49
MW
264###--------------------------------------------------------------------------
265### Packet buffer.
579d0169 266
267cdef extern from 'mLib/pkbuf.h':
268 ctypedef struct pkbuf:
269 int f
270 int want
271 enum:
272 PKBUF_ENABLE
273 void pkbuf_flush(pkbuf *pk, unsigned char *p, size_t len)
274 void pkbuf_close(pkbuf *pk)
275 size_t pkbuf_free(pkbuf *pk, unsigned char **p)
276 void pkbuf_want(pkbuf *pk, size_t sz)
277 void pkbuf_init(pkbuf *b,
5b1830f3
MW
278 void (*func)(unsigned char *s, size_t len,
279 pkbuf *pk, size_t *keep, void *arg),
280 void *arg)
579d0169 281 void pkbuf_destroy(pkbuf *b)
282
976d8e49
MW
283###--------------------------------------------------------------------------
284### Select stuff.
579d0169 285
5b1830f3 286## Basics.
579d0169 287cdef extern from 'mLib/sel.h':
288 ctypedef struct sel_state:
289 pass
290 ctypedef struct sel_file:
291 int fd
292 ctypedef struct sel_timer:
293 pass
294 enum:
295 _SEL_READ "SEL_READ"
296 _SEL_WRITE "SEL_WRITE"
297 _SEL_EXC "SEL_EXC"
298 void sel_init(sel_state *s)
299 void sel_initfile(sel_state *s, sel_file *f, int fd, unsigned mode,
5b1830f3
MW
300 void (*func)(int fd, unsigned mode, void *arg),
301 void *arg)
579d0169 302 void sel_force(sel_file *f)
303 void sel_addfile(sel_file *f)
304 void sel_rmfile(sel_file *f)
305 void sel_addtimer(sel_state *s, sel_timer *t, timeval *tv,
5b1830f3
MW
306 void (*func)(timeval *tv, void *arg),
307 void *arg)
579d0169 308 void sel_rmtimer(sel_timer *t)
309 int sel_select(sel_state *s) except *
310
5b1830f3 311### Non-blocking connection.
579d0169 312cdef extern from 'mLib/conn.h':
313 ctypedef struct conn:
314 pass
315 int conn_fd(conn *c, sel_state *s, int fd,
5b1830f3 316 void (*func)(int fd, void *arg), void *arg)
579d0169 317 void conn_kill(conn *c)
318
5b1830f3 319## Background name resolver.
579d0169 320cdef extern from 'mLib/bres.h':
321 ctypedef struct bres_client:
322 pass
323 void bres_byname(bres_client *r, char *name,
5b1830f3 324 void (*func)(hostent *h, void *arg), void *arg)
579d0169 325 void bres_byaddr(bres_client *r, in_addr addr,
5b1830f3 326 void (*func)(hostent *h, void *arg), void *arg)
579d0169 327 void bres_abort(bres_client *r)
328 void bres_exec(char *null)
329 void bres_init(sel_state *s)
330
5b1830f3 331## In-band signal handling.
579d0169 332cdef extern from 'mLib/sig.h':
333 ctypedef struct sig:
334 pass
335 void sig_add(sig *s, int n, void (*func)(int n, void *arg), void *arg)
336 void sig_remove(sig *s)
337 void sig_init(sel_state *s)
338
5b1830f3 339## Line buffer.
579d0169 340cdef extern from 'mLib/selbuf.h':
341 ctypedef struct selbuf:
342 sel_file reader
343 lbuf b
344 void selbuf_enable(selbuf *b)
345 void selbuf_disable(selbuf *b)
346 void selbuf_setsize(selbuf *b, size_t sz)
347 void selbuf_init(selbuf *b, sel_state *s, int fd,
5b1830f3 348 void (*func)(char *s, size_t len, void *arg), void *arg)
579d0169 349 void selbuf_destroy(selbuf *b)
350
5b1830f3 351## Packet buffer.
579d0169 352cdef extern from 'mLib/selpk.h':
353 ctypedef struct selpk:
354 sel_file reader
355 pkbuf pk
356 void selpk_enable(selpk *b)
357 void selpk_disable(selpk *b)
358 void selpk_want(selpk *b, size_t sz)
359 void selpk_init(selpk *b, sel_state *s, int fd,
5b1830f3
MW
360 void (*func)(unsigned char *p, size_t n,
361 pkbuf *pk, size_t *keep, void *arg),
362 void *arg)
579d0169 363 void selpk_destroy(selpk *b)
364
5b1830f3 365## Ident client.
579d0169 366cdef extern from 'mLib/ident.h':
367 ctypedef struct ident_request:
368 pass
369 enum:
370 IDENT_USERID
371 IDENT_ERROR
372 IDENT_BAD
373 struct ident_userid:
374 char *os
375 char *user
376 union ident_u:
377 ident_userid userid
378 char *error
379 ctypedef struct ident_reply:
380 int sport
381 int dport
382 int type
383 ident_u u
384 void ident(ident_request *rq, sel_state *s,
5b1830f3
MW
385 sockaddr_in *local, sockaddr_in *remote,
386 void (*func)(ident_reply *r, void *arg),
387 void *arg)
579d0169 388 void ident_abort(ident_request *rq)
389
976d8e49
MW
390###--------------------------------------------------------------------------
391### Error reporting.
579d0169 392
393cdef extern from 'mLib/quis.h':
394 void _ego "ego"(char *prog)
395 char *_quis "quis"()
ae68e889 396
579d0169 397cdef extern from 'mLib/report.h':
398 void _moan "moan"(char *f, char *msg)
399
976d8e49
MW
400###--------------------------------------------------------------------------
401### File comparison.
ae68e889
MW
402
403cdef extern from 'mLib/fwatch.h':
404 ctypedef struct fwatch:
405 pass
406 void fwatch_init(fwatch *f, char *name)
407 void fwatch_initfd(fwatch *f, int fd)
408 int fwatch_update(fwatch *f, char *name)
409 int fwatch_updatefd(fwatch *f, int fd)
410
976d8e49
MW
411###--------------------------------------------------------------------------
412### File descriptor hacking.
ae68e889
MW
413
414cdef extern from 'mLib/fdflags.h':
415 int _fdflags "fdflags"(int fd,
5b1830f3
MW
416 unsigned fbic, unsigned fxor,
417 unsigned fdbic, unsigned fdxor)
ae68e889
MW
418
419cdef extern from 'mLib/fdpass.h':
420 int fdpass_send(int sock, int fd, void *p, size_t sz)
421 int fdpass_recv(int sock, int *fd, void *p, size_t sz)
422
ea2fc600
MW
423cdef extern from 'mLib/mdup.h':
424 ctypedef struct mdup_fd:
425 int cur
426 int want
427 int _mdup "mdup"(mdup_fd *v, size_t n)
428
976d8e49
MW
429###--------------------------------------------------------------------------
430### Daemon utilities.
ae68e889
MW
431
432cdef extern from 'mLib/daemonize.h':
433 int _daemonize "daemonize"()
434 void _detachtty "detachtty"()
435
976d8e49
MW
436###--------------------------------------------------------------------------
437### Internal utilities.
579d0169 438
439cdef extern from 'grim.h':
440 int PSIZEOF(void *x)
441
5b1830f3 442###----- That's all, folks --------------------------------------------------