|
||||
File indexing completed on 2025-01-18 10:15:38
0001 #ifndef __XRDOUCGATHERCONF_HH__ 0002 #define __XRDOUCGATHERCONF_HH__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d O u c G a t h e r C o n f . h h */ 0006 /* */ 0007 /* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 0009 /* DE-AC02-76-SFO0515 with the Deprtment of Energy */ 0010 /* */ 0011 /* This file is part of the XRootD software suite. */ 0012 /* */ 0013 /* XRootD is free software: you can redistribute it and/or modify it under */ 0014 /* the terms of the GNU Lesser General Public License as published by the */ 0015 /* Free Software Foundation, either version 3 of the License, or (at your */ 0016 /* option) any later version. */ 0017 /* */ 0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0021 /* License for more details. */ 0022 /* */ 0023 /* You should have received a copy of the GNU Lesser General Public License */ 0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0026 /* */ 0027 /* The copyright holder's institutional names and contributor's names may not */ 0028 /* be used to endorse or promote products derived from this software without */ 0029 /* specific prior written permission of the institution or contributor. */ 0030 /******************************************************************************/ 0031 0032 struct XrdOucGatherConfData; 0033 class XrdSysError; 0034 0035 class XrdOucGatherConf 0036 { 0037 public: 0038 0039 //------------------------------------------------------------------------------ 0040 //! Echo the last line retrieved using GetLine() using proper framing. 0041 //! 0042 //! @notes 1) An exception is thrown if a XrdSysError object was not supplied. 0043 //------------------------------------------------------------------------------ 0044 0045 void EchoLine(); 0046 0047 //------------------------------------------------------------------------------ 0048 //! Specift the order in which the last line is displayed vs a message. 0049 //! 0050 //! @paramn doBefore - When true, the line is displayed before the message. 0051 //! When false, it is displayed after the message (default). 0052 //! 0053 //! @notes 1) This call is only relevant to calls to MsgE(), MsgW(), MsgfE(), 0054 //! and MsgfW. 0055 //------------------------------------------------------------------------------ 0056 0057 void EchoOrder(bool doBefore); 0058 0059 //------------------------------------------------------------------------------ 0060 //! Gather information from a config file. 0061 //! 0062 //! @note You must call this method or a successful useData() before calling 0063 //! any Get/Ret methods. 0064 //! 0065 //! @param cfname Path to the configuration file. 0066 //! @param lvl Indicates how the gathered directives are to be saved: 0067 //! full_lines - the full directive line, including newline. 0068 //! trim_lines - Like full_lines but the prefix (i.e.characters 0069 //! the dot) are discarded. Useful only when 0070 //! gathering a single prefix. 0071 //! only_body Saves the body of each wanted directive as a 0072 //! space separated string blob. 0073 //! trim_body Like only_body but also includes the directive 0074 //! characters after the dot. Useful only when 0075 //! gathering a single prefix. 0076 //! @param parms Optional pointer to initial configuration parameters. 0077 //! These may be present for plugins. 0078 //! 0079 //! @return > 0 Success, configuration data has been gathered. 0080 //! @return = 0 Nothing was gathered. 0081 //! @return < 0 Problem reading the config file, returned value is -errno. 0082 //------------------------------------------------------------------------------ 0083 0084 enum Level {full_lines = 0, //!< Complete lines 0085 trim_lines, //!< Prefix trimmed lines 0086 only_body, //!< Only directive bodies as a string blob. 0087 trim_body //!< Prefix trimmed lines as a string blob. 0088 }; 0089 0090 int Gather(const char *cfname, Level lvl, const char *parms=0); 0091 0092 //------------------------------------------------------------------------------ 0093 //! Sequence to the next line in the configuration file. 0094 //! 0095 //! @return Pointer to the next line that will be tokenized or NIL if there 0096 //! are no more lines left. 0097 //! 0098 //! @notes 1) You must call GetLine() before calling GetToken(). 0099 //------------------------------------------------------------------------------ 0100 0101 char* GetLine(); 0102 0103 //------------------------------------------------------------------------------ 0104 //! Get the next blank-delimited token in the record returned by Getline(). 0105 //! 0106 //! @param rest - Address of a char pointer. When specified, a pointer to 0107 //! the first non-blank character after the returned token. 0108 //! @param lowcasee - When 1, all characters are converted to lower case. 0109 //! When 0, the default, the characters are not changed. 0110 //! 0111 //! @return A pointer to the next token. If the end of the line has been 0112 //! reached, a NIL pointer is returned. 0113 //------------------------------------------------------------------------------ 0114 0115 char* GetToken(char **rest=0, int lowcase=0); 0116 0117 //------------------------------------------------------------------------------ 0118 //! Get the last line. 0119 //! 0120 //! @return pointer to the last line. If no last line exists a null string is 0121 //! returned. The pointer is valid until GetLine() is called. 0122 //------------------------------------------------------------------------------ 0123 0124 const char* LastLine(); 0125 0126 //------------------------------------------------------------------------------ 0127 //! Check if data is present. 0128 //! 0129 //! @return True if data is present and false, otherwise. 0130 //------------------------------------------------------------------------------ 0131 0132 bool hasData(); 0133 0134 //----------------------------------------------------------------------------- 0135 //! Display a space delimited error/warning message. 0136 //! 0137 //! @param txt1,txt2,txt3,txt4,txt5,txt6 the message components formatted as 0138 //! "txt1 [txt2] [txt3] [txt4] [txt5] [txt6]" 0139 //! 0140 //! @notes 1) This methods throws an exception if a XrdSysError object was not 0141 //! passed to the constructor. 0142 //! 2) The last line returned by this object will be displayed either 0143 //! before or after the message (see EchoOrder()). 0144 //! 3) Messages are truncated at 2048 bytes. 0145 //! 4} Use MsgE for errors. The text is prefixed by "Config mistake:" 0146 //! Use MsgW for warnings. The text is prefixed by "Config warning:" 0147 //----------------------------------------------------------------------------- 0148 0149 void MsgE(const char* txt1, const char* txt2=0, const char* txt3=0, 0150 const char* txt4=0, const char* txt5=0, const char* txt6=0); 0151 0152 void MsgW(const char* txt1, const char* txt2=0, const char* txt3=0, 0153 const char* txt4=0, const char* txt5=0, const char* txt6=0); 0154 0155 //----------------------------------------------------------------------------- 0156 //! Display a formated error/warning message using variable args (i.e. vprintf). 0157 //! 0158 //! @param fmt the message formatting template (i.e. printf format). 0159 //! @param ... the arguments that should be used with the template. The 0160 //! formatted message is truncated at 2048 bytes. 0161 //! 0162 //! @notes 1) This methods throws an exception if a XrdSysError object was not 0163 //! passed to the constructor. 0164 //! 2) The last line returned by this object will be displayed either 0165 //! before or after the message (see EchoOrder()). 0166 //! 3) Messages are truncated at 2048 bytes. 0167 //! 4} Use MsgfE for errors. The text is prefixed by "Config mistake:" 0168 //! Use MsgfW for warnings. The text is prefixed by "Config warning:" 0169 //----------------------------------------------------------------------------- 0170 0171 void MsgfE(const char *fmt, ...); 0172 0173 void MsgfW(const char *fmt, ...); 0174 0175 //------------------------------------------------------------------------------ 0176 //! Backups the token scanner just prior to the last returned token. 0177 //! 0178 //! @notes 1) Only one backup is allowed. Calling RetToken() more than once 0179 //! without an intervening GetToken() call results in undefined 0180 //! behaviour. 0181 //! 2) This call is useful for backing up due to an overscan. 0182 //------------------------------------------------------------------------------ 0183 0184 void RetToken(); 0185 0186 //------------------------------------------------------------------------------ 0187 //! Specify how tag characters should be handled. 0188 //! 0189 //! @param x - When 0, tabs are converted to spaces. 0190 //! When 1, tabs are untouched (the default). 0191 //------------------------------------------------------------------------------ 0192 0193 void Tabs(int x=1); 0194 0195 //------------------------------------------------------------------------------ 0196 //! Attempt to use pre-existing data. 0197 //! 0198 //! @param data - Pointer to null terminated pre-existing data. 0199 //! 0200 //! @return False if the pointer is nil or points to a null string; true o/w. 0201 //------------------------------------------------------------------------------ 0202 0203 bool useData(const char *data); 0204 0205 //------------------------------------------------------------------------------ 0206 //! Constructor #1 0207 //! 0208 //! @note This object collects relevant configuration directives ready to be 0209 //! processed by the Get/Ret methods. All if-fi, set, and variable 0210 //! substitutions are performed. 0211 //! 0212 //! @param want A space separated list of directive prefixes (i.e. end with a 0213 //! dot) and actual directives that should be gathered. 0214 //! @param errP Optional pointer to an error object. When supplied, gathered 0215 //! lines are echoed. Additionally, error messages are issued. supplied XrdSysError object or using std::cerr using a 0216 //------------------------------------------------------------------------------ 0217 0218 XrdOucGatherConf(const char *want, XrdSysError *errP=0); 0219 0220 //------------------------------------------------------------------------------ 0221 //! Constructor #2 0222 //! 0223 //! @note This is the same as constructor #1 but uses vector to hold the 0224 //! wanted directives or directive prefixes. 0225 //! 0226 //! @param want A vector of strings of directive prefixes (i.e. end with a 0227 //! dot) and actual directives that should be gathered. The 0228 //! end of the vector is indicated by a nil pointer 0229 //! (e,g, const char *want[] = {"x.c", "y.", 0}; 0230 //! @param errP Optional pointer to an error object. When supplied, gathered 0231 //! lines are echoed. Additionally, error messages are issued. supplied XrdSysError object or using std::cerr using a 0232 //------------------------------------------------------------------------------ 0233 0234 XrdOucGatherConf(const char **&want, XrdSysError *errP=0); 0235 0236 ~XrdOucGatherConf(); 0237 0238 private: 0239 0240 void MsgX(const char** mVec, int n); 0241 void MsgfX(const char* txt1, const char* txt2); 0242 0243 XrdOucGatherConfData *gcP; 0244 }; 0245 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |