// SNMP context class.
// Copyright (C) 2009-2010 Lex Li
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Net;
using GSF.Net.Snmp.Messaging;
using GSF.Net.Snmp.Security;
namespace GSF.Net.Snmp.Pipeline
{
///
/// SNMP context.
///
internal abstract class SnmpContextBase : ISnmpContext
{
///
/// Initializes a new instance of the class.
///
/// The request.
/// The sender.
/// The users.
/// The engine core group.
/// The binding.
protected SnmpContextBase(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
{
Request = request;
Binding = binding;
Users = users;
Sender = sender;
CreatedTime = DateTime.Now;
Group = group;
}
///
/// Gets or sets the binding.
///
/// The binding.
public IListenerBinding Binding { get; private set; }
///
/// Gets the created time.
///
/// The created time.
public DateTime CreatedTime { get; private set; }
///
/// Gets the request.
///
/// The request.
public ISnmpMessage Request { get; private set; }
///
/// Gets the users.
///
/// The users.
protected UserRegistry Users { get; private set; }
///
/// Gets the response.
///
/// The response.
public ISnmpMessage Response { get; protected set; }
///
/// Gets the sender.
///
/// The sender.
public IPEndPoint Sender { get; private set; }
///
/// Gets or sets the objects.
///
/// The objects.
protected EngineGroup Group { get; private set; }
///
/// Gets a value indicating whether [too big].
///
/// true if the response is too big; otherwise, false.
public bool TooBig
{
get
{
int length = Response.ToBytes().Length;
return length > Request.Header.MaxSize || length > Messenger.MaxMessageSize;
}
}
///
/// Sends out response message.
///
public void SendResponse()
{
if (Response == null)
{
return;
}
Binding.SendResponse(Response, Sender);
}
///
/// Generates the response.
///
/// The variables.
public abstract void GenerateResponse(IList variables);
///
/// Copies the request variable bindings to response.
///
/// The status.
/// The index.
public abstract void CopyRequest(ErrorCode status, int index);
///
/// Handles the membership authentication.
///
///
public abstract bool HandleMembership();
///
/// Generates too big message.
///
public abstract void GenerateTooBig();
}
}