root/src/stratcon_jlog_streamer.h

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

better debugging, refs #42

  • 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_str;
52   char *remote_cn;
53   u_int32_t current_backoff;
54   int wants_shutdown;
55   noit_hash_table *config;
56   noit_hash_table *sslconfig;
57   eventer_t timeout_event;
58
59   eventer_func_t consumer_callback;
60   void (*consumer_free)(void *);
61   void *consumer_ctx;
62 } noit_connection_ctx_t;
63
64 typedef struct jlog_streamer_ctx_t {
65   u_int32_t jlog_feed_cmd;
66   int bytes_expected;
67   int bytes_read;
68   char *buffer;         /* These guys are for doing partial reads */
69
70   enum {
71     JLOG_STREAMER_WANT_INITIATE = 0,
72     JLOG_STREAMER_WANT_COUNT = 1,
73     JLOG_STREAMER_WANT_HEADER = 2,
74     JLOG_STREAMER_WANT_BODY = 3,
75     JLOG_STREAMER_WANT_CHKPT = 4,
76   } state;
77   int count;            /* Number of jlog messages we need to read */
78   struct {
79     jlog_id   chkpt;
80     u_int32_t tv_sec;
81     u_int32_t tv_usec;
82     u_int32_t message_len;
83   } header;
84
85   void (*push)(stratcon_datastore_op_t, struct sockaddr *, void *);
86 } jlog_streamer_ctx_t;
87
88 API_EXPORT(void)
89   stratcon_jlog_streamer_init(const char *toplevel);
90 API_EXPORT(void)
91   stratcon_jlog_streamer_reload(const char *toplevel);
92 API_EXPORT(int)
93   stratcon_jlog_recv_handler(eventer_t e, int mask, void *closure,
94                              struct timeval *now);
95 API_EXPORT(jlog_streamer_ctx_t *)
96   stratcon_jlog_streamer_ctx_alloc(void);
97 API_EXPORT(void)
98   jlog_streamer_ctx_free(void *cl);
99 API_EXPORT(void)
100   stratcon_streamer_connection(const char *toplevel, const char *destination,
101                                eventer_func_t handler,
102                                void *(*handler_alloc)(void), void *handler_ctx,
103                                void (*handler_free)(void *));
104
105 #endif
Note: See TracBrowser for help on using the browser.