Changeset 1175:cae6ab372398


Ignore:
Timestamp:
02/28/09 15:24:11 (3 years ago)
Author:
niam
Branch:
default
Message:

cleaned headers in data::format::(json|xml), data::memory::shared

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/libdodo/dataFormatJsonNode.h

    r1160 r1175  
    3434 
    3535#include <libdodo/types.h> 
    36 #include <libdodo/toolsString.h> 
    37 #include <libdodo/dataFormatJsonNodeEx.h> 
    3836 
    3937namespace dodo 
  • trunk/include/libdodo/dataFormatJsonProcessor.h

    r1160 r1175  
    3434 
    3535#include <libdodo/types.h> 
    36 #include <libdodo/toolsString.h> 
    37 #include <libdodo/toolsFilesystem.h> 
    38 #include <libdodo/dataFormatJsonProcessorEx.h> 
    3936#include <libdodo/dataFormatJsonNode.h> 
    4037 
  • trunk/include/libdodo/dataFormatXmlNode.h

    r1166 r1175  
    3333#include <libdodo/directives.h> 
    3434 
    35 #include <algorithm> 
    36  
    3735#include <libdodo/types.h> 
    38 #include <libdodo/toolsMisc.h> 
    3936 
    4037namespace dodo 
  • trunk/include/libdodo/dataFormatXmlProcessor.h

    r1166 r1175  
    3333#include <libdodo/directives.h> 
    3434 
    35 #ifdef LIBXML2_EXT 
    36  
    37 #include <libxml/parser.h> 
    38 #include <libxml/xmlmemory.h> 
    39  
    40 #endif 
    41  
    42 #include <libdodo/dataFormatXmlProcessorEx.h> 
     35#include <libdodo/types.h> 
    4336#include <libdodo/dataFormatXmlNode.h> 
    44 #include <libdodo/types.h> 
    4537 
    4638namespace dodo 
     
    5345                        { 
    5446                                /** 
     47                                 * @struct __node 
     48                                 * @brief defines XML node properties 
     49                                 */ 
     50                                struct __node; 
     51 
     52                                /** 
     53                                 * @struct __document 
     54                                 * @brief defines XML document properties 
     55                                 */ 
     56                                struct __doc; 
     57 
     58                                /** 
     59                                 * @struct __attribute 
     60                                 * @brief defines XML attribute properties 
     61                                 */ 
     62                                struct __attr; 
     63 
     64                                /** 
    5565                                 * @struct __nodeDef 
    5666                                 * @brief defines processor tree definition 
     
    172182                                         * @param file defines path to XML file 
    173183                                         */ 
    174                                         virtual __info getFileInfo(const dodoString &file); 
     184                                        static __info getFileInfo(const dodoString &file); 
    175185 
    176186                                        /** 
     
    178188                                         * @param buffer defines XML buffer 
    179189                                         */ 
    180                                         virtual __info getBufferInfo(const dodoString &buffer); 
     190                                        static __info getBufferInfo(const dodoString &buffer); 
    181191 
    182192                                        /** 
     
    223233 
    224234#ifdef LIBXML2_EXT 
    225  
    226235                                        /** 
    227236                                         * @return true if content is in CDATA 
    228237                                         * @param xnode defines XML tree node 
    229238                                         */ 
    230                                         bool isCDATA(xmlNodePtr xnode); 
     239                                        bool isCDATA(const __node &xnode); 
    231240 
    232241                                        /** 
     
    235244                                         * @param xnode defines XML tree node 
    236245                                         */ 
    237                                         virtual dodoArray<node> parse(xmlNodePtr xnode); 
     246                                        virtual dodoArray<node> parse(__node xnode); 
    238247 
    239248                                        /** 
     
    243252                                         * @param chNode defines XML tree node 
    244253                                         */ 
    245                                         virtual dodoArray<node> parse(const __nodeDef  &definition, 
    246                                                                                                   const xmlNodePtr chNode); 
     254                                        virtual dodoArray<node> parse(const __nodeDef &definition, 
     255                                                                                                  const __node    &xnode); 
    247256 
    248257                                        /** 
     
    251260                                         * @param attributes defines buffer for attributes 
    252261                                         */ 
    253                                         virtual void getAttributes(const xmlNodePtr xnode, 
     262                                        virtual void getAttributes(const __node         &xnode, 
    254263                                                                                           dodoStringMap    &attributes); 
    255264 
     
    261270                                         */ 
    262271                                        virtual void getAttributes(const __nodeDef  &definition, 
    263                                                                                            const xmlNodePtr xnode, 
     272                                                                                           const __node         &xnode, 
    264273                                                                                           dodoStringMap    &attributes); 
    265274 
     
    269278                                         * @param sample defines buffer for node 
    270279                                         */ 
    271                                         virtual void getNodeInfo(const xmlNodePtr xnode, 
    272                                                                                          node             &sample); 
    273  
     280                                        virtual void getNodeInfo(const __node &xnode, 
     281                                                                                         node             &sample); 
    274282#endif 
    275283 
     
    277285 
    278286#ifdef LIBXML2_EXT 
    279  
    280                                         /** 
    281                                          * @typedef xcharCmp 
     287                                        /** 
     288                                         * @typedef strCmp 
    282289                                         * @brief defines name compare function 
    283290                                         * @param one defines string to compare 
    284291                                         * @param two defines string to compare 
    285292                                         */ 
    286                                         typedef int (*xcharCmp)(const xmlChar *one, const xmlChar *two); 
    287  
    288                                         xcharCmp cmpFunc;   ///< name compare function 
     293                                        typedef int (*strCmp)(const unsigned char *one, const unsigned char *two); 
     294                                        strCmp cmpFunc;   ///< name compare function 
    289295 
    290296                                        /** 
     
    293299                                         * @param node defines node content 
    294300                                         */ 
    295                                         xmlNodePtr findNode(const __nodeDef &definition, 
    296                                                                                 xmlNodePtr      node); 
    297  
    298                                         xmlDocPtr document; ///< XML Document 
    299                                         xmlAttr *attribute; ///< XML attributes 
    300  
    301                                         /** 
    302                                          * catche libprocessor2 warnings 
    303                                          * @param data defines user-defined data 
    304                                          * @param error defines error descriptor 
    305                                          */ 
    306                                         static void errHandler(void        *data, 
    307                                                                                    xmlErrorPtr error); 
    308  
     301                                        __node findNode(const __nodeDef &definition, 
     302                                                                        const __node    &node); 
     303 
     304                                        __doc *document; ///< XML Document 
    309305#endif 
    310306 
  • trunk/include/libdodo/dataMemoryShared.h

    r1160 r1175  
    3333#include <libdodo/directives.h> 
    3434 
    35 #include <sys/types.h> 
    36 #include <sys/mman.h> 
    37  
    38 #ifdef XSI_IPC 
    39  
    40 #include <sys/ipc.h> 
    41 #include <sys/shm.h> 
    42  
    43 #else /*POSIX_SEMAPHORES*/ 
    44  
    45 #include <fcntl.h> 
    46  
    47 #endif 
    48  
    49 #include <libdodo/dataMemorySharedEx.h> 
    50 #include <libdodo/toolsMisc.h> 
    51 #include <libdodo/toolsCode.h> 
    52  
    5335namespace dodo 
    5436{ 
     
    5739                namespace memory 
    5840                { 
     41                        /** 
     42                         * @struct __key 
     43                         * @brief defines shared memory key 
     44                         */ 
     45                        struct __key; 
     46 
    5947                        /** 
    6048                         * @class shared 
     
    143131                                int shm;            ///< shared data descriptor 
    144132                                void *mshared;      ///< shared data 
     133#ifndef XSI_IPC 
     134                                unsigned long size; ///< size of shared data 
     135#endif 
    145136 
    146 #ifdef XSI_IPC 
    147  
    148                                 int key;            ///< key for the shared data 
    149  
    150 #else 
    151  
    152                                 dodoString key;     ///< key for the shared data 
    153                                 unsigned long size; ///< size of shared data 
    154  
    155 #endif 
     137                                __key *key; ///< key for the shared data 
    156138 
    157139                                bool autogenerated; ///< true if key was autogenerated 
  • trunk/src/dataFormatJsonNode.cc

    r1162 r1175  
    2828 */ 
    2929 
     30#include <libdodo/directives.h> 
     31 
     32#include <libdodo/types.h> 
     33#include <libdodo/toolsString.h> 
     34#include <libdodo/dataFormatJsonNodeEx.h> 
    3035#include <libdodo/dataFormatJsonNode.h> 
    3136 
  • trunk/src/dataFormatJsonProcessor.cc

    r1166 r1175  
    2828 */ 
    2929 
     30#include <libdodo/directives.h> 
     31 
     32#include <libdodo/types.h> 
     33#include <libdodo/toolsString.h> 
     34#include <libdodo/toolsFilesystem.h> 
     35#include <libdodo/dataFormatJsonProcessorEx.h> 
     36#include <libdodo/dataFormatJsonNode.h> 
    3037#include <libdodo/dataFormatJsonProcessor.h> 
    3138 
  • trunk/src/dataFormatXmlNode.cc

    r1162 r1175  
    2828 */ 
    2929 
    30  
    3130#include <libdodo/dataFormatXmlNode.h> 
     31#include <libdodo/toolsMisc.h> 
     32#include <libdodo/types.h> 
    3233 
    3334using namespace dodo::data::format::xml; 
  • trunk/src/dataFormatXmlProcessor.cc

    r1162 r1175  
    2828 */ 
    2929 
    30  
     30#include <libdodo/directives.h> 
     31 
     32#ifdef LIBXML2_EXT 
     33 
     34#include <libxml/parser.h> 
     35#include <libxml/xmlmemory.h> 
     36 
     37namespace dodo 
     38{ 
     39        namespace data 
     40        { 
     41                namespace format 
     42                { 
     43                        namespace xml 
     44                        { 
     45                                struct __node 
     46                                { 
     47                                        /** 
     48                                         * constructor 
     49                                         */ 
     50                                        __node(); 
     51 
     52 
     53                                        /** 
     54                                         * constructor 
     55                                         */ 
     56                                        __node(xmlNodePtr node); 
     57 
     58                                        xmlNodePtr node; ///< represents internal libxml2 node data 
     59                                }; 
     60 
     61                                struct __doc 
     62                                { 
     63                                        xmlDocPtr document; ///< represents internal libxml2 document data 
     64                                }; 
     65                        }; 
     66                }; 
     67        }; 
     68}; 
     69 
     70#endif 
     71 
     72#include <libdodo/dataFormatXmlProcessorEx.h> 
    3173#include <libdodo/dataFormatXmlProcessor.h> 
    3274 
    3375using namespace dodo::data::format::xml; 
    3476 
    35 __info::__info(const dodoString &a_version, 
    36                            const dodoString &a_encoding, 
    37                            const dodoString &a_root, 
    38                            int              a_compression) : version(a_version), 
    39                                                                                                  encoding(a_encoding), 
    40                                                                                                  root(a_root), 
    41                                                                                                  compression(a_compression) 
     77__node::__node(xmlNodePtr node) : node(node) 
     78{ 
     79} 
     80 
     81//------------------------------------------------------------------- 
     82 
     83__node::__node() 
     84{ 
     85} 
     86 
     87//------------------------------------------------------------------- 
     88 
     89__info::__info(const dodoString &version, 
     90                           const dodoString &encoding, 
     91                           const dodoString &root, 
     92                           int              compression) : version(version), 
     93                                                                                           encoding(encoding), 
     94                                                                                           root(root), 
     95                                                                                           compression(compression) 
    4296{ 
    4397} 
     
    85139//------------------------------------------------------------------- 
    86140 
     141#ifdef LIBXML2_EXT 
     142 
     143void 
     144errHandler(void        *data, 
     145                   xmlErrorPtr error) 
     146{ 
     147} 
     148 
     149#endif 
     150 
     151//------------------------------------------------------------------- 
     152 
     153 
    87154processor::processor(processor &xt) 
    88155{ 
     
    92159 
    93160processor::processor() : icaseNames(false) 
    94  
    95 #ifdef LIBXML2_EXT 
    96  
     161#ifdef LIBXML2_EXT 
    97162                                                 , 
    98                                                  document(NULL) 
    99  
    100 #endif 
    101  
    102 { 
    103 #ifdef LIBXML2_EXT 
    104  
     163                                                 document(new __doc) 
     164#endif 
     165{ 
     166#ifdef LIBXML2_EXT 
    105167        xmlPedanticParserDefault(0); 
    106168        xmlInitParser(); 
    107         xmlSetStructuredErrorFunc(NULL, processor::errHandler); 
    108  
     169        xmlSetStructuredErrorFunc(NULL, errHandler); 
    109170#endif 
    110171} 
     
    115176{ 
    116177#ifdef LIBXML2_EXT 
    117  
    118         xmlFreeDoc(document); 
    119  
     178        xmlFreeDoc(document->document); 
    120179        xmlCleanupParser(); 
    121180 
     181        delete document; 
    122182#endif 
    123183} 
     
    128188 
    129189bool 
    130 processor::isCDATA(xmlNodePtr chNode) 
    131 { 
    132         xmlNodePtr xnode = chNode->children; 
     190processor::isCDATA(const __node &a_xnode) 
     191{ 
     192        xmlNodePtr xnode = a_xnode.node->children; 
    133193        while (xnode != NULL) 
    134194        { 
     
    153213{ 
    154214#ifdef LIBXML2_EXT 
    155  
    156         xmlFreeDoc(document); 
    157  
    158         document = xmlParseFile(file.c_str()); 
    159         if (document == NULL) 
     215        xmlFreeDoc(document->document); 
     216 
     217        document->document = xmlParseFile(file.c_str()); 
     218        if (document->document == NULL) 
    160219        { 
    161220                xmlErrorPtr error = xmlGetLastError(); 
     
    170229                } 
    171230        } 
    172  
    173231#endif 
    174232 
     
    183241{ 
    184242#ifdef LIBXML2_EXT 
    185  
    186         xmlFreeDoc(document); 
    187  
    188         document = xmlParseMemory(buffer.c_str(), buffer.size()); 
    189         if (document == NULL) 
     243        xmlFreeDoc(document->document); 
     244 
     245        document->document = xmlParseMemory(buffer.c_str(), buffer.size()); 
     246        if (document->document == NULL) 
    190247        { 
    191248                xmlErrorPtr error = xmlGetLastError(); 
     
    200257                } 
    201258        } 
    202  
    203259#endif 
    204260 
     
    212268{ 
    213269#ifdef LIBXML2_EXT 
    214  
    215         xmlNodePtr xnode = xmlDocGetRootElement(document); 
    216         if (xnode == NULL) 
     270        __node xnode = xmlDocGetRootElement(document->document); 
     271        if (xnode.node == NULL) 
    217272        { 
    218273                xmlErrorPtr error = xmlGetLastError(); 
     
    230285        xnode = findNode(definition, xnode); 
    231286 
     287        if (xnode.node == NULL) 
     288        { 
     289                return node(); 
     290        } 
     291 
    232292        node sample; 
    233  
    234         if (xnode == NULL) 
     293        getNodeInfo(xnode, sample); 
     294 
     295        getAttributes(definition, xnode, sample.attributes); 
     296 
     297        if (xnode.node->children == NULL) 
    235298        { 
    236299                return sample; 
    237300        } 
    238301 
    239         getNodeInfo(xnode, sample); 
    240  
    241         getAttributes(definition, xnode, sample.attributes); 
    242  
    243         if (xnode->children == NULL) 
    244         { 
    245                 return sample; 
    246         } 
    247  
    248302        sample.CDATA = isCDATA(xnode); 
    249303 
    250304        if (definition.allChildren) 
    251305        { 
    252                 xnode = xnode->children; 
     306                xnode.node = xnode.node->children; 
    253307 
    254308                node one; 
     
    257311                dodoArray<node>::iterator i, j; 
    258312 
    259                 while (xnode != NULL) 
    260                 { 
    261                         if (xnode->type != XML_ELEMENT_NODE) 
    262                         { 
    263                                 xnode = xnode->next; 
     313                while (xnode.node != NULL) 
     314                { 
     315                        if (xnode.node->type != XML_ELEMENT_NODE) 
     316                        { 
     317                                xnode.node = xnode.node->next; 
    264318 
    265319                                continue; 
     
    272326                        one.CDATA = isCDATA(xnode); 
    273327 
    274                         if (xnode->children != NULL) 
    275                         { 
    276                                 children = parse(xnode->children); 
     328                        if (xnode.node->children != NULL) 
     329                        { 
     330                                children = parse(__node(xnode.node->children)); 
    277331                                i = children.begin(); 
    278332                                j = children.end(); 
     
    283337                        } 
    284338 
    285                         sample.children[(char *)xnode->name].push_back(one); 
     339                        sample.children[(char *)xnode.node->name].push_back(one); 
    286340 
    287341                        initNode(one); 
    288342 
    289                         xnode = xnode->next; 
     343                        xnode.node = xnode.node->next; 
    290344                } 
    291345        } 
     
    297351                        for (; i != j; ++i) 
    298352                        { 
    299                                 sample.children.insert(make_pair(i->first, parse(i->second, xnode->children))); 
     353                                sample.children.insert(make_pair(i->first, parse(i->second, xnode.node->children))); 
    300354                        } 
    301355                } 
     
    303357 
    304358        return sample; 
    305  
    306359#else 
    307  
    308360        return node(); 
    309  
    310361#endif 
    311362} 
     
    316367 
    317368dodoArray<node> 
    318 processor::parse(const __nodeDef  &definition, 
    319                                  const xmlNodePtr chNode) 
    320 { 
    321         xmlNodePtr xnode = chNode, subNode; 
     369processor::parse(const __nodeDef &definition, 
     370                                 const __node    &a_xnode) 
     371{ 
     372        xmlNodePtr xnode = a_xnode.node, subNode; 
    322373 
    323374        node sample; 
    324375        dodoArray<node> sampleArr; 
    325376 
    326         if (icaseNames) 
    327         { 
    328                 cmpFunc = xmlStrcasecmp; 
    329         } 
    330         else 
    331         { 
    332                 cmpFunc = xmlStrcmp; 
    333         } 
     377        cmpFunc = icaseNames?xmlStrcasecmp:xmlStrcmp; 
    334378 
    335379        do 
     
    351395                        } 
    352396 
    353                         if (cmpFunc(xnode->ns->prefix, (xmlChar *)definition.ns.c_str()) != 0) 
     397                        if (cmpFunc(xnode->ns->prefix, (unsigned char *)definition.ns.c_str()) != 0) 
    354398                        { 
    355399                                xnode = xnode->next; 
     
    359403                } 
    360404 
    361                 if (cmpFunc(xnode->name, (xmlChar *)definition.name.c_str()) != 0) 
     405                if (cmpFunc(xnode->name, (unsigned char *)definition.name.c_str()) != 0) 
    362406                { 
    363407                        xnode = xnode->next; 
     
    442486 
    443487void 
    444 processor::errHandler(void        *data, 
    445                                           xmlErrorPtr error) 
    446 { 
    447 } 
    448  
    449 //------------------------------------------------------------------- 
    450  
    451 void 
    452488processor::getAttributes(const __nodeDef  &definition, 
    453                                                  const xmlNodePtr xnode, 
     489                                                 const __node &xnode, 
    454490                                                 dodoStringMap    &attributes) 
    455491{ 
    456         attribute = xnode->properties; 
     492        xmlAttrPtr attribute = xnode.node->properties; 
    457493 
    458494        if (definition.allAttributes) 
     
    460496                while (attribute != NULL) 
    461497                { 
    462                         xmlChar *xChar = xmlGetProp(xnode, attribute->name); 
     498                        unsigned char *xChar = xmlGetProp(xnode.node, attribute->name); 
    463499                        if (xChar != NULL) 
    464500                        { 
     
    482518                                        for (; iAttr != jAttr; ++iAttr) 
    483519                                        { 
    484                                                 if (xmlStrcmp(attribute->name, (xmlChar *)iAttr->c_str()) == 0) 
     520                                                if (xmlStrcmp(attribute->name, (unsigned char *)iAttr->c_str()) == 0) 
    485521                                                { 
    486                                                         xmlChar *xChar = xmlGetProp(xnode, attribute->name); 
     522                                                        unsigned char *xChar = xmlGetProp(xnode.node, attribute->name); 
    487523                                                        if (xChar != NULL) 
    488524                                                        { 
     
    501537                                for (; iAttr != jAttr; ++iAttr) 
    502538                                { 
    503                                         xmlChar *xChar = xmlGetProp(xnode, (xmlChar *)iAttr->c_str()); 
     539                                        unsigned char *xChar = xmlGetProp(xnode.node, (unsigned char *)iAttr->c_str()); 
    504540                                        if (xChar != NULL) 
    505541                                        { 
     
    516552 
    517553void 
    518 processor::getAttributes(const xmlNodePtr xnode, 
     554processor::getAttributes(const __node &xnode, 
    519555                                                 dodoStringMap    &attributes) 
    520556{ 
    521         attribute = xnode->properties; 
     557        xmlAttrPtr attribute = xnode.node->properties; 
    522558 
    523559        while (attribute != NULL) 
    524560        { 
    525                 xmlChar *xChar = xmlGetProp(xnode, attribute->name); 
     561                unsigned char *xChar = xmlGetProp(xnode.node, attribute->name); 
    526562                if (xChar != NULL) 
    527563                { 
     
    537573 
    538574void 
    539 processor::getNodeInfo(const xmlNodePtr xnode, 
    540                                            node             &resNode) 
    541 { 
    542         if (xnode->ns != NULL) 
    543         { 
    544                 resNode.ns.prefix = (char *)xnode->ns->prefix; 
    545                 resNode.ns.href = (char *)xnode->ns->href; 
    546         } 
    547  
    548         if (xnode->nsDef != NULL) 
    549         { 
    550                 resNode.nsDef.prefix = (char *)xnode->nsDef->prefix; 
    551                 resNode.nsDef.href = (char *)xnode->nsDef->href; 
    552         } 
    553  
    554         if (xnode->name != NULL) 
    555         { 
    556                 resNode.name.assign((char *)xnode->name); 
    557         } 
    558  
    559         xmlChar *xChar = xmlNodeListGetString(document, xnode->children, 1); 
     575processor::getNodeInfo(const __node &xnode, 
     576                                           node                 &resNode) 
     577{ 
     578        if (xnode.node->ns != NULL) 
     579        { 
     580                resNode.ns.prefix = (char *)xnode.node->ns->prefix; 
     581                resNode.ns.href = (char *)xnode.node->ns->href; 
     582        } 
     583 
     584        if (xnode.node->nsDef != NULL) 
     585        { 
     586                resNode.nsDef.prefix = (char *)xnode.node->nsDef->prefix; 
     587                resNode.nsDef.href = (char *)xnode.node->nsDef->href; 
     588        } 
     589 
     590        if (xnode.node->name != NULL) 
     591        { 
     592                resNode.name.assign((char *)xnode.node->name); 
     593        } 
     594 
     595        unsigned char *xChar = xmlNodeListGetString(document->document, xnode.node->children, 1); 
    560596        if (xChar != NULL) 
    561597        { 
     
    573609{ 
    574610#ifdef LIBXML2_EXT 
     611        xmlDocPtr document = xmlParseFile(file.c_str()); 
     612        if (document == NULL) 
     613        { 
     614                xmlErrorPtr error = xmlGetLastError(); 
     615 
     616                if (error == NULL) 
     617                { 
     618                        throw exception::basic(exception::ERRMODULE_DATAFORMATXMLPROCESSOR, PROCESSOREX_GETFILEINFO, exception::ERRNO_LIBDODO, PROCESSOREX_EMPTYDOCUMENT, DATAFORMATXMLPROCESSOREX_EMPTYDOCUMENT_STR, __LINE__, __FILE__, file); 
     619                } 
     620                else 
     621                { 
     622                        throw exception::basic(exception::ERRMODULE_DATAFORMATXMLPROCESSOR, PROCESSOREX_GETFILEINFO, exception::ERRNO_LIBXML2, error->code, error->message, __LINE__, __FILE__, file); 
     623                } 
     624        } 
     625 
     626        __info i(document->version != NULL ? (char *)document->version : __dodostring__, 
     627                         document->encoding != NULL ? (char *)document->encoding : __dodostring__, 
     628                         (document->children != NULL && document->children->name != NULL) ? (char *)document->children->name : __dodostring__, 
     629                         document->compression); 
    575630 
    576631        xmlFreeDoc(document); 
    577632 
    578         document = xmlParseFile(file.c_str()); 
    579         if (document == NULL) 
    580         { 
    581                 xmlErrorPtr error = xmlGetLastError(); 
    582  
    583                 if (error == NULL) 
    584                 { 
    585                         throw exception::basic(exception::ERRMODULE_DATAFORMATXMLPROCESSOR, PROCESSOREX_GETFILEINFO, exception::ERRNO_LIBDODO, PROCESSOREX_EMPTYDOCUMENT, DATAFORMATXMLPROCESSOREX_EMPTYDOCUMENT_STR, __LINE__, __FILE__, file); 
    586                 } 
    587                 else 
    588                 { 
    589                         throw exception::basic(exception::ERRMODULE_DATAFORMATXMLPROCESSOR, PROCESSOREX_GETFILEINFO, exception::ERRNO_LIBXML2, error->code, error->message, __LINE__, __FILE__, file); 
    590                 } 
    591         } 
    592  
    593         return __info(document->version != NULL ? (char *)document->version : __dodostring__, 
    594                                   document->encoding != NULL ? (char *)document->encoding : __dodostring__, 
    595                                   (document->children != NULL && document->children->name != NULL) ? (char *)document->children->name : __dodostring__, 
    596                                   document->compression); 
    597  
     633        return i; 
    598634#else 
    599  
    600635        return __info(); 
    601  
    602636#endif 
    603637} 
     
    609643{ 
    610644#ifdef LIBXML2_EXT 
     645        xmlDocPtr document = xmlParseMemory(buffer.c_str(), buffer.size()); 
     646        if (document == NULL) 
     647        { 
     648                xmlErrorPtr error = xmlGetLastError(); 
     649 
     650                if (error == NULL) 
     651                { 
     652                        throw exception::basic(exception::ERRMODULE_DATAFORMATXMLPROCESSOR, PROCESSOREX_GETBUFFERINFO, exception::ERRNO_LIBDODO, PROCESSOREX_EMPTYDOCUMENT, DATAFORMATXMLPROCESSOREX_EMPTYDOCUMENT_STR, __LINE__, __FILE__); 
     653                } 
     654                else 
     655                { 
     656                        throw exception::basic(exception::ERRMODULE_DATAFORMATXMLPROCESSOR, PROCESSOREX_GETBUFFERINFO, exception::ERRNO_LIBXML2, error->code, error->message, __LINE__, __FILE__); 
     657                } 
     658        } 
     659 
     660        __info i(document->version != NULL ? (char *)document->version : __dodostring__, 
     661                         document->encoding != NULL ? (char *)document->encoding : __dodostring__, 
     662                         (document->children != NULL && document->children->name != NULL) ? (char *)document->children->name : __dodostring__, 
     663                         document->compression); 
    611664 
    612665        xmlFreeDoc(document); 
    613666 
    614         document = xmlParseMemory(buffer.c_str(), buffer.size()); 
    615         if (document == NULL) 
    616         { 
    617                 xmlErrorPtr error = xmlGetLastError(); 
    618  
    619                 if (error == NULL) 
    620                 { 
    621                         throw exception::basic(exception::ERRMODULE_DATAFORMATXMLPROCESSOR, PROCESSOREX_GETBUFFERINFO, exception::ERRNO_LIBDODO, PROCESSOREX_EMPTYDOCUMENT, DATAFORMATXMLPROCESSOREX_EMPTYDOCUMENT_STR, __LINE__, __FILE__); 
    622                 } 
    623                 else 
    624                 { 
    625                         throw exception::basic(exception::ERRMODULE_DATAFORMATXMLPROCESSOR, PROCESSOREX_GETBUFFERINFO, exception::ERRNO_LIBXML2, error->code, error->message, __LINE__, __FILE__); 
    626                 } 
    627         } 
    628  
    629         return __info(document->version != NULL ? (char *)document->version : __dodostring__, 
    630                                   document->encoding != NULL ? (char *)document->encoding : __dodostring__, 
    631                                   (document->children != NULL && document->children->name != NULL) ? (char *)document->children->name : __dodostring__, 
    632                                   document->compression); 
    633  
     667        return i; 
    634668#else 
    635  
    636669        return __info(); 
    637  
    638670#endif 
    639671} 
     
    644676 
    645677dodoArray<node> 
    646 processor::parse(xmlNodePtr xnode) 
     678processor::parse(__node xnode) 
    647679{ 
    648680        dodoArray<node> sample; 
     
    653685        dodoArray<node>::iterator i, j; 
    654686 
    655         while (xnode != NULL) 
    656         { 
    657                 if (xnode->type != XML_ELEMENT_NODE) 
    658                 { 
    659                         xnode = xnode->next; 
     687        while (xnode.node != NULL) 
     688        { 
     689                if (xnode.node->type != XML_ELEMENT_NODE) 
     690                { 
     691                        xnode.node = xnode.node->next; 
    660692 
    661693                        continue; 
     
    668700                one.CDATA = isCDATA(xnode); 
    669701 
    670                 if (xnode->children != NULL) 
    671                 { 
    672                         children = parse(xnode->children); 
     702                if (xnode.node->children != NULL) 
     703                { 
     704                        children = parse(__node(xnode.node->children)); 
    673705                        i = children.begin(); 
    674706                        j = children.end(); 
     
    683715                initNode(one); 
    684716 
    685                 xnode = xnode->next; 
     717                xnode.node = xnode.node->next; 
    686718        } 
    687719 
     
    712744{ 
    713745#ifdef LIBXML2_EXT 
    714  
    715         xmlFreeDoc(document); 
    716  
    717         document = xmlParseFile(file.c_str()); 
    718         if (document == NULL) 
     746        xmlFreeDoc(document->document); 
     747 
     748        document->document = xmlParseFile(file.c_str()); 
     749        if (document->document == NULL) 
    719750        { 
    720751                xmlErrorPtr error = xmlGetLastError(); 
     
    730761        } 
    731762 
    732         xmlNodePtr xnode = xmlDocGetRootElement(document); 
     763        xmlNodePtr xnode = xmlDocGetRootElement(document->document); 
    733764        if (xnode == NULL) 
    734765        { 
     
    745776        } 
    746777 
    747         return *(parse(xnode).begin()); 
    748  
     778        return *(parse(__node(xnode)).begin()); 
    749779#else 
    750  
    751780        return node(); 
    752  
    753781#endif 
    754782} 
     
    760788{ 
    761789#ifdef LIBXML2_EXT 
    762  
    763         xmlFreeDoc(document); 
    764  
    765         document = xmlParseMemory(buffer.c_str(), buffer.size()); 
    766         if (document == NULL) 
     790        xmlFreeDoc(document->document); 
     791 
     792        document->document = xmlParseMemory(buffer.c_str(), buffer.size()); 
     793        if (document->document == NULL) 
    767794        { 
    768795                xmlErrorPtr error = xmlGetLastError(); 
     
    778805        } 
    779806 
    780         xmlNodePtr xnode = xmlDocGetRootElement(document); 
     807        xmlNodePtr xnode = xmlDocGetRootElement(document->document); 
    781808        if (xnode == NULL) 
    782809        { 
     
    793820        } 
    794821 
    795         return *(parse(xnode).begin()); 
    796  
     822        return *(parse(__node(xnode)).begin()); 
    797823#else 
    798  
    799824        return node(); 
    800  
    801825#endif 
    802826} 
     
    817841#ifdef LIBXML2_EXT 
    818842 
    819 xmlNodePtr 
     843__node 
    820844processor::findNode(const __nodeDef &definition, 
    821                                         xmlNodePtr      xnode) 
    822 { 
    823         xmlNodePtr one; 
     845                                        const __node    &a_xnode) 
     846{ 
     847        xmlNodePtr one, xnode = a_xnode.node; 
    824848        bool skip; 
    825849 
    826         if (icaseNames) 
    827         { 
    828                 cmpFunc = xmlStrcasecmp; 
    829         } 
    830         else 
    831         { 
    832                 cmpFunc = xmlStrcmp; 
    833         } 
     850        cmpFunc = icaseNames?xmlStrcasecmp:xmlStrcmp; 
    834851 
    835852        while (xnode != NULL) 
     
    850867                                skip = true; 
    851868                        } 
    852                         else if (cmpFunc(xnode->ns->prefix, (xmlChar *)definition.ns.c_str()) != 0) 
     869                        else if (cmpFunc(xnode->ns->prefix, (unsigned char *)definition.ns.c_str()) != 0) 
    853870                        { 
    854871                                skip = true; 
     
    858875                if (!skip && xnode->name != NULL) 
    859876                { 
    860                         if (cmpFunc(xnode->name, (xmlChar *)definition.name.c_str()) == 0) 
     877                        if (cmpFunc(xnode->name, (unsigned char *)definition.name.c_str()) == 0) 
    861878                        { 
    862879                                return xnode; 
     
    864881                } 
    865882 
    866                 one = findNode(definition, xnode->children); 
     883                one = findNode(definition, __node(xnode->children)).node; 
    867884 
    868885                if (one != NULL) 
     
    874891        } 
    875892 
    876         return NULL; 
     893        return __node(NULL); 
    877894} 
    878895 
     
    885902{ 
    886903#ifdef LIBXML2_EXT 
    887  
    888         xmlFreeDoc(document); 
    889         document = NULL; 
    890  
     904        xmlFreeDoc(document->document); 
     905        document->document = NULL; 
    891906#endif 
    892907} 
  • trunk/src/dataMemoryShared.cc

    r1162 r1175  
    2828 */ 
    2929 
    30  
     30#include <libdodo/directives.h> 
     31#include <libdodo/types.h> 
     32 
     33#include <sys/types.h> 
     34#include <sys/mman.h> 
     35 
     36#ifdef XSI_IPC 
     37#include <sys/ipc.h> 
     38#include <sys/shm.h> 
     39#else /*POSIX_SEMAPHORES*/ 
     40#include <fcntl.h> 
     41#endif 
     42 
     43namespace dodo 
     44{ 
     45        namespace data 
     46        { 
     47                namespace memory 
     48                { 
     49                        struct __key 
     50                        { 
     51#ifdef XSI_IPC 
     52                                int key;            ///< key for the shared data 
     53#else 
     54                                dodoString key;     ///< key for the shared data 
     55#endif 
     56                        }; 
     57                }; 
     58        }; 
     59}; 
     60 
     61#include <libdodo/toolsMisc.h> 
     62#include <libdodo/toolsCode.h> 
    3163#include <libdodo/dataMemoryShared.h> 
     64#include <libdodo/dataMemorySharedEx.h> 
    3265 
    3366using namespace dodo::data::memory; 
     
    4174shared::shared() : mshared(NULL), 
    4275                                   autogenerated(false), 
    43  
     76                                   key(new __key), 
    4477#ifndef XSI_IPC 
    45  
    4678                                   size(0), 
    47  
    48 #endif 
    49  
     79#endif 
    5080                                   shm(-1) 
    5181{ 
     
    5686shared::shared(int a_key) : mshared(NULL), 
    5787                                                        autogenerated(false), 
    58  
     88                                                        key(new __key), 
    5989#ifndef XSI_IPC 
    60  
    6190                                                        size(0), 
    62  
    63 #endif 
    64  
     91#endif 
    6592                                                        shm(-1) 
    6693{ 
    6794#ifdef XSI_IPC 
    68  
    6995        if (a_key == 0) 
    7096        { 
    71                 key = tools::misc::iRandom(); 
     97                key->key = tools::misc::iRandom(); 
    7298 
    7399                autogenerated = true; 
     
    75101        else 
    76102        { 
    77                 key = a_key; 
    78         } 
    79  
     103                key->key = a_key; 
     104        } 
    80105#else 
    81106 
    82107#ifdef __FreeBSD__ 
    83  
    84         key = "/tmp/"; 
    85  
    86 #else 
    87  
    88         key = '/'; 
    89  
     108        key->key = "/tmp/"; 
     109#else 
     110        key->key = '/'; 
    90111#endif 
    91112 
     
    95116                tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 
    96117 
    97                 key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 
     118                key->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 
    98119 
    99120                autogenerated = true; 
     
    104125                memcpy(_key, &a_key, 4); 
    105126 
    106                 key.append(tools::code::binToHex(dodoString(_key, 4))); 
    107         } 
    108  
    109         shm = shm_open(key.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); 
     127                key->key.append(tools::code::binToHex(dodoString(_key, 4))); 
     128        } 
     129 
     130        shm = shm_open(key->key.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); 
    110131        if (shm == -1) 
    111132        { 
    112133                throw exception::basic(exception::ERRMODULE_DATAMEMORYSHARED, SHAREDEX_SHARED, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    113134        } 
    114  
    115135#endif 
    116136} 
     
    121141{ 
    122142#ifdef XSI_IPC 
    123  
    124143        if (shm != -1 && autogenerated) 
    125144        { 
    126145                shmctl(shm, IPC_RMID, NULL); 
    127146        } 
    128  
    129 #else 
    130  
     147#else 
    131148        if (shm != -1) 
    132149        { 
     
    138155                if (autogenerated) 
    139156                { 
    140                         shm_unlink(key.c_str()); 
    141                 } 
    142         } 
    143 #endif 
     157                        shm_unlink(key->key.c_str()); 
     158                } 
     159        } 
     160#endif 
     161 
     162        delete key; 
    144163} 
    145164 
     
    152171 
    153172#ifdef XSI_IPC 
    154  
    155173        if (a_key == 0) 
    156174        { 
    157                 key = tools::misc::iRandom(); 
     175                key->key = tools::misc::iRandom(); 
    158176 
    159177                autogenerated = true; 
     
    163181                key = a_key; 
    164182        } 
    165  
    166183#else 
    167184 
    168185#ifdef __FreeBSD__ 
    169  
    170         key = "/tmp/"; 
    171  
    172 #else 
    173  
    174         key = '/'; 
    175  
     186        key->key = "/tmp/"; 
     187#else 
     188        key->key = '/'; 
    176189#endif 
    177190 
     
    181194                tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 
    182195 
    183                 key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 
     196                key->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 
    184197 
    185198                autogenerated = true; 
     
    190203                memcpy(_key, &a_key, 4); 
    191204 
    192                 key.append(tools::code::binToHex(dodoString(_key, 4))); 
    193         } 
    194  
    195         shm = shm_open(key.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); 
     205                key->key.append(tools::code::binToHex(dodoString(_key, 4))); 
     206        } 
     207 
     208        shm = shm_open(key->key.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); 
    196209        if (shm == -1) 
    197210        { 
    198211                throw exception::basic(exception::ERRMODULE_DATAMEMORYSHARED, SHAREDEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    199212        } 
    200  
    201213#endif 
    202214} 
     
    208220{ 
    209221#ifdef XSI_IPC 
    210  
    211222        if (shm != -1 && autogenerated) 
    212223        { 
     
    216227                } 
    217228        } 
    218  
    219 #else 
    220  
     229#else 
    221230        if (shm != -1) 
    222231        { 
     
    231240                if (autogenerated) 
    232241                { 
    233                         if (shm_unlink(key.c_str()) == -1) 
     242                        if (shm_unlink(key->key.c_str()) == -1) 
    234243                        { 
    235244                                throw exception::basic(exception::ERRMODULE_DATAMEMORYSHARED, SHAREDEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     
    246255{ 
    247256#ifdef XSI_IPC 
    248  
    249257        int shm = shmget(a_key, 0, O_RDWR); 
    250258        if (shm == -1) 
     
    257265                throw exception::basic(exception::ERRMODULE_DATAMEMORYSHARED, SHAREDEX_REMOVE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    258266        } 
    259  
    260267#else 
    261268 
    262269#ifdef __FreeBSD__ 
    263  
    264270        dodoString key = "/tmp/"; 
    265  
    266 #else 
    267  
     271#else 
    268272        dodoString key = "/"; 
    269  
    270273#endif 
    271274 
     
    279282                throw exception::basic(exception::ERRMODULE_DATAMEMORYSHARED, SHAREDEX_REMOVE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    280283        } 
    281  
    282284#endif 
    283285} 
     
    291293 
    292294#ifdef XSI_IPC 
    293  
    294295        if (a_size == 0) 
    295296        { 
    296                 shm = shmget(key, 0, O_RDWR); 
     297                shm = shmget(key->key, 0, O_RDWR); 
    297298                if (shm == -1) 
    298299                { 
     
    302303        else 
    303304        { 
    304                 shm = shmget(key, a_size, IPC_CREAT | O_RDWR); 
     305                shm = shmget(key->key, a_size, IPC_CREAT | O_RDWR); 
    305306                if (shm == -1) 
    306307                { 
     
    314315                throw exception::basic(exception::ERRMODULE_DATAMEMORYSHARED, SHAREDEX_MAP, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    315316        } 
    316  
    317 #else 
    318  
     317#else 
    319318        if (a_size == 0) 
    320319        { 
     
    343342                throw exception::basic(exception::ERRMODULE_DATAMEMORYSHARED, SHAREDEX_MAP, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    344343        } 
    345  
    346344#endif 
    347345 
     
    357355        { 
    358356#ifdef XSI_IPC 
    359  
    360357                if (shmdt(mshared) == -1) 
    361  
    362 #else 
    363  
     358#else 
    364359                if (munmap(mshared, size) == -1) 
    365  
    366360#endif 
    367361                { 
     
    387381{ 
    388382#ifdef XSI_IPC 
    389  
    390383        if (shm == -1) 
    391384        { 
    392                 shm = shmget(key, 0, O_RDWR); 
     385                shm = shmget(key->key, 0, O_RDWR); 
    393386                if (shm == -1) 
    394387                { 
     
    405398 
    406399        return ds.shm_segsz; 
    407  
    408 #else 
    409  
     400#else 
    410401        struct stat st; 
    411402 
     
    416407 
    417408        return st.st_size; 
    418  
    419 #endif 
    420 } 
    421  
    422 //------------------------------------------------------------------- 
    423  
     409#endif 
     410} 
     411 
     412//------------------------------------------------------------------- 
     413 
Note: See TracChangeset for help on using the changeset viewer.