File: logging.pp

package info (click to toggle)
fpc 3.2.2%2Bdfsg-46
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 341,452 kB
  • sloc: pascal: 3,820,194; xml: 194,356; ansic: 9,637; asm: 8,482; java: 5,346; sh: 4,813; yacc: 3,956; makefile: 2,705; lex: 2,661; javascript: 2,454; sql: 929; php: 474; cpp: 145; perl: 136; sed: 132; csh: 34; tcl: 7
file content (43 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(* Feel free to use this example code in any way
   you see fit (Public Domain) *)

// Original example: https://gnunet.org/svn/libmicrohttpd/doc/examples/logging.c

program logging;

{$mode objfpc}{$H+}

uses
  libmicrohttpd, sysutils;

const
  PORT = 8888;

  function PrintOutKey(ACls: Pointer; AKind: MHD_ValueKind; AKey: Pcchar;
    AValue: Pcchar): cint; cdecl;
  begin
    WriteLn(Format('%s: %s', [AKey, AValue]));
    Result := MHD_YES;
  end;

  function AnswerToConnection(ACls: Pointer; AConnection: PMHD_Connection;
    AUrl: Pcchar; AMethod: Pcchar; AVersion: Pcchar; AUploadData: Pcchar;
    AUploadDataSize: Psize_t; AConCls: PPointer): cint; cdecl;
  begin
    WriteLn(Format('New %s request for %s using version %s',
      [AMethod, AUrl, AVersion]));
    MHD_get_connection_values(AConnection, MHD_HEADER_KIND, @PrintOutKey, nil);
    Result := MHD_NO;
  end;

var
  VDaemon: PMHD_Daemon;
begin
  VDaemon := MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, PORT, nil, nil,
    @AnswerToConnection, nil, MHD_OPTION_END);
  if not Assigned(VDaemon) then
    Halt(1);
  ReadLn;
  MHD_stop_daemon(VDaemon)
end.