1 /* 2 * binkleyforce -- unix FTN mailer project 3 * 4 * Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * $Id: session.h,v 1.1.1.1 2004/09/09 09:52:40 kstepanenkov Exp $ 12 */ 13 14 #ifndef _S_MAIN_H_ 15 #define _S_MAIN_H_ 16 17 #define CALLOPT_FORCE 0x01 18 #define CALLOPT_INET 0x02 19 20 #include "io.h" 21 #include "nodelist.h" 22 #include "outbound.h" 23 #include "prot_common.h" 24 25 typedef enum session { 26 SESSION_UNKNOWN, 27 SESSION_FTSC, 28 SESSION_YOOHOO, 29 SESSION_EMSI, 30 SESSION_BINKP 31 } e_session; 32 33 typedef enum protocol { 34 PROT_NOPROT, 35 PROT_XMODEM, 36 PROT_ZMODEM, 37 PROT_ZEDZAP, 38 PROT_DIRZAP, 39 PROT_JANUS, 40 PROT_HYDRA, 41 PROT_TCP, 42 PROT_BINKP 43 } e_protocol; 44 45 typedef enum reqstat { 46 REQS_DISABLED, /* Freqs not supported by the system */ 47 REQS_ALLOW, /* We will process file requests */ 48 REQS_NOTALLOW /* Freqs TEMPORARY disabled for any reason */ 49 } e_reqstat; 50 51 #define HRC_OK 0 /* No errors */ 52 #define HRC_LOW_SPEED 1 /* Connect speed too low (shown it in EMSI) */ 53 #define HRC_BAD_PASSWD 2 /* Pasword failure (shown it in EMSI) */ 54 #define HRC_NO_ADDRESS 3 /* Expected address was not presented */ 55 #define HRC_NO_PROTOS 4 /* No common protocols :( */ 56 #define HRC_BUSY 5 /* All remote AKAs are busy */ 57 #define HRC_FATAL_ERR 6 /* Any other fatal handshake error */ 58 #define HRC_TEMP_ERR 7 /* Any other temporary handshake error */ 59 #define HRC_OTHER_ERR 8 /* Any other error (e.g. timeout, NO CARRIER) */ 60 61 typedef struct sysaddr { 62 s_faddr addr; 63 bool busy; 64 bool good; 65 int flags; 66 } s_sysaddr; 67 68 typedef struct { 69 char passwd[128]; 70 char challenge[128]; 71 int challenge_length; 72 bool cram_auth; 73 } s_session_passwd; 74 75 typedef struct sendopts { 76 int fnc:1, /* Convert outgoing file names to 8+3 format */ 77 holdreq:1, /* Hold .REQ files? (file requests) */ 78 holdhold:1, /* Hold files with HOLD flavor? */ 79 holdfiles:1, /* Hold all files except netmail + arcmail */ 80 holdxt:1, /* Hold all except netmail? */ 81 holdall:1, /* Hold ALL trafic!? */ 82 hydraRH1; /* Hydra RH1 mode (EMSI only) */ 83 } s_sendopts; 84 85 /* 86 * Handhake protocols API 87 */ 88 typedef struct handshake_protocol 89 { 90 /* 91 * 1. Main pointers 92 */ 93 char *verbal_name; 94 char *author; 95 char *standard; 96 char *remote_data; 97 char *local_data; 98 e_protocol protocol; 99 100 void (*init)(struct handshake_protocol *THIS); 101 void (*deinit)(struct handshake_protocol *THIS); 102 int (*incoming_session)(struct handshake_protocol *THIS); 103 int (*outgoing_session)(struct handshake_protocol *THIS); 104 105 /* 106 * 2. Remote system information extract methods 107 */ 108 s_faddr* (*remote_address)(struct handshake_protocol *THIS); 109 char* (*remote_password)(struct handshake_protocol *THIS); 110 char* (*remote_sysop_name)(struct handshake_protocol *THIS); 111 char* (*remote_system_name)(struct handshake_protocol *THIS); 112 char* (*remote_location)(struct handshake_protocol *THIS); 113 char* (*remote_phone)(struct handshake_protocol *THIS); 114 char* (*remote_flags)(struct handshake_protocol *THIS); 115 char* (*remote_mailer)(struct handshake_protocol *THIS); 116 int (*remote_traffic)(struct handshake_protocol *THIS, s_traffic *dest); 117 118 /* 119 * 3. Local system information extract methods 120 */ 121 s_faddr* (*local_address)(struct handshake_protocol *THIS); 122 char* (*local_password)(struct handshake_protocol *THIS); 123 } s_handshake_protocol; 124 125 struct state 126 { 127 s_node node; 128 const s_modemport *modemport; 129 char *linename; /* Verbal line name (i.e. ttyS1, tcpip, etc.) */ 130 time_t start_time; /* Session start time (e.g. connect time) */ 131 e_tcpmode tcpmode; /* Current mode to work via TCP/IP */ 132 e_session session; /* handshake type (EMSI, YooHoo, etc.) */ 133 bool valid; /* This structure contain real information */ 134 bool caller; /* Outgoing session */ 135 bool protected; /* Password protected session? */ 136 bool listed; /* Session with listed system? */ 137 bool inet; /* We are working via TCP/IP now */ 138 int session_rc; /* Session return code */ 139 s_sendopts sopts; /* Our send options (hold arcmail, etc.) */ 140 e_reqstat reqstat; /* Our file request processor status */ 141 s_override override; 142 s_sess_stat sess_stat; /* Try counters, hold timers, etc. */ 143 long connspeed; 144 long minspeed; 145 char *cidstr; /* Caller Phone/ID when we are answering */ 146 char *peername; /* Remote peer name than using TCP/IP */ 147 long peerport; /* Remote port number, we are connected to */ 148 char *connstr; 149 char *inbound; /* Inbound directory for this session */ 150 char *tinbound; /* Temporary inbound for this session */ 151 s_traffic traff_send; /* Expected outgoing traffic */ 152 s_traffic traff_recv; /* Expected incoming traffic */ 153 154 s_handshake_protocol *handshake; 155 156 s_falist *mailfor; /* Remote valid addresses */ 157 s_fsqueue queue; /* Send files queue */ 158 }; 159 typedef struct state s_state; 160 161 /* s_common.c */ 162 int session_get_local_address(s_faddr *addr); 163 int session_get_remote_address(s_faddr *addr); 164 int session_get_remote_sysop(char **dest); 165 int session_get_remote_systname(char **const dest); 166 int session_get_remote_mailer(char **const dest); 167 int session_get_remote_phone(char **const dest); 168 int session_get_remote_location(char **const dest); 169 int session_is_remote_protected(void); 170 int session_is_remote_listed(void); 171 int session_get_callerid(char **const dest); 172 int session_get_connect(char **const dest); 173 int session_run_command(const char *execstr); 174 int override_get(s_override *dest, s_faddr addr, int line); 175 void init_state(s_state *pstate); 176 void deinit_state(s_state *pstate); 177 178 /* s_init.c */ 179 int session_init_outgoing(void); 180 int session_init_incoming(void); 181 182 /* s_main.c */ 183 extern s_state state; 184 185 s_faddr *session_get_bestaka(s_faddr addr); 186 int session_addrs_lock(s_sysaddr *addrs, int anum); 187 int session_addrs_add(s_sysaddr **addrs, int *anum, s_faddr addr); 188 int session_addrs_check(s_sysaddr *addrs, int anum, const char *passwd, 189 const char *challenge, int challenge_length); 190 int session_addrs_to_falist(s_sysaddr *addrs, int anum, s_falist **dest); 191 int session_addrs_check_genuine(s_sysaddr *addrs, int anum, s_faddr expected); 192 int session_check_speed(void); 193 int session_check_addr(s_faddr addr); 194 int session_get_password(s_faddr addr, char *buffer, size_t buflen); 195 int session_remote_lookup(s_sysaddr *addrs, int anum); 196 void session_remote_log_status(void); 197 int session_check_password(s_faddr addr, const char *passwd); 198 int session_set_inbound(void); 199 void session_set_freqs_status(void); 200 void session_set_send_options(void); 201 void session_set_send_files(void); 202 int session_create_files_queue(s_sysaddr *addrs, int anum); 203 int session_traffic_set_incoming(s_traffic *dest); 204 int session_traffic_set_outgoing(s_traffic *dest); 205 void session_traffic(void); 206 void session_update_history(s_traffic *send, s_traffic *recv, int rc); 207 int session(void); 208 209 /* sess_call.c */ 210 int call_system(s_faddr addr, const s_bforce_opts *opts); 211 int call_system_modem(void); 212 int call_system_tcpip(void); 213 214 /* sess_answ.c */ 215 int answ_system(e_session type, char *connstr, int inetd); 216 217 /* sess_stat.c */ 218 void session_stat_reset_counters(s_sess_stat *stat); 219 int session_stat_get(s_sess_stat *stat, s_faddr *addr); 220 int session_stat_apply_diff(s_faddr addr, s_sess_stat stat); 221 int session_stat_update(s_faddr *addr, s_sess_stat *stat, bool caller, int rc); 222 223 #endif 224