CURL problem

DOS specific questions.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

CURL problem

Postby Cpcdos » Feb 23, 2014 17:40

Hello !

For DOS have rename curl files :
CHttpStream.bi & .bas > CHttpStm.bi & .bas
CHttpform.bi & .bas > CHttpfrm.bi & .bas

When i compile my CURL program with

Code: Select all

FBC test.bas -lang fb


I have this
Image

why i have this ?

Thank
TJF
Posts: 3576
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: CURL problem

Postby TJF » Feb 23, 2014 17:59

That's a message from the linker (ld). It cannot find the binaries for the libraries. (I don't know how to fix this under DOS.)
dkl
Site Admin
Posts: 3211
Joined: Jul 28, 2005 14:45
Location: Germany

Re: CURL problem

Postby dkl » Feb 23, 2014 18:44

The example http library ("CHttp") in FreeBASIC/examples/network/curl/CHttp/ is based on libcurl. You'd need to get a version of libcurl, libcurl.a, compiled for DOS (DJGPP). I don't know whether something like that is available, because the curl download page doesn't provide a libcurl download for DJGPP.

To get libCHttp.a, do this: (as noted at the top of CHttp.bas)

fbc -lib CHttp.bas CHttpStream.bas CHttpForm.bas


(you may need to shorten the file names to 8.3 format again)

I suspect getting libcurl for DJGPP will be the more difficult part though, even when installing DJGPP and compiling libcurl manually...
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: CURL problem

Postby Cpcdos » Feb 28, 2014 23:08

Okay Thank you for answers
someone have libcurl.a ?
Dinosaur
Posts: 1342
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: CURL problem

Postby Dinosaur » Mar 01, 2014 21:49

Hi All

Yes i have it.
Send me a pm with your email and I will email it, 3,643kb.
I used curl to network my machines in large factories.

Regards

EDIT: On second thoughts, the file is a bit big to email. Here is the link(for about a month)
http://www.tubejoiners.com/downloads/libcurl.a
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: CURL problem

Postby Cpcdos » Mar 07, 2014 18:53

Yes thank you !! :D

but now i have this
Image

what is the missing lib ? :/

Thank you
Dinosaur
Posts: 1342
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: CURL problem

Postby Dinosaur » Mar 08, 2014 8:52

Hi All

The only library I have is libCHttp.a which I have put at
http://www.tubejoiners.com/downloads/libCHttp.a
for you , so you may have to rename it.

If you are having these kind of problems, there are only two options:
Either your path is not pointing at the right location
Or you dont have the library.

FreeBasic has a folder
examples\network\curl\CHttp which you should have.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: CURL problem

Postby Cpcdos » Mar 08, 2014 10:18

Thank you !

but this is for Win32 :/

i have this when i compil ( + hexa edition )
Image

you haven't for dos ?

Thank
Dinosaur
Posts: 1342
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: CURL problem

Postby Dinosaur » Mar 08, 2014 21:34

Hi All

Cpcdos, I don't recall using Curl in Windows, so
I either haven't used that library for Dos, or that is the library that got linked in.

This is a test program that I used to download an update from my website for the customer.
I removed my ftp link, but for the rest it should work.

Code: Select all

#Include Once "curl.bi"
Declare Sub HookInt()
Dim Shared As UInteger TickCount,dssave
Dim Shared As Integer FP
Dim Ver_Ptr As ZString Ptr
Type cURLSession
   InFile    As String * 12
   OutFile   As String * 12
   url        As String * 90
   InFSize   As Double
   OutFSize  As Double
   InSofar     As Double
   OutSofar  As Double
   StartTime As Double
   Elapsed     As Double
   OldTick     As Double
   InPerc    As UInteger
   OutPerc   As UInteger
   Running   As UInteger
   FilePtr   As Integer
   ftp_handle       As CURL Ptr
   Multi_handle   As CURLM Ptr
