]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Action.cc
Sync with trunk
[thirdparty/squid.git] / src / mgr / Action.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 16 Cache Manager API
5 *
6 */
7
8 #include "config.h"
9 #include "comm/Connection.h"
10 #include "HttpReply.h"
11 #include "ipc/Port.h"
12 #include "mgr/ActionCreator.h"
13 #include "mgr/Action.h"
14 #include "mgr/ActionParams.h"
15 #include "mgr/ActionProfile.h"
16 #include "mgr/Command.h"
17 #include "mgr/Request.h"
18 #include "mgr/Response.h"
19 #include "SquidTime.h"
20 #include "Store.h"
21
22
23 Mgr::Action::Action(const Command::Pointer &aCmd): cmd(aCmd)
24 {
25 Must(cmd != NULL);
26 Must(cmd->profile != NULL);
27 }
28
29 Mgr::Action::~Action()
30 {
31 }
32
33 const Mgr::Command &
34 Mgr::Action::command() const
35 {
36 Must(cmd != NULL);
37 return *cmd;
38 }
39
40 bool
41 Mgr::Action::atomic() const
42 {
43 return command().profile->isAtomic;
44 }
45
46 const char*
47 Mgr::Action::name() const
48 {
49 return command().profile->name;
50 }
51
52 StoreEntry*
53 Mgr::Action::createStoreEntry() const
54 {
55 const ActionParams &params = command().params;
56 const char *uri = params.httpUri.termedBuf();
57 return storeCreateEntry(uri, uri, params.httpFlags, params.httpMethod);
58 }
59
60 void
61 Mgr::Action::add(const Action& action)
62 {
63 }
64
65 void
66 Mgr::Action::respond(const Request& request)
67 {
68 debugs(16, 5, HERE);
69
70 // Assume most kid classes are fully aggregatable (i.e., they do not dump
71 // local info at all). Do not import the remote HTTP fd into our Comm
72 // space; collect and send an IPC msg with collected info to Coordinator.
73 request.conn->close();
74 collect();
75 sendResponse(request.requestId);
76 }
77
78 void
79 Mgr::Action::sendResponse(unsigned int requestId)
80 {
81 Response response(requestId, this);
82 Ipc::TypedMsgHdr message;
83 response.pack(message);
84 Ipc::SendMessage(Ipc::coordinatorAddr, message);
85 }
86
87 void
88 Mgr::Action::run(StoreEntry* entry, bool writeHttpHeader)
89 {
90 debugs(16, 5, HERE);
91 collect();
92 fillEntry(entry, writeHttpHeader);
93 }
94
95 void
96 Mgr::Action::fillEntry(StoreEntry* entry, bool writeHttpHeader)
97 {
98 debugs(16, 5, HERE);
99 entry->buffer();
100
101 if (writeHttpHeader) {
102 HttpReply *rep = new HttpReply;
103 rep->setHeaders(HTTP_OK, NULL, "text/plain", -1, squid_curtime, squid_curtime);
104 entry->replaceHttpReply(rep);
105 }
106
107 dump(entry);
108
109 entry->flush();
110
111 if (atomic())
112 entry->complete();
113 }