HTTP library

DOS specific questions.
Post Reply
Qlink
Posts: 79
Joined: Jun 06, 2007 15:21

HTTP library

Post by Qlink »

I've been working with the chisock library in Linux, and i'm wondering if there is anything similar available in DOS. Right now I'm writing a wget type program designed to also render QML pages, and it would be nice to be able to also make a DOS build. Anyone know of a library that will let me get a page into a string (with the necessary drivers present, of course)?
Fox
Posts: 353
Joined: Aug 08, 2006 13:39
Location: Lille, France
Contact:

Re: HTTP library

Post by Fox »

Qlink wrote:I've been working with the chisock library in Linux, and i'm wondering if there is anything similar available in DOS. Right now I'm writing a wget type program designed to also render QML pages, and it would be nice to be able to also make a DOS build. Anyone know of a library that will let me get a page into a string (with the necessary drivers present, of course)?
Hi!

This is a big problem in FreeBASIC. So far, nobody came up with any solution....

The most used network library used in DOS application these days is definitely use Watt32 (requires only a packet driver to work). Recently, I compiled a C program which uses this library, so I had to recompile the whole lib also.

Look here: http://mateusz.viste.free.fr/dos/htget.zip

There you will find two interesting files: libwatt.a and tcp.h. I guess that translating the tcp.h file into tcp.bi would be enough to start using the library... Unfortunately, I have no clue about how to translate the thing. If you do, feel free to try, and report here your results. ;-)
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

I don't have a DOS machine with a working net connection to test it, but here's a swig translated header:
http://freefile.kristopherw.us/uploads/ ... dos_tcp.bi
I had to add some return type specifiers to the c header, but it shouldn't have caused any problems, who knows why they didn't specify it.
Fox
Posts: 353
Joined: Aug 08, 2006 13:39
Location: Lille, France
Contact:

Post by Fox »

sir_mud wrote:I don't have a DOS machine with a working net connection to test it, but here's a swig translated header:
Wow, got many many compilation errors... Seems that SWIG isn't doing a great job here.

For example, I see some odd things like "TYPE BYTE AS UBYTE", I wonder how FreeBASIC is interpreting that...

Still, if anyone could come up with a working (at least minimalistic) header file for the libwatt.a library, it would be a great contribution to the FB DOS project. :-)
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

i'll take another look at it, shouldn't be too hard to clean up.

Code: Select all

''
''
'' tcp -- header translated with help of SWIG FB wrapper
''
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
''         be included in other distributions without authorization.
''
''
#ifndef __tcp_bi__
#define __tcp_bi__

#define WTCP_VER &h0102

#inclib "watt"
type word as uinteger
type longword as uinteger

type tcp_Socket
	undoc(0 to 4300-1) as ubyte
end type

type udp_Socket
	undoc(0 to 2200-1) as ubyte
end type

type sockaddr
	s_type as word
	s_port as word
	s_ip as longword
	s_spares(0 to 6-1) as ubyte
end type

type in_addr
	s_addr as longword
end type

#define MAX_COOKIES 10
#define MAX_NAMESERVERS 10
#define TCP_MODE_BINARY 0
#define TCP_MODE_ASCII 1
#define UDP_MODE_CHK 0
#define UDP_MODE_NOCHK 2
#define TCP_MODE_NAGLE 0
#define TCP_MODE_NONAGLE 4

