annotate dpi/dpiutil.h @ 0:6ee11bf9e3ea

Initial revision
author jcid
date Sun, 07 Oct 2007 00:36:34 +0200
parents
children 7a76f872ce73
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: dpiutil.h
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
4 * Copyright 2004-2005 Jorge Arellano Cid <jcid@dillo.org>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 * This file contains common functions used by dpi programs.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15 * (i.e. a convenience library).
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #ifndef __DPIUTIL_H__
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 #define __DPIUTIL_H__
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 #include <stdio.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include "d_size.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 #include "../dlib/dlib.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #ifdef __cplusplus
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 extern "C" {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 #endif /* __cplusplus */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 #define BUFLEN 256
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 #define TOUT 300
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 /* Streamed Sockets API (not mandatory) ----------------------------------*/
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 typedef struct _SockHandler SockHandler;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38 struct _SockHandler {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 int fd_in;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 int fd_out;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 /* FILE *in; --Unused. The stream functions block when reading. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 FILE *out;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 char *buf; /* internal buffer */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 uint_t buf_sz; /* data size */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 uint_t buf_max; /* allocated size */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 uint_t flush_sz; /* max size before flush */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 SockHandler *sock_handler_new(int fd_in, int fd_out, int flush_sz);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 int sock_handler_write(SockHandler *sh, int flush,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 const char *Data,size_t DataSize);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 int sock_handler_write_str(SockHandler *sh, int flush, const char *str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 char *sock_handler_read(SockHandler *sh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 void sock_handler_close(SockHandler *sh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 void sock_handler_free(SockHandler *sh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 #define sock_handler_printf(sh, flush, ...) \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 D_STMT_START { \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 Dstr *dstr = dStr_sized_new(128); \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 dStr_sprintf(dstr, __VA_ARGS__); \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 sock_handler_write(sh, flush, dstr->str, dstr->len); \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 dStr_free(dstr, 1); \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 } D_STMT_END
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 /* ----------------------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 * Escape URI characters in 'esc_set' as %XX sequences.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 * Return value: New escaped string.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 char *Escape_uri_str(const char *str, char *p_esc_set);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 * Escape unsafe characters as html entities.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 * Return value: New escaped string.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 char *Escape_html_str(const char *str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 * Unescape a few HTML entities (inverse of Escape_html_str)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 * Return value: New unescaped string.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 char *Unescape_html_str(const char *str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 * Filter an SMTP hack with a FTP URI
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89 char *Filter_smtp_hack(char *url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92 #ifdef __cplusplus
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 #endif /* __cplusplus */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 #endif /* __DPIUTIL_H__ */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97