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