End Type
Common Shared cURLSession As cURLSession
private function write_callback Cdecl ( byval buffer as byte ptr,byval size as integer,byval nitems as integer,byval outstream as any Ptr) as Integer
   Dim as integer bytes = size * nitems
   put #FP ,,*buffer,bytes
   function = bytes            'this is used by curl to verify delivered = written
end Function
private function curl_progress_callback cdecl(byval update as any ptr, byval dlTotal as double, byval dlNow as double, byval ulTotal as double, byval ulNow as double) as Integer
   With cURLSession
      .InFSize  = dlTotal
      .InSofar  = dlNow
      .InPerc   = (.InSofar / .InFSize) * 100
      .OutFSize = ulTotal
      .OutSofar = ulNow
      .OutPerc  = (.OutSofar / .OutFSize) * 100
   End With
   Function = 0
End Function
Sub HookInt
   'Because my code is the only code running on a dos PC,
   'and power is turned off after program exits,
   'I do NOT re-set the interupt hook.
asm
    mov     dssave,ds             
    '--------------------
    mov     ax,&H0205                   'assign an extra
    mov     bx,&H1c                     'handler
    mov     cx,cs
    mov     edx, offset SaveTick        'offset of label where we
    Int     &H31                        'want the int to go to every 1/18s.
    jnc     HookExit                    'if no error jump to exit
    mov     TickCount,eax               'otherwise use it as err store.
    jmp     HookExit                    'then get out by jumping over int routine.
    '--------------------
SaveTick:
    push   eax                          'save all registers which are modified!
    push   ds
    mov    ds, cs:[dssave]              'set it to segment of our variable.
    mov    eax,TickCount                'get last TickCount
    inc    eax                          'inc by one
    mov    TickCount,eax                'and save it again.
    pop    ds                           'restore ds of other handler.
    pop    eax                           
    iretD                               'and return to it.
HookExit:   
End asm
End Sub

   Cls
   HookInt
   If TickCount > 0 Then
         End                        'or do your error handling
   End If   
   Ver_Ptr = curl_version()         'Get pointer to Version info.
   Locate 1,1: Print "Version=";
   Print *Ver_Ptr                  'print the info
   With cURLSession
      .InFile = "Mc211.bin"
      .ftp_handle = curl_easy_init()   'Initialize and get Handle
      FP = FreeFile
      Open .InFile For Binary Access Write As #FP
      .url = "ftp://  your ftp link  /Downloads/Myfile.exe" + Chr(0)
      '-------------------------------
      'curl_easy_setopt( .ftp_handle, CURLOPT_VERBOSE,1)
      curl_easy_setopt( .ftp_handle, CURLOPT_URL,.url )
      curl_easy_setopt( .ftp_handle, CURLOPT_WRITEFUNCTION, @write_callback )            'to write data to file
      curl_easy_setopt( .ftp_handle, CURLOPT_PROGRESSFUNCTION, @curl_progress_callback )   'to get Total, Recvd info
      curl_easy_setopt( .ftp_handle, CURLOPT_NOPROGRESS, 0)                        'disable internal progress info
      .multi_Handle = curl_multi_init()                                       'get handle for multi operation
      curl_multi_add_handle(.multi_handle, .ftp_handle)                              'and add them together
      .StartTime = TickCount                                                'Record starting time
      Locate 2,1:Print "Percent Done:"
      Do
         If Tickcount - .StartTime > 1800 Then Exit do
         curl_multi_perform(.multi_handle, @.running)
         If TickCount > .OldTick Then
            Locate 2,15:Print CUInt(.InPerc);"%";.InSofar;" Bytes"
            .OldTick = TickCount
         EndIf
         If .running < 1 Then Exit Do
      Loop
      Locate
      '-------------------------------
      Close #FP
      curl_multi_cleanup(.multi_handle)         'reset options to default.
      curl_easy_cleanup(.ftp_handle)       'cleanup and quit cURL
      Locate 3,1:Print "Elapsed =";(TickCount - .StartTime) * 54.925402;" mSec"
   End With

   End
   


Then I compiled with this statement.

Code: Select all