declare function sock_init cdecl alias "sock_init" () as integer
declare function sock_read cdecl alias "sock_read" (byval s as any ptr, byval dp as ubyte ptr, byval len as integer) as integer
declare function sock_fastread cdecl alias "sock_fastread" (byval s as any ptr, byval dp as ubyte ptr, byval len as integer) as integer
declare function sock_write cdecl alias "sock_write" (byval s as any ptr, byval dp as ubyte ptr, byval len as integer) as integer
declare sub sock_enqueue cdecl alias "sock_enqueue" (byval s as any ptr, byval dp as ubyte ptr, byval len as integer)
declare function sock_fastwrite cdecl alias "sock_fastwrite" (byval s as any ptr, byval dp as ubyte ptr, byval len as integer) as integer
declare function sock_flush cdecl alias "sock_flush" (byval s as any ptr) as integer
declare function sock_flushnext cdecl alias "sock_flushnext" (byval s as any ptr) as integer
declare function sock_puts cdecl alias "sock_puts" (byval s as any ptr, byval dp as ubyte ptr) as integer
declare function sock_gets cdecl alias "sock_gets" (byval s as any ptr, byval dp as ubyte ptr, byval n as integer) as word
declare function sock_putc cdecl alias "sock_putc" (byval s as any ptr, byval c as ubyte) as ubyte
declare function sock_getc cdecl alias "sock_getc" (byval s as any ptr) as ubyte
declare function sock_dataready cdecl alias "sock_dataready" (byval s as any ptr) as word
declare function sock_close cdecl alias "sock_close" (byval s as any ptr) as integer
declare function sock_abort cdecl alias "sock_abort" (byval s as any ptr) as integer
declare function sock_printf cdecl alias "sock_printf" (byval s as any ptr, byval format as zstring ptr, ...) as integer
declare function sock_scanf cdecl alias "sock_scanf" (byval s as any ptr, byval format as zstring ptr, ...) as integer
declare function sock_mode cdecl alias "sock_mode" (byval s as any ptr, byval mode as word) as integer
declare sub db_write cdecl alias "db_write" (byval msg as zstring ptr)
declare sub dbug_init cdecl alias "dbug_init" ()
declare sub dbug_printf cdecl alias "dbug_printf" (byval as zstring ptr, ...)
declare function udp_open cdecl alias "udp_open" (byval s as any ptr, byval lport as word, byval ina as longword, byval port as word, byval datahandler as function cdecl(byval as ) as integer) as integer
declare function tcp_open cdecl alias "tcp_open" (byval s as any ptr, byval lport as word, byval ina as longword, byval port as word, byval datahandler as function cdecl(byval as ) as integer) as integer
declare function tcp_listen cdecl alias "tcp_listen" (byval s as any ptr, byval lport as word, byval ina as longword, byval port as word, byval datahandler as function cdecl(byval as ) as integer, byval timeout as word) as integer
declare function tcp_established cdecl alias "tcp_established" (byval s as any ptr) as integer
declare function rip cdecl alias "rip" (byval s as zstring ptr) as zstring ptr
declare function resolve cdecl alias "resolve" (byval name as zstring ptr) as longword
declare function reverse_addr_lookup cdecl alias "reverse_addr_lookup" (byval ipaddr as longword, byval name as zstring ptr) as integer
declare function aton cdecl alias "aton" (byval text as zstring ptr) as longword
declare function isaddr cdecl alias "isaddr" (byval text as zstring ptr) as integer
declare function tcp_cbreak cdecl alias "tcp_cbreak" (byval mode as word) as integer
declare function intel cdecl alias "intel" (byval x as longword) as longword
declare function intel16 cdecl alias "intel16" (byval x as word) as word
declare sub ip_timer_init cdecl alias "ip_timer_init" (byval s as any ptr, byval delayseconds as word)
declare function ip_timer_expired cdecl alias "ip_timer_expired" (byval s as any ptr) as word
extern my_ip_addr alias "my_ip_addr" as longword
extern sin_mask alias "sin_mask" as longword
extern sock_delay alias "sock_delay" as word
declare function tcp_shutdown cdecl alias "tcp_shutdown" () as integer
declare function tcp_Init cdecl alias "tcp_Init" () as integer
declare function sock_debugdump cdecl alias "sock_debugdump" (byval s as any ptr) as integer
declare function tcp_config cdecl alias "tcp_config" (byval path as zstring ptr) as integer
declare function tcp_tick cdecl alias "tcp_tick" (byval s as any ptr) as integer
declare function tcp_Retransmitter cdecl alias "tcp_Retransmitter" () as integer
declare function tcp_set_debug_state cdecl alias "tcp_set_debug_state" (byval x as word) as integer
extern _last_cookie alias "_last_cookie" as integer
extern _cookie(0 to 10-1) alias "_cookie" as longword
extern def_domain alias "def_domain" as zstring ptr
extern def_nameservers(0 to 10-1) alias "def_nameservers" as longword
extern wathndlcbrk alias "wathndlcbrk" as word
extern watcbroke alias "watcbroke" as word
declare function _ip_delay0 cdecl alias "_ip_delay0" (byval s as any ptr, byval seconds as integer, byval fn as function cdecl(byval as ) as integer, byval statusptr as any ptr) as integer
declare function _ip_delay1 cdecl alias "_ip_delay1" (byval s as any ptr, byval seconds as integer, byval fn as function cdecl(byval as ) as integer, byval statusptr as any ptr) as integer
declare function _ip_delay2 cdecl alias "_ip_delay2" (byval s as any ptr, byval seconds as integer, byval fn as function cdecl(byval as ) as integer, byval statusptr as any ptr) as integer
declare function set_timeout cdecl alias "set_timeout" (byval seconds as uinteger) as uinteger
declare function set_ttimeout cdecl alias "set_ttimeout" (byval ticks as uinteger) as uinteger
declare function chk_timeout cdecl alias "chk_timeout" (byval timeout as uinteger) as integer
declare function tcp_tick cdecl alias "tcp_tick" (byval s as any ptr) as integer
extern usr_init alias "usr_init" as sub cdecl(byval as )
declare function aton cdecl alias "aton" (byval string as zstring ptr) as longword
declare function _send_ping cdecl alias "_send_ping" (byval host as longword, byval countnum as longword, byval ttl as ubyte, byval tos as ubyte, byval theid as longword ptr) as integer
declare function _chk_ping cdecl alias "_chk_ping" (byval host as longword, byval ptr as longword ptr) as longword
declare sub _arp_register cdecl alias "_arp_register" (byval use as longword, byval instead_of as longword)
declare sub _eth_init cdecl alias "_eth_init" ()
declare function _eth_formatpacket cdecl alias "_eth_formatpacket" (byval eth_dest as any ptr, byval eth_type as word) as ubyte ptr
declare sub _eth_send cdecl alias "_eth_send" (byval len as word)
declare sub _eth_free cdecl alias "_eth_free" (byval buf as any ptr)
declare function _eth_arrived cdecl alias "_eth_arrived" (byval type_ptr as word ptr) as ubyte ptr
declare sub _eth_release cdecl alias "_eth_release" ()
declare function sock_rbsize cdecl alias "sock_rbsize" (byval s as any ptr) as integer
declare function sock_rbused cdecl alias "sock_rbused" (byval s as any ptr) as integer
declare function sock_rbleft cdecl alias "sock_rbleft" (byval s as any ptr) as integer
declare function sock_tbsize cdecl alias "sock_tbsize" (byval s as any ptr) as integer
declare function sock_tbused cdecl alias "sock_tbused" (byval s as any ptr) as integer
declare function sock_tbleft cdecl alias "sock_tbleft" (byval s as any ptr) as integer
declare function _chk_socket cdecl alias "_chk_socket" (byval s as tcp_Socket ptr) as integer
declare function inet_ntoa cdecl alias "inet_ntoa" (byval s as zstring ptr, byval x as longword) as zstring ptr
declare function psocket cdecl alias "psocket" (byval s as tcp_Socket ptr) as zstring ptr
declare function inet_addr cdecl alias "inet_addr" (byval s as zstring ptr) as longword
declare function sockerr cdecl alias "sockerr" (byval s as tcp_Socket ptr) as zstring ptr
declare function sockstate cdecl alias "sockstate" (byval s as tcp_Socket ptr) as zstring ptr
declare function getpeername cdecl alias "getpeername" (byval s as tcp_Socket ptr, byval dest as any ptr, byval len as integer ptr) as integer
declare function getsockname cdecl alias "getsockname" (byval s as tcp_Socket ptr, byval dest as any ptr, byval len as integer ptr) as integer
declare function gethostid cdecl alias "gethostid" () as longword
declare function sethostid cdecl alias "sethostid" (byval ip as longword) as longword
declare function getdomainname cdecl alias "getdomainname" (byval name as zstring ptr, byval length as integer) as zstring ptr
declare function setdomainname cdecl alias "setdomainname" (byval string as zstring ptr) as zstring ptr
declare function gethostname cdecl alias "gethostname" (byval name as zstring ptr, byval length as integer) as zstring ptr
declare function sethostname cdecl alias "sethostname" (byval string as zstring ptr) as zstring ptr
declare function ntohs cdecl alias "ntohs" (byval a as word) as word
declare function htons cdecl alias "htons" (byval a as word) as word
declare function ntohl cdecl alias "ntohl" (byval x as longword) as longword
declare function htonl cdecl alias "htonl" (byval x as longword) as longword
declare sub _arp_register cdecl alias "_arp_register" (byval use as longword, byval instead_of as longword)
declare function _arp_resolve cdecl alias "_arp_resolve" (byval ina as longword, byval ethap as any ptr, byval nowait as integer) as integer
declare function sock_established cdecl alias "sock_established" (byval s as tcp_Socket ptr) as integer
declare function sock_stats cdecl alias "sock_stats" (byval s as tcp_Socket ptr, byval days as word ptr, byval inactive as word ptr, byval cwindow as word ptr, byval avg as word ptr, byval sd as word ptr) as integer
declare function addwattcpd cdecl alias "addwattcpd" (byval p as sub cdecl(byval as )) as integer
declare function delwattcpd cdecl alias "delwattcpd" (byval p as sub cdecl(byval as )) as integer
declare function tap_add cdecl alias "tap_add" (byval socket as any ptr, byval userid as any ptr) as integer

