Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compatibility code to GTimeVal -> gint64 transition #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions config.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# paths
PREFIX ?= /usr/local

# where are the sources of irssi?
# where are the sources of irssi? lets ask pkg-config first
irssi_incdirs_pc != pkg-config --cflags-only-I irssi-1 2>/dev/null
ifneq (,$(irssi_incdirs_pc))
IRSSI_INCLUDE ?= `pkg-config --cflags-only-I irssi-1`
irssi_incdirs = ${IRSSI_INCLUDE}
else
IRSSI_INCLUDE ?= ${PREFIX}/include/irssi
irssi_incdirs = \
-I${IRSSI_INCLUDE}/.. \
-I${IRSSI_INCLUDE} \
-I${IRSSI_INCLUDE}/src \
-I${IRSSI_INCLUDE}/src/core \
-I$(IRSSI_INCLUDE)/src/fe-common/core \
-I$(IRSSI_INCLUDE)/src/fe-text
endif
# where should be installed the module?
irssi_libdir_pc != pkg-config --variable=libdir irssi-1 2>/dev/null
ifneq (,$(irssi_libdir_pc))
IRSSI_LIB ?= ${irssi_libdir_pc}/irssi
else
IRSSI_LIB ?= ${PREFIX}/lib/irssi
endif
# where should be installed the documentation?
IRSSI_DOC ?= ${PREFIX}/share/doc/irssi
# where should be installed the help for commands ?
Expand All @@ -13,11 +31,7 @@ IRSSI_HELP ?= ${PREFIX}/share/irssi/help
# includes and libs
INCS = ${LIB_INCS} \
-I../../src/core \
-I${IRSSI_INCLUDE} \
-I${IRSSI_INCLUDE}/src \
-I${IRSSI_INCLUDE}/src/core \
-I$(IRSSI_INCLUDE)/src/fe-common/core \
-I$(IRSSI_INCLUDE)/src/fe-text \
${irssi_incdirs} \
`pkg-config --cflags glib-2.0` \
`pkg-config --cflags loudmouth-1.0`
LIBS = ${LIB_LIBS}
Expand Down
4 changes: 2 additions & 2 deletions src/core/module.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MODULE_NAME "xmpp/core"

#include "irssi-config.h"
#include "common.h"
#include <irssi/irssi-config.h>
#include <irssi/src/common.h>
#include "xmpp.h"
2 changes: 1 addition & 1 deletion src/core/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "rosters-tools.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/rosters.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <string.h>

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "rosters-tools.h"
Expand Down
4 changes: 2 additions & 2 deletions src/core/stanzas.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

#include "module.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "tools.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <string.h>

#include "module.h"
#include "recode.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/recode.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#define XMPP_PRIORITY_MIN -128
#define XMPP_PRIORITY_MAX 127
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/chatstates.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "disco.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/composing.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <string.h>

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "xmpp-queries.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "tools.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/disco.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string.h>

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "tools.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/muc-commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <stdlib.h>

#include "module.h"
#include "settings.h"
#include "signals.h"
#include "window-item-def.h"
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>
#include <irssi/src/core/window-item-def.h>

#include "xmpp-servers.h"
#include "xmpp-commands.h"
Expand Down
8 changes: 4 additions & 4 deletions src/core/xep/muc-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include <string.h>

#include "module.h"
#include "commands.h"
#include "misc.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/commands.h>
#include <irssi/src/core/misc.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "rosters-tools.h"
#include "tools.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/muc-nicklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <string.h>

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "rosters.h"
#include "muc-affiliation.h"
Expand Down
4 changes: 2 additions & 2 deletions src/core/xep/muc-nicklist.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __MUC_NICKLIST_H
#define __MUC_NICKLIST_H

#include "nicklist.h"
#include <irssi/src/core/nicklist.h>
#include "muc.h"

/* Returns XMPP_NICK_REC if it's XMPP channel, NULL if it isn't. */
Expand All @@ -16,7 +16,7 @@


