/**
 * Header file for eCryptfs decision graph
 * 
 * Copyright (C) 2004-2006 International Business Machines Corp.
 *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
 *              Trevor Highland <trevor.highland@gmail.com>
 *
 * The structs here are shared between kernel and userspace, so if you
 * are running a 64-bit kernel, you need to compile your userspace
 * applications as 64-bit binaries.
 *
 * 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 (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 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., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#ifndef DECISION_GRAPH_H
#define DECISION_GRAPH_H

#ifndef S_SPLINT_S
#include <stdio.h>
#endif

struct param_node;

struct val_node {
        void *val;
        struct val_node *prev;
};

struct ecryptfs_ctx;

struct transition_node {
        /* If val == NULL, then this matches every time. If token_id
         * == NULL_TOK, then trans_func must be defined. Else, if
         * trans_func is defined and returns NULL_TOK, then token_id
         * is used. */
        char *val;
        char *pretty_val;
        struct param_node *next_token;
        int (*trans_func)(struct ecryptfs_ctx *, struct param_node *,
			  struct val_node **, void **);
};

struct param_node {
#define MOUNT_ERROR -3
#define NULL_TOK -1
#define DEFAULT_TOK -2
        int num_mnt_opt_names;
#define MAX_NUM_MNT_OPT_NAMES 8
        char *mnt_opt_names[MAX_NUM_MNT_OPT_NAMES];
        char *prompt;
#define VAL_STR 0
#define VAL_HEX 1
        int val_type;
        char *val;
        char *default_val;
        void (*display_opts)(struct param_node *);
#define DISPLAY_TRANSITION_NODE_VALS    0x00000001
#define MASK_OUTPUT                     0x00000002
#define ALLOW_IMPLICIT_TRANSITION       0x00000004
#define NO_VALUE                        0x00000008
#define ECHO_INPUT			0x00000010
#define VERIFY_VALUE			0x00000020
#define STDIN_REQUIRED			0x00000040
#define PARAMETER_SET			0x00000080
        uint32_t flags;
        int num_transitions;
#define MAX_NUM_TRANSITIONS 8
        struct transition_node tl[MAX_NUM_TRANSITIONS];
};

int add_transition_node_to_param_node(struct param_node *param_node,
				      struct transition_node *trans_node);
void ecryptfs_dump_param_node(FILE *file_stream,
			      struct param_node *param_node, int depth,
			      int recursive);
void ecryptfs_dump_transition_node(FILE *file_stream,
				   struct transition_node *trans_node,
				   int depth, int recursive);
void ecryptfs_dump_decision_graph(FILE *file_stream,
				  struct param_node *param_node, int depth);
int ecryptfs_set_exit_param_on_graph(struct param_node *param_node,
				     struct param_node *exit_param_node);

struct ecryptfs_name_val_pair;

int eval_param_tree(struct ecryptfs_ctx *ctx, struct param_node *node,
		    struct ecryptfs_name_val_pair *nvp_head,
		    struct val_node **val_stack_head);

#endif
