mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 20:33:46 +02:00
implement server-time
This commit is contained in:
parent
33d8cc3254
commit
d535a79730
21 changed files with 323 additions and 39 deletions
|
|
@ -48,6 +48,7 @@ typedef struct {
|
|||
} EXPANDO_REC;
|
||||
|
||||
const char *current_expando = NULL;
|
||||
time_t reference_time = (time_t) -1;
|
||||
time_t current_time = (time_t)-1;
|
||||
|
||||
static int timer_tag;
|
||||
|
|
@ -59,6 +60,7 @@ static char *last_privmsg_from, *last_public_from;
|
|||
static char *sysname, *sysrelease, *sysarch;
|
||||
|
||||
static char *timestamp_format;
|
||||
static char *timestamp_format_alt;
|
||||
static int timestamp_seconds;
|
||||
static time_t last_timestamp;
|
||||
|
||||
|
|
@ -441,12 +443,24 @@ static char *expando_time(SERVER_REC *server, void *item, int *free_ret)
|
|||
time_t now;
|
||||
struct tm *tm;
|
||||
char str[256];
|
||||
char *format;
|
||||
|
||||
now = current_time != (time_t)-1 ? current_time : time(NULL);
|
||||
now = current_time != (time_t) -1 ? current_time : time(NULL);
|
||||
tm = localtime(&now);
|
||||
format = timestamp_format;
|
||||
|
||||
if (strftime(str, sizeof(str), timestamp_format, tm) == 0)
|
||||
return "";
|
||||
if (reference_time != (time_t) -1) {
|
||||
time_t ref = reference_time;
|
||||
struct tm tm_ref;
|
||||
if (localtime_r(&ref, &tm_ref)) {
|
||||
if (tm_ref.tm_yday != tm->tm_yday || tm_ref.tm_year != tm->tm_year) {
|
||||
format = timestamp_format_alt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strftime(str, sizeof(str), format, tm) == 0)
|
||||
return "";
|
||||
|
||||
*free_ret = TRUE;
|
||||
return g_strdup(str);
|
||||
|
|
@ -576,7 +590,9 @@ static int sig_timer(void)
|
|||
static void read_settings(void)
|
||||
{
|
||||
g_free_not_null(timestamp_format);
|
||||
g_free_not_null(timestamp_format_alt);
|
||||
timestamp_format = g_strdup(settings_get_str("timestamp_format"));
|
||||
timestamp_format_alt = g_strdup(settings_get_str("timestamp_format_alt"));
|
||||
|
||||
timestamp_seconds =
|
||||
strstr(timestamp_format, "%r") != NULL ||
|
||||
|
|
@ -594,6 +610,7 @@ void expandos_init(void)
|
|||
#endif
|
||||
settings_add_str("misc", "STATUS_OPER", "*");
|
||||
settings_add_str("lookandfeel", "timestamp_format", "%H:%M");
|
||||
settings_add_str("lookandfeel", "timestamp_format_alt", "%a %e %b %H:%M");
|
||||
settings_add_bool("lookandfeel", "chanmode_expando_strip", FALSE);
|
||||
|
||||
last_sent_msg = NULL; last_sent_msg_body = NULL;
|
||||
|
|
@ -730,6 +747,7 @@ void expandos_deinit(void)
|
|||
g_free_not_null(sysrelease);
|
||||
g_free_not_null(sysarch);
|
||||
g_free_not_null(timestamp_format);
|
||||
g_free_not_null(timestamp_format_alt);
|
||||
|
||||
g_source_remove(timer_tag);
|
||||
signal_remove("message public", (SIGNAL_FUNC) sig_message_public);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ typedef char* (*EXPANDO_FUNC)
|
|||
|
||||
extern const char *current_expando;
|
||||
extern time_t current_time;
|
||||
extern time_t reference_time;
|
||||
|
||||
/* Create expando - overrides any existing ones.
|
||||
... = signal, type, ..., NULL - list of signals that might change the
|
||||
|
|
|
|||
|
|
@ -3,7 +3,16 @@
|
|||
#include <irssi/src/core/refstrings.h>
|
||||
|
||||
#if GLIB_CHECK_VERSION(2, 58, 0)
|
||||
/* nothing */
|
||||
|
||||
/* callback implementation for GHashTable */
|
||||
#undef i_refstr_release
|
||||
void i_refstr_release(char *str)
|
||||
{
|
||||
if (str != NULL) {
|
||||
g_ref_string_release(str);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
GHashTable *i_refstr_table;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#if GLIB_CHECK_VERSION(2, 58, 0)
|
||||
|
||||
#define i_refstr_init() /* nothing */
|
||||
/* callback implementation */
|
||||
void i_refstr_release(char *str);
|
||||
#define i_refstr_release(str) ((str) == NULL ? NULL : g_ref_string_release(str))
|
||||
#define i_refstr_intern(str) ((str) == NULL ? NULL : g_ref_string_new_intern(str))
|
||||
#define i_refstr_deinit() /* nothing */
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ int lag; /* server lag in milliseconds */
|
|||
GSList *channels;
|
||||
GSList *queries;
|
||||
|
||||
/* transient meta data stash */
|
||||
GHashTable *current_incoming_meta;
|
||||
|
||||
/* -- support for multiple server types -- */
|
||||
|
||||
/* -- must not be NULL: -- */
|
||||
|
|
|
|||
|
|
@ -19,14 +19,15 @@
|
|||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include <irssi/src/core/signals.h>
|
||||
#include <irssi/src/core/commands.h>
|
||||
#include <irssi/src/core/misc.h>
|
||||
#include <irssi/src/core/net-disconnect.h>
|
||||
#include <irssi/src/core/net-nonblock.h>
|
||||
#include <irssi/src/core/net-sendbuffer.h>
|
||||
#include <irssi/src/core/misc.h>
|
||||
#include <irssi/src/core/rawlog.h>
|
||||
#include <irssi/src/core/refstrings.h>
|
||||
#include <irssi/src/core/settings.h>
|
||||
#include <irssi/src/core/signals.h>
|
||||
|
||||
#include <irssi/src/core/chat-protocols.h>
|
||||
#include <irssi/src/core/servers.h>
|
||||
|
|
@ -354,6 +355,9 @@ void server_connect_init(SERVER_REC *server)
|
|||
MODULE_DATA_INIT(server);
|
||||
server->type = module_get_uniq_id("SERVER", 0);
|
||||
server_ref(server);
|
||||
server->current_incoming_meta =
|
||||
g_hash_table_new_full(g_str_hash, (GEqualFunc) g_strcmp0,
|
||||
(GDestroyNotify) i_refstr_release, (GDestroyNotify) g_free);
|
||||
|
||||
server->nick = g_strdup(server->connrec->nick);
|
||||
if (server->connrec->username == NULL || *server->connrec->username == '\0') {
|
||||
|
|
@ -535,6 +539,7 @@ int server_unref(SERVER_REC *server)
|
|||
g_free(server->away_reason);
|
||||
g_free(server->nick);
|
||||
g_free(server->tag);
|
||||
g_hash_table_destroy(server->current_incoming_meta);
|
||||
|
||||
server->type = 0;
|
||||
g_free(server);
|
||||
|
|
@ -655,6 +660,22 @@ void server_change_nick(SERVER_REC *server, const char *nick)
|
|||
signal_emit("server nick changed", 1, server);
|
||||
}
|
||||
|
||||
void server_meta_stash(SERVER_REC *server, const char *meta_key, const char *meta_value)
|
||||
{
|
||||
g_hash_table_replace(server->current_incoming_meta, i_refstr_intern(meta_key),
|
||||
g_strdup(meta_value));
|
||||
}
|
||||
|
||||
const char *server_meta_stash_find(SERVER_REC *server, const char *meta_key)
|
||||
{
|
||||
return g_hash_table_lookup(server->current_incoming_meta, meta_key);
|
||||
}
|
||||
|
||||
void server_meta_clear_all(SERVER_REC *server)
|
||||
{
|
||||
g_hash_table_remove_all(server->current_incoming_meta);
|
||||
}
|
||||
|
||||
/* Update own IPv4 and IPv6 records */
|
||||
void server_connect_own_ip_save(SERVER_CONNECT_REC *conn,
|
||||
IPADDR *ip4, IPADDR *ip6)
|
||||
|
|
|
|||
|
|
@ -66,6 +66,13 @@ void server_connect_failed(SERVER_REC *server, const char *msg);
|
|||
/* Change your nick */
|
||||
void server_change_nick(SERVER_REC *server, const char *nick);
|
||||
|
||||
/* Push meta data onto the server stash */
|
||||
void server_meta_stash(SERVER_REC *server, const char *meta_key, const char *meta_value);
|
||||
/* Get a value from the stash */
|
||||
const char *server_meta_stash_find(SERVER_REC *server, const char *meta_key);
|
||||
/* clear meta stash */
|
||||
void server_meta_clear_all(SERVER_REC *server);
|
||||
|
||||
/* Update own IPv4 and IPv6 records */
|
||||
void server_connect_own_ip_save(SERVER_CONNECT_REC *conn,
|
||||
IPADDR *ip4, IPADDR *ip6);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue