/* echat.c * * copyright (c) 2000-2003 SeaD * see GPL for copying info * */ #include #include #include "echat.h" /* #ifdef FREEBSD # include #endif * FREEBSD */ #ifdef DEBUG # include #endif /* DEBUG */ char *buf = NULL; char *packet = NULL; char *message = NULL; struct config_t *config = NULL; struct status_t *status = NULL; #ifdef DEBUG FILE *debug_file = NULL; #endif /* DEBUG */ void stat_init(void) { chnl_parse(); status->room = &status->chnl[0]; strncpy(status->chnl[0].name, status->channel, CHANNEL_MAXLEN); status->channels++; if (*config->log_main == '~') { snprintf(buf, PATH_SIZE, "%s/%s", getenv("HOME"), &config->log_main[1]); strncpy(config->log_main, buf, PATH_SIZE); } if (*config->log_mesg == '~') { snprintf(buf, PATH_SIZE, "%s/%s", getenv("HOME"), &config->log_mesg[1]); strncpy(config->log_mesg, buf, PATH_SIZE); } if (*config->log_priv == '~') { snprintf(buf, PATH_SIZE, "%s/%s", getenv("HOME"), &config->log_priv[1]); strncpy(config->log_priv, buf, PATH_SIZE); } *buf = '\0'; } int main(int argc, char *argv[]) { fprintf(stdout, "%s v%s by %s <%s>\n\n", NAME, VERSION, AUTHOR, MAIL); #ifdef DEBUG fprintf(stderr, "eChat: debugfile: Opening %s\n", DEBUG); if (!(debug_file = fopen(DEBUG, "a"))) fprintf(stderr, "echat: debugfile: %s\n", strerror(errno)); #endif /* DEBUG */ #ifdef DEBUG fprintf(debug_file, "eChat: Start %s v%s\n", NAME, VERSION); fflush(debug_file); #endif /* DEBUG */ if ((buf = (char *) malloc(BUF_SIZE)) == NULL) { #ifdef DEBUG fprintf(debug_file, "malloc(): %s\n", strerror(errno)); #endif /* DEBUG */ exit(EXIT_FAILURE); } if ((packet = (char *) malloc(BUF_SIZE)) == NULL) { #ifdef DEBUG fprintf(debug_file, "malloc(): %s\n", strerror(errno)); #endif /* DEBUG */ exit(EXIT_FAILURE); } if ((message = (char *) malloc(BUF_SIZE)) == NULL) { #ifdef DEBUG fprintf(debug_file, "malloc(): %s\n", strerror(errno)); #endif /* DEBUG */ exit(EXIT_FAILURE); } if ((config = (struct config_t *) malloc(sizeof(struct config_t))) == NULL) { #ifdef DEBUG fprintf(debug_file, "malloc(): %s\n", strerror(errno)); #endif /* DEBUG */ exit(EXIT_FAILURE); } if ((status = (struct status_t *) malloc(sizeof(struct status_t))) == NULL) { #ifdef DEBUG fprintf(debug_file, "malloc(): %s\n", strerror(errno)); #endif /* DEBUG */ exit(EXIT_FAILURE); } memset(config, 0, sizeof(struct config_t)); memset(status, 0, sizeof(struct status_t)); srand((unsigned int) getpid()); conf_init(argc, argv); addr_parse(); user_parsfavorite(); user_parsignore(); user_parsban(); sock_init(); addr_init(); term_init(); stat_init(); window_init(); window_refresh(); sig_init(); chnl_init(); snprintf(message, STR_SIZE, ECHAT_WELCOME, time_get(), NAME, VERSION, config->nick); write_log(config->log_main); write_str(status->room->name, COL_SYSTEM); while (1) { sig_process(); sock_recv(); #ifdef TCP sock_tcprecv(); #endif /* TCP */ read_str(); time_users(); } }