Release 11
git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@25 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
146
asn1util.pas
146
asn1util.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.000.000 |
|
| Project : Delphree - Synapse | 001.001.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: support for ASN.1 coding and decoding |
|
| Content: support for ASN.1 coding and decoding |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -43,83 +43,107 @@ const
|
|||||||
ASN1_GAUGE = $42;
|
ASN1_GAUGE = $42;
|
||||||
ASN1_TIMETICKS = $43;
|
ASN1_TIMETICKS = $43;
|
||||||
|
|
||||||
|
function ASNEncOIDitem(Value: integer): string;
|
||||||
|
function ASNDecOIDitem(var Start: integer; Buffer: string): integer;
|
||||||
function ASNEncLen(Len: integer): string;
|
function ASNEncLen(Len: integer): string;
|
||||||
function ASNDecLen(var Start: integer; Buffer: string): integer;
|
function ASNDecLen(var Start: integer; Buffer: string): integer;
|
||||||
function ASNEncInt(Len: integer): string;
|
function ASNEncInt(Value: integer): string;
|
||||||
function ASNObject(Data: string; ASNType: integer): string;
|
function ASNObject(Data: string; ASNType: integer): string;
|
||||||
function ASNItem(var Start: integer; Buffer: string): string;
|
function ASNItem(var Start: integer; Buffer: string; var ValueType:integer): string;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function ASNEncOIDitem(Value: integer): string;
|
||||||
|
var
|
||||||
|
x,xm:integer;
|
||||||
|
b:boolean;
|
||||||
|
begin
|
||||||
|
x:=value;
|
||||||
|
b:=false;
|
||||||
|
result:='';
|
||||||
|
repeat
|
||||||
|
xm:=x mod 128;
|
||||||
|
x:=x div 128;
|
||||||
|
if b then
|
||||||
|
xm:=xm or $80;
|
||||||
|
if x>0
|
||||||
|
then b:=true;
|
||||||
|
result:=char(xm)+result;
|
||||||
|
until x=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ASNDecOIDitem(var Start: integer; Buffer: string): integer;
|
||||||
|
var
|
||||||
|
x:integer;
|
||||||
|
b:boolean;
|
||||||
|
begin
|
||||||
|
result:=0;
|
||||||
|
repeat
|
||||||
|
result:=result*128;
|
||||||
|
x := Ord(Buffer[Start]);
|
||||||
|
inc(start);
|
||||||
|
b:=x>$7f;
|
||||||
|
x:=x and $7f;
|
||||||
|
result:=result+x;
|
||||||
|
if not b
|
||||||
|
then break;
|
||||||
|
until false
|
||||||
|
end;
|
||||||
|
|
||||||
function ASNEncLen(Len: integer): string;
|
function ASNEncLen(Len: integer): string;
|
||||||
var
|
var
|
||||||
x, y: integer;
|
x, y: integer;
|
||||||
begin
|
begin
|
||||||
if (Len < $80) then
|
if (len<$80)
|
||||||
Result := Char(Len)
|
then result:=char(len)
|
||||||
else
|
|
||||||
if (Len < $FF) then
|
|
||||||
Result := Char($81) + Char(Len)
|
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
x := Len div $FF;
|
x:=len;
|
||||||
y := Len mod $FF;
|
result:='';
|
||||||
Result := Char($82) + Char(x) + Char(y);
|
repeat
|
||||||
end;
|
y:=x mod 256;
|
||||||
|
x:=x div 256;
|
||||||
|
result:=char(y)+result;
|
||||||
|
until x=0;
|
||||||
|
y:=length(result);
|
||||||
|
y:=y or $80;
|
||||||
|
result:=char(y)+result;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ASNDecLen(var Start: integer; Buffer: string): integer;
|
function ASNDecLen(var Start: integer; Buffer: string): integer;
|
||||||
var
|
var
|
||||||
x: integer;
|
x,n: integer;
|
||||||
begin
|
begin
|
||||||
x := Ord(Buffer[Start]);
|
x:=Ord(Buffer[Start]);
|
||||||
if (x < $80) then
|
Inc(Start);
|
||||||
begin
|
if (x<$80)
|
||||||
Inc(Start);
|
then Result:=x
|
||||||
Result := x;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if (x = $81) then
|
|
||||||
begin
|
|
||||||
Inc(Start);
|
|
||||||
Result := Ord(Buffer[Start]);
|
|
||||||
Inc(Start);
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Inc(Start);
|
result:=0;
|
||||||
x := Ord(Buffer[Start]);
|
x:=x and $7f;
|
||||||
Inc(Start);
|
for n:=1 to x do
|
||||||
Result := x * $FF + Ord(Buffer[Start]);
|
begin
|
||||||
Inc(Start);
|
result:=result*256;
|
||||||
end;
|
x:=Ord(Buffer[Start]);
|
||||||
|
Inc(Start);
|
||||||
|
result:=result+x;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ASNEncInt(Len: integer): string;
|
function ASNEncInt(Value: integer): string;
|
||||||
var
|
var
|
||||||
j, y: integer;
|
x,y:integer;
|
||||||
begin
|
begin
|
||||||
Result := '';
|
x:=Value;
|
||||||
j := 0;
|
result:='';
|
||||||
y := Len div $FFFFFF;
|
repeat
|
||||||
Len := Len - (y * $FFFFFF);
|
y:=x mod 256;
|
||||||
if ((y > 0) or (j = 1)) then
|
x:=x div 256;
|
||||||
begin
|
result:=char(y)+result;
|
||||||
j := 1;
|
until x=0;
|
||||||
Result := Result + Char(y);
|
|
||||||
end;
|
|
||||||
y := Len div $FFFF;
|
|
||||||
Len := Len - (y * $FFFF);
|
|
||||||
if ((y > 0) or (j = 1)) then
|
|
||||||
begin
|
|
||||||
j := 1;
|
|
||||||
Result := Result + Char(y);
|
|
||||||
end;
|
|
||||||
y := Len div $FF;
|
|
||||||
Len := Len - (y * $FF);
|
|
||||||
if ((y > 0) or (j = 1)) then
|
|
||||||
Result := Result + Char(y);
|
|
||||||
Result := Result + Char(Len);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ASNObject(Data: string; ASNType: integer): string;
|
function ASNObject(Data: string; ASNType: integer): string;
|
||||||
@ -127,7 +151,7 @@ begin
|
|||||||
Result := Char(ASNType) + ASNEncLen(Length(Data)) + Data;
|
Result := Char(ASNType) + ASNEncLen(Length(Data)) + Data;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ASNItem(var Start: integer; Buffer: string): string;
|
function ASNItem(var Start: integer; Buffer: string; var ValueType:integer): string;
|
||||||
var
|
var
|
||||||
ASNType: integer;
|
ASNType: integer;
|
||||||
ASNSize: integer;
|
ASNSize: integer;
|
||||||
@ -136,6 +160,7 @@ var
|
|||||||
c: char;
|
c: char;
|
||||||
begin
|
begin
|
||||||
ASNType := Ord(Buffer[Start]);
|
ASNType := Ord(Buffer[Start]);
|
||||||
|
Valuetype:=ASNType;
|
||||||
Inc(start);
|
Inc(start);
|
||||||
ASNSize := ASNDecLen(Start, Buffer);
|
ASNSize := ASNDecLen(Start, Buffer);
|
||||||
Result := '';
|
Result := '';
|
||||||
@ -197,5 +222,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
exit;
|
||||||
|
asm
|
||||||
|
db 'Synapse ASN.1 library by Lukas Gebauer',0
|
||||||
|
end;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.000.000 |
|
| Project : Delphree - Synapse | 001.001.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: Library base for RAW sockets |
|
| Content: Library base for RAW sockets |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -116,7 +116,7 @@ begin
|
|||||||
Result:=False;
|
Result:=False;
|
||||||
r1:=False;
|
r1:=False;
|
||||||
r2:=False;
|
r2:=False;
|
||||||
Value:=Timeout*1000;
|
Value:=Timeout;
|
||||||
len:=SizeOf(Value);
|
len:=SizeOf(Value);
|
||||||
Res:=Winsock.setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,@Value,len);
|
Res:=Winsock.setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,@Value,len);
|
||||||
r1:=res<>SOCKET_ERROR;
|
r1:=res<>SOCKET_ERROR;
|
||||||
|
78
blcksock.pas
78
blcksock.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.001.001 |
|
| Project : Delphree - Synapse | 002.000.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: Library base |
|
| Content: Library base |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -32,6 +32,12 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
ESynapseError = class (Exception)
|
||||||
|
Public
|
||||||
|
ErrorCode:integer;
|
||||||
|
ErrorMessage:string;
|
||||||
|
end;
|
||||||
|
|
||||||
{TBlockSocket}
|
{TBlockSocket}
|
||||||
TBlockSocket = class (TObject)
|
TBlockSocket = class (TObject)
|
||||||
Protected
|
Protected
|
||||||
@ -41,6 +47,7 @@ Protected
|
|||||||
FLastError:integer;
|
FLastError:integer;
|
||||||
FProtocol:integer;
|
FProtocol:integer;
|
||||||
FBuffer:string;
|
FBuffer:string;
|
||||||
|
FRaiseExcept:boolean;
|
||||||
|
|
||||||
procedure SetSin (var sin:TSockAddrIn;ip,port:string);
|
procedure SetSin (var sin:TSockAddrIn;ip,port:string);
|
||||||
function GetSinIP (sin:TSockAddrIn):string;
|
function GetSinIP (sin:TSockAddrIn):string;
|
||||||
@ -55,7 +62,7 @@ public
|
|||||||
Procedure CloseSocket;
|
Procedure CloseSocket;
|
||||||
procedure Bind(ip,port:string);
|
procedure Bind(ip,port:string);
|
||||||
procedure Connect(ip,port:string);
|
procedure Connect(ip,port:string);
|
||||||
procedure SendBuffer(buffer:pointer;length:integer); virtual;
|
function SendBuffer(buffer:pointer;length:integer):integer; virtual;
|
||||||
procedure SendByte(data:byte); virtual;
|
procedure SendByte(data:byte); virtual;
|
||||||
procedure SendString(data:string); virtual;
|
procedure SendString(data:string); virtual;
|
||||||
function RecvBuffer(buffer:pointer;length:integer):integer; virtual;
|
function RecvBuffer(buffer:pointer;length:integer):integer; virtual;
|
||||||
@ -67,6 +74,7 @@ public
|
|||||||
procedure SetLinger(enable:boolean;Linger:integer);
|
procedure SetLinger(enable:boolean;Linger:integer);
|
||||||
procedure GetSins;
|
procedure GetSins;
|
||||||
function SockCheck(SockResult:integer):integer;
|
function SockCheck(SockResult:integer):integer;
|
||||||
|
procedure ExceptCheck;
|
||||||
function LocalName:string;
|
function LocalName:string;
|
||||||
function GetLocalSinIP:string;
|
function GetLocalSinIP:string;
|
||||||
function GetRemoteSinIP:string;
|
function GetRemoteSinIP:string;
|
||||||
@ -74,7 +82,7 @@ public
|
|||||||
function GetRemoteSinPort:integer;
|
function GetRemoteSinPort:integer;
|
||||||
function CanRead(Timeout:integer):boolean;
|
function CanRead(Timeout:integer):boolean;
|
||||||
function CanWrite(Timeout:integer):boolean;
|
function CanWrite(Timeout:integer):boolean;
|
||||||
procedure SendBufferTo(buffer:pointer;length:integer);
|
function SendBufferTo(buffer:pointer;length:integer):integer;
|
||||||
function RecvBufferFrom(buffer:pointer;length:integer):integer;
|
function RecvBufferFrom(buffer:pointer;length:integer):integer;
|
||||||
|
|
||||||
published
|
published
|
||||||
@ -83,6 +91,7 @@ published
|
|||||||
property RemoteSin:TSockAddrIn read FRemoteSin;
|
property RemoteSin:TSockAddrIn read FRemoteSin;
|
||||||
property LastError:integer read FLastError;
|
property LastError:integer read FLastError;
|
||||||
property Protocol:integer read FProtocol;
|
property Protocol:integer read FProtocol;
|
||||||
|
property RaiseExcept:boolean read FRaiseExcept write FRaiseExcept;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TUDPBlockSocket}
|
{TUDPBlockSocket}
|
||||||
@ -108,9 +117,11 @@ implementation
|
|||||||
constructor TBlockSocket.Create;
|
constructor TBlockSocket.Create;
|
||||||
begin
|
begin
|
||||||
inherited create;
|
inherited create;
|
||||||
|
FRaiseExcept:=false;
|
||||||
FSocket:=INVALID_SOCKET;
|
FSocket:=INVALID_SOCKET;
|
||||||
FProtocol:=IPPROTO_IP;
|
FProtocol:=IPPROTO_IP;
|
||||||
SockCheck(winsock.WSAStartup($101, FWsaData));
|
SockCheck(winsock.WSAStartup($101, FWsaData));
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.Destroy}
|
{TBlockSocket.Destroy}
|
||||||
@ -172,6 +183,7 @@ Procedure TBlockSocket.CreateSocket;
|
|||||||
begin
|
begin
|
||||||
if FSocket=INVALID_SOCKET then FLastError:=winsock.WSAGetLastError
|
if FSocket=INVALID_SOCKET then FLastError:=winsock.WSAGetLastError
|
||||||
else FLastError:=0;
|
else FLastError:=0;
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -191,6 +203,7 @@ begin
|
|||||||
SockCheck(winsock.bind(FSocket,sin,sizeof(sin)));
|
SockCheck(winsock.bind(FSocket,sin,sizeof(sin)));
|
||||||
len:=sizeof(FLocalSin);
|
len:=sizeof(FLocalSin);
|
||||||
Winsock.GetSockName(FSocket,FLocalSin,Len);
|
Winsock.GetSockName(FSocket,FLocalSin,Len);
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.Connect}
|
{TBlockSocket.Connect}
|
||||||
@ -201,6 +214,7 @@ begin
|
|||||||
SetSin(sin,ip,port);
|
SetSin(sin,ip,port);
|
||||||
SockCheck(winsock.connect(FSocket,sin,sizeof(sin)));
|
SockCheck(winsock.connect(FSocket,sin,sizeof(sin)));
|
||||||
GetSins;
|
GetSins;
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.GetSins}
|
{TBlockSocket.GetSins}
|
||||||
@ -215,21 +229,25 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.SendBuffer}
|
{TBlockSocket.SendBuffer}
|
||||||
procedure TBlockSocket.SendBuffer(buffer:pointer;length:integer);
|
function TBlockSocket.SendBuffer(buffer:pointer;length:integer):integer;
|
||||||
begin
|
begin
|
||||||
sockcheck(winsock.send(FSocket,buffer^,length,0));
|
result:=winsock.send(FSocket,buffer^,length,0);
|
||||||
|
sockcheck(result);
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.SendByte}
|
{TBlockSocket.SendByte}
|
||||||
procedure TBlockSocket.SendByte(data:byte);
|
procedure TBlockSocket.SendByte(data:byte);
|
||||||
begin
|
begin
|
||||||
sockcheck(winsock.send(FSocket,data,1,0));
|
sockcheck(winsock.send(FSocket,data,1,0));
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.SendString}
|
{TBlockSocket.SendString}
|
||||||
procedure TBlockSocket.SendString(data:string);
|
procedure TBlockSocket.SendString(data:string);
|
||||||
begin
|
begin
|
||||||
sockcheck(winsock.send(FSocket,pchar(data)^,length(data),0));
|
sockcheck(winsock.send(FSocket,pchar(data)^,length(data),0));
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.RecvBuffer}
|
{TBlockSocket.RecvBuffer}
|
||||||
@ -239,6 +257,7 @@ begin
|
|||||||
if result=0
|
if result=0
|
||||||
then FLastError:=WSAENOTCONN
|
then FLastError:=WSAENOTCONN
|
||||||
else sockcheck(result);
|
else sockcheck(result);
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.RecvByte}
|
{TBlockSocket.RecvByte}
|
||||||
@ -257,6 +276,7 @@ begin
|
|||||||
result:=data;
|
result:=data;
|
||||||
end
|
end
|
||||||
else FLastError:=WSAETIMEDOUT;
|
else FLastError:=WSAETIMEDOUT;
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.Recvstring}
|
{TBlockSocket.Recvstring}
|
||||||
@ -313,6 +333,7 @@ begin
|
|||||||
result:=s;
|
result:=s;
|
||||||
end
|
end
|
||||||
else result:='';
|
else result:='';
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.PeekBuffer}
|
{TBlockSocket.PeekBuffer}
|
||||||
@ -320,6 +341,7 @@ function TBlockSocket.PeekBuffer(buffer:pointer;length:integer):integer;
|
|||||||
begin
|
begin
|
||||||
result:=winsock.recv(FSocket,buffer^,length,MSG_PEEK);
|
result:=winsock.recv(FSocket,buffer^,length,MSG_PEEK);
|
||||||
sockcheck(result);
|
sockcheck(result);
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.PeekByte}
|
{TBlockSocket.PeekByte}
|
||||||
@ -338,6 +360,7 @@ begin
|
|||||||
result:=data;
|
result:=data;
|
||||||
end
|
end
|
||||||
else FLastError:=WSAETIMEDOUT;
|
else FLastError:=WSAETIMEDOUT;
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.SockCheck}
|
{TBlockSocket.SockCheck}
|
||||||
@ -348,6 +371,22 @@ begin
|
|||||||
FLastError:=result;
|
FLastError:=result;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{TBlockSocket.ExceptCheck}
|
||||||
|
procedure TBlockSocket.ExceptCheck;
|
||||||
|
var
|
||||||
|
e:ESynapseError;
|
||||||
|
s:string;
|
||||||
|
begin
|
||||||
|
if FRaiseExcept and (LastError<>0) then
|
||||||
|
begin
|
||||||
|
s:=GetErrorDesc(LastError);
|
||||||
|
e:=ESynapseError.CreateFmt('TCP/IP socket error %d: %s',[LastError,s]);
|
||||||
|
e.ErrorCode:=LastError;
|
||||||
|
e.ErrorMessage:=s;
|
||||||
|
raise e;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{TBlockSocket.WaitingData}
|
{TBlockSocket.WaitingData}
|
||||||
function TBlockSocket.WaitingData:integer;
|
function TBlockSocket.WaitingData:integer;
|
||||||
var
|
var
|
||||||
@ -363,8 +402,9 @@ var
|
|||||||
li:TLinger;
|
li:TLinger;
|
||||||
begin
|
begin
|
||||||
li.l_onoff := ord(enable);
|
li.l_onoff := ord(enable);
|
||||||
li.l_linger := Linger;
|
li.l_linger := Linger div 1000;
|
||||||
SockCheck(winsock.SetSockOpt(FSocket, SOL_SOCKET, SO_LINGER, @li, SizeOf(li)));
|
SockCheck(winsock.SetSockOpt(FSocket, SOL_SOCKET, SO_LINGER, @li, SizeOf(li)));
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.LocalName}
|
{TBlockSocket.LocalName}
|
||||||
@ -418,8 +458,8 @@ var
|
|||||||
TimeV:tTimeval;
|
TimeV:tTimeval;
|
||||||
x:integer;
|
x:integer;
|
||||||
begin
|
begin
|
||||||
Timev.tv_usec:=0;
|
Timev.tv_usec:=(Timeout mod 1000)*1000;
|
||||||
Timev.tv_sec:=Timeout;
|
Timev.tv_sec:=Timeout div 1000;
|
||||||
TimeVal:=@TimeV;
|
TimeVal:=@TimeV;
|
||||||
if timeout = -1 then Timeval:=nil;
|
if timeout = -1 then Timeval:=nil;
|
||||||
Winsock.FD_Zero(FDSet);
|
Winsock.FD_Zero(FDSet);
|
||||||
@ -428,6 +468,7 @@ begin
|
|||||||
SockCheck(x);
|
SockCheck(x);
|
||||||
If FLastError<>0 then x:=0;
|
If FLastError<>0 then x:=0;
|
||||||
result:=x>0;
|
result:=x>0;
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.CanWrite}
|
{TBlockSocket.CanWrite}
|
||||||
@ -438,8 +479,8 @@ var
|
|||||||
TimeV:tTimeval;
|
TimeV:tTimeval;
|
||||||
x:integer;
|
x:integer;
|
||||||
begin
|
begin
|
||||||
Timev.tv_usec:=0;
|
Timev.tv_usec:=(Timeout mod 1000)*1000;
|
||||||
Timev.tv_sec:=Timeout;
|
Timev.tv_sec:=Timeout div 1000;
|
||||||
TimeVal:=@TimeV;
|
TimeVal:=@TimeV;
|
||||||
if timeout = -1 then Timeval:=nil;
|
if timeout = -1 then Timeval:=nil;
|
||||||
Winsock.FD_Zero(FDSet);
|
Winsock.FD_Zero(FDSet);
|
||||||
@ -448,15 +489,18 @@ begin
|
|||||||
SockCheck(x);
|
SockCheck(x);
|
||||||
If FLastError<>0 then x:=0;
|
If FLastError<>0 then x:=0;
|
||||||
result:=x>0;
|
result:=x>0;
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.SendBufferTo}
|
{TBlockSocket.SendBufferTo}
|
||||||
procedure TBlockSocket.SendBufferTo(buffer:pointer;length:integer);
|
function TBlockSocket.SendBufferTo(buffer:pointer;length:integer):integer;
|
||||||
var
|
var
|
||||||
len:integer;
|
len:integer;
|
||||||
begin
|
begin
|
||||||
len:=sizeof(FRemoteSin);
|
len:=sizeof(FRemoteSin);
|
||||||
sockcheck(winsock.sendto(FSocket,buffer^,length,0,FRemoteSin,len));
|
result:=winsock.sendto(FSocket,buffer^,length,0,FRemoteSin,len);
|
||||||
|
sockcheck(result);
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TBlockSocket.RecvBufferFrom}
|
{TBlockSocket.RecvBufferFrom}
|
||||||
@ -467,6 +511,7 @@ begin
|
|||||||
len:=sizeof(FRemoteSin);
|
len:=sizeof(FRemoteSin);
|
||||||
result:=winsock.recvfrom(FSocket,buffer^,length,0,FRemoteSin,len);
|
result:=winsock.recvfrom(FSocket,buffer^,length,0,FRemoteSin,len);
|
||||||
sockcheck(result);
|
sockcheck(result);
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -491,6 +536,7 @@ begin
|
|||||||
Res:=winsock.SetSockOpt(FSocket, SOL_SOCKET, SO_BROADCAST, @opt, SizeOf(opt));
|
Res:=winsock.SetSockOpt(FSocket, SOL_SOCKET, SO_BROADCAST, @opt, SizeOf(opt));
|
||||||
SockCheck(Res);
|
SockCheck(Res);
|
||||||
Result:=res=0;
|
Result:=res=0;
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -508,6 +554,7 @@ end;
|
|||||||
procedure TTCPBlockSocket.Listen;
|
procedure TTCPBlockSocket.Listen;
|
||||||
begin
|
begin
|
||||||
SockCheck(winsock.listen(FSocket,SOMAXCONN));
|
SockCheck(winsock.listen(FSocket,SOMAXCONN));
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TTCPBlockSocket.Accept}
|
{TTCPBlockSocket.Accept}
|
||||||
@ -522,6 +569,7 @@ begin
|
|||||||
result:=winsock.accept(FSocket,@FRemoteSin,@len);
|
result:=winsock.accept(FSocket,@FRemoteSin,@len);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
SockCheck(result);
|
SockCheck(result);
|
||||||
|
ExceptCheck;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -587,5 +635,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
exit;
|
||||||
|
asm
|
||||||
|
db 'Synapse TCP/IP library by Lukas Gebauer',0
|
||||||
|
end;
|
||||||
end.
|
end.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.000.000 |
|
| Project : Delphree - Synapse | 001.001.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: DNS client |
|
| Content: DNS client |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -102,7 +102,7 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
sock:=TUDPBlockSocket.create;
|
sock:=TUDPBlockSocket.create;
|
||||||
sock.CreateSocket;
|
sock.CreateSocket;
|
||||||
timeout:=5;
|
timeout:=5000;
|
||||||
DNShost:='localhost';
|
DNShost:='localhost';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.000.000 |
|
| Project : Delphree - Synapse | 001.001.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: HTTP client |
|
| Content: HTTP client |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -55,7 +55,7 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
sock:=TTCPBlockSocket.create;
|
sock:=TTCPBlockSocket.create;
|
||||||
sock.CreateSocket;
|
sock.CreateSocket;
|
||||||
timeout:=300;
|
timeout:=300000;
|
||||||
HTTPhost:='localhost';
|
HTTPhost:='localhost';
|
||||||
HTTPPort:=80;
|
HTTPPort:=80;
|
||||||
end;
|
end;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.000.000 |
|
| Project : Delphree - Synapse | 001.001.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: PING sender |
|
| Content: PING sender |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -94,7 +94,7 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
sock:=TICMPBlockSocket.create;
|
sock:=TICMPBlockSocket.create;
|
||||||
sock.CreateSocket;
|
sock.CreateSocket;
|
||||||
timeout:=5;
|
timeout:=5000;
|
||||||
packetsize:=32;
|
packetsize:=32;
|
||||||
seq:=0;
|
seq:=0;
|
||||||
end;
|
end;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.001.001 |
|
| Project : Delphree - Synapse | 001.002.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: SMTP client |
|
| Content: SMTP client |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -63,7 +63,7 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
sock:=TTCPBlockSocket.create;
|
sock:=TTCPBlockSocket.create;
|
||||||
sock.CreateSocket;
|
sock.CreateSocket;
|
||||||
timeout:=300;
|
timeout:=300000;
|
||||||
SMTPhost:='localhost';
|
SMTPhost:='localhost';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -187,6 +187,7 @@ begin
|
|||||||
try
|
try
|
||||||
t.assign(Maildata);
|
t.assign(Maildata);
|
||||||
t.Insert(0,'');
|
t.Insert(0,'');
|
||||||
|
t.Insert(0,'x-mailer: Synapse - Delphi TCP/IP library by Lukas Gebauer');
|
||||||
t.Insert(0,'subject: '+subject);
|
t.Insert(0,'subject: '+subject);
|
||||||
t.Insert(0,'date: '+Rfc822DateTime(now));
|
t.Insert(0,'date: '+Rfc822DateTime(now));
|
||||||
t.Insert(0,'to: '+mailto);
|
t.Insert(0,'to: '+mailto);
|
||||||
|
105
snmpsend.pas
105
snmpsend.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 002.000.000 |
|
| Project : Delphree - Synapse | 002.001.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: SNMP client |
|
| Content: SNMP client |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -50,16 +50,6 @@ EGenErr=5;
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
TSNMPMibValueType = (smvtInteger,
|
|
||||||
smvtOctetString,
|
|
||||||
smvtNull,
|
|
||||||
smvtObjectId,
|
|
||||||
smvtSequence,
|
|
||||||
smvtIpAddress,
|
|
||||||
smvtCounter,
|
|
||||||
smvtGauge,
|
|
||||||
smvtTimeTicks);
|
|
||||||
|
|
||||||
TSNMPMib = class
|
TSNMPMib = class
|
||||||
OID: string;
|
OID: string;
|
||||||
Value: string;
|
Value: string;
|
||||||
@ -80,10 +70,9 @@ TSNMPRec=class(TObject)
|
|||||||
procedure DecodeBuf(Buffer:string);
|
procedure DecodeBuf(Buffer:string);
|
||||||
function EncodeBuf:string;
|
function EncodeBuf:string;
|
||||||
procedure Clear;
|
procedure Clear;
|
||||||
procedure MIBAdd(MIB,Value:string; ValueType:TSNMPMibValueType);
|
procedure MIBAdd(MIB,Value:string; ValueType:integer);
|
||||||
procedure MIBdelete(Index:integer);
|
procedure MIBdelete(Index:integer);
|
||||||
function MIBGet(MIB:string):string;
|
function MIBGet(MIB:string):string;
|
||||||
function ConvertValueType(ValueType: TSNMPMibValueType): integer;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TSNMPSend=class(TObject)
|
TSNMPSend=class(TObject)
|
||||||
@ -101,7 +90,7 @@ TSNMPSend=class(TObject)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function SNMPget (Oid, Community, SNMPHost:string; var Value:string):Boolean;
|
function SNMPget (Oid, Community, SNMPHost:string; var Value:string):Boolean;
|
||||||
function SNMPSet (Oid, Community, SNMPHost, Value: string; ValueType: TSNMPMibValueType): boolean;
|
function SNMPSet (Oid, Community, SNMPHost, Value: string; ValueType: integer): boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -127,23 +116,22 @@ var
|
|||||||
Pos:integer;
|
Pos:integer;
|
||||||
endpos:integer;
|
endpos:integer;
|
||||||
sm,sv:string;
|
sm,sv:string;
|
||||||
svt: TSNMPMibValueType;
|
svt: integer;
|
||||||
begin
|
begin
|
||||||
Pos:=2;
|
Pos:=2;
|
||||||
Endpos:=ASNDecLen(Pos,buffer);
|
Endpos:=ASNDecLen(Pos,buffer);
|
||||||
Self.version:=StrToIntDef(ASNItem(Pos,buffer),0);
|
Self.version:=StrToIntDef(ASNItem(Pos,buffer,svt),0);
|
||||||
Self.community:=ASNItem(Pos,buffer);
|
Self.community:=ASNItem(Pos,buffer,svt);
|
||||||
Self.PDUType:=StrToIntDef(ASNItem(Pos,buffer),0);
|
Self.PDUType:=StrToIntDef(ASNItem(Pos,buffer,svt),0);
|
||||||
Self.ID:=StrToIntDef(ASNItem(Pos,buffer),0);
|
Self.ID:=StrToIntDef(ASNItem(Pos,buffer,svt),0);
|
||||||
Self.ErrorStatus:=StrToIntDef(ASNItem(Pos,buffer),0);
|
Self.ErrorStatus:=StrToIntDef(ASNItem(Pos,buffer,svt),0);
|
||||||
Self.ErrorIndex:=StrToIntDef(ASNItem(Pos,buffer),0);
|
Self.ErrorIndex:=StrToIntDef(ASNItem(Pos,buffer,svt),0);
|
||||||
ASNItem(Pos,buffer);
|
ASNItem(Pos,buffer,svt);
|
||||||
while Pos<Endpos do
|
while Pos<Endpos do
|
||||||
begin
|
begin
|
||||||
ASNItem(Pos,buffer);
|
ASNItem(Pos,buffer,svt);
|
||||||
Sm:=ASNItem(Pos,buffer);
|
Sm:=ASNItem(Pos,buffer,svt);
|
||||||
Sv:=ASNItem(Pos,buffer);
|
Sv:=ASNItem(Pos,buffer,svt);
|
||||||
Svt:=smvtNull;
|
|
||||||
Self.MIBadd(sm,sv, svt);
|
Self.MIBadd(sm,sv, svt);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -151,7 +139,7 @@ end;
|
|||||||
{TSNMPRec.EncodeBuf}
|
{TSNMPRec.EncodeBuf}
|
||||||
function TSNMPRec.EncodeBuf:string;
|
function TSNMPRec.EncodeBuf:string;
|
||||||
var
|
var
|
||||||
data,s,t:string;
|
data,s:string;
|
||||||
SNMPMib: TSNMPMib;
|
SNMPMib: TSNMPMib;
|
||||||
n:integer;
|
n:integer;
|
||||||
begin
|
begin
|
||||||
@ -162,24 +150,35 @@ begin
|
|||||||
case (SNMPMib.ValueType) of
|
case (SNMPMib.ValueType) of
|
||||||
ASN1_INT, ASN1_COUNTER, ASN1_GAUGE, ASN1_TIMETICKS:
|
ASN1_INT, ASN1_COUNTER, ASN1_GAUGE, ASN1_TIMETICKS:
|
||||||
begin
|
begin
|
||||||
t := chr(strToInt('$'+copy(inttohex(strToInt(SNMPMib.Value),4),1,2)));
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID)
|
||||||
t := t+chr(strToInt('$'+copy(inttohex(strToInt(SNMPMib.Value),4),3,2)));
|
+ASNObject(ASNEncInt(strToIntDef(SNMPMib.Value,0)),SNMPMib.ValueType);
|
||||||
s := ASNObject(MibToID(SNMPMib.OID),6) + ASNObject(t,SNMPMib.ValueType);
|
|
||||||
end;
|
end;
|
||||||
else
|
ASN1_OBJID:
|
||||||
s := ASNObject(MibToID(SNMPMib.OID),6) + ASNObject(SNMPMib.Value,SNMPMib.ValueType);
|
begin
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID) + ASNObject(MibToID(SNMPMib.Value),SNMPMib.ValueType);
|
||||||
|
end;
|
||||||
|
ASN1_IPADDR:
|
||||||
|
begin
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID) + ASNObject(IPToID(SNMPMib.Value),SNMPMib.ValueType);
|
||||||
|
end;
|
||||||
|
ASN1_NULL:
|
||||||
|
begin
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID) + ASNObject('',ASN1_NULL);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID) + ASNObject(SNMPMib.Value,SNMPMib.ValueType);
|
||||||
end;
|
end;
|
||||||
data := data + ASNObject(s, $30);
|
data := data + ASNObject(s, ASN1_SEQ);
|
||||||
end;
|
end;
|
||||||
data:=ASNObject(data,$30);
|
data:=ASNObject(data,ASN1_SEQ);
|
||||||
data:=ASNObject(char(Self.ID),2)
|
data:=ASNObject(char(Self.ID),ASN1_INT)
|
||||||
+ASNObject(char(Self.ErrorStatus),2)
|
+ASNObject(char(Self.ErrorStatus),ASN1_INT)
|
||||||
+ASNObject(char(Self.ErrorIndex),2)
|
+ASNObject(char(Self.ErrorIndex),ASN1_INT)
|
||||||
+data;
|
+data;
|
||||||
data:=ASNObject(char(Self.Version),2)
|
data:=ASNObject(char(Self.Version),ASN1_INT)
|
||||||
+ASNObject(Self.community,4)
|
+ASNObject(Self.community,ASN1_OCTSTR)
|
||||||
+ASNObject(data,Self.PDUType);
|
+ASNObject(data,Self.PDUType);
|
||||||
data:=ASNObject(data,$30);
|
data:=ASNObject(data,ASN1_SEQ);
|
||||||
Result:=data;
|
Result:=data;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -200,14 +199,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{TSNMPRec.MIBAdd}
|
{TSNMPRec.MIBAdd}
|
||||||
procedure TSNMPRec.MIBAdd(MIB,Value:string; ValueType:TSNMPMibValueType);
|
procedure TSNMPRec.MIBAdd(MIB,Value:string; ValueType:integer);
|
||||||
var
|
var
|
||||||
SNMPMib: TSNMPMib;
|
SNMPMib: TSNMPMib;
|
||||||
begin
|
begin
|
||||||
SNMPMib := TSNMPMib.Create;
|
SNMPMib := TSNMPMib.Create;
|
||||||
SNMPMib.OID := MIB;
|
SNMPMib.OID := MIB;
|
||||||
SNMPMib.Value := Value;
|
SNMPMib.Value := Value;
|
||||||
SNMPMib.ValueType := ConvertValueType(ValueType);
|
SNMPMib.ValueType := ValueType;
|
||||||
SNMPMibList.Add(SNMPMib);
|
SNMPMibList.Add(SNMPMib);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -237,21 +236,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TSNMPRec.GetValueType}
|
|
||||||
function TSNMPRec.ConvertValueType(ValueType: TSNMPMibValueType): integer;
|
|
||||||
begin
|
|
||||||
result := ASN1_NULL;
|
|
||||||
if (ValueType = smvtInteger) then result := ASN1_INT;
|
|
||||||
if (ValueType = smvtOctetString) then result := ASN1_OCTSTR;
|
|
||||||
if (ValueType = smvtNull) then result := ASN1_NULL;
|
|
||||||
if (ValueType = smvtObjectId) then result := ASN1_OBJID;
|
|
||||||
if (ValueType = smvtSequence) then result := ASN1_SEQ;
|
|
||||||
if (ValueType = smvtIpAddress) then result := ASN1_IPADDR;
|
|
||||||
if (ValueType = smvtCounter) then result := ASN1_COUNTER;
|
|
||||||
if (ValueType = smvtGauge) then result := ASN1_GAUGE;
|
|
||||||
if (ValueType = smvtTimeTicks) then result := ASN1_TIMETICKS;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{==============================================================================}
|
{==============================================================================}
|
||||||
|
|
||||||
@ -265,7 +249,7 @@ begin
|
|||||||
Reply.Clear;
|
Reply.Clear;
|
||||||
sock:=TUDPBlockSocket.create;
|
sock:=TUDPBlockSocket.create;
|
||||||
sock.createsocket;
|
sock.createsocket;
|
||||||
timeout:=5;
|
timeout:=5000;
|
||||||
host:='localhost';
|
host:='localhost';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -308,12 +292,11 @@ function SNMPget (Oid, Community, SNMPHost:string; var Value:string):Boolean;
|
|||||||
var
|
var
|
||||||
SNMP:TSNMPSend;
|
SNMP:TSNMPSend;
|
||||||
begin
|
begin
|
||||||
Result:=False;
|
|
||||||
SNMP:=TSNMPSend.Create;
|
SNMP:=TSNMPSend.Create;
|
||||||
try
|
try
|
||||||
Snmp.Query.community:=Community;
|
Snmp.Query.community:=Community;
|
||||||
Snmp.Query.PDUType:=PDUGetRequest;
|
Snmp.Query.PDUType:=PDUGetRequest;
|
||||||
Snmp.Query.MIBAdd(Oid,'',smvtNull);
|
Snmp.Query.MIBAdd(Oid,'',ASN1_NULL);
|
||||||
Snmp.host:=SNMPHost;
|
Snmp.host:=SNMPHost;
|
||||||
Result:=Snmp.DoIt;
|
Result:=Snmp.DoIt;
|
||||||
if Result then
|
if Result then
|
||||||
@ -323,7 +306,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SNMPSet(Oid, Community, SNMPHost, Value: string; ValueType: TSNMPMibValueType): boolean;
|
function SNMPSet(Oid, Community, SNMPHost, Value: string; ValueType: integer): boolean;
|
||||||
var
|
var
|
||||||
SNMPSend: TSNMPSend;
|
SNMPSend: TSNMPSend;
|
||||||
begin
|
begin
|
||||||
|
127
snmptrap.pas
127
snmptrap.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.002.001 |
|
| Project : Delphree - Synapse | 002.000.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: SNMP traps |
|
| Content: SNMP traps |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -29,7 +29,7 @@ unit SNMPTrap;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, BlckSock, SynaUtil, ASN1Util;
|
Classes, SysUtils, BlckSock, SynaUtil, ASN1Util, SNMPsend;
|
||||||
|
|
||||||
const
|
const
|
||||||
TRAP_PORT = 162;
|
TRAP_PORT = 162;
|
||||||
@ -57,12 +57,11 @@ type
|
|||||||
GenTrap: integer;
|
GenTrap: integer;
|
||||||
SpecTrap: integer;
|
SpecTrap: integer;
|
||||||
TimeTicks: integer;
|
TimeTicks: integer;
|
||||||
MIBOID: TStringList;
|
SNMPMibList: TList;
|
||||||
MIBValue: TStringList;
|
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Clear;
|
procedure Clear;
|
||||||
procedure MIBAdd(MIB, Value: string);
|
procedure MIBAdd(MIB, Value: string; ValueType:integer);
|
||||||
procedure MIBDelete(Index: integer);
|
procedure MIBDelete(Index: integer);
|
||||||
function MIBGet(MIB: string): string;
|
function MIBGet(MIB: string): string;
|
||||||
function EncodeTrap: integer;
|
function EncodeTrap: integer;
|
||||||
@ -83,7 +82,7 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function SendTrap(Dest, Source, Enterprise, Community: string;
|
function SendTrap(Dest, Source, Enterprise, Community: string;
|
||||||
Generic, Specific, Seconds: integer; MIBName, MIBValue: TStringList): integer;
|
Generic, Specific, Seconds: integer; MIBName, MIBValue: string; MIBtype:integer): integer;
|
||||||
function RecvTrap(var Dest, Source, Enterprise, Community: string;
|
function RecvTrap(var Dest, Source, Enterprise, Community: string;
|
||||||
var Generic, Specific, Seconds: integer; var MIBName, MIBValue: TStringList): integer;
|
var Generic, Specific, Seconds: integer; var MIBName, MIBValue: TStringList): integer;
|
||||||
|
|
||||||
@ -92,8 +91,7 @@ implementation
|
|||||||
constructor TTrapPDU.Create;
|
constructor TTrapPDU.Create;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
MIBOID := TStringList.Create;
|
SNMPMibList := TList.create;
|
||||||
MIBValue := TStringList.Create;
|
|
||||||
TrapPort := TRAP_PORT;
|
TrapPort := TRAP_PORT;
|
||||||
Version := SNMP_VERSION;
|
Version := SNMP_VERSION;
|
||||||
PDUType := PDU_TRAP;
|
PDUType := PDU_TRAP;
|
||||||
@ -102,54 +100,89 @@ end;
|
|||||||
|
|
||||||
destructor TTrapPDU.Destroy;
|
destructor TTrapPDU.Destroy;
|
||||||
begin
|
begin
|
||||||
MIBValue.Free;
|
SNMPMibList.free;
|
||||||
MIBOID.Free;
|
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTrapPDU.Clear;
|
procedure TTrapPDU.Clear;
|
||||||
|
var
|
||||||
|
i:integer;
|
||||||
begin
|
begin
|
||||||
MIBOID.Clear;
|
for i := 0 to SNMPMibList.count - 1 do
|
||||||
MIBValue.Clear;
|
TSNMPMib(SNMPMibList[i]).Free;
|
||||||
|
SNMPMibList.Clear;
|
||||||
TrapPort := TRAP_PORT;
|
TrapPort := TRAP_PORT;
|
||||||
Version := SNMP_VERSION;
|
Version := SNMP_VERSION;
|
||||||
PDUType := PDU_TRAP;
|
PDUType := PDU_TRAP;
|
||||||
Community := 'public';
|
Community := 'public';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTrapPDU.MIBAdd(MIB, Value: string);
|
procedure TTrapPDU.MIBAdd(MIB, Value: string; ValueType:integer);
|
||||||
|
var
|
||||||
|
SNMPMib: TSNMPMib;
|
||||||
begin
|
begin
|
||||||
MIBOID.Add(MIB);
|
SNMPMib := TSNMPMib.Create;
|
||||||
MIBValue.Add(Value);
|
SNMPMib.OID := MIB;
|
||||||
|
SNMPMib.Value := Value;
|
||||||
|
SNMPMib.ValueType := ValueType;
|
||||||
|
SNMPMibList.Add(SNMPMib);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTrapPDU.MIBDelete(Index: integer);
|
procedure TTrapPDU.MIBDelete(Index: integer);
|
||||||
begin
|
begin
|
||||||
MIBOID.Delete(Index);
|
if (Index >= 0) and (Index < SNMPMibList.count) then
|
||||||
MIBValue.Delete(Index);
|
begin
|
||||||
|
TSNMPMib(SNMPMibList[Index]).Free;
|
||||||
|
SNMPMibList.Delete(Index);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTrapPDU.MIBGet(MIB: string): string;
|
function TTrapPDU.MIBGet(MIB: string): string;
|
||||||
var
|
var
|
||||||
x: integer;
|
i: integer;
|
||||||
begin
|
begin
|
||||||
x := MIBOID.IndexOf(MIB);
|
Result := '';
|
||||||
if (x < 0) then
|
for i := 0 to SNMPMibList.count - 1 do
|
||||||
Result := ''
|
begin
|
||||||
else
|
if ((TSNMPMib(SNMPMibList[i])).OID = MIB) then
|
||||||
Result := MIBValue[x];
|
begin
|
||||||
|
Result := (TSNMPMib(SNMPMibList[i])).Value;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTrapPDU.EncodeTrap: integer;
|
function TTrapPDU.EncodeTrap: integer;
|
||||||
var
|
var
|
||||||
s: string;
|
s: string;
|
||||||
n: integer;
|
n: integer;
|
||||||
|
SNMPMib: TSNMPMib;
|
||||||
begin
|
begin
|
||||||
Buffer := '';
|
Buffer := '';
|
||||||
for n:=0 to MIBOID.Count-1 do
|
for n:=0 to SNMPMibList.Count-1 do
|
||||||
begin
|
begin
|
||||||
s := ASNObject(MibToID(MIBOID[n]), ASN1_OBJID)
|
SNMPMib := SNMPMibList[n];
|
||||||
+ ASNObject(MIBValue[n], ASN1_OCTSTR);
|
case (SNMPMib.ValueType) of
|
||||||
|
ASN1_INT, ASN1_COUNTER, ASN1_GAUGE, ASN1_TIMETICKS:
|
||||||
|
begin
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID)
|
||||||
|
+ASNObject(ASNEncInt(strToIntDef(SNMPMib.Value,0)),SNMPMib.ValueType);
|
||||||
|
end;
|
||||||
|
ASN1_OBJID:
|
||||||
|
begin
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID) + ASNObject(MibToID(SNMPMib.Value),SNMPMib.ValueType);
|
||||||
|
end;
|
||||||
|
ASN1_IPADDR:
|
||||||
|
begin
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID) + ASNObject(IPToID(SNMPMib.Value),SNMPMib.ValueType);
|
||||||
|
end;
|
||||||
|
ASN1_NULL:
|
||||||
|
begin
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID) + ASNObject('',ASN1_NULL);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
s := ASNObject(MibToID(SNMPMib.OID),ASN1_OBJID) + ASNObject(SNMPMib.Value,SNMPMib.ValueType);
|
||||||
|
end;
|
||||||
Buffer := Buffer + ASNObject(s, ASN1_SEQ);
|
Buffer := Buffer + ASNObject(s, ASN1_SEQ);
|
||||||
end;
|
end;
|
||||||
Buffer := ASNObject(Buffer, ASN1_SEQ);
|
Buffer := ASNObject(Buffer, ASN1_SEQ);
|
||||||
@ -171,24 +204,26 @@ function TTrapPDU.DecodeTrap: integer;
|
|||||||
var
|
var
|
||||||
Pos, EndPos: integer;
|
Pos, EndPos: integer;
|
||||||
Sm, Sv: string;
|
Sm, Sv: string;
|
||||||
|
Svt:integer;
|
||||||
begin
|
begin
|
||||||
|
clear;
|
||||||
Pos := 2;
|
Pos := 2;
|
||||||
EndPos := ASNDecLen(Pos, Buffer);
|
EndPos := ASNDecLen(Pos, Buffer);
|
||||||
Version := StrToIntDef(ASNItem(Pos, Buffer), 0);
|
Version := StrToIntDef(ASNItem(Pos, Buffer,svt), 0);
|
||||||
Community := ASNItem(Pos, Buffer);
|
Community := ASNItem(Pos, Buffer,svt);
|
||||||
PDUType := StrToIntDef(ASNItem(Pos, Buffer), PDU_TRAP);
|
PDUType := StrToIntDef(ASNItem(Pos, Buffer,svt), PDU_TRAP);
|
||||||
Enterprise := IdToMIB(ASNItem(Pos, Buffer));
|
Enterprise := IdToMIB(ASNItem(Pos, Buffer,svt));
|
||||||
TrapHost := ASNItem(Pos, Buffer);
|
TrapHost := ASNItem(Pos, Buffer,svt);
|
||||||
GenTrap := StrToIntDef(ASNItem(Pos, Buffer), 0);
|
GenTrap := StrToIntDef(ASNItem(Pos, Buffer,svt), 0);
|
||||||
Spectrap := StrToIntDef(ASNItem(Pos, Buffer), 0);
|
Spectrap := StrToIntDef(ASNItem(Pos, Buffer,svt), 0);
|
||||||
TimeTicks := StrToIntDef(ASNItem(Pos, Buffer), 0);
|
TimeTicks := StrToIntDef(ASNItem(Pos, Buffer,svt), 0);
|
||||||
ASNItem(Pos, Buffer);
|
ASNItem(Pos, Buffer,svt);
|
||||||
while (Pos < EndPos) do
|
while (Pos < EndPos) do
|
||||||
begin
|
begin
|
||||||
ASNItem(Pos, Buffer);
|
ASNItem(Pos, Buffer,svt);
|
||||||
Sm := ASNItem(Pos, Buffer);
|
Sm := ASNItem(Pos, Buffer,svt);
|
||||||
Sv := ASNItem(Pos, Buffer);
|
Sv := ASNItem(Pos, Buffer,svt);
|
||||||
MIBAdd(Sm, Sv);
|
MIBAdd(Sm, Sv, svt);
|
||||||
end;
|
end;
|
||||||
Result := 1;
|
Result := 1;
|
||||||
end;
|
end;
|
||||||
@ -198,7 +233,7 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
Sock := TUDPBlockSocket.Create;
|
Sock := TUDPBlockSocket.Create;
|
||||||
Trap := TTrapPDU.Create;
|
Trap := TTrapPDU.Create;
|
||||||
Timeout := 5;
|
Timeout := 5000;
|
||||||
SNMPHost := '127.0.0.1';
|
SNMPHost := '127.0.0.1';
|
||||||
Sock.CreateSocket;
|
Sock.CreateSocket;
|
||||||
end;
|
end;
|
||||||
@ -238,10 +273,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function SendTrap(Dest, Source, Enterprise, Community: string;
|
function SendTrap(Dest, Source, Enterprise, Community: string;
|
||||||
Generic, Specific, Seconds: integer; MIBName, MIBValue: TStringList): integer;
|
Generic, Specific, Seconds: integer; MIBName, MIBValue: string; MIBtype:integer): integer;
|
||||||
var
|
var
|
||||||
SNMP: TTrapSNMP;
|
SNMP: TTrapSNMP;
|
||||||
i: integer;
|
|
||||||
begin
|
begin
|
||||||
SNMP := TTrapSNMP.Create;
|
SNMP := TTrapSNMP.Create;
|
||||||
try
|
try
|
||||||
@ -252,8 +286,7 @@ begin
|
|||||||
SNMP.Trap.GenTrap := Generic;
|
SNMP.Trap.GenTrap := Generic;
|
||||||
SNMP.Trap.SpecTrap := Specific;
|
SNMP.Trap.SpecTrap := Specific;
|
||||||
SNMP.Trap.TimeTicks := Seconds;
|
SNMP.Trap.TimeTicks := Seconds;
|
||||||
for i:=0 to (MIBName.Count - 1) do
|
SNMP.Trap.MIBAdd(MIBName,MIBValue,MIBType);
|
||||||
SNMP.Trap.MIBAdd(MIBName[i], MIBValue[i]);
|
|
||||||
Result := SNMP.Send;
|
Result := SNMP.Send;
|
||||||
finally
|
finally
|
||||||
SNMP.Free;
|
SNMP.Free;
|
||||||
@ -282,10 +315,10 @@ begin
|
|||||||
Seconds := SNMP.Trap.TimeTicks;
|
Seconds := SNMP.Trap.TimeTicks;
|
||||||
MIBName.Clear;
|
MIBName.Clear;
|
||||||
MIBValue.Clear;
|
MIBValue.Clear;
|
||||||
for i:=0 to (SNMP.Trap.MIBOID.Count - 1) do
|
for i:=0 to (SNMP.Trap.SNMPMibList.count - 1) do
|
||||||
begin
|
begin
|
||||||
MIBName.Add(SNMP.Trap.MIBOID[i]);
|
MIBName.Add(TSNMPMib(SNMP.Trap.SNMPMibList[i]).OID);
|
||||||
MIBValue.Add(SNMP.Trap.MIBValue[i]);
|
MIBValue.Add(TSNMPMib(SNMP.Trap.SNMPMibList[i]).Value);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.000.000 |
|
| Project : Delphree - Synapse | 001.001.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: SNTP client |
|
| Content: SNTP client |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -73,7 +73,7 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
sock:=TUDPBlockSocket.create;
|
sock:=TUDPBlockSocket.create;
|
||||||
sock.CreateSocket;
|
sock.CreateSocket;
|
||||||
timeout:=5;
|
timeout:=5000;
|
||||||
sntphost:='localhost';
|
sntphost:='localhost';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
24
synautil.pas
24
synautil.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Delphree - Synapse | 001.002.000 |
|
| Project : Delphree - Synapse | 001.002.001 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: support procedures and functions |
|
| Content: support procedures and functions |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -46,6 +46,9 @@ function IPToID(Host: string): string;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
ASN1util;
|
||||||
|
|
||||||
{==============================================================================}
|
{==============================================================================}
|
||||||
{timezone}
|
{timezone}
|
||||||
function timezone:string;
|
function timezone:string;
|
||||||
@ -54,8 +57,12 @@ var
|
|||||||
bias:integer;
|
bias:integer;
|
||||||
h,m:integer;
|
h,m:integer;
|
||||||
begin
|
begin
|
||||||
GetTimeZoneInformation(Zoneinfo);
|
case GetTimeZoneInformation(Zoneinfo) of
|
||||||
bias:=zoneinfo.bias;
|
2: bias:=zoneinfo.bias+zoneinfo.DaylightBias;
|
||||||
|
1: bias:=zoneinfo.bias+zoneinfo.StandardBias;
|
||||||
|
else
|
||||||
|
bias:=zoneinfo.bias;
|
||||||
|
end;
|
||||||
if bias<=0 then result:='+'
|
if bias<=0 then result:='+'
|
||||||
else result:='-';
|
else result:='-';
|
||||||
bias:=abs(bias);
|
bias:=abs(bias);
|
||||||
@ -215,11 +222,11 @@ begin
|
|||||||
result:='';
|
result:='';
|
||||||
x:=walkint(mib);
|
x:=walkint(mib);
|
||||||
x:=x*40+walkint(mib);
|
x:=x*40+walkint(mib);
|
||||||
result:=char(x);
|
result:=ASNEncOIDItem(x);
|
||||||
while mib<>'' do
|
while mib<>'' do
|
||||||
begin
|
begin
|
||||||
x:=walkint(mib);
|
x:=walkint(mib);
|
||||||
result:=result+char(x);
|
result:=result+ASNEncOIDItem(x);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -231,10 +238,11 @@ var
|
|||||||
x,y,n:integer;
|
x,y,n:integer;
|
||||||
begin
|
begin
|
||||||
result:='';
|
result:='';
|
||||||
For n:=1 to length(id) do
|
n:=1;
|
||||||
|
while length(id)+1>n do
|
||||||
begin
|
begin
|
||||||
x:=ord(id[n]);
|
x:=ASNDecOIDItem(n,id);
|
||||||
if n=1 then
|
if (n-1)=1 then
|
||||||
begin
|
begin
|
||||||
y:=x div 40;
|
y:=x div 40;
|
||||||
x:=x mod 40;
|
x:=x mod 40;
|
||||||
|
Reference in New Issue
Block a user