FbcDos cURLTest.bas -w pedantic -v -R -l wmemu -l curl -l Watt -x cURLTest.exe


And these are the libraries used in the link statement.

Code: Select all

ld options in 'temp.res':   -o "cURLTest.exe" -T "C:\fbdos\lib\dos\i386go32.x" -s -L "C:\fbdos\lib\dos" -L "." "C:\fbdos\lib\dos\crt0.o" "C:\fbdos\lib\dos\fbrt0.o" "cURLTest.o" "-(" -lwmemu -lcurl -lWatt -lfb -lgcc -lc -lm -lsupcx "-)"

linking:      C:\fbdos\bin\dos\ld.exe @temp.res


Regards
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: CURL problem

Postby Cpcdos » Mar 16, 2014 18:24

Okay thank i will see when i will have my PC
I reaffirm you
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: CURL problem

Postby Cpcdos » Mar 22, 2014 23:37

hi!

I have download extended library for basic, and i have compiled
now, i have this
Image

:(

Socket.bi :

Code: Select all

''Title: net/socket.bi
''
''About: License
''Copyright (c) 2007-2012, FreeBASIC Extended Library Development Group
''Contains code contributed and Copyright (c) 2012, Ruben Rodriguez (cha0s) therealcha0s.net
''
''Distributed under the FreeBASIC Extended Library Group license. See
''accompanying file LICENSE.txt or copy at
''http://code.google.com/p/fb-extended-lib/wiki/License

#include once "crt.bi"
#include once "ext/detail/common.bi"
#include once "ext/net/detail/common.bi"
#include once "ext/error.bi"

#ifndef FBEXT_NET_SOCKET_BI__
#define FBEXT_NET_SOCKET_BI__ -1

#ifdef socket
#undef socket
#endif

''namespace: ext.net
namespace ext.net

''Type: socket_info
''Holds advanced information about a socket
type socket_info

data as sockaddr_in
declare property port( ) as ushort

declare operator cast( ) as string
declare operator cast( ) as sockaddr ptr

end type

''Type: socket
''Wrapper around system specific low level socket calls.
type socket
public:

declare constructor( )
declare destructor( )

''Function: client
''Create a TCP client with the 32-bit IP address "ip" on port "port".
''
''Returns:
''<SOCKET_ERRORS>
''
declare function client _
( _
byval ip as integer, _
byval port as integer _
) as integer

''Function: client
''Create a TCP client with the hostname "server" on the port "port"
''
''Returns:
''<SOCKET_ERRORS>
''
declare function client _
( _
byref server as string, _
byval port as integer _
) as integer

''Function: UDPClient
''Create a UDP client with the 32-bit IP address "ip" on port "port".
''
''Returns:
''<SOCKET_ERRORS>
''
declare function UDPClient _
( _
byval ip as integer, _
byval port as integer _
) as integer

''Function: UDPClient
''Create a UDP client with the hostname "server" on the port "port"
''
''Returns:
''<SOCKET_ERRORS>
''
declare function UDPClient _
( _
byref server as string, _
byval port as integer _
) as integer

declare function UDPClient _
( _
) as integer

''Function: server
''Create a TCP server that listens on port "port". It can queue up to "max_queue"
''incoming connections. When a socket connects, it is added to the queue. When
''listen() is used with the listening socket, it removes a socket from the queue
''if one exists. The default queue size is 4 pending connections.
''
''Returns:
''<SOCKET_ERRORS>
''
declare function server _
( _
byval port as integer, _
byval max_queue as integer = 4 _
) as integer

''Function: UDPServer
''Create a UDP server that listens on port "port"
''
''Returns:
''<SOCKET_ERRORS>
''
declare function UDPServer _
( _
byval port as integer, _
byval ip as integer = INADDR_ANY _
) as integer

declare function UDPConnectionlessServer _
( _
byval port as integer _
) as integer

''Function: listen
''Listen on a server socket for incoming connections. If "timeout" is 0,
''then the socket blocks indefinitely until a connection is recieved.
''Otherwise, the socket blocks for "timeout" seconds. If "info" is NULL,
''the peer info is discarded, otherwise it is returned through info.
''The connection socket is the same as the listener.
''Better to use listen_to_new() most of the time.
''
''Returns:
''Returns TRUE if a connection was recieved, else FALSE.
''
declare function listen _
( _
byref timeout as double = 0 _
) as bool

''Function: listenToNew
''Listen on the "listener" socket for incoming connections. If "timeout" is 0,
''then the socket blocks indefinitely until a connection is recieved.
''Otherwise, the socket blocks for "timeout" seconds. If "info" is NULL,
''the peer info is discarded, otherwise it is returned through info.
''The socket that calls listen_to_new() recieves the new connection.
''
''Returns:
''Returns TRUE if a connection was recieved, else FALSE.
''
declare function listenToNew _
( _
byref listener as socket, _
byval timeout as double = 0 _
) as bool

''Function: getData
''Attempt to retrieve "size" bytes of data from the socket stream, filling
''"data_". If "peek_only" is FALSE (default), then the data is removed from
''the socket stream as well.
''Note: This function is considered low-level and isn't necessary to use.
''
''Returns:
''Number of bytes read from stream.
''
declare function getData _
( _
byval data_ as any ptr, _
byval size as SizeType, _
byval peek_only as bool = FALSE _
) as sizetype

''Function: getLine
''Get the next line from the input stream, seperated by CRLF (HTTP and other protocols).
''
declare function getLine _
( _
) as string

''Function: getUntil
''Fills the return string until the specified string is found in the input.
''
''Parameters:
''target - when found in string the function will return everything up to that point.
''
declare function getUntil _
( _
byref target as string _
) as string

''Function: get
''
''Parameters:
''t - any built-in type.
''elems - specifies how many "t"s to retrieve (default 1).
''time_out - can be ext.net.socket.ONLY_ONCE (only tries retriving one time before giving up), ext.net.socket.BLOCK (blocks forever until enough data is there to retrieve) or, any other number specifies the number of milliseconds to try before giving up.
''peek_only - If false (default), the data is removed from the socket stream
''
''Returns:
''Upon return "elems" contains the amount of "t"s that were
''successfully recieved. Return value is the number of bytes returned in total.
''
#macro fbext_SocketGet_Declare(T_)
declare function get overload _
( _
byref data_ as fbext_TypeName(T_), _
byref elems as integer = 1, _
byval time_out as integer = ONLY_ONCE, _
byval peek_only as integer = FALSE _
) as integer
#endmacro

fbext_InstanciateMulti(fbext_SocketGet, fbext_BuiltinTypes())

''Function: putData
''Attempt to commit "size" bytes of data at "data_" to the socket stream.
''Note: This function is considered low-level and isn't necessary to use.
''
''Returns:
''Number of bytes placed into the stream.
''
declare function putData _
( _
byval data_ as any ptr, _
byval size as sizetype _
) as integer

''Function: put
''Overloaded for all built-in types.
''"elems" specifies how many "t"s to put in the stream. "time_out" can be
''"ext.net.socket.ONLY_ONCE" (only tries putting one time before giving up)
''"ext.net.socket.BLOCK" (blocks forever until enough data can be put)
''or, any other number specifies the number of milliseconds to try before
''giving up. Upon return "elems" contains the amount of "t"s that were
''successfully sent.
''
''Returns:
''True if succesful
''
#macro fbext_SocketPut_Declare(T_)
declare function put overload _
( _
byref data_ as fbext_TypeName(T_), _
byref elems as integer = 1, _
byval time_out as integer = 0 _
) as bool
#endmacro

fbext_InstanciateMulti(fbext_SocketPut, fbext_BuiltinTypes())

''Function: putLine
''Similiar to the FreeBASIC print function, place a line in the output stream
''ending with the CRLF line ending. (Used by HTTP and other protocols.)
''
''Returns:
''True if successful.
''
declare function putLine _
( _
byref text as string _
) as integer

''Function: putString
''Similiar to the FreeBASIC print function with the ; line ending,
''place the string in the output stream without adding the line
''ending character sequence. Does not add leading length of string
''like the put(string) function does.
''
''Returns:
''True if successful.
''
declare function putString _
( _
byref text as string _
) as integer

declare function putHTTPRequest _
( _
byref server_name as string, _
byref method as string = "GET", _
byref post_data as string = "" _
) as integer

declare function putIRCAuth _
( _
byref nick as string = "undefined", _
byref realname as string = "undefined", _
byref pass as string = "" _
) as integer

''Function: dumpData
''Discard "size" bytes of data from the socket stream.
''
''Returns:
''Returns true on success.
''
declare function dumpData _
( _
byval size as integer _
) as bool

''Function: length
''Retrieve the length of waiting data in the receive buffer.
''
declare function length _
( _
) as SizeType

''Function: isClosed
''Poll the socket to see if its connection is still alive.
''
''Returns:
''Boolean
''
declare function isClosed _
( _
) as bool

''Function: close
''Close the specified socket, and shut it down.
''
''Returns:
''<SOCKET_ERRORS>
''
declare function close _
( _
) as SOCKET_ERRORS

declare property recvLimit _
( _
byref limit as integer _
)

declare property sendLimit _
( _
byref limit as integer _
)

declare property recvLimit _
( _
) as integer

declare property sendLimit _
( _
) as integer

declare function recvRate _
( _
) as integer

declare function sendRate _
( _
) as integer

declare function setDestination _
( _
byval info as socket_info ptr = NULL _
) as integer

declare function connectionInfo _
( _
) as socket_info ptr

declare property hold _
( _
byval as bool _
)

private:

const as integer THREAD_BUFF_SIZE = 1024 * 16
const as integer RECV_BUFF_SIZE = 1024 * 64
const as integer SEND_BUFF_SIZE = 1024 * 16

const as integer BUFF_RATE = 10

enum KINDS
SOCK_TCP
SOCK_UDP
SOCK_UDP_CONNECTIONLESS
end enum

declare static sub recv_proc _
( _
byval opaque as any ptr _
)

declare static sub send_proc _
( _
byval opaque as any ptr _
)

as bool p_hold
as any ptr p_hold_lock, p_hold_signal
as any ptr p_go_lock, p_go_signal

p_send_buff_size as integer = SEND_BUFF_SIZE
p_send_data as ubyte ptr
p_send_caret as integer
p_send_size as integer
p_send_thread as any ptr
p_send_lock as any ptr
p_send_limit as integer
p_send_accum as integer
p_send_timer as double
p_send_disp_timer as double
p_send_rate as integer
p_send_info as socket_info Ptr
p_send_sleep As UShort = 1

p_recv_buff_size as integer = RECV_BUFF_SIZE
p_recv_data as ubyte ptr
p_recv_caret as integer
p_recv_size as integer
p_recv_thread as any ptr
p_recv_lock as any ptr
p_recv_limit as integer
p_recv_accum as integer
p_recv_timer as double
p_recv_disp_timer as double
p_recv_rate as integer
p_recv_info as socket_info
p_recv_sleep As UShort = 1

as socket_info cnx_info

as integer p_socket, p_listener
p_dead as bool

p_kind as KINDS

end type

end namespace

#endif 'FBEXT_NET_SOCKET_BI__
dkl
Site Admin
Posts: 3211
Joined: Jul 28, 2005 14:45
Location: Germany

Re: CURL problem

Postby dkl » Mar 23, 2014 11:44

Well, I don't think FB has socket declarations in the crt.bi for DOS, and this part of fbext seems to depend on them (not provide them).

Once you find a socket library that can be used (see also the posts at the end of the thread here), most likely an FB binding must be created to allow using it from FB code.

Or perhaps the socket declarations from crt.bi for Linux or Win32 could be re-used for DOS, but that also will require adjustments in the crt.bi headers.

Return to “DOS”

Who is online

Users browsing this forum: No registered users and 1 guest