1 #ident "$Id: conf_sf.c,v 4.15 2009/03/19 15:13:53 gert Exp $ Copyright (c) Gert Doering" 2 3 /* conf_sf.c 4 * 5 * configuration defaults / configuration reading code for sendfax 6 */ 7 8 #include <stdio.h> 9 #include <string.h> 10 #include <unistd.h> 11 12 #include "mgetty.h" 13 #include "policy.h" 14 #include "syslibs.h" 15 16 #include "config.h" 17 #include "conf_sf.h" 18 19 #include "version.h" 20 char * mgetty_version = VERSION_LONG; /* version.h */ 21 22 #ifndef FAX_SEND_MAX_TRIES 23 #define FAX_SEND_MAX_TRIES 0 24 #endif 25 26 #ifndef FAX_SEND_SWITCHBD 27 #define FAX_SEND_SWITCHBD 0 28 #endif 29 30 struct conf_data_sendfax c = { 31 { "fax-devices", {0}, CT_STRING, C_EMPTY }, 32 { "fax-devices", {0}, CT_STRING, C_IGNORE }, 33 { "modem-init", {0}, CT_STRING, C_EMPTY }, 34 #ifdef FAX_MODEM_HANDSHAKE 35 { "modem-handshake", {(p_int) FAX_MODEM_HANDSHAKE}, CT_STRING, C_PRESET }, 36 #else 37 { "modem-handshake", {0}, CT_STRING, C_EMPTY }, 38 #endif 39 { "modem-type", {(p_int) DEFAULT_MODEMTYPE}, CT_STRING, C_PRESET }, 40 { "modem-quirks", {0}, CT_INT, C_EMPTY }, 41 { "reset-after-fail", {0}, CT_STRING, C_EMPTY }, 42 { "fax-send-flow", {FAXSEND_FLOW}, CT_FLOWL, C_PRESET }, 43 { "fax-rec-flow", {FAXREC_FLOW}, CT_FLOWL, C_PRESET }, 44 { "max-tries", {FAX_SEND_MAX_TRIES}, CT_INT, C_PRESET }, 45 { "max-tries-continue", {TRUE}, CT_BOOL, C_PRESET }, 46 { "speed", {FAX_SEND_BAUD}, CT_INT, C_PRESET }, 47 { "switchbd", {FAX_SEND_SWITCHBD}, CT_INT, C_PRESET }, 48 { "open-delay", {0}, CT_INT, C_EMPTY }, 49 { "ignore-carrier", {TRUE }, CT_BOOL, C_PRESET }, 50 { "dial-prefix", {(p_int) FAX_DIAL_PREFIX}, CT_STRING, C_PRESET }, 51 { "fax-id", {(p_int)FAX_STATION_ID}, CT_STRING, C_PRESET }, 52 { "poll-dir", {(p_int)"."}, CT_STRING, C_PRESET }, 53 { "normal-res", {0}, CT_BOOL, C_PRESET }, 54 { "fax-min-speed", {0}, CT_INT, C_PRESET }, 55 { "fax-max-speed", {14400}, CT_INT, C_PRESET }, 56 { "debug", {LOG_LEVEL}, CT_INT, C_PRESET }, 57 { "verbose", {FALSE}, CT_BOOL, C_PRESET }, 58 { "" /* polling */, {FALSE}, CT_BOOL, C_PRESET }, 59 { "page-header", {0}, CT_STRING, C_EMPTY }, 60 { "" /* stdin */, {FALSE}, CT_BOOL, C_PRESET }, 61 { "" /* rename */, {FALSE}, CT_BOOL, C_PRESET }, 62 { "" /* acct_handle */, {(p_int)""}, CT_STRING, C_PRESET }, 63 { NULL, {0}, CT_STRING, C_EMPTY }}; 64 65 int sendfax_parse_args _P2( (argc,argv), int argc, char ** argv ) 66 { 67 int opt; 68 char * p; 69 70 /* sanity check: 71 * make sure that structs-in-struct can be handled exactly as if 72 * packed in array (get_config relies on it!) 73 */ 74 conf_data c_a[2]; 75 if ( ( (char *)&c_a[1] - (char *)&c_a[0] ) != 76 ( (char *)&c.ttys_0 - (char *)&c.ttys ) ) 77 { 78 fprintf( stderr, "ERROR: config table size mixup. contact author\n" ); 79 exit(99); 80 } 81 82 /* since "ttys" has to be writable, we strdup() the default string */ 83 p = malloc( sizeof( FAX_MODEM_TTYS )+1 ); 84 if ( p == NULL ) 85 c.ttys.flags = C_EMPTY; 86 else 87 { 88 strcpy( p, FAX_MODEM_TTYS ); 89 c.ttys.d.p = p; 90 c.ttys.flags = C_CONF; 91 } 92 93 /* get command line arguments */ 94 while ((opt = getopt(argc, argv, "d:vx:ph:l:nm:SC:I:rA:D:M:R:V")) != EOF) 95 { 96 switch (opt) { 97 case 'd': /* set target directory for polling */ 98 conf_set_string( &c.poll_dir, optarg ); 99 break; 100 case 'v': /* verbose blurb on stdout */ 101 conf_set_bool( &c.verbose, TRUE ); 102 break; 103 case 'x': /* set debug level */ 104 conf_set_int( &c.debug, atoi(optarg) ); 105 log_set_llevel( c_int(debug) ); 106 break; 107 case 'p': /* activate poll receive */ 108 conf_set_int( &c.fax_poll_wanted, TRUE ); 109 break; 110 case 'h': /* set header page */ 111 conf_set_string( &c.fax_page_header, optarg ); 112 break; 113 case 'l': /* set device(s) to use */ 114 if ( optarg[0] == '/' && 115 strncmp( optarg, "/dev/", 5 ) != 0 ) 116 { 117 fprintf( stderr, "%s: -l: device must be located in /dev!\n", 118 argv[0]); 119 exit(1); 120 } 121 conf_set_string( &c.ttys, optarg ); 122 break; 123 case 'n': /* set normal resolution */ 124 conf_set_bool( &c.normal_res, TRUE ); 125 break; 126 case 'm': /* modem initialization string */ 127 conf_set_string( &c.modem_init, optarg ); 128 break; 129 case 'S': /* modem on stdin */ 130 conf_set_bool( &c.use_stdin, TRUE ); 131 break; 132 case 'C': /* modem class */ 133 conf_set_string( &c.modem_type, optarg ); 134 break; 135 case 'I': /* local fax id */ 136 conf_set_string( &c.station_id, optarg ); 137 break; 138 case 'r': 139 conf_set_bool( &c.rename_files, TRUE ); 140 break; 141 case 'A': 142 conf_set_string( &c.acct_handle, optarg ); 143 break; 144 case 'D': 145 conf_set_string( &c.dial_prefix, optarg ); 146 break; 147 case 'M': /* set max. fax speed */ 148 conf_set_int( &c.fax_max_speed, atoi(optarg) ); 149 break; 150 case 'R': /* retries */ 151 conf_set_int( &c.max_tries, atoi(optarg) ); 152 break; 153 case 'V': 154 printf("\nmgetty+sendfax by Gert Doering\n%s\n\n", 155 mgetty_version); 156 printf("log file written to '%s'\n", FAX_LOG ); 157 #ifdef SENDFAX_CONFIG 158 printf("config file read from '%s'\n\n", 159 makepath( SENDFAX_CONFIG, CONFDIR )); 160 #endif 161 exit(0); 162 case '?': /* unrecognized parameter */ 163 return ERROR; 164 break; 165 } 166 } 167 168 return NOERROR; 169 } 170 171 /* get sendfax configuration from file (if configured) 172 * 173 * if "port == NULL", read "fax-devices" (c.tty), if != NULL, skip 174 * c.tty (because it woudln't make sense to set it, and would break 175 * fax_open()) 176 */ 177 void sendfax_get_config _P1( (port), char * port ) 178 { 179 #ifdef SENDFAX_CONFIG 180 if ( port == NULL ) 181 { 182 lprintf( L_NOISE, "reading default configuration" ); 183 get_config( makepath( SENDFAX_CONFIG, CONFDIR ), 184 (conf_data *)&c, "port", NULL ); 185 } 186 else 187 { 188 lprintf( L_NOISE, "reading specific data for port '%s'", port ); 189 get_config( makepath( SENDFAX_CONFIG, CONFDIR ), 190 ((conf_data *)&c)+1, "port", port ); 191 } 192 #else 193 lprintf( L_NOISE, "not reading config file, not configured" ); 194 #endif 195 log_set_llevel( c_int(debug) ); 196 197 if ( c_isset(modem_quirks) ) 198 { 199 lprintf( L_NOISE, "set modem_quirks: 0x%04x", c_int(modem_quirks)); 200 modem_quirks = c_int(modem_quirks); 201 } 202 } 203