-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodembank.h
141 lines (110 loc) · 3.59 KB
/
modembank.h
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
139
140
141
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <time.h>
#include <poll.h>
#include <signal.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <string.h>
#define _POSIX_SOURCE 1
// Modem constatns
#define INIT_ATTEMPTS 5
#define INIT_DURATION 1
// Network constants
#define HOST_PORT 5001
#define CONN_TIMEOUT 5
// Modem & Network constatns
#define MASTER_TIMEOUT 5
#define BUFFER_LEN 256
#define CONNNAME_LEN 20
// User constatns
#define TERMTYPE_LEN 20
#define USERNAME_LEN 20
#define COMMAND_LEN 100
#define PROMPT_LEN 10
// Linked-list flag constants
#define FLAG_GARB (1 << 0) // Garbage node
// User flag constants
#define FLAG_DEVL (1 << 1) // User is developer (oper + dev = admin)
#define FLAG_OPER (1 << 2) // User is sysop
#define FLAG_BRDG (1 << 3) // User is in bridge mode (stdin in and stdout are inter-connected)
// Conn flag constants
#define FLAG_MODM (1 << 1) // Conn is a modem (else: socket)
#define FLAG_OUTG (1 << 2) // Conn is outgoing
#define FLAG_CALL (1 << 3) // Conn is currently connected
// ModemBank operation list
enum operations { req_idle, req_opensock, };
typedef struct conn
{
// Status flags
int flags;
// Networking
int fd; // Stores the client socket fd
char buf[BUFFER_LEN + 1]; // Stores incoming data from the socket
int buflen; // Stores number of bytes in buf
time_t first; // Unix time of first connect
time_t last; // Unix time of last data
char name[CONNNAME_LEN + 1]; // A printable identifier for the conn
// Origin of the conn
union {
char path[15]; // Path to the modem
struct sockaddr_in addr; // IP & Port of the socket
} org;
// Linked list
struct conn * next; // Next conn in the linked list
} conn;
typedef struct user
{
// Status flags
int flags;
struct conn * stdin; // Input conn
struct conn * stdout; // Output conn
time_t first; // Unix time of initial connect
time_t last; // Unix time of last char recived
// Account
char name[USERNAME_LEN + 1]; // Username of the client
// Command Line
char cmdbuf[COMMAND_LEN + 1]; // Stores the current command line
char cmdppt[PROMPT_LEN + 1]; // Store the prompt string to print
int cmdsec; // Boolean, does not echo characters typed if true
int cmdwnt; // Number of bytes wanted, should not excede COMMAND_LEN, a value of 0 indicates that cmdbuf holds a valid string
int cmdlen; // Length of current command
int cmdpos; // Position of the cursor
// Terminal attributes
int width;
int height;
char termtype[TERMTYPE_LEN + 1]; // Terminal type
// Operation to be preformed by ModemBank
enum operations opcmd;
// Data associated with the operation, will be freed on completion
void * opdat;
// Linked list
struct user * next; // Next user in the linked list
} user;
typedef struct data
{
struct conn * headconn;
int conn_count;
struct user * headuser;
int user_count;
} data;
void xlog(user * muser, const char * format, ...);
void vxlog(user * muser, const char * format, va_list args);
void ylog(conn * mconn, const char * format, ...);
void vylog(conn * mconn, const char * format, va_list args);
void zlog(const char * format, ...);
void vzlog(const char * format, va_list args);
int createSession(user ** headuser, conn * newconn);
int uprintf(user * muser, const char * format, ...);
void sigHandler(int sig);
#include "connections.h"
#include "shell.h"
#include "commands.h"