]> git.ipfire.org Git - thirdparty/squid.git/blob - src/snmp/Request.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / snmp / Request.cc
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 49 SNMP Interface */
10
11 #include "squid.h"
12 #include "ipc/Messages.h"
13 #include "ipc/TypedMsgHdr.h"
14 #include "snmp/Request.h"
15
16 Snmp::Request::Request(int aRequestorId, unsigned int aRequestId,
17 const Pdu& aPdu, const Session& aSession,
18 int aFd, const Ip::Address& anAddress):
19 Ipc::Request(aRequestorId, aRequestId),
20 pdu(aPdu), session(aSession), fd(aFd), address(anAddress)
21 {
22 }
23
24 Snmp::Request::Request(const Request& request):
25 Ipc::Request(request.requestorId, request.requestId),
26 pdu(request.pdu), session(request.session),
27 fd(request.fd), address(request.address)
28 {
29 }
30
31 Snmp::Request::Request(const Ipc::TypedMsgHdr& msg):
32 Ipc::Request(0, 0)
33 {
34 msg.checkType(Ipc::mtSnmpRequest);
35 msg.getPod(requestorId);
36 msg.getPod(requestId);
37 pdu.unpack(msg);
38 session.unpack(msg);
39 msg.getPod(address);
40
41 // Requests from strands have FDs. Requests from Coordinator do not.
42 fd = msg.hasFd() ? msg.getFd() : -1;
43 }
44
45 void
46 Snmp::Request::pack(Ipc::TypedMsgHdr& msg) const
47 {
48 msg.setType(Ipc::mtSnmpRequest);
49 msg.putPod(requestorId);
50 msg.putPod(requestId);
51 pdu.pack(msg);
52 session.pack(msg);
53 msg.putPod(address);
54
55 // Requests sent to Coordinator have FDs. Requests sent to strands do not.
56 if (fd >= 0)
57 msg.putFd(fd);
58 }
59
60 Ipc::Request::Pointer
61 Snmp::Request::clone() const
62 {
63 return new Request(*this);
64 }
65