]> git.ipfire.org Git - thirdparty/squid.git/blob - src/snmp/Request.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / snmp / Request.cc
1 /*
2 * Copyright (C) 1996-2021 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(const int aRequestorId, const Ipc::RequestId 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 Ipc::TypedMsgHdr &msg)
25 {
26 msg.checkType(Ipc::mtSnmpRequest);
27 msg.getPod(requestorId);
28 msg.getPod(requestId);
29 pdu.unpack(msg);
30 session.unpack(msg);
31 msg.getPod(address);
32
33 // Requests from strands have FDs. Requests from Coordinator do not.
34 fd = msg.hasFd() ? msg.getFd() : -1;
35 }
36
37 void
38 Snmp::Request::pack(Ipc::TypedMsgHdr& msg) const
39 {
40 msg.setType(Ipc::mtSnmpRequest);
41 msg.putPod(requestorId);
42 msg.putPod(requestId);
43 pdu.pack(msg);
44 session.pack(msg);
45 msg.putPod(address);
46
47 // Requests sent to Coordinator have FDs. Requests sent to strands do not.
48 if (fd >= 0)
49 msg.putFd(fd);
50 }
51
52 Ipc::Request::Pointer
53 Snmp::Request::clone() const
54 {
55 return new Request(*this);
56 }
57