1997-12-03 08:08:07 +03:00
/*
1998-01-22 16:27:43 +03:00
* Copyright ( C ) 1997 - 1998 by Norm Jacobs , Colorado Springs , Colorado , USA
* Copyright ( C ) 1997 - 1998 by Sun Microsystem , Inc .
1997-12-03 08:08:07 +03:00
* All Rights Reserved
*
* 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
1997-12-03 08:08:07 +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 09:23:25 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
1997-12-03 08:08:07 +03:00
*/
/*
* This module implements support for gathering and comparing available
* printer information on a SVID or XPG4 compliant system . It does this
* through the use of the SVID / XPG4 command " lpstat(1) " .
*
* The expectations is that execution of the command " lpstat -v " will
* generate responses in the form of :
*
* device for serial : / dev / term / b
* system for fax : server
* system for color : server ( as printer chroma )
*/
# include "includes.h"
2010-05-14 16:39:40 +04:00
# include "printing/pcap.h"
1997-12-03 08:08:07 +03:00
2005-03-08 01:10:27 +03:00
# if defined(SYSV) || defined(HPUX)
2007-10-19 04:40:25 +04:00
bool sysv_cache_reload ( void )
1997-12-03 08:08:07 +03:00
{
2000-04-16 15:00:21 +04:00
char * * lines ;
int i ;
2005-11-22 17:20:02 +03:00
# if defined(HPUX)
DEBUG ( 5 , ( " reloading hpux printcap cache \n " ) ) ;
# else
2005-01-05 19:20:35 +03:00
DEBUG ( 5 , ( " reloading sysv printcap cache \n " ) ) ;
2005-11-22 17:20:02 +03:00
# endif
2000-04-16 15:00:21 +04:00
2005-01-05 19:20:35 +03:00
if ( ( lines = file_lines_pload ( " /usr/bin/lpstat -v " , NULL ) ) = = NULL )
2005-11-22 17:20:02 +03:00
{
# if defined(HPUX)
/*
* if " lpstat -v " is NULL then we check if schedular is running if it is
* that means no printers are added on the HP - UX system , if schedular is not
* running we display reload error .
*/
char * * scheduler ;
scheduler = file_lines_pload ( " /usr/bin/lpstat -r " , NULL ) ;
if ( ! strcmp ( * scheduler , " scheduler is running " ) ) {
DEBUG ( 3 , ( " No Printers found!!! \n " ) ) ;
2008-10-12 19:34:43 +04:00
TALLOC_FREE ( scheduler ) ;
2005-11-22 17:20:02 +03:00
return True ;
}
else {
DEBUG ( 3 , ( " Scheduler is not running!!! \n " ) ) ;
2008-10-12 19:34:43 +04:00
TALLOC_FREE ( scheduler ) ;
2005-11-22 17:20:02 +03:00
return False ;
}
# else
DEBUG ( 3 , ( " No Printers found!!! \n " ) ) ;
2005-01-05 19:20:35 +03:00
return False ;
2005-11-22 17:20:02 +03:00
# endif
}
2005-01-05 19:20:35 +03:00
for ( i = 0 ; lines [ i ] ; i + + ) {
2000-04-16 15:00:21 +04:00
char * name , * tmp ;
char * buf = lines [ i ] ;
/* eat "system/device for " */
2001-07-04 11:36:09 +04:00
if ( ( ( tmp = strchr_m ( buf , ' ' ) ) = = NULL ) | |
( ( tmp = strchr_m ( + + tmp , ' ' ) ) = = NULL ) )
2000-04-16 15:00:21 +04:00
continue ;
/*
* In case we ' re only at the " for " .
*/
2005-01-05 19:20:35 +03:00
if ( ! strncmp ( " for " , + + tmp , 4 ) ) {
2001-07-04 11:36:09 +04:00
tmp = strchr_m ( tmp , ' ' ) ;
2000-04-16 15:00:21 +04:00
tmp + + ;
}
2001-08-09 23:36:12 +04:00
/* Eat whitespace. */
while ( * tmp = = ' ' )
+ + tmp ;
/*
* On HPUX there is an extra line that can be ignored .
* d . thibadeau 2001 / 08 / 09
*/
2005-01-05 19:20:35 +03:00
if ( ! strncmp ( " remote to " , tmp , 9 ) )
2001-08-09 23:36:12 +04:00
continue ;
2000-04-16 15:00:21 +04:00
name = tmp ;
/* truncate the ": ..." */
2001-07-04 11:36:09 +04:00
if ( ( tmp = strchr_m ( name , ' : ' ) ) ! = NULL )
2000-04-16 15:00:21 +04:00
* tmp = ' \0 ' ;
/* add it to the cache */
2005-01-05 19:20:35 +03:00
if ( ! pcap_cache_add ( name , NULL ) ) {
2008-10-12 19:34:43 +04:00
TALLOC_FREE ( lines ) ;
2005-01-05 19:20:35 +03:00
return False ;
1997-12-03 08:08:07 +03:00
}
}
2000-04-16 15:00:21 +04:00
2008-10-12 19:34:43 +04:00
TALLOC_FREE ( lines ) ;
2005-01-05 19:20:35 +03:00
return True ;
1997-12-03 08:08:07 +03:00
}
# else
/* this keeps fussy compilers happy */
1998-10-17 21:41:13 +04:00
void print_svid_dummy ( void ) ;
1997-12-03 08:08:07 +03:00
void print_svid_dummy ( void ) { }
# endif