tor  0.4.2.1-alpha-dev
ocirc_event.c
Go to the documentation of this file.
1 /* Copyright (c) 2007-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
19 #include "core/or/or.h"
20 
21 #define OCIRC_EVENT_PRIVATE
22 
23 #include "core/or/cpath_build_state_st.h"
24 #include "core/or/ocirc_event.h"
26 #include "core/or/origin_circuit_st.h"
27 #include "lib/subsys/subsys.h"
28 
29 DECLARE_PUBLISH(ocirc_state);
30 DECLARE_PUBLISH(ocirc_chan);
31 DECLARE_PUBLISH(ocirc_cevent);
32 
33 static void
34 ocirc_event_free(msg_aux_data_t u)
35 {
36  tor_free_(u.ptr);
37 }
38 
39 static char *
40 ocirc_state_fmt(msg_aux_data_t u)
41 {
42  ocirc_state_msg_t *msg = (ocirc_state_msg_t *)u.ptr;
43  char *s = NULL;
44 
45  tor_asprintf(&s, "<gid=%"PRIu32" state=%d onehop=%d>",
46  msg->gid, msg->state, msg->onehop);
47  return s;
48 }
49 
50 static char *
51 ocirc_chan_fmt(msg_aux_data_t u)
52 {
53  ocirc_chan_msg_t *msg = (ocirc_chan_msg_t *)u.ptr;
54  char *s = NULL;
55 
56  tor_asprintf(&s, "<gid=%"PRIu32" chan=%"PRIu64" onehop=%d>",
57  msg->gid, msg->chan, msg->onehop);
58  return s;
59 }
60 
61 static char *
62 ocirc_cevent_fmt(msg_aux_data_t u)
63 {
64  ocirc_cevent_msg_t *msg = (ocirc_cevent_msg_t *)u.ptr;
65  char *s = NULL;
66 
67  tor_asprintf(&s, "<gid=%"PRIu32" evtype=%d reason=%d onehop=%d>",
68  msg->gid, msg->evtype, msg->reason, msg->onehop);
69  return s;
70 }
71 
72 static dispatch_typefns_t ocirc_state_fns = {
73  .free_fn = ocirc_event_free,
74  .fmt_fn = ocirc_state_fmt,
75 };
76 
77 static dispatch_typefns_t ocirc_chan_fns = {
78  .free_fn = ocirc_event_free,
79  .fmt_fn = ocirc_chan_fmt,
80 };
81 
82 static dispatch_typefns_t ocirc_cevent_fns = {
83  .free_fn = ocirc_event_free,
84  .fmt_fn = ocirc_cevent_fmt,
85 };
86 
87 static int
88 ocirc_add_pubsub(struct pubsub_connector_t *connector)
89 {
90  if (DISPATCH_REGISTER_TYPE(connector, ocirc_state, &ocirc_state_fns))
91  return -1;
92  if (DISPATCH_REGISTER_TYPE(connector, ocirc_chan, &ocirc_chan_fns))
93  return -1;
94  if (DISPATCH_REGISTER_TYPE(connector, ocirc_cevent, &ocirc_cevent_fns))
95  return -1;
96  if (DISPATCH_ADD_PUB(connector, ocirc, ocirc_state))
97  return -1;
98  if (DISPATCH_ADD_PUB(connector, ocirc, ocirc_chan))
99  return -1;
100  if (DISPATCH_ADD_PUB(connector, ocirc, ocirc_cevent))
101  return -1;
102  return 0;
103 }
104 
105 void
106 ocirc_state_publish(ocirc_state_msg_t *msg)
107 {
108  PUBLISH(ocirc_state, msg);
109 }
110 
111 void
112 ocirc_chan_publish(ocirc_chan_msg_t *msg)
113 {
114  PUBLISH(ocirc_chan, msg);
115 }
116 
117 void
118 ocirc_cevent_publish(ocirc_cevent_msg_t *msg)
119 {
120  PUBLISH(ocirc_cevent, msg);
121 }
122 
123 const subsys_fns_t sys_ocirc_event = {
124  .name = "ocirc_event",
125  .supported = true,
126  .level = -32,
127  .add_pubsub = ocirc_add_pubsub,
128 };
Declare subsystem object for the origin circuit event module.
#define PUBLISH(messagename, arg)
struct pubsub_connector_t pubsub_connector_t
#define DECLARE_PUBLISH(messagename)
#define DISPATCH_REGISTER_TYPE(con, type, fns)
#define DISPATCH_ADD_PUB(connector, channel, messagename)
void(* free_fn)(msg_aux_data_t)
Definition: msgtypes.h:74
int tor_asprintf(char **strp, const char *fmt,...)
Definition: printf.c:75
Master header file for Tor-specific functionality.
void tor_free_(void *mem)
Definition: malloc.c:227
const char * name
Definition: subsys.h:28
Header file for ocirc_event.c.