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
|
/*
* 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.
*
*/
#include "logproto-framed-client.h"
#include "logproto-text-client.h"
#include "messages.h"
#define LPFCS_FRAME_SEND 0
#define LPFCS_MESSAGE_SEND 1
typedef struct _LogProtoFramedClient
{
LogProtoTextClient super;
guchar frame_hdr_buf[9];
} LogProtoFramedClient;
static LogProtoStatus
log_proto_framed_client_post(LogProtoClient *s, LogMessage *logmsg, guchar *msg, gsize msg_len, gboolean *consumed)
{
LogProtoFramedClient *self = (LogProtoFramedClient *) s;
gint frame_hdr_len;
LogProtoStatus status;
if (msg_len > 9999999)
{
static const guchar *warn_msg;
if (warn_msg != msg)
{
msg_warning("Error, message length too large for framed protocol, truncated",
evt_tag_int("length", msg_len));
warn_msg = msg;
}
msg_len = 9999999;
}
status = LPS_SUCCESS;
while (status == LPS_SUCCESS && !(*consumed) && self->super.partial == NULL)
{
switch (self->super.state)
{
case LPFCS_FRAME_SEND:
frame_hdr_len = g_snprintf((gchar *) self->frame_hdr_buf, sizeof(self->frame_hdr_buf), "%" G_GSIZE_FORMAT" ", msg_len);
status = log_proto_text_client_submit_write(s, self->frame_hdr_buf, frame_hdr_len, NULL, LPFCS_MESSAGE_SEND);
break;
case LPFCS_MESSAGE_SEND:
*consumed = TRUE;
status = log_proto_text_client_submit_write(s, msg, msg_len, (GDestroyNotify) g_free, LPFCS_FRAME_SEND);
break;
default:
g_assert_not_reached();
}
}
return status;
}
LogProtoClient *
log_proto_framed_client_new(LogTransport *transport, const LogProtoClientOptions *options)
{
LogProtoFramedClient *self = g_new0(LogProtoFramedClient, 1);
log_proto_text_client_init(&self->super, transport, options);
self->super.super.post = log_proto_framed_client_post;
self->super.state = LPFCS_FRAME_SEND;
return &self->super.super;
}
|