root/src/noit_jlog_listener.c

Revision 06f58e662d9dcb103af43ff53f3bd7e72248cea4, 2.0 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

prep for jlog transit over SSL

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #include "noit_defines.h"
7 #include "eventer/eventer.h"
8 #include "noit_listener.h"
9 #include "utils/noit_hash.h"
10 #include "utils/noit_log.h"
11 #include "jlog/jlog.h"
12 #include "noit_jlog_listener.h"
13
14 void
15 noit_jlog_listener_init() {
16   eventer_name_callback("log_transit", noit_jlog_handler);
17 }
18
19 typedef struct {
20   jlog_ctx *jlog;
21   int wants_shutdown;
22 } noit_jlog_closure_t;
23
24 noit_jlog_closure_t *
25 noit_jlog_closure_alloc(void) {
26   noit_jlog_closure_t *jcl;
27   jcl = calloc(1, sizeof(*jcl));
28   return jcl;
29 }
30
31 void
32 noit_jlog_closure_free(noit_jlog_closure_t *jcl) {
33   if(jcl->jlog) jlog_ctx_close(jcl->jlog);
34   free(jcl);
35 }
36
37 int
38 noit_jlog_handler(eventer_t e, int mask, void *closure,
39                      struct timeval *now) {
40   int newmask = EVENTER_READ | EVENTER_EXCEPTION;
41   acceptor_closure_t *ac = closure;
42   noit_jlog_closure_t *jcl = ac->service_ctx;
43
44   if(mask & EVENTER_EXCEPTION || (jcl && jcl->wants_shutdown)) {
45 socket_error:
46     /* Exceptions cause us to simply snip the connection */
47     eventer_remove_fd(e->fd);
48     e->opset->close(e->fd, &newmask, e);
49     if(jcl) noit_jlog_closure_free(jcl);
50     if(ac) acceptor_closure_free(ac);
51     return 0;
52   }
53
54   if(!ac->service_ctx) {
55     noit_log_stream_t ls;
56     const char *logname;
57     jcl = ac->service_ctx = noit_jlog_closure_alloc();
58     if(!noit_hash_retrieve(ac->config, "log", strlen("log"),
59                            (void **)&logname)) {
60       noitL(noit_error, "No 'log' specified in log_transit.\n");
61       goto socket_error;
62     }
63     ls = noit_log_stream_find(logname);
64     if(!ls) {
65       noitL(noit_error, "Could not find log '%s' for log_transit.\n",
66             logname);
67       goto socket_error;
68     }
69     if(!ls->type || strcmp(ls->type, "jlog")) {
70       noitL(noit_error, "Log '%s' for log_transit is not a jlog.\n",
71             logname);
72       goto socket_error;
73     }
74   }
75
76   e->opset->close(e->fd, &newmask, e);
77   eventer_remove_fd(e->fd);
78   return 0;
79 }
Note: See TracBrowser for help on using the browser.