FB 1.09.0
Code: Select all
Public Function MainDebug2() As Long Export
' ........................................................................................
'
' ........................................................................................
Dim cURLHandle As CURL Ptr, cURLSList As curl_slist Ptr = NULL, cURLRetValue As Long = 0
Dim As ZString * 2048 sSourceURL, sCookiesFilePath
' ........................................................................................
'
' ........................................................................................
sSourceURL = "???"
sCookiesFilePath = "C:\Temp\_CookiesFileInQuestion.txt"
' ........................................................................................
'
' ........................................................................................
curl_global_init(CURL_GLOBAL_ALL)
cURLHandle = curl_easy_init()
If cURLHandle = 0 Then
Print "x-> cURL Easy Init Fail"
Return 1
EndIf
' ........................................................................................
'
' ........................................................................................
Dim As tagcURLCallBackBuffer Ptr ptInfo = New tagcURLCallBackBuffer(65535)
' ........................................................................................
Dim As Long cURLErrorBufferSize = CURL_ERROR_SIZE
Dim As ZString Ptr cURLErrorBuffer = Callocate(cURLErrorBufferSize + 1,1)
' ........................................................................................
curl_easy_setopt(cURLHandle, CURLOPT_DEBUGFUNCTION, @cURLCallbackFunc_DebugTraceFuncEL)
curl_easy_setopt(cURLHandle, CURLOPT_DEBUGDATA, ptInfo)
' ........................................................................................
curl_easy_setopt(cURLHandle, CURLOPT_VERBOSE, 1L)
' ........................................................................................
curl_easy_setopt(cURLHandle, CURLOPT_URL, @sSourceURL)
' ........................................................................................
curl_easy_setopt(cURLHandle, CURLOPT_COOKIESESSION, 1L)
curl_easy_setopt(cURLHandle, CURLOPT_COOKIEFILE, sCookiesFilePath)
curl_easy_setopt(cURLHandle, CURLOPT_COOKIEJAR, sCookiesFilePath)
' ----------------------------------------------------------------------------------------
'
' ----------------------------------------------------------------------------------------
cURLRetValue = curl_easy_perform(cURLHandle)
' ----------------------------------------------------------------------------------------
'
' ----------------------------------------------------------------------------------------
Print "--> Connection Log Start :"
Print "--------------------------------------------------------------------------------------------"
Print *ptInfo->strbuf
Print "--------------------------------------------------------------------------------------------"
Print "--> Connection Log End :"
' ........................................................................................
Delete ptInfo
' ----------------------------------------------------------------------------------------
'
' ----------------------------------------------------------------------------------------
Print "> CleanUp - 0"
curl_slist_free_all(cURLSList)
Sleep(1000,1)
Print "> CleanUp - 1"
curl_easy_cleanup(cURLHandle) ' <---------------------- crush
Sleep(1000,1)
Print "> CleanUp - 2"
DeAllocate(cURLErrorBuffer) : cURLErrorBuffer = 0
Sleep(1000,1)
Print "> CleanUp - 3"
curl_global_cleanup()
' ........................................................................................
Print "--> Done"
' ----------------------------------------------------------------------------------------
'
' ----------------------------------------------------------------------------------------
return 0
End Function
Code: Select all
Type tagcURLCallBackBuffer
strbuf As zString Ptr
size As size_t = 0
allocated As size_t = 0
Declare Sub Append(ByRef psBuffer As ZString Ptr, ByVal iBufferLengh As size_t)
Declare Sub ReserveSpace(ByVal iBufferLengh As size_t)
Declare Constructor()
Declare Constructor(ByRef iSizeToAllocate As Integer)
Declare Constructor(ByRef tcURLCallBackBuffer As tagcURLCallBackBuffer)
Declare Operator Let(ByRef tcURLCallBackBuffer As tagcURLCallBackBuffer)
Declare Destructor ()
End Type
' ............................................................................................................
Constructor tagcURLCallBackBuffer
This.allocated = 7
This.size = 0
This.strbuf = Callocate(8,1)
End Constructor
' ............................................................................................................
Constructor tagcURLCallBackBuffer(ByRef iSizeToAllocate As Integer)
This.allocated = iSizeToAllocate
This.size = 0
This.strbuf = Callocate(iSizeToAllocate + 1,1)
End Constructor
' ............................................................................................................
Constructor tagcURLCallBackBuffer(ByRef tcURLCallBackBuffer As tagcURLCallBackBuffer)
This.allocated = tcURLCallBackBuffer.allocated
This.size = tcURLCallBackBuffer.size
'This.strbuf = Callocate(tcURLCallBackBuffer.size + 1,1) : memcpy(This.strbuf,tcURLCallBackBuffer.strbuf,tcURLCallBackBuffer.size)
This.strbuf = Callocate(tcURLCallBackBuffer.allocated + 1,1) : memcpy(This.strbuf,tcURLCallBackBuffer.strbuf,tcURLCallBackBuffer.size)
End Constructor
' ............................................................................................................
Operator tagcURLCallBackBuffer.Let(ByRef tcURLCallBackBuffer As tagcURLCallBackBuffer)
If tcURLCallBackBuffer.size >= This.allocated Then
This.strbuf = ReAllocate(This.strbuf,tcURLCallBackBuffer.allocated + 1) : Clear(*This.strbuf,0,tcURLCallBackBuffer.allocated + 1) : memcpy(This.strbuf,tcURLCallBackBuffer.strbuf,tcURLCallBackBuffer.size)
This.allocated = tcURLCallBackBuffer.allocated
Else
Clear(*This.strbuf,0,This.allocated + 1) : memcpy(This.strbuf,tcURLCallBackBuffer.strbuf,tcURLCallBackBuffer.size)
EndIf
This.size = tcURLCallBackBuffer.size
End Operator
' ............................................................................................................
Destructor tagcURLCallBackBuffer
This.allocated = 0 : This.size = 0 : *This.strbuf = ""
DeAllocate(This.strbuf) : This.strbuf = 0
End Destructor
' ............................................................................................................
1. comment line : curl_easy_setopt(cURLHandle, CURLOPT_VERBOSE, 1L)
2. comment lines : curl_easy_setopt(cURLHandle, CURLOPT_DEBUGFUNCTION, @cURLCallbackFunc_DebugTraceFuncEL)
curl_easy_setopt(cURLHandle, CURLOPT_DEBUGDATA, ptInfo)
3. comment line : Delete ptInfo
Prototypes:
FB:
Code: Select all
type curl_debug_callback as function(byval handle as CURL ptr, byval type as curl_infotype, byval data as zstring ptr, byval size as uinteger, byval userptr as any ptr) as long
Code: Select all
int debug_callback(CURL *handle,
curl_infotype type,
char *data,
size_t size,
void *userptr);
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
debug_callback);