[go: up one dir, main page]

Menu

[r456]: / tags / miau-0-6-1 / src / log.c  Maximize  Restore  History

Download this file

124 lines (96 with data), 2.8 kB

  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
/* $Id$
* -------------------------------------------------------
* Copyright (C) 2004-2005 Tommi Saviranta <wnd@iki.fi>
* -------------------------------------------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* ifdef HAVE_CONFIG_H */
#include "etc.h"
#ifdef NEED_LOGGING
#include "log.h"
#include "error.h"
#include "irc.h"
#include "messages.h"
#include "tools.h"
#include "common.h"
#include <string.h>
int warned_already = 0;
void
log_cannot_write(const char *file)
{
char *rfile;
size_t size;
if (file == NULL) {
debug("log_cannot_write(NULL)");
return;
}
if (warned_already == 1) {
return;
}
size = strlen(LOGDIR) + strlen(file) + 2;
rfile = xmalloc(size);
snprintf(rfile, size, "%s/%s", LOGDIR, file);
rfile[size - 1] = '\0';
report(MIAU_LOGNOWRITE, rfile);
xfree(rfile);
warned_already = 1;
} /* void log_cannot_write(const char *file) */
void
log_reset_warn_timer(void)
{
warned_already = 0;
} /* void log_reset_warn_timer(void) */
/*
* Prepare message for logging. Returns pointer to printable message or NULL
* if message is normal PRIVMSG.
*
* Memory that returned pointer points to, must not be freed.
*/
char *
log_prepare_entry(const char *nick, const char *msg)
{
static char buf[IRC_MSGLEN];
int i;
int len, rpos;
if (nick == NULL || msg == NULL) {
#ifdef ENDUSERDEBUG
enduserdebug("log_prepare_entry(): nick = %s, msg = %s",
nick == NULL ? "NULL" : nick,
msg == NULL ? "NULL" : msg);
#endif /* ifdef ENDUSERDEBUG */
return NULL;
}
/* Messages not beginning with '\1ACTION ' don't need to be touched. */
if (msg[0] != '\1' || xstrncmp(msg, "\1ACTION ", 8) != 0) {
return NULL;
}
/* Neither do messages that are malformed. */
len = (int) strlen(msg + 8);
i = len;
while (msg[i + 8] != '\1' && i > 0) { i--; }
if (i == 0) {
return NULL;
}
rpos = len - i + 1;
/* Right now we only parse ACTIONs. */
/* termination and validity guaranteed */
/* even msg + 8 is safe, see xstrncmp above */
snprintf(buf, IRC_MSGLEN, LOGM_ACTION,
get_short_localtime(), nick, msg + 8);
buf[IRC_MSGLEN - 1] = '\0';
/* Remove trailing '\1'. */
len = (int) strlen(buf);
memmove(buf + len - rpos, buf + len - rpos + 1, rpos);
return buf;
} /* char *log_prepare_entry(const char *nick, const char *msg) */
#endif /* ifdef NEED_LOGGING */