LCOV - code coverage report
Current view: top level - source3/printing - print_svid.c (source / functions) Hit Total Coverage
Test: coverage report for master 70ed9daf Lines: 0 1 0.0 %
Date: 2024-01-11 09:59:51 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 1997-1998 by Norm Jacobs, Colorado Springs, Colorado, USA
       3             :  * Copyright (C) 1997-1998 by Sun Microsystem, Inc.
       4             :  * All Rights Reserved
       5             :  *
       6             :  * This program is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  * 
      11             :  * This program is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  * 
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : /*
      21             :  * This module implements support for gathering and comparing available
      22             :  * printer information on a SVID or XPG4 compliant system.  It does this
      23             :  * through the use of the SVID/XPG4 command "lpstat(1)".
      24             :  *
      25             :  * The expectations is that execution of the command "lpstat -v" will
      26             :  * generate responses in the form of:
      27             :  *
      28             :  *      device for serial: /dev/term/b
      29             :  *      system for fax: server
      30             :  *      system for color: server (as printer chroma)
      31             :  */
      32             : 
      33             : 
      34             : #include "includes.h"
      35             : #include "printing/pcap.h"
      36             : #include "lib/util_file.h"
      37             : 
      38             : #if defined(SYSV) || defined(HPUX)
      39             : bool sysv_cache_reload(struct pcap_cache **_pcache)
      40             : {
      41             :         char **lines;
      42             :         int i;
      43             :         struct pcap_cache *pcache = NULL;
      44             :         char **argl = NULL;
      45             : 
      46             : #if defined(HPUX)
      47             :         DEBUG(5, ("reloading hpux printcap cache\n"));
      48             : #else
      49             :         DEBUG(5, ("reloading sysv printcap cache\n"));
      50             : #endif
      51             : 
      52             :         argl = str_list_make_empty(talloc_tos());
      53             :         str_list_add_printf(&argl, "/usr/bin/lpstat");
      54             :         str_list_add_printf(&argl, "-v");
      55             :         if (argl == NULL) {
      56             :                 return false;
      57             :         }
      58             : 
      59             :         lines = file_lines_ploadv(talloc_tos(), argl, NULL);
      60             :         if (lines == NULL) {
      61             : #if defined(HPUX)
      62             :       
      63             :                /*
      64             :                 * if "lpstat -v" is NULL then we check if schedular is running if it is
      65             :                 * that means no printers are added on the HP-UX system, if schedular is not
      66             :                 * running we display reload error.
      67             :                 */
      68             : 
      69             :                 char **scheduler;
      70             : 
      71             :                 argl[1] = talloc_strdup(argl, "-r");
      72             :                 if (argl[1] == NULL) {
      73             :                         TALLOC_FREE(argl);
      74             :                         return false;
      75             :                 }
      76             :                 scheduler = file_lines_ploadv(talloc_tos(), argl, NULL);
      77             :                 TALLOC_FREE(argl);
      78             :                 if(!strcmp(*scheduler,"scheduler is running")){
      79             :                         DEBUG(3,("No Printers found!!!\n"));
      80             :                         TALLOC_FREE(scheduler);
      81             :                         return True;
      82             :                 }
      83             :                 else{
      84             :                         DEBUG(3,("Scheduler is not running!!!\n"));
      85             :                         TALLOC_FREE(scheduler);
      86             :                         return False;
      87             :                 }
      88             : #else
      89             :                 DEBUG(3,("No Printers found!!!\n"));
      90             :                 return False;
      91             : #endif
      92             :         }
      93             :         TALLOC_FREE(argl);
      94             : 
      95             :         for (i = 0; lines[i]; i++) {
      96             :                 char *name, *tmp;
      97             :                 char *buf = lines[i];
      98             : 
      99             :                 /* eat "system/device for " */
     100             :                 if (((tmp = strchr_m(buf, ' ')) == NULL) ||
     101             :                     ((tmp = strchr_m(++tmp, ' ')) == NULL))
     102             :                         continue;
     103             : 
     104             :                 /*
     105             :                  * In case we're only at the "for ".
     106             :                  */
     107             : 
     108             :                 if(!strncmp("for ", ++tmp, 4)) {
     109             :                         tmp=strchr_m(tmp, ' ');
     110             :                         tmp++;
     111             :                 }
     112             : 
     113             :                 /* Eat whitespace. */
     114             : 
     115             :                 while(*tmp == ' ')
     116             :                         ++tmp;
     117             : 
     118             :                 /*
     119             :                  * On HPUX there is an extra line that can be ignored.
     120             :                  * d.thibadeau 2001/08/09
     121             :                  */
     122             :                 if(!strncmp("remote to", tmp, 9))
     123             :                         continue;
     124             : 
     125             :                 name = tmp;
     126             : 
     127             :                 /* truncate the ": ..." */
     128             :                 if ((tmp = strchr_m(name, ':')) != NULL)
     129             :                         *tmp = '\0';
     130             :                 
     131             :                 /* add it to the cache */
     132             :                 if (!pcap_cache_add_specific(&pcache, name, NULL, NULL)) {
     133             :                         TALLOC_FREE(lines);
     134             :                         pcap_cache_destroy_specific(&pcache);
     135             :                         return false;
     136             :                 }
     137             :         }
     138             : 
     139             :         TALLOC_FREE(lines);
     140             :         *_pcache = pcache;
     141             :         return true;
     142             : }
     143             : 
     144             : #else
     145             : /* this keeps fussy compilers happy */
     146             :  void print_svid_dummy(void);
     147           0 :  void print_svid_dummy(void) {}
     148             : #endif

Generated by: LCOV version 1.14