AmendHub

Download

jcs

/

subtext

/

session.h

 

(View History)

jcs   *: Minor cleanups, remove dead variables, fix some error paths Latest amendment: 580 on 2024-01-24

1 /*
2 * Copyright (c) 2021 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 /* forward declarations */
18 struct session;
19 struct session_menu_option;
20
21 #ifndef __SESSION_H__
22 #define __SESSION_H__
23
24 #include <stdlib.h>
25
26 #include "db.h"
27 #include "uthread.h"
28 #include "user.h"
29
30 enum session_input_state {
31 SESSION_INPUT_NONE,
32 SESSION_INPUT_LINE,
33 SESSION_INPUT_CHAR
34 };
35
36 /* must keep sessions area_labels[] in sync */
37 enum session_area {
38 SESSION_AREA_MAIN_MENU,
39 SESSION_AREA_MOTD,
40 SESSION_AREA_BOARDS,
41 SESSION_AREA_FTN,
42 SESSION_AREA_CHAT,
43 SESSION_AREA_MAIL,
44 SESSION_AREA_FILES,
45 SESSION_AREA_WHO,
46 SESSION_AREA_RECENT_LOGINS,
47 SESSION_AREA_SETTINGS,
48 SESSION_AREA_SIGNUP
49 };
50
51 #define DEFAULT_TERMINAL_COLUMNS 80
52 #define DEFAULT_TERMINAL_LINES 24
53 #define MIN_TERMINAL_COLUMNS 20
54 #define MIN_TERMINAL_LINES 4
55
56 #define CONTROL_C 3
57 #define CONTROL_D 4
58 #define BACKSPACE 8
59 #define CONTROL_L 12
60 #define DELETE 127
61
62 #define KEY_UP (0x0100 | 'A')
63 #define KEY_DOWN (0x0100 | 'B')
64 #define KEY_RIGHT (0x0100 | 'C')
65 #define KEY_LEFT (0x0100 | 'D')
66 #define KEY_OTHER (0x0100 | 0xff)
67
68 typedef struct session session;
69
70 struct node_funcs {
71 void (*setup)(struct session *session);
72 short (*input)(struct session *session);
73 short (*output)(struct session *session);
74 void (*close)(struct session *session);
75 };
76
77 struct session_log {
78 unsigned long id;
79 char username[DB_USERNAME_LENGTH + 1];
80 char node[10];
81 char via[10];
82 unsigned long logged_on_at;
83 unsigned long logged_off_at;
84 unsigned long ip_address;
85 unsigned short tspeed;
86 char location[32];
87 };
88
89 struct session {
90 char node[16];
91 char via[16];
92 char location[32];
93 unsigned char obuf[768];
94 unsigned long obuf_canary;
95 unsigned char ibuf[512];
96 unsigned long ibuf_canary;
97 short obuflen;
98 unsigned long obuflen_canary;
99 short ibuflen;
100 unsigned long ibuflen_canary;
101 short ibufoff;
102 unsigned long established_at;
103 char autologin_username[DB_USERNAME_LENGTH + 1];
104 char terminal_type[24];
105 enum session_input_state input_state;
106 unsigned short last_input;
107 unsigned long last_input_at;
108 unsigned short terminal_columns;
109 unsigned short terminal_lines;
110 unsigned short tspeed;
111 bool logged_in;
112 bool ending;
113 bool abort_input;
114 bool ban_node_source;
115 bool vt100;
116 bool vt52;
117 bool color;
118 bool direct_output;
119 bool is_telnet;
120 bool can_nomodem;
121 char chatting_with_node[16];
122 char chat_username[DB_USERNAME_LENGTH + 1];
123 bool chatting;
124 short area;
125 struct session_log log;
126 struct user *user;
127 void *cookie;
128 struct node_funcs *node_funcs;
129 struct uthread *uthread;
130 };
131
132 #define MAX_SESSIONS NUM_UTHREADS
133 extern struct session *sessions[MAX_SESSIONS];
134 extern short nsessions;
135
136 struct session_tally {
137 char date[9];
138 unsigned long calls;
139 };
140 extern struct session_tally session_today_tally;
141
142 struct session_menu_option {
143 char ret;
144 char key[15];
145 char title[50];
146 };
147
148 struct session * session_create(char *node, char *via,
149 struct node_funcs *node_funcs);
150 void session_close(struct session *session);
151 void session_idle(struct session *session);
152 short session_get_char(struct session *session, unsigned char *b);
153 short session_get_chars(struct session *session, unsigned char *b,
154 size_t count);
155 bool session_wait_for_chars(struct session *session,
156 unsigned short timeout_ms, unsigned short num_chars);
157 unsigned short session_input_char(struct session *session);
158 void session_clear_input(struct session *session);
159 void session_flush(struct session *session);
160 size_t session_logf(struct session *session, const char *format, ...);
161 size_t session_logf_buffered(struct session *session, const char *format, ...);
162 size_t session_output(struct session *session, const char *str, size_t len);
163 size_t session_paginate(struct session *session, const char *str,
164 size_t len, size_t first_page_printed);
165 size_t session_printf(struct session *session, const char *format, ...);
166 size_t session_output_view_or_printf(struct session *session, short id,
167 const char *format, ...);
168 size_t session_output_template(struct session *session, const char *str);
169 size_t session_expand_template(struct session *session, const char *str,
170 char **ret);
171 char * session_field_input(struct session *session, unsigned short size,
172 unsigned short width, char *initial_input, bool multiline, char mask);
173 void session_pause_return(struct session *s, char enforce, char *msg);
174 void session_print_motd(struct session *s, bool force);
175 void session_recents(struct session *s);
176 void session_who(struct session *s);
177 char session_menu(struct session *s, char *title, char *prompt,
178 char *prompt_help, const struct session_menu_option *opts, size_t nopts,
179 bool show_opts, char *number_prompt, short *ret_number);
180 void session_prune_logs(short days);
181 void session_check_buf_canaries(struct session *session);
182
183 #endif /* __SESSION_H__ */