]> WPIA git - cassiopeia.git/commitdiff
add: load CAs based on prefixes
authorFelix Dörre <felix@dogcraft.de>
Sat, 30 May 2015 13:26:58 +0000 (15:26 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sat, 30 May 2015 13:26:58 +0000 (15:26 +0200)
src/config.cpp

index ce78f417582a8a8049389f18435279cde60b7fa8..ad3c1375963a16602d07611b62bc7ff502e31606 100644 (file)
@@ -91,26 +91,26 @@ int parseProfiles() {
 
         std::string cas = map->at( "ca" );
 
-        for( size_t pos = 0; pos != std::string::npos; ) {
-            size_t end = cas.find( ",", pos );
-            std::string sub;
-
-            if( end == std::string::npos ) {
-                sub = cas.substr( pos );
-            } else {
-                sub = cas.substr( pos, end - pos );
-                end++;
+        DIR *dir;
+        struct dirent *ent;
+        if ((dir = opendir ("ca")) != NULL) {
+            while ((ent = readdir (dir)) != NULL) {
+                std::string caName = std::string(ent->d_name);
+                if( caName.find( cas ) != 0 ){
+                    continue;
+                }
+
+                if( CAs.find( caName ) == CAs.end() ) {
+                    std::shared_ptr<CAConfig> ca( new CAConfig( caName ) );
+                    CAs.emplace( caName, ca );
+                }
+
+                prof.ca.push_back( CAs.at( caName ) );
+                std::cout << "Adding CA: " << caName << std::endl;
             }
-
-            pos = end;
-
-            if( CAs.find( sub ) == CAs.end() ) {
-                std::shared_ptr<CAConfig> ca( new CAConfig( sub ) );
-                CAs.emplace( sub, ca );
-            }
-
-            prof.ca.push_back( CAs.at( sub ) );
-
+            closedir (dir);
+        } else {
+            throw "Directory with CAConfigs not found";
         }
 
         profiles.emplace( profileName, prof );