2 uploader -- simplest form file uploader
3 Copyright (C) 2018-2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 type UCSPIAddr struct {
32 func (addr *UCSPIAddr) Network() string { return "tcp" }
34 func (addr *UCSPIAddr) String() string { return addr.ip + ":" + addr.port }
36 type UCSPIConn struct{}
38 func (conn *UCSPIConn) Read(b []byte) (int, error) { return os.Stdin.Read(b) }
40 func (conn *UCSPIConn) Write(b []byte) (int, error) { return os.Stdout.Write(b) }
42 func (conn *UCSPIConn) Close() error {
43 if err := os.Stdin.Close(); err != nil {
46 return os.Stdin.Close()
49 func (conn *UCSPIConn) LocalAddr() net.Addr {
50 return &UCSPIAddr{ip: os.Getenv("TCPLOCALIP"), port: os.Getenv("TCPLOCALPORT")}
53 func (conn *UCSPIConn) RemoteAddr() net.Addr {
54 return &UCSPIAddr{ip: os.Getenv("TCPREMOTEIP"), port: os.Getenv("TCPREMOTEPORT")}
57 func (conn *UCSPIConn) SetDeadline(t time.Time) error {
58 if err := os.Stdin.SetReadDeadline(t); err != nil {
61 return os.Stdout.SetWriteDeadline(t)
64 func (conn *UCSPIConn) SetReadDeadline(t time.Time) error {
65 return os.Stdin.SetReadDeadline(t)
68 func (conn *UCSPIConn) SetWriteDeadline(t time.Time) error {
69 return os.Stdout.SetWriteDeadline(t)
72 type UCSPI struct{ accepted bool }
74 type UCSPIAlreadyAccepted struct{}
76 func (u UCSPIAlreadyAccepted) Error() string {
77 return "already accepted"
80 func (ucspi *UCSPI) Accept() (net.Conn, error) {
82 return nil, UCSPIAlreadyAccepted{}
85 return &UCSPIConn{}, nil
88 func (ucspi *UCSPI) Close() error {
92 func (ucspi *UCSPI) Addr() net.Addr {
93 return &UCSPIAddr{ip: os.Getenv("TCPLOCALIP"), port: os.Getenv("TCPLOCALPORT")}
96 func connStater(conn net.Conn, connState http.ConnState) {
100 case http.StateClosed: