blob: 9fd1e67d0aff1b6b5b800d95fd6e654b10f01db7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2021, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* @file dispatch_naming.c
* @brief Name-to-ID maps for our message dispatch system.
**/
#include "orconfig.h"
#include "lib/cc/compat_compiler.h"
#include "lib/dispatch/dispatch_naming.h"
#include "lib/dispatch/msgtypes.h"
#include "lib/container/namemap.h"
#include "lib/container/namemap_st.h"
#include "lib/log/util_bug.h"
#include "lib/log/log.h"
#include <stdlib.h>
/** Global namemap for message IDs. */
static namemap_t message_id_map = NAMEMAP_INIT();
/** Global namemap for subsystem IDs. */
static namemap_t subsys_id_map = NAMEMAP_INIT();
/** Global namemap for channel IDs. */
static namemap_t channel_id_map = NAMEMAP_INIT();
/** Global namemap for message type IDs. */
static namemap_t msg_type_id_map = NAMEMAP_INIT();
void
dispatch_naming_init(void)
{
}
#ifndef COCCI
/* Helper macro: declare functions to map IDs to and from names for a given
* type in a namemap_t.
*/
#define DECLARE_ID_MAP_FNS(type) \
type##_id_t \
get_##type##_id(const char *name) \
{ \
unsigned u = namemap_get_or_create_id(&type##_id_map, name); \
tor_assert(u != NAMEMAP_ERR); \
tor_assert(u != ERROR_ID); \
return (type##_id_t) u; \
} \
const char * \
get_##type##_id_name(type##_id_t id) \
{ \
return namemap_fmt_name(&type##_id_map, id); \
} \
size_t \
get_num_##type##_ids(void) \
{ \
return namemap_get_size(&type##_id_map); \
} \
EAT_SEMICOLON
#endif /* !defined(COCCI) */
DECLARE_ID_MAP_FNS(message);
DECLARE_ID_MAP_FNS(channel);
DECLARE_ID_MAP_FNS(subsys);
DECLARE_ID_MAP_FNS(msg_type);
|