root/src/stratcon_jlog_streamer.h

Revision 304ec80b8cf842fc0abe5f9029790908b6455957, 4.0 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 months ago)

Convert to libmtev.

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