diff --git a/src/bbs.c b/src/bbs.c index de45216..e4d64d3 100644 --- a/src/bbs.c +++ b/src/bbs.c @@ -21,13 +21,11 @@ #include "lua/lualib.h" #include "lua/lauxlib.h" - int telnet_bin_mode = 0; int mynode = 0; struct bbs_config conf; - struct user_record *gUser; int gSocket; int sshBBS; @@ -39,8 +37,7 @@ struct mosquitto *mosq = NULL; char *ipaddress = NULL; -void sigterm_handler2(int s) -{ +void sigterm_handler2(int s) { if (mynode != 0) { disconnect("Terminated."); } @@ -48,12 +45,11 @@ void sigterm_handler2(int s) exit(0); } -void sigint_handler(int s) -{ +void sigint_handler(int s) { // do nothing... } void broadcast(char *mess, ...) { - char buffer[PATH_MAX]; + char buffer[PATH_MAX]; if (conf.broadcast_enable && conf.broadcast_port != 0 && conf.broadcast_address != NULL) { va_list ap; va_start(ap, mess); @@ -79,7 +75,7 @@ void dolog_www(char *ipaddr, char *fmt, ...) { snprintf(buffer, PATH_MAX, "%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) { + if (!logfptr) { return; } va_list ap; @@ -107,7 +103,7 @@ void dolog(char *fmt, ...) { snprintf(buffer, PATH_MAX, "%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) { + if (!logfptr) { return; } va_list ap; @@ -133,8 +129,8 @@ struct fido_addr *parse_fido_addr(const char *str) { ret->node = 0; ret->point = 0; - for (c=0;czone = ret->zone * 10 + (str[c] - '0'); - break; - case 1: - ret->net = ret->net * 10 + (str[c] - '0'); - break; - case 2: - ret->node = ret->node * 10 + (str[c] - '0'); - break; - case 3: - ret->point = ret->point * 10 + (str[c] - '0'); - break; - } + case '9': { + switch (state) { + case 0: + ret->zone = ret->zone * 10 + (str[c] - '0'); + break; + case 1: + ret->net = ret->net * 10 + (str[c] - '0'); + break; + case 2: + ret->node = ret->node * 10 + (str[c] - '0'); + break; + case 3: + ret->point = ret->point * 10 + (str[c] - '0'); + break; } - break; + } break; default: free(ret); return NULL; @@ -179,7 +173,6 @@ struct fido_addr *parse_fido_addr(const char *str) { return ret; } - void timer_handler(int signum) { if (signum == SIGALRM) { if (gUser != NULL) { @@ -189,8 +182,6 @@ void timer_handler(int signum) { s_printf(get_string(0)); disconnect("Out of Time"); } - - } if (timeoutpaused == 0) { usertimeout--; @@ -212,9 +203,9 @@ void s_printf(char *fmt, ...) { vsnprintf(buffer, 512, fmt, ap); va_end(ap); - if (fmt[0] == '@' && fmt[1] == '@' && fmt[strlen(fmt)-1] == '@' && fmt[strlen(fmt)-2] == '@') { + if (fmt[0] == '@' && fmt[1] == '@' && fmt[strlen(fmt) - 1] == '@' && fmt[strlen(fmt) - 2] == '@') { pos = 0; - for (i=2;icodepage; - } + } return conf.codepage; } @@ -246,11 +237,11 @@ void s_putchar(char c) { if (sshBBS) { putchar(c); } else { - ret = send(gSocket, &c, 1, 0); + ret = send(gSocket, &c, 1, 0); if (ret == -1) { if (errno == ECONNRESET) { disconnect("Disconnected"); - } + } } } } else { @@ -272,7 +263,7 @@ void s_putchar(char c) { if (errno == ECONNRESET) { disconnect("Disconnected"); } - } + } } iconv_close(ic); free(ptr1); @@ -281,7 +272,7 @@ void s_putchar(char c) { } void s_putstring(char *c) { - iconv_t ic; + iconv_t ic; char *inbuf; char *outbuf; size_t inc; @@ -298,7 +289,7 @@ void s_putstring(char *c) { if (ret == -1) { if (errno == ECONNRESET) { disconnect("Disconnected"); - } + } } } } else { @@ -308,7 +299,7 @@ void s_putstring(char *c) { outbuf = (char *)malloc(inc * 4); memset(outbuf, 0, inc * 4); ptr1 = outbuf; - ptr2 = inbuf; + ptr2 = inbuf; ouc = inc * 4; sz = iconv(ic, &inbuf, &inc, &outbuf, &ouc); if (sshBBS) { @@ -318,8 +309,8 @@ void s_putstring(char *c) { if (ret == -1) { if (errno == ECONNRESET) { disconnect("Disconnected"); - } - } + } + } } iconv_close(ic); free(ptr1); @@ -365,7 +356,7 @@ void s_displayansi_pause(char *file, int pause) { s_putchar(c); lastch = c; - + if (pause) { if (c == '\n') { lines++; @@ -373,7 +364,7 @@ void s_displayansi_pause(char *file, int pause) { s_printf(get_string(223)); ch = s_getchar(); s_printf("\r\n"); - switch(tolower(ch)) { + switch (tolower(ch)) { case 'c': pause = 0; break; @@ -396,7 +387,6 @@ void s_displayansi_p(char *file) { s_displayansi_pause(file, 0); } - void s_displayansi(char *file) { FILE *fptr; char c; @@ -411,7 +401,6 @@ void s_displayansi(char *file) { } } - char s_getchar() { unsigned char c; unsigned char d; @@ -463,9 +452,9 @@ char s_getchar() { if (errno == ECONNRESET) { disconnect("Disconnected"); } - } + } } - } + } break; case IAC_WONT: if (d == 0) { @@ -476,9 +465,9 @@ char s_getchar() { if (errno == ECONNRESET) { disconnect("Disconnected"); } - } + } } - } + } break; case IAC_DO: if (d == 0) { @@ -490,7 +479,6 @@ char s_getchar() { disconnect("Disconnected"); } } - } } break; @@ -503,10 +491,10 @@ char s_getchar() { if (errno == ECONNRESET) { disconnect("Disconnected"); } - } + } } - } - break; + } + break; } } else if (c == 250) { do { @@ -516,9 +504,9 @@ char s_getchar() { if (len <= 0) { disconnect("Socket Closed"); } - } while(c != 240); - } - + } while (c != 240); + } + do { len = read(gSocket, &c, 1); } while (len == -1 && errno == EINTR); @@ -543,7 +531,7 @@ char s_getc() { void s_readstring_inject(char *buffer, int max, char *inject) { int i; char c; - + memset(buffer, 0, max); if (strlen(inject) > max) { @@ -554,11 +542,11 @@ void s_readstring_inject(char *buffer, int max, char *inject) { s_printf("%s", inject); - for (i=strlen(buffer);i 0) { - buffer[i-1] = '\0'; + buffer[i - 1] = '\0'; i -= 2; s_printf("\e[D \e[D"); continue; @@ -579,8 +567,8 @@ void s_readstring_inject(char *buffer, int max, char *inject) { } s_putchar(c); buffer[i] = c; - buffer[i+1] = '\0'; - } + buffer[i + 1] = '\0'; + } } void s_readstring(char *buffer, int max) { @@ -589,11 +577,11 @@ void s_readstring(char *buffer, int max) { memset(buffer, 0, max); - for (i=0;i 0) { - buffer[i-1] = '\0'; + buffer[i - 1] = '\0'; i -= 2; s_printf("\e[D \e[D"); continue; @@ -614,7 +602,7 @@ void s_readstring(char *buffer, int max) { } s_putchar(c); buffer[i] = c; - buffer[i+1] = '\0'; + buffer[i + 1] = '\0'; } } @@ -622,12 +610,12 @@ void s_readpass(char *buffer, int max) { int i; char c; - for (i=0;i 0) { - buffer[i-1] = '\0'; - i-=2; + buffer[i - 1] = '\0'; + i -= 2; s_printf("\e[D \e[D"); continue; } else if (c == '\b' || c == 127) { @@ -647,7 +635,7 @@ void s_readpass(char *buffer, int max) { } s_putchar('*'); buffer[i] = c; - buffer[i+1] = '\0'; + buffer[i + 1] = '\0'; } } @@ -661,7 +649,7 @@ void exit_bbs() { mosquitto_loop_stop(mosq, 0); mosquitto_destroy(mosq); mosquitto_lib_cleanup(); - } + } } void disconnect(char *calledby) { @@ -676,7 +664,7 @@ void disconnect(char *calledby) { if (!sshBBS) { close(gSocket); - } + } exit(0); } @@ -684,11 +672,11 @@ void record_last10_callers(struct user_record *user) { struct last10_callers new_entry; struct last10_callers callers[10]; - int i,j; + int i, j; FILE *fptr = fopen("last10v2.dat", "rb"); if (fptr != NULL) { - for (i=0;i<10;i++) { + for (i = 0; i < 10; i++) { if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) { break; } @@ -698,7 +686,7 @@ void record_last10_callers(struct user_record *user) { i = 0; } - if (strcasecmp(conf.sysop_name, user->loginname) != 0 ) { + if (strcasecmp(conf.sysop_name, user->loginname) != 0) { memset(&new_entry, 0, sizeof(struct last10_callers)); strcpy(new_entry.name, user->loginname); strcpy(new_entry.location, user->location); @@ -710,7 +698,7 @@ void record_last10_callers(struct user_record *user) { j = 0; } fptr = fopen("last10v2.dat", "wb"); - for (;jloginname); s_getc(); - for (i=1;i<=conf.nodes;i++) { + for (i = 1; i <= conf.nodes; i++) { snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i); if (stat(buffer, &s) == 0) { nodefile = fopen(buffer, "r"); @@ -1068,7 +1054,7 @@ tryagain: } else { s_printf(get_string(25), conf.bbs_name); s_getc(); - gUser = new_user(); + gUser = new_user(); user = gUser; } } @@ -1094,14 +1080,11 @@ tryagain: if (stat(buffer, &s) == 0) { recursive_delete(buffer); } - #if defined(ENABLE_WWW) www_expire_old_links(); #endif - - // do post-login dolog("%s logged in, on node %d", user->loginname, mynode); broadcast("USER: %s; NODE:%d; STATUS: Logged in.", user->loginname, mynode); @@ -1120,7 +1103,6 @@ tryagain: user->timeson++; - if (conf.script_path != NULL) { snprintf(buffer, PATH_MAX, "%s/login_stanza.lua", conf.script_path); if (stat(buffer, &s) == 0) { @@ -1142,7 +1124,7 @@ tryagain: display_bulletins(); blog_display(); - + // display info display_info(); @@ -1166,9 +1148,9 @@ tryagain: // main menu menu_system(conf.root_menu); - + do_logout(); - + dolog("%s is logging out, on node %d", user->loginname, mynode); broadcast("USER: %s; NODE:%d; STATUS: Logging out.", user->loginname, mynode); disconnect("Log out"); @@ -1182,7 +1164,7 @@ void do_logout() { char c; int result; int do_internal_logout = 1; - + if (conf.script_path != NULL) { snprintf(buffer, PATH_MAX, "%s/logout_stanza.lua", conf.script_path); if (stat(buffer, &s) == 0) { @@ -1231,54 +1213,54 @@ void runbbs_ssh(char *ip) { } int recursive_delete(const char *dir) { - int ret = 0; - FTS *ftsp = NULL; - FTSENT *curr; + int ret = 0; + FTS *ftsp = NULL; + FTSENT *curr; - char *files[] = { (char *) dir, NULL }; + char *files[] = {(char *)dir, NULL}; - ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL); - if (!ftsp) { - dolog("%s: fts_open failed: %s", dir, strerror(errno)); - ret = -1; - goto finish; - } + ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL); + if (!ftsp) { + dolog("%s: fts_open failed: %s", dir, strerror(errno)); + ret = -1; + goto finish; + } - while ((curr = fts_read(ftsp))) { - switch (curr->fts_info) { - case FTS_NS: - case FTS_DNR: - case FTS_ERR: - dolog("%s: fts_read error: %s", curr->fts_accpath, strerror(curr->fts_errno)); - break; + while ((curr = fts_read(ftsp))) { + switch (curr->fts_info) { + case FTS_NS: + case FTS_DNR: + case FTS_ERR: + dolog("%s: fts_read error: %s", curr->fts_accpath, strerror(curr->fts_errno)); + break; - case FTS_DC: - case FTS_DOT: - case FTS_NSOK: - break; + case FTS_DC: + case FTS_DOT: + case FTS_NSOK: + break; - case FTS_D: - break; + case FTS_D: + break; - case FTS_DP: - case FTS_F: - case FTS_SL: - case FTS_SLNONE: - case FTS_DEFAULT: - if (remove(curr->fts_accpath) < 0) { - dolog("%s: Failed to remove: %s", curr->fts_path, strerror(errno)); - ret = -1; - } - break; - } - } + case FTS_DP: + case FTS_F: + case FTS_SL: + case FTS_SLNONE: + case FTS_DEFAULT: + if (remove(curr->fts_accpath) < 0) { + dolog("%s: Failed to remove: %s", curr->fts_path, strerror(errno)); + ret = -1; + } + break; + } + } finish: - if (ftsp) { - fts_close(ftsp); - } + if (ftsp) { + fts_close(ftsp); + } - return ret; + return ret; } int copy_file(char *src, char *dest) { @@ -1297,7 +1279,7 @@ int copy_file(char *src, char *dest) { return -1; } - while(1) { + while (1) { c = fgetc(src_file); if (!feof(src_file)) { fputc(c, dest_file); @@ -1339,14 +1321,15 @@ char *str_replace(const char *str, const char *from, const char *to) { pos_cache_tmp = realloc(pos_cache, sizeof(*pos_cache) * cache_sz); if (pos_cache_tmp == NULL) { goto end_repl_str; - } else pos_cache = pos_cache_tmp; + } else + pos_cache = pos_cache_tmp; cache_sz_inc *= cache_sz_inc_factor; if (cache_sz_inc > cache_sz_inc_max) { cache_sz_inc = cache_sz_inc_max; } } - pos_cache[count-1] = pstr2 - str; + pos_cache[count - 1] = pstr2 - str; pstr = pstr2 + fromlen; } @@ -1356,7 +1339,8 @@ char *str_replace(const char *str, const char *from, const char *to) { if (count > 0) { tolen = strlen(to); retlen = orglen + (tolen - fromlen) * count; - } else retlen = orglen; + } else + retlen = orglen; ret = malloc(retlen + 1); if (ret == NULL) { goto end_repl_str; @@ -1375,7 +1359,7 @@ char *str_replace(const char *str, const char *from, const char *to) { memcpy(pret, to, tolen); pret += tolen; pstr = str + pos_cache[i] + fromlen; - cpylen = (i == count-1 ? orglen : pos_cache[i+1]) - pos_cache[i] - fromlen; + cpylen = (i == count - 1 ? orglen : pos_cache[i + 1]) - pos_cache[i] - fromlen; memcpy(pret, pstr, cpylen); pret += cpylen; } diff --git a/src/bbs.h b/src/bbs.h index d3bcd17..79b1594 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -20,17 +20,17 @@ #define NETWORK_FIDO 1 #define NETWORK_WWIV 2 #define NETWORK_MAGI 3 -#define NETWORK_QWK 4 +#define NETWORK_QWK 4 -#define TYPE_LOCAL_AREA 0 -#define TYPE_NETMAIL_AREA 1 +#define TYPE_LOCAL_AREA 0 +#define TYPE_NETMAIL_AREA 1 #define TYPE_ECHOMAIL_AREA 2 #define TYPE_NEWSGROUP_AREA 3 -#define IAC 255 +#define IAC 255 #define IAC_WILL 251 #define IAC_WONT 252 -#define IAC_DO 253 +#define IAC_DO 253 #define IAC_DONT 254 #define IAC_TRANSMIT_BINARY 0 #define IAC_SUPPRESS_GO_AHEAD 3 @@ -48,7 +48,7 @@ struct last10_callers { char location[33]; time_t time; int calls; -}__attribute__((packed)); +} __attribute__((packed)); struct text_file { char *name; @@ -120,9 +120,9 @@ struct protocol { int upload_prompt; }; -#define IP_STATUS_UNKNOWN 0 -#define IP_STATUS_WHITELISTED 1 -#define IP_STATUS_BLACKLISTED 2 +#define IP_STATUS_UNKNOWN 0 +#define IP_STATUS_WHITELISTED 1 +#define IP_STATUS_BLACKLISTED 2 struct ip_address_guard { int status; @@ -162,14 +162,14 @@ struct bbs_config { int bwave_max_msgs; int date_style; struct fido_addr *main_aka; - + char *root_menu; char *menu_path; char *external_editor_cmd; int external_editor_stdio; char *external_editor_codepage; int fork; - + int nodes; int newuserlvl; int automsgwritelvl; @@ -179,11 +179,11 @@ struct bbs_config { char *broadcast_topic; char *broadcast_user; char *broadcast_pass; - + int ipguard_enable; int ipguard_timeout; int ipguard_tries; - + int mail_conference_count; struct mail_conference **mail_conferences; int door_count; @@ -192,11 +192,11 @@ struct bbs_config { struct file_directory **file_directories; int text_file_count; struct text_file **text_files; - + char *config_path; int archiver_count; struct archiver **archivers; - + int protocol_count; struct protocol **protocols; }; @@ -252,10 +252,10 @@ struct msg_headers { }; struct blog_entry_t { - char *subject; - char *author; - char *body; - time_t date; + char *subject; + char *author; + char *body; + time_t date; }; extern char *str_replace(const char *orig, const char *rep, const char *with); @@ -373,9 +373,9 @@ extern void chomp(char *string); #if defined(ENABLE_WWW) extern void www_init(); -extern void *www_logger(void * cls, const char * uri, struct MHD_Connection *con); +extern void *www_logger(void *cls, const char *uri, struct MHD_Connection *con); extern void www_request_completed(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe); -extern int www_handler(void * cls, struct MHD_Connection * connection, const char * url, const char * method, const char * version, const char * upload_data, size_t * upload_data_size, void ** ptr); +extern int www_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr); extern char *www_email_summary(struct user_record *user); extern char *www_email_display(struct user_record *user, int email); extern int www_send_email(struct user_record *user, char *recipient, char *subject, char *body); diff --git a/src/bbs_list.c b/src/bbs_list.c index 1d1b5c8..f45c9d8 100644 --- a/src/bbs_list.c +++ b/src/bbs_list.c @@ -8,20 +8,20 @@ extern struct bbs_config conf; extern struct user_record *gUser; struct bbs_list_entry_t { - int id; - char *bbsname; - char *sysopname; - char *telnet; - int owner; + int id; + char *bbsname; + char *sysopname; + char *telnet; + int owner; }; int add_bbs(struct bbs_list_entry_t *new_entry) { char *create_sql = "CREATE TABLE IF NOT EXISTS bbslist (" - "id INTEGER PRIMARY KEY," - "bbsname TEXT," - "sysop TEXT," - "telnet TEXT," - "owner INTEGER);"; + "id INTEGER PRIMARY KEY," + "bbsname TEXT," + "sysop TEXT," + "telnet TEXT," + "owner INTEGER);"; char *insert_sql = "INSERT INTO bbslist (bbsname, sysop, telnet, owner) VALUES(?,?, ?, ?)"; @@ -32,11 +32,11 @@ int add_bbs(struct bbs_list_entry_t *new_entry) { char c; char *err_msg = 0; sqlite3 *db; - sqlite3_stmt *res; - int rc; - int id; - - s_printf("\e[2J\e[1;1H"); + sqlite3_stmt *res; + int rc; + int id; + + s_printf("\e[2J\e[1;1H"); s_printf(get_string(28)); s_readstring(bbsname, 18); @@ -60,14 +60,14 @@ int add_bbs(struct bbs_list_entry_t *new_entry) { snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { dolog("Cannot open database: %s", sqlite3_errmsg(db)); - return 0; + return 0; } sqlite3_busy_timeout(db, 5000); rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { + if (rc != SQLITE_OK) { dolog("SQL error: %s", err_msg); @@ -86,69 +86,68 @@ int add_bbs(struct bbs_list_entry_t *new_entry) { sqlite3_bind_int(res, 4, gUser->id); } else { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - return 0; + sqlite3_close(db); + return 0; } - rc = sqlite3_step(res); if (rc != SQLITE_DONE) { dolog("execution failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(res); + sqlite3_finalize(res); sqlite3_close(db); return 0; } - id = sqlite3_last_insert_rowid(db); + id = sqlite3_last_insert_rowid(db); - sqlite3_finalize(res); + sqlite3_finalize(res); sqlite3_close(db); s_printf(get_string(38)); - if (new_entry != NULL) { - new_entry->id = id; - new_entry->bbsname = strdup(bbsname); - new_entry->sysopname = strdup(sysop); - new_entry->telnet = strdup(telnet); - new_entry->owner = gUser->id; - } - return 1; + if (new_entry != NULL) { + new_entry->id = id; + new_entry->bbsname = strdup(bbsname); + new_entry->sysopname = strdup(sysop); + new_entry->telnet = strdup(telnet); + new_entry->owner = gUser->id; + } + return 1; } else { s_printf(get_string(39)); - return 0; + return 0; } } int delete_bbs(int id) { char buffer[PATH_MAX]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char *sql = "SELECT bbsname FROM bbslist WHERE id=? and owner=?"; - char *dsql = "DELETE FROM bbslist WHERE id=?"; - char c; - - s_printf("\e[2J\e[1;1H"); + sqlite3_stmt *res; + int rc; + char *sql = "SELECT bbsname FROM bbslist WHERE id=? and owner=?"; + char *dsql = "DELETE FROM bbslist WHERE id=?"; + char c; - snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path); + s_printf("\e[2J\e[1;1H"); + + snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path); + + rc = sqlite3_open(buffer, &db); - rc = sqlite3_open(buffer, &db); - if (rc != SQLITE_OK) { return 0; } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); if (rc == SQLITE_OK) { sqlite3_bind_int(res, 1, id); sqlite3_bind_int(res, 2, gUser->id); } else { - sqlite3_close(db); - s_printf(get_string(41)); - return 0; - } - if (sqlite3_step(res) == SQLITE_ROW) { + sqlite3_close(db); + s_printf(get_string(41)); + return 0; + } + if (sqlite3_step(res) == SQLITE_ROW) { s_printf(get_string(42), sqlite3_column_text(res, 0)); sqlite3_finalize(res); c = s_getc(); @@ -164,18 +163,18 @@ int delete_bbs(int id) { sqlite3_step(res); s_printf(get_string(43)); sqlite3_finalize(res); - sqlite3_close(db); - return 1; + sqlite3_close(db); + return 1; } else { s_printf(get_string(39)); - sqlite3_close(db); - return 0; + sqlite3_close(db); + return 0; } } else { sqlite3_finalize(res); s_printf(get_string(44)); - sqlite3_close(db); - return 0; + sqlite3_close(db); + return 0; } } @@ -187,207 +186,207 @@ void bbs_list() { char c; char buffer[PATH_MAX]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist"; - struct bbs_list_entry_t **entries; - int entrycount; - struct bbs_list_entry_t *newentry; + sqlite3_stmt *res; + int rc; + char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist"; + struct bbs_list_entry_t **entries; + int entrycount; + struct bbs_list_entry_t *newentry; - while(1) { - entrycount = 0; - snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path); + while (1) { + entrycount = 0; + snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path); - rc = sqlite3_open(buffer, &db); + rc = sqlite3_open(buffer, &db); - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - return; - } + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + return; + } - sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc != SQLITE_OK) { - sqlite3_close(db); + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); - } else { - while (sqlite3_step(res) == SQLITE_ROW) { - if (entrycount == 0) { - entries = (struct bbs_list_entry_t **)malloc(sizeof(struct bbs_list_entry_t *)); - } else { - entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1)); - } - entries[entrycount] = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t)); + } else { + while (sqlite3_step(res) == SQLITE_ROW) { + if (entrycount == 0) { + entries = (struct bbs_list_entry_t **)malloc(sizeof(struct bbs_list_entry_t *)); + } else { + entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1)); + } + entries[entrycount] = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t)); - entries[entrycount]->id = sqlite3_column_int(res, 0); - entries[entrycount]->bbsname = strdup(sqlite3_column_text(res, 1)); - entries[entrycount]->sysopname = strdup(sqlite3_column_text(res, 2)); - entries[entrycount]->telnet = strdup(sqlite3_column_text(res, 3)); - entrycount++; - } - sqlite3_finalize(res); - sqlite3_close(db); - } + entries[entrycount]->id = sqlite3_column_int(res, 0); + entries[entrycount]->bbsname = strdup(sqlite3_column_text(res, 1)); + entries[entrycount]->sysopname = strdup(sqlite3_column_text(res, 2)); + entries[entrycount]->telnet = strdup(sqlite3_column_text(res, 3)); + entrycount++; + } + sqlite3_finalize(res); + sqlite3_close(db); + } - if (entrycount > 0) { - while (1) { - if (redraw) { - s_printf("\e[2J\e[1;1H"); - s_printf(get_string(270)); - s_printf(get_string(271)); - for (i=start;ibbsname, entries[i]->sysopname, entries[i]->telnet); - } else { - s_printf(get_string(268), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet); - } - } - s_printf("\e[%d;5H", selected - start + 2); - redraw = 0; - } - c = s_getchar(); - if (tolower(c) == 'q') { - for (i=0;ibbsname); - free(entries[i]->sysopname); - free(entries[i]->telnet); - free(entries[i]); - } - free(entries); - return; - } else if (tolower(c) == 'a') { - newentry = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t)); - if (add_bbs(newentry)) { - entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1)); - entries[entrycount] = newentry; - entrycount++; - redraw = 1; - } else { - free(newentry); - redraw = 1; - } - } else if (tolower(c) == 'd') { - if (delete_bbs(entries[selected]->id)) { - free(entries[selected]->bbsname); - free(entries[selected]->sysopname); - free(entries[selected]->telnet); - free(entries[selected]); + if (entrycount > 0) { + while (1) { + if (redraw) { + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(270)); + s_printf(get_string(271)); + for (i = start; i < start + 22 && i < entrycount; i++) { + if (i == selected) { + s_printf(get_string(269), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet); + } else { + s_printf(get_string(268), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet); + } + } + s_printf("\e[%d;5H", selected - start + 2); + redraw = 0; + } + c = s_getchar(); + if (tolower(c) == 'q') { + for (i = 0; i < entrycount; i++) { + free(entries[i]->bbsname); + free(entries[i]->sysopname); + free(entries[i]->telnet); + free(entries[i]); + } + free(entries); + return; + } else if (tolower(c) == 'a') { + newentry = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t)); + if (add_bbs(newentry)) { + entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1)); + entries[entrycount] = newentry; + entrycount++; + redraw = 1; + } else { + free(newentry); + redraw = 1; + } + } else if (tolower(c) == 'd') { + if (delete_bbs(entries[selected]->id)) { + free(entries[selected]->bbsname); + free(entries[selected]->sysopname); + free(entries[selected]->telnet); + free(entries[selected]); - for (i=selected;i= entrycount) { - selected = entrycount - 1; - } - } - redraw = 1; - } else if (c == 27) { - c = s_getchar(); - if (c == 91) { - c = s_getchar(); - if (c == 66) { - // down - if (selected + 1 >= start + 22) { - start += 22; - if (start >= entrycount) { - start = entrycount - 22; - } - redraw = 1; - } - selected++; - if (selected >= entrycount) { - selected = entrycount - 1; - } else { - if (!redraw) { - s_printf(get_string(268), selected - start + 1, selected - 1, entries[selected - 1]->bbsname, entries[selected - 1]->sysopname, entries[selected - 1]->telnet); - s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet); - s_printf("\e[%d;4H", selected - start + 2); - } - } - } else if (c == 65) { - // up - if (selected - 1 < start) { - start -= 22; - if (start < 0) { - start = 0; - } - redraw = 1; - } - selected--; - if (selected < 0) { - selected = 0; - } else { - if (!redraw) { - s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet); - s_printf(get_string(268), selected - start + 3, selected + 1, entries[selected + 1]->bbsname, entries[selected + 1]->sysopname, entries[selected + 1]->telnet); - s_printf("\e[%d;4H", selected - start + 2); - } - } - } else if (c == 75) { - // END KEY - selected = entrycount - 1; - start = entrycount - 22; - if (start < 0) { - start = 0; - } - redraw = 1; - } else if (c == 72) { - // HOME KEY - selected = 0; - start = 0; - redraw = 1; - } else if (c == 86 || c == '5') { - if (c == '5') { - s_getchar(); - } - // PAGE UP - selected = selected - 22; - if (selected < 0) { - selected = 0; - } - start = selected; - redraw = 1; - } else if (c == 85 || c == '6') { - if (c == '6') { - s_getchar(); - } - // PAGE DOWN - selected = selected + 22; - if (selected >= entrycount) { - selected = entrycount -1; - } - start = selected; - redraw = 1; - } - } - } - } - } else { - // no entries - s_printf("\e[2J\e[1;1H"); - s_printf(get_string(270)); - s_printf(get_string(271)); - s_printf(get_string(272)); - s_printf(get_string(273)); + if (selected >= entrycount) { + selected = entrycount - 1; + } + } + redraw = 1; + } else if (c == 27) { + c = s_getchar(); + if (c == 91) { + c = s_getchar(); + if (c == 66) { + // down + if (selected + 1 >= start + 22) { + start += 22; + if (start >= entrycount) { + start = entrycount - 22; + } + redraw = 1; + } + selected++; + if (selected >= entrycount) { + selected = entrycount - 1; + } else { + if (!redraw) { + s_printf(get_string(268), selected - start + 1, selected - 1, entries[selected - 1]->bbsname, entries[selected - 1]->sysopname, entries[selected - 1]->telnet); + s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet); + s_printf("\e[%d;4H", selected - start + 2); + } + } + } else if (c == 65) { + // up + if (selected - 1 < start) { + start -= 22; + if (start < 0) { + start = 0; + } + redraw = 1; + } + selected--; + if (selected < 0) { + selected = 0; + } else { + if (!redraw) { + s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet); + s_printf(get_string(268), selected - start + 3, selected + 1, entries[selected + 1]->bbsname, entries[selected + 1]->sysopname, entries[selected + 1]->telnet); + s_printf("\e[%d;4H", selected - start + 2); + } + } + } else if (c == 75) { + // END KEY + selected = entrycount - 1; + start = entrycount - 22; + if (start < 0) { + start = 0; + } + redraw = 1; + } else if (c == 72) { + // HOME KEY + selected = 0; + start = 0; + redraw = 1; + } else if (c == 86 || c == '5') { + if (c == '5') { + s_getchar(); + } + // PAGE UP + selected = selected - 22; + if (selected < 0) { + selected = 0; + } + start = selected; + redraw = 1; + } else if (c == 85 || c == '6') { + if (c == '6') { + s_getchar(); + } + // PAGE DOWN + selected = selected + 22; + if (selected >= entrycount) { + selected = entrycount - 1; + } + start = selected; + redraw = 1; + } + } + } + } + } else { + // no entries + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(270)); + s_printf(get_string(271)); + s_printf(get_string(272)); + s_printf(get_string(273)); - while(1) { - c = s_getchar(); - - if (tolower(c) == 'a') { - add_bbs(NULL); - break; - } else if (tolower(c) == 'q') { - return; - } - } - } - } + while (1) { + c = s_getchar(); + + if (tolower(c) == 'a') { + add_bbs(NULL); + break; + } else if (tolower(c) == 'q') { + return; + } + } + } + } } diff --git a/src/blog.c b/src/blog.c index 61b2c01..eecea44 100644 --- a/src/blog.c +++ b/src/blog.c @@ -7,250 +7,249 @@ extern struct bbs_config conf; extern struct user_record *gUser; int blog_load(struct blog_entry_t ***entries) { - int blog_entry_count = 0; - struct blog_entry_t **blog_entries; - char *sql = "SELECT author, title, body, date FROM blog ORDER BY date DESC"; + int blog_entry_count = 0; + struct blog_entry_t **blog_entries; + char *sql = "SELECT author, title, body, date FROM blog ORDER BY date DESC"; - char buffer[PATH_MAX]; - int rc; - sqlite3 *db; + char buffer[PATH_MAX]; + int rc; + sqlite3 *db; sqlite3_stmt *res; - snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path); + snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path); - rc = sqlite3_open(buffer, &db); + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { dolog("Cannot open database: %s", sqlite3_errmsg(db)); - *entries = NULL; + *entries = NULL; return 0; - } - sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc != SQLITE_OK) { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - *entries = NULL; - return 0; - } - while (sqlite3_step(res) == SQLITE_ROW) { - if (blog_entry_count == 0) { - blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *)); - } else { - blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1)); - } - blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t)); + if (rc != SQLITE_OK) { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + *entries = NULL; + return 0; + } + while (sqlite3_step(res) == SQLITE_ROW) { + if (blog_entry_count == 0) { + blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *)); + } else { + blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1)); + } + blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t)); - blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0)); - blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1)); - blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2)); - blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3); - blog_entry_count++; - } + blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0)); + blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1)); + blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2)); + blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3); + blog_entry_count++; + } - sqlite3_finalize(res); - sqlite3_close(db); + sqlite3_finalize(res); + sqlite3_close(db); - *entries = blog_entries; - return blog_entry_count; + *entries = blog_entries; + return blog_entry_count; } void blog_display() { - - struct blog_entry_t **blog_entries; - int blog_entry_count = 0; - - int i; - struct tm thetime; - char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; - char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; - char c; - int hour; - int j; - int lines = 2; - s_printf("\e[2J\e[1;1H"); - s_printf(get_string(280)); - s_printf(get_string(281)); - blog_entry_count = blog_load(&blog_entries); - if (blog_entry_count == 0) { - s_printf(get_string(282)); - s_printf(get_string(6)); - s_getchar(); - return; - } + struct blog_entry_t **blog_entries; + int blog_entry_count = 0; - c = 'y'; + int i; + struct tm thetime; + char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; + char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; + char c; + int hour; + int j; + int lines = 2; + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(280)); + s_printf(get_string(281)); - for (i=0;idate, &thetime); + blog_entry_count = blog_load(&blog_entries); + if (blog_entry_count == 0) { + s_printf(get_string(282)); + s_printf(get_string(6)); + s_getchar(); + return; + } - s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author); - lines++; - if (lines == 22 && tolower(c) != 'c') { - s_printf("\r\n"); - s_printf(get_string(223)); - c = s_getchar(); - if (tolower(c) == 'n') { - break; - } - s_printf("\r\n\r\n"); - lines = 0; - } - if (thetime.tm_hour >= 12) { - hour = thetime.tm_hour - 12; - } else { - hour = thetime.tm_hour; - } - s_printf(get_string(284), (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900); + c = 'y'; - lines++; - if (lines == 22 && tolower(c) != 'c') { - s_printf("\r\n"); - s_printf(get_string(223)); - c = s_getchar(); - if (tolower(c) == 'n') { - break; - } - s_printf("\r\n\r\n"); - lines = 0; - } - - s_printf("\r\n\e[0m"); - lines++; - if (lines == 22 && tolower(c) != 'c') { - s_printf("\r\n"); - s_printf(get_string(223)); - c = s_getchar(); - if (tolower(c) == 'n') { - break; - } - s_printf("\r\n\r\n"); - lines = 0; - } - for (j=0; jbody); j++) { - if (blog_entries[i]->body[j] == '\r') { - s_printf("\r\n"); - lines++; - if (lines == 22 && tolower(c) != 'c') { - s_printf("\r\n"); - s_printf(get_string(223)); - c = s_getchar(); - if (tolower(c) == 'n') { - break; - } - s_printf("\r\n\r\n"); - lines = 0; - } - } else { - s_printf("%c", blog_entries[i]->body[j]); - } - } + for (i = 0; i < blog_entry_count; i++) { + localtime_r(&blog_entries[i]->date, &thetime); - if (tolower(c) == 'n') { - break; - } - s_printf("\r\n"); - lines++; - if (lines == 22 && tolower(c) != 'c') { - s_printf("\r\n"); - s_printf(get_string(223)); - c = s_getchar(); - if (tolower(c) == 'n') { - break; - } - s_printf("\r\n\r\n"); - lines = 0; - } - } - for (i=0;isubject); - free(blog_entries[i]->author); - free(blog_entries[i]->body); - free(blog_entries[i]); - } + s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + if (thetime.tm_hour >= 12) { + hour = thetime.tm_hour - 12; + } else { + hour = thetime.tm_hour; + } + s_printf(get_string(284), (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900); - free(blog_entries); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } - s_printf(get_string(6)); - s_getchar(); + s_printf("\r\n\e[0m"); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + for (j = 0; j < strlen(blog_entries[i]->body); j++) { + if (blog_entries[i]->body[j] == '\r') { + s_printf("\r\n"); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + } else { + s_printf("%c", blog_entries[i]->body[j]); + } + } + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n"); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + } + for (i = 0; i < blog_entry_count; i++) { + free(blog_entries[i]->subject); + free(blog_entries[i]->author); + free(blog_entries[i]->body); + free(blog_entries[i]); + } + + free(blog_entries); + + s_printf(get_string(6)); + s_getchar(); } void blog_write() { - char *csql = "CREATE TABLE IF NOT EXISTS blog (" - "id INTEGER PRIMARY KEY," - "author TEXT COLLATE NOCASE," - "title TEXT," - "body TEXT," - "date INTEGER);"; + char *csql = "CREATE TABLE IF NOT EXISTS blog (" + "id INTEGER PRIMARY KEY," + "author TEXT COLLATE NOCASE," + "title TEXT," + "body TEXT," + "date INTEGER);"; char *isql = "INSERT INTO blog (author, title, body, date) VALUES(?, ?, ?, ?)"; - int rc; - sqlite3 *db; + int rc; + sqlite3 *db; sqlite3_stmt *res; - char *blog_entry; - char buffer[PATH_MAX]; - char *blog_subject; - char *err_msg = 0; + char *blog_entry; + char buffer[PATH_MAX]; + char *blog_subject; + char *err_msg = 0; - s_printf(get_string(285)); - s_readstring(buffer, 64); - s_printf("\r\n"); + s_printf(get_string(285)); + s_readstring(buffer, 64); + s_printf("\r\n"); - if (strlen(buffer) == 0) { - s_printf(get_string(39)); - return; - } - - blog_subject = strdup(buffer); - - blog_entry = external_editor(gUser, "No-One", "No-One", NULL, 0, "No-One", "Blog Editor", 0, 1); - - if (blog_entry != NULL) { - snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path); - rc = sqlite3_open(buffer, &db); - - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - free(blog_entry); - free(blog_subject); - return; - } - sqlite3_busy_timeout(db, 5000); - rc = sqlite3_exec(db, csql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { - dolog("SQL error: %s", err_msg); - sqlite3_free(err_msg); - sqlite3_close(db); - free(blog_entry); - free(blog_subject); - return; - } - - rc = sqlite3_prepare_v2(db, isql, -1, &res, 0); - - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, gUser->loginname, -1, 0); - sqlite3_bind_text(res, 2, blog_subject, -1, 0); - sqlite3_bind_text(res, 3, blog_entry, -1, 0); - sqlite3_bind_int(res, 4, time(NULL)); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); - sqlite3_finalize(res); - sqlite3_close(db); - free(blog_entry); - free(blog_subject); - return; - } - sqlite3_step(res); - - sqlite3_finalize(res); - sqlite3_close(db); - free(blog_entry); - free(blog_subject); - return; + if (strlen(buffer) == 0) { + s_printf(get_string(39)); + return; } - free(blog_subject); + + blog_subject = strdup(buffer); + + blog_entry = external_editor(gUser, "No-One", "No-One", NULL, 0, "No-One", "Blog Editor", 0, 1); + + if (blog_entry != NULL) { + snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path); + rc = sqlite3_open(buffer, &db); + + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + free(blog_entry); + free(blog_subject); + return; + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_exec(db, csql, 0, 0, &err_msg); + if (rc != SQLITE_OK) { + dolog("SQL error: %s", err_msg); + sqlite3_free(err_msg); + sqlite3_close(db); + free(blog_entry); + free(blog_subject); + return; + } + + rc = sqlite3_prepare_v2(db, isql, -1, &res, 0); + + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, gUser->loginname, -1, 0); + sqlite3_bind_text(res, 2, blog_subject, -1, 0); + sqlite3_bind_text(res, 3, blog_entry, -1, 0); + sqlite3_bind_int(res, 4, time(NULL)); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + sqlite3_finalize(res); + sqlite3_close(db); + free(blog_entry); + free(blog_subject); + return; + } + sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); + free(blog_entry); + free(blog_subject); + return; + } + free(blog_subject); } \ No newline at end of file diff --git a/src/bluewave.c b/src/bluewave.c index cba3b40..50eab7d 100644 --- a/src/bluewave.c +++ b/src/bluewave.c @@ -23,10 +23,10 @@ tLONG convertl(tLONG l) { #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ unsigned char result_bytes[4]; unsigned int result; - result_bytes[0] = (unsigned char) ((l >> 24) & 0xFF); - result_bytes[1] = (unsigned char) ((l >> 16) & 0xFF); - result_bytes[2] = (unsigned char) ((l >> 8) & 0xFF); - result_bytes[3] = (unsigned char) (l & 0xFF); + result_bytes[0] = (unsigned char)((l >> 24) & 0xFF); + result_bytes[1] = (unsigned char)((l >> 16) & 0xFF); + result_bytes[2] = (unsigned char)((l >> 8) & 0xFF); + result_bytes[3] = (unsigned char)(l & 0xFF); memcpy(&result, result_bytes, 4); return result; #else @@ -38,8 +38,8 @@ tWORD converts(tWORD s) { #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ unsigned char result_bytes[2]; unsigned short result; - result_bytes[0] = (unsigned char) ((s >> 8) & 0xFF); - result_bytes[1] = (unsigned char) (s & 0xFF); + result_bytes[0] = (unsigned char)((s >> 8) & 0xFF); + result_bytes[1] = (unsigned char)(s & 0xFF); memcpy(&result, result_bytes, 4); return result; #else @@ -66,8 +66,8 @@ int bwave_scan_email(int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FI snprintf(buffer, PATH_MAX, "%s/email.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); return totmsgs; } sqlite3_busy_timeout(db, 5000); @@ -91,7 +91,7 @@ int bwave_scan_email(int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FI strncpy(fti.subject, sqlite3_column_text(res, 1), 71); thetime = sqlite3_column_int(res, 2); localtime_r((time_t *)&thetime, &timeStruct); - + sprintf(fti.date, "%02d-%s-%04d %02d:%02d", timeStruct.tm_mday, month_name[timeStruct.tm_mon], timeStruct.tm_year + 1900, timeStruct.tm_hour, timeStruct.tm_min); fti.msgnum = converts((tWORD)sqlite3_column_int(res, 4)); body = strdup(sqlite3_column_text(res, 3)); @@ -99,8 +99,8 @@ int bwave_scan_email(int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FI fti.replyat = 0; fti.msgptr = convertl(*last_ptr); fti.msglength = convertl(strlen(body)); - - *last_ptr += strlen(body); + + *last_ptr += strlen(body); fti.flags |= FTI_MSGLOCAL; fti.flags = converts(fti.flags); fti.orig_zone = 0; @@ -110,7 +110,7 @@ int bwave_scan_email(int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FI fwrite(&fti, sizeof(FTI_REC), 1, fti_file); free(body); area_msgs++; - totmsgs++; + totmsgs++; } sqlite3_finalize(res); @@ -124,12 +124,12 @@ int bwave_scan_email(int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FI sqlite3_close(db); memset(&mix, 0, sizeof(MIX_REC)); - + snprintf(mix.areanum, 6, "%d", 1); mix.totmsgs = converts(area_msgs); mix.numpers = converts(area_msgs); mix.msghptr = convertl(mixptr); - fwrite(&mix, sizeof(MIX_REC), 1, mix_file); + fwrite(&mix, sizeof(MIX_REC), 1, mix_file); return totmsgs; } @@ -151,12 +151,12 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file struct tm timeStruct; char realname[66]; char *month_name[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - + snprintf(realname, 65, "%s %s", gUser->firstname, gUser->lastname); if (msghs == NULL) { return totmsgs; } - + jb = open_jam_base(conf.mail_conferences[confr]->mail_areas[area]->path); if (!jb) { dolog("Error opening JAM base.. %s", conf.mail_conferences[confr]->mail_areas[area]->path); @@ -170,44 +170,43 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file jlr.LastReadMsg = 0; jlr.HighReadMsg = 0; jlr.UserCRC = JAM_Crc32(gUser->loginname, strlen(gUser->loginname)); - jlr.UserID = gUser->id; + jlr.UserID = gUser->id; all_unread = 1; } else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) { all_unread = 1; } - } - + if (all_unread == 0) { k = jlr.HighReadMsg; - for (i=0;imsg_count;i++) { + for (i = 0; i < msghs->msg_count; i++) { if (msghs->msgs[i]->msg_h->MsgNum == k) { break; } } - i+=1; + i += 1; } else { i = 0; } - + mixptr = ftell(fti_file); area_msgs = 0; personal_msgs = 0; - - for (k=i;kmsg_count;k++) { - + + for (k = i; k < msghs->msg_count; k++) { + if (totmsgs == conf.bwave_max_msgs) { break; } - + if (msghs->msgs[k]->to != NULL) { if (strcasecmp(msghs->msgs[k]->to, gUser->loginname) == 0 || strncasecmp(msghs->msgs[k]->to, realname, 42) == 0) { personal_msgs++; } } - + memset(&fti, 0, sizeof(FTI_REC)); - + if (msghs->msgs[k]->from != NULL) { strncpy(fti.from, msghs->msgs[k]->from, 35); } else { @@ -218,30 +217,30 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file } else { sprintf(fti.to, "(Missing To)"); } - + if (msghs->msgs[k]->subject != NULL) { strncpy(fti.subject, msghs->msgs[k]->subject, 71); } else { sprintf(fti.subject, "(Missing Subject)"); } - + localtime_r((time_t *)&msghs->msgs[k]->msg_h->DateWritten, &timeStruct); - + sprintf(fti.date, "%02d-%s-%04d %02d:%02d", timeStruct.tm_mday, month_name[timeStruct.tm_mon], timeStruct.tm_year + 1900, timeStruct.tm_hour, timeStruct.tm_min); fti.msgnum = converts((tWORD)msghs->msgs[k]->msg_h->MsgNum); fti.replyto = 0; fti.replyat = 0; fti.msgptr = convertl(*last_ptr); fti.msglength = convertl(msghs->msgs[k]->msg_h->TxtLen); - + *last_ptr += msghs->msgs[k]->msg_h->TxtLen; - + if (msghs->msgs[k]->msg_h->Attribute & JAM_MSG_LOCAL) { fti.flags |= FTI_MSGLOCAL; } - + fti.flags = converts(fti.flags); - + fido = parse_fido_addr(msghs->msgs[k]->oaddress); if (fido != NULL) { fti.orig_zone = converts(fido->zone); @@ -256,31 +255,31 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file // write msg data body = (char *)malloc(msghs->msgs[k]->msg_h->TxtLen); JAM_ReadMsgText(jb, msghs->msgs[k]->msg_h->TxtOffset, msghs->msgs[k]->msg_h->TxtLen, (char *)body); - + fwrite(body, 1, msghs->msgs[k]->msg_h->TxtLen, dat_file); fwrite(&fti, sizeof(FTI_REC), 1, fti_file); - + free(body); jlr.LastReadMsg = msghs->msgs[k]->msg_h->MsgNum; if (jlr.HighReadMsg < msghs->msgs[k]->msg_h->MsgNum) { jlr.HighReadMsg = msghs->msgs[k]->msg_h->MsgNum; - } - + } + JAM_WriteLastRead(jb, gUser->id, &jlr); - + area_msgs++; totmsgs++; } - + //if (area_msgs) { - - memset(&mix, 0, sizeof(MIX_REC)); - - snprintf(mix.areanum, 6, "%d", areano); - mix.totmsgs = converts(area_msgs); - mix.numpers = converts(personal_msgs); - mix.msghptr = convertl(mixptr); - fwrite(&mix, sizeof(MIX_REC), 1, mix_file); + + memset(&mix, 0, sizeof(MIX_REC)); + + snprintf(mix.areanum, 6, "%d", areano); + mix.totmsgs = converts(area_msgs); + mix.numpers = converts(personal_msgs); + mix.msghptr = convertl(mixptr); + fwrite(&mix, sizeof(MIX_REC), 1, mix_file); //} JAM_CloseMB(jb); free(jb); @@ -302,7 +301,7 @@ void bwave_create_packet() { int last_ptr = 0; int stout; int stin; - int sterr; + int sterr; char *weekday[] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"}; struct termios oldit; struct termios oldot; @@ -321,25 +320,25 @@ void bwave_create_packet() { char *cmd; pid_t pid; - for (i=0;imail_area_count;j++) { + for (i = 0; i < conf.mail_conference_count; i++) { + for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { if (msgbase_is_subscribed(i, j)) { tot_areas++; } } } - + if (tot_areas == 0) { s_printf(get_string(224)); s_printf(get_string(6)); s_getchar(); return; } - + area_count = 0; - + memset(&hdr, 0, sizeof(INF_HEADER)); - + hdr.ver = PACKET_LEVEL; strncpy(hdr.loginname, gUser->loginname, 42); //strncpy(hdr.aliasname, gUser->loginname, 42); @@ -349,7 +348,7 @@ void bwave_create_packet() { hdr.net = converts(conf.main_aka->net); hdr.point = converts(conf.main_aka->point); strncpy(hdr.sysop, conf.sysop_name, 40); - + strncpy(hdr.systemname, conf.bbs_name, 64); hdr.inf_header_len = converts(sizeof(INF_HEADER)); hdr.inf_areainfo_len = converts(sizeof(INF_AREA_INFO)); @@ -359,7 +358,7 @@ void bwave_create_packet() { hdr.from_to_len = 35; hdr.subject_len = 71; memcpy(hdr.packet_id, conf.bwave_name, strlen(conf.bwave_name)); - + snprintf(buffer, 1024, "%s/node%d", conf.bbs_path, mynode); if (stat(buffer, &s) != 0) { @@ -367,93 +366,93 @@ void bwave_create_packet() { } snprintf(buffer, 1024, "%s/node%d/bwave/", conf.bbs_path, mynode); - + if (stat(buffer, &s) == 0) { recursive_delete(buffer); } mkdir(buffer, 0755); - + snprintf(buffer, 1024, "%s/node%d/bwave/%s.FTI", conf.bbs_path, mynode, conf.bwave_name); - + fti_file = fopen(buffer, "wb"); - + snprintf(buffer, 1024, "%s/node%d/bwave/%s.MIX", conf.bbs_path, mynode, conf.bwave_name); mix_file = fopen(buffer, "wb"); - + snprintf(buffer, 1024, "%s/node%d/bwave/%s.DAT", conf.bbs_path, mynode, conf.bwave_name); dat_file = fopen(buffer, "wb"); - + s_printf("\r\n"); - - totmsgs = bwave_scan_email(area_count+1, totmsgs, fti_file, mix_file, dat_file, &last_ptr); - s_printf(get_string(195), "Private Email", "Private Email", totmsgs); + + totmsgs = bwave_scan_email(area_count + 1, totmsgs, fti_file, mix_file, dat_file, &last_ptr); + s_printf(get_string(195), "Private Email", "Private Email", totmsgs); areas = (INF_AREA_INFO **)malloc(sizeof(INF_AREA_INFO *)); flags = 0; areas[area_count] = (INF_AREA_INFO *)malloc(sizeof(INF_AREA_INFO)); - + memset(areas[area_count], 0, sizeof(INF_AREA_INFO)); - snprintf(areas[area_count]->areanum, 6, "%d", area_count + 1); - + snprintf(areas[area_count]->areanum, 6, "%d", area_count + 1); + memcpy(areas[area_count]->echotag, "PRIVATE_EMAIL", 13); - + strncpy(areas[area_count]->title, "Private Email", 49); flags |= INF_POST; flags |= INF_NO_PUBLIC; flags |= INF_SCANNING; - + areas[area_count]->area_flags = converts(flags); areas[area_count]->network_type = INF_NET_FIDONET; - + area_count++; if (totmsgs < conf.bwave_max_msgs) { - for (i=0;imail_area_count;j++) { + for (i = 0; i < conf.mail_conference_count; i++) { + for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level <= gUser->sec_level && conf.mail_conferences[i]->mail_areas[j]->qwkname != NULL && msgbase_is_subscribed(i, j)) { lasttot = totmsgs; - totmsgs = bwave_scan_area(i, j, area_count+1, totmsgs, fti_file, mix_file, dat_file, &last_ptr); - s_printf(get_string(195), conf.mail_conferences[i]->name, conf.mail_conferences[i]->mail_areas[j]->name, totmsgs - lasttot); + totmsgs = bwave_scan_area(i, j, area_count + 1, totmsgs, fti_file, mix_file, dat_file, &last_ptr); + s_printf(get_string(195), conf.mail_conferences[i]->name, conf.mail_conferences[i]->mail_areas[j]->name, totmsgs - lasttot); //if (lasttot == totmsgs) { // continue; //} - + areas = (INF_AREA_INFO **)realloc(areas, sizeof(INF_AREA_INFO *) * (area_count + 1)); - + flags = 0; areas[area_count] = (INF_AREA_INFO *)malloc(sizeof(INF_AREA_INFO)); - + memset(areas[area_count], 0, sizeof(INF_AREA_INFO)); - + snprintf(areas[area_count]->areanum, 6, "%d", area_count + 1); - + memcpy(areas[area_count]->echotag, conf.mail_conferences[i]->mail_areas[j]->qwkname, strlen(conf.mail_conferences[i]->mail_areas[j]->qwkname)); - + strncpy(areas[area_count]->title, conf.mail_conferences[i]->mail_areas[j]->name, 49); - + if (conf.mail_conferences[i]->mail_areas[j]->write_sec_level <= gUser->sec_level) { flags |= INF_POST; } - + if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { flags |= INF_NO_PUBLIC; flags |= INF_NETMAIL; flags |= INF_ECHO; } - + if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NEWSGROUP_AREA) { flags |= INF_NO_PRIVATE; flags |= INF_ECHO; } - + if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_LOCAL_AREA) { flags |= INF_NO_PRIVATE; } - + flags |= INF_SCANNING; - + areas[area_count]->area_flags = converts(flags); areas[area_count]->network_type = INF_NET_FIDONET; @@ -461,7 +460,6 @@ void bwave_create_packet() { if (totmsgs == conf.bwave_max_msgs) { break; } - } } if (totmsgs == conf.bwave_max_msgs) { @@ -473,56 +471,56 @@ void bwave_create_packet() { fclose(dat_file); fclose(mix_file); fclose(fti_file); - + snprintf(buffer, 1024, "%s/node%d/bwave/%s.INF", conf.bbs_path, mynode, conf.bwave_name); - + inf_file = fopen(buffer, "wb"); fwrite(&hdr, sizeof(INF_HEADER), 1, inf_file); - - for (i=0;i 0) { // create archive bpos = 0; if (gUser->bwavestyle) { thetime = time(NULL); localtime_r(&thetime, &time_tm); - + if (gUser->bwavepktno / 10 != time_tm.tm_wday) { gUser->bwavepktno = time_tm.tm_wday * 10; } - + snprintf(archive, 1024, "%s/node%d/%s.%s%d", conf.bbs_path, mynode, conf.bwave_name, weekday[time_tm.tm_wday], gUser->bwavepktno % 10); } else { snprintf(archive, 1024, "%s/node%d/%s.%03d", conf.bbs_path, mynode, conf.bwave_name, gUser->bwavepktno); } - - for (i=0;idefarchiver-1]->pack);i++) { - if (conf.archivers[gUser->defarchiver-1]->pack[i] == '*') { + + for (i = 0; i < strlen(conf.archivers[gUser->defarchiver - 1]->pack); i++) { + if (conf.archivers[gUser->defarchiver - 1]->pack[i] == '*') { i++; - if (conf.archivers[gUser->defarchiver-1]->pack[i] == 'a') { + if (conf.archivers[gUser->defarchiver - 1]->pack[i] == 'a') { sprintf(&buffer[bpos], "%s", archive); bpos = strlen(buffer); - } else if (conf.archivers[gUser->defarchiver-1]->pack[i] == 'f') { + } else if (conf.archivers[gUser->defarchiver - 1]->pack[i] == 'f') { sprintf(&buffer[bpos], "%s/node%d/bwave/%s.INF %s/node%d/bwave/%s.MIX %s/node%d/bwave/%s.FTI %s/node%d/bwave/%s.DAT", conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name); bpos = strlen(buffer); - } else if (conf.archivers[gUser->defarchiver-1]->pack[i] == '*') { + } else if (conf.archivers[gUser->defarchiver - 1]->pack[i] == '*') { buffer[bpos++] = '*'; buffer[bpos] = '\0'; } } else { - buffer[bpos++] = conf.archivers[gUser->defarchiver-1]->pack[i]; + buffer[bpos++] = conf.archivers[gUser->defarchiver - 1]->pack[i]; buffer[bpos] = '\0'; } } @@ -530,13 +528,13 @@ void bwave_create_packet() { stout = dup(STDOUT_FILENO); stin = dup(STDIN_FILENO); sterr = dup(STDERR_FILENO); - + dup2(bbs_stdout, STDOUT_FILENO); dup2(bbs_stderr, STDERR_FILENO); dup2(bbs_stdin, STDIN_FILENO); } - - args = (char **)malloc(sizeof (char *)); + + args = (char **)malloc(sizeof(char *)); arg_count = 0; args[arg_count] = strtok(buffer, " "); while (args[arg_count] != NULL) { @@ -555,13 +553,13 @@ void bwave_create_packet() { ret = -1; } free(cmd); - free(args); + free(args); if (sshBBS) { - + dup2(stout, STDOUT_FILENO); - dup2(sterr, STDERR_FILENO); + dup2(sterr, STDERR_FILENO); dup2(stin, STDIN_FILENO); - + close(stin); close(stout); close(sterr); @@ -575,7 +573,7 @@ void bwave_create_packet() { snprintf(buffer, 1024, "%s/node%d/bwave", conf.bbs_path, mynode); recursive_delete(buffer); - + unlink(archive); gUser->bwavepktno++; if (gUser->bwavepktno > 999) { @@ -583,16 +581,15 @@ void bwave_create_packet() { } save_user(gUser); } - + s_printf(get_string(6)); s_getc(); } - int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char *subject, struct fido_addr *destaddr, char *msg) { s_JamBase *jb; s_JamMsgHeader jmh; - s_JamSubPacket* jsp; + s_JamSubPacket *jsp; s_JamSubfield jsf; int z; char buffer[256]; @@ -604,7 +601,7 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char return 1; } - JAM_ClearMsgHeader( &jmh ); + JAM_ClearMsgHeader(&jmh); jmh.DateWritten = dwritten; jmh.Attribute |= JAM_MSG_LOCAL; if (conf.mail_conferences[confr]->realnames == 0) { @@ -612,34 +609,33 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char } else { sprintf(buffer, "%s %s", gUser->firstname, gUser->lastname); } - jsp = JAM_NewSubPacket(); - jsf.LoID = JAMSFLD_SENDERNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_SENDERNAME; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { sprintf(buffer, "ALL"); - jsf.LoID = JAMSFLD_RECVRNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_RECVRNAME; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); } else { - jsf.LoID = JAMSFLD_RECVRNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_RECVRNAME; + jsf.HiID = 0; jsf.DatLen = strlen(to); jsf.Buffer = (char *)to; JAM_PutSubfield(jsp, &jsf); } - jsf.LoID = JAMSFLD_SUBJECT; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_SUBJECT; + jsf.HiID = 0; jsf.DatLen = strlen(subject); jsf.Buffer = (char *)subject; JAM_PutSubfield(jsp, &jsf); @@ -647,57 +643,55 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { jmh.Attribute |= JAM_MSG_TYPEECHO; - if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[confr]->fidoaddr->point) { sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node, + conf.mail_conferences[confr]->fidoaddr->point); } else { sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node); } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point, - generate_msgid()); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node, + conf.mail_conferences[confr]->fidoaddr->point, + generate_msgid()); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); } else if (conf.mail_conferences[confr]->nettype == NETWORK_MAGI) { sprintf(buffer, "%d", conf.mail_conferences[confr]->maginode); - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - uuid_generate(magi_msgid); uuid_unparse_lower(magi_msgid, buffer); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); + jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); } else if (conf.mail_conferences[confr]->nettype == NETWORK_QWK) { - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(conf.bwave_name); jsf.Buffer = (char *)conf.bwave_name; JAM_PutSubfield(jsp, &jsf); @@ -705,19 +699,19 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char } else if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NETMAIL_AREA && conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { jmh.Attribute |= JAM_MSG_TYPENET; jmh.Attribute |= JAM_MSG_PRIVATE; - + if (conf.mail_conferences[confr]->fidoaddr->point) { sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node, + conf.mail_conferences[confr]->fidoaddr->point); } else { sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node); } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -725,29 +719,29 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char if (destaddr != NULL) { if (destaddr->point) { sprintf(buffer, "%d:%d/%d.%d", destaddr->zone, - destaddr->net, - destaddr->node, - destaddr->point); + destaddr->net, + destaddr->node, + destaddr->point); } else { sprintf(buffer, "%d:%d/%d", destaddr->zone, - destaddr->net, - destaddr->node); + destaddr->net, + destaddr->node); } - jsf.LoID = JAMSFLD_DADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_DADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); } sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point, - generate_msgid()); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node, + conf.mail_conferences[confr]->fidoaddr->point, + generate_msgid()); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -763,14 +757,14 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char } else { dolog("Failed to lock msg base!"); JAM_CloseMB(jb); - free(jb); + free(jb); return 1; } } if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) { dolog("Failed to add message"); JAM_UnlockMB(jb); - + JAM_DelSubPacket(jsp); JAM_CloseMB(jb); free(jb); @@ -811,60 +805,60 @@ void bwave_upload_reply() { int stin; int sterr; sqlite3 *db; - sqlite3_stmt *res; - int rc; + sqlite3_stmt *res; + int rc; char *csql = "CREATE TABLE IF NOT EXISTS email (" - "id INTEGER PRIMARY KEY," - "sender TEXT COLLATE NOCASE," - "recipient TEXT COLLATE NOCASE," - "subject TEXT," - "body TEXT," - "date INTEGER," - "seen INTEGER);"; + "id INTEGER PRIMARY KEY," + "sender TEXT COLLATE NOCASE," + "recipient TEXT COLLATE NOCASE," + "subject TEXT," + "body TEXT," + "date INTEGER," + "seen INTEGER);"; char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; - char *err_msg = 0; + char *err_msg = 0; char **args; int arg_count; char *cmd; pid_t pid; int ret; msg_count = 0; - + snprintf(buffer, 1024, "%s/node%d", conf.bbs_path, mynode); if (stat(buffer, &s) != 0) { mkdir(buffer, 0755); } - + snprintf(buffer, 1024, "%s/node%d/bwave/", conf.bbs_path, mynode); - + if (stat(buffer, &s) == 0) { recursive_delete(buffer); } - mkdir(buffer, 0755); - + mkdir(buffer, 0755); + if (!do_upload(gUser, buffer)) { s_printf(get_string(211)); recursive_delete(buffer); return; } - + bpos = 0; - for (i=0;idefarchiver-1]->unpack);i++) { - if (conf.archivers[gUser->defarchiver-1]->unpack[i] == '*') { + for (i = 0; i < strlen(conf.archivers[gUser->defarchiver - 1]->unpack); i++) { + if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == '*') { i++; - if (conf.archivers[gUser->defarchiver-1]->unpack[i] == 'a') { + if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == 'a') { sprintf(&buffer[bpos], "%s", upload_filename); bpos = strlen(buffer); - } else if (conf.archivers[gUser->defarchiver-1]->unpack[i] == 'd') { + } else if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == 'd') { sprintf(&buffer[bpos], "%s/node%d/bwave/", conf.bbs_path, mynode); - bpos = strlen(buffer); - } else if (conf.archivers[gUser->defarchiver-1]->unpack[i] == '*') { + bpos = strlen(buffer); + } else if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == '*') { buffer[bpos++] = '*'; buffer[bpos] = '\0'; } } else { - buffer[bpos++] = conf.archivers[gUser->defarchiver-1]->unpack[i]; + buffer[bpos++] = conf.archivers[gUser->defarchiver - 1]->unpack[i]; buffer[bpos] = '\0'; } } @@ -872,12 +866,12 @@ void bwave_upload_reply() { stout = dup(STDOUT_FILENO); stin = dup(STDIN_FILENO); sterr = dup(STDERR_FILENO); - + dup2(bbs_stdout, STDOUT_FILENO); dup2(bbs_stderr, STDERR_FILENO); dup2(bbs_stdin, STDIN_FILENO); } - args = (char **)malloc(sizeof (char *)); + args = (char **)malloc(sizeof(char *)); arg_count = 0; args[arg_count] = strtok(buffer, " "); while (args[arg_count] != NULL) { @@ -898,22 +892,22 @@ void bwave_upload_reply() { free(cmd); free(args); if (sshBBS) { - + dup2(stout, STDOUT_FILENO); - dup2(sterr, STDERR_FILENO); + dup2(sterr, STDERR_FILENO); dup2(stin, STDIN_FILENO); - + close(stin); close(stout); close(sterr); } - + unlink(upload_filename); - + snprintf(buffer, 1024, "%s/node%d/bwave/%s.UPL", conf.bbs_path, mynode, conf.bwave_name); - + upl_file = fopen(buffer, "r"); - + if (!upl_file) { snprintf(buffer, 1024, "%s/node%d/bwave/%s.upl", conf.bbs_path, mynode, conf.bwave_name); upl_file = fopen(buffer, "r"); @@ -922,19 +916,19 @@ void bwave_upload_reply() { return; } } - + if (!fread(&upl_hdr, sizeof(UPL_HEADER), 1, upl_file)) { s_printf(get_string(196)); fclose(upl_file); - return; + return; } - + while (fread(&upl_rec, sizeof(UPL_REC), 1, upl_file)) { if (strcmp("PRIVATE_EMAIL", upl_rec.echotag) == 0) { if (msg_attr & UPL_INACTIVE) { continue; } - + if (strcasecmp(upl_rec.from, gUser->loginname) != 0) { continue; } @@ -943,21 +937,21 @@ void bwave_upload_reply() { if (stat(msgbuffer, &s) != 0) { continue; } - + body = (char *)malloc(s.st_size + 1); msg_file = fopen(msgbuffer, "r"); if (!msg_file) { free(body); continue; } - + fread(body, 1, s.st_size, msg_file); fclose(msg_file); - + body[s.st_size] = '\0'; - + bpos = 0; - for (i=0;imail_area_count;j++) { + + for (i = 0; i < conf.mail_conference_count; i++) { + for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { if (strcmp(conf.mail_conferences[i]->mail_areas[j]->qwkname, upl_rec.echotag) == 0) { confr = i; area = j; @@ -1026,25 +1020,25 @@ void bwave_upload_reply() { break; } } - + if (confr != -1 && area != -1) { // import message if (conf.mail_conferences[confr]->mail_areas[area]->write_sec_level <= gUser->sec_level) { msg_attr = converts(upl_rec.msg_attr); - + if (msg_attr & UPL_INACTIVE) { continue; } - + if (strcasecmp(upl_rec.from, gUser->loginname) != 0) { continue; } - + addr.zone = 0; addr.net = 0; addr.node = 0; - addr.zone = 0; - + addr.zone = 0; + if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { if (!(msg_attr & UPL_NETMAIL)) { continue; @@ -1062,28 +1056,28 @@ void bwave_upload_reply() { } else { // Local area if (msg_attr & UPL_PRIVATE) { continue; - } + } } - + snprintf(msgbuffer, 1024, "%s/node%d/bwave/%s", conf.bbs_path, mynode, upl_rec.filename); - + if (conf.mail_conferences[confr]->tagline != NULL) { tagline = conf.mail_conferences[confr]->tagline; } else { tagline = conf.default_tagline; } - + if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[confr]->fidoaddr->point == 0) { snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (%d:%d/%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node); } else { - + snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (%d:%d/%d.%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node, + conf.mail_conferences[confr]->fidoaddr->point); } } else if (conf.mail_conferences[confr]->nettype == NETWORK_MAGI) { snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (@%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->maginode); @@ -1092,7 +1086,7 @@ void bwave_upload_reply() { } else { snprintf(originlinebuffer, 256, "\r"); } - + if (stat(msgbuffer, &s) != 0) { continue; } @@ -1102,30 +1096,29 @@ void bwave_upload_reply() { free(body); continue; } - + fread(body, 1, s.st_size, msg_file); fclose(msg_file); - + body[s.st_size] = '\0'; - + strcat(body, originlinebuffer); - + bpos = 0; - for (i=0;i 0) { - s_printf(get_string(204), msg_count); + s_printf(get_string(204), msg_count); } - + s_printf(get_string(6)); s_getc(); } diff --git a/src/bluewave.h b/src/bluewave.h index a4d5e63..d222299 100644 --- a/src/bluewave.h +++ b/src/bluewave.h @@ -19,14 +19,12 @@ /* */ /*****************************************************************************/ -#ifndef __BLUEWAVE_H /* An extra safeguard to prevent this header from */ -#define __BLUEWAVE_H /* being included twice in the same source file */ - - -#define PACKET_LEVEL 3 /* The current mail packet revision level, */ - /* used in the "ver" field of the *.INF */ - /* file header. */ +#ifndef __BLUEWAVE_H /* An extra safeguard to prevent this header from */ +#define __BLUEWAVE_H /* being included twice in the same source file */ +#define PACKET_LEVEL 3 /* The current mail packet revision level, */ + /* used in the "ver" field of the *.INF */ + /* file header. */ /* ** This header defines the data structures for the following files in the @@ -67,12 +65,10 @@ ** function. Example: "memset(&ftirec, 0, sizeof(FTI_REC))".) */ - /*****************************************************************************/ /* >>>>>>>>>>>>>>>>>>>>>>> DATA TYPE DEFINITIONS <<<<<<<<<<<<<<<<<<<<<<<<< */ /*****************************************************************************/ - /* ** The data type definitions below help make these structures a little more ** universal between environments. The 8-bit, 16-bit, and 32-bit data types @@ -96,22 +92,17 @@ ** they aren't, you're bound to get some *very* interesting results. */ - - - -typedef signed char tCHAR; /* 8 bit signed values */ -typedef unsigned char tBYTE; /* 8 bit unsigned values */ -typedef signed short tINT; /* 16 bit signed values */ -typedef unsigned short tWORD; /* 16 bit unsigned values */ -typedef int tLONG; /* 32 bit signed values */ -typedef unsigned int tDWORD; /* 32 bit unsigned values */ - +typedef signed char tCHAR; /* 8 bit signed values */ +typedef unsigned char tBYTE; /* 8 bit unsigned values */ +typedef signed short tINT; /* 16 bit signed values */ +typedef unsigned short tWORD; /* 16 bit unsigned values */ +typedef int tLONG; /* 32 bit signed values */ +typedef unsigned int tDWORD; /* 32 bit unsigned values */ /*****************************************************************************/ /* >>>>>>>>>>>>>>>>>>>>> DOOR DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<<<<<<< */ /*****************************************************************************/ - /* ** Name of file: *.INF ** @@ -129,128 +120,128 @@ typedef unsigned int tDWORD; /* 32 bit unsigned values */ /* Bit-masks for INF_HEADER.UFLAGS field */ -#define INF_HOTKEYS 0x0001 /* User uses "hotkeys" in door prompts */ -#define INF_XPERT 0x0002 /* Short menus displayed in door */ -#define INF_RES1 0x0004 /* RESERVED -- DO NOT USE! */ -#define INF_GRAPHICS 0x0008 /* Enable ANSI control sequences in door */ -#define INF_NOT_MY_MAIL 0x0010 /* Do not bundle mail from user */ -#define INF_EXT_INFO 0x0020 /* Download extended info with messages */ - /* (* VERSION 3 AND LATER ONLY *) */ -#define INF_NUMERIC_EXT 0x0040 /* Use numeric extensions on packets */ - /* (* VERSION 3 AND LATER ONLY *) */ +#define INF_HOTKEYS 0x0001 /* User uses "hotkeys" in door prompts */ +#define INF_XPERT 0x0002 /* Short menus displayed in door */ +#define INF_RES1 0x0004 /* RESERVED -- DO NOT USE! */ +#define INF_GRAPHICS 0x0008 /* Enable ANSI control sequences in door */ +#define INF_NOT_MY_MAIL 0x0010 /* Do not bundle mail from user */ +#define INF_EXT_INFO 0x0020 /* Download extended info with messages */ + /* (* VERSION 3 AND LATER ONLY *) */ +#define INF_NUMERIC_EXT 0x0040 /* Use numeric extensions on packets */ + /* (* VERSION 3 AND LATER ONLY *) */ /* Bit-masks for INF_HEADER.NETMAIL_FLAGS field */ -#define INF_CAN_CRASH 0x0002 /* Allow Crash status */ -#define INF_CAN_ATTACH 0x0010 /* Allow File Attach messages */ -#define INF_CAN_KSENT 0x0080 /* Allow Kill/Sent status */ -#define INF_CAN_HOLD 0x0200 /* Allow Hold status */ -#define INF_CAN_IMM 0x0400 /* Allow Immediate status */ -#define INF_CAN_FREQ 0x0800 /* Allow File Request messages */ -#define INF_CAN_DIRECT 0x1000 /* Allow Direct status */ +#define INF_CAN_CRASH 0x0002 /* Allow Crash status */ +#define INF_CAN_ATTACH 0x0010 /* Allow File Attach messages */ +#define INF_CAN_KSENT 0x0080 /* Allow Kill/Sent status */ +#define INF_CAN_HOLD 0x0200 /* Allow Hold status */ +#define INF_CAN_IMM 0x0400 /* Allow Immediate status */ +#define INF_CAN_FREQ 0x0800 /* Allow File Request messages */ +#define INF_CAN_DIRECT 0x1000 /* Allow Direct status */ /* Bit-masks for INF_HEADER.CTRL_FLAGS field */ -#define INF_NO_CONFIG 0x0001 /* Do not allow offline configuration */ -#define INF_NO_FREQ 0x0002 /* Do not allow file requesting */ +#define INF_NO_CONFIG 0x0001 /* Do not allow offline configuration */ +#define INF_NO_FREQ 0x0002 /* Do not allow file requesting */ /* Values for INF_HEADER.FILE_LIST_TYPE field */ -#define INF_FLIST_NONE 0 /* Door does not generate a list file */ -#define INF_FLIST_TEXT 1 /* Door generates plain text list file */ -#define INF_FLIST_ANSI 2 /* Door generates ANSI list file */ +#define INF_FLIST_NONE 0 /* Door does not generate a list file */ +#define INF_FLIST_TEXT 1 /* Door generates plain text list file */ +#define INF_FLIST_ANSI 2 /* Door generates ANSI list file */ -typedef struct /* INF_HEADER */ +typedef struct /* INF_HEADER */ { - tBYTE ver; /* Packet version type (currently 2) */ - tBYTE readerfiles[5][13]; /* Files to be displayed by reader */ - tBYTE regnum[9]; /* User's registration number */ - tBYTE mashtype; /* Currently unused (door fills with 0) */ - /* Reserved for Blue Wave reader to store */ - /* the compression type the packet uses. */ - tBYTE loginname[43]; /* Name user types at BBS login */ - tBYTE aliasname[43]; /* User's "other" name */ - tBYTE password[21]; /* Password */ - /* All bytes should be the actually ASCII */ - /* value plus 10. Lame security, yes, */ - /* but it does prevent "TYPE *.INF" from */ - /* showing the password. */ - tBYTE passtype; /* Password type */ - /* 0=none 1=door 2=reader 3=both */ - tWORD zone; /* Main network address of host BBS */ - tWORD net; /* (zone:net/node.point) */ - tWORD node; - tWORD point; - tBYTE sysop[41]; /* Name of SysOp of host BBS */ - tWORD ctrl_flags; /* Flags to control reader capabilities */ - /* (* VERSION 3 AND LATER ONLY *) */ - tBYTE systemname[65]; /* Name of host BBS */ - tBYTE maxfreqs; /* Max number of file requests allowed */ - tWORD is_QWK; /* Whether *.INF belongs to a QWK packet */ - tBYTE obsolete2[4]; /* OBSOLETE -- DO NOT USE! */ - tWORD uflags; /* Bit-mapped door options/toggles */ - tBYTE keywords[10][21]; /* User's entire set of door keywords */ - tBYTE filters[10][21]; /* User's entire set of door filters */ - tBYTE macros[3][80]; /* User's door bundling command macros */ - tWORD netmail_flags; /* Bit-mapped NetMail options */ - tWORD credits; /* NetMail credits */ - tWORD debits; /* NetMail debits */ - tBYTE can_forward; /* 0=Message forwarding not allowed */ - tWORD inf_header_len; /* Size of INF_HEADER structure */ - tWORD inf_areainfo_len; /* Size of INF_AREA_INFO structure */ - tWORD mix_structlen; /* Size of MIX_REC structure */ - tWORD fti_structlen; /* Size of FTI_REC structure */ - tBYTE uses_upl_file; /* If this field is not zero, the door that */ - /* created this packet can receive reply */ - /* packets in the new *.UPL file format. */ - /* Otherwise, the old *.UPI and *.NET */ - /* files must be used. */ - tBYTE from_to_len; /* The maximum length of the FROM: and TO: */ - /* fields that the host BBS can support. */ - /* If this value is 0 or is greater than */ - /* 35, then 35 must be used (the upload */ - /* file formats only allow for a maximum */ - /* of 35 characters). */ - tBYTE subject_len; /* The maximum length of the SUBJECT: field */ - /* that the host BBS can support. If */ - /* this value is 0 or is greater than 71, */ - /* then 71 must be used (the upload file */ - /* formats only allow for a maximum of 71 */ - /* characters). */ - tBYTE packet_id[9]; /* Original root name of the mail packet, */ - /* as specified by the mail door. All */ - /* files in the packet that are created */ - /* by the mail door will use this root */ - /* name, as will the reader when creating */ - /* the upload files. Thus, even if the */ - /* packets themselves are renamed to */ - /* something completely different, the */ - /* mail doors and readers will still be */ - /* able to work with the proper files. */ - tBYTE file_list_type; /* New file listing type */ - /* (* VERSION 3 AND LATER ONLY *) */ - /* Specifies the type of new file list */ - /* that is generated by the door (see */ - /* INF_FLIST_xxx, above). This field is */ - /* intended for use with offline config. */ - tBYTE auto_macro[3]; /* Auto-macro indicator flags */ - /* (* VERSION 3 AND LATER ONLY *) */ - /* Specifies which macros are auto macros */ - /* (i.e. execute automatically after mail */ - /* is scanned). */ - tINT max_packet_size; /* Maximum size of uncompressed packet */ - /* (* VERSION 3 AND LATER ONLY *) */ - /* Specifies, in K, the maximum size of */ - /* an uncompressed mail packet. A value */ - /* of 0 indicates no maximum length. */ - /* This field is intended for use with */ - /* offline config. */ - tBYTE reserved[228]; /* RESERVED FOR FUTURE USE */ - /* This field MUST be filled with ASCII */ - /* NUL (0x00) characters in order for */ - /* future additional features to work */ - /* properly! */ -}__attribute__((packed)) + tBYTE ver; /* Packet version type (currently 2) */ + tBYTE readerfiles[5][13]; /* Files to be displayed by reader */ + tBYTE regnum[9]; /* User's registration number */ + tBYTE mashtype; /* Currently unused (door fills with 0) */ + /* Reserved for Blue Wave reader to store */ + /* the compression type the packet uses. */ + tBYTE loginname[43]; /* Name user types at BBS login */ + tBYTE aliasname[43]; /* User's "other" name */ + tBYTE password[21]; /* Password */ + /* All bytes should be the actually ASCII */ + /* value plus 10. Lame security, yes, */ + /* but it does prevent "TYPE *.INF" from */ + /* showing the password. */ + tBYTE passtype; /* Password type */ + /* 0=none 1=door 2=reader 3=both */ + tWORD zone; /* Main network address of host BBS */ + tWORD net; /* (zone:net/node.point) */ + tWORD node; + tWORD point; + tBYTE sysop[41]; /* Name of SysOp of host BBS */ + tWORD ctrl_flags; /* Flags to control reader capabilities */ + /* (* VERSION 3 AND LATER ONLY *) */ + tBYTE systemname[65]; /* Name of host BBS */ + tBYTE maxfreqs; /* Max number of file requests allowed */ + tWORD is_QWK; /* Whether *.INF belongs to a QWK packet */ + tBYTE obsolete2[4]; /* OBSOLETE -- DO NOT USE! */ + tWORD uflags; /* Bit-mapped door options/toggles */ + tBYTE keywords[10][21]; /* User's entire set of door keywords */ + tBYTE filters[10][21]; /* User's entire set of door filters */ + tBYTE macros[3][80]; /* User's door bundling command macros */ + tWORD netmail_flags; /* Bit-mapped NetMail options */ + tWORD credits; /* NetMail credits */ + tWORD debits; /* NetMail debits */ + tBYTE can_forward; /* 0=Message forwarding not allowed */ + tWORD inf_header_len; /* Size of INF_HEADER structure */ + tWORD inf_areainfo_len; /* Size of INF_AREA_INFO structure */ + tWORD mix_structlen; /* Size of MIX_REC structure */ + tWORD fti_structlen; /* Size of FTI_REC structure */ + tBYTE uses_upl_file; /* If this field is not zero, the door that */ + /* created this packet can receive reply */ + /* packets in the new *.UPL file format. */ + /* Otherwise, the old *.UPI and *.NET */ + /* files must be used. */ + tBYTE from_to_len; /* The maximum length of the FROM: and TO: */ + /* fields that the host BBS can support. */ + /* If this value is 0 or is greater than */ + /* 35, then 35 must be used (the upload */ + /* file formats only allow for a maximum */ + /* of 35 characters). */ + tBYTE subject_len; /* The maximum length of the SUBJECT: field */ + /* that the host BBS can support. If */ + /* this value is 0 or is greater than 71, */ + /* then 71 must be used (the upload file */ + /* formats only allow for a maximum of 71 */ + /* characters). */ + tBYTE packet_id[9]; /* Original root name of the mail packet, */ + /* as specified by the mail door. All */ + /* files in the packet that are created */ + /* by the mail door will use this root */ + /* name, as will the reader when creating */ + /* the upload files. Thus, even if the */ + /* packets themselves are renamed to */ + /* something completely different, the */ + /* mail doors and readers will still be */ + /* able to work with the proper files. */ + tBYTE file_list_type; /* New file listing type */ + /* (* VERSION 3 AND LATER ONLY *) */ + /* Specifies the type of new file list */ + /* that is generated by the door (see */ + /* INF_FLIST_xxx, above). This field is */ + /* intended for use with offline config. */ + tBYTE auto_macro[3]; /* Auto-macro indicator flags */ + /* (* VERSION 3 AND LATER ONLY *) */ + /* Specifies which macros are auto macros */ + /* (i.e. execute automatically after mail */ + /* is scanned). */ + tINT max_packet_size; /* Maximum size of uncompressed packet */ + /* (* VERSION 3 AND LATER ONLY *) */ + /* Specifies, in K, the maximum size of */ + /* an uncompressed mail packet. A value */ + /* of 0 indicates no maximum length. */ + /* This field is intended for use with */ + /* offline config. */ + tBYTE reserved[228]; /* RESERVED FOR FUTURE USE */ + /* This field MUST be filled with ASCII */ + /* NUL (0x00) characters in order for */ + /* future additional features to work */ + /* properly! */ +} __attribute__((packed)) INF_HEADER; /* @@ -286,10 +277,10 @@ INF_HEADER; ** value in INF_HEADER.XXXXX_LEN is 0, you must use these values instead! */ -#define ORIGINAL_INF_HEADER_LEN 1230 /* Original *.INF header len */ -#define ORIGINAL_INF_AREA_LEN 80 /* Original *.INF area rec len */ -#define ORIGINAL_MIX_STRUCT_LEN 14 /* Original *.MIX record len */ -#define ORIGINAL_FTI_STRUCT_LEN 186 /* Original *.FTI record len */ +#define ORIGINAL_INF_HEADER_LEN 1230 /* Original *.INF header len */ +#define ORIGINAL_INF_AREA_LEN 80 /* Original *.INF area rec len */ +#define ORIGINAL_MIX_STRUCT_LEN 14 /* Original *.MIX record len */ +#define ORIGINAL_FTI_STRUCT_LEN 186 /* Original *.FTI record len */ /* ** Below is some sample C code for reading in the variable length *.INF @@ -353,71 +344,71 @@ INF_HEADER; /* Bit-masks for INF_AREA_INFO.AREA_FLAGS field */ -#define INF_SCANNING 0x0001 /* On=User is active for area */ -#define INF_ALIAS_NAME 0x0002 /* On=Alias name, Off=Login name */ - /* If ON, use INF_HEADER.ALIASNAME when */ - /* addressing new mail or replies for the */ - /* message area. If OFF, the reader uses */ - /* the INF_HEADER.LOGINNAME for this */ - /* purpose. */ -#define INF_ANY_NAME 0x0004 /* On=Allow any name to be entered */ - /* If ON, any name can be entered in the */ - /* From: field when addressing new mail */ - /* or replies for the message area. If */ - /* OFF, the normal rules apply. */ -#define INF_ECHO 0x0008 /* On=Network mail, Off=Local mail */ -#define INF_NETMAIL 0x0010 /* On=E-mail, Off=Conference mail */ - /* Refer to the chart below (the values */ - /* for the NETWORK_TYPE field) for info */ - /* on how these two flags should be set */ - /* for message areas. */ -#define INF_POST 0x0020 /* On=User can post, Off=User CANNOT post */ -#define INF_NO_PRIVATE 0x0040 /* On=Private messages are NOT allowed */ -#define INF_NO_PUBLIC 0x0080 /* On=Public messages are NOT allowed */ -#define INF_NO_TAGLINE 0x0100 /* On=Taglines are not allowed */ -#define INF_NO_HIGHBIT 0x0200 /* On=ASCII 1-127 only, Off=ASCII 1-255 */ - /* If ON, only ASCII values 1 to 127 are */ - /* allowed in messages. If OFF, all */ - /* values from 1 to 255 are allowed. Due */ - /* to the fact that ASCII value 0 is used */ - /* in C as a string terminator, the value */ - /* 0 should not be allowed in messages at */ - /* all. */ -#define INF_NOECHO 0x0400 /* On=User can prevent messages from being */ - /* sent through the network */ -#define INF_HASFILE 0x0800 /* On=User can attach files to messages */ -#define INF_PERSONAL 0x1000 /* On=User is downloading only personal */ - /* msgs in this message area. The flag */ - /* INF_SCANNING also needs to be ON. */ - /* (* VERSION 3 AND LATER ONLY *) */ -#define INF_TO_ALL 0x2000 /* On=User is downloading messages to "All" */ - /* and personal messages only in this */ - /* area. The flag INF_SCANNING also */ - /* needs to be ON. INF_PERSONAL should */ - /* *not* be set, as this flag implies the */ - /* downloading of personal messages also. */ - /* (* VERSION 3 AND LATER ONLY *) */ +#define INF_SCANNING 0x0001 /* On=User is active for area */ +#define INF_ALIAS_NAME 0x0002 /* On=Alias name, Off=Login name */ + /* If ON, use INF_HEADER.ALIASNAME when */ + /* addressing new mail or replies for the */ + /* message area. If OFF, the reader uses */ + /* the INF_HEADER.LOGINNAME for this */ + /* purpose. */ +#define INF_ANY_NAME 0x0004 /* On=Allow any name to be entered */ + /* If ON, any name can be entered in the */ + /* From: field when addressing new mail */ + /* or replies for the message area. If */ + /* OFF, the normal rules apply. */ +#define INF_ECHO 0x0008 /* On=Network mail, Off=Local mail */ +#define INF_NETMAIL 0x0010 /* On=E-mail, Off=Conference mail */ + /* Refer to the chart below (the values */ + /* for the NETWORK_TYPE field) for info */ + /* on how these two flags should be set */ + /* for message areas. */ +#define INF_POST 0x0020 /* On=User can post, Off=User CANNOT post */ +#define INF_NO_PRIVATE 0x0040 /* On=Private messages are NOT allowed */ +#define INF_NO_PUBLIC 0x0080 /* On=Public messages are NOT allowed */ +#define INF_NO_TAGLINE 0x0100 /* On=Taglines are not allowed */ +#define INF_NO_HIGHBIT 0x0200 /* On=ASCII 1-127 only, Off=ASCII 1-255 */ + /* If ON, only ASCII values 1 to 127 are */ + /* allowed in messages. If OFF, all */ + /* values from 1 to 255 are allowed. Due */ + /* to the fact that ASCII value 0 is used */ + /* in C as a string terminator, the value */ + /* 0 should not be allowed in messages at */ + /* all. */ +#define INF_NOECHO 0x0400 /* On=User can prevent messages from being */ + /* sent through the network */ +#define INF_HASFILE 0x0800 /* On=User can attach files to messages */ +#define INF_PERSONAL 0x1000 /* On=User is downloading only personal */ + /* msgs in this message area. The flag */ + /* INF_SCANNING also needs to be ON. */ + /* (* VERSION 3 AND LATER ONLY *) */ +#define INF_TO_ALL 0x2000 /* On=User is downloading messages to "All" */ + /* and personal messages only in this */ + /* area. The flag INF_SCANNING also */ + /* needs to be ON. INF_PERSONAL should */ + /* *not* be set, as this flag implies the */ + /* downloading of personal messages also. */ + /* (* VERSION 3 AND LATER ONLY *) */ /* Values for INF_AREA_INFO.NETWORK_TYPE field */ -#define INF_NET_FIDONET 0 /* FidoNet-style E-mail and conferences */ - /* Local = INF_ECHO=off, NETMAIL=off */ - /* EchoMail = INF_ECHO=on, NETMAIL=off */ - /* GroupMail = INF_ECHO=on, NETMAIL=off */ - /* NetMail = INF_ECHO=on, NETMAIL=on */ -#define INF_NET_INTERNET 1 /* Internet E-mail and Usenet newsgroups */ - /* Local = INF_ECHO=off, NETMAIL=off */ - /* Newsgroup = INF_ECHO=on, NETMAIL=off */ - /* E-mail = INF_ECHO=on, NETMAIL=on */ +#define INF_NET_FIDONET 0 /* FidoNet-style E-mail and conferences */ + /* Local = INF_ECHO=off, NETMAIL=off */ + /* EchoMail = INF_ECHO=on, NETMAIL=off */ + /* GroupMail = INF_ECHO=on, NETMAIL=off */ + /* NetMail = INF_ECHO=on, NETMAIL=on */ +#define INF_NET_INTERNET 1 /* Internet E-mail and Usenet newsgroups */ + /* Local = INF_ECHO=off, NETMAIL=off */ + /* Newsgroup = INF_ECHO=on, NETMAIL=off */ + /* E-mail = INF_ECHO=on, NETMAIL=on */ -typedef struct /* INF_AREA_INFO */ +typedef struct /* INF_AREA_INFO */ { - tBYTE areanum[6]; /* Area number this record corresponds to */ - tBYTE echotag[21]; /* Area tag name (*.BRD name for Telegard) */ - tBYTE title[50]; /* Area description/title */ - tWORD area_flags; /* Bit-mapped area options */ - tBYTE network_type; /* Network mail type (see above) */ -}__attribute__((packed)) + tBYTE areanum[6]; /* Area number this record corresponds to */ + tBYTE echotag[21]; /* Area tag name (*.BRD name for Telegard) */ + tBYTE title[50]; /* Area description/title */ + tWORD area_flags; /* Bit-mapped area options */ + tBYTE network_type; /* Network mail type (see above) */ +} __attribute__((packed)) INF_AREA_INFO; /*---------------------------------------------------------------------------*/ @@ -434,15 +425,15 @@ INF_AREA_INFO; ** ... */ -typedef struct /* MIX_REC */ +typedef struct /* MIX_REC */ { - tBYTE areanum[6]; /* Area number this record corresponds to */ - /* This is the ASCII representation of the */ - /* actual area number shown on the host BBS. */ - tWORD totmsgs; /* Total number of messages for this area */ - tWORD numpers; /* Total number of personal messages in this area */ - tLONG msghptr; /* Pointer to first message header in *.FTI file */ -}__attribute__((packed)) + tBYTE areanum[6]; /* Area number this record corresponds to */ + /* This is the ASCII representation of the */ + /* actual area number shown on the host BBS. */ + tWORD totmsgs; /* Total number of messages for this area */ + tWORD numpers; /* Total number of personal messages in this area */ + tLONG msghptr; /* Pointer to first message header in *.FTI file */ +} __attribute__((packed)) MIX_REC; /*---------------------------------------------------------------------------*/ @@ -467,54 +458,54 @@ MIX_REC; /* Bit-masks for FTI_REC.FLAGS field */ -#define FTI_MSGPRIVATE 0x0001 /* Private = For addressee ONLY */ -#define FTI_MSGCRASH 0x0002 /* Crash = High priority mail */ -#define FTI_MSGREAD 0x0004 /* Read = Message read by addressee */ -#define FTI_MSGSENT 0x0008 /* Sent = Message sent */ -#define FTI_MSGFILE 0x0010 /* File Attach = Send file(s) */ -#define FTI_MSGFWD 0x0020 /* Forward = Message to/from others */ -#define FTI_MSGORPHAN 0x0040 /* Orphan = Message destination unknown */ -#define FTI_MSGKILL 0x0080 /* Kill/Sent = Delete after sending */ -#define FTI_MSGLOCAL 0x0100 /* Local = Message originated here */ -#define FTI_MSGHOLD 0x0200 /* Hold = Hold for pickup, don't send */ -#define FTI_MSGIMMEDIATE 0x0400 /* Immediate = Send message NOW */ -#define FTI_MSGFRQ 0x0800 /* File Request = Request file(s) */ -#define FTI_MSGDIRECT 0x1000 /* Direct = Send direct, no routing */ -#define FTI_MSGUNUSED1 0x2000 /* */ -#define FTI_MSGUNUSED2 0x4000 /* */ -#define FTI_MSGURQ 0x8000 /* Update Request = Req updated file(s) */ +#define FTI_MSGPRIVATE 0x0001 /* Private = For addressee ONLY */ +#define FTI_MSGCRASH 0x0002 /* Crash = High priority mail */ +#define FTI_MSGREAD 0x0004 /* Read = Message read by addressee */ +#define FTI_MSGSENT 0x0008 /* Sent = Message sent */ +#define FTI_MSGFILE 0x0010 /* File Attach = Send file(s) */ +#define FTI_MSGFWD 0x0020 /* Forward = Message to/from others */ +#define FTI_MSGORPHAN 0x0040 /* Orphan = Message destination unknown */ +#define FTI_MSGKILL 0x0080 /* Kill/Sent = Delete after sending */ +#define FTI_MSGLOCAL 0x0100 /* Local = Message originated here */ +#define FTI_MSGHOLD 0x0200 /* Hold = Hold for pickup, don't send */ +#define FTI_MSGIMMEDIATE 0x0400 /* Immediate = Send message NOW */ +#define FTI_MSGFRQ 0x0800 /* File Request = Request file(s) */ +#define FTI_MSGDIRECT 0x1000 /* Direct = Send direct, no routing */ +#define FTI_MSGUNUSED1 0x2000 /* */ +#define FTI_MSGUNUSED2 0x4000 /* */ +#define FTI_MSGURQ 0x8000 /* Update Request = Req updated file(s) */ -typedef struct /* FTI_REC */ +typedef struct /* FTI_REC */ { - tBYTE from[36]; /* Person message is from */ - tBYTE to[36]; /* Person message is to */ - tBYTE subject[72]; /* Subject/title of message */ - tBYTE date[20]; /* Origin date of message */ - /* Depending on the host BBS's date storage */ - /* format, the EXACT format of this field */ - /* will change. Some will take all 19 bytes, */ - /* others may take only 10. */ - tWORD msgnum; /* Number of THIS message on BBS */ - tWORD replyto; /* "This is a reply to #xx" */ - /* Not used for every message. When non- */ - /* zero, there is a previous message in */ - /* the thread. */ - tWORD replyat; /* "There is a reply at #xx" */ - /* Not used for every message. When non- */ - /* zero, there is a reply to this message. */ - tLONG msgptr; /* Offset to start of message in *.DAT file */ - /* Seek to this exact offset in the *.DAT */ - /* file, then read "msglength" bytes from */ - /* the file to load the entire message text. */ - tLONG msglength; /* Length of message text (in bytes) */ - tWORD flags; /* Bit-mapped message status flags */ - tWORD orig_zone; /* Origin address of message */ - /* These three fields will most likely be 0, */ - /* unless the current message belongs to a */ - /* NetMail message base. */ - tWORD orig_net; - tWORD orig_node; -}__attribute__((packed)) + tBYTE from[36]; /* Person message is from */ + tBYTE to[36]; /* Person message is to */ + tBYTE subject[72]; /* Subject/title of message */ + tBYTE date[20]; /* Origin date of message */ + /* Depending on the host BBS's date storage */ + /* format, the EXACT format of this field */ + /* will change. Some will take all 19 bytes, */ + /* others may take only 10. */ + tWORD msgnum; /* Number of THIS message on BBS */ + tWORD replyto; /* "This is a reply to #xx" */ + /* Not used for every message. When non- */ + /* zero, there is a previous message in */ + /* the thread. */ + tWORD replyat; /* "There is a reply at #xx" */ + /* Not used for every message. When non- */ + /* zero, there is a reply to this message. */ + tLONG msgptr; /* Offset to start of message in *.DAT file */ + /* Seek to this exact offset in the *.DAT */ + /* file, then read "msglength" bytes from */ + /* the file to load the entire message text. */ + tLONG msglength; /* Length of message text (in bytes) */ + tWORD flags; /* Bit-mapped message status flags */ + tWORD orig_zone; /* Origin address of message */ + /* These three fields will most likely be 0, */ + /* unless the current message belongs to a */ + /* NetMail message base. */ + tWORD orig_net; + tWORD orig_node; +} __attribute__((packed)) FTI_REC; /*---------------------------------------------------------------------------*/ @@ -534,12 +525,10 @@ FTI_REC; ** File format: Unstructured */ - /*****************************************************************************/ /* >>>>>>>>>>>>>>>>> MISCELLANEOUS DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<< */ /*****************************************************************************/ - /* ** Name of file: *.MSG ** @@ -567,49 +556,49 @@ FTI_REC; /* Bit-masks for MSG_REC.ATTR field */ -#define MSG_NET_PRIVATE 0x0001 /* Private */ -#define MSG_NET_CRASH 0x0002 /* Crash mail */ -#define MSG_NET_RECEIVED 0x0004 /* Received */ -#define MSG_NET_SENT 0x0008 /* Sent */ -#define MSG_NET_FATTACH 0x0010 /* File attached */ -#define MSG_NET_INTRANSIT 0x0020 /* In-transit */ -#define MSG_NET_ORPHAN 0x0040 /* Orphaned */ -#define MSG_NET_KILL 0x0080 /* Kill after sending */ -#define MSG_NET_LOCAL 0x0100 /* Local message */ -#define MSG_NET_HOLD 0x0200 /* Hold for pickup */ -#define MSG_NET_RESERVED 0x0400 /* RESERVED */ -#define MSG_NET_FREQ 0x0800 /* File request */ -#define MSG_NET_RREQ 0x1000 /* Return receipt request */ -#define MSG_NET_RECEIPT 0x2000 /* Return receipt message */ -#define MSG_NET_AREQ 0x4000 /* Audit request */ -#define MSG_NET_FUREQ 0x8000 /* File update request */ +#define MSG_NET_PRIVATE 0x0001 /* Private */ +#define MSG_NET_CRASH 0x0002 /* Crash mail */ +#define MSG_NET_RECEIVED 0x0004 /* Received */ +#define MSG_NET_SENT 0x0008 /* Sent */ +#define MSG_NET_FATTACH 0x0010 /* File attached */ +#define MSG_NET_INTRANSIT 0x0020 /* In-transit */ +#define MSG_NET_ORPHAN 0x0040 /* Orphaned */ +#define MSG_NET_KILL 0x0080 /* Kill after sending */ +#define MSG_NET_LOCAL 0x0100 /* Local message */ +#define MSG_NET_HOLD 0x0200 /* Hold for pickup */ +#define MSG_NET_RESERVED 0x0400 /* RESERVED */ +#define MSG_NET_FREQ 0x0800 /* File request */ +#define MSG_NET_RREQ 0x1000 /* Return receipt request */ +#define MSG_NET_RECEIPT 0x2000 /* Return receipt message */ +#define MSG_NET_AREQ 0x4000 /* Audit request */ +#define MSG_NET_FUREQ 0x8000 /* File update request */ -typedef struct /* MSG_REC (will soon be obsolete) */ +typedef struct /* MSG_REC (will soon be obsolete) */ { - tBYTE from[36]; /* Person message is from */ - tBYTE to[36]; /* Person message is to */ - tBYTE subj[72]; /* Subject/title of message */ - tBYTE date[20]; /* Creation date/time */ - /* This date/time is usually in either of the */ - /* Fido-sanctioned formats "DD MMM YY HH:MM:SS" */ - /* or "WWW DD MMM YY HH:MM", but due to the */ - /* chaotic nature of FidoNet-compatible software, */ - /* this CANNOT be relied upon! */ - tWORD times; /* Number of times read (fairly obsolete) */ - tWORD dest; /* Destination node (of net/node) */ - tWORD orig; /* Origin node (of net/node) */ - tWORD cost; /* Cost of sending message (usually in US cents) */ - tWORD orig_net; /* Origin net (of net/node) */ - tWORD destnet; /* Destination net (of net/node) */ - tLONG unused1; /* Undefined */ - tLONG unused2; /* Some software (Opus and Maximus, for example) */ - /* uses these fields to store the sent/received */ - /* date/time as bit-packed fields, using the same */ - /* format used in MS-DOS directory entries. */ - tWORD reply; /* Message # that this message replies to */ - tWORD attr; /* Message attributes and behavior flags */ - tWORD up; /* Message # that replies to this message */ -}__attribute__((packed)) + tBYTE from[36]; /* Person message is from */ + tBYTE to[36]; /* Person message is to */ + tBYTE subj[72]; /* Subject/title of message */ + tBYTE date[20]; /* Creation date/time */ + /* This date/time is usually in either of the */ + /* Fido-sanctioned formats "DD MMM YY HH:MM:SS" */ + /* or "WWW DD MMM YY HH:MM", but due to the */ + /* chaotic nature of FidoNet-compatible software, */ + /* this CANNOT be relied upon! */ + tWORD times; /* Number of times read (fairly obsolete) */ + tWORD dest; /* Destination node (of net/node) */ + tWORD orig; /* Origin node (of net/node) */ + tWORD cost; /* Cost of sending message (usually in US cents) */ + tWORD orig_net; /* Origin net (of net/node) */ + tWORD destnet; /* Destination net (of net/node) */ + tLONG unused1; /* Undefined */ + tLONG unused2; /* Some software (Opus and Maximus, for example) */ + /* uses these fields to store the sent/received */ + /* date/time as bit-packed fields, using the same */ + /* format used in MS-DOS directory entries. */ + tWORD reply; /* Message # that this message replies to */ + tWORD attr; /* Message attributes and behavior flags */ + tWORD up; /* Message # that replies to this message */ +} __attribute__((packed)) MSG_REC; /*---------------------------------------------------------------------------*/ @@ -646,33 +635,31 @@ MSG_REC; /* Bit-masks for XTI_REC.FLAGS field */ -#define XTI_HAS_READ 0x01 /* Message has been read */ -#define XTI_HAS_REPLIED 0x02 /* Message has been replied to */ -#define XTI_IS_PERSONAL 0x04 /* Message is personal */ -#define XTI_IS_TAGGED 0x08 /* Message has been 'tagged' */ -#define XTI_HAS_SAVED 0x10 /* Message has been saved */ -#define XTI_HAS_PRINTED 0x20 /* Message has been printed */ +#define XTI_HAS_READ 0x01 /* Message has been read */ +#define XTI_HAS_REPLIED 0x02 /* Message has been replied to */ +#define XTI_IS_PERSONAL 0x04 /* Message is personal */ +#define XTI_IS_TAGGED 0x08 /* Message has been 'tagged' */ +#define XTI_HAS_SAVED 0x10 /* Message has been saved */ +#define XTI_HAS_PRINTED 0x20 /* Message has been printed */ /* Bit-masks for XTI_REC.MARKS field */ -#define XTI_MARK_SAVE 0x01 /* Message marked for saving */ -#define XTI_MARK_REPLY 0x02 /* Message marked for replying */ -#define XTI_MARK_PRINT 0x04 /* Message marked for printing */ -#define XTI_MARK_DELETE 0x08 /* Message marked for deletion */ +#define XTI_MARK_SAVE 0x01 /* Message marked for saving */ +#define XTI_MARK_REPLY 0x02 /* Message marked for replying */ +#define XTI_MARK_PRINT 0x04 /* Message marked for printing */ +#define XTI_MARK_DELETE 0x08 /* Message marked for deletion */ -typedef struct /* XTI_REC */ +typedef struct /* XTI_REC */ { - tBYTE flags; /* Bit-mapped message flags */ - tBYTE marks; /* Bit-mapped message markers */ -}__attribute__((packed)) + tBYTE flags; /* Bit-mapped message flags */ + tBYTE marks; /* Bit-mapped message markers */ +} __attribute__((packed)) XTI_REC; - /*****************************************************************************/ /* >>>>>>>>>>>>>>>>>>>> READER DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<<<<<< */ /*****************************************************************************/ - /* ** Name of file: *.NET ** @@ -692,19 +679,19 @@ XTI_REC; ** ... */ -typedef struct /* NET_REC */ +typedef struct /* NET_REC */ { - MSG_REC msg; /* The Fido-style *.MSG header */ - tBYTE fname[13]; /* Filename the message text is in */ - tBYTE echotag[21]; /* NetMail area tag (*.BRD name for Telegard) */ - tWORD zone; /* Destination zone (of zone:net/node.point) */ - tWORD point; /* Destination point (of zone:net/node.point) */ - tLONG unix_date; /* Date/time of message */ - /* This Unix-style date/time value (number */ - /* of seconds since 01/01/70) is converted */ - /* to the date/time storage method used by */ - /* the host BBS. */ -}__attribute__((packed)) + MSG_REC msg; /* The Fido-style *.MSG header */ + tBYTE fname[13]; /* Filename the message text is in */ + tBYTE echotag[21]; /* NetMail area tag (*.BRD name for Telegard) */ + tWORD zone; /* Destination zone (of zone:net/node.point) */ + tWORD point; /* Destination point (of zone:net/node.point) */ + tLONG unix_date; /* Date/time of message */ + /* This Unix-style date/time value (number */ + /* of seconds since 01/01/70) is converted */ + /* to the date/time storage method used by */ + /* the host BBS. */ +} __attribute__((packed)) NET_REC; /*---------------------------------------------------------------------------*/ @@ -729,60 +716,60 @@ NET_REC; ** ... */ -typedef struct /* UPI_HEADER */ +typedef struct /* UPI_HEADER */ { - tBYTE regnum[9]; /* Reader registration number */ - tBYTE vernum[13]; /* Reader version number */ - /* All bytes should be the actually ASCII */ - /* value plus 10. Lame security, yes, but it */ - /* does prevent "TYPE *.UPI" from showing the */ - /* version number. */ - tBYTE future[33]; /* RESERVED FOR FUTURE USE */ + tBYTE regnum[9]; /* Reader registration number */ + tBYTE vernum[13]; /* Reader version number */ + /* All bytes should be the actually ASCII */ + /* value plus 10. Lame security, yes, but it */ + /* does prevent "TYPE *.UPI" from showing the */ + /* version number. */ + tBYTE future[33]; /* RESERVED FOR FUTURE USE */ #ifdef PAD_SIZES_EVEN - tBYTE evenpad; /* If your compiler pads structures out to even */ - /* numbered sizes, define PAD_SIZES_EVEN */ - /* before including this header. When the */ - /* *.UPI file is written, be sure to write */ - /* sizeof(UPI_HEADER) - 1 bytes, otherwise */ - /* your compiler may insert an extra byte not */ - /* explicitly specified here. */ + tBYTE evenpad; /* If your compiler pads structures out to even */ + /* numbered sizes, define PAD_SIZES_EVEN */ + /* before including this header. When the */ + /* *.UPI file is written, be sure to write */ + /* sizeof(UPI_HEADER) - 1 bytes, otherwise */ + /* your compiler may insert an extra byte not */ + /* explicitly specified here. */ #endif -}__attribute__((packed)) +} __attribute__((packed)) UPI_HEADER; /* Bit-masks for UPI_REC.FLAGS field */ -#define UPI_RES1 0x01 /* RESERVED FOR FUTURE USE */ -#define UPI_RES2 0x02 /* RESERVED FOR FUTURE USE */ -#define UPI_RES3 0x04 /* RESERVED FOR FUTURE USE */ -#define UPI_RES4 0x08 /* RESERVED FOR FUTURE USE */ -#define UPI_RES5 0x10 /* RESERVED FOR FUTURE USE */ -#define UPI_RES6 0x20 /* RESERVED FOR FUTURE USE */ -#define UPI_PRIVATE 0x40 /* Message is PRIVATE */ -#define UPI_NO_ECHO 0x80 /* Message is NOT to be echoed */ - /* This feature is not yet implemented in */ - /* the Blue Wave reader or doors, as none */ - /* of the currently supported BBS software */ - /* has support for this feature. */ +#define UPI_RES1 0x01 /* RESERVED FOR FUTURE USE */ +#define UPI_RES2 0x02 /* RESERVED FOR FUTURE USE */ +#define UPI_RES3 0x04 /* RESERVED FOR FUTURE USE */ +#define UPI_RES4 0x08 /* RESERVED FOR FUTURE USE */ +#define UPI_RES5 0x10 /* RESERVED FOR FUTURE USE */ +#define UPI_RES6 0x20 /* RESERVED FOR FUTURE USE */ +#define UPI_PRIVATE 0x40 /* Message is PRIVATE */ +#define UPI_NO_ECHO 0x80 /* Message is NOT to be echoed */ + /* This feature is not yet implemented in */ + /* the Blue Wave reader or doors, as none */ + /* of the currently supported BBS software */ + /* has support for this feature. */ -typedef struct /* UPI_REC */ +typedef struct /* UPI_REC */ { - tBYTE from[36]; /* Person message is from */ - tBYTE to[36]; /* Person message is to */ - tBYTE subj[72]; /* Subject/title of message */ - tLONG unix_date; /* Date/time of message */ - /* This Unix-style date/time value (number */ - /* of seconds since 01/01/70) is converted */ - /* to the date/time storage method used by */ - /* the host BBS. */ - tBYTE fname[13]; /* Filename the message text is in */ - tBYTE echotag[21]; /* Area tag name (*.BRD name for Telegard) */ - tBYTE flags; /* Bit-mapped flags */ - tBYTE reedit; /* INTERNAL USE ONLY! */ - /* This flag is used internally by the Blue */ - /* Wave reader. Doors should ignore this */ - /* field during reply packet processing. */ -}__attribute__((packed)) + tBYTE from[36]; /* Person message is from */ + tBYTE to[36]; /* Person message is to */ + tBYTE subj[72]; /* Subject/title of message */ + tLONG unix_date; /* Date/time of message */ + /* This Unix-style date/time value (number */ + /* of seconds since 01/01/70) is converted */ + /* to the date/time storage method used by */ + /* the host BBS. */ + tBYTE fname[13]; /* Filename the message text is in */ + tBYTE echotag[21]; /* Area tag name (*.BRD name for Telegard) */ + tBYTE flags; /* Bit-mapped flags */ + tBYTE reedit; /* INTERNAL USE ONLY! */ + /* This flag is used internally by the Blue */ + /* Wave reader. Doors should ignore this */ + /* field during reply packet processing. */ +} __attribute__((packed)) UPI_REC; /*---------------------------------------------------------------------------*/ @@ -807,229 +794,229 @@ UPI_REC; ** ... */ -typedef struct /* UPL_HEADER */ +typedef struct /* UPL_HEADER */ { - tBYTE regnum[10]; /* Reader registration number (if desired) */ - tBYTE vernum[20]; /* Reader version number as a string. */ - /* All bytes should be the actually ASCII */ - /* value plus 10. Lame security, yes, but it */ - /* does prevent "TYPE *.UPL" from showing the */ - /* version number. */ - /* Examples: "2.10a Beta" */ - /* "2.11" */ - tBYTE reader_major; /* Major version of the reader (number to the */ - /* left of the decimal point) */ - tBYTE reader_minor; /* Minor version of the reader (number to the */ - /* right of the decimal point) */ - tBYTE reader_name[80]; /* String containing name of the reader, such */ - /* as "The Blue Wave Offline Mail Reader". */ - /* This is provided for door programmers that */ - /* wish to display the name of the reader */ - /* that created the reply packet. (Filling */ - /* it is mandatory but using it is optional.) */ - tWORD upl_header_len; /* Size of UPL_HEADER structure */ - tWORD upl_rec_len; /* Size of UPL_REC structure */ - /* NOTE: Refer to the INF_HEADER section for */ - /* more information on using the size */ - /* fields. */ - tBYTE loginname[44]; /* Name found in INF_HEADER.LOGINNAME. This is */ - /* provided for door authors as a security */ - /* measure to implement as they wish. */ - tBYTE aliasname[44]; /* Name found in INF_HEADER.ALIASNAME */ - tBYTE reader_tear[16]; /* String containing abbreviated name of the */ - /* reader, such as "Blue Wave", "Q-Blue", */ - /* "Wave Rider", etc. This is provided for */ - /* doors programmers that wish to add to the */ - /* tear line the name of the reader that */ - /* created the reply packet. (Filling it is */ - /* mandatory but using it is optional.) If */ - /* this field is blank, the tear line to be */ - /* generated is left to the discretion of the */ - /* door author. */ - tBYTE compress_type; /* Compression type required for mail packet */ - /* The Blue Wave reader uses this internally */ - /* to store the compression type required for */ - /* this particular mail packet. */ - tBYTE flags; /* Reader processing flags */ - /* The Blue Wave reader uses this internally */ - /* to store flags required for later */ - /* processing. */ - /* 0x01 = Was a .QWK packet. */ - /* 0x02 = Host requires a *.UPI file */ - tBYTE not_registered; /* Reader is not registered to user */ - /* If this byte is set to a non-zero value, */ - /* the Blue Wave doors will assume that the */ - /* user's reader was not registered, and will */ - /* place "[NR]" at the end of the tear line. */ - /* Third-party doors may use this flag for */ - /* the same purpose; its use is optional by */ - /* mail readers (especially if you don't care */ - /* whether or not "[NR]" shows up on the tear */ - /* line ). */ - tBYTE pad[33]; /* RESERVED FOR FUTURE USE, and to pad struct */ - /* out to a 'nice' 256 bytes */ -}__attribute__((packed)) + tBYTE regnum[10]; /* Reader registration number (if desired) */ + tBYTE vernum[20]; /* Reader version number as a string. */ + /* All bytes should be the actually ASCII */ + /* value plus 10. Lame security, yes, but it */ + /* does prevent "TYPE *.UPL" from showing the */ + /* version number. */ + /* Examples: "2.10a Beta" */ + /* "2.11" */ + tBYTE reader_major; /* Major version of the reader (number to the */ + /* left of the decimal point) */ + tBYTE reader_minor; /* Minor version of the reader (number to the */ + /* right of the decimal point) */ + tBYTE reader_name[80]; /* String containing name of the reader, such */ + /* as "The Blue Wave Offline Mail Reader". */ + /* This is provided for door programmers that */ + /* wish to display the name of the reader */ + /* that created the reply packet. (Filling */ + /* it is mandatory but using it is optional.) */ + tWORD upl_header_len; /* Size of UPL_HEADER structure */ + tWORD upl_rec_len; /* Size of UPL_REC structure */ + /* NOTE: Refer to the INF_HEADER section for */ + /* more information on using the size */ + /* fields. */ + tBYTE loginname[44]; /* Name found in INF_HEADER.LOGINNAME. This is */ + /* provided for door authors as a security */ + /* measure to implement as they wish. */ + tBYTE aliasname[44]; /* Name found in INF_HEADER.ALIASNAME */ + tBYTE reader_tear[16]; /* String containing abbreviated name of the */ + /* reader, such as "Blue Wave", "Q-Blue", */ + /* "Wave Rider", etc. This is provided for */ + /* doors programmers that wish to add to the */ + /* tear line the name of the reader that */ + /* created the reply packet. (Filling it is */ + /* mandatory but using it is optional.) If */ + /* this field is blank, the tear line to be */ + /* generated is left to the discretion of the */ + /* door author. */ + tBYTE compress_type; /* Compression type required for mail packet */ + /* The Blue Wave reader uses this internally */ + /* to store the compression type required for */ + /* this particular mail packet. */ + tBYTE flags; /* Reader processing flags */ + /* The Blue Wave reader uses this internally */ + /* to store flags required for later */ + /* processing. */ + /* 0x01 = Was a .QWK packet. */ + /* 0x02 = Host requires a *.UPI file */ + tBYTE not_registered; /* Reader is not registered to user */ + /* If this byte is set to a non-zero value, */ + /* the Blue Wave doors will assume that the */ + /* user's reader was not registered, and will */ + /* place "[NR]" at the end of the tear line. */ + /* Third-party doors may use this flag for */ + /* the same purpose; its use is optional by */ + /* mail readers (especially if you don't care */ + /* whether or not "[NR]" shows up on the tear */ + /* line ). */ + tBYTE pad[33]; /* RESERVED FOR FUTURE USE, and to pad struct */ + /* out to a 'nice' 256 bytes */ +} __attribute__((packed)) UPL_HEADER; /* Bit-masks for UPL_REC.MSG_ATTR field */ -#define UPL_INACTIVE 0x0001 /* Message is INACTIVE */ - /* Doors should NOT attempt to import this */ - /* message. */ -#define UPL_PRIVATE 0x0002 /* Message is PRIVATE */ -#define UPL_NO_ECHO 0x0004 /* Message is NOT to be echoed */ - /* This feature is not yet implemented in */ - /* the Blue Wave reader or doors, as none */ - /* of the currently supported BBS software */ - /* has support for this feature. */ -#define UPL_HAS_FILE 0x0008 /* Message has file "attached" to it */ - /* It is up to the door to check the */ - /* validity of this flag. If the file is */ - /* contained in the mail packet, great. */ - /* If not, the door should probably prompt */ - /* the user to begin uploading the file */ - /* after importing the messages. (Not yet */ - /* implemented in the Blue Wave reader.) */ -#define UPL_NETMAIL 0x0010 /* Message is network mail */ - /* Indicates NetMail/E-mail message. The */ - /* NETWORK_TYPE field (see below) will */ - /* indicate which fields should be used */ - /* for addressing the message. */ -#define UPL_IS_REPLY 0x0020 /* Indicates that the message is a reply to */ - /* an existing message, rather than being */ - /* a completely new message. */ -#define UPL_MRES7 0x0040 /* RESERVED FOR FUTURE USE */ -#define UPL_MRES8 0x0080 /* RESERVED FOR FUTURE USE */ - /* All of the other 8 bits of this field are */ - /* also reserved for future use. This */ - /* should provide for plenty of expansion */ - /* for future development. */ +#define UPL_INACTIVE 0x0001 /* Message is INACTIVE */ + /* Doors should NOT attempt to import this */ + /* message. */ +#define UPL_PRIVATE 0x0002 /* Message is PRIVATE */ +#define UPL_NO_ECHO 0x0004 /* Message is NOT to be echoed */ + /* This feature is not yet implemented in */ + /* the Blue Wave reader or doors, as none */ + /* of the currently supported BBS software */ + /* has support for this feature. */ +#define UPL_HAS_FILE 0x0008 /* Message has file "attached" to it */ + /* It is up to the door to check the */ + /* validity of this flag. If the file is */ + /* contained in the mail packet, great. */ + /* If not, the door should probably prompt */ + /* the user to begin uploading the file */ + /* after importing the messages. (Not yet */ + /* implemented in the Blue Wave reader.) */ +#define UPL_NETMAIL 0x0010 /* Message is network mail */ + /* Indicates NetMail/E-mail message. The */ + /* NETWORK_TYPE field (see below) will */ + /* indicate which fields should be used */ + /* for addressing the message. */ +#define UPL_IS_REPLY 0x0020 /* Indicates that the message is a reply to */ + /* an existing message, rather than being */ + /* a completely new message. */ +#define UPL_MRES7 0x0040 /* RESERVED FOR FUTURE USE */ +#define UPL_MRES8 0x0080 /* RESERVED FOR FUTURE USE */ + /* All of the other 8 bits of this field are */ + /* also reserved for future use. This */ + /* should provide for plenty of expansion */ + /* for future development. */ /* Bit-masks for UPL_REC.NETMAIL_ATTR field */ -#define UPL_NRES1 0x0001 /* RESERVED FOR FUTURE USE */ -#define UPL_NETCRASH 0x0002 /* Crash = High priority mail */ -#define UPL_NRES2 0x0004 /* RESERVED FOR FUTURE USE */ -#define UPL_NRES3 0x0008 /* RESERVED FOR FUTURE USE */ -#define UPL_NETFILE 0x0010 /* File Attach = Send file(s) listed */ - /* in Subject field */ -#define UPL_NRES4 0x0020 /* RESERVED FOR FUTURE USE */ -#define UPL_NRES5 0x0040 /* RESERVED FOR FUTURE USE */ -#define UPL_NETKILL 0x0080 /* Kill/Sent = Delete after sending */ -#define UPL_NETLOCAL 0x0100 /* Local = Message originated here */ -#define UPL_NETHOLD 0x0200 /* Hold = Hold for pickup, do not send */ -#define UPL_NETIMMEDIATE 0x0400 /* Immediate = Send message NOW */ -#define UPL_NETFRQ 0x0800 /* File Request = Request file(s) */ - /* listed in Subject field */ -#define UPL_NETDIRECT 0x1000 /* Direct = Send direct, no routing */ -#define UPL_NRES6 0x2000 /* RESERVED FOR FUTURE USE */ -#define UPL_NRES7 0x4000 /* RESERVED FOR FUTURE USE */ -#define UPL_NETURQ 0x8000 /* Update Request = Request updated */ - /* file(s) listed in Subject field */ +#define UPL_NRES1 0x0001 /* RESERVED FOR FUTURE USE */ +#define UPL_NETCRASH 0x0002 /* Crash = High priority mail */ +#define UPL_NRES2 0x0004 /* RESERVED FOR FUTURE USE */ +#define UPL_NRES3 0x0008 /* RESERVED FOR FUTURE USE */ +#define UPL_NETFILE 0x0010 /* File Attach = Send file(s) listed */ + /* in Subject field */ +#define UPL_NRES4 0x0020 /* RESERVED FOR FUTURE USE */ +#define UPL_NRES5 0x0040 /* RESERVED FOR FUTURE USE */ +#define UPL_NETKILL 0x0080 /* Kill/Sent = Delete after sending */ +#define UPL_NETLOCAL 0x0100 /* Local = Message originated here */ +#define UPL_NETHOLD 0x0200 /* Hold = Hold for pickup, do not send */ +#define UPL_NETIMMEDIATE 0x0400 /* Immediate = Send message NOW */ +#define UPL_NETFRQ 0x0800 /* File Request = Request file(s) */ + /* listed in Subject field */ +#define UPL_NETDIRECT 0x1000 /* Direct = Send direct, no routing */ +#define UPL_NRES6 0x2000 /* RESERVED FOR FUTURE USE */ +#define UPL_NRES7 0x4000 /* RESERVED FOR FUTURE USE */ +#define UPL_NETURQ 0x8000 /* Update Request = Request updated */ + /* file(s) listed in Subject field */ /* Values for UPL_REC.NETWORK_TYPE field */ -#define UPL_NET_FIDONET 0 /* FidoNet-style E-mail and conferences */ - /* UPL_NETMAIL=off - Local, Echo, Group */ - /* UPL_NETMAIL=on - NetMail */ -#define UPL_NET_INTERNET 1 /* Internet E-mail and Usenet newsgroups */ - /* UPL_NETMAIL=off - Local, Newsgroup */ - /* UPL_NETMAIL=on - E-mail */ +#define UPL_NET_FIDONET 0 /* FidoNet-style E-mail and conferences */ + /* UPL_NETMAIL=off - Local, Echo, Group */ + /* UPL_NETMAIL=on - NetMail */ +#define UPL_NET_INTERNET 1 /* Internet E-mail and Usenet newsgroups */ + /* UPL_NETMAIL=off - Local, Newsgroup */ + /* UPL_NETMAIL=on - E-mail */ -typedef struct /* UPL_REC */ +typedef struct /* UPL_REC */ { - tBYTE from[36]; /* Person message is from */ - /* NOTE: Doors should validate this field! */ - tBYTE to[36]; /* Person message is to (non-Internet) */ - /* For Internet E-mail, the NET_DEST field */ - /* should be used to store the destination */ - /* name/address, leaving this field blank. */ - /* For Usenet newsgroups, this field should be */ - /* left blank, as newsgroups don't use a "To:" */ - /* field. */ - tBYTE subj[72]; /* Subject/Title of message */ - tWORD destzone; /* Destination address (FidoNet only) */ - /* If the message is not a FidoNet NetMail */ - /* message, this field (and the subsequent */ - /* three fields as well) should be set to */ - /* zero. */ - tWORD destnet; - tWORD destnode; - tWORD destpoint; - tWORD msg_attr; /* Bit-mapped message attributes */ - tWORD netmail_attr; /* Bit-mapped NetMail attributes (FidoNet only) */ - /* If the message is not a FidoNet NetMail */ - /* message, this field should not be used. */ - tLONG unix_date; /* Date/time of message */ - /* This Unix-style date/time value (number */ - /* of seconds since 01/01/70) is converted to */ - /* the date/time storage method used by the */ - /* host BBS. */ - tDWORD replyto; /* This unsigned long word stores the message # */ - /* that this message is a reply to. This */ - /* should be the same as FTI.MSGNUM. Note, */ - /* however, that FTI.MSGNUM is a word. C */ - /* programmers especially will need to */ - /* properly typecast the value (i.e. */ - /* upl.replyto=(tDWORD)fti.msgnum). As */ - /* messaging/BBS systems become more complex, */ - /* FTI.MSGNUM may become obsolete, and a */ - /* tDWORD variable may be used in its place. */ - tBYTE filename[13]; /* Filename the message text is in */ - /* If this file does not exist in the upload */ - /* packet then doors should consider this an */ - /* invalid record. */ - tBYTE echotag[21]; /* Area tag the message goes in */ - /* This must correspond exactly to the */ - /* INF_AREA_INFO.ECHOTAG field for the message */ - /* area this message belongs to. Simple area */ - /* number matching has proven not to work */ - /* simply because sysops are finicky people, */ - /* and seem to constantly renumber/change the */ - /* message area numbers on the host BBS. */ - /* Using an echotag helps to alleviate this */ - /* problem. C_ECHO will be C_ECHO on the BBS, */ - /* whether it is msg area 17 on the host BBS */ - /* or whether it is area 207. Doors should do */ - /* a case-INSENSITIVE compare on this field to */ - /* find where the message belongs. */ - tWORD area_flags; /* The Blue Wave Offline Mail Reader uses this */ - /* word internally to store the same value as */ - /* in INF_AREA_INFO.AREA_FLAGS. The purpose */ - /* of this word is to hold the original */ - /* information about the message area so that */ - /* later message editing processes can be */ - /* controlled properly. For example, if a */ - /* user later wanted to edit this message, the */ - /* reader would know instantly whether this is */ - /* a NETMAIL area, whether PVT messages are */ - /* allowed, etc. This allows re-editing of */ - /* the message, even when there is not a */ - /* corresponding *.INF file laying around, or */ - /* the area is not listed in the *.INF file */ - /* you currently have to work with. DOOR */ - /* AUTHORS SHOULD IGNORE THIS FIELD WHEN */ - /* IMPORTING MESSAGES! */ - tBYTE f_attach[13]; /* If the UPL_HAS_FILE flag is set, this field */ - /* will contain the file name that is attached */ - /* to the message. */ - tBYTE user_area[6]; /* User-defined storage. Doors should ignore */ - /* this field, and reader authors should feel */ - /* free to utilize this field for their own */ - /* internal use, if necessary. */ - tBYTE network_type; /* Indicates the network type. This field must */ - /* hold the same value as the NETWORK_TYPE */ - /* field in INF_AREA_INFO, allowing doors and */ - /* readers to properly handle the message. */ - /* (Values duplicated as UPL_NET_xxx, above.) */ - /* For FidoNet NetMail and Internet E-mail, it */ - /* also indicates which fields should be used */ - /* for addressing and status information (as */ - /* indicated in comments above and below). */ - tBYTE net_dest[100]; /* Network destination address (non-FidoNet) */ - /* Internet E-mail messages should use this */ - /* field to store the destination address. */ -}__attribute__((packed)) + tBYTE from[36]; /* Person message is from */ + /* NOTE: Doors should validate this field! */ + tBYTE to[36]; /* Person message is to (non-Internet) */ + /* For Internet E-mail, the NET_DEST field */ + /* should be used to store the destination */ + /* name/address, leaving this field blank. */ + /* For Usenet newsgroups, this field should be */ + /* left blank, as newsgroups don't use a "To:" */ + /* field. */ + tBYTE subj[72]; /* Subject/Title of message */ + tWORD destzone; /* Destination address (FidoNet only) */ + /* If the message is not a FidoNet NetMail */ + /* message, this field (and the subsequent */ + /* three fields as well) should be set to */ + /* zero. */ + tWORD destnet; + tWORD destnode; + tWORD destpoint; + tWORD msg_attr; /* Bit-mapped message attributes */ + tWORD netmail_attr; /* Bit-mapped NetMail attributes (FidoNet only) */ + /* If the message is not a FidoNet NetMail */ + /* message, this field should not be used. */ + tLONG unix_date; /* Date/time of message */ + /* This Unix-style date/time value (number */ + /* of seconds since 01/01/70) is converted to */ + /* the date/time storage method used by the */ + /* host BBS. */ + tDWORD replyto; /* This unsigned long word stores the message # */ + /* that this message is a reply to. This */ + /* should be the same as FTI.MSGNUM. Note, */ + /* however, that FTI.MSGNUM is a word. C */ + /* programmers especially will need to */ + /* properly typecast the value (i.e. */ + /* upl.replyto=(tDWORD)fti.msgnum). As */ + /* messaging/BBS systems become more complex, */ + /* FTI.MSGNUM may become obsolete, and a */ + /* tDWORD variable may be used in its place. */ + tBYTE filename[13]; /* Filename the message text is in */ + /* If this file does not exist in the upload */ + /* packet then doors should consider this an */ + /* invalid record. */ + tBYTE echotag[21]; /* Area tag the message goes in */ + /* This must correspond exactly to the */ + /* INF_AREA_INFO.ECHOTAG field for the message */ + /* area this message belongs to. Simple area */ + /* number matching has proven not to work */ + /* simply because sysops are finicky people, */ + /* and seem to constantly renumber/change the */ + /* message area numbers on the host BBS. */ + /* Using an echotag helps to alleviate this */ + /* problem. C_ECHO will be C_ECHO on the BBS, */ + /* whether it is msg area 17 on the host BBS */ + /* or whether it is area 207. Doors should do */ + /* a case-INSENSITIVE compare on this field to */ + /* find where the message belongs. */ + tWORD area_flags; /* The Blue Wave Offline Mail Reader uses this */ + /* word internally to store the same value as */ + /* in INF_AREA_INFO.AREA_FLAGS. The purpose */ + /* of this word is to hold the original */ + /* information about the message area so that */ + /* later message editing processes can be */ + /* controlled properly. For example, if a */ + /* user later wanted to edit this message, the */ + /* reader would know instantly whether this is */ + /* a NETMAIL area, whether PVT messages are */ + /* allowed, etc. This allows re-editing of */ + /* the message, even when there is not a */ + /* corresponding *.INF file laying around, or */ + /* the area is not listed in the *.INF file */ + /* you currently have to work with. DOOR */ + /* AUTHORS SHOULD IGNORE THIS FIELD WHEN */ + /* IMPORTING MESSAGES! */ + tBYTE f_attach[13]; /* If the UPL_HAS_FILE flag is set, this field */ + /* will contain the file name that is attached */ + /* to the message. */ + tBYTE user_area[6]; /* User-defined storage. Doors should ignore */ + /* this field, and reader authors should feel */ + /* free to utilize this field for their own */ + /* internal use, if necessary. */ + tBYTE network_type; /* Indicates the network type. This field must */ + /* hold the same value as the NETWORK_TYPE */ + /* field in INF_AREA_INFO, allowing doors and */ + /* readers to properly handle the message. */ + /* (Values duplicated as UPL_NET_xxx, above.) */ + /* For FidoNet NetMail and Internet E-mail, it */ + /* also indicates which fields should be used */ + /* for addressing and status information (as */ + /* indicated in comments above and below). */ + tBYTE net_dest[100]; /* Network destination address (non-FidoNet) */ + /* Internet E-mail messages should use this */ + /* field to store the destination address. */ +} __attribute__((packed)) UPL_REC; /*---------------------------------------------------------------------------*/ @@ -1057,10 +1044,10 @@ UPL_REC; ** ... */ -typedef struct /* REQ_REC */ +typedef struct /* REQ_REC */ { - tBYTE filename[13]; /* Name of file to request */ -}__attribute__((packed)) + tBYTE filename[13]; /* Name of file to request */ +} __attribute__((packed)) REQ_REC; /*---------------------------------------------------------------------------*/ @@ -1099,31 +1086,31 @@ REQ_REC; /* Bit-masks for PDQ_HEADER.FLAGS field */ -#define PDQ_HOTKEYS 0x0001 /* Toggle "hotkeys" in prompts */ -#define PDQ_XPERT 0x0002 /* Toggle expert mode (menu displays) */ -#define PDQ_AREA_CHANGES 0x0004 /* Change active message areas */ -#define PDQ_GRAPHICS 0x0008 /* Toggle IBM 8-bit ASCII characters */ -#define PDQ_NOT_MY_MAIL 0x0010 /* Toggle bundling mail from user */ +#define PDQ_HOTKEYS 0x0001 /* Toggle "hotkeys" in prompts */ +#define PDQ_XPERT 0x0002 /* Toggle expert mode (menu displays) */ +#define PDQ_AREA_CHANGES 0x0004 /* Change active message areas */ +#define PDQ_GRAPHICS 0x0008 /* Toggle IBM 8-bit ASCII characters */ +#define PDQ_NOT_MY_MAIL 0x0010 /* Toggle bundling mail from user */ -typedef struct /* PDQ_HEADER */ +typedef struct /* PDQ_HEADER */ { - tBYTE keywords[10][21]; /* User's entire set of door keywords */ - tBYTE filters[10][21]; /* User's entire set of door filters */ - tBYTE macros[3][78]; /* User's door bundling command macros */ - tBYTE password[21]; /* Password */ - tBYTE passtype; /* Password type */ - /* 0=none 1=door 2=reader 3=both */ - tWORD flags; /* Bit-mapped flags */ -}__attribute__((packed)) + tBYTE keywords[10][21]; /* User's entire set of door keywords */ + tBYTE filters[10][21]; /* User's entire set of door filters */ + tBYTE macros[3][78]; /* User's door bundling command macros */ + tBYTE password[21]; /* Password */ + tBYTE passtype; /* Password type */ + /* 0=none 1=door 2=reader 3=both */ + tWORD flags; /* Bit-mapped flags */ +} __attribute__((packed)) PDQ_HEADER; -typedef struct /* PDQ_REC */ +typedef struct /* PDQ_REC */ { - tBYTE echotag[21]; /* Echo tag of message area to activate */ - /* With Telegard systems, this should */ - /* be the name of the *.BRD file, rather */ - /* than the actual echo tag. */ -}__attribute__((packed)) + tBYTE echotag[21]; /* Echo tag of message area to activate */ + /* With Telegard systems, this should */ + /* be the name of the *.BRD file, rather */ + /* than the actual echo tag. */ +} __attribute__((packed)) PDQ_REC; /*---------------------------------------------------------------------------*/ @@ -1148,5 +1135,4 @@ PDQ_REC; /*---------------------------------------------------------------------------*/ -#endif /* __BLUEWAVE_H */ - +#endif /* __BLUEWAVE_H */ diff --git a/src/chat_system.c b/src/chat_system.c index 9b27b0d..123f7df 100644 --- a/src/chat_system.c +++ b/src/chat_system.c @@ -8,7 +8,7 @@ #include #include #if defined(__OpenBSD__) -# include +#include #endif #include "../deps/jsmn/jsmn.h" #include "bbs.h" @@ -32,15 +32,14 @@ extern struct user_record gUser; extern int usertimeout; struct chat_msg { - char nick[16]; - char bbstag[16]; - char msg[512]; + char nick[16]; + char bbstag[16]; + char msg[512]; }; - static int jsoneq(const char *json, jsmntok_t *tok, const char *s) { - if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && - strncmp(json + tok->start, s, tok->end - tok->start) == 0) { + if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start && + strncmp(json + tok->start, s, tok->end - tok->start) == 0) { return 0; } return -1; @@ -50,12 +49,12 @@ static char *encapsulate_quote(char *in) { char out[512]; int i = 0; int j = 0; - for (j=0;jcolor; } } - for (x = 0;x<80;x++) { + for (x = 0; x < 80; x++) { screenbuffer[22][x]->c = '\0'; screenbuffer[22][x]->color = color; } @@ -81,14 +80,14 @@ void scroll_up() { void raw(char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - vsnprintf(sbuf, 512, fmt, ap); - va_end(ap); - write(chat_socket, sbuf, strlen(sbuf)); + va_list ap; + va_start(ap, fmt); + vsnprintf(sbuf, 512, fmt, ap); + va_end(ap); + write(chat_socket, sbuf, strlen(sbuf)); } -int hostname_to_ip6(char * hostname , char* ip) { +int hostname_to_ip6(char *hostname, char *ip) { struct addrinfo hints, *res, *p; int status; struct sockaddr_in6 *ipv6; @@ -103,7 +102,7 @@ int hostname_to_ip6(char * hostname , char* ip) { return 1; } - for (p=res; p!= NULL; p=p->ai_next) { + for (p = res; p != NULL; p = p->ai_next) { if (p->ai_family == AF_INET6) { ipv6 = (struct sockaddr_in6 *)p->ai_addr; inet_ntop(p->ai_family, &(ipv6->sin6_addr), ip, INET6_ADDRSTRLEN); @@ -115,7 +114,7 @@ int hostname_to_ip6(char * hostname , char* ip) { return 1; } -int hostname_to_ip(char * hostname , char* ip) { +int hostname_to_ip(char *hostname, char *ip) { struct addrinfo hints, *res, *p; int status; struct sockaddr_in *ipv4; @@ -130,7 +129,7 @@ int hostname_to_ip(char * hostname , char* ip) { return 1; } - for (p=res; p!= NULL; p=p->ai_next) { + for (p = res; p != NULL; p = p->ai_next) { if (p->ai_family == AF_INET) { ipv4 = (struct sockaddr_in *)p->ai_addr; inet_ntop(p->ai_family, &(ipv4->sin_addr), ip, INET_ADDRSTRLEN); @@ -149,15 +148,15 @@ void append_screenbuffer(char *buffer) { int last_pos = 0; int curr_color = 7; - for (z=0;z= 0) && (buffer[z+1] - '0' <= 9 && buffer[z+1] - '0' >= 0)) { - curr_color = (buffer[z] - '0') * 10 + (buffer[z+1] - '0'); - z+=2; + if ((buffer[z] - '0' <= 2 && buffer[z] - '0' >= 0) && (buffer[z + 1] - '0' <= 9 && buffer[z + 1] - '0' >= 0)) { + curr_color = (buffer[z] - '0') * 10 + (buffer[z + 1] - '0'); + z += 2; } else { z--; } @@ -165,23 +164,23 @@ void append_screenbuffer(char *buffer) { if (row_at == 79) { if (line_at == 22) { if (last_space > 0) { - for (i=last_space;i<=row_at;i++) { + for (i = last_space; i <= row_at; i++) { screenbuffer[line_at][i]->c = '\0'; screenbuffer[line_at][i]->color = curr_color; } } scroll_up(); row_at = 0; - for (i=last_pos+1;i= 0) && (buffer[i+1] - '0' <= 9 && buffer[i+1] - '0' >= 0)) { - curr_color = (buffer[i] - '0') * 10 + (buffer[i+1] - '0'); - i+=2; + if ((buffer[i] - '0' <= 2 && buffer[i] - '0' >= 0) && (buffer[i + 1] - '0' <= 9 && buffer[i + 1] - '0' >= 0)) { + curr_color = (buffer[i] - '0') * 10 + (buffer[i + 1] - '0'); + i += 2; } else { i--; } - } + } if (i < strlen(buffer)) { screenbuffer[line_at][row_at]->c = buffer[i]; screenbuffer[line_at][row_at++]->color = curr_color; @@ -191,23 +190,23 @@ void append_screenbuffer(char *buffer) { last_pos = 0; } else { if (last_space > 0) { - for (i=last_space;i<=row_at;i++) { + for (i = last_space; i <= row_at; i++) { screenbuffer[line_at][i]->c = '\0'; screenbuffer[line_at][i]->color = curr_color; } } - line_at++; + line_at++; row_at = 0; - for (i=last_pos+1;i= 0) && (buffer[i+1] - '0' <= 9 && buffer[i+1] - '0' >= 0)) { - curr_color = (buffer[i] - '0') * 10 + (buffer[i+1] - '0'); - i+=2; + if ((buffer[i] - '0' <= 2 && buffer[i] - '0' >= 0) && (buffer[i + 1] - '0' <= 9 && buffer[i + 1] - '0' >= 0)) { + curr_color = (buffer[i] - '0') * 10 + (buffer[i + 1] - '0'); + i += 2; } else { i--; } - } + } if (i < strlen(buffer)) { screenbuffer[line_at][row_at]->c = buffer[i]; screenbuffer[line_at][row_at++]->color = curr_color; @@ -261,9 +260,9 @@ void chat_system(struct user_record *user) { int i; int j; int chat_in; - jsmn_parser parser; - jsmntok_t tokens[8]; - int r; + jsmn_parser parser; + jsmntok_t tokens[8]; + int r; struct chat_msg msg; char *input_b; char *ptr; @@ -284,8 +283,6 @@ void chat_system(struct user_record *user) { return; } - - row_at = 0; line_at = 0; s_putstring("\e[2J\e[23;1H"); @@ -299,13 +296,13 @@ void chat_system(struct user_record *user) { if (!inet_pton(AF_INET6, buffer, &servaddr6.sin6_addr)) { chat_connected = 0; } else { - servaddr6.sin6_family = AF_INET6; - servaddr6.sin6_port = htons(conf.mgchat_port); - if ( (chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { - chat_connected = 0; - } else { - if (connect(chat_socket, (struct sockaddr*)&servaddr6, sizeof(servaddr6)) < 0 ) { - chat_connected = 0; + servaddr6.sin6_family = AF_INET6; + servaddr6.sin6_port = htons(conf.mgchat_port); + if ((chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { + chat_connected = 0; + } else { + if (connect(chat_socket, (struct sockaddr *)&servaddr6, sizeof(servaddr6)) < 0) { + chat_connected = 0; } else { chat_connected = 1; } @@ -315,17 +312,17 @@ void chat_system(struct user_record *user) { chat_connected = 0; } } else { - servaddr6.sin6_family = AF_INET6; + servaddr6.sin6_family = AF_INET6; servaddr6.sin6_port = htons(conf.mgchat_port); - if ( (chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { - chat_connected = 0; - } else { - if (connect(chat_socket, (struct sockaddr*)&servaddr6, sizeof(servaddr6)) < 0 ) { - chat_connected = 0; + if ((chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { + chat_connected = 0; + } else { + if (connect(chat_socket, (struct sockaddr *)&servaddr6, sizeof(servaddr6)) < 0) { + chat_connected = 0; } else { chat_connected = 1; } - } + } } } @@ -336,45 +333,43 @@ void chat_system(struct user_record *user) { if (!inet_pton(AF_INET, buffer, &servaddr.sin_addr)) { return; } else { - servaddr.sin_family = AF_INET; - servaddr.sin_port = htons(conf.mgchat_port); - if ( (chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - return; - } - if (connect(chat_socket, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0 ) { - return; - } + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(conf.mgchat_port); + if ((chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + return; + } + if (connect(chat_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { + return; + } } } else { return; } } else { - servaddr.sin_family = AF_INET; + servaddr.sin_family = AF_INET; servaddr.sin_port = htons(conf.mgchat_port); - if ( (chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - return; - } - if (connect(chat_socket, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0 ) { - return; - } + if ((chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + return; + } + if (connect(chat_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { + return; + } } } - - memset(buffer, 0, 513); screenbuffer = (struct character_t ***)malloc(sizeof(struct character_t **) * 23); - for (i=0;i<23;i++) { + for (i = 0; i < 23; i++) { screenbuffer[i] = (struct character_t **)malloc(sizeof(struct character_t *) * 80); - for (z=0;z<80;z++) { + for (z = 0; z < 80; z++) { screenbuffer[i][z] = (struct character_t *)malloc(sizeof(struct character_t)); screenbuffer[i][z]->c = '\0'; screenbuffer[i][z]->color = 7; } } memset(partmessage, 0, 1024); - + raw("{ \"bbs\": \"%s\", \"nick\": \"%s\", \"msg\": \"LOGIN\" }\n", conf.mgchat_bbstag, user->loginname); while (1) { @@ -397,14 +392,14 @@ void chat_system(struct user_record *user) { close(chat_socket); disconnect("Socket closed"); } - + usertimeout = 10; - + if (c == '\r') { if (inputbuffer[0] == '/') { if (strcasecmp(&inputbuffer[1], "quit") == 0) { close(chat_socket); - for (i=0;i<22;i++) { + for (i = 0; i < 22; i++) { free(screenbuffer[i]); } free(screenbuffer); @@ -437,47 +432,47 @@ void chat_system(struct user_record *user) { len = read(chat_socket, readbuffer, 512); if (len == 0) { s_putstring("\r\n\r\n\r\nLost connection to chat server!\r\n"); - for (i=0;i<22;i++) { + for (i = 0; i < 22; i++) { free(screenbuffer[i]); } free(screenbuffer); return; } - + strncat(partmessage, readbuffer, len); strcpy(readbuffer, partmessage); y = 0; - for (z = 0;z < strlen(readbuffer); z++) { + for (z = 0; z < strlen(readbuffer); z++) { if (readbuffer[z] != '\n') { message[y] = readbuffer[z]; - message[y+1] = '\0'; + message[y + 1] = '\0'; y++; } else { - + y = 0; // json parse - jsmn_init(&parser); + jsmn_init(&parser); // we got some data from a client - r = jsmn_parse(&parser, message, strlen(message), tokens, sizeof(tokens)/sizeof(tokens[0])); - - if ((r < 0) || (r < 1 || tokens[0].type != JSMN_OBJECT)) { + r = jsmn_parse(&parser, message, strlen(message), tokens, sizeof(tokens) / sizeof(tokens[0])); + + if ((r < 0) || (r < 1 || tokens[0].type != JSMN_OBJECT)) { // invalid json } else { for (j = 1; j < r; j++) { if (jsoneq(message, &tokens[j], "bbs") == 0) { - sprintf(msg.bbstag, "%.*s", tokens[j+1].end-tokens[j+1].start, message + tokens[j+1].start); + sprintf(msg.bbstag, "%.*s", tokens[j + 1].end - tokens[j + 1].start, message + tokens[j + 1].start); j++; } if (jsoneq(message, &tokens[j], "nick") == 0) { - sprintf(msg.nick, "%.*s", tokens[j+1].end-tokens[j+1].start, message + tokens[j+1].start); + sprintf(msg.nick, "%.*s", tokens[j + 1].end - tokens[j + 1].start, message + tokens[j + 1].start); j++; } if (jsoneq(message, &tokens[j], "msg") == 0) { - sprintf(msg.msg, "%.*s", tokens[j+1].end-tokens[j+1].start, message + tokens[j+1].start); + sprintf(msg.msg, "%.*s", tokens[j + 1].end - tokens[j + 1].start, message + tokens[j + 1].start); j++; - } - } + } + } } // set outputbuffer if (strcmp(msg.bbstag, "SYSTEM") == 0 && strcmp(msg.nick, "SYSTEM") == 0) { @@ -493,11 +488,9 @@ void chat_system(struct user_record *user) { append_screenbuffer(outputbuffer); do_update = 1; - memset(buffer, 0, 513); - buffer_at = 0; + buffer_at = 0; } - } if (z < len) { memset(partmessage, 0, 1024); @@ -509,8 +502,8 @@ void chat_system(struct user_record *user) { } if (do_update == 1) { s_putstring("\e[2J\e[1;1H"); - for (i=0;i<=line_at;i++) { - for (z = 0;z < 80; z++) { + for (i = 0; i <= line_at; i++) { + for (z = 0; z < 80; z++) { if (screenbuffer[i][z]->color != last_color) { switch (screenbuffer[i][z]->color) { case 0: @@ -572,7 +565,7 @@ void chat_system(struct user_record *user) { } s_printf("\r\n"); } - for (i=line_at+1;i<22;i++) { + for (i = line_at + 1; i < 22; i++) { s_putstring("\r\n"); } s_putstring(get_string(50)); diff --git a/src/doors.c b/src/doors.c index a4b49ce..c36ef1c 100644 --- a/src/doors.c +++ b/src/doors.c @@ -11,13 +11,13 @@ #include #include #if defined(linux) -# include +#include #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) -# include +#include #elif defined(__FreeBSD__) -# include +#include #elif defined(__sun) -# include "os/sunos.h" +#include "os/sunos.h" #endif #include "bbs.h" #include "lua/lua.h" @@ -36,10 +36,10 @@ int running_door = 0; extern int telnet_bin_mode; extern int timeoutpaused; -void doorchld_handler(int s) -{ - // waitpid() might overwrite errno, so we save and restore it: - while(waitpid(-1, NULL, WNOHANG) > 0); +void doorchld_handler(int s) { + // waitpid() might overwrite errno, so we save and restore it: + while (waitpid(-1, NULL, WNOHANG) > 0) + ; running_door = 0; } @@ -66,9 +66,9 @@ int write_door32sys(struct user_record *user) { return 1; } - fprintf(fptr, "2\r\n"); // telnet type + fprintf(fptr, "2\r\n"); // telnet type fprintf(fptr, "%d\r\n", gSocket); // socket - fprintf(fptr, "38400\r\n"); // baudrate + fprintf(fptr, "38400\r\n"); // baudrate fprintf(fptr, "Magicka %d.%d\r\n", VERSION_MAJOR, VERSION_MINOR); fprintf(fptr, "%d\r\n", user->id); fprintf(fptr, "%s %s\r\n", user->firstname, user->lastname); @@ -95,9 +95,9 @@ int write_door32sys(struct user_record *user) { ptr = NULL; - for (i=0;isec_level); fprintf(fptr, "%d\r\n", user->timeleft); fprintf(fptr, "-1\r\n"); - + fclose(fptr); // create door.sys @@ -173,7 +173,7 @@ int write_door32sys(struct user_record *user) { fprintf(fptr, "none\r\n"); fprintf(fptr, "Y\r\n"); fprintf(fptr, "N\r\n"); - fprintf(fptr, "Y\r\n"); + fprintf(fptr, "Y\r\n"); fprintf(fptr, "7\r\n"); fprintf(fptr, "0\r\n"); fprintf(fptr, "01-01-1971\r\n"); @@ -192,13 +192,11 @@ int write_door32sys(struct user_record *user) { return 0; } - - void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage) { char *arguments[4]; int door_out; char buffer[10]; - + if (sshBBS) { door_out = STDOUT_FILENO; } else { @@ -209,17 +207,17 @@ void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage) { arguments[1] = strdup(buffer); sprintf(buffer, "%d", door_out); arguments[2] = strdup(buffer); - arguments[3] = NULL; - + arguments[3] = NULL; + runexternal(user, cmd, stdio, arguments, NULL, 0, codepage); - + free(arguments[0]); free(arguments[1]); free(arguments[2]); } void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], char *cwd, int raw, char *codepage) { - + char buffer[1024]; int ret; unsigned char c; @@ -276,8 +274,6 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c door_out = gSocket; } - - ws.ws_row = 24; ws.ws_col = 80; @@ -306,8 +302,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c close(master); dup2(slave, 0); - dup2(slave, 1); - + dup2(slave, 1); + close(slave); setsid(); @@ -319,8 +315,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c running_door_pid = pid; gotiac = 0; flush = 0; - - while(running_door || !flush) { + + while (running_door || !flush) { FD_ZERO(&fdset); FD_SET(master, &fdset); FD_SET(door_in, &fdset); @@ -329,10 +325,10 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c } else { t = door_in + 1; } - + thetimeout.tv_sec = 5; thetimeout.tv_usec = 0; - + ret = select(t, &fdset, NULL, NULL, &thetimeout); if (ret > 0) { if (FD_ISSET(door_in, &fdset)) { @@ -343,7 +339,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c return; } g = 0; - for (h=0;hcodepage == 0) || (strcmp(codepage, "UTF-8") == 0 && user->codepage == 1)) { write(door_out, outbuf, g); @@ -472,7 +468,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c } write(door_out, ptr2p, ptr2 - ptr2p); - free(ptr2p); + free(ptr2p); iconv_close(ic); } } @@ -482,16 +478,16 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c } } } - } + } } - + } else { if (raw) { ttySetRaw(STDIN_FILENO, &oldit); ttySetRaw(STDOUT_FILENO, &oldot); - } - + } + sa.sa_handler = doorchld_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART | SA_SIGINFO; @@ -510,11 +506,11 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c dup2(bbs_stderr, 2); execvp(cmd, argv); } else { - while(running_door) { + while (running_door) { sleep(1); } } - + if (raw) { tcsetattr(STDIN_FILENO, TCSANOW, &oldit); tcsetattr(STDOUT_FILENO, TCSANOW, &oldot); @@ -523,13 +519,13 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c } else { if (!sshBBS) { snprintf(buffer, 1024, "%s", cmd); - for (i=1;argv[i] != NULL; i++) { + for (i = 1; argv[i] != NULL; i++) { snprintf(&buffer[strlen(buffer)], 1024 - strlen(buffer), " %s", argv[i]); } if (cwd != NULL) { chdir(cwd); } - args = (char **)malloc(sizeof (char *)); + args = (char **)malloc(sizeof(char *)); arg_count = 0; args[arg_count] = strtok(buffer, " "); while (args[arg_count] != NULL) { diff --git a/src/email.c b/src/email.c index 06b30b7..bdeb07e 100644 --- a/src/email.c +++ b/src/email.c @@ -22,22 +22,22 @@ void commit_email(char *recipient, char *subject, char *msg) { char buffer[PATH_MAX]; sqlite3 *db; sqlite3_stmt *res; - int rc; + int rc; char *csql = "CREATE TABLE IF NOT EXISTS email (" - "id INTEGER PRIMARY KEY," - "sender TEXT COLLATE NOCASE," - "recipient TEXT COLLATE NOCASE," - "subject TEXT," - "body TEXT," - "date INTEGER," - "seen INTEGER);"; + "id INTEGER PRIMARY KEY," + "sender TEXT COLLATE NOCASE," + "recipient TEXT COLLATE NOCASE," + "subject TEXT," + "body TEXT," + "date INTEGER," + "seen INTEGER);"; char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; char *err_msg = 0; snprintf(buffer, PATH_MAX, "%s/email.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { dolog("Cannot open database: %s", sqlite3_errmsg(db)); return; @@ -45,7 +45,7 @@ void commit_email(char *recipient, char *subject, char *msg) { sqlite3_busy_timeout(db, 5000); rc = sqlite3_exec(db, csql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { + if (rc != SQLITE_OK) { dolog("SQL error: %s", err_msg); @@ -78,10 +78,9 @@ void commit_email(char *recipient, char *subject, char *msg) { void send_email(struct user_record *user) { char buffer[26]; - char *recipient; - char *subject; - char *msg; - + char *recipient; + char *subject; + char *msg; s_printf(get_string(54)); s_readstring(buffer, 16); @@ -112,13 +111,13 @@ void send_email(struct user_record *user) { commit_email(recipient, subject, msg); free(msg); } - free(subject); - free(recipient); + free(subject); + free(recipient); } void show_email(struct user_record *user, int msgno, int email_count, struct email_msg **emails) { - char buffer[256]; - sqlite3 *db; + char buffer[256]; + sqlite3 *db; sqlite3_stmt *res; int rc; char *dsql = "DELETE FROM email WHERE id=?"; @@ -155,101 +154,100 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema lines = 0; chars = 0; - - - msg_line_count = 0; - start_line = 0; - - // count the number of lines... - for (z=0;zbody);z++) { - if (emails[msgno]->body[z] == '\r' || chars == 79) { - if (msg_line_count == 0) { - msg_lines = (char **)malloc(sizeof(char *)); - } else { - msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1)); - } - - msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1)); - - if (z == start_line) { - msg_lines[msg_line_count][0] = '\0'; - } else { - strncpy(msg_lines[msg_line_count], &emails[msgno]->body[start_line], z - start_line); - msg_lines[msg_line_count][z-start_line] = '\0'; - } - msg_line_count++; - if (emails[msgno]->body[z] == '\r') { - start_line = z + 1; - } else { - start_line = z; - } - chars = 0; - } else { - chars ++; - } - } - - lines = 0; - - position = 0; - should_break = 0; - - while (!should_break) { - s_printf("\e[5;1H"); - for (z=position;z= 17) { - break; - } - } - s_printf(get_string(187)); - s_printf(get_string(191)); - c = s_getchar(); - - if (tolower(c) == 'r') { - should_break = 1; - } else if (tolower(c) == 'q') { - should_break = 1; - quit = 1; + + msg_line_count = 0; + start_line = 0; + + // count the number of lines... + for (z = 0; z < strlen(emails[msgno]->body); z++) { + if (emails[msgno]->body[z] == '\r' || chars == 79) { + if (msg_line_count == 0) { + msg_lines = (char **)malloc(sizeof(char *)); + } else { + msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1)); + } + + msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1)); + + if (z == start_line) { + msg_lines[msg_line_count][0] = '\0'; + } else { + strncpy(msg_lines[msg_line_count], &emails[msgno]->body[start_line], z - start_line); + msg_lines[msg_line_count][z - start_line] = '\0'; + } + msg_line_count++; + if (emails[msgno]->body[z] == '\r') { + start_line = z + 1; + } else { + start_line = z; + } + chars = 0; + } else { + chars++; + } + } + + lines = 0; + + position = 0; + should_break = 0; + + while (!should_break) { + s_printf("\e[5;1H"); + for (z = position; z < msg_line_count; z++) { + + s_printf("%s\e[K\r\n", msg_lines[z]); + + if (z - position >= 17) { + break; + } + } + s_printf(get_string(187)); + s_printf(get_string(191)); + c = s_getchar(); + + if (tolower(c) == 'r') { + should_break = 1; + } else if (tolower(c) == 'q') { + should_break = 1; + quit = 1; } else if (tolower(c) == 'd') { should_break = 1; - } else if (c == '\e') { - c = s_getchar(); - if (c == 91) { - c = s_getchar(); - if (c == 65) { - position--; - if (position < 0) { - position = 0; - } - } else if (c == 66) { - position++; - if (position + 17 >= msg_line_count) { - position--; - } - } else if (c == 67) { + } else if (c == '\e') { + c = s_getchar(); + if (c == 91) { + c = s_getchar(); + if (c == 65) { + position--; + if (position < 0) { + position = 0; + } + } else if (c == 66) { + position++; + if (position + 17 >= msg_line_count) { + position--; + } + } else if (c == 67) { c = ' '; should_break = 1; } else if (c == 68) { c = 'b'; should_break = 1; } - } - } - } + } + } + } + + for (i = 0; i < msg_line_count; i++) { + free(msg_lines[i]); + } + free(msg_lines); + msg_line_count = 0; - for (i=0;isubject != NULL) { @@ -286,7 +283,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema replybody = external_editor(user, user->loginname, emails[msgno]->from, emails[msgno]->body, strlen(emails[msgno]->body), emails[msgno]->from, subject, 1, 0); if (replybody != NULL) { - sprintf(buffer, "%s/email.sq3", conf.bbs_path); + sprintf(buffer, "%s/email.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { @@ -329,7 +326,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema exit(1); } - sqlite3_busy_timeout(db, 5000); + sqlite3_busy_timeout(db, 5000); rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0); if (rc == SQLITE_OK) { @@ -341,12 +338,12 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema return; } sqlite3_step(res); - + sqlite3_finalize(res); sqlite3_close(db); quit = 1; } else if (tolower(c) == ' ') { - msgno ++; + msgno++; if (msgno == email_count) { quit = 1; } @@ -356,7 +353,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema quit = 1; } } - } + } } void list_emails(struct user_record *user) { @@ -380,8 +377,8 @@ void list_emails(struct user_record *user) { rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); exit(1); } sqlite3_busy_timeout(db, 5000); @@ -406,9 +403,9 @@ void list_emails(struct user_record *user) { } else { emails = (struct email_msg **)realloc(emails, sizeof(struct email_msg *) * (email_count + 1)); } - + emails[email_count] = (struct email_msg *)malloc(sizeof(struct email_msg)); - + emails[email_count]->from = strdup((char *)sqlite3_column_text(res, 0)); emails[email_count]->subject = strdup((char *)sqlite3_column_text(res, 1)); emails[email_count]->seen = sqlite3_column_int(res, 2); @@ -417,49 +414,49 @@ void list_emails(struct user_record *user) { emails[email_count]->id = sqlite3_column_int(res, 5); email_count++; } - + sqlite3_finalize(res); sqlite3_close(db); - + if (email_count == 0) { s_printf(get_string(194)); return; } - + redraw = 1; start = 0; position = 0; while (!closed) { if (redraw) { s_printf(get_string(126)); - for (i=start;idate, &msg_date); if (i == position) { if (!emails[i]->seen) { if (conf.date_style == 1) { - s_printf(get_string(192), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(192), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(192), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(192), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } else { if (conf.date_style == 1) { - s_printf(get_string(193), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(193), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(193), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(193), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } } else { if (!emails[i]->seen) { if (conf.date_style == 1) { - s_printf(get_string(64), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(64), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(64), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(64), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } else { if (conf.date_style == 1) { - s_printf(get_string(65), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(65), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(65), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(65), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } } @@ -490,20 +487,20 @@ void list_emails(struct user_record *user) { s_printf("\e[%d;5H", position - start + 2); } else if (!redraw) { s_printf("\e[%d;1H", position - start + 1); - localtime_r((time_t *)&emails[position-1]->date, &msg_date); + localtime_r((time_t *)&emails[position - 1]->date, &msg_date); if (!emails[position - 1]->seen) { if (conf.date_style == 1) { - s_printf(get_string(64), position, emails[position-1]->subject, emails[position-1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(64), position, emails[position - 1]->subject, emails[position - 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(64), position, emails[position-1]->subject, emails[position-1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(64), position, emails[position - 1]->subject, emails[position - 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } else { if (conf.date_style == 1) { - s_printf(get_string(65), position, emails[position-1]->subject, emails[position-1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(65), position, emails[position - 1]->subject, emails[position - 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(65), position, emails[position-1]->subject, emails[position-1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(65), position, emails[position - 1]->subject, emails[position - 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - } + } s_printf("\e[%d;1H", position - start + 2); localtime_r((time_t *)&emails[position]->date, &msg_date); if (!emails[position]->seen) { @@ -518,14 +515,14 @@ void list_emails(struct user_record *user) { } else { s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - } + } s_printf("\e[%d;5H", position - start + 2); } } else if (c == 65) { // up position--; if (position < start) { - start -=22; + start -= 22; if (start < 0) { start = 0; } @@ -550,7 +547,7 @@ void list_emails(struct user_record *user) { } else { s_printf(get_string(65), position + 2, emails[position + 1]->subject, emails[position + 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - } + } s_printf("\e[%d;1H", position - start + 2); localtime_r((time_t *)&emails[position]->date, &msg_date); if (!emails[position]->seen) { @@ -565,9 +562,9 @@ void list_emails(struct user_record *user) { } else { s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - } + } s_printf("\e[%d;5H", position - start + 3); - } + } } else if (c == 75) { // END KEY position = email_count - 1; @@ -599,7 +596,7 @@ void list_emails(struct user_record *user) { // PAGE DOWN position = position + 22; if (position >= email_count) { - position = email_count -1; + position = email_count - 1; } start = position; redraw = 1; @@ -609,9 +606,9 @@ void list_emails(struct user_record *user) { closed = 1; show_email(user, position, email_count, emails); } - } - - for (i=0;ifrom); free(emails[i]->subject); free(emails[i]->body); @@ -620,40 +617,39 @@ void list_emails(struct user_record *user) { free(emails); } - int mail_getemailcount(struct user_record *user) { char *sql = "SELECT COUNT(*) FROM email WHERE recipient LIKE ?"; int count; char buffer[256]; sqlite3 *db; - sqlite3_stmt *res; - int rc; + sqlite3_stmt *res; + int rc; sprintf(buffer, "%s/email.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } - sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + exit(1); + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, user->loginname, -1, 0); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, user->loginname, -1, 0); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); 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); } diff --git a/src/files.c b/src/files.c index 97e40ad..511273f 100644 --- a/src/files.c +++ b/src/files.c @@ -50,30 +50,30 @@ struct tagged_file **tagged_files; int tagged_count = 0; int ttySetRaw(int fd, struct termios *prevTermios) { - struct termios t; + struct termios t; - if (tcgetattr(fd, &t) == -1) - return -1; + if (tcgetattr(fd, &t) == -1) + return -1; - if (prevTermios != NULL) - *prevTermios = t; + if (prevTermios != NULL) + *prevTermios = t; - t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO); - t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP | IXON | PARMRK); - t.c_oflag &= ~OPOST; - t.c_cc[VMIN] = 1; - t.c_cc[VTIME] = 0; + t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO); + t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP | IXON | PARMRK); + t.c_oflag &= ~OPOST; + t.c_cc[VMIN] = 1; + t.c_cc[VTIME] = 0; - if (tcsetattr(fd, TCSAFLUSH, &t) == -1) - return -1; + if (tcsetattr(fd, TCSAFLUSH, &t) == -1) + return -1; - return 0; + return 0; } int ZXmitStr(u_char *str, int len, ZModem *info) { int i; - for (i=0;iofd, &str[i], 1) == 0) { return ZmErrSys; @@ -94,18 +94,18 @@ void ZOFlush(ZModem *info) { } int ZAttn(ZModem *info) { - char *ptr ; + char *ptr; - if( info->attn == NULL ) - return 0 ; + if (info->attn == NULL) + return 0; - for(ptr = info->attn; *ptr != '\0'; ++ptr) { - if( *ptr == ATTNBRK ) { + for (ptr = info->attn; *ptr != '\0'; ++ptr) { + if (*ptr == ATTNBRK) { - } else if( *ptr == ATTNPSE ) { + } else if (*ptr == ATTNPSE) { sleep(1); } else { - write(info->ifd, ptr, 1) ; + write(info->ifd, ptr, 1); } } return 0; @@ -117,7 +117,6 @@ void ZFlowControl(int onoff, ZModem *info) { void ZStatus(int type, int value, char *status) { } - char *upload_path; char upload_filename[1024]; @@ -136,11 +135,11 @@ FILE *ZOpenFile(char *name, u_long crc, ZModem *info) { return fptr; } -int ZWriteFile(u_char *buffer, int len, FILE *file, ZModem *info) { +int ZWriteFile(u_char *buffer, int len, FILE *file, ZModem *info) { return fwrite(buffer, 1, len, file) == len ? 0 : ZmErrSys; } -int ZCloseFile(ZModem *info) { +int ZCloseFile(ZModem *info) { fclose(info->file); return 0; } @@ -153,25 +152,25 @@ int doIO(ZModem *zm) { struct timeval timeout; u_char buffer[2048]; u_char buffer2[1024]; - int len; + int len; int pos; int done = 0; - int i; + int i; int j; char iac_binary_will[] = {IAC, IAC_WILL, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_do[] = {IAC, IAC_DO, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_wont[] = {IAC, IAC_WONT, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_dont[] = {IAC, IAC_DONT, IAC_TRANSMIT_BINARY, '\0'}; - while(!done) { + 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) ; + 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) ; + if (i == 0) { + done = ZmodemTimeout(zm); } else if (i > 0) { len = read(zm->ifd, buffer, 2048); if (len == 0) { @@ -179,34 +178,34 @@ int doIO(ZModem *zm) { } pos = 0; - for (j=0;j 0) { - done = ZmodemRcv(buffer2, pos, zm) ; + done = ZmodemRcv(buffer2, pos, zm); } } else { // SIG INT catch @@ -281,7 +280,7 @@ void upload_zmodem(struct user_record *user, char *upload_p) { if (sshBBS) { tcsetattr(STDIN_FILENO, TCSANOW, &oldit); tcsetattr(STDOUT_FILENO, TCSANOW, &oldot); - } + } } char *get_file_id_diz(char *filename) { @@ -304,29 +303,29 @@ char *get_file_id_diz(char *filename) { char *cmd; ext = 0; arch = -1; - - for (i=strlen(filename)-1;i>=0;i--) { + + for (i = strlen(filename) - 1; i >= 0; i--) { if (filename[i] == '.') { ext = i + 1; break; } } - + if (ext == 0) { return NULL; } - - for (i=0;iextension) == 0) { arch = i; break; } } - + if (arch == -1) { return NULL; } - + snprintf(buffer, 1024, "%s/node%d", conf.bbs_path, mynode); if (stat(buffer, &s) != 0) { mkdir(buffer, 0755); @@ -334,16 +333,16 @@ char *get_file_id_diz(char *filename) { snprintf(buffer, 1024, "%s/node%d/temp", conf.bbs_path, mynode); if (stat(buffer, &s) == 0) { - + if (recursive_delete(buffer) != 0) { return NULL; } } - + mkdir(buffer, 0755); - + bpos = 0; - for (i=0;iunpack);i++) { + for (i = 0; i < strlen(conf.archivers[arch]->unpack); i++) { if (conf.archivers[arch]->unpack[i] == '*') { i++; if (conf.archivers[arch]->unpack[i] == 'a') { @@ -351,7 +350,7 @@ char *get_file_id_diz(char *filename) { bpos = strlen(buffer); } else if (conf.archivers[arch]->unpack[i] == 'd') { sprintf(&buffer[bpos], "%s/node%d/temp/", conf.bbs_path, mynode); - bpos = strlen(buffer); + bpos = strlen(buffer); } else if (conf.archivers[arch]->unpack[i] == '*') { buffer[bpos++] = '*'; buffer[bpos] = '\0'; @@ -361,17 +360,17 @@ char *get_file_id_diz(char *filename) { buffer[bpos] = '\0'; } } - + if (sshBBS) { stout = dup(STDOUT_FILENO); stin = dup(STDIN_FILENO); sterr = dup(STDERR_FILENO); - + dup2(bbs_stdout, STDOUT_FILENO); dup2(bbs_stderr, STDERR_FILENO); dup2(bbs_stdin, STDIN_FILENO); } - args = (char **)malloc(sizeof (char *)); + args = (char **)malloc(sizeof(char *)); arg_count = 0; args[arg_count] = strtok(buffer, " "); while (args[arg_count] != NULL) { @@ -391,18 +390,18 @@ char *get_file_id_diz(char *filename) { } free(cmd); free(args); - + if (sshBBS) { - + dup2(stout, STDOUT_FILENO); - dup2(sterr, STDERR_FILENO); + dup2(sterr, STDERR_FILENO); dup2(stin, STDIN_FILENO); - + close(stin); close(stout); close(sterr); } - + snprintf(buffer, 1024, "%s/node%d/temp/FILE_ID.DIZ", conf.bbs_path, mynode); if (stat(buffer, &s) != 0) { snprintf(buffer, 1024, "%s/node%d/temp/file_id.diz", conf.bbs_path, mynode); @@ -412,30 +411,29 @@ char *get_file_id_diz(char *filename) { return NULL; } } - + description = (char *)malloc(s.st_size + 1); - + fptr = fopen(buffer, "rb"); - + fread(description, 1, s.st_size, fptr); description[s.st_size] = '\0'; fclose(fptr); - + bpos = 0; len = strlen(description); - for (i=0;idefprotocol - 1]->download);i++) { + for (i = 0; i < strlen(conf.protocols[user->defprotocol - 1]->download); i++) { if (conf.protocols[user->defprotocol - 1]->download[i] == '*') { i++; if (conf.protocols[user->defprotocol - 1]->download[i] == '*') { @@ -482,7 +480,7 @@ int do_download(struct user_record *user, char *file) { } else if (conf.protocols[user->defprotocol - 1]->download[i] == 'f') { sprintf(&download_command[bpos], "%s", file); bpos = strlen(download_command); - + continue; } else if (conf.protocols[user->defprotocol - 1]->download[i] == 's') { if (!sshBBS) { @@ -493,7 +491,7 @@ int do_download(struct user_record *user, char *file) { return 0; } } - + } else { download_command[bpos++] = conf.protocols[user->defprotocol - 1]->download[i]; download_command[bpos] = '\0'; @@ -501,7 +499,7 @@ int do_download(struct user_record *user, char *file) { } argc = 1; last_char_space = 0; - for (i=0;idefprotocol - 1]->stdio, arguments, conf.bbs_path, 1, NULL); - - free(arguments); + + free(arguments); } return 1; } @@ -572,14 +570,14 @@ int do_upload(struct user_record *user, char *final_path) { timeoutpaused = 0; return 1; } else { - + if (conf.protocols[user->defprotocol - 1]->upload_prompt) { s_printf(get_string(210)); s_readstring(buffer3, 256); s_printf("\r\n"); } bpos = 0; - for (i=0;idefprotocol - 1]->upload);i++) { + for (i = 0; i < strlen(conf.protocols[user->defprotocol - 1]->upload); i++) { if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') { i++; if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') { @@ -601,7 +599,7 @@ int do_upload(struct user_record *user, char *final_path) { return 0; } } - + } else { upload_command[bpos++] = conf.protocols[user->defprotocol - 1]->upload[i]; upload_command[bpos] = '\0'; @@ -609,7 +607,7 @@ int do_upload(struct user_record *user, char *final_path) { } argc = 1; last_char_space = 0; - for (i=0;idefprotocol - 1]->stdio, arguments, upload_path, 1, NULL); - + free(arguments); - + if (conf.protocols[user->defprotocol - 1]->upload_prompt) { snprintf(upload_command, 1024, "%s%s", upload_path, buffer3); if (stat(upload_command, &s) != 0) { recursive_delete(upload_path); return 0; } - + snprintf(upload_filename, 1024, "%s/%s", final_path, buffer3); if (stat(upload_filename, &s) == 0) { recursive_delete(upload_path); @@ -673,9 +671,9 @@ int do_upload(struct user_record *user, char *final_path) { } if (copy_file(upload_command, upload_filename) != 0) { recursive_delete(upload_path); - return 0; + return 0; } - + recursive_delete(upload_path); return 1; } else { @@ -693,24 +691,23 @@ int do_upload(struct user_record *user, char *final_path) { #endif snprintf(upload_command, 1024, "%s%s", upload_path, dent->d_name); snprintf(upload_filename, 1024, "%s/%s", final_path, dent->d_name); - + if (stat(upload_filename, &s) == 0) { recursive_delete(upload_path); s_printf(get_string(214)); closedir(inb); return 0; } - + if (copy_file(upload_command, upload_filename) != 0) { recursive_delete(upload_path); closedir(inb); - return 0; + return 0; } closedir(inb); recursive_delete(upload_path); return 1; } - } closedir(inb); @@ -725,13 +722,13 @@ void upload(struct user_record *user) { int i; char *create_sql = "CREATE TABLE IF NOT EXISTS files (" - "Id INTEGER PRIMARY KEY," - "filename TEXT," - "description TEXT," - "size INTEGER," - "dlcount INTEGER," - "uploaddate INTEGER," - "approved INTEGER);"; + "Id INTEGER PRIMARY KEY," + "filename TEXT," + "description TEXT," + "size INTEGER," + "dlcount INTEGER," + "uploaddate INTEGER," + "approved INTEGER);"; char *sql = "INSERT INTO files (filename, description, size, dlcount, approved, uploaddate) VALUES(?, ?, ?, 0, 0, ?)"; sqlite3 *db; sqlite3_stmt *res; @@ -740,22 +737,22 @@ void upload(struct user_record *user) { char *err_msg = NULL; char *description; time_t curtime; - + if (!do_upload(user, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_path)) { s_printf(get_string(211)); return; } - + description = NULL; - + s_printf(get_string(198)); description = get_file_id_diz(upload_filename); - + if (description == NULL) { s_printf(get_string(199)); s_printf(get_string(200)); buffer[0] = '\0'; - for (i=0;i<5;i++) { + for (i = 0; i < 5; i++) { s_printf("\r\n%d: ", i); s_readstring(buffer2, 65); if (strlen(buffer2) == 0) { @@ -773,62 +770,62 @@ void upload(struct user_record *user) { rc = sqlite3_open(buffer3, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + exit(1); + } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { - dolog("SQL error: %s", err_msg); - sqlite3_free(err_msg); - sqlite3_close(db); + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); + if (rc != SQLITE_OK) { + dolog("SQL error: %s", err_msg); + sqlite3_free(err_msg); + sqlite3_close(db); if (description != NULL) { free(description); - } - return; - } - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + } + 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); - if (description == NULL) { + sqlite3_bind_text(res, 1, upload_filename, -1, 0); + if (description == NULL) { sqlite3_bind_text(res, 2, buffer, -1, 0); } else { sqlite3_bind_text(res, 2, description, -1, 0); } - sqlite3_bind_int(res, 3, s.st_size); - curtime = time(NULL); - sqlite3_bind_int(res, 4, curtime); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + sqlite3_bind_int(res, 3, s.st_size); + curtime = time(NULL); + sqlite3_bind_int(res, 4, curtime); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); if (description != NULL) { free(description); } return; - } + } - rc = sqlite3_step(res); + rc = sqlite3_step(res); - if (rc != SQLITE_DONE) { - dolog("execution failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(res); + if (rc != SQLITE_DONE) { + dolog("execution failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(res); sqlite3_close(db); if (description != NULL) { free(description); - } + } return; - } - sqlite3_finalize(res); - sqlite3_close(db); - if (description != NULL) { + } + sqlite3_finalize(res); + sqlite3_close(db); + if (description != NULL) { free(description); } - + s_printf(get_string(202)); s_printf(get_string(6)); s_getc(); @@ -836,7 +833,7 @@ void upload(struct user_record *user) { void download_zmodem(struct user_record *user, char *filename) { ZModem zm; - int done ; + int done; dolog("Attempting to upload %s", filename); @@ -856,39 +853,38 @@ void download_zmodem(struct user_record *user, char *filename) { zm.packetsize = 1024; - - ZmodemTInit(&zm) ; + ZmodemTInit(&zm); done = doIO(&zm); - if ( done != ZmDone ) { + if (done != ZmDone) { return; } - done = ZmodemTFile(filename, basename(filename), ZCBIN,0,0,0,0,0, &zm) ; + done = ZmodemTFile(filename, basename(filename), ZCBIN, 0, 0, 0, 0, 0, &zm); - switch( done ) { - case 0: - break ; + switch (done) { + case 0: + break; - case ZmErrCantOpen: - dolog("cannot open file \"%s\": %s", filename, strerror(errno)) ; - return; + case ZmErrCantOpen: + dolog("cannot open file \"%s\": %s", filename, strerror(errno)); + return; - case ZmFileTooLong: - dolog("filename \"%s\" too long, skipping...", filename) ; - return; + case ZmFileTooLong: + dolog("filename \"%s\" too long, skipping...", filename); + return; - case ZmDone: - return; + case ZmDone: + return; - default: - return; + default: + return; } if (!done) { done = doIO(&zm); } - if ( done != ZmDone ) { + if (done != ZmDone) { return; } @@ -899,17 +895,16 @@ void download_zmodem(struct user_record *user, char *filename) { } } - void genurls() { -#if defined(ENABLE_WWW) +#if defined(ENABLE_WWW) int i; char *url; if (conf.www_server) { - for (i=0;idir, tagged_files[i]->sub, tagged_files[i]->fid); @@ -922,12 +917,12 @@ void genurls() { s_printf(get_string(257)); } } - for (i=0;ifilename); free(tagged_files[i]); } free(tagged_files); - tagged_count = 0; + tagged_count = 0; s_printf(get_string(6)); s_getc(); } else { @@ -939,10 +934,9 @@ void genurls() { s_printf(get_string(258)); s_printf(get_string(6)); s_getc(); -#endif +#endif } - void download(struct user_record *user) { int i; char *ssql = "select dlcount from files where filename like ?"; @@ -953,8 +947,7 @@ void download(struct user_record *user) { sqlite3_stmt *res; int rc; - - for (i=0;ifilename)); do_download(user, tagged_files[i]->filename); @@ -1005,9 +998,7 @@ void download(struct user_record *user) { sqlite3_close(db); } - - - for (i=0;ifilename); free(tagged_files[i]); } @@ -1025,10 +1016,10 @@ void do_list_files(struct file_entry **files_e, int files_c) { int k; int match; char buffer[6]; - + s_printf("\r\n"); - - for (i=0;isize; if (file_size > 1024 * 1024 * 1024) { file_size = file_size / 1024 / 1024 / 1024; @@ -1047,8 +1038,8 @@ void do_list_files(struct file_entry **files_e, int files_c) { } else { s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); } - lines+=3; - for (j=0;jdescription);j++) { + lines += 3; + for (j = 0; j < strlen(files_e[i]->description); j++) { if (files_e[i]->description[j] == '\n') { s_printf("\r\n"); lines++; @@ -1061,7 +1052,7 @@ void do_list_files(struct file_entry **files_e, int files_c) { s_printf("\r\n"); break; } else if (tolower(buffer[0]) == 'q') { - for (z=0;zfilename); free(files_e[z]->description); free(files_e[z]); @@ -1069,12 +1060,12 @@ void do_list_files(struct file_entry **files_e, int files_c) { free(files_e); s_printf("\r\n"); return; - } else { + } else { z = atoi(buffer); if (z >= 0 && z < files_c) { if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { match = 0; - for (k=0;kfilename, files_e[z]->filename) == 0) { match = 1; break; @@ -1119,7 +1110,7 @@ void do_list_files(struct file_entry **files_e, int files_c) { s_printf("\r\n"); break; } else if (tolower(buffer[0]) == 'q') { - for (z=0;zfilename); free(files_e[z]->description); free(files_e[z]); @@ -1127,12 +1118,12 @@ void do_list_files(struct file_entry **files_e, int files_c) { free(files_e); s_printf("\r\n"); return; - } else { + } else { z = atoi(buffer); if (z >= 0 && z < files_c) { if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { match = 0; - for (k=0;kfilename, files_e[z]->filename) == 0) { match = 1; break; @@ -1160,13 +1151,13 @@ void do_list_files(struct file_entry **files_e, int files_c) { } } } - } + } } while (1) { s_printf(get_string(75)); s_readstring(buffer, 5); if (strlen(buffer) == 0) { - for (z=0;zfilename); free(files_e[z]->description); free(files_e[z]); @@ -1179,7 +1170,7 @@ void do_list_files(struct file_entry **files_e, int files_c) { if (z >= 0 && z < files_c) { if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { match = 0; - for (k=0;kfilename, files_e[z]->filename) == 0) { match = 1; break; @@ -1206,7 +1197,7 @@ void do_list_files(struct file_entry **files_e, int files_c) { } } } - } + } } void file_search() { @@ -1223,15 +1214,15 @@ void file_search() { int search_dir; int search_sub; sqlite3 *db; - sqlite3_stmt *res; - int rc; + sqlite3_stmt *res; + int rc; int files_c; struct file_entry **files_e; - + s_printf(get_string(236)); ch = s_getc(); - - switch(tolower(ch)) { + + switch (tolower(ch)) { case 'd': stype = 1; break; @@ -1239,18 +1230,18 @@ void file_search() { stype = 2; break; } - + s_printf(get_string(237)); - + ch = s_getc(); if (tolower(ch) == 'a') { all = 1; } - + s_printf(get_string(239)); - + s_readstring(buffer, 128); - + if (strlen(buffer) == 0) { s_printf(get_string(238)); return; @@ -1262,7 +1253,7 @@ void file_search() { } else { searchterms = (char **)realloc(searchterms, sizeof(char *) * (searchterm_count + 1)); } - + searchterms[searchterm_count] = malloc(strlen(ptr) + 3); sprintf(searchterms[searchterm_count], "%%%s%%", ptr); searchterm_count++; @@ -1270,32 +1261,32 @@ void file_search() { } if (stype == 0) { snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename LIKE ?"); - for (i=1; i < searchterm_count; i++) { + for (i = 1; i < searchterm_count; i++) { strncat(sqlbuffer, " OR filename LIKE ?", 1024); } strncat(sqlbuffer, ")", 1024); } if (stype == 1) { snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (description LIKE ?"); - for (i=1; i < searchterm_count; i++) { + for (i = 1; i < searchterm_count; i++) { strncat(sqlbuffer, " OR description LIKE ?", 1024); } strncat(sqlbuffer, ")", 1024); } if (stype == 2) { snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename LIKE ?"); - for (i=1; i < searchterm_count; i++) { + for (i = 1; i < searchterm_count; i++) { strncat(sqlbuffer, " OR filename LIKE ?", 1024); } strncat(sqlbuffer, " OR description LIKE ?", 1024); - for (i=1; i < searchterm_count; i++) { + for (i = 1; i < searchterm_count; i++) { strncat(sqlbuffer, " OR description LIKE ?", 1024); } strncat(sqlbuffer, ")", 1024); } - + if (!all) { - files_c = 0; + files_c = 0; snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->database); rc = sqlite3_open(buffer, &db); @@ -1311,26 +1302,24 @@ void file_search() { if (rc != SQLITE_OK) { sqlite3_finalize(res); sqlite3_close(db); - for (i=0;isec_level > gUser->sec_level) { continue; @@ -1382,13 +1371,13 @@ void file_search() { continue; } if (stype == 2) { - for (j=0;j<2;j++) { - for (i=0;icur_file_dir]->file_subs[user->cur_file_sub]->database); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } + exit(1); + } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc != SQLITE_OK) { + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + if (rc != SQLITE_OK) { sqlite3_close(db); s_printf(get_string(68)); return; - } + } if (sql == nsql) { sqlite3_bind_int(res, 1, userlaston); } - - - files_c = 0; + files_c = 0; while (sqlite3_step(res) == SQLITE_ROW) { if (files_c == 0) { @@ -1507,7 +1493,7 @@ void list_files(struct user_record *user) { s_printf(get_string(68)); return; } - + do_list_files(files_e, files_c); } @@ -1525,7 +1511,7 @@ void choose_subdir() { int selected = 0; char c; - for (i=0;icur_file_dir]->file_sub_count;i++) { + for (i = 0; i < conf.file_directories[gUser->cur_file_dir]->file_sub_count; i++) { if (conf.file_directories[gUser->cur_file_dir]->file_subs[i]->download_sec_level <= gUser->sec_level) { if (list_tmp == 0) { sub_tmp = (struct subdir_tmp_t **)malloc(sizeof(struct subdir_tmp_t *)); @@ -1545,7 +1531,7 @@ void choose_subdir() { s_printf("\e[2J\e[1;1H"); s_printf(get_string(252), conf.file_directories[gUser->cur_file_dir]->name); s_printf(get_string(248)); - for (i=start;iindex, sub_tmp[i]->sub->name); } else { @@ -1575,7 +1561,7 @@ void choose_subdir() { if (selected >= list_tmp) { selected = list_tmp - 1; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(250), selected - start + 1, sub_tmp[selected - 1]->index, sub_tmp[selected - 1]->sub->name); s_printf(get_string(249), selected - start + 2, sub_tmp[selected]->index, sub_tmp[selected]->sub->name); s_printf("\e[%d;5H", selected - start + 2); @@ -1594,11 +1580,11 @@ void choose_subdir() { if (selected < 0) { selected = 0; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(249), selected - start + 2, sub_tmp[selected]->index, sub_tmp[selected]->sub->name); s_printf(get_string(250), selected - start + 3, sub_tmp[selected + 1]->index, sub_tmp[selected + 1]->sub->name); s_printf("\e[%d;5H", selected - start + 2); - } + } } } else if (c == 75) { // END KEY @@ -1631,7 +1617,7 @@ void choose_subdir() { // PAGE DOWN selected = selected + 22; if (selected >= list_tmp) { - selected = list_tmp -1; + selected = list_tmp - 1; } start = selected; redraw = 1; @@ -1643,7 +1629,7 @@ void choose_subdir() { } } - for (i=0;isec_level <= gUser->sec_level) { if (list_tmp == 0) { dir_tmp = (struct dir_tmp_t **)malloc(sizeof(struct dir_tmp_t *)); @@ -1683,7 +1669,7 @@ void choose_directory() { s_printf("\e[2J\e[1;1H"); s_printf(get_string(253)); s_printf(get_string(248)); - for (i=start;iindex, dir_tmp[i]->dir->name); } else { @@ -1713,7 +1699,7 @@ void choose_directory() { if (selected >= list_tmp) { selected = list_tmp - 1; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(250), selected - start + 1, dir_tmp[selected - 1]->index, dir_tmp[selected - 1]->dir->name); s_printf(get_string(249), selected - start + 2, dir_tmp[selected]->index, dir_tmp[selected]->dir->name); s_printf("\e[%d;5H", selected - start + 2); @@ -1732,11 +1718,11 @@ void choose_directory() { if (selected < 0) { selected = 0; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(249), selected - start + 2, dir_tmp[selected]->index, dir_tmp[selected]->dir->name); s_printf(get_string(250), selected - start + 3, dir_tmp[selected + 1]->index, dir_tmp[selected + 1]->dir->name); s_printf("\e[%d;5H", selected - start + 2); - } + } } } else if (c == 75) { // END KEY @@ -1769,7 +1755,7 @@ void choose_directory() { // PAGE DOWN selected = selected + 22; if (selected >= list_tmp) { - selected = list_tmp -1; + selected = list_tmp - 1; } start = selected; redraw = 1; @@ -1782,7 +1768,7 @@ void choose_directory() { } } - for (i=0;i 0) { - for (i=0;ifilename); free(tagged_files[i]); } @@ -1803,11 +1789,11 @@ void clear_tagged_files() { void next_file_dir(struct user_record *user) { int i; - for (i=user->cur_file_dir;icur_file_dir; i < conf.file_directory_count; i++) { if (i + 1 == conf.file_directory_count) { i = -1; } - if (conf.file_directories[i+1]->sec_level <= user->sec_level) { + if (conf.file_directories[i + 1]->sec_level <= user->sec_level) { user->cur_file_dir = i + 1; user->cur_file_sub = 0; break; @@ -1817,11 +1803,11 @@ void next_file_dir(struct user_record *user) { void prev_file_dir(struct user_record *user) { int i; - for (i=user->cur_file_dir;i>=0;i--) { + for (i = user->cur_file_dir; i >= 0; i--) { if (i - 1 == -1) { i = conf.file_directory_count; } - if (conf.file_directories[i-1]->sec_level <= user->sec_level) { + if (conf.file_directories[i - 1]->sec_level <= user->sec_level) { user->cur_file_dir = i - 1; user->cur_file_sub = 0; break; @@ -1831,7 +1817,7 @@ void prev_file_dir(struct user_record *user) { void next_file_sub(struct user_record *user) { int i; - i=user->cur_file_sub; + i = user->cur_file_sub; if (i + 1 == conf.file_directories[user->cur_file_dir]->file_sub_count) { i = -1; } @@ -1840,7 +1826,7 @@ void next_file_sub(struct user_record *user) { void prev_file_sub(struct user_record *user) { int i; - i=user->cur_file_sub; + i = user->cur_file_sub; if (i - 1 == -1) { i = conf.file_directories[user->cur_file_dir]->file_sub_count; } @@ -1855,15 +1841,15 @@ void file_scan() { char sql[] = "SELECT COUNT(*) FROM files WHERE uploaddate > ? AND approved=1"; int rc; sqlite3 *db; - sqlite3_stmt *res; + sqlite3_stmt *res; int new_files; int lines = 0; - + s_printf(get_string(232)); c = s_getc(); - + if (tolower(c) == 'y') { - for (i=0;isec_level > gUser->sec_level) { continue; } @@ -1873,8 +1859,8 @@ void file_scan() { s_printf(get_string(6)); s_getc(); lines = 0; - } - for (j=0;jfile_sub_count;j++) { + } + for (j = 0; j < conf.file_directories[i]->file_sub_count; j++) { if (conf.file_directories[i]->file_subs[j]->download_sec_level > gUser->sec_level) { continue; } @@ -1895,7 +1881,7 @@ void file_scan() { continue; } sqlite3_bind_int(res, 1, userlaston); - + if (sqlite3_step(res) != SQLITE_ERROR) { new_files = sqlite3_column_int(res, 0); if (new_files > 0) { @@ -1905,15 +1891,15 @@ void file_scan() { } sqlite3_finalize(res); sqlite3_close(db); - + if (lines == 22) { s_printf(get_string(6)); s_getc(); lines = 0; - } + } } } s_printf(get_string(6)); - s_getc(); + s_getc(); } } diff --git a/src/hashmap/hashmap.c b/src/hashmap/hashmap.c index 3978400..f8bed2a 100644 --- a/src/hashmap/hashmap.c +++ b/src/hashmap/hashmap.c @@ -11,15 +11,15 @@ #define MAX_CHAIN_LENGTH (8) /* We need to keep keys and values */ -typedef struct _hashmap_element{ - char* key; +typedef struct _hashmap_element { + char *key; int in_use; any_t data; } hashmap_element; /* A hashmap has some maximum size and current size, * as well as the data to hold. */ -typedef struct _hashmap_map{ +typedef struct _hashmap_map { int table_size; int size; hashmap_element *data; @@ -29,144 +29,141 @@ typedef struct _hashmap_map{ * Return an empty hashmap, or NULL on failure. */ map_t hashmap_new() { - hashmap_map* m = (hashmap_map*) malloc(sizeof(hashmap_map)); - if(!m) goto err; + hashmap_map *m = (hashmap_map *)malloc(sizeof(hashmap_map)); + if (!m) goto err; - m->data = (hashmap_element*) calloc(INITIAL_SIZE, sizeof(hashmap_element)); - if(!m->data) goto err; + m->data = (hashmap_element *)calloc(INITIAL_SIZE, sizeof(hashmap_element)); + if (!m->data) goto err; m->table_size = INITIAL_SIZE; m->size = 0; return m; - err: - if (m) - hashmap_free(m); - return NULL; +err: + if (m) + hashmap_free(m); + return NULL; } /* The implementation here was originally done by Gary S. Brown. I have borrowed the tables directly, and made some minor changes to the crc32-function (including changing the interface). //ylo */ - /* ============================================================= */ - /* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or */ - /* code or tables extracted from it, as desired without restriction. */ - /* */ - /* First, the polynomial itself and its table of feedback terms. The */ - /* polynomial is */ - /* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */ - /* */ - /* Note that we take it "backwards" and put the highest-order term in */ - /* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ - /* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ - /* the MSB being 1. */ - /* */ - /* Note that the usual hardware shift register implementation, which */ - /* is what we're using (we're merely optimizing it by doing eight-bit */ - /* chunks at a time) shifts bits into the lowest-order term. In our */ - /* implementation, that means shifting towards the right. Why do we */ - /* do it this way? Because the calculated CRC must be transmitted in */ - /* order from highest-order term to lowest-order term. UARTs transmit */ - /* characters in order from LSB to MSB. By storing the CRC this way, */ - /* we hand it to the UART in the order low-byte to high-byte; the UART */ - /* sends each low-bit to hight-bit; and the result is transmission bit */ - /* by bit from highest- to lowest-order term without requiring any bit */ - /* shuffling on our part. Reception works similarly. */ - /* */ - /* The feedback terms table consists of 256, 32-bit entries. Notes: */ - /* */ - /* The table can be generated at runtime if desired; code to do so */ - /* is shown later. It might not be obvious, but the feedback */ - /* terms simply represent the results of eight shift/xor opera- */ - /* tions for all combinations of data and CRC register values. */ - /* */ - /* The values must be right-shifted by eight bits by the "updcrc" */ - /* logic; the shift must be unsigned (bring in zeroes). On some */ - /* hardware you could probably optimize the shift in assembler by */ - /* using byte-swap instructions. */ - /* polynomial $edb88320 */ - /* */ - /* -------------------------------------------------------------------- */ +/* ============================================================= */ +/* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or */ +/* code or tables extracted from it, as desired without restriction. */ +/* */ +/* First, the polynomial itself and its table of feedback terms. The */ +/* polynomial is */ +/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */ +/* */ +/* Note that we take it "backwards" and put the highest-order term in */ +/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ +/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ +/* the MSB being 1. */ +/* */ +/* Note that the usual hardware shift register implementation, which */ +/* is what we're using (we're merely optimizing it by doing eight-bit */ +/* chunks at a time) shifts bits into the lowest-order term. In our */ +/* implementation, that means shifting towards the right. Why do we */ +/* do it this way? Because the calculated CRC must be transmitted in */ +/* order from highest-order term to lowest-order term. UARTs transmit */ +/* characters in order from LSB to MSB. By storing the CRC this way, */ +/* we hand it to the UART in the order low-byte to high-byte; the UART */ +/* sends each low-bit to hight-bit; and the result is transmission bit */ +/* by bit from highest- to lowest-order term without requiring any bit */ +/* shuffling on our part. Reception works similarly. */ +/* */ +/* The feedback terms table consists of 256, 32-bit entries. Notes: */ +/* */ +/* The table can be generated at runtime if desired; code to do so */ +/* is shown later. It might not be obvious, but the feedback */ +/* terms simply represent the results of eight shift/xor opera- */ +/* tions for all combinations of data and CRC register values. */ +/* */ +/* The values must be right-shifted by eight bits by the "updcrc" */ +/* logic; the shift must be unsigned (bring in zeroes). On some */ +/* hardware you could probably optimize the shift in assembler by */ +/* using byte-swap instructions. */ +/* polynomial $edb88320 */ +/* */ +/* -------------------------------------------------------------------- */ static unsigned long crc32_tab[] = { - 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, - 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, - 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, - 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, - 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, - 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, - 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, - 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, - 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, - 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, - 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, - 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, - 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, - 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, - 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, - 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, - 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, - 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, - 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, - 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, - 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, - 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, - 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, - 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, - 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, - 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, - 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, - 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, - 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, - 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, - 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, - 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, - 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, - 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, - 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, - 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, - 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, - 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, - 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, - 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, - 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, - 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, - 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, - 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, - 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, - 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, - 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, - 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, - 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, - 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, - 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, - 0x2d02ef8dL - }; + 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, + 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, + 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, + 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, + 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, + 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, + 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, + 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, + 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, + 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, + 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, + 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, + 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, + 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, + 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, + 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, + 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, + 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, + 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, + 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, + 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, + 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, + 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, + 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, + 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, + 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, + 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, + 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, + 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, + 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, + 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, + 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, + 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, + 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, + 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, + 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, + 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, + 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, + 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, + 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, + 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, + 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, + 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, + 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, + 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, + 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, + 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, + 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, + 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, + 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, + 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, + 0x2d02ef8dL}; /* Return a 32-bit CRC of the contents of the buffer. */ -unsigned long crc32(const unsigned char *s, unsigned int len) -{ - unsigned int i; - unsigned long crc32val; - - crc32val = 0; - for (i = 0; i < len; i ++) - { - crc32val = - crc32_tab[(crc32val ^ s[i]) & 0xff] ^ - (crc32val >> 8); - } - return crc32val; +unsigned long crc32(const unsigned char *s, unsigned int len) { + unsigned int i; + unsigned long crc32val; + + crc32val = 0; + for (i = 0; i < len; i++) { + crc32val = + crc32_tab[(crc32val ^ s[i]) & 0xff] ^ + (crc32val >> 8); + } + return crc32val; } /* * Hashing function for a string */ -unsigned int hashmap_hash_int(hashmap_map * m, char* keystring){ +unsigned int hashmap_hash_int(hashmap_map *m, char *keystring) { - unsigned long key = crc32((unsigned char*)(keystring), strlen(keystring)); + unsigned long key = crc32((unsigned char *)(keystring), strlen(keystring)); /* Robert Jenkins' 32 bit Mix Function */ key += (key << 12); @@ -188,25 +185,25 @@ unsigned int hashmap_hash_int(hashmap_map * m, char* keystring){ * Return the integer of the location in data * to store the point to the item, or MAP_FULL. */ -int hashmap_hash(map_t in, char* key){ +int hashmap_hash(map_t in, char *key) { int curr; int i; /* Cast the hashmap */ - hashmap_map* m = (hashmap_map *) in; + hashmap_map *m = (hashmap_map *)in; /* If full, return immediately */ - if(m->size >= (m->table_size/2)) return MAP_FULL; + if (m->size >= (m->table_size / 2)) return MAP_FULL; /* Find the best index */ curr = hashmap_hash_int(m, key); /* Linear probing */ - for(i = 0; i< MAX_CHAIN_LENGTH; i++){ - if(m->data[curr].in_use == 0) + for (i = 0; i < MAX_CHAIN_LENGTH; i++) { + if (m->data[curr].in_use == 0) return curr; - if(m->data[curr].in_use == 1 && (strcmp(m->data[curr].key,key)==0)) + if (m->data[curr].in_use == 1 && (strcmp(m->data[curr].key, key) == 0)) return curr; curr = (curr + 1) % m->table_size; @@ -218,16 +215,16 @@ int hashmap_hash(map_t in, char* key){ /* * Doubles the size of the hashmap, and rehashes all the elements */ -int hashmap_rehash(map_t in){ +int hashmap_rehash(map_t in) { int i; int old_size; - hashmap_element* curr; + hashmap_element *curr; /* Setup the new elements */ - hashmap_map *m = (hashmap_map *) in; - hashmap_element* temp = (hashmap_element *) - calloc(2 * m->table_size, sizeof(hashmap_element)); - if(!temp) return MAP_OMEM; + hashmap_map *m = (hashmap_map *)in; + hashmap_element *temp = (hashmap_element *) + calloc(2 * m->table_size, sizeof(hashmap_element)); + if (!temp) return MAP_OMEM; /* Update the array */ curr = m->data; @@ -239,12 +236,12 @@ int hashmap_rehash(map_t in){ m->size = 0; /* Rehash the elements */ - for(i = 0; i < old_size; i++){ - int status; + for (i = 0; i < old_size; i++) { + int status; + + if (curr[i].in_use == 0) + continue; - if (curr[i].in_use == 0) - continue; - status = hashmap_put(m, curr[i].key, curr[i].data); if (status != MAP_OK) return status; @@ -258,16 +255,16 @@ int hashmap_rehash(map_t in){ /* * Add a pointer to the hashmap with some key */ -int hashmap_put(map_t in, char* key, any_t value){ +int hashmap_put(map_t in, char *key, any_t value) { int index; - hashmap_map* m; + hashmap_map *m; /* Cast the hashmap */ - m = (hashmap_map *) in; + m = (hashmap_map *)in; /* Find a place to put our value */ index = hashmap_hash(in, key); - while(index == MAP_FULL){ + while (index == MAP_FULL) { if (hashmap_rehash(in) == MAP_OMEM) { return MAP_OMEM; } @@ -278,7 +275,7 @@ int hashmap_put(map_t in, char* key, any_t value){ m->data[index].data = value; m->data[index].key = key; m->data[index].in_use = 1; - m->size++; + m->size++; return MAP_OK; } @@ -286,26 +283,26 @@ int hashmap_put(map_t in, char* key, any_t value){ /* * Get your pointer out of the hashmap with a key */ -int hashmap_get(map_t in, char* key, any_t *arg){ +int hashmap_get(map_t in, char *key, any_t *arg) { int curr; int i; - hashmap_map* m; + hashmap_map *m; /* Cast the hashmap */ - m = (hashmap_map *) in; + m = (hashmap_map *)in; /* Find data location */ curr = hashmap_hash_int(m, key); /* Linear probing, if necessary */ - for(i = 0; idata[curr].in_use; - if (in_use == 1){ - if (strcmp(m->data[curr].key,key)==0){ - *arg = (m->data[curr].data); - return MAP_OK; - } + int in_use = m->data[curr].in_use; + if (in_use == 1) { + if (strcmp(m->data[curr].key, key) == 0) { + *arg = (m->data[curr].data); + return MAP_OK; + } } curr = (curr + 1) % m->table_size; @@ -326,54 +323,54 @@ int hashmap_iterate(map_t in, PFany f, any_t item) { int i; /* Cast the hashmap */ - hashmap_map* m = (hashmap_map*) in; + hashmap_map *m = (hashmap_map *)in; /* On empty hashmap, return immediately */ if (hashmap_length(m) <= 0) - return MAP_MISSING; + return MAP_MISSING; /* Linear probing */ - for(i = 0; i< m->table_size; i++) - if(m->data[i].in_use != 0) { - any_t data = (any_t) (m->data[i].data); + for (i = 0; i < m->table_size; i++) + if (m->data[i].in_use != 0) { + any_t data = (any_t)(m->data[i].data); int status = f(item, data); if (status != MAP_OK) { return status; } } - return MAP_OK; + return MAP_OK; } /* * Remove an element with that key from the map */ -int hashmap_remove(map_t in, char* key){ +int hashmap_remove(map_t in, char *key) { int i; int curr; - hashmap_map* m; + hashmap_map *m; /* Cast the hashmap */ - m = (hashmap_map *) in; + m = (hashmap_map *)in; /* Find key */ curr = hashmap_hash_int(m, key); /* Linear probing, if necessary */ - for(i = 0; idata[curr].in_use; - if (in_use == 1){ - if (strcmp(m->data[curr].key,key)==0){ - /* Blank out the fields */ - m->data[curr].in_use = 0; - m->data[curr].data = NULL; - m->data[curr].key = NULL; + int in_use = m->data[curr].in_use; + if (in_use == 1) { + if (strcmp(m->data[curr].key, key) == 0) { + /* Blank out the fields */ + m->data[curr].in_use = 0; + m->data[curr].data = NULL; + m->data[curr].key = NULL; - /* Reduce the size */ - m->size--; - return MAP_OK; - } + /* Reduce the size */ + m->size--; + return MAP_OK; + } } curr = (curr + 1) % m->table_size; } @@ -383,15 +380,17 @@ int hashmap_remove(map_t in, char* key){ } /* Deallocate the hashmap */ -void hashmap_free(map_t in){ - hashmap_map* m = (hashmap_map*) in; +void hashmap_free(map_t in) { + hashmap_map *m = (hashmap_map *)in; free(m->data); free(m); } /* Return the length of the hashmap */ -int hashmap_length(map_t in){ - hashmap_map* m = (hashmap_map *) in; - if(m != NULL) return m->size; - else return 0; +int hashmap_length(map_t in) { + hashmap_map *m = (hashmap_map *)in; + if (m != NULL) + return m->size; + else + return 0; } \ No newline at end of file diff --git a/src/hashmap/hashmap.h b/src/hashmap/hashmap.h index 70cc33f..ce8bee4 100644 --- a/src/hashmap/hashmap.h +++ b/src/hashmap/hashmap.h @@ -9,10 +9,10 @@ #ifndef __HASHMAP_H__ #define __HASHMAP_H__ -#define MAP_MISSING -3 /* No such element */ -#define MAP_FULL -2 /* Hashmap is full */ -#define MAP_OMEM -1 /* Out of Memory */ -#define MAP_OK 0 /* OK */ +#define MAP_MISSING -3 /* No such element */ +#define MAP_FULL -2 /* Hashmap is full */ +#define MAP_OMEM -1 /* Out of Memory */ +#define MAP_OK 0 /* OK */ /* * any_t is a pointer. This allows you to put arbitrary structures in @@ -50,17 +50,17 @@ extern int hashmap_iterate(map_t in, PFany f, any_t item); /* * Add an element to the hashmap. Return MAP_OK or MAP_OMEM. */ -extern int hashmap_put(map_t in, char* key, any_t value); +extern int hashmap_put(map_t in, char *key, any_t value); /* * Get an element from the hashmap. Return MAP_OK or MAP_MISSING. */ -extern int hashmap_get(map_t in, char* key, any_t *arg); +extern int hashmap_get(map_t in, char *key, any_t *arg); /* * Remove an element from the hashmap. Return MAP_OK or MAP_MISSING. */ -extern int hashmap_remove(map_t in, char* key); +extern int hashmap_remove(map_t in, char *key); /* * Get any element. Return MAP_OK or MAP_MISSING. diff --git a/src/hashmap/main.c b/src/hashmap/main.c index 4c128e3..6efebe1 100644 --- a/src/hashmap/main.c +++ b/src/hashmap/main.c @@ -10,72 +10,67 @@ #define KEY_MAX_LENGTH (256) #define KEY_PREFIX ("somekey") -#define KEY_COUNT (1024*1024) +#define KEY_COUNT (1024 * 1024) -typedef struct data_struct_s -{ - char key_string[KEY_MAX_LENGTH]; - int number; +typedef struct data_struct_s { + char key_string[KEY_MAX_LENGTH]; + int number; } data_struct_t; -int main(char* argv, int argc) -{ - int index; - int error; - map_t mymap; - char key_string[KEY_MAX_LENGTH]; - data_struct_t* value; - - mymap = hashmap_new(); +int main(char *argv, int argc) { + int index; + int error; + map_t mymap; + char key_string[KEY_MAX_LENGTH]; + data_struct_t *value; - /* First, populate the hash map with ascending values */ - for (index=0; indexkey_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); - value->number = index; + mymap = hashmap_new(); - error = hashmap_put(mymap, value->key_string, value); - assert(error==MAP_OK); - } + /* First, populate the hash map with ascending values */ + for (index = 0; index < KEY_COUNT; index += 1) { + /* Store the key string along side the numerical value so we can free it later */ + value = malloc(sizeof(data_struct_t)); + snprintf(value->key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); + value->number = index; - /* Now, check all of the expected values are there */ - for (index=0; indexkey_string, value); + assert(error == MAP_OK); + } - error = hashmap_get(mymap, key_string, (void**)(&value)); - - /* Make sure the value was both found and the correct number */ - assert(error==MAP_OK); - assert(value->number==index); - } - - /* Make sure that a value that wasn't in the map can't be found */ - snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT); + /* Now, check all of the expected values are there */ + for (index = 0; index < KEY_COUNT; index += 1) { + snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); - error = hashmap_get(mymap, key_string, (void**)(&value)); - - /* Make sure the value was not found */ - assert(error==MAP_MISSING); + error = hashmap_get(mymap, key_string, (void **)(&value)); - /* Free all of the values we allocated and remove them from the map */ - for (index=0; indexnumber == index); + } - error = hashmap_get(mymap, key_string, (void**)(&value)); - assert(error==MAP_OK); + /* Make sure that a value that wasn't in the map can't be found */ + snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT); - error = hashmap_remove(mymap, key_string); - assert(error==MAP_OK); + error = hashmap_get(mymap, key_string, (void **)(&value)); - free(value); - } - - /* Now, destroy the map */ - hashmap_free(mymap); + /* Make sure the value was not found */ + assert(error == MAP_MISSING); - return 1; + /* Free all of the values we allocated and remove them from the map */ + for (index = 0; index < KEY_COUNT; index += 1) { + snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); + + error = hashmap_get(mymap, key_string, (void **)(&value)); + assert(error == MAP_OK); + + error = hashmap_remove(mymap, key_string); + assert(error == MAP_OK); + + free(value); + } + + /* Now, destroy the map */ + hashmap_free(mymap); + + return 1; } \ No newline at end of file diff --git a/src/inih/ini.c b/src/inih/ini.c index 27ca85b..5ff0a4d 100644 --- a/src/inih/ini.c +++ b/src/inih/ini.c @@ -25,170 +25,160 @@ https://github.com/benhoyt/inih #define MAX_NAME 50 /* Strip whitespace chars off end of given string, in place. Return s. */ -static char* rstrip(char* s) -{ - char* p = s + strlen(s); - while (p > s && isspace((unsigned char)(*--p))) - *p = '\0'; - return s; +static char *rstrip(char *s) { + char *p = s + strlen(s); + while (p > s && isspace((unsigned char)(*--p))) + *p = '\0'; + return s; } /* Return pointer to first non-whitespace char in given string. */ -static char* lskip(const char* s) -{ - while (*s && isspace((unsigned char)(*s))) - s++; - return (char*)s; +static char *lskip(const char *s) { + while (*s && isspace((unsigned char)(*s))) + s++; + return (char *)s; } /* Return pointer to first char (of chars) or inline comment in given string, or pointer to null at end of string if neither found. Inline comment must be prefixed by a whitespace character to register as a comment. */ -static char* find_chars_or_comment(const char* s, const char* chars) -{ +static char *find_chars_or_comment(const char *s, const char *chars) { #if INI_ALLOW_INLINE_COMMENTS - int was_space = 0; - while (*s && (!chars || !strchr(chars, *s)) && - !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) { - was_space = isspace((unsigned char)(*s)); - s++; - } + int was_space = 0; + while (*s && (!chars || !strchr(chars, *s)) && + !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) { + was_space = isspace((unsigned char)(*s)); + s++; + } #else - while (*s && (!chars || !strchr(chars, *s))) { - s++; - } + while (*s && (!chars || !strchr(chars, *s))) { + s++; + } #endif - return (char*)s; + return (char *)s; } /* Version of strncpy that ensures dest (size bytes) is null-terminated. */ -static char* strncpy0(char* dest, const char* src, size_t size) -{ - strncpy(dest, src, size); - dest[size - 1] = '\0'; - return dest; +static char *strncpy0(char *dest, const char *src, size_t size) { + strncpy(dest, src, size); + dest[size - 1] = '\0'; + return dest; } /* See documentation in header file. */ -int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, - void* user) -{ - /* Uses a fair bit of stack (use heap instead if you need to) */ +int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, + void *user) { +/* Uses a fair bit of stack (use heap instead if you need to) */ #if INI_USE_STACK - char line[INI_MAX_LINE]; + char line[INI_MAX_LINE]; #else - char* line; + char *line; #endif - char section[MAX_SECTION] = ""; - char prev_name[MAX_NAME] = ""; + char section[MAX_SECTION] = ""; + char prev_name[MAX_NAME] = ""; - char* start; - char* end; - char* name; - char* value; - int lineno = 0; - int error = 0; + char *start; + char *end; + char *name; + char *value; + int lineno = 0; + int error = 0; #if !INI_USE_STACK - line = (char*)malloc(INI_MAX_LINE); - if (!line) { - return -2; - } + line = (char *)malloc(INI_MAX_LINE); + if (!line) { + return -2; + } #endif - /* Scan through stream line by line */ - while (reader(line, INI_MAX_LINE, stream) != NULL) { - lineno++; + /* Scan through stream line by line */ + while (reader(line, INI_MAX_LINE, stream) != NULL) { + lineno++; - start = line; + start = line; #if INI_ALLOW_BOM - if (lineno == 1 && (unsigned char)start[0] == 0xEF && - (unsigned char)start[1] == 0xBB && - (unsigned char)start[2] == 0xBF) { - start += 3; - } + if (lineno == 1 && (unsigned char)start[0] == 0xEF && + (unsigned char)start[1] == 0xBB && + (unsigned char)start[2] == 0xBF) { + start += 3; + } #endif - start = lskip(rstrip(start)); + start = lskip(rstrip(start)); - if (*start == ';' || *start == '#') { - /* Per Python configparser, allow both ; and # comments at the + if (*start == ';' || *start == '#') { + /* Per Python configparser, allow both ; and # comments at the start of a line */ - } + } #if INI_ALLOW_MULTILINE - else if (*prev_name && *start && start > line) { - /* Non-blank line with leading whitespace, treat as continuation + else if (*prev_name && *start && start > line) { + /* Non-blank line with leading whitespace, treat as continuation of previous name's value (as per Python configparser). */ - if (!handler(user, section, prev_name, start) && !error) - error = lineno; - } + if (!handler(user, section, prev_name, start) && !error) + error = lineno; + } #endif - else if (*start == '[') { - /* A "[section]" line */ - end = find_chars_or_comment(start + 1, "]"); - if (*end == ']') { - *end = '\0'; - strncpy0(section, start + 1, sizeof(section)); - *prev_name = '\0'; - } - else if (!error) { - /* No ']' found on section line */ - error = lineno; - } - } - else if (*start) { - /* Not a comment, must be a name[=:]value pair */ - end = find_chars_or_comment(start, "=:"); - if (*end == '=' || *end == ':') { - *end = '\0'; - name = rstrip(start); - value = lskip(end + 1); + else if (*start == '[') { + /* A "[section]" line */ + end = find_chars_or_comment(start + 1, "]"); + if (*end == ']') { + *end = '\0'; + strncpy0(section, start + 1, sizeof(section)); + *prev_name = '\0'; + } else if (!error) { + /* No ']' found on section line */ + error = lineno; + } + } else if (*start) { + /* Not a comment, must be a name[=:]value pair */ + end = find_chars_or_comment(start, "=:"); + if (*end == '=' || *end == ':') { + *end = '\0'; + name = rstrip(start); + value = lskip(end + 1); #if INI_ALLOW_INLINE_COMMENTS - end = find_chars_or_comment(value, NULL); - if (*end) - *end = '\0'; + end = find_chars_or_comment(value, NULL); + if (*end) + *end = '\0'; #endif - rstrip(value); + rstrip(value); - /* Valid name[=:]value pair found, call handler */ - strncpy0(prev_name, name, sizeof(prev_name)); - if (!handler(user, section, name, value) && !error) - error = lineno; - } - else if (!error) { - /* No '=' or ':' found on name[=:]value line */ - error = lineno; - } - } + /* Valid name[=:]value pair found, call handler */ + strncpy0(prev_name, name, sizeof(prev_name)); + if (!handler(user, section, name, value) && !error) + error = lineno; + } else if (!error) { + /* No '=' or ':' found on name[=:]value line */ + error = lineno; + } + } #if INI_STOP_ON_FIRST_ERROR - if (error) - break; + if (error) + break; #endif - } + } #if !INI_USE_STACK - free(line); + free(line); #endif - return error; + return error; } /* See documentation in header file. */ -int ini_parse_file(FILE* file, ini_handler handler, void* user) -{ - return ini_parse_stream((ini_reader)fgets, file, handler, user); +int ini_parse_file(FILE *file, ini_handler handler, void *user) { + return ini_parse_stream((ini_reader)fgets, file, handler, user); } /* See documentation in header file. */ -int ini_parse(const char* filename, ini_handler handler, void* user) -{ - FILE* file; - int error; +int ini_parse(const char *filename, ini_handler handler, void *user) { + FILE *file; + int error; - file = fopen(filename, "r"); - if (!file) - return -1; - error = ini_parse_file(file, handler, user); - fclose(file); - return error; + file = fopen(filename, "r"); + if (!file) + return -1; + error = ini_parse_file(file, handler, user); + fclose(file); + return error; } diff --git a/src/inih/ini.h b/src/inih/ini.h index eaa554d..d93a7d4 100644 --- a/src/inih/ini.h +++ b/src/inih/ini.h @@ -18,11 +18,11 @@ extern "C" { #include /* Typedef for prototype of handler function. */ -typedef int (*ini_handler)(void* user, const char* section, - const char* name, const char* value); +typedef int (*ini_handler)(void *user, const char *section, + const char *name, const char *value); /* Typedef for prototype of fgets-style reader function. */ -typedef char* (*ini_reader)(char* str, int num, void* stream); +typedef char *(*ini_reader)(char *str, int num, void *stream); /* Parse given INI-style file. May have [section]s, name=value pairs (whitespace stripped), and comments starting with ';' (semicolon). Section @@ -37,16 +37,16 @@ typedef char* (*ini_reader)(char* str, int num, void* stream); stop on first error), -1 on file open error, or -2 on memory allocation error (only when INI_USE_STACK is zero). */ -int ini_parse(const char* filename, ini_handler handler, void* user); +int ini_parse(const char *filename, ini_handler handler, void *user); /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't close the file when it's finished -- the caller must do that. */ -int ini_parse_file(FILE* file, ini_handler handler, void* user); +int ini_parse_file(FILE *file, ini_handler handler, void *user); /* Same as ini_parse(), but takes an ini_reader function pointer instead of filename. Used for implementing custom or string-based I/O. */ -int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, - void* user); +int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, + void *user); /* Nonzero to allow multi-line value parsing, in the style of Python's configparser. If allowed, ini_parse() will call the handler with the same diff --git a/src/lua_glue.c b/src/lua_glue.c index 8ead90b..5702683 100644 --- a/src/lua_glue.c +++ b/src/lua_glue.c @@ -55,7 +55,7 @@ int l_bbsRChar(lua_State *L) { int l_bbsDisplayAnsiPause(lua_State *L) { char *str = (char *)lua_tostring(L, -1); char buffer[256]; - + if (strchr(str, '/') == NULL) { sprintf(buffer, "%s/%s.ans", conf.ansi_path, str); s_displayansi_pause(buffer, 1); @@ -187,8 +187,7 @@ int l_getBBSInfo(lua_State *L) { return 4; } - -int l_getUserHandle(lua_State *L) { +int l_getUserHandle(lua_State *L) { lua_pushstring(L, gUser->loginname); return 1; @@ -203,7 +202,7 @@ int l_messageFound(lua_State *L) { s_JamBase *jb; s_JamBaseHeader jbh; s_JamMsgHeader jmh; - s_JamSubPacket* jsp; + s_JamSubPacket *jsp; jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); if (!jb) { @@ -226,12 +225,12 @@ int l_messageFound(lua_State *L) { lua_pushnumber(L, 0); return 1; } - + JAM_DelSubPacket(jsp); JAM_CloseMB(jb); free(jb); lua_pushnumber(L, 1); - return 1; + return 1; } int l_readMessageHdr(lua_State *L) { @@ -243,7 +242,7 @@ int l_readMessageHdr(lua_State *L) { s_JamBase *jb; s_JamBaseHeader jbh; s_JamMsgHeader jmh; - s_JamSubPacket* jsp; + s_JamSubPacket *jsp; char *subject = NULL; char *sender = NULL; @@ -265,7 +264,7 @@ int l_readMessageHdr(lua_State *L) { JAM_CloseMB(jb); free(jb); } else { - for (z=0;zNumFields;z++) { + for (z = 0; z < jsp->NumFields; z++) { if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { subject = (char *)malloc(jsp->Fields[z]->DatLen + 1); memset(subject, 0, jsp->Fields[z]->DatLen + 1); @@ -281,11 +280,10 @@ int l_readMessageHdr(lua_State *L) { memset(recipient, 0, jsp->Fields[z]->DatLen + 1); memcpy(recipient, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); } - } JAM_DelSubPacket(jsp); JAM_CloseMB(jb); - free(jb); + free(jb); } if (subject == NULL) { subject = strdup("(No Subject)"); @@ -307,7 +305,6 @@ int l_readMessageHdr(lua_State *L) { free(sender); free(recipient); - return 3; } @@ -350,7 +347,7 @@ int l_readMessage(lua_State *L) { lua_pushstring(L, body); free(body); - + return 1; } @@ -362,7 +359,7 @@ int l_dataPath(lua_State *L) { if (stat(buffer, &s) != 0) { mkdir(buffer, 0755); } - + lua_pushstring(L, buffer); return 1; @@ -376,7 +373,7 @@ int l_tempPath(lua_State *L) { if (stat(buffer, &s) != 0) { mkdir(buffer, 0755); } - + lua_pushstring(L, buffer); return 1; @@ -401,7 +398,7 @@ int l_postMessage(lua_State *L) { s_JamBase *jb; s_JamMsgHeader jmh; - s_JamSubPacket* jsp; + s_JamSubPacket *jsp; s_JamSubfield jsf; int z; int j; @@ -416,37 +413,36 @@ int l_postMessage(lua_State *L) { return 0; } - JAM_ClearMsgHeader( &jmh ); + JAM_ClearMsgHeader(&jmh); jmh.DateWritten = dwritten; jmh.Attribute |= JAM_MSG_LOCAL; - jsp = JAM_NewSubPacket(); - jsf.LoID = JAMSFLD_SENDERNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_SENDERNAME; + jsf.HiID = 0; jsf.DatLen = strlen(from); jsf.Buffer = (char *)from; JAM_PutSubfield(jsp, &jsf); if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { sprintf(buffer, "ALL"); - jsf.LoID = JAMSFLD_RECVRNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_RECVRNAME; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); } else { - jsf.LoID = JAMSFLD_RECVRNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_RECVRNAME; + jsf.HiID = 0; jsf.DatLen = strlen(to); jsf.Buffer = (char *)to; JAM_PutSubfield(jsp, &jsf); } - jsf.LoID = JAMSFLD_SUBJECT; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_SUBJECT; + jsf.HiID = 0; jsf.DatLen = strlen(subject); jsf.Buffer = (char *)subject; JAM_PutSubfield(jsp, &jsf); @@ -456,28 +452,28 @@ int l_postMessage(lua_State *L) { if (conf.mail_conferences[confr]->fidoaddr->point) { sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node, + conf.mail_conferences[confr]->fidoaddr->point); } else { sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node); } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point, - generate_msgid()); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node, + conf.mail_conferences[confr]->fidoaddr->point, + generate_msgid()); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -499,7 +495,7 @@ int l_postMessage(lua_State *L) { } else { dolog("Failed to lock msg base!"); JAM_CloseMB(jb); - free(jb); + free(jb); return 0; } } @@ -514,23 +510,23 @@ int l_postMessage(lua_State *L) { if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[confr]->fidoaddr->point == 0) { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node); } else { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + conf.mail_conferences[confr]->fidoaddr->net, + conf.mail_conferences[confr]->fidoaddr->node, + conf.mail_conferences[confr]->fidoaddr->point); } } else { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline); } msg = (char *)malloc(strlen(body) + 2 + strlen(buffer)); - + j = 0; - for (i=0;i lastid) { lastid = unixtime; @@ -107,7 +106,7 @@ unsigned long generate_msgid() { void free_message_headers(struct msg_headers *msghs) { int i; - for (i=0;imsg_count;i++) { + for (i = 0; i < msghs->msg_count; i++) { free(msghs->msgs[i]->msg_h); if (msghs->msgs[i]->from != NULL) { free(msghs->msgs[i]->from); @@ -153,12 +152,12 @@ int msg_is_to(struct user_record *user, char *addressed_to, char *address, int t if (strcasecmp(myname, addressed_to) == 0) { dest = parse_fido_addr(address); if (conf.mail_conferences[msgconf]->fidoaddr->zone == dest->zone && - conf.mail_conferences[msgconf]->fidoaddr->net == dest->net && - conf.mail_conferences[msgconf]->fidoaddr->node == dest->node && - conf.mail_conferences[msgconf]->fidoaddr->point == dest->point) { - free(dest); - free(myname); - return 1; + conf.mail_conferences[msgconf]->fidoaddr->net == dest->net && + conf.mail_conferences[msgconf]->fidoaddr->node == dest->node && + conf.mail_conferences[msgconf]->fidoaddr->point == dest->point) { + free(dest); + free(myname); + return 1; } free(dest); } @@ -200,12 +199,12 @@ int msg_is_from(struct user_record *user, char *addressed_from, char *address, i if (strcasecmp(myname, addressed_from) == 0) { orig = parse_fido_addr(address); if (conf.mail_conferences[msgconf]->fidoaddr->zone == orig->zone && - conf.mail_conferences[msgconf]->fidoaddr->net == orig->net && - conf.mail_conferences[msgconf]->fidoaddr->node == orig->node && - conf.mail_conferences[msgconf]->fidoaddr->point == orig->point) { - free(orig); - free(myname); - return 1; + conf.mail_conferences[msgconf]->fidoaddr->net == orig->net && + conf.mail_conferences[msgconf]->fidoaddr->node == orig->node && + conf.mail_conferences[msgconf]->fidoaddr->point == orig->point) { + free(orig); + free(myname); + return 1; } free(orig); } @@ -235,7 +234,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r s_JamBase *jb; s_JamBaseHeader jbh; s_JamMsgHeader jmh; - s_JamSubPacket* jsp; + s_JamSubPacket *jsp; struct jam_msg *jamm; int to_us; int i; @@ -258,7 +257,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r msghs = (struct msg_headers *)malloc(sizeof(struct msg_headers)); msghs->msg_count = 0; k = 0; - for (i=0;k < jbh.ActiveMsgs;i++) { + for (i = 0; k < jbh.ActiveMsgs; i++) { memset(&jmh, 0, sizeof(s_JamMsgHeader)); z = JAM_ReadMsgHeader(jb, i, &jmh, &jsp); @@ -285,7 +284,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r jamm->msgid = NULL; jamm->replyid = NULL; - for (z=0;zNumFields;z++) { + for (z = 0; z < jsp->NumFields; z++) { if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { jamm->subject = (char *)malloc(jsp->Fields[z]->DatLen + 1); memset(jamm->subject, 0, jsp->Fields[z]->DatLen + 1); @@ -332,11 +331,11 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r } if (jamm->to == NULL) { jamm->to = strdup("(No Recipient)"); - } + } if (jmh.Attribute & JAM_MSG_PRIVATE) { if (!msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, conf.mail_conferences[msgconf]->realnames, msgconf) && !msg_is_from(user, jamm->from, jamm->oaddress, conf.mail_conferences[msgconf]->nettype, conf.mail_conferences[msgconf]->realnames, msgconf) && - !msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, !conf.mail_conferences[msgconf]->realnames, msgconf) && + !msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, !conf.mail_conferences[msgconf]->realnames, msgconf) && !msg_is_from(user, jamm->from, jamm->oaddress, conf.mail_conferences[msgconf]->nettype, !conf.mail_conferences[msgconf]->realnames, msgconf)) { if (jamm->subject != NULL) { @@ -394,7 +393,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r free(jamm); k++; continue; - } + } } if (msghs->msg_count == 0) { @@ -432,8 +431,6 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot struct stat s; struct utsname name; - - if (conf.external_editor_cmd != NULL && user->exteditor != 0) { if (user->exteditor == 2) { s_printf(get_string(85)); @@ -458,7 +455,7 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot // write msgtemp if (quote != NULL) { fptr = fopen(buffer, "w"); - for (i=0;icur_mail_conf]->mail_areas[user->cur_mail_area]->name); - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA){ + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { fprintf(fptr, "YES\r\n"); } else { fprintf(fptr, "NO\r\n"); } } else { fprintf(fptr, "None\r\n"); - fprintf(fptr, "NO\r\n"); + fprintf(fptr, "NO\r\n"); } } fclose(fptr); @@ -519,8 +516,6 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot body = (char *)realloc(body, totlen + 1); } - - memcpy(&body[totlen - len], buffer, len); body[totlen] = '\0'; @@ -545,13 +540,13 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) { if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); } else { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); } } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI && !email) { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->maginode); @@ -571,7 +566,7 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot j = 0; - for (i=0;i 15;i--) { + for (i = strlen(linebuffer) - 1; i > 15; i--) { if (linebuffer[i] == ' ') { linebuffer[i] = '\0'; - strcpy(next_line_buffer, &linebuffer[i+1]); + strcpy(next_line_buffer, &linebuffer[i + 1]); s_printf("\e[%dD\e[0K", 70 - i); break; } @@ -668,10 +663,10 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in if (linebuffer[0] == '/' && strlen(linebuffer) == 2) { if (toupper(linebuffer[1]) == 'S') { - for (i=0;icur_mail_conf]->tagline != NULL) { tagline = conf.mail_conferences[user->cur_mail_conf]->tagline; @@ -683,13 +678,13 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) { if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); } else { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); } } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI && !email) { snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->maginode); @@ -711,7 +706,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in msg = (char *)malloc(size); memset(msg, 0, size); - for (i=0;i 0) { @@ -742,7 +737,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in } if (quote != NULL) { - for (i=0;i= lines) { s_printf(get_string(39)); } else { - for (i=z;iz;i--) { - content[i] = content[i-1]; + for (i = lines; i > z; i--) { + content[i] = content[i - 1]; } content[z] = strdup(linebuffer); @@ -882,7 +877,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in } } if (quote != NULL) { - for (i=0;i 80) { line_at++; char_at -= 80; - } + } } else { char_at++; while (char_at > 80) { @@ -945,7 +940,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { char_at -= 80; } } - + if (line_at > line_count) { line_count = line_at; } @@ -960,7 +955,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { } } else if (state == 2) { param_count = 0; - for (j=0;j<16;j++) { + for (j = 0; j < 16; j++) { params[j] = 0; } state = 3; @@ -973,30 +968,30 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { continue; } else if (body[i] >= '0' && body[i] <= '9') { if (!param_count) param_count = 1; - params[param_count-1] = params[param_count-1] * 10 + (body[i] - '0'); + params[param_count - 1] = params[param_count - 1] * 10 + (body[i] - '0'); continue; } else { state = 4; } } - + if (state == 4) { - switch(body[i]) { + switch (body[i]) { case 'H': case 'f': if (params[0]) params[0]--; if (params[1]) params[1]--; line_at = params[0] + 1; char_at = params[1] + 1; - + if (char_at > 80) { char_at = 80; } - + if (line_at > line_count) { line_count = line_at; } - + state = 0; break; case 'A': @@ -1025,7 +1020,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { if (param_count > 0) { char_at = char_at + params[0]; } else { - char_at ++; + char_at++; } if (char_at > 80) { char_at = 80; @@ -1036,7 +1031,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { if (param_count > 0) { char_at = char_at - params[0]; } else { - char_at --; + char_at--; } if (char_at < 1) { char_at = 1; @@ -1058,23 +1053,23 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { break; } } - } - + } + fake_screen = (struct character_t ***)malloc(sizeof(struct character_t **) * line_count); - for (i=0;ic = ' '; fake_screen[i][j]->fg = fg; fake_screen[i][j]->bg = bg; } } - + line_at = 1; char_at = 1; - - for (i=0;i line_count) line_at = line_count; - fake_screen[line_at -1][char_at - 1]->c = ' '; - fake_screen[line_at -1][char_at - 1]->fg = fg; - fake_screen[line_at -1][char_at - 1]->bg = bg; + fake_screen[line_at - 1][char_at - 1]->c = ' '; + fake_screen[line_at - 1][char_at - 1]->fg = fg; + fake_screen[line_at - 1][char_at - 1]->bg = bg; char_at++; while (char_at > 80) { line_at++; char_at -= 80; - } + } } } else { if (line_at > line_count) line_at = line_count; - fake_screen[line_at -1][char_at - 1]->c = body[i]; - fake_screen[line_at -1][char_at - 1]->fg = fg; - fake_screen[line_at -1][char_at - 1]->bg = bg; + fake_screen[line_at - 1][char_at - 1]->c = body[i]; + fake_screen[line_at - 1][char_at - 1]->fg = fg; + fake_screen[line_at - 1][char_at - 1]->bg = bg; char_at++; while (char_at > 80) { line_at++; @@ -1118,7 +1113,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { } } else if (state == 2) { param_count = 0; - for (j=0;j<16;j++) { + for (j = 0; j < 16; j++) { params[j] = 0; } state = 3; @@ -1131,15 +1126,15 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { continue; } else if (body[i] >= '0' && body[i] <= '9') { if (!param_count) param_count = 1; - params[param_count-1] = params[param_count-1] * 10 + (body[i] - '0'); + params[param_count - 1] = params[param_count - 1] * 10 + (body[i] - '0'); continue; } else { state = 4; } } - + if (state == 4) { - switch(body[i]) { + switch (body[i]) { case 'H': case 'f': if (params[0]) params[0]--; @@ -1174,7 +1169,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { if (param_count > 0) { char_at = char_at + params[0]; } else { - char_at ++; + char_at++; } if (char_at > 80) { char_at = 80; @@ -1185,7 +1180,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { if (param_count > 0) { char_at = char_at - params[0]; } else { - char_at --; + char_at--; } if (char_at < 1) { char_at = 1; @@ -1203,8 +1198,8 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { state = 0; break; case 'm': - for (j=0;jc = ' '; - fake_screen[line_at-1][k]->fg = fg; - fake_screen[line_at-1][k]->bg = bg; + for (k = char_at - 1; k < 80; k++) { + fake_screen[line_at - 1][k]->c = ' '; + fake_screen[line_at - 1][k]->fg = fg; + fake_screen[line_at - 1][k]->bg = bg; } } else if (params[0] == 1) { - for (k=0;kc = ' '; - fake_screen[line_at-1][k]->fg = fg; - fake_screen[line_at-1][k]->bg = bg; + for (k = 0; k < char_at; k++) { + fake_screen[line_at - 1][k]->c = ' '; + fake_screen[line_at - 1][k]->fg = fg; + fake_screen[line_at - 1][k]->bg = bg; } } else if (params[0] == 2) { - for (k=0;k<80;k++) { - fake_screen[line_at-1][k]->c = ' '; - fake_screen[line_at-1][k]->fg = fg; - fake_screen[line_at-1][k]->bg = bg; + for (k = 0; k < 80; k++) { + fake_screen[line_at - 1][k]->c = ' '; + fake_screen[line_at - 1][k]->fg = fg; + fake_screen[line_at - 1][k]->bg = bg; } } state = 0; break; case 'J': if (params[0] == 0) { - for (k=char_at-1;k<80;k++) { - fake_screen[line_at-1][k]->c = ' '; - fake_screen[line_at-1][k]->fg = fg; - fake_screen[line_at-1][k]->bg = bg; + for (k = char_at - 1; k < 80; k++) { + fake_screen[line_at - 1][k]->c = ' '; + fake_screen[line_at - 1][k]->fg = fg; + fake_screen[line_at - 1][k]->bg = bg; } - - for (k=line_at;kc = ' '; fake_screen[k][j]->fg = fg; fake_screen[k][j]->bg = bg; } } } else if (params[0] == 1) { - for (k=0;kc = ' '; - fake_screen[line_at-1][k]->fg = fg; - fake_screen[line_at-1][k]->bg = bg; + for (k = 0; k < char_at; k++) { + fake_screen[line_at - 1][k]->c = ' '; + fake_screen[line_at - 1][k]->fg = fg; + fake_screen[line_at - 1][k]->bg = bg; } - - for (k=line_at-2;k>=0;k--) { - for (j=0;j<80;j++) { + + for (k = line_at - 2; k >= 0; k--) { + for (j = 0; j < 80; j++) { fake_screen[k][j]->c = ' '; fake_screen[k][j]->fg = fg; fake_screen[k][j]->bg = bg; } } } else if (params[0] == 2) { - for (k=0;kc = ' '; fake_screen[k][j]->fg = fg; fake_screen[k][j]->bg = bg; @@ -1379,14 +1373,14 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { fg = 0x07; bg = 0x00; - + out_max = 256; out_len = 0; out = (char *)malloc(256); - - for (i=0;ifg != fg || fake_screen[i][j]->bg != bg) { buffer[buf_at++] = 27; buffer[buf_at++] = '['; @@ -1420,8 +1414,6 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { case 0x07: buffer[buf_at++] = '7'; break; - - } } else { buffer[buf_at++] = '1'; @@ -1452,12 +1444,9 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { case 0x0F: buffer[buf_at++] = '7'; break; - - - } + } } - - + bg = fake_screen[i][j]->bg; buffer[buf_at++] = ';'; buffer[buf_at++] = '4'; @@ -1486,59 +1475,50 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) { case 0x07: buffer[buf_at++] = '7'; break; - - - } + } buffer[buf_at++] = 'm'; } buffer[buf_at++] = fake_screen[i][j]->c; } - - - while (buf_at > 0 && buffer[buf_at-1] == ' ') { + + while (buf_at > 0 && buffer[buf_at - 1] == ' ') { buf_at--; } - + buffer[buf_at++] = '\r'; while (buf_at + out_len > out_max) { out_max += 256; out = (char *)realloc(out, out_max); } - + memcpy(&out[out_len], buffer, buf_at); out_len += buf_at; - } - - for (i=0;icur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { @@ -1616,118 +1596,117 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno lines = 0; chars = 0; - - body2 = body; - z = z2; - - unmangle_ansi(body2, z, &body, &z2); - free(body2); - msg_line_count = 0; - start_line = 0; - - // count the number of lines... - for (z=0;z= 15) { - break; - } - } - s_printf(get_string(187)); + body2 = body; + z = z2; + + unmangle_ansi(body2, z, &body, &z2); + free(body2); + msg_line_count = 0; + start_line = 0; + + // count the number of lines... + for (z = 0; z < z2; z++) { + if (body[z] == '\r' || chars == 80) { + if (msg_line_count == 0) { + msg_lines = (char **)malloc(sizeof(char *)); + } else { + msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1)); + } + + msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1)); + + if (z == start_line) { + msg_lines[msg_line_count][0] = '\0'; + } else { + strncpy(msg_lines[msg_line_count], &body[start_line], z - start_line); + msg_lines[msg_line_count][z - start_line] = '\0'; + } + msg_line_count++; + if (body[z] == '\r') { + start_line = z + 1; + } else { + start_line = z; + } + chars = 0; + } else { + if (body[z] == 27) { + ansi = z; + while (strchr("ABCDEFGHIGJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", body[z]) == NULL) + z++; + if (body[z] == 'm') { + // do nothing + } else { + y = ansi; + for (j = z + 1; j < z2; j++) { + body[y] = body[j]; + y++; + } + z2 = z2 - (z2 - y); + z = ansi - 1; + } + } else { + chars++; + } + } + } + + lines = 0; + + position = 0; + should_break = 0; + + while (!should_break) { + s_printf("\e[7;1H"); + for (z = position; z < msg_line_count; z++) { + + s_printf("%s\e[K\r\n", msg_lines[z]); + + if (z - position >= 15) { + break; + } + } + + s_printf(get_string(187)); if (newscan) { s_printf(get_string(234)); } else { s_printf(get_string(186)); } - c = s_getc(); - - if (tolower(c) == 'r') { - should_break = 1; - } else if (tolower(c) == 'q') { - should_break = 1; + c = s_getc(); + + if (tolower(c) == 'r') { + should_break = 1; + } else if (tolower(c) == 'q') { + should_break = 1; } else if (tolower(c) == 'j' && newscan == 1) { should_break = 1; } else if (tolower(c) == 'f') { should_break = 1; - } else if (c == '\e') { - c = s_getc(); - if (c == 91) { - c = s_getc(); - if (c == 65) { - position--; - if (position < 0) { - position = 0; - } - } else if (c == 66) { - position++; - if (position + 15 >= msg_line_count) { - position--; - } - } else if (c == 67) { - c = ' '; - should_break = 1; - } else if (c == 68) { - c = 'b'; - should_break = 1; - } - } - } - - } + } else if (c == '\e') { + c = s_getc(); + if (c == 91) { + c = s_getc(); + if (c == 65) { + position--; + if (position < 0) { + position = 0; + } + } else if (c == 66) { + position++; + if (position + 15 >= msg_line_count) { + position--; + } + } else if (c == 67) { + c = ' '; + should_break = 1; + } else if (c == 68) { + c = 'b'; + should_break = 1; + } + } + } + } if (tolower(c) == 'r') { JAM_CloseMB(jb); @@ -1783,86 +1762,82 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno free(subject); free(to); free(from); - for (i=0;icur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { jmh.Attribute |= JAM_MSG_TYPEECHO; - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { + if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); } else { sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, + generate_msgid()); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); if (msghs->msgs[mailno]->msgid != NULL) { sprintf(buffer, "%s", msghs->msgs[mailno]->msgid); - jsf.LoID = JAMSFLD_REPLYID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_REPLYID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - jmh.ReplyCRC = JAM_Crc32(buffer, strlen(buffer)); + jmh.ReplyCRC = JAM_Crc32(buffer, strlen(buffer)); } - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI) { sprintf(buffer, "%d", conf.mail_conferences[user->cur_mail_conf]->maginode); - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -1870,23 +1845,23 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno uuid_generate(magi_msgid); uuid_unparse_lower(magi_msgid, buffer); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); if (msghs->msgs[mailno]->msgid != NULL) { sprintf(buffer, "%s", msghs->msgs[mailno]->msgid); - jsf.LoID = JAMSFLD_REPLYID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_REPLYID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - jmh.ReplyCRC = JAM_Crc32(buffer, strlen(buffer)); - } + jmh.ReplyCRC = JAM_Crc32(buffer, strlen(buffer)); + } } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_QWK) { - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(conf.bwave_name); jsf.Buffer = (char *)conf.bwave_name; JAM_PutSubfield(jsp, &jsf); @@ -1898,16 +1873,16 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); } else { sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -1916,45 +1891,44 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno if (from_addr != NULL) { if (from_addr->point) { sprintf(buffer, "%d:%d/%d.%d", from_addr->zone, - from_addr->net, - from_addr->node, - from_addr->point); + from_addr->net, + from_addr->node, + from_addr->point); } else { sprintf(buffer, "%d:%d/%d", from_addr->zone, - from_addr->net, - from_addr->node); + from_addr->net, + from_addr->node); } - jsf.LoID = JAMSFLD_DADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_DADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); free(from_addr); } - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, + generate_msgid()); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); if (msghs->msgs[mailno]->msgid != NULL) { sprintf(buffer, "%s", msghs->msgs[mailno]->msgid); - jsf.LoID = JAMSFLD_REPLYID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_REPLYID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - jmh.ReplyCRC = JAM_Crc32(buffer, strlen(buffer)); + jmh.ReplyCRC = JAM_Crc32(buffer, strlen(buffer)); } - } + } } while (1) { @@ -1970,10 +1944,10 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno free(to); free(from); dolog("Failed to lock msg base!"); - for (i=0;icur_mail_conf, user->cur_mail_area, msghs->msgs[mailno]->msg_h->MsgNum); free(body); } else { - free(body); - } - for (i=0;imsg_count > 0) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); @@ -2088,17 +2062,17 @@ int read_new_msgs(struct user_record *user, struct msg_headers *msghs) { free(jb); if (all_unread == 0) { k = jlr.HighReadMsg; - for (i=0;imsg_count;i++) { + for (i = 0; i < msghs->msg_count; i++) { if (msghs->msgs[i]->msg_h->MsgNum == k) { - i+=2; + i += 2; break; } if (msghs->msgs[i]->msg_h->MsgNum > k) { i++; break; - } + } } - + } else { i = 1; } @@ -2148,7 +2122,7 @@ void read_mail(struct user_record *user) { if (tolower(buffer[0]) == 'n') { if (all_unread == 0) { k = jlr.HighReadMsg; - for (i=0;imsg_count;i++) { + for (i = 0; i < msghs->msg_count; i++) { if (msghs->msgs[i]->msg_h->MsgNum == k) { break; } @@ -2187,7 +2161,7 @@ void post_message(struct user_record *user) { s_JamBase *jb; s_JamMsgHeader jmh; - s_JamSubPacket* jsp; + s_JamSubPacket *jsp; s_JamSubfield jsf; s_JamLastRead jlr; @@ -2264,7 +2238,7 @@ void post_message(struct user_record *user) { return; } - JAM_ClearMsgHeader( &jmh ); + JAM_ClearMsgHeader(&jmh); jmh.DateWritten = (uint32_t)utc_to_local(time(NULL)); jmh.Attribute |= JAM_MSG_LOCAL; if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) { @@ -2275,20 +2249,20 @@ void post_message(struct user_record *user) { jsp = JAM_NewSubPacket(); - jsf.LoID = JAMSFLD_SENDERNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_SENDERNAME; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - jsf.LoID = JAMSFLD_RECVRNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_RECVRNAME; + jsf.HiID = 0; jsf.DatLen = strlen(to); jsf.Buffer = (char *)to; JAM_PutSubfield(jsp, &jsf); - jsf.LoID = JAMSFLD_SUBJECT; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_SUBJECT; + jsf.HiID = 0; jsf.DatLen = strlen(subject); jsf.Buffer = (char *)subject; JAM_PutSubfield(jsp, &jsf); @@ -2299,28 +2273,28 @@ void post_message(struct user_record *user) { if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); } else { sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, + generate_msgid()); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -2328,26 +2302,25 @@ void post_message(struct user_record *user) { } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI) { sprintf(buffer, "%d", conf.mail_conferences[user->cur_mail_conf]->maginode); - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - uuid_generate(magi_msgid); uuid_unparse_lower(magi_msgid, buffer); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_QWK) { - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(conf.bwave_name); jsf.Buffer = (char *)conf.bwave_name; JAM_PutSubfield(jsp, &jsf); @@ -2358,16 +2331,16 @@ void post_message(struct user_record *user) { if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); } else { sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -2375,16 +2348,16 @@ void post_message(struct user_record *user) { if (from_addr != NULL) { if (from_addr->point) { sprintf(buffer, "%d:%d/%d.%d", from_addr->zone, - from_addr->net, - from_addr->node, - from_addr->point); + from_addr->net, + from_addr->node, + from_addr->point); } else { sprintf(buffer, "%d:%d/%d", from_addr->zone, - from_addr->net, - from_addr->node); + from_addr->net, + from_addr->node); } - jsf.LoID = JAMSFLD_DADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_DADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -2393,18 +2366,18 @@ void post_message(struct user_record *user) { } sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, + generate_msgid()); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - } + } } while (1) { @@ -2494,7 +2467,7 @@ void list_messages(struct user_record *user) { if (tolower(buffer[0]) == 'n') { if (all_unread == 0) { k = jlr.HighReadMsg; - for (i=0;imsg_count;i++) { + for (i = 0; i < msghs->msg_count; i++) { if (msghs->msgs[i]->msg_h->MsgNum == k) { break; } @@ -2502,9 +2475,9 @@ void list_messages(struct user_record *user) { if (i == msghs->msg_count - 1) { i = 1; } else { - i+=2; + i += 2; } - + } else { i = 1; } @@ -2515,22 +2488,21 @@ void list_messages(struct user_record *user) { } } closed = 0; - redraw = 1; - start = i-1; + start = i - 1; while (!closed) { if (redraw) { s_printf(get_string(126)); - for (j=start;jmsg_count;j++) { + for (j = start; j < start + 22 && j < msghs->msg_count; j++) { gmtime_r((time_t *)&msghs->msgs[j]->msg_h->DateWritten, &msg_date); - if (j == i -1) { + if (j == i - 1) { if (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[j]->msg_h->MsgNum)) { if (conf.date_style == 1) { s_printf(get_string(286), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { s_printf(get_string(286), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } + } } else if (msghs->msgs[j]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { if (conf.date_style == 1) { s_printf(get_string(188), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); @@ -2550,7 +2522,7 @@ void list_messages(struct user_record *user) { s_printf(get_string(287), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { s_printf(get_string(287), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } + } } else if (msghs->msgs[j]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { if (conf.date_style == 1) { s_printf(get_string(127), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); @@ -2587,59 +2559,59 @@ void list_messages(struct user_record *user) { } redraw = 1; } - if (i-1 == msghs->msg_count) { + if (i - 1 == msghs->msg_count) { i--; s_printf("\e[%d;5H", i - start + 1); } else if (!redraw) { s_printf("\e[%d;1H", i - start); - gmtime_r((time_t *)&msghs->msgs[i-2]->msg_h->DateWritten, &msg_date); - if (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[i-2]->msg_h->MsgNum)) { + gmtime_r((time_t *)&msghs->msgs[i - 2]->msg_h->DateWritten, &msg_date); + if (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[i - 2]->msg_h->MsgNum)) { if (conf.date_style == 1) { - s_printf(get_string(287), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(287), i - 1, msghs->msgs[i - 2]->subject, msghs->msgs[i - 2]->from, msghs->msgs[i - 2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(287), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - } else if (msghs->msgs[i-2]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(287), i - 1, msghs->msgs[i - 2]->subject, msghs->msgs[i - 2]->from, msghs->msgs[i - 2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + } else if (msghs->msgs[i - 2]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { if (conf.date_style == 1) { - s_printf(get_string(127), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(127), i - 1, msghs->msgs[i - 2]->subject, msghs->msgs[i - 2]->from, msghs->msgs[i - 2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(127), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(127), i - 1, msghs->msgs[i - 2]->subject, msghs->msgs[i - 2]->from, msghs->msgs[i - 2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } else { if (conf.date_style == 1) { - s_printf(get_string(128), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(128), i - 1, msghs->msgs[i - 2]->subject, msghs->msgs[i - 2]->from, msghs->msgs[i - 2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(128), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(128), i - 1, msghs->msgs[i - 2]->subject, msghs->msgs[i - 2]->from, msghs->msgs[i - 2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - } + } s_printf("\e[%d;1H", i - start + 1); - gmtime_r((time_t *)&msghs->msgs[i-1]->msg_h->DateWritten, &msg_date); - if (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[i-1]->msg_h->MsgNum)) { + gmtime_r((time_t *)&msghs->msgs[i - 1]->msg_h->DateWritten, &msg_date); + if (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[i - 1]->msg_h->MsgNum)) { if (conf.date_style == 1) { - s_printf(get_string(286), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(286), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(286), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - } else if (msghs->msgs[i-1]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(286), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + } else if (msghs->msgs[i - 1]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { if (conf.date_style == 1) { - s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(188), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(188), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } else { if (conf.date_style == 1) { - s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(189), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(189), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - } + } s_printf("\e[%d;5H", i - start + 1); } } else if (c == 65) { // up i--; if (i - 1 < start) { - start -=22; + start -= 22; if (start < 0) { start = 0; } @@ -2657,7 +2629,7 @@ void list_messages(struct user_record *user) { s_printf(get_string(287), i + 1, msghs->msgs[i]->subject, msghs->msgs[i]->from, msghs->msgs[i]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { s_printf(get_string(287), i + 1, msghs->msgs[i]->subject, msghs->msgs[i]->from, msghs->msgs[i]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } + } } else if (msghs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { if (conf.date_style == 1) { s_printf(get_string(127), i + 1, msghs->msgs[i]->subject, msghs->msgs[i]->from, msghs->msgs[i]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); @@ -2670,31 +2642,30 @@ void list_messages(struct user_record *user) { } else { s_printf(get_string(128), i + 1, msghs->msgs[i]->subject, msghs->msgs[i]->from, msghs->msgs[i]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - } + } s_printf("\e[%d;1H", i - start + 1); - gmtime_r((time_t *)&msghs->msgs[i-1]->msg_h->DateWritten, &msg_date); - if (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[i-1]->msg_h->MsgNum)) { + gmtime_r((time_t *)&msghs->msgs[i - 1]->msg_h->DateWritten, &msg_date); + if (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[i - 1]->msg_h->MsgNum)) { if (conf.date_style == 1) { - s_printf(get_string(286), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(286), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(286), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - } else if (msghs->msgs[i-1]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(286), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + } else if (msghs->msgs[i - 1]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { if (conf.date_style == 1) { - s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(188), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(188), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } else { if (conf.date_style == 1) { - s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + s_printf(get_string(189), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf(get_string(189), i, msghs->msgs[i - 1]->subject, msghs->msgs[i - 1]->from, msghs->msgs[i - 1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - } - s_printf("\e[%d;5H", i - start + 1); - - } + } + s_printf("\e[%d;5H", i - start + 1); + } } else if (c == 75) { // END KEY i = msghs->msg_count; @@ -2742,7 +2713,7 @@ void list_messages(struct user_record *user) { dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (msghs != NULL) { free_message_headers(msghs); - } + } return; } else { all_unread = 0; @@ -2756,7 +2727,7 @@ void list_messages(struct user_record *user) { } } else if (tolower(c) == 'f') { redraw = 1; - msgbase_flag_unflag(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[i-1]->msg_h->MsgNum); + msgbase_flag_unflag(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[i - 1]->msg_h->MsgNum); } } } @@ -2783,7 +2754,7 @@ void choose_conference() { int selected = 0; char c; - for (i=0;isec_level <= gUser->sec_level) { if (list_tmp == 0) { conf_tmp = (struct conf_tmp_t **)malloc(sizeof(struct conf_tmp_t *)); @@ -2803,7 +2774,7 @@ void choose_conference() { s_printf("\e[2J\e[1;1H"); s_printf(get_string(247)); s_printf(get_string(248)); - for (i=start;iindex, conf_tmp[i]->conference->name); } else { @@ -2833,7 +2804,7 @@ void choose_conference() { if (selected >= list_tmp) { selected = list_tmp - 1; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(250), selected - start + 1, conf_tmp[selected - 1]->index, conf_tmp[selected - 1]->conference->name); s_printf(get_string(249), selected - start + 2, conf_tmp[selected]->index, conf_tmp[selected]->conference->name); s_printf("\e[%d;5H", selected - start + 2); @@ -2852,11 +2823,11 @@ void choose_conference() { if (selected < 0) { selected = 0; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(249), selected - start + 2, conf_tmp[selected]->index, conf_tmp[selected]->conference->name); s_printf(get_string(250), selected - start + 3, conf_tmp[selected + 1]->index, conf_tmp[selected + 1]->conference->name); s_printf("\e[%d;5H", selected - start + 2); - } + } } } else if (c == 75) { // END KEY @@ -2889,7 +2860,7 @@ void choose_conference() { // PAGE DOWN selected = selected + 22; if (selected >= list_tmp) { - selected = list_tmp -1; + selected = list_tmp - 1; } start = selected; redraw = 1; @@ -2902,7 +2873,7 @@ void choose_conference() { } } - for (i=0;icur_mail_conf]->mail_area_count;i++) { + for (i = 0; i < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; i++) { if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i]->read_sec_level <= gUser->sec_level) { if (list_tmp == 0) { area_tmp = (struct area_tmp_t **)malloc(sizeof(struct area_tmp_t *)); @@ -2956,7 +2926,7 @@ void choose_area() { } s_printf(get_string(251), conf.mail_conferences[gUser->cur_mail_conf]->name); s_printf(get_string(248)); - for (i=start;icur_mail_conf, area_tmp[i]->index)) { s_printf(get_string(259), i - start + offset, area_tmp[i]->index, area_tmp[i]->area->name); @@ -2966,7 +2936,7 @@ void choose_area() { } else { if (new_messages(gUser, gUser->cur_mail_conf, area_tmp[i]->index)) { s_printf(get_string(260), i - start + offset, area_tmp[i]->index, area_tmp[i]->area->name); - } else { + } else { s_printf(get_string(250), i - start + offset, area_tmp[i]->index, area_tmp[i]->area->name); } } @@ -2994,7 +2964,7 @@ void choose_area() { if (selected >= list_tmp) { selected = list_tmp - 1; } else { - if (!redraw) { + if (!redraw) { if (new_messages(gUser, gUser->cur_mail_conf, area_tmp[selected - 1]->index)) { s_printf(get_string(260), selected - start + (offset - 1), area_tmp[selected - 1]->index, area_tmp[selected - 1]->area->name); } else { @@ -3021,7 +2991,7 @@ void choose_area() { if (selected < 0) { selected = 0; } else { - if (!redraw) { + if (!redraw) { if (new_messages(gUser, gUser->cur_mail_conf, area_tmp[selected]->index)) { s_printf(get_string(259), selected - start + offset, area_tmp[selected]->index, area_tmp[selected]->area->name); } else { @@ -3033,7 +3003,7 @@ void choose_area() { s_printf(get_string(250), selected - start + (offset + 1), area_tmp[selected + 1]->index, area_tmp[selected + 1]->area->name); } s_printf("\e[%d;5H", selected - start + offset); - } + } } } else if (c == 75) { // END KEY @@ -3066,7 +3036,7 @@ void choose_area() { // PAGE DOWN selected = selected + height; if (selected >= list_tmp) { - selected = list_tmp -1; + selected = list_tmp - 1; } start = selected; redraw = 1; @@ -3078,21 +3048,20 @@ void choose_area() { } } - for (i=0;icur_mail_conf;icur_mail_conf; i < conf.mail_conference_count; i++) { if (i + 1 == conf.mail_conference_count) { i = -1; } - if (conf.mail_conferences[i+1]->sec_level <= user->sec_level) { + if (conf.mail_conferences[i + 1]->sec_level <= user->sec_level) { user->cur_mail_conf = i + 1; user->cur_mail_area = 0; break; @@ -3102,11 +3071,11 @@ void next_mail_conf(struct user_record *user) { void prev_mail_conf(struct user_record *user) { int i; - for (i=user->cur_mail_conf;i>=0;i--) { + for (i = user->cur_mail_conf; i >= 0; i--) { if (i - 1 == -1) { i = conf.mail_conference_count; } - if (conf.mail_conferences[i-1]->sec_level <= user->sec_level) { + if (conf.mail_conferences[i - 1]->sec_level <= user->sec_level) { user->cur_mail_conf = i - 1; user->cur_mail_area = 0; break; @@ -3116,11 +3085,11 @@ void prev_mail_conf(struct user_record *user) { void next_mail_area(struct user_record *user) { int i; - for (i=user->cur_mail_area;icur_mail_conf]->mail_area_count;i++) { + for (i = user->cur_mail_area; i < conf.mail_conferences[user->cur_mail_conf]->mail_area_count; i++) { if (i + 1 == conf.mail_conferences[user->cur_mail_conf]->mail_area_count) { i = -1; } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i+1]->read_sec_level <= user->sec_level) { + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i + 1]->read_sec_level <= user->sec_level) { user->cur_mail_area = i + 1; break; } @@ -3129,19 +3098,17 @@ void next_mail_area(struct user_record *user) { void prev_mail_area(struct user_record *user) { int i; - for (i=user->cur_mail_area;i>=0;i--) { + for (i = user->cur_mail_area; i >= 0; i--) { if (i - 1 == -1) { i = conf.mail_conferences[user->cur_mail_conf]->mail_area_count; } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i-1]->read_sec_level <= user->sec_level) { + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i - 1]->read_sec_level <= user->sec_level) { user->cur_mail_area = i - 1; break; } } } - - void do_mail_scan(struct user_record *user, int oldscan, int personal) { s_JamBase *jb; s_JamBaseHeader jbh; @@ -3166,41 +3133,41 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { c = s_getc(); if (tolower(c) == 'y' || tolower(c) == 's') { - for (i=0;isec_level > user->sec_level) { continue; } if (oldscan) { s_printf(get_string(140), i, conf.mail_conferences[i]->name); - - lines+=2; + + lines += 2; if (lines == 22) { s_printf(get_string(6)); s_getc(); lines = 0; } } - for (j=0;jmail_area_count;j++) { + for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level > user->sec_level) { continue; } - + if (tolower(c) == 's' && !msgbase_is_subscribed(i, j)) { continue; } - + jb = open_jam_base(conf.mail_conferences[i]->mail_areas[j]->path); if (!jb) { dolog("Unable to open message base"); continue; } - + if (JAM_ReadMBHeader(jb, &jbh) != 0) { JAM_CloseMB(jb); free(jb); continue; } - + if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { if (jbh.ActiveMsgs == 0) { JAM_CloseMB(jb); @@ -3222,20 +3189,20 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } else { s_printf("\e[2J\e[1;1H"); s_printf(get_string(277), i, conf.mail_conferences[i]->name); - s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); + s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); s_printf(get_string(279)); - + ch = s_getchar(); s_printf("\r\n"); - if (tolower(ch) == 'y') { + if (tolower(ch) == 'y') { orig_conf = user->cur_mail_conf; orig_area = user->cur_mail_area; - + user->cur_mail_conf = i; user->cur_mail_area = j; - + res = read_new_msgs(user, msghs); - + user->cur_mail_conf = orig_conf; user->cur_mail_area = orig_area; } @@ -3255,24 +3222,24 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } else { msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { - + if (msghs->msg_count > 0) { s_printf("\e[2J\e[1;1H"); s_printf(get_string(277), i, conf.mail_conferences[i]->name); - s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); + s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); s_printf(get_string(279)); ch = s_getchar(); s_printf("\r\n"); - if (tolower(ch) == 'y') { + if (tolower(ch) == 'y') { orig_conf = user->cur_mail_conf; orig_area = user->cur_mail_area; - + user->cur_mail_conf = i; user->cur_mail_area = j; - + res = read_new_msgs(user, msghs); - + user->cur_mail_conf = orig_conf; user->cur_mail_area = orig_area; } @@ -3284,20 +3251,18 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } else { if (jlr.HighReadMsg < jbh.ActiveMsgs) { - - if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { if (msghs->msg_count > 0) { unread_count = 0; - for (k=msghs->msg_count-1;k>=0;k--) { + for (k = msghs->msg_count - 1; k >= 0; k--) { if (msghs->msgs[k]->msg_no < jlr.HighReadMsg) { break; } unread_count++; - } + } if (unread_count > 0) { if (oldscan) { s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); @@ -3310,20 +3275,20 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } else { s_printf("\e[2J\e[1;1H"); s_printf(get_string(277), i, conf.mail_conferences[i]->name); - s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); + s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); s_printf(get_string(279)); - + ch = s_getchar(); s_printf("\r\n"); - if (tolower(ch) == 'y') { + if (tolower(ch) == 'y') { orig_conf = user->cur_mail_conf; orig_area = user->cur_mail_area; - + user->cur_mail_conf = i; user->cur_mail_area = j; - + res = read_new_msgs(user, msghs); - + user->cur_mail_conf = orig_conf; user->cur_mail_area = orig_area; } @@ -3344,32 +3309,32 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } else { msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { - if (msghs->msg_count > 0) { + if (msghs->msg_count > 0) { unread_count = 0; - for (k=msghs->msg_count-1;k>=0;k--) { + for (k = msghs->msg_count - 1; k >= 0; k--) { if (msghs->msgs[k]->msg_no < jlr.HighReadMsg) { break; } unread_count++; } - if (unread_count > 0) { + if (unread_count > 0) { s_printf("\e[2J\e[1;1H"); s_printf(get_string(277), i, conf.mail_conferences[i]->name); - s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); + s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); s_printf(get_string(279)); - + ch = s_getchar(); s_printf("\r\n"); - if (tolower(ch) == 'y') { + if (tolower(ch) == 'y') { orig_conf = user->cur_mail_conf; orig_area = user->cur_mail_area; - + user->cur_mail_conf = i; user->cur_mail_area = j; - + res = read_new_msgs(user, msghs); - + user->cur_mail_conf = orig_conf; user->cur_mail_area = orig_area; } @@ -3393,9 +3358,9 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } if (res) { break; - } + } } - + s_printf(get_string(6)); s_getc(); } @@ -3413,7 +3378,6 @@ void mail_scan(struct user_record *user) { do_mail_scan(user, 1, 0); } - void msg_conf_sub_bases() { int i; int lines = 0; @@ -3422,15 +3386,15 @@ void msg_conf_sub_bases() { int done = 0; int j; s_printf("\e[1;1H\e[2J"); - + do { - - for (i=0;icur_mail_conf]->mail_area_count;i++) { + + for (i = 0; i < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; i++) { if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i]->read_sec_level <= gUser->sec_level) { s_printf(get_string(226), i, (msgbase_is_subscribed(gUser->cur_mail_conf, i) ? get_string(227) : get_string(228)), conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i]->name); lines++; } - + if (lines == 23) { s_printf(get_string(225)); s_readstring(buffer, 9); @@ -3442,11 +3406,11 @@ void msg_conf_sub_bases() { msgbase_sub_unsub(gUser->cur_mail_conf, toggle_area); } lines = 0; - + break; } if (buffer[0] == 'a' || buffer[0] == 'A') { - for (j=0;jcur_mail_conf]->mail_area_count;j++) { + for (j = 0; j < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; j++) { if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[j]->read_sec_level <= gUser->sec_level) { if (!msgbase_is_subscribed(gUser->cur_mail_conf, j)) { msgbase_sub_unsub(gUser->cur_mail_conf, j); @@ -3456,7 +3420,7 @@ void msg_conf_sub_bases() { break; } if (buffer[0] == 'n' || buffer[0] == 'N') { - for (j=0;jcur_mail_conf]->mail_area_count;j++) { + for (j = 0; j < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; j++) { if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[j]->read_sec_level <= gUser->sec_level) { if (msgbase_is_subscribed(gUser->cur_mail_conf, j)) { msgbase_sub_unsub(gUser->cur_mail_conf, j); @@ -3464,12 +3428,12 @@ void msg_conf_sub_bases() { } } break; - } + } } lines = 0; } } - + if (lines > 0) { s_printf(get_string(225)); s_readstring(buffer, 9); @@ -3482,7 +3446,7 @@ void msg_conf_sub_bases() { } lines = 0; } else if (buffer[0] == 'a' || buffer[0] == 'A') { - for (j=0;jcur_mail_conf]->mail_area_count;j++) { + for (j = 0; j < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; j++) { if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[j]->read_sec_level <= gUser->sec_level) { if (!msgbase_is_subscribed(gUser->cur_mail_conf, j)) { msgbase_sub_unsub(gUser->cur_mail_conf, j); @@ -3490,13 +3454,13 @@ void msg_conf_sub_bases() { } } } else if (buffer[0] == 'n' || buffer[0] == 'N') { - for (j=0;jcur_mail_conf]->mail_area_count;j++) { + for (j = 0; j < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; j++) { if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[j]->read_sec_level <= gUser->sec_level) { if (msgbase_is_subscribed(gUser->cur_mail_conf, j)) { msgbase_sub_unsub(gUser->cur_mail_conf, j); } } - } + } } else { done = 1; } @@ -3545,7 +3509,7 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { } } - for (i=0;jid, &jlr) != JAM_NO_USER) { jlr.LastReadMsg = max_msg; @@ -3568,7 +3532,7 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { jlr.LastReadMsg = max_msg; jlr.HighReadMsg = max_msg; jlr.UserCRC = JAM_Crc32(gUser->loginname, strlen(gUser->loginname)); - jlr.UserID = gUser->id; + jlr.UserID = gUser->id; JAM_WriteLastRead(jb, gUser->id, &jlr); } JAM_CloseMB(jb); @@ -3577,9 +3541,9 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { void msgbase_reset_all_pointers(int readm) { int i, j; - - for (i=0;imail_area_count;j++) { + + for (i = 0; i < conf.mail_conference_count; i++) { + for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { msgbase_reset_pointers(i, j, readm, -1); } } @@ -3591,7 +3555,7 @@ int new_messages(struct user_record *user, int conference, int area) { s_JamBaseHeader jbh; s_JamLastRead jlr; struct msg_headers *msghs; - + jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); if (!jb) { return 0; @@ -3618,8 +3582,8 @@ int new_messages(struct user_record *user, int conference, int area) { msghs = read_message_headers(conference, area, user, 0); if (msghs != NULL) { if (msghs->msg_count > 0) { - if (msghs->msgs[msghs->msg_count-1]->msg_h->MsgNum > jlr.HighReadMsg) { - count = msghs->msgs[msghs->msg_count-1]->msg_h->MsgNum - jlr.HighReadMsg; + if (msghs->msgs[msghs->msg_count - 1]->msg_h->MsgNum > jlr.HighReadMsg) { + count = msghs->msgs[msghs->msg_count - 1]->msg_h->MsgNum - jlr.HighReadMsg; } } free_message_headers(msghs); diff --git a/src/main.c b/src/main.c index ecd42b2..9e10b1f 100644 --- a/src/main.c +++ b/src/main.c @@ -17,16 +17,16 @@ #include #include #if defined(linux) -# include -#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) -# include +#include +#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) +#include #elif defined(__FreeBSD__) -# include +#include #elif defined(__sun) -# include "os/sunos.h" +#include "os/sunos.h" #endif #if defined(ENABLE_WWW) -# include +#include #endif #include #include "bbs.h" @@ -51,8 +51,7 @@ int bbs_stderr; struct MHD_Daemon *www_daemon; #endif -void sigterm_handler(int s) -{ +void sigterm_handler(int s) { if (ssh_pid != -1) { kill(ssh_pid, SIGTERM); } @@ -66,28 +65,27 @@ void sigterm_handler(int s) #endif if (ipv6_pid != -1) { kill(ipv6_pid, SIGTERM); - } + } remove(conf.pid_file); exit(0); } -void sigchld_handler(int s) -{ - // waitpid() might overwrite errno, so we save and restore it: - int saved_errno = errno; +void sigchld_handler(int s) { + // waitpid() might overwrite errno, so we save and restore it: + int saved_errno = errno; - while(waitpid(-1, NULL, WNOHANG) > 0); + while (waitpid(-1, NULL, WNOHANG) > 0) + ; - errno = saved_errno; + errno = saved_errno; } -static int protocol_config_handler(void* user, const char* section, const char* name, - const char* value) -{ +static int protocol_config_handler(void *user, const char *section, const char *name, + const char *value) { struct bbs_config *conf = (struct bbs_config *)user; int i; - for (i=0;iprotocol_count;i++) { + for (i = 0; i < conf->protocol_count; i++) { if (strcasecmp(conf->protocols[i]->name, section) == 0) { // found it if (strcasecmp(name, "upload command") == 0) { @@ -129,7 +127,7 @@ static int protocol_config_handler(void* user, const char* section, const char* conf->protocols[conf->protocol_count]->internal_zmodem = 0; conf->protocols[conf->protocol_count]->upload_prompt = 0; conf->protocols[conf->protocol_count]->stdio = 0; - + if (strcasecmp(name, "upload command") == 0) { conf->protocols[conf->protocol_count]->upload = strdup(value); } else if (strcasecmp(name, "download command") == 0) { @@ -158,13 +156,12 @@ static int protocol_config_handler(void* user, const char* section, const char* return 1; } -static int archiver_config_handler(void* user, const char* section, const char* name, - const char* value) -{ +static int archiver_config_handler(void *user, const char *section, const char *name, + const char *value) { struct bbs_config *conf = (struct bbs_config *)user; int i; - for (i=0;iarchiver_count;i++) { + for (i = 0; i < conf->archiver_count; i++) { if (strcasecmp(conf->archivers[i]->name, section) == 0) { // found it if (strcasecmp(name, "extension") == 0) { @@ -200,13 +197,12 @@ static int archiver_config_handler(void* user, const char* section, const char* return 1; } -static int door_config_handler(void* user, const char* section, const char* name, - const char* value) -{ +static int door_config_handler(void *user, const char *section, const char *name, + const char *value) { struct bbs_config *conf = (struct bbs_config *)user; int i; - for (i=0;idoor_count;i++) { + for (i = 0; i < conf->door_count; i++) { if (strcasecmp(conf->doors[i]->name, section) == 0) { // found it if (strcasecmp(name, "command") == 0) { @@ -251,9 +247,8 @@ static int door_config_handler(void* user, const char* section, const char* name return 1; } -static int file_sub_handler(void* user, const char* section, const char* name, - const char* value) -{ +static int file_sub_handler(void *user, const char *section, const char *name, + const char *value) { struct file_directory *fd = (struct file_directory *)user; int i; @@ -269,7 +264,7 @@ static int file_sub_handler(void* user, const char* section, const char* name, } } else { // check if it's partially filled in - for (i=0;ifile_sub_count;i++) { + for (i = 0; i < fd->file_sub_count; i++) { if (strcasecmp(fd->file_subs[i]->name, section) == 0) { if (strcasecmp(name, "upload sec level") == 0) { fd->file_subs[i]->upload_sec_level = atoi(value); @@ -306,10 +301,8 @@ static int file_sub_handler(void* user, const char* section, const char* name, return 1; } - -static int mail_area_handler(void* user, const char* section, const char* name, - const char* value) -{ +static int mail_area_handler(void *user, const char *section, const char *name, + const char *value) { struct mail_conference *mc = (struct mail_conference *)user; int i; @@ -351,7 +344,7 @@ static int mail_area_handler(void* user, const char* section, const char* name, } } else { // check if it's partially filled in - for (i=0;imail_area_count;i++) { + for (i = 0; i < mc->mail_area_count; i++) { if (strcasecmp(mc->mail_areas[i]->name, section) == 0) { if (strcasecmp(name, "read sec level") == 0) { mc->mail_areas[i]->read_sec_level = atoi(value); @@ -385,9 +378,9 @@ static int mail_area_handler(void* user, const char* section, const char* name, } mc->mail_areas[mc->mail_area_count] = (struct mail_area *)malloc(sizeof(struct mail_area)); - + mc->mail_areas[mc->mail_area_count]->qwkname = NULL; - + mc->mail_areas[mc->mail_area_count]->name = strdup(section); if (strcasecmp(name, "read sec level") == 0) { mc->mail_areas[mc->mail_area_count]->read_sec_level = atoi(value); @@ -416,9 +409,8 @@ static int mail_area_handler(void* user, const char* section, const char* name, return 1; } -static int handler(void* user, const char* section, const char* name, - const char* value) -{ +static int handler(void *user, const char *section, const char *name, + const char *value) { struct bbs_config *conf = (struct bbs_config *)user; struct passwd *pwd; @@ -432,7 +424,7 @@ static int handler(void* user, const char* section, const char* name, conf->ssh_server = 1; } else { conf->ssh_server = 0; - } + } } else if (strcasecmp(name, "enable ipv6") == 0) { if (strcasecmp(value, "true") == 0) { conf->ipv6 = 1; @@ -486,7 +478,7 @@ static int handler(void* user, const char* section, const char* name, } } else if (strcasecmp(name, "automessage write level") == 0) { conf->automsgwritelvl = atoi(value); - } else if (strcasecmp(name, "fork") == 0) { + } else if (strcasecmp(name, "fork") == 0) { if (strcasecmp(value, "true") == 0) { conf->fork = 1; } else { @@ -548,7 +540,7 @@ static int handler(void* user, const char* section, const char* name, conf->gid = pwd->pw_gid; } } - } else if (strcasecmp(section, "paths") == 0){ + } else if (strcasecmp(section, "paths") == 0) { if (strcasecmp(name, "ansi path") == 0) { conf->ansi_path = strdup(value); } else if (strcasecmp(name, "bbs path") == 0) { @@ -612,7 +604,6 @@ static int handler(void* user, const char* section, const char* name, conf->text_files[conf->text_file_count]->name = strdup(name); conf->text_files[conf->text_file_count]->path = strdup(value); conf->text_file_count++; - } return 1; @@ -625,15 +616,15 @@ int ssh_authenticate(ssh_session p_ssh_session) { do { message = ssh_message_get(p_ssh_session); - + if (message == NULL) { gUser = NULL; - return 0; + return 0; } - switch(ssh_message_type(message)) { + switch (ssh_message_type(message)) { case SSH_REQUEST_AUTH: - switch(ssh_message_subtype(message)) { + switch (ssh_message_subtype(message)) { case SSH_AUTH_METHOD_PASSWORD: username = ssh_message_auth_user(message); password = ssh_message_auth_password(message); @@ -666,7 +657,7 @@ int ssh_authenticate(ssh_session p_ssh_session) { } ssh_message_free(message); - } while(1); + } while (1); } /* char *ssh_getip(ssh_session session) { @@ -683,57 +674,56 @@ char *ssh_getip(ssh_session session) { } */ static int ssh_copy_fd_to_chan(socket_t fd, int revents, void *userdata) { - ssh_channel chan = (ssh_channel)userdata; - char buf[2048]; - int sz = 0; + ssh_channel chan = (ssh_channel)userdata; + char buf[2048]; + int sz = 0; - if(!chan) { - close(fd); - return -1; - } - if(revents & POLLIN) { - sz = read(fd, buf, 2048); - if(sz > 0) { - ssh_channel_write(chan, buf, sz); - } - } - if(revents & POLLHUP) { - ssh_channel_close(chan); - sz = -1; - } - return sz; + if (!chan) { + close(fd); + return -1; + } + if (revents & POLLIN) { + sz = read(fd, buf, 2048); + if (sz > 0) { + ssh_channel_write(chan, buf, sz); + } + } + if (revents & POLLHUP) { + ssh_channel_close(chan); + sz = -1; + } + return sz; } static int ssh_copy_chan_to_fd(ssh_session session, - ssh_channel channel, - void *data, - uint32_t len, - int is_stderr, - void *userdata) { - int fd = *(int*)userdata; - int sz; - (void)session; - (void)channel; - (void)is_stderr; + ssh_channel channel, + void *data, + uint32_t len, + int is_stderr, + void *userdata) { + int fd = *(int *)userdata; + int sz; + (void)session; + (void)channel; + (void)is_stderr; - sz = write(fd, data, len); - return sz; + sz = write(fd, data, len); + return sz; } static void ssh_chan_close(ssh_session session, ssh_channel channel, void *userdata) { - int fd = *(int*)userdata; + int fd = *(int *)userdata; int status; - (void)session; - (void)channel; - close(fd); + (void)session; + (void)channel; + close(fd); } struct ssh_channel_callbacks_struct ssh_cb = { - .channel_data_function = ssh_copy_chan_to_fd, - .channel_eof_function = ssh_chan_close, - .channel_close_function = ssh_chan_close, - .userdata = NULL -}; + .channel_data_function = ssh_copy_chan_to_fd, + .channel_eof_function = ssh_chan_close, + .channel_close_function = ssh_chan_close, + .userdata = NULL}; void serverssh(int port, int ipv6) { ssh_session p_ssh_session; @@ -762,7 +752,7 @@ void serverssh(int port, int ipv6) { bbs_stdin = dup(STDIN_FILENO); bbs_stdout = dup(STDOUT_FILENO); bbs_stderr = dup(STDERR_FILENO); - + err = ssh_init(); if (err == -1) { fprintf(stderr, "Error starting SSH server.\n"); @@ -789,7 +779,6 @@ void serverssh(int port, int ipv6) { exit(-1); } - if (setsockopt(ssh_sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { fprintf(stderr, "setsockopt(SO_REUSEADDR) failed"); exit(-1); @@ -799,7 +788,7 @@ void serverssh(int port, int ipv6) { if (setsockopt(ssh_sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) { fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed"); } - + memset(&server, 0, sizeof(server)); server.sin6_family = AF_INET6; server.sin6_addr = in6addr_any; @@ -828,7 +817,7 @@ void serverssh(int port, int ipv6) { } c = sizeof(struct sockaddr_in); } - + if (conf.uid != getuid()) { if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) { perror("SetUID Failed: "); @@ -838,23 +827,23 @@ void serverssh(int port, int ipv6) { } listen(ssh_sock, 3); - + while ((csock = accept(ssh_sock, (struct sockaddr *)client_p, (socklen_t *)&c))) { p_ssh_session = ssh_new(); if (p_ssh_session == NULL) { fprintf(stderr, "Error starting SSH session.\n"); close(csock); continue; - } + } if (ssh_bind_accept_fd(p_ssh_bind, p_ssh_session, csock) == SSH_OK) { if (ipv6) { ip = strdup(inet_ntop(AF_INET6, &((struct sockaddr_in6 *)client_p)->sin6_addr, str, sizeof(str))); } else { ip = strdup(inet_ntop(AF_INET, &((struct sockaddr_in *)client_p)->sin_addr, str, sizeof(str))); - } + } if (conf.ipguard_enable) { i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard)); - + if (i == MAP_MISSING) { ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard)); ip_guard->status = IP_STATUS_UNKNOWN; @@ -862,7 +851,7 @@ void serverssh(int port, int ipv6) { ip_guard->connection_count = 1; hashmap_put(ip_guard_map, strdup(ip), ip_guard); } else if (i == MAP_OK) { - + if (ip_guard->status == IP_STATUS_BLACKLISTED) { free(ip); ssh_disconnect(p_ssh_session); @@ -879,16 +868,15 @@ void serverssh(int port, int ipv6) { free(ip); ssh_disconnect(p_ssh_session); continue; - } } else { ip_guard->connection_count = 0; ip_guard->last_connection = time(NULL); } } - } - } - + } + } + pid = fork(); if (pid == 0) { close(ssh_sock); @@ -912,7 +900,7 @@ void serverssh(int port, int ipv6) { } else { break; } - } while(!chan); + } while (!chan); if (!chan) { fprintf(stderr, "Failed to get channel\n"); ssh_finalize(); @@ -924,7 +912,7 @@ void serverssh(int port, int ipv6) { if (message) { if (ssh_message_type(message) == SSH_REQUEST_CHANNEL) { if (ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_SHELL) { - shell = 1; + shell = 1; ssh_message_channel_request_reply_success(message); ssh_message_free(message); break; @@ -945,10 +933,6 @@ void serverssh(int port, int ipv6) { exit(-1); } - - - - bbs_pid = forkpty(&fd, NULL, NULL, NULL); if (bbs_pid == 0) { tcgetattr(STDIN_FILENO, &tios); @@ -966,22 +950,22 @@ void serverssh(int port, int ipv6) { events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; event = ssh_event_new(); - if(event == NULL) { + if (event == NULL) { ssh_finalize(); exit(0); } - if(ssh_event_add_fd(event, fd, events, ssh_copy_fd_to_chan, chan) != SSH_OK) { + if (ssh_event_add_fd(event, fd, events, ssh_copy_fd_to_chan, chan) != SSH_OK) { ssh_finalize(); exit(0); } - if(ssh_event_add_session(event, p_ssh_session) != SSH_OK) { + if (ssh_event_add_session(event, p_ssh_session) != SSH_OK) { ssh_finalize(); exit(0); } do { ssh_event_dopoll(event, 1000); - } while(!ssh_channel_is_closed(chan)); + } while (!ssh_channel_is_closed(chan)); ssh_event_remove_fd(event, fd); @@ -998,7 +982,6 @@ void serverssh(int port, int ipv6) { close(csock); free(ip); } else { - } } } @@ -1028,49 +1011,49 @@ void server(int port, int ipv6) { if (conf.ipguard_enable) { ip_guard_map = hashmap_new(); - + snprintf(buffer, 1024, "%s/whitelist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4)); - + fptr = fopen(buffer, "r"); if (fptr) { fgets(buffer, 1024, fptr); while (!feof(fptr)) { - for (i=strlen(buffer)-1;i> 0; i--) { + for (i = strlen(buffer) - 1; i > 0; i--) { if (buffer[i] == '\r' || buffer[i] == '\n') { buffer[i] = '\0'; } else { break; } } - + ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard)); ip_guard->status = IP_STATUS_WHITELISTED; - + hashmap_put(ip_guard_map, strdup(buffer), ip_guard); - + fgets(buffer, 1024, fptr); } fclose(fptr); } snprintf(buffer, 1024, "%s/blacklist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4)); - + fptr = fopen(buffer, "r"); if (fptr) { fgets(buffer, 1024, fptr); while (!feof(fptr)) { - for (i=strlen(buffer)-1;i> 0; i--) { + for (i = strlen(buffer) - 1; i > 0; i--) { if (buffer[i] == '\r' || buffer[i] == '\n') { buffer[i] = '\0'; } else { break; } } - + ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard)); ip_guard->status = IP_STATUS_BLACKLISTED; - + hashmap_put(ip_guard_map, strdup(buffer), ip_guard); - + fgets(buffer, 1024, fptr); } fclose(fptr); @@ -1080,27 +1063,27 @@ void server(int port, int ipv6) { sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART | SA_SIGINFO; if (sigaction(SIGCHLD, &sa, NULL) == -1) { - perror("sigaction - sigchld"); - remove(conf.pid_file); - exit(1); + perror("sigaction - sigchld"); + remove(conf.pid_file); + exit(1); } st.sa_handler = sigterm_handler; sigemptyset(&st.sa_mask); st.sa_flags = SA_SIGINFO; if (sigaction(SIGTERM, &st, NULL) == -1) { - perror("sigaction - sigterm"); - remove(conf.pid_file); - exit(1); + perror("sigaction - sigterm"); + remove(conf.pid_file); + exit(1); } sq.sa_handler = sigterm_handler; sigemptyset(&sq.sa_mask); sq.sa_flags = SA_SIGINFO; if (sigaction(SIGQUIT, &sq, NULL) == -1) { - perror("sigaction - sigquit"); - remove(conf.pid_file); - exit(1); + perror("sigaction - sigquit"); + remove(conf.pid_file); + exit(1); } if (conf.ssh_server) { @@ -1133,7 +1116,6 @@ void server(int port, int ipv6) { fprintf(stderr, "Couldn't create socket..\n"); exit(1); } - if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { remove(conf.pid_file); @@ -1145,7 +1127,6 @@ void server(int port, int ipv6) { printf(" - Telnet Starting on Port %d (IPv%d)\n", port, (ipv6 ? 6 : 4)); } - if (ipv6) { if (setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) { fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed"); @@ -1189,14 +1170,14 @@ void server(int port, int ipv6) { } } -#if defined(ENABLE_WWW) +#if defined(ENABLE_WWW) if (conf.www_server && conf.www_path != NULL && conf.www_url != NULL) { if (!conf.fork) { printf(" - HTTP Starting on Port %d (IPv%d)\n", conf.www_port, (ipv6 ? 6 : 4)); } www_init(); if (ipv6) { - www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION|MHD_USE_IPv6, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); + www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); } else { www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); } @@ -1205,7 +1186,6 @@ void server(int port, int ipv6) { listen(server_socket, 3); - while ((client_sock = accept(server_socket, (struct sockaddr *)client_p, (socklen_t *)&c))) { if (ipv6) { ip = strdup(inet_ntop(AF_INET6, &((struct sockaddr_in6 *)client_p)->sin6_addr, str, sizeof(str))); @@ -1219,10 +1199,10 @@ void server(int port, int ipv6) { exit(-1); } } - + if (conf.ipguard_enable) { i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard)); - + if (i == MAP_MISSING) { ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard)); ip_guard->status = IP_STATUS_UNKNOWN; @@ -1230,7 +1210,7 @@ void server(int port, int ipv6) { ip_guard->connection_count = 1; hashmap_put(ip_guard_map, strdup(ip), ip_guard); } else if (i == MAP_OK) { - + if (ip_guard->status == IP_STATUS_BLACKLISTED) { write(client_sock, "BLOCKED\r\n", 9); free(ip); @@ -1249,14 +1229,13 @@ void server(int port, int ipv6) { free(ip); close(client_sock); continue; - } } else { ip_guard->connection_count = 0; ip_guard->last_connection = time(NULL); } } - } + } } pid = fork(); @@ -1284,7 +1263,7 @@ int main(int argc, char **argv) { FILE *fptr; struct stat s; char buffer[1024]; - + if (argc < 2) { fprintf(stderr, "Usage ./magicka config/bbs.ini\n"); exit(1); @@ -1319,38 +1298,38 @@ int main(int argc, char **argv) { conf.ipguard_enable = 0; conf.ipguard_tries = 4; conf.ipguard_timeout = 120; - conf.protocol_count = 0; + conf.protocol_count = 0; conf.codepage = 0; conf.date_style = 0; conf.ipv6 = 0; conf.uid = getuid(); conf.gid = getgid(); // Load BBS data - if (ini_parse(argv[1], handler, &conf) <0) { + if (ini_parse(argv[1], handler, &conf) < 0) { fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]); exit(-1); } - + if (conf.config_path == NULL) { fprintf(stderr, "Config Path must be set in your bbs ini!\n"); exit(-1); } - + if (conf.root_menu == NULL) { fprintf(stderr, "Root Menu must be set in your bbs ini!\n"); - exit(-1); + exit(-1); } // Load mail Areas - for (i=0;ipath, mail_area_handler, conf.mail_conferences[i]) <0) { + for (i = 0; i < conf.mail_conference_count; i++) { + if (ini_parse(conf.mail_conferences[i]->path, mail_area_handler, conf.mail_conferences[i]) < 0) { 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) { + for (i = 0; i < conf.file_directory_count; i++) { + if (ini_parse(conf.file_directories[i]->path, file_sub_handler, conf.file_directories[i]) < 0) { fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.file_directories[i]->path); exit(-1); } @@ -1358,24 +1337,23 @@ int main(int argc, char **argv) { snprintf(buffer, 1024, "%s/doors.ini", conf.config_path); - if (ini_parse(buffer, door_config_handler, &conf) <0) { + if (ini_parse(buffer, door_config_handler, &conf) < 0) { fprintf(stderr, "Unable to load configuration ini (doors.ini)!\n"); exit(-1); } snprintf(buffer, 1024, "%s/archivers.ini", conf.config_path); - if (ini_parse(buffer, archiver_config_handler, &conf) <0) { + if (ini_parse(buffer, archiver_config_handler, &conf) < 0) { fprintf(stderr, "Unable to load configuration ini %s\n", buffer); exit(-1); } snprintf(buffer, 1024, "%s/protocols.ini", conf.config_path); - if (ini_parse(buffer, protocol_config_handler, &conf) <0) { + if (ini_parse(buffer, protocol_config_handler, &conf) < 0) { fprintf(stderr, "Unable to load configuration ini %s\n", buffer); exit(-1); } - load_strings(); if (conf.fork) { @@ -1389,8 +1367,7 @@ int main(int argc, char **argv) { if (main_pid < 0) { fprintf(stderr, "Error forking.\n"); exit(-1); - } else - if (main_pid > 0) { + } else if (main_pid > 0) { if (conf.uid != getuid()) { if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) { perror("Setuid Error: "); @@ -1405,7 +1382,7 @@ int main(int argc, char **argv) { fclose(fptr); } } else { - for (i=1;i<=conf.nodes;i++) { + for (i = 1; i <= conf.nodes; i++) { snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i); if (stat(buffer, &s) == 0) { unlink(buffer); @@ -1415,7 +1392,7 @@ int main(int argc, char **argv) { ipv6_pid = fork(); if (ipv6_pid < 0) { fprintf(stderr, "Error forking.\n"); - exit(-1); + exit(-1); } else if (ipv6_pid > 0) { server(conf.telnet_port, 0); } else { @@ -1429,18 +1406,18 @@ int main(int argc, char **argv) { } else { printf("Magicka BBS Server Starting....\n"); - for (i=1;i<=conf.nodes;i++) { + for (i = 1; i <= conf.nodes; i++) { snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i); if (stat(buffer, &s) == 0) { printf(" - Removing stale file: nodeinuse.%d\n", i); unlink(buffer); } - } + } if (conf.ipv6) { ipv6_pid = fork(); if (ipv6_pid < 0) { fprintf(stderr, "Error forking.\n"); - exit(-1); + exit(-1); } else if (ipv6_pid > 0) { server(conf.telnet_port, 0); } else { diff --git a/src/main_menu.c b/src/main_menu.c index b643709..08503b1 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -17,7 +17,7 @@ void display_bulletins() { char buffer[PATH_MAX]; struct stat s; i = 0; - + sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); while (stat(buffer, &s) == 0) { @@ -37,15 +37,15 @@ void active_nodes() { char buffer[PATH_MAX]; FILE *fptr; - for (i=0;iname); } else { @@ -137,7 +137,7 @@ void display_textfiles() { if (selected >= conf.text_file_count) { selected = conf.text_file_count - 1; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(250), selected - start + 1, selected - 1, conf.text_files[selected - 1]->name); s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name); s_printf("\e[%d;5H", selected - start + 2); @@ -156,11 +156,11 @@ void display_textfiles() { if (selected < 0) { selected = 0; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name); s_printf(get_string(250), selected - start + 3, selected + 1, conf.text_files[selected + 1]->name); s_printf("\e[%d;5H", selected - start + 2); - } + } } } else if (c == 75) { // END KEY @@ -193,7 +193,7 @@ void display_textfiles() { // PAGE DOWN selected = selected + 22; if (selected >= conf.text_file_count) { - selected = conf.text_file_count -1; + selected = conf.text_file_count - 1; } start = selected; redraw = 1; @@ -204,7 +204,7 @@ void display_textfiles() { s_displayansi_p(conf.text_files[selected]->path); s_printf(get_string(185)); s_getc(); - s_printf("\r\n"); + s_printf("\r\n"); redraw = 1; } } diff --git a/src/menus.c b/src/menus.c index 30e436a..f71baef 100644 --- a/src/menus.c +++ b/src/menus.c @@ -8,331 +8,327 @@ #include "lua/lualib.h" #include "lua/lauxlib.h" -#define MENU_SUBMENU 1 -#define MENU_LOGOFF 2 -#define MENU_PREVMENU 3 -#define MENU_AUTOMESSAGE 4 -#define MENU_TEXTFILES 5 -#define MENU_CHATSYSTEM 6 -#define MENU_BBSLIST 7 -#define MENU_LISTUSERS 8 -#define MENU_BULLETINS 9 -#define MENU_LAST10 10 -#define MENU_SETTINGS 11 -#define MENU_DOOR 12 -#define MENU_MAILSCAN 13 -#define MENU_READMAIL 14 -#define MENU_POSTMESSAGE 15 -#define MENU_CHOOSEMAILCONF 16 -#define MENU_CHOOSEMAILAREA 17 -#define MENU_SENDEMAIL 18 -#define MENU_LISTEMAIL 19 -#define MENU_NEXTMAILCONF 20 -#define MENU_PREVMAILCONF 21 -#define MENU_NEXTMAILAREA 22 -#define MENU_PREVMAILAREA 23 -#define MENU_BLUEWAVEDOWN 24 -#define MENU_BLUEWAVEUP 25 -#define MENU_CHOOSEFILEDIR 26 -#define MENU_CHOOSEFILESUB 27 -#define MENU_LISTFILES 28 -#define MENU_UPLOAD 29 -#define MENU_DOWNLOAD 30 -#define MENU_CLEARTAGGEDFILES 31 -#define MENU_NEXTFILEDIR 32 -#define MENU_PREVFILEDIR 33 -#define MENU_NEXTFILESUB 34 -#define MENU_PREVFILESUB 35 -#define MENU_LISTMESSAGES 36 -#define MENU_DOSCRIPT 37 -#define MENU_SENDNODEMSG 38 -#define MENU_SUBUNSUBCONF 39 -#define MENU_RESETPOINTERS 40 -#define MENU_RESETALLPOINTERS 41 -#define MENU_FILESCAN 42 -#define MENU_FULLMAILSCAN 43 -#define MENU_FILESEARCH 44 -#define MENU_DISPTXTFILE 45 -#define MENU_DISPTXTFILEPAUSE 46 -#define MENU_GENWWWURLS 47 -#define MENU_NLBROWSER 48 -#define MENU_SENDFEEDBACK 49 -#define MENU_BLOGDISPLAY 50 -#define MENU_BLOGWRITE 51 +#define MENU_SUBMENU 1 +#define MENU_LOGOFF 2 +#define MENU_PREVMENU 3 +#define MENU_AUTOMESSAGE 4 +#define MENU_TEXTFILES 5 +#define MENU_CHATSYSTEM 6 +#define MENU_BBSLIST 7 +#define MENU_LISTUSERS 8 +#define MENU_BULLETINS 9 +#define MENU_LAST10 10 +#define MENU_SETTINGS 11 +#define MENU_DOOR 12 +#define MENU_MAILSCAN 13 +#define MENU_READMAIL 14 +#define MENU_POSTMESSAGE 15 +#define MENU_CHOOSEMAILCONF 16 +#define MENU_CHOOSEMAILAREA 17 +#define MENU_SENDEMAIL 18 +#define MENU_LISTEMAIL 19 +#define MENU_NEXTMAILCONF 20 +#define MENU_PREVMAILCONF 21 +#define MENU_NEXTMAILAREA 22 +#define MENU_PREVMAILAREA 23 +#define MENU_BLUEWAVEDOWN 24 +#define MENU_BLUEWAVEUP 25 +#define MENU_CHOOSEFILEDIR 26 +#define MENU_CHOOSEFILESUB 27 +#define MENU_LISTFILES 28 +#define MENU_UPLOAD 29 +#define MENU_DOWNLOAD 30 +#define MENU_CLEARTAGGEDFILES 31 +#define MENU_NEXTFILEDIR 32 +#define MENU_PREVFILEDIR 33 +#define MENU_NEXTFILESUB 34 +#define MENU_PREVFILESUB 35 +#define MENU_LISTMESSAGES 36 +#define MENU_DOSCRIPT 37 +#define MENU_SENDNODEMSG 38 +#define MENU_SUBUNSUBCONF 39 +#define MENU_RESETPOINTERS 40 +#define MENU_RESETALLPOINTERS 41 +#define MENU_FILESCAN 42 +#define MENU_FULLMAILSCAN 43 +#define MENU_FILESEARCH 44 +#define MENU_DISPTXTFILE 45 +#define MENU_DISPTXTFILEPAUSE 46 +#define MENU_GENWWWURLS 47 +#define MENU_NLBROWSER 48 +#define MENU_SENDFEEDBACK 49 +#define MENU_BLOGDISPLAY 50 +#define MENU_BLOGWRITE 51 extern struct bbs_config conf; extern struct user_record *gUser; extern int mynode; struct menu_item { - char hotkey; - int *command; - char **data; - int command_count; - int seclevel; + char hotkey; + int *command; + char **data; + int command_count; + int seclevel; }; int menu_system(char *menufile) { - FILE *fptr; - char buffer[PATH_MAX]; - int menu_items = 0; - struct menu_item **menu; - char *lua_script; - int do_lua_menu; - char *ansi_file; - int i; - int j; - int k; - int m; - struct stat s; - char *lRet; + FILE *fptr; + char buffer[PATH_MAX]; + int menu_items = 0; + struct menu_item **menu; + char *lua_script; + int do_lua_menu; + char *ansi_file; + int i; + int j; + int k; + int m; + struct stat s; + char *lRet; lua_State *L; - int result; - int doquit = 0; - char c; - int clearscreen = 0; + int result; + int doquit = 0; + char c; + int clearscreen = 0; char confirm; - char *msg; + char *msg; - dolog("%s is loading menu: %s", gUser->loginname, menufile); + dolog("%s is loading menu: %s", gUser->loginname, menufile); broadcast("USER: %s; NODE:%d; STATUS: Browsing menu %s.", gUser->loginname, mynode, menufile); + if (menufile[0] == '/') { + snprintf(buffer, PATH_MAX, "%s.mnu", menufile); + } else { + snprintf(buffer, PATH_MAX, "%s/%s.mnu", conf.menu_path, menufile); + } + fptr = fopen(buffer, "r"); - if (menufile[0] == '/') { - snprintf(buffer, PATH_MAX, "%s.mnu", menufile); - } else { - snprintf(buffer, PATH_MAX, "%s/%s.mnu", conf.menu_path, menufile); - } - fptr = fopen(buffer, "r"); - - if (!fptr) { - s_printf("Error opening menu file! %s\r\n", menufile); - return 0; - } + if (!fptr) { + s_printf("Error opening menu file! %s\r\n", menufile); + return 0; + } - lua_script = NULL; - ansi_file = NULL; + lua_script = NULL; + ansi_file = NULL; + fgets(buffer, 256, fptr); + while (!feof(fptr)) { - fgets(buffer, 256, fptr); - while (!feof(fptr)) { + chomp(buffer); - - chomp(buffer); - - if (strncasecmp(buffer, "HOTKEY", 6) == 0) { - menu_items++; - if (menu_items == 1) { - menu = (struct menu_item **)malloc(sizeof(struct menu_item *)); - } else { - menu = (struct menu_item **)realloc(menu, sizeof(struct menu_item *) * (menu_items)); - } - menu[menu_items-1] = (struct menu_item *)malloc(sizeof(struct menu_item)); - menu[menu_items-1]->hotkey = buffer[7]; - menu[menu_items-1]->command = NULL; - menu[menu_items-1]->data = NULL; - menu[menu_items-1]->command_count = 0; - menu[menu_items-1]->seclevel = 0; - } else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) { - if (menu[menu_items-1]->command_count == 0) { - menu[menu_items-1]->command = (int *)malloc(sizeof(int)); - menu[menu_items-1]->data = (char **)malloc(sizeof(char *)); - } else { - menu[menu_items-1]->command = (int *)realloc(menu[menu_items-1]->command, sizeof(int) * (menu[menu_items-1]->command_count + 1)); - menu[menu_items-1]->data = (char **)realloc(menu[menu_items-1]->data, sizeof(char *) * (menu[menu_items-1]->command_count + 1)); - } - menu[menu_items-1]->command_count++; - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = 0; - menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] = NULL; - if (strncasecmp(&buffer[8], "SUBMENU", 7) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SUBMENU; - } else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LOGOFF; - } else if (strncasecmp(&buffer[8], "PREVMENU", 8) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMENU; - } else if (strncasecmp(&buffer[8], "AUTOMESSAGE", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_AUTOMESSAGE; - } else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_TEXTFILES; - } else if (strncasecmp(&buffer[8], "CHATSYSTEM", 10) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHATSYSTEM; - } else if (strncasecmp(&buffer[8], "BBSLIST", 7) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BBSLIST; - } else if (strncasecmp(&buffer[8], "LISTUSERS", 9) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTUSERS; - } else if (strncasecmp(&buffer[8], "BULLETINS", 9) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BULLETINS; - } else if (strncasecmp(&buffer[8], "LAST10CALLERS", 13) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LAST10; - } else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SETTINGS; - } else if (strncasecmp(&buffer[8], "RUNDOOR", 7) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOOR; - } else if (strncasecmp(&buffer[8], "MAILSCAN", 8) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_MAILSCAN; - } else if (strncasecmp(&buffer[8], "READMAIL", 8) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_READMAIL; - } else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_POSTMESSAGE; - } else if (strncasecmp(&buffer[8], "CHOOSEMAILCONF", 14) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEMAILCONF; - } else if (strncasecmp(&buffer[8], "CHOOSEMAILAREA", 14) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEMAILAREA; - } else if (strncasecmp(&buffer[8], "SENDEMAIL", 9) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDEMAIL; - } else if (strncasecmp(&buffer[8], "LISTEMAIL", 9) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTEMAIL; - } else if (strncasecmp(&buffer[8], "NEXTMAILCONF", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTMAILCONF; - } else if (strncasecmp(&buffer[8], "PREVMAILCONF", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMAILCONF; - } else if (strncasecmp(&buffer[8], "NEXTMAILAREA", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTMAILAREA; - } else if (strncasecmp(&buffer[8], "PREVMAILAREA", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMAILAREA; - } else if (strncasecmp(&buffer[8], "BLUEWAVEDOWNLOAD", 16) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLUEWAVEDOWN; - } else if (strncasecmp(&buffer[8], "BLUEWAVEUPLOAD", 14) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLUEWAVEUP; - } else if (strncasecmp(&buffer[8], "CHOOSEFILEDIR", 13) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEFILEDIR; - } else if (strncasecmp(&buffer[8], "CHOOSEFILESUB", 13) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEFILESUB; - } else if (strncasecmp(&buffer[8], "LISTFILES", 9) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTFILES; - } else if (strncasecmp(&buffer[8], "UPLOAD", 6) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_UPLOAD; - } else if (strncasecmp(&buffer[8], "DOWNLOAD", 8) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOWNLOAD; - } else if (strncasecmp(&buffer[8], "CLEARTAGGED", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CLEARTAGGEDFILES; - } else if (strncasecmp(&buffer[8], "NEXTFILEDIR", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTFILEDIR; - } else if (strncasecmp(&buffer[8], "PREVFILEDIR", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVFILEDIR; - } else if (strncasecmp(&buffer[8], "NEXTFILESUB", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTFILESUB; - } else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVFILESUB; - } else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTMESSAGES; - } else if (strncasecmp(&buffer[8], "DOSCRIPT", 8) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOSCRIPT; - } else if (strncasecmp(&buffer[8], "SENDNODEMSG", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDNODEMSG; - } else if (strncasecmp(&buffer[8], "SUBUNSUBCONF", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SUBUNSUBCONF; + if (strncasecmp(buffer, "HOTKEY", 6) == 0) { + menu_items++; + if (menu_items == 1) { + menu = (struct menu_item **)malloc(sizeof(struct menu_item *)); + } else { + menu = (struct menu_item **)realloc(menu, sizeof(struct menu_item *) * (menu_items)); + } + menu[menu_items - 1] = (struct menu_item *)malloc(sizeof(struct menu_item)); + menu[menu_items - 1]->hotkey = buffer[7]; + menu[menu_items - 1]->command = NULL; + menu[menu_items - 1]->data = NULL; + menu[menu_items - 1]->command_count = 0; + menu[menu_items - 1]->seclevel = 0; + } else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) { + if (menu[menu_items - 1]->command_count == 0) { + menu[menu_items - 1]->command = (int *)malloc(sizeof(int)); + menu[menu_items - 1]->data = (char **)malloc(sizeof(char *)); + } else { + menu[menu_items - 1]->command = (int *)realloc(menu[menu_items - 1]->command, sizeof(int) * (menu[menu_items - 1]->command_count + 1)); + menu[menu_items - 1]->data = (char **)realloc(menu[menu_items - 1]->data, sizeof(char *) * (menu[menu_items - 1]->command_count + 1)); + } + menu[menu_items - 1]->command_count++; + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = 0; + menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1] = NULL; + if (strncasecmp(&buffer[8], "SUBMENU", 7) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SUBMENU; + } else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LOGOFF; + } else if (strncasecmp(&buffer[8], "PREVMENU", 8) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMENU; + } else if (strncasecmp(&buffer[8], "AUTOMESSAGE", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_AUTOMESSAGE; + } else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_TEXTFILES; + } else if (strncasecmp(&buffer[8], "CHATSYSTEM", 10) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHATSYSTEM; + } else if (strncasecmp(&buffer[8], "BBSLIST", 7) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BBSLIST; + } else if (strncasecmp(&buffer[8], "LISTUSERS", 9) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTUSERS; + } else if (strncasecmp(&buffer[8], "BULLETINS", 9) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BULLETINS; + } else if (strncasecmp(&buffer[8], "LAST10CALLERS", 13) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LAST10; + } else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SETTINGS; + } else if (strncasecmp(&buffer[8], "RUNDOOR", 7) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOOR; + } else if (strncasecmp(&buffer[8], "MAILSCAN", 8) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_MAILSCAN; + } else if (strncasecmp(&buffer[8], "READMAIL", 8) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_READMAIL; + } else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_POSTMESSAGE; + } else if (strncasecmp(&buffer[8], "CHOOSEMAILCONF", 14) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEMAILCONF; + } else if (strncasecmp(&buffer[8], "CHOOSEMAILAREA", 14) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEMAILAREA; + } else if (strncasecmp(&buffer[8], "SENDEMAIL", 9) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDEMAIL; + } else if (strncasecmp(&buffer[8], "LISTEMAIL", 9) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTEMAIL; + } else if (strncasecmp(&buffer[8], "NEXTMAILCONF", 12) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTMAILCONF; + } else if (strncasecmp(&buffer[8], "PREVMAILCONF", 12) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMAILCONF; + } else if (strncasecmp(&buffer[8], "NEXTMAILAREA", 12) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTMAILAREA; + } else if (strncasecmp(&buffer[8], "PREVMAILAREA", 12) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMAILAREA; + } else if (strncasecmp(&buffer[8], "BLUEWAVEDOWNLOAD", 16) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLUEWAVEDOWN; + } else if (strncasecmp(&buffer[8], "BLUEWAVEUPLOAD", 14) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLUEWAVEUP; + } else if (strncasecmp(&buffer[8], "CHOOSEFILEDIR", 13) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEFILEDIR; + } else if (strncasecmp(&buffer[8], "CHOOSEFILESUB", 13) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEFILESUB; + } else if (strncasecmp(&buffer[8], "LISTFILES", 9) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTFILES; + } else if (strncasecmp(&buffer[8], "UPLOAD", 6) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_UPLOAD; + } else if (strncasecmp(&buffer[8], "DOWNLOAD", 8) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOWNLOAD; + } else if (strncasecmp(&buffer[8], "CLEARTAGGED", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CLEARTAGGEDFILES; + } else if (strncasecmp(&buffer[8], "NEXTFILEDIR", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTFILEDIR; + } else if (strncasecmp(&buffer[8], "PREVFILEDIR", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVFILEDIR; + } else if (strncasecmp(&buffer[8], "NEXTFILESUB", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTFILESUB; + } else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVFILESUB; + } else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTMESSAGES; + } else if (strncasecmp(&buffer[8], "DOSCRIPT", 8) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOSCRIPT; + } else if (strncasecmp(&buffer[8], "SENDNODEMSG", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDNODEMSG; + } else if (strncasecmp(&buffer[8], "SUBUNSUBCONF", 12) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SUBUNSUBCONF; } else if (strncasecmp(&buffer[8], "RESETMSGPTRS", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_RESETPOINTERS; + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_RESETPOINTERS; } else if (strncasecmp(&buffer[8], "RESETALLMSGPTRS", 15) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_RESETALLPOINTERS; + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_RESETALLPOINTERS; } else if (strncasecmp(&buffer[8], "FILESCAN", 8) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FILESCAN; + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_FILESCAN; } else if (strncasecmp(&buffer[8], "FULLMAILSCAN", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FULLMAILSCAN; + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_FULLMAILSCAN; } else if (strncasecmp(&buffer[8], "FILESEARCH", 10) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FILESEARCH; + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_FILESEARCH; } else if (strncasecmp(&buffer[8], "DISPLAYTXTFILE", 14) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DISPTXTFILE; + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DISPTXTFILE; } else if (strncasecmp(&buffer[8], "DISPLAYTXTPAUSE", 15) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DISPTXTFILEPAUSE; + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DISPTXTFILEPAUSE; } else if (strncasecmp(&buffer[8], "GENWWWURLS", 10) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_GENWWWURLS; - } else if (strncasecmp(&buffer[8], "NLBROWSER", 9) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NLBROWSER; - } else if (strncasecmp(&buffer[8], "SENDFEEDBACK", 12) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDFEEDBACK; - } else if (strncasecmp(&buffer[8], "BLOGDISPLAY", 11) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLOGDISPLAY; - } else if (strncasecmp(&buffer[8], "BLOGWRITE", 9) == 0) { - menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLOGWRITE; - } - } else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) { - menu[menu_items-1]->seclevel = atoi(&buffer[9]); - } else if (strncasecmp(buffer, "DATA", 4) == 0) { - if (menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] != NULL) { - free(menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1]); - } - menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] = strdup(&buffer[5]); - } else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) { - if (lua_script != NULL) { - free(lua_script); - } - lua_script = strdup(&buffer[10]); - } else if (strncasecmp(buffer, "ANSIFILE", 8) == 0) { - if (ansi_file != NULL) { - free(ansi_file); - } - ansi_file = strdup(&buffer[9]); - } else if (strncasecmp(buffer, "CLEARSCREEN", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_GENWWWURLS; + } else if (strncasecmp(&buffer[8], "NLBROWSER", 9) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NLBROWSER; + } else if (strncasecmp(&buffer[8], "SENDFEEDBACK", 12) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDFEEDBACK; + } else if (strncasecmp(&buffer[8], "BLOGDISPLAY", 11) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLOGDISPLAY; + } else if (strncasecmp(&buffer[8], "BLOGWRITE", 9) == 0) { + menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLOGWRITE; + } + } else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) { + menu[menu_items - 1]->seclevel = atoi(&buffer[9]); + } else if (strncasecmp(buffer, "DATA", 4) == 0) { + if (menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1] != NULL) { + free(menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1]); + } + menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1] = strdup(&buffer[5]); + } else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) { + if (lua_script != NULL) { + free(lua_script); + } + lua_script = strdup(&buffer[10]); + } else if (strncasecmp(buffer, "ANSIFILE", 8) == 0) { + if (ansi_file != NULL) { + free(ansi_file); + } + ansi_file = strdup(&buffer[9]); + } else if (strncasecmp(buffer, "CLEARSCREEN", 11) == 0) { clearscreen = 1; } - fgets(buffer, 256, fptr); - } - fclose(fptr); + fgets(buffer, 256, fptr); + } + fclose(fptr); - do_lua_menu = 0; + do_lua_menu = 0; - if (lua_script != NULL) { - if (conf.script_path != NULL && lua_script[0] != '/') { - snprintf(buffer, PATH_MAX, "%s/%s.lua", conf.script_path, lua_script); - do_lua_menu = 1; - } else if (lua_script[0] == '/') { - snprintf(buffer, PATH_MAX, "%s.lua", lua_script); - do_lua_menu = 1; - } - - if (do_lua_menu) { - if (stat(buffer, &s) == 0) { - L = luaL_newstate(); - luaL_openlibs(L); - lua_push_cfunctions(L); - luaL_loadfile(L, buffer); - do_lua_menu = 1; - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_lua_menu = 0; - } - } else { - do_lua_menu = 0; - } - } - } + if (lua_script != NULL) { + if (conf.script_path != NULL && lua_script[0] != '/') { + snprintf(buffer, PATH_MAX, "%s/%s.lua", conf.script_path, lua_script); + do_lua_menu = 1; + } else if (lua_script[0] == '/') { + snprintf(buffer, PATH_MAX, "%s.lua", lua_script); + do_lua_menu = 1; + } + if (do_lua_menu) { + if (stat(buffer, &s) == 0) { + L = luaL_newstate(); + luaL_openlibs(L); + lua_push_cfunctions(L); + luaL_loadfile(L, buffer); + do_lua_menu = 1; + result = lua_pcall(L, 0, 1, 0); + if (result) { + dolog("Failed to run script: %s", lua_tostring(L, -1)); + do_lua_menu = 0; + } + } else { + do_lua_menu = 0; + } + } + } while (!doquit) { - if (gUser->nodemsgs) { - snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode); + if (gUser->nodemsgs) { + snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode); - if (stat(buffer, &s) == 0) { - fptr = fopen(buffer, "r"); - if (fptr) { - fgets(buffer, PATH_MAX, fptr); - while (!feof(fptr)) { - chomp(buffer); - s_printf("\r\n%s\r\n", buffer); - fgets(buffer, PATH_MAX, fptr); - } - fclose(fptr); - snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode); - unlink(buffer); + if (stat(buffer, &s) == 0) { + fptr = fopen(buffer, "r"); + if (fptr) { + fgets(buffer, PATH_MAX, fptr); + while (!feof(fptr)) { + chomp(buffer); + s_printf("\r\n%s\r\n", buffer); + fgets(buffer, PATH_MAX, fptr); + } + fclose(fptr); + snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode); + unlink(buffer); - s_printf(get_string(6)); - c = s_getc(); - } - } - } - - if (clearscreen) { + s_printf(get_string(6)); + c = s_getc(); + } + } + } + + if (clearscreen) { s_printf("\e[2J\e[1;1H"); } - + if (do_lua_menu == 0) { - if (ansi_file != NULL) { - s_displayansi(ansi_file); - } + if (ansi_file != NULL) { + s_displayansi(ansi_file); + } s_printf(get_string(142), gUser->timeleft); c = s_getc(); } else { @@ -345,335 +341,333 @@ int menu_system(char *menufile) { continue; } lRet = (char *)lua_tostring(L, -1); - c = lRet[0]; + c = lRet[0]; lua_pop(L, 1); } - for (i=0;ihotkey) == tolower(c)) { - if (menu[i]->seclevel <= gUser->sec_level) { - for (j=0; jcommand_count;j++) { - switch(menu[i]->command[j]) { - case MENU_SUBMENU: - doquit = menu_system(menu[i]->data[j]); - if (doquit == 1) { - // free menus - if (do_lua_menu) { - lua_close(L); - } - if (lua_script != NULL) { - free(lua_script); - } - if (ansi_file != NULL) { - free(ansi_file); - } - for (i=0;icommand_count;j++) { - if (menu[i]->data[j] != NULL) { - free(menu[i]->data[j]); - } - } - free(menu[i]->data); - free(menu[i]->command); - free(menu[i]); - } - free(menu); - return doquit; - } - break; - case MENU_LOGOFF: - if (do_lua_menu) { - lua_close(L); - } - if (lua_script != NULL) { - free(lua_script); - } - if (ansi_file != NULL) { - free(ansi_file); - } - for (i=0;icommand_count;j++) { - if (menu[i]->data[j] != NULL) { - free(menu[i]->data[j]); - } - } - free(menu[i]->data); - free(menu[i]->command); - free(menu[i]); - } - free(menu); - return 1; - case MENU_PREVMENU: - if (do_lua_menu) { - lua_close(L); - } - if (lua_script != NULL) { - free(lua_script); - } - if (ansi_file != NULL) { - free(ansi_file); - } - for (i=0;icommand_count;j++) { - if (menu[i]->data[j] != NULL) { - free(menu[i]->data[j]); - } - } - free(menu[i]->data); - free(menu[i]->command); - free(menu[i]); - } - free(menu); - return 0; - case MENU_AUTOMESSAGE: - broadcast("USER: %s; NODE:%d; STATUS: Viewing/Changing Automessage.", gUser->loginname, mynode); - automessage(); - break; - case MENU_TEXTFILES: - broadcast("USER: %s; NODE:%d; STATUS: Browsing Textfiles.", gUser->loginname, mynode); - display_textfiles(); - break; - case MENU_CHATSYSTEM: - broadcast("USER: %s; NODE:%d; STATUS: In Chat System.", gUser->loginname, mynode); - chat_system(gUser); - break; - case MENU_BBSLIST: - broadcast("USER: %s; NODE:%d; STATUS: Browsing BBS List.", gUser->loginname, mynode); - bbs_list(gUser); - break; - case MENU_LISTUSERS: - broadcast("USER: %s; NODE:%d; STATUS: Browsing User List.", gUser->loginname, mynode); - list_users(gUser); - break; - case MENU_BULLETINS: - broadcast("USER: %s; NODE:%d; STATUS: Reading Bulletins.", gUser->loginname, mynode); - display_bulletins(); - break; - case MENU_LAST10: - broadcast("USER: %s; NODE:%d; STATUS: Viewing Last 10 Callers.", gUser->loginname, mynode); - display_last10_callers(gUser); - break; - case MENU_SETTINGS: - settings_menu(gUser); - break; - case MENU_DOOR: - { - for (m=0;mdata[j], conf.doors[m]->name) == 0) { - dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); - broadcast("USER: %s; NODE:%d; STATUS: Executing Door %s.", gUser->loginname, mynode, conf.doors[m]->name); - rundoor(gUser, conf.doors[m]->command, conf.doors[m]->stdio, conf.doors[m]->codepage); - dolog("%s returned from door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); - break; - } - } - } - break; - case MENU_MAILSCAN: - broadcast("USER: %s; NODE:%d; STATUS: Performing Mail Scan.", gUser->loginname, mynode); - mail_scan(gUser); - break; - case MENU_READMAIL: - broadcast("USER: %s; NODE:%d; STATUS: Reading Mail.", gUser->loginname, mynode); - read_mail(gUser); - break; - case MENU_POSTMESSAGE: - broadcast("USER: %s; NODE:%d; STATUS: Posting a Message.", gUser->loginname, mynode); - post_message(gUser); - break; - case MENU_CHOOSEMAILCONF: - broadcast("USER: %s; NODE:%d; STATUS: Choosing Mail Conference.", gUser->loginname, mynode); - choose_conference(); - break; - case MENU_CHOOSEMAILAREA: - broadcast("USER: %s; NODE:%d; STATUS: Choosing Mail Area.", gUser->loginname, mynode); - choose_area(); - break; - case MENU_SENDEMAIL: - broadcast("USER: %s; NODE:%d; STATUS: Sending an Email.", gUser->loginname, mynode); - send_email(gUser); - break; - case MENU_LISTEMAIL: - broadcast("USER: %s; NODE:%d; STATUS: Browsing their Emails.", gUser->loginname, mynode); - list_emails(gUser); - break; - case MENU_NEXTMAILCONF: - next_mail_conf(gUser); - break; - case MENU_PREVMAILCONF: - prev_mail_conf(gUser); - break; - case MENU_NEXTMAILAREA: - next_mail_area(gUser); - break; - case MENU_PREVMAILAREA: - prev_mail_area(gUser); - break; - case MENU_BLUEWAVEDOWN: - broadcast("USER: %s; NODE:%d; STATUS: Downloading Bluewave Packet.", gUser->loginname, mynode); - bwave_create_packet(); - break; - case MENU_BLUEWAVEUP: - broadcast("USER: %s; NODE:%d; STATUS: Uploading Bluewave Packet.", gUser->loginname, mynode); - bwave_upload_reply(); - break; - case MENU_CHOOSEFILEDIR: - broadcast("USER: %s; NODE:%d; STATUS: Choosing a file directory.", gUser->loginname, mynode); - choose_directory(); - break; - case MENU_CHOOSEFILESUB: - broadcast("USER: %s; NODE:%d; STATUS: Choosing a file sub-directory.", gUser->loginname, mynode); - choose_subdir(); - break; - case MENU_LISTFILES: - broadcast("USER: %s; NODE:%d; STATUS: Browsing Files.", gUser->loginname, mynode); - list_files(gUser); - break; - case MENU_UPLOAD: - if (gUser->sec_level >= conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->upload_sec_level) { - broadcast("USER: %s; NODE:%d; STATUS: Uploading a File.", gUser->loginname, mynode); - upload(gUser); - } else { - s_printf(get_string(84)); - } - break; - case MENU_DOWNLOAD: - broadcast("USER: %s; NODE:%d; STATUS: Downloading Files.", gUser->loginname, mynode); - download(gUser); - break; - case MENU_CLEARTAGGEDFILES: - clear_tagged_files(); - break; - case MENU_NEXTFILEDIR: - next_file_dir(gUser); - break; - case MENU_PREVFILEDIR: - prev_file_dir(gUser); - break; - case MENU_NEXTFILESUB: - next_file_sub(gUser); - break; - case MENU_PREVFILESUB: - prev_file_sub(gUser); - break; - case MENU_LISTMESSAGES: - list_messages(gUser); - break; - case MENU_DOSCRIPT: - broadcast("USER: %s; NODE:%d; STATUS: Executing a script %s.", gUser->loginname, mynode, menu[i]->data[j]); - do_lua_script(menu[i]->data[j]); - break; - case MENU_SENDNODEMSG: - broadcast("USER: %s; NODE:%d; STATUS: Sending a node Message.", gUser->loginname, mynode); - send_node_msg(); - break; - case MENU_SUBUNSUBCONF: - broadcast("USER: %s; NODE:%d; STATUS: Subscribing to conferences.", gUser->loginname, mynode); - msg_conf_sub_bases(); - break; - case MENU_RESETPOINTERS: - s_printf(get_string(229)); - s_readstring(buffer, 10); - if (tolower(buffer[0]) == 'r') { - k = -1; - m = 1; - } else if (tolower(buffer[0]) == 'u') { - k = -1; - m = 0; - } else if (buffer[0] < '0' || buffer[0] > '9') { - s_printf(get_string(39)); - break; - } else { - k = atoi(buffer) - 1; - } + for (i = 0; i < menu_items; i++) { + if (tolower(menu[i]->hotkey) == tolower(c)) { + if (menu[i]->seclevel <= gUser->sec_level) { + for (j = 0; j < menu[i]->command_count; j++) { + switch (menu[i]->command[j]) { + case MENU_SUBMENU: + doquit = menu_system(menu[i]->data[j]); + if (doquit == 1) { + // free menus + if (do_lua_menu) { + lua_close(L); + } + if (lua_script != NULL) { + free(lua_script); + } + if (ansi_file != NULL) { + free(ansi_file); + } + for (i = 0; i < menu_items; i++) { + for (j = 0; j < menu[i]->command_count; j++) { + if (menu[i]->data[j] != NULL) { + free(menu[i]->data[j]); + } + } + free(menu[i]->data); + free(menu[i]->command); + free(menu[i]); + } + free(menu); + return doquit; + } + break; + case MENU_LOGOFF: + if (do_lua_menu) { + lua_close(L); + } + if (lua_script != NULL) { + free(lua_script); + } + if (ansi_file != NULL) { + free(ansi_file); + } + for (i = 0; i < menu_items; i++) { + for (j = 0; j < menu[i]->command_count; j++) { + if (menu[i]->data[j] != NULL) { + free(menu[i]->data[j]); + } + } + free(menu[i]->data); + free(menu[i]->command); + free(menu[i]); + } + free(menu); + return 1; + case MENU_PREVMENU: + if (do_lua_menu) { + lua_close(L); + } + if (lua_script != NULL) { + free(lua_script); + } + if (ansi_file != NULL) { + free(ansi_file); + } + for (i = 0; i < menu_items; i++) { + for (j = 0; j < menu[i]->command_count; j++) { + if (menu[i]->data[j] != NULL) { + free(menu[i]->data[j]); + } + } + free(menu[i]->data); + free(menu[i]->command); + free(menu[i]); + } + free(menu); + return 0; + case MENU_AUTOMESSAGE: + broadcast("USER: %s; NODE:%d; STATUS: Viewing/Changing Automessage.", gUser->loginname, mynode); + automessage(); + break; + case MENU_TEXTFILES: + broadcast("USER: %s; NODE:%d; STATUS: Browsing Textfiles.", gUser->loginname, mynode); + display_textfiles(); + break; + case MENU_CHATSYSTEM: + broadcast("USER: %s; NODE:%d; STATUS: In Chat System.", gUser->loginname, mynode); + chat_system(gUser); + break; + case MENU_BBSLIST: + broadcast("USER: %s; NODE:%d; STATUS: Browsing BBS List.", gUser->loginname, mynode); + bbs_list(gUser); + break; + case MENU_LISTUSERS: + broadcast("USER: %s; NODE:%d; STATUS: Browsing User List.", gUser->loginname, mynode); + list_users(gUser); + break; + case MENU_BULLETINS: + broadcast("USER: %s; NODE:%d; STATUS: Reading Bulletins.", gUser->loginname, mynode); + display_bulletins(); + break; + case MENU_LAST10: + broadcast("USER: %s; NODE:%d; STATUS: Viewing Last 10 Callers.", gUser->loginname, mynode); + display_last10_callers(gUser); + break; + case MENU_SETTINGS: + settings_menu(gUser); + break; + case MENU_DOOR: { + for (m = 0; m < conf.door_count; m++) { + if (strcasecmp(menu[i]->data[j], conf.doors[m]->name) == 0) { + dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); + broadcast("USER: %s; NODE:%d; STATUS: Executing Door %s.", gUser->loginname, mynode, conf.doors[m]->name); + rundoor(gUser, conf.doors[m]->command, conf.doors[m]->stdio, conf.doors[m]->codepage); + dolog("%s returned from door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); + break; + } + } + } break; + case MENU_MAILSCAN: + broadcast("USER: %s; NODE:%d; STATUS: Performing Mail Scan.", gUser->loginname, mynode); + mail_scan(gUser); + break; + case MENU_READMAIL: + broadcast("USER: %s; NODE:%d; STATUS: Reading Mail.", gUser->loginname, mynode); + read_mail(gUser); + break; + case MENU_POSTMESSAGE: + broadcast("USER: %s; NODE:%d; STATUS: Posting a Message.", gUser->loginname, mynode); + post_message(gUser); + break; + case MENU_CHOOSEMAILCONF: + broadcast("USER: %s; NODE:%d; STATUS: Choosing Mail Conference.", gUser->loginname, mynode); + choose_conference(); + break; + case MENU_CHOOSEMAILAREA: + broadcast("USER: %s; NODE:%d; STATUS: Choosing Mail Area.", gUser->loginname, mynode); + choose_area(); + break; + case MENU_SENDEMAIL: + broadcast("USER: %s; NODE:%d; STATUS: Sending an Email.", gUser->loginname, mynode); + send_email(gUser); + break; + case MENU_LISTEMAIL: + broadcast("USER: %s; NODE:%d; STATUS: Browsing their Emails.", gUser->loginname, mynode); + list_emails(gUser); + break; + case MENU_NEXTMAILCONF: + next_mail_conf(gUser); + break; + case MENU_PREVMAILCONF: + prev_mail_conf(gUser); + break; + case MENU_NEXTMAILAREA: + next_mail_area(gUser); + break; + case MENU_PREVMAILAREA: + prev_mail_area(gUser); + break; + case MENU_BLUEWAVEDOWN: + broadcast("USER: %s; NODE:%d; STATUS: Downloading Bluewave Packet.", gUser->loginname, mynode); + bwave_create_packet(); + break; + case MENU_BLUEWAVEUP: + broadcast("USER: %s; NODE:%d; STATUS: Uploading Bluewave Packet.", gUser->loginname, mynode); + bwave_upload_reply(); + break; + case MENU_CHOOSEFILEDIR: + broadcast("USER: %s; NODE:%d; STATUS: Choosing a file directory.", gUser->loginname, mynode); + choose_directory(); + break; + case MENU_CHOOSEFILESUB: + broadcast("USER: %s; NODE:%d; STATUS: Choosing a file sub-directory.", gUser->loginname, mynode); + choose_subdir(); + break; + case MENU_LISTFILES: + broadcast("USER: %s; NODE:%d; STATUS: Browsing Files.", gUser->loginname, mynode); + list_files(gUser); + break; + case MENU_UPLOAD: + if (gUser->sec_level >= conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->upload_sec_level) { + broadcast("USER: %s; NODE:%d; STATUS: Uploading a File.", gUser->loginname, mynode); + upload(gUser); + } else { + s_printf(get_string(84)); + } + break; + case MENU_DOWNLOAD: + broadcast("USER: %s; NODE:%d; STATUS: Downloading Files.", gUser->loginname, mynode); + download(gUser); + break; + case MENU_CLEARTAGGEDFILES: + clear_tagged_files(); + break; + case MENU_NEXTFILEDIR: + next_file_dir(gUser); + break; + case MENU_PREVFILEDIR: + prev_file_dir(gUser); + break; + case MENU_NEXTFILESUB: + next_file_sub(gUser); + break; + case MENU_PREVFILESUB: + prev_file_sub(gUser); + break; + case MENU_LISTMESSAGES: + list_messages(gUser); + break; + case MENU_DOSCRIPT: + broadcast("USER: %s; NODE:%d; STATUS: Executing a script %s.", gUser->loginname, mynode, menu[i]->data[j]); + do_lua_script(menu[i]->data[j]); + break; + case MENU_SENDNODEMSG: + broadcast("USER: %s; NODE:%d; STATUS: Sending a node Message.", gUser->loginname, mynode); + send_node_msg(); + break; + case MENU_SUBUNSUBCONF: + broadcast("USER: %s; NODE:%d; STATUS: Subscribing to conferences.", gUser->loginname, mynode); + msg_conf_sub_bases(); + break; + case MENU_RESETPOINTERS: + s_printf(get_string(229)); + s_readstring(buffer, 10); + if (tolower(buffer[0]) == 'r') { + k = -1; + m = 1; + } else if (tolower(buffer[0]) == 'u') { + k = -1; + m = 0; + } else if (buffer[0] < '0' || buffer[0] > '9') { + s_printf(get_string(39)); + break; + } else { + k = atoi(buffer) - 1; + } - msgbase_reset_pointers(gUser->cur_mail_conf, gUser->cur_mail_area, m, k); + msgbase_reset_pointers(gUser->cur_mail_conf, gUser->cur_mail_area, m, k); - break; - case MENU_RESETALLPOINTERS: - s_printf(get_string(230)); - confirm = s_getc(); - if (confirm == 'r' || confirm == 'R') { - m = 1; - } else if (confirm == 'u' || confirm == 'U') { - m = 0; - } else { - s_printf(get_string(39)); - break; - } - msgbase_reset_all_pointers(m); - break; - case MENU_FILESCAN: - broadcast("USER: %s; NODE:%d; STATUS: Doing a filescan.", gUser->loginname, mynode); - file_scan(); - break; - case MENU_FULLMAILSCAN: - if (menu[i]->data[j] != NULL) { - if (strcasecmp(menu[i]->data[j], "PERSONAL") == 0) { - broadcast("USER: %s; NODE:%d; STATUS: Scanning for personal mail.", gUser->loginname, mynode); - full_mail_scan_personal(gUser); - } else { - broadcast("USER: %s; NODE:%d; STATUS: Scanning all mail.", gUser->loginname, mynode); - full_mail_scan(gUser); - } - } else { - full_mail_scan(gUser); - } - break; - case MENU_FILESEARCH: - broadcast("USER: %s; NODE:%d; STATUS: Executing a filesearch.", gUser->loginname, mynode); - file_search(); - break; - case MENU_DISPTXTFILE: - if (menu[i]->data[j] != NULL) { - broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, menu[i]->data[j]); - s_displayansi_pause(menu[i]->data[j], 0); - } - break; - case MENU_DISPTXTFILEPAUSE: - if (menu[i]->data[j] != NULL) { - broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, menu[i]->data[j]); - s_displayansi_pause(menu[i]->data[j], 1); - } - s_printf(get_string(6)); - s_getc(); - break; - case MENU_GENWWWURLS: - genurls(); - break; - case MENU_NLBROWSER: - broadcast("USER: %s; NODE:%d; STATUS: Executing a filesearch.", gUser->loginname, mynode); - nl_browser(); - break; - case MENU_SENDFEEDBACK: - if (check_user(conf.sysop_name)) { - break; - } - broadcast("USER: %s; NODE:%d; STATUS: Sending feedback to Sysop.", gUser->loginname, mynode); - msg = external_editor(gUser, conf.sysop_name, gUser->loginname, NULL, 0, NULL, "Feedback", 1, 0); - if (msg != NULL) { - commit_email(conf.sysop_name, "Feedback", msg); - free(msg); - } - break; - case MENU_BLOGDISPLAY: - broadcast("USER: %s; NODE:%d; STATUS: Displaying Blog.", gUser->loginname, mynode); - blog_display(); - break; - case MENU_BLOGWRITE: - broadcast("USER: %s; NODE:%d; STATUS: Writing a Blog Entry.", gUser->loginname, mynode); - blog_write(); - break; - default: - break; - } - } - break; - } - } - } - } + break; + case MENU_RESETALLPOINTERS: + s_printf(get_string(230)); + confirm = s_getc(); + if (confirm == 'r' || confirm == 'R') { + m = 1; + } else if (confirm == 'u' || confirm == 'U') { + m = 0; + } else { + s_printf(get_string(39)); + break; + } + msgbase_reset_all_pointers(m); + break; + case MENU_FILESCAN: + broadcast("USER: %s; NODE:%d; STATUS: Doing a filescan.", gUser->loginname, mynode); + file_scan(); + break; + case MENU_FULLMAILSCAN: + if (menu[i]->data[j] != NULL) { + if (strcasecmp(menu[i]->data[j], "PERSONAL") == 0) { + broadcast("USER: %s; NODE:%d; STATUS: Scanning for personal mail.", gUser->loginname, mynode); + full_mail_scan_personal(gUser); + } else { + broadcast("USER: %s; NODE:%d; STATUS: Scanning all mail.", gUser->loginname, mynode); + full_mail_scan(gUser); + } + } else { + full_mail_scan(gUser); + } + break; + case MENU_FILESEARCH: + broadcast("USER: %s; NODE:%d; STATUS: Executing a filesearch.", gUser->loginname, mynode); + file_search(); + break; + case MENU_DISPTXTFILE: + if (menu[i]->data[j] != NULL) { + broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, menu[i]->data[j]); + s_displayansi_pause(menu[i]->data[j], 0); + } + break; + case MENU_DISPTXTFILEPAUSE: + if (menu[i]->data[j] != NULL) { + broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, menu[i]->data[j]); + s_displayansi_pause(menu[i]->data[j], 1); + } + s_printf(get_string(6)); + s_getc(); + break; + case MENU_GENWWWURLS: + genurls(); + break; + case MENU_NLBROWSER: + broadcast("USER: %s; NODE:%d; STATUS: Executing a filesearch.", gUser->loginname, mynode); + nl_browser(); + break; + case MENU_SENDFEEDBACK: + if (check_user(conf.sysop_name)) { + break; + } + broadcast("USER: %s; NODE:%d; STATUS: Sending feedback to Sysop.", gUser->loginname, mynode); + msg = external_editor(gUser, conf.sysop_name, gUser->loginname, NULL, 0, NULL, "Feedback", 1, 0); + if (msg != NULL) { + commit_email(conf.sysop_name, "Feedback", msg); + free(msg); + } + break; + case MENU_BLOGDISPLAY: + broadcast("USER: %s; NODE:%d; STATUS: Displaying Blog.", gUser->loginname, mynode); + blog_display(); + break; + case MENU_BLOGWRITE: + broadcast("USER: %s; NODE:%d; STATUS: Writing a Blog Entry.", gUser->loginname, mynode); + blog_write(); + break; + default: + break; + } + } + break; + } + } + } + } - // free menus; - return doquit; + // free menus; + return doquit; } diff --git a/src/nodelist.c b/src/nodelist.c index 003b31a..1dd66ef 100644 --- a/src/nodelist.c +++ b/src/nodelist.c @@ -8,22 +8,22 @@ extern struct user_record *gUser; char *nl_get_bbsname(struct fido_addr *addr, char *domain) { sqlite3 *db; - sqlite3_stmt *res; + sqlite3_stmt *res; int rc; char buffer[PATH_MAX]; char *ret; char *sql_buf = "SELECT bbsname FROM nodelist WHERE nodeno=? AND domain=?"; - + snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - return strdup("Unknown"); - } + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + return strdup("Unknown"); + } sqlite3_busy_timeout(db, 5000); - + rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); if (rc != SQLITE_OK) { @@ -31,22 +31,22 @@ char *nl_get_bbsname(struct fido_addr *addr, char *domain) { return strdup("Unknown"); } - if (addr->point == 0) { - snprintf(buffer, PATH_MAX, "%d:%d/%d", addr->zone, addr->net, addr->node); - } else { - // no support for point addresses yet. - return strdup("Unknown"); - } + if (addr->point == 0) { + snprintf(buffer, PATH_MAX, "%d:%d/%d", addr->zone, addr->net, addr->node); + } else { + // no support for point addresses yet. + return strdup("Unknown"); + } + + sqlite3_bind_text(res, 1, buffer, -1, 0); + sqlite3_bind_text(res, 2, domain, -1, 0); - sqlite3_bind_text(res, 1, buffer, -1, 0); - sqlite3_bind_text(res, 2, domain, -1, 0); - if (sqlite3_step(res) != SQLITE_ROW) { sqlite3_finalize(res); sqlite3_close(db); return strdup("Unknown"); - } - ret = strdup(sqlite3_column_text(res, 0)); + } + ret = strdup(sqlite3_column_text(res, 0)); sqlite3_finalize(res); sqlite3_close(db); @@ -64,7 +64,7 @@ void nl_browser() { int entry_count = 0; struct nl_temp **entries; sqlite3 *db; - sqlite3_stmt *res; + sqlite3_stmt *res; int rc; char buffer[PATH_MAX]; char *ret; @@ -77,15 +77,15 @@ void nl_browser() { // load nodelist snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path); - + rc = sqlite3_open(buffer, &db); - + if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - return; - } + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + return; + } sqlite3_busy_timeout(db, 5000); - + rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); if (rc != SQLITE_OK) { @@ -93,8 +93,8 @@ void nl_browser() { return; } - sqlite3_bind_text(res, 1, conf.mail_conferences[gUser->cur_mail_conf]->domain, -1, 0); - + sqlite3_bind_text(res, 1, conf.mail_conferences[gUser->cur_mail_conf]->domain, -1, 0); + while (sqlite3_step(res) == SQLITE_ROW) { if (entry_count == 0) { entries = (struct nl_temp **)malloc(sizeof(struct nl_temp *)); @@ -108,10 +108,10 @@ void nl_browser() { entries[entry_count]->sysop = strdup(sqlite3_column_text(res, 2)); entries[entry_count]->bbsname = strdup(sqlite3_column_text(res, 3)); entry_count++; - } - sqlite3_finalize(res); + } + sqlite3_finalize(res); sqlite3_close(db); - + if (entry_count == 0) { return; } @@ -121,7 +121,7 @@ void nl_browser() { s_printf("\e[2J\e[1;1H"); s_printf(get_string(145)); s_printf(get_string(146)); - for (i=start;iaddress, entries[i]->bbsname); } else { @@ -151,7 +151,7 @@ void nl_browser() { if (selected >= entry_count) { selected = entry_count - 1; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(261), selected - start + 1, selected - 1, entries[selected - 1]->address, entries[selected - 1]->bbsname); s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname); s_printf("\e[%d;5H", selected - start + 2); @@ -170,11 +170,11 @@ void nl_browser() { if (selected < 0) { selected = 0; } else { - if (!redraw) { + if (!redraw) { s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname); s_printf(get_string(261), selected - start + 3, selected + 1, entries[selected + 1]->address, entries[selected + 1]->bbsname); s_printf("\e[%d;5H", selected - start + 2); - } + } } } else if (c == 75) { // END KEY @@ -207,7 +207,7 @@ void nl_browser() { // PAGE DOWN selected = selected + 22; if (selected >= entry_count) { - selected = entry_count -1; + selected = entry_count - 1; } start = selected; redraw = 1; @@ -223,11 +223,11 @@ void nl_browser() { s_printf(get_string(267)); s_printf(get_string(185)); s_getc(); - s_printf("\r\n"); + s_printf("\r\n"); redraw = 1; } } - for (i=0;iaddress); free(entries[i]->bbsname); free(entries[i]->sysop); diff --git a/src/os/sunos.c b/src/os/sunos.c index 07d2782..436848c 100644 --- a/src/os/sunos.c +++ b/src/os/sunos.c @@ -12,32 +12,31 @@ int openpty(int *amaster, int *aslave, char *name, void *termp, void *winp) { int pts; ptm = open("/dev/ptmx", O_RDWR); - + grantpt(ptm); unlockpt(ptm); pname = ptsname(ptm); - + if (name != NULL) { strcpy(name, pname); - } + } pts = open(pname, O_RDWR); ioctl(pts, I_PUSH, "ptem"); ioctl(pts, I_PUSH, "ldterm"); ioctl(pts, I_PUSH, "ttcompat"); - if (termp != NULL) { - tcsetattr(pts, TCSAFLUSH, termp); - } - if (winp != NULL) { - ioctl(pts, TIOCSWINSZ, winp); - } - + if (termp != NULL) { + tcsetattr(pts, TCSAFLUSH, termp); + } + if (winp != NULL) { + ioctl(pts, TIOCSWINSZ, winp); + } *amaster = ptm; *aslave = pts; - + return 0; } @@ -52,7 +51,7 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) { grantpt(ptm); unlockpt(ptm); - + pname = ptsname(ptm); if (name != NULL) { @@ -71,7 +70,7 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) { } pid = fork(); - + if (!pid) { close(ptm); dup2(pts, 0); @@ -82,16 +81,15 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) { *amaster = ptm; } - return pid; + return pid; } - static long difftm(struct tm *a, struct tm *b) { int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); int by = b->tm_year + (TM_YEAR_ORIGIN - 1); - long days = (a->tm_yday - b->tm_yday + ((ay >> 2) - (by >> 2)) - (ay / 100 - by/100) + ((ay/100 >> 2) - (by / 100 >> 2)) + (long)(ay-by) * 365); + long days = (a->tm_yday - b->tm_yday + ((ay >> 2) - (by >> 2)) - (ay / 100 - by / 100) + ((ay / 100 >> 2) - (by / 100 >> 2)) + (long)(ay - by) * 365); - return (60 * (60 * (24 *days + (a->tm_hour - b->tm_hour)) + (a->tm_min - b->tm_min)) + (a->tm_sec - b->tm_sec)); + return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) + (a->tm_min - b->tm_min)) + (a->tm_sec - b->tm_sec)); } long gmtoff(time_t value) { diff --git a/src/os/sunos.h b/src/os/sunos.h index 42950ed..0fc660b 100644 --- a/src/os/sunos.h +++ b/src/os/sunos.h @@ -5,4 +5,3 @@ extern int openpty(int *amaster, int *aslave, char *name, void *termp, void *win extern int forkpty(int *amaster, char *name, void *termp, void *winp); extern long gmtoff(time_t value); #endif - diff --git a/src/settings.c b/src/settings.c index 667d595..d273caf 100644 --- a/src/settings.c +++ b/src/settings.c @@ -44,138 +44,116 @@ void settings_menu(struct user_record *user) { c = s_getc(); - switch(tolower(c)) { - case 27: - { + switch (tolower(c)) { + case 27: { + c = s_getc(); + if (c == 91) { c = s_getc(); - if (c == 91) { - c = s_getc(); - } } - break; - case 'p': - { - s_printf(get_string(155)); - s_readpass(buffer, 16); - hash = hash_sha256(buffer, user->salt); - if (strcmp(hash, user->password) == 0) { - s_printf(get_string(156)); - s_readstring(buffer, 16); - if (strlen(buffer) >= 8) { - free(user->password); - free(user->salt); + } break; + case 'p': { + s_printf(get_string(155)); + s_readpass(buffer, 16); + hash = hash_sha256(buffer, user->salt); + if (strcmp(hash, user->password) == 0) { + s_printf(get_string(156)); + s_readstring(buffer, 16); + if (strlen(buffer) >= 8) { + free(user->password); + free(user->salt); - gen_salt(&user->salt); - user->password = hash_sha256(buffer, user->salt); + gen_salt(&user->salt); + user->password = hash_sha256(buffer, user->salt); - save_user(user); - s_printf(get_string(157)); - } else { - s_printf(get_string(158)); - } - } else { - s_printf(get_string(159)); - } - } - break; - case 'l': - { - s_printf(get_string(160)); - s_readstring(buffer, 32); - free(user->location); - user->location = (char *)malloc(strlen(buffer) + 1); - strcpy(user->location, buffer); - save_user(user); - } - break; - case 'a': - { - s_printf(get_string(206)); - - for (i=0;iname); - } - - s_printf(get_string(208)); - s_readstring(buffer, 5); - new_arc = atoi(buffer); - - if (new_arc - 1 < 0 || new_arc > conf.archiver_count) { - break; - } else { - user->defarchiver = new_arc; save_user(user); - } - } - break; - - case 'o': - { - s_printf(get_string(212)); - - for (i=0;iname); - } - - s_printf(get_string(208)); - s_readstring(buffer, 5); - new_arc = atoi(buffer); - - if (new_arc - 1 < 0 || new_arc > conf.protocol_count) { - break; + s_printf(get_string(157)); } else { - user->defprotocol = new_arc; - save_user(user); + s_printf(get_string(158)); } + } else { + s_printf(get_string(159)); } - break; - case 'm': - { - user->nodemsgs = !user->nodemsgs; + } break; + case 'l': { + s_printf(get_string(160)); + s_readstring(buffer, 32); + free(user->location); + user->location = (char *)malloc(strlen(buffer) + 1); + strcpy(user->location, buffer); + save_user(user); + } break; + case 'a': { + s_printf(get_string(206)); + + for (i = 0; i < conf.archiver_count; i++) { + s_printf(get_string(207), i + 1, conf.archivers[i]->name); + } + + s_printf(get_string(208)); + s_readstring(buffer, 5); + new_arc = atoi(buffer); + + if (new_arc - 1 < 0 || new_arc > conf.archiver_count) { + break; + } else { + user->defarchiver = new_arc; save_user(user); } - break; - case 'c': - { - user->codepage = !user->codepage; + } break; + + case 'o': { + s_printf(get_string(212)); + + for (i = 0; i < conf.protocol_count; i++) { + s_printf(get_string(207), i + 1, conf.protocols[i]->name); + } + + s_printf(get_string(208)); + s_readstring(buffer, 5); + new_arc = atoi(buffer); + + if (new_arc - 1 < 0 || new_arc > conf.protocol_count) { + break; + } else { + user->defprotocol = new_arc; save_user(user); } - break; - case 'e': - { - user->exteditor++; - if (user->exteditor == 3) { - user->exteditor = 0; - } + } break; + case 'm': { + user->nodemsgs = !user->nodemsgs; + save_user(user); + } break; + case 'c': { + user->codepage = !user->codepage; + save_user(user); + } break; + case 'e': { + user->exteditor++; + if (user->exteditor == 3) { + user->exteditor = 0; + } + save_user(user); + } break; + case 'b': { + user->bwavepktno = 0; + user->bwavestyle = !user->bwavestyle; + save_user(user); + } break; + case 's': { + // set signature + if (user->signature != NULL) { + free(user->signature); + } + sig = external_editor(user, "No-One", "No-One", NULL, 0, "No-One", "Signature Editor", 0, 1); + if (sig != NULL) { + user->signature = sig; save_user(user); } - break; - case 'b': - { - user->bwavepktno = 0; - user->bwavestyle = !user->bwavestyle; - save_user(user); - } - break; - case 's': - { - // set signature - if (user->signature != NULL) { - free(user->signature); - } - sig = external_editor(user, "No-One", "No-One", NULL, 0, "No-One", "Signature Editor", 0, 1); - if (sig != NULL) { - user->signature = sig; - save_user(user); - } - } - break; - case 't': - { - user->autosig = !user->autosig; - save_user(user); - } - break; + } break; + case 't': { + user->autosig = !user->autosig; + save_user(user); + } break; case 'q': dosettings = 1; break; diff --git a/src/strings.c b/src/strings.c index b6680af..3e3a27f 100644 --- a/src/strings.c +++ b/src/strings.c @@ -10,8 +10,8 @@ char **strings; int string_count; void chomp(char *string) { - while (strlen(string) && (string[strlen(string)-1] == '\r' || string[strlen(string)-1] == '\n')) { - string[strlen(string)-1] = '\0'; + while (strlen(string) && (string[strlen(string) - 1] == '\r' || string[strlen(string) - 1] == '\n')) { + string[strlen(string) - 1] = '\0'; } } @@ -19,7 +19,7 @@ char *parse_newlines(char *string) { char *newstring = (char *)malloc(strlen(string) + 1); int pos = 0; int i; - for (i=0;ipassword, -1, 0); + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, user->password, -1, 0); sqlite3_bind_text(res, 2, user->salt, -1, 0); - sqlite3_bind_text(res, 3, user->firstname, -1, 0); - sqlite3_bind_text(res, 4, user->lastname, -1, 0); - sqlite3_bind_text(res, 5, user->email, -1, 0); - sqlite3_bind_text(res, 6, user->location, -1, 0); - sqlite3_bind_int(res, 7, user->sec_level); - sqlite3_bind_int(res, 8, user->laston); - sqlite3_bind_int(res, 9, user->timeleft); - sqlite3_bind_int(res, 10, user->cur_mail_conf); - sqlite3_bind_int(res, 11, user->cur_mail_area); - 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); - sqlite3_bind_int(res, 15, user->bwavepktno); - sqlite3_bind_int(res, 16, user->defarchiver); - sqlite3_bind_int(res, 17, user->defprotocol); + sqlite3_bind_text(res, 3, user->firstname, -1, 0); + sqlite3_bind_text(res, 4, user->lastname, -1, 0); + sqlite3_bind_text(res, 5, user->email, -1, 0); + sqlite3_bind_text(res, 6, user->location, -1, 0); + sqlite3_bind_int(res, 7, user->sec_level); + sqlite3_bind_int(res, 8, user->laston); + sqlite3_bind_int(res, 9, user->timeleft); + sqlite3_bind_int(res, 10, user->cur_mail_conf); + sqlite3_bind_int(res, 11, user->cur_mail_area); + 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); + sqlite3_bind_int(res, 15, user->bwavepktno); + sqlite3_bind_int(res, 16, user->defarchiver); + sqlite3_bind_int(res, 17, user->defprotocol); sqlite3_bind_int(res, 18, user->nodemsgs); sqlite3_bind_int(res, 19, user->codepage); sqlite3_bind_int(res, 20, user->exteditor); sqlite3_bind_int(res, 21, user->bwavestyle); sqlite3_bind_text(res, 22, user->signature, -1, 0); sqlite3_bind_int(res, 23, user->autosig); - sqlite3_bind_text(res, 24, user->loginname, -1, 0); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); - } + sqlite3_bind_text(res, 24, user->loginname, -1, 0); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + } - - rc = sqlite3_step(res); - if (rc != SQLITE_DONE) { + rc = sqlite3_step(res); + if (rc != SQLITE_DONE) { sqlite3_finalize(res); - dolog("execution failed: %s", sqlite3_errmsg(db)); + dolog("execution failed: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); - } + } sqlite3_finalize(res); sqlite3_close(db); return 1; - } int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, int msgid) { sqlite3 *db; - sqlite3_stmt *res; + sqlite3_stmt *res; int rc; char buffer[PATH_MAX]; char *create_sql = "CREATE TABLE IF NOT EXISTS msg_flags (conference INTEGER, msgbase INTEGER, uid INTEGER, msg INTEGER);"; char *flag_buf = "INSERT INTO msg_flags (conference, msgbase, uid, msg) VALUES(?, ?, ?, ?)"; char *unflag_buf = "DELETE FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?"; - char *err_msg = 0; - int flagunflag = 0; - - - flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid); - - snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); + char *err_msg = 0; + int flagunflag = 0; + + flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid); + + snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - return 0; - } + return 0; + } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); + if (rc != SQLITE_OK) { - dolog("SQL error: %s", err_msg); + dolog("SQL error: %s", err_msg); - sqlite3_free(err_msg); - sqlite3_close(db); + sqlite3_free(err_msg); + sqlite3_close(db); - return 0; - } - if (flagunflag == 1) { + return 0; + } + if (flagunflag == 1) { rc = sqlite3_prepare_v2(db, unflag_buf, -1, &res, 0); } else { rc = sqlite3_prepare_v2(db, flag_buf, -1, &res, 0); } - sqlite3_bind_int(res, 1, conference); - sqlite3_bind_int(res, 2, msgbase); - sqlite3_bind_int(res, 3, user->id); - sqlite3_bind_int(res, 4, msgid); + sqlite3_bind_int(res, 1, conference); + sqlite3_bind_int(res, 2, msgbase); + sqlite3_bind_int(res, 3, user->id); + sqlite3_bind_int(res, 4, msgid); + + rc = sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); - rc = sqlite3_step(res); - - sqlite3_finalize(res); - sqlite3_close(db); - return 1; } int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, int msgid) { sqlite3 *db; - sqlite3_stmt *res; + sqlite3_stmt *res; int rc; char buffer[PATH_MAX]; - - char *sql_buf = "SELECT * FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?"; - - snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); - - rc = sqlite3_open(buffer, &db); - - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } + char *sql_buf = "SELECT * FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?"; + + snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); + + rc = sqlite3_open(buffer, &db); + + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + + exit(1); + } sqlite3_busy_timeout(db, 5000); - + rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); if (rc != SQLITE_OK) { @@ -240,16 +234,16 @@ int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, in return 0; } - sqlite3_bind_int(res, 1, conference); - sqlite3_bind_int(res, 2, msgbase); - sqlite3_bind_int(res, 3, user->id); + sqlite3_bind_int(res, 1, conference); + sqlite3_bind_int(res, 2, msgbase); + sqlite3_bind_int(res, 3, user->id); sqlite3_bind_int(res, 4, msgid); - + if (sqlite3_step(res) != SQLITE_ROW) { sqlite3_finalize(res); sqlite3_close(db); return 0; - } + } sqlite3_finalize(res); sqlite3_close(db); return 1; @@ -257,79 +251,76 @@ int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, in int msgbase_sub_unsub(int conference, int msgbase) { sqlite3 *db; - sqlite3_stmt *res; + sqlite3_stmt *res; int rc; char buffer[PATH_MAX]; char *create_sql = "CREATE TABLE IF NOT EXISTS msg_subs (conference INTEGER, msgbase INTEGER, uid INTEGER);"; char *sub_buf = "INSERT INTO msg_subs (conference, msgbase, uid) VALUES(?, ?, ?)"; char *unsub_buf = "DELETE FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?"; - char *err_msg = 0; - int subunsub = 0; - - - subunsub = msgbase_is_subscribed(conference, msgbase); - - snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); + char *err_msg = 0; + int subunsub = 0; + + subunsub = msgbase_is_subscribed(conference, msgbase); + + snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - return 0; - } + return 0; + } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); + if (rc != SQLITE_OK) { - dolog("SQL error: %s", err_msg); + dolog("SQL error: %s", err_msg); - sqlite3_free(err_msg); - sqlite3_close(db); + sqlite3_free(err_msg); + sqlite3_close(db); - return 0; - } - if (subunsub == 1) { + return 0; + } + if (subunsub == 1) { rc = sqlite3_prepare_v2(db, unsub_buf, -1, &res, 0); } else { rc = sqlite3_prepare_v2(db, sub_buf, -1, &res, 0); } - sqlite3_bind_int(res, 1, conference); - sqlite3_bind_int(res, 2, msgbase); - sqlite3_bind_int(res, 3, gUser->id); - - rc = sqlite3_step(res); - - sqlite3_finalize(res); - sqlite3_close(db); - + sqlite3_bind_int(res, 1, conference); + sqlite3_bind_int(res, 2, msgbase); + sqlite3_bind_int(res, 3, gUser->id); + + rc = sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); + return 1; } int msgbase_is_subscribed(int conference, int msgbase) { sqlite3 *db; - sqlite3_stmt *res; + sqlite3_stmt *res; int rc; char buffer[PATH_MAX]; - - char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?"; - - - - snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); - - rc = sqlite3_open(buffer, &db); - - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } + char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?"; + + snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); + + rc = sqlite3_open(buffer, &db); + + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + + exit(1); + } sqlite3_busy_timeout(db, 5000); - + rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); if (rc != SQLITE_OK) { @@ -337,15 +328,15 @@ int msgbase_is_subscribed(int conference, int msgbase) { return 0; } - sqlite3_bind_int(res, 1, conference); - sqlite3_bind_int(res, 2, msgbase); - sqlite3_bind_int(res, 3, gUser->id); - + sqlite3_bind_int(res, 1, conference); + sqlite3_bind_int(res, 2, msgbase); + sqlite3_bind_int(res, 3, gUser->id); + if (sqlite3_step(res) != SQLITE_ROW) { sqlite3_finalize(res); sqlite3_close(db); return 0; - } + } sqlite3_finalize(res); sqlite3_close(db); return 1; @@ -354,79 +345,79 @@ int msgbase_is_subscribed(int conference, int msgbase) { int inst_user(struct user_record *user) { char buffer[PATH_MAX]; sqlite3 *db; - sqlite3_stmt *res; + sqlite3_stmt *res; int rc; - char *create_sql = "CREATE TABLE IF NOT EXISTS users (" - "Id INTEGER PRIMARY KEY," - "loginname TEXT COLLATE NOCASE," - "password TEXT," - "salt TEXT," - "firstname TEXT," - "lastname TEXT," - "email TEXT," - "location TEXT," - "sec_level INTEGER," - "last_on INTEGER," - "time_left INTEGER," - "cur_mail_conf INTEGER," - "cur_mail_area INTEGER," - "cur_file_sub INTEGER," - "cur_file_dir INTEGER," - "times_on INTEGER," - "bwavepktno INTEGER," - "archiver INTEGER," - "protocol INTEGER," - "nodemsgs INTEGER," - "codepage INTEGER," - "exteditor INTEGER," - "bwavestyle INTEGER," - "signature TEXT," - "autosig INTEGER);"; + char *create_sql = "CREATE TABLE IF NOT EXISTS users (" + "Id INTEGER PRIMARY KEY," + "loginname TEXT COLLATE NOCASE," + "password TEXT," + "salt TEXT," + "firstname TEXT," + "lastname TEXT," + "email TEXT," + "location TEXT," + "sec_level INTEGER," + "last_on INTEGER," + "time_left INTEGER," + "cur_mail_conf INTEGER," + "cur_mail_area INTEGER," + "cur_file_sub INTEGER," + "cur_file_dir INTEGER," + "times_on INTEGER," + "bwavepktno INTEGER," + "archiver INTEGER," + "protocol INTEGER," + "nodemsgs INTEGER," + "codepage INTEGER," + "exteditor INTEGER," + "bwavestyle INTEGER," + "signature TEXT," + "autosig INTEGER);"; char *insert_sql = "INSERT INTO users (loginname, password, salt, firstname," - "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage, exteditor, bwavestyle, signature, autosig) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - char *err_msg = 0; + "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage, exteditor, bwavestyle, signature, autosig) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + char *err_msg = 0; - snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); + snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } + exit(1); + } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); + if (rc != SQLITE_OK) { - dolog("SQL error: %s", err_msg); + dolog("SQL error: %s", err_msg); - sqlite3_free(err_msg); - sqlite3_close(db); + sqlite3_free(err_msg); + sqlite3_close(db); - exit(1); - } + exit(1); + } - rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0); + rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0); - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, user->loginname, -1, 0); - sqlite3_bind_text(res, 2, user->password, -1, 0); + 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->salt, -1, 0); - sqlite3_bind_text(res, 4, user->firstname, -1, 0); - sqlite3_bind_text(res, 5, user->lastname, -1, 0); - sqlite3_bind_text(res, 6, user->email, -1, 0); - sqlite3_bind_text(res, 7, user->location, -1, 0); - sqlite3_bind_int(res, 8, user->sec_level); - sqlite3_bind_int(res, 9, user->laston); - sqlite3_bind_int(res, 10, user->timeleft); - sqlite3_bind_int(res, 11, user->cur_mail_conf); - sqlite3_bind_int(res, 12, user->cur_mail_area); - sqlite3_bind_int(res, 13, user->cur_file_dir); - sqlite3_bind_int(res, 14, user->cur_file_sub); - sqlite3_bind_int(res, 15, user->timeson); + sqlite3_bind_text(res, 4, user->firstname, -1, 0); + sqlite3_bind_text(res, 5, user->lastname, -1, 0); + sqlite3_bind_text(res, 6, user->email, -1, 0); + sqlite3_bind_text(res, 7, user->location, -1, 0); + sqlite3_bind_int(res, 8, user->sec_level); + sqlite3_bind_int(res, 9, user->laston); + sqlite3_bind_int(res, 10, user->timeleft); + sqlite3_bind_int(res, 11, user->cur_mail_conf); + sqlite3_bind_int(res, 12, user->cur_mail_area); + sqlite3_bind_int(res, 13, user->cur_file_dir); + sqlite3_bind_int(res, 14, user->cur_file_sub); + sqlite3_bind_int(res, 15, user->timeson); sqlite3_bind_int(res, 16, user->bwavepktno); sqlite3_bind_int(res, 17, user->defarchiver); sqlite3_bind_int(res, 18, user->defprotocol); @@ -436,24 +427,23 @@ int inst_user(struct user_record *user) { sqlite3_bind_int(res, 22, user->bwavestyle); sqlite3_bind_text(res, 23, user->signature, -1, 0); sqlite3_bind_int(res, 24, user->autosig); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } - - - rc = sqlite3_step(res); - - if (rc != SQLITE_DONE) { - dolog("execution failed: %s", sqlite3_errmsg(db)); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); - } + } - user->id = sqlite3_last_insert_rowid(db); + rc = sqlite3_step(res); - sqlite3_finalize(res); + if (rc != SQLITE_DONE) { + dolog("execution failed: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + exit(1); + } + + user->id = sqlite3_last_insert_rowid(db); + + sqlite3_finalize(res); sqlite3_close(db); return 1; } @@ -462,36 +452,36 @@ struct user_record *check_user_pass(char *loginname, char *password) { struct user_record *user; char buffer[1024]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char *sql = "SELECT Id, loginname, password, salt, firstname," - "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs, codepage, exteditor, bwavestyle, signature, autosig FROM users WHERE loginname LIKE ?"; + sqlite3_stmt *res; + int rc; + char *sql = "SELECT Id, loginname, password, salt, firstname," + "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs, codepage, exteditor, bwavestyle, signature, autosig FROM users WHERE loginname LIKE ?"; char *pass_hash; sprintf(buffer, "%s/users.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } + exit(1); + } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, loginname, -1, 0); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, loginname, -1, 0); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); return NULL; - } + } - int step = sqlite3_step(res); + 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)); @@ -530,24 +520,24 @@ struct user_record *check_user_pass(char *loginname, char *password) { free(user->signature); free(user); free(pass_hash); - sqlite3_finalize(res); + sqlite3_finalize(res); sqlite3_close(db); return NULL; } free(pass_hash); - } else { + } else { sqlite3_finalize(res); sqlite3_close(db); return NULL; } - sqlite3_finalize(res); - sqlite3_close(db); + sqlite3_finalize(res); + sqlite3_close(db); - user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t)); + user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t)); - snprintf(buffer, 1024, "%s/s%d.ini", conf.config_path, user->sec_level); - if (ini_parse(buffer, secLevel, user->sec_info) <0) { + snprintf(buffer, 1024, "%s/s%d.ini", conf.config_path, user->sec_level); + if (ini_parse(buffer, secLevel, user->sec_info) < 0) { dolog("Unable to load sec Level ini (%s)!", buffer); exit(-1); } @@ -567,16 +557,15 @@ struct user_record *check_user_pass(char *loginname, char *password) { user->cur_file_sub = 0; } - - return user; + return user; } void list_users(struct user_record *user) { char buffer[256]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - int i; + sqlite3_stmt *res; + int rc; + int i; char *sql = "SELECT loginname,location,times_on FROM users"; @@ -585,22 +574,22 @@ void list_users(struct user_record *user) { rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + exit(1); + } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); if (rc != SQLITE_OK) { - dolog("Cannot prepare statement: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } - s_printf(get_string(161)); - s_printf(get_string(162)); - s_printf(get_string(163)); - i = 0; - while (sqlite3_step(res) == SQLITE_ROW) { + dolog("Cannot prepare statement: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + exit(1); + } + s_printf(get_string(161)); + s_printf(get_string(162)); + s_printf(get_string(163)); + i = 0; + while (sqlite3_step(res) == SQLITE_ROW) { s_printf(get_string(164), sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2)); i++; @@ -610,91 +599,91 @@ void list_users(struct user_record *user) { i = 0; } } - s_printf(get_string(165)); - sqlite3_finalize(res); - sqlite3_close(db); + s_printf(get_string(165)); + sqlite3_finalize(res); + sqlite3_close(db); - s_printf(get_string(6)); + s_printf(get_string(6)); s_getc(); } int check_fullname(char *firstname, char *lastname) { char buffer[256]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char *sql = "SELECT * FROM users WHERE firstname = ? AND lastname = ?"; + sqlite3_stmt *res; + int rc; + char *sql = "SELECT * FROM users WHERE firstname = ? AND lastname = ?"; sprintf(buffer, "%s/users.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } - sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + exit(1); + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, firstname, -1, 0); - sqlite3_bind_text(res, 2, lastname, -1, 0); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); - } + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, firstname, -1, 0); + sqlite3_bind_text(res, 2, lastname, -1, 0); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + } - int step = sqlite3_step(res); + int step = sqlite3_step(res); - if (step == SQLITE_ROW) { + if (step == SQLITE_ROW) { sqlite3_finalize(res); sqlite3_close(db); return 0; - } + } - sqlite3_finalize(res); - sqlite3_close(db); - return 1; + sqlite3_finalize(res); + sqlite3_close(db); + return 1; } int check_user(char *loginname) { char buffer[256]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char *sql = "SELECT * FROM users WHERE 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) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } - sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + exit(1); + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, loginname, -1, 0); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); - } + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, loginname, -1, 0); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + } - int step = sqlite3_step(res); + int step = sqlite3_step(res); - if (step == SQLITE_ROW) { + if (step == SQLITE_ROW) { sqlite3_finalize(res); sqlite3_close(db); return 0; - } + } - sqlite3_finalize(res); - sqlite3_close(db); - return 1; + sqlite3_finalize(res); + sqlite3_close(db); + return 1; } struct user_record *new_user() { @@ -706,7 +695,7 @@ struct user_record *new_user() { int passok = 0; int i; int fullnameok = 0; - + user = (struct user_record *)malloc(sizeof(struct user_record)); s_printf("\r\n\r\n"); s_displayansi("newuser"); @@ -726,7 +715,7 @@ struct user_record *new_user() { s_printf(get_string(240)); continue; } - for (i=0;i= 97 && tolower(buffer[i]) <= 122) && buffer[i] != 32 && !(buffer[i] >= '0' && buffer[i] <= '9')) { s_printf(get_string(168)); nameok = 1; @@ -756,7 +745,7 @@ struct user_record *new_user() { if (strcasecmp(buffer, "ftp") == 0) { s_printf(get_string(169)); continue; - } + } user->loginname = strdup(buffer); nameok = check_user(user->loginname); if (!nameok) { @@ -782,14 +771,14 @@ struct user_record *new_user() { if (strchr(buffer, ' ') != NULL) { s_printf(get_string(244)); continue; - } + } s_printf("\r\n"); user->firstname = strdup(buffer); nameok = 1; } while (!nameok); nameok = 0; - - do { + + do { s_printf(get_string(172)); memset(buffer, 0, 256); s_readstring(buffer, 32); @@ -870,7 +859,7 @@ struct user_record *new_user() { user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t)); snprintf(buffer, PATH_MAX, "%s/config/s%d.ini", conf.bbs_path, user->sec_level); - if (ini_parse(buffer, secLevel, user->sec_info) <0) { + if (ini_parse(buffer, secLevel, user->sec_info) < 0) { dolog("Unable to load sec Level ini (%s)!", buffer); exit(-1); } diff --git a/src/www.c b/src/www.c index 99de903..e125256 100644 --- a/src/www.c +++ b/src/www.c @@ -40,7 +40,7 @@ struct connection_info_s { struct MHD_PostProcessor *pp; }; -void *www_logger(void * cls, const char * uri, struct MHD_Connection *con) { +void *www_logger(void *cls, const char *uri, struct MHD_Connection *con) { struct sockaddr *so = (struct sockaddr *)MHD_get_connection_info(con, MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr; char *ipaddr; if (so->sa_family == AF_INET) { @@ -62,11 +62,11 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void ** if (con_info == NULL) { return; } - + if (con_info->connection_type == POST) { if (con_info->count > 0) { - for (i=0;icount;i++) { + for (i = 0; i < con_info->count; i++) { free(con_info->values[i]); free(con_info->keys[i]); } @@ -74,7 +74,7 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void ** free(con_info->keys); } - if (con_info->pp != NULL) { + if (con_info->pp != NULL) { MHD_destroy_post_processor(con_info->pp); } } @@ -88,13 +88,13 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void ** free(con_info->user->sec_info); free(con_info->user->signature); free(con_info->user); - } - + } + free(con_info->url); free(con_info); } -static int iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) { +static int iterate_post(void *coninfo_cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) { struct connection_info_s *con_info = coninfo_cls; int i; @@ -103,23 +103,22 @@ static int iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char return MHD_NO; } - if (con_info != NULL) { if (con_info->connection_type == POST) { - for (i=0;icount;i++) { + for (i = 0; i < con_info->count; i++) { if (strcmp(con_info->keys[i], key) == 0) { con_info->values[i] = (char *)realloc(con_info->values[i], strlen(con_info->values[i]) + size + 1); strcat(con_info->values[i], data); return MHD_YES; } } - + if (con_info->count == 0) { con_info->keys = (char **)malloc(sizeof(char *)); con_info->values = (char **)malloc(sizeof(char *)); } else { con_info->keys = (char **)realloc(con_info->keys, sizeof(char *) * (con_info->count + 1)); - con_info->values = (char **)realloc(con_info->values, sizeof(char *) * (con_info->count + 1)); + con_info->values = (char **)realloc(con_info->values, sizeof(char *) * (con_info->count + 1)); } con_info->keys[con_info->count] = strdup(key); con_info->values[con_info->count] = strdup(data); @@ -137,11 +136,11 @@ void www_init() { FILE *fptr; char buffer[PATH_MAX]; int i; - + mime_types_count = 0; - + snprintf(buffer, PATH_MAX, "%s/mime.types", conf.www_path); - + fptr = fopen(buffer, "r"); if (!fptr) { return; @@ -149,8 +148,8 @@ void www_init() { fgets(buffer, 256, fptr); while (!feof(fptr)) { chomp(buffer); - - for (i=0;imime = strdup(buffer); - mime_types[mime_types_count]->ext = strdup(&buffer[i+1]); - + mime_types[mime_types_count]->ext = strdup(&buffer[i + 1]); + mime_types_count++; break; } } - + fgets(buffer, 256, fptr); } - + fclose(fptr); } char *www_get_mime_type(const char *extension) { int i; static char default_mime_type[] = "application/octet-stream"; - + if (extension == NULL) { return default_mime_type; } - for (i=0;iext) == 0) { return mime_types[i]->mime; } @@ -191,7 +190,7 @@ char *www_get_mime_type(const char *extension) { return default_mime_type; } -int www_401(char *header, char *footer, struct MHD_Connection * connection) { +int www_401(char *header, char *footer, struct MHD_Connection *connection) { char buffer[PATH_MAX]; char *page, *page_tmp; struct stat s; @@ -199,11 +198,11 @@ int www_401(char *header, char *footer, struct MHD_Connection * connection) { struct MHD_Response *response; int ret; FILE *fptr; - + snprintf(buffer, PATH_MAX, "%s/401.tpl", conf.www_path); - + page_tmp = NULL; - + if (stat(buffer, &s) == 0) { page_tmp = (char *)malloc(s.st_size + 1); if (page_tmp == NULL) { @@ -219,7 +218,7 @@ int www_401(char *header, char *footer, struct MHD_Connection * connection) { page_tmp = NULL; } } - + if (page_tmp == NULL) { page_tmp = (char *)malloc(16); if (page_tmp == NULL) { @@ -232,21 +231,21 @@ int www_401(char *header, char *footer, struct MHD_Connection * connection) { free(page_tmp); whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); - response = MHD_create_response_from_buffer (strlen(whole_page), (void*)whole_page, MHD_RESPMEM_MUST_FREE); - + response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE); + MHD_add_response_header(response, "WWW-Authenticate", "Basic realm=\"BBS Area\""); - - ret = MHD_queue_response (connection, 401, response); - MHD_destroy_response (response); + + ret = MHD_queue_response(connection, 401, response); + MHD_destroy_response(response); free(page); - + return 0; } -int www_404(char *header, char *footer, struct MHD_Connection * connection) { +int www_404(char *header, char *footer, struct MHD_Connection *connection) { char buffer[PATH_MAX]; char *page, *page_tmp; struct stat s; @@ -254,11 +253,11 @@ int www_404(char *header, char *footer, struct MHD_Connection * connection) { struct MHD_Response *response; int ret; FILE *fptr; - + snprintf(buffer, PATH_MAX, "%s/404.tpl", conf.www_path); - + page_tmp = NULL; - + if (stat(buffer, &s) == 0) { page_tmp = (char *)malloc(s.st_size + 1); if (page_tmp == NULL) { @@ -274,7 +273,7 @@ int www_404(char *header, char *footer, struct MHD_Connection * connection) { page = NULL; } } - + if (page_tmp == NULL) { page_tmp = (char *)malloc(16); if (page_tmp == NULL) { @@ -287,19 +286,19 @@ int www_404(char *header, char *footer, struct MHD_Connection * connection) { free(page_tmp); whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); - response = MHD_create_response_from_buffer (strlen(whole_page), (void*)whole_page, MHD_RESPMEM_MUST_FREE); - - ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response); - MHD_destroy_response (response); + response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE); + + ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response); + MHD_destroy_response(response); free(page); - + return 0; } -int www_403(char *header, char *footer, struct MHD_Connection * connection) { +int www_403(char *header, char *footer, struct MHD_Connection *connection) { char buffer[PATH_MAX]; char *page, *page_tmp; struct stat s; @@ -308,11 +307,11 @@ int www_403(char *header, char *footer, struct MHD_Connection * connection) { int ret; FILE *fptr; char *endptr; - + snprintf(buffer, PATH_MAX, "%s/403.tpl", conf.www_path); - + page_tmp = NULL; - + if (stat(buffer, &s) == 0) { page_tmp = (char *)malloc(s.st_size + 1); if (page_tmp == NULL) { @@ -328,7 +327,7 @@ int www_403(char *header, char *footer, struct MHD_Connection * connection) { page_tmp = NULL; } } - + if (page_tmp == NULL) { page_tmp = (char *)malloc(16); if (page_tmp == NULL) { @@ -341,15 +340,15 @@ int www_403(char *header, char *footer, struct MHD_Connection * connection) { free(page_tmp); whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); - response = MHD_create_response_from_buffer (strlen(whole_page), (void*)whole_page, MHD_RESPMEM_MUST_FREE); - - ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response); - MHD_destroy_response (response); + response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE); + + ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response); + MHD_destroy_response(response); free(page); - + return 0; } @@ -363,30 +362,30 @@ struct user_record *www_auth_ok(struct MHD_Connection *connection, const char *u char *password; int i; struct user_record *u; - + if (ptr == NULL) { return NULL; } - + user_password = strdup(ptr); - + if (strncasecmp(user_password, "basic ", 6) == 0) { if (strlen(&user_password[6]) <= 48) { base64_init_decodestate(&state); len = base64_decode_block(&user_password[6], strlen(&user_password[6]), decoded_pass, &state); decoded_pass[len] = '\0'; - + username = decoded_pass; - for (i=0;i\n\n%s\n\n\n

%s


", conf.bbs_name, conf.bbs_name); } - + header = str_replace(header_tmp, "@@WWW_URL@@", conf.www_url); free(header_tmp); snprintf(buffer, PATH_MAX, "%s/footer.tpl", conf.www_path); - + footer_tmp = NULL; - + if (stat(buffer, &s) == 0) { footer_tmp = (char *)malloc(s.st_size + 1); if (footer_tmp == NULL) { @@ -512,7 +511,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url footer_tmp = NULL; } } - + if (footer_tmp == NULL) { footer_tmp = (char *)malloc(43); if (footer_tmp == NULL) { @@ -529,9 +528,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (strcasecmp(url, "/") == 0) { snprintf(buffer, PATH_MAX, "%s/index.tpl", conf.www_path); - + page_tmp = NULL; - + if (stat(buffer, &s) == 0) { page_tmp = (char *)malloc(s.st_size + 1); if (page_tmp == NULL) { @@ -549,29 +548,29 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url page_tmp = NULL; } } - + if (page_tmp == NULL) { page_tmp = (char *)malloc(16); if (page_tmp == NULL) { free(header); - free(footer); + free(footer); return MHD_NO; } sprintf(page_tmp, "Missing Content"); } - + page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url); free(page_tmp); whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strcasecmp(url, "/last10/") == 0 || strcasecmp(url, "/last10") == 0) { page = www_last10(); if (page == NULL) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); @@ -581,62 +580,62 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (page == NULL) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - sprintf(whole_page, "%s%s%s", header, page, footer); + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) { con_inf->user = www_auth_ok(connection, url_); - + if (con_inf->user == NULL) { www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; } page = www_email_summary(con_inf->user); if (page == NULL) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); sprintf(whole_page, "%s%s%s", header, page, footer); - } else if(strcasecmp(url, "/email/new") == 0) { + } else if (strcasecmp(url, "/email/new") == 0) { con_inf->user = www_auth_ok(connection, url_); - + if (con_inf->user == NULL) { www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; } page = www_new_email(); if (page == NULL) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - - sprintf(whole_page, "%s%s%s", header, page, footer); + + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strncasecmp(url, "/email/delete/", 14) == 0) { con_inf->user = www_auth_ok(connection, url_); - + if (con_inf->user == NULL) { www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; } email = strtol(&url[14], &endptr, 10); if (email == -1 || !www_email_delete(con_inf->user, email)) { page = (char *)malloc(31); if (page == NULL) { free(header); - free(footer); + free(footer); return MHD_NO; } sprintf(page, "

Error Deleting Email.

"); @@ -644,7 +643,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url page = (char *)malloc(24); if (page == NULL) { free(header); - free(footer); + free(footer); return MHD_NO; } sprintf(page, "

Email Deleted!

"); @@ -652,67 +651,67 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (page == NULL) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - - sprintf(whole_page, "%s%s%s", header, page, footer); + + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strncasecmp(url, "/email/", 7) == 0) { con_inf->user = www_auth_ok(connection, url_); - + if (con_inf->user == NULL) { www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; } email = strtol(&url[7], &endptr, 10); if (email == -1) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } page = www_email_display(con_inf->user, email); if (page == NULL) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strcasecmp(url, "/msgs/") == 0 || strcasecmp(url, "/msgs") == 0) { con_inf->user = www_auth_ok(connection, url_); - + if (con_inf->user == NULL) { www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; } page = www_msgs_arealist(con_inf->user); if (page == NULL) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strncasecmp(url, "/msgs/flag/", 11) == 0) { con_inf->user = www_auth_ok(connection, url_); - + if (con_inf->user == NULL) { www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; } conference = -1; area = -1; msg = -1; url_copy = strdup(&url[11]); - + aptr = strtok(url_copy, "/"); if (aptr != NULL) { conference = strtol(aptr, &endptr, 10); @@ -730,19 +729,19 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url msg = strtol(aptr, &endptr, 10); if (endptr == aptr) { msg = -1; - } + } } } } free(url_copy); - + if (conference != -1 && area != -1 && msg != -1) { msgbase_flag_unflag(con_inf->user, conference, area, msg); - response = MHD_create_response_from_buffer (0, (void*) "", MHD_RESPMEM_PERSISTENT); + response = MHD_create_response_from_buffer(0, (void *)"", MHD_RESPMEM_PERSISTENT); snprintf(buffer, PATH_MAX, "%smsgs/%d/%d/%d", conf.www_url, conference, area, msg); - - MHD_add_response_header (response, "Location", buffer); - MHD_queue_response (connection, MHD_HTTP_FOUND, response); + + MHD_add_response_header(response, "Location", buffer); + MHD_queue_response(connection, MHD_HTTP_FOUND, response); MHD_destroy_response(response); free(header); free(footer); @@ -751,20 +750,20 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url www_404(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; } else if (strncasecmp(url, "/msgs/new/", 10) == 0) { con_inf->user = www_auth_ok(connection, url_); - + if (con_inf->user == NULL) { www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; - } + return MHD_YES; + } conference = -1; area = -1; url_copy = strdup(&url[10]); - + aptr = strtok(url_copy, "/"); if (aptr != NULL) { conference = strtol(aptr, &endptr, 10); @@ -776,35 +775,35 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url area = strtol(aptr, &endptr, 10); if (endptr == aptr) { area = -1; - } + } } } free(url_copy); - + if (area != -1 && conference != -1) { page = www_new_msg(con_inf->user, conference, area); } else { free(header); free(footer); - return MHD_NO; + return MHD_NO; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - - sprintf(whole_page, "%s%s%s", header, page, footer); + + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strncasecmp(url, "/msgs/", 6) == 0) { con_inf->user = www_auth_ok(connection, url_); - + if (con_inf->user == NULL) { www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; - } + return MHD_YES; + } conference = -1; area = -1; msg = -1; url_copy = strdup(&url[6]); - + aptr = strtok(url_copy, "/"); if (aptr != NULL) { conference = strtol(aptr, &endptr, 10); @@ -822,16 +821,16 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url msg = strtol(aptr, &endptr, 10); if (endptr == aptr) { msg = -1; - } + } } } } free(url_copy); - - val = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "skip"); - + + val = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "skip"); + if (val != NULL) { - skip = atoi(val); + skip = atoi(val); } else { skip = 0; } @@ -841,20 +840,19 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url } else if (conference != -1 && area != -1 && msg != -1) { page = www_msgs_messageview(con_inf->user, conference, area, msg); } - - + if (page == NULL) { if (www_403(header, footer, connection) != 0) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } free(header); free(footer); - return MHD_YES; + return MHD_YES; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strncasecmp(url, "/static/", 8) == 0) { // sanatize path @@ -866,9 +864,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url mime = NULL; // get mimetype - for (i=strlen(url);i>0;--i) { + for (i = strlen(url); i > 0; --i) { if (url[i] == '.') { - mime = www_get_mime_type(&url[i+1]); + mime = www_get_mime_type(&url[i + 1]); break; } if (url[i] == '/') { @@ -881,9 +879,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url mime = www_get_mime_type(NULL); } - // load file - + sprintf(buffer, "%s%s", conf.www_path, url); if (stat(buffer, &s) == 0 && S_ISREG(s.st_mode)) { fno = open(buffer, O_RDONLY); @@ -894,32 +891,32 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url response = MHD_create_response_from_fd(s.st_size, fno); //response = MHD_create_response_from_buffer (s.st_size, (void*) static_buffer, MHD_RESPMEM_MUST_FREE); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime); - ret = MHD_queue_response (connection, MHD_HTTP_OK, response); - MHD_destroy_response (response); + ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_destroy_response(response); free(header); free(footer); - return ret; + return ret; } else { if (www_403(header, footer, connection) != 0) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } free(header); free(footer); - return MHD_YES; + return MHD_YES; } } else { if (www_404(header, footer, connection) != 0) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } free(header); free(footer); - return MHD_YES; + return MHD_YES; } - } else if (strcasecmp(url, "/files/areas/") == 0 || strcasecmp(url, "/files/areas") == 0) { + } else if (strcasecmp(url, "/files/areas/") == 0 || strcasecmp(url, "/files/areas") == 0) { page = www_files_areas(); whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); sprintf(whole_page, "%s%s%s", header, page, footer); @@ -928,7 +925,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url file_sub = -1; filen = NULL; url_copy = strdup(&url[13]); - + aptr = strtok(url_copy, "/"); if (aptr != NULL) { file_dir = strtol(aptr, &endptr, 10); @@ -943,7 +940,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url } aptr = strtok(NULL, "/"); if (aptr != NULL) { - filen = strdup(aptr); + filen = strdup(aptr); } } } @@ -964,9 +961,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (filename != NULL) { mime = NULL; // get mimetype - for (i=strlen(filename);i>0;--i) { + for (i = strlen(filename); i > 0; --i) { if (filename[i] == '.') { - mime = www_get_mime_type(&filename[i+1]); + mime = www_get_mime_type(&filename[i + 1]); break; } if (filename[i] == '/') { @@ -977,21 +974,20 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (mime = NULL) { mime = www_get_mime_type(NULL); - } + } if (stat(filename, &s) == 0 && S_ISREG(s.st_mode)) { fno = open(filename, O_RDONLY); if (fno != -1) { - response = MHD_create_response_from_fd(s.st_size, fno); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime); sprintf(buffer, "%ld", s.st_size); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_LENGTH, buffer); - + snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename)); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer); - ret = MHD_queue_response (connection, MHD_HTTP_OK, response); - MHD_destroy_response (response); + ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_destroy_response(response); free(header); free(footer); free(filename); @@ -1003,11 +999,11 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (www_404(header, footer, connection) != 0) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } free(header); free(footer); - return MHD_YES; + return MHD_YES; } else { free(filen); } @@ -1019,23 +1015,23 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (www_403(header, footer, connection) != 0) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } free(header); free(footer); - return MHD_YES; + return MHD_YES; } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - - sprintf(whole_page, "%s%s%s", header, page, footer); + + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strncasecmp(url, "/files/", 7) == 0) { filename = www_decode_hash(&url[7]); if (filename != NULL) { mime = NULL; // get mimetype - for (i=strlen(filename);i>0;--i) { + for (i = strlen(filename); i > 0; --i) { if (filename[i] == '.') { - mime = www_get_mime_type(&filename[i+1]); + mime = www_get_mime_type(&filename[i + 1]); break; } if (filename[i] == '/') { @@ -1047,20 +1043,20 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (mime = NULL) { mime = www_get_mime_type(NULL); } - + if (stat(filename, &s) == 0 && S_ISREG(s.st_mode)) { fno = open(filename, O_RDONLY); if (fno != -1) { - + response = MHD_create_response_from_fd(s.st_size, fno); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime); sprintf(buffer, "%ld", s.st_size); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_LENGTH, buffer); - + snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename)); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer); - ret = MHD_queue_response (connection, MHD_HTTP_OK, response); - MHD_destroy_response (response); + ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_destroy_response(response); free(header); free(footer); free(filename); @@ -1072,20 +1068,20 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (www_404(header, footer, connection) != 0) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } free(header); free(footer); - return MHD_YES; + return MHD_YES; } else { if (www_404(header, footer, connection) != 0) { free(header); free(footer); - return MHD_NO; + return MHD_NO; } free(header); free(footer); - return MHD_YES; + return MHD_YES; } } else if (strcmp(method, "POST") == 0) { if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) { @@ -1095,22 +1091,22 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; + } + if (con_inf->pp == NULL) { + con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void *)con_inf); } - if (con_inf->pp == NULL) { - con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void*) con_inf); - } if (*upload_data_size != 0) { - - MHD_post_process (con_inf->pp, upload_data, *upload_data_size); + + MHD_post_process(con_inf->pp, upload_data, *upload_data_size); *upload_data_size = 0; - + return MHD_YES; } subj = NULL; to = NULL; body = NULL; - for (i=0;icount;i++) { + for (i = 0; i < con_inf->count; i++) { if (strcmp(con_inf->keys[i], "recipient") == 0) { to = con_inf->values[i]; } else if (strcmp(con_inf->keys[i], "subject") == 0) { @@ -1123,7 +1119,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url page = (char *)malloc(50); if (page == NULL) { free(header); - free(footer); + free(footer); return MHD_NO; } sprintf(page, "

Error Sending Email (Check User Exists?)

"); @@ -1131,15 +1127,15 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url page = (char *)malloc(21); if (page == NULL) { free(header); - free(footer); + free(footer); return MHD_NO; } sprintf(page, "

Email Sent!

"); } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); - + } else if (strcasecmp(url, "/msgs/") == 0 || strcasecmp(url, "/msgs") == 0) { con_inf->user = www_auth_ok(connection, url_); @@ -1147,16 +1143,16 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url www_401(header, footer, connection); free(header); free(footer); - return MHD_YES; + return MHD_YES; } - if (con_inf->pp == NULL) { - con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void*) con_inf); + if (con_inf->pp == NULL) { + con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void *)con_inf); } - + if (*upload_data_size != 0) { - MHD_post_process (con_inf->pp, upload_data, *upload_data_size); + MHD_post_process(con_inf->pp, upload_data, *upload_data_size); *upload_data_size = 0; - + return MHD_YES; } subj = NULL; @@ -1165,8 +1161,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url replyid = NULL; conference = -1; area = -1; - - for (i=0;icount;i++) { + + for (i = 0; i < con_inf->count; i++) { if (strcmp(con_inf->keys[i], "recipient") == 0) { to = con_inf->values[i]; } else if (strcmp(con_inf->keys[i], "subject") == 0) { @@ -1192,7 +1188,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url page = (char *)malloc(31); if (page == NULL) { free(header); - free(footer); + free(footer); return MHD_NO; } sprintf(page, "

Error Sending Message

"); @@ -1200,32 +1196,31 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url page = (char *)malloc(23); if (page == NULL) { free(header); - free(footer); + free(footer); return MHD_NO; } sprintf(page, "

Message Sent!

"); } whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); - + sprintf(whole_page, "%s%s%s", header, page, footer); - - + } else { free(header); - free(footer); + free(footer); return MHD_NO; } } else { free(header); - free(footer); - return MHD_NO; + free(footer); + return MHD_NO; } - response = MHD_create_response_from_buffer (strlen (whole_page), (void*) whole_page, MHD_RESPMEM_MUST_FREE); - + response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE); + MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html"); - - ret = MHD_queue_response (connection, MHD_HTTP_OK, response); - MHD_destroy_response (response); + + ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_destroy_response(response); free(page); free(header); free(footer); diff --git a/src/www_blog.c b/src/www_blog.c index 43b2ac1..8342570 100644 --- a/src/www_blog.c +++ b/src/www_blog.c @@ -5,7 +5,6 @@ #include #include "bbs.h" - extern struct bbs_config conf; char *www_blog() { @@ -14,20 +13,20 @@ char *www_blog() { int len; char buffer[4096]; - struct blog_entry_t **blog_entries; - int blog_entry_count = 0; - int i, j; - struct tm thetime; - int hour; - - char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; - char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; + struct blog_entry_t **blog_entries; + int blog_entry_count = 0; + int i, j; + struct tm thetime; + int hour; + + char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; + char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; page = (char *)malloc(4096); max_len = 4096; len = 0; memset(page, 0, 4096); - + sprintf(buffer, "

System Blog

\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -36,85 +35,85 @@ char *www_blog() { strcat(page, buffer); len += strlen(buffer); - blog_entry_count = blog_load(&blog_entries); + blog_entry_count = blog_load(&blog_entries); - if (blog_entry_count == 0) { - sprintf(buffer, "

No Entries

\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - } else { - for (i=0;idate, &thetime); - if (thetime.tm_hour >= 12) { - hour = thetime.tm_hour - 12; - } else { - hour = thetime.tm_hour; - } - sprintf(buffer, "

%s

%d:%02d%s %s, %s %d %d
by %s
", blog_entries[i]->subject,(hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900, blog_entries[i]->author); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + if (blog_entry_count == 0) { + sprintf(buffer, "

No Entries

\n"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + } else { + for (i = 0; i < blog_entry_count; i++) { + localtime_r(&blog_entries[i]->date, &thetime); + if (thetime.tm_hour >= 12) { + hour = thetime.tm_hour - 12; + } else { + hour = thetime.tm_hour; + } + sprintf(buffer, "

%s

%d:%02d%s %s, %s %d %d
by %s
", blog_entries[i]->subject, (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900, blog_entries[i]->author); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); - sprintf(buffer, "

"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + sprintf(buffer, "

"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); - for (j=0;jbody);j++) { - if (blog_entries[i]->body[j] == '\r') { - if (blog_entries[i]->body[j+1] == '\r') { - sprintf(buffer, "

"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - } else { - if (len + 1 > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - page[len++] = ' '; - page[len] = '\0'; - } - } else { - if (len + 1 > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - page[len++] = blog_entries[i]->body[j]; - page[len] = '\0'; - } - } - sprintf(buffer, "

"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - } + for (j = 0; j < strlen(blog_entries[i]->body); j++) { + if (blog_entries[i]->body[j] == '\r') { + if (blog_entries[i]->body[j + 1] == '\r') { + sprintf(buffer, "

"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + } else { + if (len + 1 > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + page[len++] = ' '; + page[len] = '\0'; + } + } else { + if (len + 1 > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + page[len++] = blog_entries[i]->body[j]; + page[len] = '\0'; + } + } + sprintf(buffer, "

"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + } + + for (i = 0; i < blog_entry_count; i++) { + free(blog_entries[i]->subject); + free(blog_entries[i]->author); + free(blog_entries[i]->body); + free(blog_entries[i]); + } + free(blog_entries); + } - for (i=0;isubject); - free(blog_entries[i]->author); - free(blog_entries[i]->body); - free(blog_entries[i]); - } - free(blog_entries); - } - return page; } diff --git a/src/www_email.c b/src/www_email.c index b64783f..c6dbf98 100644 --- a/src/www_email.c +++ b/src/www_email.c @@ -7,7 +7,6 @@ #include #include "bbs.h" - extern struct bbs_config conf; int www_email_delete(struct user_record *user, int id) { @@ -15,17 +14,17 @@ int www_email_delete(struct user_record *user, int id) { sqlite3 *db; sqlite3_stmt *res; int rc; - char *csql = "CREATE TABLE IF NOT EXISTS email (" - "id INTEGER PRIMARY KEY," - "sender TEXT COLLATE NOCASE," - "recipient TEXT COLLATE NOCASE," - "subject TEXT," - "body TEXT," - "date INTEGER," - "seen INTEGER);"; + char *csql = "CREATE TABLE IF NOT EXISTS email (" + "id INTEGER PRIMARY KEY," + "sender TEXT COLLATE NOCASE," + "recipient TEXT COLLATE NOCASE," + "subject TEXT," + "body TEXT," + "date INTEGER," + "seen INTEGER);"; char *dsql = "DELETE FROM email WHERE id=? AND recipient LIKE ?"; char *err_msg = 0; - + sprintf(buffer, "%s/email.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); @@ -36,7 +35,7 @@ int www_email_delete(struct user_record *user, int id) { } sqlite3_busy_timeout(db, 5000); rc = sqlite3_exec(db, csql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { + if (rc != SQLITE_OK) { sqlite3_free(err_msg); sqlite3_close(db); @@ -65,21 +64,21 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha sqlite3 *db; sqlite3_stmt *res; int rc; - char *csql = "CREATE TABLE IF NOT EXISTS email (" - "id INTEGER PRIMARY KEY," - "sender TEXT COLLATE NOCASE," - "recipient TEXT COLLATE NOCASE," - "subject TEXT," - "body TEXT," - "date INTEGER," - "seen INTEGER);"; + char *csql = "CREATE TABLE IF NOT EXISTS email (" + "id INTEGER PRIMARY KEY," + "sender TEXT COLLATE NOCASE," + "recipient TEXT COLLATE NOCASE," + "subject TEXT," + "body TEXT," + "date INTEGER," + "seen INTEGER);"; char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; char *err_msg = 0; char *body; struct utsname name; int i; int pos; - + if (recipient == NULL || subject == NULL || ibody == NULL) { return 0; } @@ -87,25 +86,23 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha if (check_user(recipient)) { return 0; } - - uname(&name); - + snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, conf.default_tagline); - + body = (char *)malloc(strlen(ibody) + strlen(buffer) + 1); memset(body, 0, strlen(ibody) + strlen(buffer) + 1); pos = 0; - for (i = 0;i max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -177,7 +172,7 @@ char *www_new_email() { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -185,7 +180,7 @@ char *www_new_email() { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -193,7 +188,7 @@ char *www_new_email() { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -201,20 +196,19 @@ char *www_new_email() { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - sprintf(buffer, "\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - - return page; + + return page; } char *www_email_display(struct user_record *user, int email) { @@ -235,17 +229,17 @@ char *www_email_display(struct user_record *user, int email) { int chars; char *err_msg = 0; char *email_create_sql = "CREATE TABLE IF NOT EXISTS email (" - "id INTEGER PRIMARY KEY," - "sender TEXT COLLATE NOCASE," - "recipient TEXT COLLATE NOCASE," - "subject TEXT," - "body TEXT," - "date INTEGER," - "seen INTEGER);"; + "id INTEGER PRIMARY KEY," + "sender TEXT COLLATE NOCASE," + "recipient TEXT COLLATE NOCASE," + "subject TEXT," + "body TEXT," + "date INTEGER," + "seen INTEGER);"; char *email_show_sql = "SELECT id,sender,subject,body,date FROM email WHERE recipient LIKE ? LIMIT ?, 1"; - + char *update_seen_sql = "UPDATE email SET seen=1 WHERE id=?"; - + page = (char *)malloc(4096); max_len = 4096; len = 0; @@ -257,11 +251,11 @@ char *www_email_display(struct user_record *user, int email) { if (rc != SQLITE_OK) { sqlite3_close(db); free(page); - return NULL; + return NULL; } sqlite3_busy_timeout(db, 5000); rc = sqlite3_exec(db, email_create_sql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { + if (rc != SQLITE_OK) { sqlite3_free(err_msg); sqlite3_close(db); @@ -277,16 +271,16 @@ char *www_email_display(struct user_record *user, int email) { sqlite3_finalize(res); sqlite3_close(db); free(page); - return NULL; + return NULL; } - if (sqlite3_step(res) == SQLITE_ROW) { - id = sqlite3_column_int(res, 0); + if (sqlite3_step(res) == SQLITE_ROW) { + id = sqlite3_column_int(res, 0); from = strdup((char *)sqlite3_column_text(res, 1)); subject = strdup((char *)sqlite3_column_text(res, 2)); body = strdup((char *)sqlite3_column_text(res, 3)); date = (time_t)sqlite3_column_int(res, 4); localtime_r(&date, &msg_date); - + sprintf(buffer, "

Your Email

\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -299,26 +293,26 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - + sprintf(buffer, "
%s
\n", subject); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - + sprintf(buffer, "
From: %s
\n", from); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - + if (conf.date_style == 1) { sprintf(buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { @@ -327,26 +321,26 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - + sprintf(buffer, "\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); sprintf(buffer, "
\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - for (i=0;i"); } else if (body[i] == '<') { @@ -359,7 +353,7 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); } @@ -367,7 +361,7 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -375,7 +369,7 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); sprintf(buffer, "

Reply

\n"); @@ -385,12 +379,12 @@ char *www_email_display(struct user_record *user, int email) { } strcat(page, buffer); len += strlen(buffer); - + sprintf(buffer, "
\n", conf.www_url); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -398,7 +392,7 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -410,7 +404,7 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -418,7 +412,7 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -426,7 +420,7 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -434,13 +428,13 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); chars = 0; - - for (i=0;i "); chars = 0; @@ -449,21 +443,21 @@ char *www_email_display(struct user_record *user, int email) { chars = 1; } else { sprintf(buffer, "%c", body[i]); - chars ++; + chars++; } if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); } - + sprintf(buffer, "\n
"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -471,16 +465,15 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - sprintf(buffer, "\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -488,16 +481,16 @@ char *www_email_display(struct user_record *user, int email) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - + free(from); free(body); free(subject); - + sqlite3_finalize(res); - + rc = sqlite3_prepare_v2(db, update_seen_sql, -1, &res, 0); if (rc == SQLITE_OK) { @@ -506,9 +499,9 @@ char *www_email_display(struct user_record *user, int email) { sqlite3_finalize(res); sqlite3_close(db); free(page); - return NULL; + return NULL; } - + sqlite3_step(res); } else { sprintf(buffer, "

No Such Email

\n"); @@ -516,8 +509,8 @@ char *www_email_display(struct user_record *user, int email) { max_len += 4096; page = (char *)realloc(page, max_len); } - strcat(page, buffer); - len += strlen(buffer); + strcat(page, buffer); + len += strlen(buffer); } sqlite3_finalize(res); @@ -544,15 +537,14 @@ char *www_email_summary(struct user_record *user) { int msgid = 0; char *err_msg = 0; char *email_create_sql = "CREATE TABLE IF NOT EXISTS email (" - "id INTEGER PRIMARY KEY," - "sender TEXT COLLATE NOCASE," - "recipient TEXT COLLATE NOCASE," - "subject TEXT," - "body TEXT," - "date INTEGER," - "seen INTEGER);"; - - + "id INTEGER PRIMARY KEY," + "sender TEXT COLLATE NOCASE," + "recipient TEXT COLLATE NOCASE," + "subject TEXT," + "body TEXT," + "date INTEGER," + "seen INTEGER);"; + page = (char *)malloc(4096); max_len = 4096; len = 0; @@ -565,7 +557,7 @@ char *www_email_summary(struct user_record *user) { } strcat(page, buffer); len += strlen(buffer); - + sprintf(buffer, "\n", conf.www_url); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -573,18 +565,18 @@ char *www_email_summary(struct user_record *user) { } strcat(page, buffer); len += strlen(buffer); - + sprintf(buffer, "%s/email.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { sqlite3_close(db); free(page); - return NULL; + return NULL; } -sqlite3_busy_timeout(db, 5000); + sqlite3_busy_timeout(db, 5000); rc = sqlite3_exec(db, email_create_sql, 0, 0, &err_msg); - if (rc != SQLITE_OK ) { + if (rc != SQLITE_OK) { sqlite3_free(err_msg); sqlite3_close(db); @@ -599,9 +591,9 @@ sqlite3_busy_timeout(db, 5000); sqlite3_finalize(res); sqlite3_close(db); free(page); - return NULL; + return NULL; } - + sprintf(buffer, "
\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -609,7 +601,7 @@ sqlite3_busy_timeout(db, 5000); } strcat(page, buffer); len += strlen(buffer); - + while (sqlite3_step(res) == SQLITE_ROW) { id = sqlite3_column_int(res, 0); from = strdup((char *)sqlite3_column_text(res, 1)); @@ -642,11 +634,10 @@ sqlite3_busy_timeout(db, 5000); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } strcat(page, buffer); len += strlen(buffer); - + sqlite3_finalize(res); sqlite3_close(db); return page; diff --git a/src/www_files.c b/src/www_files.c index 3fbee22..bd4228c 100644 --- a/src/www_files.c +++ b/src/www_files.c @@ -7,349 +7,348 @@ #include "bbs.h" #include "../deps/hashids/hashids.h" - extern struct bbs_config conf; extern struct user_record *gUser; -extern char * aha(char *input); +extern char *aha(char *input); static char *www_decode(char *clean_url) { - char *url = (char *)malloc(strlen(clean_url) + 1); - int i; - int j = 0; - unsigned char c; - if (clean_url == NULL) { - free(url); - return NULL; - } + char *url = (char *)malloc(strlen(clean_url) + 1); + int i; + int j = 0; + unsigned char c; + if (clean_url == NULL) { + free(url); + return NULL; + } - for (i=0;i= conf.file_directory_count || sub >= conf.file_directories[dir]->file_sub_count) { - return NULL; - } + if (dir >= conf.file_directory_count || sub >= conf.file_directories[dir]->file_sub_count) { + return NULL; + } - // get filename from database - snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); + // get filename from database + snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - return NULL; - } - sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc != SQLITE_OK) { - sqlite3_close(db); return NULL; - } - sqlite3_bind_int(res, 1, fid); - if (sqlite3_step(res) == SQLITE_ROW) { - ret = strdup(sqlite3_column_text(res, 0)); - sqlite3_finalize(res); - sqlite3_close(db); + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + return NULL; + } + sqlite3_bind_int(res, 1, fid); + if (sqlite3_step(res) == SQLITE_ROW) { + ret = strdup(sqlite3_column_text(res, 0)); + sqlite3_finalize(res); + sqlite3_close(db); - return ret; - } + return ret; + } sqlite3_finalize(res); sqlite3_close(db); - return NULL; + return NULL; } char *www_create_link(int dir, int sub, int fid) { - char url[PATH_MAX]; - char *ret; - char *hashid; - int sizereq; - time_t expiry; + char url[PATH_MAX]; + char *ret; + char *hashid; + int sizereq; + time_t expiry; - hashids_t *hashids = hashids_init(conf.bbs_name); + hashids_t *hashids = hashids_init(conf.bbs_name); - sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid); + sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid); - hashid = (char *)malloc(sizereq + 1); + hashid = (char *)malloc(sizereq + 1); - memset(hashid, 0, sizereq + 1); + memset(hashid, 0, sizereq + 1); - if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) { - hashids_free(hashids); - free(hashid); - return NULL; - } + if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) { + hashids_free(hashids); + free(hashid); + return NULL; + } - hashids_free(hashids); + hashids_free(hashids); - snprintf(url, PATH_MAX, "%sfiles/%s", conf.www_url, hashid); + snprintf(url, PATH_MAX, "%sfiles/%s", conf.www_url, hashid); - // add link into hash database - expiry = time(NULL) + 86400; - www_add_hash_to_db(hashid, expiry); + // add link into hash database + expiry = time(NULL) + 86400; + www_add_hash_to_db(hashid, expiry); - free(hashid); + free(hashid); - ret = strdup(url); + ret = strdup(url); - return ret; + return ret; } char *www_files_display_listing(int dir, int sub) { - char *page; - int max_len; - int len; - char buffer[4096]; + char *page; + int max_len; + int len; + char buffer[4096]; char *sql = "select id, filename, description, size, dlcount, uploaddate from files where approved=1 ORDER BY filename"; - char *filename; - char c; - int size; - char *aha_out; - char *description; + char *filename; + char c; + int size; + char *aha_out; + char *description; sqlite3 *db; - sqlite3_stmt *res; - int rc; - int i; - char *clean_url; + sqlite3_stmt *res; + int rc; + int i; + char *clean_url; - page = (char *)malloc(4096); + page = (char *)malloc(4096); max_len = 4096; len = 0; memset(page, 0, 4096); - + snprintf(buffer, 4096, "

Files: %s - %s

\n", conf.file_directories[dir]->name, conf.file_directories[dir]->file_subs[sub]->name); - if (len + strlen(buffer) > max_len - 1) { + if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); - + len += strlen(buffer); + snprintf(buffer, 4096, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - free(page); - return NULL; - } - sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc != SQLITE_OK) { - sqlite3_close(db); - free(page); + free(page); return NULL; - } + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + free(page); + return NULL; + } snprintf(buffer, 4096, "\n"); - if (len + strlen(buffer) > max_len - 1) { + if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); - + len += strlen(buffer); + while (sqlite3_step(res) == SQLITE_ROW) { - filename = strdup(sqlite3_column_text(res, 1)); - clean_url = www_encode(basename(filename)); - snprintf(buffer, 4096, "", conf.www_url, dir, sub, basename(clean_url), basename(filename)); - free(clean_url); - free(filename); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + filename = strdup(sqlite3_column_text(res, 1)); + clean_url = www_encode(basename(filename)); + snprintf(buffer, 4096, "", conf.www_url, dir, sub, basename(clean_url), basename(filename)); + free(clean_url); + free(filename); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); - size = sqlite3_column_int(res, 3); + size = sqlite3_column_int(res, 3); - if (size > 1024 * 1024 * 1024) { + if (size > 1024 * 1024 * 1024) { size = size / 1024 / 1024 / 1024; c = 'G'; } else if (size > 1024 * 1024) { @@ -362,190 +361,188 @@ char *www_files_display_listing(int dir, int sub) { c = 'b'; } - snprintf(buffer, 4096, "", size, c); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + snprintf(buffer, 4096, "", size, c); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); - description = strdup((char *)sqlite3_column_text(res, 2)); + description = strdup((char *)sqlite3_column_text(res, 2)); - for (i=0;i"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + snprintf(buffer, 4096, "\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - + snprintf(buffer, 4096, "\n"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); } - snprintf(buffer, 4096, "
FilenameSizeDescription
%s
%s%d%c%d%c"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); aha_out = aha(description); while (len + strlen(aha_out) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, aha_out); - len += strlen(aha_out); - + len += strlen(aha_out); + free(aha_out); free(description); - snprintf(buffer, 4096, "
\n"); - if (len + strlen(buffer) > max_len - 1) { + snprintf(buffer, 4096, "\n"); + if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); sqlite3_finalize(res); sqlite3_close(db); - return page; + return page; } char *www_files_areas() { - char *page; - int max_len; - int len; - char buffer[4096]; - int i; - int j; + char *page; + int max_len; + int len; + char buffer[4096]; + int i; + int j; - page = (char *)malloc(4096); + page = (char *)malloc(4096); max_len = 4096; len = 0; memset(page, 0, 4096); - + sprintf(buffer, "

File Directories

\n"); - if (len + strlen(buffer) > max_len - 1) { + if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); - for (i=0;idisplay_on_web) { - sprintf(buffer, "
%s
\n", conf.file_directories[i]->name); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - for (j=0;jfile_sub_count;j++) { - sprintf(buffer, "\n", conf.www_url, i, j, conf.file_directories[i]->file_subs[j]->name); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - } - } - } + for (i = 0; i < conf.file_directory_count; i++) { + if (conf.file_directories[i]->display_on_web) { + sprintf(buffer, "
%s
\n", conf.file_directories[i]->name); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + for (j = 0; j < conf.file_directories[i]->file_sub_count; j++) { + sprintf(buffer, "\n", conf.www_url, i, j, conf.file_directories[i]->file_subs[j]->name); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + } + } + } - return page; + return page; } char *www_files_get_from_area(int dir, int sub, char *clean_file) { - char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\""; - char *filenamelike; + char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\""; + char *filenamelike; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char buffer[PATH_MAX]; - char *ret = NULL; - int i; - int extra = 0; - int j; - char *file; + sqlite3_stmt *res; + int rc; + char buffer[PATH_MAX]; + char *ret = NULL; + int i; + int extra = 0; + int j; + char *file; - file = www_decode(clean_file); + file = www_decode(clean_file); - for (i=0;ifile_subs[sub]->database); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - return NULL; - } + return NULL; + } sqlite3_busy_timeout(db, 5000); - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc != SQLITE_OK) { + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + if (rc != SQLITE_OK) { sqlite3_close(db); return NULL; - } - sqlite3_bind_text(res, 1, filenamelike, -1, 0); + } + sqlite3_bind_text(res, 1, filenamelike, -1, 0); - rc = sqlite3_step(res); - if (rc == SQLITE_ROW) { - ret = strdup(sqlite3_column_text(res, 0)); + rc = sqlite3_step(res); + if (rc == SQLITE_ROW) { + ret = strdup(sqlite3_column_text(res, 0)); + } - } - - free(filenamelike); - sqlite3_finalize(res); - sqlite3_close(db); - return ret; + free(filenamelike); + sqlite3_finalize(res); + sqlite3_close(db); + return ret; } #endif diff --git a/src/www_last10.c b/src/www_last10.c index 62bac31..dccfd3a 100644 --- a/src/www_last10.c +++ b/src/www_last10.c @@ -5,7 +5,6 @@ #include #include "bbs.h" - extern struct bbs_config conf; char *www_last10() { @@ -15,13 +14,13 @@ char *www_last10() { char buffer[4096]; struct last10_callers callers[10]; - int i,z; + int i, z; struct tm l10_time; FILE *fptr = fopen("last10v2.dat", "rb"); if (fptr != NULL) { - for (i=0;i<10;i++) { + for (i = 0; i < 10; i++) { if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) { break; } @@ -36,7 +35,7 @@ char *www_last10() { max_len = 4096; len = 0; memset(page, 0, 4096); - + sprintf(buffer, "

Last 10 Callers

\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -52,8 +51,8 @@ char *www_last10() { } strcat(page, buffer); len += strlen(buffer); - - for (z=0;z\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -83,7 +82,7 @@ char *www_last10() { } strcat(page, buffer); len += strlen(buffer); - + return page; } diff --git a/src/www_msgs.c b/src/www_msgs.c index 91873fd..64e0f58 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -12,16 +12,15 @@ #define IN 0 #define OUT 1 -extern char * aha(char *input); +extern char *aha(char *input); extern struct bbs_config conf; - static char *www_wordwrap(char *content, int cutoff); char *www_sanitize(char *inp) { int i; char *result; int len = 0; - for (i=0;i')) { len += 4; } else if (inp[i] == '&') { @@ -34,8 +33,8 @@ char *www_sanitize(char *inp) { result = (char *)malloc(len + 1); memset(result, 0, len + 1); len = 0; - for (i=0;isec_level <= user->sec_level) { sprintf(buffer, "
%s
\n", conf.mail_conferences[i]->name); if (len + strlen(buffer) > max_len - 1) { @@ -89,9 +88,9 @@ char *www_msgs_arealist(struct user_record *user) { strcat(page, buffer); len += strlen(buffer); - for (j=0;jmail_area_count; j++) { + for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level <= user->sec_level) { - + if (new_messages(user, i, j) > 0) { sprintf(buffer, "\n", conf.www_url, i, j, conf.mail_conferences[i]->mail_areas[j]->name); } else { @@ -134,7 +133,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i max_len = 4096; len = 0; memset(page, 0, 4096); - + sprintf(buffer, "

%s - %s

\n", conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -142,7 +141,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i } strcat(page, buffer); len += strlen(buffer); - + if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { sprintf(buffer, "\n", conf.www_url, conference, area); if (len + strlen(buffer) > max_len - 1) { @@ -150,10 +149,10 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); } mhrs = read_message_headers(conference, area, user, 0); - + if (mhrs == NULL) { sprintf(buffer, "

No Messages

\n"); if (len + strlen(buffer) > max_len - 1) { @@ -164,14 +163,14 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i len += strlen(buffer); return page; } - + sprintf(buffer, "
\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); if (!jb) { @@ -190,8 +189,8 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i if (skip_t < 0) { skip_t = 0; } - - for (i=skip_f -1; i>=skip_t;i--) { + + for (i = skip_f - 1; i >= skip_t; i--) { date = (time_t)mhrs->msgs[i]->msg_h->DateWritten; gmtime_r(&date, &msg_date); to = www_sanitize(mhrs->msgs[i]->to); @@ -226,7 +225,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); } sprintf(buffer, "
\n"); if (len + strlen(buffer) > max_len - 1) { @@ -234,7 +233,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); if (skip + 50 <= mhrs->msg_count) { sprintf(buffer, "\n", conf.www_url, conference, area, skip + 50); if (len + strlen(buffer) > max_len - 1) { @@ -256,21 +255,21 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i page = (char *)realloc(page, max_len); } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); } - + free_message_headers(mhrs); - return page; + return page; } char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) { s_JamBase *jb; s_JamMsgHeader jmh; - s_JamSubPacket* jsp; + s_JamSubPacket *jsp; s_JamSubfield jsf; s_JamLastRead jlr; s_JamBaseHeader jbh; - + char *subject = NULL; char *from = NULL; char *to = NULL; @@ -287,7 +286,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i char *page; int max_len; int len; - char buffer[4096]; + char buffer[4096]; int chars; int i; char *from_s; @@ -302,15 +301,15 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { return NULL; } - + if (conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level) { jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); - if (!jb) { + if (!jb) { return NULL; } - + JAM_ReadMBHeader(jb, &jbh); - + memset(&jmh, 0, sizeof(s_JamMsgHeader)); z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp); if (z != 0) { @@ -323,9 +322,9 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i JAM_CloseMB(jb); free(jb); return NULL; - } - - for (z=0;zNumFields;z++) { + } + + for (z = 0; z < jsp->NumFields; z++) { if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { subject = (char *)malloc(jsp->Fields[z]->DatLen + 1); memset(subject, 0, jsp->Fields[z]->DatLen + 1); @@ -362,8 +361,8 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i memcpy(replyid, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); } } - JAM_DelSubPacket(jsp); - + JAM_DelSubPacket(jsp); + if (subject == NULL) { subject = strdup("(No Subject)"); } @@ -375,12 +374,12 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (to == NULL) { to = strdup("(No Recipient)"); } - + if (jmh.Attribute & JAM_MSG_PRIVATE) { if (!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && - !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && - !msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) && - !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) { + !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && + !msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) && + !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) { if (subject != NULL) { free(subject); @@ -411,7 +410,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i body = (char *)malloc(jmh.TxtLen + 1); memset(body, 0, jmh.TxtLen + 1); - JAM_ReadMsgText(jb, jmh.TxtOffset,jmh.TxtLen, (char *)body); + JAM_ReadMsgText(jb, jmh.TxtOffset, jmh.TxtLen, (char *)body); if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { jlr.UserCRC = JAM_Crc32(user->loginname, strlen(user->loginname)); @@ -422,17 +421,17 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i jlr.LastReadMsg = msg; if (jlr.HighReadMsg < msg) { jlr.HighReadMsg = msg; - } + } JAM_WriteLastRead(jb, user->id, &jlr); JAM_CloseMB(jb); free(jb); - + page = (char *)malloc(4096); max_len = 4096; len = 0; memset(page, 0, 4096); - + sprintf(buffer, "\n", conf.www_url, conference, area, conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -440,7 +439,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i } strcat(page, buffer); len += strlen(buffer); - + if (msgbase_is_flagged(user, conference, area, msg)) { sprintf(buffer, "
\n"); } else { @@ -449,7 +448,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); subject_s = www_sanitize(subject); @@ -457,14 +456,14 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } free(subject_s); strcat(page, buffer); len += strlen(buffer); from_s = www_sanitize(from); if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) { - + if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { sprintf(buffer, "
From: %s (@%s)
\n", from_s, oaddress); } else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { @@ -492,7 +491,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); to_s = www_sanitize(to); @@ -500,11 +499,11 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } free(to_s); strcat(page, buffer); len += strlen(buffer); - + date = (time_t)jmh.DateWritten; gmtime_r(&date, &msg_date); if (conf.date_style == 1) { @@ -512,11 +511,11 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i } else { sprintf(buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - + if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -524,26 +523,25 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - + sprintf(buffer, "
\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); sprintf(buffer, "
\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - - + aha_text = (char *)malloc(jmh.TxtLen + 1); memcpy(aha_text, body, jmh.TxtLen); @@ -552,28 +550,26 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i while (len + strlen(aha_out) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, aha_out); - len += strlen(aha_out); - + len += strlen(aha_out); + free(aha_out); free(aha_text); - + sprintf(buffer, "
\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - - - sprintf(buffer, "
\n"); + sprintf(buffer, "
\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { @@ -588,7 +584,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -596,22 +592,22 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); sprintf(buffer, "\n", area); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); sprintf(buffer, "\n", msgid); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -619,7 +615,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -631,7 +627,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -639,7 +635,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -647,20 +643,20 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); replybody = (char *)malloc(strlen(body) + 1); l2 = 0; - for (l1=0;l1 ", from[0]); chars = 0; @@ -683,39 +679,37 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i chars = 1; } else { sprintf(buffer, "%c", body2[i]); - chars ++; + chars++; } if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); } free(body2); sprintf(buffer, "\n
"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - sprintf(buffer, "\n
"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - sprintf(buffer, "\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -723,7 +717,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); } @@ -747,7 +741,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i } if (replyid != NULL) { free(replyid); - } + } return page; } else { return NULL; @@ -765,10 +759,10 @@ static char *www_wordwrap(char *content, int cutoff) { int quote_line = 0; int z; - for (i=0;i' && line_count < 4) { quote_line = 1; } - if (content[i] == '\r' && content[i+1] != '\r') { - if (content[i+1] == ' ' && quote_line != 1) { + if (content[i] == '\r' && content[i + 1] != '\r') { + if (content[i + 1] == ' ' && quote_line != 1) { content[at++] = '\r'; line_count = 0; quote_line = 0; } else if (quote_line != 1) { - for (z = i+1;content[z] != ' ' && z < len;z++); - if (at > 0 && content[at-1] != '\r' && content[at-1] != ' ' && cutoff - line_count < z - i) { + for (z = i + 1; content[z] != ' ' && z < len; z++) + ; + if (at > 0 && content[at - 1] != '\r' && content[at - 1] != ' ' && cutoff - line_count < z - i) { content[at++] = ' '; line_count++; } else { content[at++] = '\r'; line_count = 0; - quote_line = 0; + quote_line = 0; } } else if (quote_line == 1) { content[at++] = '\r'; line_count = 0; - quote_line = 0; + quote_line = 0; } - } else if (content[i] == '\r' && content[i+1] == '\r') { + } else if (content[i] == '\r' && content[i + 1] == '\r') { content[at++] = '\r'; content[at++] = '\r'; line_count = 0; @@ -815,7 +810,6 @@ static char *www_wordwrap(char *content, int cutoff) { content[at++] = content[i]; content[at] = '\0'; - at = 0; len = strlen(content); @@ -823,11 +817,11 @@ static char *www_wordwrap(char *content, int cutoff) { if (ret == NULL) { return NULL; } - + line_count = 0; quote_line = 0; - for (i=0;irealnames == 0) { strcpy(buffer, user->loginname); } else { @@ -929,60 +923,60 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, } jsp = JAM_NewSubPacket(); - jsf.LoID = JAMSFLD_SENDERNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_SENDERNAME; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - jsf.LoID = JAMSFLD_RECVRNAME; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_RECVRNAME; + jsf.HiID = 0; jsf.DatLen = strlen(to); jsf.Buffer = (char *)to; JAM_PutSubfield(jsp, &jsf); - jsf.LoID = JAMSFLD_SUBJECT; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_SUBJECT; + jsf.HiID = 0; jsf.DatLen = strlen(subj); jsf.Buffer = (char *)subj; JAM_PutSubfield(jsp, &jsf); - + if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) { jmh.Attribute |= JAM_MSG_TYPEECHO; if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[conference]->fidoaddr->point) { sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node, - conf.mail_conferences[conference]->fidoaddr->point); + conf.mail_conferences[conference]->fidoaddr->net, + conf.mail_conferences[conference]->fidoaddr->node, + conf.mail_conferences[conference]->fidoaddr->point); } else { sprintf(buffer, "%d:%d/%d", conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node); + conf.mail_conferences[conference]->fidoaddr->net, + conf.mail_conferences[conference]->fidoaddr->node); } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node, - conf.mail_conferences[conference]->fidoaddr->point, - generate_msgid()); + conf.mail_conferences[conference]->fidoaddr->net, + conf.mail_conferences[conference]->fidoaddr->node, + conf.mail_conferences[conference]->fidoaddr->point, + generate_msgid()); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - + if (strcasecmp(replyid, "NULL") != 0) { - jsf.LoID = JAMSFLD_REPLYID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_REPLYID; + jsf.HiID = 0; jsf.DatLen = strlen(replyid); jsf.Buffer = (char *)replyid; JAM_PutSubfield(jsp, &jsf); @@ -990,8 +984,8 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, } } else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { sprintf(buffer, "%d", conf.mail_conferences[conference]->maginode); - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); @@ -999,16 +993,16 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, uuid_generate(magi_msgid); uuid_unparse_lower(magi_msgid, buffer); - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; jsf.DatLen = strlen(buffer); jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - + if (strcasecmp(replyid, "NULL") != 0) { - jsf.LoID = JAMSFLD_REPLYID; - jsf.HiID = 0; + jsf.LoID = JAMSFLD_REPLYID; + jsf.HiID = 0; jsf.DatLen = strlen(replyid); jsf.Buffer = (char *)replyid; JAM_PutSubfield(jsp, &jsf); @@ -1033,27 +1027,25 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, free(jb); return 0; } - - if (conf.mail_conferences[conference]->tagline != NULL) { tagline = conf.mail_conferences[conference]->tagline; } else { tagline = conf.default_tagline; - } - + } + uname(&name); if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[conference]->fidoaddr->point == 0) { snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node); + conf.mail_conferences[conference]->fidoaddr->net, + conf.mail_conferences[conference]->fidoaddr->node); } else { snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node, - conf.mail_conferences[conference]->fidoaddr->point); + conf.mail_conferences[conference]->fidoaddr->net, + conf.mail_conferences[conference]->fidoaddr->node, + conf.mail_conferences[conference]->fidoaddr->point); } } else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->maginode); @@ -1068,7 +1060,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, free(jb); return 0; } - body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer)); + body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer)); if (body3 == NULL) { free(body2); JAM_UnlockMB(jb); @@ -1077,7 +1069,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, free(jb); return 0; } - memset(body3, 0, strlen(body2) + 2 + strlen(buffer)); pos = 0; @@ -1087,7 +1078,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, body2 = (char *)malloc(strlen(body3) + 1); ic = iconv_open("CP437", "UTF-8"); - + inc = strlen(body3); ouc = strlen(body3); @@ -1097,7 +1088,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, free(body3); if (JAM_AddMessage(jb, &jmh, jsp, (char *)body2, oubuf - body2)) { - free(body2); + free(body2); JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); @@ -1113,13 +1104,12 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, } } - free(body2); JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); + JAM_CloseMB(jb); free(jb); iconv_close(ic); return 1; @@ -1132,12 +1122,12 @@ char *www_new_msg(struct user_record *user, int conference, int area) { int max_len; int len; char buffer[4096]; - + page = (char *)malloc(4096); max_len = 4096; len = 0; memset(page, 0, 4096); - + sprintf(buffer, "

New Message

\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; @@ -1150,7 +1140,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -1158,22 +1148,22 @@ char *www_new_msg(struct user_record *user, int conference, int area) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); sprintf(buffer, "\n", area); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); - len += strlen(buffer); + len += strlen(buffer); sprintf(buffer, "\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -1181,7 +1171,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -1189,7 +1179,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -1197,7 +1187,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); @@ -1205,20 +1195,19 @@ char *www_new_msg(struct user_record *user, int conference, int area) { if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - sprintf(buffer, "\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); - } + } strcat(page, buffer); len += strlen(buffer); - - return page; + + return page; } #endif