@@ -89,6 +89,13 @@ char* myoptarg = NULL;
8989 fprintf(stderr, __VA_ARGS__); \
9090 } while (0)
9191
92+
93+ #define LOG_MSG (...) \
94+ do { \
95+ printf(__VA_ARGS__); \
96+ fflush(stdout); \
97+ } while(0)
98+
9299#ifndef _WIN32
93100/* Signal handler flag */
94101static volatile int got_signal = 0 ;
@@ -127,17 +134,17 @@ typedef struct {
127134/* Usage help */
128135static void Usage (void )
129136{
130- printf ("OCSP Responder Example\n\n" );
131- printf ("Usage: ocsp_responder [options]\n\n" );
132- printf ("Options:\n" );
133- printf (" -? Help\n" );
134- printf (" -p <num> Port (default %d)\n" , DEFAULT_PORT );
135- printf (" -c <file> CA certificate\n" );
136- printf (" -k <file> CA private key\n" );
137- printf (" -i <file> Index file for cert status\n" );
138- printf (" -n <num> Exit after n requests\n" );
139- printf (" -v Verbose\n" );
140- printf (" -x Exclude certs from response\n" );
137+ LOG_MSG ("OCSP Responder Example\n\n" );
138+ LOG_MSG ("Usage: ocsp_responder [options]\n\n" );
139+ LOG_MSG ("Options:\n" );
140+ LOG_MSG (" -? Help\n" );
141+ LOG_MSG (" -p <num> Port (default %d)\n" , DEFAULT_PORT );
142+ LOG_MSG (" -c <file> CA certificate\n" );
143+ LOG_MSG (" -k <file> CA private key\n" );
144+ LOG_MSG (" -i <file> Index file for cert status\n" );
145+ LOG_MSG (" -n <num> Exit after n requests\n" );
146+ LOG_MSG (" -v Verbose\n" );
147+ LOG_MSG (" -x Exclude certs from response\n" );
141148}
142149
143150/* Load file into buffer, auto-detect PEM vs DER */
@@ -739,7 +746,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
739746 goto cleanup ;
740747 }
741748 if (opts .verbose ) {
742- printf ("Loaded CA certificate: %s (%d bytes)\n" , opts .certFile , caCertDerSz );
749+ LOG_MSG ("Loaded CA certificate: %s (%d bytes)\n" , opts .certFile , caCertDerSz );
743750 }
744751
745752 /* Load CA key */
@@ -750,7 +757,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
750757 goto cleanup ;
751758 }
752759 if (opts .verbose ) {
753- printf ("Loaded CA key: %s (%d bytes)\n" , opts .keyFile , caKeyDerSz );
760+ LOG_MSG ("Loaded CA key: %s (%d bytes)\n" , opts .keyFile , caKeyDerSz );
754761 }
755762
756763 /* Parse CA certificate to get subject */
@@ -772,7 +779,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
772779 LOG_ERROR ("Warning: Could not parse index file: %s\n" , opts .indexFile );
773780 }
774781 else if (opts .verbose ) {
775- printf ("Loaded index file: %s\n" , opts .indexFile );
782+ LOG_MSG ("Loaded index file: %s\n" , opts .indexFile );
776783 }
777784 }
778785
@@ -792,7 +799,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
792799 goto cleanup ;
793800 }
794801 if (opts .verbose ) {
795- printf ("Added CA to responder\n" );
802+ LOG_MSG ("Added CA to responder\n" );
796803 }
797804
798805 /* Populate responder with certificate statuses from index */
@@ -802,7 +809,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
802809 LOG_ERROR ("Error populating responder from index: %d\n" , statusCount );
803810 }
804811 else if (opts .verbose ) {
805- printf ("Populated responder with %d certificate statuses\n" , statusCount );
812+ LOG_MSG ("Populated responder with %d certificate statuses\n" , statusCount );
806813 }
807814 }
808815
@@ -813,7 +820,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
813820 ret = -1 ;
814821 goto cleanup ;
815822 }
816- printf ("OCSP Responder listening on port %d\n" , opts .port );
823+ LOG_MSG ("OCSP Responder listening on port %d\n" , opts .port );
817824
818825#ifndef _WIN32
819826 /* Install signal handlers for clean shutdown */
@@ -826,7 +833,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
826833 sigaction (SIGINT , & sa , NULL );
827834 }
828835 if (opts .verbose ) {
829- printf ("Signal handlers installed\n" );
836+ LOG_MSG ("Signal handlers installed\n" );
830837 }
831838#endif
832839
@@ -851,7 +858,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
851858 }
852859
853860 if (opts .verbose ) {
854- printf ("Connection from %s:%d\n" ,
861+ LOG_MSG ("Connection from %s:%d\n" ,
855862 inet_ntoa (clientAddr .sin_addr ), ntohs (clientAddr .sin_port ));
856863 }
857864
@@ -865,7 +872,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
865872 httpBuf [recvLen ] = '\0' ;
866873
867874 if (opts .verbose ) {
868- printf ("Received %d bytes\n" , recvLen );
875+ LOG_MSG ("Received %d bytes\n" , recvLen );
869876 }
870877
871878 /* Parse HTTP request */
@@ -878,7 +885,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
878885 }
879886
880887 if (opts .verbose ) {
881- printf ("OCSP request: %d bytes, path: %s\n" , ocspReqSz , path );
888+ LOG_MSG ("OCSP request: %d bytes, path: %s\n" , ocspReqSz , path );
882889 }
883890
884891 /* Process OCSP request and generate response */
@@ -904,13 +911,13 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
904911 }
905912
906913 if (opts .verbose ) {
907- printf ("Generated OCSP error response (status=%d): %d bytes\n" ,
914+ LOG_MSG ("Generated OCSP error response (status=%d): %d bytes\n" ,
908915 errStatus , respSz );
909916 }
910917 }
911918
912919 if (opts .verbose ) {
913- printf ("Generated OCSP response: %d bytes\n" , respSz );
920+ LOG_MSG ("Generated OCSP response: %d bytes\n" , respSz );
914921 }
915922
916923 /* Send HTTP response */
@@ -924,7 +931,7 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
924931 requestsProcessed ++ ;
925932
926933 if (opts .verbose ) {
927- printf ("Processed request %d\n" , requestsProcessed );
934+ LOG_MSG ("Processed request %d\n" , requestsProcessed );
928935 }
929936 }
930937
0 commit comments