library mod_test;
{$mode objfpc}{$H+}
uses
Classes, sysutils,httpd24, apr24;
var
test_module: module; {$ifdef Unix} public name 'test_module'; {$endif}
default_module_ptr: Pmodule;
const
MODULE_NAME = 'mod_test.so';
exports
test_module name 'test_module';
function ap_rputs(const str: string; const r: Prequest_rec): Integer;
begin
Result := ap_rwrite(@str[1],length(str),r);
end;
//this function will be iterated over the table and will do absolutely nothing
function test_function(rec: Pointer; const key, value: PChar): Integer; cdecl;
begin
Result:=0;
end;
function DefaultHandler(r: Prequest_rec): Integer; cdecl;
var
RequestedHandler: string;
begin
RequestedHandler := r^.handler;
if not SameText(RequestedHandler, 'test-handler') then
begin
Result := DECLINED;
Exit;
end;
ap_set_content_type(r, 'text/html');
if (r^.header_only <> 0) then
begin
Result := OK;
Exit;
end;
ap_rputs('<HTML>' + LineEnding, r);
ap_rputs('<HEAD>' + LineEnding, r);
ap_rputs('<TITLE>Hello There</TITLE>' + LineEnding, r);
ap_rputs('</HEAD>' + LineEnding, r);
ap_rputs('<BODY BGCOLOR="#FFFFFF">' + LineEnding ,r);
ap_rputs('<H1>Hello world</H1>' + LineEnding, r);
ap_rputs('This is the first Apache Module working with the new binding from Free Pascal<br><br>' + LineEnding, r);
apr_table_do(@test_function,r,r^.headers_in); //When I comment this out, everything works fine
ap_rputs('</BODY></HTML>' + LineEnding, r);
Result := OK;
end;
procedure RegisterHooks(p: Papr_pool_t); cdecl;
begin
ap_hook_handler(@DefaultHandler, nil, nil, APR_HOOK_MIDDLE);
end;
begin
default_module_ptr := @test_module;
FillChar(default_module_ptr^, SizeOf(default_module_ptr^), 0);
STANDARD20_MODULE_STUFF(test_module);
with test_module do
begin
name := MODULE_NAME;
register_hooks := @RegisterHooks;
end;
end.