root/ossie/trunk/ossie/parser/SPDParser.cpp @ 3357

Revision 3357, 6.5 KB (checked in by balister, 6 years ago)

Fix seg fault in SPDParser.

  • Property svn:eol-style set to native
Line 
1/*******************************************************************************
2
3Copyright 2004, 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE Parser.
6
7OSSIE Parser is free software; you can redistribute it and/or modify
8it under the terms of the Lesser GNU General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or
10(at your option) any later version.
11
12OSSIE Parser is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15Lesser GNU General Public License for more details.
16
17You should have received a copy of the Lesser GNU General Public License
18along with OSSIE Parser; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21Even though all code is original, the architecture of the OSSIE Parser is based
22on the architecture of the CRCs SCA Reference Implementation(SCARI)
23see: http://www.crc.ca/en/html/rmsc/home/sdr/projects/scari
24
25*********************************************************************************/
26
27#include <iostream>
28#include <string>
29
30#include "ossie/SPDParser.h"
31#include "ossie/SPDImplementation.h"
32#include "ossie/parserErrorHandler.h"
33#include "ossie/cf.h"
34#include "ossie/debug.h"
35
36SPDParser::SPDParser(CF::File_ptr file)
37{
38    DEBUG(4, SPDParser, "In constructor.");
39
40    unsigned long fileSize = file->sizeOf();
41    CF::OctetSequence_var fileData;
42
43    file->read(fileData, fileSize);
44
45    unsigned char *fileBuffer = fileData->get_buffer();
46
47    XMLDoc.Parse((const char *)fileBuffer);
48
49    // Handle SAD or DCD files
50    TiXmlElement *elem = XMLDoc.FirstChildElement("softpkg");
51    if (!elem) {
52        DEBUG(1, SPDParser, "Bad SPD file.");
53    }
54
55    parseFile(elem);
56}
57
58SPDParser::~SPDParser()
59{
60    DEBUG(4, SPDParser, "In destructor.");
61
62        unsigned int i;
63
64        for (i=0; i<authors.size(); i++)
65        {
66                delete authors[i];
67        }
68
69/*
70        for (i=0; i<implementations.size(); i++)
71        {
72                mdel(implementations[i]);
73        }
74*/
75
76        for (i=0; i<usesDevice.size(); i++)
77        {
78                delete usesDevice[i];
79        }
80
81}
82
83
84void SPDParser::parseFile(TiXmlElement *elem)
85{
86    DEBUG(4, SPDParser, "In parseFile.");
87
88    parseSoftPkgAttributes(elem);
89    parseSoftPkgTitle(elem);
90    parseSoftPkgDescription(elem);
91    parseSoftPkgAuthor(elem);
92    parsePRFRef(elem);
93    parseSCDRef(elem);
94    parseImplementations(elem);
95    parseUsesDevices(elem);
96}
97
98
99void SPDParser::parseSoftPkgAttributes(TiXmlElement *elem)
100{
101    DEBUG(4, SPDParser, "In parseSoftPkgAttributes.");
102
103    const char *id = elem->Attribute("id");
104    softPkgID = id;
105   
106    const char *name = elem->Attribute("name");
107    softPkgName = name;
108   
109    const char *type = elem->Attribute("type");
110    if (type) {
111        softPkgType = type;
112    } else {
113        softPkgType = "sca_compliant";
114    }
115   
116    const char *ver = elem->Attribute("version");
117    if (ver)
118        softPkgVersion = ver;
119}
120
121
122void SPDParser::parseSoftPkgTitle(TiXmlElement *elem)
123{
124    DEBUG(4, SPDParser, "In parseSoftPkgTitle.");
125
126    TiXmlElement *title = elem->FirstChildElement("title");
127
128    if(title) {
129        const char *str = title->GetText();
130        if (str)
131            softPkgTitle = str;
132    }
133}
134
135
136void SPDParser::parseSoftPkgDescription(TiXmlElement *elem)
137{
138    DEBUG(4, SPDParser, "In parseSoftPkgDescription.");
139
140    TiXmlElement *title = elem->FirstChildElement("description");
141
142    if(title) {
143        softPkgDescription = title->GetText();
144    }
145}
146
147
148void SPDParser::parseSoftPkgAuthor(TiXmlElement *elem)
149{
150    DEBUG(4, SPDParser, "In parseSoftPkgAuthor.");
151
152    TiXmlElement *author = elem->FirstChildElement("author");
153   
154    for(; author; author = author->NextSiblingElement("author")) {
155        SPDAuthor* spdAuthor = new SPDAuthor(author);
156        authors.push_back(spdAuthor);
157    }
158}
159
160
161void SPDParser::parsePRFRef(TiXmlElement *elem)
162{
163    DEBUG(4, SPDParser, "In parsePRFRef.");
164
165    TiXmlElement *prf = elem->FirstChildElement("propertyfile");
166   
167    if(prf) {
168        TiXmlElement *local = prf->FirstChildElement("localfile");
169        PRFFile = local->Attribute("name");;
170    }
171}
172
173
174void SPDParser::parseSCDRef(TiXmlElement *elem)
175{
176    DEBUG(4, SPDParser, "In parseSCDRef.");
177
178    TiXmlElement *scd = elem->FirstChildElement("descriptor");
179   
180    if(scd) {
181        TiXmlElement *local = scd->FirstChildElement("localfile");
182        SCDFile = local->Attribute("name");;
183    }
184}
185
186
187void SPDParser::parseImplementations(TiXmlElement *elem)
188{
189    DEBUG(4, SPDParser, "In parseImplementations.");
190
191    TiXmlElement *imp = elem->FirstChildElement("implementation");
192   
193    for(; imp; imp = imp->NextSiblingElement("implementation")) {
194        implementations.push_back(new SPDImplementation(imp));
195    }
196}
197
198
199void SPDParser::parseUsesDevices(TiXmlElement *elem)
200{
201    DEBUG(4, SPDParser, "In parseUsesDevices.");
202
203    TiXmlElement *uses = elem->FirstChildElement("usesdevice");
204
205    for (; uses; uses = uses->NextSiblingElement("usesDevice")) {
206
207        const char *id = uses->Attribute("id");
208        const char *type = uses->Attribute("type");
209
210        CF::Properties props;
211        unsigned int i(0);
212
213        TiXmlElement *prop = uses->FirstChildElement("propertyref");
214        for(; prop; prop = prop->NextSiblingElement("propertyref")) {
215            const char *refid = prop->Attribute("refid");
216            const char *value = prop->Attribute("value");
217
218            props.length(i+1);
219            props[i].id = CORBA::string_dup(refid);
220            props[i].value <<= value;
221            i++;
222        }
223       
224        usesDevice.push_back(new SPDUsesDevice(id, type, props));
225    }
226}
227
228
229bool SPDParser::isScaCompliant()
230{
231
232    if(softPkgType == "sca_compliant")
233        return true;
234    else
235        return false;
236}
237
238
239bool SPDParser::isScaNonCompliant()
240{
241    if(softPkgType == "sca_non_compliant")
242        return true;
243    else
244        return false;
245}
246
247
248const char* SPDParser::getSoftPkgID()
249{
250        return softPkgID.c_str();
251}
252
253
254const char* SPDParser::getSoftPkgName()
255{
256        return softPkgName.c_str();
257}
258
259
260const char* SPDParser::getSoftPkgType()
261{
262        return softPkgType.c_str();
263}
264
265
266const char* SPDParser::getSoftPkgVersion()
267{
268        return softPkgVersion.c_str();
269}
270
271
272const char* SPDParser::getSoftPkgTitle()
273{
274        return softPkgTitle.c_str();
275}
276
277
278const char* SPDParser::getDescription()
279{
280        return softPkgDescription.c_str();
281}
282
283
284const char* SPDParser::getSPDFile()
285{
286        return SPDFile.c_str();
287}
288
289
290const char* SPDParser::getPRFFile()
291{
292        return PRFFile.c_str();
293}
294
295
296const char* SPDParser::getSCDFile()
297{
298        return SCDFile.c_str();
299}
300
301
302std::vector <SPDAuthor*>* SPDParser::getAuthors()
303{
304        return &authors;
305}
306
307
308std::vector <SPDImplementation*>* SPDParser::getImplementations()
309{
310        return &implementations;
311}
312
313
314std::vector <SPDUsesDevice*>* SPDParser::getUsesDevices()
315{
316        return &usesDevice;
317}
Note: See TracBrowser for help on using the browser.