Overview
Comment: | Merged in trunk |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | piv |
Files: | files | file ages | folders |
SHA1: | 8f2721461139ecc83f1150005089c290527f1ba2 |
User & Date: | rkeene on 2013-01-15 14:12:42 |
Other Links: | manifest | tags |
Context
2013-01-15
| ||
15:59 | Updated to use BER-TLV decoding to extract responses rather than hard-coded offsets check-in: ab26dec401 user: rkeene tags: piv | |
14:12 | Merged in trunk check-in: 8f27214611 user: rkeene tags: piv | |
14:11 | Updated debugging messages to be written in a single fprintf() call in an attempt to avoid having them intermingled when written from multiple threads check-in: 402217513a user: rkeene tags: trunk | |
05:27 | Updated to copy type when copying pcsc_identities check-in: 150cbc7790 user: rkeene tags: piv | |
Changes
Modified cackey.c from [edf097489b] to [ddd6381c90].
195 195 #define MAX_ATR_SIZE 1024 196 196 #endif 197 197 198 198 #ifdef CACKEY_DEBUG 199 199 # ifdef HAVE_TIME_H 200 200 # include <time.h> 201 201 static time_t cackey_debug_start_time = 0; 202 -# define CACKEY_DEBUG_PRINTTIME { if (cackey_debug_start_time == 0) { cackey_debug_start_time = time(NULL); }; fprintf(cackey_debug_fd(), "[%lu]: ", (unsigned long) (time(NULL) - cackey_debug_start_time)); } 202 +static unsigned long CACKEY_DEBUG_GETTIME(void) { 203 + if (cackey_debug_start_time == 0) { 204 + cackey_debug_start_time = time(NULL); 205 + } 206 + 207 + return(time(NULL) - cackey_debug_start_time); 208 +} 203 209 # else 204 -# define CACKEY_DEBUG_PRINTTIME /**/ 210 +static unsigned long CACKEY_DEBUG_GETTIME(void) { 211 + return(0); 212 +} 205 213 # endif 206 214 207 -# define CACKEY_DEBUG_PRINTF(x...) { CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: ", __func__, __LINE__); fprintf(cackey_debug_fd(), x); fprintf(cackey_debug_fd(), "\n"); fflush(cackey_debug_fd()); } 208 -# define CACKEY_DEBUG_PRINTBUF(f, x, y) { unsigned char *TMPBUF; unsigned long idx; TMPBUF = (unsigned char *) (x); CACKEY_DEBUG_PRINTTIME; fprintf(cackey_debug_fd(), "%s():%i: %s (%s/%lu = {%02x", __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0]); for (idx = 1; idx < (y); idx++) { fprintf(cackey_debug_fd(), ", %02x", TMPBUF[idx]); }; fprintf(cackey_debug_fd(), "})\n"); fflush(cackey_debug_fd()); } 209 -# define CACKEY_DEBUG_PERROR(x) { fprintf(cackey_debug_fd(), "%s():%i: ", __func__, __LINE__); CACKEY_DEBUG_PRINTTIME; perror(x); fflush(cackey_debug_fd()); } 215 +# define CACKEY_DEBUG_PRINTF(x...) { \ 216 + static char buf_user[4096] = {0}; \ 217 + snprintf(buf_user, sizeof(buf_user), x); \ 218 + buf_user[sizeof(buf_user) - 1] = '\0'; \ 219 + fprintf(cackey_debug_fd(), "[%lu]: %s():%i: %s\n", CACKEY_DEBUG_GETTIME(), __func__, __LINE__, buf_user); \ 220 + fflush(cackey_debug_fd()); \ 221 +} 222 +# define CACKEY_DEBUG_PRINTBUF(f, x, y) { \ 223 + static char buf_user[4096] = {0}, *buf_user_p; \ 224 + unsigned long buf_user_size; \ 225 + unsigned char *TMPBUF; \ 226 + unsigned long idx; \ 227 + int snprintf_ret; \ 228 + TMPBUF = (unsigned char *) (x); \ 229 + buf_user_p = buf_user; \ 230 + buf_user_size = sizeof(buf_user); \ 231 + for (idx = 1; idx < (y); idx++) { \ 232 + if (buf_user_size <= 0) { \ 233 + break; \ 234 + }; \ 235 + snprintf_ret = snprintf(buf_user_p, buf_user_size, ", %02x", TMPBUF[idx]); \ 236 + if (snprintf_ret <= 0) { \ 237 + break; \ 238 + }; \ 239 + buf_user_p += snprintf_ret; \ 240 + buf_user_size -= snprintf_ret; \ 241 + }; \ 242 + buf_user[sizeof(buf_user) - 1] = '\0'; \ 243 + fprintf(cackey_debug_fd(), "[%lu]: %s():%i: %s (%s/%lu = {%02x%s})\n", CACKEY_DEBUG_GETTIME(), __func__, __LINE__, f, #x, (unsigned long) (y), TMPBUF[0], buf_user); \ 244 + fflush(cackey_debug_fd()); \ 245 +} 210 246 # define free(x) { CACKEY_DEBUG_PRINTF("FREE(%p) (%s)", (void *) x, #x); free(x); } 211 247 212 248 static FILE *cackey_debug_fd(void) { 213 249 static FILE *fd = NULL; 214 250 char *logfile; 215 251 216 252 if (fd != NULL) { ................................................................................ 255 291 } 256 292 257 293 static void *CACKEY_DEBUG_FUNC_MALLOC(size_t size, const char *func, int line) { 258 294 void *retval; 259 295 260 296 retval = malloc(size); 261 297 262 - CACKEY_DEBUG_PRINTTIME; 263 - fprintf(cackey_debug_fd(), "%s():%i: ", func, line); 264 - fprintf(cackey_debug_fd(), "MALLOC() = %p", retval); 265 - fprintf(cackey_debug_fd(), "\n"); 298 + fprintf(cackey_debug_fd(), "[%lu]: %s():%i: MALLOC() = %p\n", CACKEY_DEBUG_GETTIME(), func, line, retval); 266 299 fflush(cackey_debug_fd()); 267 300 268 301 return(retval); 269 302 } 270 303 271 304 static void *CACKEY_DEBUG_FUNC_REALLOC(void *ptr, size_t size, const char *func, int line) { 272 305 void *retval; 273 306 274 307 retval = realloc(ptr, size); 275 308 276 309 if (retval != ptr) { 277 - CACKEY_DEBUG_PRINTTIME; 278 - fprintf(cackey_debug_fd(), "%s():%i: ", func, line); 279 - fprintf(cackey_debug_fd(), "REALLOC(%p) = %p", ptr, retval); 280 - fprintf(cackey_debug_fd(), "\n"); 310 + fprintf(cackey_debug_fd(), "[%lu]: %s():%i: REALLOC(%p) = %p\n", CACKEY_DEBUG_GETTIME(), func, line, ptr, retval); 281 311 fflush(cackey_debug_fd()); 282 312 } 283 313 284 314 if (retval == NULL) { 285 315 CACKEY_DEBUG_PRINTF(" *** ERROR *** realloc returned NULL (size = %lu)", (unsigned long) size); 286 316 } 287 317 ................................................................................ 289 319 } 290 320 291 321 static char *CACKEY_DEBUG_FUNC_STRDUP(const char *ptr, const char *func, int line) { 292 322 char *retval; 293 323 294 324 retval = strdup(ptr); 295 325 296 - CACKEY_DEBUG_PRINTTIME; 297 - fprintf(cackey_debug_fd(), "%s():%i: ", func, line); 298 - fprintf(cackey_debug_fd(), "STRDUP_MALLOC() = %p", retval); 299 - fprintf(cackey_debug_fd(), "\n"); 326 + fprintf(cackey_debug_fd(), "[%lu]: %s():%i: STRDUP_MALLOC() = %p\n", CACKEY_DEBUG_GETTIME(), func, line, retval); 300 327 fflush(cackey_debug_fd()); 301 328 302 329 return(retval); 303 330 } 304 331 305 332 static const char *CACKEY_DEBUG_FUNC_TAG_TO_STR(unsigned char tag) { 306 333 switch (tag) { ................................................................................ 674 701 # ifdef strdup 675 702 # undef strdup 676 703 # endif 677 704 # define strdup(x) CACKEY_DEBUG_FUNC_STRDUP(x, __func__, __LINE__) 678 705 #else 679 706 # define CACKEY_DEBUG_PRINTF(x...) /**/ 680 707 # define CACKEY_DEBUG_PRINTBUF(f, x, y) /**/ 681 -# define CACKEY_DEBUG_PERROR(x) /**/ 682 708 # define CACKEY_DEBUG_FUNC_TAG_TO_STR(x) "DEBUG_DISABLED" 683 709 # define CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(x) "DEBUG_DISABLED" 684 710 # define CACKEY_DEBUG_FUNC_OBJID_TO_STR(x) "DEBUG_DISABLED" 685 711 # define CACKEY_DEBUG_FUNC_APPTYPE_TO_STR(x) "DEBUG_DISABLED" 686 712 # define CACKEY_DEBUG_FUNC_ATTRIBUTE_TO_STR(x) "DEBUG_DISABLED" 687 713 #endif 688 714