Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added examples to the build and tests #723

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NULL =

SAFE_VERSION = @XMLSEC_VERSION_SAFE@
SUBDIRS = include src
SUBDIRS = include src examples
if XMLSEC_APPS
SUBDIRS += apps
endif
Expand Down Expand Up @@ -41,7 +41,6 @@ DISTCLEANFILES = \

EXTRA_DIST = \
m4 \
examples \
scripts \
tests \
win32 \
Expand All @@ -64,10 +63,6 @@ EXTRA_DIST = \
xmlsec1.m4 \
$(NULL)

EXTRA_CLEAN = \
examples \
$(NULL)

ABS_SRCDIR=@abs_srcdir@
ABS_BUILDDIR=@abs_builddir@
XMLSEC_OPENSSL_TEST_CONFIG=@OPENSSL_TEST_CONFIG@
Expand Down Expand Up @@ -103,7 +98,10 @@ docs-clean:
docs-man:
@(cd man && $(MAKE) docs)

check: check-all check-info
check: check-examples check-all check-info

check-examples:
@(cd examples && $(MAKE) check)

check-all: $(TEST_APP)
for crypto in $(CHECK_CRYPTO_LIST) ; do \
Expand Down Expand Up @@ -192,13 +190,3 @@ perfcheck: $(TEST_APP)

dist-hook:

cleantar:
@($(RM) -f xmlsec*.tar.gz COPYING.LIB)

tar-release: clean cleantar
@(unset CDPATH && $(MAKE) dist)

rpm: cleantar tar-release
@(unset CDPATH && rpmbuild -ta $(distdir).tar.gz)

rpm-release: clean cleantar rpm
3 changes: 2 additions & 1 deletion apps/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ AM_CFLAGS = \
-I../include \
-I$(top_srcdir)/include \
$(XMLSEC_DEFINES) \
$(XMLSEC_APP_DEFINES) \
@XMLSEC_EXTRA_APP_CFLAGS@ \
$(CRYPTO_INCLUDES) \
$(LIBXSLT_CFLAGS) \
$(LIBXML_CFLAGS) \
Expand All @@ -65,6 +65,7 @@ xmlsec1_SOURCES = \
xmlsec1_LDFLAGS = \
@XMLSEC_STATIC_BINARIES@ \
@XMLSEC_EXTRA_LDFLAGS@ \
@XMLSEC_EXTRA_APP_LDFLAGS@ \
$(CRYPTO_LD_FLAGS) \
$(NULL)

