1 /* 2 * Copyright (C) 2010 Citrix Ltd. 3 * Author Ian Jackson <ian.jackson@eu.citrix.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Lesser General Public License as published 7 * by the Free Software Foundation; version 2.1 only. with the special 8 * exception on linking described in file LICENSE. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 */ 15 16 #ifndef LIBXLUTIL_H 17 #define LIBXLUTIL_H 18 19 #include <stdio.h> 20 21 #include "libxl.h" 22 23 enum XLU_ConfigValueType { 24 XLU_STRING, 25 XLU_LIST, 26 }; 27 28 enum XLU_Operation { 29 XLU_OP_ASSIGNMENT = 0, 30 XLU_OP_ADDITION, 31 }; 32 33 /* Unless otherwise stated, all functions return an errno value. */ 34 typedef struct XLU_Config XLU_Config; 35 typedef struct XLU_ConfigList XLU_ConfigList; 36 typedef struct XLU_ConfigValue XLU_ConfigValue; 37 38 XLU_Config *xlu_cfg_init(FILE *report, const char *report_filename); 39 /* 0 means we got ENOMEM. */ 40 /* report_filename is copied; report is saved and must remain valid 41 * until the Config is destroyed. */ 42 43 int xlu_cfg_readfile(XLU_Config*, const char *real_filename); 44 int xlu_cfg_readdata(XLU_Config*, const char *data, int length); 45 /* If these fail, then it is undefined behaviour to call xlu_cfg_get_... 46 * functions. You have to just xlu_cfg_destroy. */ 47 48 void xlu_cfg_destroy(XLU_Config*); 49 50 51 /* All of the following print warnings to "report" if there is a problem. 52 * Return values are: 53 * 0 OK 54 * ESRCH not defined 55 * EINVAL value found but wrong format for request (prints warning unless dont_warn=true) 56 * ERANGE value out of range (from strtol) 57 */ 58 59 int xlu_cfg_get_string(const XLU_Config*, const char *n, const char **value_r, 60 int dont_warn); 61 /* free/strdup version */ 62 int xlu_cfg_replace_string(const XLU_Config *cfg, const char *n, 63 char **value_r, int dont_warn); 64 int xlu_cfg_get_long(const XLU_Config*, const char *n, long *value_r, 65 int dont_warn); 66 int xlu_cfg_get_bounded_long(const XLU_Config*, const char *n, long min, 67 long max, long *value_r, int dont_warn); 68 int xlu_cfg_get_defbool(const XLU_Config*, const char *n, libxl_defbool *b, 69 int dont_warn); 70 71 int xlu_cfg_get_list(const XLU_Config*, const char *n, 72 XLU_ConfigList **list_r /* may be 0 */, 73 int *entries_r /* may be 0 */, 74 int dont_warn); 75 /* there is no need to free *list_r; lifetime is that of the XLU_Config */ 76 int xlu_cfg_get_list_as_string_list(const XLU_Config *cfg, const char *n, 77 libxl_string_list *sl, int dont_warn); 78 const char *xlu_cfg_get_listitem(const XLU_ConfigList*, int entry); 79 /* xlu_cfg_get_listitem cannot fail, except that if entry is 80 * out of range it returns 0 (not setting errno) */ 81 82 enum XLU_ConfigValueType xlu_cfg_value_type(const XLU_ConfigValue *value); 83 int xlu_cfg_value_get_string(const XLU_Config *cfg, XLU_ConfigValue *value, 84 char **value_r, int dont_warn); 85 int xlu_cfg_value_get_list(const XLU_Config *cfg, XLU_ConfigValue *value, 86 XLU_ConfigList **value_r, int dont_warn); 87 XLU_ConfigValue *xlu_cfg_get_listitem2(const XLU_ConfigList *list, 88 int entry); 89 90 /* 91 * Disk specification parsing. 92 */ 93 94 int xlu_disk_parse(XLU_Config *cfg, int nspecs, const char *const *specs, 95 libxl_device_disk *disk); 96 /* disk must have been initialised. 97 * 98 * On error, returns errno value. Bad strings cause EINVAL and 99 * print a message to cfg's report (that's all cfg is used for). 100 * 101 * Normally one would pass nspecs==1 and only specs[0]. But it is 102 * permitted to pass more strings in which case each is parsed as a 103 * string containing a collection of parameters (but they all refer 104 * to of the configuration for a single disk). 105 * 106 * nspecs==0 is permitted but since it does not specify some mandatory 107 * properties, it produces a run-time configuration error if the 108 * resulting disk struct is used with libxl. 109 */ 110 111 /* 112 * PCI specification parsing 113 */ 114 int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str); 115 116 /* 117 * RDM parsing 118 */ 119 int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve *rdm, const char *str); 120 121 /* 122 * Vif rate parsing. 123 */ 124 125 int xlu_vif_parse_rate(XLU_Config *cfg, const char *rate, 126 libxl_device_nic *nic); 127 128 #endif /* LIBXLUTIL_H */ 129 130 /* 131 * Local variables: 132 * mode: C 133 * c-basic-offset: 4 134 * indent-tabs-mode: nil 135 * End: 136 */ 137