]>
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(ICAPServiceRep::Pointer
&aService
, Callback
*aCbAddr
, void *aCbData
):
16 ICAPXaction("ICAPOptXact"),
17 cbAddr(aCbAddr
), cbData(cbdataReference(aCbData
))
19 Must(aCbAddr
&& aCbData
);
23 ICAPOptXact::~ICAPOptXact()
26 debugs(93, 1, HERE
<< "BUG: exiting without sending options");
27 cbdataReferenceDone(cbData
);
31 void ICAPOptXact::start()
33 ICAPXaction_Enter(start
);
37 Must(self
!= NULL
); // set by AsyncStart;
44 void ICAPOptXact::handleCommConnected()
50 makeRequest(requestBuf
);
51 debugs(93, 9, "ICAPOptXact request " << status() << ":\n" <<
52 (requestBuf
.terminate(), requestBuf
.content()));
54 scheduleWrite(requestBuf
);
57 void ICAPOptXact::makeRequest(MemBuf
&buf
)
59 const ICAPServiceRep
&s
= service();
60 buf
.Printf("OPTIONS %s ICAP/1.0\r\n", s
.uri
.buf());
61 buf
.Printf("Host: %s:%d\r\n", s
.host
.buf(), s
.port
);
62 buf
.append(ICAP::crlf
, 2);
65 void ICAPOptXact::handleCommWrote(size_t size
)
67 debugs(93, 9, "ICAPOptXact finished writing " << size
<<
68 "-byte request " << status());
71 // comm module read a portion of the ICAP response for us
72 void ICAPOptXact::handleCommRead(size_t)
74 if (ICAPOptions
*options
= parseResponse()) {
76 Must(done()); // there should be nothing else to do
83 ICAPOptions
*ICAPOptXact::parseResponse()
85 debugs(93, 5, HERE
<< "have " << readBuf
.contentSize() << " bytes to parse" <<
87 debugs(93, 5, HERE
<< "\n" << readBuf
.content());
89 HttpReply
*r
= new HttpReply
;
90 r
->protoPrefix
= "ICAP/"; // TODO: make an IcapReply class?
92 if (!parseHttpMsg(r
)) { // throws on errors
97 if (httpHeaderHasConnDir(&r
->header
, "close"))
98 reuseConnection
= false;
100 ICAPOptions
*options
= new ICAPOptions
;
101 options
->configure(r
);
108 void ICAPOptXact::swanSong() {
110 debugs(93, 3, HERE
<< "probably failed; sending NULL options");
113 ICAPXaction::swanSong();
116 void ICAPOptXact::sendOptions(ICAPOptions
*options
) {
117 debugs(93, 3, HERE
<< "sending options " << options
<< " to " << cbData
<<
118 " at " << (void*)cbAddr
<< status());
121 Callback
*addr
= cbAddr
;
122 cbAddr
= NULL
; // in case the callback calls us or throws
125 if (cbdataReferenceValidDone(cbData
, &data
))
126 (*addr
)(options
, data
); // callee takes ownership of the options
128 debugs(93, 2, HERE
<< "sending options " << options
<< " to " <<
129 data
<< " failed" << status());