diff --git a/UDPTCPNetwork.h b/UDPTCPNetwork.h index 8a6e478..45d1c93 100644 --- a/UDPTCPNetwork.h +++ b/UDPTCPNetwork.h @@ -74,16 +74,15 @@ std::string string_to_upper(std::string s); int file_is_readable (const char *fname); -#ifndef UDPTCPNETWORK_DISABLE_DEBUG -void debug_set_logfile (std::string fname); -void _debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...); -void _errorexit (char *srcfile, int srcline, char *srcfunc, char *fmt,...); - -#ifndef debug -#define debug(...) _debug ((char*)__FILE__, __LINE__, (char*)__FUNCTION__, (char*)__VA_ARGS__) -#endif -#define errorexit(...) _errorexit ((char*)__FILE__, __LINE__, (char*)__FUNCTION__, (char*)__VA_ARGS__) +void UDPTCPNetwork_debug_set_logfile (std::string fname); +void UDPTCPNetwork_debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...); +void UDPTCPNetwork_errorexit (char *srcfile, int srcline, char *srcfunc, char *fmt,...); +void UDPTCPNetwork_enable_debug (int enable); +#ifndef UDPTCPNETWORK_DISABLE_DEBUG +#define debug(...) UDPTCPNetwork_debug ((char*)__FILE__, __LINE__, (char*)__FUNCTION__, (char*)__VA_ARGS__) +#define errorexit(...) UDPTCPNetwork_errorexit ((char*)__FILE__, __LINE__, (char*)__FUNCTION__, (char*)__VA_ARGS__) +#define debug_enable(enable) UDPTCPNetwork_enable_debug (enable) #endif /************************************************************************ diff --git a/network.cc b/network.cc index 26472ac..d1523b8 100644 --- a/network.cc +++ b/network.cc @@ -14,6 +14,7 @@ using namespace std; char dnsip[NET_HOSTLEN]; int UDPTCPNetwork_init = 0; std::string debug_file = ""; +int debug_enabeld = 0; // // convert host and port to sockaddr_in6 @@ -96,7 +97,7 @@ std::string string_to_lower(std::string s) { }; -void debug_set_logfile(std::string fname) { +void UDPTCPNetwork_debug_set_logfile(std::string fname) { debug_file = fname; }; @@ -104,7 +105,7 @@ void debug_set_logfile(std::string fname) { #define LEN_TEXT 256 #define DEBUG_TEXT1LEN 4096 #define DEBUG_TEXT2LEN (DEBUG_TEXT1LEN+LEN_TEXT) -void _debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...) { +void UDPTCPNetwork_debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...) { va_list args; char texttime[LEN_TEXT]; char text1[DEBUG_TEXT1LEN]; @@ -115,6 +116,8 @@ void _debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...) { struct tm tmp; struct tm *tmptr = NULL; + if (debug_enabeld == 0) return; + va_start (args, fmt); vsnprintf (text1, (DEBUG_TEXT1LEN-1), fmt, args); va_end (args); @@ -143,11 +146,16 @@ void _debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...) { }; -void _errorexit (char *srcfile, int srcline, char *srcfunc, char *fmt,...) { +void UDPTCPNetwork_enable_debug (int enable) { + debug_enabeld = enable; +}; + + +void UDPTCPNetwork_errorexit (char *srcfile, int srcline, char *srcfunc, char *fmt,...) { va_list args; va_start (args, fmt); - _debug (srcfile, srcline, srcfunc, fmt, args); + UDPTCPNetwork_debug (srcfile, srcline, srcfunc, fmt, args); va_end (args); exit (1);