]> arthur.barton.de Git - netatalk.git/blobdiff - etc/papd/magics.c
Remove bdb env on exit
[netatalk.git] / etc / papd / magics.c
index 800c1854271097d95de6be8e03969d3f2a8766a8..5e128e56099c4d3e8faa26240ae60ab9a587160b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: magics.c,v 1.11 2003-02-17 01:34:35 srittau Exp $
+ * $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.
 #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 :
@@ -38,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 :
@@ -50,6 +69,10 @@ int ps( infile, outfile, sat )
                lp_close();
                return( 0 );
 
+           case -2:
+               parser_error(outfile);
+               return( 0 );
+
            case -1 :
                return( 0 );
            }
@@ -59,6 +82,7 @@ int ps( infile, outfile, sat )
                    compush( comment );
                    continue;   /* top of for (;;) */
                }
+#if 0
                infile->pf_state &= ~PF_BOT;
 
                /* set up spool file */
@@ -66,18 +90,17 @@ int ps( infile, outfile, sat )
                    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;
@@ -93,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 ) {
@@ -108,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;
@@ -126,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 ) {
                LOG(log_error, logtype_papd, "lp_open failed" );
                spoolerror( out, "Ignoring job." );
            }
+#endif
        } else {
            if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
                compush( comment );
@@ -141,16 +169,14 @@ 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;
@@ -164,6 +190,9 @@ int cm_psswitch( in, out, sat )
 
     case -1 :
        return( CH_MORE );
+
+    case -2 :
+        return( CH_ERROR );
     }
 
     stop = start + linelength;
@@ -178,7 +207,7 @@ 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 ) {
            LOG(log_error, logtype_papd, "cm_psswitch: can't find psquery!" );
@@ -193,9 +222,10 @@ int cm_psswitch( in, out, sat )
     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 },
 };