Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You forgot to <code>return 255;</code> in the <code>main()</code> function.</p> <p>Remember that connection handler return codes have a signification:</p> <pre><code>return 255; // execute next connection step return 0; // close connection </code></pre> <p>Also, even if it remains empty, you must declare a <code>clean()</code> function in a connection handler:</p> <pre><code>void clean(int argc, char *argv[]) {} </code></pre> <p>Finally, you MUST test the handler state in <code>main()</code>.</p> <p>This gives us the tested code below:</p> <pre><code>// ============================================================================ // Handler C script for the G-WAN Web Application Server (http://gwan.ch/) // ---------------------------------------------------------------------------- // main.c: basic rewrite example // ============================================================================ #include "gwan.h" // G-WAN exported functions #include &lt;stdio.h&gt; // puts(), printf() // ---------------------------------------------------------------------------- // init() will initialize your data structures, load your files, etc. // ---------------------------------------------------------------------------- // init() should return -1 if failure (to allocate memory for example) int init(int argc, char *argv[]) { // define which handler states we want to be notified in main(): // enum HANDLER_ACT { // HDL_INIT = 0, // HDL_AFTER_ACCEPT, // just after accept (only client IP address setup) // HDL_AFTER_READ, // each time a read was done until HTTP request OK // HDL_BEFORE_PARSE, // HTTP verb/URI validated but HTTP headers are not // HDL_AFTER_PARSE, // HTTP headers validated, ready to build reply // HDL_BEFORE_WRITE, // after a reply was built, but before it is sent // HDL_HTTP_ERRORS, // when G-WAN is going to reply with an HTTP error // HDL_CLEANUP }; u32 *states = (u32*)get_env(argv, US_HANDLER_STATES); *states = (1 &lt;&lt; HDL_AFTER_READ); return 0; } // ---------------------------------------------------------------------------- // clean() will free any allocated memory and possibly log summarized stats // ---------------------------------------------------------------------------- void clean(int argc, char *argv[]) {} // ---------------------------------------------------------------------------- // main() does the job for all the connection states below: // (see 'HTTP_Env' in gwan.h for all the values you can fetch with get_env()) // ---------------------------------------------------------------------------- int main(int argc, char *argv[]) { // HDL_HTTP_ERRORS return values: // 0: Close the client connection // 2: Send a server reply based on a custom reply buffer // 255: Continue (send a reply based on the request HTTP code) const int state = (long)argv[0]; if(state != HDL_AFTER_READ) return 255; xbuf_t *read_xbuf = (xbuf_t*)get_env(argv, READ_XBUF); printf("req_1: %.20s\n", read_xbuf-&gt;ptr); xbuf_replfrto(read_xbuf, read_xbuf-&gt;ptr, read_xbuf-&gt;ptr + 16, " / ", " /?home "); printf("req_2: %.20s\n-------------------\n\n", read_xbuf-&gt;ptr); return 255; // continue G-WAN's default execution path } // ============================================================================ // End of Source Code // ============================================================================ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload