Moving bbcbasic.co.uk to a new host (reprise)

Here you can talk about anything related to BBC BASIC, not covered in another category
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Moving bbcbasic.co.uk to a new host (reprise)

Post by Richard Russell »

Many of you will remember that earlier this year I moved bbcbasic.co.uk to a new host, primarily to overcome problems caused by my old hosting service capping the monthly bandwidth. The process turned out to be quite painful, perhaps not surprisingly given the relatively unusual ways in which the host is used (e.g. serving the in-browser edition of BBCSDL) and there was a long thread at the time about it.

Since then the new host (Krystal Hosting) has been largely trouble free and I was looking forward to this continuing for a long time. However they have recently informed me that it is their intention "in the near future" to discontinue support for plain (unencrypted) FTP file transfers, and of course I rely on this feature.

Although they haven't explicitly said so, I wouldn't be surprised if they also plan to discontinue unencrypted web (http://) access, which again is something which I critically rely on because BBC BASIC's socklib library does not support encrypted connections (it cannot do so because it in turn uses the SDL2_net library which doesn't).

I have more than once suggested to the SDL developers that they consider adding support for secure connections to their SDL_net library, but they take the view that since SDL is supposed to be 'Simple' - it's what the 'S' stands for - it would not be appropriate and/or practical to do so. It would no doubt be quite difficult, considering the range of platforms supported.

Realistically, given my age and health, I would not be able to move the site again - even if a hosting service could be found which guarantees continued support for unencrypted connections. So at some point in the relatively near future things are going to stop working; exactly what and when will depend on Krystal.

When that happens I can only suggest that you complain to them!
User avatar
hellomike
Posts: 184
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: Moving bbcbasic.co.uk to a new host (reprise)

Post by hellomike »

In addition to the excellent socklib library maybe you or another brilliant mind could see if it's feasible to develop a curllib library to access the libcurl API.

https://curl.se/libcurl/c/libcurl.html

Then again, I guess this isn't cross-platform.

Just an idea.

Regards,

Mike
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Moving bbcbasic.co.uk to a new host (reprise)

Post by Richard Russell »

hellomike wrote: Fri 25 Oct 2024, 12:26 see if it's feasible to develop a curllib library to access the libcurl API.
I presume libcurl is a C source-code library that you have to compile, yes? In which case it ought to be straightforward to compile it into a shared object (.dll in Windows, .so on most other platforms) which exports the relevant functions, then BBC BASIC could access it using SYS "SDL_LoadObject" and SYS "SDL_LoadFunction". Maybe there's some 'gotcha' that I haven't thought of, but I feel it should work.
User avatar
hellomike
Posts: 184
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: Moving bbcbasic.co.uk to a new host (reprise)

Post by hellomike »

About a year ago I did a feeble attempt for use in BB4W. I managed to find a recent libcurl.dll somewhere and made the following:

Code: Select all

      REM>libcurl
      REM Source:
      REM - https://curl.se/libcurl/

      PROClibcurlInit

      URL$ = "https://sourceforge.net/" + CHR$0
      PRINT FN_curl_version

      Curl% = FN_curl_easy_init
      IF Curl% THEN
        SYS `curl_easy_escape`, Curl%, "https://sourceforge.net/", 0 TO S%
        DIM R% LEN$$S%
        $$R%=$$S%
        SYS `curl_free`, S%
        PRINT $$R%
  
        PROC_curl_easy_setopt(Curl%, CURLOPT_URL, R%)
        PROC_curl_easy_setopt(Curl%, CURLOPT_FOLLOWLOCATION, 1)
        E%=FN_curl_easy_perform(Curl%)
        IF E% <> CURLE_OK THEN
          PRINT FN_curl_easy_strerror(E%)
        ENDIF
        PROC_curl_easy_cleanup(Curl%)
      ENDIF
      END

      REM ----------------------------------------------------------------------
      DEF PROClibcurlInit
      LOCAL dll%, gpa%

      SYS "LoadLibrary", @dir$ + "libcurl.dll"
      SYS "GetModuleHandle", @dir$ + "libcurl.dll" TO dll%
      IF dll% == 0 ERROR 100, "Could not load libcurl.dll"

      gpa%=SYS"GetProcAddress"
      SYS gpa%, dll%, "curl_easy_init"     TO `curl_easy_init`
      SYS gpa%, dll%, "curl_easy_cleanup"  TO `curl_easy_cleanup`
      SYS gpa%, dll%, "curl_easy_setopt"   TO `curl_easy_setopt`
      SYS gpa%, dll%, "curl_easy_perform"  TO `curl_easy_perform`
      SYS gpa%, dll%, "curl_easy_strerror" TO `curl_easy_strerror`
      SYS gpa%, dll%, "curl_easy_escape"   TO `curl_easy_escape`
      SYS gpa%, dll%, "curl_free"          TO `curl_free`
      SYS gpa%, dll%, "curl_version"       TO `curl_version`

      CURLE_OK = 0
      CURLOPT_ERRORBUFFER = 10
      CURLOPT_FOLLOWLOCATION = 52
      CURLOPT_URL = 2
      CURLOPT_VERBOSE = 41
      CURL_ERROR_SIZE = 256
      ENDPROC

      REM ----------------------------------------------------------------------
      DEF FN_curl_easy_init
      LOCAL C%

      SYS `curl_easy_init` TO C%
      =C%

      REM ----------------------------------------------------------------------
      DEF PROC_curl_easy_cleanup(C%)
      SYS `curl_easy_cleanup`, C%
      ENDPROC

      REM ----------------------------------------------------------------------
      DEF PROC_curl_easy_setopt(C%, A%, B%)
      SYS `curl_easy_setopt`, C%, A%, B%
      ENDPROC

      REM ----------------------------------------------------------------------
      DEF FN_curl_easy_perform(C%)
      LOCAL E%

      SYS `curl_easy_perform`, C% TO E%
      =E%

      REM ----------------------------------------------------------------------
      DEF FN_curl_easy_strerror(E%)
      LOCAL S%

      SYS `curl_easy_strerror`, E% TO S%
      =$$S% + " (" + STR$E% + ")"

      REM ----------------------------------------------------------------------
      DEF FN_curl_easy_escape(C%, S%, L%)
      LOCAL S%, R%

      SYS `curl_easy_escape`, C%, S%, L% TO S%
      DIM R% LEN$$S%
      $$R%=$$S%
      SYS `curl_free`, S%
      =$$R%

      REM ----------------------------------------------------------------------
      DEF FN_curl_version
      LOCAL S%

      SYS `curl_version` TO S%
      =$$S%
and got this as output.

Code: Select all

libcurl/8.4.0 OpenSSL/3.1.4 (Schannel) zlib/1.3 brotli/1.1.0 zstd/1.5.5 WinIDN libssh2/1.11.0 nghttp2/1.58.0 ngtcp2/1.1.0 nghttp3/1.1.0
https%3A%2F%2Fsourceforge.net%2F
URL using bad/illegal format or missing URL (3)
>
So at least the functions are easy to call but my lack of knowledge about Internet terminology prevented me to continuing.

Regards,

Mike
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Moving bbcbasic.co.uk to a new host (reprise)

Post by Richard Russell »

hellomike wrote: Fri 25 Oct 2024, 18:53 URL using bad/illegal format or missing URL (3)
It's pretty clear what's happened there:

Code: Select all

https%3A%2F%2Fsourceforge.net%2F
As you can see the :// has been escaped, which you don't want it to be. When calling `curl_easy_escape` pass only what you want to be escaped, not what you don't. In the case of that specific URL, nothing needs to be escaped anyway.
User avatar
hellomike
Posts: 184
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: Moving bbcbasic.co.uk to a new host (reprise)

Post by hellomike »

I'm sure you are correct. Listing the code and the output was mainly to show that the functionality the libcurl.dll provides is easy to use in BB4W and obviously also in BBCSDL.

Maybe I continue my effort in the near future and start by investing the use of the curl_url_set and curl_url_get API's.