1996-05-04 11:50:46 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1996-05-04 11:50:46 +04:00
printcap parsing
1998-01-22 16:27:43 +03:00
Copyright ( C ) Karl Auer 1993 - 1998
1996-05-04 11:50:46 +04:00
Re - working by Martin Kiff , 1994
Re - written again by Andrew Tridgell
1997-12-03 08:08:07 +03:00
Modified for SVID support by Norm Jacobs , 1997
1999-12-13 16:27:58 +03:00
Modified for CUPS support by Michael Sweet , 1999
1996-05-04 11:50:46 +04:00
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
1996-05-04 11:50:46 +04: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/>.
1996-05-04 11:50:46 +04:00
*/
/*
1997-12-03 08:08:07 +03:00
* Modified to call SVID / XPG4 support if printcap name is set to " lpstat "
* in smb . conf under Solaris .
1999-12-13 16:27:58 +03:00
*
* Modified to call CUPS support if printcap name is set to " cups "
* in smb . conf .
2005-09-21 03:28:22 +04:00
*
* Modified to call iPrint support if printcap name is set to " iprint "
* in smb . conf .
1996-05-04 11:50:46 +04:00
*/
# include "includes.h"
2010-05-14 16:39:40 +04:00
# include "printing/pcap.h"
2005-01-05 19:20:35 +03:00
2008-10-10 22:55:14 +04:00
struct pcap_cache {
2005-01-05 19:20:35 +03:00
char * name ;
char * comment ;
struct pcap_cache * next ;
2008-10-10 22:55:14 +04:00
} ;
2005-01-05 19:20:35 +03:00
2008-10-10 22:55:14 +04:00
/* The systemwide printcap cache. */
static struct pcap_cache * pcap_cache = NULL ;
2005-01-05 19:20:35 +03:00
2008-10-10 22:55:14 +04:00
bool pcap_cache_add_specific ( struct pcap_cache * * ppcache , const char * name , const char * comment )
1996-05-04 11:50:46 +04:00
{
2008-10-10 22:55:14 +04:00
struct pcap_cache * p ;
2005-01-05 19:20:35 +03:00
2008-10-10 22:55:14 +04:00
if ( name = = NULL | | ( ( p = SMB_MALLOC_P ( struct pcap_cache ) ) = = NULL ) )
return false ;
2005-01-05 19:20:35 +03:00
p - > name = SMB_STRDUP ( name ) ;
p - > comment = ( comment & & * comment ) ? SMB_STRDUP ( comment ) : NULL ;
2008-10-10 22:55:14 +04:00
DEBUG ( 11 , ( " pcap_cache_add_specific: Adding name %s info %s \n " ,
p - > name , p - > comment ? p - > comment : " " ) ) ;
p - > next = * ppcache ;
* ppcache = p ;
2005-01-05 19:20:35 +03:00
2008-10-10 22:55:14 +04:00
return true ;
1996-05-04 11:50:46 +04:00
}
2005-01-05 19:20:35 +03:00
2008-10-10 22:55:14 +04:00
void pcap_cache_destroy_specific ( struct pcap_cache * * pp_cache )
1996-05-04 11:50:46 +04:00
{
2008-10-10 22:55:14 +04:00
struct pcap_cache * p , * next ;
1996-05-04 11:50:46 +04:00
2008-10-10 22:55:14 +04:00
for ( p = * pp_cache ; p ! = NULL ; p = next ) {
2005-01-05 19:20:35 +03:00
next = p - > next ;
SAFE_FREE ( p - > name ) ;
SAFE_FREE ( p - > comment ) ;
SAFE_FREE ( p ) ;
1996-05-04 11:50:46 +04:00
}
2008-10-10 22:55:14 +04:00
* pp_cache = NULL ;
}
bool pcap_cache_add ( const char * name , const char * comment )
{
return pcap_cache_add_specific ( & pcap_cache , name , comment ) ;
1996-05-04 11:50:46 +04:00
}
2007-10-19 04:40:25 +04:00
bool pcap_cache_loaded ( void )
1996-05-04 11:50:46 +04:00
{
2005-01-05 19:20:35 +03:00
return ( pcap_cache ! = NULL ) ;
1996-05-04 11:50:46 +04:00
}
1998-07-29 07:08:05 +04:00
2008-10-10 22:55:14 +04:00
void pcap_cache_replace ( const struct pcap_cache * pcache )
{
const struct pcap_cache * p ;
pcap_cache_destroy_specific ( & pcap_cache ) ;
for ( p = pcache ; p ; p = p - > next ) {
pcap_cache_add ( p - > name , p - > comment ) ;
}
}
2005-01-05 19:20:35 +03:00
void pcap_cache_reload ( void )
1996-05-04 11:50:46 +04:00
{
2005-01-05 19:20:35 +03:00
const char * pcap_name = lp_printcapname ( ) ;
2007-10-19 04:40:25 +04:00
bool pcap_reloaded = False ;
2008-10-10 22:55:14 +04:00
struct pcap_cache * tmp_cache = NULL ;
2005-01-05 19:20:35 +03:00
DEBUG ( 3 , ( " reloading printcap cache \n " ) ) ;
/* only go looking if no printcap name supplied */
if ( pcap_name = = NULL | | * pcap_name = = 0 ) {
DEBUG ( 0 , ( " No printcap file name configured! \n " ) ) ;
return ;
}
tmp_cache = pcap_cache ;
pcap_cache = NULL ;
1997-12-03 08:08:07 +03:00
2001-08-23 23:06:20 +04:00
# ifdef HAVE_CUPS
2005-01-05 19:20:35 +03:00
if ( strequal ( pcap_name , " cups " ) ) {
2010-08-09 00:50:28 +04:00
pcap_reloaded = cups_cache_reload ( server_event_context ( ) ,
server_messaging_context ( ) ) ;
2005-01-05 19:20:35 +03:00
goto done ;
}
# endif
1999-12-13 16:27:58 +03:00
2005-09-21 03:28:22 +04:00
# ifdef HAVE_IPRINT
if ( strequal ( pcap_name , " iprint " ) ) {
pcap_reloaded = iprint_cache_reload ( ) ;
goto done ;
}
# endif
2005-03-08 01:10:27 +03:00
# if defined(SYSV) || defined(HPUX)
2005-01-05 19:20:35 +03:00
if ( strequal ( pcap_name , " lpstat " ) ) {
pcap_reloaded = sysv_cache_reload ( ) ;
goto done ;
}
1997-12-03 08:08:07 +03:00
# endif
1996-05-04 11:50:46 +04:00
# ifdef AIX
2005-01-05 19:20:35 +03:00
if ( strstr_m ( pcap_name , " /qconfig " ) ! = NULL ) {
pcap_reloaded = aix_cache_reload ( ) ;
goto done ;
}
1996-05-04 11:50:46 +04:00
# endif
1997-12-03 08:08:07 +03:00
2010-05-13 22:23:23 +04:00
pcap_reloaded = std_pcap_cache_reload ( pcap_name ) ;
2005-01-05 19:20:35 +03:00
done :
DEBUG ( 3 , ( " reload status: %s \n " , ( pcap_reloaded ) ? " ok " : " error " ) ) ;
if ( pcap_reloaded )
2008-10-10 22:55:14 +04:00
pcap_cache_destroy_specific ( & tmp_cache ) ;
2005-01-05 19:20:35 +03:00
else {
2008-10-10 22:55:14 +04:00
pcap_cache_destroy_specific ( & pcap_cache ) ;
2005-01-05 19:20:35 +03:00
pcap_cache = tmp_cache ;
}
return ;
1996-05-04 11:50:46 +04:00
}
2007-10-19 04:40:25 +04:00
bool pcap_printername_ok ( const char * printername )
2005-01-05 19:20:35 +03:00
{
2008-10-10 22:55:14 +04:00
struct pcap_cache * p ;
2005-01-05 19:20:35 +03:00
for ( p = pcap_cache ; p ! = NULL ; p = p - > next )
if ( strequal ( p - > name , printername ) )
return True ;
return False ;
}
1996-05-04 11:50:46 +04:00
/***************************************************************************
2008-10-10 22:55:14 +04:00
run a function on each printer name in the printcap file .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-10-10 22:55:14 +04:00
void pcap_printer_fn_specific ( const struct pcap_cache * pc ,
void ( * fn ) ( const char * , const char * , void * ) ,
void * pdata )
1996-05-04 11:50:46 +04:00
{
2008-10-10 22:55:14 +04:00
const struct pcap_cache * p ;
1996-05-04 11:50:46 +04:00
2008-10-10 22:55:14 +04:00
for ( p = pc ; p ! = NULL ; p = p - > next )
fn ( p - > name , p - > comment , pdata ) ;
1996-05-04 11:50:46 +04:00
2005-01-05 19:20:35 +03:00
return ;
1996-05-04 11:50:46 +04:00
}
2008-10-10 22:55:14 +04:00
void pcap_printer_fn ( void ( * fn ) ( const char * , const char * , void * ) , void * pdata )
{
2008-10-12 12:38:55 +04:00
pcap_printer_fn_specific ( pcap_cache , fn , pdata ) ;
2008-10-10 22:55:14 +04:00
}