Action.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 16 Cache Manager API */
10
11#include "squid.h"
12#include "CacheManager.h"
13#include "comm/Connection.h"
14#include "HttpReply.h"
15#include "ipc/Port.h"
16#include "mgr/Action.h"
17#include "mgr/ActionCreator.h"
18#include "mgr/ActionParams.h"
19#include "mgr/ActionProfile.h"
20#include "mgr/Command.h"
21#include "mgr/Request.h"
22#include "mgr/Response.h"
23#include "Store.h"
24
26{
27 Must(cmd != nullptr);
28 Must(cmd->profile != nullptr);
29}
30
32{
33}
34
35const Mgr::Command &
37{
38 Must(cmd != nullptr);
39 return *cmd;
40}
41
42bool
44{
45 return command().profile->isAtomic;
46}
47
48const char*
50{
51 return command().profile->name;
52}
53
56{
57 const ActionParams &params = command().params;
58 const char *uri = params.httpUri.termedBuf();
59 return storeCreateEntry(uri, uri, params.httpFlags, params.httpMethod);
60}
61
62void
64{
65}
66
67void
69{
70 debugs(16, 5, MYNAME);
71
72 // Assume most kid classes are fully aggregatable (i.e., they do not dump
73 // local info at all). Do not import the remote HTTP fd into our Comm
74 // space; collect and send an IPC msg with collected info to Coordinator.
75 ::close(request.conn->fd);
76 request.conn->fd = -1;
77 collect();
78 sendResponse(request.requestId);
79}
80
81void
83{
84 Response response(requestId, this);
85 Ipc::TypedMsgHdr message;
86 response.pack(message);
88}
89
90void
91Mgr::Action::run(StoreEntry* entry, bool writeHttpHeader)
92{
93 debugs(16, 5, MYNAME);
94 collect();
95 fillEntry(entry, writeHttpHeader);
96}
97
98void
99Mgr::Action::fillEntry(StoreEntry* entry, bool writeHttpHeader)
100{
101 debugs(16, 5, MYNAME);
102 entry->buffer();
103
104 if (writeHttpHeader) {
105 HttpReply *rep = new HttpReply;
106 rep->setHeaders(Http::scOkay, nullptr, contentType(), -1, squid_curtime, squid_curtime);
107
108 const auto &origin = command().params.httpOrigin;
109 const auto originOrNil = origin.size() ? origin.termedBuf() : nullptr;
111
112 entry->replaceHttpReply(rep);
113 }
114
115 dump(entry);
116
117 entry->flush();
118
119 if (atomic())
120 entry->complete();
121}
122
time_t squid_curtime
Definition: stub_libtime.cc:20
#define Must(condition)
Definition: TextException.h:75
static void PutCommonResponseHeaders(HttpReply &, const char *httpOrigin)
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition: HttpReply.cc:170
static String CoordinatorAddr()
get the IPC message address for coordinator process
Definition: Port.cc:65
RequestId requestId
matches the request[or] with the response
Definition: Request.h:38
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:35
Cache Manager Action parameters extracted from the user request.
Definition: ActionParams.h:24
String httpUri
HTTP request URI.
Definition: ActionParams.h:33
RequestFlags httpFlags
HTTP request flags.
Definition: ActionParams.h:35
HttpRequestMethod httpMethod
HTTP request method.
Definition: ActionParams.h:34
Action(const CommandPointer &aCmd)
Definition: Action.cc:25
void fillEntry(StoreEntry *entry, bool writeHttpHeader)
prepare store entry, dump info, close store entry (if possible)
Definition: Action.cc:99
const Command & command() const
the cause of this action
Definition: Action.cc:36
void sendResponse(Ipc::RequestId)
notify Coordinator that this action is done with local processing
Definition: Action.cc:82
virtual void respond(const Request &request)
respond to Coordinator request; default is to collect and sendResponse
Definition: Action.cc:68
StoreEntry * createStoreEntry() const
creates store entry from params
Definition: Action.cc:55
bool atomic() const
dump() call writes everything before returning
Definition: Action.cc:43
~Action() override
Definition: Action.cc:31
const char * name() const
label as seen in the cache manager menu
Definition: Action.cc:49
const CommandPointer cmd
the command that caused this action
Definition: Action.h:86
virtual void add(const Action &action)
incrementally merge in remote information (of the same action type)
Definition: Action.cc:63
void run(StoreEntry *entry, bool writeHttpHeader)
collect + fillEntry: collect local information and fill the store entry
Definition: Action.cc:91
combined hard-coded action profile with user-supplied action parameters
Definition: Command.h:22
cache manager request
Definition: Request.h:24
Comm::ConnectionPointer conn
HTTP client connection descriptor.
Definition: Request.h:35
void pack(Ipc::TypedMsgHdr &msg) const override
prepare for sendmsg()
Definition: Response.cc:43
void complete()
Definition: store.cc:1017
void flush() override
Definition: store.cc:1598
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition: store.cc:1691
void buffer() override
Definition: store.cc:1587
char const * termedBuf() const
Definition: SquidString.h:92
#define MYNAME
Definition: Stream.h:236
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
@ scOkay
Definition: StatusCode.h:26
void SendMessage(const String &toAddress, const TypedMsgHdr &message)
Definition: UdsOp.cc:188
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:745

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors