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: bforce.h,v 1.1.1.1 2004/09/09 09:52:40 kstepanenkov Exp $
12  */
13 
14 #ifndef _BFORCE_H_
15 #define _BFORCE_H_
16 
17 #ifndef DAEMON_LOGFILE
18 #define DAEMON_LOGFILE "/var/log/bforce/bf-daemon"
19 #endif
20 
21 #ifndef BFORCE_LOGFILE
22 #define BFORCE_LOGFILE "/var/log/bforce/bf-log"
23 #endif
24 
25 #ifndef BFORCE_DEBFILE
26 #define BFORCE_DEBFILE "/var/log/bforce/bf-debug"
27 #endif
28 
29 #ifndef BFORCE_CFGFILE
30 #define BFORCE_CFGFILE "/etc/bforce/bforce.conf"
31 #endif
32 
33 /*
34  * BinkleyForce limits
35  */
36 #define BF_MAXCFGLINE		512
37 #define BF_MAXREQLINE		256
38 #define BF_MAXPATH		256
39 #define BF_MAXDOMAIN		40
40 #define BF_MAXADDRSTR		80
41 
42 /*
43  * Maximum length of file name (without path)
44  */
45 #define BFORCE_MAX_NAME         128
46 
47 /*
48  * Maximum path length, including file name length
49  */
50 #define BFORCE_MAX_PATH         256
51 
52 /*
53  * Maximum length of address string
54  */
55 #define BFORCE_MAX_ADDRSTR      80
56 
57 /*
58  * Lock files type:
59  *   1 - Ascii lock files
60  *   2 - Binary lock files
61  *   3 - SVR4 lock files (not implemented)
62  */
63 #define BFORCE_LOCK_TYPE        1
64 
65 /*
66  * Maximum length of phone number string
67  */
68 #define BFORCE_MAX_PHONE        80
69 
70 /*
71  * Maximum length of modem command string. Most modems
72  * cannot handle strings longer 40 characters.
73  */
74 #define MODEM_MAX_COMMAND       120
75 
76 /*
77  * Maximum length of modem response string
78  */
79 #define MODEM_MAX_RESP          120
80 
81 /*
82  * Maximum number of characters that modem can response
83  * on something command. Responses larger this will be
84  * considered invalid, and mailer will return "modem not
85  * response" without further waiting for "OK" or "ERROR"
86  */
87 #define MODEM_MAX_RESP_SIZE     8128
88 
89 /*
90  *  BinkleyForce return codes
91  */
92 #define BFERR_NOERROR		0
93 #define BFERR_FATALERROR	1
94 #define BFERR_PHONE_UNKNOWN	2
95 #define BFERR_PORTBUSY		3
96 #define	BFERR_SYSTEM_LOCKED	4
97 #define	BFERR_TRY_LATER		5
98 #define	BFERR_NOMODEM		6
99 #define	BFERR_NOTWORKING	7
100 #define	BFERR_CANT_CONNECT10	10
101 #define	BFERR_CANT_CONNECT11	11
102 #define	BFERR_CANT_CONNECT12	12
103 #define	BFERR_CANT_CONNECT13	13
104 #define	BFERR_CANT_CONNECT14	14
105 #define	BFERR_CANT_CONNECT15	15
106 #define	BFERR_CANT_CONNECT16	16
107 #define	BFERR_CANT_CONNECT17	17
108 #define	BFERR_CANT_CONNECT18	18
109 #define	BFERR_CANT_CONNECT19	19
110 #define	BFERR_CONNECT_TOOLOW	20
111 #define	BFERR_HANDSHAKE_ERROR	21
112 #define	BFERR_XMITERROR		22
113 #define	BFERR_CPSTOOLOW		23
114 #define	BFERR_STOPTIME		24
115 
116 #define BFERR_MAXERRNO		24	/* Maximal error number */
117 
118 #define BFERR_NAME(rc)      ((rc >= 0) && (rc <= BFERR_MAXERRNO) ? BFERR[rc] : "Out of range")
119 
120 /*
121  *  Some most popular defines
122  */
123 #define gotoexit(a)	{ rc = a; goto exit; }
124 
125 #ifdef __GNUC__
126 #define ASSERT_MSG()	bf_log("assertion failed: file: %s, line: %d, function: %s", \
127 				__FILE__, __LINE__, __FUNCTION__);
128 #else
129 #define ASSERT_MSG()	bf_log("assertion failed: file: %s, line: %d", \
130 				__FILE__, __LINE__);
131 #endif
132 
133 #define ASSERT(expr) \
134 	if( !(expr) ) \
135 	{ \
136 		ASSERT_MSG(); \
137 		abort(); \
138 	}
139 
140 #define ISHEX(s) (strspn(s, "0123456790abcdefABCDEF") == strlen(s))
141 #define ISDEC(s) (strspn(s, "0123456789"            ) == strlen(s))
142 #define ISOCT(s) (strspn(s, "01234567"              ) == strlen(s))
143 
144 /*
145  *  Some usable defines
146  */
147 #define FALSE		0
148 #define TRUE		1
149 #define UNDEF		-1
150 
151 /*
152  *  Definition of new pretty types
153  */
154 typedef char            bool;
155 typedef unsigned long   UINT32;
156 typedef unsigned short  UINT16;
157 typedef unsigned char   UINT8;
158 typedef signed long     SINT32;
159 typedef signed short    SINT16;
160 typedef signed char     SINT8;
161 
162 #include "confread.h"
163 
164 /*
165  * Command line options
166  */
167 typedef struct {
168 	bool   daemon;		/* Run as daemon?                 */
169 	bool   quit;		/* Quit from daemon               */
170 	bool   dontcall;    /* -m key */
171 	int    inetd;		/* Called from inetd?             */
172 	int    force;		/* Force call?                    */
173 	int    hiddline;	/* Hidden line number (0,1..)     */
174 	char  *confname;	/* Use this config instead def.   */
175 	char  *incname;		/* Include this config            */
176 	char  *phone;		/* Forced phone number            */
177 	char  *iaddr;		/* Forced IP address              */
178 	char  *connect;		/* Connect string                 */
179 	char  *device;		/* Forced device name             */
180 	int    stype;		/* Handshake type in slave mode   */
181 	s_falist *addrlist;
182 } s_bforce_opts;
183 
184 /*
185  *  Global variables
186  */
187 extern const char *BFERR[];
188 
189 int daemon_run(const char *confname, const char *incname, bool quit);
190 
191 #endif
192