Debian Codegraph @

exp/prj/amd/src/app/exp-amd-htmmc.als

raw
1 # ----------------------------------------------------------------------------
2 # - exp-amd-htmmc -
3 # - afnix:amd http media controller module -
4 # ----------------------------------------------------------------------------
5 # - This program is free software; you can redistribute it and/or modify -
6 # - it provided that this copyright notice is kept intact. -
7 # - -
8 # - This program is distributed in the hope that it will be useful, but -
9 # - without any warranty; without even the implied warranty of -
10 # - merchantability or fitness for a particular purpose. In not event shall -
11 # - the copyright holder be liable for any direct, indirect, incidental or -
12 # - special damages arising in any way out of the use of this software. -
13 # ----------------------------------------------------------------------------
14 # - copyright (c) 1999-2023 amaury darsch -
15 # ----------------------------------------------------------------------------
16
17 # ----------------------------------------------------------------------------
18 # - public section -
19 # ----------------------------------------------------------------------------
20
21 # the media controller clas
22 const afnix:amd:htmmc (class)
23 # the media nameset
24 const AFNIX:AMD:HTMMC (nameset AFNIX:AMD)
25
26 # ----------------------------------------------------------------------------
27 # - private section -
28 # ----------------------------------------------------------------------------
29
30 # the media controler type name
31 const AFNIX:AMD:HTMMC:HTTP-TYPE-NAME "http"
32 # the user agent header
33 const AFNIX:AMD:HTMMC:HTTP-USER-NAME "User-Agent"
34 const AFNIX:AMD:HTMMC:HTTP-USER-HEAD AFNIX:AMD:TITLE
35
36 # ----------------------------------------------------------------------------
37 # - initial section -
38 # ----------------------------------------------------------------------------
39
40 # preset the controller environment
41 # @param uri the uri to process
42
43 trans afnix:amd:htmmc:preset (uri) {
44 # make sure we have the right scheme
45 assert AFNIX:AMD:HTMMC:HTTP-TYPE-NAME (uri:get-scheme)
46 # save the uri
47 const this:super uri
48 }
49
50 # ----------------------------------------------------------------------------
51 # - main section -
52 # ----------------------------------------------------------------------------
53
54 # execute the media dump by creating a http request to the authority
55
56 trans afnix:amd:htmmc:dump nil {
57 # create a http request
58 const hrq (afnix:nwg:HttpRequest this:super)
59 # set the request header
60 hrq:header-set AFNIX:AMD:HTMMC:HTTP-USER-NAME AFNIX:AMD:HTMMC:HTTP-USER-HEAD
61 # get the socket host and port
62 const host (this:get-host)
63 const port (this:get-port)
64 # open a tcp socket
65 const s (afnix:net:TcpClient host port)
66 # write the request
67 hrq:write s
68 # create a http response
69 const hrs (afnix:nwg:HttpResponse)
70 # parse the response
71 hrs:parse s
72 # check the response and dump
73 if (hrs:status-ok-p) {
74 # create a http stream
75 const is (afnix:nwg:HttpStream hrs s)
76 # create an output file
77 const os (afnix:sio:OutputFile (afnix:amd:get-output-name uri))
78 # read the response
79 while (is:valid-p) (os:write (is:read))
80 # close the streams
81 os:close
82 }
83 }