Subversion Repositories IRC-Archiver

Rev

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

Rev 7 Rev 8
Line 1... Line 1...
1
/* $Id: main.c 7 2024-08-30 03:00:02Z nishi $ */
1
/* $Id: main.c 8 2024-08-30 03:46:36Z 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>
7
#include <sys/stat.h>
7
#include <sys/stat.h>
8
#include <stdbool.h>
8
#include <stdbool.h>
9
 
9
 
10
#include "ia_util.h"
10
#include "ia_util.h"
11
#include "ia_bot.h"
11
#include "ia_bot.h"
-
 
12
#include "ia_db.h"
12
 
13
 
13
extern bool ia_do_log;
14
extern bool ia_do_log;
14
 
15
 
15
char* host = NULL;
16
char* host = NULL;
16
int port = 0;
17
int port = 0;
17
char* nickname = NULL;
18
char* nickname = NULL;
-
 
19
char* webroot = NULL;
18
char* database = NULL;
20
char* database = NULL;
19
char* username = NULL;
21
char* username = NULL;
20
char* realname = NULL;
22
char* realname = NULL;
-
 
23
char* nickserv = NULL;
21
char* password = NULL;
24
char* password = NULL;
22
char* admin = NULL;
25
char* admin = NULL;
23
char* channels[128];
26
char* channels[128];
24
int chanincr;
27
int chanincr;
25
 
28
 
Line 92... Line 95...
92
							if(admin != NULL) free(admin);
95
							if(admin != NULL) free(admin);
93
							admin = ia_strdup(value);
96
							admin = ia_strdup(value);
94
						} else if(strcmp(key, "realname") == 0) {
97
						} else if(strcmp(key, "realname") == 0) {
95
							if(realname != NULL) free(realname);
98
							if(realname != NULL) free(realname);
96
							realname = ia_strdup(value);
99
							realname = ia_strdup(value);
-
 
100
						} else if(strcmp(key, "webroot") == 0) {
-
 
101
							if(webroot != NULL) free(webroot);
-
 
102
							webroot = ia_strdup(value);
-
 
103
						} else if(strcmp(key, "nickserv") == 0) {
-
 
104
							if(nickserv != NULL) free(nickserv);
-
 
105
							nickserv = ia_strdup(value);
97
						} else if(strcmp(key, "channel") == 0) {
106
						} else if(strcmp(key, "channel") == 0) {
98
							channels[chanincr++] = ia_strdup(value);
107
							channels[chanincr++] = ia_strdup(value);
99
							channels[chanincr] = NULL;
108
							channels[chanincr] = NULL;
100
						}
109
						}
101
 
110
 
Line 134... Line 143...
134
	}
143
	}
135
	if(admin == NULL) {
144
	if(admin == NULL) {
136
		fprintf(stderr, "Specify admin\n");
145
		fprintf(stderr, "Specify admin\n");
137
		st = 1;
146
		st = 1;
138
	}
147
	}
-
 
148
	if(webroot == NULL) {
-
 
149
		fprintf(stderr, "Specify webroot\n");
-
 
150
		st = 1;
-
 
151
	}
139
	if(realname == NULL) {
152
	if(realname == NULL) {
140
		fprintf(stderr, "Specify realname\n");
153
		fprintf(stderr, "Specify realname\n");
141
		st = 1;
154
		st = 1;
142
	}
155
	}
143
	if(st == 1) return st;
156
	if(st == 1) return st;
144
 
157
 
145
	printf("Initializing the database\n");
158
	printf("Initializing the database\n");
146
 
159
 
-
 
160
	if(ia_db_init() != 0) {
-
 
161
		fprintf(stderr, "Failed to open database\n");
-
 
162
		goto cleanup;
-
 
163
	}
-
 
164
 
147
	pid_t pid = 0;
165
	pid_t pid = 0;
148
	if(daemon) {
166
	if(daemon) {
149
		printf("Bot spawning a daemon\n");
167
		printf("Bot spawning a daemon\n");
150
		pid = fork();
168
		pid = fork();
151
	}
169
	}
Line 154... Line 172...
154
		_exit(0);
172
		_exit(0);
155
	} else {
173
	} else {
156
		printf("Spawned daemon, I am exiting\n");
174
		printf("Spawned daemon, I am exiting\n");
157
	}
175
	}
158
 
176
 
-
 
177
cleanup:
159
	if(host != NULL) free(host);
178
	if(host != NULL) free(host);
-
 
179
	if(nickserv != NULL) free(nickserv);
-
 
180
	if(webroot != NULL) free(webroot);
160
	if(realname != NULL) free(realname);
181
	if(realname != NULL) free(realname);
161
	if(database != NULL) free(database);
182
	if(database != NULL) free(database);
162
	if(username != NULL) free(username);
183
	if(username != NULL) free(username);
163
	if(nickname != NULL) free(nickname);
184
	if(nickname != NULL) free(nickname);
164
	if(password != NULL) free(password);
185
	if(password != NULL) free(password);
165
	if(admin != NULL) free(admin);
186
	if(admin != NULL) free(admin);
166
	for(i = 0; channels[i] != NULL; i++) {
187
	for(i = 0; channels[i] != NULL; i++) {
167
		free(channels[i]);
188
		free(channels[i]);
168
	}
189
	}
-
 
190
	return st;
169
}
191
}