r23801: The FSF has moved around a lot. This fixes their Mass Ave address.
[sfrench/samba-autobuild/.git] / source / printing / print_svid.c
index 5c5eebeb5028c193c59661af4fe5cddb2a6aec15..fb7e56794e49ce05b4420bdf95fe2f6361198762 100644 (file)
@@ -5,7 +5,7 @@
  *
  * 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
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  * 
  * This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  * 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 02139, USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
 
 
 #include "includes.h"
-#include "smb.h"
 
-#ifdef SYSV
-
-extern int DEBUGLEVEL;
+#if defined(SYSV) || defined(HPUX)
+BOOL sysv_cache_reload(void)
+{
+       char **lines;
+       int i;
 
-typedef struct printer {
-       char *name;
-       struct printer *next;
-} printer_t;
-static printer_t *printers = NULL;
+#if defined(HPUX)
+       DEBUG(5, ("reloading hpux printcap cache\n"));
+#else
+       DEBUG(5, ("reloading sysv printcap cache\n"));
+#endif
 
-static void populate_printers(void)
-{
-       FILE *fp;
-
-       if ((fp = popen("/usr/bin/lpstat -v", "r")) != NULL) {
-               char buf[BUFSIZ];
-
-               while (fgets(buf, sizeof (buf), fp) != NULL) {
-                       printer_t *ptmp;
-                       char *name, *tmp;
-
-                       /* eat "system/device for " */
-                       if (((tmp = strchr(buf, ' ')) == NULL) ||
-                           ((tmp = strchr(++tmp, ' ')) == NULL))
-                               continue;
-                       name = ++tmp;
-
-                       /* truncate the ": ..." */
-                       if ((tmp = strchr(name, ':')) != NULL)
-                               *tmp = '\0';
-
-                       /* add it to the cache */
-                       if ((ptmp = malloc(sizeof (*ptmp))) != NULL) {
-                               ZERO_STRUCTP(ptmp);
-                               ptmp->name = strdup(name);
-                               ptmp->next = printers;
-                               printers = ptmp;
-                       }
+       if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL)
+       {
+#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"));
+                       file_lines_free(scheduler);
+                        return True;
+                }
+                else{
+                        DEBUG(3,("Scheduler is not running!!!\n"));
+                       file_lines_free(scheduler);
+                       return False;
                }
-               pclose(fp);
-       } else {
-               DEBUG(0,( "Unable to run lpstat!\n"));
+#else
+               DEBUG(3,("No Printers found!!!\n"));
+               return False;
+#endif
        }
-}
 
+       for (i = 0; lines[i]; i++) {
+               char *name, *tmp;
+               char *buf = lines[i];
 
-/*
- * 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).
- */
-void sysv_printer_fn(void (*fn)(char *, char *))
-{
-       printer_t *tmp;
+               /* eat "system/device for " */
+               if (((tmp = strchr_m(buf, ' ')) == NULL) ||
+                   ((tmp = strchr_m(++tmp, ' ')) == NULL))
+                       continue;
 
-       if (printers == NULL)
-               populate_printers();
-       for (tmp = printers; tmp != NULL; tmp = tmp->next)
-               (fn)(tmp->name, "");
-}
+               /*
+                * In case we're only at the "for ".
+                */
 
+               if(!strncmp("for ", ++tmp, 4)) {
+                       tmp=strchr_m(tmp, ' ');
+                       tmp++;
+               }
 
-/*
- * 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);
+               /* Eat whitespace. */
+
+               while(*tmp == ' ')
+                       ++tmp;
+
+               /*
+                * On HPUX there is an extra line that can be ignored.
+                * d.thibadeau 2001/08/09
+                */
+               if(!strncmp("remote to", tmp, 9))
+                       continue;
+
+               name = tmp;
+
+               /* truncate the ": ..." */
+               if ((tmp = strchr_m(name, ':')) != NULL)
+                       *tmp = '\0';
+               
+               /* add it to the cache */
+               if (!pcap_cache_add(name, NULL)) {
+                       file_lines_free(lines);
+                       return False;
+               }
+       }
+
+       file_lines_free(lines);
+       return True;
 }
 
 #else