source: squid-ssl/trunk/fuentes/src/esi/Context.h @ 5495

Last change on this file since 5495 was 5495, checked in by Juanma, 23 months ago

Initial release

File size: 4.7 KB
Line 
1/*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_ESICONTEXT_H
10#define SQUID_ESICONTEXT_H
11
12#include "clientStream.h"
13#include "err_type.h"
14#include "esi/Element.h"
15#include "esi/Parser.h"
16#include "HttpReply.h"
17#include "http/StatusCode.h"
18
19class ESIVarState;
20class ClientHttpRequest;
21
22/* ESIContext */
23
24class ESIContext : public esiTreeParent, public ESIParserClient
25{
26
27public:
28    typedef RefCount<ESIContext> Pointer;
29    ESIContext() :
30        thisNode(NULL),
31        http(NULL),
32        errorpage(ERR_NONE),
33        errorstatus(Http::scNone),
34        errormessage(NULL),
35        rep(NULL),
36        outbound_offset(0),
37        readpos(0),
38        pos(0),
39        varState(NULL),
40        cachedASTInUse(false),
41        reading_(true),
42        processing(false) {
43        memset(&flags, 0, sizeof(flags));
44    }
45
46    ~ESIContext();
47
48    enum esiKick_t {
49        ESI_KICK_FAILED,
50        ESI_KICK_PENDING,
51        ESI_KICK_SENT,
52        ESI_KICK_INPROGRESS
53    };
54
55    /* when esi processing completes */
56    void provideData(ESISegment::Pointer, ESIElement *source);
57    void fail (ESIElement *source, char const*anError = NULL);
58    void startRead();
59    void finishRead();
60    bool reading() const;
61    void setError();
62    void setErrorMessage(char const *);
63
64    void addStackElement (ESIElement::Pointer element);
65    void addLiteral (const char *s, int len);
66
67    void finishChildren ();
68
69    clientStreamNode *thisNode; /* our stream node */
70    /* the request we are processing. HMM: cbdataReferencing this will result
71     * in a circular reference, so we don't. Note: we are automatically freed
72     * when it is, so thats ok. */
73    ClientHttpRequest *http;
74
75    struct {
76        int passthrough:1;
77        int oktosend:1;
78        int finished:1;
79
80        /* an error has occured, send full body replies
81         * regardless. Note that we don't fail midstream
82         * because we buffer until we can not fail
83         */
84        int error:1;
85
86        int finishedtemplate:1; /* we've read the entire template */
87        int clientwantsdata:1; /* we need to satisfy a read request */
88        int kicked:1; /* note on reentering the kick routine */
89        int detached:1; /* our downstream has detached */
90    } flags;
91
92    err_type errorpage; /* if we error what page to use */
93    Http::StatusCode errorstatus; /* if we error, what code to return */
94    char *errormessage; /* error to pass to error page */
95    HttpReply::Pointer rep; /* buffered until we pass data downstream */
96    ESISegment::Pointer buffered; /* unprocessed data - for whatever reason */
97    ESISegment::Pointer incoming;
98    /* processed data we are waiting to send, or for
99     * potential errors to be resolved
100     */
101    ESISegment::Pointer outbound;
102    ESISegment::Pointer outboundtail; /* our write segment */
103    /* the offset to the next character to send -
104     * non zero if we haven't sent the entire segment
105     * for some reason
106     */
107    size_t outbound_offset;
108    int64_t readpos; /* the logical position we are reading from */
109    int64_t pos; /* the logical position of outbound_offset in the data stream */
110
111    class ParserState
112    {
113
114    public:
115        ESIElement::Pointer stack[10]; /* a stack of esi elements that are open */
116        int stackdepth; /* self explanatory */
117        ESIParser::Pointer theParser;
118        ESIElement::Pointer top();
119        void init (ESIParserClient *);
120        bool inited() const;
121        ParserState();
122        void freeResources();
123        void popAll();
124        int parsing:1; /* libexpat is not reentrant on the same context */
125
126    private:
127        bool inited_;
128    }
129
130    parserState; /* todo factor this off somewhere else; */
131    ESIVarState *varState;
132    ESIElement::Pointer tree;
133
134    esiKick_t kick ();
135    RefCount<ESIContext> cbdataLocker;
136    bool failed() const {return flags.error != 0;}
137
138    bool cachedASTInUse;
139
140private:
141    void fail ();
142    void freeResources();
143    void fixupOutboundTail();
144    void trimBlanks();
145    size_t send ();
146    bool reading_;
147    void appendOutboundData(ESISegment::Pointer theData);
148    esiProcessResult_t process ();
149    void parse();
150    void parseOneBuffer();
151    void updateCachedAST();
152    bool hasCachedAST() const;
153    void getCachedAST();
154    virtual void start(const char *el, const char **attr, size_t attrCount);
155    virtual void end(const char *el);
156    virtual void parserDefault (const char *s, int len);
157    virtual void parserComment (const char *s);
158    bool processing;
159
160    CBDATA_CLASS2(ESIContext);
161};
162
163#endif /* SQUID_ESICONTEXT_H */
164
Note: See TracBrowser for help on using the repository browser.