]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/snmp/Session.cc
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 49 SNMP Interface */
12 #include "base/TextException.h"
13 #include "ipc/TypedMsgHdr.h"
14 #include "snmp/Session.h"
17 Snmp::Session::Session()
22 Snmp::Session::Session(const Session
& session
)
27 Snmp::Session::~Session()
33 Snmp::Session::operator = (const Session
& session
)
41 Snmp::Session::clear()
43 memset(this, 0, sizeof(*this));
49 if (community_len
> 0) {
50 Must(community
!= NULL
);
59 Snmp::Session::assign(const Session
& session
)
61 memcpy(this, &session
, sizeof(*this));
62 if (session
.community
!= NULL
) {
63 community
= (u_char
*)xstrdup((char*)session
.community
);
64 Must(community
!= NULL
);
66 if (session
.peername
!= NULL
) {
67 peername
= xstrdup(session
.peername
);
68 Must(peername
!= NULL
);
73 Snmp::Session::pack(Ipc::TypedMsgHdr
& msg
) const
76 msg
.putInt(community_len
);
77 if (community_len
> 0) {
78 Must(community
!= NULL
);
79 msg
.putFixed(community
, community_len
);
83 int len
= peername
!= NULL
? strlen(peername
) : 0;
86 msg
.putFixed(peername
, len
);
87 msg
.putPod(remote_port
);
88 msg
.putPod(local_port
);
92 Snmp::Session::unpack(const Ipc::TypedMsgHdr
& msg
)
96 community_len
= msg
.getInt();
97 if (community_len
> 0) {
98 community
= static_cast<u_char
*>(xmalloc(community_len
+ 1));
99 Must(community
!= NULL
);
100 msg
.getFixed(community
, community_len
);
101 community
[community_len
] = 0;
105 int len
= msg
.getInt();
107 peername
= static_cast<char*>(xmalloc(len
+ 1));
108 Must(peername
!= NULL
);
109 msg
.getFixed(peername
, len
);
112 msg
.getPod(remote_port
);
113 msg
.getPod(local_port
);