This file is indexed.

/usr/share/doc/discover/api-reference/device-xml_8c-source.html is in libdiscover-dev 2.1.2-5.1.

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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
<!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/device-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&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;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>device-xml.c</h1><a href="device-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 &lt;jdaily@progeny.com&gt;</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="comment">/*</span>
00037 <span class="comment"> * This is slightly different than busclass-xml.c and vendor-xml.c.</span>
00038 <span class="comment"> * With those, the data that interests us is actually in the</span>
00039 <span class="comment"> * XML files, so the structures built by those modules are the final</span>
00040 <span class="comment"> * structures.</span>
00041 <span class="comment"></span>
00042 <span class="comment"> * With the devices, the list we build here is only an intermediate</span>
00043 <span class="comment"> * place to store the discover_device structures.  When we probe the</span>
00044 <span class="comment"> * bus, we will move the discover_device structures for which</span>
00045 <span class="comment"> * we have found corresponding hardware from this list to the final</span>
00046 <span class="comment"> * one. (That action happens in the modules for the individual buses,</span>
00047 <span class="comment"> * such as pci.c.)</span>
00048 <span class="comment"></span>
00049 <span class="comment"> * Whereas busclass-xml.c and vendor-xml.c create pci_busclasses and</span>
00050 <span class="comment"> * pci_vendors lists, respectively, this module creates</span>
00051 <span class="comment"> * pci_devices_xml.  Objects are moved from this list to the</span>
00052 <span class="comment"> * pci_devices list in pci.c, and the rest are freed.</span>
00053 <span class="comment"> */</span>
00054 
00055 <span class="preprocessor">#include "config.h"</span>
00056 
00057 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
00058 
00059 <span class="preprocessor">#include &lt;assert.h&gt;</span>
00060 <span class="preprocessor">#include &lt;ctype.h&gt;</span>
00061 <span class="preprocessor">#include &lt;limits.h&gt;</span>
00062 <span class="preprocessor">#include &lt;stdbool.h&gt;</span>
00063 <span class="preprocessor">#include &lt;string.h&gt;</span>
00064 <span class="preprocessor">#include &lt;errno.h&gt;</span>
00065 
00066 <span class="preprocessor">#include &lt;expat.h&gt;</span>
00067 
00068 <span class="preprocessor">#include &lt;<a class="code" href="discover_8h.html">discover/discover.h</a>&gt;</span>
00069 <span class="preprocessor">#include &lt;<a class="code" href="discover-xml_8h.html">discover/discover-xml.h</a>&gt;</span>
00070 
00071 <span class="preprocessor">#include &lt;discover/load-url.h&gt;</span>
00072 <span class="preprocessor">#include &lt;discover/device.h&gt;</span>
00073 <span class="preprocessor">#include &lt;discover/utils.h&gt;</span>
00074 <span class="preprocessor">#include &lt;discover/stack.h&gt;</span>
00075 
<a name="l00077"></a><a class="code" href="device-xml_8c.html#a0">00077</a> <span class="preprocessor">#define IDLEN 5</span>
00078 <span class="preprocessor"></span>
00079 <span class="keyword">static</span> <a class="code" href="group__types.html#ga3">discover_device_t</a> *devices_xml[<a class="code" href="group__types.html#ga14">BUS_COUNT</a>];
00080 
<a name="l00082"></a><a class="code" href="device-xml_8c.html#a20">00082</a> <span class="keyword">enum</span> <a class="code" href="conf_8c.html#a33">state</a> { START, FINISH, DEVICE, DATA };
00083 <span class="keyword">struct </span>context {
00084     <span class="keyword">enum</span> <a class="code" href="conf_8c.html#a33">state</a> <a class="code" href="conf_8c.html#a33">state</a>;
00085 
00086     <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclasses;
00087     <a class="code" href="group__types.html#ga6">discover_xml_vendor_t</a> *vendors;
00088 
00089     <span class="comment">/* Device stuff */</span>
00090     <a class="code" href="group__types.html#ga3">discover_device_t</a> **dhead;
00091     <a class="code" href="group__types.html#ga3">discover_device_t</a> *dtail;
00092 
00093     <span class="comment">/* data stuff */</span>
00094     discover_xml_stack *stack;
00095 <span class="comment">/*</span>
00096 <span class="comment">    discover_data_t *data_current;</span>
00097 <span class="comment">    discover_data_t *data_parent;</span>
00098 <span class="comment">*/</span>
00099     <span class="keywordtype">int</span> nesting;
00100     <span class="keywordtype">int</span> last_nesting;
00101 
00102     <span class="keywordtype">int</span> unknown_level; <span class="comment">/* How deep are we into unknown XML tags? */</span>
00103 };
00104 
00105 <span class="keyword">static</span> <span class="keywordtype">char</span> *known_device_elements[] = {
00106     <span class="stringliteral">"data"</span>,
00107     <span class="stringliteral">"device"</span>,
00108     <span class="stringliteral">"device_list"</span>,
00109     NULL
00110 };
00111 
00112 <span class="keyword">static</span> <span class="keywordtype">void</span>
00113 get_data_failure_handler(<a class="code" href="structdiscover__error.html">discover_error_t</a> **status, <span class="keywordtype">char</span> *url)
00114 {
00115     <span class="keywordtype">char</span> *errmsg;
00116     <span class="keyword">static</span> <span class="keywordtype">int</span> maxurlsize = 1024; <span class="comment">/* If your URL is longer than this,</span>
00117 <span class="comment">                                     you've got problems */</span>
00118 
00119     <span class="keywordflow">if</span>((*status)-&gt;code == <a class="code" href="group__types.html#gga15a16">DISCOVER_EIO</a>) {
00120         errmsg = _discover_xmalloc(maxurlsize + 1);
00121         snprintf(errmsg, maxurlsize, <span class="stringliteral">"Resource not found: %s"</span>, url);
00122         (*status)-&gt;create_message(status, errmsg);
00123         free(errmsg);
00124     } <span class="keywordflow">else</span> {
00125         <span class="keywordflow">if</span> (errno) {
00126             errmsg = _discover_xmalloc(maxurlsize + 1);
00127             snprintf(errmsg, maxurlsize, <span class="stringliteral">"Problem loading resource: %s: %s"</span>,
00128                      strerror(errno), url);
00129             (*status)-&gt;create_message(status, errmsg);
00130             free(errmsg);
00131         } <span class="keywordflow">else</span> {
00132             (*status)-&gt;create_message(status,
00133                     <span class="stringliteral">"Unknown failure from system-dependent libraries"</span>);
00134         }
00135     }
00136 }
00137 
00138 <span class="keyword">static</span> <span class="keywordtype">bool</span>
00139 unknown_device_element(<span class="keyword">const</span> XML_Char * <span class="keyword">const</span> tag)
00140 {
00141     <span class="keywordtype">int</span> i;
00142     <span class="keywordflow">for</span> (i = 0; known_device_elements[i] != NULL; i++) {
00143         <span class="keywordflow">if</span> (strcmp(tag, known_device_elements[i]) == 0)
00144             <span class="keywordflow">return</span> <span class="keyword">false</span>;
00145     }
00146     <span class="keywordflow">return</span> <span class="keyword">true</span>;
00147 }
00148 
00149 <span class="keyword">static</span> <span class="keywordtype">void</span>
00150 create_device(<span class="keyword">struct</span> context *context, <span class="keyword">const</span> XML_Char *attrs[])
00151 {
00152     <span class="keywordtype">int</span> i;
00153     <span class="keywordtype">char</span> *busclass, *model_id, *model_name, *vendor_id, *vendor_name;
00154     <a class="code" href="group__types.html#ga3">discover_device_t</a> *new_device;
00155 
00156     assert(context != NULL);
00157     assert(attrs != NULL);
00158 
00159     busclass = model_id = model_name = vendor_id = NULL;
00160     <span class="keywordflow">for</span> (i = 0; attrs[i]; i += 2) {
00161         <span class="keywordflow">if</span> (strcmp(attrs[i], <span class="stringliteral">"busclass"</span>) == 0) {
00162             busclass = (<span class="keywordtype">char</span> *)attrs[i + 1];
00163 
00164         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(attrs[i], <span class="stringliteral">"model"</span>) == 0) {
00165             model_id = (<span class="keywordtype">char</span> *)attrs[i + 1];
00166 
00167         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(attrs[i], <span class="stringliteral">"model_name"</span>) == 0) {
00168             model_name = (<span class="keywordtype">char</span> *)attrs[i + 1];
00169 
00170         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(attrs[i], <span class="stringliteral">"vendor"</span>) == 0) {
00171             vendor_id = (<span class="keywordtype">char</span> *)attrs[i + 1];
00172         }
00173     }
00174 
00175     assert(model_id != NULL);
00176     assert(model_name != NULL);
00177     assert(vendor_id != NULL);
00178 
00179     vendor_name = <a class="code" href="group__vendor__xml.html#ga3">discover_xml_vendor_id2name</a>(context-&gt;vendors, vendor_id);
00180     assert(vendor_name != NULL);
00181 
00182     context-&gt;stack = <a class="code" href="stack_8c.html#a0">discover_xml_stack_new</a>();
00183 
00184     new_device = <a class="code" href="group__device.html#ga22">discover_device_new</a>();
00185     new_device-&gt;busclasses = context-&gt;busclasses;
00186     new_device-&gt;vendors = context-&gt;vendors;
00187     <span class="keywordflow">if</span> (busclass) {
00188         new_device-&gt;busclass = _discover_xstrdup(busclass);
00189     } <span class="keywordflow">else</span> {
00190         new_device-&gt;busclass = NULL;
00191     }
00192     new_device-&gt;model_id = _discover_xstrdup(model_id);
00193     new_device-&gt;model_name = _discover_xstrdup(model_name);
00194     new_device-&gt;vendor_id = _discover_xstrdup(vendor_id);
00195     new_device-&gt;vendor_name = _discover_xstrdup(vendor_name);
00196     new_device-&gt;data = NULL;
00197     new_device-&gt;next = NULL;
00198 
00199     <span class="keywordflow">if</span> (*(context-&gt;dhead)) {
00200         context-&gt;dtail-&gt;next = new_device;
00201         context-&gt;dtail = new_device;
00202     } <span class="keywordflow">else</span> {
00203         *(context-&gt;dhead) = new_device;
00204         context-&gt;dtail = new_device;
00205     }
00206 }
00207 
00208 <span class="keyword">static</span> <span class="keywordtype">void</span>
00209 create_data(<span class="keyword">struct</span> context *context, <span class="keyword">const</span> XML_Char *attrs[])
00210 {
00211     <a class="code" href="group__types.html#ga4">discover_data_t</a> *new_data, *current_data;
00212     discover_xml_stack *stack;
00213     <span class="keywordtype">int</span> i;
00214     <span class="keywordtype">char</span> *discover_class, *version;
00215 
00216     assert(context != NULL);
00217     assert(attrs != NULL);
00218 
00219     new_data = <a class="code" href="group__device.html#ga13">discover_data_new</a>();
00220     new_data-&gt;text = NULL;
00221     new_data-&gt;next = new_data-&gt;prev = new_data-&gt;child = NULL;
00222 
00223 
00224     discover_class = version = NULL;
00225     <span class="keywordflow">for</span> (i = 0; attrs[i]; i += 2) {
00226         <span class="keywordflow">if</span> (strcmp(attrs[i], <span class="stringliteral">"class"</span>) == 0) {
00227             discover_class = (<span class="keywordtype">char</span> *)attrs[i + 1];
00228         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(attrs[i], <span class="stringliteral">"version"</span>) == 0) {
00229             version = (<span class="keywordtype">char</span> *)attrs[i + 1];
00230         }
00231     }
00232 
00233     assert(discover_class != NULL);
00234 
00235     new_data-&gt;discover_class = _discover_xstrdup(discover_class);
00236     <span class="keywordflow">if</span> (version) {
00237         new_data-&gt;version = _discover_xstrdup(version);
00238     }
00239 
00240     stack = context-&gt;stack;
00241 
00242     assert(stack != NULL);
00243 
00244     current_data = <a class="code" href="stack_8c.html#a4">discover_xml_stack_get</a>(stack);
00245 
00246     <span class="keywordflow">if</span>(current_data) { <span class="comment">/* The first time through this, we have no data. */</span>
00247         <span class="comment">/* First element of the list */</span>
00248         <span class="keywordflow">if</span>(stack-&gt;depth &gt; context-&gt;nesting) {
00249             <a class="code" href="stack_8c.html#a3">discover_xml_stack_pop</a>(&amp;stack);
00250             <span class="comment">//current_data = discover_xml_stack_pop(&amp;stack);</span>
00251             new_data-&gt;prev = current_data;
00252             new_data-&gt;prev-&gt;next = new_data;
00253             <span class="keywordflow">if</span>(context-&gt;nesting) {
00254                 new_data-&gt;parent =
00255                     <a class="code" href="stack_8c.html#a5">discover_xml_stack_getbynum</a>(stack, context-&gt;nesting);
00256             }
00257         } <span class="keywordflow">else</span> {
00258             <span class="comment">/* Brand new child */</span>
00259             new_data-&gt;parent = current_data;
00260             new_data-&gt;parent-&gt;child = new_data;
00261         }
00262     }
00263 
00264     <a class="code" href="stack_8c.html#a2">discover_xml_stack_push</a>(&amp;stack, new_data);
00265     context-&gt;stack = stack;
00266 }
00267 
00268 <span class="keyword">static</span> <span class="keywordtype">void</span>
00269 start_element(<span class="keywordtype">void</span> *ctx, <span class="keyword">const</span> XML_Char *name, <span class="keyword">const</span> XML_Char *attrs[])
00270 {
00271     <span class="keyword">struct </span>context *context = ctx;
00272 
00273     assert(context != NULL);
00274     assert(name != NULL);
00275     assert(attrs != NULL);
00276 
00277 
00278     <span class="keywordflow">if</span> (unknown_device_element(name)) {
00279         context-&gt;unknown_level++;
00280         <span class="keywordflow">return</span>;
00281     }
00282 
00283     <span class="keywordflow">if</span> (context-&gt;unknown_level &gt; 0) {
00284         <span class="keywordflow">return</span>;
00285     }
00286 
00287     <span class="keywordflow">switch</span> (context-&gt;state) {
00288     <span class="keywordflow">case</span> FINISH:
00289         <span class="keywordflow">return</span>;
00290 
00291     <span class="keywordflow">case</span> START:
00292         <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"device"</span>) == 0) {
00293             context-&gt;state = DEVICE;
00294             create_device(context, attrs);
00295         }
00296         <span class="keywordflow">break</span>;
00297 
00298     <span class="keywordflow">case</span> DEVICE:
00299         <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"data"</span>) == 0) {
00300             context-&gt;nesting = context-&gt;last_nesting = 0;
00301             context-&gt;state = DATA;
00302         }
00303         <span class="comment">/* Falls through */</span>
00304 
00305     <span class="keywordflow">case</span> DATA:
00306         <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"data"</span>) == 0) {
00307             create_data(context, attrs);
00308             context-&gt;last_nesting = context-&gt;nesting;
00309             context-&gt;nesting++;
00310         }
00311         <span class="keywordflow">break</span>;
00312     }
00313 }
00314 
00315 <span class="keyword">static</span> <span class="keywordtype">void</span>
00316 end_element(<span class="keywordtype">void</span> *ctx, <span class="keyword">const</span> XML_Char *name)
00317 {
00318     <span class="keyword">struct </span>context *context = ctx;
00319     <a class="code" href="group__types.html#ga3">discover_device_t</a> *device;
00320     <a class="code" href="group__types.html#ga4">discover_data_t</a> *current_data;
00321     discover_xml_stack *stack;
00322 
00323 
00324     assert(context != NULL);
00325     assert(name != NULL);
00326 
00327 
00328     <span class="keywordflow">if</span> (unknown_device_element(name)) {
00329         context-&gt;unknown_level--;
00330         <span class="keywordflow">return</span>;
00331     }
00332 
00333     <span class="keywordflow">if</span> (context-&gt;unknown_level &gt; 0) {
00334         <span class="keywordflow">return</span>;
00335     }
00336 
00337     <span class="keywordflow">switch</span> (context-&gt;state) {
00338     <span class="keywordflow">case</span> FINISH:
00339     <span class="keywordflow">case</span> START:
00340         <span class="keywordflow">break</span>;
00341 
00342     <span class="keywordflow">case</span> DEVICE:
00343         context-&gt;state = START;
00344         device = context-&gt;dtail;
00345         stack = context-&gt;stack;
00346         current_data = <a class="code" href="stack_8c.html#a4">discover_xml_stack_get</a>(stack);
00347         device-&gt;data = <a class="code" href="group__device.html#ga12">discover_data_get_first</a>(current_data);
00348 
00349         <span class="keywordflow">while</span> (<a class="code" href="stack_8c.html#a3">discover_xml_stack_pop</a>(&amp;(context-&gt;stack))) ;
00350         <a class="code" href="stack_8c.html#a1">discover_xml_stack_destroy</a>(context-&gt;stack);
00351         context-&gt;stack = NULL;
00352 
00353         <span class="keywordflow">break</span>;
00354 
00355     <span class="keywordflow">case</span> DATA:
00356         context-&gt;nesting--;
00357         stack = context-&gt;stack;
00358         <span class="keywordflow">if</span>((context-&gt;nesting + 2) &lt;= stack-&gt;depth) {
00359             <span class="keywordflow">while</span>((context-&gt;nesting + 1 &lt; stack-&gt;depth) &amp;&amp;
00360                     stack-&gt;depth &gt; 1) {
00361                 <a class="code" href="stack_8c.html#a3">discover_xml_stack_pop</a>(&amp;stack);
00362             }
00363             context-&gt;stack = stack;
00364         }
00365 
00366         <span class="keywordflow">if</span> (context-&gt;nesting == 0) {
00367             context-&gt;state = DEVICE;
00368         }
00369     }
00370 }
00371 
00372 <span class="keyword">static</span> <span class="keywordtype">void</span>
00373 cdata(<span class="keywordtype">void</span> *ctx, <span class="keyword">const</span> XML_Char *data, <span class="keywordtype">int</span> len)
00374 {
00375     <span class="keyword">struct </span>context *context = ctx;
00376     size_t old_len;
00377     <a class="code" href="group__types.html#ga4">discover_data_t</a> *current_data;
00378 
00379     assert(context != NULL);
00380     assert(data != NULL);
00381 
00382     <span class="keywordflow">if</span> (context-&gt;state == DATA
00383         &amp;&amp; context-&gt;nesting &gt; context-&gt;last_nesting) {
00384         assert(context-&gt;stack != NULL);
00385         current_data = context-&gt;stack-&gt;data;
00386         assert(current_data != NULL);
00387 
00388         <span class="keywordflow">if</span> (!current_data-&gt;text) {
00389             old_len = 0;
00390             current_data-&gt;text = _discover_xmalloc(1);
00391             current_data-&gt;text[0] = <span class="charliteral">'\0'</span>;
00392         } <span class="keywordflow">else</span> {
00393             old_len = strlen(current_data-&gt;text);
00394         }
00395         current_data-&gt;text
00396             = _discover_xrealloc(current_data-&gt;text,
00397                                  old_len + len + 1);
00398         strncat(current_data-&gt;text,
00399                 (<span class="keyword">const</span> <span class="keywordtype">char</span> *)data,
00400                 (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)len);
00401     }
00402 }
00403 
00418 <span class="comment">/* Sshh!  Don't tell, but this doesn't actually do any merging at all.</span>
00419 <span class="comment"> * Instead, it simply inserts newer entries at the front of the list,</span>
00420 <span class="comment"> * meaning that device info found later supersedes info found earlier.</span>
00421 <span class="comment"> * This gives the illusion of merging, but potentially wastes memory</span>
00422 <span class="comment"> * with duplicates.</span>
00423 <span class="comment"> */</span>
00424 <span class="keywordtype">void</span>
<a name="l00425"></a><a class="code" href="group__device__xml.html#ga0">00425</a> <a class="code" href="group__device__xml.html#ga0">discover_xml_merge_device_url</a>(<a class="code" href="group__types.html#ga3">discover_device_t</a> **dlist, <span class="keywordtype">char</span> *url,
00426                               <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclasses,
00427                               <a class="code" href="group__types.html#ga6">discover_xml_vendor_t</a> *vendors,
00428                               <a class="code" href="structdiscover__error.html">discover_error_t</a> *status)
00429 {
00430     XML_Parser parser;
00431     <span class="keyword">struct </span>context context;
00432 
00433     assert(url != NULL);
00434     assert(busclasses != NULL);
00435     assert(vendors != NULL);
00436     assert(status != NULL);
00437 
00438     context.state = START;
00439     context.dhead = dlist;
00440     <span class="keywordflow">if</span> (*(context.dhead)) {
00441         <a class="code" href="group__types.html#ga3">discover_device_t</a> *next = *(context.dhead);
00442         <span class="keywordflow">while</span>(next-&gt;next != NULL) {
00443             next = next-&gt;next;
00444         }
00445         context.dtail = next;
00446     } <span class="keywordflow">else</span> {
00447         context.dtail = NULL;
00448     }
00449 
00450     context.busclasses = busclasses;
00451     context.vendors = vendors;
00452     context.unknown_level = 0;
00453     context.stack = NULL;
00454 
00455     parser = XML_ParserCreate(NULL);
00456     XML_SetElementHandler(parser, start_element, end_element);
00457     XML_SetCharacterDataHandler(parser, cdata);
00458     XML_SetUserData(parser, &amp;context);
00459 
00460     <span class="keywordflow">if</span> (!_discover_load_url(url, parser)) {
00461         XML_ParserFree(parser);
00462         status-&gt;<a class="code" href="structdiscover__error.html#o0">code</a> = <a class="code" href="group__types.html#gga15a16">DISCOVER_EIO</a>;
00463         <span class="keywordflow">return</span>;
00464     }
00465 
00466     <span class="keywordflow">if</span> (!XML_Parse(parser, <span class="stringliteral">""</span>, 0, 1)) {
00467         XML_ParserFree(parser);
00468         status-&gt;<a class="code" href="structdiscover__error.html#o0">code</a> = <a class="code" href="group__types.html#gga15a17">DISCOVER_EXML</a>;
00469         <span class="keywordflow">return</span>;
00470     }
00471 
00472     XML_ParserFree(parser);
00473 
00474     <span class="keywordflow">return</span>;
00475 }
00476 
00483 <a class="code" href="group__types.html#ga3">discover_device_t</a> *
<a name="l00484"></a><a class="code" href="group__device__xml.html#ga1">00484</a> <a class="code" href="group__device__xml.html#ga1">discover_xml_get_devices</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)
00485 {
00486     <a class="code" href="group__types.html#ga7">discover_xml_url_t</a> *urls, *i;
00487     <span class="keywordtype">char</span> *url;
00488     <a class="code" href="group__types.html#ga5">discover_xml_busclass_t</a> *busclasses;
00489     <a class="code" href="group__types.html#ga6">discover_xml_vendor_t</a> *vendors;
00490 
00491     assert(status != NULL);
00492 
00493     status-&gt;<a class="code" href="structdiscover__error.html#o0">code</a> = 0;
00494 
00495     <span class="keywordflow">if</span> (!devices_xml[bus]) {
00496         urls = <a class="code" href="group__url__xml.html#ga2">discover_xml_get_data_urls</a>(bus, DEVICE, status);
00497         <span class="keywordflow">if</span> (status-&gt;<a class="code" href="structdiscover__error.html#o0">code</a> != 0) {
00498             <span class="keywordflow">return</span> NULL;
00499         }
00500 
00501         busclasses = <a class="code" href="group__busclass__xml.html#ga1">discover_xml_get_busclasses</a>(bus, status);
00502         <span class="keywordflow">if</span> (status-&gt;<a class="code" href="structdiscover__error.html#o0">code</a> != 0) {
00503             <span class="keywordflow">return</span> NULL;
00504         }
00505 
00506         vendors = <a class="code" href="group__vendor__xml.html#ga1">discover_xml_get_vendors</a>(bus, status);
00507         <span class="keywordflow">if</span> (status-&gt;<a class="code" href="structdiscover__error.html#o0">code</a> != 0) {
00508             <span class="keywordflow">return</span> NULL;
00509         }
00510 
00511         <span class="keywordflow">for</span> (i = urls;
00512              i;
00513              i = <a class="code" href="group__url__xml.html#ga10">discover_xml_url_get_next</a>(i)) {
00514             url = <a class="code" href="group__url__xml.html#ga6">discover_xml_url_get_url</a>(i);
00515             <a class="code" href="group__device__xml.html#ga0">discover_xml_merge_device_url</a>(&amp;(devices_xml[bus]), url,
00516                                           busclasses, vendors, status);
00517             <span class="keywordflow">if</span> (status-&gt;<a class="code" href="structdiscover__error.html#o0">code</a> != 0) {
00518                 get_data_failure_handler(&amp;status, url);
00519             }
00520         }
00521     }
00522 
00523 
00524     <span class="keywordflow">return</span> devices_xml[bus];
00525 }
00526 
00530 <span class="keywordtype">void</span>
<a name="l00531"></a><a class="code" href="group__device__xml.html#ga2">00531</a> <a class="code" href="group__device__xml.html#ga2">discover_xml_free_devices</a>(<span class="keywordtype">void</span>)
00532 {
00533     <span class="keywordtype">int</span> i;
00534     <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="group__types.html#ga14">BUS_COUNT</a>; i++) {
00535         <a class="code" href="group__device.html#ga23">discover_device_free</a>(devices_xml[i], 1);
00536         devices_xml[i] = NULL;
00537     }
00538 }
00539 
00549 <a class="code" href="group__types.html#ga3">discover_device_t</a> *
<a name="l00550"></a><a class="code" href="group__device__xml.html#ga3">00550</a> <a class="code" href="group__device__xml.html#ga3">discover_xml_find_device</a>(<a class="code" href="group__types.html#ga3">discover_device_t</a> *xml_devices,
00551                          <span class="keywordtype">char</span> *target_vendor, <span class="keywordtype">char</span> *target_model,
00552                          <a class="code" href="structdiscover__error.html">discover_error_t</a> *status)
00553 {
00554     <a class="code" href="group__types.html#ga3">discover_device_t</a> *device;
00555 
00556     assert(target_vendor || target_model);
00557 
00558     <span class="keywordflow">for</span> (device = xml_devices;
00559          device;
00560          device = device-&gt;next) {
00561         <span class="keywordflow">if</span> (target_vendor &amp;&amp; target_model) {
00562             <span class="keywordflow">if</span> (strcmp(device-&gt;model_id, target_model) == 0
00563                 &amp;&amp; strcmp(device-&gt;vendor_id, target_vendor) == 0) {
00564                 <span class="keywordflow">break</span>;
00565             }
00566         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (target_vendor) {
00567             <span class="keywordflow">if</span> (strcmp(device-&gt;vendor_id, target_vendor) == 0) {
00568                 <span class="keywordflow">break</span>;
00569             }
00570         } <span class="keywordflow">else</span> {
00571             <span class="comment">/* We only have target_model. */</span>
00572             <span class="keywordflow">if</span> (strcmp(device-&gt;model_id, target_model) == 0) {
00573                 <span class="keywordflow">break</span>;
00574             }
00575         }
00576     }
00577 
00578     <span class="keywordflow">return</span> device;
00579 }
00580 
00593 <a class="code" href="group__types.html#ga3">discover_device_t</a> *
<a name="l00594"></a><a class="code" href="group__device__xml.html#ga4">00594</a> <a class="code" href="group__device__xml.html#ga4">discover_xml_find_next_device</a>(<a class="code" href="group__types.html#ga3">discover_device_t</a> *xml_devices,
00595                          <span class="keywordtype">char</span> *target_vendor, <span class="keywordtype">char</span> *target_model,
00596                          <a class="code" href="structdiscover__error.html">discover_error_t</a> *status)
00597 {
00598     <span class="keywordflow">return</span> <a class="code" href="group__device__xml.html#ga3">discover_xml_find_device</a>(xml_devices-&gt;next,
00599                                     target_vendor, target_model,
00600                                     status);
00601 }
00602 
00603 
00613 <a class="code" href="group__types.html#ga3">discover_device_t</a> *
<a name="l00614"></a><a class="code" href="group__device__xml.html#ga5">00614</a> <a class="code" href="group__device__xml.html#ga5">discover_xml_get_matching_devices</a>(<a class="code" href="group__types.html#ga3">discover_device_t</a> *xml_devices,
00615                                   <span class="keywordtype">char</span> *target_vendor, <span class="keywordtype">char</span> *target_model,
00616                                   <a class="code" href="structdiscover__error.html">discover_error_t</a> *status)
00617 {
00618     <a class="code" href="group__types.html#ga3">discover_device_t</a> *device, *last, *copy;
00619     <a class="code" href="group__types.html#ga3">discover_device_t</a> *head_device = NULL;
00620 
00621     device = <a class="code" href="group__device__xml.html#ga3">discover_xml_find_device</a>(xml_devices, target_vendor,
00622                                       target_model, status);
00623     last = NULL;
00624 
00625     <span class="keywordflow">while</span>(device) {
00626         copy = <a class="code" href="group__device.html#ga22">discover_device_new</a>();
00627         <a class="code" href="group__device.html#ga5">discover_device_copy</a>(device, copy);
00628         copy-&gt;next = NULL;
00629         copy-&gt;extra = NULL;
00630 
00631         <span class="keywordflow">if</span> (last) {
00632             last-&gt;extra = copy;
00633         } <span class="keywordflow">else</span> {
00634             head_device = copy;
00635         }
00636 
00637         last = copy;
00638 
00639         device = <a class="code" href="group__device__xml.html#ga4">discover_xml_find_next_device</a>(device, target_vendor,
00640                                                target_model, status);
00641     }
00642 
00643     <span class="keywordflow">return</span> head_device;
00644 }
00645 
00648 <span class="comment">/*</span>
00649 <span class="comment"> * Local variables:</span>
00650 <span class="comment"> * c-file-style: "progeny"</span>
00651 <span class="comment"> * indent-tabs-mode: nil</span>
00652 <span class="comment"> * End:</span>
00653 <span class="comment"> */</span>
00654 <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&nbsp;
<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>