tor  0.4.2.1-alpha-dev
orconn_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 #include "lib/pubsub/pubsub.h"
21 #include "lib/subsys/subsys.h"
22 
23 #define ORCONN_EVENT_PRIVATE
24 #include "core/or/orconn_event.h"
26 
27 DECLARE_PUBLISH(orconn_state);
28 DECLARE_PUBLISH(orconn_status);
29 
30 static void
31 orconn_event_free(msg_aux_data_t u)
32 {
33  tor_free_(u.ptr);
34 }
35 
36 static char *
37 orconn_state_fmt(msg_aux_data_t u)
38 {
39  orconn_state_msg_t *msg = (orconn_state_msg_t *)u.ptr;
40  char *s = NULL;
41 
42  tor_asprintf(&s, "<gid=%"PRIu64" chan=%"PRIu64" proxy_type=%d state=%d>",
43  msg->gid, msg->chan, msg->proxy_type, msg->state);
44  return s;
45 }
46 
47 static char *
48 orconn_status_fmt(msg_aux_data_t u)
49 {
51  char *s = NULL;
52 
53  tor_asprintf(&s, "<gid=%"PRIu64" status=%d reason=%d>",
54  msg->gid, msg->status, msg->reason);
55  return s;
56 }
57 
58 static dispatch_typefns_t orconn_state_fns = {
59  .free_fn = orconn_event_free,
60  .fmt_fn = orconn_state_fmt,
61 };
62 
63 static dispatch_typefns_t orconn_status_fns = {
64  .free_fn = orconn_event_free,
65  .fmt_fn = orconn_status_fmt,
66 };
67 
68 static int
69 orconn_add_pubsub(struct pubsub_connector_t *connector)
70 {
71  if (DISPATCH_REGISTER_TYPE(connector, orconn_state, &orconn_state_fns))
72  return -1;
73  if (DISPATCH_REGISTER_TYPE(connector, orconn_status, &orconn_status_fns))
74  return -1;
75  if (DISPATCH_ADD_PUB(connector, orconn, orconn_state) != 0)
76  return -1;
77  if (DISPATCH_ADD_PUB(connector, orconn, orconn_status) != 0)
78  return -1;
79  return 0;
80 }
81 
82 void
83 orconn_state_publish(orconn_state_msg_t *msg)
84 {
85  PUBLISH(orconn_state, msg);
86 }
87 
88 void
89 orconn_status_publish(orconn_status_msg_t *msg)
90 {
91  PUBLISH(orconn_status, msg);
92 }
93 
94 const subsys_fns_t sys_orconn_event = {
95  .name = "orconn_event",
96  .supported = true,
97  .level = -33,
98  .add_pubsub = orconn_add_pubsub,
99 };
#define PUBLISH(messagename, arg)
struct pubsub_connector_t pubsub_connector_t
#define DECLARE_PUBLISH(messagename)
#define DISPATCH_REGISTER_TYPE(con, type, fns)
Header file for orconn_event.c.
#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
Declare subsystem object for the OR connection event module.
Master header file for Tor-specific functionality.
void tor_free_(void *mem)
Definition: malloc.c:227
const char * name
Definition: subsys.h:28
Header for OO publish-subscribe functionality.