root/branches/libfreebob-1.0/src/xmlparser.c

Revision 241, 24.1 kB (checked in by pieterpalmers, 18 years ago)

* configure.ac: Version bump to 1.0.0

* Changed all FreeBob? to FreeBoB
* Removed all .cvsignore
* Added Pieter to AUTHORS
* Updated NEWS and README (release canditate date added)

by Daniel Wagner

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* xmlparser.cpp
2  * Copyright (C) 2005,06 Pieter Palmers, Daniel Wagner
3  *
4  * This file is part of FreeBoB
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21
22 #include "libfreebob/xmlparser.h"
23 #include "libfreebob/freebob.h"
24
25 #include <libxml/xmlmemory.h>
26 #include <libxml/parser.h>
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <assert.h>
32
33 #undef DEBUG
34 #ifdef DEBUG
35 #define debugPrint( format, args... ) printf( format, ##args )
36 #else
37 #define debugPrint( format, args... )
38 #endif
39
40 /* XML parsing functions
41  */
42 freebob_stream_spec_t*
43 freebob_xmlparse_stream( xmlDocPtr doc, xmlNodePtr cur )
44 {
45     freebob_stream_spec_t *stream_spec;
46
47     // allocate memory
48     stream_spec = malloc( sizeof(freebob_stream_spec_t) );
49     if ( !stream_spec ) {
50         fprintf( stderr, "Could not allocate memory for stream_spec" );
51         return 0;
52     }
53
54 #define StreamSpecParseNode( NodeName, Member )                     \
55         if ( !xmlStrcmp( cur->name, (const xmlChar*) NodeName ) ) {     \
56             xmlChar* key =                                              \
57                 xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 );   \
58             debugPrint( "\t\t"#NodeName": %s\n", key );                 \
59             stream_spec->Member = strtol( (const char*) key,            \
60                                           (char**) 0, 10 );             \
61             xmlFree( key );                                             \
62         }
63
64     cur = cur->xmlChildrenNode;
65     while ( cur ) {
66         StreamSpecParseNode( "Position", position );
67         StreamSpecParseNode( "Location", location );
68         StreamSpecParseNode( "Format", format );
69         StreamSpecParseNode( "Type", type );
70         StreamSpecParseNode( "DestinationPort", destination_port );
71
72         if ( !xmlStrcmp( cur->name, (const xmlChar *) "Name" ) ) {
73             xmlChar* key =
74                 xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 );
75             debugPrint( "\t\tname: %s\n", key );
76             strncpy( stream_spec->name, (const char*) key,
77                      FREEBOB_MAX_NAME_LEN );
78             xmlFree( key );
79         }
80         cur = cur->next;
81     }
82 #undef StreamSpecParseNode
83
84     return stream_spec;
85 }
86
87 freebob_stream_info_t *
88 freebob_xmlparse_streams( xmlDocPtr doc, xmlNodePtr node )
89 {
90     freebob_stream_info_t* stream_info;
91
92     // allocate memory
93     stream_info = malloc( sizeof(freebob_stream_info_t) );
94     if ( !stream_info ) {
95         fprintf( stderr, "Could not allocate memory for stream_info" );
96         return 0;
97     }
98
99     // count number of child streams
100     stream_info->nb_streams=0;
101     xmlNodePtr cur = node->xmlChildrenNode;
102     while (cur != NULL) {
103         if ( !xmlStrcmp( cur->name, (const xmlChar*) "Stream" ) ) {
104             stream_info->nb_streams++;
105         }
106         cur = cur->next;
107     }
108
109     if ( stream_info->nb_streams ) {
110         // allocate memory for the stream_spec pointer array
111         stream_info->streams =
112             (freebob_stream_spec_t**) calloc( stream_info->nb_streams,
113                                               sizeof(freebob_stream_spec_t*) );
114
115         if ( !stream_info->streams ) {
116             fprintf( stderr, "Could not allocate memory for stream specs" );
117             free( stream_info );
118             return 0;
119         }
120
121         // parse the child stream_specs
122         cur = node->xmlChildrenNode;
123         int i = 0;
124         while ( cur ) {
125             if ( !xmlStrcmp( cur->name, (const xmlChar*) "Stream" ) ) {
126                 stream_info->streams[i] =
127                     freebob_xmlparse_stream( doc, cur );
128
129                 if ( !stream_info->streams[i] ) {
130                     // invalid XML or memory problem, clean up.
131                     while ( --i ) {
132                         free( stream_info->streams[i] );
133                     }
134                     free( stream_info->streams );
135                     stream_info->streams = 0;
136                     free( stream_info );
137                     return 0;
138                 }
139                 i++;
140             }
141             cur = cur->next;
142         }
143     }
144     return stream_info;
145 }
146
147
148
149
150 freebob_connection_spec_t*
151 freebob_xmlparse_connection( xmlDocPtr doc, xmlNodePtr cur )
152 {
153 #define ConnectionSpecParseNode( NodeName, Member )                  \
154          if ( !xmlStrcmp( cur->name, (const xmlChar*) NodeName ) ) {     \
155              xmlChar* key =                                              \
156                  xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 );   \
157              debugPrint( "\t"#NodeName": %s\n",  key );                  \
158              connection_spec->Member = strtol( (const char*) key,        \
159                                                (char**) 0, 10 );         \
160              xmlFree( key );                                             \
161          }
162
163     // allocate memory
164     freebob_connection_spec_t* connection_spec =
165         calloc( 1, sizeof(freebob_connection_spec_t) );
166     if ( !connection_spec ) {
167         fprintf( stderr, "Could not allocate memory for connection_spec" );
168         return 0;
169     }
170
171     cur = cur->xmlChildrenNode;
172     while ( cur ) {
173         ConnectionSpecParseNode( "Id", id );
174         ConnectionSpecParseNode( "Node", node );
175         ConnectionSpecParseNode( "Port", port );
176         ConnectionSpecParseNode( "Plug", plug );
177         ConnectionSpecParseNode( "Dimension", dimension );
178         ConnectionSpecParseNode( "Samplerate", samplerate );
179         ConnectionSpecParseNode( "IsoChannel", iso_channel );
180
181         if ( !xmlStrcmp( cur->name, (const xmlChar*) "Streams" ) ) {
182             connection_spec->stream_info
183                 = freebob_xmlparse_streams( doc, cur );
184             if ( !connection_spec->stream_info ) {
185                 free( connection_spec );
186                 return 0;
187             }
188         }
189         cur = cur->next;
190     }
191 #undef ConnectionSpecParseNode
192
193     return connection_spec;
194 }
195
196 freebob_supported_stream_format_spec_t*
197 freebob_xmlparse_supported_stream_format_node(  xmlDocPtr doc, xmlNodePtr cur  )
198 {
199 #define FormatSpecParseNode( NodeName, Member )                          \
200          if ( !xmlStrcmp( cur->name, (const xmlChar*) NodeName ) ) {     \
201              xmlChar* key =                                              \
202                  xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 );   \
203              debugPrint( "\t"#NodeName": %s\n",  key );                  \
204              format_spec->Member = strtol( (const char*) key,            \
205                                                (char**) 0, 10 );         \
206              xmlFree( key );                                             \
207          }
208
209     // allocate memory
210     freebob_supported_stream_format_spec_t* format_spec =
211         calloc( 1, sizeof(freebob_supported_stream_format_spec_t) );
212     if ( !format_spec ) {
213         fprintf( stderr, "Could not allocate memory for format_spec" );
214         return 0;
215     }
216
217     cur = cur->xmlChildrenNode;
218     while ( cur ) {
219         FormatSpecParseNode( "Samplerate", samplerate );
220         FormatSpecParseNode( "AudioChannels", nb_audio_channels );
221         FormatSpecParseNode( "MidiChannels", nb_midi_channels );
222         cur = cur->next;
223     }
224 #undef FormatSpecParseNode
225    
226     return format_spec;
227 }
228
229 freebob_connection_info_t*
230 freebob_xmlparse_connectionset( xmlDocPtr doc, xmlNodePtr node )
231 {
232     assert( node );
233
234     // allocate memory
235     freebob_connection_info_t* connection_info =
236         malloc( sizeof(freebob_connection_info_t) );
237     if ( !connection_info ) {
238         fprintf( stderr, "Could not allocate memory for connection_info" );
239         return 0;
240     }
241
242     // count number of child streams
243     connection_info->nb_connections = 0;
244     xmlNodePtr cur = node->xmlChildrenNode;
245     while ( cur ) {
246         if ( !xmlStrcmp( cur->name, (const xmlChar*) "Connection" ) ) {
247             connection_info->nb_connections =
248                 connection_info->nb_connections + 1;
249             debugPrint( "nb_connections: %d\n",
250                         connection_info->nb_connections );
251         }
252
253         if ( !xmlStrcmp( cur->name, (const xmlChar*) "Direction" ) ) {
254             xmlChar* key =
255                 xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 );
256             debugPrint( "\tdirection: %s\n", key );
257             connection_info->direction = strtol( (const char*) key,
258                                                  (char**) 0, 10);
259             xmlFree( key );
260         }
261         cur = cur->next;
262     }
263
264     debugPrint( "ConnectionInfo contains %d connection_specs\n",
265                 connection_info->nb_connections );
266
267     if ( connection_info->nb_connections ) {
268         // allocate memory for the connection_spec pointer array
269         connection_info->connections =
270             (freebob_connection_spec_t**)
271             calloc( connection_info->nb_connections,
272                     sizeof(freebob_connection_spec_t*) );
273
274         if ( !connection_info->connections ) {
275             fprintf( stderr,
276                      "Could not allocate memory for connection specs" );
277             free( connection_info );
278             return 0;
279         }
280
281         // parse the child stream_specs
282         cur = node->xmlChildrenNode;
283         int i = 0;
284         while ( cur ) {
285             if ( !xmlStrcmp( cur->name, (const xmlChar*) "Connection" ) ) {
286                 connection_info->connections[i] =
287                     freebob_xmlparse_connection( doc, cur );
288
289                 if ( !connection_info->connections[i] ) {
290                     // invalid XML or memory problem, clean up.
291                     while ( --i ) {
292                         freebob_free_connection_spec( connection_info->connections[i] );
293                     }
294                     free( connection_info->connections );
295                     connection_info->connections = 0;
296                     free( connection_info );
297                     return 0;
298                 }
299                 i++;
300             }
301             cur = cur->next;
302         }
303     }
304
305     return connection_info;
306 }
307
308 freebob_supported_stream_format_info_t*
309 freebob_xmlparse_supported_stream_format( xmlDocPtr doc, xmlNodePtr node )
310 {
311     assert( node );
312
313     // allocate memory
314     freebob_supported_stream_format_info_t* stream_info =
315         malloc( sizeof(freebob_supported_stream_format_info_t) );
316     if ( !stream_info ) {
317         fprintf( stderr, "Could not allocate memory for stream_info" );
318         return 0;
319     }
320
321     // count number of child streams
322     stream_info->nb_formats = 0;
323     xmlNodePtr cur = node->xmlChildrenNode;
324     while ( cur ) {
325         if ( !xmlStrcmp( cur->name, (const xmlChar*) "Format" ) ) {
326             stream_info->nb_formats += 1;
327             debugPrint( "\tnb_formats: %d\n",
328                         stream_info->nb_formats );
329         }
330
331         if ( !xmlStrcmp( cur->name, (const xmlChar*) "Direction" ) ) {
332             xmlChar* key =
333                 xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 );
334             debugPrint( "\tdirection: %s\n", key );
335             stream_info->direction = strtol( (const char*) key,
336                                                  (char**) 0, 10);
337             xmlFree( key );
338         }
339         cur = cur->next;
340     }
341
342     debugPrint( "StreamFormatInfo contains %d stream_format_specs\n",
343                 stream_info->nb_formats );
344
345     if ( stream_info->nb_formats ) {
346         // allocate memory for the connection_spec pointer array
347         stream_info->formats =
348             (freebob_supported_stream_format_spec_t**)
349             calloc( stream_info->nb_formats,
350                     sizeof(freebob_supported_stream_format_spec_t*) );
351
352         if ( !stream_info->formats ) {
353             fprintf( stderr,
354                      "Could not allocate memory for stream format specs" );
355             free( stream_info );
356             return 0;
357         }
358
359         // parse the child stream_specs
360         cur = node->xmlChildrenNode;
361         int i = 0;
362         while ( cur ) {
363             if ( !xmlStrcmp( cur->name, (const xmlChar*) "Format" ) ) {
364                 stream_info->formats[i] =
365                     freebob_xmlparse_supported_stream_format_node( doc, cur );
366
367                 if ( !stream_info->formats[i] ) {
368                     // invalid XML or memory problem, clean up.
369                     while ( --i ) {
370                         freebob_free_supported_stream_format_spec( stream_info->formats[i] );
371                     }
372                     free( stream_info->formats );
373                     stream_info->formats = 0;
374                     free( stream_info );
375                     return 0;
376                 }
377                 i++;
378             }
379             cur = cur->next;
380         }
381     }
382
383     return stream_info;
384 }
385
386
387 xmlNodePtr
388 freebob_xmlparse_get_connectionset_node( xmlDocPtr doc,
389                                          xmlNodePtr cur,
390                                          int direction )
391 {
392     while ( cur ) {
393         if ( !xmlStrcmp( cur->name, (const xmlChar*) "ConnectionSet" ) ) {
394             xmlNodePtr cur2 = cur->xmlChildrenNode;
395             while ( cur2 ) {
396                 if ( !xmlStrcmp( cur2->name, (const xmlChar*) "Direction" ) ) {
397                     xmlChar* key = xmlNodeListGetString( doc,
398                                                          cur2->xmlChildrenNode,
399                                                          1 );
400                     int tmp_direction = strtol( (const char*) key,
401                                                 (char**) 0, 10 );
402                     xmlFree( key );
403                     if( tmp_direction == direction) {
404                         return cur;
405                     }
406                 }
407                 cur2 = cur2->next;
408             }
409         }
410         cur = cur->next;
411     }
412     return 0;
413 }
414
415 xmlNodePtr
416 freebob_xmlparse_get_supported_stream_format_node( xmlDocPtr doc,
417                                                    xmlNodePtr cur,
418                                                    int direction )
419 {
420     while ( cur ) {
421         if ( !xmlStrcmp( cur->name, (const xmlChar*) "StreamFormats" ) ) {
422             xmlNodePtr cur2 = cur->xmlChildrenNode;
423             while ( cur2 ) {
424                 if ( !xmlStrcmp( cur2->name, (const xmlChar*) "Direction" ) ) {
425                     xmlChar* key = xmlNodeListGetString( doc,
426                                                          cur2->xmlChildrenNode,
427                                                          1 );
428                     int tmp_direction = strtol( (const char*) key,
429                                                 (char**) 0, 10 );
430                     xmlFree( key );
431                     if( tmp_direction == direction) {
432                         return cur;
433                     }
434                 }
435                 cur2 = cur2->next;
436             }
437         }
438         cur = cur->next;
439     }
440     return 0;
441 }
442
443 xmlNodePtr
444 freebob_xmlparse_get_connection_set_by_node_id( xmlDocPtr doc,
445                                                 xmlNodePtr cur,
446                                                 int nodeId )
447 {
448     while ( cur ) {
449         if ( !xmlStrcmp( cur->name, (const xmlChar*) "Device" ) ) {
450             xmlNodePtr cur2 = cur->xmlChildrenNode;
451             while ( cur2 ) {
452                 if ( !xmlStrcmp( cur2->name,
453                                  (const xmlChar*) "NodeId" ) )
454                 {
455                     xmlChar* key = xmlNodeListGetString( doc,
456                                                          cur2->xmlChildrenNode,
457                                                          1 );
458                     int tmp_node_id = strtol( (const char*) key,
459                                               (char**) 0, 10 );
460                     xmlFree( key );
461
462                     if ( tmp_node_id == nodeId ) {
463                         xmlNodePtr cur3 = cur->xmlChildrenNode;
464                         while ( cur3 ) {
465                             if ( !xmlStrcmp( cur3->name,
466                                              (const xmlChar*) "ConnectionSet" ) )
467                             {
468                                 return cur3;
469                             }
470                             cur3 = cur3->next;
471                         }
472                     }
473                 }
474                 cur2 = cur2->next;
475             }
476         }
477         cur = cur->next;
478     }
479
480     return 0;
481 }
482
483 xmlNodePtr
484 freebob_xmlparse_get_supported_stream_format_set_by_node_id( xmlDocPtr doc,
485                                                              xmlNodePtr cur,
486                                                              int nodeId )
487 {
488     while ( cur ) {
489         if ( !xmlStrcmp( cur->name, (const xmlChar*) "Device" ) ) {
490             xmlNodePtr cur2 = cur->xmlChildrenNode;
491             while ( cur2 ) {
492                 if ( !xmlStrcmp( cur2->name,
493                                  (const xmlChar*) "NodeId" ) )
494                 {
495                     xmlChar* key = xmlNodeListGetString( doc,
496                                                          cur2->xmlChildrenNode,
497                                                          1 );
498                     int tmp_node_id = strtol( (const char*) key,
499                                               (char**) 0, 10 );
500                     xmlFree( key );
501
502                     if ( tmp_node_id == nodeId ) {
503                         xmlNodePtr cur3 = cur->xmlChildrenNode;
504                         while ( cur3 ) {
505                             if ( !xmlStrcmp( cur3->name,
506                                              (const xmlChar*) "StreamFormats" ) )
507                             {
508                                 return cur3;
509                             }
510                             cur3 = cur3->next;
511                         }
512                     }
513                 }
514                 cur2 = cur2->next;
515             }
516         }
517         cur = cur->next;
518     }
519
520     return 0;
521 }
522
523 xmlNodePtr
524 freebob_xmlparse_get_connection_set_by_device( xmlDocPtr doc,
525                                                xmlNodePtr cur,
526                                                int device )
527 {
528     int count=0;
529     while ( count < device ) {
530         if(!cur) {
531             return NULL;
532         }
533        
534         if(!xmlStrcmp( cur->name, (const xmlChar*) "Device" )) {
535             count++;
536         }
537         cur=cur->next;
538     }
539    
540     if ( !xmlStrcmp( cur->name, (const xmlChar*) "Device" ) ) {
541         xmlNodePtr cur3 = cur->xmlChildrenNode;
542         while ( cur3 ) {
543             if ( !xmlStrcmp( cur3->name,
544                              (const xmlChar*) "ConnectionSet" ) )
545             {
546                 return cur3;
547             }
548             cur3 = cur3->next;
549         }
550     } else {
551         return NULL;
552     }
553    
554     return NULL;
555 }
556
557 // a side effect is that both old connection info's are freed, unless NULL is returned!
558 freebob_connection_info_t*
559 freebob_xmlparse_append_connectionset(freebob_connection_info_t* connection_info, freebob_connection_info_t* cinfo)
560 {
561     if(connection_info==NULL) return cinfo;
562     if(cinfo==NULL) return connection_info;
563    
564     if (connection_info->direction != cinfo->direction) {
565         // direction mismatch
566         return NULL;
567     }
568    
569     freebob_connection_info_t *tmpci=calloc(1,sizeof(freebob_connection_info_t));
570     if (!tmpci) {
571         return NULL;
572     }
573    
574     tmpci->nb_connections=connection_info->nb_connections+cinfo->nb_connections;
575     tmpci->connections = calloc( tmpci->nb_connections, sizeof(freebob_connection_spec_t*));
576    
577     int i=0;
578     int c=0;
579     for(i=0;i<connection_info->nb_connections;i++) {
580         tmpci->connections[c]=connection_info->connections[i]; // these are pointers
581         c++;
582     }
583     for(i=0;i<cinfo->nb_connections;i++) {
584         tmpci->connections[c]=cinfo->connections[i]; // these are pointers
585         c++;
586     }
587    
588     free(connection_info->connections);
589     free(cinfo->connections);
590    
591     free(connection_info);
592     free(cinfo);
593    
594     connection_info=NULL;
595     cinfo=NULL;
596    
597     return tmpci;
598 }
599
600 // a side effect is that both old connection info's are freed, unless NULL is returned!
601 freebob_supported_stream_format_info_t*
602 freebob_xmlparse_append_stream_format(freebob_supported_stream_format_info_t* stream_info,
603                                       freebob_supported_stream_format_info_t* cinfo)
604 {
605     if ( !stream_info ) {
606         return cinfo;
607     }
608     if ( !cinfo ) {
609         return stream_info;
610     }
611    
612     if ( stream_info->direction != cinfo->direction ) {
613         return 0;
614     }
615    
616     freebob_supported_stream_format_info_t* tmpci =
617         calloc( 1, sizeof( freebob_supported_stream_format_info_t ) );
618     if ( !tmpci ) {
619         return 0;
620     }
621    
622     tmpci->nb_formats =
623         stream_info->nb_formats + cinfo->nb_formats;
624     tmpci->formats =
625         calloc( tmpci->nb_formats,
626                 sizeof( freebob_supported_stream_format_spec_t* ) );
627    
628     int c = 0;
629     for( int i = 0; i < stream_info->nb_formats; i++, c++ ) {
630         tmpci->formats[c] = stream_info->formats[i];
631     }
632     for ( int i = 0; i < cinfo->nb_formats; i++, c++ ) {
633         tmpci->formats[c] = cinfo->formats[i];
634     }
635    
636     free( stream_info->formats );
637     free( cinfo->formats );
638    
639     free( stream_info );
640     free( cinfo );
641    
642     stream_info = 0;
643     cinfo = 0;
644    
645     return tmpci;
646 }
647
648 int
649 freebob_xmlparse_get_nb_devices( xmlDocPtr doc,
650                                  xmlNodePtr cur)
651 {
652     int count=0;
653     while (cur != NULL) {
654         if ((!xmlStrcmp(cur->name, (const xmlChar *)"Device"))) {
655             count++;
656         }
657         cur = cur->next;
658     }
659     return count;
660 }
661
662 freebob_connection_info_t*
663 freebob_xmlparse_get_connection_info( xmlDocPtr doc,
664                                       int node_id,
665                                       int direction )
666 {
667     xmlNodePtr base = xmlDocGetRootElement(doc);
668     xmlNodePtr cur;
669    
670     if ( !base ) {
671         fprintf( stderr, "empty document\n");
672         return 0;
673     }
674
675     if ( xmlStrcmp( base->name, (const xmlChar*) "FreeBoBConnectionInfo") ) {
676         fprintf( stderr,
677                  "document of the wrong type, root node "
678                  "!= FreeBoBConnectionInfo\n" );
679         return 0;
680     }
681
682     base = base->xmlChildrenNode;
683     if ( !base ) {
684         fprintf( stderr, "Root node has no children!\n" );
685         return 0;
686     }
687        
688     if( node_id > -1) {
689         cur = freebob_xmlparse_get_connection_set_by_node_id( doc, base, node_id );
690         if ( !cur ) {
691             fprintf( stderr,
692                      "Could not get description for node id %d\n", node_id );
693             return 0;
694         }
695         cur = freebob_xmlparse_get_connectionset_node( doc, cur, direction );
696         if ( !cur ) {
697             fprintf( stderr,
698                      "Could not get a connection set for direction %d\n",
699                      direction );
700             return 0;
701         }
702
703         freebob_connection_info_t* connection_info =
704             freebob_xmlparse_connectionset( doc, cur );
705
706         return connection_info;
707     } else {
708         freebob_connection_info_t* connection_info=NULL;
709                
710         int device_nr=0;
711                
712         int nb_devices=freebob_xmlparse_get_nb_devices(doc, base);
713                
714 /*      fprintf( stderr,
715                  "Nb devices %d\n",
716                  nb_devices );*/
717                                        
718         for(device_nr=0;device_nr<nb_devices;device_nr++) {
719                
720             cur = freebob_xmlparse_get_connection_set_by_device( doc, base, device_nr );
721             if ( !cur ) {
722                 fprintf( stderr,
723                          "Could not get description for device %d\n", device_nr );
724                 return 0;
725             }
726                        
727             cur = freebob_xmlparse_get_connectionset_node( doc, cur, direction );
728             if ( !cur ) {
729                 fprintf( stderr,
730                          "Could not get a connection set for direction %d\n",
731                          direction );
732                 return 0;
733             }
734        
735             freebob_connection_info_t* cinfo = freebob_xmlparse_connectionset( doc, cur );
736             connection_info=freebob_xmlparse_append_connectionset(connection_info,cinfo);
737         }
738                
739         return connection_info;
740     }
741 }
742
743 freebob_supported_stream_format_info_t*
744 freebob_xmlparse_get_stream_formats( xmlDocPtr doc,
745                                      int node_id,
746                                      int direction )
747 {
748     xmlNodePtr base = xmlDocGetRootElement(doc);
749     xmlNodePtr cur;
750    
751     if ( !base ) {
752         fprintf( stderr, "empty document\n");
753         return 0;
754     }
755
756     if ( xmlStrcmp( base->name, (const xmlChar*) "FreeBoBConnectionInfo") ) {
757         fprintf( stderr,
758                  "document of the wrong type, root node "
759                  "!= FreeBoBConnectionInfo\n" );
760         return 0;
761     }
762
763     base = base->xmlChildrenNode;
764     if ( !base ) {
765         fprintf( stderr, "Root node has no children!\n" );
766         return 0;
767     }
768
769     cur = freebob_xmlparse_get_supported_stream_format_set_by_node_id( doc, base, node_id );
770     if ( !cur ) {
771         fprintf( stderr,
772                  "Could not get description for node id %d\n", node_id );
773         return 0;
774     }
775     cur = freebob_xmlparse_get_supported_stream_format_node( doc, cur, direction );
776     if ( !cur ) {
777         fprintf( stderr,
778                  "Could not get a connection set for direction %d\n",
779                  direction );
780         return 0;
781     }
782    
783     freebob_supported_stream_format_info_t* stream_info =
784         freebob_xmlparse_supported_stream_format( doc, cur );
785    
786     return stream_info;    return 0;   
787 }
Note: See TracBrowser for help on using the browser.