author | Mikael Berthe <mikael@lilotux.net> |
Wed, 15 Nov 2006 00:04:57 +0100 | |
changeset 1016 | 4d3c48844746 |
parent 899 | a833f3d6119a |
child 1058 | c0d44a9a99bc |
permissions | -rw-r--r-- |
110 | 1 |
/* |
699 | 2 |
* histolog.c -- File history handling |
395
3e4f2f98c0bf
Whitespace cleanup (histolog.c)
Mikael Berthe <mikael@lilotux.net>
parents:
394
diff
changeset
|
3 |
* |
699 | 4 |
* Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.lilotux.net> |
110 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; either version 2 of the License, or (at |
|
9 |
* your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but |
|
12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
* General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
19 |
* USA |
|
20 |
*/ |
|
21 |
||
22 |
#include <string.h> |
|
23 |
#include <stdlib.h> |
|
24 |
#include <time.h> |
|
113 | 25 |
#include <ctype.h> |
26 |
#include <sys/types.h> |
|
27 |
#include <sys/stat.h> |
|
28 |
#include <fcntl.h> |
|
110 | 29 |
|
30 |
#include "histolog.h" |
|
178 | 31 |
#include "hbuf.h" |
113 | 32 |
#include "jabglue.h" |
241 | 33 |
#include "utils.h" |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
34 |
#include "logprint.h" |
635
d4119cb85aeb
New "load_muc_logs" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
35 |
#include "settings.h" |
727
1c3620668857
Expand tabs when reading history files
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
36 |
#include "utils.h" |
110 | 37 |
|
38 |
static guint UseFileLogging; |
|
177 | 39 |
static guint FileLoadLogs; |
110 | 40 |
static char *RootDir; |
41 |
||
42 |
||
43 |
// user_histo_file() |
|
44 |
// Returns history filename for the given jid |
|
45 |
// Note: the caller *must* free the filename after use (if not null). |
|
111 | 46 |
static char *user_histo_file(const char *jid) |
110 | 47 |
{ |
48 |
char *filename; |
|
186 | 49 |
char *lowerid, *p; |
178 | 50 |
if (!UseFileLogging && !FileLoadLogs) return NULL; |
110 | 51 |
|
186 | 52 |
lowerid = g_strdup(jid); |
53 |
for (p=lowerid; *p ; p++) |
|
54 |
*p = tolower(*p); |
|
55 |
||
110 | 56 |
filename = g_new(char, strlen(RootDir) + strlen(jid) + 1); |
57 |
strcpy(filename, RootDir); |
|
186 | 58 |
strcat(filename, lowerid); |
59 |
g_free(lowerid); |
|
110 | 60 |
return filename; |
61 |
} |
|
62 |
||
178 | 63 |
// write_histo_line() |
110 | 64 |
// Adds a history (multi-)line to the jid's history logfile |
113 | 65 |
static void write_histo_line(const char *jid, |
66 |
time_t timestamp, guchar type, guchar info, const char *data) |
|
110 | 67 |
{ |
68 |
guint len = 0; |
|
113 | 69 |
FILE *fp; |
110 | 70 |
time_t ts; |
113 | 71 |
const char *p; |
178 | 72 |
char *filename; |
241 | 73 |
char str_ts[20]; |
273 | 74 |
int err; |