/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 10-09-2008 0h57 by Vamps (vamps@alterinet.org) * * */ #include #include #include #include #include #include "include/struct.h" #include "include/config.h" int LoadConf(char *file, struct config *config_t) { int a, i; char byte = 0; int error = 0; char *ptr; char buf[SIZE_BUFFER]; char buf_tmp[SIZE_BUFFER]; FILE *configfile; int nb_config = 0; if ((configfile = fopen(file, "r")) == NULL) { perror("fopen"); return 1; } while (feof(configfile) == 0 && error == 0) { memset(buf, 0, SIZE_BUFFER); for (a = 0; a < SIZE_BUFFER; a++) { if (fread(&byte, sizeof(char), 1, configfile) == 0) { error = 1; break; } if (byte == '\n') break; buf[a] = byte; } while (1) { ptr = strstr(buf, "MYSQL_SERVER="); if (ptr != NULL) { memset(config_t->mysql_server, 0, SIZE_BUFFER); for (a = strlen("MYSQL_SERVER="), i = 0; a < strlen(buf); a++, i++) { config_t->mysql_server[i] = buf[a]; } nb_config++; break; } ptr = strstr(buf, "MYSQL_BASE="); if (ptr != NULL) { memset(config_t->mysql_base, 0, SIZE_BUFFER); for (a = strlen("MYSQL_BASE="), i = 0; a < strlen(buf); a++, i++) { config_t->mysql_base[i] = buf[a]; } nb_config++; break; } ptr = strstr(buf, "MYSQL_USER="); if (ptr != NULL) { memset(config_t->mysql_user, 0, SIZE_BUFFER); for (a = strlen("MYSQL_USER="), i = 0; a < strlen(buf); a++, i++) { config_t->mysql_user[i] = buf[a]; } nb_config++; break; } ptr = strstr(buf, "MYSQL_PASSWORD="); if (ptr != NULL) { memset(config_t->mysql_password, 0, SIZE_BUFFER); for (a = strlen("MYSQL_PASSWORD="), i = 0; a < strlen(buf); a++, i++) { config_t->mysql_password[i] = buf[a]; } nb_config++; break; } ptr = strstr(buf, "MYSQL_PORT="); if (ptr != NULL) { memset(buf_tmp, 0, SIZE_BUFFER); for (a = strlen("MYSQL_PORT="), i = 0; a < strlen(buf); a++, i++) { buf_tmp[i] = buf[a]; } config_t->mysql_port = atoi(buf_tmp); nb_config++; break; } break; } } fclose(configfile); if (nb_config != NB_CONFIG) { printf("Error in reading config file, no more options (%d)\n", nb_config); return 1; } return 0; }