/usr/share/doc/discover/api-reference/busclass-xml_8c-source.html is in libdiscover-dev 2.1.2-5.2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>discover: /home/pere/src/debiancvs/pkg-discover/discover/trunk/lib/busclass-xml.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
<div class="nav">
<a class="el" href="dir_000002.html">lib</a></div>
<h1>busclass-xml.c</h1><a href="busclass-xml_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001
00010 <span class="comment">/* $Progeny$</span>
00011 <span class="comment"> *</span>
00012 <span class="comment"> * AUTHOR: John R. Daily <jdaily@progeny.com></span>
00013 <span class="comment"> *</span>
00014 <span class="comment"> * Copyright 2002 Progeny Linux Systems, Inc.</span>
00015 <span class="comment"> * Copyright 2002 Hewlett-Packard Company</span>
00016 <span class="comment"> *</span>
00017 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
00018 <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span>
00019 <span class="comment"> * to deal in the Software without restriction, including without limitation</span>
00020 <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
00021 <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
00022 <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
00023 <span class="comment"> *</span>
00024 <span class="comment"> * The above copyright notice and this permission notice shall be included in</span>
00025 <span class="comment"> * all copies or substantial portions of the Software.</span>
00026 <span class="comment"> *</span>
00027 <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
00028 <span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
00029 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span>
00030 <span class="comment"> * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
00031 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
00032 <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
00033 <span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
00034 <span class="comment"> */</span>
00035
00036 <span class="preprocessor">#include "config.h"</span>
00037
00038 <span class="preprocessor">#include <sys/types.h></span>
00039
00040 <span class="preprocessor">#include <assert.h></span>
00041 <span class="preprocessor">#include <limits.h></span>
00042 <span class="preprocessor">#include <stdio.h></span>
00043 <span class="preprocessor">#include <string.h></span>
00044
00045 <span class="preprocessor">#include <expat.h></span>
00046
00047 <span class="preprocessor">#include <<a class="code" href="discover_8h.html">discover/discover.h</a>></span>
00048 <span class="preprocessor">#include <<a class="code" href="discover-xml_8h.html">discover/discover-xml.h</a>></span>
00049
00050 <span class="preprocessor">#include <discover/load-url.h></span>
00051 <span class="preprocessor">#include <discover/utils.h></span>
00052
00054 <span class="keyword">struct </span>discover_xml_busclass {
00055 <span class="keywordtype">char</span> *id;
00056 <span class="keywordtype">char</span> *name;
00057 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *next;
00058 };
00059
00060 <span class="keyword">static</span> <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclasses[<a class="code" href="group__types.html#ga14">BUS_COUNT</a>];
00061
00062 <span class="keyword">struct </span>context {
00063 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> **blist;
00064
00065 <span class="keywordtype">int</span> unknown_level; <span class="comment">/* How deep are we into unknown XML tags? */</span>
00066 };
00067
00068 <span class="keyword">static</span> <span class="keywordtype">char</span> *known_bus_elements[] = {
00069 <span class="stringliteral">"busclass"</span>,
00070 <span class="stringliteral">"busclass_list"</span>,
00071 NULL
00072 };
00073
00074 <span class="keyword">static</span> <span class="keywordtype">bool</span>
00075 unknown_bus_element(<span class="keyword">const</span> XML_Char * <span class="keyword">const</span> tag)
00076 {
00077 <span class="keywordtype">int</span> i;
00078 <span class="keywordflow">for</span> (i = 0; known_bus_elements[i] != NULL; i++) {
00079 <span class="keywordflow">if</span> (strcmp(tag, known_bus_elements[i]) == 0)
00080 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00081 }
00082 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00083 }
00084
00085 <span class="keyword">static</span> <span class="keywordtype">void</span>
00086 start_element(<span class="keywordtype">void</span> *ctx, <span class="keyword">const</span> XML_Char *name, <span class="keyword">const</span> XML_Char *attrs[])
00087 {
00088 <span class="keyword">struct </span>context *context = ctx;
00089 <span class="keywordtype">int</span> i;
00090 <span class="keywordtype">char</span> *vid, *vname;
00091 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *next, **blist;
00092
00093 assert(context != NULL);
00094 assert(name != NULL);
00095 assert(attrs != NULL);
00096
00097 <span class="keywordflow">if</span> (unknown_bus_element(name)) {
00098 context->unknown_level++;
00099 <span class="keywordflow">return</span>;
00100 }
00101
00102 <span class="keywordflow">if</span> (context->unknown_level > 0) {
00103 <span class="keywordflow">return</span>;
00104 }
00105
00106 <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"busclass"</span>) == 0) {
00107 vid = vname = NULL;
00108 <span class="keywordflow">for</span> (i = 0; attrs[i]; i += 2) {
00109 <span class="keywordflow">if</span> (strcmp(attrs[i], <span class="stringliteral">"id"</span>) == 0) {
00110 vid = (<span class="keywordtype">char</span> *) attrs[i + 1];
00111 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(attrs[i], <span class="stringliteral">"name"</span>) == 0) {
00112 vname = (<span class="keywordtype">char</span> *) attrs[i + 1];
00113 }
00114 }
00115
00116 assert(vid != NULL);
00117 assert(vname != NULL);
00118
00119 blist = context->blist;
00120 next = *blist;
00121 *blist = <a class="code" href="group__busclass__xml.html#ga8">discover_xml_busclass_new</a>();
00122 (*blist)->id = _discover_xstrdup(vid);
00123 (*blist)->name = _discover_xstrdup(vname);
00124 (*blist)->next = next;
00125 }
00126 }
00127
00128 <span class="keyword">static</span> <span class="keywordtype">void</span>
00129 end_element(<span class="keywordtype">void</span> *ctx, <span class="keyword">const</span> XML_Char *name)
00130 {
00131 <span class="keyword">struct </span>context *context = ctx;
00132
00133 assert(context != NULL);
00134 assert(name != NULL);
00135
00136 <span class="keywordflow">if</span> (unknown_bus_element(name)) {
00137 context->unknown_level--;
00138 <span class="keywordflow">return</span>;
00139 }
00140
00141 <span class="keywordflow">if</span> (context->unknown_level > 0) {
00142 <span class="keywordflow">return</span>;
00143 }
00144
00145 <span class="comment">/*</span>
00146 <span class="comment"> * We don't have any end tags to worry about, but if we did, they</span>
00147 <span class="comment"> * would be handled here.</span>
00148 <span class="comment"> */</span>
00149 }
00150
00151
00164 <span class="comment">/* Sshh! Don't tell, but this doesn't actually do any merging at all.</span>
00165 <span class="comment"> * Instead, it simply inserts newer entries at the front of the list,</span>
00166 <span class="comment"> * meaning that busclass info found later supersedes info found earlier.</span>
00167 <span class="comment"> * This gives the illusion of merging, but potentially wastes memory</span>
00168 <span class="comment"> * with duplicates.</span>
00169 <span class="comment"> */</span>
00170 <span class="keywordtype">void</span>
<a name="l00171"></a><a class="code" href="group__busclass__xml.html#ga0">00171</a> <a class="code" href="group__busclass__xml.html#ga0">discover_xml_merge_busclass_url</a>(<a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> **blist,
00172 <span class="keywordtype">char</span> *url, <a class="code" href="structdiscover__error.html">discover_error_t</a> *status)
00173 {
00174 XML_Parser parser;
00175 <span class="keyword">struct </span>context context;
00176
00177 assert(url != NULL);
00178 assert(status != NULL);
00179
00180 status-><a class="code" href="structdiscover__error.html#o0">code</a> = 0;
00181
00182 context.blist = blist;
00183 context.unknown_level = 0;
00184
00185 parser = XML_ParserCreate(NULL);
00186 XML_SetElementHandler(parser, start_element, end_element);
00187 XML_SetUserData(parser, &context);
00188
00189 <span class="keywordflow">if</span> (!_discover_load_url(url, parser)) {
00190 XML_ParserFree(parser);
00191 status-><a class="code" href="structdiscover__error.html#o0">code</a> = <a class="code" href="group__types.html#gga15a16">DISCOVER_EIO</a>;
00192 <span class="keywordflow">return</span>;
00193 }
00194
00195 <span class="keywordflow">if</span> (!XML_Parse(parser, <span class="stringliteral">""</span>, 0, 1)) {
00196 XML_ParserFree(parser);
00197 status-><a class="code" href="structdiscover__error.html#o0">code</a> = <a class="code" href="group__types.html#gga15a17">DISCOVER_EXML</a>;
00198 <span class="keywordflow">return</span>;
00199 }
00200
00201 XML_ParserFree(parser);
00202
00203 <span class="keywordflow">return</span>;
00204 }
00205
00212 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *
<a name="l00213"></a><a class="code" href="group__busclass__xml.html#ga1">00213</a> <a class="code" href="group__busclass__xml.html#ga1">discover_xml_get_busclasses</a>(<a class="code" href="group__types.html#ga16">discover_bus_t</a> bus, <a class="code" href="structdiscover__error.html">discover_error_t</a> *status)
00214 {
00215 <a class="code" href="group__types.html#ga7">discover_xml_url_t</a> *urls, *i;
00216 <span class="keywordtype">char</span> *url;
00217
00218 assert(status != NULL);
00219
00220 status-><a class="code" href="structdiscover__error.html#o0">code</a> = 0;
00221
00222 <span class="keywordflow">if</span> (!busclasses[bus]) {
00223 urls = <a class="code" href="group__url__xml.html#ga2">discover_xml_get_data_urls</a>(bus, BUSCLASS_TYPE, status);
00224 <span class="keywordflow">if</span> (status-><a class="code" href="structdiscover__error.html#o0">code</a> != 0) {
00225 <span class="keywordflow">return</span> NULL;
00226 }
00227
00228 <span class="keywordflow">for</span> (i = urls;
00229 i;
00230 i = <a class="code" href="group__url__xml.html#ga10">discover_xml_url_get_next</a>(i)) {
00231 url = <a class="code" href="group__url__xml.html#ga6">discover_xml_url_get_url</a>(i);
00232 <a class="code" href="group__busclass__xml.html#ga0">discover_xml_merge_busclass_url</a>(&(busclasses[bus]), url, status);
00233 <span class="keywordflow">if</span> (status-><a class="code" href="structdiscover__error.html#o0">code</a> != 0) {
00234 <span class="keywordflow">return</span> NULL;
00235 }
00236 }
00237 }
00238
00239 <span class="keywordflow">return</span> busclasses[bus];
00240 }
00241
00242
00246 <span class="keywordtype">void</span>
<a name="l00247"></a><a class="code" href="group__busclass__xml.html#ga2">00247</a> <a class="code" href="group__busclass__xml.html#ga2">discover_xml_free_busclasses</a>(<span class="keywordtype">void</span>)
00248 {
00249 <span class="keywordtype">int</span> i;
00250 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="group__types.html#ga14">BUS_COUNT</a>; i++) {
00251 <a class="code" href="group__busclass__xml.html#ga9">discover_xml_busclass_free</a>(busclasses[i]);
00252 busclasses[i] = NULL;
00253 }
00254 }
00255
00262 <span class="keywordtype">char</span> *
<a name="l00263"></a><a class="code" href="group__busclass__xml.html#ga3">00263</a> <a class="code" href="group__busclass__xml.html#ga3">discover_xml_busclass_to_class</a>(<span class="keywordtype">char</span> *busclass,
00264 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclasses)
00265 {
00266 <span class="keywordtype">char</span> *result;
00267
00268 assert(busclass != NULL);
00269 assert(busclasses != NULL);
00270
00271 result = NULL;
00272
00273 <span class="keywordflow">for</span> (;
00274 busclasses;
00275 busclasses = busclasses->next) {
00276 <span class="keywordflow">if</span> (strcmp(busclass, busclasses->id) == 0) {
00277 result = busclasses->name;
00278 <span class="keywordflow">break</span>;
00279 }
00280 }
00281
00282 <span class="keywordflow">return</span> result;
00283 }
00284
00294 <span class="keywordtype">int</span>
<a name="l00295"></a><a class="code" href="group__busclass__xml.html#ga4">00295</a> <a class="code" href="group__busclass__xml.html#ga4">discover_xml_busclass_cmp</a>(<span class="keywordtype">char</span> *busclass, <span class="keywordtype">char</span> *discover_class,
00296 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclasses)
00297 {
00298 <span class="keywordtype">char</span> *found_class_name = NULL;
00299
00300 assert(busclass != NULL);
00301 assert(discover_class != NULL);
00302 assert(busclasses != NULL);
00303
00304 <span class="keywordflow">if</span> (strcmp(discover_class, <span class="stringliteral">"all"</span>) == 0) {
00305 <span class="keywordflow">return</span> 0;
00306 }
00307
00308 found_class_name = <a class="code" href="group__busclass__xml.html#ga3">discover_xml_busclass_to_class</a>(busclass, busclasses);
00309
00310 <span class="comment">/*</span>
00311 <span class="comment"> * If the busclass database doesn't know about this device class, we</span>
00312 <span class="comment"> * can't make any valid comparison.</span>
00313 <span class="comment"> */</span>
00314 <span class="keywordflow">if</span> (found_class_name == NULL) {
00315 <span class="keywordflow">return</span> -1;
00316 }
00317
00318 <span class="keywordflow">return</span> strcmp(found_class_name, discover_class);
00319 }
00320
00326 <span class="keywordtype">char</span> *
<a name="l00327"></a><a class="code" href="group__busclass__xml.html#ga5">00327</a> <a class="code" href="group__busclass__xml.html#ga5">discover_xml_busclass_get_id</a>(<a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclass)
00328 {
00329 assert(busclass != NULL);
00330
00331 <span class="keywordflow">return</span> busclass->id;
00332 }
00333
00339 <span class="keywordtype">char</span> *
<a name="l00340"></a><a class="code" href="group__busclass__xml.html#ga6">00340</a> <a class="code" href="group__busclass__xml.html#ga6">discover_xml_busclass_get_name</a>(<a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclass)
00341 {
00342 assert(busclass != NULL);
00343
00344 <span class="keywordflow">return</span> busclass->name;
00345 }
00346
00351 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *
<a name="l00352"></a><a class="code" href="group__busclass__xml.html#ga7">00352</a> <a class="code" href="group__busclass__xml.html#ga7">discover_xml_busclass_get_next</a>(<a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclass)
00353 {
00354 assert(busclass != NULL);
00355
00356 <span class="keywordflow">return</span> busclass->next;
00357 }
00358
00362 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *
<a name="l00363"></a><a class="code" href="group__busclass__xml.html#ga8">00363</a> <a class="code" href="group__busclass__xml.html#ga8">discover_xml_busclass_new</a>(<span class="keywordtype">void</span>)
00364 {
00365 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *<span class="keyword">new</span>;
00366
00367 <span class="keyword">new</span> = _discover_xmalloc(<span class="keyword">sizeof</span>(<a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a>));
00368
00369 <span class="keyword">new</span>->id = NULL;
00370 <span class="keyword">new</span>->name = NULL;
00371 <span class="keyword">new</span>->next = NULL;
00372
00373 <span class="keywordflow">return</span> <span class="keyword">new</span>;
00374 }
00375
00381 <span class="keywordtype">void</span>
<a name="l00382"></a><a class="code" href="group__busclass__xml.html#ga9">00382</a> <a class="code" href="group__busclass__xml.html#ga9">discover_xml_busclass_free</a>(<a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclasses)
00383 {
00384 <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclass, *last;
00385
00386 last = NULL;
00387
00388 <span class="keywordflow">for</span> (busclass = busclasses;
00389 busclass;
00390 busclass = busclass->next) {
00391 <span class="keywordflow">if</span> (busclass->id) {
00392 free(busclass->id);
00393 }
00394
00395 <span class="keywordflow">if</span> (busclass->name) {
00396 free(busclass->name);
00397 }
00398
00399 <span class="keywordflow">if</span> (last) {
00400 free(last);
00401 }
00402 last = busclass;
00403 }
00404
00405 <span class="keywordflow">if</span> (last) {
00406 free(last);
00407 }
00408 }
00409
00412 <span class="comment">/*</span>
00413 <span class="comment"> * Local variables:</span>
00414 <span class="comment"> * c-file-style: "progeny"</span>
00415 <span class="comment"> * indent-tabs-mode: nil</span>
00416 <span class="comment"> * End:</span>
00417 <span class="comment"> */</span>
00418 <span class="comment">/* vim: set cin fo=tcroq sw=4 et sts=4 tw=75: */</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Jul 28 03:38:00 2005 for discover by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
|