"Fossies" - the Fresh Open Source Software Archive

Member "leafnode-1.12.0/leafnode.h" (28 Dec 2021, 12197 Bytes) of package /linux/misc/leafnode-1.12.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "leafnode.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.11.12_vs_1.12.0.

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