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: outbound.h,v 1.1.1.1 2004/09/09 09:52:40 kstepanenkov Exp $
12  */
13 
14 #ifndef _OUTBOUND_H_
15 #define _OUTBOUND_H_
16 
17 #include "nodelist.h"
18 
19 #define FLAVOR_NONE		0x000
20 #define FLAVOR_HOLD		0x001
21 #define FLAVOR_NORMAL		0x002
22 #define FLAVOR_DIRECT		0x004
23 #define FLAVOR_IMMED		0x008
24 #define FLAVOR_CRASH		0x010
25 
26 #define ACTION_NOTHING		0x000	/* Do nothing with file after ses.   */
27 #define ACTION_UNLINK		0x001	/* Unlink file if send successful    */
28 #define ACTION_TRUNCATE		0x002	/* Truncate file if send successful  */
29 #define ACTION_FORCEUNLINK	0x004	/* Unlink file in any case after ses.*/
30 
31 #define TYPE_UNKNOWN		0x000
32 #define TYPE_NETMAIL		0x001
33 #define TYPE_ARCMAIL		0x002
34 #define TYPE_TICFILE		0x004
35 #define TYPE_FILEECHO		0x008
36 #define TYPE_FILEBOX		0x010
37 #define TYPE_FROMFLO		0x020
38 #define TYPE_REQUEST		0x040
39 #define TYPE_REQANSW		0x080	/* Our answer on incoming file req.  */
40 #define TYPE_FLOFILE		0x100
41 #define TYPE_ASONAME		0x200	/* File with AmigaDOS Style Outbound */
42                     		     	/* name (e.g. 2.5020.1398.11.out)    */
43 
44 #define STATUS_WILLSEND		0
45 #define STATUS_SKIP		1
46 #define STATUS_SENDING		2
47 #define STATUS_SENT		3
48 
49 #define QUEUE_SORT_ADDRESS	0x01
50 #define QUEUE_SORT_SIZE	0x02
51 #define QUEUE_SORT_REVERSE	0x04
52 
53 typedef struct {
54 	FILE *fp;
55 	char  att_path[BFORCE_MAX_PATH+1];
56 	int   att_action;
57 	int   att_offs; /* offset of the curent line */
58 } s_FLO;
59 
60 enum { OUTB_TYPE_BSO,
61 	   OUTB_TYPE_DOMAIN,
62        OUTB_TYPE_ASO,
63        OUTB_TYPE_FBOX };
64 
65 typedef struct outbound_callback_data {
66 	int (*callback)(struct outbound_callback_data *);
67 	void *dest;
68 	s_faddr addr;
69 	char *path;
70 	int flavor; /* Force this flavor for file */
71 	unsigned short type;
72 } s_outbound_callback_data;
73 
74 typedef struct filelist {
75 	struct filelist *next;
76 	char *fname;
77 	size_t size;
78 	unsigned short type;
79 	unsigned short status;
80 	unsigned short action;
81 	unsigned short flavor;
82 	short flodsc;
83 } s_filelist;
84 
85 typedef struct flofile {
86 	char *fname;
87 	short flavor;
88 	time_t mtime;
89 } s_flofile;
90 
91 typedef struct fsqueue {
92 	s_flofile  *flotab;
93 	s_filelist *fslist;
94 	int flonum;		/* Number of items in .?LO files table */
95 } s_fsqueue;
96 
97 #define TRIES_RESET -1 /* Use this macro to reset tries counter  */
98 #define HOLD_RESET   1 /* Use this macro to reset hold timer  */
99 
100 typedef struct sess_stat {
101 	bool undialable;
102 	int  tries;
103 	int  tries_noconn;
104 	int  tries_nodial;
105 	int  tries_noansw;
106 	int  tries_hshake;
107 	int  tries_sessns;
108 	unsigned long hold_until;
109 	unsigned long hold_freqs;
110 	unsigned long last_success;
111 	unsigned long last_success_in;
112 	unsigned long last_success_out;
113 } s_sess_stat;
114 
115 typedef struct sysentry {
116 	s_node node;
117 	bool lookedup;
118 const	s_override *overrides; /* List of all overrides */
119 const	s_override *lineptr;   /* List of all overrides */
120 	s_sess_stat stat;
121 	int  line;              /* Current line number */
122 	bool tcpip;             /* Call to the current line via TCP/IP? */
123 	bool busy;              /* Address is busy [in an another queue, etc.] */
124 	time_t lastcall;        /* Last call _finish_ time */
125 	time_t mailage;         /* The oldest file modification time */
126 	size_t netmail_size;
127 	size_t arcmail_size;
128 	size_t request_size;
129 	size_t files_size;
130 	int  flavors;
131 	int  types;
132 } s_sysentry;
133 
134 typedef struct sysqueue {
135 	s_sysentry *systab;
136 	int sysnum;
137 	time_t holduntil;
138 	int current_modem;
139 	int current_tcpip;
140 	int next_modem;
141 	int next_tcpip;
142 } s_sysqueue;
143 
144 typedef struct exttab {
145 const	char *ext;
146 	int type;
147 	int flavor;
148 	int action;
149 } s_exttab;
150 
151 extern s_exttab outtab[];
152 extern s_exttab exttab[];
153 extern int (*sysqueue_add_callback)(s_sysentry *);
154 extern int (*sysqueue_rem_callback)(s_sysentry *);
155 extern bool sysqueue_dont_count_sizes;
156 
157 /* outb_bsy.c */
158 int out_bsy_check(s_faddr addr);
159 #ifdef BFORCE_USE_CSY
160 int out_bsy_lock(s_faddr addr, bool csy_locks);
161 #else
162 int out_bsy_lock(s_faddr addr);
163 #endif
164 int out_bsy_unlock(s_faddr addr);
165 int out_bsy_unlockall(void);
166 
167 /* outb_flo.h */
168 s_FLO *flo_open(const char *path, const char *mode);
169 int    flo_next(s_FLO *FLO);
170 int    flo_mark_sent(s_FLO *FLO);
171 int    flo_eof(s_FLO *FLO);
172 int    flo_close(s_FLO *FLO);
173 bool   out_flo_isempty(const char *path);
174 int    out_flo_marksent(const char *fname, const char *floname);
175 int    out_flo_getsizes(const char *floname, size_t *arcmail, size_t *files);
176 int    out_flo_unlinkempty(const s_flofile *flotab, int flonum);
177 
178 /* outb_getname.c */
179 char *out_getname_4d(s_faddr addr);
180 char *out_getname_domain(s_faddr addr);
181 char *out_getname_amiga(s_faddr addr);
182 
183 /* outb_queue.c */
184 int out_filetype(const char *fname);
185 int out_handle_fsqueue(s_outbound_callback_data *callback);
186 void deinit_filelist(s_filelist *filelist);
187 void deinit_fsqueue(s_fsqueue *q);
188 #ifdef DEBUG
189 void log_filelist(const s_filelist *filelist);
190 void log_fsqueue(const s_fsqueue *q);
191 #endif
192 
193 /* outb_main.c */
194 int out_get_root(const char *outbound, char **out_root, char **out_main);
195 int out_parse_name_aso(s_faddr *addr, const char *name);
196 int out_scan(s_outbound_callback_data *callback, const s_falist *fa_list);
197 
198 /* outb_sysqueue.c */
199 void out_reset_trycounters(s_sysentry *syst);
200 void out_reset_sysqueue(s_sysqueue *q);
201 void out_sysqueue_sort(s_sysqueue *q, int opts);
202 void out_remove_from_sysqueue(s_sysqueue *q, int pos);
203 int out_handle_sysqueue(s_outbound_callback_data *callback);
204 void deinit_sysqueue(s_sysqueue *q);
205 #ifdef DEBUG
206 void log_sysqueue(const s_sysqueue *q);
207 #endif
208 
209 #endif
210