Version 0.5.0 of tinydtls
Dependents: tinydtls_test_cellular tinydtls_test_ethernet tiny-dtls
debug.h@1:598a56fe116e, 2014-02-12 (annotated)
- Committer:
- ashleymills
- Date:
- Wed Feb 12 09:30:16 2014 +0000
- Revision:
- 1:598a56fe116e
- Parent:
- 0:ff9ebe0cf0e9
Explicitly removed something instead of relying on MACRO to disable it. Mbed can't use it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:ff9ebe0cf0e9 | 1 | /* debug.h -- debug utilities |
ashleymills | 0:ff9ebe0cf0e9 | 2 | * |
ashleymills | 0:ff9ebe0cf0e9 | 3 | * Copyright (C) 2011--2012 Olaf Bergmann <bergmann@tzi.org> |
ashleymills | 0:ff9ebe0cf0e9 | 4 | * |
ashleymills | 0:ff9ebe0cf0e9 | 5 | * Permission is hereby granted, free of charge, to any person |
ashleymills | 0:ff9ebe0cf0e9 | 6 | * obtaining a copy of this software and associated documentation |
ashleymills | 0:ff9ebe0cf0e9 | 7 | * files (the "Software"), to deal in the Software without |
ashleymills | 0:ff9ebe0cf0e9 | 8 | * restriction, including without limitation the rights to use, copy, |
ashleymills | 0:ff9ebe0cf0e9 | 9 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
ashleymills | 0:ff9ebe0cf0e9 | 10 | * of the Software, and to permit persons to whom the Software is |
ashleymills | 0:ff9ebe0cf0e9 | 11 | * furnished to do so, subject to the following conditions: |
ashleymills | 0:ff9ebe0cf0e9 | 12 | * |
ashleymills | 0:ff9ebe0cf0e9 | 13 | * The above copyright notice and this permission notice shall be |
ashleymills | 0:ff9ebe0cf0e9 | 14 | * included in all copies or substantial portions of the Software. |
ashleymills | 0:ff9ebe0cf0e9 | 15 | * |
ashleymills | 0:ff9ebe0cf0e9 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
ashleymills | 0:ff9ebe0cf0e9 | 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
ashleymills | 0:ff9ebe0cf0e9 | 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ashleymills | 0:ff9ebe0cf0e9 | 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
ashleymills | 0:ff9ebe0cf0e9 | 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
ashleymills | 0:ff9ebe0cf0e9 | 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
ashleymills | 0:ff9ebe0cf0e9 | 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
ashleymills | 0:ff9ebe0cf0e9 | 23 | * SOFTWARE. |
ashleymills | 0:ff9ebe0cf0e9 | 24 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 25 | |
ashleymills | 0:ff9ebe0cf0e9 | 26 | #ifndef _DEBUG_H_ |
ashleymills | 0:ff9ebe0cf0e9 | 27 | #define _DEBUG_H_ |
ashleymills | 0:ff9ebe0cf0e9 | 28 | |
ashleymills | 0:ff9ebe0cf0e9 | 29 | #include "config.h" |
ashleymills | 0:ff9ebe0cf0e9 | 30 | #include "global.h" |
ashleymills | 0:ff9ebe0cf0e9 | 31 | #include <stdlib.h> |
ashleymills | 0:ff9ebe0cf0e9 | 32 | |
ashleymills | 0:ff9ebe0cf0e9 | 33 | #ifdef __cplusplus |
ashleymills | 0:ff9ebe0cf0e9 | 34 | extern "C" { |
ashleymills | 0:ff9ebe0cf0e9 | 35 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 36 | |
ashleymills | 0:ff9ebe0cf0e9 | 37 | struct __session_t; |
ashleymills | 0:ff9ebe0cf0e9 | 38 | |
ashleymills | 0:ff9ebe0cf0e9 | 39 | /** Pre-defined log levels akin to what is used in \b syslog. */ |
ashleymills | 0:ff9ebe0cf0e9 | 40 | typedef enum { LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARN, |
ashleymills | 0:ff9ebe0cf0e9 | 41 | LOG_NOTICE, LOG_INFO, LOG_DEBUG |
ashleymills | 0:ff9ebe0cf0e9 | 42 | } log_t; |
ashleymills | 0:ff9ebe0cf0e9 | 43 | |
ashleymills | 0:ff9ebe0cf0e9 | 44 | #ifndef NDEBUG |
ashleymills | 0:ff9ebe0cf0e9 | 45 | /** Returns the current log level. */ |
ashleymills | 0:ff9ebe0cf0e9 | 46 | log_t dtls_get_log_level(); |
ashleymills | 0:ff9ebe0cf0e9 | 47 | |
ashleymills | 0:ff9ebe0cf0e9 | 48 | /** Sets the log level to the specified value. */ |
ashleymills | 0:ff9ebe0cf0e9 | 49 | void dtls_set_log_level(log_t level); |
ashleymills | 0:ff9ebe0cf0e9 | 50 | |
ashleymills | 0:ff9ebe0cf0e9 | 51 | size_t |
ashleymills | 0:ff9ebe0cf0e9 | 52 | dsrv_print_addr(const session_t *addr, unsigned char *buf, size_t len); |
ashleymills | 0:ff9ebe0cf0e9 | 53 | |
ashleymills | 0:ff9ebe0cf0e9 | 54 | /** |
ashleymills | 0:ff9ebe0cf0e9 | 55 | * Writes the given text to \c stdout. The text is output only when \p |
ashleymills | 0:ff9ebe0cf0e9 | 56 | * level is below or equal to the log level that set by |
ashleymills | 0:ff9ebe0cf0e9 | 57 | * set_log_level(). */ |
ashleymills | 0:ff9ebe0cf0e9 | 58 | void dsrv_log(log_t level, char *format, ...); |
ashleymills | 0:ff9ebe0cf0e9 | 59 | |
ashleymills | 0:ff9ebe0cf0e9 | 60 | /** dumps packets in usual hexdump format */ |
ashleymills | 0:ff9ebe0cf0e9 | 61 | void hexdump(const unsigned char *packet, int length); |
ashleymills | 0:ff9ebe0cf0e9 | 62 | |
ashleymills | 0:ff9ebe0cf0e9 | 63 | /** dump as narrow string of hex digits */ |
ashleymills | 0:ff9ebe0cf0e9 | 64 | void dump(unsigned char *buf, size_t len); |
ashleymills | 0:ff9ebe0cf0e9 | 65 | |
ashleymills | 0:ff9ebe0cf0e9 | 66 | void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend); |
ashleymills | 0:ff9ebe0cf0e9 | 67 | |
ashleymills | 0:ff9ebe0cf0e9 | 68 | void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr); |
ashleymills | 0:ff9ebe0cf0e9 | 69 | |
ashleymills | 0:ff9ebe0cf0e9 | 70 | #else /* NDEBUG */ |
ashleymills | 0:ff9ebe0cf0e9 | 71 | |
ashleymills | 0:ff9ebe0cf0e9 | 72 | static inline log_t dtls_get_log_level() |
ashleymills | 0:ff9ebe0cf0e9 | 73 | { |
ashleymills | 0:ff9ebe0cf0e9 | 74 | return LOG_EMERG; |
ashleymills | 0:ff9ebe0cf0e9 | 75 | } |
ashleymills | 0:ff9ebe0cf0e9 | 76 | |
ashleymills | 0:ff9ebe0cf0e9 | 77 | static inline void dtls_set_log_level(log_t level) |
ashleymills | 0:ff9ebe0cf0e9 | 78 | {} |
ashleymills | 0:ff9ebe0cf0e9 | 79 | |
ashleymills | 0:ff9ebe0cf0e9 | 80 | static inline void dsrv_log(log_t level, char *format, ...) |
ashleymills | 0:ff9ebe0cf0e9 | 81 | {} |
ashleymills | 0:ff9ebe0cf0e9 | 82 | |
ashleymills | 0:ff9ebe0cf0e9 | 83 | static inline void hexdump(const unsigned char *packet, int length) |
ashleymills | 0:ff9ebe0cf0e9 | 84 | {} |
ashleymills | 0:ff9ebe0cf0e9 | 85 | |
ashleymills | 0:ff9ebe0cf0e9 | 86 | static inline void dump(unsigned char *buf, size_t len) |
ashleymills | 0:ff9ebe0cf0e9 | 87 | {} |
ashleymills | 0:ff9ebe0cf0e9 | 88 | |
ashleymills | 0:ff9ebe0cf0e9 | 89 | static inline void |
ashleymills | 0:ff9ebe0cf0e9 | 90 | dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend) |
ashleymills | 0:ff9ebe0cf0e9 | 91 | {} |
ashleymills | 0:ff9ebe0cf0e9 | 92 | |
ashleymills | 0:ff9ebe0cf0e9 | 93 | static inline void |
ashleymills | 0:ff9ebe0cf0e9 | 94 | dtls_dsrv_log_addr(log_t level, const char *name, const struct __session_t *addr) |
ashleymills | 0:ff9ebe0cf0e9 | 95 | {} |
ashleymills | 0:ff9ebe0cf0e9 | 96 | |
ashleymills | 0:ff9ebe0cf0e9 | 97 | #endif /* NDEBUG */ |
ashleymills | 0:ff9ebe0cf0e9 | 98 | |
ashleymills | 0:ff9ebe0cf0e9 | 99 | /* A set of convenience macros for common log levels. */ |
ashleymills | 0:ff9ebe0cf0e9 | 100 | #define info2(...) dsrv_log(LOG_INFO, __VA_ARGS__) |
ashleymills | 0:ff9ebe0cf0e9 | 101 | #define warn2(...) dsrv_log(LOG_WARN, __VA_ARGS__) |
ashleymills | 0:ff9ebe0cf0e9 | 102 | #define debug2(...) dsrv_log(LOG_DEBUG, __VA_ARGS__) |
ashleymills | 0:ff9ebe0cf0e9 | 103 | |
ashleymills | 0:ff9ebe0cf0e9 | 104 | #endif /* _DEBUG_H_ */ |
ashleymills | 0:ff9ebe0cf0e9 | 105 | |
ashleymills | 0:ff9ebe0cf0e9 | 106 | #ifdef __cplusplus |
ashleymills | 0:ff9ebe0cf0e9 | 107 | } |
ashleymills | 0:ff9ebe0cf0e9 | 108 | #endif |