OpenVPN
argv.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2024 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 *
24 * A printf-like function (that only recognizes a subset of standard printf
25 * format operators) that prints arguments to an argv list instead
26 * of a standard string. This is used to build up argv arrays for passing
27 * to execve.
28 */
29
30#ifndef ARGV_H
31#define ARGV_H
32
33#include "buffer.h"
34
35struct argv {
36 struct gc_arena gc;
37 size_t capacity;
38 size_t argc;
39 char **argv;
40};
41
42struct argv argv_new(void);
43
44void argv_free(struct argv *a);
45
46const char *argv_str(const struct argv *a, struct gc_arena *gc, const unsigned int flags);
47
48struct argv argv_insert_head(const struct argv *a, const char *head);
49
50void argv_msg(const int msglev, const struct argv *a);
51
52void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
53
54void argv_parse_cmd(struct argv *a, const char *s);
55
56bool argv_printf(struct argv *a, const char *format, ...)
57#ifdef __GNUC__
58#if __USE_MINGW_ANSI_STDIO
59__attribute__ ((format(gnu_printf, 2, 3)))
60#else
61__attribute__ ((format(__printf__, 2, 3)))
62#endif
63#endif
64;
65
66bool argv_printf_cat(struct argv *a, const char *format, ...)
67#ifdef __GNUC__
68#if __USE_MINGW_ANSI_STDIO
69__attribute__ ((format(gnu_printf, 2, 3)))
70#else
71__attribute__ ((format(__printf__, 2, 3)))
72#endif
73#endif
74;
75
76#endif /* ifndef ARGV_H */
const char * argv_str(const struct argv *a, struct gc_arena *gc, const unsigned int flags)
Generate a single string with all the arguments in a struct argv concatenated.
Definition argv.c:231
void argv_msg(const int msglev, const struct argv *a)
Write the arguments stored in a struct argv via the msg() command.
Definition argv.c:243
void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
Similar to argv_msg() but prefixes the messages being written with a given string.
Definition argv.c:260
bool argv_printf(struct argv *a, const char *format,...)
printf() variant which populates a struct argv.
Definition argv.c:440
bool argv_printf_cat(struct argv *a, const char *format,...)
printf() inspired argv concatenation.
Definition argv.c:464
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:102
void argv_parse_cmd(struct argv *a, const char *s)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
Definition argv.c:483
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:88
struct argv argv_insert_head(const struct argv *a, const char *head)
Inserts an argument string in front of all other argument slots.
Definition argv.c:208
Definition argv.h:35
char ** argv
Definition argv.h:39
size_t argc
Definition argv.h:38
size_t capacity
Definition argv.h:37
struct gc_arena gc
Definition argv.h:36
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:117
__attribute__((unused))
Definition test.c:42
struct gc_arena gc
Definition test_ssl.c:155