+class FileFilter {
+public:
+ // It is valid for program to be NULL or empty; if so, no filtering is
+ // done.
+ static FileFilter *New(int fd, const char *program);
+
+ // Wait for the filter process to terminate.
+ int wait();
+
+ // Accessors for the file descriptors.
+ int get_raw_fd() const { return fd_raw; }
+ int get_wrapped_fd() const { return fd_wrapped; }
+
+private:
+ FileFilter(int raw, int wrapped, pid_t pid);
+
+ // Launch a process to filter data written to a file descriptor. fd_out is
+ // the file descriptor where the filtered data should be written. program
+ // is the filter program to execute (a single string which will be
+ // interpreted by /bin/sh). The return value is a file descriptor to which
+ // the data to be filtered should be written. The process ID of the filter
+ // process is stored at address filter_pid if non-NULL.
+ static int spawn_filter(int fd_out, const char *program, pid_t *filter_pid);
+
+ // The original file descriptor passed when creating the FileFilter object.
+ int fd_raw;
+
+ // The wrapped file descriptor: writes here are piped through the filter
+ // program.
+ int fd_wrapped;
+
+ // The filter process if one was launched, or -1 if there is no filter
+ // program.
+ pid_t pid;
+};
+