3
* Copyright (C) 2003 Sawtooth Consulting Ltd.
5
* This file is part of yaSSL.
7
* yaSSL is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* There are special exceptions to the terms and conditions of the GPL as it
13
* is applied to yaSSL. View the full text of the exception in the file
14
* FLOSS-EXCEPTIONS in the directory of this software distribution.
16
* yaSSL is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
26
/* Debug logging functions
30
#include "runtime.hpp"
46
enum { MAX_MSG = 81 };
48
Log::Log(const char* str)
50
log_ = fopen(str, "w");
51
Trace("********** Logger Attached **********");
57
Trace("********** Logger Detached **********");
63
void Log::Trace(const char* str)
67
time_t clicks = time(0);
71
strncpy(timeStr, ctime(&clicks), sizeof(timeStr));
72
unsigned int len = strlen(timeStr);
77
strncpy(msg, timeStr, sizeof(timeStr));
79
strncat(msg, str, MAX_MSG - sizeof(timeStr) - 2);
80
strncat(msg, "\n", 1);
87
#if defined(_WIN32) || defined(__MACH__) || defined(__hpux__)
88
typedef int socklen_t;
93
void Log::ShowTCP(socket_t fd, bool ended)
96
socklen_t len = sizeof(peeraddr);
97
if (getpeername(fd, (sockaddr*)&peeraddr, &len) != 0)
100
const char* p = reinterpret_cast<const char*>(&peeraddr.sin_addr);
105
strncpy(msg, "yaSSL conn DONE w/ peer ", 26);
107
strncpy(msg, "yaSSL conn BEGUN w/ peer ", 26);
108
for (int i = 0; i < 4; ++i) {
109
sprintf(number, "%u", static_cast<unsigned short>(p[i]));
110
strncat(msg, number, 8);
112
strncat(msg, ".", 1);
114
strncat(msg, " port ", 8);
115
sprintf(number, "%d", htons(peeraddr.sin_port));
116
strncat(msg, number, 8);
118
msg[MAX_MSG - 1] = 0;
123
// log processed data
124
void Log::ShowData(uint bytes, bool sent)
130
strncpy(msg, "Sent ", 10);
132
strncpy(msg, "Received ", 10);
133
sprintf(number, "%u", bytes);
134
strncat(msg, number, 8);
135
strncat(msg, " bytes of application data", 27);
137
msg[MAX_MSG - 1] = 0;
142
#else // no YASSL_LOG
145
Log::Log(const char*) {}
147
void Log::Trace(const char*) {}
148
void Log::ShowTCP(socket_t, bool) {}
149
void Log::ShowData(uint, bool) {}