1 /*
2  * vmx.h: VMware VMX parsing/formatting functions
3  *
4  * Copyright (C) 2009-2011, 2015 Matthias Bolte <matthias.bolte@googlemail.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library.  If not, see
18  * <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #pragma once
23 
24 #include "internal.h"
25 #include "virconf.h"
26 #include "domain_conf.h"
27 
28 #define VMX_CONFIG_FORMAT_ARGV "vmware-vmx"
29 
30 typedef struct _virVMXContext virVMXContext;
31 
32 virDomainXMLOption *virVMXDomainXMLConfInit(virCaps *caps);
33 
34 
35 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
36  * Context
37  */
38 
39 typedef int (*virVMXParseFileName)(const char *fileName,
40                                    void *opaque,
41                                    char **src,
42                                    bool allow_missing);
43 typedef char * (*virVMXFormatFileName)(const char *src, void *opaque);
44 typedef int (*virVMXAutodetectSCSIControllerModel)(virDomainDiskDef *def,
45                                                    int *model, void *opaque);
46 
47 /*
48  * parseFileName is only used by virVMXParseConfig.
49  * formatFileName is only used by virVMXFormatConfig.
50  * autodetectSCSIControllerModel is optionally used by virVMXFormatConfig.
51  * datacenterPath is only used by virVMXFormatConfig.
52  * moref is only used by virVMXFormatConfig.
53  */
54 struct _virVMXContext {
55     void *opaque;
56     virVMXParseFileName parseFileName;
57     virVMXFormatFileName formatFileName;
58     virVMXAutodetectSCSIControllerModel autodetectSCSIControllerModel;
59     const char *datacenterPath; /* including folders */
60     const char *moref;
61 };
62 
63 
64 
65 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
66  * Helpers
67  */
68 
69 char *virVMXEscapeHex(const char *string, char escape, const char *special);
70 
71 #define virVMXEscapeHexPipe(_string) virVMXEscapeHex(_string, '|', "\"")
72 
73 #define virVMXEscapeHexPercent(_string) virVMXEscapeHex(_string, '%', "/\\")
74 
75 int virVMXUnescapeHex(char *string, char escape);
76 
77 #define virVMXUnescapeHexPipe(_string) virVMXUnescapeHex(_string, '|')
78 
79 #define virVMXUnescapeHexPercent(_string) virVMXUnescapeHex(_string, '%')
80 
81 char *virVMXConvertToUTF8(const char *encoding, const char *string);
82 
83 
84 
85 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
86  * VMX -> Domain XML
87  */
88 
89 virDomainDef *virVMXParseConfig(virVMXContext *ctx,
90                                   virDomainXMLOption *xmlopt,
91                                   virCaps *caps,
92                                   const char *vmx);
93 
94 
95 
96 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
97  * Domain XML -> VMX
98  */
99 
100 char *virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt,
101                          virDomainDef *def, int virtualHW_version);
102