1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
/*
* Copyright (c) 2002-2012 Balabit
* Copyright (c) 1998-2012 Balázs Scheidler
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#ifndef LOGPROTO_SERVER_H_INCLUDED
#define LOGPROTO_SERVER_H_INCLUDED
#include "logproto.h"
#include "persist-state.h"
#include "transport/transport-aux-data.h"
#include "ack-tracker/bookmark.h"
typedef struct _LogProtoServer LogProtoServer;
typedef struct _LogProtoServerOptions LogProtoServerOptions;
typedef enum
{
LPPA_POLL_IO,
LPPA_FORCE_SCHEDULE_FETCH,
LPPA_SUSPEND
} LogProtoPrepareAction;
#define LOG_PROTO_SERVER_OPTIONS_SIZE 128
struct _LogProtoServerOptions
{
void (*destroy)(LogProtoServerOptions *self);
gboolean initialized;
gchar *encoding;
/* maximum message length in bytes */
gint max_msg_size;
gboolean trim_large_messages;
gint max_buffer_size;
gint init_buffer_size;
gboolean position_tracking_enabled;
};
typedef union LogProtoServerOptionsStorage
{
LogProtoServerOptions super;
gchar __padding[LOG_PROTO_SERVER_OPTIONS_SIZE];
} LogProtoServerOptionsStorage;
gboolean log_proto_server_options_validate(const LogProtoServerOptions *options);
gboolean log_proto_server_options_set_encoding(LogProtoServerOptions *s, const gchar *encoding);
void log_proto_server_options_defaults(LogProtoServerOptions *options);
void log_proto_server_options_init(LogProtoServerOptions *options, GlobalConfig *cfg);
void log_proto_server_options_destroy(LogProtoServerOptions *options);
typedef void (*LogProtoServerWakeupFunc)(gpointer user_data);
typedef struct _LogProtoServerWakeupCallback
{
LogProtoServerWakeupFunc func;
gpointer user_data;
} LogProtoServerWakeupCallback;
struct _LogProtoServer
{
LogProtoStatus status;
const LogProtoServerOptions *options;
LogTransport *transport;
AckTracker *ack_tracker;
LogProtoServerWakeupCallback wakeup_callback;
/* FIXME: rename to something else */
gboolean (*is_position_tracked)(LogProtoServer *s);
LogProtoPrepareAction (*prepare)(LogProtoServer *s, GIOCondition *cond, gint *timeout);
gboolean (*restart_with_state)(LogProtoServer *s, PersistState *state, const gchar *persist_name);
LogProtoStatus (*fetch)(LogProtoServer *s, const guchar **msg, gsize *msg_len, gboolean *may_read,
LogTransportAuxData *aux, Bookmark *bookmark);
gboolean (*validate_options)(LogProtoServer *s);
gboolean (*handshake_in_progess)(LogProtoServer *s);
LogProtoStatus (*handshake)(LogProtoServer *s);
void (*free_fn)(LogProtoServer *s);
};
static inline gboolean
log_proto_server_validate_options(LogProtoServer *self)
{
return self->validate_options(self);
}
static inline gboolean
log_proto_server_handshake_in_progress(LogProtoServer *s)
{
if (s->handshake_in_progess)
{
return s->handshake_in_progess(s);
}
return FALSE;
}
static inline LogProtoStatus
log_proto_server_handshake(LogProtoServer *s)
{
if (s->handshake)
{
return s->handshake(s);
}
return LPS_SUCCESS;
}
static inline void
log_proto_server_set_options(LogProtoServer *self, const LogProtoServerOptions *options)
{
self->options = options;
}
static inline gboolean
log_proto_server_prepare(LogProtoServer *s, GIOCondition *cond, gint *timeout)
{
return s->prepare(s, cond, timeout);
}
static inline gboolean
log_proto_server_restart_with_state(LogProtoServer *s, PersistState *state, const gchar *persist_name)
{
if (s->restart_with_state)
return s->restart_with_state(s, state, persist_name);
return FALSE;
}
static inline LogProtoStatus
log_proto_server_fetch(LogProtoServer *s, const guchar **msg, gsize *msg_len, gboolean *may_read,
LogTransportAuxData *aux, Bookmark *bookmark)
{
if (s->status == LPS_SUCCESS)
return s->fetch(s, msg, msg_len, may_read, aux, bookmark);
return s->status;
}
static inline gint
log_proto_server_get_fd(LogProtoServer *s)
{
/* FIXME: Layering violation, as transport may not be fd based at all.
* But LogReader assumes it is. */
return s->transport->fd;
}
static inline void
log_proto_server_reset_error(LogProtoServer *s)
{
s->status = LPS_SUCCESS;
}
static inline gboolean
log_proto_server_is_position_tracked(LogProtoServer *s)
{
if (s->is_position_tracked)
return s->is_position_tracked(s);
return FALSE;
}
static inline void
log_proto_server_set_wakeup_cb(LogProtoServer *s, LogProtoServerWakeupFunc wakeup, gpointer user_data)
{
s->wakeup_callback.user_data = user_data;
s->wakeup_callback.func = wakeup;
}
static inline void
log_proto_server_wakeup_cb_call(LogProtoServerWakeupCallback *wakeup_callback)
{
if (wakeup_callback->func)
wakeup_callback->func(wakeup_callback->user_data);
}
gboolean log_proto_server_validate_options_method(LogProtoServer *s);
void log_proto_server_init(LogProtoServer *s, LogTransport *transport, const LogProtoServerOptions *options);
void log_proto_server_free_method(LogProtoServer *s);
void log_proto_server_free(LogProtoServer *s);
static inline void
log_proto_server_set_ack_tracker(LogProtoServer *s, AckTracker *ack_tracker)
{
g_assert(ack_tracker);
s->ack_tracker = ack_tracker;
}
#define DEFINE_LOG_PROTO_SERVER(prefix) \
static gpointer \
prefix ## _server_plugin_construct(Plugin *self) \
{ \
static LogProtoServerFactory proto = { \
.construct = prefix ## _server_new, \
}; \
return &proto; \
}
#define LOG_PROTO_SERVER_PLUGIN(prefix, __name) \
{ \
.type = LL_CONTEXT_SERVER_PROTO, \
.name = __name, \
.construct = prefix ## _server_plugin_construct, \
}
#define LOG_PROTO_SERVER_PLUGIN_WITH_GRAMMAR(__parser, __name) \
{ \
.type = LL_CONTEXT_SERVER_PROTO, \
.name = __name, \
.parser = &__parser, \
}
typedef struct _LogProtoServerFactory LogProtoServerFactory;
struct _LogProtoServerFactory
{
LogProtoServer *(*construct)(LogTransport *transport, const LogProtoServerOptions *options);
gint default_inet_port;
gboolean use_multitransport;
};
static inline LogProtoServer *
log_proto_server_factory_construct(LogProtoServerFactory *self, LogTransport *transport,
const LogProtoServerOptions *options)
{
return self->construct(transport, options);
}
LogProtoServerFactory *log_proto_server_get_factory(PluginContext *context, const gchar *name);
const guchar *find_eom(const guchar *s, gsize n);
#endif
|