Action.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 "comm/Connection.h"
13 #include "HttpReply.h"
14 #include "ipc/Port.h"
15 #include "mgr/Action.h"
16 #include "mgr/ActionCreator.h"
17 #include "mgr/ActionParams.h"
18 #include "mgr/ActionProfile.h"
19 #include "mgr/Command.h"
20 #include "mgr/Request.h"
21 #include "mgr/Response.h"
22 #include "SquidTime.h"
23 #include "Store.h"
24 
25 Mgr::Action::Action(const Command::Pointer &aCmd): cmd(aCmd)
26 {
27  Must(cmd != NULL);
28  Must(cmd->profile != NULL);
29 }
30 
32 {
33 }
34 
35 const Mgr::Command &
37 {
38  Must(cmd != NULL);
39  return *cmd;
40 }
41 
42 bool
44 {
45  return command().profile->isAtomic;
46 }
47 
48 const 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 
62 void
64 {
65 }
66 
67 void
69 {
70  debugs(16, 5, HERE);
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 
81 void
82 Mgr::Action::sendResponse(unsigned int requestId)
83 {
84  Response response(requestId, this);
85  Ipc::TypedMsgHdr message;
86  response.pack(message);
88 }
89 
90 void
91 Mgr::Action::run(StoreEntry* entry, bool writeHttpHeader)
92 {
93  debugs(16, 5, HERE);
94  collect();
95  fillEntry(entry, writeHttpHeader);
96 }
97 
98 void
99 Mgr::Action::fillEntry(StoreEntry* entry, bool writeHttpHeader)
100 {
101  debugs(16, 5, HERE);
102  entry->buffer();
103 
104  if (writeHttpHeader) {
105  HttpReply *rep = new HttpReply;
106  rep->setHeaders(Http::scOkay, NULL, contentType(), -1, squid_curtime, squid_curtime);
107  // Allow cachemgr and other XHR scripts access to our version string
108  const ActionParams &params = command().params;
109  if (params.httpOrigin.size() > 0) {
110  rep->header.putExt("Access-Control-Allow-Origin", params.httpOrigin.termedBuf());
111 #if HAVE_AUTH_MODULE_BASIC
112  rep->header.putExt("Access-Control-Allow-Credentials","true");
113 #endif
114  rep->header.putExt("Access-Control-Expose-Headers","Server");
115  }
116  entry->replaceHttpReply(rep);
117  }
118 
119  dump(entry);
120 
121  entry->flush();
122 
123  if (atomic())
124  entry->complete();
125 }
126 
cache manager request
Definition: Request.h:22
void fillEntry(StoreEntry *entry, bool writeHttpHeader)
prepare store entry, dump info, close store entry (if possible)
Definition: Action.cc:99
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
virtual void buffer()
Definition: store.cc:1707
void putExt(const char *name, const char *value)
Definition: HttpHeader.cc:1152
virtual void flush()
Definition: store.cc:1718
size_type size() const
Definition: SquidString.h:71
String httpOrigin
HTTP Origin: header (if any)
Definition: ActionParams.h:36
time_t squid_curtime
Definition: stub_time.cc:17
Cache Manager Action parameters extracted from the user request.
Definition: ActionParams.h:23
void replaceHttpReply(HttpReply *, bool andStartWriting=true)
Definition: store.cc:1854
virtual void complete()
Definition: store.cc:1088
virtual void respond(const Request &request)
respond to Coordinator request; default is to collect and sendResponse
Definition: Action.cc:68
bool atomic() const
dump() call writes everything before returning
Definition: Action.cc:43
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition: HttpReply.cc:151
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:800
HttpRequestMethod httpMethod
HTTP request method.
Definition: ActionParams.h:34
unsigned int requestId
unique for sender; matches request w/ response
Definition: Request.h:39
char const * termedBuf() const
Definition: SquidString.h:90
Action(const CommandPointer &aCmd)
Definition: Action.cc:25
void sendResponse(unsigned int requestId)
notify Coordinator that this action is done with local processing
Definition: Action.cc:82
void SendMessage(const String &toAddress, const TypedMsgHdr &message)
Definition: UdsOp.cc:188
const Command & command() const
the cause of this action
Definition: Action.cc:36
const CommandPointer cmd
the command that caused this action
Definition: Action.h:86
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
#define Must(cond)
Definition: TextException.h:89
combined hard-coded action profile with user-supplied action parameters
Definition: Command.h:21
HttpHeader header
Definition: Message.h:74
Comm::ConnectionPointer conn
HTTP client connection descriptor.
Definition: Request.h:37
const char * name() const
label as seen in the cache manager menu
Definition: Action.cc:49
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:31
virtual ~Action()
Definition: Action.cc:31
RequestFlags httpFlags
HTTP request flags.
Definition: ActionParams.h:35
StoreEntry * createStoreEntry() const
creates store entry from params
Definition: Action.cc:55
virtual void add(const Action &action)
incrementally merge in remote information (of the same action type)
Definition: Action.cc:63
String httpUri
HTTP request URI.
Definition: ActionParams.h:33
static String CoordinatorAddr()
get the IPC message address for coordinator process
Definition: Port.cc:64
#define NULL
Definition: types.h:166
void run(StoreEntry *entry, bool writeHttpHeader)
collect + fillEntry: collect local information and fill the store entry
Definition: Action.cc:91
virtual void pack(Ipc::TypedMsgHdr &msg) const
prepare for sendmsg()
Definition: Response.cc:48

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors