/** * \fn int getNameAndValue(char *name, int *value) * \brief Permet de récuperer le nom et sa valeur associer. * * \param name Nom de la clef auquel on cherche sa valeur. * \param value Valeur de la clef. * \return -1 les information sont vide, ou non trouver. * * Permet pour une ligne du fichier de configuration de récuperer le couple * nom, valeur si la fonction retourn -1 il y a rien a récuperer. */ int getValueOf(char *key, int *value) { FILE *configFile = fopen("config.conf", "r"); char buffer[BUFFER_SIZE]; char currentKey[BUFFER_SIZE]; int currentValue; int ret = -1; if(configFile == NULL) { fclose(configFile); return(-1); } do { fgets(buffer, BUFFER_SIZE, configFile); if(getKeyAndValue(buffer, currentKey, ¤tValue) == -1) { ret = -1; break; } if(strcmp(currentKey, key) == 0) { ret = 0; *value = currentValue; break; } } while(!feof(configFile)); fclose(configFile); return(ret); }
int CredsCommonsInnerBackend::getMethodFromConfigurationFile(const CredentialsMap &methodCodeMap, const std::string &methodName, int &method) { std::ifstream f(credsConfigurationFile()); if (!f.is_open()) return CYNARA_API_CONFIGURATION_ERROR; std::locale loc = f.getloc(); bool occurred = false; std::string key, value; int tmpMethod; while (getKeyAndValue(f, loc, key, value)) if (key == methodName && !interpretValue(methodCodeMap, tmpMethod, value, occurred)) return CYNARA_API_CONFIGURATION_ERROR; if (occurred) { method = tmpMethod; return CYNARA_API_SUCCESS; } return CYNARA_API_CONFIGURATION_ERROR; }