]> arthur.barton.de Git - netatalk.git/blobdiff - etc/papd/magics.c
Remove bdb env on exit
[netatalk.git] / etc / papd / magics.c
index 59fac7c291ba8b7994a142990e0d7bbeae0507ec..5e128e56099c4d3e8faa26240ae60ab9a587160b 100644 (file)
@@ -1,31 +1,51 @@
 /*
+ * $Id: magics.c,v 1.15 2009-10-13 22:55:37 didg Exp $
+ *
  * Copyright (c) 1990,1994 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
 
-#include <sys/syslog.h>
+#include <atalk/logger.h>
 #include <sys/param.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
+#include <netatalk/at.h>
+
 #include "file.h"
 #include "comment.h"
 #include "lp.h"
 
-int ps( infile, outfile, sat )
-    struct papfile     *infile, *outfile;
-    struct sockaddr_at *sat;
+static int state=0;
+
+static void parser_error(struct papfile *outfile)
+{
+                spoolerror( outfile, "Comments error, Ignoring job." );
+               outfile->pf_state |= PF_EOF;
+               lp_close();
+}
+
+int ps( struct papfile *infile, struct papfile *outfile, struct sockaddr_at *sat)
 {
     char                       *start;
     int                                linelength, crlflength;
     struct papd_comment                *comment;
 
     for (;;) {
+        if ( infile->pf_state & PF_STW ) {
+               infile->pf_state &= ~PF_STW;
+               /* set up spool file */
+               if ( lp_open( outfile, sat ) < 0 && !state) {
+                   LOG(log_error, logtype_papd, "lp_open failed" );
+                   spoolerror( outfile, "Ignoring job." );
+               }
+               state = 1;
+       }       
        if ( (comment = compeek()) ) {
            switch( (*comment->c_handler)( infile, outfile, sat )) {
            case CH_DONE :
@@ -34,10 +54,13 @@ int ps( infile, outfile, sat )
            case CH_MORE :
                return( CH_MORE );
 
+           case CH_ERROR :
+               parser_error(outfile);
+               return( 0 );
+
            default :
                return( CH_ERROR );
            }
-
        } else {
            switch ( markline( infile, &start, &linelength, &crlflength )) {
            case 0 :
@@ -46,6 +69,10 @@ int ps( infile, outfile, sat )
                lp_close();
                return( 0 );
 
+           case -2:
+               parser_error(outfile);
+               return( 0 );
+
            case -1 :
                return( 0 );
            }
@@ -55,25 +82,25 @@ int ps( infile, outfile, sat )
                    compush( comment );
                    continue;   /* top of for (;;) */
                }
+#if 0
                infile->pf_state &= ~PF_BOT;
 
                /* set up spool file */
                if ( lp_open( outfile, sat ) < 0 ) {
-                   syslog( LOG_ERR, "lp_open failed" );
+                   LOG(log_error, logtype_papd, "lp_open failed" );
                    spoolerror( outfile, "Ignoring job." );
                }
+#endif
            }
 
            /* write to file */
-           lp_write( start, linelength + crlflength );
+           lp_write( infile, start, linelength + crlflength );
            CONSUME( infile, linelength + crlflength );
        }
     }
 }
 
-int cm_psquery( in, out, sat )
-    struct papfile     *in, *out;
-    struct sockaddr_at *sat;
+int cm_psquery( struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
 {
     struct papd_comment        *comment;
     char               *start;
@@ -89,6 +116,9 @@ int cm_psquery( in, out, sat )
 
        case -1 :
            return( CH_MORE );
+
+        case -2 :
+            return( CH_ERROR );
        }
 
        if ( in->pf_state & PF_BOT ) {
@@ -104,9 +134,7 @@ int cm_psquery( in, out, sat )
     }
 }
 
-int cm_psadobe( in, out, sat )
-    struct papfile     *in, *out;
-    struct sockaddr_at *sat;
+int cm_psadobe( struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
 {
     char               *start;
     int                        linelength, crlflength;
@@ -122,14 +150,18 @@ int cm_psadobe( in, out, sat )
 
        case -1 :
            return( CH_MORE );
-       }
 
+        case -2 :
+            return( CH_ERROR );
+       }
        if ( in->pf_state & PF_BOT ) {
            in->pf_state &= ~PF_BOT;
+#if 0
            if ( lp_open( out, sat ) < 0 ) {
-               syslog( LOG_ERR, "lp_open failed" );
+               LOG(log_error, logtype_papd, "lp_open failed" );
                spoolerror( out, "Ignoring job." );
            }
+#endif
        } else {
            if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
                compush( comment );
@@ -137,20 +169,17 @@ int cm_psadobe( in, out, sat )
            }
        }
 
-       lp_write( start, linelength + crlflength );
+       lp_write( in, start, linelength + crlflength );
        CONSUME( in, linelength + crlflength );
     }
 }
 
 char   *Query = "Query";
 
-int cm_psswitch( in, out, sat )
-    struct papfile     *in, *out;
-    struct sockaddr_at *sat;
+int cm_psswitch(struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
 {
     char               *start, *stop, *p;
     int                        linelength, crlflength;
-    struct papd_comment        *comment = compeek();
 
     switch ( markline( in, &start, &linelength, &crlflength )) {
     case 0 :
@@ -161,6 +190,9 @@ int cm_psswitch( in, out, sat )
 
     case -1 :
        return( CH_MORE );
+
+    case -2 :
+        return( CH_ERROR );
     }
 
     stop = start + linelength;
@@ -175,24 +207,25 @@ int cm_psswitch( in, out, sat )
        }
     }
 
-    if ( stop - p >= strlen( Query ) &&
+    if ( (size_t)(stop - p) >= strlen( Query ) &&
            strncmp( p, Query, strlen( Query )) == 0 ) {
        if ( comswitch( magics, cm_psquery ) < 0 ) {
-           syslog( LOG_ERR, "cm_psswitch: can't find psquery!" );
+           LOG(log_error, logtype_papd, "cm_psswitch: can't find psquery!" );
            exit( 1 );
        }
     } else {
        if ( comswitch( magics, cm_psadobe ) < 0 ) {
-           syslog( LOG_ERR, "cm_psswitch: can't find psadobe!" );
+           LOG(log_error, logtype_papd, "cm_psswitch: can't find psadobe!" );
            exit( 1 );
        }
     }
     return( CH_DONE );
 }
 
+
 struct papd_comment    magics[] = {
-    { "%!PS-Adobe-3.0 Query",  0,                      cm_psquery, C_FULL },
-    { "%!PS-Adobe-3.0",                0,                      cm_psadobe, C_FULL },
-    { "%!PS-Adobe-",           0,                      cm_psswitch,    0 },
-    { 0 },
+    { "%!PS-Adobe-3.0 Query",  NULL,                   cm_psquery, C_FULL },
+    { "%!PS-Adobe-3.0",                NULL,                   cm_psadobe, C_FULL },
+    { "%!PS-Adobe-",           NULL,                   cm_psswitch,    0 },
+    { NULL,                    NULL,                   NULL,           0 },
 };