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
* the Free Software Foundation ; either version 2 of the License , or
* ( 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
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
/*
* 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"
# include "smb.h"
# ifdef SYSV
typedef struct printer {
char * name ;
struct printer * next ;
} printer_t ;
static printer_t * printers = NULL ;
1998-04-13 23:24:06 +04:00
static void populate_printers ( void )
1997-12-03 08:08:07 +03:00
{
2000-04-16 15:00:21 +04:00
char * * lines ;
int i ;
2001-07-04 11:15:53 +04:00
lines = file_lines_pload ( " /usr/bin/lpstat -v " , NULL ) ;
2000-04-16 15:00:21 +04:00
if ( ! lines ) return ;
for ( i = 0 ; lines [ i ] ; i + + ) {
printer_t * ptmp ;
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 " .
*/
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
*/
2001-08-10 07:17:58 +04: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 */
if ( ( ptmp = malloc ( sizeof ( * ptmp ) ) ) ! = NULL ) {
ZERO_STRUCTP ( ptmp ) ;
if ( ( ptmp - > name = strdup ( name ) ) = = NULL )
DEBUG ( 0 , ( " populate_printers: malloc fail in strdup ! \n " ) ) ;
ptmp - > next = printers ;
printers = ptmp ;
} else {
DEBUG ( 0 , ( " populate_printers: malloc fail for ptmp \n " ) ) ;
1997-12-03 08:08:07 +03:00
}
}
2000-04-16 15:00:21 +04:00
file_lines_free ( lines ) ;
1997-12-03 08:08:07 +03:00
}
/*
* provide the equivalent of pcap_printer_fn ( ) for SVID / XPG4 conforming
* systems . It was unclear why pcap_printer_fn ( ) was tossing names longer
* than 8 characters . I suspect that its a protocol limit , but amazingly
* names longer than 8 characters appear to work with my test
* clients ( Win95 / NT ) .
*/
1998-04-13 23:24:06 +04:00
void sysv_printer_fn ( void ( * fn ) ( char * , char * ) )
1997-12-03 08:08:07 +03:00
{
printer_t * tmp ;
if ( printers = = NULL )
populate_printers ( ) ;
for ( tmp = printers ; tmp ! = NULL ; tmp = tmp - > next )
2001-07-04 11:15:53 +04:00
( fn ) ( tmp - > name , " " ) ;
1997-12-03 08:08:07 +03:00
}
/*
* provide the equivalent of pcap_printername_ok ( ) for SVID / XPG4 conforming
* systems .
*/
int sysv_printername_ok ( char * name )
{
printer_t * tmp ;
if ( printers = = NULL )
populate_printers ( ) ;
for ( tmp = printers ; tmp ! = NULL ; tmp = tmp - > next )
if ( strcmp ( tmp - > name , name ) = = 0 )
return ( True ) ;
return ( False ) ;
}
# 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