The question I have is where should we focus on learning the AsmBB source? I've downloaded it and begun to comb through it, but a starting point may help me find out more about how you managed to successfully get the whole thing working. I'm more interested in learning assembly, but I've found that jumping headlong into examples does me more good than just writing small bits of code that don't do much.
Well, I can help by shortly describing the structure of the project. But notice that because of using FastCGI protocol, AsmBB is a little bit more complex than usual for beginner assembly programmer.
The simple CGI web application (for example my CMS MiniMagAsm) works by short living CGI processes. They are started by the web server, receive the HTTP request by reading STDIN, write the response (e.g. HTML) to STDOUT and terminate.
The FastCGI application works a little bit different. At first it works all the time and listens for connections on some socket. The web server connects to this socket and sends the request. Then the FastCGI application sends back the response using the same connection. Serving multiply requests on the same connection and multiply connections are possible. Also, the web server can start several instances of the FastCGI application. It is all about a performance.
So, the structure of AsmBB:
Everything starts in engine.asm
, line:84 - the label start:
. Here the engine initializes its environments and opens the SQLite database with the forum data. Then it calls the procedure Listen
(line: 126) that is the main loop of the program. It returns only when the engine terminates. After retuning from Listen
, the program closes the database, finalizes its works and exits.
The procedure Listen
is defined in the source file fcgi.asm:155
. This is the code, that handles FastCGI protocol. It simply listens for connections from the web server and on connection creates a thread that to serve the request and continues to listen. The thread is started in the procedure procServeRequest
in fcgi.asm:347
.
This thread, receives the request information on the socket and collects it for future processing.
Once the whole information is collected - i.e. the HTTP reques, the POST data (if any) and the environment parameters, the procedure ServeOneRequest
is called. It is actually the "business logic" code that makes the application to act as a web forum.
ServeOneRequest
returns the response (e.g. HTML code, images, etc.) that is returned to the web server, according to FastCGI protocol. After completing the request, the thread terminates or stays waiting for another request. It depends on how the web server can multiplex the requests on the FastCGI connection.
ServeOneRequest
is located in the file commands.asm:49
. It analyzes the request URL and the request type (GET, POST) and decides how to serve it. For example, it can return some file directly, or read the information from the database, or store some information in the database.
The URL analyze is important and located on commands.asm:332
- it dispatches the control depending on the URL elements. The addresses of the different procedures are loaded to ECX
and later called (label .exec_command
, line: 524 or .exec_command2:
, line: 541).
Later you can browse these procedures. They are located in different files, serving different aspects of forum engine. For example, the procedure ListThreads
(threadlist.asm) creates the list of threads on the front page of the forum.
The procedure ShowThread
(showthread.asm) displays one thread. And so on.
Notice, that AsmBB widely uses the library FreshLib. You can read more in FreshLib reference and FreshLib user guide, but unfortunately the documentation is far from perfect.
In order to better browse the big code, scattered across multiply files, I would suggest using Fresh IDE code browsing features. Read more in the following article: Tips and tricks. Especially useful if the feature "Goto definition" (Ctrl+D) that will jump you at the line where some label is defined. The cross reference is also useful (Ctrl+R).
FreshLib user guide