]> git.vomp.tv Git - vompserver.git/blob - config.h
15 years that line of code has been waiting to crash
[vompserver.git] / config.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3     Copyright 2004-2005 University Of Bradford
4
5     This file is part of VOMP.
6
7     VOMP is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     VOMP is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with VOMP; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21
22 #ifndef CONFIG_H
23 #define CONFIG_H
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <pthread.h>
29 #include <ctype.h>
30
31 #include "log.h"
32
33 #define MAX_FILENAME_LENGTH 500
34 #define BUFFER_LENGTH 1500
35
36 class Config
37 {
38   public:
39     Config();
40
41     int init(char* fileName);
42     int shutdown();
43     int status();
44
45     char* getValueString(const char* section, const char* key);
46     long getValueLong(const char* section, const char* key, int* failure);
47     long long getValueLongLong(char* section, char* key, int* failure);
48     double getValueDouble(char* section, char* key, int* failure);
49
50     int setValueString(const char* section, const char* key, const char* newValue);
51     int setValueLong(const char* section, char* key, long newValue);
52     int setValueLongLong(char* section, char* key, long long newValue);
53     int setValueDouble(char* section, char* key, double newValue);
54
55     int deleteValue(const char* section, char* key); // err.. delete "key".
56     char* getSectionKeyNames(const char* section, int& numberOfReturns, int& length);
57
58   private:
59     pthread_mutex_t fileLock;
60     int initted;
61     int lastLineLength;
62     Log* log;
63
64     char fileName[MAX_FILENAME_LENGTH];
65     char fileNameTemp[MAX_FILENAME_LENGTH];
66
67     FILE* file;
68     char buffer[BUFFER_LENGTH];
69
70     int openFile();
71     void closeFile();
72     int readLine();
73     int findSection(const char* section);
74     int findKey(const char* key);
75     void trim(char* sting);
76     FILE* copyToHere(long position);
77     int copyRest(FILE* newFile);
78 };
79
80 #endif