"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.8.3/src/utils/common/params.h" (16 Jul 2019, 4154 Bytes) of package /linux/misc/dns/knot-2.8.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "params.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.7.6_vs_2.8.0.

    1 /*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15  */
   16 
   17 #pragma once
   18 
   19 #include <limits.h>
   20 #include <stdint.h>
   21 #include <stdbool.h>
   22 #include <stdio.h>
   23 
   24 #include "libknot/libknot.h"
   25 #include "contrib/ucw/lists.h"
   26 
   27 #define DEFAULT_IPV4_NAME   "127.0.0.1"
   28 #define DEFAULT_IPV6_NAME   "::1"
   29 #define DEFAULT_DNS_PORT    "53"
   30 #define DEFAULT_DNS_TLS_PORT    "853"
   31 #define DEFAULT_UDP_SIZE    512
   32 #define DEFAULT_EDNS_SIZE   4096
   33 #define MAX_PACKET_SIZE     65535
   34 
   35 #define SEP_CHARS       "\n\t "
   36 
   37 /*! \brief Variants of IP protocol. */
   38 typedef enum {
   39     IP_ALL,
   40     IP_4,
   41     IP_6
   42 } ip_t;
   43 
   44 /*! \brief Variants of transport protocol. */
   45 typedef enum {
   46     PROTO_ALL,
   47     PROTO_TCP,
   48     PROTO_UDP
   49 } protocol_t;
   50 
   51 /*! \brief Variants of output type. */
   52 typedef enum {
   53     /*!< Verbose output (same for host and dig). */
   54     FORMAT_FULL,
   55     /*!< Short dig output. */
   56     FORMAT_DIG,
   57     /*!< Brief host output. */
   58     FORMAT_HOST,
   59     /*!< Brief nsupdate output. */
   60     FORMAT_NSUPDATE
   61 } format_t;
   62 
   63 /*! \brief Text output settings. */
   64 typedef struct {
   65     /*!< Output format. */
   66     format_t    format;
   67 
   68     /*!< Style of rrset dump. */
   69     knot_dump_style_t   style;
   70 
   71     /*!< Show query packet. */
   72     bool    show_query;
   73     /*!< Show header info. */
   74     bool    show_header;
   75     /*!< Show section name. */
   76     bool    show_section;
   77     /*!< Show EDNS pseudosection. */
   78     bool    show_edns;
   79     /*!< Show QUERY/ZONE section. */
   80     bool    show_question;
   81     /*!< Show ANSWER/PREREQ section. */
   82     bool    show_answer;
   83     /*!< Show UPDATE/AUTHORITY section. */
   84     bool    show_authority;
   85     /*!< Show ADDITIONAL section. */
   86     bool    show_additional;
   87     /*!< Show TSIG pseudosection. */
   88     bool    show_tsig;
   89     /*!< Show footer info. */
   90     bool    show_footer;
   91 
   92     /*!< KHOST - Hide CNAME record in answer (duplicity reduction). */
   93     bool    hide_cname;
   94 } style_t;
   95 
   96 /*! \brief Parameter handler. */
   97 typedef int (*param_handle_f)(const char *arg, void *params);
   98 
   99 /*! \brief Parameter argument type. */
  100 typedef enum {
  101     ARG_NONE,
  102     ARG_REQUIRED,
  103     ARG_OPTIONAL
  104 } arg_t;
  105 
  106 /*! \brief Parameter specification. */
  107 typedef struct {
  108     const char     *name;
  109     arg_t          arg;
  110     param_handle_f handler;
  111 } param_t;
  112 
  113 inline static void print_version(const char *program_name)
  114 {
  115     printf("%s (Knot DNS), version %s\n", program_name, PACKAGE_VERSION);
  116 }
  117 
  118 /*!
  119  * \brief Transforms localized IDN string to ASCII punycode.
  120  *
  121  * \param idn_name  IDN name to transform.
  122  *
  123  * \retval NULL     if transformation fails.
  124  * \retval string   if ok.
  125  */
  126 char *name_from_idn(const char *idn_name);
  127 
  128 /*!
  129  * \brief Transforms ASCII punycode to localized IDN string.
  130  *
  131  * If an error occurs or IDN support is missing, this function does nothing.
  132  *
  133  * \param name  ASCII name to transform and replace with IDN name.
  134  */
  135 void name_to_idn(char **name);
  136 
  137 /*!
  138  * \brief Find the best parameter match in table based on prefix equality.
  139  *
  140  * \param str       Parameter name to look up.
  141  * \param str_len   Parameter name length.
  142  * \param tbl       Parameter table.
  143  * \param unique    Indication if output is unique result.
  144  *
  145  * \retval >=0      looked up parameter position in \a tbl.
  146  * \retval err      if error.
  147  */
  148 int best_param(const char *str, const size_t str_len, const param_t *tbl,
  149                bool *unique);
  150 
  151 char *get_reverse_name(const char *name);
  152 
  153 char *get_fqd_name(const char *name);
  154 
  155 int params_parse_class(const char *value, uint16_t *rclass);
  156 
  157 int params_parse_type(const char *value, uint16_t *rtype, int64_t *serial,
  158                       bool *notify);
  159 
  160 int params_parse_server(const char *value, list_t *servers, const char *def_port);
  161 
  162 int params_parse_wait(const char *value, int32_t *dst);