aboutsummaryrefslogtreecommitdiff
path: root/player/talking.f90
blob: 42b6451b4ec19fdf8a47606aece748cf26bbd637 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
! Copyright (c) 2021 Approximatrix, LLC <support@approximatrix.com>
!
! Permission is hereby granted, free of charge, to any person obtaining a copy
! of this software and associated documentation files (the "Software"), to deal
! in the Software without restriction, including without limitation the rights
! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
! copies of the Software, and to permit persons to whom the Software is
! furnished to do so, subject to the following conditions:
!
! The above copyright notice and this permission notice shall be included in
! all copies or substantial portions of the Software.
!
! The Software shall be used for Good, not Evil.
!
! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
! SOFTWARE.

module talking
implicit none

contains

    function request_to_file(url, filename) result(status_code)
    use utilities
    use gemini_protocol
    implicit none
    
        character(*), intent(in)::url
        character(*), intent(in)::filename
        
        character(64)::return_type
        
        integer::unit_number
        integer::status_code
        integer::istatus
        
        character(len=:), allocatable::mod_url
        
        allocate(character(len=len_trim(url)) :: mod_url)
        mod_url = url
        
        open(newunit=unit_number, file=filename, status='UNKNOWN', &
             access='STREAM', iostat=istatus) !  form='FORMATTED', 
        
        if(istatus == 0) then
            status_code = request_url(mod_url, unit_number, return_type)
        else
            status_code = STATUS_LOCALFAIL
            Print *, "Failed to open: "//trim(filename)
        end if

        close(unit_number)
        
        deallocate(mod_url)
        
    end function request_to_file

    function request_to_temporary_file(url, filename) result(status_code)
    use utilities, only: generate_temporary_filename
    use gemini_protocol, only: STATUS_LOCALFAIL
    implicit none
    
        character(*), intent(in)::url
        character(:), pointer::filename
        integer::status_code
        
        filename => generate_temporary_filename()
        if(.not. associated(filename)) then
            status_code = STATUS_LOCALFAIL
        else
            status_code = request_to_file(url, filename)
        end if
        
    end function request_to_temporary_file
    
    function request_to_ignored(url) result(status_code)
    use gemini_protocol
    implicit none
        
        character(*), intent(in)::url
        integer::status_code
        integer::io
        character(64)::return_type
        
        character(len=:), allocatable::mod_url
        
        allocate(character(len=len_trim(url)) :: mod_url)
        mod_url = url
        
        open(newunit=io, status="scratch", access='stream')
        status_code = request_url(mod_url, io, return_type)
        close(io)
        
        deallocate(mod_url)
        
    end function request_to_ignored
    
    function send_file(url, filename) result(status_code)
    use gemini_protocol
    use config, only: token
    implicit none
        
        character(*), intent(in)::url
        character(*), intent(in)::filename
        integer::status_code
        integer::io
        
        character(64)::return_type
        character(len=:), allocatable::mod_url
        
        integer(kind=8)::file_size
        integer::unit_number, istatus
        
        allocate(character(len=len_trim(url)) :: mod_url)
        mod_url = url
        
        inquire(file=filename, size=file_size)
        
        open(newunit=unit_number, file=trim(filename), status='OLD', &
             access='STREAM', form='UNFORMATTED', iostat=istatus)
        
        if(istatus == 0) then
            status_code = titan_post_url(mod_url, unit_number, file_size, token)
            close(unit_number)
        else
            status_code = STATUS_LOCALFAIL
        end if
        
        deallocate(mod_url)
        
    end function send_file
    
end module talking