mongoose embedded web server + harbour interpreter, why not ?

497 views
Skip to first unread message

Domenico D'Oria

unread,
Oct 16, 2013, 11:17:50 AM10/16/13
to harbou...@googlegroups.com
Hi all

today surfing the web i saw this site

http://cesanta.com/

it is a small footprint web server written in c and working with different platforms, as reported in his page, and also may be embedded in any code ( probably even in harbour )

first i'm not a c expert , but reading this page

http://cesanta.com/docs.html#docs/FAQ.md

I was struck by a flash.

Could be a good idea porting the harbour interpreter to this server ?

best regards





marek.h...@interia.pl

unread,
Oct 19, 2013, 5:33:34 PM10/19/13
to harbou...@googlegroups.com



Od: "Domenico D'Oria" <nikk...@gmail.com>
Do: harbou...@googlegroups.com;
Wysłane: 17:17 Środa 2013-10-16
Temat: [harbour] mongoose embedded web server + harbour interpreter, why not ?

[...]


first i'm not a c expert , but reading this page

http://cesanta.com/docs.html#docs/FAQ.md

I was struck by a flash.

Could be a good idea porting the harbour interpreter to this server ?

Hi,

In the Harbor is all you need. SqlLite, www server and scripts host. And many, many more.


Regards,

Marek Horodyski

Domenico D'Oria

unread,
Oct 24, 2013, 5:47:13 AM10/24/13
to harbou...@googlegroups.com
Hi homar

after a lot of time surf and search the web, i try to explain better my question.

i know there is webserver like hbttpd written in harbour, but the question is : can this good piece of software be able to "interprete" harbour as a scripting language, like php or for example lua ? or asp vbscript for the incoming standards like html5.

or we must use it as a programming language ? as showed in the examples.

best regards

marek.h...@interia.pl

unread,
Oct 25, 2013, 6:31:55 AM10/25/13
to harbou...@googlegroups.com



Od: "Domenico D'Oria" <nikk...@gmail.com>
Do: harbou...@googlegroups.com;
Wysłane: 11:47 Czwartek 2013-10-24
Temat: Re: [harbour] mongoose embedded web server + harbour interpreter, why not ?



Hi homar

after a lot of time surf and search the web, i try to explain better my question.

i know there is webserver like hbttpd written in harbour, but the question is : can this good piece of software be able to "interprete" harbour as a scripting language, like php or for example lua ? or asp vbscript for the incoming standards like html5.

or we must use it as a programming language ? as showed in the examples.

best regards

Hi Domenico

You can use scripts like in php. In example in \harbour\examples\httpsrv\ they are as cgi. But two examples \harbour\examples\httpsrv\ and \harbour\contrib\hbhttpd\ are very difficult to analisys.

My anglish is limited, but in the evening I will try to send circa 600 lines code http server based on this example serwer with runing scripts.


Regards,

Marek Horodyski


marek.h...@interia.pl

unread,
Oct 25, 2013, 10:00:44 PM10/25/13
to harbou...@googlegroups.com



Od: "Domenico D'Oria" <nikk...@gmail.com>
Do: harbou...@googlegroups.com;
Wysłane: 11:47 Czwartek 2013-10-24
Temat: Re: [harbour] mongoose embedded web server + harbour interpreter, why not ?


Hi homar

after a lot of time surf and search the web, i try to explain better my question.

i know there is webserver like hbttpd written in harbour, but the question is : can this good piece of software be able to "interprete" harbour as a scripting language, like php or for example lua ? or asp vbscript for the incoming standards like html5.

or we must use it as a programming language ? as showed in the examples.

best regards

Hi Domenico

In attachment are simple http server based on Mindaugas code with execute scripts.

You can adapt it to your needs.

How it work ?

I run it from another  script :) You can from exe (at the beginning).

Runing code from my script :

//====================

local o := HttpServer():new(), n
cls 

hb_gtInfo( 26, "http_Server")

o:nPort := 80 //02

o:lRejestr := .f.

o:lConnect := .t.

o:nPartTime := 1 / 86400 * 16  // domyślny czas podtrzymania połaczenia

o:cFileStartPage := "index.html" // old version, mabe form script, see in line 396.

o:cPathHttpFiles := "\homar\httpFiles\"

o:cPathBossFiles := "\homar\BossFiles\" 

o:cPathTempFiles := "\homar\tempFiles\"

// o:cPathBossFiles := "\homar\BossFiles\"


if !o:Run() // <-- here is runing server

 ? 'Error :', o:cError

end

? len( o:aThreads)

? o:cError

