]> git.ipfire.org Git - thirdparty/squid.git/blame - src/eCAP/XactionRep.cc
Synced with libecap changes related to FirstLine move to Message.
[thirdparty/squid.git] / src / eCAP / XactionRep.cc
CommitLineData
fdc96a39
AR
1#include "squid.h"
2#include <libecap/adapter/xaction.h>
3#include "TextException.h"
4#include "assert.h"
5#include "HttpRequest.h"
6#include "HttpReply.h"
7#include "eCAP/XactionRep.h"
8
9// CBDATA_CLASS_INIT(Ecap::XactionRep);
10// TODO: add CBDATA_NAMESPACED_CLASS_INIT(namespace, classname)
11cbdata_type Ecap::XactionRep::CBDATA_XactionRep = CBDATA_UNKNOWN;
12
13
14Ecap::XactionRep::XactionRep(Adaptation::Initiator *anInitiator,
15 HttpMsg *virginHeader, HttpRequest *virginCause,
16 const Adaptation::ServicePointer &aService):
17 AsyncJob("Ecap::XactionRep"),
18 Adaptation::Initiate("Ecap::XactionRep", anInitiator, aService),
19 theVirgin(virginHeader), theCause(virginCause),
027320b4
AR
20 theVirginRep(theVirgin, NULL), theCauseRep(NULL),
21 theAnswerRep(NULL)
fdc96a39 22{
027320b4
AR
23 if (virginCause)
24 theCauseRep = new MessageRep(theCause, NULL);
fdc96a39
AR
25}
26
27Ecap::XactionRep::~XactionRep()
28{
29 assert(!theMaster);
027320b4
AR
30 delete theCauseRep;
31 delete theAnswerRep;
fdc96a39
AR
32}
33
34void
35Ecap::XactionRep::master(const AdapterXaction &x)
36{
37 Must(!theMaster);
38 Must(x != NULL);
39 theMaster = x;
40}
41
42void
43Ecap::XactionRep::start()
44{
45 Must(theMaster);
46 theMaster->start();
47}
48
49void
50Ecap::XactionRep::swangSong()
51{
52 terminateMaster();
53 Adaptation::Initiate::swanSong();
54}
55
56void
57Ecap::XactionRep::terminateMaster()
58{
59 if (theMaster) {
60 AdapterXaction x = theMaster;
61 theMaster.reset();
62 x->stop();
63 }
64}
65
66libecap::Message &
027320b4 67Ecap::XactionRep::virgin()
fdc96a39 68{
7b67e5b6 69 return theVirginRep;
fdc96a39
AR
70}
71
027320b4
AR
72const libecap::Message *
73Ecap::XactionRep::cause()
fdc96a39 74{
7b67e5b6 75 return theCauseRep;
fdc96a39
AR
76}
77
78void
79Ecap::XactionRep::useVirgin()
80{
81 theMaster.reset();
027320b4
AR
82 Adaptation::Message::ShortCircuit(theVirgin, theAnswer);
83 Must(!theVirgin.body_pipe == !theAnswer.body_pipe);
fdc96a39
AR
84 sendAnswer(theAnswer.header);
85}
86
87void
027320b4 88Ecap::XactionRep::adaptVirgin()
fdc96a39 89{
027320b4
AR
90 // XXX: check state everywhere
91 Must(!theAnswerRep);
92 Must(!theAnswer.header);
93 Must(!theAnswer.body_pipe);
94 theAnswer.set(theVirgin.header->clone());
95 theAnswerRep = new MessageRep(theAnswer, this);
96 Must(!theAnswer.body_pipe);
fdc96a39
AR
97}
98
99void
027320b4 100Ecap::XactionRep::adaptNewRequest()
fdc96a39
AR
101{
102 theAnswer.set(new HttpRequest);
027320b4 103 theAnswerRep = new MessageRep(theAnswer, this);
fdc96a39
AR
104}
105
106void
027320b4 107Ecap::XactionRep::adaptNewResponse()
fdc96a39
AR
108{
109 theAnswer.set(new HttpReply);
027320b4 110 theAnswerRep = new MessageRep(theAnswer, this);
fdc96a39
AR
111}
112
027320b4
AR
113libecap::Message *
114Ecap::XactionRep::adapted()
fdc96a39 115{
7b67e5b6 116 return theAnswerRep;
fdc96a39
AR
117}
118
119void
120Ecap::XactionRep::useAdapted()
121{
122 theMaster.reset();
123 sendAnswer(theAnswer.header);
124}
125
126void
127Ecap::XactionRep::useNone()
128{
129 theMaster.reset();
130 tellQueryAborted(true); // should eCAP support retries?
131}
132
133void
134Ecap::XactionRep::noteMoreBodySpaceAvailable(RefCount<BodyPipe> bp)
135{
136 Must(theMaster);
137 theMaster->noteAdaptedSpaceAvailable();
138}
139
140void
141Ecap::XactionRep::noteBodyConsumerAborted(RefCount<BodyPipe> bp)
142{
143 Must(theMaster);
144 theMaster->noteAdaptedAborted();
145}
146
147void
148Ecap::XactionRep::noteMoreBodyDataAvailable(RefCount<BodyPipe> bp)
149{
150 Must(theMaster);
151 theMaster->noteVirginDataAvailable();
152}
153
154void
155Ecap::XactionRep::noteBodyProductionEnded(RefCount<BodyPipe> bp)
156{
157 Must(theMaster);
158 theMaster->noteVirginDataEnded();
159}
160
161void
162Ecap::XactionRep::noteBodyProducerAborted(RefCount<BodyPipe> bp)
163{
164 Must(theMaster);
165 theMaster->noteVirginAborted();
166}
167
168void
169Ecap::XactionRep::noteInitiatorAborted()
170{
171 mustStop("initiator aborted");
172}
173
174const char *Ecap::XactionRep::status() const
175{
176 return Adaptation::Initiate::status();
177}