1/*
2 * The Initial Developer of the Original Code is International
3 * Business Machines Corporation. Portions created by IBM
4 * Corporation are Copyright (C) 2005, 2006 International Business
5 * Machines Corporation. All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the Common Public License as published by
9 * IBM Corporation; either version 1 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * Common Public License for more details.
16 *
17 * You should have received a copy of the Common Public License
18 * along with this program; if not, a copy can be viewed at
19 * http://www.opensource.org/licenses/cpl1.0.php.
20 */
21
22#ifndef __TPM_UTILS_H
23#define __TPM_UTILS_H
24
25#ifdef ENABLE_NLS
26#include <libintl.h>
27#include <locale.h>
28#define _(String) gettext(String)
29#define N_(String) String
30#else
31#define setlocale(category, local)
32#define bindtextdomain(package, localedir)
33#define textdomain(package);
34#define _(String) String
35#define N_(String) String
36#endif
37
38#include <string.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <stdarg.h>
42//#define GNU_SOURCE
43#include <getopt.h>
44
45#ifndef BOOL
46#define BOOL int
47#endif
48
49#ifndef FALSE
50#define FALSE 0
51#endif
52
53#ifndef TRUE
54#define TRUE (!FALSE)
55#endif
56
57#define CMD_VERSION             PACKAGE_VERSION
58
59#define LOG_NONE                _("none")
60#define LOG_LEVEL_NONE          0
61#define LOG_ERROR               _("error")
62#define LOG_LEVEL_ERROR         1
63#define LOG_INFO                _("info")
64#define LOG_LEVEL_INFO          2
65#define LOG_DEBUG               _("debug")
66#define LOG_LEVEL_DEBUG         3
67
68typedef int (*CmdOptParser)( const int aOpt, const char *aOptArg );
69typedef void (*CmdHelpFunction)( const char *aCmd );
70
71void initIntlSys( );
72
73int genericOptHandler( int a_iNumArgs, char **a_pszArgs,
74		       const char *a_pszShortOpts,
75		       struct option *a_psLongOpts, int a_iNumOpts,
76		       CmdOptParser, CmdHelpFunction );
77char *getPlainPasswd( const char* a_pszPrompt, BOOL a_bConfirm );
78#ifdef TSS_LIB_IS_12
79char *_getPasswd12( const char *a_pszPrompt, int *a_iLen, BOOL a_bConfirm, BOOL a_uUseUnicode);
80char *getPasswd12( const char *a_pszPrompt, int *a_iLen, BOOL a_bConfirm );
81
82#define _GETPASSWD	_getPasswd12
83#define GETPASSWD	getPasswd12
84#else
85char *getPasswd( const char *a_pszPrompt, int *a_iLen, BOOL a_bConfirm );
86
87#define _GETPASSWD	_getPasswd
88#define GETPASSWD	getPasswd
89#endif
90char *_getPasswd( const char *a_pszPrompt, int *a_iLen, BOOL a_bConfirm, BOOL a_bUseUnicode);
91void  shredPasswd( char *a_pszPasswd );
92char *getReply( const char *a_pszPrompt, int a_iMaxLen );
93
94extern int iLogLevel;
95extern BOOL useUnicode;
96
97int logHex( int a_iLen, void *a_pData );
98int logMsg( const char *a_pszFormat, ... );
99int logDebug( const char *a_pszFormat, ... );
100int logInfo( const char *a_pszFormat, ... );
101int logError( const char *a_pszFormat, ... );
102
103int logProcess( FILE *a_pStream, const char *a_pszFormat, va_list a_vaArgs );
104int logIt( FILE *a_pStream, const char *a_pszFormat, va_list a_vaArgs );
105
106void  logSuccess( const char *a_pszCmd );
107void  logCmdOption( const char *a_pszOption, const char *a_pszDescr );
108void  logUnicodeCmdOption( );
109void  logGenericOptions( );
110void  logCmdHelp( const char *a_pszCmd );
111void  logCmdHelpEx( const char *a_pszCmd, char *a_pszArgs[], char *a_pszArgDescs[] );
112char *logBool( BOOL aValue );
113void  logOwnerPassCmdOption( );
114void  logNVIndexCmdOption( );
115
116#endif
117