chiark / gitweb /
debian: Fix package sections.
[mLib-python] / defs.pxi
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
30 cdef extern from 'errno.h':
31   int errno
32   enum:
33     EINTR
34     EAGAIN
35 cdef extern from 'limits.h':
36   enum:
37     LONG_MAX
38 cdef extern from 'math.h':
39   double modf(double x, double *i)
40 cdef extern from 'stddef.h':
41   ctypedef int size_t
42 cdef extern from 'string.h':
43   void memcpy(void *p, void *q, size_t n)
44   char *strerror(int err)
45
46 #----- Unix interface -------------------------------------------------------
47
48 cdef extern from 'sys/types.h':
49   pass
50 cdef extern from 'sys/time.h':
51   struct timeval:
52     int tv_sec
53     int tv_usec
54
55 cdef extern from 'sys/socket.h':
56   struct sockaddr:
57     int sa_family
58   enum:
59     AF_INET
60   int getsockname(int fd, sockaddr *pa, size_t *psz)
61   int getpeername(int fd, sockaddr *pa, size_t *psz)
62 cdef extern from 'arpa/inet.h':
63   struct in_addr:
64     int s_addr
65   int inet_aton(char *rp, in_addr *ia)
66   char *inet_ntoa(in_addr ia)
67 cdef extern from 'netinet/in.h':
68   struct sockaddr_in:
69     int sin_family
70     in_addr sin_addr
71     int sin_port
72   int htons(int x)
73   int htonl(int x)
74   int ntohs(int x)
75   int ntohl(int x)
76 cdef extern from 'netdb.h':
77   struct hostent:
78     char *h_name
79     char **h_aliases
80     int h_addrtype
81     int h_length
82     char **h_addr_list
83     char *h_addr
84   int h_errno
85
86 #----- Python ---------------------------------------------------------------
87
88 cdef extern from 'Python.h':
89
90   object PyString_FromStringAndSize(char *p, int len)
91   int PyString_AsStringAndSize(obj, char **p, int *len) except -1
92   int PyObject_AsReadBuffer(obj, void **buf, int *len) except -1
93   int PyObject_TypeCheck(obj, ty)
94   object PyInt_FromLong(long i)
95   object PyLong_FromUnsignedLong(unsigned long i)
96
97   ctypedef struct PyObject:
98     pass
99   ctypedef struct PyTypeObject:
100     pass
101   void Py_INCREF(PyObject *obj)
102   void Py_DECREF(PyObject *obj)
103
104 #----- mLib basic stuff -----------------------------------------------------
105
106 cdef extern from 'mLib/alloc.h':
107   char *xstrdup(char *p)
108   void *xmalloc(size_t sz)
109   void xfree(void *p)
110
111 cdef extern from 'mLib/bits.h':
112   ctypedef int uint32
113
114 cdef extern from 'mLib/dstr.h':
115   ctypedef struct dstr:
116     char *buf
117     int len
118   void DCREATE(dstr *d)
119   void dstr_destroy(dstr *d)
120
121 #----- CRC32 ----------------------------------------------------------------
122
123 cdef extern from 'mLib/crc32.h':
124   uint32 c_crc32 "crc32" (uint32 a, void *p, int sz)
125
126 #----- Universal hashing ----------------------------------------------------
127
128 cdef extern from 'mLib/unihash.h':
129   ctypedef struct unihash_info:
130     pass
131   void unihash_setkey(unihash_info *i, uint32 k)
132   uint32 UNIHASH_INIT(unihash_info *i)
133   uint32 unihash_hash(unihash_info *i, uint32 a, void *p, int sz)
134   unihash_info unihash_global
135
136 #----- Symbol tables --------------------------------------------------------
137
138 cdef extern from 'mLib/sym.h':
139   ctypedef struct sym_table:
140     pass
141   ctypedef struct sym_base:
142     pass
143   ctypedef struct sym_iter:
144     pass
145   void sym_create(sym_table *t)
146   void sym_destroy(sym_table *t)
147   void *sym_find(sym_table *t, char *n, long l, int sz, unsigned *f)
148   void sym_remove(sym_table *t, void *b)
149   char *SYM_NAME(void *b)
150   int SYM_LEN(void *b)
151   void sym_mkiter(sym_iter *i, sym_table *t)
152   void *sym_next(sym_iter *i)
153
154 #----- Atom stuff -----------------------------------------------------------
155
156 # --- Atoms ---
157 #
158 # Partly written in `real' C.
159
160 cdef extern from 'atom.h':
161   ctypedef struct atom:
162     pass
163   ctypedef struct atom_iter:
164     pass
165   ctypedef struct atom_table:
166     pass
167   atom_table *ATOM_GLOBAL
168   void atom_mkiter(atom_iter *i, atom_table *t)
169   atom *atom_next(atom_iter *)
170   void atom_pysetup()
171   atom_pywrap(atom *a)
172   atom_pyintern(obj)
173   atom *ATOM_A(obj)
174   PyTypeObject atom_pytype
175
176 # --- Association tables ---
177
178 cdef extern from 'mLib/assoc.h':
179   ctypedef struct assoc_table:
180     pass
181   ctypedef struct assoc_base:
182     pass
183   ctypedef struct assoc_iter:
184     pass
185   void assoc_create(assoc_table *t)
186   void assoc_destroy(assoc_table *t)
187   void *assoc_find(assoc_table *t, atom *a, int sz, unsigned *f)
188   void assoc_remove(assoc_table *t, void *b)
189   atom *ASSOC_ATOM(void *b)
190   void assoc_mkiter(assoc_iter *i, assoc_table *t)
191   void *assoc_next(assoc_iter *i)
192
193 #----- Double-ended arrays --------------------------------------------------
194
195 cdef extern from 'array.h':
196   void da_pysetup()
197   PyTypeObject da_pytype
198   PyTypeObject daiter_pytype
199
200 #----- Line buffer ----------------------------------------------------------
201
202 cdef extern from 'mLib/lbuf.h':
203   cdef struct lbuf:
204     int f
205     int delim
206     size_t sz
207   enum:
208     LBUF_ENABLE
209     _LBUF_CRLF "LBUF_CRLF"
210     _LBUF_STRICTCRLF "LBUF_STRICTCRLF"
211   void lbuf_flush(lbuf *b, char *p, size_t len)
212   void lbuf_close(lbuf *b)
213   size_t lbuf_free(lbuf *b, char **p)
214   void lbuf_setsize(lbuf *b, size_t sz)
215   void lbuf_enable(lbuf *b)
216   void lbuf_disable(lbuf *b)
217   void lbuf_init(lbuf *b,
218                  void (*func)(char *s, size_t len, void *arg), void *arg)
219   void lbuf_destroy(lbuf *b)
220
221 #----- Packet buffer --------------------------------------------------------
222
223 cdef extern from 'mLib/pkbuf.h':
224   ctypedef struct pkbuf:
225     int f
226     int want
227   enum:
228     PKBUF_ENABLE
229   void pkbuf_flush(pkbuf *pk, unsigned char *p, size_t len)
230   void pkbuf_close(pkbuf *pk)
231   size_t pkbuf_free(pkbuf *pk, unsigned char **p)
232   void pkbuf_want(pkbuf *pk, size_t sz)
233   void pkbuf_init(pkbuf *b,
234                   void (*func)(unsigned char *s, size_t len,
235                                pkbuf *pk, size_t *keep, void *arg),
236                   void *arg)
237   void pkbuf_destroy(pkbuf *b)
238
239 #----- Select stuff ---------------------------------------------------------
240
241 # --- Basics ---
242
243 cdef extern from 'mLib/sel.h':
244   ctypedef struct sel_state:
245     pass
246   ctypedef struct sel_file:
247     int fd
248   ctypedef struct sel_timer:
249     pass
250   enum:
251     _SEL_READ "SEL_READ"
252     _SEL_WRITE "SEL_WRITE"
253     _SEL_EXC "SEL_EXC"
254   void sel_init(sel_state *s)
255   void sel_initfile(sel_state *s, sel_file *f, int fd, unsigned mode,
256                     void (*func)(int fd, unsigned mode, void *arg),
257                     void *arg)
258   void sel_force(sel_file *f)
259   void sel_addfile(sel_file *f)
260   void sel_rmfile(sel_file *f)
261   void sel_addtimer(sel_state *s, sel_timer *t, timeval *tv,
262                     void (*func)(timeval *tv, void *arg),
263                     void *arg)
264   void sel_rmtimer(sel_timer *t)
265   int sel_select(sel_state *s) except *
266
267 # --- Non-blocking connection ---
268
269 cdef extern from 'mLib/conn.h':
270   ctypedef struct conn:
271     pass
272   int conn_fd(conn *c, sel_state *s, int fd,
273               void (*func)(int fd, void *arg), void *arg)
274   void conn_kill(conn *c)
275
276 # --- Background name resolver ---
277
278 cdef extern from 'mLib/bres.h':
279   ctypedef struct bres_client:
280     pass
281   void bres_byname(bres_client *r, char *name,
282                    void (*func)(hostent *h, void *arg), void *arg)
283   void bres_byaddr(bres_client *r, in_addr addr,
284                    void (*func)(hostent *h, void *arg), void *arg)
285   void bres_abort(bres_client *r)
286   void bres_exec(char *null)
287   void bres_init(sel_state *s)
288
289 # --- In-band signal handling ---
290
291 cdef extern from 'mLib/sig.h':
292   ctypedef struct sig:
293     pass
294   void sig_add(sig *s, int n, void (*func)(int n, void *arg), void *arg)
295   void sig_remove(sig *s)
296   void sig_init(sel_state *s)
297
298 # --- Line buffer ---
299
300 cdef extern from 'mLib/selbuf.h':
301   ctypedef struct selbuf:
302     sel_file reader
303     lbuf b
304   void selbuf_enable(selbuf *b)
305   void selbuf_disable(selbuf *b)
306   void selbuf_setsize(selbuf *b, size_t sz)
307   void selbuf_init(selbuf *b, sel_state *s, int fd,
308                    void (*func)(char *s, size_t len, void *arg), void *arg)
309   void selbuf_destroy(selbuf *b)
310
311 # --- Packet buffer ---
312
313 cdef extern from 'mLib/selpk.h':
314   ctypedef struct selpk:
315     sel_file reader
316     pkbuf pk
317   void selpk_enable(selpk *b)
318   void selpk_disable(selpk *b)
319   void selpk_want(selpk *b, size_t sz)
320   void selpk_init(selpk *b, sel_state *s, int fd,
321                   void (*func)(unsigned char *p, size_t n,
322                                pkbuf *pk, size_t *keep, void *arg),
323                   void *arg)
324   void selpk_destroy(selpk *b)
325
326 # --- Ident client ---
327
328 cdef extern from 'mLib/ident.h':
329   ctypedef struct ident_request:
330     pass
331   enum:
332     IDENT_USERID
333     IDENT_ERROR
334     IDENT_BAD
335   struct ident_userid:
336     char *os
337     char *user
338   union ident_u:
339     ident_userid userid
340     char *error
341   ctypedef struct ident_reply:
342     int sport
343     int dport
344     int type
345     ident_u u
346   void ident(ident_request *rq, sel_state *s,
347              sockaddr_in *local, sockaddr_in *remote,
348              void (*func)(ident_reply *r, void *arg),
349              void *arg)
350   void ident_abort(ident_request *rq)
351
352 #----- Error reporting ------------------------------------------------------
353
354 cdef extern from 'mLib/quis.h':
355   void _ego "ego"(char *prog)
356   char *_quis "quis"()
357 cdef extern from 'mLib/report.h':
358   void _moan "moan"(char *f, char *msg)
359
360 #----- Internal utilities ---------------------------------------------------
361
362 cdef extern from 'grim.h':
363   int PSIZEOF(void *x)
364
365 #----- That's all, folks ----------------------------------------------------