File: dclists.h

package info (click to toggle)
gdnsd 3.8.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,584 kB
  • sloc: ansic: 30,669; sh: 4,872; perl: 1,047; makefile: 401; pascal: 108
file content (86 lines) | stat: -rw-r--r-- 3,305 bytes parent folder | download | duplicates (3)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright © 2012 Brandon L Black <blblack@gmail.com>
 *
 * This file is part of gdnsd.
 *
 * gdnsd-plugin-geoip is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gdnsd-plugin-geoip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gdnsd.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef DCLISTS_H
#define DCLISTS_H

#include "dcinfo.h"

#include <gdnsd/compiler.h>
#include <gdnsd/vscf.h>

#include <inttypes.h>
#include <stdbool.h>

struct dclists {
    unsigned count; // count of unique result lists
    unsigned old_count; // count from object we cloned from
    uint8_t** list;    // strings of dc numbers
    const dcinfo_t* info; // dclists_t doesn't own "info", just uses it for reference a lot
};

typedef struct dclists dclists_t;

typedef enum {
    KILL_NO_LISTS,
    KILL_ALL_LISTS,
    KILL_NEW_LISTS
} dclists_destroy_depth_t;

// At the nlist/ntree layer, a uint32_t node reference has the high bit set
//   if it's a dclist, and cleared if it's an internal tree-node reference.
// This implies that legal, real dclist indices used in the construction of
//   nlist_t and ntree_t cannot have the high bit set, ever, and thus our
//   list of real dclist indices is a 31-bit value.
// As a further constraint, the maximal 31-bit value is not allowed for a real
//   dclist index because it is used in two magic ways:
//   1) At the dclists/dcmap/gdgeoip layer it's used to signal automatic
//     distance-mapped mapping (DCLIST_AUTO below), which will be translated
//     to a real dclist index before passing to the nlist/tree layer.
//   2) NN_UNDEF is the 'undefined' case at the nlist/tree layer and is the
//     value UINT32_MAX, and we don't want a legit dclist index, when OR'd
//     with the high-bit at the ntree layer, to overlap with this definition
//     of NN_UNDEF.
// Therefore:
#define DCLIST_AUTO 0x7FFFFFFF
#define DCLIST_MAX  0x7FFFFFFE

F_NONNULL F_WUNUSED F_RETNN
dclists_t* dclists_new(const dcinfo_t* info);
F_NONNULL F_WUNUSED F_RETNN
dclists_t* dclists_clone(const dclists_t* old);
F_NONNULL F_PURE
unsigned dclists_get_count(const dclists_t* lists);
F_NONNULL F_PURE F_RETNN
const uint8_t* dclists_get_list(const dclists_t* lists, const uint32_t idx);
F_NONNULL
void dclists_replace_list0(const dclists_t* lists, uint8_t* newlist);

// retval here: true -> "auto", false -> normal list
F_NONNULL
bool dclists_xlate_vscf(const dclists_t* lists, vscf_data_t* vscf_list, const char* map_name, uint8_t* newlist, const bool allow_auto);

F_NONNULL
uint32_t dclists_find_or_add_vscf(dclists_t* lists, vscf_data_t* vscf_list, const char* map_name, const bool allow_auto);
F_NONNULL
uint32_t dclists_city_auto_map(dclists_t* lists, const char* map_name, const double lat, const double lon);
F_NONNULL
void dclists_destroy(dclists_t* lists, dclists_destroy_depth_t depth);

#endif // DCLISTS_H