Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_mgmt_common.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /**
34  * @file
35  * Common functions used for the output formatting by ocs_mgmt_* functions.
36  */
37 
38 #include "ocs.h"
39 #include "ocs_mgmt.h"
40 
41 static char *mode_string(int mode);
42 
43 
44 /**
45  * @ingroup mgmt
46  * @brief Generate the beginning of a numbered section in a management XML document.
47  *
48  * @par Description
49  * This function begins a section. The XML information is appended to
50  * the textbuf. This form of the function is used for sections that might have
51  * multiple instances, such as a node or a SLI Port (sport). The index number
52  * is appended to the name.
53  *
54  * @param textbuf Pointer to the driver dump text buffer.
55  * @param name Name of the section.
56  * @param index Index number of this instance of the section.
57  *
58  * @return None.
59  */
60 
61 extern void ocs_mgmt_start_section(ocs_textbuf_t *textbuf, const char *name, int index)
62 {
63  ocs_textbuf_printf(textbuf, "<%s instance=\"%d\">\n", name, index);
64 }
65 
66 /**
67  * @ingroup mgmt
68  * @brief Generate the beginning of an unnumbered section in a management XML document.
69  *
70  * @par Description
71  * This function begins a section. The XML information is appended to
72  * the textbuf. This form of the function is used for sections that have
73  * a single instance only. Therefore, no index number is needed.
74  *
75  * @param textbuf Pointer to the driver dump text buffer.
76  * @param name Name of the section.
77  *
78  * @return None.
79  */
80 
81 extern void ocs_mgmt_start_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
82 {
83  ocs_textbuf_printf(textbuf, "<%s>\n", name);
84 }
85 
86 /**
87  * @ingroup mgmt
88  * @brief Generate the end of a section in a management XML document.
89  *
90  * @par Description
91  * This function ends a section. The XML information is appended to
92  * the textbuf.
93  *
94  * @param textbuf Pointer to the driver dump text buffer.
95  * @param name Name of the section.
96  *
97  * @return None.
98  */
99 
101 {
102  ocs_textbuf_printf(textbuf, "</%s>\n", name);
103 }
104 
105 /**
106  * @ingroup mgmt
107  * @brief Generate the indexed end of a section in a management XML document.
108  *
109  * @par Description
110  * This function ends a section. The XML information is appended to
111  * the textbuf.
112  *
113  * @param textbuf Pointer to the driver dump text buffer.
114  * @param name Name of the section.
115  * @param index Index number of this instance of the section.
116  *
117  * @return None.
118  */
119 
120 void ocs_mgmt_end_section(ocs_textbuf_t *textbuf, const char *name, int index)
121 {
122 
123  ocs_textbuf_printf(textbuf, "</%s>\n", name);
124 
125 }
126 
127 /**
128  * @ingroup mgmt
129  * @brief Generate a property, with no value, in a management XML document.
130  *
131  * @par Description
132  * This function generates a property name. The XML information is appended to
133  * the textbuf. This form of the function is used by the list functions
134  * when the property name only (and not the current value) is given.
135  *
136  * @param textbuf Pointer to the driver dump text buffer.
137  * @param mode Defines whether the property is read(r)/write(w)/executable(x).
138  * @param name Name of the property.
139  *
140  * @return None.
141  */
142 
143 void ocs_mgmt_emit_property_name(ocs_textbuf_t *textbuf, int mode, const char *name)
144 {
145  ocs_textbuf_printf(textbuf, "<%s mode=\"%s\"/>\n", name, mode_string(mode));
146 }
147 
148 /**
149  * @ingroup mgmt
150  * @brief Generate a property with a string value in a management XML document.
151  *
152  * @par Description
153  * This function generates a property name and a string value.
154  * The XML information is appended to the textbuf.
155  *
156  * @param textbuf Pointer to the driver dump text buffer.
157  * @param mode Defines whether the property is read(r)/write(w)/executable(x).
158  * @param name Name of the property.
159  * @param value Value of the property.
160  *
161  * @return None.
162  */
163 
164 void ocs_mgmt_emit_string(ocs_textbuf_t *textbuf, int mode, const char *name, const char *value)
165 {
166  ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), value, name);
167 }
168 
169 /**
170  * @ingroup mgmt
171  * @brief Generate a property with an integer value in a management XML document.
172  *
173  * @par Description
174  * This function generates a property name and an integer value.
175  * The XML information is appended to the textbuf.
176  *
177  * @param textbuf Pointer to driver dump text buffer.
178  * @param mode Defines whether the property is read(r)/write(w)/executable(x).
179  * @param name Name of the property.
180  * @param fmt A printf format for formatting the integer value.
181  *
182  * @return none
183  */
184 
185 void ocs_mgmt_emit_int(ocs_textbuf_t *textbuf, int mode, const char *name, const char *fmt, ...)
186 {
187  va_list ap;
188  char valuebuf[64];
189 
190  va_start(ap, fmt);
191  ocs_vsnprintf(valuebuf, sizeof(valuebuf), fmt, ap);
192  va_end(ap);
193 
194  ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), valuebuf, name);
195 }
196 
197 /**
198  * @ingroup mgmt
199  * @brief Generate a property with a boolean value in a management XML document.
200  *
201  * @par Description
202  * This function generates a property name and a boolean value.
203  * The XML information is appended to the textbuf.
204  *
205  * @param textbuf Pointer to the driver dump text buffer.
206  * @param mode Defines whether the property is read(r)/write(w)/executable(x).
207  * @param name Name of the property.
208  * @param value Boolean value to be added to the textbuf.
209  *
210  * @return None.
211  */
212 
213 void ocs_mgmt_emit_boolean(ocs_textbuf_t *textbuf, int mode, const char *name, int value)
214 {
215  char *valuebuf = value ? "true" : "false";
216 
217  ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), valuebuf, name);
218 }
219 
220 static char *mode_string(int mode)
221 {
222  static char mode_str[4];
223 
224  mode_str[0] = '\0';
225  if (mode & MGMT_MODE_RD) {
226  strcat(mode_str, "r");
227  }
228  if (mode & MGMT_MODE_WR) {
229  strcat(mode_str, "w");
230  }
231  if (mode & MGMT_MODE_EX) {
232  strcat(mode_str, "x");
233  }
234 
235  return mode_str;
236 
237 }
void ocs_mgmt_emit_int(ocs_textbuf_t *textbuf, int mode, const char *name, const char *fmt,...)
Generate a property with an integer value in a management XML document.
#define MGMT_MODE_EX
Definition: ocs_mgmt.h:49
const char * name
Definition: ocs_ddump.h:54
void ocs_mgmt_start_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
Generate the beginning of an unnumbered section in a management XML document.
void ocs_mgmt_start_section(ocs_textbuf_t *textbuf, const char *name, int index)
Generate the beginning of a numbered section in a management XML document.
int const char const char void ocs_mgmt_emit_boolean(ocs_textbuf_t *textbuf, int access, const char *name, const int value)
Generate a property with a boolean value in a management XML document.
void ocs_mgmt_end_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
Generate the end of a section in a management XML document.
void ocs_mgmt_end_section(ocs_textbuf_t *textbuf, const char *name, int index)
Generate the indexed end of a section in a management XML document.
const char const char va_list ap
Definition: ocs_ramlog.h:54
#define MGMT_MODE_RD
Definition: ocs_mgmt.h:47
void ocs_textbuf_printf(ocs_textbuf_t *textbuf, const char *fmt,...)
Helper function to dump message.
Definition: ocs_textbuf.c:238
static char * mode_string(int mode)
#define MGMT_MODE_WR
Definition: ocs_mgmt.h:48
void ocs_mgmt_emit_string(ocs_textbuf_t *textbuf, int access, const char *name, const char *value)
Generate a property with a string value in a management XML document.
const char const char * fmt
Definition: ocs_ddump.h:54
void ocs_mgmt_emit_property_name(ocs_textbuf_t *textbuf, int access, const char *name)
Generate a property, with no value, in a management XML document.