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 /* Unless otherwise stated, all functions return an errno value. */ 29 typedef struct XLU_Config XLU_Config; 30 typedef struct XLU_ConfigList XLU_ConfigList; 31 typedef struct XLU_ConfigValue XLU_ConfigValue; 32 33 XLU_Config *xlu_cfg_init(FILE *report, const char *report_filename); 34 /* 0 means we got ENOMEM. */ 35 /* report_filename is copied; report is saved and must remain valid 36 * until the Config is destroyed. */ 37 38 int xlu_cfg_readfile(XLU_Config*, const char *real_filename); 39 int xlu_cfg_readdata(XLU_Config*, const char *data, int length); 40 /* If these fail, then it is undefined behaviour to call xlu_cfg_get_... 41 * functions. You have to just xlu_cfg_destroy. */ 42 43 void xlu_cfg_destroy(XLU_Config*); 44 45 46 /* All of the following print warnings to "report" if there is a problem. 47 * Return values are: 48 * 0 OK 49 * ESRCH not defined 50 * EINVAL value found but wrong format for request (prints warning unless dont_warn=true) 51 * ERANGE value out of range (from strtol) 52 */ 53 54 int xlu_cfg_get_string(const XLU_Config*, const char *n, const char **value_r, 55 int dont_warn); 56 /* free/strdup version */ 57 int xlu_cfg_replace_string(const XLU_Config *cfg, const char *n, 58 char **value_r, int dont_warn); 59 int xlu_cfg_get_long(const XLU_Config*, const char *n, long *value_r, 60 int dont_warn); 61 int xlu_cfg_get_defbool(const XLU_Config*, const char *n, libxl_defbool *b, 62 int dont_warn); 63 64 int xlu_cfg_get_list(const XLU_Config*, const char *n, 65 XLU_ConfigList **list_r /* may be 0 */, 66 int *entries_r /* may be 0 */, 67 int dont_warn); 68 /* there is no need to free *list_r; lifetime is that of the XLU_Config */ 69 int xlu_cfg_get_list_as_string_list(const XLU_Config *cfg, const char *n, 70 libxl_string_list *sl, int dont_warn); 71 const char *xlu_cfg_get_listitem(const XLU_ConfigList*, int entry); 72 /* xlu_cfg_get_listitem cannot fail, except that if entry is 73 * out of range it returns 0 (not setting errno) */ 74 75 enum XLU_ConfigValueType xlu_cfg_value_type(const XLU_ConfigValue *value); 76 int xlu_cfg_value_get_string(const XLU_Config *cfg, XLU_ConfigValue *value, 77 char **value_r, int dont_warn); 78 int xlu_cfg_value_get_list(const XLU_Config *cfg, XLU_ConfigValue *value, 79 XLU_ConfigList **value_r, int dont_warn); 80 XLU_ConfigValue *xlu_cfg_get_listitem2(const XLU_ConfigList *list, 81 int entry); 82 83 /* 84 * Disk specification parsing. 85 */ 86 87 int xlu_disk_parse(XLU_Config *cfg, int nspecs, const char *const *specs, 88 libxl_device_disk *disk); 89 /* disk must have been initialised. 90 * 91 * On error, returns errno value. Bad strings cause EINVAL and 92 * print a message to cfg's report (that's all cfg is used for). 93 * 94 * Normally one would pass nspecs==1 and only specs[0]. But it is 95 * permitted to pass more strings in which case each is parsed as a 96 * string containing a collection of parameters (but they all refer 97 * to of the configuration for a single disk). 98 * 99 * nspecs==0 is permitted but since it does not specify some mandatory 100 * properties, it produces a run-time configuration error if the 101 * resulting disk struct is used with libxl. 102 */ 103 104 /* 105 * PCI specification parsing 106 */ 107 int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str); 108 109 /* 110 * RDM parsing 111 */ 112 int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve *rdm, const char *str); 113 114 /* 115 * Vif rate parsing. 116 */ 117 118 int xlu_vif_parse_rate(XLU_Config *cfg, const char *rate, 119 libxl_device_nic *nic); 120 121 #endif /* LIBXLUTIL_H */ 122 123 /* 124 * Local variables: 125 * mode: C 126 * c-basic-offset: 4 127 * indent-tabs-mode: nil 128 * End: 129 */ 130