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