1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
|
/*
* This file is copyrighted material. See the file COPYING for licensing
* conditions.
*/
/* $Id: leafnode.h,v 1.95 2008/08/07 20:19:41 emma Exp $ */
#ifndef LEAFNODE_H
#define LEAFNODE_H
#include "config.h"
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#include "critmem.h"
/* I wish the world were a happy place */
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#define PLURAL(no) (((no) == 1) ? "" : "s")
/* limits.h may contain PATH_MAX but shall not if the system has variable
* length limits here */
#include <limits.h>
#ifndef PATH_MAX
/* just some random limit - we'll use this as a starting point
* for dynamically growing memory only */
#define PATH_MAX 4096
#endif
#define PORTFILENAMECSET "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-"
#include <pcre.h>
#include <stdarg.h> /* va_list */
#include <stdio.h> /* FILE * */
#include <setjmp.h> /* sigjmp_buf */
#include "system.h" /* time.h */
#ifdef HAVE_AP_CONFIG_H
#define AP_CONFIG_H
#endif
#include <errno.h>
/* from strdup.c */
#ifndef HAVE_STRDUP
char *strdup(const char *);
#endif
/* from snprintf.c */
#ifndef HAVE_WORKING_SNPRINTF
int ln_snprintf(char *str, size_t n, const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format(printf, 3, 4)))
#endif
;
int ln_vsnprintf(char *str, size_t n, const char *format, va_list ap);
#define snprintf ln_snprintf
#define vsnprintf ln_vsnprintf
#endif
int xsnprintf(/*@out@*/ char *str, size_t n, const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format(printf, 3, 4)))
#endif
;
/* map LOG_NEWS onto LOG_DAEMON where the former doesn't exist */
#include <syslog.h>
#if !defined( LOG_NEWS )
#define LOG_NEWS LOG_DAEMON
#endif
/* define LOG_CONS if missing */
#if !defined( LOG_CONS )
#define LOG_CONS 0 /* if it isn't supported, make do without */
#endif
#define SECONDS_PER_DAY ( 24L * 60 * 60 )
/* Limit on the number of message bodies marked for download per group. */
#define BODY_DOWNLOAD_LIMIT 2048
/* initialize global variables */
int initvars(char *progname);
/* converts a message-id to a file name, the return value points into
a static array */
#define LOOKUP_FREE ((const char *)-2)
/*@dependent@*/ const char *lookup(const char *msgid);
/*@dependent@*/
char *getaline(FILE * f); /* reads one line, regardless of length */
/*@dependent@*/
char *mgetaline(FILE * f); /* dito, with timeout */
void mgetaline_settimeout(unsigned int); /* set timeout for mgetaline */
extern sigjmp_buf timeout;
extern void timer(int sig);
/* changes (and optionally creates) directory */
int chdirgroup(const char *group, int creatdir);
/*
* newsgroup management
*/
struct newsgroup {
unsigned long first;
unsigned long last;
char *name;
char *desc;
time_t age;
};
int isinteresting(const char *groupname);
void insertgroup(const char *name, long unsigned first, long unsigned last,
time_t date);
extern void changegroupdesc(const char *groupname, const char *description);
extern void newgroupdesc(const char *groupname, const char *description);
void mergegroups(void);
/*@null@*//*@dependent@*/
struct newsgroup *xfindgroup(struct newsgroup *active, const char *name,
unsigned long size);
/*@null@*//*@dependent@*/
struct newsgroup *findgroup(const char *name);
void readactive(void);
int writeactive(void);
void fakeactive(void);
void freeactive(/*@null@*/ struct newsgroup *act);
extern char *activeread(void);
extern int killactiveread(void);
extern size_t activesize;
/*@null@*/ extern struct newsgroup *active;
extern size_t oldactivesize;
/*@null@*/ extern struct newsgroup *oldactive;
/* translation from message-id to article number, used in fetch and expire */
void clearidtree(void);
void insertmsgid( /*@unique@*/ const char *msgid);
int findmsgid(const char *msgid);
typedef int (*tmihook)(const char *);
int traverseidtree(tmihook h);
/* -----------here starts the new stuff-----------------*/
/*
* a linear list of strings
*/
struct stringlist {
struct stringlist *next;
char string[1];
};
void
prependtolist(struct stringlist **list, /*@unique@*/ const char *newentry);
/*@null@*//*@dependent@*/
struct stringlist **lfindinlist(struct stringlist **haystack, char *needle, size_t len);
/* find a stringlist element by doing a linear search */
char *findinlist(struct stringlist *haystack, char *needle);
/* find a string in a stringlist by doing a linear search */
void freelist( /*@only@*/ struct stringlist *list);
/* free memory occupied by a stringlist */
/*
* filterfile.c -- PCRE filtering of articles
*/
void readfilter(char *filterfile);
void freefilter(void);
int dofilter(char *h);
/*
* artutil.c -- handling article files
*/
void store(const char *filename,
FILE * filehandle, const char *newsgroups, const char *msgid);
/*
* find a certain header in an article and return it
*/
/*@null@*//*@only@*/ char *getheader(const char *filename, const char *header);
/*@null@*//*@only@*/ char *fgetheader(FILE * f, const char *header);
/*
* the strings in config.c
*/
extern const char *spooldir;
extern const char *sysconfdir;
extern const char *version;
extern const char *lockfile;
/*
* global variables from config file. These are defined in configutil.c
*/
struct expire_entry {
struct expire_entry *next;
char *group;
time_t xtime;
int days;
};
struct server {
struct server *next;
char *name; /* Servername */
char *username;
char *password;
pcre *group_pcre;
unsigned int port;
int descriptions; /* download descriptions as well */
int timeout; /* timeout in seconds before we give up */
int nopost; /* if set, do not try to post to this server */
int noread; /* if set, do not try to fetch articles from
this server */
int updateactive; /* update the active file of this server, BITFIELD: 1 = from command line, 2 = automatically set */
int post_anygroup; /* if set, do not check if the group is on the
server, but just post */
int noxover; /* if set, use XHDR for overview */
int only_groups_match_all; /* if set, any unmatched group (refer to
group_pcre) prevents the post */
};
extern int date_is_evil; /* skip DATE check on servers known bad */
extern int stat_is_evil; /* use HEAD instead of STAT to figure if a
posting is available upstream, workaround for broken NewsCache */
extern time_t expire; /* articles not touched since this time get deleted */
extern int expiredays;
extern struct expire_entry *expire_base;
/* expire for certain groups */
extern unsigned long artlimit; /* max # of articles to read per group in one go */
extern unsigned long initiallimit;
/* max # of articles to read at first time */
extern long crosspostlimit;
/* crossposting limit, to reduce spam */
extern int delaybody; /* delay download of message body */
extern int db_situ; /* delaybody: keep original article number */
extern int debugmode; /* log lots of stuff via syslog */
extern int create_all_links;
/* store articles even in uninteresting groups */
extern int maxage; /* max age of articles */
extern long maxlines; /* max length of articles in lines */
extern long minlines; /* min length of articles in lines */
extern unsigned long maxbytes; /* max length of articles in bytes */
extern int timeout_short; /* don't fetch groups that have been
accidentally accessed after that many days */
extern int timeout_long; /* don't fetch groups that have been accessed
that many days */
extern int timeout_active; /* reread active file after that many days */
extern int timeout_client; /* activity timeout for clients in seconds */
extern int timeout_fetchnews; /* response deadline for upstream in seconds */
extern int clamp_maxage; /* limit maxage to applicable group/global expire? */
extern int article_despite_filter; /* request and discard body if filterfile is defined, for high-latency, high-throughput links */
extern char *filterfile; /* filename where filter resides */
extern struct server *servers; /* list of servers to use */
extern int allowstrangers; /* if addresses not local to our links
are allowed to connect */
extern int allow_8bit_headers; /* if 8bit junk in headers is allowed */
extern char *newsadmin; /* address of news administrator, default: news@%s with %s = fqdn */
extern unsigned long timeout_lock; /* lock file timeout */
/*
* other global variables
*/
#define SIZE_lineout 1024
extern char last_command[SIZE_lineout + 1];
extern char lineout[SIZE_lineout + 1];
/* defined in nntputil.c */
extern /*@relnull@*/ /*@dependent@*/ FILE *nntpin;
extern /*@relnull@*/ /*@dependent@*/ FILE *nntpout;
#define SIZE_s (8192)
#define FQDNLEN 255
extern char fqdn[FQDNLEN + 1]; /* my name, and my naming myself */
extern int verbose; /* verbosity level, for fetch and texpire */
extern int debug; /* debug level */
/*
* misc prototypes
*/
int try_lock(unsigned long);
int handover_lock(pid_t);
void putaline(void);
void retry(void);
void readexpire(void);
int readconfig(int logtostderr);
void freeexpire(void);
void freeservers(void);
void freeconfig(void);
void lowercase(char *string);
int ngmatch(const char *pattern, const char *string);
void overrun(void);
void replaceinlist(struct stringlist **haystack, char *needle, size_t len);
time_t lookup_expire(char *group);
int lookup_expiredays(char *group);
int log_unlink(const char *f, int ignore_enoent);
/* int rename(const char *old, const char *new); */
/* to avoid barfing of Digital Unix */
/*
* stuff from nntputil.c
*/
int authenticate(const struct server*); /* authenticate ourselves at a server */
/*@dependent@*//*@null@*/
char *lastreply(void); /* last line frpm nntpreply */
int nntpreply(const struct server*); /* decode an NNTP reply number */
int nntpconnect(const struct server *upstream);
/* connect to upstream server */
void nntpdisconnect(void); /* disconnect from upstream server */
void nntpquit(void); /* send QUIT, then disconnect from upstream server */
void freelastreply(void);
/*@dependent@*/
const char *rfctime(void); /* An rfc type date */
int safe_mkstemp(char *); /* permission safe mkstemp wrapper */
/* from syslog.c */
void myopenlog(const char *ident);
/* from mkstemp.c */
#ifndef HAVE_MKSTEMP
int mkstemp(char *);
#endif
/* from getline.c */
#ifndef HAVE_GETLINE
ssize_t getline(char **, size_t *, FILE *); /* fgets replacement */
#endif
void freegetaline(void);
#ifndef HAVE_TIMEGM
time_t timegm(struct tm *tm);
#endif
/* from wildmat.c */
int wildmat(const char *, const char *);
/* from getfoldedline.c */
/*@null@*/ /*@only@*/
char *getfoldedline(FILE * f, char *(*reader)(FILE *));
/* reads one line, regardless of length, returns malloc()ed string! */
/* from writes.c (ln-2) */
ssize_t writes(int fd, const char *string);
void fixxover(void);
/* from grouplist.c */
/*@null@*/ struct stringlist *get_grouplist(void);
/* checkpeerlocal.c */
int checkpeerlocal(int sock);
/* pcre_extract.c */
int pcre_extract(const char *input, const char *pattern, /*@out@*/ char **output, size_t num);
void pcre_extract_free(char **vec, int count);
size_t xstrlcpy(/*@out@*/ char *dst, const char *src, size_t size);
/* xoverutil.c */
struct xoverinfo {
char *text;
int exists;
};
/*@null@*/ extern struct xoverinfo *xoverinfo;
extern unsigned long xfirst;
extern unsigned long xlast;
int getxover(void); /* set xoverinfo, return 0 on error, nonzero else */
int legalxoverline(const char *xover, /*@out@*/ const char **errmsg);
void freexover(void);
/* agetcwd.c */
int agetcwd(/*@out@*/ char **buf, /*@out@*/ size_t *capa);
#ifdef CHECKGROUPORDER
void checkgrouporder(void);
#endif /* CHECKGROUPORDER */
#define SKIPLWS(p) while (*(p) && isspace((unsigned char) *(p))) { (p)++; }
#endif /* #ifndef LEAFNODE_H */
|