root/src/stratcon_jlog_streamer.h

Revision 88a71780101cbf23034aa0cb840f9f0368fda2dd, 3.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

fixes #126

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _STRATCON_LOG_STREAMER_H
34 #define _STRATCON_LOG_STREAMER_H
35
36 #include "noit_conf.h"
37 #include "jlog/jlog.h"
38 #include <netinet/in.h>
39 #include <sys/un.h>
40 #include <arpa/inet.h>
41 #include "stratcon_datastore.h"
42
43 typedef struct noit_connection_ctx_t {
44   union {
45     struct sockaddr remote;
46     struct sockaddr_un remote_un;
47     struct sockaddr_in remote_in;
48     struct sockaddr_in6 remote_in6;
49   } r;
50   socklen_t remote_len;
51   char *remote_cn;
52   u_int32_t current_backoff;
53   int wants_shutdown;
54   noit_hash_table *config;
55   noit_hash_table *sslconfig;
56   eventer_t timeout_event;
57
58   eventer_func_t consumer_callback;
59   void (*consumer_free)(void *);
60   void *consumer_ctx;
61 } noit_connection_ctx_t;
62
63 typedef struct jlog_streamer_ctx_t {
64   u_int32_t jlog_feed_cmd;
65   int bytes_expected;
66   int bytes_read;
67   char *buffer;         /* These guys are for doing partial reads */
68
69   enum {
70     JLOG_STREAMER_WANT_INITIATE = 0,
71     JLOG_STREAMER_WANT_COUNT = 1,
72     JLOG_STREAMER_WANT_HEADER = 2,
73     JLOG_STREAMER_WANT_BODY = 3,
74     JLOG_STREAMER_WANT_CHKPT = 4,
75   } state;
76   int count;            /* Number of jlog messages we need to read */
77   struct {
78     jlog_id   chkpt;
79     u_int32_t tv_sec;
80     u_int32_t tv_usec;
81     u_int32_t message_len;
82   } header;
83
84   void (*push)(stratcon_datastore_op_t, struct sockaddr *, void *);
85 } jlog_streamer_ctx_t;
86
87 API_EXPORT(void)
88   stratcon_jlog_streamer_init(const char *toplevel);
89 API_EXPORT(void)
90   stratcon_jlog_streamer_reload(const char *toplevel);
91 API_EXPORT(int)
92   stratcon_jlog_recv_handler(eventer_t e, int mask, void *closure,
93                              struct timeval *now);
94 API_EXPORT(jlog_streamer_ctx_t *)
95   stratcon_jlog_streamer_ctx_alloc(void);
96 API_EXPORT(void)
97   jlog_streamer_ctx_free(void *cl);
98 API_EXPORT(void)
99   stratcon_streamer_connection(const char *toplevel, const char *destination,
100                                eventer_func_t handler,
101                                void *(*handler_alloc)(void), void *handler_ctx,
102                                void (*handler_free)(void *));
103
104 #endif
Note: See TracBrowser for help on using the browser.