File: options.h

package info (click to toggle)
nbdkit 1.46.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,504 kB
  • sloc: ansic: 63,658; sh: 18,717; makefile: 6,814; python: 1,848; cpp: 1,143; perl: 504; ml: 504; tcl: 62
file content (164 lines) | stat: -rw-r--r-- 6,707 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* nbdkit
 * Copyright Red Hat
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of Red Hat nor the names of its contributors may be
 * used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef NBDKIT_OPTIONS_H
#define NBDKIT_OPTIONS_H

#include <stdbool.h>
#include <getopt.h>
#include <limits.h>
#include <string.h>

enum {
  HELP_OPTION = CHAR_MAX + 1,
  DUMP_CONFIG_OPTION,
  DUMP_PLUGIN_OPTION,
  EXIT_WITH_PARENT_OPTION,
  FILTER_OPTION,
  KEEPALIVE_OPTION,
  LOG_OPTION,
  LONG_OPTIONS_OPTION,
  MASK_HANDSHAKE_OPTION,
  NAME_OPTION,
  NO_MC_OPTION,
  NO_SR_OPTION,
  PRINT_URI,
  RUN_OPTION,
  SELINUX_LABEL_OPTION,
  SHORT_OPTIONS_OPTION,
  SWAP_OPTION,
  TIMEOUT_OPTION,
  TLS_OPTION,
  TLS_CERTIFICATES_OPTION,
  TLS_PRIORITY_OPTION,
  TLS_PSK_OPTION,
  TLS_VERIFY_PEER_OPTION,
  VSOCK_OPTION,
};

static const char *short_options = "46D:e:fg:i:nop:P:rst:u:U:vV";
static const struct option long_options[] = {
  { "ipv4-only",        no_argument,       NULL, '4' },
  { "ipv6-only",        no_argument,       NULL, '6' },
  { "debug",            required_argument, NULL, 'D' },
  { "dump-config",      no_argument,       NULL, DUMP_CONFIG_OPTION },
  { "dump-plugin",      no_argument,       NULL, DUMP_PLUGIN_OPTION },
  { "exit-with-parent", no_argument,       NULL, EXIT_WITH_PARENT_OPTION },
  { "export",           required_argument, NULL, 'e' },
  { "export-name",      required_argument, NULL, 'e' },
  { "exportname",       required_argument, NULL, 'e' },
  { "filter",           required_argument, NULL, FILTER_OPTION },
  { "foreground",       no_argument,       NULL, 'f' },
  { "no-fork",          no_argument,       NULL, 'f' },
  { "group",            required_argument, NULL, 'g' },
  { "help",             no_argument,       NULL, HELP_OPTION },
  { "ip-addr",          required_argument, NULL, 'i' },
  { "ipaddr",           required_argument, NULL, 'i' },
  { "keepalive",        no_argument,       NULL, KEEPALIVE_OPTION },
  { "keep-alive",       no_argument,       NULL, KEEPALIVE_OPTION },
  { "log",              required_argument, NULL, LOG_OPTION },
  { "long-options",     no_argument,       NULL, LONG_OPTIONS_OPTION },
  { "mask-handshake",   required_argument, NULL, MASK_HANDSHAKE_OPTION },
  { "name",             required_argument, NULL, NAME_OPTION },
  { "new-style",        no_argument,       NULL, 'n' },
  { "newstyle",         no_argument,       NULL, 'n' },
  { "no-mc",            no_argument,       NULL, NO_MC_OPTION },
  { "no-meta-contexts", no_argument,       NULL, NO_MC_OPTION },
  { "no-sr",            no_argument,       NULL, NO_SR_OPTION },
  { "no-structured-replies", no_argument,  NULL, NO_SR_OPTION },
  { "old-style",        no_argument,       NULL, 'o' },
  { "oldstyle",         no_argument,       NULL, 'o' },
  { "pid-file",         required_argument, NULL, 'P' },
  { "pidfile",          required_argument, NULL, 'P' },
  { "print-uri",        no_argument,       NULL, PRINT_URI },
  { "print-url",        no_argument,       NULL, PRINT_URI },
  { "port",             required_argument, NULL, 'p' },
  { "read-only",        no_argument,       NULL, 'r' },
  { "readonly",         no_argument,       NULL, 'r' },
  { "run",              required_argument, NULL, RUN_OPTION },
  { "selinux-label",    required_argument, NULL, SELINUX_LABEL_OPTION },
  { "short-options",    no_argument,       NULL, SHORT_OPTIONS_OPTION },
  { "show-uri",         no_argument,       NULL, PRINT_URI },
  { "show-url",         no_argument,       NULL, PRINT_URI },
  { "single",           no_argument,       NULL, 's' },
  { "stdin",            no_argument,       NULL, 's' },
  { "swap",             no_argument,       NULL, SWAP_OPTION },
  { "threads",          required_argument, NULL, 't' },
  { "timeout",          required_argument, NULL, TIMEOUT_OPTION },
  { "time-out",         required_argument, NULL, TIMEOUT_OPTION },
  { "tls",              required_argument, NULL, TLS_OPTION },
  { "tls-certificates", required_argument, NULL, TLS_CERTIFICATES_OPTION },
  { "tls-priority",     required_argument, NULL, TLS_PRIORITY_OPTION },
  { "tls-psk",          required_argument, NULL, TLS_PSK_OPTION },
  { "tls-verify-peer",  no_argument,       NULL, TLS_VERIFY_PEER_OPTION },
  { "unix",             required_argument, NULL, 'U' },
  { "user",             required_argument, NULL, 'u' },
  { "verbose",          no_argument,       NULL, 'v' },
  { "version",          no_argument,       NULL, 'V' },
  { "vsock",            no_argument,       NULL, VSOCK_OPTION },
  { NULL },
};

/* Is it a plugin or filter name relative to the plugindir/filterdir? */
static inline bool
is_short_name (const char *filename)
{
  const size_t n = strlen (filename);
  size_t i;

  /* Empty string is not a short name. */
  if (n == 0) return false;

  for (i = 0; i < n; ++i) {
    switch (filename[i]) {
    case '/': case '\\':        /* directory separators */
    case ':': case ';':         /* path separators */
    case ' ':
    case '.':
    case ',':
    case '=':                   /* nbdkit parameter separator */
      return false;

      /* non-printable ASCII */
    case 127:
      return false;
    default:
      if ((unsigned)filename[i] <= 31)
        return false;
    }
  }

  /* Short names cannot contain the dir separator string. */
  return strstr (filename, DIR_SEPARATOR_STR) == NULL;
}

#endif /* NBDKIT_OPTIONS_H */