diff --git a/Makefile b/Makefile index 06312de..8ea7e95 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ ECHO = @echo GCC = g++ RM = @rm -f -CCFLAGS = -c -g -ansi -pedantic -Wall #optimization? +CCFLAGS = -c -g -std=c++11 -pedantic -Wall #optimization? OBJETS = $(SRC:.cpp=.o) SRC = $(wildcard *.cpp) EXE = deployer diff --git a/Services.cpp b/Services.cpp index 2e784cd..78a5221 100644 --- a/Services.cpp +++ b/Services.cpp @@ -1,9 +1,12 @@ // deployer Services implementation // Copyright (C) 2024 Jean-Cloud // GNU General Public License v3 -#include + +#include #include #include +#include +#include #include "Services.h" Services::Services(const char *ServicesCSV) @@ -13,33 +16,35 @@ Services::Services(const char *ServicesCSV) Services::~Services(){} -vector Services::readServicesFromCSV (const char *CSV) const { +vector Services::readServicesFromCSV (const char *CSV) const +{ + //this method extracts the list of uid|username|servers from the services.csv file + //and returns them in a vector , with serviceData a structure defined in the header vector result; - FILE *streamServices=fopen(CSV,"r"); - if (streamServices==NULL){ + ifstream streamServices(CSV); + if (!streamServices){ cout << "Invalid services.csv file." << endl; }else{ - char line [1000]; + string line; int userID; + string tmpUserID; string username; string serveur; list serveurs; - while(fgets(line,sizeof(line),streamServices)!=NULL){ - userID=atoi(strtok(line,";")); - username=strtok(NULL,";"); - //while loop - serveur=strtok(NULL,";"); - cout << serveur << " "; - while(!serveur.empty()){ - serveur=strtok(NULL,";"); - //serveurs.push_back(serveur); - cout << serveur << " "; + while(getline(streamServices,line)){ + if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account + continue; + } + stringstream streamLine(line); + getline(streamLine,tmpUserID,';'); //extracting the userID + userID=stoi(tmpUserID); + getline(streamLine,username,';'); //extracting the username + while(getline(streamLine,serveur,';')){ //extracting the server(s) + serveurs.push_back(serveur); } - //serviceData entry = {userID,username,serveurs}; - //cout << entry.userID <