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-2018 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 
35 struct argv {
36  struct gc_arena gc;
37  size_t capacity;
38  size_t argc;
39  char **argv;
40 };
41 
42 struct argv argv_new(void);
43 
44 void argv_free(struct argv *a);
45 
46 const char *argv_str(const struct argv *a, struct gc_arena *gc, const unsigned int flags);
47 
48 struct argv argv_insert_head(const struct argv *a, const char *head);
49 
50 void argv_msg(const int msglev, const struct argv *a);
51 
52 void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
53 
54 void argv_parse_cmd(struct argv *a, const char *s);
55 
56 bool 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 
66 bool 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:233
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition: argv.c:90
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:485
list flags
bool argv_printf_cat(struct argv *a, const char *format,...)
printf() inspired argv concatenation.
Definition: argv.c:466
struct gc_arena gc
Definition: argv.h:36
size_t capacity
Definition: argv.h:37
char ** argv
Definition: argv.h:39
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:245
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:262
size_t argc
Definition: argv.h:38
bool argv_printf(struct argv *a, const char *format,...)
printf() variant which populates a struct argv.
Definition: argv.c:442
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition: argv.c:104
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
Definition: argv.h:35
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:210