summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
fd34612)
14 files changed:
\r
{$include lcoreconfig.inc}\r
\r
\r
{$include lcoreconfig.inc}\r
\r
-{$ifndef win32}\r
-uses sockets;\r
-{$endif}\r
+uses\r
+ {$ifndef win32}{$ifdef ipv6}sockets,{$endif}{$endif}\r
+ pgtypes;\r
\r
{$ifdef fpc}\r
{$mode delphi}\r
\r
{$ifdef fpc}\r
{$mode delphi}\r
{$include uint32.inc}\r
\r
const\r
{$include uint32.inc}\r
\r
const\r
- hexchars:array[0..15] of char='0123456789abcdef';\r
+ hexchars:array[0..15] of ansichar='0123456789abcdef';\r
{$ifdef win32}\r
AF_INET=2;\r
AF_INET6=23;\r
{$ifdef win32}\r
AF_INET=2;\r
AF_INET6=23;\r
while this is really just a string, on the interface side it must be treated\r
as an opaque var which is passed as "var" when it needs to be modified}\r
\r
while this is really just a string, on the interface side it must be treated\r
as an opaque var which is passed as "var" when it needs to be modified}\r
\r
+ tbiniplist=tbufferstring;\r
\r
function biniplist_new:tbiniplist;\r
procedure biniplist_add(var l:tbiniplist;ip:tbinip);\r
\r
function biniplist_new:tbiniplist;\r
procedure biniplist_add(var l:tbiniplist;ip:tbinip);\r
procedure biniplist_setcount(var l:tbiniplist;newlen:integer);\r
procedure biniplist_free(var l:tbiniplist);\r
procedure biniplist_addlist(var l:tbiniplist;const l2:tbiniplist);\r
procedure biniplist_setcount(var l:tbiniplist;newlen:integer);\r
procedure biniplist_free(var l:tbiniplist);\r
procedure biniplist_addlist(var l:tbiniplist;const l2:tbiniplist);\r
-function biniplist_tostr(const l:tbiniplist):string;\r
+function biniplist_tostr(const l:tbiniplist):thostname;\r
function isbiniplist(const l:tbiniplist):boolean;\r
\r
function htons(w:word):word;\r
function htonl(i:uint32):uint32;\r
\r
function isbiniplist(const l:tbiniplist):boolean;\r
\r
function htons(w:word):word;\r
function htonl(i:uint32):uint32;\r
\r
-function ipstrtobin(const s:string;var binip:tbinip):boolean;\r
-function ipstrtobinf(const s:string):tbinip;\r
-function ipbintostr(const binip:tbinip):string;\r
+function ipstrtobin(const s:thostname;var binip:tbinip):boolean;\r
+function ipstrtobinf(const s:thostname):tbinip;\r
+function ipbintostr(const binip:tbinip):thostname;\r
-function ip6bintostr(const bin:tin6_addr):string;\r
-function ip6strtobin(const s:string;var bin:tin6_addr):boolean;\r
+function ip6bintostr(const bin:tin6_addr):thostname;\r
+function ip6strtobin(const s:thostname;var bin:tin6_addr):boolean;\r
{$endif}\r
\r
function comparebinip(const ip1,ip2:tbinip):boolean;\r
{$endif}\r
\r
function comparebinip(const ip1,ip2:tbinip):boolean;\r
procedure addipsoffamily(var l:tbiniplist;const l2:tbiniplist;family:integer);\r
\r
{deprecated}\r
procedure addipsoffamily(var l:tbiniplist;const l2:tbiniplist;family:integer);\r
\r
{deprecated}\r
-function longip(s:string):longint;\r
+function longip(s:thostname):longint;\r
\r
function needconverttov4(const ip:tbinip):boolean;\r
procedure converttov4(var ip:tbinip);\r
procedure converttov6(var ip:tbinip);\r
\r
function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip;\r
\r
function needconverttov4(const ip:tbinip):boolean;\r
procedure converttov4(var ip:tbinip);\r
procedure converttov6(var ip:tbinip);\r
\r
function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip;\r
-function makeinaddrv(addr:tbinip;port:string;var inaddr:tinetsockaddrv):integer;\r
+function makeinaddrv(addr:tbinip;port:ansistring;var inaddr:tinetsockaddrv):integer;\r
function inaddrsize(inaddr:tinetsockaddrv):integer;\r
\r
implementation\r
function inaddrsize(inaddr:tinetsockaddrv):integer;\r
\r
implementation\r
-function makeinaddrv(addr:tbinip;port:string;var inaddr:tinetsockaddrv):integer;\r
+function makeinaddrv(addr:tbinip;port:ansistring;var inaddr:tinetsockaddrv):integer;\r
begin\r
result := 0;\r
{ biniptemp := forwardlookup(addr,10);}\r
begin\r
result := 0;\r
{ biniptemp := forwardlookup(addr,10);}\r
\r
{internal}\r
{converts dotted v4 IP to longint. returns host endian order}\r
\r
{internal}\r
{converts dotted v4 IP to longint. returns host endian order}\r
-function longip(s:string):longint;\r
+function longip(s:thostname):longint;\r
var\r
l:longint;\r
a,b:integer;\r
var\r
l:longint;\r
a,b:integer;\r
-function convertbyte(const s:string):integer;\r
+function convertbyte(const s:ansistring):integer;\r
begin\r
result := strtointdef(s,-1);\r
if result < 0 then begin\r
begin\r
result := strtointdef(s,-1);\r
if result < 0 then begin\r
ipstrtobin(s,result);\r
end;\r
\r
ipstrtobin(s,result);\r
end;\r
\r
-function ipstrtobin(const s:string;var binip:tbinip):boolean;\r
+function ipstrtobin(const s:thostname;var binip:tbinip):boolean;\r
begin\r
binip.family := 0;\r
result := false;\r
begin\r
binip.family := 0;\r
result := false;\r
-function ipbintostr(const binip:tbinip):string;\r
+function ipbintostr(const binip:tbinip):thostname;\r
var\r
a:integer;\r
begin\r
var\r
a:integer;\r
begin\r
{fpc has hostaddrtostr6 and strtohostaddr6 but the later isnt implemented yet}\r
\r
\r
{fpc has hostaddrtostr6 and strtohostaddr6 but the later isnt implemented yet}\r
\r
\r
-function ip6bintostr(const bin:tin6_addr):string;\r
+function ip6bintostr(const bin:tin6_addr):thostname;\r
{base16 with lowercase output}\r
{base16 with lowercase output}\r
-function makehex(w:word):string;\r
+function makehex(w:word):ansistring;\r
begin\r
result := '';\r
if w >= 4096 then result := result + hexchars[w shr 12];\r
begin\r
result := '';\r
if w >= 4096 then result := result + hexchars[w shr 12];\r
-function ip6strtobin(const s:string;var bin:tin6_addr):boolean;\r
+function ip6strtobin(const s:thostname;var bin:tin6_addr):boolean;\r
- fields:array[0..7] of string;\r
+ fields:array[0..7] of ansistring;\r
fieldcount:integer;\r
emptyfield:integer;\r
wordcount:integer;\r
fieldcount:integer;\r
emptyfield:integer;\r
wordcount:integer;\r
{-----------biniplist stuff--------------------------------------------------}\r
\r
const\r
{-----------biniplist stuff--------------------------------------------------}\r
\r
const\r
- biniplist_prefix='bipl'#0;\r
+ biniplist_prefix: ansistring = 'bipl'#0;\r
//fpc 1.0.x doesn't seem to like use of length function in a constant \r
//definition\r
//biniplist_prefixlen=length(biniplist_prefix);\r
//fpc 1.0.x doesn't seem to like use of length function in a constant \r
//definition\r
//biniplist_prefixlen=length(biniplist_prefix);\r
l := l + copy(l2,biniplist_prefixlen+1,maxlongint);\r
end;\r
\r
l := l + copy(l2,biniplist_prefixlen+1,maxlongint);\r
end;\r
\r
-function biniplist_tostr(const l:tbiniplist):string;\r
+function biniplist_tostr(const l:tbiniplist):thostname;\r
var\r
a:integer;\r
begin\r
var\r
a:integer;\r
begin\r
end;\r
\r
tstringlinklist=class(tlinklist)\r
end;\r
\r
tstringlinklist=class(tlinklist)\r
end;\r
\r
tthing=class(tlinklist)\r
end;\r
\r
tthing=class(tlinklist)\r
- name:string; {name/nick}\r
+ name:ansistring; {name/nick}\r
hashname:integer; {hash of name}\r
end;\r
\r
hashname:integer; {hash of name}\r
end;\r
\r
type\r
thashitem=class(tlinklist)\r
hash:integer;\r
type\r
thashitem=class(tlinklist)\r
hash:integer;\r
p:pointer;\r
end;\r
thashtable=array[0..hashtable_size-1] of thashitem;\r
phashtable=^thashtable;\r
\r
{adds "item" to the tree for name "s". the name must not exist (no checking done)}\r
p:pointer;\r
end;\r
thashtable=array[0..hashtable_size-1] of thashitem;\r
phashtable=^thashtable;\r
\r
{adds "item" to the tree for name "s". the name must not exist (no checking done)}\r
-procedure addtree(t:phashtable;s:string;item:pointer);\r
+procedure addtree(t:phashtable;s:ansistring;item:pointer);\r
\r
{removes name "s" from the tree. the name must exist (no checking done)}\r
\r
{removes name "s" from the tree. the name must exist (no checking done)}\r
-procedure deltree(t:phashtable;s:string);\r
+procedure deltree(t:phashtable;s:ansistring);\r
\r
{returns the item pointer for s, or nil if not found}\r
\r
{returns the item pointer for s, or nil if not found}\r
-function findtree(t:phashtable;s:string):pointer;\r
+function findtree(t:phashtable;s:ansistring):pointer;\r
-function makehash(s:string):integer;\r
+function makehash(s:ansistring):integer;\r
const\r
shifter=6;\r
var\r
const\r
shifter=6;\r
var\r
result := (result xor result shr 16) and (hashtable_size-1);\r
end;\r
\r
result := (result xor result shr 16) and (hashtable_size-1);\r
end;\r
\r
-procedure addtree(t:phashtable;s:string;item:pointer);\r
+procedure addtree(t:phashtable;s:ansistring;item:pointer);\r
var\r
hash:integer;\r
p:thashitem;\r
var\r
hash:integer;\r
p:thashitem;\r
linklistadd(tlinklist(t[hash]),tlinklist(p));\r
end;\r
\r
linklistadd(tlinklist(t[hash]),tlinklist(p));\r
end;\r
\r
-procedure deltree(t:phashtable;s:string);\r
+procedure deltree(t:phashtable;s:ansistring);\r
var\r
p,p2:thashitem;\r
hash:integer;\r
var\r
p,p2:thashitem;\r
hash:integer;\r
-function findtree(t:phashtable;s:string):pointer;\r
+function findtree(t:phashtable;s:ansistring):pointer;\r
var\r
p:thashitem;\r
hash:integer;\r
var\r
p:thashitem;\r
hash:integer;\r
//for this dnsasync object. This is not a reccomended mode of operation\r
//because it limits the app to one dns server but is kept for compatibility\r
//and special uses.\r
//for this dnsasync object. This is not a reccomended mode of operation\r
//because it limits the app to one dns server but is kept for compatibility\r
//and special uses.\r
+ addr,port:ansistring;\r
\r
overrideaf : integer;\r
\r
procedure cancel;//cancel an outstanding dns request\r
\r
overrideaf : integer;\r
\r
procedure cancel;//cancel an outstanding dns request\r
- function dnsresult:string; //get result of dnslookup as a string\r
+ function dnsresult:ansistring; //get result of dnslookup as a string\r
procedure dnsresultbin(var binip:tbinip); //get result of dnslookup as a tbinip\r
property dnsresultlist : tbiniplist read fresultlist;\r
procedure dnsresultbin(var binip:tbinip); //get result of dnslookup as a tbinip\r
property dnsresultlist : tbiniplist read fresultlist;\r
- procedure forwardlookup(const name:string); //start forward lookup,\r
+ procedure forwardlookup(const name:ansistring); //start forward lookup,\r
//preffering ipv4\r
procedure reverselookup(const binip:tbinip); //start reverse lookup\r
//preffering ipv4\r
procedure reverselookup(const binip:tbinip); //start reverse lookup\r
- procedure customlookup(const name:string;querytype:integer); //start custom type lookup\r
+ procedure customlookup(const name:ansistring;querytype:integer); //start custom type lookup\r
\r
constructor create(aowner:tcomponent); override;\r
destructor destroy; override;\r
\r
constructor create(aowner:tcomponent); override;\r
destructor destroy; override;\r
Src : TInetSockAddrV;\r
SrcLen : Integer;\r
fromip:tbinip;\r
Src : TInetSockAddrV;\r
SrcLen : Integer;\r
fromip:tbinip;\r
begin\r
socketno := tlsocket(sender).tag;\r
//writeln('got a reply on socket number ',socketno);\r
begin\r
socketno := tlsocket(sender).tag;\r
//writeln('got a reply on socket number ',socketno);\r
\r
function tdnsasync.sendquery(socketno:integer;const packet:tdnspacket;len:integer):boolean;\r
var\r
\r
function tdnsasync.sendquery(socketno:integer;const packet:tdnspacket;len:integer):boolean;\r
var\r
- destination : string;\r
+ destination : ansistring;\r
inaddr : tinetsockaddrv;\r
trytolisten:integer;\r
begin\r
inaddr : tinetsockaddrv;\r
trytolisten:integer;\r
begin\r
inc(numsockused);\r
end;\r
{$endif}\r
inc(numsockused);\r
end;\r
{$endif}\r
for i := 0 to numsockused-1 do begin\r
asyncprocess(i);\r
end;\r
for i := 0 to numsockused-1 do begin\r
asyncprocess(i);\r
end;\r
end;\r
\r
procedure tdnsasync.reverselookup;\r
end;\r
\r
procedure tdnsasync.reverselookup;\r
when a packet is received the application should put the packet in\r
recvbuf/recvbuflen , set state.parsepacket and call state_process again\r
\r
when a packet is received the application should put the packet in\r
recvbuf/recvbuflen , set state.parsepacket and call state_process again\r
\r
- once the app gets action_done it can determine sucess or failure in the\r
+ once the app gets action_done it can determine success or failure in the\r
following ways.\r
\r
on failure state.resultstr will be an empty string and state.resultbin will\r
following ways.\r
\r
on failure state.resultstr will be an empty string and state.resultbin will\r
{\r
(temporarily) use a different nameserver, regardless of the dnsserverlist\r
}\r
{\r
(temporarily) use a different nameserver, regardless of the dnsserverlist\r
}\r
-var overridednsserver:string;\r
+var overridednsserver:ansistring;\r
\r
const\r
maxnamelength=127;\r
\r
const\r
maxnamelength=127;\r
tdnsstate=record\r
id:word;\r
recursioncount:integer;\r
tdnsstate=record\r
id:word;\r
recursioncount:integer;\r
+ queryname:ansistring;\r
requesttype:word;\r
parsepacket:boolean;\r
requesttype:word;\r
parsepacket:boolean;\r
+ resultstr:ansistring;\r
resultbin:tbinip;\r
resultlist:tbiniplist;\r
resultaction:integer;\r
numrr1:array[0..3] of integer;\r
numrr2:integer;\r
resultbin:tbinip;\r
resultlist:tbiniplist;\r
resultaction:integer;\r
numrr1:array[0..3] of integer;\r
numrr2:integer;\r
sendpacketlen:integer;\r
sendpacket:tdnspacket;\r
recvpacketlen:integer;\r
sendpacketlen:integer;\r
sendpacket:tdnspacket;\r
recvpacketlen:integer;\r
//function buildrequest(const name:string;var packet:tdnspacket;requesttype:word):integer;\r
\r
//returns the DNS name used to reverse look up an IP, such as 4.3.2.1.in-addr.arpa for 1.2.3.4\r
//function buildrequest(const name:string;var packet:tdnspacket;requesttype:word):integer;\r
\r
//returns the DNS name used to reverse look up an IP, such as 4.3.2.1.in-addr.arpa for 1.2.3.4\r
-function makereversename(const binip:tbinip):string;\r
+function makereversename(const binip:tbinip):ansistring;\r
-procedure setstate_request_init(const name:string;var state:tdnsstate);\r
+procedure setstate_request_init(const name:ansistring;var state:tdnsstate);\r
\r
//set up state for a foward lookup. A family value of AF_INET6 will give only\r
//ipv6 results. Any other value will give only ipv4 results\r
\r
//set up state for a foward lookup. A family value of AF_INET6 will give only\r
//ipv6 results. Any other value will give only ipv4 results\r
-procedure setstate_forward(const name:string;var state:tdnsstate;family:integer);\r
+procedure setstate_forward(const name:ansistring;var state:tdnsstate;family:integer);\r
\r
procedure setstate_reverse(const binip:tbinip;var state:tdnsstate);\r
procedure setstate_failure(var state:tdnsstate);\r
//procedure setstate_return(const rrp:trrpointer;len:integer;var state:tdnsstate);\r
\r
//for custom raw lookups such as TXT, as desired by the user\r
\r
procedure setstate_reverse(const binip:tbinip;var state:tdnsstate);\r
procedure setstate_failure(var state:tdnsstate);\r
//procedure setstate_return(const rrp:trrpointer;len:integer;var state:tdnsstate);\r
\r
//for custom raw lookups such as TXT, as desired by the user\r
-procedure setstate_custom(const name:string; requesttype:integer; var state:tdnsstate);\r
+procedure setstate_custom(const name:ansistring; requesttype:integer; var state:tdnsstate);\r
\r
procedure state_process(var state:tdnsstate);\r
\r
\r
procedure state_process(var state:tdnsstate);\r
\r
//getcurrentsystemnameserver returns the nameserver the app should use and sets\r
//id to the id of that nameserver. id should later be used to report how laggy\r
//the servers response was and if it was timed out.\r
//getcurrentsystemnameserver returns the nameserver the app should use and sets\r
//id to the id of that nameserver. id should later be used to report how laggy\r
//the servers response was and if it was timed out.\r
-function getcurrentsystemnameserver(var id:integer) :string;\r
+function getcurrentsystemnameserver(var id:integer) :ansistring;\r
procedure reportlag(id:integer;lag:integer); //lag should be in microseconds and should be -1 to report a timeout\r
\r
//var\r
procedure reportlag(id:integer;lag:integer); //lag should be in microseconds and should be -1 to report a timeout\r
\r
//var\r
- failurereason:string;\r
+ failurereason:ansistring;\r
-function getquerytype(s:string):integer;\r
+function getquerytype(s:ansistring):integer;\r
-function getquerytype(s:string):integer;\r
+function getquerytype(s:ansistring):integer;\r
begin\r
s := uppercase(s);\r
result := 0;\r
begin\r
s := uppercase(s);\r
result := 0;\r
if (s = 'SPF') then result := querytype_spf;\r
end;\r
\r
if (s = 'SPF') then result := querytype_spf;\r
end;\r
\r
-function buildrequest(const name:string;var packet:tdnspacket;requesttype:word):integer;\r
+function buildrequest(const name:ansistring;var packet:tdnspacket;requesttype:word):integer;\r
arr:array[0..sizeof(packet)-1] of byte absolute packet;\r
begin\r
{ writeln('buildrequest: name: ',name);}\r
arr:array[0..sizeof(packet)-1] of byte absolute packet;\r
begin\r
{ writeln('buildrequest: name: ',name);}\r
arr[result-4] := requesttype shr 8;\r
end;\r
\r
arr[result-4] := requesttype shr 8;\r
end;\r
\r
-function makereversename(const binip:tbinip):string;\r
+function makereversename(const binip:tbinip):ansistring;\r
a,b:integer;\r
begin\r
name := '';\r
a,b:integer;\r
begin\r
name := '';\r
empty result + non null failurereason: failure\r
empty result + null failurereason: internal use\r
}\r
empty result + non null failurereason: failure\r
empty result + null failurereason: internal use\r
}\r
-function decodename(const packet:tdnspacket;len,start,recursion:integer;var numread:integer):string;\r
+function decodename(const packet:tdnspacket;len,start,recursion:integer;var numread:integer):ansistring;\r
var\r
arr:array[0..sizeof(packet)-1] of byte absolute packet;\r
var\r
arr:array[0..sizeof(packet)-1] of byte absolute packet;\r
a,b:integer;\r
begin\r
numread := 0;\r
a,b:integer;\r
begin\r
numread := 0;\r
failurereason := 'decoding name: got out of range2';\r
exit;\r
end;\r
failurereason := 'decoding name: got out of range2';\r
exit;\r
end;\r
- result := result + char(arr[a]);\r
+ result := result + ansichar(arr[a]);\r
end;\r
inc(numread,b+1);\r
\r
end;\r
inc(numread,b+1);\r
\r
\r
{==============================================================================}\r
\r
\r
{==============================================================================}\r
\r
-function getrawfromrr(const rrp:trrpointer;len:integer):string;\r
+function getrawfromrr(const rrp:trrpointer;len:integer):ansistring;\r
begin\r
setlength(result,htons(trr(rrp.p^).datalen));\r
uniquestring(result);\r
begin\r
setlength(result,htons(trr(rrp.p^).datalen));\r
uniquestring(result);\r
-procedure setstate_request_init(const name:string;var state:tdnsstate);\r
+procedure setstate_request_init(const name:ansistring;var state:tdnsstate);\r
begin\r
{destroy things properly}\r
state.resultstr := '';\r
begin\r
{destroy things properly}\r
state.resultstr := '';\r
state.parsepacket := false;\r
end;\r
\r
state.parsepacket := false;\r
end;\r
\r
-procedure setstate_forward(const name:string;var state:tdnsstate;family:integer);\r
+procedure setstate_forward(const name:ansistring;var state:tdnsstate;family:integer);\r
begin\r
setstate_request_init(name,state);\r
state.forwardfamily := family;\r
begin\r
setstate_request_init(name,state);\r
state.forwardfamily := family;\r
state.requesttype := querytype_ptr;\r
end;\r
\r
state.requesttype := querytype_ptr;\r
end;\r
\r
-procedure setstate_custom(const name:string; requesttype:integer; var state:tdnsstate);\r
+procedure setstate_custom(const name:ansistring; requesttype:integer; var state:tdnsstate);\r
begin\r
setstate_request_init(name,state);\r
state.requesttype := requesttype;\r
begin\r
setstate_request_init(name,state);\r
state.requesttype := requesttype;\r
type\r
tip_addr_string=packed record\r
Next :pointer;\r
type\r
tip_addr_string=packed record\r
Next :pointer;\r
- IpAddress : array[0..15] of char;\r
- ipmask : array[0..15] of char;\r
+ IpAddress : array[0..15] of ansichar;\r
+ ipmask : array[0..15] of ansichar;\r
context : dword;\r
end;\r
pip_addr_string=^tip_addr_string;\r
tFIXED_INFO=packed record\r
context : dword;\r
end;\r
pip_addr_string=^tip_addr_string;\r
tFIXED_INFO=packed record\r
- HostName : array[0..MAX_HOSTNAME_LEN-1] of char;\r
- DomainName : array[0..MAX_DOMAIN_NAME_LEN-1] of char;\r
+ HostName : array[0..MAX_HOSTNAME_LEN-1] of ansichar;\r
+ DomainName : array[0..MAX_DOMAIN_NAME_LEN-1] of ansichar;\r
currentdnsserver : pip_addr_string;\r
dnsserverlist : tip_addr_string;\r
nodetype : longint;\r
currentdnsserver : pip_addr_string;\r
dnsserverlist : tip_addr_string;\r
nodetype : longint;\r
- ScopeId : array[0..MAX_SCOPE_ID_LEN + 4] of char;\r
+ ScopeId : array[0..MAX_SCOPE_ID_LEN + 4] of ansichar;\r
enablerouting : longbool;\r
enableproxy : longbool;\r
enabledns : longbool;\r
enablerouting : longbool;\r
enableproxy : longbool;\r
enabledns : longbool;\r
currentdnsserver : pip_addr_string;\r
{$else}\r
t:textfile;\r
currentdnsserver : pip_addr_string;\r
{$else}\r
t:textfile;\r
a:integer;\r
{$endif}\r
begin\r
a:integer;\r
{$endif}\r
begin\r
-function getcurrentsystemnameserver(var id:integer):string;\r
+function getcurrentsystemnameserver(var id:integer):ansistring;\r
var\r
counter : integer;\r
\r
var\r
counter : integer;\r
\r
function getv6localips:tbiniplist;\r
var\r
t:textfile;\r
function getv6localips:tbiniplist;\r
var\r
t:textfile;\r
ip:tbinip;\r
a:integer;\r
begin\r
ip:tbinip;\r
a:integer;\r
begin\r
//on error the binip will have a family of 0 (other fiels are also currently\r
//zeroed out but may be used for further error information in future)\r
//timeout is in miliseconds, it is ignored when using windows dns\r
//on error the binip will have a family of 0 (other fiels are also currently\r
//zeroed out but may be used for further error information in future)\r
//timeout is in miliseconds, it is ignored when using windows dns\r
-function forwardlookup(name:string;timeout:integer):tbinip;\r
+function forwardlookup(name:ansistring;timeout:integer):tbinip;\r
\r
//convert a name to a list of all IP's returned\r
//this returns both v4 and v6 IP's, or possibly only v4 or v6, depending on settings\r
//on error, returns an empty list\r
\r
//convert a name to a list of all IP's returned\r
//this returns both v4 and v6 IP's, or possibly only v4 or v6, depending on settings\r
//on error, returns an empty list\r
-function forwardlookuplist(name:string;timeout:integer):tbiniplist;\r
+function forwardlookuplist(name:ansistring;timeout:integer):tbiniplist;\r
\r
\r
//convert an IP to a name, on error a null string will be returned, other\r
//details as above\r
\r
\r
//convert an IP to a name, on error a null string will be returned, other\r
//details as above\r
-function reverselookup(ip:tbinip;timeout:integer):string;\r
+function reverselookup(ip:tbinip;timeout:integer):ansistring;\r
function sendquery(socknum:integer;const packet:tdnspacket;len:integer):boolean;\r
var\r
a:integer;\r
function sendquery(socknum:integer;const packet:tdnspacket;len:integer):boolean;\r
var\r
a:integer;\r
- addr : string;\r
- port : string;\r
+ addr : ansistring;\r
+ port : ansistring;\r
inaddr : TInetSockAddrV;\r
begin\r
{ writeln('sendquery ',decodename(state.packet,state.packetlen,12,0,a),' ',state.requesttype);}\r
inaddr : TInetSockAddrV;\r
begin\r
{ writeln('sendquery ',decodename(state.packet,state.packetlen,12,0,a),' ',state.requesttype);}\r
inAddrtemp : TInetSockAddrV;\r
a:integer;\r
biniptemp:tbinip;\r
inAddrtemp : TInetSockAddrV;\r
a:integer;\r
biniptemp:tbinip;\r
begin\r
//init both sockets smultaneously, always, so they get succesive fd's\r
if fd[0] > 0 then exit;\r
begin\r
//init both sockets smultaneously, always, so they get succesive fd's\r
if fd[0] > 0 then exit;\r
Srcx : {$ifdef win32}sockaddr_in{$else}TInetSockAddrV{$endif} absolute Src;\r
SrcLen : Integer;\r
fromip:tbinip;\r
Srcx : {$ifdef win32}sockaddr_in{$else}TInetSockAddrV{$endif} absolute Src;\r
SrcLen : Integer;\r
fromip:tbinip;\r
\r
begin\r
if timeout < mintimeout then timeout := defaulttimeout;\r
\r
begin\r
if timeout < mintimeout then timeout := defaulttimeout;\r
-function forwardlookuplist(name:string;timeout:integer):tbiniplist;\r
+function forwardlookuplist(name:ansistring;timeout:integer):tbiniplist;\r
var\r
dummy : integer;\r
a,b:integer;\r
var\r
dummy : integer;\r
a,b:integer;\r
-function forwardlookup(name:string;timeout:integer):tbinip;\r
+function forwardlookup(name:ansistring;timeout:integer):tbinip;\r
var\r
listtemp:tbiniplist;\r
begin\r
var\r
listtemp:tbiniplist;\r
begin\r
result := biniplist_get(listtemp,0);\r
end;\r
\r
result := biniplist_get(listtemp,0);\r
end;\r
\r
-function reverselookup(ip:tbinip;timeout:integer):string;\r
+function reverselookup(ip:tbinip;timeout:integer):ansistring;\r
var\r
dummy : integer;\r
begin\r
var\r
dummy : integer;\r
begin\r
-uses binipstuff,classes,lcore;\r
+uses binipstuff,classes,lcore,pgtypes;\r
\r
{$include lcoreconfig.inc}\r
\r
//on failure a null string or zeroed out binip will be retuned and error will be\r
//set to a windows error code (error will be left untouched under non error\r
//conditions).\r
\r
{$include lcoreconfig.inc}\r
\r
//on failure a null string or zeroed out binip will be retuned and error will be\r
//set to a windows error code (error will be left untouched under non error\r
//conditions).\r
-function winforwardlookuplist(name : string;familyhint:integer;var error : integer) : tbiniplist;\r
-function winreverselookup(ip:tbinip;var error:integer):string;\r
+function winforwardlookuplist(name : thostname;familyhint:integer;var error : integer) : tbiniplist;\r
+function winreverselookup(ip:tbinip;var error:integer):thostname;\r
procedure execute; override;\r
public\r
onrequestdone:tsocketevent;\r
procedure execute; override;\r
public\r
onrequestdone:tsocketevent;\r
iplist : tbiniplist;\r
\r
iplist : tbiniplist;\r
\r
- procedure forwardlookup(name:string);\r
+ procedure forwardlookup(name:thostname);\r
procedure reverselookup(ip:tbinip);\r
destructor destroy; override;\r
procedure release;\r
procedure reverselookup(ip:tbinip);\r
destructor destroy; override;\r
procedure release;\r
\r
implementation\r
uses\r
\r
implementation\r
uses\r
- lsocket,pgtypes,sysutils,winsock,windows,messages;\r
+ { zipplet: moved pgtypes to interface because it's needed for the string definitions }\r
+ lsocket,sysutils,winsock,windows,messages;\r
\r
type\r
//taddrinfo = record; //forward declaration\r
\r
type\r
//taddrinfo = record; //forward declaration\r
ai_socktype : longint;\r
ai_protocol : longint;\r
ai_addrlen : taddrint;\r
ai_socktype : longint;\r
ai_protocol : longint;\r
ai_addrlen : taddrint;\r
- ai_canonname : pchar;\r
+ ai_canonname : pansichar;\r
ai_addr : pinetsockaddrv;\r
ai_next : paddrinfo;\r
end;\r
ppaddrinfo = ^paddrinfo;\r
ai_addr : pinetsockaddrv;\r
ai_next : paddrinfo;\r
end;\r
ppaddrinfo = ^paddrinfo;\r
- tgetaddrinfo = function(nodename : pchar; servname : pchar; hints : paddrinfo;res : ppaddrinfo) : longint; stdcall;\r
+ tgetaddrinfo = function(nodename : pansichar; servname : pansichar; hints : paddrinfo;res : ppaddrinfo) : longint; stdcall;\r
tfreeaddrinfo = procedure(ai : paddrinfo); stdcall;\r
tfreeaddrinfo = procedure(ai : paddrinfo); stdcall;\r
- tgetnameinfo = function(sa:Pinetsockaddrv;salen : longint; host:pchar;hostlen : longint;serv:pchar;servlen:longint;flags:longint) : longint;stdcall;\r
+ tgetnameinfo = function(sa:Pinetsockaddrv;salen : longint; host:pansichar;hostlen : longint;serv:pansichar;servlen:longint;flags:longint) : longint;stdcall;\r
var\r
getaddrinfo : tgetaddrinfo;\r
freeaddrinfo : tfreeaddrinfo;\r
var\r
getaddrinfo : tgetaddrinfo;\r
freeaddrinfo : tfreeaddrinfo;\r
plongint = ^longint;\r
pplongint = ^plongint;\r
\r
plongint = ^longint;\r
pplongint = ^plongint;\r
\r
-function v4onlygetaddrinfo(nodename : pchar; servname : pchar; hints : paddrinfo;res : ppaddrinfo) : longint; stdcall;\r
+function v4onlygetaddrinfo(nodename : pansichar; servname : pansichar; hints : paddrinfo;res : ppaddrinfo) : longint; stdcall;\r
var\r
output,prev,first : paddrinfo;\r
hostent : phostent;\r
var\r
output,prev,first : paddrinfo;\r
hostent : phostent;\r
if a<b then result := a else result := b;\r
end;\r
\r
if a<b then result := a else result := b;\r
end;\r
\r
-function v4onlygetnameinfo(sa:Pinetsockaddrv;salen : longint; host:pchar;hostlen : longint;serv:pchar;servlen:longint;flags:longint) : longint;stdcall;\r
+function v4onlygetnameinfo(sa:Pinetsockaddrv;salen : longint; host:pansichar;hostlen : longint;serv:pansichar;servlen:longint;flags:longint) : longint;stdcall;\r
var\r
hostent : phostent;\r
bytestocopy : integer;\r
var\r
hostent : phostent;\r
bytestocopy : integer;\r
var\r
libraryhandle : hmodule;\r
i : integer;\r
var\r
libraryhandle : hmodule;\r
i : integer;\r
+ dllname : ansistring;\r
\r
begin\r
if assigned(getaddrinfo) then exit; //procvars already populated\r
for i := 0 to 1 do begin\r
if i=0 then dllname := 'Ws2_32.dll' else dllname := 'Wship6.dll';\r
\r
begin\r
if assigned(getaddrinfo) then exit; //procvars already populated\r
for i := 0 to 1 do begin\r
if i=0 then dllname := 'Ws2_32.dll' else dllname := 'Wship6.dll';\r
- libraryhandle := LoadLibrary(pchar(dllname));\r
+ libraryhandle := LoadLibraryA(pansichar(dllname));\r
getaddrinfo := getprocaddress(libraryhandle,'getaddrinfo');\r
freeaddrinfo := getprocaddress(libraryhandle,'freeaddrinfo');\r
getnameinfo := getprocaddress(libraryhandle,'getnameinfo');\r
getaddrinfo := getprocaddress(libraryhandle,'getaddrinfo');\r
freeaddrinfo := getprocaddress(libraryhandle,'freeaddrinfo');\r
getnameinfo := getprocaddress(libraryhandle,'getnameinfo');\r
-function winforwardlookuplist(name : string;familyhint:integer;var error : integer) : tbiniplist;\r
+function winforwardlookuplist(name : thostname;familyhint:integer;var error : integer) : tbiniplist;\r
var\r
hints: taddrinfo;\r
res0,res : paddrinfo;\r
var\r
hints: taddrinfo;\r
res0,res : paddrinfo;\r
hints.ai_canonname := nil;\r
hints.ai_addr := nil;\r
hints.ai_next := nil;\r
hints.ai_canonname := nil;\r
hints.ai_addr := nil;\r
hints.ai_next := nil;\r
- getaddrinforesult := getaddrinfo(pchar(name),'1',@hints,@res);\r
+ getaddrinforesult := getaddrinfo(pansichar(name),'1',@hints,@res);\r
res0 := res;\r
result := biniplist_new;\r
if getaddrinforesult = 0 then begin\r
res0 := res;\r
result := biniplist_new;\r
if getaddrinforesult = 0 then begin\r
-function winreverselookup(ip:tbinip;var error : integer):string;\r
+function winreverselookup(ip:tbinip;var error : integer):thostname;\r
var\r
sa : tinetsockaddrv;\r
getnameinforesult : integer;\r
var\r
sa : tinetsockaddrv;\r
getnameinforesult : integer;\r
makeinaddrv(ip,'1',sa);\r
populateprocvars;\r
setlength(result,1025);\r
makeinaddrv(ip,'1',sa);\r
populateprocvars;\r
setlength(result,1025);\r
- getnameinforesult := getnameinfo(@sa,sizeof(tinetsockaddrv),pchar(result),length(result),nil,0,0);\r
+ getnameinforesult := getnameinfo(@sa,sizeof(tinetsockaddrv),pansichar(result),length(result),nil,0,0);\r
if getnameinforesult <> 0 then begin\r
error := getnameinforesult;\r
result := '';\r
if getnameinforesult <> 0 then begin\r
error := getnameinforesult;\r
result := '';\r
-procedure tdnswinasync.forwardlookup(name:string);\r
+procedure tdnswinasync.forwardlookup(name:thostname);\r
begin\r
self.name := name;\r
freverse := false;\r
begin\r
self.name := name;\r
freverse := false;\r
\r
procedure getmd5(const data;len:longint;var result);\r
\r
\r
procedure getmd5(const data;len:longint;var result);\r
\r
-function md5tostr(const md5:tmd5):string;\r
+function md5tostr(const md5:tmd5):ansistring;\r
-function inttohex(val,bits:integer):string;\r
+function inttohex(val,bits:integer):ansistring;\r
- hexchar:array[0..15] of char='0123456789abcdef';\r
+ hexchar:array[0..15] of ansichar='0123456789abcdef';\r
begin\r
inttohex := hexchar[val shr 4]+hexchar[val and $f];\r
end;\r
begin\r
inttohex := hexchar[val shr 4]+hexchar[val and $f];\r
end;\r
md5finish(t,result);\r
end;\r
\r
md5finish(t,result);\r
end;\r
\r
-function md5tostr(const md5:tmd5):string;\r
+function md5tostr(const md5:tmd5):ansistring;\r
begin\r
s := '';\r
for a := 0 to 15 do s := s + inttohex(md5[a],2);\r
begin\r
s := '';\r
for a := 0 to 15 do s := s + inttohex(md5[a],2);\r
lasterror:integer;\r
destroying:boolean;\r
recvbufsize:integer;\r
lasterror:integer;\r
destroying:boolean;\r
recvbufsize:integer;\r
- function receivestr:string; virtual;\r
+ function receivestr:tbufferstring; virtual;\r
procedure close;\r
procedure abort;\r
procedure internalclose(error:word); virtual;\r
procedure close;\r
procedure abort;\r
procedure internalclose(error:word); virtual;\r
procedure dup(invalue:longint);\r
\r
function sendflush : integer;\r
procedure dup(invalue:longint);\r
\r
function sendflush : integer;\r
- procedure sendstr(const str : string);virtual;\r
- procedure putstringinsendbuffer(const newstring : string);\r
+ procedure sendstr(const str : tbufferstring);virtual;\r
+ procedure putstringinsendbuffer(const newstring : tbufferstring);\r
function send(data:pointer;len:integer):integer;virtual;\r
procedure putdatainsendbuffer(data:pointer;len:integer); virtual;\r
procedure deletebuffereddata;\r
function send(data:pointer;len:integer):integer;virtual;\r
procedure putdatainsendbuffer(data:pointer;len:integer); virtual;\r
procedure deletebuffereddata;\r
-procedure tlasio.sendstr(const str : string);\r
+procedure tlasio.sendstr(const str : tbufferstring);\r
begin\r
putstringinsendbuffer(str);\r
sendflush;\r
end;\r
\r
begin\r
putstringinsendbuffer(str);\r
sendflush;\r
end;\r
\r
-procedure tlasio.putstringinsendbuffer(const newstring : string);\r
+procedure tlasio.putstringinsendbuffer(const newstring : tbufferstring);\r
begin\r
if newstring <> '' then putdatainsendbuffer(@newstring[1],length(newstring));\r
end;\r
begin\r
if newstring <> '' then putdatainsendbuffer(@newstring[1],length(newstring));\r
end;\r
function randombits(b:integer):longint;\r
\r
{generate a version 4 random uuid}\r
function randombits(b:integer):longint;\r
\r
{generate a version 4 random uuid}\r
-function generate_uuid:string;\r
+function generate_uuid:ansistring;\r
\r
{$ifndef nolcorernd}\r
\r
\r
{$ifndef nolcorernd}\r
\r
- ch:array[0..15] of char='0123456789abcdef';\r
+ ch:array[0..15] of ansichar='0123456789abcdef';\r
-function generate_uuid:string;\r
+function generate_uuid:ansistring;\r
var\r
buf:array[0..7] of word;\r
var\r
buf:array[0..7] of word;\r
-function inttohex(w:word):string;\r
+function inttohex(w:word):ansistring;\r
begin\r
result := ch[w shr 12] + ch[(w shr 8) and $f] + ch[(w shr 4) and $f] + ch[w and $f];\r
end;\r
begin\r
result := ch[w shr 12] + ch[(w shr 8) and $f] + ch[(w shr 4) and $f] + ch[w and $f];\r
end;\r
//host : THostentry ;\r
\r
//mainthread : boolean ; //for debuggin only\r
//host : THostentry ;\r
\r
//mainthread : boolean ; //for debuggin only\r
- addr:string;\r
- port:string;\r
- localaddr:string;\r
- localport:string;\r
- proto:string;\r
+ addr:thostname;\r
+ port:ansistring;\r
+ localaddr:thostname;\r
+ localport:ansistring;\r
+ proto:ansistring;\r
udp,dgram:boolean;\r
listenqueue:integer;\r
{$ifdef secondlistener}\r
udp,dgram:boolean;\r
listenqueue:integer;\r
{$ifdef secondlistener}\r
\r
procedure handlefdtrigger(readtrigger,writetrigger:boolean); override;\r
function send(data:pointer;len:integer):integer;override;\r
\r
procedure handlefdtrigger(readtrigger,writetrigger:boolean); override;\r
function send(data:pointer;len:integer):integer;override;\r
- procedure sendstr(const str : string);override;\r
+ procedure sendstr(const str : tbufferstring);override;\r
function Receive(Buf:Pointer;BufSize:integer):integer; override;\r
function getpeername(var addr:tsockaddrin;addrlen:integer):integer; virtual;\r
procedure getXaddrbin(var binip:tbinip); virtual;\r
procedure getpeeraddrbin(var binip:tbinip); virtual;\r
function Receive(Buf:Pointer;BufSize:integer):integer; override;\r
function getpeername(var addr:tsockaddrin;addrlen:integer):integer; virtual;\r
procedure getXaddrbin(var binip:tbinip); virtual;\r
procedure getpeeraddrbin(var binip:tbinip); virtual;\r
- function getXaddr:string; virtual;\r
- function getpeeraddr:string; virtual;\r
- function getXport:string; virtual;\r
- function getpeerport:string; virtual;\r
+ function getXaddr:thostname; virtual;\r
+ function getpeeraddr:thostname; virtual;\r
+ function getXport:ansistring; virtual;\r
+ function getpeerport:ansistring; virtual;\r
constructor Create(AOwner: TComponent); override;\r
\r
//this one has to be kept public for now because lcorewsaasyncselect calls it\r
constructor Create(AOwner: TComponent); override;\r
\r
//this one has to be kept public for now because lcorewsaasyncselect calls it\r
-procedure tlsocket.sendstr(const str : string);\r
+procedure tlsocket.sendstr(const str : tbufferstring);\r
begin\r
if dgram then begin\r
send(@str[1],length(str))\r
begin\r
if dgram then begin\r
send(@str[1],length(str))\r
yes,no:longint;\r
socktype:integer;\r
biniptemp:tbinip;\r
yes,no:longint;\r
socktype:integer;\r
biniptemp:tbinip;\r
begin\r
if state <> wsclosed then close;\r
udp := uppercase(proto) = 'UDP';\r
begin\r
if state <> wsclosed then close;\r
udp := uppercase(proto) = 'UDP';\r
fdhandlein := socket(biniptemp.family,socktype,0);\r
{$ifdef ipv6}\r
if (addr = '::') and (origaddr = '') and (fdhandlein < 0) then begin\r
fdhandlein := socket(biniptemp.family,socktype,0);\r
{$ifdef ipv6}\r
if (addr = '::') and (origaddr = '') and (fdhandlein < 0) then begin\r
- writeln('failed to create an IPV6 socket with error ',socketerror,'. trying to create an IPV4 one instead');\r
+ {writeln('failed to create an IPV6 socket with error ',socketerror,'. trying to create an IPV4 one instead');}\r
addr := '0.0.0.0';\r
fdhandlein := socket(PF_INET,socktype,0);\r
end;\r
addr := '0.0.0.0';\r
fdhandlein := socket(PF_INET,socktype,0);\r
end;\r
converttov4(binip);\r
end;\r
\r
converttov4(binip);\r
end;\r
\r
-function tlsocket.getXaddr:string;\r
+function tlsocket.getXaddr:thostname;\r
var\r
biniptemp:tbinip;\r
begin\r
var\r
biniptemp:tbinip;\r
begin\r
if result = '' then result := 'error';\r
end;\r
\r
if result = '' then result := 'error';\r
end;\r
\r
-function tlsocket.getpeeraddr:string;\r
+function tlsocket.getpeeraddr:thostname;\r
var\r
biniptemp:tbinip;\r
begin\r
var\r
biniptemp:tbinip;\r
begin\r
if result = '' then result := 'error';\r
end;\r
\r
if result = '' then result := 'error';\r
end;\r
\r
-function tlsocket.getXport:string;\r
+function tlsocket.getXport:ansistring;\r
var\r
addr:tinetsockaddrv;\r
i:integer;\r
var\r
addr:tinetsockaddrv;\r
i:integer;\r
result := inttostr(htons(addr.InAddr.port));\r
end;\r
\r
result := inttostr(htons(addr.InAddr.port));\r
end;\r
\r
-function tlsocket.getpeerport:string;\r
+function tlsocket.getpeerport:ansistring;\r
var\r
addr:tinetsockaddrv;\r
i:integer;\r
var\r
addr:tinetsockaddrv;\r
i:integer;\r
{$endif}\r
paddrint=^taddrint;\r
\r
{$endif}\r
paddrint=^taddrint;\r
\r
+ { string type for storing hostnames or IP addresses as strings }\r
+ thostname = ansistring;\r
+ { string type for storing data (bytes) }\r
+ tbufferstring = ansistring;\r
+\r
constructor create(asourcestream: tstream; adestroysourcestream:boolean);\r
constructor createf(filename : string);\r
\r
constructor create(asourcestream: tstream; adestroysourcestream:boolean);\r
constructor createf(filename : string);\r
\r
- function readline:string;\r
+ function readline:ansistring;\r
function eof:boolean;\r
destructor destroy; override;\r
private\r
function eof:boolean;\r
destructor destroy; override;\r
private\r
destroysourcestream := false;\r
end;\r
\r
destroysourcestream := false;\r
end;\r
\r
-constructor treadtxt.createf(filename : string);\r
+constructor treadtxt.createf(filename: string);\r
begin\r
create(tfilestream.create(filename,fmOpenRead),true);\r
end;\r
begin\r
create(tfilestream.create(filename,fmOpenRead),true);\r
end;\r
procedure processmessages;\r
\r
var\r
procedure processmessages;\r
\r
var\r
- onshutdown:procedure(s:string);\r
+ onshutdown:procedure(s:ansistring);\r