Introduce global timed handlers

There are situations when applications need more predictable timed
handlers that don't depend on connection status. Other usecase of
the global handlers is to manage offline connections, for example,
reconnect after a disconnection.
This commit is contained in:
Dmitry Podgorny
2020-06-03 02:11:40 +03:00
parent cba21b5598
commit 3dcc5a60f2
5 changed files with 131 additions and 78 deletions

View File

@@ -29,6 +29,38 @@
#include "rand.h"
#include "snprintf.h"
/** handlers **/
typedef struct _xmpp_handlist_t xmpp_handlist_t;
struct _xmpp_handlist_t {
/* common members */
int user_handler;
int (*handler)();
void *userdata;
int enabled; /* handlers are added disabled and enabled after the
* handler chain is processed to prevent stanzas from
* getting processed by newly added handlers */
xmpp_handlist_t *next;
union {
/* timed handlers */
struct {
unsigned long period;
uint64_t last_stamp;
};
/* id handlers */
struct {
char *id;
};
/* normal handlers */
struct {
char *ns;
char *name;
char *type;
};
} u;
};
/** run-time context **/
typedef enum {
@@ -49,6 +81,7 @@ struct _xmpp_ctx_t {
xmpp_rand_t *rand;
xmpp_loop_status_t loop_status;
xmpp_connlist_t *connlist;
xmpp_handlist_t *timed_handlers;
unsigned long timeout;
};
@@ -100,36 +133,6 @@ struct _xmpp_send_queue_t {
xmpp_send_queue_t *next;
};
typedef struct _xmpp_handlist_t xmpp_handlist_t;
struct _xmpp_handlist_t {
/* common members */
int user_handler;
int (*handler)();
void *userdata;
int enabled; /* handlers are added disabled and enabled after the
* handler chain is processed to prevent stanzas from
* getting processed by newly added handlers */
xmpp_handlist_t *next;
union {
/* timed handlers */
struct {
unsigned long period;
uint64_t last_stamp;
};
/* id handlers */
struct {
char *id;
};
/* normal handlers */
struct {
char *ns;
char *name;
char *type;
};
} u;
};
#define UNUSED(x) ((void)(x))
#define MAX_DOMAIN_LEN 256