Subversion Repositories IRC-Archiver

Rev

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

Rev 4 Rev 5
Line 1... Line 1...
1
/* $Id: main.c 4 2024-08-30 01:49:08Z nishi $ */
1
/* $Id: main.c 5 2024-08-30 02:36:44Z 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 <unistd.h>
6
#include <unistd.h>
Line 12... Line 12...
12
 
12
 
13
extern bool ia_do_log;
13
extern bool ia_do_log;
14
 
14
 
15
char* host = NULL;
15
char* host = NULL;
16
int port = 0;
16
int port = 0;
-
 
17
char* nickname = NULL;
17
char* username = NULL;
18
char* username = NULL;
-
 
19
char* realname = NULL;
18
char* password = NULL;
20
char* password = NULL;
19
char* admin = NULL;
21
char* admin = NULL;
-
 
22
char* channels[128];
-
 
23
int chanincr;
20
 
24
 
21
int main(int argc, char** argv) {
25
int main(int argc, char** argv) {
22
	const char* fn = "archiver.ini";
26
	const char* fn = "archiver.ini";
23
	int i;
27
	int i;
24
	bool daemon = true;
28
	bool daemon = true;
Line 49... Line 53...
49
	fread(buf, s.st_size, 1, f);
53
	fread(buf, s.st_size, 1, f);
50
	buf[s.st_size] = 0;
54
	buf[s.st_size] = 0;
51
 
55
 
52
	int incr = 0;
56
	int incr = 0;
53
 
57
 
-
 
58
	channels[0] = NULL;
-
 
59
 
54
	for(i = 0;; i++) {
60
	for(i = 0;; i++) {
55
		if(buf[i] == 0 || buf[i] == '\n') {
61
		if(buf[i] == 0 || buf[i] == '\n') {
56
			char oldc = buf[i];
62
			char oldc = buf[i];
57
			buf[i] = 0;
63
			buf[i] = 0;
58
			char* line = buf + incr;
64
			char* line = buf + incr;
Line 70... Line 76...
70
						} else if(strcmp(key, "port") == 0) {
76
						} else if(strcmp(key, "port") == 0) {
71
							port = atoi(value);
77
							port = atoi(value);
72
						} else if(strcmp(key, "username") == 0) {
78
						} else if(strcmp(key, "username") == 0) {
73
							if(username != NULL) free(username);
79
							if(username != NULL) free(username);
74
							username = ia_strdup(value);
80
							username = ia_strdup(value);
-
 
81
						} else if(strcmp(key, "nickname") == 0) {
-
 
82
							if(nickname != NULL) free(nickname);
-
 
83
							nickname = ia_strdup(value);
75
						} else if(strcmp(key, "password") == 0) {
84
						} else if(strcmp(key, "password") == 0) {
76
							if(password != NULL) free(password);
85
							if(password != NULL) free(password);
77
							password = ia_strdup(value);
86
							password = ia_strdup(value);
78
						} else if(strcmp(key, "admin") == 0) {
87
						} else if(strcmp(key, "admin") == 0) {
79
							if(admin != NULL) free(admin);
88
							if(admin != NULL) free(admin);
80
							admin = ia_strdup(value);
89
							admin = ia_strdup(value);
-
 
90
						} else if(strcmp(key, "realname") == 0) {
-
 
91
							if(realname != NULL) free(realname);
-
 
92
							realname = ia_strdup(value);
-
 
93
						} else if(strcmp(key, "channel") == 0) {
-
 
94
							channels[chanincr++] = ia_strdup(value);
-
 
95
							channels[chanincr] = NULL;
81
						}
96
						}
82
 
97
 
83
						break;
98
						break;
84
					}
99
					}
85
				}
100
				}
Line 99... Line 114...
99
	}
114
	}
100
	if(username == NULL) {
115
	if(username == NULL) {
101
		fprintf(stderr, "Specify username\n");
116
		fprintf(stderr, "Specify username\n");
102
		st = 1;
117
		st = 1;
103
	}
118
	}
-
 
119
	if(nickname == NULL) {
-
 
120
		fprintf(stderr, "Specify nickname\n");
-
 
121
		st = 1;
-
 
122
	}
104
	if(password == NULL) {
123
	if(password == NULL) {
105
		fprintf(stderr, "Specify password\n");
124
		fprintf(stderr, "Specify password\n");
106
		st = 1;
125
		st = 1;
107
	}
126
	}
108
	if(admin == NULL) {
127
	if(admin == NULL) {
109
		fprintf(stderr, "Specify admin\n");
128
		fprintf(stderr, "Specify admin\n");
110
		st = 1;
129
		st = 1;
111
	}
130
	}
-
 
131
	if(realname == NULL) {
-
 
132
		fprintf(stderr, "Specify realname\n");
-
 
133
		st = 1;
-
 
134
	}
112
	if(st == 1) return st;
135
	if(st == 1) return st;
113
 
136
 
114
	printf("Bot spawning a daemon\n");
137
	printf("Bot spawning a daemon\n");
115
	pid_t pid = 0;
138
	pid_t pid = 0;
116
	if(daemon) {
139
	if(daemon) {
Line 122... Line 145...
122
	} else {
145
	} else {
123
		printf("Spawned daemon, I am exiting\n");
146
		printf("Spawned daemon, I am exiting\n");
124
	}
147
	}
125
 
148
 
126
	if(host != NULL) free(host);
149
	if(host != NULL) free(host);
-
 
150
	if(realname != NULL) free(realname);
127
	if(username != NULL) free(username);
151
	if(username != NULL) free(username);
-
 
152
	if(nickname != NULL) free(nickname);
128
	if(password != NULL) free(password);
153
	if(password != NULL) free(password);
129
	if(admin != NULL) free(admin);
154
	if(admin != NULL) free(admin);
-
 
155
	for(i = 0; channels[i] != NULL; i++) {
-
 
156
		free(channels[i]);
-
 
157
	}
130
}
158
}