Hello, DSAPI!
DSAPI(Domino WebServer API)は、DominoサーバのHTTPタスクにアドインするためのAPI。 今回は、これでHelloアプリを作る。
することは2つ。
1つは、インストールに成功したら、DominoのログにHello, DSAPI Init!
の表示をする。
もう1つは、ブラウザから/hello
としたらHellp. DSAPI Filter!
の表示をする。
#include <dsapi.h> #include <string> extern "C" __declspec(dllexport) unsigned int FilterInit(FilterInitData *pInitData) { pInitData->appFilterVersion = kInterfaceVersion; pInitData->eventFlags = kFilterParsedRequest; strcpy_s(pInitData->filterDesc, "Hello, DSAPI Init!"); return kFilterHandledEvent; } extern "C" __declspec(dllexport) unsigned int HttpFilterProc(FilterContext* ctx, unsigned int eventType, void*) { try { unsigned int errId = 0; switch (eventType) { case kFilterParsedRequest: FilterRequest req; ctx->GetRequest(ctx, &req, &errId); if (errId != 0) throw errId; if (req.method == kRequestGET && std::strncmp(req.URL, "/hello", 6) == 0) { char content[] = "HTTP/1.1 200 OK\n" "Content-Type: text/plain; charset=utf8\n" "\n" "Hello, DSAPI Filter!"; ctx->WriteClient(ctx, content, strlen(content), 0, &errId); if (errId != 0) throw errId; return kFilterHandledRequest; } break; default: return kFilterNotHandled; } } catch (...) { return kFilterError; } }
- コンパイルして、DLLを作成する。例えば、
hello
というアドインであれば、nhello.dll
という名前でDLLを作る。頭文字のn
はWindows用のプリフィックス。 nhello.dll
をDominoサーバのプログラムディレクトリにコピーする(他に必要なモジュールも同様にプログラムディレクトリに置く)。- サーバ文書かWeb設定のDSAPI欄に、
hello
と記述する(n
と.dll
は書かない)。 - Dominoサーバを再起動する。
すると、Dominoコンソールには以下のように表示される。
続いて、ブラウザから次のようなリクエストを送る。
http://localhost/hello
すると、以下のようなレスポンスが返ってくる。