log.h
Go to the documentation of this file.
1
7 /* purple
8 *
9 * Purple is the legal property of its developers, whose names are too numerous
10 * to list here. Please refer to the COPYRIGHT file distributed with this
11 * source distribution.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 */
27 #ifndef _PURPLE_LOG_H_
28 #define _PURPLE_LOG_H_
29
30 #include <stdio.h>
31
32
33 /********************************************************
34 * DATA STRUCTURES **************************************
35 ********************************************************/
36
37 typedef struct _PurpleLog PurpleLog;
38 typedef struct _PurpleLogLogger PurpleLogLogger;
39 typedef struct _PurpleLogCommonLoggerData PurpleLogCommonLoggerData;
40 typedef struct _PurpleLogSet PurpleLogSet;
41
42 typedef enum {
43 PURPLE_LOG_IM,
44 PURPLE_LOG_CHAT,
45 PURPLE_LOG_SYSTEM
46 } PurpleLogType;
47
48 typedef enum {
49 PURPLE_LOG_READ_NO_NEWLINE = 1
50 } PurpleLogReadFlags;
51
52 #include "account.h"
53 #include "conversation.h"
54
55 typedef void (*PurpleLogSetCallback) (GHashTable *sets, PurpleLogSet *set);
56
63 struct _PurpleLogLogger {
64 char *name;
65 char *id;
69 void (*create)(PurpleLog *log);
70
72 gsize (*write)(PurpleLog *log,
73 PurpleMessageFlags type,
74 const char *from,
75 time_t time,
76 const char *message);
77
79 void (*finalize)(PurpleLog *log);
80
82 GList *(*list)(PurpleLogType type, const char *name, PurpleAccount *account);
83
86 char *(*read)(PurpleLog *log, PurpleLogReadFlags *flags);
87
90 int (*size)(PurpleLog *log);
91
94 int (*total_size)(PurpleLogType type, const char *name, PurpleAccount *account);
95
97 GList *(*list_syslog)(PurpleAccount *account);
98
107 void (*get_log_sets)(PurpleLogSetCallback cb, GHashTable *sets);
108
109 /* Attempts to delete the specified log, indicating success or failure */
110 gboolean (*remove)(PurpleLog *log);
111
112 /* Tests whether a log is deletable */
113 gboolean (*is_deletable)(PurpleLog *log);
114
115 void (*_purple_reserved1)(void);
116 void (*_purple_reserved2)(void);
117 void (*_purple_reserved3)(void);
118 void (*_purple_reserved4)(void);
119 };
120
124 struct _PurpleLog {
125 PurpleLogType type;
126 char *name;
127 PurpleAccount *account;
129 PurpleConversation *conv;
130 time_t time;
133 PurpleLogLogger *logger;
135 void *logger_data;
136 struct tm *tm;
143 /* IMPORTANT: Some code in log.c allocates these without zeroing them.
144 * IMPORTANT: Update that code if you add members here. */
145 };
146
151 struct _PurpleLogCommonLoggerData {
152 char *path;
153 FILE *file;
154 void *extra_data;
155 };
156
163 struct _PurpleLogSet {
164 PurpleLogType type;
165 char *name;
166 PurpleAccount *account;
173 gboolean buddy;
175 char *normalized_name;
180 /* IMPORTANT: Some code in log.c allocates these without zeroing them.
181 * IMPORTANT: Update that code if you add members here. */
182 };
183
184 #ifdef __cplusplus
185 extern "C" {
186 #endif
187
188 /***************************************/
190 /***************************************/
206 PurpleLog *purple_log_new(PurpleLogType type, const char *name, PurpleAccount *account,
207 PurpleConversation *conv, time_t time, const struct tm *tm);
208
214 void purple_log_free(PurpleLog *log);
215
226 void purple_log_write(PurpleLog *log,
227 PurpleMessageFlags type,
228 const char *from,
229 time_t time,
230 const char *message);
231
240 char *purple_log_read(PurpleLog *log, PurpleLogReadFlags *flags);
241
250 GList *purple_log_get_logs(PurpleLogType type, const char *name, PurpleAccount *account);
251
268 GHashTable *purple_log_get_log_sets(void);
269
276 GList *purple_log_get_system_logs(PurpleAccount *account);
277
284 int purple_log_get_size(PurpleLog *log);
285
294 int purple_log_get_total_size(PurpleLogType type, const char *name, PurpleAccount *account);
295
307 int purple_log_get_activity_score(PurpleLogType type, const char *name, PurpleAccount *account);
308
319 gboolean purple_log_is_deletable(PurpleLog *log);
320
327 gboolean purple_log_delete(PurpleLog *log);
328
339 char *purple_log_get_log_dir(PurpleLogType type, const char *name, PurpleAccount *account);
340
348 gint purple_log_compare(gconstpointer y, gconstpointer z);
349
357 gint purple_log_set_compare(gconstpointer y, gconstpointer z);
358
364 void purple_log_set_free(PurpleLogSet *set);
365
368 /******************************************/
370 /******************************************/
389 void purple_log_common_writer(PurpleLog *log, const char *ext);
390
408 GList *purple_log_common_lister(PurpleLogType type, const char *name,
409 PurpleAccount *account, const char *ext,
410 PurpleLogLogger *logger);
411
431 int purple_log_common_total_sizer(PurpleLogType type, const char *name,
432 PurpleAccount *account, const char *ext);
433
447 int purple_log_common_sizer(PurpleLog *log);
448
462 gboolean purple_log_common_deleter(PurpleLog *log);
463
477 gboolean purple_log_common_is_deletable(PurpleLog *log);
478
481 /******************************************/
483 /******************************************/
506 PurpleLogLogger *purple_log_logger_new(const char *id, const char *name, int functions, ...);
507
513 void purple_log_logger_free(PurpleLogLogger *logger);
514
520 void purple_log_logger_add (PurpleLogLogger *logger);
521
528 void purple_log_logger_remove (PurpleLogLogger *logger);
529
536 void purple_log_logger_set (PurpleLogLogger *logger);
537
544 PurpleLogLogger *purple_log_logger_get (void);
545
552 GList *purple_log_logger_get_options(void);
553
554 /**************************************************************************/
556 /**************************************************************************/
562 void purple_log_init(void);
563
569 void *purple_log_get_handle(void);
570
574 void purple_log_uninit(void);
575
579 #ifdef __cplusplus
580 }
581 #endif
582
583 #endif /* _PURPLE_LOG_H_ */
purple_log_get_handle
void * purple_log_get_handle(void)
Returns the log subsystem handle.
PurpleMessageFlags
PurpleMessageFlags
Flags applicable to a message.
Definition: conversation.h:105
_PurpleLog
A log.
Definition: log.h:124
_PurpleLog::name
char * name
The name of this log.
Definition: log.h:126
purple_log_common_is_deletable
gboolean purple_log_common_is_deletable(PurpleLog *log)
Checks to see if a log is deletable.
purple_log_logger_get
PurpleLogLogger * purple_log_logger_get(void)
Returns the current logger.
_PurpleLogSet::buddy
gboolean buddy
Is this (account, name) a buddy on the buddy list?
Definition: log.h:173
_PurpleLogSet::name
char * name
The name of the logs available.
Definition: log.h:165
purple_log_new
PurpleLog * purple_log_new(PurpleLogType type, const char *name, PurpleAccount *account, PurpleConversation *conv, time_t time, const struct tm *tm)
Creates a new log.
purple_log_write
void purple_log_write(PurpleLog *log, PurpleMessageFlags type, const char *from, time_t time, const char *message)
Writes to a log file.
conversation.h
Conversation API.
_PurpleLog::logger_data
void * logger_data
Data used by the log logger.
Definition: log.h:135
purple_log_uninit
void purple_log_uninit(void)
Uninitializes the log subsystem.
_PurpleLogSet
Describes available logs.
Definition: log.h:163
purple_log_logger_get_options
GList * purple_log_logger_get_options(void)
Returns a GList containing the IDs and names of the registered loggers.
_PurpleLogLogger::write
gsize(* write)(PurpleLog *log, PurpleMessageFlags type, const char *from, time_t time, const char *message)
This is used to write to the log file.
Definition: log.h:72
purple_log_logger_add
void purple_log_logger_add(PurpleLogLogger *logger)
Adds a new logger.
_PurpleAccount
Structure representing an account.
Definition: account.h:169
purple_log_is_deletable
gboolean purple_log_is_deletable(PurpleLog *log)
Tests whether a log is deletable.
purple_log_logger_set
void purple_log_logger_set(PurpleLogLogger *logger)
Sets the current logger.
purple_log_logger_free
void purple_log_logger_free(PurpleLogLogger *logger)
Frees a logger.
purple_log_get_log_dir
char * purple_log_get_log_dir(PurpleLogType type, const char *name, PurpleAccount *account)
Returns the default logger directory Purple uses for a given account and username.
purple_log_common_writer
void purple_log_common_writer(PurpleLog *log, const char *ext)
Opens a new log file in the standard Purple log location with the given file extension, named for the current time, for writing.
purple_log_free
void purple_log_free(PurpleLog *log)
Frees a log.
purple_log_init
void purple_log_init(void)
Initializes the log subsystem.
purple_log_logger_new
PurpleLogLogger * purple_log_logger_new(const char *id, const char *name, int functions,...)
Creates a new logger.
purple_log_get_size
int purple_log_get_size(PurpleLog *log)
Returns the size of a log.
purple_log_set_compare
gint purple_log_set_compare(gconstpointer y, gconstpointer z)
Implements GCompareFunc for PurpleLogSets.
_PurpleLog::logger
PurpleLogLogger * logger
The logging mechanism this log is to use.
Definition: log.h:133
_PurpleLogLogger::size
int(* size)(PurpleLog *log)
Given one of the logs returned by the logger&#39;s list function, this returns the size of the log in byt...
Definition: log.h:90
_PurpleLogSet::normalized_name
char * normalized_name
The normalized version of name.
Definition: log.h:175
purple_log_get_log_sets
GHashTable * purple_log_get_log_sets(void)
Returns a GHashTable of PurpleLogSets.
purple_log_common_sizer
int purple_log_common_sizer(PurpleLog *log)
Returns the size of a given PurpleLog.
purple_log_common_total_sizer
int purple_log_common_total_sizer(PurpleLogType type, const char *name, PurpleAccount *account, const char *ext)
Returns the total size of all the logs for a given user, with a given extension.
_PurpleLogCommonLoggerData
A common logger_data struct containing a file handle and path, as well as a pointer to something else...
Definition: log.h:151
account.h
Account API.
purple_log_read
char * purple_log_read(PurpleLog *log, PurpleLogReadFlags *flags)
Reads from a log.
_PurpleLog::time
time_t time
The time this conversation started, converted to the local timezone.
Definition: log.h:130
purple_log_get_activity_score
int purple_log_get_activity_score(PurpleLogType type, const char *name, PurpleAccount *account)
Returns the activity score of a log, based on total size in bytes, which is then decayed based on age...
purple_log_logger_remove
void purple_log_logger_remove(PurpleLogLogger *logger)
Removes a logger.
purple_log_set_free
void purple_log_set_free(PurpleLogSet *set)
Frees a log set.
_PurpleLog::account
PurpleAccount * account
The account this log is taking place on.
Definition: log.h:127
_PurpleLog::tm
struct tm * tm
The time this conversation started, saved with original timezone data, if available and if struct tm ...
Definition: log.h:136
purple_log_compare
gint purple_log_compare(gconstpointer y, gconstpointer z)
Implements GCompareFunc for PurpleLogs.
purple_log_get_system_logs
GList * purple_log_get_system_logs(PurpleAccount *account)
Returns a list of all available system logs.
_PurpleLog::conv
PurpleConversation * conv
The conversation being logged.
Definition: log.h:129
_PurpleLogLogger::id
char * id
an identifier to refer to this logger
Definition: log.h:65
purple_log_common_deleter
gboolean purple_log_common_deleter(PurpleLog *log)
Deletes a log.
purple_log_delete
gboolean purple_log_delete(PurpleLog *log)
Deletes a log.
_PurpleLogSet::type
PurpleLogType type
The type of logs available.
Definition: log.h:164
_PurpleLogSet::account
PurpleAccount * account
The account the available logs took place on.
Definition: log.h:166
_PurpleLogLogger::finalize
void(* finalize)(PurpleLog *log)
Called when the log is destroyed.
Definition: log.h:79
purple_log_get_total_size
int purple_log_get_total_size(PurpleLogType type, const char *name, PurpleAccount *account)
Returns the size, in bytes, of all available logs in this conversation.
_PurpleLogLogger::get_log_sets
void(* get_log_sets)(PurpleLogSetCallback cb, GHashTable *sets)
Adds PurpleLogSets to a GHashTable.
Definition: log.h:107
purple_log_get_logs
GList * purple_log_get_logs(PurpleLogType type, const char *name, PurpleAccount *account)
Returns a list of all available logs.
_PurpleLogLogger::name
char * name
The logger&#39;s name.
Definition: log.h:64
_PurpleLogLogger
A log logger.
Definition: log.h:63
_PurpleLogLogger::total_size
int(* total_size)(PurpleLogType type, const char *name, PurpleAccount *account)
Returns the total size of all the logs.
Definition: log.h:94
_PurpleLogLogger::create
void(* create)(PurpleLog *log)
This gets called when the log is first created.
Definition: log.h:69
purple_log_common_lister
GList * purple_log_common_lister(PurpleLogType type, const char *name, PurpleAccount *account, const char *ext, PurpleLogLogger *logger)
Returns a sorted GList of PurpleLogs of the requested type.
_PurpleConversation
A core representation of a conversation between two or more people.
Definition: conversation.h:338
_PurpleLog::type
PurpleLogType type
The type of log this is.
Definition: log.h:125