chiark / gitweb /
url: Support form-urlencoding functions.
[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
160 char *str_qword(char **pp, unsigned f)
161 size_t str_qsplit(char *p, char **v, size_t c, char **rest, unsigned f)
162 int str_match(char *p, char *s)
163 void str_sanitize(char *d, char *p, size_t sz)
164
5ce5170c
MW
165#----- Form-urlencoding functions -------------------------------------------
166
167cdef extern from 'mLib/url.h':
168 struct url_ectx:
169 unsigned f
170 struct url_dctx:
171 char *p
172 unsigned f
173 enum:
174 URLF_STRICT
175 URLF_LAX
176 URLF_SEMI
177 void url_initenc(url_ectx *ctx)
178 void url_enc(url_ectx *ctx, dstr *d, char *name, char *value)
179 void url_initdec(url_dctx *ctx, char *p)
180 int url_dec(url_dctx *ctx, dstr *n, dstr *v)
181
579d0169 182#----- Atom stuff -----------------------------------------------------------
183
184# --- Atoms ---
185#
186# Partly written in `real' C.
187
188cdef extern from 'atom.h':
189 ctypedef struct atom:
190 pass
191 ctypedef struct atom_iter:
192 pass
193 ctypedef struct atom_table:
194 pass
195 atom_table *ATOM_GLOBAL
196 void atom_mkiter(atom_iter *i, atom_table *t)
197 atom *atom_next(atom_iter *)
198 void atom_pysetup()
199 atom_pywrap(atom *a)
200 atom_pyintern(obj)
201 atom *ATOM_A(obj)
202 PyTypeObject atom_pytype
203
204# --- Association tables ---
205
206cdef extern from 'mLib/assoc.h':
207 ctypedef struct assoc_table:
208 pass
209 ctypedef struct assoc_base:
210 pass
211 ctypedef struct assoc_iter:
212 pass
213 void assoc_create(assoc_table *t)
214 void assoc_destroy(assoc_table *t)
215 void *assoc_find(assoc_table *t, atom *a, int sz, unsigned *f)
216 void assoc_remove(assoc_table *t, void *b)
217 atom *ASSOC_ATOM(void *b)
218 void assoc_mkiter(assoc_iter *i, assoc_table *t)
219 void *assoc_next(assoc_iter *i)
220
221#----- Double-ended arrays --------------------------------------------------
222
223cdef extern from 'array.h':
224 void da_pysetup()
225 PyTypeObject da_pytype
226 PyTypeObject daiter_pytype
227
228#----- Line buffer ----------------------------------------------------------
229
230cdef extern from 'mLib/lbuf.h':
231 cdef struct lbuf:
232 int f
233 int delim
234 size_t sz
235 enum:
236 LBUF_ENABLE
237 _LBUF_CRLF "LBUF_CRLF"
238 _LBUF_STRICTCRLF "LBUF_STRICTCRLF"
239 void lbuf_flush(lbuf *b, char *p, size_t len)
240 void lbuf_close(lbuf *b)
241 size_t lbuf_free(lbuf *b, char **p)
242 void lbuf_setsize(lbuf *b, size_t sz)
243 void lbuf_enable(lbuf *b)
244 void lbuf_disable(lbuf *b)
245 void lbuf_init(lbuf *b,
246 void (*func)(char *s, size_t len, void *arg), void *arg)
247 void lbuf_destroy(lbuf *b)
248
249#----- Packet buffer --------------------------------------------------------
250
251cdef extern from 'mLib/pkbuf.h':
252 ctypedef struct pkbuf:
253 int f
254 int want
255 enum:
256 PKBUF_ENABLE
257 void pkbuf_flush(pkbuf *pk, unsigned char *p, size_t len)
258 void pkbuf_close(pkbuf *pk)
259 size_t pkbuf_free(pkbuf *pk, unsigned char **p)
260 void pkbuf_want(pkbuf *pk, size_t sz)
261 void pkbuf_init(pkbuf *b,
262 void (*func)(unsigned char *s, size_t len,
263 pkbuf *pk, size_t *keep, void *arg),
264 void *arg)
265 void pkbuf_destroy(pkbuf *b)
266
267#----- Select stuff ---------------------------------------------------------
268
269# --- Basics ---
270
271cdef extern from 'mLib/sel.h':
272 ctypedef struct sel_state:
273 pass
274 ctypedef struct sel_file:
275 int fd
276 ctypedef struct sel_timer:
277 pass
278 enum:
279 _SEL_READ "SEL_READ"
280 _SEL_WRITE "SEL_WRITE"
281 _SEL_EXC "SEL_EXC"
282 void sel_init(sel_state *s)
283 void sel_initfile(sel_state *s, sel_file *f, int fd, unsigned mode,
284 void (*func)(int fd, unsigned mode, void *arg),
285 void *arg)
286 void sel_force(sel_file *f)
287 void sel_addfile(sel_file *f)
288 void sel_rmfile(sel_file *f)
289 void sel_addtimer(sel_state *s, sel_timer *t, timeval *tv,
290 void (*func)(timeval *tv, void *arg),
291 void *arg)
292 void sel_rmtimer(sel_timer *t)
293 int sel_select(sel_state *s) except *
294
295# --- Non-blocking connection ---
296
297cdef extern from 'mLib/conn.h':
298 ctypedef struct conn:
299 pass
300 int conn_fd(conn *c, sel_state *s, int fd,
301 void (*func)(int fd, void *arg), void *arg)
302 void conn_kill(conn *c)
303
304# --- Background name resolver ---
305
306cdef extern from 'mLib/bres.h':
307 ctypedef struct bres_client:
308 pass
309 void bres_byname(bres_client *r, char *name,
310 void (*func)(hostent *h, void *arg), void *arg)
311 void bres_byaddr(bres_client *r, in_addr addr,
312 void (*func)(hostent *h, void *arg), void *arg)
313 void bres_abort(bres_client *r)
314 void bres_exec(char *null)
315 void bres_init(sel_state *s)
316
317# --- In-band signal handling ---
318
319cdef extern from 'mLib/sig.h':
320 ctypedef struct sig:
321 pass
322 void sig_add(sig *s, int n, void (*func)(int n, void *arg), void *arg)
323 void sig_remove(sig *s)
324 void sig_init(sel_state *s)
325
326# --- Line buffer ---
327
328cdef extern from 'mLib/selbuf.h':
329 ctypedef struct selbuf:
330 sel_file reader
331 lbuf b
332 void selbuf_enable(selbuf *b)
333 void selbuf_disable(selbuf *b)
334 void selbuf_setsize(selbuf *b, size_t sz)
335 void selbuf_init(selbuf *b, sel_state *s, int fd,
336 void (*func)(char *s, size_t len, void *arg), void *arg)
337 void selbuf_destroy(selbuf *b)
338
339# --- Packet buffer ---
340
341cdef extern from 'mLib/selpk.h':
342 ctypedef struct selpk:
343 sel_file reader
344 pkbuf pk
345 void selpk_enable(selpk *b)
346 void selpk_disable(selpk *b)
347 void selpk_want(selpk *b, size_t sz)
348 void selpk_init(selpk *b, sel_state *s, int fd,
349 void (*func)(unsigned char *p, size_t n,
350 pkbuf *pk, size_t *keep, void *arg),
351 void *arg)
352 void selpk_destroy(selpk *b)
353
354# --- Ident client ---
355
356cdef extern from 'mLib/ident.h':
357 ctypedef struct ident_request:
358 pass
359 enum:
360 IDENT_USERID
361 IDENT_ERROR
362 IDENT_BAD
363 struct ident_userid:
364 char *os
365 char *user
366 union ident_u:
367 ident_userid userid
368 char *error
369 ctypedef struct ident_reply:
370 int sport
371 int dport
372 int type
373 ident_u u
374 void ident(ident_request *rq, sel_state *s,
375 sockaddr_in *local, sockaddr_in *remote,
376 void (*func)(ident_reply *r, void *arg),
377 void *arg)
378 void ident_abort(ident_request *rq)
379
380#----- Error reporting ------------------------------------------------------
381
382cdef extern from 'mLib/quis.h':
383 void _ego "ego"(char *prog)
384 char *_quis "quis"()
385cdef extern from 'mLib/report.h':
386 void _moan "moan"(char *f, char *msg)
387
388#----- Internal utilities ---------------------------------------------------
389
390cdef extern from 'grim.h':
391 int PSIZEOF(void *x)
392
393#----- That's all, folks ----------------------------------------------------