Download
jcs
/subtext
/binkp.h
(View History)
jcs *: Minor cleanups, remove dead variables, fix some error paths | Latest amendment: 580 on 2024-01-24 |
1 | /* |
2 | * Copyright (c) 2023 joshua stein <jcs@jcs.org> |
3 | * |
4 | * Permission to use, copy, modify, and distribute this software for any |
5 | * purpose with or without fee is hereby granted, provided that the above |
6 | * copyright notice and this permission notice appear in all copies. |
7 | * |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ |
16 | |
17 | #ifndef __BINKP_H__ |
18 | #define __BINKP_H__ |
19 | |
20 | #include "fidopkt.h" |
21 | #include "tcp.h" |
22 | #include "uthread.h" |
23 | #include "util.h" |
24 | |
25 | struct binkp_frame { |
26 | u_int16_t data_size; |
27 | char command_id; |
28 | #define BINKP_DATA -1 |
29 | #define BINKP_COMMAND_M_NUL 0 |
30 | #define BINKP_COMMAND_M_ADR 1 |
31 | #define BINKP_COMMAND_M_PWD 2 |
32 | #define BINKP_COMMAND_M_FILE 3 |
33 | #define BINKP_COMMAND_M_OK 4 |
34 | #define BINKP_COMMAND_M_EOB 5 |
35 | #define BINKP_COMMAND_M_GOT 6 |
36 | #define BINKP_COMMAND_M_ERR 7 |
37 | #define BINKP_COMMAND_M_BSY 8 |
38 | #define BINKP_COMMAND_M_GET 9 |
39 | #define BINKP_COMMAND_M_SKIP 10 |
40 | |
41 | char type; |
42 | #define BINKP_TYPE_DATA 0x0 |
43 | #define BINKP_TYPE_COMMAND 0x1 |
44 | }; |
45 | |
46 | struct binkp_file { |
47 | char filename[64]; |
48 | size_t size; |
49 | unsigned long mtime; |
50 | size_t data_read; |
51 | Str255 pfilename; |
52 | short frefnum; |
53 | }; |
54 | |
55 | struct binkp_connection { |
56 | TCPiopb tcp_send_iopb; |
57 | TCPiopb tcp_read_iopb; |
58 | StreamPtr tcp_stream; |
59 | unsigned char *tcp_buf; |
60 | size_t tcp_buf_size; |
61 | wdsEntry tcp_wds[2]; |
62 | TCPStatusPB tcp_status_pb; |
63 | |
64 | char *buf; |
65 | size_t buf_size; |
66 | struct binkp_frame cur_frame; |
67 | struct binkp_file cur_incoming_file; |
68 | time_t last_frame_at; |
69 | bool done_receiving; |
70 | bool done_sending; |
71 | bool error; |
72 | }; |
73 | |
74 | extern bool binkp_ready; |
75 | extern time_t binkp_next_poll; |
76 | extern bool binkp_last_poll_error; |
77 | |
78 | void binkp_init(void); |
79 | bool binkp_reinit(void); |
80 | void binkp_atexit(void); |
81 | void binkp_poll(void); |
82 | bool binkp_scan_message(struct fidopkt_message *msg); |
83 | bool binkp_packets_in_outbox(void); |
84 | |
85 | #endif |