File: conf_sf.c

package info (click to toggle)
mgetty 1.1.36-1.5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,192 kB
  • ctags: 3,675
  • sloc: ansic: 40,051; sh: 6,120; perl: 5,879; makefile: 1,436; tcl: 756; lisp: 283
file content (200 lines) | stat: -rw-r--r-- 5,938 bytes parent folder | download | duplicates (4)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#ident "$Id: conf_sf.c,v 4.13 2006/11/22 15:40:40 gert Exp $ Copyright (c) Gert Doering"

/* conf_sf.c
 *
 * configuration defaults / configuration reading code for sendfax
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "mgetty.h"
#include "policy.h"
#include "syslibs.h"

#include "config.h"
#include "conf_sf.h"

extern char * mgetty_version;		/* sendfax.c/version.h */

#ifndef FAX_SEND_MAX_TRIES
#define FAX_SEND_MAX_TRIES 0
#endif

#ifndef FAX_SEND_SWITCHBD
#define FAX_SEND_SWITCHBD 0
#endif

struct conf_data_sendfax c = {
	{ "fax-devices", {0}, CT_STRING, C_EMPTY },
	{ "fax-devices", {0}, CT_STRING, C_IGNORE },
	{ "modem-init", {0}, CT_STRING, C_EMPTY },
#ifdef FAX_MODEM_HANDSHAKE
	{ "modem-handshake", {(p_int) FAX_MODEM_HANDSHAKE}, CT_STRING, C_PRESET },
#else
	{ "modem-handshake", {0}, CT_STRING, C_EMPTY },
#endif
	{ "modem-type", {(p_int) DEFAULT_MODEMTYPE}, CT_STRING, C_PRESET },
	{ "modem-quirks", {0}, CT_INT, C_EMPTY },
	{ "fax-send-flow", {FAXSEND_FLOW}, CT_FLOWL, C_PRESET },
	{ "fax-rec-flow", {FAXREC_FLOW}, CT_FLOWL, C_PRESET },
	{ "max-tries", {FAX_SEND_MAX_TRIES}, CT_INT, C_PRESET },
	{ "max-tries-continue", {TRUE}, CT_BOOL, C_PRESET },
	{ "speed", {FAX_SEND_BAUD}, CT_INT, C_PRESET },
	{ "switchbd", {FAX_SEND_SWITCHBD}, CT_INT, C_PRESET },
	{ "open-delay",	{0}, CT_INT, C_EMPTY },
	{ "ignore-carrier", {TRUE }, CT_BOOL, C_PRESET },
	{ "dial-prefix", {(p_int) FAX_DIAL_PREFIX}, CT_STRING, C_PRESET },
	{ "fax-id", {(p_int)FAX_STATION_ID}, CT_STRING, C_PRESET },
	{ "poll-dir", {(p_int)"."}, CT_STRING, C_PRESET },
	{ "normal-res", {0}, CT_BOOL, C_PRESET },
	{ "fax-min-speed", {0}, CT_INT, C_PRESET },
	{ "fax-max-speed", {14400}, CT_INT, C_PRESET },
	{ "debug", {LOG_LEVEL}, CT_INT, C_PRESET },
	{ "verbose", {FALSE}, CT_BOOL, C_PRESET },
	{ "" /* polling */, {FALSE}, CT_BOOL, C_PRESET },
	{ "page-header", {0}, CT_STRING, C_EMPTY },
	{ "" /* stdin */, {FALSE}, CT_BOOL, C_PRESET },
	{ "" /* rename */, {FALSE}, CT_BOOL, C_PRESET },
	{ "" /* acct_handle */, {(p_int)""}, CT_STRING, C_PRESET },
	{ NULL, {0}, CT_STRING, C_EMPTY }};

