Subversion Repositories IRC-Archiver

Rev

Rev 2 | Rev 4 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 3
Line 1... Line 1...
1
/* $Id: main.c 2 2024-08-29 17:56:13Z nishi $ */
1
/* $Id: main.c 3 2024-08-29 18:49:46Z nishi $ */
2
 
2
 
3
#include <stdio.h>
3
#include <stdio.h>
4
#include <stdlib.h>
4
#include <stdlib.h>
5
#include <string.h>
5
#include <string.h>
6
#include <sys/stat.h>
6
#include <sys/stat.h>
7
 
7
 
-
 
8
#include "ia_util.h"
-
 
9
#include "ia_util.h"
-
 
10
 
8
int main(int argc, char** argv){
11
int main(int argc, char** argv) {
9
	const char* fn = argv[1] == NULL ? "archiver.ini" : argv[1];
12
	const char* fn = argv[1] == NULL ? "archiver.ini" : argv[1];
10
	FILE* f = fopen(fn, "r");
13
	FILE* f = fopen(fn, "r");
11
	if(f == NULL){
14
	if(f == NULL) {
12
		fprintf(stderr, "Could not open the config: %s\n", fn);
15
		fprintf(stderr, "Could not open the config: %s\n", fn);
13
		return 1;
16
		return 1;
14
	}
17
	}
15
 
18
 
16
	struct stat s;
19
	struct stat s;
Line 21... Line 24...
21
	buf[s.st_size] = 0;
24
	buf[s.st_size] = 0;
22
 
25
 
23
	int i;
26
	int i;
24
	int incr = 0;
27
	int incr = 0;
25
 
28
 
-
 
29
	char* host = NULL;
-
 
30
	int port = 0;
-
 
31
	char* username = NULL;
-
 
32
	char* password = NULL;
-
 
33
 
26
	for(i = 0;; i++){
34
	for(i = 0;; i++) {
27
		if(buf[i] == 0 || buf[i] == '\n'){
35
		if(buf[i] == 0 || buf[i] == '\n') {
28
			char oldc = buf[i];
36
			char oldc = buf[i];
29
			buf[i] = 0;
37
			buf[i] = 0;
30
			char* line = buf + incr;
38
			char* line = buf + incr;
31
			if(strlen(line) > 0){
39
			if(strlen(line) > 0 && line[0] != '#') {
32
				int j;
40
				int j;
33
				for(j = 0; line[j] != 0; j++){
41
				for(j = 0; line[j] != 0; j++) {
34
					if(line[j] == '='){
42
					if(line[j] == '=') {
35
						line[j] = 0;
43
						line[j] = 0;
36
						char* key = line;
44
						char* key = line;
37
						char* value = line + j + 1;
45
						char* value = line + j + 1;
38
 
46
 
-
 
47
						if(strcmp(key, "host") == 0) {
-
 
48
							if(host != NULL) free(host);
-
 
49
							host = ia_strdup(value);
-
 
50
						} else if(strcmp(key, "port") == 0) {
-
 
51
							port = atoi(value);
-
 
52
						} else if(strcmp(key, "username") == 0) {
-
 
53
							if(username != NULL) free(username);
-
 
54
							username = ia_strdup(value);
-
 
55
						} else if(strcmp(key, "password") == 0) {
-
 
56
							if(password != NULL) free(password);
-
 
57
							password = ia_strdup(value);
39
 
58
						}
40
 
59
 
41
						break;
60
						break;
42
					}
61
					}
43
				}
62
				}
44
			}
63
			}
45
			incr = i + 1;
64
			incr = i + 1;
46
			if(oldc == 0) break;
65
			if(oldc == 0) break;
47
		}else{
-
 
48
		}
66
		}
49
	}
67
	}
50
 
68
 
51
	free(buf);
69
	free(buf);
52
	fclose(f);
70
	fclose(f);
-
 
71
 
-
 
72
	int st = 0;
-
 
73
	if(host == NULL) {
-
 
74
		fprintf(stderr, "Specify host\n");
-
 
75
		st = 1;
-
 
76
	}
-
 
77
	if(username == NULL) {
-
 
78
		fprintf(stderr, "Specify username\n");
-
 
79
		st = 1;
-
 
80
	}
-
 
81
	if(password == NULL) {
-
 
82
		fprintf(stderr, "Specify password\n");
-
 
83
		st = 1;
-
 
84
	}
-
 
85
	if(st == 1) return st;
-
 
86
 
-
 
87
	if(host != NULL) free(host);
-
 
88
	if(username != NULL) free(username);
-
 
89
	if(password != NULL) free(password);
53
}
90
}