2005-01-05 19:20:35 +03:00
/*
AIX - specific printcap loading
Copyright ( C ) Jean - Pierre . Boulard @ univ - rennes1 . fr 1996
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-05 19:20:35 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-05 19:20:35 +03:00
*/
/*
* This module implements AIX - specific printcap loading . Most of the code
* here was originally provided by Jean - Pierre . Boulard @ univ - rennes1 . fr in
* the Samba 1.9 .14 release , and was formerly contained in pcap . c . It has
* been moved here and condensed as part of a larger effort to clean up and
* simplify the printcap code . - - Rob Foehl , 2004 / 12 / 06
*/
# include "includes.h"
2011-04-20 19:54:24 +04:00
# include "system/filesys.h"
2010-05-14 16:39:40 +04:00
# include "printing/pcap.h"
2005-01-05 19:20:35 +03:00
# ifdef AIX
2007-10-19 04:40:25 +04:00
bool aix_cache_reload ( void )
2005-01-05 19:20:35 +03:00
{
int iEtat ;
XFILE * pfile ;
char * line = NULL , * p ;
2007-12-11 00:43:12 +03:00
char * name = NULL ;
2007-11-22 00:56:36 +03:00
TALLOC_CTX * ctx = talloc_init ( " aix_cache_reload " ) ;
if ( ! ctx ) {
return false ;
}
2005-01-05 19:20:35 +03:00
DEBUG ( 5 , ( " reloading aix printcap cache \n " ) ) ;
if ( ( pfile = x_fopen ( lp_printcapname ( ) , O_RDONLY , 0 ) ) = = NULL ) {
DEBUG ( 0 , ( " Unable to open qconfig file %s for read! \n " , lp_printcapname ( ) ) ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return false ;
2005-01-05 19:20:35 +03:00
}
iEtat = 0 ;
/* scan qconfig file for searching <printername>: */
2008-10-19 15:06:14 +04:00
for ( ; ( line = fgets_slash ( NULL , 1024 , pfile ) ) ; free ( line ) ) {
2005-01-05 19:20:35 +03:00
if ( * line = = ' * ' | | * line = = 0 )
continue ;
switch ( iEtat ) {
case 0 : /* locate an entry */
if ( * line = = ' \t ' | | * line = = ' ' )
continue ;
if ( ( p = strchr_m ( line , ' : ' ) ) ) {
2008-01-23 13:04:10 +03:00
char * saveptr ;
2005-01-05 19:20:35 +03:00
* p = ' \0 ' ;
2008-01-23 13:04:10 +03:00
p = strtok_r ( line , " : " , & saveptr ) ;
2005-01-05 19:20:35 +03:00
if ( strcmp ( p , " bsh " ) ! = 0 ) {
2007-11-22 00:56:36 +03:00
name = talloc_strdup ( ctx , p ) ;
if ( ! name ) {
2008-10-19 15:06:14 +04:00
SAFE_FREE ( line ) ;
2007-11-22 00:56:36 +03:00
x_fclose ( pfile ) ;
TALLOC_FREE ( ctx ) ;
return false ;
}
2005-01-05 19:20:35 +03:00
iEtat = 1 ;
continue ;
}
}
break ;
case 1 : /* scanning device stanza */
if ( * line = = ' * ' | | * line = = 0 )
continue ;
if ( * line ! = ' \t ' & & * line ! = ' ' ) {
/* name is found without stanza device */
/* probably a good printer ??? */
iEtat = 0 ;
2011-05-13 12:02:42 +04:00
if ( ! pcap_cache_add ( name , NULL , NULL ) ) {
2008-10-19 15:06:14 +04:00
SAFE_FREE ( line ) ;
2005-01-05 19:20:35 +03:00
x_fclose ( pfile ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return false ;
2005-01-05 19:20:35 +03:00
}
continue ;
}
2007-11-22 00:56:36 +03:00
2005-01-05 19:20:35 +03:00
if ( strstr_m ( line , " backend " ) ) {
/* it's a device, not a virtual printer */
iEtat = 0 ;
} else if ( strstr_m ( line , " device " ) ) {
/* it's a good virtual printer */
iEtat = 0 ;
2011-05-13 12:02:42 +04:00
if ( ! pcap_cache_add ( name , NULL , NULL ) ) {
2008-10-19 15:06:14 +04:00
SAFE_FREE ( line ) ;
2005-01-05 19:20:35 +03:00
x_fclose ( pfile ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return false ;
2005-01-05 19:20:35 +03:00
}
continue ;
}
break ;
}
}
x_fclose ( pfile ) ;
2007-11-22 00:56:36 +03:00
TALLOC_FREE ( ctx ) ;
return true ;
2005-01-05 19:20:35 +03:00
}
# else
/* this keeps fussy compilers happy */
void print_aix_dummy ( void ) ;
void print_aix_dummy ( void ) { }
# endif /* AIX */