:: [DNG] Web server [ was Re: Learning…
Pàgina inicial
Delete this message
Reply to this message
Autor: Didier Kryn
Data:  
A: dng
Assumptes vells: Re: [DNG] Learning C (books)
Assumptes nous: [DNG] Web server, [DNG] Sharing mob phone dataRe: Web server [ was Re: Learning C (books) ]
Assumpte: [DNG] Web server [ was Re: Learning C (books) ]
Le 07/10/2024 à 12:57, Nick via Dng a écrit :
> Just curiosity but what is so special that you are writing a complete
> new web server for it?


    My initial goal was to upload files from my smartphone (I bought my
1st one 1 year ago) to my laptop. You know that smartphones are
producers of images files. I do not like extracting and inserting the SD
card: it is delicate and likely to break something. Note also that I
have experimented trying to move a video file from a USB stick to the
Windows computer of a friend, and the Windows, after half an hour, was
still not responsive, and when we gave up and removed the USB stick, I
discovered Windows had written hundreds of junk files into it.

    It appeared to me that the HTTP protocol was the solution, because
there are plethora of functionnal browsers both on Windows and on
smartphones and they are forced to comply to the protocol and this
protocol provides a good insulation of both ends. Furthermore,
smartphones provide fast wifi connections when you enable connection
sharing and connect you computer to it

    I did not want either to write a cgi-bin program and configure a
full featured NGINX server to upload files through this cgi-bin because
it needs a complicated configuration. I wanted a lightweight solution.
Therefore I decided to write a web server which provides upload out of
the box and does not need any configuration. I first hacked a server
which provided upload. It took me one month.

    My server works on one single directory and follows neither subdirs
nor symbolic links; it is a one-client server, and it needs absolutely
no configuration.  But it was difficult to use, let me explain why.

    To permit upload, the client sends a GET request to which the
server replies by sending an HTML form with the method POST and the
Content-Type multipart/form-data. To perform file-selection and
submission, the browsers implement their own selectors and buttons, and
they are almost unreadable, at least on smartphones. Industrial web
services get around this by using javascripts. I don't know javascript
and don't want; therefore I had to work out style shits.

    Two other issues arised: first my HTTP parser was really a hack and
I wanted to make it more robust. I devised a method based on Flex which
I find now unmaintainable and I am working to change again. Second, on
smartphones, you cannot click on the right mouse button to download a
file instead of display it, therefore I implemented special links for
download. Third, while I was on this way, I implemented the delete
functionality. My server can now visit, download, upload and delete.
Upload and delete can be done several files in one shot, but there is no
way in HTML to download several files.

    My server presents 3 pages, each containing buttons to reach the
two others, plus an exit button. The visit/download page is a particular
format of autoindex and the delete page is another format of autoindex.
The upload page contains the browser's file-selector and the erase and
submit buttons. The download/visit page and the delete page are
obviously generated dynamically.

    My current work is to replace the Flex-based parser with a bare C
one. Then I will add some limited internationalization, since I intend
to make this work public. The internationalization will be for the error
pages sent to the client, based on the Accept-Language header line sent
by the browser. The server side will still write log and error messages
in the Unix jargon.

    The usage is extremely simple: you execute the server in a terminal
emulator, with a path as argument. The last directory in the path is
then shared with the first client which connects.

    --     Didier