@@ -41,54 +41,65 @@ struct error_log_level
41
41
typedef enum {INFO, WARNING, ERROR} type;
42
42
};
43
43
44
- #undef DBUG_ASSERT
45
- #ifndef DBUG_OFF
46
- #define DBUG_ASSERT (X ) assert(X)
44
+
45
+ /*
46
+ If DEBUG_ERROR_LOG is defined then error logging happens only
47
+ in debug-copiled code. Otherwise ERROR_LOG() expands to
48
+ error_log_print() even in production code. Note that in client
49
+ plugin, error_log_print() will print nothing if opt_auth_win_clinet_log
50
+ is 0.
51
+
52
+ Note: Macro ERROR_LOG() can use printf-like format string like this:
53
+
54
+ ERROR_LOG(Level, ("format string", args));
55
+
56
+ The implementation should handle it correctly. Currently it is passed
57
+ to fprintf() (see error_log_vprint() function).
58
+ */
59
+
60
+ extern " C" int opt_auth_win_client_log;
61
+
62
+ #if defined(DEBUG_ERROR_LOG) && defined(DBUG_OFF)
63
+ #define ERROR_LOG (Level, Msg ) do {} while (0 )
47
64
#else
48
- #define DBUG_ASSERT ( X ) do {} while ( 0 )
65
+ #define ERROR_LOG ( Level, Msg ) error_log_print< error_log_level::Level > Msg
49
66
#endif
50
67
51
- extern " C" int opt_auth_win_client_log;
52
68
53
- /*
54
- Note1: Double level of indirection in definition of DBUG_PRINT allows to
55
- temporary redefine or disable DBUG_PRINT macro and then easily return to
56
- the original definition (in terms of DBUG_PRINT_DO).
69
+ void error_log_vprint (error_log_level::type level,
70
+ const char *fmt, va_list args);
57
71
58
- Note2: DBUG_PRINT() can use printf-like format string like this:
72
+ template <error_log_level::type Level>
73
+ void error_log_print (const char *fmt, ...)
74
+ {
75
+ va_list args;
76
+ va_start (args, fmt);
77
+ error_log_vprint (Level, fmt, args);
78
+ va_end (args);
79
+ }
59
80
60
- DBUG_PRINT(Keyword, ("format string", args));
81
+ typedef char Error_message_buf[1024 ];
82
+ const char * get_last_error_message (Error_message_buf);
61
83
62
- The implementation should handle it correctly. Currently it is passed
63
- to fprintf() (see debug_msg() function).
84
+
85
+ /*
86
+ Internal implementation of debug message printing which does not use
87
+ dbug library. This is invoked via macro:
88
+
89
+ DBUG_PRINT_DO(Keyword, ("format string", args));
90
+
91
+ This is supposed to be used as an implementation of DBUG_PRINT() macro,
92
+ unless the dbug library implementation is used or debug messages are disabled.
64
93
*/
65
94
66
95
#ifndef DBUG_OFF
96
+
67
97
#define DBUG_PRINT_DO (Keyword, Msg ) \
68
98
do { \
69
99
if (2 > opt_auth_win_client_log) break ; \
70
100
fprintf (stderr, " winauth: %s: " , Keyword); \
71
101
debug_msg Msg; \
72
102
} while (0 )
73
- #else
74
- #define DBUG_PRINT_DO (K, M ) do {} while (0 )
75
- #endif
76
-
77
- #undef DBUG_PRINT
78
- #define DBUG_PRINT (Keyword, Msg ) DBUG_PRINT_DO(Keyword, Msg)
79
-
80
- /*
81
- If DEBUG_ERROR_LOG is defined then error logging happens only
82
- in debug-copiled code. Otherwise ERROR_LOG() expands to
83
- error_log_print() even in production code. Note that in client
84
- plugin, error_log_print() will print nothing if opt_auth_win_clinet_log
85
- is 0.
86
- */
87
- #if defined(DEBUG_ERROR_LOG) && defined(DBUG_OFF)
88
- #define ERROR_LOG (Level, Msg ) do {} while (0 )
89
- #else
90
- #define ERROR_LOG (Level, Msg ) error_log_print< error_log_level::Level > Msg
91
- #endif
92
103
93
104
inline
94
105
void debug_msg (const char *fmt, ...)
@@ -101,21 +112,38 @@ void debug_msg(const char *fmt, ...)
101
112
va_end (args);
102
113
}
103
114
115
+ #else
116
+ #define DBUG_PRINT_DO (K, M ) do {} while (0 )
117
+ #endif
104
118
105
- void error_log_vprint (error_log_level::type level,
106
- const char *fmt, va_list args);
107
119
108
- template <error_log_level::type Level>
109
- void error_log_print (const char *fmt, ...)
110
- {
111
- va_list args;
112
- va_start (args, fmt);
113
- error_log_vprint (Level, fmt, args);
114
- va_end (args);
115
- }
120
+ #ifndef WINAUTH_USE_DBUG_LIB
116
121
117
- typedef char Error_message_buf[1024 ];
118
- const char * get_last_error_message (Error_message_buf);
122
+ #undef DBUG_PRINT
123
+ #define DBUG_PRINT (Keyword, Msg ) DBUG_PRINT_DO(Keyword, Msg)
124
+
125
+ /*
126
+ Redefine few more debug macros to make sure that no symbols from
127
+ dbug library are used.
128
+ */
129
+
130
+ #undef DBUG_ENTER
131
+ #define DBUG_ENTER (X ) do {} while (0 )
132
+
133
+ #undef DBUG_RETURN
134
+ #define DBUG_RETURN (X ) return (X)
135
+
136
+ #undef DBUG_ASSERT
137
+ #ifndef DBUG_OFF
138
+ #define DBUG_ASSERT (X ) assert (X)
139
+ #else
140
+ #define DBUG_ASSERT (X ) do {} while (0 )
141
+ #endif
142
+
143
+ #undef DBUG_DUMP
144
+ #define DBUG_DUMP (A,B,C ) do {} while (0 )
145
+
146
+ #endif
119
147
120
148
121
149
/* * Blob class *************************************************************/
@@ -158,15 +186,21 @@ class Blob
158
186
return m_len;
159
187
}
160
188
161
- byte operator [](unsigned pos) const
189
+ byte& operator [](unsigned pos) const
162
190
{
163
- return pos < len () ? m_ptr[pos] : 0x00 ;
191
+ static byte out_of_range= 0 ; // alas, no exceptions...
192
+ return pos < len () ? m_ptr[pos] : out_of_range;
164
193
}
165
194
166
195
bool is_null () const
167
196
{
168
197
return m_ptr == NULL ;
169
198
}
199
+
200
+ void trim (size_t l)
201
+ {
202
+ m_len= l;
203
+ }
170
204
};
171
205
172
206
0 commit comments