Subversion Repositories IRC-Archiver

Rev

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

Rev 5 Rev 7
Line 1... Line 1...
1
/* $Id: main.c 5 2024-08-30 02:36:44Z nishi $ */
1
/* $Id: main.c 7 2024-08-30 03:00:02Z 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 13... Line 13...
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* nickname = NULL;
-
 
18
char* database = NULL;
18
char* username = NULL;
19
char* username = NULL;
19
char* realname = NULL;
20
char* realname = NULL;
20
char* password = NULL;
21
char* password = NULL;
21
char* admin = NULL;
22
char* admin = NULL;
22
char* channels[128];
23
char* channels[128];
Line 73... Line 74...
73
						if(strcmp(key, "host") == 0) {
74
						if(strcmp(key, "host") == 0) {
74
							if(host != NULL) free(host);
75
							if(host != NULL) free(host);
75
							host = ia_strdup(value);
76
							host = ia_strdup(value);
76
						} else if(strcmp(key, "port") == 0) {
77
						} else if(strcmp(key, "port") == 0) {
77
							port = atoi(value);
78
							port = atoi(value);
-
 
79
						} else if(strcmp(key, "database") == 0) {
-
 
80
							if(database != NULL) free(database);
-
 
81
							database = ia_strdup(value);
78
						} else if(strcmp(key, "username") == 0) {
82
						} else if(strcmp(key, "username") == 0) {
79
							if(username != NULL) free(username);
83
							if(username != NULL) free(username);
80
							username = ia_strdup(value);
84
							username = ia_strdup(value);
81
						} else if(strcmp(key, "nickname") == 0) {
85
						} else if(strcmp(key, "nickname") == 0) {
82
							if(nickname != NULL) free(nickname);
86
							if(nickname != NULL) free(nickname);
Line 110... Line 114...
110
	int st = 0;
114
	int st = 0;
111
	if(host == NULL) {
115
	if(host == NULL) {
112
		fprintf(stderr, "Specify host\n");
116
		fprintf(stderr, "Specify host\n");
113
		st = 1;
117
		st = 1;
114
	}
118
	}
-
 
119
	if(database == NULL) {
-
 
120
		fprintf(stderr, "Specify database\n");
-
 
121
		st = 1;
-
 
122
	}
115
	if(username == NULL) {
123
	if(username == NULL) {
116
		fprintf(stderr, "Specify username\n");
124
		fprintf(stderr, "Specify username\n");
117
		st = 1;
125
		st = 1;
118
	}
126
	}
119
	if(nickname == NULL) {
127
	if(nickname == NULL) {
Line 132... Line 140...
132
		fprintf(stderr, "Specify realname\n");
140
		fprintf(stderr, "Specify realname\n");
133
		st = 1;
141
		st = 1;
134
	}
142
	}
135
	if(st == 1) return st;
143
	if(st == 1) return st;
136
 
144
 
137
	printf("Bot spawning a daemon\n");
145
	printf("Initializing the database\n");
-
 
146
 
138
	pid_t pid = 0;
147
	pid_t pid = 0;
139
	if(daemon) {
148
	if(daemon) {
-
 
149
		printf("Bot spawning a daemon\n");
140
		pid = fork();
150
		pid = fork();
141
	}
151
	}
142
	if(pid == 0) {
152
	if(pid == 0) {
143
		ia_bot_loop();
153
		ia_bot_loop();
144
		_exit(0);
154
		_exit(0);
Line 146... Line 156...
146
		printf("Spawned daemon, I am exiting\n");
156
		printf("Spawned daemon, I am exiting\n");
147
	}
157
	}
148
 
158
 
149
	if(host != NULL) free(host);
159
	if(host != NULL) free(host);
150
	if(realname != NULL) free(realname);
160
	if(realname != NULL) free(realname);
-
 
161
	if(database != NULL) free(database);
151
	if(username != NULL) free(username);
162
	if(username != NULL) free(username);
152
	if(nickname != NULL) free(nickname);
163
	if(nickname != NULL) free(nickname);
153
	if(password != NULL) free(password);
164
	if(password != NULL) free(password);
154
	if(admin != NULL) free(admin);
165
	if(admin != NULL) free(admin);
155
	for(i = 0; channels[i] != NULL; i++) {
166
	for(i = 0; channels[i] != NULL; i++) {