### FastCGI Protocol Message Flow Examples Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/FastCGI Specification.html Illustrates typical FastCGI protocol message flows with detailed examples, including requests with and without stdin data, error handling, and multiplexed requests. ```APIDOC ## FastCGI Protocol Message Flow Examples ### Description This section provides examples of common FastCGI protocol message sequences, demonstrating various scenarios such as simple requests, requests with input data, error conditions, and multiplexed connections. ### Notational Conventions - `contentData` of stream records (FCGI_PARAMS, FCGI_STDIN, FCGI_STDOUT, FCGI_STDERR) is represented as a character string. A string ending in " ... " is truncated. - Messages sent to the Web server are indented. - Messages are shown in the time sequence experienced by the application. ### Example 1: Simple Request with Successful Response **Flow:** 1. `FCGI_BEGIN_REQUEST`: Initiates a request, specifying the role (RESPONDER) and flags. 2. `FCGI_PARAMS`: Sends request parameters (e.g., server variables). 3. `FCGI_STDIN`: Sends standard input data (empty in this case). 4. `FCGI_STDOUT`: Sends standard output (HTML content). 5. `FCGI_END_REQUEST`: Terminates the request, indicating the app status and protocol status. **Messages:** ``` {FCGI_BEGIN_REQUEST, 1, {FCGI_RESPONDER, 0}} {FCGI_PARAMS, 1, "\013\002SERVER_PORT80\013\016SERVER_ADDR199.170.183.42 ... "} {FCGI_PARAMS, 1, ""} {FCGI_STDIN, 1, ""} {FCGI_STDOUT, 1, "Content-type: text/html\r\n\r\n\n ... "} {FCGI_STDOUT, 1, ""} {FCGI_END_REQUEST, 1, {0, FCGI_REQUEST_COMPLETE}} ``` ### Example 2: Request with Data on Stdin **Flow:** Similar to Example 1, but includes data in `FCGI_STDIN` and potentially more `FCGI_PARAMS` records. **Messages:** ``` {FCGI_BEGIN_REQUEST, 1, {FCGI_RESPONDER, 0}} {FCGI_PARAMS, 1, "\013\002SERVER_PORT80\013\016SER"} {FCGI_PARAMS, 1, "VER_ADDR199.170.183.42 ... "} {FCGI_PARAMS, 1, ""} {FCGI_STDIN, 1, "quantity=100&item=3047936"} {FCGI_STDIN, 1, ""} {FCGI_STDOUT, 1, "Content-type: text/html\r\n\r\n\n ... "} {FCGI_STDOUT, 1, ""} {FCGI_END_REQUEST, 1, {0, FCGI_REQUEST_COMPLETE}} ``` ### Example 3: Application Detects an Error **Flow:** The application logs to stderr, returns a page via stdout, and returns a non-zero exit status. **Messages:** ``` {FCGI_BEGIN_REQUEST, 1, {FCGI_RESPONDER, 0}} {FCGI_PARAMS, 1, "\013\002SERVER_PORT80\013\016SERVER_ADDR199.170.183.42 ... "} {FCGI_PARAMS, 1, ""} {FCGI_STDIN, 1, ""} {FCGI_STDOUT, 1, "Content-type: text/html\r\n\r\n\n ... "} {FCGI_STDOUT, 1, ""} {FCGI_STDERR, 1, ""} {FCGI_END_REQUEST, 1, {938, FCGI_REQUEST_COMPLETE}} ``` ### Example 4: Multiplexed Requests **Flow:** Two requests are processed concurrently on a single connection, potentially finishing out of order. **Messages:** ``` {FCGI_BEGIN_REQUEST, 1, {FCGI_RESPONDER, FCGI_KEEP_CONN}} {FCGI_PARAMS, 1, "\013\002SERVER_PORT80\013\016SERVER_ADDR199.170.183.42 ... "} {FCGI_PARAMS, 1, ""} {FCGI_BEGIN_REQUEST, 2, {FCGI_RESPONDER, FCGI_KEEP_CONN}} {FCGI_PARAMS, 2, "\013\002SERVER_PORT80\013\016SERVER_ADDR199.170.183.42 ... "} {FCGI_STDIN, 1, ""} {FCGI_STDOUT, 1, "Content-type: text/html\r\n\r\n"} {FCGI_PARAMS, 2, ""} {FCGI_STDIN, 2, ""} {FCGI_STDOUT, 2, "Content-type: text/html\r\n\r\n\n ... "} {FCGI_STDOUT, 2, ""} {FCGI_END_REQUEST, 2, {0, FCGI_REQUEST_COMPLETE}} {FCGI_STDOUT, 1, "\n ... "} {FCGI_STDOUT, 1, ""} {FCGI_END_REQUEST, 1, {0, FCGI_REQUEST_COMPLETE}} ``` ``` -------------------------------- ### Assembly: URL Routing Examples Source: https://context7.com/johnfound/asmbb/llms.txt Illustrative examples demonstrating how different URL formats are interpreted and routed to specific functionalities. This includes handling the root path, tagged threads, specific threads with pagination, and commands prefixed with '!'. ```assembly ; Example URL routing: ; / -> ThreadList (homepage) ; /tag-name/ -> ThreadList filtered by tag ; /tag-name/thread-slug/ -> ShowThread ; /tag-name/thread-slug/5 -> ShowThread, page 5 ; /!login/ -> UserLogin command ; /!search/?query=assembly -> SearchEngine command ``` -------------------------------- ### Start AsmBB Service Command Source: https://github.com/johnfound/asmbb/blob/master/install/install.txt Command to start the AsmBB service using systemd. ```bash $sudo systemctl start asmbb ``` -------------------------------- ### x86 Assembly Code Block Example Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Demonstrates a basic x86 assembly code snippet within a code block. This functionality is useful for displaying inline assembly code. ```x86asm push eax mov eax, ebx ``` -------------------------------- ### Enable AsmBB Automatic Startup Command Source: https://github.com/johnfound/asmbb/blob/master/install/install.txt Command to configure the AsmBB service to start automatically on server boot. ```bash $sudo systemctl enable asmbb ``` -------------------------------- ### Example: Text Data with Charset Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/rfc7578.txt Demonstrates how to format multipart/form-data with a text part, specifying the character encoding using the 'charset' parameter in the Content-Type header. This example shows a text field 'field1' encoded in UTF-8, including a special character. ```text --AaB03x content-disposition: form-data; name="field1" content-type: text/plain;charset=UTF-8 content-transfer-encoding: quoted-printable Joe owes =E2=82=AC100. --AaB03x ``` -------------------------------- ### Example of application/x-www-form-urlencoded Data Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/rfc7578.txt Demonstrates the structure of data encoded using the 'application/x-www-form-urlencoded' media type. This format is compact but lacks mechanisms for content type or charset labeling. ```text name=Xavier+Xantico&verdict=Yes&colour=Blue&happy=sad&Utf%F6r=Send ``` -------------------------------- ### Inline Formatting Examples Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-minimag.txt Demonstrates various inline text formatting options available in AsmBB markup, including bold, italic, underlined, strikethrough, and monospaced text. Formats can be combined. ```text `*Bold text*` `/Italic text/` `_Underlined text_` `-Strikedthrough-` `Monospaced inline text` `_*/The formats can be combined/*_` ``` -------------------------------- ### FastCGI: Get Values and Get Values Result Record Types Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/FastCGI Specification.html FCGI_GET_VALUES allows the web server to query application variables, typically during startup for configuration. The application responds with FCGI_GET_VALUES_RESULT, providing values for requested variables. Unrecognized variables are omitted from the response. ```c // The application receives a query as a record {FCGI_GET_VALUES, 0, ...}. // The contentData portion of a FCGI_GET_VALUES record contains a sequence of name-value pairs with empty values. // The application responds by sending a record {FCGI_GET_VALUES_RESULT, 0, ...} with the values supplied. // Example variables: // * FCGI_MAX_CONNS: The maximum number of concurrent transport connections. // * FCGI_MAX_REQS: The maximum number of concurrent requests. // * FCGI_MPXS_CONNS: "0" if the application does not multiplex connections, "1" otherwise. ``` -------------------------------- ### Image Formatting with BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Demonstrates the BBCode tag for embedding images. This tag supports an optional ALT text and requires the image URL. It is primarily used for block-level images. ```nohighlight [img=ALT_TEXT]IMAGE_URL[/img] ``` -------------------------------- ### Example: Default Charset Specification Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/rfc7578.txt Illustrates how a default charset can be established for a multipart/form-data message using a hidden form entry named '_charset_'. Subsequent text parts without an explicit charset parameter will inherit this default encoding. ```text --AaB03x content-disposition: form-data; name="_charset_" iso-8859-1 --AaB03x-- content-disposition: form-data; name="field1" ...text encoded in iso-8859-1 ... AaB03x-- ``` -------------------------------- ### List Formatting with BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Demonstrates BBCode tags for creating unordered ([list], [ul]) and ordered ([ol]) lists. List items are defined using the [*] tag, and nesting of lists is supported. ```nohighlight [list] [*] Bullet item 1 [ol] [*] Num item 1 [*] Num item 2 [/ol] [*] Bullet item 2 [ul] [*] Nested bullet item. Paragraph for this bullet item. [*] Another nested bullet item. [/ul] [/list] ``` -------------------------------- ### Header Formatting with BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Illustrates BBCode tags for creating headers of different levels, from h1 to h6. These tags are used to structure content and denote headings within the document. ```nohighlight [h1]Header level 1[/h1] [h2]Header level 2[/h2] [h3]Header level 3[/h3] [h4]Header level 4[/h4] [h5]Header level 5[/h5] [h6]Header level 6[/h6] ``` -------------------------------- ### Systemd Service Configuration for AsmBB Source: https://github.com/johnfound/asmbb/blob/master/install/install.txt This snippet defines a systemd service file to manage the AsmBB forum engine. It specifies the user, working directory, and the command to start the engine. The service is configured to restart on failure and depends on the Nginx service. ```systemd [Unit] Description=AsmBB forum engine FastCGI script. After=nginx.service [Service] Type=simple User=NON_ROOT WorkingDirectory=/PATH/TO/FORUM ExecStart=/PATH/TO/FORUM/engine Restart=on-failure [Install] WantedBy=nginx.service ``` -------------------------------- ### Link Formatting with BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Shows the BBCode tag for creating hyperlinks. The tag takes a URL as a parameter and the link text to be displayed. This is used to reference external or internal resources. ```nohighlight [url=URL]Link text[/url] ``` -------------------------------- ### URL Routing and Command Handling Source: https://context7.com/johnfound/asmbb/llms.txt This section details how incoming URLs are parsed and mapped to specific command handlers using a hash table. It also outlines the structure of request parameters and provides examples of URL routing. ```APIDOC ## URL Routing and Command Handling ### Description Handles incoming HTTP requests by parsing the URL into components such as command, directory/tag, thread slug, and page number. It then routes these components to specialized handler procedures using a pre-defined hash table. ### Method GET, POST ### Endpoint `/` `/tag-name/` `/tag-name/thread-slug/` `/tag-name/thread-slug/page_number` `/!command/` `/!command/?query_params` ### Parameters #### Path Parameters - **tag-name** (string) - Optional - The directory or tag name specified in the URL. - **thread-slug** (string) - Optional - The unique identifier for a thread. - **page_number** (integer) - Optional - The page number or post ID within a thread. - **command** (string) - Required - The specific command to be executed (e.g., `login`, `search`). #### Query Parameters - **query** (string) - Optional - Search query parameter for the `SearchEngine` command. #### Request Body Not typically used for GET requests, but POST requests might contain data related to commands like `new_thread` or `new_post`. ### Request Example ```json { "example": "/!login/" } ``` ```json { "example": "/!search/?query=assembly" } ``` ### Response #### Success Response (200) Responses vary depending on the command executed. Examples include: - Thread list for the homepage or tag-filtered views. - Specific thread content with pagination. - User authentication status. - Search results. #### Response Example ```json { "example": "[Thread List Data]" } ``` ```json { "example": "[User Authentication Response]" } ``` ``` -------------------------------- ### FastCGI: Begin Request Structure and Flags Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/FastCGI Specification.html The FCGI_BEGIN_REQUEST record initiates a request from the web server to the application. It specifies the role the application should play (Responder, Authorizer, Filter) and includes flags to control connection persistence after the request is completed. ```c typedef struct { unsigned char roleB1; unsigned char roleB0; unsigned char flags; unsigned char reserved[5]; } FCGI_BeginRequestBody; // The flags component contains a bit that controls connection shutdown: // * flags & FCGI_KEEP_CONN: If zero, the application closes the connection after responding. // If not zero, the web server retains responsibility for the connection. ``` -------------------------------- ### FastCGI Protocol Overview Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/FastCGI Specification.html This section provides a high-level overview of the FastCGI protocol, explaining its purpose, design goals, and comparison to conventional CGI implementations. ```APIDOC ## FastCGI Protocol Overview ### Description FastCGI is an open extension to CGI that provides high performance for internet applications without the penalties of Web server APIs. This specification details the interface between a FastCGI application and a Web server. ### Key Features - Supports long-lived application processes (application servers). - Multiplexes a single transport connection between several independent FastCGI requests. - Provides independent data streams within each request (e.g., stdout and stderr over a single connection). - Defines distinct roles for applications: Responder, Authorizer, and Filter. ### Target Environment - Primarily designed for Unix-like systems (POSIX systems supporting Berkeley Sockets). - Protocol is independent of byte ordering and extensible to other systems. ``` -------------------------------- ### Mixed Nested Lists Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-minimag.txt Provides an example of freely nesting unordered and ordered lists within each other in AsmBB markup. ```text ;ulist * Bullet item 1 ;olist * Num item 1 * Num item 2 ;end * Bullet item 2 ;ulist * Nested bullet item. * Another nested bullet item. ;end ;end ``` -------------------------------- ### Emoticon Support in BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Lists common BBCode tags that represent emoticons. These tags are replaced with corresponding graphical emoticons when rendered. ```nohighlight [:)] = Smile [:D] = LOL [:rofl:] = ROFL [;)] = Wink [:P] = Tongue [:(] = Sad [:`(] = Crying [>:(] = Angry ``` -------------------------------- ### FastCGI Listening and Request Handling (Assembly) Source: https://context7.com/johnfound/asmbb/llms.txt Implements the core logic for the FastCGI interface in AsmBB. The 'Listen' procedure initializes the server and accepts incoming connections, while 'procServeRequest' handles individual client requests, including parsing parameters, reading input, routing commands, and sending responses. Supports multiplexed connections and persistent processes. ```assembly ; Main listening loop for FastCGI requests ; Call this to start accepting connections proc Listen ; Initialize socket and bind to Unix socket or TCP port ; Listen for incoming FastCGI connections ; Spawn thread for each connection (max 20 concurrent) ; Call procServeRequest for each request ; Handle connection persistence with FCGI_KEEP_CONN flag end ; Process individual FastCGI request proc procServeRequest, .hSocket, .requestID ; Parse FCGI_PARAMS for HTTP headers and CGI variables ; Read FCGI_STDIN for POST data ; Route to appropriate command handler ; Send response via FCGI_STDOUT ; End request with FCGI_END_REQUEST end ``` -------------------------------- ### Application Record Types: FCGI_BEGIN_REQUEST Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/FastCGI Specification.html Details the FCGI_BEGIN_REQUEST record, which the web server sends to initiate a request. It specifies the expected role of the application and flags for connection management. ```APIDOC ## FCGI_BEGIN_REQUEST ### Description The FCGI_BEGIN_REQUEST record is sent by the Web server to initiate a request to the application. It defines the role the application should assume (Responder, Authorizer, or Filter) and includes flags that control connection handling after the request is processed. ### Method Not Applicable (Record-based communication) ### Endpoint Not Applicable (Record-based communication) ### Parameters #### Request Body (FCGI_BEGIN_REQUEST) - **roleB1** (unsigned char): High byte of the role. - **roleB0** (unsigned char): Low byte of the role. - **flags** (unsigned char): Contains flags, notably FCGI_KEEP_CONN. - **reserved** (unsigned char[5]): Reserved bytes. ### Role Definitions - **FCGI_RESPONDER**: The application will generate a response. - **FCGI_AUTHORIZER**: The application will authorize the request. - **FCGI_FILTER**: The application will act as a filter. ### Flags - **FCGI_KEEP_CONN**: If set (non-zero), the application should not close the connection after responding. The Web server retains responsibility for the connection. If zero, the application closes the connection. ### Request Example ```json { "record_type": "FCGI_BEGIN_REQUEST", "request_id": 1, "content": { "roleB1": 0, "roleB0": 1, "flags": 1, "reserved": [0,0,0,0,0] } } ``` ### Response Example Not Applicable (This is a request record from the server) ``` -------------------------------- ### Spoiler Element Formatting with BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Shows the BBCode tag for creating a spoiler element. This tag allows for content that is initially hidden and can be expanded by the user, featuring a visible title. ```nohighlight [spoiler=ALWAIS VISIBLE TITLE TEXT]INITIALLY HIDDEN TEXT[/spoiler] ``` -------------------------------- ### User Registration Procedure - Assembly Source: https://context7.com/johnfound/asmbb/llms.txt Handles new user registration by validating input fields such as username, password, and email format. It generates a salt, hashes the password, creates an activation secret, and stores the user information awaiting email confirmation. ```assembly ; User registration with email confirmation proc RegisterNewUser, .pSpecial begin ; Validate username (min 3 chars, alphanumeric) stdcall GetPostString, ebx, "username", 0 stdcall StrLen, eax cmp eax, 3 jb .redirect_back_short_name ; Validate password (min 6 chars) stdcall GetPostString, ebx, "password", 0 mov [.password], eax stdcall StrLen, eax cmp eax, MIN_PASS_LENGTH jb .redirect_back_short_pass ; Check password confirmation matches stdcall GetPostString, ebx, "password2", 0 stdcall StrComp, eax, [.password] jne .redirect_back_passwords_different ; Validate email format stdcall GetPostString, ebx, "email", 0 stdcall ValidateEmail, eax jc .redirect_back_bad_email ; Generate salt and hash password stdcall GetRandomString, 32 mov [.salt], eax stdcall HashPassword, [.password], [.salt] mov [.passHash], eax ; Generate activation secret stdcall GetRandomString, 64 mov [.secret], eax ; Insert into WaitingActivation table cinvoke sqlitePrepare_v2, [hMainDatabase], sqlInsertWaiting, sqlInsertWaiting.length, .stmt, 0 stdcall StrPtr, [.secret] cinvoke sqliteBindText, [.stmt], 1, eax, [eax+string.len], SQLITE_STATIC cinvoke sqliteBindInt, [.stmt], 2, uopCreateAccount stdcall StrPtr, [.user] cinvoke sqliteBindText, [.stmt], 3, eax, [eax+string.len], SQLITE_STATIC stdcall StrPtr, [.passHash] cinvoke sqliteBindText, [.stmt], 4, eax, [eax+string.len], SQLITE_STATIC stdcall StrPtr, [.salt] cinvoke sqliteBindText, [.stmt], 5, eax, [eax+string.len], SQLITE_STATIC stdcall StrPtr, [.email] cinvoke sqliteBindText, [.stmt], 6, eax, [eax+string.len], SQLITE_STATIC cinvoke sqliteBindInt, [.stmt], 7, [esi+TSpecialParams.remoteIP] cinvoke sqliteStep, [.stmt] ; Send activation email with link: http://forum.com/!activate/SECRET stdcall GetParam, "host", gpString stdcall StrCat, eax, "/!activate/", [.secret] stdcall SendEmail, [.email], "Activate your account", eax stdcall ShowMessage, "user_created" return end ``` -------------------------------- ### Accepting Transport Connections in FastCGI Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/FastCGI Specification.html Shows the C code pattern for a FastCGI application to accept incoming transport connections on the listening socket. It includes the crucial step of checking the FCGI_WEB_SERVER_ADDRS environment variable to validate the web server's IP address. ```c #include #include #include #define FCGI_LISTENSOCK_FILENO 0 int main() { // Assume FCGI_LISTENSOCK_FILENO is already set up by the web server int listening_socket = FCGI_LISTENSOCK_FILENO; struct sockaddr_in sa; socklen_t len = sizeof(sa); int client_socket; client_socket = accept(listening_socket, (struct sockaddr *)&sa, &len); if (client_socket < 0) { perror("accept failed"); return 1; } // Check FCGI_WEB_SERVER_ADDRS if it exists char *web_server_addrs = getenv("FCGI_WEB_SERVER_ADDRS"); if (web_server_addrs) { // Logic to parse web_server_addrs and check sa.sin_addr.s_addr // If the peer IP address is not in the list, close(client_socket); printf("FCGI_WEB_SERVER_ADDRS is set. Validation required.\n"); } printf("Accepted connection on socket: %d\n", client_socket); // ... proceed with FastCGI communication ... close(client_socket); return 0; } ``` -------------------------------- ### Nginx Configuration for AsmBB Source: https://github.com/johnfound/asmbb/blob/master/install/install.txt This snippet shows how to configure Nginx to serve the AsmBB forum. It specifies the root directory for the forum files and how to pass requests to the AsmBB engine via FastCGI. Ensure placeholders like root path and socket path are replaced. ```nginx server { ..... # Your subdomain server configuration. # Should contains at least "listen" and "server_name" nginx options. root /PATH/TO/FORUM/; location / { fastcgi_pass unix:/PATH/TO/FORUM/engine.sock; include fastcgi_params; } } ``` -------------------------------- ### Block Quote Formatting with BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Shows the BBCode tag used for creating block quotes. This tag can optionally take a title and is used to offset quoted text from the main content. ```nohighlight [quote=QUOTE_TITLE]QUOTE TEXT[/quote] ``` -------------------------------- ### Show Thread with Posts - Assembly Source: https://context7.com/johnfound/asmbb/llms.txt This procedure displays a forum thread along with its posts, supporting pagination. It checks read permissions, retrieves the current page number (defaulting to 1), and fetches the user's 'posts per page' setting. It then queries the database for thread and post information, applying pagination using LIMIT and OFFSET clauses. The results are rendered using a specified template. Dependencies include SQLite functions and parameter retrieval utilities. ```assembly ; Display thread with posts (paginated) proc ShowThread, .pSpecial .stmt dd ? .page_num dd ? .posts_per_page dd ? begin mov esi, [.pSpecial] ; Check read permission test [esi+TSpecialParams.userStatus], permRead jz .no_permission ; Get page number (default 1) mov eax, [esi+TSpecialParams.page_num] test eax, eax jnz .page_ok mov eax, 1 .page_ok: mov [.page_num], eax ; Get posts per page setting stdcall GetParam, "page_length", gpInteger mov [.posts_per_page], eax ; Query thread and posts with pagination cinvoke sqlitePrepare_v2, [hMainDatabase], "SELECT P.id, P.userID, U.nick, P.postTime, P.editTime, P.Content, P.format FROM Posts P LEFT JOIN Users U ON P.userID=U.id WHERE P.threadID=(SELECT id FROM Threads WHERE Slug=?)", -1, .stmt, 0 stdcall StrPtr, [esi+TSpecialParams.thread] cinvoke sqliteBindText, [.stmt], 1, eax, [eax+string.len], SQLITE_STATIC cinvoke sqliteStep, [.stmt] cinvoke sqlitePrepare_v2, [hMainDatabase], "SELECT P.id, P.userID, U.nick, P.postTime, P.editTime, P.Content, P.format FROM Posts P LEFT JOIN Users U ON P.userID=U.id WHERE P.threadID=? ORDER BY P.id LIMIT ? OFFSET ?", -1, .stmt, 0 cinvoke sqliteBindInt, [.stmt], 1, [esi+TSpecialParams.threadID] cinvoke sqliteBindInt, [.stmt], 2, [.posts_per_page] mov eax, [.page_num] dec eax imul eax, [.posts_per_page] cinvoke sqliteBindInt, [.stmt], 3, eax ; Render template with posts stdcall RenderTemplate, 0, "show_thread.tpl", [.stmt], esi cinvoke sqliteFinalize, [.stmt] return end ``` -------------------------------- ### Protocol Notation - Variable Length Structs Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/FastCGI Specification.html Illustrates the C language notation used to define variable-length structures in the FastCGI protocol. This allows for messages where the length of a data component is determined by preceding length fields. ```c struct { unsigned char mumbleLengthB1; unsigned char mumbleLengthB0; // ... other stuff ... unsigned char mumbleData[mumbleLength]; }; ``` -------------------------------- ### Assembly: Pre-command Hash Table for URL Routing Source: https://context7.com/johnfound/asmbb/llms.txt This assembly code defines a hash table that maps URL patterns (like '!avatar', '!login') to their corresponding handler procedures (e.g., UserAvatar, UserLogin). This structure is fundamental for routing incoming requests to the correct functionality within the application. ```assembly ; Pre-command hash table mapping URLs to handlers PHashTable tablePreCommands, tpl_func, "!avatar", UserAvatar, "!attached", GetAttachedFile, "!login", UserLogin, "!logout", UserLogout, "!register", RegisterNewUser, "!resetpassword", ResetPassword, "!changepassword", ChangePassword, "!changemail", ChangeEmail, "!sqlite", SQLiteConsole, "!settings", BoardSettings, "!message", ShowForumMessage, "!activate", ActivateAccount, "!userinfo", ShowUserInfo, "!users_online", UserActivityTable, "!chat", ChatPage, "!events", EventsRealTime, "!users", UsersList, "!search", SearchEngine, "!new_thread", CreateNewThread, "!new_post", CreateNewPost, "!edit_post", EditPost, "!delete_post", DeletePost, "!atom", AtomFeed ``` -------------------------------- ### Inline Text Formatting with BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Demonstrates BBCode tags for applying bold, italic, underline, strikethrough, monospaced text, font size, and color to inline text. These tags are used within paragraphs to style specific parts of the text. ```nohighlight [b]Bold text[/b] [i]Italic text[/i] [u]Underlined text[/u] [s]Strikedthrough[/s] [c]Monospaced inline text[/c] [size=CSS_SIZE]Different size of the text[/size] [color=CSS_COLOR]Different color of the text[/color] ``` -------------------------------- ### Source Code Block Formatting with BBCode Source: https://github.com/johnfound/asmbb/blob/master/www/templates/Urban Sunrise/help-bbcode.txt Illustrates the BBCode tag for displaying source code blocks. It supports an optional language parameter for syntax highlighting, with 'nohighlight' and 'plaintext' options for disabling or plain text formatting. All formatting tags are disabled within code blocks. ```nohighlight [code=LANGUAGE]SOURCE CODE[/code] ``` -------------------------------- ### Application Record Types: Byte Streams (FCGI_STDIN, FCGI_DATA, FCGI_STDOUT, FCGI_STDERR) Source: https://github.com/johnfound/asmbb/blob/master/source/Documents/FastCGI Specification.html Details the stream record types used for transferring arbitrary data between the web server and the application. FCGI_STDIN and FCGI_DATA are for server-to-app data, while FCGI_STDOUT and FCGI_STDERR are for app-to-server data. ```APIDOC ## Byte Streams: FCGI_STDIN, FCGI_DATA, FCGI_STDOUT, FCGI_STDERR ### Description These record types facilitate the transfer of arbitrary byte data between the Web server and the application. FCGI_STDIN and FCGI_DATA are used by the server to send data to the application (e.g., POST request bodies), while FCGI_STDOUT and FCGI_STDERR are used by the application to send its response output and error messages back to the server. ### Method Not Applicable (Record-based communication) ### Endpoint Not Applicable (Record-based communication) ### Parameters #### Server to Application (FCGI_STDIN, FCGI_DATA) - **arbitrary data**: The contentData portion contains the bytes being sent. #### Application to Server (FCGI_STDOUT, FCGI_STDERR) - **arbitrary data**: The contentData portion contains the bytes being sent. ### Request Example (Server to App) ```json { "record_type": "FCGI_STDIN", "request_id": 1, "content": "This is the standard input data." } ``` ### Response Example (App to Server) ```json { "record_type": "FCGI_STDOUT", "request_id": 1, "content": "This is the standard output response." } ``` ```