MCPcopy Create free account
hub / github.com/acl-dev/acl / xmlToJson

Method xmlToJson

app/master/tools/master_dispatch/www/http_servlet.cpp:174–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174bool http_servlet::xmlToJson(acl::xml& xml, acl::json& json)
175{
176 /**
177 * ���ݸ�ʽ
178 * <servers>
179 * <server conns='xxx' used='xxx' qlen='xxx' max_threads='xxx'
180 * curr_threads='xxx' busy_threads='xxx' addr='xxx' load='xxx'>
181 * <proc>
182 * <conns>xxx</conns>
183 * <used>xxx</used>
184 * <pid>xxx</pid>
185 * <max_threads>xxx</max_threads>
186 * <curr_threads>xxx</curr_threads>
187 * <busy_threads>xxx</busy_threads>
188 * <qlen>xxx</qlen>
189 * <type>xxx</type>
190 * </proc>
191 * </server>
192 * </servers>
193 */
194
195 acl::xml_node& root = xml.get_root();
196 acl::xml_node* servers = NULL;
197 for (acl::xml_node* child = root.first_child();
198 child != NULL; child = root.next_child())
199 {
200 const char* tag = child->tag_name();
201 if (tag != NULL && strcasecmp(tag, "servers") == 0)
202 {
203 servers = child;
204 break;
205 }
206 }
207
208 if (servers == NULL)
209 {
210 logger_error("no servers found in: %s", xml.to_string());
211 return false;
212 }
213
214 acl::json_node& a = json.create_array();
215 json.get_root().add_child("servers", a);
216
217 for (acl::xml_node* child = servers->first_child();
218 child != NULL; child = servers->next_child())
219 {
220 const char* tag = child->tag_name();
221 if (tag == NULL || strcasecmp(tag, "server") != 0)
222 continue;
223
224 const char* ptr = (*child)["conns"];
225 if (ptr == NULL || *ptr == 0)
226 continue;
227 int conns = atoi(ptr);
228
229 if ((ptr = (*child)["used"]) == NULL || *ptr == 0)
230 continue;
231 int used = atoi(ptr);

Callers

nothing calls this directly

Calls 5

first_childMethod · 0.45
next_childMethod · 0.45
tag_nameMethod · 0.45
to_stringMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected