chiark / gitweb /
Rerun autoconf2.13 on etch and consequently refresh configure-hostname patch
[inn-innduct.git] / include / libinn.h
1 /*  $Id: libinn.h 6135 2003-01-19 01:15:40Z rra $
2 **
3 **  Here be declarations of functions in the InterNetNews library.
4 */
5
6 #ifndef LIBINN_H
7 #define LIBINN_H 1
8
9 #include "inn/defines.h"
10
11 /* Eventually we don't want to include this, since this will be an installed
12    header and we don't want to install config.h. */
13 #include "config.h"
14
15 #include <stdio.h>              /* FILE */
16 #include <sys/types.h>          /* size_t and ssize_t */
17
18 /* Forward declarations to avoid unnecessary includes. */
19 struct stat;
20 struct iovec;
21 struct sockaddr;
22 struct sockaddr_in;
23 struct in_addr;
24
25 BEGIN_DECLS
26
27 /*
28 **  MEMORY MANAGEMENT
29 */
30
31 /* The functions are actually macros so that we can pick up the file and line
32    number information for debugging error messages without the user having to
33    pass those in every time. */
34 #define xcalloc(n, size)        x_calloc((n), (size), __FILE__, __LINE__)
35 #define xmalloc(size)           x_malloc((size), __FILE__, __LINE__)
36 #define xrealloc(p, size)       x_realloc((p), (size), __FILE__, __LINE__)
37 #define xstrdup(p)              x_strdup((p), __FILE__, __LINE__)
38 #define xstrndup(p, size)       x_strndup((p), (size), __FILE__, __LINE__)
39
40 /* Last two arguments are always file and line number.  These are internal
41    implementations that should not be called directly.  ISO C99 says that
42    identifiers beginning with _ and a lowercase letter are reserved for
43    identifiers of file scope, so while the position of libraries in the
44    standard isn't clear, it's probably not entirely kosher to use _xmalloc
45    here.  Use x_malloc instead. */
46 extern void *x_calloc(size_t, size_t, const char *, int);
47 extern void *x_malloc(size_t, const char *, int);
48 extern void *x_realloc(void *, size_t, const char *, int);
49 extern char *x_strdup(const char *, const char *, int);
50 extern char *x_strndup(const char *, size_t, const char *, int);
51
52 /* Failure handler takes the function, the size, the file, and the line. */
53 typedef void (*xmalloc_handler_t)(const char *, size_t, const char *, int);
54
55 /* The default error handler. */
56 void xmalloc_fail(const char *, size_t, const char *, int);
57
58 /* Assign to this variable to choose a handler other than the default, which
59    just calls sysdie. */
60 extern xmalloc_handler_t xmalloc_error_handler;
61
62
63 /*
64 **  TIME AND DATE PARSING, GENERATION, AND HANDLING
65 */
66 typedef struct _TIMEINFO {
67     time_t      time;
68     long        usec;
69     long        tzone;
70 } TIMEINFO;
71
72 extern int      GetTimeInfo(TIMEINFO *Now);
73 extern bool     makedate(time_t, bool local, char *buff, size_t buflen);
74 extern time_t   parsedate(char *p, TIMEINFO *now);
75 extern time_t   parsedate_nntp(const char *, const char *, bool local);
76 extern time_t   parsedate_rfc2822(const char *);
77
78
79 /*
80 **  VERSION INFORMATION
81 */
82 extern const int        inn_version[3];
83 extern const char       inn_version_extra[];
84 extern const char       inn_version_string[];
85
86 /* Earlier versions of INN didn't have <inn/version.h> and some source is
87    intended to be portable to different INN versions; it can use this macro
88    to determine whether <inn/version.h> is available. */
89 #define HAVE_INN_VERSION_H 1
90
91
92 /*
93 **  WILDMAT MATCHING
94 */
95 enum uwildmat {
96     UWILDMAT_FAIL   = 0,
97     UWILDMAT_MATCH  = 1,
98     UWILDMAT_POISON
99 };
100
101 extern bool             uwildmat(const char *text, const char *pat);
102 extern bool             uwildmat_simple(const char *text, const char *pat);
103 extern enum uwildmat    uwildmat_poison(const char *text, const char *pat);
104
105
106 /*
107 **  FILE LOCKING
108 */
109 enum inn_locktype {
110     INN_LOCK_READ,
111     INN_LOCK_WRITE,
112     INN_LOCK_UNLOCK
113 };
114
115 extern bool     inn_lock_file(int fd, enum inn_locktype type, bool block);
116 extern bool     inn_lock_range(int fd, enum inn_locktype type, bool block,
117                                off_t offset, off_t size);
118
119
120 /*
121 **  MISCELLANEOUS UTILITY FUNCTIONS
122 */
123 extern void     close_on_exec(int fd, bool flag);
124 extern char *   concat(const char *first, ...);
125 extern char *   concatpath(const char *base, const char *name);
126 extern void     daemonize(const char *path);
127 extern int      getfdlimit(void);
128 extern int      nonblocking(int fd, bool flag);
129 extern int      setfdlimit(unsigned int limit);
130 extern ssize_t  xpwrite(int fd, const void *buffer, size_t size, off_t offset);
131 extern void     (*xsignal(int signum, void (*sigfunc)(int)))(int);
132 extern void     (*xsignal_norestart(int signum, void (*sigfunc)(int)))(int);
133 extern ssize_t  xwrite(int fd, const void *buffer, size_t size);
134 extern ssize_t  xwritev(int fd, const struct iovec *iov, int iovcnt);
135
136
137 /* Headers. */
138 extern char *           GenerateMessageID(char *domain);
139 extern void             HeaderCleanFrom(char *from);
140 extern struct _DDHANDLE * DDstart(FILE *FromServer, FILE *ToServer);
141 extern void               DDcheck(struct _DDHANDLE *h, char *group);
142 extern char *             DDend(struct _DDHANDLE *h);
143
144 /* NNTP functions. */
145 extern int      NNTPlocalopen(FILE **FromServerp, FILE **ToServerp,
146                               char *errbuff);
147 extern int      NNTPremoteopen(int port, FILE **FromServerp,
148                                FILE **ToServerp, char *errbuff);
149 extern int      NNTPconnect(char *host, int port, FILE **FromServerp,
150                             FILE **ToServerp, char *errbuff);
151 extern int      NNTPsendarticle(char *, FILE *F, bool Terminate);
152 extern int      NNTPsendpassword(char *server, FILE *FromServer,
153                                  FILE *ToServer);
154
155 /* clientlib compatibility functions. */
156 extern char *   getserverbyfile(char *file);
157 extern int      server_init(char *host, int port);
158 extern int      handle_server_response(int response, char *host);
159 extern void     put_server(const char *text);
160 extern int      get_server(char *buff, int buffsize);
161 extern void     close_server(void);
162
163 /* Opening the active file on a client. */
164 extern FILE *   CAopen(FILE *FromServer, FILE *ToServer);
165 extern FILE *   CAlistopen(FILE *FromServer, FILE *ToServer,
166                            const char *request);
167 extern FILE *   CA_listopen(char *pathname, FILE *FromServer, FILE *ToServer,
168                             const char *request);
169 extern void     CAclose(void);
170
171 extern char *    GetFQDN(char *domain);
172 extern char *    GetModeratorAddress(FILE *FromServer, FILE *ToServer,
173                                      char *group, char *moderatormailer); 
174
175 #define TEMPORARYOPEN   0
176 #define INND_HISTORY    1
177 #define INND_HISLOG     2
178 #define DBZ_DIR         3
179 #define DBZ_BASE        4
180
181 /* Hash functions */
182 typedef struct {
183     char        hash[16];
184 } HASH;
185 extern HASH     Hash(const void *value, const size_t len);
186 /* Return the hash of a case mapped message-id */
187 extern HASH     HashMessageID(const char *MessageID);
188 extern bool     HashEmpty(const HASH hash);
189 extern void     HashClear(HASH *hash);
190 extern char *   HashToText(const HASH hash);
191 extern HASH     TextToHash(const char *text);
192 extern int      HashCompare(const HASH *h1, const HASH *h2);
193
194 /* Miscellaneous. */
195 extern int      dbzneedfilecount(void);
196 extern bool     MakeDirectory(char *Name, bool Recurse);
197 extern int      xread(int fd, char *p, off_t i);
198 extern int      GetResourceUsage(double *usertime, double *systime);
199 extern void     Radix32(unsigned long, char *buff);
200 extern char *   ReadInDescriptor(int fd, struct stat *Sbp);
201 extern char *   ReadInFile(const char *name, struct stat *Sbp);
202 extern FILE *   xfopena(const char *p);
203 extern bool     fdreserve(int fdnum);
204 extern FILE *   Fopen(const char *p, const char *type, int fd);
205 extern int      Fclose(FILE *fp);
206 extern char *   sprint_sockaddr(const struct sockaddr *sa);
207 extern void     make_sin(struct sockaddr_in *s, const struct in_addr *src);
208
209 END_DECLS
210
211 /* <ctype.h>'s isspace includes \n, which is not what we want. */
212 #define ISWHITE(c)              ((c) == ' ' || (c) == '\t')
213
214 #endif /* LIBINN_H */