source: src-qt4/pc-sounddetect/parse_sound.c @ 1620346

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 2 years ago

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <cneirabustos@gmail.com> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return,carlos neira bustos
7 * ----------------------------------------------------------------------------
8 */ 
9
10#include <libxml/xmlmemory.h>
11#include <libxml/parser.h>
12#include <string.h>
13
14const char* GetKo(xmlDocPtr doc, xmlNodePtr cur, char* chip_id); 
15const char*  parse_Sound_CardXML(char *docname, char* Vendor_Name, char* chip_id ) ;
16
17
18
19/* cnb 2008-01-01
20    we get the kernel module to load according to search keys(vendor,chipid)
21 */
22
23const char* GetKo(xmlDocPtr doc, xmlNodePtr cur, char* chip_id) {
24
25        xmlChar *key;
26        static char tempkey[16];
27        cur = cur->xmlChildrenNode ;
28        while (cur!= NULL) {
29
30                    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
31                    snprintf(tempkey,sizeof tempkey ,"%s",(char*)key);
32
33                    if(!memcmp(tempkey,chip_id,strlen(tempkey))) { 
34                        xmlFree(key);
35                        return cur->name;
36                    }
37                    cur = cur->next;
38        }
39        xmlFree(key);
40        return "UNKNOWN";
41
42}
43
44/* cnb 2008-01-01
45   "validate" the xml and parse the soundcards.xml , searching with keys vendor
46   and chip_id
47 */
48const char* parse_Sound_CardXML(char *docname, char* Vendor_Name, char* chip_id ) 
49{
50
51        xmlDocPtr doc;
52        xmlNodePtr cur;
53        static char kernelmodule[16];
54
55        doc = xmlParseFile(docname);
56        sprintf(kernelmodule,"%s","UNKNOWN");
57       
58        if (doc == NULL ) {
59                fprintf(stderr,"/usr/local/share/pcbsd/pc-sounddetect/soundcards.xml not found!\n");
60                return kernelmodule;
61        }
62       
63        cur = xmlDocGetRootElement(doc);
64       
65        if (cur == NULL) {
66                fprintf(stderr,"empty document\n");
67                xmlFreeDoc(doc);
68                return kernelmodule;
69        }
70       
71        if (xmlStrcmp(cur->name, (const xmlChar *) "SoundCard_vendors")) {
72                fprintf(stderr,"This xml does not have information about sound cards ");
73                xmlFreeDoc(doc);
74                return kernelmodule;
75        }
76        cur = cur->xmlChildrenNode;
77        while (cur!= NULL) 
78        {           
79                if ((!xmlStrcmp(cur->name, (const xmlChar *)Vendor_Name))){
80                    snprintf(kernelmodule,sizeof kernelmodule,"%s",GetKo(doc, cur,chip_id));
81                        xmlFreeDoc(doc);
82                        return kernelmodule;
83                }
84                 
85                cur = cur->next;
86        }
87        xmlFreeDoc(doc);
88        return kernelmodule;
89 }
Note: See TracBrowser for help on using the repository browser.