diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -23,6 +23,7 @@ #include "gpg.h" #include "gpgedit_config.h" #include "strll.h" +#include "logger.h" void system_edit(char* file) { char cmd[256]; // Buffer for editor command @@ -50,8 +51,11 @@ void usage() { "\nUsage:\n\n" " gpgedit [-r user@host] <file.gpg>\n" "\nArguments:\n" + " -h,--help Print this help text\n" + " -q,--quiet Quiet output (only error and fatal)\n" " -r,--recipient Adds a recipient key to the encrypted output\n" - " -h,--help Print this help text\n"; + " -s,--silent No output (only if you have good karma)\n" + " -v,--verbose Verbose output (debug level)\n"; printf("%s\n", helptext); } @@ -63,8 +67,14 @@ void parseargs(int argc, char* argv[], struct gpgedit_config* config) { while(i < argc) { if(strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--recipient") == 0) { i++; - //printf("Adding recipient %s\n", argv[i]); + logger(LOG_DEBUG, "Adding recipient %s\n", argv[i]); strll_add(config->recipients, argv[i]); + } else if(strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) { + config->log_level = LOG_DEBUG; + } else if(strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0) { + config->log_level = LOG_ERROR; + } else if(strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--silent") == 0) { + config->log_level = -1; } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { usage(); exit(0); @@ -84,9 +94,11 @@ int main(int argc, char* argv[]) { config = gpgedit_config_new(); parseargs(argc, argv, config); + // Initialize the logger + logger_init(config->log_level); if(config->file == NULL) { - printf("Please specify a gpg encrypted file to edit\n"); + logger(LOG_INFO, "Please specify a gpg encrypted file to edit\n"); return 1; } @@ -95,7 +107,7 @@ int main(int argc, char* argv[]) { // to create it. FILE* fd = fopen(config->file, "r"); if(!fd) { - printf("File '%s' does not exist. Creating.\n", config->file); + logger(LOG_INFO, "File '%s' does not exist. Creating.\n", config->file); mkstemp(tmpfile); } else { // File exists, close the fd for testing existance @@ -105,7 +117,7 @@ int main(int argc, char* argv[]) { // to, and run decryption operation. err = init_gpg(&decctx, GPGME_PROTOCOL_OPENPGP); if(err != GPG_ERR_NO_ERROR) { - printf("Error: %s\n", gpgme_strerror(err)); + logger(LOG_ERROR, "%s\n", gpgme_strerror(err)); return 1; } @@ -120,16 +132,16 @@ int main(int argc, char* argv[]) { // We can't do anything if the recipient list is empty (eg: new file but no // recipients specified). if(config->recipients->str == NULL) { - printf("Recipient list empty. Cannot proceed.\n"); + logger(LOG_INFO, "Recipient list empty. Cannot proceed.\n"); } else { // Open the system editor system_edit(tmpfile); - printf("Recipients:\n"); - strll_dump(config->recipients); - // Re-encrypt the plaintext tmp file - //printf("Re-encrypting file '%s' -> '%s'\n", tmpfile, config->file); + logger(LOG_DEBUG, + "Re-encrypting file '%s' -> '%s'\n", + tmpfile, + config->file); gpg_encrypt_file(tmpfile, config->file, config->recipients); } |