aboutsummaryrefslogtreecommitdiff
path: root/player/talking.f90
blob: 9c9db05b41aea74fded5d4a5b2019d89b07b352f (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
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', form='UNFORMATTED', iostat=istatus)
        
        if(istatus == 0) then
            status_code = request_url(mod_url, unit_number, return_type)
        else
            status_code = STATUS_LOCALFAIL
        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, form="formatted", 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='UNKNOWN', &
             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