#endif
*edit*
There ya go, try that.
Fox
Posts: 353
Joined: Aug 08, 2006 13:39
Location: Lille, France
Contact:

Post by Fox »

sir_mud wrote:There ya go, try that.
Hi sid_mud,

Thanks for your help :-)

I tried your (hand-modified) tcp.bi file right now, and here come all error messages I got: ;-)

d:/Mateusz/programy/dev/fb_020b/TCP.BI(67) error 56: Illegal specification, at parameter 1 () in 'Declare Function udp_open Cdecl Alias "udp_open" (Byval s As Any Ptr, Byval lport As word, Byval ina As longword, Byval port As word, Byval datahandler As Function Cdecl(Byval As ) As Integer) As Integer'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(68) error 56: Illegal specification, at parameter 1 () in 'Declare Function tcp_open Cdecl Alias "tcp_open" (Byval s As Any Ptr, Byval lport As word, Byval ina As longword, Byval port As word, Byval datahandler As Function Cdecl(Byval As ) As Integer) As Integer'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(69) error 56: Illegal specification, at parameter 1 () in 'Declare Function tcp_listen Cdecl Alias "tcp_listen" (Byval s As Any Ptr, Byval lport As word, Byval ina As longword, Byval port As word, Byval datahandler As Function Cdecl(Byval As ) As Integer, Byval timeout As word) As Integer'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(97) error 56: Illegal specification, at parameter 1 (timeout) in 'Declare Function _ip_delay0 Cdecl Alias "_ip_delay0" (Byval s As Any Ptr, Byval seconds As Integer, Byval fn As Function Cdecl(Byval As ) As Integer, Byval statusptr As Any Ptr) As Integer'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(98) error 56: Illegal specification, at parameter 1 (statusptr) in 'Declare Function _ip_delay1 Cdecl Alias "_ip_delay1" (Byval s As Any Ptr, Byval seconds As Integer, Byval fn As Function Cdecl(Byval As ) As Integer, Byval statusptr As Any Ptr) As Integer'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(99) error 56: Illegal specification, at parameter 1 (statusptr) in 'Declare Function _ip_delay2 Cdecl Alias "_ip_delay2" (Byval s As Any Ptr, Byval seconds As Integer, Byval fn As Function Cdecl(Byval As ) As Integer, Byval statusptr As Any Ptr) As Integer'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(103) error 4: Duplicated definition in 'Declare Function tcp_tick Cdecl Alias "tcp_tick" (Byval s As Any Ptr) As Integer'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(104) error 56: Illegal specification, at parameter 1 (s) in 'Extern usr_init Alias "usr_init" As Sub Cdecl(Byval As )'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(105) error 4: Duplicated definition in 'Declare Function aton Cdecl Alias "aton" (Byval String As Zstring Ptr) As longword'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(139) error 4: Duplicated definition in 'Declare Sub _arp_register Cdecl Alias "_arp_register" (Byval use As longword, Byval instead_of As longword)'

