Add some CSP_FLAGs for the header parsers.
[privoxy.git] / pcrs.h
1 #ifndef PCRS_H_INCLUDED
2 #define PCRS_H_INCLUDED
3
4 /*********************************************************************
5  *
6  * File        :  $Source: /cvsroot/ijbswa/current/pcrs.h,v $
7  *
8  * Purpose     :  Header file for pcrs.c
9  *
10  * Copyright   :  see pcrs.c
11  *
12  * Revisions   :
13  *    $Log: pcrs.h,v $
14  *    Revision 1.14  2006/12/24 17:27:37  fabiankeil
15  *    Increase pcrs error code offset to prevent overlaps
16  *    with pcre versions newer than our own.
17  *
18  *    Revision 1.13  2006/07/18 14:48:47  david__schmidt
19  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
20  *    with what was really the latest development (the v_3_0_branch branch)
21  *
22  *    Revision 1.11  2002/03/08 14:18:23  oes
23  *    Fixing -Wconversion warnings
24  *
25  *    Revision 1.10  2002/03/08 13:44:48  oes
26  *    Hiding internal functions, preventing double inclusion of pcre.h
27  *
28  *    Revision 1.9  2001/08/18 11:35:29  oes
29  *    - Introduced pcrs_strerror()
30  *    - added pcrs_execute_list()
31  *
32  *    Revision 1.8  2001/08/15 15:32:50  oes
33  *    Replaced the hard limit for the maximum number of matches
34  *    by dynamic reallocation
35  *
36  *    Revision 1.7  2001/08/05 13:13:11  jongfoster
37  *    Making parameters "const" where possible.
38  *
39  *    Revision 1.6  2001/07/29 18:52:06  jongfoster
40  *    Renaming _PCRS_H, and adding "extern C {}"
41  *
42  *    Revision 1.5  2001/07/18 17:27:00  oes
43  *    Changed interface; Cosmetics
44  *
45  *    Revision 1.4  2001/06/29 13:33:19  oes
46  *    - Cleaned up, commented and adapted to reflect the
47  *      changes in pcrs.c
48  *    - Introduced the PCRS_* flags
49  *
50  *    Revision 1.3  2001/06/09 10:58:57  jongfoster
51  *    Removing a single unused #define which referenced BUFSIZ
52  *
53  *    Revision 1.2  2001/05/25 11:03:55  oes
54  *    Added sanity check for NULL jobs to pcrs_exec_substitution
55  *
56  *    Revision 1.1.1.1  2001/05/15 13:59:02  oes
57  *    Initial import of version 2.9.3 source tree
58  *
59  *    Revision 1.4  2001/05/11 01:57:02  rodney
60  *    Added new file header standard w/RCS control tags.
61  *
62  *    revision 1.3  2001/05/08 02:38:13  rodney
63  *    Changed C++ "//" style comment to C style comments.
64  *
65  *    revision 1.2  2001/04/30 02:39:24  rodney
66  *    Made this pcrs.h file conditionally included.
67  *
68  *    revision 1.1  2001/04/16 21:10:38  rodney
69  *    Initial checkin
70  *
71  *********************************************************************/
72
73 #define PCRS_H_VERSION "$Id: pcrs.h,v 1.14 2006/12/24 17:27:37 fabiankeil Exp $"
74 \f
75
76 #ifndef _PCRE_H
77 #include <pcre.h>
78 #endif
79
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83
84 /*
85  * Constants:
86  */
87
88 #define FALSE 0
89 #define TRUE 1
90
91 /* Capacity */
92 #define PCRS_MAX_SUBMATCHES  33     /* Maximum number of capturing subpatterns allowed. MUST be <= 99! FIXME: Should be dynamic */
93 #define PCRS_MAX_MATCH_INIT  40     /* Initial amount of matches that can be stored in global searches */
94 #define PCRS_MAX_MATCH_GROW  1.6    /* Factor by which storage for matches is extended if exhausted */
95
96 /*
97  * PCRS error codes
98  *
99  * They are supposed to be handled together with PCRE error
100  * codes and have to start with an offset to prevent overlaps.
101  *
102  * PCRE 6.7 uses error codes from -1 to -21, PCRS error codes
103  * below -100 should be safe for a while.
104  */
105 #define PCRS_ERR_NOMEM     -100      /* Failed to acquire memory. */
106 #define PCRS_ERR_CMDSYNTAX -101      /* Syntax of s///-command */
107 #define PCRS_ERR_STUDY     -102      /* pcre error while studying the pattern */
108 #define PCRS_ERR_BADJOB    -103      /* NULL job pointer, pattern or substitute */
109 #define PCRS_WARN_BADREF   -104      /* Backreference out of range */
110
111 /* Flags */
112 #define PCRS_GLOBAL          1      /* Job should be applied globally, as with perl's g option */
113 #define PCRS_TRIVIAL         2      /* Backreferences in the substitute are ignored */
114 #define PCRS_SUCCESS         4      /* Job did previously match */
115
116
117 /*
118  * Data types:
119  */
120
121 /* A compiled substitute */
122
123 typedef struct {
124   char  *text;                                   /* The plaintext part of the substitute, with all backreferences stripped */
125   size_t length;                                 /* The substitute may not be a valid C string so we can't rely on strlen(). */
126   int    backrefs;                               /* The number of backreferences */
127   int    block_offset[PCRS_MAX_SUBMATCHES];      /* Array with the offsets of all plaintext blocks in text */
128   size_t block_length[PCRS_MAX_SUBMATCHES];      /* Array with the lengths of all plaintext blocks in text */
129   int    backref[PCRS_MAX_SUBMATCHES];           /* Array with the backref number for all plaintext block borders */
130   int    backref_count[PCRS_MAX_SUBMATCHES + 2]; /* Array with the number of references to each backref index */
131 } pcrs_substitute;
132
133
134 /*
135  * A match, including all captured subpatterns (submatches)
136  * Note: The zeroth is the whole match, the PCRS_MAX_SUBMATCHES + 0th
137  * is the range before the match, the PCRS_MAX_SUBMATCHES + 1th is the
138  * range after the match.
139  */
140
141 typedef struct {
142   int    submatches;                               /* Number of captured subpatterns */
143   int    submatch_offset[PCRS_MAX_SUBMATCHES + 2]; /* Offset for each submatch in the subject */
144   size_t submatch_length[PCRS_MAX_SUBMATCHES + 2]; /* Length of each submatch in the subject */
145 } pcrs_match;
146
147
148 /* A PCRS job */
149
150 typedef struct PCRS_JOB {
151   pcre *pattern;                            /* The compiled pcre pattern */
152   pcre_extra *hints;                        /* The pcre hints for the pattern */
153   int options;                              /* The pcre options (numeric) */
154   int flags;                                /* The pcrs and user flags (see "Flags" above) */
155   pcrs_substitute *substitute;              /* The compiled pcrs substitute */
156   struct PCRS_JOB *next;                    /* Pointer for chaining jobs to joblists */
157 } pcrs_job;
158
159
160 /*
161  * Prototypes:
162  */
163
164 /* Main usage */
165 extern pcrs_job        *pcrs_compile_command(const char *command, int *errptr);
166 extern pcrs_job        *pcrs_compile(const char *pattern, const char *substitute, const char *options, int *errptr);
167 extern int              pcrs_execute(pcrs_job *job, char *subject, size_t subject_length, char **result, size_t *result_length);
168 extern int              pcrs_execute_list(pcrs_job *joblist, char *subject, size_t subject_length, char **result, size_t *result_length);
169
170 /* Freeing jobs */
171 extern pcrs_job        *pcrs_free_job(pcrs_job *job);
172 extern void             pcrs_free_joblist(pcrs_job *joblist);
173
174 /* Info on errors: */
175 extern const char *pcrs_strerror(const int error);
176
177
178 #ifdef __cplusplus
179 } /* extern "C" */
180 #endif
181
182 #endif /* ndef PCRS_H_INCLUDED */
183
184 /*
185   Local Variables:
186   tab-width: 3
187   end:
188 */