Commit | Line | Data |
---|---|---|
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. | |
d8d81d1b | 18 | # |
579d0169 | 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. | |
d8d81d1b | 23 | # |
579d0169 | 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) | |
6a6bd8fa | 45 | size_t strlen(char *p) |
579d0169 | 46 | |
47 | #----- Unix interface ------------------------------------------------------- | |
48 | ||
49 | cdef extern from 'sys/types.h': | |
50 | pass | |
51 | cdef extern from 'sys/time.h': | |
52 | struct timeval: | |
53 | int tv_sec | |
54 | int tv_usec | |
55 | ||
56 | cdef 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) | |
63 | cdef 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) | |
68 | cdef 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) | |
77 | cdef 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 | ||
89 | cdef extern from 'Python.h': | |
90 | ||
ae68e889 MW |
91 | ctypedef struct PyObject: |
92 | pass | |
93 | ctypedef struct PyTypeObject: | |
94 | pass | |
95 | ||
579d0169 | 96 | object PyString_FromStringAndSize(char *p, int len) |
97 | int PyString_AsStringAndSize(obj, char **p, int *len) except -1 | |
98 | int PyObject_AsReadBuffer(obj, void **buf, int *len) except -1 | |
99 | int PyObject_TypeCheck(obj, ty) | |
100 | object PyInt_FromLong(long i) | |
101 | object PyLong_FromUnsignedLong(unsigned long i) | |
ae68e889 MW |
102 | char *PyString_AS_STRING(string) |
103 | int _PyString_Resize(PyObject **string, int size) except -1 | |
579d0169 | 104 | |
579d0169 | 105 | void Py_INCREF(PyObject *obj) |
106 | void Py_DECREF(PyObject *obj) | |
107 | ||
108 | #----- mLib basic stuff ----------------------------------------------------- | |
109 | ||
110 | cdef extern from 'mLib/alloc.h': | |
111 | char *xstrdup(char *p) | |
112 | void *xmalloc(size_t sz) | |
113 | void xfree(void *p) | |
114 | ||
115 | cdef extern from 'mLib/bits.h': | |
116 | ctypedef int uint32 | |
117 | ||
118 | cdef extern from 'mLib/dstr.h': | |
119 | ctypedef struct dstr: | |
120 | char *buf | |
121 | int len | |
122 | void DCREATE(dstr *d) | |
123 | void dstr_destroy(dstr *d) | |
124 | ||
125 | #----- CRC32 ---------------------------------------------------------------- | |
126 | ||
127 | cdef extern from 'mLib/crc32.h': | |
128 | uint32 c_crc32 "crc32" (uint32 a, void *p, int sz) | |
129 | ||
130 | #----- Universal hashing ---------------------------------------------------- | |
131 | ||
132 | cdef extern from 'mLib/unihash.h': | |
133 | ctypedef struct unihash_info: | |
134 | pass | |
135 | void unihash_setkey(unihash_info *i, uint32 k) | |
136 | uint32 UNIHASH_INIT(unihash_info *i) | |
137 | uint32 unihash_hash(unihash_info *i, uint32 a, void *p, int sz) | |
138 | unihash_info unihash_global | |
139 | ||
140 | #----- Symbol tables -------------------------------------------------------- | |
141 | ||
142 | cdef extern from 'mLib/sym.h': | |
143 | ctypedef struct sym_table: | |
144 | pass | |
145 | ctypedef struct sym_base: | |
146 | pass | |
147 | ctypedef struct sym_iter: | |
148 | pass | |
149 | void sym_create(sym_table *t) | |
150 | void sym_destroy(sym_table *t) | |
151 | void *sym_find(sym_table *t, char *n, long l, int sz, unsigned *f) | |
152 | void sym_remove(sym_table *t, void *b) | |
153 | char *SYM_NAME(void *b) | |
154 | int SYM_LEN(void *b) | |
155 | void sym_mkiter(sym_iter *i, sym_table *t) | |
156 | void *sym_next(sym_iter *i) | |
157 | ||
6a6bd8fa MW |
158 | #----- String utilities ----------------------------------------------------- |
159 | ||
160 | cdef extern from 'mLib/str.h': | |
161 | enum: | |
162 | STRF_QUOTE | |
95920c4f | 163 | STRF_PREFIX |
6a6bd8fa MW |
164 | char *str_qword(char **pp, unsigned f) |
165 | size_t str_qsplit(char *p, char **v, size_t c, char **rest, unsigned f) | |
95920c4f | 166 | int str_matchx(char *p, char *s, unsigned f) |
6a6bd8fa MW |
167 | void str_sanitize(char *d, char *p, size_t sz) |
168 | ||
ae68e889 MW |
169 | cdef extern from 'mLib/versioncmp.h': |
170 | int _versioncmp "versioncmp"(char *va, char *vb) | |
171 | ||
5ce5170c MW |
172 | #----- Form-urlencoding functions ------------------------------------------- |
173 | ||
174 | cdef extern from 'mLib/url.h': | |
175 | struct url_ectx: | |
176 | unsigned f | |
177 | struct url_dctx: | |
178 | char *p | |
179 | unsigned f | |
180 | enum: | |
181 | URLF_STRICT | |
182 | URLF_LAX | |
183 | URLF_SEMI | |
184 | void url_initenc(url_ectx *ctx) | |
185 | void url_enc(url_ectx *ctx, dstr *d, char *name, char *value) | |
186 | void url_initdec(url_dctx *ctx, char *p) | |
187 | int url_dec(url_dctx *ctx, dstr *n, dstr *v) | |
188 | ||
579d0169 | 189 | #----- Atom stuff ----------------------------------------------------------- |
190 | ||
191 | # --- Atoms --- | |
192 | # | |
193 | # Partly written in `real' C. | |
194 | ||
195 | cdef extern from 'atom.h': | |
196 | ctypedef struct atom: | |
197 | pass | |
198 | ctypedef struct atom_iter: | |
199 | pass | |
200 | ctypedef struct atom_table: | |
201 | pass | |
202 | atom_table *ATOM_GLOBAL | |
203 | void atom_mkiter(atom_iter *i, atom_table *t) | |
204 | atom *atom_next(atom_iter *) | |
205 | void atom_pysetup() | |
206 | atom_pywrap(atom *a) | |
207 | atom_pyintern(obj) | |
208 | atom *ATOM_A(obj) | |
209 | PyTypeObject atom_pytype | |
210 | ||
211 | # --- Association tables --- | |
212 | ||
213 | cdef extern from 'mLib/assoc.h': | |
214 | ctypedef struct assoc_table: | |
215 | pass | |
216 | ctypedef struct assoc_base: | |
217 | pass | |
218 | ctypedef struct assoc_iter: | |
219 | pass | |
220 | void assoc_create(assoc_table *t) | |
221 | void assoc_destroy(assoc_table *t) | |
222 | void *assoc_find(assoc_table *t, atom *a, int sz, unsigned *f) | |
223 | void assoc_remove(assoc_table *t, void *b) | |
224 | atom *ASSOC_ATOM(void *b) | |
225 | void assoc_mkiter(assoc_iter *i, assoc_table *t) | |
226 | void *assoc_next(assoc_iter *i) | |
227 | ||
228 | #----- Double-ended arrays -------------------------------------------------- | |
229 | ||
230 | cdef extern from 'array.h': | |
231 | void da_pysetup() | |
232 | PyTypeObject da_pytype | |
233 | PyTypeObject daiter_pytype | |
234 | ||
235 | #----- Line buffer ---------------------------------------------------------- | |
236 | ||
237 | cdef extern from 'mLib/lbuf.h': | |
238 | cdef struct lbuf: | |
239 | int f | |
240 | int delim | |
241 | size_t sz | |
242 | enum: | |
243 | LBUF_ENABLE | |
244 | _LBUF_CRLF "LBUF_CRLF" | |
245 | _LBUF_STRICTCRLF "LBUF_STRICTCRLF" | |
246 | void lbuf_flush(lbuf *b, char *p, size_t len) | |
247 | void lbuf_close(lbuf *b) | |
248 | size_t lbuf_free(lbuf *b, char **p) | |
249 | void lbuf_setsize(lbuf *b, size_t sz) | |
250 | void lbuf_enable(lbuf *b) | |
251 | void lbuf_disable(lbuf *b) | |
252 | void lbuf_init(lbuf *b, | |
d8d81d1b | 253 | void (*func)(char *s, size_t len, void *arg), void *arg) |
579d0169 | 254 | void lbuf_destroy(lbuf *b) |
255 | ||
256 | #----- Packet buffer -------------------------------------------------------- | |
257 | ||
258 | cdef extern from 'mLib/pkbuf.h': | |
259 | ctypedef struct pkbuf: | |
260 | int f | |
261 | int want | |
262 | enum: | |
263 | PKBUF_ENABLE | |
264 | void pkbuf_flush(pkbuf *pk, unsigned char *p, size_t len) | |
265 | void pkbuf_close(pkbuf *pk) | |
266 | size_t pkbuf_free(pkbuf *pk, unsigned char **p) | |
267 | void pkbuf_want(pkbuf *pk, size_t sz) | |
268 | void pkbuf_init(pkbuf *b, | |
d8d81d1b MW |
269 | void (*func)(unsigned char *s, size_t len, |
270 | pkbuf *pk, size_t *keep, void *arg), | |
271 | void *arg) | |
579d0169 | 272 | void pkbuf_destroy(pkbuf *b) |
273 | ||
274 | #----- Select stuff --------------------------------------------------------- | |
275 | ||
276 | # --- Basics --- | |
277 | ||
278 | cdef extern from 'mLib/sel.h': | |
279 | ctypedef struct sel_state: | |
280 | pass | |
281 | ctypedef struct sel_file: | |
282 | int fd | |
283 | ctypedef struct sel_timer: | |
284 | pass | |
285 | enum: | |
286 | _SEL_READ "SEL_READ" | |
287 | _SEL_WRITE "SEL_WRITE" | |
288 | _SEL_EXC "SEL_EXC" | |
289 | void sel_init(sel_state *s) | |
290 | void sel_initfile(sel_state *s, sel_file *f, int fd, unsigned mode, | |
d8d81d1b MW |
291 | void (*func)(int fd, unsigned mode, void *arg), |
292 | void *arg) | |
579d0169 | 293 | void sel_force(sel_file *f) |
294 | void sel_addfile(sel_file *f) | |
295 | void sel_rmfile(sel_file *f) | |
296 | void sel_addtimer(sel_state *s, sel_timer *t, timeval *tv, | |
d8d81d1b MW |
297 | void (*func)(timeval *tv, void *arg), |
298 | void *arg) | |
579d0169 | 299 | void sel_rmtimer(sel_timer *t) |
300 | int sel_select(sel_state *s) except * | |
301 | ||
302 | # --- Non-blocking connection --- | |
303 | ||
304 | cdef extern from 'mLib/conn.h': | |
305 | ctypedef struct conn: | |
306 | pass | |
307 | int conn_fd(conn *c, sel_state *s, int fd, | |
d8d81d1b | 308 | void (*func)(int fd, void *arg), void *arg) |
579d0169 | 309 | void conn_kill(conn *c) |
310 | ||
311 | # --- Background name resolver --- | |
312 | ||
313 | cdef extern from 'mLib/bres.h': | |
314 | ctypedef struct bres_client: | |
315 | pass | |
316 | void bres_byname(bres_client *r, char *name, | |
d8d81d1b | 317 | void (*func)(hostent *h, void *arg), void *arg) |
579d0169 | 318 | void bres_byaddr(bres_client *r, in_addr addr, |
d8d81d1b | 319 | void (*func)(hostent *h, void *arg), void *arg) |
579d0169 | 320 | void bres_abort(bres_client *r) |
321 | void bres_exec(char *null) | |
322 | void bres_init(sel_state *s) | |
323 | ||
324 | # --- In-band signal handling --- | |
325 | ||
326 | cdef extern from 'mLib/sig.h': | |
327 | ctypedef struct sig: | |
328 | pass | |
329 | void sig_add(sig *s, int n, void (*func)(int n, void *arg), void *arg) | |
330 | void sig_remove(sig *s) | |
331 | void sig_init(sel_state *s) | |
332 | ||
333 | # --- Line buffer --- | |
334 | ||
335 | cdef extern from 'mLib/selbuf.h': | |
336 | ctypedef struct selbuf: | |
337 | sel_file reader | |
338 | lbuf b | |
339 | void selbuf_enable(selbuf *b) | |
340 | void selbuf_disable(selbuf *b) | |
341 | void selbuf_setsize(selbuf *b, size_t sz) | |
342 | void selbuf_init(selbuf *b, sel_state *s, int fd, | |
d8d81d1b | 343 | void (*func)(char *s, size_t len, void *arg), void *arg) |
579d0169 | 344 | void selbuf_destroy(selbuf *b) |
345 | ||
346 | # --- Packet buffer --- | |
347 | ||
348 | cdef extern from 'mLib/selpk.h': | |
349 | ctypedef struct selpk: | |
350 | sel_file reader | |
351 | pkbuf pk | |
352 | void selpk_enable(selpk *b) | |
353 | void selpk_disable(selpk *b) | |
354 | void selpk_want(selpk *b, size_t sz) | |
355 | void selpk_init(selpk *b, sel_state *s, int fd, | |
d8d81d1b MW |
356 | void (*func)(unsigned char *p, size_t n, |
357 | pkbuf *pk, size_t *keep, void *arg), | |
358 | void *arg) | |
579d0169 | 359 | void selpk_destroy(selpk *b) |
360 | ||
361 | # --- Ident client --- | |
362 | ||
363 | cdef extern from 'mLib/ident.h': | |
364 | ctypedef struct ident_request: | |
365 | pass | |
366 | enum: | |
367 | IDENT_USERID | |
368 | IDENT_ERROR | |
369 | IDENT_BAD | |
370 | struct ident_userid: | |
371 | char *os | |
372 | char *user | |
373 | union ident_u: | |
374 | ident_userid userid | |
375 | char *error | |
376 | ctypedef struct ident_reply: | |
377 | int sport | |
378 | int dport | |
379 | int type | |
380 | ident_u u | |
381 | void ident(ident_request *rq, sel_state *s, | |
d8d81d1b MW |
382 | sockaddr_in *local, sockaddr_in *remote, |
383 | void (*func)(ident_reply *r, void *arg), | |
384 | void *arg) | |
579d0169 | 385 | void ident_abort(ident_request *rq) |
386 | ||
387 | #----- Error reporting ------------------------------------------------------ | |
388 | ||
389 | cdef extern from 'mLib/quis.h': | |
390 | void _ego "ego"(char *prog) | |
391 | char *_quis "quis"() | |
ae68e889 | 392 | |
579d0169 | 393 | cdef extern from 'mLib/report.h': |
394 | void _moan "moan"(char *f, char *msg) | |
395 | ||
ae68e889 MW |
396 | #----- File comparison ------------------------------------------------------ |
397 | ||
398 | cdef extern from 'mLib/fwatch.h': | |
399 | ctypedef struct fwatch: | |
400 | pass | |
401 | void fwatch_init(fwatch *f, char *name) | |
402 | void fwatch_initfd(fwatch *f, int fd) | |
403 | int fwatch_update(fwatch *f, char *name) | |
404 | int fwatch_updatefd(fwatch *f, int fd) | |
405 | ||
406 | #----- File descriptor hacking ---------------------------------------------- | |
407 | ||
408 | cdef extern from 'mLib/fdflags.h': | |
409 | int _fdflags "fdflags"(int fd, | |
d8d81d1b MW |
410 | unsigned fbic, unsigned fxor, |
411 | unsigned fdbic, unsigned fdxor) | |
ae68e889 MW |
412 | |
413 | cdef extern from 'mLib/fdpass.h': | |
414 | int fdpass_send(int sock, int fd, void *p, size_t sz) | |
415 | int fdpass_recv(int sock, int *fd, void *p, size_t sz) | |
416 | ||
ea2fc600 MW |
417 | cdef extern from 'mLib/mdup.h': |
418 | ctypedef struct mdup_fd: | |
419 | int cur | |
420 | int want | |
421 | int _mdup "mdup"(mdup_fd *v, size_t n) | |
422 | ||
ae68e889 MW |
423 | #----- Daemon utilities ----------------------------------------------------- |
424 | ||
425 | cdef extern from 'mLib/daemonize.h': | |
426 | int _daemonize "daemonize"() | |
427 | void _detachtty "detachtty"() | |
428 | ||
579d0169 | 429 | #----- Internal utilities --------------------------------------------------- |
430 | ||
431 | cdef extern from 'grim.h': | |
432 | int PSIZEOF(void *x) | |
433 | ||
434 | #----- That's all, folks ---------------------------------------------------- |