bah.libcurl.mod and bah.libcurlssl.mod questions

BlitzMax Forums/Brucey's Modules/bah.libcurl.mod and bah.libcurlssl.mod questions

MOBii(Posted 2016) [#1]
I start learning libcurl.mod and have some questions:

When I do:
curl.setOptString(CURLOPT_URL, http://www.blhtml.org/BLL.php?blhtml_user=Martin&blhtml_passwd=MyPassword")
I can see the session
But I can't have the session open, I need to keep login on every request
So my first question is can I create a session so I don't need to login on every call?

curl.cleanup()
when I call cleanup() the connection is already lost!

My Second Question is:
I can't see but it look like my url request is in plain text so every time I send the url request, someone can sniff my username and password
can I somehow cryptate my request with libcurl.mod?


When I try build libcurlssl.mod:
C:\Wello\MinGW/bin/ar.exe: creating C:/BlitzMax/mod/bah.mod/libcurl.mod/libcurl.debug.mt.win32.x86.a
C:\Wello\MinGW/bin/ar.exe: creating C:/BlitzMax/mod/bah.mod/libcurl.mod/libcurl.release.mt.win32.x86.a
C:/BlitzMax/mod/bah.mod/libssh2.mod/src/channel.c: In function 'libssh2_channel_open_ex':
C:/BlitzMax/mod/bah.mod/libssh2.mod/src/channel.c:148:35: error: macro "_libssh2_debug" passed 5 arguments, but takes just 4
                        packet_size);
                                   ^
C:/BlitzMax/mod/bah.mod/libssh2.mod/src/channel.c:146:9: error: '_libssh2_debug' undeclared (first use in this function)
         _libssh2_debug(session, LIBSSH2_DBG_CONN,
         ^
C:/BlitzMax/mod/bah.mod/libssh2.mod/src/channel.c:146:9: note: each undeclared identifier is reported only once for each function it appears in
C:/BlitzMax/mod/bah.mod/libssh2.mod/src/channel.c:257:69: error: macro "_libssh2_debug" passed 9 arguments, but takes just 4
                            session->open_channel->remote.packet_size);
My libcurlssl.mod question is: Do I need to have something on the server to use the ssl?


in php I can use a function md5 is there a md5 function in BlitzMax? (I know this don't make it more secure, but it's a simple way to just hide the password)
(then I can send the password scrambled in plain text and still check the password on the server)

If I am forced to send my password on every request, Then I need to cryptate the userinformation/password somehow!

Sorry for yet again another universal WRONG and ask to many question in the same post!


Henri(Posted 2016) [#2]
Hi,

just to get you started, here is something that I use:

'---------------------------------------
'A BASIC SESSION EXAMPLE USING LIBCURL	
'---------------------------------------

'Create a new session.
'--------------------
Local cookie_file:String = "cookie.txt"

curl = TCurlEasy.Create()
curl.setOptString(CURLOPT_COOKIEJAR, cookie_file)

'Login
'------
data = "usercode=" + user + "&password=" + password

curl.setOptString(CURLOPT_POSTFIELDS, data)
curl.setOptString(CURLOPT_URL, MY_SERVER + "/system/login")
curl.perform()

'Interact with the server using previously established session
'--------------------------------------------------------------
data = "code=" + mycode + "&name=" + myname + "&age=" + myage

curl.setOptString(CURLOPT_POSTFIELDS, data)
curl.setOptString(CURLOPT_COOKIE, cookie_file)
curl.setOptString(CURLOPT_URL, MY_SERVER + "/document/getperson")
curl.perform()

'Logout
'-------
curl.setOptString(CURLOPT_COOKIE, cookie_file)
curl.setOptString(CURLOPT_URL, MY_SERVER + "/system/logout")
curl.perform()
curl.cleanup()


-Henri


MOBii(Posted 2016) [#3]
Thank thee this is the coolest thing I been doing in BlitzMax
I am really jumping up and Down here!
the cookie working perfectly!


MOBii(Posted 2016) [#4]
My Server is in Denmark and I live on the other side of the Globe!

to catch the answer from the server I use: setWriteString()

When I use setWriteString() and perform() it lock the application until I get the answer from the server, and if the return package is lost in the void then my application goes into a coma!


Is it possible to do a crocodile fix and set a timeout so perform() stop listening for the answer after X amount of seconds?


My real question: can I somehow do a perform() without locking the application until he receive the answer from the server?
(So I can use a timer to check if the answer has arrived?)


Derron(Posted 2016) [#5]
Hmm, you could use a thread for your request.

In this example here:
https://github.com/maxmods/bah.mod/blob/master/libcurl.mod/examples/ex_02.bmx

you see how it calls a callback-function - this could be used to stop the thread which executed the remote-request.

From the docs (in curlmain.bmx):
Returning a non-zero value from this callback will cause libcurl to abort the transfer and return #CURLE_ABORTED_BY_CALLBACK.


So after you waited for X seconds, you just set a variable "timeOut = 1" and within your callback function you then do a "return timeOut".


Of course this also works _without_ threads, but then your app is blocked until the timeout happens (exception: you do something like "updateMyApp()" within the callback - to have it get updated at least once a second).




The other example:
https://github.com/maxmods/bah.mod/blob/master/libcurl.mod/examples/ex_05.bmx

does a "multi-perform", maybe this is already something useful?


bye
Ron


MOBii(Posted 2016) [#6]
Thank the Derron
perform() still hijack the application!
Print "1-----------------------------------------------------"
Local res:Int = curl.perform()
Print "2-----------------------------------------------------"
If I do this simple test:
it Print 1 and after 3 to 5 second it Print 2
progressCallback is called to show the progress


the ex_05.bmx only for queues:
While status = CURLM_CALL_MULTI_PERFORM 
	status = multi.multiPerform(running)
Wend
He is stuck in this While until he is Done


the only option is if I can set a timeout how long time curl.perform() shall wait for the answer from the server!


Brucey(Posted 2016) [#7]
Maybe this can help : https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html


MOBii(Posted 2016) [#8]
Thank thee that was noobish of me to not find: bah.mod\libcurl.mod\consts.bmx
CURLOPT_TIMEOUT