forked from arjenv/omnikstats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omnikreadconfig.c
78 lines (70 loc) · 1.83 KB
/
omnikreadconfig.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* omnikreadconfig.c
*
* Reads the config file and stores the data
*
* V1.1 sept, 13 2013
* V1.1 Changes: Added optional IPnumber and Serial number
* Beach
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/socket.h>
#include "omnikstats.h"
int omnikreadconfig(void) {
FILE *pFile;
char line[128], *pline;
int len;
if ((pFile = fopen("omnik.conf", "r")) == NULL) {
printf("Cannot open config file\n");
return(1);
}
while ((fgets(line, sizeof line, pFile)) != NULL) {
len = strlen(line);
// printf("%s", line); //for debugging
if ((line == strchr(line, '#')) || (len==1)) {
// printf("starts with comment, skipping....\n");
continue; //#=comment, skip line
}
for (pline=line; *pline; pline++, len--) {
//make it all lowercase and get rid of whitespaces
while (isspace(*pline)) memmove(pline, pline+1, len--);
*pline = tolower(*pline);
}
// printf("nospaces(?) %s\n", line); //for debugging
if (strstr(line, "omnikurl") != NULL) {
if (strlen(line) < 68) {
strcpy(stats.url, &line[8]);
if (stats.verbose==2) printf("URL: %s\n", stats.url);
}
}
if (strstr(line, "omnikapi") != NULL) {
if (strlen(line) < 68) {
strcpy(stats.key, &line[8]);
if (stats.verbose==2) printf("KEY: %s\n", stats.key);
}
}
if (strstr(line, "systemid") != NULL) {
if (strlen(line) < 18) {
strcpy(stats.ID, &line[8]);
if (stats.verbose==2) printf("ID: %s\n", stats.ID);
}
}
if (strstr(line, "ipnumber") != NULL) {
if (strlen(line) < 25) {
strcpy(stats.IPnumber, &line[8]);
if (stats.verbose==2) printf("IP: %s\n", stats.IPnumber);
}
}
if (strstr(line, "snumber") != NULL) {
if (strlen(line) < 25) {
stats.serial_number = atol(&line[7]);
if (stats.verbose==2) printf("SN: %li\n", stats.serial_number);
}
}
}
return(0);
}