Tor  0.4.7.0-alpha-dev
dispatch_naming.c
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 dispatch_naming.c
9  * @brief Name-to-ID maps for our message dispatch system.
10  **/
11 
12 #include "orconfig.h"
13 
14 #include "lib/cc/compat_compiler.h"
15 
17 #include "lib/dispatch/msgtypes.h"
18 
19 #include "lib/container/namemap.h"
21 
22 #include "lib/log/util_bug.h"
23 #include "lib/log/log.h"
24 
25 #include <stdlib.h>
26 
27 /** Global namemap for message IDs. */
29 /** Global namemap for subsystem IDs. */
31 /** Global namemap for channel IDs. */
33 /** Global namemap for message type IDs. */
35 
36 void
37 dispatch_naming_init(void)
38 {
39 }
40 
41 #ifndef COCCI
42 /* Helper macro: declare functions to map IDs to and from names for a given
43  * type in a namemap_t.
44  */
45 #define DECLARE_ID_MAP_FNS(type) \
46  type##_id_t \
47  get_##type##_id(const char *name) \
48  { \
49  unsigned u = namemap_get_or_create_id(&type##_id_map, name); \
50  tor_assert(u != NAMEMAP_ERR); \
51  tor_assert(u != ERROR_ID); \
52  return (type##_id_t) u; \
53  } \
54  const char * \
55  get_##type##_id_name(type##_id_t id) \
56  { \
57  return namemap_fmt_name(&type##_id_map, id); \
58  } \
59  size_t \
60  get_num_##type##_ids(void) \
61  { \
62  return namemap_get_size(&type##_id_map); \
63  } \
64  EAT_SEMICOLON
65 #endif /* !defined(COCCI) */
66 
67 DECLARE_ID_MAP_FNS(message);
68 DECLARE_ID_MAP_FNS(channel);
69 DECLARE_ID_MAP_FNS(subsys);
70 DECLARE_ID_MAP_FNS(msg_type);
Utility macros to handle different features and behavior in different compilers.
static namemap_t msg_type_id_map
static namemap_t channel_id_map
static namemap_t message_id_map
static namemap_t subsys_id_map
Header for dispatch_naming.c.
Headers for log.c.
Types used for messages in the dispatcher code.
Header for namemap.c.
Internal declarations for namemap structure.
#define NAMEMAP_INIT()
Definition: namemap_st.h:38
Macros to manage assertions, fatal and non-fatal.