~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/esi/Context.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id$
 
3
 *
 
4
 *
 
5
 * SQUID Web Proxy Cache          http://www.squid-cache.org/
 
6
 * ----------------------------------------------------------
 
7
 *
 
8
 *  Squid is the result of efforts by numerous individuals from
 
9
 *  the Internet community; see the CONTRIBUTORS file for full
 
10
 *  details.   Many organizations have provided support for Squid's
 
11
 *  development; see the SPONSORS file for full details.  Squid is
 
12
 *  Copyrighted (C) 2001 by the Regents of the University of
 
13
 *  California; see the COPYRIGHT file for full details.  Squid
 
14
 *  incorporates software developed and/or copyrighted by other
 
15
 *  sources; see the CREDITS file for full details.
 
16
 *
 
17
 *  This program is free software; you can redistribute it and/or modify
 
18
 *  it under the terms of the GNU General Public License as published by
 
19
 *  the Free Software Foundation; either version 2 of the License, or
 
20
 *  (at your option) any later version.
 
21
 *
 
22
 *  This program is distributed in the hope that it will be useful,
 
23
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
24
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
25
 *  GNU General Public License for more details.
 
26
 *
 
27
 *  You should have received a copy of the GNU General Public License
 
28
 *  along with this program; if not, write to the Free Software
 
29
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 
30
 *
 
31
 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
 
32
 */
 
33
 
 
34
#ifndef SQUID_ESICONTEXT_H
 
35
#define SQUID_ESICONTEXT_H
 
36
 
 
37
#include "esi/Element.h"
 
38
#include "clientStream.h"
 
39
 
 
40
class ESIVarState;
 
41
 
 
42
class ClientHttpRequest;
 
43
 
 
44
#include "esi/Parser.h"
 
45
 
 
46
/* ESIContext */
 
47
 
 
48
class ESIContext : public esiTreeParent, public ESIParserClient
 
49
{
 
50
 
 
51
public:
 
52
    typedef RefCount<ESIContext> Pointer;
 
53
    void *operator new (size_t byteCount);
 
54
    void operator delete (void *address);
 
55
    ESIContext():reading_(true) {}
 
56
 
 
57
    ~ESIContext();
 
58
 
 
59
    enum esiKick_t {
 
60
        ESI_KICK_FAILED,
 
61
        ESI_KICK_PENDING,
 
62
        ESI_KICK_SENT,
 
63
        ESI_KICK_INPROGRESS
 
64
    };
 
65
 
 
66
    /* when esi processing completes */
 
67
    void provideData(ESISegment::Pointer, ESIElement *source);
 
68
    void fail (ESIElement *source, char const*anError = NULL);
 
69
    void startRead();
 
70
    void finishRead();
 
71
    bool reading() const;
 
72
    void setError();
 
73
    void setErrorMessage(char const *);
 
74
 
 
75
    void addStackElement (ESIElement::Pointer element);
 
76
    void addLiteral (const char *s, int len);
 
77
 
 
78
    void finishChildren ();
 
79
 
 
80
    clientStreamNode *thisNode; /* our stream node */
 
81
    /* the request we are processing. HMM: cbdataReferencing this will result
 
82
     * in a circular reference, so we don't. Note: we are automatically freed
 
83
     * when it is, so thats ok. */
 
84
    ClientHttpRequest *http;
 
85
 
 
86
    struct {
 
87
        int passthrough:1;
 
88
        int oktosend:1;
 
89
        int finished:1;
 
90
 
 
91
        /* an error has occured, send full body replies
 
92
         * regardless. Note that we don't fail midstream
 
93
         * because we buffer until we can not fail
 
94
         */
 
95
        int error:1;
 
96
 
 
97
        int finishedtemplate:1; /* we've read the entire template */
 
98
        int clientwantsdata:1; /* we need to satisfy a read request */
 
99
        int kicked:1; /* note on reentering the kick routine */
 
100
        int detached:1; /* our downstream has detached */
 
101
    } flags;
 
102
 
 
103
    err_type errorpage; /* if we error what page to use */
 
104
    http_status errorstatus; /* if we error, what code to return */
 
105
    char *errormessage; /* error to pass to error page */
 
106
    HttpReply *rep; /* buffered until we pass data downstream */
 
107
    ESISegment::Pointer buffered; /* unprocessed data - for whatever reason */
 
108
    ESISegment::Pointer incoming;
 
109
    /* processed data we are waiting to send, or for
 
110
     * potential errors to be resolved
 
111
     */
 
112
    ESISegment::Pointer outbound;
 
113
    ESISegment::Pointer outboundtail; /* our write segment */
 
114
    /* the offset to the next character to send -
 
115
     * non zero if we haven't sent the entire segment
 
116
     * for some reason
 
117
     */
 
118
    size_t outbound_offset;
 
119
    int64_t readpos; /* the logical position we are reading from */
 
120
    int64_t pos; /* the logical position of outbound_offset in the data stream */
 
121
 
 
122
    class ParserState
 
123
    {
 
124
 
 
125
    public:
 
126
        ESIElement::Pointer stack[10]; /* a stack of esi elements that are open */
 
127
        int stackdepth; /* self explanatory */
 
128
        ESIParser::Pointer theParser;
 
129
        ESIElement::Pointer top();
 
130
        void init (ESIParserClient *);
 
131
        bool inited() const;
 
132
        ParserState();
 
133
        void freeResources();
 
134
        void popAll();
 
135
        int parsing:1; /* libexpat is not reentrant on the same context */
 
136
 
 
137
    private:
 
138
        bool inited_;
 
139
    }
 
140
 
 
141
    parserState; /* todo factor this off somewhere else; */
 
142
    ESIVarState *varState;
 
143
    ESIElement::Pointer tree;
 
144
 
 
145
    esiKick_t kick ();
 
146
    RefCount<ESIContext> cbdataLocker;
 
147
    bool failed() const {return flags.error != 0;}
 
148
 
 
149
    bool cachedASTInUse;
 
150
 
 
151
private:
 
152
    CBDATA_CLASS(ESIContext);
 
153
    void fail ();
 
154
    void freeResources();
 
155
    void fixupOutboundTail();
 
156
    void trimBlanks();
 
157
    size_t send ();
 
158
    bool reading_;
 
159
    void appendOutboundData(ESISegment::Pointer theData);
 
160
    esiProcessResult_t process ();
 
161
    void parse();
 
162
    void parseOneBuffer();
 
163
    void updateCachedAST();
 
164
    bool hasCachedAST() const;
 
165
    void getCachedAST();
 
166
    virtual void start(const char *el, const char **attr, size_t attrCount);
 
167
    virtual void end(const char *el);
 
168
    virtual void parserDefault (const char *s, int len);
 
169
    virtual void parserComment (const char *s);
 
170
    bool processing;
 
171
};
 
172
 
 
173
#endif /* SQUID_ESICONTEXT_H */