logging.pp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. (* Feel free to use this example code in any way
  2. you see fit (Public Domain) *)
  3. // Original example: https://gnunet.org/svn/libmicrohttpd/doc/examples/logging.c
  4. program logging;
  5. {$mode objfpc}{$H+}
  6. uses
  7. libmicrohttpd, sysutils;
  8. const
  9. PORT = 8888;
  10. function PrintOutKey(ACls: Pointer; AKind: MHD_ValueKind; AKey: Pcchar;
  11. AValue: Pcchar): cint; cdecl;
  12. begin
  13. WriteLn(Format('%s: %s', [AKey, AValue]));
  14. Result := MHD_YES;
  15. end;
  16. function AnswerToConnection(ACls: Pointer; AConnection: PMHD_Connection;
  17. AUrl: Pcchar; AMethod: Pcchar; AVersion: Pcchar; AUploadData: Pcchar;
  18. AUploadDataSize: Psize_t; AConCls: PPointer): cint; cdecl;
  19. begin
  20. WriteLn(Format('New %s request for %s using version %s',
  21. [AMethod, AUrl, AVersion]));
  22. MHD_get_connection_values(AConnection, MHD_HEADER_KIND, @PrintOutKey, nil);
  23. Result := MHD_NO;
  24. end;
  25. var
  26. VDaemon: PMHD_Daemon;
  27. begin
  28. VDaemon := MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, PORT, nil, nil,
  29. @AnswerToConnection, nil, MHD_OPTION_END);
  30. if not Assigned(VDaemon) then
  31. Halt(1);
  32. ReadLn;
  33. MHD_stop_daemon(VDaemon)
  34. end.