chiark / gitweb /
Merge branch 'master' of login.chiark.greenend.org.uk:public-git/inn-innduct
[inn-innduct.git] / include / storage.h
1 /*  $Id: storage.h 5933 2002-12-07 09:47:17Z rra $
2 **
3 **  Here be declarations related to the storage subsystem.
4 */
5
6 #ifndef __STORAGE_H__
7 #define __STORAGE_H__
8
9 /* We've probably already included this; only include it if we need it. */
10 #ifndef __CONFIG_H__
11 # include "config.h"
12 #endif
13
14 #include <stdio.h>
15 #include <sys/types.h>
16
17 #define STORAGE_TOKEN_LENGTH 16
18
19 /* This is the type of an empty token.  Tokens with this type will be
20    returned when errors occur */
21 #define TOKEN_EMPTY     255
22
23 typedef enum {RETR_ALL, RETR_HEAD, RETR_BODY, RETR_STAT} RETRTYPE;
24 typedef enum {SM_RDWR, SM_PREOPEN} SMSETUP;
25
26 #define NUM_STORAGE_CLASSES 256
27 typedef unsigned char STORAGECLASS;
28 typedef unsigned char STORAGETYPE;
29
30 typedef struct token {
31     STORAGETYPE         type;
32     STORAGECLASS        class;
33     char                token[STORAGE_TOKEN_LENGTH];
34 } TOKEN;
35
36 typedef struct {
37   unsigned char  type;       /* Method that retrieved the article */
38   const char     *data;      /* Where the requested data starts */
39   struct iovec   *iov;       /* writev() style vector */
40   int            iovcnt;     /* writev() style count */
41   size_t         len;        /* Length of the requested data */
42   unsigned char  nextmethod; /* Next method to try when iterating over the
43                                 spool */
44   void           *private;   /* A pointer to method specific data */
45   time_t         arrived;    /* The time when the article arrived */
46   time_t         expires;    /* The time when the article will be expired */
47   char           *groups;    /* Where Newsgroups header starts */
48   int            groupslen;  /* Length of Newsgroups header */
49   TOKEN          *token;     /* A pointer to the article's TOKEN */
50 } ARTHANDLE;
51  /* SMstore uses     iov*   but not data,len
52   * SMretrieve sets  type data,len private     data is in wire format
53   */
54
55 #define SMERR_NOERROR          0
56 #define SMERR_INTERNAL         1
57 #define SMERR_UNDEFINED        2
58 #define SMERR_NOENT            3
59 #define SMERR_TOKENSHORT       4
60 #define SMERR_NOBODY           5
61 #define SMERR_UNINIT           6
62 #define SMERR_CONFIG           7
63 #define SMERR_BADHANDLE        8
64 #define SMERR_BADTOKEN         9
65 #define SMERR_NOMATCH         10
66
67 extern int              SMerrno;
68 extern char             *SMerrorstr;
69
70 typedef enum {SELFEXPIRE, SMARTNGNUM, EXPENSIVESTAT} PROBETYPE;
71 typedef enum {SM_ALL, SM_HEAD, SM_CANCELEDART} FLUSHTYPE;
72
73 struct artngnum {
74     char        *groupname;
75     ARTNUM      artnum;
76 };
77
78 BEGIN_DECLS
79
80 char *      TokenToText(const TOKEN token);
81 TOKEN       TextToToken(const char *text);
82 bool        IsToken(const char *text);
83 char *      ToWireFmt(const char *article, size_t len, size_t *newlen);
84 char *      FromWireFmt(const char *article, size_t len, size_t *newlen);
85             
86 bool        SMsetup(SMSETUP type, void *value);
87 bool        SMinit(void);
88 TOKEN       SMstore(const ARTHANDLE article);
89 ARTHANDLE * SMretrieve(const TOKEN token, const RETRTYPE amount);
90 ARTHANDLE * SMnext(const ARTHANDLE *article, const RETRTYPE amount);
91 void        SMfreearticle(ARTHANDLE *article);
92 bool        SMcancel(TOKEN token);
93 bool        SMprobe(PROBETYPE type, TOKEN *token, void *value);
94 bool        SMflushcacheddata(FLUSHTYPE type);
95 void        SMprintfiles(FILE *file, TOKEN token, char **xref, int ngroups);
96 void        SMshutdown(void);
97
98 END_DECLS
99     
100 #endif