1 /* $Id: libinn.h 6135 2003-01-19 01:15:40Z rra $
3 ** Here be declarations of functions in the InterNetNews library.
9 #include "inn/defines.h"
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. */
15 #include <stdio.h> /* FILE */
16 #include <sys/types.h> /* size_t and ssize_t */
18 /* Forward declarations to avoid unnecessary includes. */
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__)
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);
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);
55 /* The default error handler. */
56 void xmalloc_fail(const char *, size_t, const char *, int);
58 /* Assign to this variable to choose a handler other than the default, which
60 extern xmalloc_handler_t xmalloc_error_handler;
64 ** TIME AND DATE PARSING, GENERATION, AND HANDLING
66 typedef struct _TIMEINFO {
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 *);
80 ** VERSION INFORMATION
82 extern const int inn_version[3];
83 extern const char inn_version_extra[];
84 extern const char inn_version_string[];
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
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);
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);
121 ** MISCELLANEOUS UTILITY FUNCTIONS
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);
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);
144 /* NNTP functions. */
145 extern int NNTPlocalopen(FILE **FromServerp, FILE **ToServerp,
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,
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);
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);
171 extern char * GetFQDN(char *domain);
172 extern char * GetModeratorAddress(FILE *FromServer, FILE *ToServer,
173 char *group, char *moderatormailer);
175 #define TEMPORARYOPEN 0
176 #define INND_HISTORY 1
177 #define INND_HISLOG 2
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);
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);
211 /* <ctype.h>'s isspace includes \n, which is not what we want. */
212 #define ISWHITE(c) ((c) == ' ' || (c) == '\t')
214 #endif /* LIBINN_H */