mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
New enum constant ERROR clashed with a macro in MinGW's wingdi.h.
Use uglier names. [originally from svn r5352]
This commit is contained in:
parent
dc52b43cc3
commit
53d4c434e7
36
logging.c
36
logging.c
@ -10,7 +10,7 @@
|
|||||||
/* log session to file stuff ... */
|
/* log session to file stuff ... */
|
||||||
struct LogContext {
|
struct LogContext {
|
||||||
FILE *lgfp;
|
FILE *lgfp;
|
||||||
enum { CLOSED, OPENING, OPEN, ERROR } state;
|
enum { L_CLOSED, L_OPENING, L_OPEN, L_ERROR } state;
|
||||||
bufchain queue;
|
bufchain queue;
|
||||||
Filename currlogfilename;
|
Filename currlogfilename;
|
||||||
void *frontend;
|
void *frontend;
|
||||||
@ -28,19 +28,19 @@ static void xlatlognam(Filename *d, Filename s, char *hostname, struct tm *tm);
|
|||||||
static void logwrite(struct LogContext *ctx, void *data, int len)
|
static void logwrite(struct LogContext *ctx, void *data, int len)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* In state CLOSED, we call logfopen, which will set the state
|
* In state L_CLOSED, we call logfopen, which will set the state
|
||||||
* to one of OPENING, OPEN or ERROR. Hence we process all of
|
* to one of L_OPENING, L_OPEN or L_ERROR. Hence we process all of
|
||||||
* those three _after_ processing CLOSED.
|
* those three _after_ processing L_CLOSED.
|
||||||
*/
|
*/
|
||||||
if (ctx->state == CLOSED)
|
if (ctx->state == L_CLOSED)
|
||||||
logfopen(ctx);
|
logfopen(ctx);
|
||||||
|
|
||||||
if (ctx->state == OPENING) {
|
if (ctx->state == L_OPENING) {
|
||||||
bufchain_add(&ctx->queue, data, len);
|
bufchain_add(&ctx->queue, data, len);
|
||||||
} else if (ctx->state == OPEN) {
|
} else if (ctx->state == L_OPEN) {
|
||||||
assert(ctx->lgfp);
|
assert(ctx->lgfp);
|
||||||
fwrite(data, 1, len, ctx->lgfp);
|
fwrite(data, 1, len, ctx->lgfp);
|
||||||
} /* else ERROR, so ignore the write */
|
} /* else L_ERROR, so ignore the write */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -66,7 +66,7 @@ static void logprintf(struct LogContext *ctx, const char *fmt, ...)
|
|||||||
void logflush(void *handle) {
|
void logflush(void *handle) {
|
||||||
struct LogContext *ctx = (struct LogContext *)handle;
|
struct LogContext *ctx = (struct LogContext *)handle;
|
||||||
if (ctx->cfg.logtype > 0)
|
if (ctx->cfg.logtype > 0)
|
||||||
if (ctx->state == OPEN)
|
if (ctx->state == L_OPEN)
|
||||||
fflush(ctx->lgfp);
|
fflush(ctx->lgfp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,17 +78,17 @@ static void logfopen_callback(void *handle, int mode)
|
|||||||
const char *fmode;
|
const char *fmode;
|
||||||
|
|
||||||
if (mode == 0) {
|
if (mode == 0) {
|
||||||
ctx->state = ERROR; /* disable logging */
|
ctx->state = L_ERROR; /* disable logging */
|
||||||
} else {
|
} else {
|
||||||
fmode = (mode == 1 ? "a" : "w");
|
fmode = (mode == 1 ? "a" : "w");
|
||||||
ctx->lgfp = f_open(ctx->currlogfilename, fmode);
|
ctx->lgfp = f_open(ctx->currlogfilename, fmode);
|
||||||
if (ctx->lgfp)
|
if (ctx->lgfp)
|
||||||
ctx->state = OPEN;
|
ctx->state = L_OPEN;
|
||||||
else
|
else
|
||||||
ctx->state = ERROR;
|
ctx->state = L_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->state == OPEN) {
|
if (ctx->state == L_OPEN) {
|
||||||
/* Write header line into log file. */
|
/* Write header line into log file. */
|
||||||
tm = ltime();
|
tm = ltime();
|
||||||
strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm);
|
strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm);
|
||||||
@ -111,7 +111,7 @@ static void logfopen_callback(void *handle, int mode)
|
|||||||
* Having either succeeded or failed in opening the log file,
|
* Having either succeeded or failed in opening the log file,
|
||||||
* we should write any queued data out.
|
* we should write any queued data out.
|
||||||
*/
|
*/
|
||||||
assert(ctx->state != OPENING); /* make _sure_ it won't be requeued */
|
assert(ctx->state != L_OPENING); /* make _sure_ it won't be requeued */
|
||||||
while (bufchain_size(&ctx->queue)) {
|
while (bufchain_size(&ctx->queue)) {
|
||||||
void *data;
|
void *data;
|
||||||
int len;
|
int len;
|
||||||
@ -133,7 +133,7 @@ void logfopen(void *handle)
|
|||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
/* Prevent repeat calls */
|
/* Prevent repeat calls */
|
||||||
if (ctx->state != CLOSED)
|
if (ctx->state != L_CLOSED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!ctx->cfg.logtype)
|
if (!ctx->cfg.logtype)
|
||||||
@ -156,7 +156,7 @@ void logfopen(void *handle)
|
|||||||
mode = 2; /* create == overwrite */
|
mode = 2; /* create == overwrite */
|
||||||
|
|
||||||
if (mode < 0)
|
if (mode < 0)
|
||||||
ctx->state = OPENING;
|
ctx->state = L_OPENING;
|
||||||
else
|
else
|
||||||
logfopen_callback(ctx, mode); /* open the file */
|
logfopen_callback(ctx, mode); /* open the file */
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ void logfclose(void *handle)
|
|||||||
fclose(ctx->lgfp);
|
fclose(ctx->lgfp);
|
||||||
ctx->lgfp = NULL;
|
ctx->lgfp = NULL;
|
||||||
}
|
}
|
||||||
ctx->state = CLOSED;
|
ctx->state = L_CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -300,7 +300,7 @@ void *log_init(void *frontend, Config *cfg)
|
|||||||
{
|
{
|
||||||
struct LogContext *ctx = snew(struct LogContext);
|
struct LogContext *ctx = snew(struct LogContext);
|
||||||
ctx->lgfp = NULL;
|
ctx->lgfp = NULL;
|
||||||
ctx->state = CLOSED;
|
ctx->state = L_CLOSED;
|
||||||
ctx->frontend = frontend;
|
ctx->frontend = frontend;
|
||||||
ctx->cfg = *cfg; /* STRUCTURE COPY */
|
ctx->cfg = *cfg; /* STRUCTURE COPY */
|
||||||
bufchain_init(&ctx->queue);
|
bufchain_init(&ctx->queue);
|
||||||
|
Loading…
Reference in New Issue
Block a user