From 6b78526669c175a9ebb8da4cb6273100556d2df0 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 4 Aug 2016 19:25:49 +1000 Subject: [PATCH] Replace printf / fprintf(stderr... with dolog --- bbs.c | 12 +-- bbs_list.c | 92 +++++++++++----------- doors.c | 84 ++++++++++---------- email.c | 188 ++++++++++++++++++++++---------------------- files.c | 209 +++++++++++++++++++++++++------------------------ mail_menu.c | 30 +++---- main.c | 12 +-- main_menu.c | 28 +++---- users.c | 220 ++++++++++++++++++++++++++-------------------------- 9 files changed, 437 insertions(+), 438 deletions(-) diff --git a/bbs.c b/bbs.c index f46e277..a192bbc 100644 --- a/bbs.c +++ b/bbs.c @@ -41,7 +41,7 @@ void dolog(char *fmt, ...) { snprintf(buffer, 512, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday); logfptr = fopen(buffer, "a"); if (!logfptr) { - printf("Error opening log file!\n"); + dolog("Error opening log file!"); return; } va_list ap; @@ -422,7 +422,7 @@ void automessage_write(int socket, struct user_record *user) { fwrite(automsg, strlen(automsg), 1, fptr); fclose(fptr); } else { - printf("Unable to open automessage.txt for writing\n"); + dolog("Unable to open automessage.txt for writing"); } } } @@ -446,7 +446,7 @@ void automessage_display(int socket) { } fclose(fptr); } else { - printf("Error opening automessage.txt\n"); + dolog("Error opening automessage.txt"); } } else { s_putstring(socket, "No automessage!\r\n"); @@ -491,7 +491,7 @@ void runbbs(int socket, char *ip) { mynode = i; nodefile = fopen(buffer, "w"); if (!nodefile) { - printf("Error opening nodefile!\n"); + dolog("Error opening nodefile!"); close(socket); exit(1); } @@ -548,7 +548,7 @@ void runbbs(int socket, char *ip) { if (stat(buffer, &s) == 0) { nodefile = fopen(buffer, "r"); if (!nodefile) { - printf("Error opening nodefile!\n"); + dolog("Error opening nodefile!"); disconnect(socket, "Error opening nodefile!"); } fgets(buffer, 256, nodefile); @@ -566,7 +566,7 @@ void runbbs(int socket, char *ip) { sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode); nodefile = fopen(buffer, "w"); if (!nodefile) { - printf("Error opening nodefile!\n"); + dolog("Error opening nodefile!"); close(socket); exit(1); } diff --git a/bbs_list.c b/bbs_list.c index e126620..7b7dcb8 100644 --- a/bbs_list.c +++ b/bbs_list.c @@ -15,7 +15,7 @@ void add_bbs(int socket, struct user_record *user) { "sysop TEXT," "telnet TEXT," "owner INTEGER);"; - + char *insert_sql = "INSERT INTO bbslist (bbsname, sysop, telnet, owner) VALUES(?,?, ?, ?)"; char bbsname[19]; @@ -23,20 +23,20 @@ void add_bbs(int socket, struct user_record *user) { char telnet[39]; char buffer[256]; char c; - char *err_msg = 0; + char *err_msg = 0; sqlite3 *db; sqlite3_stmt *res; - int rc; - + int rc; + s_putstring(socket, "\r\n\e[1;37mEnter the BBS Name: \e[0m"); s_readstring(socket, bbsname, 18); - + s_putstring(socket, "\r\n\e[1;37mEnter the Sysop's Name: \e[0m"); s_readstring(socket, sysop, 16); - + s_putstring(socket, "\r\n\e[1;37mEnter the Telnet URL: \e[0m"); s_readstring(socket, telnet, 38); - + s_putstring(socket, "\r\nYou entered:\r\n"); s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n"); sprintf(buffer, "\e[1;37mBBS Name: \e[1;32m%s\r\n", bbsname); @@ -47,55 +47,55 @@ void add_bbs(int socket, struct user_record *user) { s_putstring(socket, buffer); s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n"); s_putstring(socket, "Is this correct? (Y/N) :"); - + c = s_getc(socket); if (tolower(c) == 'y') { sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } - + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); if (rc != SQLITE_OK ) { - - fprintf(stderr, "SQL error: %s\n", err_msg); - - sqlite3_free(err_msg); + + dolog("SQL error: %s", err_msg); + + sqlite3_free(err_msg); sqlite3_close(db); - + return; - } - + } + rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, bbsname, -1, 0); sqlite3_bind_text(res, 2, sysop, -1, 0); sqlite3_bind_text(res, 3, telnet, -1, 0); sqlite3_bind_int(res, 4, user->id); - + } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } - - + + rc = sqlite3_step(res); - + if (rc != SQLITE_DONE) { - - printf("execution failed: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + + dolog("execution failed: %s", sqlite3_errmsg(db)); + sqlite3_close(db); exit(1); } - sqlite3_finalize(res); - sqlite3_close(db); + sqlite3_finalize(res); + sqlite3_close(db); s_putstring(socket, "\r\n\e[1;32mAdded!\e[0m\r\n"); } else { s_putstring(socket, "\r\n\e[1;31mAborted!\e[0m\r\n"); @@ -111,13 +111,13 @@ void delete_bbs(int socket, struct user_record *user) { char *dsql = "DELETE FROM bbslist WHERE id=?"; int i; char c; - + s_putstring(socket, "\r\nPlease enter the id of the BBS you want to delete: "); s_readstring(socket, buffer, 5); i = atoi(buffer); - + sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { return; @@ -165,12 +165,12 @@ void list_bbses(int socket) { int rc; char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist"; int i; - + sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } @@ -190,29 +190,29 @@ void list_bbses(int socket) { if (i == 20) { sprintf(buffer, "Press any key to continue...\r\n"); s_putstring(socket, buffer); - s_getc(socket); + s_getc(socket); i = 0; - } + } } - + s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); sqlite3_finalize(res); sqlite3_close(db); - + sprintf(buffer, "Press any key to continue...\r\n"); s_putstring(socket, buffer); - s_getc(socket); + s_getc(socket); } void bbs_list(int socket, struct user_record *user) { int doquit = 0; char c; - + while(!doquit) { s_putstring(socket, "\r\n\e[1;32mBBS Listings: \e[1;37m(\e[1;33mL\e[1;37m) \e[1;32mList, \e[1;37m(\e[1;33mA\e[1;37m) \e[1;32mAdd \e[1;37m(\e[1;33mD\e[1;37m) \e[1;32mDelete \e[1;37m(\e[1;33mQ\e[1;37m) \e[1;32mQuit\e[0m\r\n"); - + c = s_getc(socket); - + switch(tolower(c)) { case 'l': list_bbses(socket); diff --git a/doors.c b/doors.c index f7c3d05..358c102 100644 --- a/doors.c +++ b/doors.c @@ -42,22 +42,22 @@ int write_door32sys(int socket, struct user_record *user) { FILE *fptr; char *ptr; int i; - + sprintf(buffer, "%s/node%d", conf.bbs_path, mynode); - + if (stat(buffer, &s) != 0) { mkdir(buffer, 0755); } - + sprintf(buffer, "%s/node%d/door32.sys", conf.bbs_path, mynode); - + fptr = fopen(buffer, "w"); - + if (!fptr) { - printf("Unable to open %s for writing!\n", buffer); + dolog("Unable to open %s for writing!", buffer); return 1; } - + fprintf(fptr, "2\n"); // telnet type fprintf(fptr, "%d\n", socket); // socket fprintf(fptr, "38400\n"); // baudrate @@ -69,30 +69,30 @@ int write_door32sys(int socket, struct user_record *user) { fprintf(fptr, "%d\n", user->timeleft); fprintf(fptr, "1\n"); // ansi emulation = 1 fprintf(fptr, "%d\n", mynode); - + fclose(fptr); - + // create dorinfo1.def - + sprintf(buffer, "%s/node%d", conf.bbs_path, mynode); - + if (stat(buffer, &s) != 0) { mkdir(buffer, 0755); } - + sprintf(buffer, "%s/node%d/dorinfo1.def", conf.bbs_path, mynode); - + fptr = fopen(buffer, "w"); - + if (!fptr) { - printf("Unable to open %s for writing!\n", buffer); + dolog("Unable to open %s for writing!", buffer); return 1; } - + strcpy(buffer, conf.sysop_name); - + ptr = NULL; - + for (i=0;itimeleft); fprintf(fptr, "-1\n"); - + fclose(fptr); - - + + return 0; } @@ -140,27 +140,27 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { int t; struct winsize ws; struct sigaction sa; - + timeoutpaused = 1; - + if (write_door32sys(socket, user) != 0) { return; } - + if (stdio) { - + arguments[0] = strdup(cmd); sprintf(buffer, "%d", mynode); arguments[1] = strdup(buffer); sprintf(buffer, "%d", socket); arguments[2] = strdup(buffer); arguments[3] = NULL; - + ws.ws_row = 24; ws.ws_col = 80; - + running_door = 1; - + if (openpty(&master, &slave, NULL, NULL, &ws) == 0) { sa.sa_handler = doorchld_handler; sigemptyset(&sa.sa_mask); @@ -169,26 +169,26 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { perror("sigaction"); exit(1); } - + pid = fork(); if (pid < 0) { return; } else if (pid == 0) { - + close(master); dup2(slave, 0); dup2(slave, 1); - + close(slave); - + setsid(); - + ioctl(0, TIOCSCTTY, 1); - + execvp(cmd, arguments); } else { running_door_pid = pid; - + while(running_door != 0) { FD_ZERO(&fdset); FD_SET(master, &fdset); @@ -245,7 +245,7 @@ int door_menu(int socket, struct user_record *user) { char *lRet; lua_State *L; int result; - + if (conf.script_path != NULL) { sprintf(buffer, "%s/doors.lua", conf.script_path); if (stat(buffer, &s) == 0) { @@ -256,7 +256,7 @@ int door_menu(int socket, struct user_record *user) { do_internal_menu = 0; result = lua_pcall(L, 0, 1, 0); if (result) { - fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1)); + dolog("Failed to run script: %s", lua_tostring(L, -1)); do_internal_menu = 1; } } else { @@ -269,16 +269,16 @@ int door_menu(int socket, struct user_record *user) { while (!dodoors) { if (do_internal_menu == 1) { s_displayansi(socket, "doors"); - + sprintf(prompt, "\e[0m\r\nTL: %dm :> ", user->timeleft); s_putstring(socket, prompt); - + c = s_getc(socket); } else { lua_getglobal(L, "menu"); result = lua_pcall(L, 0, 1, 0); if (result) { - fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1)); + dolog("Failed to run script: %s", lua_tostring(L, -1)); do_internal_menu = 1; lua_close(L); continue; @@ -292,7 +292,7 @@ int door_menu(int socket, struct user_record *user) { dodoors = 1; break; case 'g': - { + { s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); c = s_getc(socket); if (tolower(c) == 'y') { diff --git a/email.c b/email.c index 26bf37f..4df5b8b 100644 --- a/email.c +++ b/email.c @@ -26,10 +26,10 @@ void send_email(int socket, struct user_record *user) { "seen INTEGER);"; char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; char *err_msg = 0; - + s_putstring(socket, "\r\nTO: "); s_readstring(socket, buffer, 16); - + if (strlen(buffer) == 0) { s_putstring(socket, "\r\nAborted\r\n"); return; @@ -38,7 +38,7 @@ void send_email(int socket, struct user_record *user) { s_putstring(socket, "\r\n\r\nInvalid Username\r\n"); return; } - + recipient = strdup(buffer); s_putstring(socket, "\r\nSUBJECT: "); s_readstring(socket, buffer, 25); @@ -48,54 +48,54 @@ void send_email(int socket, struct user_record *user) { return; } subject = strdup(buffer); - + // post a message msg = external_editor(socket, user, user->loginname, recipient, NULL, NULL, subject, 1); - + if (msg != NULL) { sprintf(buffer, "%s/email.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); - } - - + } + + rc = sqlite3_exec(db, csql, 0, 0, &err_msg); if (rc != SQLITE_OK ) { - - fprintf(stderr, "SQL error: %s\n", err_msg); - - sqlite3_free(err_msg); + + dolog("SQL error: %s", err_msg); + + sqlite3_free(err_msg); sqlite3_close(db); - + return; - } - + } + rc = sqlite3_prepare_v2(db, isql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->loginname, -1, 0); sqlite3_bind_text(res, 2, recipient, -1, 0); sqlite3_bind_text(res, 3, subject, -1, 0); sqlite3_bind_text(res, 4, msg, -1, 0); sqlite3_bind_int(res, 5, time(NULL)); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); - s_putstring(socket, "\r\nNo such email\r\n"); + sqlite3_close(db); + s_putstring(socket, "\r\nNo such email\r\n"); return; } sqlite3_step(res); - + sqlite3_finalize(res); sqlite3_close(db); free(msg); - } + } free(subject); free(recipient); } @@ -120,26 +120,26 @@ void show_email(int socket, struct user_record *user, int msgno) { char c; char *replybody; int chars; - + sprintf(buffer, "%s/email.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->loginname, -1, 0); sqlite3_bind_int(res, 2, msgno); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); - s_putstring(socket, "\r\nNo such email\r\n"); + sqlite3_close(db); + s_putstring(socket, "\r\nNo such email\r\n"); return; } if (sqlite3_step(res) == SQLITE_ROW) { @@ -148,8 +148,8 @@ void show_email(int socket, struct user_record *user, int msgno) { subject = strdup((char *)sqlite3_column_text(res, 2)); body = strdup((char *)sqlite3_column_text(res, 3)); date = (time_t)sqlite3_column_int(res, 4); - - + + sprintf(buffer, "\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", sender); s_putstring(socket, buffer); sprintf(buffer, "\e[1;32mSubject : \e[1;37m%s\r\n", subject); @@ -160,10 +160,10 @@ void show_email(int socket, struct user_record *user, int msgno) { strcat(buffer, "\r\n"); s_putstring(socket, buffer); s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); - + lines = 0; chars = 0; - + for (z=0;zloginname, sender, body, sender, subject, 1); + replybody = external_editor(socket, user, user->loginname, sender, body, sender, subject, 1); if (replybody != NULL) { rc = sqlite3_prepare_v2(db, isql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->loginname, -1, 0); sqlite3_bind_text(res, 2, sender, -1, 0); sqlite3_bind_text(res, 3, subject, -1, 0); sqlite3_bind_text(res, 4, replybody, -1, 0); sqlite3_bind_int(res, 5, time(NULL)); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); - s_putstring(socket, "\r\nNo such email\r\n"); + sqlite3_close(db); + s_putstring(socket, "\r\nNo such email\r\n"); return; } sqlite3_step(res); - + sqlite3_finalize(res); free(replybody); } free(sender); free(subject); free(body); - sqlite3_close(db); + sqlite3_close(db); } else if (tolower(c) == 'd') { free(sender); free(subject); free(body); - + rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_int(res, 1, id); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); - s_putstring(socket, "\r\nNo such email\r\n"); + sqlite3_close(db); + s_putstring(socket, "\r\nNo such email\r\n"); return; } sqlite3_step(res); - + sqlite3_finalize(res); - sqlite3_close(db); + sqlite3_close(db); } - + } else { - printf("Failed\n"); + dolog("Failed"); sqlite3_finalize(res); sqlite3_close(db); } @@ -280,31 +280,31 @@ void list_emails(int socket, struct user_record *user) { int msgid; int msgtoread; struct tm msg_date; - + sprintf(buffer, "%s/email.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->loginname, -1, 0); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); - s_putstring(socket, "\r\nYou have no email\r\n"); + sqlite3_close(db); + s_putstring(socket, "\r\nYou have no email\r\n"); return; } - + msgid = 0; - - while (sqlite3_step(res) == SQLITE_ROW) { + + while (sqlite3_step(res) == SQLITE_ROW) { from = strdup((char *)sqlite3_column_text(res, 0)); subject = strdup((char *)sqlite3_column_text(res, 1)); seen = sqlite3_column_int(res, 2); @@ -316,10 +316,10 @@ void list_emails(int socket, struct user_record *user) { sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } s_putstring(socket, buffer); - + free(from); free(subject); - + if (msgid % 22 == 0 && msgid != 0) { s_putstring(socket, "Enter # to read, Q to quit or Enter to continue\r\n"); @@ -337,9 +337,9 @@ void list_emails(int socket, struct user_record *user) { return; } } - + } - + msgid++; } if (msgid == 0) { @@ -354,7 +354,7 @@ void list_emails(int socket, struct user_record *user) { show_email(socket, user, msgtoread); return; } - + } sqlite3_finalize(res); sqlite3_close(db); @@ -367,36 +367,36 @@ int mail_getemailcount(struct user_record *user) { char buffer[256]; sqlite3 *db; sqlite3_stmt *res; - int rc; - + int rc; + sprintf(buffer, "%s/email.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->loginname, -1, 0); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); + sqlite3_close(db); return 0; } - + count = 0; - if (sqlite3_step(res) == SQLITE_ROW) { + if (sqlite3_step(res) == SQLITE_ROW) { count = sqlite3_column_int(res, 0); } - + sqlite3_finalize(res); - sqlite3_close(db); - + sqlite3_close(db); + return count; } diff --git a/files.c b/files.c index e71e16a..54e65fb 100644 --- a/files.c +++ b/files.c @@ -28,7 +28,7 @@ int tagged_count = 0; int ZXmitStr(u_char *str, int len, ZModem *info) { int i; - + for (i=0;iofd, &str[i], 1) == 0) { @@ -39,7 +39,7 @@ int ZXmitStr(u_char *str, int len, ZModem *info) { return ZmErrSys; } } - + return 0; } @@ -57,7 +57,7 @@ int ZAttn(ZModem *info) { for(ptr = info->attn; *ptr != '\0'; ++ptr) { if( *ptr == ATTNBRK ) { - + } else if( *ptr == ATTNPSE ) { sleep(1); } else { @@ -78,18 +78,17 @@ char *upload_path; char upload_filename[1024]; FILE *ZOpenFile(char *name, u_long crc, ZModem *info) { - + FILE *fptr; struct stat s; - + snprintf(upload_filename, 1023, "%s/%s", upload_path, basename(name)); - fprintf(stderr, "%s\n", upload_filename); if (stat(upload_filename, &s) == 0) { return NULL; } - + fptr = fopen(upload_filename, "wb"); - + return fptr; } @@ -115,14 +114,14 @@ int doIO(ZModem *zm) { int done = 0; int i; int j; - + while(!done) { FD_ZERO(&readfds); FD_SET(zm->ifd, &readfds) ; timeout.tv_sec = zm->timeout ; timeout.tv_usec = 0 ; i = select(zm->ifd+1, &readfds,NULL,NULL, &timeout) ; - + if( i==0 ) { done = ZmodemTimeout(zm) ; } else if (i > 0) { @@ -130,7 +129,7 @@ int doIO(ZModem *zm) { if (len == 0) { disconnect(zm->ifd, "Socket closed"); } - + pos = 0; for (j=0;jcur_file_dir]->file_subs[user->cur_file_sub]->upload_path; - + zm.attn = NULL; zm.windowsize = 0; zm.bufsize = 0; - + zm.ifd = socket; zm.ofd = socket; - + zm.zrinitflags = 0; zm.zsinitflags = 0; - + zm.packetsize = 1024; - + done = ZmodemRInit(&zm); doIO(&zm); @@ -202,9 +201,9 @@ void upload(int socket, struct user_record *user) { int rc; struct stat s; char *err_msg = NULL; - + upload_zmodem(socket, user); - + s_putstring(socket, "\r\nPlease enter a description:\r\n"); buffer[0] = '\0'; for (i=0;i<5;i++) { @@ -217,45 +216,45 @@ void upload(int socket, struct user_record *user) { strcat(buffer, buffer2); strcat(buffer, "\n"); } - + sprintf(buffer3, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database); - + rc = sqlite3_open(buffer3, &db); - + if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } - + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { - fprintf(stderr, "SQL error: %s\n", err_msg); - sqlite3_free(err_msg); + if (rc != SQLITE_OK ) { + dolog("SQL error: %s", err_msg); + sqlite3_free(err_msg); sqlite3_close(db); return; - } + } rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { stat(upload_filename, &s); - + sqlite3_bind_text(res, 1, upload_filename, -1, 0); sqlite3_bind_text(res, 2, buffer, -1, 0); - sqlite3_bind_int(res, 3, s.st_size); + sqlite3_bind_int(res, 3, s.st_size); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); - return; + sqlite3_close(db); + return; } - + rc = sqlite3_step(res); - + if (rc != SQLITE_DONE) { - printf("execution failed: %s", sqlite3_errmsg(db)); + dolog("execution failed: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); + sqlite3_close(db); return; } sqlite3_finalize(res); @@ -271,43 +270,43 @@ void download_zmodem(int socket, struct user_record *user, char *filename) { int j; int len; int pos; - + u_char buffer[2048]; u_char buffer2[1024]; - - printf("Attempting to upload %s\n", filename); - + + dolog("Attempting to upload %s", filename); + zm.attn = NULL; zm.windowsize = 0; zm.bufsize = 0; - + zm.ifd = socket; zm.ofd = socket; - + zm.zrinitflags = 0; zm.zsinitflags = 0; - + zm.packetsize = 1024; - - + + ZmodemTInit(&zm) ; done = doIO(&zm); if ( done != ZmDone ) { return; } - + done = ZmodemTFile(filename, basename(filename), ZCBIN,0,0,0,0,0, &zm) ; - + switch( done ) { - case 0: + case 0: break ; case ZmErrCantOpen: - fprintf(stderr, "cannot open file \"%s\": %s\n", filename, strerror(errno)) ; + dolog("cannot open file \"%s\": %s\n", filename, strerror(errno)) ; return; case ZmFileTooLong: - fprintf(stderr, "filename \"%s\" too long, skipping...\n", filename) ; + dolog("filename \"%s\" too long, skipping...\n", filename) ; return; case ZmDone: @@ -316,17 +315,17 @@ void download_zmodem(int socket, struct user_record *user, char *filename) { default: return; } - + if (!done) { done = doIO(&zm); } - + if ( done != ZmDone ) { return; - } - + } + done = ZmodemTFinish(&zm); - + if (!done) { done = doIO(&zm); } @@ -342,55 +341,55 @@ void download(int socket, struct user_record *user) { sqlite3 *db; sqlite3_stmt *res; int rc; - + for (i=0;icur_file_dir]->file_subs[user->cur_file_sub]->database); - + rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } rc = sqlite3_prepare_v2(db, ssql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, tagged_files[i], -1, 0); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } - - rc = sqlite3_step(res); - + + rc = sqlite3_step(res); + if (rc != SQLITE_ROW) { - fprintf(stderr, "Downloaded a file not in database!!!!!"); + dolog("Downloaded a file not in database!!!!!"); sqlite3_finalize(res); sqlite3_close(db); exit(1); } - + dloads = sqlite3_column_int(res, 0); dloads++; sqlite3_finalize(res); - + rc = sqlite3_prepare_v2(db, usql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_int(res, 1, dloads); sqlite3_bind_text(res, 2, tagged_files[i], -1, 0); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } - - rc = sqlite3_step(res); - + + rc = sqlite3_step(res); + sqlite3_finalize(res); sqlite3_close(db); } - + for (i=0;icur_file_dir]->file_subs[user->cur_file_sub]->database); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - - if (rc != SQLITE_OK) { + + if (rc != SQLITE_OK) { sqlite3_finalize(res); sqlite3_close(db); - s_putstring(socket, "\r\nNo files in this area!\r\n"); - return; + s_putstring(socket, "\r\nNo files in this area!\r\n"); + return; } - - + + files_c = 0; while (sqlite3_step(res) == SQLITE_ROW) { @@ -449,15 +448,15 @@ void list_files(int socket, struct user_record *user) { files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 1)); files_e[files_c]->size = sqlite3_column_int(res, 2); files_e[files_c]->dlcount = sqlite3_column_int(res, 3); - + files_c++; } sqlite3_finalize(res); - sqlite3_close(db); - + sqlite3_close(db); + if (files_c == 0) { - s_putstring(socket, "\r\nNo files in this area!\r\n"); - return; + s_putstring(socket, "\r\nNo files in this area!\r\n"); + return; } s_putstring(socket, "\r\n"); for (i=0;idescription[j]); } - } + } } while (1) { s_putstring(socket, "\r\n\e[0mEnter # to tag, Enter to quit: "); @@ -576,7 +575,7 @@ void list_files(int socket, struct user_record *user) { s_putstring(socket, "\r\nSorry, you don't have permission to download from this area\r\n"); } } - } + } } } @@ -592,7 +591,7 @@ int file_menu(int socket, struct user_record *user) { char *lRet; lua_State *L; int result; - + if (conf.script_path != NULL) { sprintf(prompt, "%s/filemenu.lua", conf.script_path); if (stat(prompt, &s) == 0) { @@ -603,7 +602,7 @@ int file_menu(int socket, struct user_record *user) { do_internal_menu = 0; result = lua_pcall(L, 0, 1, 0); if (result) { - fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1)); + dolog("Failed to run script: %s", lua_tostring(L, -1)); do_internal_menu = 1; } } else { @@ -612,27 +611,27 @@ int file_menu(int socket, struct user_record *user) { } else { do_internal_menu = 1; } - + while (!dofiles) { if (do_internal_menu == 1) { s_displayansi(socket, "filemenu"); - + sprintf(prompt, "\e[0m\r\nDir: (%d) %s\r\nSub: (%d) %s\r\nTL: %dm :> ", user->cur_file_dir, conf.file_directories[user->cur_file_dir]->name, user->cur_file_sub, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->name, user->timeleft); s_putstring(socket, prompt); - + c = s_getc(socket); } else { lua_getglobal(L, "menu"); result = lua_pcall(L, 0, 1, 0); if (result) { - fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1)); + dolog("Failed to run script: %s", lua_tostring(L, -1)); do_internal_menu = 1; lua_close(L); continue; } lRet = (char *)lua_tostring(L, -1); lua_pop(L, 1); - c = lRet[0]; + c = lRet[0]; } switch(tolower(c)) { case 'i': @@ -686,7 +685,7 @@ int file_menu(int socket, struct user_record *user) { } } } - break; + break; case 'l': list_files(socket, user); break; @@ -704,7 +703,7 @@ int file_menu(int socket, struct user_record *user) { break; case 'c': { - // Clear tagged files + // Clear tagged files if (tagged_count > 0) { for (i=0;imail_areas[msgarea]->path); if (!jb) { - printf("Error opening JAM base.. %s\n", conf.mail_conferences[msgconf]->mail_areas[msgarea]->path); + dolog("Error opening JAM base.. %s", conf.mail_conferences[msgconf]->mail_areas[msgarea]->path); return NULL; } @@ -119,7 +119,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r memset(&jmh, 0, sizeof(s_JamMsgHeader)); z = JAM_ReadMsgHeader(jb, i, &jmh, &jsp); if (z != 0) { - printf("Failed to read msg header: %d Erro %d\n", z, JAM_Errno(jb)); + dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); continue; } @@ -730,7 +730,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { - printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); return; } @@ -961,7 +961,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { - printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); free(replybody); free(body); free(subject); @@ -1135,12 +1135,12 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh free(subject); free(to); free(from); - printf("Failed to lock msg base!\n"); + dolog("Failed to lock msg base!"); return; } } if (JAM_AddMessage(jb, &jmh, jsp, (char *)replybody, strlen(replybody))) { - printf("Failed to add message\n"); + dolog("Failed to add message"); } else { if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { if (conf.netmail_sem != NULL) { @@ -1252,7 +1252,7 @@ int mail_menu(int socket, struct user_record *user) { do_internal_menu = 0; result = lua_pcall(L, 0, 1, 0); if (result) { - fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1)); + dolog("Failed to run script: %s", lua_tostring(L, -1)); do_internal_menu = 1; } } else { @@ -1275,7 +1275,7 @@ int mail_menu(int socket, struct user_record *user) { lua_getglobal(L, "menu"); result = lua_pcall(L, 0, 1, 0); if (result) { - fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1)); + dolog("Failed to run script: %s", lua_tostring(L, -1)); do_internal_menu = 1; lua_close(L); continue; @@ -1293,7 +1293,7 @@ int mail_menu(int socket, struct user_record *user) { if (msghs != NULL && msghs->msg_count > 0) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { - printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); break; } else { all_unread = 0; @@ -1402,7 +1402,7 @@ int mail_menu(int socket, struct user_record *user) { if (msg != NULL) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { - printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); free(msg); free(to); free(subject); @@ -1557,7 +1557,7 @@ int mail_menu(int socket, struct user_record *user) { free(msg); free(to); free(subject); - printf("Failed to lock msg base!\n"); + dolog("Failed to lock msg base!"); break; } } @@ -1567,7 +1567,7 @@ int mail_menu(int socket, struct user_record *user) { } if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) { - printf("Failed to add message\n"); + dolog("Failed to add message"); } else { if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { if (conf.netmail_sem != NULL) { @@ -1600,7 +1600,7 @@ int mail_menu(int socket, struct user_record *user) { if (msghs != NULL && msghs->msg_count > 0) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { - printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); break; } else { all_unread = 0; @@ -1854,7 +1854,7 @@ void mail_scan(int socket, struct user_record *user) { } jb = open_jam_base(conf.mail_conferences[i]->mail_areas[j]->path); if (!jb) { - printf("Unable to open message base\n"); + dolog("Unable to open message base"); continue; } if (JAM_ReadMBHeader(jb, &jbh) != 0) { diff --git a/main.c b/main.c index 5ef88d0..265e494 100644 --- a/main.c +++ b/main.c @@ -341,7 +341,7 @@ void server(int port) { socket_desc = socket(AF_INET, SOCK_STREAM, 0); if (socket_desc == -1) { - printf("Couldn't create socket..\n"); + fprintf(stderr, "Couldn't create socket..\n"); exit(1); } @@ -393,7 +393,7 @@ int main(int argc, char **argv) { FILE *fptr; if (argc < 3) { - printf("Usage ./magicka config/bbs.ini port\n"); + fprintf(stderr, "Usage ./magicka config/bbs.ini port\n"); exit(1); } @@ -412,26 +412,26 @@ int main(int argc, char **argv) { // Load BBS data if (ini_parse(argv[1], handler, &conf) <0) { - printf("Unable to load configuration ini (%s)!\n", argv[1]); + fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]); exit(-1); } // Load mail Areas for (i=0;ipath, mail_area_handler, conf.mail_conferences[i]) <0) { - printf("Unable to load configuration ini (%s)!\n", conf.mail_conferences[i]->path); + fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.mail_conferences[i]->path); exit(-1); } } // Load file Subs for (i=0;ipath, file_sub_handler, conf.file_directories[i]) <0) { - printf("Unable to load configuration ini (%s)!\n", conf.file_directories[i]->path); + fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.file_directories[i]->path); exit(-1); } } if (ini_parse("config/doors.ini", door_config_handler, &conf) <0) { - printf("Unable to load configuration ini (doors.ini)!\n"); + fprintf(stderr, "Unable to load configuration ini (doors.ini)!\n"); exit(-1); } diff --git a/main_menu.c b/main_menu.c index 852cc3f..a0484ca 100644 --- a/main_menu.c +++ b/main_menu.c @@ -8,7 +8,7 @@ #include "lua/lualib.h" #include "lua/lauxlib.h" -extern struct bbs_config conf; +extern struct bbs_config conf; void main_menu(int socket, struct user_record *user) { int doquit = 0; @@ -21,7 +21,7 @@ void main_menu(int socket, struct user_record *user) { char *lRet; lua_State *L; int result; - + if (conf.script_path != NULL) { sprintf(buffer, "%s/mainmenu.lua", conf.script_path); if (stat(buffer, &s) == 0) { @@ -32,7 +32,7 @@ void main_menu(int socket, struct user_record *user) { do_internal_menu = 0; result = lua_pcall(L, 0, 1, 0); if (result) { - fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1)); + dolog("Failed to run script: %s", lua_tostring(L, -1)); do_internal_menu = 1; } } else { @@ -41,22 +41,22 @@ void main_menu(int socket, struct user_record *user) { } else { do_internal_menu = 1; } - + while (!doquit) { - + if (do_internal_menu == 1) { s_displayansi(socket, "mainmenu"); - - + + sprintf(prompt, "\r\n\e[0mTL: %dm :> ", user->timeleft); s_putstring(socket, prompt); - + c = s_getc(socket); } else { lua_getglobal(L, "menu"); result = lua_pcall(L, 0, 1, 0); if (result) { - fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1)); + dolog("Failed to run script: %s", lua_tostring(L, -1)); do_internal_menu = 1; lua_close(L); continue; @@ -65,7 +65,7 @@ void main_menu(int socket, struct user_record *user) { lua_pop(L, 1); c = lRet[0]; } - + switch(tolower(c)) { case 'o': { @@ -75,11 +75,11 @@ void main_menu(int socket, struct user_record *user) { case 'a': { if (conf.text_file_count > 0) { - + while(1) { s_putstring(socket, "\r\n\e[1;32mText Files Collection\r\n"); s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); - + for (i=0;iname); s_putstring(socket, buffer); @@ -126,7 +126,7 @@ void main_menu(int socket, struct user_record *user) { { i = 0; sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); - + while (stat(buffer, &s) == 0) { sprintf(buffer, "bulletin%d", i); s_displayansi(socket, buffer); @@ -135,7 +135,7 @@ void main_menu(int socket, struct user_record *user) { s_getc(socket); i++; sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); - } + } } break; case '1': diff --git a/users.c b/users.c index 5b144a5..3e5c903 100644 --- a/users.c +++ b/users.c @@ -12,12 +12,12 @@ static int secLevel(void* user, const char* section, const char* name, const char* value) { struct sec_level_t *conf = (struct sec_level_t *)user; - + if (strcasecmp(section, "main") == 0) { if (strcasecmp(name, "time per day") == 0) { conf->timeperday = atoi(value); - } - } + } + } return 1; } @@ -26,25 +26,25 @@ int save_user(struct user_record *user) { sqlite3 *db; sqlite3_stmt *res; int rc; - + char *update_sql = "UPDATE users SET password=?, firstname=?," "lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=? where loginname LIKE ?"; char *err_msg = 0; - + sprintf(buffer, "%s/users.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } rc = sqlite3_prepare_v2(db, update_sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->password, -1, 0); sqlite3_bind_text(res, 2, user->firstname, -1, 0); sqlite3_bind_text(res, 3, user->lastname, -1, 0); @@ -60,16 +60,16 @@ int save_user(struct user_record *user) { sqlite3_bind_int(res, 13, user->timeson); sqlite3_bind_text(res, 14, user->loginname, -1, 0); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } - - + + rc = sqlite3_step(res); - + if (rc != SQLITE_DONE) { - - printf("execution failed: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + + dolog("execution failed: %s", sqlite3_errmsg(db)); + sqlite3_close(db); exit(1); } sqlite3_close(db); @@ -98,36 +98,36 @@ int inst_user(struct user_record *user) { "cur_file_sub INTEGER," "cur_file_dir INTEGER," "times_on INTEGER);"; - + char *insert_sql = "INSERT INTO users (loginname, password, firstname," "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on) VALUES(?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; char *err_msg = 0; - + sprintf(buffer, "%s/users.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } - + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); if (rc != SQLITE_OK ) { - - fprintf(stderr, "SQL error: %s\n", err_msg); - - sqlite3_free(err_msg); + + dolog("SQL error: %s", err_msg); + + sqlite3_free(err_msg); sqlite3_close(db); - + return 1; - } - + } + rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->loginname, -1, 0); sqlite3_bind_text(res, 2, user->password, -1, 0); sqlite3_bind_text(res, 3, user->firstname, -1, 0); @@ -142,24 +142,24 @@ int inst_user(struct user_record *user) { sqlite3_bind_int(res, 12, user->cur_file_dir); sqlite3_bind_int(res, 13, user->cur_file_sub); sqlite3_bind_int(res, 14, user->timeson); - + } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } - - + + rc = sqlite3_step(res); - + if (rc != SQLITE_DONE) { - - printf("execution failed: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + + dolog("execution failed: %s", sqlite3_errmsg(db)); + sqlite3_close(db); exit(1); } - + user->id = sqlite3_last_insert_rowid(db); - - sqlite3_finalize(res); + + sqlite3_finalize(res); sqlite3_close(db); return 1; } @@ -171,30 +171,30 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password) sqlite3_stmt *res; int rc; char *sql = "SELECT * FROM users WHERE loginname LIKE ?"; - + sprintf(buffer, "%s/users.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, loginname, -1, 0); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); - sqlite3_close(db); - return NULL; + sqlite3_close(db); + return NULL; } - + int step = sqlite3_step(res); - - if (step == SQLITE_ROW) { + + if (step == SQLITE_ROW) { user = (struct user_record *)malloc(sizeof(struct user_record)); user->id = sqlite3_column_int(res, 0); user->loginname = strdup((char *)sqlite3_column_text(res, 1)); @@ -211,7 +211,7 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password) user->cur_file_dir = sqlite3_column_int(res, 13); user->cur_file_sub = sqlite3_column_int(res, 12); user->timeson = sqlite3_column_int(res, 14); - + if (strcmp(password, user->password) != 0) { free(user->loginname); free(user->firstname); @@ -220,33 +220,33 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password) free(user->location); free(user); sqlite3_finalize(res); - sqlite3_close(db); + sqlite3_close(db); return NULL; } } else { sqlite3_finalize(res); - sqlite3_close(db); - return NULL; - } - + sqlite3_close(db); + return NULL; + } + sqlite3_finalize(res); sqlite3_close(db); - + user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t)); - + sprintf(buffer, "%s/config/s%d.ini", conf.bbs_path, user->sec_level); if (ini_parse(buffer, secLevel, user->sec_info) <0) { - printf("Unable to load sec Level ini (%s)!\n", buffer); + dolog("Unable to load sec Level ini (%s)!", buffer); exit(-1); - } - + } + if (user->cur_mail_conf > conf.mail_conference_count) { user->cur_mail_conf = 0; } if (user->cur_file_dir > conf.file_directory_count) { user->cur_file_dir = 0; } - + if (user->cur_mail_area > conf.mail_conferences[user->cur_mail_conf]->mail_area_count) { user->cur_mail_area = 0; } @@ -255,8 +255,8 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password) user->cur_file_sub = 0; } - - return user; + + return user; } void list_users(int socket, struct user_record *user) { @@ -265,21 +265,21 @@ void list_users(int socket, struct user_record *user) { sqlite3_stmt *res; int rc; int i; - + char *sql = "SELECT loginname,location,times_on FROM users"; - + sprintf(buffer, "%s/users.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot prepare statement: %s\n", sqlite3_errmsg(db)); + dolog("Cannot prepare statement: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } @@ -290,22 +290,22 @@ void list_users(int socket, struct user_record *user) { while (sqlite3_step(res) == SQLITE_ROW) { sprintf(buffer, "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%5d\r\n", sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2)); s_putstring(socket, buffer); - + i++; if (i == 20) { sprintf(buffer, "Press any key to continue...\r\n"); s_putstring(socket, buffer); - s_getc(socket); + s_getc(socket); i = 0; } } s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); sqlite3_finalize(res); sqlite3_close(db); - + sprintf(buffer, "Press any key to continue...\r\n"); s_putstring(socket, buffer); - s_getc(socket); + s_getc(socket); } int check_user(char *loginname) { @@ -314,33 +314,33 @@ int check_user(char *loginname) { sqlite3_stmt *res; int rc; char *sql = "SELECT * FROM users WHERE loginname = ?"; - + sprintf(buffer, "%s/users.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); - + exit(1); } rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - - if (rc == SQLITE_OK) { + + if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, loginname, -1, 0); } else { - fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db)); + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } - + int step = sqlite3_step(res); - + if (step == SQLITE_ROW) { sqlite3_finalize(res); sqlite3_close(db); return 0; - } - + } + sqlite3_finalize(res); sqlite3_close(db); return 1; @@ -354,11 +354,11 @@ struct user_record *new_user(int socket) { int nameok = 0; int passok = 0; int i; - + user = (struct user_record *)malloc(sizeof(struct user_record)); s_putstring(socket, "\r\n\r\n"); s_displayansi(socket, "newuser"); - + do { passok = 0; nameok = 0; @@ -370,12 +370,12 @@ struct user_record *new_user(int socket) { s_putstring(socket, "Sorry, that name is too short.\r\n"); continue; } - + for (i=0;i= 97 && tolower(buffer[i]) <= 122)) { s_putstring(socket, "Sorry, invalid character, can only use alpha characters.\r\n"); nameok = 1; - break; + break; } } if (nameok == 1) { @@ -384,16 +384,16 @@ struct user_record *new_user(int socket) { } if (strcasecmp(buffer, "unknown") == 0) { s_putstring(socket, "Sorry, that name is reserved.\r\n"); - continue; + continue; } if (strcasecmp(buffer, "all") == 0) { s_putstring(socket, "Sorry, that name is reserved.\r\n"); - continue; + continue; } if (strcasecmp(buffer, "new") == 0) { s_putstring(socket, "Sorry, that name is reserved.\r\n"); - continue; - } + continue; + } user->loginname = strdup(buffer); nameok = check_user(user->loginname); if (!nameok) { @@ -407,7 +407,7 @@ struct user_record *new_user(int socket) { s_readstring(socket, buffer, 32); s_putstring(socket, "\r\n"); user->firstname = strdup(buffer); - + s_putstring(socket, "What is your last name: "); memset(buffer, 0, 256); s_readstring(socket, buffer, 32); @@ -424,7 +424,7 @@ struct user_record *new_user(int socket) { memset(buffer, 0, 256); s_readstring(socket, buffer, 32); s_putstring(socket, "\r\n"); - user->location = strdup(buffer); + user->location = strdup(buffer); do { s_putstring(socket, "What password would you like (at least 8 characters): "); @@ -438,7 +438,7 @@ struct user_record *new_user(int socket) { } } while (!passok); user->password = strdup(buffer); - + s_putstring(socket, "You Entered:\r\n"); s_putstring(socket, "-------------------------------------\r\n"); s_putstring(socket, "Login Name: "); @@ -459,7 +459,7 @@ struct user_record *new_user(int socket) { while (tolower(c) != 'y' && tolower(c) != 'n') { c = s_getchar(socket); } - + if (tolower(c) == 'y') { done = 1; } @@ -467,13 +467,13 @@ struct user_record *new_user(int socket) { user->sec_level = conf.newuserlvl; user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t)); - + sprintf(buffer, "%s/config/s%d.ini", conf.bbs_path, user->sec_level); - + if (ini_parse(buffer, secLevel, user->sec_info) <0) { - printf("Unable to load sec Level ini (%s)!\n", buffer); + dolog("Unable to load sec Level ini (%s)!", buffer); exit(-1); - } + } user->laston = time(NULL); user->timeleft = user->sec_info->timeperday; @@ -483,6 +483,6 @@ struct user_record *new_user(int socket) { user->cur_mail_conf = 0; user->timeson = 0; inst_user(user); - + return user; }