1 #include "dmt.hpp" 2 3 #include <stdlib.h> 4 #include <string> 5 #include <map> 6 #include <stdio.h> 7 8 #include "plugin/dmtPlugin.hpp" 9 10 #define Debug printf 11 12 /* 13 Plugin Ini Format: 14 15 16 [./DevDetail/xxx/Node Path] 17 constraint=xxxx.so 18 19 ./DevDetail/interiornode= 20 /interiornode/leafnode2= 21 22 */ 23 24 extern "C" 25 SYNCML_DM_RET_STATUS_T DMT_PluginLib_CheckConstraint( 26 CPCHAR path, //This is the path that matches the ini file parameter 27 DMStringMap& mapParameters, 28 PDmtTree tree //Global Tree with same access rights for current session 29 ) 30 { 31 if (tree == NULL) 32 { 33 //When tree is NULL, means we cannot get session/lock? 34 return (SYNCML_DM_FAIL); 35 } 36 bool nodeExist=false; 37 38 #if 0 39 //Test if DmtTree is OK 40 PDmtNode node; 41 PDmtErrorDescription e=tree->GetNode( 42 ".", //const char* path, 43 node //PDmtNode& ptrNode 44 ); 45 if (e!=NULL) 46 { 47 printf( "Can't get node from DmtTree for %s, err=%s\n", ".", (const char*)e->GetErrorText().c_str() ); 48 } 49 nodeExist=tree->IsValidNode("."); 50 Debug( " nodeExist for %s=%d\n", ".", nodeExist ); 51 nodeExist=tree->IsValidNode("./SyncML"); 52 Debug( " nodeExist for %s=%d\n", "./SyncML", nodeExist ); 53 54 #endif 55 56 Debug("CheckConstraint for path %s tree=0x%x\n", path, tree.GetPtr() ); 57 58 int numPaths=0; //How many in parameters 59 int numNodes=0; //How many exists 60 61 for ( DMMap<DMString, DMString>::POS it = mapParameters.begin(); it != mapParameters.end(); it++ ) 62 { 63 DMString paramName = mapParameters.get_key( it ); 64 DMString paramValue= mapParameters.get_value( it ); 65 66 const char * pName=paramName.c_str(); 67 68 if (* pName !='.' && * pName !='/' ) 69 continue; 70 71 numPaths++; 72 73 DMString strPath; 74 if (* pName =='.') 75 strPath=paramName; //Absolute path 76 else //(* pName =='/') //Relative path 77 { 78 strPath +=path; 79 if ( (* (pName+1)) !='\0' ) 80 strPath +=pName; // pName already started with "/", no need for 81 } 82 const char * szPath=strPath.c_str(); 83 84 //Debug("szPath.len=%d\n", strlen(szPath)); 85 nodeExist=tree->IsValidNode(szPath); 86 Debug("check for isValidNode of %s nodeExist=%d\n", szPath, nodeExist); 87 88 if (nodeExist) 89 { 90 Debug(" %s isValidNode\n", szPath); 91 numNodes++; 92 } 93 } 94 Debug("numNodes=%d\n", numNodes); 95 if (numNodes ==0 || numNodes== numPaths) 96 { 97 Debug("constraint Succeed\n"); 98 return (SYNCML_DM_SUCCESS); 99 } 100 Debug("constraint Failed !!!!!!\n"); 101 return (SYNCML_DM_CONSTRAINT_FAIL); 102 } 103 104 105 extern "C" 106 int DMT_PluginLib_GetAPIVersion(void) 107 { 108 return DMT_PLUGIN_VERSION_1_1; 109 } 110 111