Tor  0.4.7.0-alpha-dev
msgtypes.h
Go to the documentation of this file.
1 /* Copyright (c) 2001, Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file msgtypes.h
9  * \brief Types used for messages in the dispatcher code.
10  **/
11 
12 #ifndef TOR_DISPATCH_MSGTYPES_H
13 #define TOR_DISPATCH_MSGTYPES_H
14 
15 #include <stdint.h>
16 
17 #include "ext/tor_queue.h"
18 
19 /**
20  * These types are aliases for subsystems, channels, and message IDs.
21  **/
22 typedef uint16_t subsys_id_t;
23 typedef uint16_t channel_id_t;
24 typedef uint16_t message_id_t;
25 
26 /**
27  * This identifies a C type that can be sent along with a message.
28  **/
29 typedef uint16_t msg_type_id_t;
30 
31 /**
32  * An ID value returned for *_type_t when none exists.
33  */
34 #define ERROR_ID 65535
35 
36 /**
37  * Auxiliary (untyped) data sent along with a message.
38  *
39  * We define this as a union of a pointer and a u64, so that the integer
40  * types will have the same range across platforms.
41  **/
42 typedef union {
43  void *ptr;
44  uint64_t u64;
46 
47 /**
48  * Structure of a received message.
49  **/
50 typedef struct msg_t {
51  TOR_SIMPLEQ_ENTRY(msg_t) next;
52  subsys_id_t sender;
53  channel_id_t channel;
54  message_id_t msg;
55  /** We could omit this field, since it is implicit in the message type, but
56  * IMO let's leave it in for safety. */
58  /** Untyped auxiliary data. You shouldn't have to mess with this
59  * directly. */
61 } msg_t;
62 
63 /**
64  * A function that a subscriber uses to receive a message.
65  **/
66 typedef void (*recv_fn_t)(const msg_t *m);
67 
68 /**
69  * Table of functions to use for a given C type. Any omitted (NULL) functions
70  * will be treated as no-ops.
71  **/
72 typedef struct dispatch_typefns_t {
73  /** Release storage held for the auxiliary data of this type. */
75  /** Format and return a newly allocated string describing the contents
76  * of this data element. */
77  char *(*fmt_fn)(msg_aux_data_t);
79 
80 #endif /* !defined(TOR_DISPATCH_MSGTYPES_H) */
uint16_t subsys_id_t
Definition: msgtypes.h:22
uint16_t msg_type_id_t
Definition: msgtypes.h:29
void(* recv_fn_t)(const msg_t *m)
Definition: msgtypes.h:66
void(* free_fn)(msg_aux_data_t)
Definition: msgtypes.h:74
Definition: msgtypes.h:50
msg_type_id_t type
Definition: msgtypes.h:57
msg_aux_data_t aux_data__
Definition: msgtypes.h:60