Changeset 8713

Show
Ignore:
Timestamp:
02/17/09 13:18:38 (4 years ago)
Author:
mcarrick
Message:

completed error checking in DPD parser

Location:
ossiedev/branches/mcarrick/DPD
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/mcarrick/DPD/DeviceClass.cpp

    r8699 r8713  
    2020        TiXmlElement *classType = elem->FirstChildElement("class"); // set link to class tags 
    2121         
    22         // there may be one or more class tags, loop through and append them all 
    23         for (; classType; classType = classType->NextSiblingElement("class")) 
     22        if (classType) 
    2423        { 
    25                 deviceClass.push_back(classType->GetText()); 
     24                // there may be one or more class tags, loop through and append them all 
     25                for (; classType; classType = classType->NextSiblingElement("class")) 
     26                { 
     27                        deviceClass.push_back(classType->GetText()); 
     28                } 
    2629        } 
    27  
     30        else 
     31        { 
     32                std::cout << "ERROR: Could not find a 'class' element in deviceclass tag, must have at least one class designation" << std::endl; 
     33                exit(-1); 
     34        } 
    2835 
    2936} 
  • ossiedev/branches/mcarrick/DPD/DevicePkg.cpp

    r8699 r8713  
    2727void DevicePkg::parseAttributes(TiXmlElement *elem) 
    2828{ 
    29         id = elem->Attribute("id"); 
    30         name = elem->Attribute("name"); 
    31         version = elem->Attribute("version"); 
     29        parseAttributeID(elem); 
     30        parseAttributeName(elem); 
     31        parseAttributeVersion(elem); 
     32} 
     33 
     34void DevicePkg::parseAttributeID(TiXmlElement *elem) 
     35{ 
     36        if (elem->Attribute("id")) 
     37        { 
     38                id = elem->Attribute("id"); 
     39        } 
     40        else 
     41        { 
     42                std::cout << "ERROR: Could not find attrbute 'id' within devicepkg tag" << std::endl; 
     43                exit(-1); 
     44        } 
     45} 
     46 
     47void DevicePkg::parseAttributeName(TiXmlElement *elem) 
     48{ 
     49        if (elem->Attribute("name")) 
     50        { 
     51                name = elem->Attribute("name"); 
     52        } 
     53        else 
     54        { 
     55                std::cout << "ERROR: Could not find attribute 'name' within devicepkg tag" << std::endl; 
     56                exit(-1); 
     57        } 
     58} 
     59 
     60void DevicePkg::parseAttributeVersion(TiXmlElement *elem) 
     61{ 
     62        if (elem->Attribute("version")) 
     63        { 
     64                version = elem->Attribute("version"); 
     65        } 
     66        else 
     67        { 
     68                std::cout << "ERROR: Could not find attribute 'version' within devicepkg tag" << std::endl; 
     69                exit(-1); 
     70        } 
    3271} 
    3372 
    3473void DevicePkg::parseChildElements(TiXmlElement *elem) 
    3574{ 
     75        parseAuthor(elem); 
     76        parseTitle(elem); 
     77        parseDescription(elem); 
     78} 
     79 
     80void DevicePkg::parseAuthor(TiXmlElement *elem) 
     81{ 
    3682        TiXmlElement *auth = elem->FirstChildElement("author"); 
    37         author = auth->GetText(); 
     83        if (auth) 
     84        { 
     85                author = auth->GetText(); 
     86        } 
     87        else 
     88        { 
     89                std::cout << "ERROR: Could not find 'author' element within devicepkg tag" << std::endl; 
     90                exit(-1); 
     91        } 
     92} 
    3893 
     94void DevicePkg::parseTitle(TiXmlElement *elem) 
     95{ 
    3996        TiXmlElement *titleElem = elem->FirstChildElement("title"); 
    40         title = titleElem->GetText(); 
     97        if (titleElem) 
     98        { 
     99                title = titleElem->GetText(); 
     100        } 
     101        else 
     102        { 
     103                std::cout << "ERROR: Could not find 'title' element within devicepkg tag" << std::endl; 
     104                exit(-1); 
     105        } 
     106} 
    41107 
     108void DevicePkg::parseDescription(TiXmlElement *elem) 
     109{ 
    42110        TiXmlElement *descrip = elem->FirstChildElement("description"); 
    43         description = descrip->GetText(); 
     111        if (descrip) 
     112        { 
     113                description = descrip->GetText(); 
     114        } 
     115        else 
     116        { 
     117                std::cout << "ERROR: Could not find 'description' element within devicepkg tag" << std::endl; 
     118        } 
    44119} 
    45120 
  • ossiedev/branches/mcarrick/DPD/DevicePkg.h

    r8699 r8713  
    2121                std::string getDevPkgName(); 
    2222                std::string getDevPkgVersion(); 
    23  
    2423                std::string getDevPkgTitle(); 
    2524                std::string getDevPkgAuthor(); 
     
    2928                void parseElement(TiXmlElement *elem); 
    3029                void parseAttributes(TiXmlElement *elem); 
     30                void parseAttributeID(TiXmlElement *elem); 
     31                void parseAttributeName(TiXmlElement *elem); 
     32                void parseAttributeVersion(TiXmlElement *elem); 
    3133                void parseChildElements(TiXmlElement *elem); 
     34                void parseTitle(TiXmlElement *elem); 
     35                void parseAuthor(TiXmlElement *elem); 
     36                void parseDescription(TiXmlElement *elem); 
    3237 
    3338        private: 
  • ossiedev/branches/mcarrick/DPD/DevicePkgRef.cpp

    r8703 r8713  
    2525void DevicePkgRef::parseAttributes(TiXmlElement *elem) 
    2626{ 
    27         type = elem->Attribute("type"); 
     27        if (elem->Attribute("type")) 
     28        { 
     29                type = elem->Attribute("type"); 
     30        } 
     31        else 
     32        { 
     33                std::cout << "ERROR: Could not find 'type' attribute in devicepkgref tag" << std::endl; 
     34                exit(-1); 
     35        } 
    2836} 
    2937 
     
    3139{ 
    3240        TiXmlElement *local = elem->FirstChildElement("localfile"); 
    33         localfile = local->Attribute("name"); 
     41        if (local) 
     42        { 
     43                localfile = local->Attribute("name"); 
     44        } 
     45        else 
     46        { 
     47                std::cout << "ERROR: Could not find 'name' attribute in localfile tag" << std::endl; 
     48                exit(-1); 
     49        } 
    3450} 
    3551 
  • ossiedev/branches/mcarrick/DPD/HWDeviceRegistration.cpp

    r8711 r8713  
    131131        if (modNum) 
    132132        { 
     133                modelnumber = modNum->GetText(); 
    133134        } 
    134135        else 
  • ossiedev/branches/mcarrick/DPD/PropertyFile.cpp

    r8699 r8713  
    2424void PropertyFile::parseAttributes(TiXmlElement *elem) 
    2525{ 
    26         type = elem->Attribute("type"); 
     26        // verify attribute exists before parsing to prevent seg fault 
     27        if (elem->Attribute("type")) 
     28        { 
     29                type = elem->Attribute("type"); 
     30        } 
     31        else 
     32        { 
     33                std::cout << "ERROR: Could not find 'type' attribute within propertyfile tag" << std::endl; 
     34                exit(-1); 
     35        } 
    2736} 
    2837 
     
    3039{ 
    3140        TiXmlElement *local = elem->FirstChildElement("localfile"); 
    32         localfile = local->Attribute("name"); 
     41        if (local) 
     42        { 
     43                localfile = local->Attribute("name"); 
     44        } 
     45        else 
     46        { 
     47                std::cout << "ERROR: Could not find 'name' attribute within localfile tag" << std::endl; 
     48                exit(-1); 
     49        } 
    3350} 
    3451