summaryrefslogtreecommitdiffstats
path: root/magicfilter.h
blob: d74a654d1512f712663fbe54829f2fe4e4c88291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 *  magicfilter.h
 *
 *  Copyright  1993-96 H. Peter Anvin
 *
 *  Header file for the magic lpr/lpd filter
 */

#include "config.h"
#include <stdio.h>
#ifdef HAVE_PATHS_H
#include <paths.h>
#endif
#include <string.h>
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <ctype.h>

/*
 * These *must* be in the same order as the table in parseconfig.c!
 */
enum actions
{
  ACT_CAT,			/* Just output the file */
  ACT_DROP,			/* Silently ignore the file */
  ACT_REJECT,			/* Mail the user and complain */
  ACT_FILTER,			/* Run through filter, then done */
  ACT_PIPE,			/* Pipe through command, then reprocess */
  ACT_ADDCR,			/* Like ACT_CAT, but \n -> \r\n, \f -> \r\f */
  ACT_PS,			/* Like ACT_ADDCR, but add PSEOJ (^D) at end */
  ACT_FFILTER,			/* Like ACT_FILTER, but use a temp file */
  ACT_FPIPE,			/* Like ACT_PIPETHRU, but use a temp file */
  ACT_RFILTER,			/* Use a different output filedescriptor */
  ACT_RPIPE,			/* d:o */
  ACT_RFFILTER,			/* d:o */
  ACT_RFPIPE,			/* d:o */
  
  ACT_ERR = -1
};

/*
 * Special magic actions
 */

#define MAG_ERR       (-1)	/* Invalid line */
#define MAG_COMMENT   (-2)	/* Line is blank or comment */
#define MAG_DEFAULT   (-3)	/* Action is the default action */
#define MAG_SET       (-4)	/* Action is a set command */

struct datatype
{
  struct datatype *next;	/* Linked list pointer */
  int offset;			/* Where in file is ID string */
  int length;			/* Length of ID string */
  char *magic;			/* Expected ID string */
  char *mask;			/* Mask for ID string */
  int action;			/* What to do with it */
  char *command;		/* Command line, or for ACT_REJECT, */
				/* text of complaint message */
};

/* Stuff to make stupid C compilers happy, and to fill in gaps */

#ifdef NOVOID
#define void
#endif
#ifdef NOCONST
#define const
#endif
#ifndef DEBUG
#define DEBUG 0
#endif

/* Function prototypes */

struct datatype *load_config(char *file, int *in_block_size);
int getoffset(char *p, char **endpos);
int getmagic(char *p, char **endpos, char *magic, char *mask);
enum actions getaction(char *pos, char **cmd);

/* Global variables */

extern int debug_flag;
extern char NO_WILD[];		/* Used as senitel value by getmagic() */