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: prot_common.h,v 1.1.1.1 2004/09/09 09:52:40 kstepanenkov Exp $
12  */
13 
14 #ifndef _P_COMMON_H_
15 #define _P_COMMON_H_
16 
17 #include "outbound.h"
18 
19 /* File transfer protocols return codes */
20 #define PRC_NOERROR         0       /* No comments :) */
21 #define PRC_ERROR           1       /* I/O error occured while snd./rcv. */
22 #define PRC_REMOTEABORTED   2       /* "ABORT" initiated by remote */
23 #define PRC_LOCALABORTED    3       /* We got SIGINT/SIGTERM? */
24 #define PRC_CPSTOOLOW       4       /* Cps was so low.. :( */
25 #define PRC_STOPTIME        5       /* Aborted due to the time limits */
26 
27 /* Send/Recv file status values */
28 #define FSTAT_PROCESS  1
29 #define FSTAT_WAITACK  2
30 #define FSTAT_SUCCESS  3
31 #define FSTAT_SKIPPED  4
32 #define FSTAT_REFUSED  5
33 
34 typedef struct traffic {
35 	int    netmail_num;    /* Number of netmail packets */
36 	int    netmail_time;   /* Netmail packets sending/receiving time */
37 	size_t netmail_size;   /* Size of netmail packtes */
38 	int    arcmail_num;    /* Dito.. */
39 	int    arcmail_time;
40 	size_t arcmail_size;
41 	int    files_num;
42 	int    files_time;
43 	size_t files_size;
44 	int    freqed_num;
45 	int    freqed_time;
46 	size_t freqed_size;
47 } s_traffic;
48 
49 /*
50  * Information on currently receiveing/transmitting file
51  */
52 typedef struct finfo {
53 	FILE  *fp;              /* File descriptor of current file */
54 	char  *local_name;      /* Local file name that is used at our side */
55 	char  *net_name;        /* File name as it known to the remote side */
56 	char  *fname;           /* Local file name with full path */
57 	time_t start_time;      /* Start of current file rx/tx transactions  */
58 	time_t mod_time;        /* File last modification time */
59 	mode_t mode;
60 	size_t bytes_total;     /* File size */
61 	size_t bytes_sent;
62 	size_t bytes_received;
63 	size_t bytes_skipped;   /* crash recovery */
64 	int    eofseen;         /* end of file seen */
65 	int    status;
66 	int    action;
67 	int    type;
68 	int    flodsc;          /* Index number in flo files table */
69 } s_finfo;
70 
71 /*
72  * Transfer protocol related structure
73  */
74 typedef struct protinfo {
75 	/* ----------------------------------------------------------------- */
76 	/* Variables defined before protocol starting                        */
77 	/* ----------------------------------------------------------------- */
78 	bool   reqs_only;       /* Send only .REQ files (for Hydra RH1 mode) */
79 	time_t stop_time;       /* Stop transfer at this time */
80 	int    freq_timelimit;  /* Abort transfer if send freqs longer this */
81 	int    min_tx_cps;      /* Minimal transmite speed */
82 	int    min_rx_cps;      /* Minimal receive speed */
83 	int    min_cps_time;    /* Abort transfer if minimal bps stay during
84 	                           this time period */
85 	char  *buffer;          /* Ptr. to buffer for buffered file saving */
86 	size_t buflen;          /* Buffer size */
87 	/* ----------------------------------------------------------------- */
88 	/* All variables below used by misc protocol routines                */
89 	/* ----------------------------------------------------------------- */
90 	s_filelist *filelist;   /* List of files.. It is our answer on .req! */
91 	int    tx_cps;          /* Current transmite CPS */
92 	int    rx_cps;          /* Current receive CPS */
93 	int    send_freqtime;   /* Time we spend at sending REQed files */
94 	time_t tx_low_cps_time; /* If CPS lower min_tx_cps it is time how
95 	                           long it lasts */
96 	time_t rx_low_cps_time; /* Same, but for transmite CPS */
97 	time_t start_time;      /* Time transfer started at */
98 
99 	s_traffic traffic_sent;
100 	s_traffic traffic_rcvd;
101 	size_t send_left_size;
102 	size_t recv_left_size;
103 	int    send_left_num;
104 	int    recv_left_num;
105 
106 	s_finfo *send;
107 	s_finfo *recv;
108 	s_finfo *sentfiles;
109 	s_finfo *rcvdfiles;
110 	int    n_sentfiles;
111 	int    n_rcvdfiles;
112 } s_protinfo;
113 
114 extern const char *Protocols[]; /* Protocol names */
115 
116 int   p_tx_fopen(s_protinfo *pi);
117 int   p_tx_fclose(s_protinfo *pi);
118 int   p_tx_readfile(char *buf, size_t sz, s_protinfo *pi);
119 int   p_rx_writefile(const char *buf, size_t sz, s_protinfo *pi);
120 int   p_compfinfo(s_finfo *finf, const char *fn, size_t sz, time_t tm);
121 int   p_rx_fopen(s_protinfo *pi, char *f_name, size_t f_size, time_t f_modtime, mode_t f_mode);
122 int   p_rx_fclose(s_protinfo *pi);
123 int   p_info(s_protinfo *pi, int bidir);
124 void  prot_update_traffic(s_protinfo *pi, const s_fsqueue *q);
125 void  p_log_txrxstat(const s_protinfo *pi);
126 void  p_session_cleanup(s_protinfo *pi, bool success);
127 void  p_shortname(char *name);
128 char *prot_unique_name(char *dirname, char *fname, int type);
129 void  p_checkname(char *name);
130 void  deinit_finfo(s_finfo *fi);
131 void  init_protinfo(s_protinfo *pi, bool caller);
132 void  deinit_protinfo(s_protinfo *pi);
133 char *p_convfilename(const char *origname, int type);
134 char *p_gettmpname(const char *inbound, char *fname, s_faddr addr, size_t sz, time_t tm);
135 
136 #endif
137