]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ICAP/ICAPOptXact.cc
2 * DEBUG: section 93 ICAP (RFC 3507) Client
9 #include "ICAPOptXact.h"
10 #include "ICAPOptions.h"
11 #include "TextException.h"
13 CBDATA_CLASS_INIT(ICAPOptXact
);
15 ICAPOptXact::ICAPOptXact(): ICAPXaction("ICAPOptXact"), options(NULL
),
16 cb(NULL
), cbData(NULL
)
21 ICAPOptXact::~ICAPOptXact()
23 Must(!options
); // the caller must set to NULL
26 void ICAPOptXact::start(ICAPServiceRep::Pointer
&aService
, Callback
*aCb
, void *aCbData
)
28 ICAPXaction_Enter(start
);
31 Must(!cb
&& aCb
&& aCbData
);
33 cbData
= cbdataReference(aCbData
);
40 void ICAPOptXact::handleCommConnected()
46 makeRequest(requestBuf
);
47 debugs(93, 9, "ICAPOptXact request " << status() << ":\n" <<
48 (requestBuf
.terminate(), requestBuf
.content()));
50 scheduleWrite(requestBuf
);
53 bool ICAPOptXact::doneAll() const
55 return options
&& ICAPXaction::doneAll();
59 void ICAPOptXact::doStop()
61 ICAPXaction::doStop();
63 if (Callback
*call
= cb
) {
67 if (cbdataReferenceValidDone(cbData
, &data
)) {
68 (*call
)(this, data
); // will delete us
73 // get rid of options if we did not call the callback
79 void ICAPOptXact::makeRequest(MemBuf
&buf
)
81 const ICAPServiceRep
&s
= service();
82 buf
.Printf("OPTIONS %s ICAP/1.0\r\n", s
.uri
.buf());
83 buf
.Printf("Host: %s:%d\r\n", s
.host
.buf(), s
.port
);
84 buf
.append(ICAP::crlf
, 2);
87 void ICAPOptXact::handleCommWrote(size_t size
)
89 debugs(93, 9, "ICAPOptXact finished writing " << size
<<
90 "-byte request " << status());
93 // comm module read a portion of the ICAP response for us
94 void ICAPOptXact::handleCommRead(size_t)
97 Must(done()); // there should be nothing else to do
102 bool ICAPOptXact::parseResponse()
104 debugs(93, 5, HERE
<< "have " << readBuf
.contentSize() << " bytes to parse" <<
106 debugs(93, 5, HERE
<< "\n" << readBuf
.content());
108 HttpReply
*r
= new HttpReply
;
109 r
->protoPrefix
= "ICAP/"; // TODO: make an IcapReply class?
111 if (!parseHttpMsg(r
)) {
116 options
= new ICAPOptions
;
118 options
->configure(r
);
120 if (httpHeaderHasConnDir(&r
->header
, "close"))
121 reuseConnection
= false;