comparison cinst/mozilla.c @ 1060:317ee9dc4684

(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 09 Sep 2014 18:49:02 +0200
parents 78798d3af8f0
children f110a3f6e387
comparison
equal deleted inserted replaced
1059:f638eb1f3b0f 1060:317ee9dc4684
42 * as defined in errorcodes.h otherwise. 42 * as defined in errorcodes.h otherwise.
43 * 43 *
44 * Success messages are written to stdout. Errors to stderr. For logging 44 * Success messages are written to stdout. Errors to stderr. For logging
45 * purposes each installation / removal of a certificate will be reported 45 * purposes each installation / removal of a certificate will be reported
46 * with the profile name that it modified. 46 * with the profile name that it modified.
47 *
48 * To get more verbose output add the --debug parameter
49 * as the last parameter on the command line.
47 * 50 *
48 */ 51 */
49 52
50 /** 53 /**
51 * @brief Needs to be defined to get strnlen() 54 * @brief Needs to be defined to get strnlen()
140 143
141 if ((cdir = getenv(envvar)) != NULL) 144 if ((cdir = getenv(envvar)) != NULL)
142 return cdir; 145 return cdir;
143 else 146 else
144 { 147 {
145 DEBUGPRINTF("FATAL! No %s in environment.\n", envvar); 148 ERRORPRINTF("FATAL! No %s in environment.\n", envvar);
146 exit(ERR_MOZ_HOMELESS); 149 exit(ERR_MOZ_HOMELESS);
147 } 150 }
148 } 151 }
149 152
150 /** 153 /**
558 size_t name_len; 561 size_t name_len;
559 cn_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_CN); 562 cn_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_CN);
560 o_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_O); 563 o_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_O);
561 if (!cn_str || !o_str) 564 if (!cn_str || !o_str)
562 { 565 {
563 DEBUGPRINTF("FATAL: Could not parse certificate!"); 566 ERRORPRINTF("FATAL: Could not parse certificate!");
564 exit(ERR_INVALID_CERT); 567 exit(ERR_INVALID_CERT);
565 } 568 }
566 name_len = strlen(cn_str) + strlen(o_str) + 4; 569 name_len = strlen(cn_str) + strlen(o_str) + 4;
567 name = (char *)xmalloc(name_len); 570 name = (char *)xmalloc(name_len);
568 snprintf(name, name_len, "%s - %s", cn_str, o_str); 571 snprintf(name, name_len, "%s - %s", cn_str, o_str);
824 parserr = true; 827 parserr = true;
825 } 828 }
826 829
827 if (parserr) 830 if (parserr)
828 { 831 {
829 DEBUGPRINTF("FATAL: Invalid input: %s\n", inpl); 832 ERRORPRINTF("FATAL: Invalid input: %s\n", inpl);
830 exit(ERR_MOZ_INVALID_INPUT); 833 exit(ERR_MOZ_INVALID_INPUT);
831 } 834 }
832 } 835 }
833 } 836 }
837
838 bool g_debug = false;
834 839
835 int 840 int
836 main (int argc, char **argv) 841 main (int argc, char **argv)
837 { 842 {
838 char **dbdirs; 843 char **dbdirs;
845 case 1: 850 case 1:
846 DEBUGPRINTF("Opening STDIN for input...\n"); 851 DEBUGPRINTF("Opening STDIN for input...\n");
847 input_stream = stdin; 852 input_stream = stdin;
848 break; 853 break;
849 case 2: 854 case 2:
855 if (strcmp(argv[1], "--debug") == 0)
856 {
857 g_debug = true;
858 DEBUGPRINTF("Opening STDIN for input...\n");
859 input_stream = stdin;
860 break;
861 }
862 case 3:
850 DEBUGPRINTF("Opening %s for input...\n", argv[1]); 863 DEBUGPRINTF("Opening %s for input...\n", argv[1]);
851 if ((input_stream = fopen(argv[1], "r")) == NULL) 864 if ((input_stream = fopen(argv[1], "r")) == NULL)
852 { 865 {
853 DEBUGPRINTF("FATAL: Could not open %s for reading!\n", 866 ERRORPRINTF ("FATAL: Could not open %s for reading!\n",
854 argv[1]); 867 argv[1]);
855 exit_code = ERR_MOZ_FAILED_TO_OPEN_INPUT; 868 exit_code = ERR_MOZ_FAILED_TO_OPEN_INPUT;
856 goto exit; 869 goto exit;
857 } 870 }
871 if (argc == 3 && strcmp(argv[2], "--debug") == 0)
872 {
873 g_debug = true;
874 }
858 break; 875 break;
859 default: 876 default:
860 DEBUGPRINTF("FATAL: Wrong number of arguments!\n"); 877 ERRORPRINTF("FATAL: Wrong number of arguments!\n");
861 exit_code = ERR_MOZ_WRONG_ARGC; 878 exit_code = ERR_MOZ_WRONG_ARGC;
862 goto exit; 879 goto exit;
863 } 880 }
864 881
865 dbdirs = 882 dbdirs =

http://wald.intevation.org/projects/trustbridge/