tor  0.4.2.1-alpha-dev
dispatch_naming.c
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-2018, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 #include "orconfig.h"
8 
10 
11 #include "lib/dispatch/dispatch_naming.h"
12 #include "lib/dispatch/msgtypes.h"
13 
14 #include "lib/container/namemap.h"
15 #include "lib/container/namemap_st.h"
16 
17 #include "lib/log/util_bug.h"
18 #include "lib/log/log.h"
19 
20 #include <stdlib.h>
21 
23 static namemap_t message_id_map = NAMEMAP_INIT();
25 static namemap_t subsys_id_map = NAMEMAP_INIT();
27 static namemap_t channel_id_map = NAMEMAP_INIT();
29 static namemap_t msg_type_id_map = NAMEMAP_INIT();
30 
31 void
32 dispatch_naming_init(void)
33 {
34 }
35 
36 /* Helper macro: declare functions to map IDs to and from names for a given
37  * type in a namemap_t.
38  */
39 #define DECLARE_ID_MAP_FNS(type) \
40  type##_id_t \
41  get_##type##_id(const char *name) \
42  { \
43  unsigned u = namemap_get_or_create_id(&type##_id_map, name); \
44  tor_assert(u != NAMEMAP_ERR); \
45  tor_assert(u != ERROR_ID); \
46  return (type##_id_t) u; \
47  } \
48  const char * \
49  get_##type##_id_name(type##_id_t id) \
50  { \
51  return namemap_fmt_name(&type##_id_map, id); \
52  } \
53  size_t \
54  get_num_##type##_ids(void) \
55  { \
56  return namemap_get_size(&type##_id_map); \
57  } \
58  EAT_SEMICOLON
59 
60 DECLARE_ID_MAP_FNS(message);
61 DECLARE_ID_MAP_FNS(channel);
62 DECLARE_ID_MAP_FNS(subsys);
63 DECLARE_ID_MAP_FNS(msg_type);
Header for namemap.c.
Types used for messages in the dispatcher code.
Utility macros to handle different features and behavior in different compilers.
Headers for log.c.
Macros to manage assertions, fatal and non-fatal.