struct _XMPP_NICK_REC {
#include "nick-rec.h"
#include <irssi/src/core/nick-rec.h>

int show;
char *status;
Expand Down
4 changes: 2 additions & 2 deletions src/core/xep/muc-reconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

#include "module.h"
#include "servers-reconnect.h"
#include "signals.h"
#include <irssi/src/core/servers-reconnect.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "muc.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/muc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include <string.h>

#include "module.h"
#include "commands.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/commands.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "rosters-tools.h"
#include "tools.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/muc.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef __MUC_H
#define __MUC_H

#include "channels.h"
#include "channels-setup.h"
#include <irssi/src/core/channels.h>
#include <irssi/src/core/channels-setup.h>
#include "xmpp-servers.h"
#include "tools.h"

Expand Down Expand Up @@ -34,7 +34,7 @@

#define STRUCT_SERVER_REC XMPP_SERVER_REC
struct _MUC_REC {
#include "channel-rec.h"
#include <irssi/src/core/channel-rec.h>

char *nick;
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/xep/oob.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#include "module.h"
#include "signals.h"
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "tools.h"
Expand Down
56 changes: 40 additions & 16 deletions src/core/xep/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#include <time.h>

#include "module.h"
#include "misc.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/misc.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "xmpp-commands.h"
Expand All @@ -36,15 +36,40 @@

#define XMLNS_PING "urn:xmpp:ping"

#if defined(IRSSI_ABI_VERSION) && IRSSI_ABI_VERSION >= 25
#define NO_TIMEVAL
#define TimeType gint64
#else
#define TimeType GTimeVal
#endif

struct ping_data {
char *id;
GTimeVal time;
char *id;
TimeType time;
};

static int timeout_tag;
static GSList *supported_servers;
static DATALIST *pings;

#ifdef NO_TIMEVAL

#define set_current_time(var) (var) = g_get_real_time()
#define clear_time(var) (var) = 0
#define has_time(var) ((var) != 0)
#define get_time_sec(var) ((var) / G_TIME_SPAN_SECOND)
#define get_time_diff(to, from) (to) - (from)

#else

#define set_current_time(var) g_get_current_time(&(var))
#define clear_time(var) memset(&(var), 0, sizeof((var)))
#define has_time(var) ((var).tv_sec != 0)
#define get_time_sec(var) ((var).tv_sec)
#define get_time_diff(to, from) (int) get_timeval_diff(&(to), &(from))

#endif

static void
request_ping(XMPP_SERVER_REC *server, const char *dest)
{
Expand All @@ -63,13 +88,13 @@ request_ping(XMPP_SERVER_REC *server, const char *dest)
g_free(server->ping_id);
server->ping_id =
g_strdup(lm_message_node_get_attribute(lmsg->node, "id"));
g_get_current_time(&server->lag_sent);
set_current_time(server->lag_sent);
server->lag_last_check = time(NULL);
} else {
pd = g_new0(struct ping_data, 1);
pd->id =
g_strdup(lm_message_node_get_attribute(lmsg->node, "id"));
g_get_current_time(&pd->time);
set_current_time(pd->time);
datalist_add(pings, server, dest, pd);
}
signal_emit("xmpp send iq", 2, server, lmsg);
Expand Down Expand Up @@ -98,27 +123,26 @@ sig_recv_iq(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
{
DATALIST_REC *rec;
LmMessageNode *node;
GTimeVal now;
TimeType now;
struct ping_data *pd;

if (type == LM_MESSAGE_SUB_TYPE_RESULT) {
/* pong response from server of our ping */
if (server->ping_id != NULL
&& (*from == '\0' || strcmp(from, server->domain) == 0)
&& strcmp(id, server->ping_id) == 0) {
g_get_current_time(&now);
server->lag =
(int)get_timeval_diff(&now, &server->lag_sent);
memset(&server->lag_sent, 0, sizeof(server->lag_sent));
set_current_time(now);
server->lag = get_time_diff(now, server->lag_sent);
clear_time(server->lag_sent);
g_free_and_null(server->ping_id);
signal_emit("server lag", 1, server);
} else if (lmsg->node->children == NULL
&& (rec = datalist_find(pings, server, from)) != NULL) {
pd = rec->data;
if (strcmp(id, pd->id) == 0) {
g_get_current_time(&now);
set_current_time(now);
signal_emit("xmpp ping", 3, server, from,
get_timeval_diff(&now, &pd->time));
get_time_diff(now, pd->time));
}
}
} else if (type == LM_MESSAGE_SUB_TYPE_GET) {
Expand Down Expand Up @@ -166,10 +190,10 @@ check_ping_func(void)
now = time(NULL);
for (tmp = supported_servers; tmp != NULL; tmp = tmp->next) {
server = XMPP_SERVER(tmp->data);
if (server->lag_sent.tv_sec != 0) {
if (has_time(server->lag_sent)) {
/* waiting for lag reply */
if (max_lag > 1 &&
(now - server->lag_sent.tv_sec) > max_lag) {
(now - get_time_sec(server->lag_sent)) > max_lag) {
/* too much lag - disconnect */
signal_emit("server lag disconnect", 1,
server);
Expand Down
4 changes: 2 additions & 2 deletions src/core/xep/registration.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <string.h>

#include "module.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>
#include "tools.h"

#include "xmpp-servers.h"
Expand Down
4 changes: 2 additions & 2 deletions src/core/xep/vcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

#include "module.h"
#include "queries.h"
#include "signals.h"
#include <irssi/src/core/queries.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "xmpp-commands.h"
Expand Down
6 changes: 3 additions & 3 deletions src/core/xep/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include <string.h>

#include "module.h"
#include "queries.h"
#include "settings.h"
#include "signals.h"
#include <irssi/src/core/queries.h>
#include <irssi/src/core/settings.h>
#include <irssi/src/core/signals.h>

#include "xmpp-servers.h"
#include "xmpp-commands.h"
Expand Down
Loading