/*
 *  File: sadbed_help.c
 *  Author: Claes M. Nyberg <md0claes@mdstud.chalmers.se>
 *  Description: Help routines for interactive SADB edit
 *  Version: 1.0
 *  Date: Tue Dec 16 22:38:51 CET 2003
 *
 *  Copyright (c) 2003 Claes M. Nyberg <md0claes@mdstud.chalmers.se>
 *  All rights reserved, all wrongs reversed.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *  3. The name of author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 *  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 *  THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#include <stdio.h>
#include "sadbed.h"

/*
 * Print help for import
 */
static void
help_import(void)
{
	printf("\nImport entries from file\n");
	printf("Usage: %s file [option(s)]\n", IACT_IMPORT);
	printf("    Options:\n");
	printf("      -d     Target file is not encrypted\n");
	printf("      -e ip  Only import entry with ip\n\n");
}

/*
 * Print help for print
 */
static void
help_print()
{
	printf("\nPrint contents for entry or all loaded entries\n");
	printf("Usage: %s [ip] [option(s)]\n", IACT_PRINT);
	printf("    Options:\n");
	printf("      -k     Print key (hex)\n");
	printf("      -p     Print packets\n\n");
}

/*
 * Print help for list
 */
static void
help_list(void)
{
	printf("\nList all loaded entries\n\n");
	printf("Usage: %s\n\n", IACT_LIST);
}

/*
 * Print help for quit
 */
static void
help_quit(void)
{
	printf("\nQuit interactive session\n");
	printf("Usage: %s\n\n", IACT_QUIT);
}

/*
 * Print help for delete
 */
static void
help_delete(void)
{
	printf("\nDelete entry\n");
	printf("Usage: %s ip [ip..]\n\n", IACT_DELETE);
}

/*
 * Print help for copy
 */
static void
help_copy(void)
{
	printf("\nCopy entry\n");
	printf("Usage: %s srcip destip [-p]\n", IACT_COPY);
	printf("    -p  Do not set the destination address in packets\n");
	printf("        that matches srcip to destip\n\n");
}

/*
 * Print help for dump
 */
static void
help_dump(void)
{
	printf("\nWrite all or specific entries to file\n");
	printf("Usage: %s file [ip..]\n\n", IACT_DUMP);
}


/*
 * Print help for resolve
 */
static void
help_resolve(void)
{
	printf("\nSet resolving of hostnames, or print state\n");
	printf("Usage: %s [yes|no]\n\n", IACT_RESOLVE);
}

/*
 * Print help for verbose
 */
static void
help_verbose(void)
{
	printf("\nSet verbose or print status\n");
	printf("Usage: %s [yes|no]\n\n", IACT_VERBOSE);
}

/*
 * Print help for save
 */
static void
help_save(void)
{
	printf("\nSave to loaded file using the same key\n");
	printf("Usage: %s\n\n", IACT_SAVE);
}

/*
 * Print help for autosave
 */
static void
help_autosave(void)
{
	printf("\nSave to loaded file on exit\n");
	printf("Usage: %s [yes|no]\n\n", IACT_AUTOSAVE);
}


/*
 * Print short summary of all commands
 */
static void
printall(void)
{
	printf("%s [yes|no]\n", IACT_AUTOSAVE);
	printf("%s srcip destip [-p]\n", IACT_COPY);
	printf("%s ip [ip..]\n", IACT_DELETE);
	printf("%s file [ip..]\n", IACT_DUMP);
	printf("%s [command]\n", IACT_HELP);
	printf("%s file [-de ip]\n", IACT_IMPORT);
	printf("%s\n", IACT_LIST);
	printf("%s [ip] [-kp]\n", IACT_PRINT);
	printf("%s [yes|no]\n", IACT_RESOLVE);
	printf("%s\n", IACT_QUIT);
	printf("%s\n", IACT_SAVE);
	printf("%s [yes|no]\n", IACT_VERBOSE);
}

/*
 * Interactive help
 */
void
interactive_help(u_char *cmd)
{
	if (cmd == NULL)
		printall();

	else if (!strncasecmp(cmd, IACT_IMPORT,
    		sizeof(IACT_IMPORT)-1))
		help_import();

	else if (!strncasecmp(cmd, IACT_PRINT,
		sizeof(IACT_PRINT)-1))
		help_print();

	else if (!strncasecmp(cmd, IACT_LIST,
			sizeof(IACT_LIST)-1))
		help_list();
	
	else if (!strncasecmp(cmd, IACT_QUIT,
			sizeof(IACT_QUIT)-1))
		help_quit();
	
	else if (!strncasecmp(cmd, IACT_DELETE,
			sizeof(IACT_DELETE)-1))
		help_delete();
	
	else if (!strncasecmp(cmd, IACT_DUMP,
			sizeof(IACT_DUMP)-1))
		help_dump();

	else if (!strncasecmp(cmd, IACT_COPY,
			sizeof(IACT_COPY)-1))
		help_copy();
		
	else if (!strncasecmp(cmd, IACT_RESOLVE,
			sizeof(IACT_RESOLVE)-1))
		help_resolve();

	else if (!strncasecmp(cmd, IACT_VERBOSE,
			sizeof(IACT_VERBOSE)-1))
		help_verbose();
	
	else if (!strncasecmp(cmd, IACT_SAVE,
			sizeof(IACT_SAVE)-1))
		help_save();
	
	else if (!strncasecmp(cmd, IACT_AUTOSAVE,
			sizeof(IACT_AUTOSAVE)-1))
		help_autosave();
	
	else 
		printall();
}

