Main file for command-line application vanillapdf.tools. Print help and forwards parameters to the separate handlers.
#include "test.h"
int main(int argc, char *argv[]) {
int i = 0;
#if (defined(DEBUG) && defined(COMPILER_MICROSOFT_VISUAL_STUDIO))
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
if (argc < 2) {
return VANILLAPDF_TEST_ERROR_INVALID_PARAMETERS;
}
for (i = 2; i < argc; ++i) {
if (strcmp(argv[i], "-p") == 0 && (i + 1 < argc)) {
password = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-k") == 0 && (i + 1 < argc)) {
cert_path = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-kp") == 0 && (i + 1 < argc)) {
cert_password = argv[i + 1];
i++;
}else if (strcmp(argv[i], "-sc") == 0 && (i + 1 < argc)) {
signing_cert_file = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-scp") == 0 && (i + 1 < argc)) {
signing_cert_password = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-l") == 0 && (i + 1 < argc)) {
license_file = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-m") == 0 && (i + 1 < argc)) {
merge_file = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-sp") == 0) {
} else if (strcmp(argv[i], "-ss") == 0) {
} else if (strcmp(argv[i], "-se") == 0) {
} else if (strcmp(argv[i], "-si") == 0) {
} else if (strcmp(argv[i], "-q") == 0) {
} else {
return VANILLAPDF_TEST_ERROR_INVALID_PARAMETERS;
}
}
if (license_file != NULL) {
RETURN_ERROR_IF_NOT_SUCCESS(process_license_info(license_file));
}
RETURN_ERROR_IF_NOT_SUCCESS(set_quiet_mode(quiet_mode));
RETURN_ERROR_IF_NOT_SUCCESS(process_library_info());
RETURN_ERROR_IF_NOT_SUCCESS(process_logging());
RETURN_ERROR_IF_NOT_SUCCESS(process_constants());
RETURN_ERROR_IF_NOT_SUCCESS(File_Open(argv[1], &file));
RETURN_ERROR_IF_NOT_SUCCESS(File_Initialize(file));
RETURN_ERROR_IF_NOT_SUCCESS(File_IsEncrypted(file, &is_encrypted));
if (password == NULL && cert_path == NULL) {
}
if (password != NULL) {
RETURN_ERROR_IF_NOT_SUCCESS(File_SetEncryptionPassword(file, password));
}
if (cert_path != NULL) {
RETURN_ERROR_IF_NOT_SUCCESS(PKCS12Key_CreateFromFile(cert_path, cert_password, &pkcs12_key));
RETURN_ERROR_IF_NOT_SUCCESS(PKCS12Key_ToEncryptionKey(pkcs12_key, &encryption_key));
RETURN_ERROR_IF_NOT_SUCCESS(File_SetEncryptionKey(file, encryption_key));
RETURN_ERROR_IF_NOT_SUCCESS(EncryptionKey_Release(encryption_key));
RETURN_ERROR_IF_NOT_SUCCESS(PKCS12Key_Release(pkcs12_key));
}
} else {
if (password != NULL || cert_path != NULL) {
return VANILLAPDF_TEST_ERROR_INVALID_PASSWORD;
}
}
RETURN_ERROR_IF_NOT_SUCCESS(process_file(file, 0));
}
RETURN_ERROR_IF_NOT_SUCCESS(Document_OpenFile(file, &document));
RETURN_ERROR_IF_NOT_SUCCESS(process_document(document, 0));
RETURN_ERROR_IF_NOT_SUCCESS(process_document_save(document, password, cert_path, cert_password, 0));
RETURN_ERROR_IF_NOT_SUCCESS(process_document_merge(document, merge_file, password, cert_path, cert_password, 0));
if (signing_cert_file != NULL) {
RETURN_ERROR_IF_NOT_SUCCESS(process_document_sign(document, signing_cert_file, signing_cert_password, password, cert_path, cert_password, 0));
}
}
RETURN_ERROR_IF_NOT_SUCCESS(process_document_edit(document, password, cert_path, cert_password, 0));
}
}
RETURN_ERROR_IF_NOT_SUCCESS(Document_Release(document));
RETURN_ERROR_IF_NOT_SUCCESS(File_Release(file));
return VANILLAPDF_TEST_ERROR_SUCCESS;
}
Represents high-level file access handle.
Represents encryption key other than password.
Represents low-level file access handle.
PKCS#12 container is often used in cryptography to store asymmetric key pair.
const boolean_type VANILLAPDF_RV_TRUE
Represents the boolean true value.
const boolean_type VANILLAPDF_RV_FALSE
Represents the boolean false value.
int8_t boolean_type
Boolean type supported in C.
Definition c_types.h:31
const char * string_type
C-Style string.
Definition c_types.h:82