for n := 1 to len( o:adbConnect) ; if( valType( o:adbConnect[ n][ 3]) == 'N', rddInfo( 1002, o:adbConnect[ n][ 3]), o:adbConnect[ n][ 3] := Nil)

end

__Wait( 'hit any key ...')

Return

// ============= end script

From this moment serwer read port 80.

In alter version worked only in intranet with one domain in path o:cPathBossFiles := "\homar\BossFiles\" are was scripts. But now server hosted many domains, and script file must be in another way examined. In this algorytm are file extension ( like .php in PHP). 

In folder o:cPathHttpFiles you can create folders for domains. In my case are 4 folders with '.pl' extensions :

╔════════════ D:\homar\httpFiles ═════════[]═╗
║        Name        │  Size   │  Date  │Time
║..                  │<UP--DIR>│13-10-26│02:23▒
║harbour-project   pl│<SUB-DIR>│13-09-09│04:51▒
║marekhorodyski    pl│<SUB-DIR>│13-07-29│19:12▒
║horodyscy         pl│<SUB-DIR>│13-07-18│23:42▒
║marek-horodyski   pl│<SUB-DIR>│13-07-16│22:38▒
║favicon          ico│    4,286│11-04-27│03:03▒
║ajax-loader      gif│    1,644│09-01-20│01:40▒
║                    │         │        │     ▒
║                    │         │        │     ▒

I hope you can see it above after formatting as txt screen :)
You can change ".pl' to your contry symbol - in 385 line.
You can test it when click http://89.77.33.3/
( I see that now is no access from the outside - I think I was late paying bill :) But try on Monday)
You can see :
These pages are empty at the moment, I have no time to write them now. But good show examples of action.
Of cours you can write www.harbour-project.pl etc.
Nested folder are result from html code.
In my case they are :
╔═[1]═════════════════════════════════════════╗
║  D:\                                        
║  ├─[+] $RECYCLE.BIN                         ▒
║  ├─[-] homar                                ▒
║  │  ├───bossFiles                           ▒
║  │  ├───boss_jQuery                         ▒
║  │  ├─[-] httpFiles                         ▒
║  │  │  ├─[-] harbour-project.pl             ■
║  │  │  │  ├───images                        ▒
║  │  │  │  ├───img                           ▒
║  │  │  │  ├───js                            ▒
║  │  │  │  └───oracle                        ▒
║  │  │  ├───horodyscy.pl                     ▒
║  │  │  ├───marek-horodyski.pl               ▒
║  │  │  └─[-] marekhorodyski.pl              ▒
║  │  │     └───zdjecia                       ▒
║  │  ├─[-] http_jQuery                       ▒
║  │  │  ├───css                              ▒
║  │  │  ├───js                               ▒
║  │  │  └───plugins                          ▒
║  │  ├───scripts                             ▒
║  │  ├───tatry                               ▒
║  │  ├─[+] tempFiles                         ▒
║  │  ├─[+] tests                             ▒
║  │  └─[+] wydruki                           ▒

You should now see source code, line 409 and 410 :
         if hb_fileExists( cFile := oServer:cPathHttpFiles + domena + server[ as_http[ 12]]) .or. hb_fileExists( cFile := oServer:cPathHttpFiles + server[ as_http[ 12]])
           if right( cFile, 4) == '.bos'

if file has extension != bos, executed is line > 427.
When is "bos", this is script, and it is evaluated in line 420.
What is "bos" ? This is my wery old, written more than 20 yars ago, "runtime" for scripts in Clipper. I use it to continue the habit. I'm getting old, and I am reluctant to switch to something better. But I would advise you to change ".bos" to ".hb" and run here scripts like hbmk2, written in harbour, using \harbour\contrib\hbrun\. In hbmk2.prg in line 1606 you can see using examle : hb_run( LaunchCommand( tmp1 ) )

Pleas see for example on script in file \harbour\contrib\make.hb - they are compiled and executed in run time - as it is a powerful tool !!!
I do not know the licenses - maybe it Przemek better explain.

Yet two words of server. Script can return html (or part in ajax) as string. But when html is very, very big, this string can be empty, and useful code can be in aTempFile[ 1]. Handler for this file script should receive in parameters. In o:adbConnect app/scripts creates and holds pointers and number connections to databases (I use SqlLite - pointers, and Oracle - numbers). 
Server supports GET, POST and HEAD. But HEAD I have yet to improve, because it is handled a little differently than in the RFC says.
Whole server in one file, less than 540 line. I know, my code is not pretty, but it works correctly and efficiently. From the Clipper87 I have a habit of austerity strings - because they are separated in the code is a lot of references to them. Maybe you can understand and apply the code - it should meet your needs.