d:/Mateusz/programy/dev/fb_020b/TCP.BI(139) error 123: Too many errors, exiting
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

Some of the function-typed parameters have parameters without types - just "byval as". The parameter names given are probably misleading - there was a small "ghosting" bug in the compiler with parameter names in error messages.
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Post by Dinosaur »

Hi all

Evaluating this Tcp/IP stack at the moment.
http://www.sics.se/~adam/uip/uip-1.0-refman/

Very well documented, open source, BUT C again.

Regards
Fox
Posts: 353
Joined: Aug 08, 2006 13:39
Location: Lille, France
Contact:

Post by Fox »

Dinosaur wrote:Evaluating this Tcp/IP stack at the moment.
http://www.sics.se/~adam/uip/uip-1.0-refman/

Very well documented, open source, BUT C again.
Well... If you ask ME, I would say that *anything* what gives the possibility to handle network stuff in FBDOS will do it :)
Unfortunately, I'm way too lame to work on such low-level stuff... :(

Looking forward for good news ;-)
etko
Posts: 113
Joined: May 27, 2005 7:55
Location: Slovakia
Contact:

Post by etko »

Something new about this?
I have packet driver working on my DOS box and OpenBSD assigns IP address using BOOTP nicely to trumpet's stack.
I would like to try wattcp32 with FB.
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Post by Dinosaur »