Expand Down
6 changes: 3 additions & 3 deletions apps/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static xmlSecAppCmdLineParamPtr xmlSecAppCmdLineParamsListFind (xmlSecAppCmdLin
xmlSecAppCmdLineParamTopic topics,
const char* name);
static int xmlSecAppCmdLineParamRead (xmlSecAppCmdLineParamPtr param,
const char** argv,
char** argv,
int argc,
int pos);
static int xmlSecAppCmdLineTimeParamRead (const char* str,
Expand Down Expand Up @@ -88,7 +88,7 @@ xmlSecAppCmdLineParamGetTime(xmlSecAppCmdLineParamPtr param, time_t def) {
int
xmlSecAppCmdLineParamsListParse(xmlSecAppCmdLineParamPtr* params,
xmlSecAppCmdLineParamTopic topics,
const char** argv, int argc, int pos) {
char** argv, int argc, int pos) {
xmlSecAppCmdLineParamPtr param;
int ii;
int ret;
Expand Down Expand Up @@ -234,7 +234,7 @@ xmlSecAppCmdLineParamsListFind(xmlSecAppCmdLineParamPtr* params, xmlSecAppCmdLin
}

static int
xmlSecAppCmdLineParamRead(xmlSecAppCmdLineParamPtr param, const char** argv, int argc, int pos) {
xmlSecAppCmdLineParamRead(xmlSecAppCmdLineParamPtr param, char** argv, int argc, int pos) {
xmlSecAppCmdLineValuePtr value;
xmlSecAppCmdLineValuePtr prev = NULL;
char* buf;
Expand Down
2 changes: 1 addition & 1 deletion apps/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ time_t xmlSecAppCmdLineParamGetTime (xmlSecAppCmdLineParamPt

int xmlSecAppCmdLineParamsListParse (xmlSecAppCmdLineParamPtr* params,
xmlSecAppCmdLineParamTopic topics,
const char** argv,
char** argv,
int argc,
int pos);
void xmlSecAppCmdLineParamsListClean (xmlSecAppCmdLineParamPtr* params);
Expand Down
151 changes: 83 additions & 68 deletions apps/xmlsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,69 +1176,96 @@ static int xmlSecAppInputReadCallback (void * context,
static int xmlSecAppInputCloseCallback (void * context);

static int xmlSecAppExecute (xmlSecAppCommand command,
const char** utf8_argv,
char** argv,
int argc);


#if defined(XMLSEC_WINDOWS) && defined(UNICODE) && defined(__MINGW32__)
int wmain(int argc, wchar_t* argv[]);
#endif /* defined(XMLSEC_WINDOWS) && defined(UNICODE) && defined(__MINGW32__) */

xmlSecKeysMngrPtr g_keysManager = NULL;
int g_repeats = 1;
int g_printDebug = 0;
int g_printVerboseDebug = 0;
int g_blockNetworkIO = 0;
clock_t g_totalTime = 0;
const char* g_xmlSecCryptoLibrary = NULL;
const char* gOutputFilename = NULL;
/* Special handling for command line parameters on Windows is needed */
static int real_main(int argc, char** argv);

#if defined(XMLSEC_WINDOWS) && defined(UNICODE)
int wmain(int argc, wchar_t *argv[]) {
#else /* defined(XMLSEC_WINDOWS) && defined(UNICODE) */
int main(int argc, const char **argv) {
#endif /* defined(XMLSEC_WINDOWS) && defined(UNICODE) */
#if defined(XMLSEC_WINDOWS)

#if defined(UNICODE) && defined(__MINGW32__)
int wmain(int argc, wchar_t* argv[]);
#endif /*defined(UNICODE) && defined(__MINGW32__) */

#if defined(UNICODE)
int wmain(int argc, wchar_t* argv[]) {
#else /* defined(UNICODE) */
int main(int argc, char** argv) {
#endif /* defined(UNICODE) */
char** utf8_argv = NULL;
size_t utf8_argv_size;
int ii;
#endif /* defined(XMLSEC_WINDOWS) */
const char** utf8_argv = NULL; /* TODO: this should be xmlChar** but it will break things downstream */
xmlSecAppCmdLineParamTopic cmdLineTopics;
xmlSecAppCommand command, subCommand;
int pos;
int res = 1;
int ret;

#if defined(XMLSEC_WINDOWS)
/* convert command line to UTF8 from locale or UNICODE */
utf8_argv_size = sizeof(char*) * (size_t)argc;
utf8_argv = (const char**)xmlMalloc(utf8_argv_size);
if(utf8_argv == NULL) {
utf8_argv = (char**)xmlMalloc(utf8_argv_size);
if (utf8_argv == NULL) {
fprintf(stderr, "Error: can not allocate memory (" XMLSEC_SIZE_T_FMT " bytes)\n",
utf8_argv_size);
goto done;
return(1);
}
memset((char**)utf8_argv, 0, utf8_argv_size);
for(ii = 0; ii < argc; ++ii) {
utf8_argv[ii] = (const char*)xmlSecWin32ConvertTstrToUtf8(argv[ii]);
if(utf8_argv[ii] == NULL) {
memset(utf8_argv, 0, utf8_argv_size);
for (ii = 0; ii < argc; ++ii) {
utf8_argv[ii] = (char*)xmlSecWin32ConvertTstrToUtf8(argv[ii]);
if (utf8_argv[ii] == NULL) {
fprintf(stderr, "Error: can not convert command line parameter at position %d to UTF8\n", ii);
goto done;
return(1);
}
}

/* call real main function */
res = real_main(argc, utf8_argv);

/* cleanup */
if (utf8_argv != NULL) {
for (ii = 0; ii < argc; ++ii) {
if (utf8_argv[ii] != NULL) {
xmlFree(BAD_CAST utf8_argv[ii]);
utf8_argv[ii] = NULL;
}
}
xmlFree(BAD_CAST utf8_argv);
utf8_argv = NULL;
}

return(res);
}

#else /* defined(XMLSEC_WINDOWS) */
utf8_argv = argv;
int main(int argc, char** argv) {
return(real_main(argc, argv));
}
#endif /* defined(XMLSEC_WINDOWS) */

xmlSecKeysMngrPtr g_keysManager = NULL;
int g_repeats = 1;
int g_printDebug = 0;
int g_printVerboseDebug = 0;
int g_blockNetworkIO = 0;
clock_t g_totalTime = 0;
const char* g_xmlSecCryptoLibrary = NULL;
const char* gOutputFilename = NULL;

static int
real_main(int argc, char** argv) {
xmlSecAppCmdLineParamTopic cmdLineTopics;
xmlSecAppCommand command, subCommand;
int pos;
int res = 1;
int ret;

/* read the command (first argument) */
if(argc < 2) {
if((argv == NULL) || (argc < 2)) {
fprintf(stderr, "Error: not enough arguments\n");
xmlSecAppPrintUsage();
goto done;
}
command = xmlSecAppParseCommand(utf8_argv[1], &cmdLineTopics, &subCommand);
command = xmlSecAppParseCommand(argv[1], &cmdLineTopics, &subCommand);
if(command == xmlSecAppCommandUnknown) {
fprintf(stderr, "Error: unknown command \"%s\"\n", utf8_argv[1]);
fprintf(stderr, "Error: unknown command \"%s\"\n", argv[1]);
xmlSecAppPrintUsage();
res = 0;
goto done;
Expand All @@ -1256,7 +1283,7 @@ int main(int argc, const char **argv) {
}

/* parse command line */
pos = xmlSecAppCmdLineParamsListParse(parameters, cmdLineTopics, utf8_argv, argc, 2);
pos = xmlSecAppCmdLineParamsListParse(parameters, cmdLineTopics, argv, argc, 2);
if(pos < 0) {
fprintf(stderr, "Error: invalid parameters\n");
xmlSecAppPrintUsage();
Expand Down Expand Up @@ -1287,7 +1314,7 @@ int main(int argc, const char **argv) {
}

/* actual processing: skip all the parameters we already parsed */
ret = xmlSecAppExecute(command, utf8_argv + pos, argc - pos);
ret = xmlSecAppExecute(command, argv + pos, argc - pos);
if(ret < 0) {
goto done;
}
Expand All @@ -1298,18 +1325,6 @@ int main(int argc, const char **argv) {
done:

xmlSecAppCmdLineParamsListClean(parameters);
#if defined(XMLSEC_WINDOWS)
if(utf8_argv != NULL) {
for(ii = 0; ii < argc; ++ii) {
if(utf8_argv[ii] != NULL) {
xmlFree(BAD_CAST utf8_argv[ii]);
utf8_argv[ii] = NULL;
}
}
xmlFree(BAD_CAST utf8_argv);
utf8_argv = NULL;
}
#endif /* defined(XMLSEC_WINDOWS) */

#if defined(_MSC_VER) && defined(_CRTDBG_MAP_ALLOC)
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
Expand All @@ -1327,7 +1342,7 @@ int main(int argc, const char **argv) {


static int
xmlSecAppExecute(xmlSecAppCommand command, const char** utf8_argv, int argc) {
xmlSecAppExecute(xmlSecAppCommand command, char** argv, int argc) {
const char* tmp = NULL;
int res = - 1;
int ii;
Expand Down Expand Up @@ -1413,11 +1428,11 @@ xmlSecAppExecute(xmlSecAppCommand command, const char** utf8_argv, int argc) {
break;
case xmlSecAppCommandCheckKeyData:
for(ii = 0; ii < argc; ++ii) {
if(xmlSecAppCheckKeyData(utf8_argv[ii]) < 0) {
fprintf(stderr, "Error: key data \"%s\" not found\n", utf8_argv[ii]);
if(xmlSecAppCheckKeyData(argv[ii]) < 0) {
fprintf(stderr, "Error: key data \"%s\" not found\n", argv[ii]);
goto done;
} else {
fprintf(stdout, "Key data \"%s\" found\n", utf8_argv[ii]);
fprintf(stdout, "Key data \"%s\" found\n", argv[ii]);
}
}
break;
Expand All @@ -1426,35 +1441,35 @@ xmlSecAppExecute(xmlSecAppCommand command, const char** utf8_argv, int argc) {
break;
case xmlSecAppCommandCheckTransforms:
for(ii = 0; ii < argc; ++ii) {
if(xmlSecAppCheckTransform(utf8_argv[ii]) < 0) {
fprintf(stderr, "Error: transform \"%s\" not found\n", utf8_argv[ii]);
if(xmlSecAppCheckTransform(argv[ii]) < 0) {
fprintf(stderr, "Error: transform \"%s\" not found\n", argv[ii]);
goto done;
} else {
fprintf(stdout, "Transforms \"%s\" found\n", utf8_argv[ii]);
fprintf(stdout, "Transforms \"%s\" found\n", argv[ii]);
}
}
break;
case xmlSecAppCommandKeys:
for(ii = 0; ii < argc; ++ii) {
if(xmlSecAppCryptoSimpleKeysMngrSave(g_keysManager, utf8_argv[ii], xmlSecKeyDataTypeAny) < 0) {
fprintf(stderr, "Error: failed to save keys to file \"%s\"\n", utf8_argv[ii]);
if(xmlSecAppCryptoSimpleKeysMngrSave(g_keysManager, argv[ii], xmlSecKeyDataTypeAny) < 0) {
fprintf(stderr, "Error: failed to save keys to file \"%s\"\n", argv[ii]);
goto done;
}
}
break;
#ifndef XMLSEC_NO_XMLDSIG
case xmlSecAppCommandSign:
for(ii = 0; ii < argc; ++ii) {
if(xmlSecAppSignFile(utf8_argv[ii], gOutputFilename) < 0) {
fprintf(stderr, "Error: failed to sign file \"%s\"\n", utf8_argv[ii]);
if(xmlSecAppSignFile(argv[ii], gOutputFilename) < 0) {
fprintf(stderr, "Error: failed to sign file \"%s\"\n", argv[ii]);
goto done;
}
}
break;
case xmlSecAppCommandVerify:
for(ii = 0; ii < argc; ++ii) {
if(xmlSecAppVerifyFile(utf8_argv[ii]) < 0) {
fprintf(stderr, "Error: failed to verify file \"%s\"\n", utf8_argv[ii]);
if(xmlSecAppVerifyFile(argv[ii]) < 0) {
fprintf(stderr, "Error: failed to verify file \"%s\"\n", argv[ii]);
goto done;
}
}
Expand All @@ -1472,16 +1487,16 @@ xmlSecAppExecute(xmlSecAppCommand command, const char** utf8_argv, int argc) {
#ifndef XMLSEC_NO_XMLENC
case xmlSecAppCommandEncrypt:
for(ii = 0; ii < argc; ++ii) {
if(xmlSecAppEncryptFile(utf8_argv[ii], gOutputFilename) < 0) {
fprintf(stderr, "Error: failed to encrypt file with template \"%s\"\n", utf8_argv[ii]);
if(xmlSecAppEncryptFile(argv[ii], gOutputFilename) < 0) {
fprintf(stderr, "Error: failed to encrypt file with template \"%s\"\n", argv[ii]);
goto done;
}
}
break;
case xmlSecAppCommandDecrypt:
for(ii = 0; ii < argc; ++ii) {
if(xmlSecAppDecryptFile(utf8_argv[ii], gOutputFilename) < 0) {
fprintf(stderr, "Error: failed to decrypt file \"%s\"\n", utf8_argv[ii]);
if(xmlSecAppDecryptFile(argv[ii], gOutputFilename) < 0) {
fprintf(stderr, "Error: failed to decrypt file \"%s\"\n", argv[ii]);
goto done;
}
}
Expand Down
Loading
Loading