Regards,
Marek Horodyski



httpServer.zip

marek.h...@interia.pl

unread,
Oct 26, 2013, 5:47:00 AM10/26/13
to harbou...@googlegroups.com

Od: marek.h...@interia.pl
Do: harbou...@googlegroups.com;
Wysłane: 4:00 Sobota 2013-10-26


Temat: Re: [harbour] mongoose embedded web server + harbour interpreter, why not ?


[...]

You can change ".pl' to your contry symbol - in 385 line.
You can test it when click http://89.77.33.3/
( I see that now is no access from the outside - I think I was late paying bill :) But try on Monday)

Oh, after half a year changed my IP adress to 89.68.115.131. Now work with this IP.

One more note : in standard errorSys procedure I make so change :

 Function ErrorSys( e)

  Static tdz

  Local cMessage, aOptions, nChoice, v := V(), www := topProcName() == 'SOCKETCONNECTION'

  Local osc := ";( DOS Error " + NTRIM( e:osCode) + ");", pl := Zrodlo() + 'ERROR.LOG'

  if ( e:genCode == EG_LOCK )

   return ( .T. )

  End

[...]

  If NtoS( e:genCode) $ '345'

   // by default, division by zero yields zero

   If !www .and. ( tdz == Nil .OR. ElapTime( tdz, Time()) > '00:03:00')

    Stop( StrTran( cMessage, ';', EOL), { || KodKlaw( 2, 13)}, 'W+/R', "╔═╗║╝═╚║ ")

    tdz := Time()

   End

   Return If( e:genCode == 5, 0, .f.)

  End

  // obsluga po stronie przegladarki !

  if www ; break( e)

  end

  aOptions := {"Omin", "Koniec"} // her begining build skip, quit, ignore etc. to alert


Regards,

Marek Horodyski

marek.h...@interia.pl

unread,
Oct 29, 2013, 12:21:34 PM10/29/13
to harbou...@googlegroups.com

Od: marek.h...@interia.pl
Do: harbou...@googlegroups.com;
Wysłane: 4:00 Sobota 2013-10-26

Temat: Re: [harbour] mongoose embedded web server + harbour interpreter, why not ?

[...]

switch to something better. But I would advise you to change ".bos" to ".hb" and run here scripts like hbmk2, written in harbour, using \harbour\contrib\hbrun\. In hbmk2.prg in line 1606 you can see using examle : hb_run( LaunchCommand( tmp1 ) )

It's a mistake. Hb_run run command from operating systems. I meant, of course, about hb_hrbDo( hb_hrbLoad( 0xn, 'hbrFile.hrb')) or hb_hrbRun( 'hrbFile.hrb').

I do not use them, so I make mistakes.


Regards,
Marek Horodyski


marek.h...@interia.pl

unread,
Nov 1, 2013, 12:28:22 PM11/1/13
to harbou...@googlegroups.com

Od: "Domenico D'Oria" <nikk...@gmail.com>
Do: harbou...@googlegroups.com;

Wysłane: 11:47 Czwartek 2013-10-24

Temat: Re: [harbour] mongoose embedded web server + harbour interpreter, why not ?

Hi homar

after a lot of time surf and search the web, i try to explain better my question.

i know there is webserver like hbttpd written in harbour, but the question is : can this good piece of software be able to "interprete" harbour as a scripting language, like php or for example lua ? or asp vbscript for the incoming standards like html5.

or we must use it as a programming language ? as showed in the examples.

best regards

Hi Domenico,

Whether you're on trial for serving web pages?
Harbour does not cease to amaze me. Look what I found in a file \harbour\contrib\hbhttpd\core.prg :

...

1631│STATIC FUNCTION compile_file( cFileName, hConfig )
1632│
1633│   LOCAL nPos, cTpl, aCode := {}
1634│
1635│   IF cFileName == NIL
1636│      cFileName := MEMVAR->server[ "SCRIPT_NAME" ]
1637│   ENDIF
1638│   cFileName := UOsFileName( hb_DirBase() + "tpl/" + cFileName + ".tpl" )
1639│   IF hb_FileExists( cFileName )
1640│      cTpl := hb_MemoRead( cFileName )
1641│      BEGIN SEQUENCE
1642│         IF ( nPos := compile_buffer( cTpl, 1, aCode ) ) < Len( cTpl ) + 1
1643│            Break( nPos )
1644│         ENDIF
1645│      RECOVER USING nPos

...

It looks like it just needs to run.

Regards,
Marek Horodyski


Reply all
Reply to author
Forward
0 new messages