int sendfax_parse_args _P2( (argc,argv), int argc, char ** argv )
{
int opt;
char * p;

    /* sanity check:
     * make sure that structs-in-struct can be handled exactly as if
     * packed in array (get_config relies on it!)
     */
conf_data c_a[2];
    if ( ( (char *)&c_a[1] - (char *)&c_a[0] )  != 
	 ( (char *)&c.ttys_0 - (char *)&c.ttys ) )
    {
	fprintf( stderr, "ERROR: config table size mixup. contact author\n" );
	exit(99);
    }

    /* since "ttys" has to be writable, we strdup() the default string */
    p = malloc( sizeof( FAX_MODEM_TTYS )+1 );
    if ( p == NULL )
	c.ttys.flags = C_EMPTY;
    else
    {
	strcpy( p, FAX_MODEM_TTYS );
	c.ttys.d.p = p;
	c.ttys.flags = C_CONF;
    }

    /* get command line arguments */
    while ((opt = getopt(argc, argv, "d:vx:ph:l:nm:SC:I:rA:D:M:R:V")) != EOF)
    {
	switch (opt) {
	  case 'd':	/* set target directory for polling */
	    conf_set_string( &c.poll_dir, optarg );
	    break;
	  case 'v':	/* verbose blurb on stdout */
	    conf_set_bool( &c.verbose, TRUE );
	    break;
	  case 'x':	/* set debug level */
	    conf_set_int( &c.debug, atoi(optarg) );
	    log_set_llevel( c_int(debug) );
	    break;
	  case 'p':	/* activate poll receive */
	    conf_set_int( &c.fax_poll_wanted, TRUE );
	    break;
	  case 'h':	/* set header page */
	    conf_set_string( &c.fax_page_header, optarg );
	    break;
	  case 'l':	/* set device(s) to use */
	    if ( optarg[0] == '/' &&
		 strncmp( optarg, "/dev/", 5 ) != 0 )
	    {
		fprintf( stderr, "%s: -l: device must be located in /dev!\n",
		                 argv[0]);
		exit(1);
	    }
	    conf_set_string( &c.ttys, optarg );
	    break;
	  case 'n':	/* set normal resolution */
	    conf_set_bool( &c.normal_res, TRUE );
	    break;
	  case 'm':	/* modem initialization string */
	    conf_set_string( &c.modem_init, optarg );
	    break;
	  case 'S':	/* modem on stdin */
	    conf_set_bool( &c.use_stdin, TRUE );
	    break;
	  case 'C':	/* modem class */
	    conf_set_string( &c.modem_type, optarg );
	    break;
	  case 'I':	/* local fax id */
	    conf_set_string( &c.station_id, optarg );
	    break;
	  case 'r':
	    conf_set_bool( &c.rename_files, TRUE );
	    break;
	  case 'A':
	    conf_set_string( &c.acct_handle, optarg );
	    break;
	  case 'D':
	    conf_set_string( &c.dial_prefix, optarg );
	    break;
	  case 'M':	/* set max. fax speed */
	    conf_set_int( &c.fax_max_speed, atoi(optarg) );
	    break;
	  case 'R':	/* retries */
	    conf_set_int( &c.max_tries, atoi(optarg) );
	    break;
	  case 'V':
	    printf("\nmgetty+sendfax by Gert Doering\n%s\n\n",
		    mgetty_version);
	    printf("log file written to '%s'\n", FAX_LOG );
#ifdef SENDFAX_CONFIG
            printf("config file read from '%s'\n\n", 
			makepath( SENDFAX_CONFIG, CONFDIR ));
#endif
	    exit(0);
	  case '?':	/* unrecognized parameter */
	    return ERROR;
	    break;
	}
    }

    return NOERROR;
}

/* get sendfax configuration from file (if configured)
 *
 * if "port == NULL", read "fax-devices" (c.tty), if != NULL, skip
 * c.tty (because it woudln't make sense to set it, and would break
 * fax_open())
 */
void sendfax_get_config _P1( (port), char * port )
{
#ifdef SENDFAX_CONFIG
    if ( port == NULL )
    {
	lprintf( L_NOISE, "reading default configuration" );
	get_config( makepath( SENDFAX_CONFIG, CONFDIR ),
		    (conf_data *)&c, "port", NULL );
    }
    else
    {
	lprintf( L_NOISE, "reading specific data for port '%s'", port );
	get_config( makepath( SENDFAX_CONFIG, CONFDIR ),
		    ((conf_data *)&c)+1, "port", port );
    }
#else
    lprintf( L_NOISE, "not reading config file, not configured" );
#endif
    log_set_llevel( c_int(debug) );

    if ( c_isset(modem_quirks) )
    {
        lprintf( L_NOISE, "set modem_quirks: 0x%04x", c_int(modem_quirks));
	modem_quirks = c_int(modem_quirks);
    }
}