を置き換えるスクリプト用の安らかなハンドラーを実装しようとしている/
ので&
、このような URL を this: に変えることができ?script.c&things
ます?script/things
。現在、Gil によるこの投稿に基づいたテスト スクリプトがあります。
// ============================================================================
// 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 <stdio.h> // 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 << 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 long state = (long)argv[0];
printf("Catching Gwan State: %i\n", (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->ptr);
xbuf_replfrto(read_xbuf, read_xbuf->ptr, read_xbuf->ptr + 16, "/", "&");
printf("req_2: %.20s\n-------------------\n\n", read_xbuf->ptr);
return 255; // continue G-WAN's default execution path
}
// ============================================================================
// End of Source Code
// ============================================================================
このスクリプトには、printf("Catching Gwan State: %lu\n", (long)argv[0] );
取得した状態 (0 ~ 8 だと思います) を出力するはずの行がありますが、出力し続けます。
Catching Gwan State: -38241808
-38241808 が何かわかりません
ヘルプはありますか?私のOSはLinux Mint 14、Gwanバージョン4.2.19です
[編集] Gwan に付属の main_generic.c ハンドラの例を使用しても、これらの奇妙な状態値が得られます