1 /* @(#) option-associated functions for udpxy
3 * Copyright 2008-2011 Pavel V. Cherenkov (pcherenkov@gmail.com)
5 * This file is part of udpxy.
7 * udpxy is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * udpxy is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with udpxy. If not, see <http://www.gnu.org/licenses/>.
32 read_http_footer (char* buf
, size_t len
)
34 const char* ev
= getenv ("UDPXY_HTTP200_FTR_LN");
39 /* if 1-line footer is specified */
41 (void) strncpy (buf
, ev
, len
-1);
46 if (NULL
!= (ev
= getenv ("UDPXY_HTTP200_FTR_FILE"))) {
47 n
= txtf_read (ev
, buf
, len
, stderr
);
54 /* populate options with default/initial values
57 init_uopt( struct udpxy_opt
* uo
)
62 uo
->is_verbose
= uf_FALSE
;
63 uo
->cl_tpstat
= uf_FALSE
;
65 uo
->rbuf_len
= DEFAULT_CACHE_LEN
;
67 uo
->max_clients
= DEFAULT_CLIENT_COUNT
;
68 uo
->rcv_tmout
= get_timeval( "UDPXY_RCV_TMOUT",
70 uo
->dhold_tmout
= get_timeval( "UDPXY_DHOLD_TMOUT",
72 uo
->sr_tmout
= get_timeval ( "UDPXY_SREAD_TMOUT", SRVSOCK_TIMEOUT
);
73 uo
->sw_tmout
= get_timeval ( "UDPXY_SWRITE_TMOUT", SRVSOCK_TIMEOUT
);
74 uo
->ssel_tmout
= get_timeval ( "UDPXY_SSEL_TMOUT", SSEL_TIMEOUT
);
75 uo
->lq_backlog
= (int) get_sizeval ("UDPXY_LQ_BACKLOG", LQ_BACKLOG
);
76 uo
->ss_rlwmark
= (int) get_sizeval ("UDPXY_SRV_RLWMARK", SRV_RLWMARK
);
78 uo
->nosync_sbuf
= (u_short
)get_flagval( "UDPXY_SSOCKBUF_NOSYNC", 0 );
79 uo
->nosync_dbuf
= (u_short
)get_flagval( "UDPXY_DSOCKBUF_NOSYNC", 0 );
83 uo
->mcast_refresh
= DEFAULT_MCAST_REFRESH
;
85 if (-1 == read_http_footer (uo
->h200_ftr
, sizeof(uo
->h200_ftr
))) {
86 rc
= -1; /* modify rc only if there is an error */
92 /* release resources allocated for udpxy options
95 free_uopt( struct udpxy_opt
* uo
)
100 free( uo
->srcfile
); uo
->srcfile
= NULL
;
104 free( uo
->dstfile
); uo
->dstfile
= NULL
;
111 /* populate udpxrec options with default/initial values
114 init_recopt( struct udpxrec_opt
* ro
)
120 ro
->is_verbose
= uf_FALSE
;
123 ro
->bg_time
= ro
->end_time
= 0;
125 ro
->bufsize
= DEFAULT_CACHE_LEN
;
128 ro
->mcast_addr
[0] = '\0';
132 ro
->rec_channel
[0] = '\0';
134 ro
->waitupd_sec
= -1;
137 (flag_t
)get_flagval( "UDPXY_SSOCKBUF_NOSYNC", 0 );
139 (flag_t
)get_flagval( "UDPXY_DSOCKBUF_NOSYNC", 0 );
147 /* release resources allocated for udpxy options
150 free_recopt( struct udpxrec_opt
* ro
)
155 free( ro
->dstfile
); ro
->dstfile
= NULL
;
158 free( ro
->pidfile
); ro
->pidfile
= NULL
;
161 ro
->rec_channel
[0] = '\0';
165 /* print udpxrec options to stream
168 fprint_recopt( FILE* stream
, struct udpxrec_opt
* ro
)
170 assert( stream
&& ro
);
172 if( ro
->is_verbose
) {
173 (void)fprintf( stream
, "verbose=[ON] " );
175 if( ro
->nice_incr
) {
176 (void)fprintf( stream
, "nice_incr=[%d] ", ro
->nice_incr
);
178 if( ro
->bg_time
> 0 ) {
179 (void)fprintf( stream
, "begin_time=[%s] ",
180 Zasctime( localtime(&(ro
->bg_time
) )) );
182 if( ro
->end_time
> 0 ) {
183 (void)fprintf( stream
, "end_time=[%s] ",
184 Zasctime( localtime(&(ro
->end_time
) )) );
186 if( ro
->max_fsize
> 0 ) {
187 (void)fprintf( stream
, "Max filesize=[%.0f] bytes ",
188 (double)ro
->max_fsize
);
191 (void)fprintf( stream
, "Buffer size=[%ld] bytes ",
194 if( ro
->rbuf_msgs
> 0 ) {
195 (void)fprintf( stream
, "Max messages=[%ld] ",
196 (long)ro
->rbuf_msgs
);
198 if( ro
->mcast_addr
[0] ) {
199 (void)fprintf( stream
, "Multicast interface=[%s] ", ro
->mcast_addr
);
201 if( ro
->rec_channel
[0] ) {
202 (void)fprintf( stream
, "Channel=[%s:%d] ", ro
->rec_channel
, ro
->rec_port
);
205 (void)fprintf( stream
, "Pidfile=[%s] ", ro
->pidfile
);
208 (void)fprintf( stream
, "Destination file=[%s] ", ro
->dstfile
);
210 if( ro
->waitupd_sec
> 0 ) {
211 (void)fprintf( stream
, "Update-wait=[%d] sec ", ro
->waitupd_sec
);
214 (void) fputs( "\n", stream
);
218 #endif /* UDPXREC_MOD */
220 /* set verbose output on
223 set_verbose( flag_t
* verbose
)