1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/**
* @file
*/
/******************************************************************************
* Copyright AllSeen Alliance. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************************/
#define AJ_MODULE DEBUG
#include <ajtcl/aj_debug.h>
uint8_t dbgDEBUG = 0;
#ifndef NDEBUG
#include <ajtcl/aj_target.h>
#include <ajtcl/aj_util.h>
#include <ajtcl/aj_config.h>
#define Printable(c) (((c) >= ' ') && ((c) <= '~')) ? (c) : '.'
void _AJ_DumpBytes(const char* tag, const uint8_t* data, uint32_t len)
{
uint32_t i;
char ascii[AJ_DUMP_BYTE_SIZE + 1];
if (tag) {
AJ_AlwaysPrintf(("%s: (%u)\n", tag, len));
}
ascii[AJ_DUMP_BYTE_SIZE] = '\0';
for (i = 0; i < len; i += AJ_DUMP_BYTE_SIZE) {
uint32_t j;
for (j = 0; j < AJ_DUMP_BYTE_SIZE; ++j, ++data) {
if ((i + j) < len) {
uint8_t n = *data;
ascii[j] = Printable(n);
if (n < 0x10) {
AJ_AlwaysPrintf(("0%x ", n));
} else {
AJ_AlwaysPrintf(("%x ", n));
}
} else {
ascii[j] = '\0';
AJ_AlwaysPrintf((" "));
}
}
ascii[j] = '\0';
AJ_AlwaysPrintf((" %s\n", ascii));
}
}
static const char* const msgType[] = { "INVALID", "CALL", "REPLY", "ERROR", "SIGNAL" };
void _AJ_DumpMsg(const char* tag, AJ_Message* msg, uint8_t body)
{
if (msg->hdr && _AJ_DbgHeader(AJ_DEBUG_ERROR, NULL, 0)) {
#if AJ_DUMP_MSG_RAW
uint8_t* p = (uint8_t*)msg->hdr + sizeof(AJ_MsgHeader);
uint32_t hdrBytes = ((msg->hdr->headerLen + 7) & ~7);
#endif
AJ_AlwaysPrintf(("%s message[%d] type %s sig=\"%s\"\n", tag, msg->hdr->serialNum, msgType[(msg->hdr->msgType <= 4) ? msg->hdr->msgType : 0], msg->signature));
switch (msg->hdr->msgType) {
case AJ_MSG_SIGNAL:
case AJ_MSG_METHOD_CALL:
AJ_AlwaysPrintf((" %s::%s\n", msg->iface, msg->member));
break;
case AJ_MSG_ERROR:
AJ_AlwaysPrintf((" Error %s\n", msg->error));
case AJ_MSG_METHOD_RET:
AJ_AlwaysPrintf((" Reply serial %d\n", msg->replySerial));
break;
}
AJ_AlwaysPrintf((" hdr len=%d\n", msg->hdr->headerLen));
#if AJ_DUMP_MSG_RAW
AJ_DumpBytes(NULL, p, hdrBytes);
AJ_AlwaysPrintf(("body len=%d\n", msg->hdr->bodyLen));
if (body) {
AJ_DumpBytes(NULL, p + hdrBytes, msg->hdr->bodyLen);
}
AJ_AlwaysPrintf(("-----------------------\n"));
#endif
}
}
int _AJ_DbgHeader(AJ_DebugLevel level, const char* file, int line)
{
static AJ_Time initTime;
uint32_t logTimeSecond;
uint32_t logTimeMS;
if (!(initTime.seconds | initTime.milliseconds)) {
AJ_InitTimer(&initTime);
}
if (level <= AJ_DbgLevel) {
AJ_Time debugTime;
if (AJ_OK == AJ_GetDebugTime(&debugTime)) {
logTimeSecond = debugTime.seconds;
logTimeMS = debugTime.milliseconds;
} else {
uint32_t elapsedTime = AJ_GetElapsedTime(&initTime, TRUE);
logTimeSecond = elapsedTime / 1000;
logTimeMS = elapsedTime % 1000;
}
if (file) {
const char* fn = file;
while (*fn) {
if ((*fn == '/') || (*fn == '\\')) {
file = fn + 1;
}
++fn;
}
AJ_AlwaysPrintf(("%03d.%03d %s:%d ", logTimeSecond, logTimeMS, file, line));
} else {
AJ_AlwaysPrintf(("%03d.%03d ", logTimeSecond, logTimeMS));
}
return TRUE;
} else {
return FALSE;
}
}
AJ_DebugLevel AJ_DbgLevel = AJ_DEBUG_INFO;
uint8_t dbgALL = 0;
#endif
#define AJ_CASE(_status) case _status: return # _status
const char* AJ_StatusText(AJ_Status status)
{
#ifdef NDEBUG
/* Expectation is that thin client status codes will NOT go beyond 255 */
static char code[4];
#ifdef _WIN32
_snprintf(code, sizeof(code), "%03u", status);
#else
snprintf(code, sizeof(code), "%03u", status);
#endif
return code;
#else
switch (status) {
AJ_CASE(AJ_OK);
AJ_CASE(AJ_ERR_NULL);
AJ_CASE(AJ_ERR_UNEXPECTED);
AJ_CASE(AJ_ERR_INVALID);
AJ_CASE(AJ_ERR_IO_BUFFER);
AJ_CASE(AJ_ERR_READ);
AJ_CASE(AJ_ERR_WRITE);
AJ_CASE(AJ_ERR_TIMEOUT);
AJ_CASE(AJ_ERR_MARSHAL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RESSURE);
AJ_CASE(AJ_ERR_ARDP_SEND_EXPIRED);
AJ_CASE(AJ_ERR_ARDP_RECV_EXPIRED);
AJ_CASE(AJ_ERR_ARDP_VERSION_NOT_SUPPORTED);
AJ_CASE(AJ_ERR_SECURITY_DIGEST_MISMATCH);
AJ_CASE(AJ_ERR_SECURITY_INVALID_CERTIFICATE);
AJ_CASE(AJ_ERR_SECURITY_DUPLICATE_CERTIFICATE);
AJ_CASE(AJ_ERR_SECURITY_POLICY_NOT_NEWER);
AJ_CASE(AJ_ERR_SECURITY_CERTIFICATE_NOT_FOUND);
default:
return "<unknown>";
}
#endif
}
|