sh8s_deployer/Services.cpp

45 lines
1.3 KiB
C++
Raw Normal View History

// deployer Services implementation
// Copyright (C) 2024 Jean-Cloud
// GNU General Public License v3
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include "Services.h"
Services::Services(const char *ServicesCSV)
{
services=readServicesFromCSV(ServicesCSV);
}
Services::~Services(){}
vector <serviceData> Services::readServicesFromCSV (const char *CSV) const {
vector <serviceData> result;
FILE *streamServices=fopen(CSV,"r");
if (streamServices==NULL){
cout << "Invalid services.csv file." << endl;
}else{
char line [1000];
int userID;
string username;
string serveur;
list <string> 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 << " ";
}
//serviceData entry = {userID,username,serveurs};
//cout << entry.userID <<entry.username << entry.serveurs.front() << endl;
//result.push_back(entry);
}
}
return result;
}