Hi all

etko, is the "Dos Box" a freestanding computer running DOS ? Dos386 corrected me on this.
I have some time at the moment and have been working on this.
So far I have a number of solutions.
1. Microsoft Net.exe. My WinImage available here:
http://www.compu-weigh.com.au/DownLoads/DownLoad.html
2. Eznos which wont work in the background from my app's, but works well
3. Arachne, once again a freestanding app, very well done, but needs user input.
4. Trumpet FTP, which seemed to have some issues being called from my app, but no longer supported.
5. FTP32 client, an application that uses wattcp and works well, and may be my solution to automate the getting and putting of files prior to my app starting.Allows a scripting file with ftp commands. I use it with Filezilla server on the Windows machine to test. Tried IIS from XP but that was just plain to difficult.

Then I re-investigated cURL , and concluded that if I can get the library compiled with djgpp then there is a really up to date well supported library that can link into FB. To do this, it needs parts of Wattcp, so currently re-installing Wattcp and re-compiling. Djgpp compile no problem, but Mingw32 fails at the last moment
att-32.res
gcc.exe: unrecognized option '-shared'
c:/djgpp/bin/ld.exe: unrecognized option '--enable-stdcall-fixup'
c:/djgpp/bin/ld.exe: use the --help option for usage information
collect2: ld returned 1 exit status
make.exe: *** [../lib/libwatt32.dll.a] Error 1
Going to throw this at the Watt32 forum.
It may well be that when I finish all this, the speed loss or "interuption" from net activity will be intolerable and I will stay with option 5 above. But I have to find out. Sadly I think the Dos port of FB is forgotton , and I dont think anyone is actively developing improvements for it.

BUT, an interesting trend on the net, is that the word DOS or MS-DOS seems to be hi-jacked by people using the Dos prompt in Windows to FTP files. Windows seems to be too slow, and there are large quantities of sites dedicated to this. Is this a trend back to the raw power of DOS ???

Regards
Post Reply