clang-format

Fix a bunch of trivial formatting issues by running
`clang-format`.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
Dan Cross 2018-10-08 14:13:11 +00:00 committed by Andrew Pamment
parent ff966a6b4d
commit d6826137dd
32 changed files with 5050 additions and 5269 deletions

108
src/bbs.c
View File

@ -21,13 +21,11 @@
#include "lua/lualib.h" #include "lua/lualib.h"
#include "lua/lauxlib.h" #include "lua/lauxlib.h"
int telnet_bin_mode = 0; int telnet_bin_mode = 0;
int mynode = 0; int mynode = 0;
struct bbs_config conf; struct bbs_config conf;
struct user_record *gUser; struct user_record *gUser;
int gSocket; int gSocket;
int sshBBS; int sshBBS;
@ -39,8 +37,7 @@ struct mosquitto *mosq = NULL;
char *ipaddress = NULL; char *ipaddress = NULL;
void sigterm_handler2(int s) void sigterm_handler2(int s) {
{
if (mynode != 0) { if (mynode != 0) {
disconnect("Terminated."); disconnect("Terminated.");
} }
@ -48,8 +45,7 @@ void sigterm_handler2(int s)
exit(0); exit(0);
} }
void sigint_handler(int s) void sigint_handler(int s) {
{
// do nothing... // do nothing...
} }
void broadcast(char *mess, ...) { void broadcast(char *mess, ...) {
@ -133,8 +129,8 @@ struct fido_addr *parse_fido_addr(const char *str) {
ret->node = 0; ret->node = 0;
ret->point = 0; ret->point = 0;
for (c=0;c<strlen(str);c++) { for (c = 0; c < strlen(str); c++) {
switch(str[c]) { switch (str[c]) {
case ':': case ':':
state = 1; state = 1;
break; break;
@ -153,8 +149,7 @@ struct fido_addr *parse_fido_addr(const char *str) {
case '6': case '6':
case '7': case '7':
case '8': case '8':
case '9': case '9': {
{
switch (state) { switch (state) {
case 0: case 0:
ret->zone = ret->zone * 10 + (str[c] - '0'); ret->zone = ret->zone * 10 + (str[c] - '0');
@ -169,8 +164,7 @@ struct fido_addr *parse_fido_addr(const char *str) {
ret->point = ret->point * 10 + (str[c] - '0'); ret->point = ret->point * 10 + (str[c] - '0');
break; break;
} }
} } break;
break;
default: default:
free(ret); free(ret);
return NULL; return NULL;
@ -179,7 +173,6 @@ struct fido_addr *parse_fido_addr(const char *str) {
return ret; return ret;
} }
void timer_handler(int signum) { void timer_handler(int signum) {
if (signum == SIGALRM) { if (signum == SIGALRM) {
if (gUser != NULL) { if (gUser != NULL) {
@ -189,8 +182,6 @@ void timer_handler(int signum) {
s_printf(get_string(0)); s_printf(get_string(0));
disconnect("Out of Time"); disconnect("Out of Time");
} }
} }
if (timeoutpaused == 0) { if (timeoutpaused == 0) {
usertimeout--; usertimeout--;
@ -212,9 +203,9 @@ void s_printf(char *fmt, ...) {
vsnprintf(buffer, 512, fmt, ap); vsnprintf(buffer, 512, fmt, ap);
va_end(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; pos = 0;
for (i=2;i<strlen(fmt) - 2;i++) { for (i = 2; i < strlen(fmt) - 2; i++) {
buffer[pos++] = fmt[i]; buffer[pos++] = fmt[i];
buffer[pos] = '\0'; buffer[pos] = '\0';
} }
@ -373,7 +364,7 @@ void s_displayansi_pause(char *file, int pause) {
s_printf(get_string(223)); s_printf(get_string(223));
ch = s_getchar(); ch = s_getchar();
s_printf("\r\n"); s_printf("\r\n");
switch(tolower(ch)) { switch (tolower(ch)) {
case 'c': case 'c':
pause = 0; pause = 0;
break; break;
@ -396,7 +387,6 @@ void s_displayansi_p(char *file) {
s_displayansi_pause(file, 0); s_displayansi_pause(file, 0);
} }
void s_displayansi(char *file) { void s_displayansi(char *file) {
FILE *fptr; FILE *fptr;
char c; char c;
@ -411,7 +401,6 @@ void s_displayansi(char *file) {
} }
} }
char s_getchar() { char s_getchar() {
unsigned char c; unsigned char c;
unsigned char d; unsigned char d;
@ -490,7 +479,6 @@ char s_getchar() {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
} }
break; break;
@ -516,7 +504,7 @@ char s_getchar() {
if (len <= 0) { if (len <= 0) {
disconnect("Socket Closed"); disconnect("Socket Closed");
} }
} while(c != 240); } while (c != 240);
} }
do { do {
@ -554,11 +542,11 @@ void s_readstring_inject(char *buffer, int max, char *inject) {
s_printf("%s", inject); s_printf("%s", inject);
for (i=strlen(buffer);i<max;i++) { for (i = strlen(buffer); i < max; i++) {
c = s_getchar(); c = s_getchar();
if ((c == '\b' || c == 127) && i > 0) { if ((c == '\b' || c == 127) && i > 0) {
buffer[i-1] = '\0'; buffer[i - 1] = '\0';
i -= 2; i -= 2;
s_printf("\e[D \e[D"); s_printf("\e[D \e[D");
continue; continue;
@ -579,7 +567,7 @@ void s_readstring_inject(char *buffer, int max, char *inject) {
} }
s_putchar(c); s_putchar(c);
buffer[i] = c; buffer[i] = c;
buffer[i+1] = '\0'; buffer[i + 1] = '\0';
} }
} }
@ -589,11 +577,11 @@ void s_readstring(char *buffer, int max) {
memset(buffer, 0, max); memset(buffer, 0, max);
for (i=0;i<max;i++) { for (i = 0; i < max; i++) {
c = s_getchar(); c = s_getchar();
if ((c == '\b' || c == 127) && i > 0) { if ((c == '\b' || c == 127) && i > 0) {
buffer[i-1] = '\0'; buffer[i - 1] = '\0';
i -= 2; i -= 2;
s_printf("\e[D \e[D"); s_printf("\e[D \e[D");
continue; continue;
@ -614,7 +602,7 @@ void s_readstring(char *buffer, int max) {
} }
s_putchar(c); s_putchar(c);
buffer[i] = 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; int i;
char c; char c;
for (i=0;i<max;i++) { for (i = 0; i < max; i++) {
c = s_getchar(); c = s_getchar();
if ((c == '\b' || c == 127) && i > 0) { if ((c == '\b' || c == 127) && i > 0) {
buffer[i-1] = '\0'; buffer[i - 1] = '\0';
i-=2; i -= 2;
s_printf("\e[D \e[D"); s_printf("\e[D \e[D");
continue; continue;
} else if (c == '\b' || c == 127) { } else if (c == '\b' || c == 127) {
@ -647,7 +635,7 @@ void s_readpass(char *buffer, int max) {
} }
s_putchar('*'); s_putchar('*');
buffer[i] = c; buffer[i] = c;
buffer[i+1] = '\0'; buffer[i + 1] = '\0';
} }
} }
@ -684,11 +672,11 @@ void record_last10_callers(struct user_record *user) {
struct last10_callers new_entry; struct last10_callers new_entry;
struct last10_callers callers[10]; struct last10_callers callers[10];
int i,j; int i, j;
FILE *fptr = fopen("last10v2.dat", "rb"); FILE *fptr = fopen("last10v2.dat", "rb");
if (fptr != NULL) { 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) { if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) {
break; break;
} }
@ -698,7 +686,7 @@ void record_last10_callers(struct user_record *user) {
i = 0; 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)); memset(&new_entry, 0, sizeof(struct last10_callers));
strcpy(new_entry.name, user->loginname); strcpy(new_entry.name, user->loginname);
strcpy(new_entry.location, user->location); strcpy(new_entry.location, user->location);
@ -710,7 +698,7 @@ void record_last10_callers(struct user_record *user) {
j = 0; j = 0;
} }
fptr = fopen("last10v2.dat", "wb"); fptr = fopen("last10v2.dat", "wb");
for (;j<i;j++) { for (; j < i; j++) {
fwrite(&callers[j], sizeof(struct last10_callers), 1, fptr); fwrite(&callers[j], sizeof(struct last10_callers), 1, fptr);
} }
fwrite(&new_entry, sizeof(struct last10_callers), 1, fptr); fwrite(&new_entry, sizeof(struct last10_callers), 1, fptr);
@ -721,7 +709,7 @@ void record_last10_callers(struct user_record *user) {
void display_last10_callers(struct user_record *user) { void display_last10_callers(struct user_record *user) {
struct last10_callers callers[10]; struct last10_callers callers[10];
int i,z; int i, z;
struct tm l10_time; struct tm l10_time;
FILE *fptr = fopen("last10v2.dat", "rb"); FILE *fptr = fopen("last10v2.dat", "rb");
time_t l10_timet; time_t l10_timet;
@ -733,7 +721,7 @@ void display_last10_callers(struct user_record *user) {
if (fptr != NULL) { 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) { if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) {
break; break;
} }
@ -744,7 +732,7 @@ void display_last10_callers(struct user_record *user) {
i = 0; i = 0;
} }
for (z=0;z<i;z++) { for (z = 0; z < i; z++) {
l10_timet = callers[z].time; l10_timet = callers[z].time;
localtime_r(&l10_timet, &l10_time); localtime_r(&l10_timet, &l10_time);
if (conf.date_style == 1) { if (conf.date_style == 1) {
@ -796,7 +784,7 @@ void automessage_write() {
automsg[strlen(automsg) - 1] = '\r'; automsg[strlen(automsg) - 1] = '\r';
automsg[strlen(automsg)] = '\n'; automsg[strlen(automsg)] = '\n';
s_printf(get_string(16)); s_printf(get_string(16));
for (i=0;i<4;i++) { for (i = 0; i < 4; i++) {
s_printf("\r\n%d: ", i); s_printf("\r\n%d: ", i);
s_readstring(buffer, 75); s_readstring(buffer, 75);
strcat(automsg, buffer); strcat(automsg, buffer);
@ -822,7 +810,7 @@ void automessage_display() {
if (stat("automessage.txt", &s) == 0) { if (stat("automessage.txt", &s) == 0) {
fptr = fopen("automessage.txt", "r"); fptr = fopen("automessage.txt", "r");
if (fptr) { if (fptr) {
for (i=0;i<5;i++) { for (i = 0; i < 5; i++) {
memset(buffer, 0, 90); memset(buffer, 0, 90);
fgets(buffer, 88, fptr); fgets(buffer, 88, fptr);
buffer[strlen(buffer) - 1] = '\r'; buffer[strlen(buffer) - 1] = '\r';
@ -846,7 +834,7 @@ void automessage() {
s_printf(get_string(275)); s_printf(get_string(275));
c = s_getchar(); c = s_getchar();
s_printf("\r\n"); s_printf("\r\n");
switch(tolower(c)) { switch (tolower(c)) {
case 'v': case 'v':
automessage_display(); automessage_display();
break; break;
@ -887,18 +875,17 @@ void runbbs_real(int socket, char *ip, int ssh) {
usertimeout = 10; usertimeout = 10;
timeoutpaused = 0; timeoutpaused = 0;
memset(&sa, 0, sizeof(sa));
memset (&sa, 0, sizeof (sa));
sa.sa_handler = &timer_handler; sa.sa_handler = &timer_handler;
sa.sa_flags = SA_RESTART; sa.sa_flags = SA_RESTART;
sigaction (SIGALRM, &sa, 0); sigaction(SIGALRM, &sa, 0);
itime.it_interval.tv_sec = 60; itime.it_interval.tv_sec = 60;
itime.it_interval.tv_usec = 0; itime.it_interval.tv_usec = 0;
itime.it_value.tv_sec = 60; itime.it_value.tv_sec = 60;
itime.it_value.tv_usec = 0; itime.it_value.tv_usec = 0;
setitimer (ITIMER_REAL, &itime, 0); setitimer(ITIMER_REAL, &itime, 0);
ipaddress = ip; ipaddress = ip;
@ -915,7 +902,6 @@ void runbbs_real(int socket, char *ip, int ssh) {
} }
gSocket = socket; gSocket = socket;
if (!ssh) { if (!ssh) {
gUser = NULL; gUser = NULL;
sshBBS = 0; sshBBS = 0;
@ -934,7 +920,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
s_printf("Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR); s_printf("Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR);
// find out which node we are // find out which node we are
for (i=1;i<=conf.nodes;i++) { for (i = 1; i <= conf.nodes; i++) {
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, i); sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, i);
if (stat(buffer, &s) != 0) { if (stat(buffer, &s) != 0) {
@ -967,7 +953,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
if (conf.broadcast_user != NULL && conf.broadcast_pass != NULL) { if (conf.broadcast_user != NULL && conf.broadcast_pass != NULL) {
mosquitto_username_pw_set(mosq, conf.broadcast_user, conf.broadcast_pass); mosquitto_username_pw_set(mosq, conf.broadcast_user, conf.broadcast_pass);
} }
if(mosquitto_connect(mosq, conf.broadcast_address, conf.broadcast_port, 60)){ if (mosquitto_connect(mosq, conf.broadcast_address, conf.broadcast_port, 60)) {
dolog("Unable to connect to MQTT server."); dolog("Unable to connect to MQTT server.");
conf.broadcast_enable = 0; conf.broadcast_enable = 0;
} else { } else {
@ -987,7 +973,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
tries = 0; tries = 0;
if (!ssh) { if (!ssh) {
tryagain: tryagain:
s_printf(get_string(19)); s_printf(get_string(19));
s_printf(get_string(20)); s_printf(get_string(20));
@ -1023,7 +1009,7 @@ tryagain:
gUser = user; gUser = user;
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); snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i);
if (stat(buffer, &s) == 0) { if (stat(buffer, &s) == 0) {
nodefile = fopen(buffer, "r"); nodefile = fopen(buffer, "r");
@ -1047,7 +1033,7 @@ tryagain:
user = gUser; user = gUser;
s_printf(get_string(24), gUser->loginname); s_printf(get_string(24), gUser->loginname);
s_getc(); 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); snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i);
if (stat(buffer, &s) == 0) { if (stat(buffer, &s) == 0) {
nodefile = fopen(buffer, "r"); nodefile = fopen(buffer, "r");
@ -1095,13 +1081,10 @@ tryagain:
recursive_delete(buffer); recursive_delete(buffer);
} }
#if defined(ENABLE_WWW) #if defined(ENABLE_WWW)
www_expire_old_links(); www_expire_old_links();
#endif #endif
// do post-login // do post-login
dolog("%s logged in, on node %d", user->loginname, mynode); dolog("%s logged in, on node %d", user->loginname, mynode);
broadcast("USER: %s; NODE:%d; STATUS: Logged in.", user->loginname, mynode); broadcast("USER: %s; NODE:%d; STATUS: Logged in.", user->loginname, mynode);
@ -1120,7 +1103,6 @@ tryagain:
user->timeson++; user->timeson++;
if (conf.script_path != NULL) { if (conf.script_path != NULL) {
snprintf(buffer, PATH_MAX, "%s/login_stanza.lua", conf.script_path); snprintf(buffer, PATH_MAX, "%s/login_stanza.lua", conf.script_path);
if (stat(buffer, &s) == 0) { if (stat(buffer, &s) == 0) {
@ -1235,7 +1217,7 @@ int recursive_delete(const char *dir) {
FTS *ftsp = NULL; FTS *ftsp = NULL;
FTSENT *curr; FTSENT *curr;
char *files[] = { (char *) dir, NULL }; char *files[] = {(char *)dir, NULL};
ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL); ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL);
if (!ftsp) { if (!ftsp) {
@ -1297,7 +1279,7 @@ int copy_file(char *src, char *dest) {
return -1; return -1;
} }
while(1) { while (1) {
c = fgetc(src_file); c = fgetc(src_file);
if (!feof(src_file)) { if (!feof(src_file)) {
fputc(c, dest_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); pos_cache_tmp = realloc(pos_cache, sizeof(*pos_cache) * cache_sz);
if (pos_cache_tmp == NULL) { if (pos_cache_tmp == NULL) {
goto end_repl_str; goto end_repl_str;
} else pos_cache = pos_cache_tmp; } else
pos_cache = pos_cache_tmp;
cache_sz_inc *= cache_sz_inc_factor; cache_sz_inc *= cache_sz_inc_factor;
if (cache_sz_inc > cache_sz_inc_max) { if (cache_sz_inc > cache_sz_inc_max) {
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; pstr = pstr2 + fromlen;
} }
@ -1356,7 +1339,8 @@ char *str_replace(const char *str, const char *from, const char *to) {
if (count > 0) { if (count > 0) {
tolen = strlen(to); tolen = strlen(to);
retlen = orglen + (tolen - fromlen) * count; retlen = orglen + (tolen - fromlen) * count;
} else retlen = orglen; } else
retlen = orglen;
ret = malloc(retlen + 1); ret = malloc(retlen + 1);
if (ret == NULL) { if (ret == NULL) {
goto end_repl_str; goto end_repl_str;
@ -1375,7 +1359,7 @@ char *str_replace(const char *str, const char *from, const char *to) {
memcpy(pret, to, tolen); memcpy(pret, to, tolen);
pret += tolen; pret += tolen;
pstr = str + pos_cache[i] + fromlen; 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); memcpy(pret, pstr, cpylen);
pret += cpylen; pret += cpylen;
} }

View File

@ -48,7 +48,7 @@ struct last10_callers {
char location[33]; char location[33];
time_t time; time_t time;
int calls; int calls;
}__attribute__((packed)); } __attribute__((packed));
struct text_file { struct text_file {
char *name; char *name;
@ -373,9 +373,9 @@ extern void chomp(char *string);
#if defined(ENABLE_WWW) #if defined(ENABLE_WWW)
extern void www_init(); 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 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_summary(struct user_record *user);
extern char *www_email_display(struct user_record *user, int email); 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); extern int www_send_email(struct user_record *user, char *recipient, char *subject, char *body);

View File

@ -67,7 +67,7 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg); dolog("SQL error: %s", err_msg);
@ -90,7 +90,6 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
return 0; return 0;
} }
rc = sqlite3_step(res); rc = sqlite3_step(res);
if (rc != SQLITE_DONE) { if (rc != SQLITE_DONE) {
@ -194,7 +193,7 @@ void bbs_list() {
int entrycount; int entrycount;
struct bbs_list_entry_t *newentry; struct bbs_list_entry_t *newentry;
while(1) { while (1) {
entrycount = 0; entrycount = 0;
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
@ -235,7 +234,7 @@ void bbs_list() {
s_printf("\e[2J\e[1;1H"); s_printf("\e[2J\e[1;1H");
s_printf(get_string(270)); s_printf(get_string(270));
s_printf(get_string(271)); s_printf(get_string(271));
for (i=start;i<start+22 && i < entrycount;i++) { for (i = start; i < start + 22 && i < entrycount; i++) {
if (i == selected) { if (i == selected) {
s_printf(get_string(269), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet); s_printf(get_string(269), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet);
} else { } else {
@ -247,7 +246,7 @@ void bbs_list() {
} }
c = s_getchar(); c = s_getchar();
if (tolower(c) == 'q') { if (tolower(c) == 'q') {
for (i=0;i<entrycount;i++) { for (i = 0; i < entrycount; i++) {
free(entries[i]->bbsname); free(entries[i]->bbsname);
free(entries[i]->sysopname); free(entries[i]->sysopname);
free(entries[i]->telnet); free(entries[i]->telnet);
@ -273,7 +272,7 @@ void bbs_list() {
free(entries[selected]->telnet); free(entries[selected]->telnet);
free(entries[selected]); free(entries[selected]);
for (i=selected;i<entrycount - 1;i++) { for (i = selected; i < entrycount - 1; i++) {
entries[selected] = entries[selected + 1]; entries[selected] = entries[selected + 1];
} }
@ -362,7 +361,7 @@ void bbs_list() {
// PAGE DOWN // PAGE DOWN
selected = selected + 22; selected = selected + 22;
if (selected >= entrycount) { if (selected >= entrycount) {
selected = entrycount -1; selected = entrycount - 1;
} }
start = selected; start = selected;
redraw = 1; redraw = 1;
@ -378,7 +377,7 @@ void bbs_list() {
s_printf(get_string(272)); s_printf(get_string(272));
s_printf(get_string(273)); s_printf(get_string(273));
while(1) { while (1) {
c = s_getchar(); c = s_getchar();
if (tolower(c) == 'a') { if (tolower(c) == 'a') {

View File

@ -64,7 +64,7 @@ void blog_display() {
int i; int i;
struct tm thetime; struct tm thetime;
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
char c; char c;
int hour; int hour;
int j; int j;
@ -83,7 +83,7 @@ void blog_display() {
c = 'y'; c = 'y';
for (i=0;i<blog_entry_count;i++) { for (i = 0; i < blog_entry_count; i++) {
localtime_r(&blog_entries[i]->date, &thetime); localtime_r(&blog_entries[i]->date, &thetime);
s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author); s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author);
@ -129,7 +129,7 @@ void blog_display() {
s_printf("\r\n\r\n"); s_printf("\r\n\r\n");
lines = 0; lines = 0;
} }
for (j=0; j<strlen(blog_entries[i]->body); j++) { for (j = 0; j < strlen(blog_entries[i]->body); j++) {
if (blog_entries[i]->body[j] == '\r') { if (blog_entries[i]->body[j] == '\r') {
s_printf("\r\n"); s_printf("\r\n");
lines++; lines++;
@ -164,7 +164,7 @@ void blog_display() {
lines = 0; lines = 0;
} }
} }
for (i=0;i<blog_entry_count;i++) { for (i = 0; i < blog_entry_count; i++) {
free(blog_entries[i]->subject); free(blog_entries[i]->subject);
free(blog_entries[i]->author); free(blog_entries[i]->author);
free(blog_entries[i]->body); free(blog_entries[i]->body);
@ -175,7 +175,6 @@ void blog_display() {
s_printf(get_string(6)); s_printf(get_string(6));
s_getchar(); s_getchar();
} }
void blog_write() { void blog_write() {
@ -220,7 +219,7 @@ void blog_write() {
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, csql, 0, 0, &err_msg); rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg); dolog("SQL error: %s", err_msg);
sqlite3_free(err_msg); sqlite3_free(err_msg);
sqlite3_close(db); sqlite3_close(db);

View File

@ -23,10 +23,10 @@ tLONG convertl(tLONG l) {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
unsigned char result_bytes[4]; unsigned char result_bytes[4];
unsigned int result; unsigned int result;
result_bytes[0] = (unsigned char) ((l >> 24) & 0xFF); result_bytes[0] = (unsigned char)((l >> 24) & 0xFF);
result_bytes[1] = (unsigned char) ((l >> 16) & 0xFF); result_bytes[1] = (unsigned char)((l >> 16) & 0xFF);
result_bytes[2] = (unsigned char) ((l >> 8) & 0xFF); result_bytes[2] = (unsigned char)((l >> 8) & 0xFF);
result_bytes[3] = (unsigned char) (l & 0xFF); result_bytes[3] = (unsigned char)(l & 0xFF);
memcpy(&result, result_bytes, 4); memcpy(&result, result_bytes, 4);
return result; return result;
#else #else
@ -38,8 +38,8 @@ tWORD converts(tWORD s) {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
unsigned char result_bytes[2]; unsigned char result_bytes[2];
unsigned short result; unsigned short result;
result_bytes[0] = (unsigned char) ((s >> 8) & 0xFF); result_bytes[0] = (unsigned char)((s >> 8) & 0xFF);
result_bytes[1] = (unsigned char) (s & 0xFF); result_bytes[1] = (unsigned char)(s & 0xFF);
memcpy(&result, result_bytes, 4); memcpy(&result, result_bytes, 4);
return result; return result;
#else #else
@ -175,17 +175,16 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file
} else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) { } else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) {
all_unread = 1; all_unread = 1;
} }
} }
if (all_unread == 0) { if (all_unread == 0) {
k = jlr.HighReadMsg; k = jlr.HighReadMsg;
for (i=0;i<msghs->msg_count;i++) { for (i = 0; i < msghs->msg_count; i++) {
if (msghs->msgs[i]->msg_h->MsgNum == k) { if (msghs->msgs[i]->msg_h->MsgNum == k) {
break; break;
} }
} }
i+=1; i += 1;
} else { } else {
i = 0; i = 0;
} }
@ -194,7 +193,7 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file
area_msgs = 0; area_msgs = 0;
personal_msgs = 0; personal_msgs = 0;
for (k=i;k<msghs->msg_count;k++) { for (k = i; k < msghs->msg_count; k++) {
if (totmsgs == conf.bwave_max_msgs) { if (totmsgs == conf.bwave_max_msgs) {
break; break;
@ -321,8 +320,8 @@ void bwave_create_packet() {
char *cmd; char *cmd;
pid_t pid; pid_t pid;
for (i=0;i<conf.mail_conference_count;i++) { for (i = 0; i < conf.mail_conference_count; i++) {
for (j=0;j<conf.mail_conferences[i]->mail_area_count;j++) { for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) {
if (msgbase_is_subscribed(i, j)) { if (msgbase_is_subscribed(i, j)) {
tot_areas++; tot_areas++;
} }
@ -385,7 +384,7 @@ void bwave_create_packet() {
s_printf("\r\n"); s_printf("\r\n");
totmsgs = bwave_scan_email(area_count+1, totmsgs, fti_file, mix_file, dat_file, &last_ptr); 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); s_printf(get_string(195), "Private Email", "Private Email", totmsgs);
areas = (INF_AREA_INFO **)malloc(sizeof(INF_AREA_INFO *)); areas = (INF_AREA_INFO **)malloc(sizeof(INF_AREA_INFO *));
@ -410,11 +409,11 @@ void bwave_create_packet() {
if (totmsgs < conf.bwave_max_msgs) { if (totmsgs < conf.bwave_max_msgs) {
for (i=0;i<conf.mail_conference_count;i++) { for (i = 0; i < conf.mail_conference_count; i++) {
for (j=0;j<conf.mail_conferences[i]->mail_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 <= gUser->sec_level && conf.mail_conferences[i]->mail_areas[j]->qwkname != NULL && msgbase_is_subscribed(i, 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; lasttot = totmsgs;
totmsgs = bwave_scan_area(i, j, area_count+1, totmsgs, fti_file, mix_file, dat_file, &last_ptr); 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); s_printf(get_string(195), conf.mail_conferences[i]->name, conf.mail_conferences[i]->mail_areas[j]->name, totmsgs - lasttot);
//if (lasttot == totmsgs) { //if (lasttot == totmsgs) {
// continue; // continue;
@ -461,7 +460,6 @@ void bwave_create_packet() {
if (totmsgs == conf.bwave_max_msgs) { if (totmsgs == conf.bwave_max_msgs) {
break; break;
} }
} }
} }
if (totmsgs == conf.bwave_max_msgs) { if (totmsgs == conf.bwave_max_msgs) {
@ -479,13 +477,13 @@ void bwave_create_packet() {
inf_file = fopen(buffer, "wb"); inf_file = fopen(buffer, "wb");
fwrite(&hdr, sizeof(INF_HEADER), 1, inf_file); fwrite(&hdr, sizeof(INF_HEADER), 1, inf_file);
for (i=0;i<area_count;i++) { for (i = 0; i < area_count; i++) {
fwrite(areas[i], sizeof(INF_AREA_INFO), 1, inf_file); fwrite(areas[i], sizeof(INF_AREA_INFO), 1, inf_file);
} }
fclose(inf_file); fclose(inf_file);
for (i=0;i<area_count;i++) { for (i = 0; i < area_count; i++) {
free(areas[i]); free(areas[i]);
} }
if (areas != NULL) { if (areas != NULL) {
@ -508,21 +506,21 @@ void bwave_create_packet() {
snprintf(archive, 1024, "%s/node%d/%s.%03d", conf.bbs_path, mynode, conf.bwave_name, gUser->bwavepktno); snprintf(archive, 1024, "%s/node%d/%s.%03d", conf.bbs_path, mynode, conf.bwave_name, gUser->bwavepktno);
} }
for (i=0;i<strlen(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] == '*') { if (conf.archivers[gUser->defarchiver - 1]->pack[i] == '*') {
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); sprintf(&buffer[bpos], "%s", archive);
bpos = strlen(buffer); 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); 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); 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++] = '*';
buffer[bpos] = '\0'; buffer[bpos] = '\0';
} }
} else { } else {
buffer[bpos++] = conf.archivers[gUser->defarchiver-1]->pack[i]; buffer[bpos++] = conf.archivers[gUser->defarchiver - 1]->pack[i];
buffer[bpos] = '\0'; buffer[bpos] = '\0';
} }
} }
@ -536,7 +534,7 @@ void bwave_create_packet() {
dup2(bbs_stdin, STDIN_FILENO); dup2(bbs_stdin, STDIN_FILENO);
} }
args = (char **)malloc(sizeof (char *)); args = (char **)malloc(sizeof(char *));
arg_count = 0; arg_count = 0;
args[arg_count] = strtok(buffer, " "); args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) { while (args[arg_count] != NULL) {
@ -588,11 +586,10 @@ void bwave_create_packet() {
s_getc(); s_getc();
} }
int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char *subject, struct fido_addr *destaddr, char *msg) { 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_JamBase *jb;
s_JamMsgHeader jmh; s_JamMsgHeader jmh;
s_JamSubPacket* jsp; s_JamSubPacket *jsp;
s_JamSubfield jsf; s_JamSubfield jsf;
int z; int z;
char buffer[256]; char buffer[256];
@ -604,7 +601,7 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
return 1; return 1;
} }
JAM_ClearMsgHeader( &jmh ); JAM_ClearMsgHeader(&jmh);
jmh.DateWritten = dwritten; jmh.DateWritten = dwritten;
jmh.Attribute |= JAM_MSG_LOCAL; jmh.Attribute |= JAM_MSG_LOCAL;
if (conf.mail_conferences[confr]->realnames == 0) { if (conf.mail_conferences[confr]->realnames == 0) {
@ -613,7 +610,6 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
sprintf(buffer, "%s %s", gUser->firstname, gUser->lastname); sprintf(buffer, "%s %s", gUser->firstname, gUser->lastname);
} }
jsp = JAM_NewSubPacket(); jsp = JAM_NewSubPacket();
jsf.LoID = JAMSFLD_SENDERNAME; jsf.LoID = JAMSFLD_SENDERNAME;
@ -647,7 +643,6 @@ 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) { 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; jmh.Attribute |= JAM_MSG_TYPEECHO;
if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) {
if (conf.mail_conferences[confr]->fidoaddr->point) { if (conf.mail_conferences[confr]->fidoaddr->point) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone, sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone,
@ -685,7 +680,6 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
uuid_generate(magi_msgid); uuid_generate(magi_msgid);
uuid_unparse_lower(magi_msgid, buffer); uuid_unparse_lower(magi_msgid, buffer);
@ -850,21 +844,21 @@ void bwave_upload_reply() {
} }
bpos = 0; bpos = 0;
for (i=0;i<strlen(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] == '*') { if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == '*') {
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); sprintf(&buffer[bpos], "%s", upload_filename);
bpos = strlen(buffer); 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); sprintf(&buffer[bpos], "%s/node%d/bwave/", conf.bbs_path, mynode);
bpos = strlen(buffer); bpos = strlen(buffer);
} else if (conf.archivers[gUser->defarchiver-1]->unpack[i] == '*') { } else if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == '*') {
buffer[bpos++] = '*'; buffer[bpos++] = '*';
buffer[bpos] = '\0'; buffer[bpos] = '\0';
} }
} else { } else {
buffer[bpos++] = conf.archivers[gUser->defarchiver-1]->unpack[i]; buffer[bpos++] = conf.archivers[gUser->defarchiver - 1]->unpack[i];
buffer[bpos] = '\0'; buffer[bpos] = '\0';
} }
} }
@ -877,7 +871,7 @@ void bwave_upload_reply() {
dup2(bbs_stderr, STDERR_FILENO); dup2(bbs_stderr, STDERR_FILENO);
dup2(bbs_stdin, STDIN_FILENO); dup2(bbs_stdin, STDIN_FILENO);
} }
args = (char **)malloc(sizeof (char *)); args = (char **)malloc(sizeof(char *));
arg_count = 0; arg_count = 0;
args[arg_count] = strtok(buffer, " "); args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) { while (args[arg_count] != NULL) {
@ -957,7 +951,7 @@ void bwave_upload_reply() {
body[s.st_size] = '\0'; body[s.st_size] = '\0';
bpos = 0; bpos = 0;
for (i=0;i<strlen(body);i++) { for (i = 0; i < strlen(body); i++) {
if (body[i] != '\n') { if (body[i] != '\n') {
body[bpos++] = body[i]; body[bpos++] = body[i];
} }
@ -977,7 +971,7 @@ void bwave_upload_reply() {
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, csql, 0, 0, &err_msg); rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg); dolog("SQL error: %s", err_msg);
@ -1014,8 +1008,8 @@ void bwave_upload_reply() {
confr = -1; confr = -1;
area = -1; area = -1;
for (i=0;i<conf.mail_conference_count;i++) { for (i = 0; i < conf.mail_conference_count; i++) {
for (j=0;j<conf.mail_conferences[i]->mail_area_count;j++) { 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) { if (strcmp(conf.mail_conferences[i]->mail_areas[j]->qwkname, upl_rec.echotag) == 0) {
confr = i; confr = i;
area = j; area = j;
@ -1111,14 +1105,13 @@ void bwave_upload_reply() {
strcat(body, originlinebuffer); strcat(body, originlinebuffer);
bpos = 0; bpos = 0;
for (i=0;i<strlen(body);i++) { for (i = 0; i < strlen(body); i++) {
if (body[i] != '\n') { if (body[i] != '\n') {
body[bpos++] = body[i]; body[bpos++] = body[i];
} }
} }
body[bpos] = '\0'; body[bpos] = '\0';
if (bwave_add_message(confr, area, convertl(upl_rec.unix_date), upl_rec.to, upl_rec.subj, &addr, body) != 0) { if (bwave_add_message(confr, area, convertl(upl_rec.unix_date), upl_rec.to, upl_rec.subj, &addr, body) != 0) {
// failed to add message // failed to add message
s_printf(get_string(197)); s_printf(get_string(197));

View File

@ -22,12 +22,10 @@
#ifndef __BLUEWAVE_H /* An extra safeguard to prevent this header from */ #ifndef __BLUEWAVE_H /* An extra safeguard to prevent this header from */
#define __BLUEWAVE_H /* being included twice in the same source file */ #define __BLUEWAVE_H /* being included twice in the same source file */
#define PACKET_LEVEL 3 /* The current mail packet revision level, */ #define PACKET_LEVEL 3 /* The current mail packet revision level, */
/* used in the "ver" field of the *.INF */ /* used in the "ver" field of the *.INF */
/* file header. */ /* file header. */
/* /*
** This header defines the data structures for the following files in the ** This header defines the data structures for the following files in the
** official Blue Wave offline mail specification: ** official Blue Wave offline mail specification:
@ -67,12 +65,10 @@
** function. Example: "memset(&ftirec, 0, sizeof(FTI_REC))".) ** function. Example: "memset(&ftirec, 0, sizeof(FTI_REC))".)
*/ */
/*****************************************************************************/ /*****************************************************************************/
/* >>>>>>>>>>>>>>>>>>>>>>> DATA TYPE DEFINITIONS <<<<<<<<<<<<<<<<<<<<<<<<< */ /* >>>>>>>>>>>>>>>>>>>>>>> DATA TYPE DEFINITIONS <<<<<<<<<<<<<<<<<<<<<<<<< */
/*****************************************************************************/ /*****************************************************************************/
/* /*
** The data type definitions below help make these structures a little more ** 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 ** universal between environments. The 8-bit, 16-bit, and 32-bit data types
@ -96,9 +92,6 @@
** they aren't, you're bound to get some *very* interesting results. ** they aren't, you're bound to get some *very* interesting results.
*/ */
typedef signed char tCHAR; /* 8 bit signed values */ typedef signed char tCHAR; /* 8 bit signed values */
typedef unsigned char tBYTE; /* 8 bit unsigned values */ typedef unsigned char tBYTE; /* 8 bit unsigned values */
typedef signed short tINT; /* 16 bit signed values */ typedef signed short tINT; /* 16 bit signed values */
@ -106,12 +99,10 @@ typedef unsigned short tWORD; /* 16 bit unsigned values */
typedef int tLONG; /* 32 bit signed values */ typedef int tLONG; /* 32 bit signed values */
typedef unsigned int tDWORD; /* 32 bit unsigned values */ typedef unsigned int tDWORD; /* 32 bit unsigned values */
/*****************************************************************************/ /*****************************************************************************/
/* >>>>>>>>>>>>>>>>>>>>> DOOR DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<<<<<<< */ /* >>>>>>>>>>>>>>>>>>>>> DOOR DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<<<<<<< */
/*****************************************************************************/ /*****************************************************************************/
/* /*
** Name of file: *.INF ** Name of file: *.INF
** **
@ -250,7 +241,7 @@ typedef struct /* INF_HEADER */
/* NUL (0x00) characters in order for */ /* NUL (0x00) characters in order for */
/* future additional features to work */ /* future additional features to work */
/* properly! */ /* properly! */
}__attribute__((packed)) } __attribute__((packed))
INF_HEADER; INF_HEADER;
/* /*
@ -417,7 +408,7 @@ typedef struct /* INF_AREA_INFO */
tBYTE title[50]; /* Area description/title */ tBYTE title[50]; /* Area description/title */
tWORD area_flags; /* Bit-mapped area options */ tWORD area_flags; /* Bit-mapped area options */
tBYTE network_type; /* Network mail type (see above) */ tBYTE network_type; /* Network mail type (see above) */
}__attribute__((packed)) } __attribute__((packed))
INF_AREA_INFO; INF_AREA_INFO;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -442,7 +433,7 @@ typedef struct /* MIX_REC */
tWORD totmsgs; /* Total number of messages for this area */ tWORD totmsgs; /* Total number of messages for this area */
tWORD numpers; /* Total number of personal messages in this area */ tWORD numpers; /* Total number of personal messages in this area */
tLONG msghptr; /* Pointer to first message header in *.FTI file */ tLONG msghptr; /* Pointer to first message header in *.FTI file */
}__attribute__((packed)) } __attribute__((packed))
MIX_REC; MIX_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -514,7 +505,7 @@ typedef struct /* FTI_REC */
/* NetMail message base. */ /* NetMail message base. */
tWORD orig_net; tWORD orig_net;
tWORD orig_node; tWORD orig_node;
}__attribute__((packed)) } __attribute__((packed))
FTI_REC; FTI_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -534,12 +525,10 @@ FTI_REC;
** File format: Unstructured ** File format: Unstructured
*/ */
/*****************************************************************************/ /*****************************************************************************/
/* >>>>>>>>>>>>>>>>> MISCELLANEOUS DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<< */ /* >>>>>>>>>>>>>>>>> MISCELLANEOUS DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<< */
/*****************************************************************************/ /*****************************************************************************/
/* /*
** Name of file: *.MSG ** Name of file: *.MSG
** **
@ -609,7 +598,7 @@ typedef struct /* MSG_REC (will soon be obsolete) */
tWORD reply; /* Message # that this message replies to */ tWORD reply; /* Message # that this message replies to */
tWORD attr; /* Message attributes and behavior flags */ tWORD attr; /* Message attributes and behavior flags */
tWORD up; /* Message # that replies to this message */ tWORD up; /* Message # that replies to this message */
}__attribute__((packed)) } __attribute__((packed))
MSG_REC; MSG_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -664,15 +653,13 @@ typedef struct /* XTI_REC */
{ {
tBYTE flags; /* Bit-mapped message flags */ tBYTE flags; /* Bit-mapped message flags */
tBYTE marks; /* Bit-mapped message markers */ tBYTE marks; /* Bit-mapped message markers */
}__attribute__((packed)) } __attribute__((packed))
XTI_REC; XTI_REC;
/*****************************************************************************/ /*****************************************************************************/
/* >>>>>>>>>>>>>>>>>>>> READER DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<<<<<< */ /* >>>>>>>>>>>>>>>>>>>> READER DATA FILE STRUCTURES <<<<<<<<<<<<<<<<<<<<<< */
/*****************************************************************************/ /*****************************************************************************/
/* /*
** Name of file: *.NET ** Name of file: *.NET
** **
@ -704,7 +691,7 @@ typedef struct /* NET_REC */
/* of seconds since 01/01/70) is converted */ /* of seconds since 01/01/70) is converted */
/* to the date/time storage method used by */ /* to the date/time storage method used by */
/* the host BBS. */ /* the host BBS. */
}__attribute__((packed)) } __attribute__((packed))
NET_REC; NET_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -747,7 +734,7 @@ typedef struct /* UPI_HEADER */
/* your compiler may insert an extra byte not */ /* your compiler may insert an extra byte not */
/* explicitly specified here. */ /* explicitly specified here. */
#endif #endif
}__attribute__((packed)) } __attribute__((packed))
UPI_HEADER; UPI_HEADER;
/* Bit-masks for UPI_REC.FLAGS field */ /* Bit-masks for UPI_REC.FLAGS field */
@ -782,7 +769,7 @@ typedef struct /* UPI_REC */
/* This flag is used internally by the Blue */ /* This flag is used internally by the Blue */
/* Wave reader. Doors should ignore this */ /* Wave reader. Doors should ignore this */
/* field during reply packet processing. */ /* field during reply packet processing. */
}__attribute__((packed)) } __attribute__((packed))
UPI_REC; UPI_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -868,7 +855,7 @@ typedef struct /* UPL_HEADER */
/* line <grin>). */ /* line <grin>). */
tBYTE pad[33]; /* RESERVED FOR FUTURE USE, and to pad struct */ tBYTE pad[33]; /* RESERVED FOR FUTURE USE, and to pad struct */
/* out to a 'nice' 256 bytes */ /* out to a 'nice' 256 bytes */
}__attribute__((packed)) } __attribute__((packed))
UPL_HEADER; UPL_HEADER;
/* Bit-masks for UPL_REC.MSG_ATTR field */ /* Bit-masks for UPL_REC.MSG_ATTR field */
@ -1029,7 +1016,7 @@ typedef struct /* UPL_REC */
tBYTE net_dest[100]; /* Network destination address (non-FidoNet) */ tBYTE net_dest[100]; /* Network destination address (non-FidoNet) */
/* Internet E-mail messages should use this */ /* Internet E-mail messages should use this */
/* field to store the destination address. */ /* field to store the destination address. */
}__attribute__((packed)) } __attribute__((packed))
UPL_REC; UPL_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -1060,7 +1047,7 @@ UPL_REC;
typedef struct /* REQ_REC */ typedef struct /* REQ_REC */
{ {
tBYTE filename[13]; /* Name of file to request */ tBYTE filename[13]; /* Name of file to request */
}__attribute__((packed)) } __attribute__((packed))
REQ_REC; REQ_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -1114,7 +1101,7 @@ typedef struct /* PDQ_HEADER */
tBYTE passtype; /* Password type */ tBYTE passtype; /* Password type */
/* 0=none 1=door 2=reader 3=both */ /* 0=none 1=door 2=reader 3=both */
tWORD flags; /* Bit-mapped flags */ tWORD flags; /* Bit-mapped flags */
}__attribute__((packed)) } __attribute__((packed))
PDQ_HEADER; PDQ_HEADER;
typedef struct /* PDQ_REC */ typedef struct /* PDQ_REC */
@ -1123,7 +1110,7 @@ typedef struct /* PDQ_REC */
/* With Telegard systems, this should */ /* With Telegard systems, this should */
/* be the name of the *.BRD file, rather */ /* be the name of the *.BRD file, rather */
/* than the actual echo tag. */ /* than the actual echo tag. */
}__attribute__((packed)) } __attribute__((packed))
PDQ_REC; PDQ_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -1149,4 +1136,3 @@ PDQ_REC;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#endif /* __BLUEWAVE_H */ #endif /* __BLUEWAVE_H */

View File

@ -8,7 +8,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#if defined(__OpenBSD__) #if defined(__OpenBSD__)
# include <sys/select.h> #include <sys/select.h>
#endif #endif
#include "../deps/jsmn/jsmn.h" #include "../deps/jsmn/jsmn.h"
#include "bbs.h" #include "bbs.h"
@ -37,9 +37,8 @@ struct chat_msg {
char msg[512]; char msg[512];
}; };
static int jsoneq(const char *json, jsmntok_t *tok, const char *s) { static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {
if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
strncmp(json + tok->start, s, tok->end - tok->start) == 0) { strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
return 0; return 0;
} }
@ -50,12 +49,12 @@ static char *encapsulate_quote(char *in) {
char out[512]; char out[512];
int i = 0; int i = 0;
int j = 0; int j = 0;
for (j=0;j<strlen(in);j++) { for (j = 0; j < strlen(in); j++) {
if (in[j] == '\"' || in[j] == '\\') { if (in[j] == '\"' || in[j] == '\\') {
out[i++] = '\\'; out[i++] = '\\';
} }
out[i] = in[j]; out[i] = in[j];
out[i+1] = '\0'; out[i + 1] = '\0';
i++; i++;
} }
return strdup(out); return strdup(out);
@ -66,13 +65,13 @@ void scroll_up() {
int x; int x;
int color; int color;
for (y=1;y<23;y++) { for (y = 1; y < 23; y++) {
for (x=0;x<80;x++) { for (x = 0; x < 80; x++) {
memcpy(screenbuffer[y-1][x], screenbuffer[y][x], sizeof(struct character_t)); memcpy(screenbuffer[y - 1][x], screenbuffer[y][x], sizeof(struct character_t));
color = screenbuffer[y][x]->color; color = screenbuffer[y][x]->color;
} }
} }
for (x = 0;x<80;x++) { for (x = 0; x < 80; x++) {
screenbuffer[22][x]->c = '\0'; screenbuffer[22][x]->c = '\0';
screenbuffer[22][x]->color = color; screenbuffer[22][x]->color = color;
} }
@ -88,7 +87,7 @@ void raw(char *fmt, ...) {
write(chat_socket, sbuf, strlen(sbuf)); 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; struct addrinfo hints, *res, *p;
int status; int status;
struct sockaddr_in6 *ipv6; struct sockaddr_in6 *ipv6;
@ -103,7 +102,7 @@ int hostname_to_ip6(char * hostname , char* ip) {
return 1; 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) { if (p->ai_family == AF_INET6) {
ipv6 = (struct sockaddr_in6 *)p->ai_addr; ipv6 = (struct sockaddr_in6 *)p->ai_addr;
inet_ntop(p->ai_family, &(ipv6->sin6_addr), ip, INET6_ADDRSTRLEN); 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; return 1;
} }
int hostname_to_ip(char * hostname , char* ip) { int hostname_to_ip(char *hostname, char *ip) {
struct addrinfo hints, *res, *p; struct addrinfo hints, *res, *p;
int status; int status;
struct sockaddr_in *ipv4; struct sockaddr_in *ipv4;
@ -130,7 +129,7 @@ int hostname_to_ip(char * hostname , char* ip) {
return 1; 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) { if (p->ai_family == AF_INET) {
ipv4 = (struct sockaddr_in *)p->ai_addr; ipv4 = (struct sockaddr_in *)p->ai_addr;
inet_ntop(p->ai_family, &(ipv4->sin_addr), ip, INET_ADDRSTRLEN); 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 last_pos = 0;
int curr_color = 7; int curr_color = 7;
for (z=0;z<strlen(buffer);z++) { for (z = 0; z < strlen(buffer); z++) {
if (buffer[z] == '\\') { if (buffer[z] == '\\') {
z++; z++;
} }
if (buffer[z] == '|') { if (buffer[z] == '|') {
z++; z++;
if ((buffer[z] - '0' <= 2 && buffer[z] - '0' >= 0) && (buffer[z+1] - '0' <= 9 && buffer[z+1] - '0' >= 0)) { 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'); curr_color = (buffer[z] - '0') * 10 + (buffer[z + 1] - '0');
z+=2; z += 2;
} else { } else {
z--; z--;
} }
@ -165,19 +164,19 @@ void append_screenbuffer(char *buffer) {
if (row_at == 79) { if (row_at == 79) {
if (line_at == 22) { if (line_at == 22) {
if (last_space > 0) { 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]->c = '\0';
screenbuffer[line_at][i]->color = curr_color; screenbuffer[line_at][i]->color = curr_color;
} }
} }
scroll_up(); scroll_up();
row_at = 0; row_at = 0;
for (i=last_pos+1;i<z;i++) { for (i = last_pos + 1; i < z; i++) {
if (buffer[i] == '|') { if (buffer[i] == '|') {
i++; i++;
if ((buffer[i] - '0' <= 2 && buffer[i] - '0' >= 0) && (buffer[i+1] - '0' <= 9 && buffer[i+1] - '0' >= 0)) { 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'); curr_color = (buffer[i] - '0') * 10 + (buffer[i + 1] - '0');
i+=2; i += 2;
} else { } else {
i--; i--;
} }
@ -191,19 +190,19 @@ void append_screenbuffer(char *buffer) {
last_pos = 0; last_pos = 0;
} else { } else {
if (last_space > 0) { 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]->c = '\0';
screenbuffer[line_at][i]->color = curr_color; screenbuffer[line_at][i]->color = curr_color;
} }
} }
line_at++; line_at++;
row_at = 0; row_at = 0;
for (i=last_pos+1;i<z;i++) { for (i = last_pos + 1; i < z; i++) {
if (buffer[i] == '|') { if (buffer[i] == '|') {
i++; i++;
if ((buffer[i] - '0' <= 2 && buffer[i] - '0' >= 0) && (buffer[i+1] - '0' <= 9 && buffer[i+1] - '0' >= 0)) { 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'); curr_color = (buffer[i] - '0') * 10 + (buffer[i + 1] - '0');
i+=2; i += 2;
} else { } else {
i--; i--;
} }
@ -284,8 +283,6 @@ void chat_system(struct user_record *user) {
return; return;
} }
row_at = 0; row_at = 0;
line_at = 0; line_at = 0;
s_putstring("\e[2J\e[23;1H"); s_putstring("\e[2J\e[23;1H");
@ -301,10 +298,10 @@ void chat_system(struct user_record *user) {
} else { } else {
servaddr6.sin6_family = AF_INET6; servaddr6.sin6_family = AF_INET6;
servaddr6.sin6_port = htons(conf.mgchat_port); servaddr6.sin6_port = htons(conf.mgchat_port);
if ( (chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { if ((chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
chat_connected = 0; chat_connected = 0;
} else { } else {
if (connect(chat_socket, (struct sockaddr*)&servaddr6, sizeof(servaddr6)) < 0 ) { if (connect(chat_socket, (struct sockaddr *)&servaddr6, sizeof(servaddr6)) < 0) {
chat_connected = 0; chat_connected = 0;
} else { } else {
chat_connected = 1; chat_connected = 1;
@ -317,10 +314,10 @@ void chat_system(struct user_record *user) {
} else { } else {
servaddr6.sin6_family = AF_INET6; servaddr6.sin6_family = AF_INET6;
servaddr6.sin6_port = htons(conf.mgchat_port); servaddr6.sin6_port = htons(conf.mgchat_port);
if ( (chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { if ((chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
chat_connected = 0; chat_connected = 0;
} else { } else {
if (connect(chat_socket, (struct sockaddr*)&servaddr6, sizeof(servaddr6)) < 0 ) { if (connect(chat_socket, (struct sockaddr *)&servaddr6, sizeof(servaddr6)) < 0) {
chat_connected = 0; chat_connected = 0;
} else { } else {
chat_connected = 1; chat_connected = 1;
@ -338,10 +335,10 @@ void chat_system(struct user_record *user) {
} else { } else {
servaddr.sin_family = AF_INET; servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(conf.mgchat_port); servaddr.sin_port = htons(conf.mgchat_port);
if ( (chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { if ((chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
return; return;
} }
if (connect(chat_socket, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0 ) { if (connect(chat_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
return; return;
} }
} }
@ -351,23 +348,21 @@ void chat_system(struct user_record *user) {
} else { } else {
servaddr.sin_family = AF_INET; servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(conf.mgchat_port); servaddr.sin_port = htons(conf.mgchat_port);
if ( (chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { if ((chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
return; return;
} }
if (connect(chat_socket, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0 ) { if (connect(chat_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
return; return;
} }
} }
} }
memset(buffer, 0, 513); memset(buffer, 0, 513);
screenbuffer = (struct character_t ***)malloc(sizeof(struct character_t **) * 23); 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); 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] = (struct character_t *)malloc(sizeof(struct character_t));
screenbuffer[i][z]->c = '\0'; screenbuffer[i][z]->c = '\0';
screenbuffer[i][z]->color = 7; screenbuffer[i][z]->color = 7;
@ -404,7 +399,7 @@ void chat_system(struct user_record *user) {
if (inputbuffer[0] == '/') { if (inputbuffer[0] == '/') {
if (strcasecmp(&inputbuffer[1], "quit") == 0) { if (strcasecmp(&inputbuffer[1], "quit") == 0) {
close(chat_socket); close(chat_socket);
for (i=0;i<22;i++) { for (i = 0; i < 22; i++) {
free(screenbuffer[i]); free(screenbuffer[i]);
} }
free(screenbuffer); free(screenbuffer);
@ -437,7 +432,7 @@ void chat_system(struct user_record *user) {
len = read(chat_socket, readbuffer, 512); len = read(chat_socket, readbuffer, 512);
if (len == 0) { if (len == 0) {
s_putstring("\r\n\r\n\r\nLost connection to chat server!\r\n"); 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[i]);
} }
free(screenbuffer); free(screenbuffer);
@ -448,10 +443,10 @@ void chat_system(struct user_record *user) {
strcpy(readbuffer, partmessage); strcpy(readbuffer, partmessage);
y = 0; y = 0;
for (z = 0;z < strlen(readbuffer); z++) { for (z = 0; z < strlen(readbuffer); z++) {
if (readbuffer[z] != '\n') { if (readbuffer[z] != '\n') {
message[y] = readbuffer[z]; message[y] = readbuffer[z];
message[y+1] = '\0'; message[y + 1] = '\0';
y++; y++;
} else { } else {
@ -459,22 +454,22 @@ void chat_system(struct user_record *user) {
// json parse // json parse
jsmn_init(&parser); jsmn_init(&parser);
// we got some data from a client // we got some data from a client
r = jsmn_parse(&parser, message, strlen(message), tokens, sizeof(tokens)/sizeof(tokens[0])); r = jsmn_parse(&parser, message, strlen(message), tokens, sizeof(tokens) / sizeof(tokens[0]));
if ((r < 0) || (r < 1 || tokens[0].type != JSMN_OBJECT)) { if ((r < 0) || (r < 1 || tokens[0].type != JSMN_OBJECT)) {
// invalid json // invalid json
} else { } else {
for (j = 1; j < r; j++) { for (j = 1; j < r; j++) {
if (jsoneq(message, &tokens[j], "bbs") == 0) { 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++; j++;
} }
if (jsoneq(message, &tokens[j], "nick") == 0) { 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++; j++;
} }
if (jsoneq(message, &tokens[j], "msg") == 0) { 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++; j++;
} }
} }
@ -493,11 +488,9 @@ void chat_system(struct user_record *user) {
append_screenbuffer(outputbuffer); append_screenbuffer(outputbuffer);
do_update = 1; do_update = 1;
memset(buffer, 0, 513); memset(buffer, 0, 513);
buffer_at = 0; buffer_at = 0;
} }
} }
if (z < len) { if (z < len) {
memset(partmessage, 0, 1024); memset(partmessage, 0, 1024);
@ -509,8 +502,8 @@ void chat_system(struct user_record *user) {
} }
if (do_update == 1) { if (do_update == 1) {
s_putstring("\e[2J\e[1;1H"); s_putstring("\e[2J\e[1;1H");
for (i=0;i<=line_at;i++) { for (i = 0; i <= line_at; i++) {
for (z = 0;z < 80; z++) { for (z = 0; z < 80; z++) {
if (screenbuffer[i][z]->color != last_color) { if (screenbuffer[i][z]->color != last_color) {
switch (screenbuffer[i][z]->color) { switch (screenbuffer[i][z]->color) {
case 0: case 0:
@ -572,7 +565,7 @@ void chat_system(struct user_record *user) {
} }
s_printf("\r\n"); 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("\r\n");
} }
s_putstring(get_string(50)); s_putstring(get_string(50));

View File

@ -11,13 +11,13 @@
#include <fcntl.h> #include <fcntl.h>
#include <iconv.h> #include <iconv.h>
#if defined(linux) #if defined(linux)
# include <pty.h> #include <pty.h>
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
# include <util.h> #include <util.h>
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
# include <libutil.h> #include <libutil.h>
#elif defined(__sun) #elif defined(__sun)
# include "os/sunos.h" #include "os/sunos.h"
#endif #endif
#include "bbs.h" #include "bbs.h"
#include "lua/lua.h" #include "lua/lua.h"
@ -36,10 +36,10 @@ int running_door = 0;
extern int telnet_bin_mode; extern int telnet_bin_mode;
extern int timeoutpaused; extern int timeoutpaused;
void doorchld_handler(int s) void doorchld_handler(int s) {
{
// waitpid() might overwrite errno, so we save and restore it: // waitpid() might overwrite errno, so we save and restore it:
while(waitpid(-1, NULL, WNOHANG) > 0); while (waitpid(-1, NULL, WNOHANG) > 0)
;
running_door = 0; running_door = 0;
} }
@ -95,9 +95,9 @@ int write_door32sys(struct user_record *user) {
ptr = NULL; ptr = NULL;
for (i=0;i<strlen(buffer);i++) { for (i = 0; i < strlen(buffer); i++) {
if (buffer[i] == ' ') { if (buffer[i] == ' ') {
ptr = &buffer[i+1]; ptr = &buffer[i + 1];
buffer[i] = '\0'; buffer[i] = '\0';
break; break;
} }
@ -192,8 +192,6 @@ int write_door32sys(struct user_record *user) {
return 0; return 0;
} }
void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage) { void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage) {
char *arguments[4]; char *arguments[4];
int door_out; int door_out;
@ -276,8 +274,6 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
door_out = gSocket; door_out = gSocket;
} }
ws.ws_row = 24; ws.ws_row = 24;
ws.ws_col = 80; ws.ws_col = 80;
@ -320,7 +316,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
gotiac = 0; gotiac = 0;
flush = 0; flush = 0;
while(running_door || !flush) { while (running_door || !flush) {
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(master, &fdset); FD_SET(master, &fdset);
FD_SET(door_in, &fdset); FD_SET(door_in, &fdset);
@ -343,7 +339,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
return; return;
} }
g = 0; g = 0;
for (h=0;h<len;h++) { for (h = 0; h < len; h++) {
c = inbuf[h]; c = inbuf[h];
if (!raw) { if (!raw) {
if (c == '\n' || c == '\0') { if (c == '\n' || c == '\0') {
@ -444,7 +440,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
break; break;
} }
g = 0; g = 0;
for (h=0;h<len;h++) { for (h = 0; h < len; h++) {
c = inbuf[h]; c = inbuf[h];
if (c == 255) { if (c == 255) {
outbuf[g++] = c; outbuf[g++] = c;
@ -510,7 +506,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
dup2(bbs_stderr, 2); dup2(bbs_stderr, 2);
execvp(cmd, argv); execvp(cmd, argv);
} else { } else {
while(running_door) { while (running_door) {
sleep(1); sleep(1);
} }
} }
@ -523,13 +519,13 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
} else { } else {
if (!sshBBS) { if (!sshBBS) {
snprintf(buffer, 1024, "%s", cmd); 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]); snprintf(&buffer[strlen(buffer)], 1024 - strlen(buffer), " %s", argv[i]);
} }
if (cwd != NULL) { if (cwd != NULL) {
chdir(cwd); chdir(cwd);
} }
args = (char **)malloc(sizeof (char *)); args = (char **)malloc(sizeof(char *));
arg_count = 0; arg_count = 0;
args[arg_count] = strtok(buffer, " "); args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) { while (args[arg_count] != NULL) {

View File

@ -45,7 +45,7 @@ void commit_email(char *recipient, char *subject, char *msg) {
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, csql, 0, 0, &err_msg); rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg); dolog("SQL error: %s", err_msg);
@ -82,7 +82,6 @@ void send_email(struct user_record *user) {
char *subject; char *subject;
char *msg; char *msg;
s_printf(get_string(54)); s_printf(get_string(54));
s_readstring(buffer, 16); s_readstring(buffer, 16);
@ -156,12 +155,11 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
lines = 0; lines = 0;
chars = 0; chars = 0;
msg_line_count = 0; msg_line_count = 0;
start_line = 0; start_line = 0;
// count the number of lines... // count the number of lines...
for (z=0;z<strlen(emails[msgno]->body);z++) { for (z = 0; z < strlen(emails[msgno]->body); z++) {
if (emails[msgno]->body[z] == '\r' || chars == 79) { if (emails[msgno]->body[z] == '\r' || chars == 79) {
if (msg_line_count == 0) { if (msg_line_count == 0) {
msg_lines = (char **)malloc(sizeof(char *)); msg_lines = (char **)malloc(sizeof(char *));
@ -175,7 +173,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
msg_lines[msg_line_count][0] = '\0'; msg_lines[msg_line_count][0] = '\0';
} else { } else {
strncpy(msg_lines[msg_line_count], &emails[msgno]->body[start_line], z - start_line); strncpy(msg_lines[msg_line_count], &emails[msgno]->body[start_line], z - start_line);
msg_lines[msg_line_count][z-start_line] = '\0'; msg_lines[msg_line_count][z - start_line] = '\0';
} }
msg_line_count++; msg_line_count++;
if (emails[msgno]->body[z] == '\r') { if (emails[msgno]->body[z] == '\r') {
@ -185,7 +183,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
} }
chars = 0; chars = 0;
} else { } else {
chars ++; chars++;
} }
} }
@ -196,7 +194,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
while (!should_break) { while (!should_break) {
s_printf("\e[5;1H"); s_printf("\e[5;1H");
for (z=position;z<msg_line_count;z++) { for (z = position; z < msg_line_count; z++) {
s_printf("%s\e[K\r\n", msg_lines[z]); s_printf("%s\e[K\r\n", msg_lines[z]);
@ -240,7 +238,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
} }
} }
for (i=0;i<msg_line_count;i++) { for (i = 0; i < msg_line_count; i++) {
free(msg_lines[i]); free(msg_lines[i]);
} }
free(msg_lines); free(msg_lines);
@ -272,7 +270,6 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
if (tolower(c) == 'r') { if (tolower(c) == 'r') {
if (emails[msgno]->subject != NULL) { if (emails[msgno]->subject != NULL) {
if (strncasecmp(emails[msgno]->subject, "RE:", 3) != 0) { if (strncasecmp(emails[msgno]->subject, "RE:", 3) != 0) {
@ -346,7 +343,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
sqlite3_close(db); sqlite3_close(db);
quit = 1; quit = 1;
} else if (tolower(c) == ' ') { } else if (tolower(c) == ' ') {
msgno ++; msgno++;
if (msgno == email_count) { if (msgno == email_count) {
quit = 1; quit = 1;
} }
@ -432,34 +429,34 @@ void list_emails(struct user_record *user) {
while (!closed) { while (!closed) {
if (redraw) { if (redraw) {
s_printf(get_string(126)); s_printf(get_string(126));
for (i=start;i<start + 22 && i<email_count;i++) { for (i = start; i < start + 22 && i < email_count; i++) {
localtime_r((time_t *)&emails[i]->date, &msg_date); localtime_r((time_t *)&emails[i]->date, &msg_date);
if (i == position) { if (i == position) {
if (!emails[i]->seen) { if (!emails[i]->seen) {
if (conf.date_style == 1) { 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 { } 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 { } else {
if (conf.date_style == 1) { 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 { } 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 { } else {
if (!emails[i]->seen) { if (!emails[i]->seen) {
if (conf.date_style == 1) { 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 { } 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 { } else {
if (conf.date_style == 1) { 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 { } 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,18 +487,18 @@ void list_emails(struct user_record *user) {
s_printf("\e[%d;5H", position - start + 2); s_printf("\e[%d;5H", position - start + 2);
} else if (!redraw) { } else if (!redraw) {
s_printf("\e[%d;1H", position - start + 1); 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 (!emails[position - 1]->seen) {
if (conf.date_style == 1) { 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 { } 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 { } else {
if (conf.date_style == 1) { 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 { } 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); s_printf("\e[%d;1H", position - start + 2);
@ -525,7 +522,7 @@ void list_emails(struct user_record *user) {
// up // up
position--; position--;
if (position < start) { if (position < start) {
start -=22; start -= 22;
if (start < 0) { if (start < 0) {
start = 0; start = 0;
} }
@ -599,7 +596,7 @@ void list_emails(struct user_record *user) {
// PAGE DOWN // PAGE DOWN
position = position + 22; position = position + 22;
if (position >= email_count) { if (position >= email_count) {
position = email_count -1; position = email_count - 1;
} }
start = position; start = position;
redraw = 1; redraw = 1;
@ -611,7 +608,7 @@ void list_emails(struct user_record *user) {
} }
} }
for (i=0;i<email_count;i++) { for (i = 0; i < email_count; i++) {
free(emails[i]->from); free(emails[i]->from);
free(emails[i]->subject); free(emails[i]->subject);
free(emails[i]->body); free(emails[i]->body);
@ -620,7 +617,6 @@ void list_emails(struct user_record *user) {
free(emails); free(emails);
} }
int mail_getemailcount(struct user_record *user) { int mail_getemailcount(struct user_record *user) {
char *sql = "SELECT COUNT(*) FROM email WHERE recipient LIKE ?"; char *sql = "SELECT COUNT(*) FROM email WHERE recipient LIKE ?";
int count; int count;

View File

@ -73,7 +73,7 @@ int ttySetRaw(int fd, struct termios *prevTermios) {
int ZXmitStr(u_char *str, int len, ZModem *info) { int ZXmitStr(u_char *str, int len, ZModem *info) {
int i; int i;
for (i=0;i<len;i++) { for (i = 0; i < len; i++) {
if (str[i] == 255 && !sshBBS) { if (str[i] == 255 && !sshBBS) {
if (write(info->ofd, &str[i], 1) == 0) { if (write(info->ofd, &str[i], 1) == 0) {
return ZmErrSys; return ZmErrSys;
@ -94,18 +94,18 @@ void ZOFlush(ZModem *info) {
} }
int ZAttn(ZModem *info) { int ZAttn(ZModem *info) {
char *ptr ; char *ptr;
if( info->attn == NULL ) if (info->attn == NULL)
return 0 ; return 0;
for(ptr = info->attn; *ptr != '\0'; ++ptr) { for (ptr = info->attn; *ptr != '\0'; ++ptr) {
if( *ptr == ATTNBRK ) { if (*ptr == ATTNBRK) {
} else if( *ptr == ATTNPSE ) { } else if (*ptr == ATTNPSE) {
sleep(1); sleep(1);
} else { } else {
write(info->ifd, ptr, 1) ; write(info->ifd, ptr, 1);
} }
} }
return 0; return 0;
@ -117,7 +117,6 @@ void ZFlowControl(int onoff, ZModem *info) {
void ZStatus(int type, int value, char *status) { void ZStatus(int type, int value, char *status) {
} }
char *upload_path; char *upload_path;
char upload_filename[1024]; char upload_filename[1024];
@ -163,15 +162,15 @@ int doIO(ZModem *zm) {
char iac_binary_wont[] = {IAC, IAC_WONT, 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'}; char iac_binary_dont[] = {IAC, IAC_DONT, IAC_TRANSMIT_BINARY, '\0'};
while(!done) { while (!done) {
FD_ZERO(&readfds); FD_ZERO(&readfds);
FD_SET(zm->ifd, &readfds) ; FD_SET(zm->ifd, &readfds);
timeout.tv_sec = zm->timeout ; timeout.tv_sec = zm->timeout;
timeout.tv_usec = 0 ; timeout.tv_usec = 0;
i = select(zm->ifd+1, &readfds,NULL,NULL, &timeout) ; i = select(zm->ifd + 1, &readfds, NULL, NULL, &timeout);
if( i==0 ) { if (i == 0) {
done = ZmodemTimeout(zm) ; done = ZmodemTimeout(zm);
} else if (i > 0) { } else if (i > 0) {
len = read(zm->ifd, buffer, 2048); len = read(zm->ifd, buffer, 2048);
if (len == 0) { if (len == 0) {
@ -179,18 +178,18 @@ int doIO(ZModem *zm) {
} }
pos = 0; pos = 0;
for (j=0;j<len;j++) { for (j = 0; j < len; j++) {
if (buffer[j] == 255 && !sshBBS) { if (buffer[j] == 255 && !sshBBS) {
if (buffer[j+1] == 255) { if (buffer[j + 1] == 255) {
buffer2[pos] = 255; buffer2[pos] = 255;
pos++; pos++;
j++; j++;
} else { } else {
// IAC command // IAC command
if (buffer[j+1] == IAC_WILL || buffer[j+1] == IAC_WONT || buffer[j+1] == IAC_DO || buffer[j+1] == IAC_DONT) { if (buffer[j + 1] == IAC_WILL || buffer[j + 1] == IAC_WONT || buffer[j + 1] == IAC_DO || buffer[j + 1] == IAC_DONT) {
switch (buffer[j+1]) { switch (buffer[j + 1]) {
case IAC_WILL: case IAC_WILL:
if (buffer[j+2] == 0) { if (buffer[j + 2] == 0) {
if (telnet_bin_mode != 1) { if (telnet_bin_mode != 1) {
telnet_bin_mode = 1; telnet_bin_mode = 1;
write(gSocket, iac_binary_do, 3); write(gSocket, iac_binary_do, 3);
@ -198,7 +197,7 @@ int doIO(ZModem *zm) {
} }
break; break;
case IAC_WONT: case IAC_WONT:
if (buffer[j+2] == 0) { if (buffer[j + 2] == 0) {
if (telnet_bin_mode != 0) { if (telnet_bin_mode != 0) {
telnet_bin_mode = 0; telnet_bin_mode = 0;
write(gSocket, iac_binary_dont, 3); write(gSocket, iac_binary_dont, 3);
@ -206,7 +205,7 @@ int doIO(ZModem *zm) {
} }
break; break;
case IAC_DO: case IAC_DO:
if (buffer[j+2] == 0) { if (buffer[j + 2] == 0) {
if (telnet_bin_mode != 1) { if (telnet_bin_mode != 1) {
telnet_bin_mode = 1; telnet_bin_mode = 1;
write(gSocket, iac_binary_will, 3); write(gSocket, iac_binary_will, 3);
@ -214,7 +213,7 @@ int doIO(ZModem *zm) {
} }
break; break;
case IAC_DONT: case IAC_DONT:
if (buffer[j+2] == 0) { if (buffer[j + 2] == 0) {
if (telnet_bin_mode != 0) { if (telnet_bin_mode != 0) {
telnet_bin_mode = 0; telnet_bin_mode = 0;
write(gSocket, iac_binary_wont, 3); write(gSocket, iac_binary_wont, 3);
@ -222,12 +221,12 @@ int doIO(ZModem *zm) {
} }
break; break;
} }
j+= 2; j += 2;
} else if (buffer[j+1] == 250) { } else if (buffer[j + 1] == 250) {
j++; j++;
do { do {
j++; j++;
} while(buffer[j] != 240); } while (buffer[j] != 240);
} }
} }
} else { } else {
@ -236,7 +235,7 @@ int doIO(ZModem *zm) {
} }
} }
if (pos > 0) { if (pos > 0) {
done = ZmodemRcv(buffer2, pos, zm) ; done = ZmodemRcv(buffer2, pos, zm);
} }
} else { } else {
// SIG INT catch // SIG INT catch
@ -305,7 +304,7 @@ char *get_file_id_diz(char *filename) {
ext = 0; ext = 0;
arch = -1; arch = -1;
for (i=strlen(filename)-1;i>=0;i--) { for (i = strlen(filename) - 1; i >= 0; i--) {
if (filename[i] == '.') { if (filename[i] == '.') {
ext = i + 1; ext = i + 1;
break; break;
@ -316,7 +315,7 @@ char *get_file_id_diz(char *filename) {
return NULL; return NULL;
} }
for (i=0;i<conf.archiver_count;i++) { for (i = 0; i < conf.archiver_count; i++) {
if (strcasecmp(&filename[ext], conf.archivers[i]->extension) == 0) { if (strcasecmp(&filename[ext], conf.archivers[i]->extension) == 0) {
arch = i; arch = i;
break; break;
@ -343,7 +342,7 @@ char *get_file_id_diz(char *filename) {
mkdir(buffer, 0755); mkdir(buffer, 0755);
bpos = 0; bpos = 0;
for (i=0;i<strlen(conf.archivers[arch]->unpack);i++) { for (i = 0; i < strlen(conf.archivers[arch]->unpack); i++) {
if (conf.archivers[arch]->unpack[i] == '*') { if (conf.archivers[arch]->unpack[i] == '*') {
i++; i++;
if (conf.archivers[arch]->unpack[i] == 'a') { if (conf.archivers[arch]->unpack[i] == 'a') {
@ -371,7 +370,7 @@ char *get_file_id_diz(char *filename) {
dup2(bbs_stderr, STDERR_FILENO); dup2(bbs_stderr, STDERR_FILENO);
dup2(bbs_stdin, STDIN_FILENO); dup2(bbs_stdin, STDIN_FILENO);
} }
args = (char **)malloc(sizeof (char *)); args = (char **)malloc(sizeof(char *));
arg_count = 0; arg_count = 0;
args[arg_count] = strtok(buffer, " "); args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) { while (args[arg_count] != NULL) {
@ -423,12 +422,11 @@ char *get_file_id_diz(char *filename) {
bpos = 0; bpos = 0;
len = strlen(description); len = strlen(description);
for (i=0;i<len;i++) { for (i = 0; i < len; i++) {
if (description[i] == '\r') { if (description[i] == '\r') {
continue; continue;
} else { } else {
description[bpos++] = description[i]; description[bpos++] = description[i];
} }
} }
description[bpos] = '\0'; description[bpos] = '\0';
@ -472,7 +470,7 @@ int do_download(struct user_record *user, char *file) {
return 1; return 1;
} else { } else {
bpos = 0; bpos = 0;
for (i=0;i<strlen(conf.protocols[user->defprotocol - 1]->download);i++) { for (i = 0; i < strlen(conf.protocols[user->defprotocol - 1]->download); i++) {
if (conf.protocols[user->defprotocol - 1]->download[i] == '*') { if (conf.protocols[user->defprotocol - 1]->download[i] == '*') {
i++; i++;
if (conf.protocols[user->defprotocol - 1]->download[i] == '*') { if (conf.protocols[user->defprotocol - 1]->download[i] == '*') {
@ -501,7 +499,7 @@ int do_download(struct user_record *user, char *file) {
} }
argc = 1; argc = 1;
last_char_space = 0; last_char_space = 0;
for (i=0;i<strlen(download_command);i++) { for (i = 0; i < strlen(download_command); i++) {
if (download_command[i] == ' ') { if (download_command[i] == ' ') {
if (!last_char_space) { if (!last_char_space) {
argc++; argc++;
@ -514,7 +512,7 @@ int do_download(struct user_record *user, char *file) {
bpos = 1; bpos = 1;
arguments = (char **)malloc(sizeof(char *) * (argc + 1)); arguments = (char **)malloc(sizeof(char *) * (argc + 1));
len = strlen(download_command); len = strlen(download_command);
for (i=0;i<len;) { for (i = 0; i < len;) {
if (download_command[i] != ' ') { if (download_command[i] != ' ') {
i++; i++;
continue; continue;
@ -579,7 +577,7 @@ int do_upload(struct user_record *user, char *final_path) {
s_printf("\r\n"); s_printf("\r\n");
} }
bpos = 0; bpos = 0;
for (i=0;i<strlen(conf.protocols[user->defprotocol - 1]->upload);i++) { for (i = 0; i < strlen(conf.protocols[user->defprotocol - 1]->upload); i++) {
if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') { if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') {
i++; i++;
if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') { if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') {
@ -609,7 +607,7 @@ int do_upload(struct user_record *user, char *final_path) {
} }
argc = 1; argc = 1;
last_char_space = 0; last_char_space = 0;
for (i=0;i<strlen(upload_command);i++) { for (i = 0; i < strlen(upload_command); i++) {
if (upload_command[i] == ' ') { if (upload_command[i] == ' ') {
if (!last_char_space) { if (!last_char_space) {
argc++; argc++;
@ -622,7 +620,7 @@ int do_upload(struct user_record *user, char *final_path) {
bpos = 1; bpos = 1;
arguments = (char **)malloc(sizeof(char *) * (argc + 1)); arguments = (char **)malloc(sizeof(char *) * (argc + 1));
len = strlen(upload_command); len = strlen(upload_command);
for (i=0;i<len;) { for (i = 0; i < len;) {
if (upload_command[i] != ' ') { if (upload_command[i] != ' ') {
i++; i++;
continue; continue;
@ -710,7 +708,6 @@ int do_upload(struct user_record *user, char *final_path) {
recursive_delete(upload_path); recursive_delete(upload_path);
return 1; return 1;
} }
} }
closedir(inb); closedir(inb);
@ -755,7 +752,7 @@ void upload(struct user_record *user) {
s_printf(get_string(199)); s_printf(get_string(199));
s_printf(get_string(200)); s_printf(get_string(200));
buffer[0] = '\0'; buffer[0] = '\0';
for (i=0;i<5;i++) { for (i = 0; i < 5; i++) {
s_printf("\r\n%d: ", i); s_printf("\r\n%d: ", i);
s_readstring(buffer2, 65); s_readstring(buffer2, 65);
if (strlen(buffer2) == 0) { if (strlen(buffer2) == 0) {
@ -779,7 +776,7 @@ void upload(struct user_record *user) {
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg); dolog("SQL error: %s", err_msg);
sqlite3_free(err_msg); sqlite3_free(err_msg);
sqlite3_close(db); sqlite3_close(db);
@ -836,7 +833,7 @@ void upload(struct user_record *user) {
void download_zmodem(struct user_record *user, char *filename) { void download_zmodem(struct user_record *user, char *filename) {
ZModem zm; ZModem zm;
int done ; int done;
dolog("Attempting to upload %s", filename); dolog("Attempting to upload %s", filename);
@ -856,25 +853,24 @@ void download_zmodem(struct user_record *user, char *filename) {
zm.packetsize = 1024; zm.packetsize = 1024;
ZmodemTInit(&zm);
ZmodemTInit(&zm) ;
done = doIO(&zm); done = doIO(&zm);
if ( done != ZmDone ) { if (done != ZmDone) {
return; 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 ) { switch (done) {
case 0: case 0:
break ; break;
case ZmErrCantOpen: case ZmErrCantOpen:
dolog("cannot open file \"%s\": %s", filename, strerror(errno)) ; dolog("cannot open file \"%s\": %s", filename, strerror(errno));
return; return;
case ZmFileTooLong: case ZmFileTooLong:
dolog("filename \"%s\" too long, skipping...", filename) ; dolog("filename \"%s\" too long, skipping...", filename);
return; return;
case ZmDone: case ZmDone:
@ -888,7 +884,7 @@ void download_zmodem(struct user_record *user, char *filename) {
done = doIO(&zm); done = doIO(&zm);
} }
if ( done != ZmDone ) { if (done != ZmDone) {
return; return;
} }
@ -899,13 +895,12 @@ void download_zmodem(struct user_record *user, char *filename) {
} }
} }
void genurls() { void genurls() {
#if defined(ENABLE_WWW) #if defined(ENABLE_WWW)
int i; int i;
char *url; char *url;
if (conf.www_server) { if (conf.www_server) {
for (i=0;i<tagged_count;i++) { for (i = 0; i < tagged_count; i++) {
if (i % 6 == 0 && i != 0) { if (i % 6 == 0 && i != 0) {
// pause // pause
s_printf(get_string(6)); s_printf(get_string(6));
@ -922,7 +917,7 @@ void genurls() {
s_printf(get_string(257)); s_printf(get_string(257));
} }
} }
for (i=0;i<tagged_count;i++) { for (i = 0; i < tagged_count; i++) {
free(tagged_files[i]->filename); free(tagged_files[i]->filename);
free(tagged_files[i]); free(tagged_files[i]);
} }
@ -942,7 +937,6 @@ void genurls() {
#endif #endif
} }
void download(struct user_record *user) { void download(struct user_record *user) {
int i; int i;
char *ssql = "select dlcount from files where filename like ?"; char *ssql = "select dlcount from files where filename like ?";
@ -953,8 +947,7 @@ void download(struct user_record *user) {
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
for (i = 0; i < tagged_count; i++) {
for (i=0;i<tagged_count;i++) {
s_printf(get_string(254), basename(tagged_files[i]->filename)); s_printf(get_string(254), basename(tagged_files[i]->filename));
do_download(user, tagged_files[i]->filename); do_download(user, tagged_files[i]->filename);
@ -1005,9 +998,7 @@ void download(struct user_record *user) {
sqlite3_close(db); sqlite3_close(db);
} }
for (i = 0; i < tagged_count; i++) {
for (i=0;i<tagged_count;i++) {
free(tagged_files[i]->filename); free(tagged_files[i]->filename);
free(tagged_files[i]); free(tagged_files[i]);
} }
@ -1028,7 +1019,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
s_printf("\r\n"); s_printf("\r\n");
for (i=0;i<files_c;i++) { for (i = 0; i < files_c; i++) {
file_size = files_e[i]->size; file_size = files_e[i]->size;
if (file_size > 1024 * 1024 * 1024) { if (file_size > 1024 * 1024 * 1024) {
file_size = 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 { } else {
s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename));
} }
lines+=3; lines += 3;
for (j=0;j<strlen(files_e[i]->description);j++) { for (j = 0; j < strlen(files_e[i]->description); j++) {
if (files_e[i]->description[j] == '\n') { if (files_e[i]->description[j] == '\n') {
s_printf("\r\n"); s_printf("\r\n");
lines++; lines++;
@ -1061,7 +1052,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
s_printf("\r\n"); s_printf("\r\n");
break; break;
} else if (tolower(buffer[0]) == 'q') { } else if (tolower(buffer[0]) == 'q') {
for (z=0;z<files_c;z++) { for (z = 0; z < files_c; z++) {
free(files_e[z]->filename); free(files_e[z]->filename);
free(files_e[z]->description); free(files_e[z]->description);
free(files_e[z]); free(files_e[z]);
@ -1074,7 +1065,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
if (z >= 0 && z < 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) { if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) {
match = 0; match = 0;
for (k=0;k<tagged_count;k++) { for (k = 0; k < tagged_count; k++) {
if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) { if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) {
match = 1; match = 1;
break; break;
@ -1119,7 +1110,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
s_printf("\r\n"); s_printf("\r\n");
break; break;
} else if (tolower(buffer[0]) == 'q') { } else if (tolower(buffer[0]) == 'q') {
for (z=0;z<files_c;z++) { for (z = 0; z < files_c; z++) {
free(files_e[z]->filename); free(files_e[z]->filename);
free(files_e[z]->description); free(files_e[z]->description);
free(files_e[z]); free(files_e[z]);
@ -1132,7 +1123,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
if (z >= 0 && z < 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) { if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) {
match = 0; match = 0;
for (k=0;k<tagged_count;k++) { for (k = 0; k < tagged_count; k++) {
if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) { if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) {
match = 1; match = 1;
break; break;
@ -1166,7 +1157,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
s_printf(get_string(75)); s_printf(get_string(75));
s_readstring(buffer, 5); s_readstring(buffer, 5);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
for (z=0;z<files_c;z++) { for (z = 0; z < files_c; z++) {
free(files_e[z]->filename); free(files_e[z]->filename);
free(files_e[z]->description); free(files_e[z]->description);
free(files_e[z]); 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 (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) { if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) {
match = 0; match = 0;
for (k=0;k<tagged_count;k++) { for (k = 0; k < tagged_count; k++) {
if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) { if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) {
match = 1; match = 1;
break; break;
@ -1231,7 +1222,7 @@ void file_search() {
s_printf(get_string(236)); s_printf(get_string(236));
ch = s_getc(); ch = s_getc();
switch(tolower(ch)) { switch (tolower(ch)) {
case 'd': case 'd':
stype = 1; stype = 1;
break; break;
@ -1270,25 +1261,25 @@ void file_search() {
} }
if (stype == 0) { if (stype == 0) {
snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename LIKE ?"); 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 filename LIKE ?", 1024);
} }
strncat(sqlbuffer, ")", 1024); strncat(sqlbuffer, ")", 1024);
} }
if (stype == 1) { if (stype == 1) {
snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (description LIKE ?"); 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, " OR description LIKE ?", 1024);
} }
strncat(sqlbuffer, ")", 1024); strncat(sqlbuffer, ")", 1024);
} }
if (stype == 2) { if (stype == 2) {
snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename LIKE ?"); 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 filename LIKE ?", 1024);
} }
strncat(sqlbuffer, " OR description 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, " OR description LIKE ?", 1024);
} }
strncat(sqlbuffer, ")", 1024); strncat(sqlbuffer, ")", 1024);
@ -1311,26 +1302,24 @@ void file_search() {
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
for (i=0;i<searchterm_count;i++) { for (i = 0; i < searchterm_count; i++) {
free(searchterms[i]); free(searchterms[i]);
} }
free(searchterms); free(searchterms);
return; return;
} }
if (stype == 2) { if (stype == 2) {
for (j=0;j<2;j++) { for (j = 0; j < 2; j++) {
for (i=0;i<searchterm_count;i++) { for (i = 0; i < searchterm_count; i++) {
sqlite3_bind_text(res, j * searchterm_count + i + 1, searchterms[i], -1, 0); sqlite3_bind_text(res, j * searchterm_count + i + 1, searchterms[i], -1, 0);
} }
} }
} else { } else {
for (i=0;i<searchterm_count;i++) { for (i = 0; i < searchterm_count; i++) {
sqlite3_bind_text(res, i + 1, searchterms[i], -1, 0); sqlite3_bind_text(res, i + 1, searchterms[i], -1, 0);
} }
} }
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
if (files_c == 0) { if (files_c == 0) {
files_e = (struct file_entry **)malloc(sizeof(struct file_entry *)); files_e = (struct file_entry **)malloc(sizeof(struct file_entry *));
@ -1382,13 +1371,13 @@ void file_search() {
continue; continue;
} }
if (stype == 2) { if (stype == 2) {
for (j=0;j<2;j++) { for (j = 0; j < 2; j++) {
for (i=0;i<searchterm_count;i++) { for (i = 0; i < searchterm_count; i++) {
sqlite3_bind_text(res, j * searchterm_count + i + 1, searchterms[i], -1, 0); sqlite3_bind_text(res, j * searchterm_count + i + 1, searchterms[i], -1, 0);
} }
} }
} else { } else {
for (i=0;i<searchterm_count;i++) { for (i = 0; i < searchterm_count; i++) {
sqlite3_bind_text(res, i + 1, searchterms[i], -1, 0); sqlite3_bind_text(res, i + 1, searchterms[i], -1, 0);
} }
} }
@ -1419,7 +1408,7 @@ void file_search() {
do_list_files(files_e, files_c); do_list_files(files_e, files_c);
} }
} }
for (i=0;i<searchterm_count;i++) { for (i = 0; i < searchterm_count; i++) {
free(searchterms[i]); free(searchterms[i]);
} }
free(searchterms); free(searchterms);
@ -1443,7 +1432,7 @@ void list_files(struct user_record *user) {
s_printf(get_string(233)); s_printf(get_string(233));
ch = s_getc(); ch = s_getc();
switch(tolower(ch)) { switch (tolower(ch)) {
case 'u': case 'u':
sql = dsql; sql = dsql;
break; break;
@ -1456,7 +1445,6 @@ void list_files(struct user_record *user) {
default: default:
sql = fsql; sql = fsql;
break; break;
} }
s_printf("\r\n"); s_printf("\r\n");
snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database); snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database);
@ -1479,8 +1467,6 @@ void list_files(struct user_record *user) {
sqlite3_bind_int(res, 1, userlaston); sqlite3_bind_int(res, 1, userlaston);
} }
files_c = 0; files_c = 0;
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
@ -1525,7 +1511,7 @@ void choose_subdir() {
int selected = 0; int selected = 0;
char c; char c;
for (i=0;i<conf.file_directories[gUser->cur_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 (conf.file_directories[gUser->cur_file_dir]->file_subs[i]->download_sec_level <= gUser->sec_level) {
if (list_tmp == 0) { if (list_tmp == 0) {
sub_tmp = (struct subdir_tmp_t **)malloc(sizeof(struct subdir_tmp_t *)); 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("\e[2J\e[1;1H");
s_printf(get_string(252), conf.file_directories[gUser->cur_file_dir]->name); s_printf(get_string(252), conf.file_directories[gUser->cur_file_dir]->name);
s_printf(get_string(248)); s_printf(get_string(248));
for (i=start;i<start+22 && i < list_tmp;i++) { for (i = start; i < start + 22 && i < list_tmp; i++) {
if (i == selected) { if (i == selected) {
s_printf(get_string(249), i - start + 2, sub_tmp[i]->index, sub_tmp[i]->sub->name); s_printf(get_string(249), i - start + 2, sub_tmp[i]->index, sub_tmp[i]->sub->name);
} else { } else {
@ -1631,7 +1617,7 @@ void choose_subdir() {
// PAGE DOWN // PAGE DOWN
selected = selected + 22; selected = selected + 22;
if (selected >= list_tmp) { if (selected >= list_tmp) {
selected = list_tmp -1; selected = list_tmp - 1;
} }
start = selected; start = selected;
redraw = 1; redraw = 1;
@ -1643,7 +1629,7 @@ void choose_subdir() {
} }
} }
for (i=0;i<list_tmp;i++) { for (i = 0; i < list_tmp; i++) {
free(sub_tmp[i]); free(sub_tmp[i]);
} }
free(sub_tmp); free(sub_tmp);
@ -1663,7 +1649,7 @@ void choose_directory() {
int selected = 0; int selected = 0;
char c; char c;
for (i=0;i<conf.file_directory_count;i++) { for (i = 0; i < conf.file_directory_count; i++) {
if (conf.file_directories[i]->sec_level <= gUser->sec_level) { if (conf.file_directories[i]->sec_level <= gUser->sec_level) {
if (list_tmp == 0) { if (list_tmp == 0) {
dir_tmp = (struct dir_tmp_t **)malloc(sizeof(struct dir_tmp_t *)); 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("\e[2J\e[1;1H");
s_printf(get_string(253)); s_printf(get_string(253));
s_printf(get_string(248)); s_printf(get_string(248));
for (i=start;i<start+22 && i < list_tmp;i++) { for (i = start; i < start + 22 && i < list_tmp; i++) {
if (i == selected) { if (i == selected) {
s_printf(get_string(249), i - start + 2, dir_tmp[i]->index, dir_tmp[i]->dir->name); s_printf(get_string(249), i - start + 2, dir_tmp[i]->index, dir_tmp[i]->dir->name);
} else { } else {
@ -1769,7 +1755,7 @@ void choose_directory() {
// PAGE DOWN // PAGE DOWN
selected = selected + 22; selected = selected + 22;
if (selected >= list_tmp) { if (selected >= list_tmp) {
selected = list_tmp -1; selected = list_tmp - 1;
} }
start = selected; start = selected;
redraw = 1; redraw = 1;
@ -1782,7 +1768,7 @@ void choose_directory() {
} }
} }
for (i=0;i<list_tmp;i++) { for (i = 0; i < list_tmp; i++) {
free(dir_tmp[i]); free(dir_tmp[i]);
} }
free(dir_tmp); free(dir_tmp);
@ -1792,7 +1778,7 @@ void clear_tagged_files() {
int i; int i;
// Clear tagged files // Clear tagged files
if (tagged_count > 0) { if (tagged_count > 0) {
for (i=0;i<tagged_count;i++) { for (i = 0; i < tagged_count; i++) {
free(tagged_files[i]->filename); free(tagged_files[i]->filename);
free(tagged_files[i]); free(tagged_files[i]);
} }
@ -1803,11 +1789,11 @@ void clear_tagged_files() {
void next_file_dir(struct user_record *user) { void next_file_dir(struct user_record *user) {
int i; int i;
for (i=user->cur_file_dir;i<conf.file_directory_count;i++) { for (i = user->cur_file_dir; i < conf.file_directory_count; i++) {
if (i + 1 == conf.file_directory_count) { if (i + 1 == conf.file_directory_count) {
i = -1; 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_dir = i + 1;
user->cur_file_sub = 0; user->cur_file_sub = 0;
break; break;
@ -1817,11 +1803,11 @@ void next_file_dir(struct user_record *user) {
void prev_file_dir(struct user_record *user) { void prev_file_dir(struct user_record *user) {
int i; int i;
for (i=user->cur_file_dir;i>=0;i--) { for (i = user->cur_file_dir; i >= 0; i--) {
if (i - 1 == -1) { if (i - 1 == -1) {
i = conf.file_directory_count; 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_dir = i - 1;
user->cur_file_sub = 0; user->cur_file_sub = 0;
break; break;
@ -1831,7 +1817,7 @@ void prev_file_dir(struct user_record *user) {
void next_file_sub(struct user_record *user) { void next_file_sub(struct user_record *user) {
int i; 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) { if (i + 1 == conf.file_directories[user->cur_file_dir]->file_sub_count) {
i = -1; i = -1;
} }
@ -1840,7 +1826,7 @@ void next_file_sub(struct user_record *user) {
void prev_file_sub(struct user_record *user) { void prev_file_sub(struct user_record *user) {
int i; int i;
i=user->cur_file_sub; i = user->cur_file_sub;
if (i - 1 == -1) { if (i - 1 == -1) {
i = conf.file_directories[user->cur_file_dir]->file_sub_count; i = conf.file_directories[user->cur_file_dir]->file_sub_count;
} }
@ -1863,7 +1849,7 @@ void file_scan() {
c = s_getc(); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
for (i=0;i<conf.file_directory_count;i++) { for (i = 0; i < conf.file_directory_count; i++) {
if (conf.file_directories[i]->sec_level > gUser->sec_level) { if (conf.file_directories[i]->sec_level > gUser->sec_level) {
continue; continue;
} }
@ -1874,7 +1860,7 @@ void file_scan() {
s_getc(); s_getc();
lines = 0; lines = 0;
} }
for (j=0;j<conf.file_directories[i]->file_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) { if (conf.file_directories[i]->file_subs[j]->download_sec_level > gUser->sec_level) {
continue; continue;
} }

View File

@ -11,15 +11,15 @@
#define MAX_CHAIN_LENGTH (8) #define MAX_CHAIN_LENGTH (8)
/* We need to keep keys and values */ /* We need to keep keys and values */
typedef struct _hashmap_element{ typedef struct _hashmap_element {
char* key; char *key;
int in_use; int in_use;
any_t data; any_t data;
} hashmap_element; } hashmap_element;
/* A hashmap has some maximum size and current size, /* A hashmap has some maximum size and current size,
* as well as the data to hold. */ * as well as the data to hold. */
typedef struct _hashmap_map{ typedef struct _hashmap_map {
int table_size; int table_size;
int size; int size;
hashmap_element *data; hashmap_element *data;
@ -29,17 +29,17 @@ typedef struct _hashmap_map{
* Return an empty hashmap, or NULL on failure. * Return an empty hashmap, or NULL on failure.
*/ */
map_t hashmap_new() { map_t hashmap_new() {
hashmap_map* m = (hashmap_map*) malloc(sizeof(hashmap_map)); hashmap_map *m = (hashmap_map *)malloc(sizeof(hashmap_map));
if(!m) goto err; if (!m) goto err;
m->data = (hashmap_element*) calloc(INITIAL_SIZE, sizeof(hashmap_element)); m->data = (hashmap_element *)calloc(INITIAL_SIZE, sizeof(hashmap_element));
if(!m->data) goto err; if (!m->data) goto err;
m->table_size = INITIAL_SIZE; m->table_size = INITIAL_SIZE;
m->size = 0; m->size = 0;
return m; return m;
err: err:
if (m) if (m)
hashmap_free(m); hashmap_free(m);
return NULL; return NULL;
@ -49,45 +49,45 @@ map_t hashmap_new() {
borrowed the tables directly, and made some minor changes to the borrowed the tables directly, and made some minor changes to the
crc32-function (including changing the interface). //ylo */ crc32-function (including changing the interface). //ylo */
/* ============================================================= */ /* ============================================================= */
/* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or */ /* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or */
/* code or tables extracted from it, as desired without restriction. */ /* code or tables extracted from it, as desired without restriction. */
/* */ /* */
/* First, the polynomial itself and its table of feedback terms. The */ /* First, the polynomial itself and its table of feedback terms. The */
/* polynomial is */ /* 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 */ /* 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 */ /* 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 */ /* 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 */ /* X^31 term, etc. The X^0 term (usually shown as "+1") results in */
/* the MSB being 1. */ /* the MSB being 1. */
/* */ /* */
/* Note that the usual hardware shift register implementation, which */ /* Note that the usual hardware shift register implementation, which */
/* is what we're using (we're merely optimizing it by doing eight-bit */ /* 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 */ /* chunks at a time) shifts bits into the lowest-order term. In our */
/* implementation, that means shifting towards the right. Why do we */ /* implementation, that means shifting towards the right. Why do we */
/* do it this way? Because the calculated CRC must be transmitted in */ /* do it this way? Because the calculated CRC must be transmitted in */
/* order from highest-order term to lowest-order term. UARTs transmit */ /* order from highest-order term to lowest-order term. UARTs transmit */
/* characters in order from LSB to MSB. By storing the CRC this way, */ /* 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 */ /* 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 */ /* 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 */ /* by bit from highest- to lowest-order term without requiring any bit */
/* shuffling on our part. Reception works similarly. */ /* shuffling on our part. Reception works similarly. */
/* */ /* */
/* The feedback terms table consists of 256, 32-bit entries. Notes: */ /* The feedback terms table consists of 256, 32-bit entries. Notes: */
/* */ /* */
/* The table can be generated at runtime if desired; code to do so */ /* The table can be generated at runtime if desired; code to do so */
/* is shown later. It might not be obvious, but the feedback */ /* is shown later. It might not be obvious, but the feedback */
/* terms simply represent the results of eight shift/xor opera- */ /* terms simply represent the results of eight shift/xor opera- */
/* tions for all combinations of data and CRC register values. */ /* tions for all combinations of data and CRC register values. */
/* */ /* */
/* The values must be right-shifted by eight bits by the "updcrc" */ /* The values must be right-shifted by eight bits by the "updcrc" */
/* logic; the shift must be unsigned (bring in zeroes). On some */ /* logic; the shift must be unsigned (bring in zeroes). On some */
/* hardware you could probably optimize the shift in assembler by */ /* hardware you could probably optimize the shift in assembler by */
/* using byte-swap instructions. */ /* using byte-swap instructions. */
/* polynomial $edb88320 */ /* polynomial $edb88320 */
/* */ /* */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
static unsigned long crc32_tab[] = { static unsigned long crc32_tab[] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
@ -141,19 +141,16 @@ static unsigned long crc32_tab[] = {
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL 0x2d02ef8dL};
};
/* Return a 32-bit CRC of the contents of the buffer. */ /* Return a 32-bit CRC of the contents of the buffer. */
unsigned long crc32(const unsigned char *s, unsigned int len) unsigned long crc32(const unsigned char *s, unsigned int len) {
{
unsigned int i; unsigned int i;
unsigned long crc32val; unsigned long crc32val;
crc32val = 0; crc32val = 0;
for (i = 0; i < len; i ++) for (i = 0; i < len; i++) {
{
crc32val = crc32val =
crc32_tab[(crc32val ^ s[i]) & 0xff] ^ crc32_tab[(crc32val ^ s[i]) & 0xff] ^
(crc32val >> 8); (crc32val >> 8);
@ -164,9 +161,9 @@ unsigned long crc32(const unsigned char *s, unsigned int len)
/* /*
* Hashing function for a string * 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 */ /* Robert Jenkins' 32 bit Mix Function */
key += (key << 12); 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 * Return the integer of the location in data
* to store the point to the item, or MAP_FULL. * 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 curr;
int i; int i;
/* Cast the hashmap */ /* Cast the hashmap */
hashmap_map* m = (hashmap_map *) in; hashmap_map *m = (hashmap_map *)in;
/* If full, return immediately */ /* 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 */ /* Find the best index */
curr = hashmap_hash_int(m, key); curr = hashmap_hash_int(m, key);
/* Linear probing */ /* Linear probing */
for(i = 0; i< MAX_CHAIN_LENGTH; i++){ for (i = 0; i < MAX_CHAIN_LENGTH; i++) {
if(m->data[curr].in_use == 0) if (m->data[curr].in_use == 0)
return curr; 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; return curr;
curr = (curr + 1) % m->table_size; 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 * 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 i;
int old_size; int old_size;
hashmap_element* curr; hashmap_element *curr;
/* Setup the new elements */ /* Setup the new elements */
hashmap_map *m = (hashmap_map *) in; hashmap_map *m = (hashmap_map *)in;
hashmap_element* temp = (hashmap_element *) hashmap_element *temp = (hashmap_element *)
calloc(2 * m->table_size, sizeof(hashmap_element)); calloc(2 * m->table_size, sizeof(hashmap_element));
if(!temp) return MAP_OMEM; if (!temp) return MAP_OMEM;
/* Update the array */ /* Update the array */
curr = m->data; curr = m->data;
@ -239,7 +236,7 @@ int hashmap_rehash(map_t in){
m->size = 0; m->size = 0;
/* Rehash the elements */ /* Rehash the elements */
for(i = 0; i < old_size; i++){ for (i = 0; i < old_size; i++) {
int status; int status;
if (curr[i].in_use == 0) if (curr[i].in_use == 0)
@ -258,16 +255,16 @@ int hashmap_rehash(map_t in){
/* /*
* Add a pointer to the hashmap with some key * 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; int index;
hashmap_map* m; hashmap_map *m;
/* Cast the hashmap */ /* Cast the hashmap */
m = (hashmap_map *) in; m = (hashmap_map *)in;
/* Find a place to put our value */ /* Find a place to put our value */
index = hashmap_hash(in, key); index = hashmap_hash(in, key);
while(index == MAP_FULL){ while (index == MAP_FULL) {
if (hashmap_rehash(in) == MAP_OMEM) { if (hashmap_rehash(in) == MAP_OMEM) {
return MAP_OMEM; return MAP_OMEM;
} }
@ -286,23 +283,23 @@ int hashmap_put(map_t in, char* key, any_t value){
/* /*
* Get your pointer out of the hashmap with a key * 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 curr;
int i; int i;
hashmap_map* m; hashmap_map *m;
/* Cast the hashmap */ /* Cast the hashmap */
m = (hashmap_map *) in; m = (hashmap_map *)in;
/* Find data location */ /* Find data location */
curr = hashmap_hash_int(m, key); curr = hashmap_hash_int(m, key);
/* Linear probing, if necessary */ /* Linear probing, if necessary */
for(i = 0; i<MAX_CHAIN_LENGTH; i++){ for (i = 0; i < MAX_CHAIN_LENGTH; i++) {
int in_use = m->data[curr].in_use; int in_use = m->data[curr].in_use;
if (in_use == 1){ if (in_use == 1) {
if (strcmp(m->data[curr].key,key)==0){ if (strcmp(m->data[curr].key, key) == 0) {
*arg = (m->data[curr].data); *arg = (m->data[curr].data);
return MAP_OK; return MAP_OK;
} }
@ -326,16 +323,16 @@ int hashmap_iterate(map_t in, PFany f, any_t item) {
int i; int i;
/* Cast the hashmap */ /* Cast the hashmap */
hashmap_map* m = (hashmap_map*) in; hashmap_map *m = (hashmap_map *)in;
/* On empty hashmap, return immediately */ /* On empty hashmap, return immediately */
if (hashmap_length(m) <= 0) if (hashmap_length(m) <= 0)
return MAP_MISSING; return MAP_MISSING;
/* Linear probing */ /* Linear probing */
for(i = 0; i< m->table_size; i++) for (i = 0; i < m->table_size; i++)
if(m->data[i].in_use != 0) { if (m->data[i].in_use != 0) {
any_t data = (any_t) (m->data[i].data); any_t data = (any_t)(m->data[i].data);
int status = f(item, data); int status = f(item, data);
if (status != MAP_OK) { if (status != MAP_OK) {
return status; return status;
@ -348,23 +345,23 @@ int hashmap_iterate(map_t in, PFany f, any_t item) {
/* /*
* Remove an element with that key from the map * 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 i;
int curr; int curr;
hashmap_map* m; hashmap_map *m;
/* Cast the hashmap */ /* Cast the hashmap */
m = (hashmap_map *) in; m = (hashmap_map *)in;
/* Find key */ /* Find key */
curr = hashmap_hash_int(m, key); curr = hashmap_hash_int(m, key);
/* Linear probing, if necessary */ /* Linear probing, if necessary */
for(i = 0; i<MAX_CHAIN_LENGTH; i++){ for (i = 0; i < MAX_CHAIN_LENGTH; i++) {
int in_use = m->data[curr].in_use; int in_use = m->data[curr].in_use;
if (in_use == 1){ if (in_use == 1) {
if (strcmp(m->data[curr].key,key)==0){ if (strcmp(m->data[curr].key, key) == 0) {
/* Blank out the fields */ /* Blank out the fields */
m->data[curr].in_use = 0; m->data[curr].in_use = 0;
m->data[curr].data = NULL; m->data[curr].data = NULL;
@ -383,15 +380,17 @@ int hashmap_remove(map_t in, char* key){
} }
/* Deallocate the hashmap */ /* Deallocate the hashmap */
void hashmap_free(map_t in){ void hashmap_free(map_t in) {
hashmap_map* m = (hashmap_map*) in; hashmap_map *m = (hashmap_map *)in;
free(m->data); free(m->data);
free(m); free(m);
} }
/* Return the length of the hashmap */ /* Return the length of the hashmap */
int hashmap_length(map_t in){ int hashmap_length(map_t in) {
hashmap_map* m = (hashmap_map *) in; hashmap_map *m = (hashmap_map *)in;
if(m != NULL) return m->size; if (m != NULL)
else return 0; return m->size;
else
return 0;
} }

View File

@ -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. * 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. * 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. * 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. * Get any element. Return MAP_OK or MAP_MISSING.

View File

@ -10,66 +10,61 @@
#define KEY_MAX_LENGTH (256) #define KEY_MAX_LENGTH (256)
#define KEY_PREFIX ("somekey") #define KEY_PREFIX ("somekey")
#define KEY_COUNT (1024*1024) #define KEY_COUNT (1024 * 1024)
typedef struct data_struct_s typedef struct data_struct_s {
{
char key_string[KEY_MAX_LENGTH]; char key_string[KEY_MAX_LENGTH];
int number; int number;
} data_struct_t; } data_struct_t;
int main(char* argv, int argc) int main(char *argv, int argc) {
{
int index; int index;
int error; int error;
map_t mymap; map_t mymap;
char key_string[KEY_MAX_LENGTH]; char key_string[KEY_MAX_LENGTH];
data_struct_t* value; data_struct_t *value;
mymap = hashmap_new(); mymap = hashmap_new();
/* First, populate the hash map with ascending values */ /* First, populate the hash map with ascending values */
for (index=0; index<KEY_COUNT; index+=1) for (index = 0; index < KEY_COUNT; index += 1) {
{
/* Store the key string along side the numerical value so we can free it later */ /* Store the key string along side the numerical value so we can free it later */
value = malloc(sizeof(data_struct_t)); value = malloc(sizeof(data_struct_t));
snprintf(value->key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); snprintf(value->key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
value->number = index; value->number = index;
error = hashmap_put(mymap, value->key_string, value); error = hashmap_put(mymap, value->key_string, value);
assert(error==MAP_OK); assert(error == MAP_OK);
} }
/* Now, check all of the expected values are there */ /* Now, check all of the expected values are there */
for (index=0; index<KEY_COUNT; index+=1) for (index = 0; index < KEY_COUNT; index += 1) {
{
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
error = hashmap_get(mymap, key_string, (void**)(&value)); error = hashmap_get(mymap, key_string, (void **)(&value));
/* Make sure the value was both found and the correct number */ /* Make sure the value was both found and the correct number */
assert(error==MAP_OK); assert(error == MAP_OK);
assert(value->number==index); assert(value->number == index);
} }
/* Make sure that a value that wasn't in the map can't be found */ /* 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); snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT);
error = hashmap_get(mymap, key_string, (void**)(&value)); error = hashmap_get(mymap, key_string, (void **)(&value));
/* Make sure the value was not found */ /* Make sure the value was not found */
assert(error==MAP_MISSING); assert(error == MAP_MISSING);
/* Free all of the values we allocated and remove them from the map */ /* Free all of the values we allocated and remove them from the map */
for (index=0; index<KEY_COUNT; index+=1) for (index = 0; index < KEY_COUNT; index += 1) {
{
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
error = hashmap_get(mymap, key_string, (void**)(&value)); error = hashmap_get(mymap, key_string, (void **)(&value));
assert(error==MAP_OK); assert(error == MAP_OK);
error = hashmap_remove(mymap, key_string); error = hashmap_remove(mymap, key_string);
assert(error==MAP_OK); assert(error == MAP_OK);
free(value); free(value);
} }

View File

@ -25,27 +25,24 @@ https://github.com/benhoyt/inih
#define MAX_NAME 50 #define MAX_NAME 50
/* Strip whitespace chars off end of given string, in place. Return s. */ /* Strip whitespace chars off end of given string, in place. Return s. */
static char* rstrip(char* s) static char *rstrip(char *s) {
{ char *p = s + strlen(s);
char* p = s + strlen(s);
while (p > s && isspace((unsigned char)(*--p))) while (p > s && isspace((unsigned char)(*--p)))
*p = '\0'; *p = '\0';
return s; return s;
} }
/* Return pointer to first non-whitespace char in given string. */ /* Return pointer to first non-whitespace char in given string. */
static char* lskip(const char* s) static char *lskip(const char *s) {
{
while (*s && isspace((unsigned char)(*s))) while (*s && isspace((unsigned char)(*s)))
s++; s++;
return (char*)s; return (char *)s;
} }
/* Return pointer to first char (of chars) or inline comment in given string, /* 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 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. */ 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 #if INI_ALLOW_INLINE_COMMENTS
int was_space = 0; int was_space = 0;
while (*s && (!chars || !strchr(chars, *s)) && while (*s && (!chars || !strchr(chars, *s)) &&
@ -58,39 +55,37 @@ static char* find_chars_or_comment(const char* s, const char* chars)
s++; s++;
} }
#endif #endif
return (char*)s; return (char *)s;
} }
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */ /* Version of strncpy that ensures dest (size bytes) is null-terminated. */
static char* strncpy0(char* dest, const char* src, size_t size) static char *strncpy0(char *dest, const char *src, size_t size) {
{
strncpy(dest, src, size); strncpy(dest, src, size);
dest[size - 1] = '\0'; dest[size - 1] = '\0';
return dest; return dest;
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
void* user) void *user) {
{ /* Uses a fair bit of stack (use heap instead if you need to) */
/* Uses a fair bit of stack (use heap instead if you need to) */
#if INI_USE_STACK #if INI_USE_STACK
char line[INI_MAX_LINE]; char line[INI_MAX_LINE];
#else #else
char* line; char *line;
#endif #endif
char section[MAX_SECTION] = ""; char section[MAX_SECTION] = "";
char prev_name[MAX_NAME] = ""; char prev_name[MAX_NAME] = "";
char* start; char *start;
char* end; char *end;
char* name; char *name;
char* value; char *value;
int lineno = 0; int lineno = 0;
int error = 0; int error = 0;
#if !INI_USE_STACK #if !INI_USE_STACK
line = (char*)malloc(INI_MAX_LINE); line = (char *)malloc(INI_MAX_LINE);
if (!line) { if (!line) {
return -2; return -2;
} }
@ -129,13 +124,11 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
*end = '\0'; *end = '\0';
strncpy0(section, start + 1, sizeof(section)); strncpy0(section, start + 1, sizeof(section));
*prev_name = '\0'; *prev_name = '\0';
} } else if (!error) {
else if (!error) {
/* No ']' found on section line */ /* No ']' found on section line */
error = lineno; error = lineno;
} }
} } else if (*start) {
else if (*start) {
/* Not a comment, must be a name[=:]value pair */ /* Not a comment, must be a name[=:]value pair */
end = find_chars_or_comment(start, "=:"); end = find_chars_or_comment(start, "=:");
if (*end == '=' || *end == ':') { if (*end == '=' || *end == ':') {
@ -153,8 +146,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
strncpy0(prev_name, name, sizeof(prev_name)); strncpy0(prev_name, name, sizeof(prev_name));
if (!handler(user, section, name, value) && !error) if (!handler(user, section, name, value) && !error)
error = lineno; error = lineno;
} } else if (!error) {
else if (!error) {
/* No '=' or ':' found on name[=:]value line */ /* No '=' or ':' found on name[=:]value line */
error = lineno; error = lineno;
} }
@ -174,15 +166,13 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse_file(FILE* file, ini_handler handler, void* user) int ini_parse_file(FILE *file, ini_handler handler, void *user) {
{
return ini_parse_stream((ini_reader)fgets, file, handler, user); return ini_parse_stream((ini_reader)fgets, file, handler, user);
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse(const char* filename, ini_handler handler, void* user) int ini_parse(const char *filename, ini_handler handler, void *user) {
{ FILE *file;
FILE* file;
int error; int error;
file = fopen(filename, "r"); file = fopen(filename, "r");

View File

@ -18,11 +18,11 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
/* Typedef for prototype of handler function. */ /* Typedef for prototype of handler function. */
typedef int (*ini_handler)(void* user, const char* section, typedef int (*ini_handler)(void *user, const char *section,
const char* name, const char* value); const char *name, const char *value);
/* Typedef for prototype of fgets-style reader function. */ /* 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 /* Parse given INI-style file. May have [section]s, name=value pairs
(whitespace stripped), and comments starting with ';' (semicolon). Section (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 stop on first error), -1 on file open error, or -2 on memory allocation
error (only when INI_USE_STACK is zero). 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 /* 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. */ 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 /* Same as ini_parse(), but takes an ini_reader function pointer instead of
filename. Used for implementing custom or string-based I/O. */ filename. Used for implementing custom or string-based I/O. */
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
void* user); void *user);
/* Nonzero to allow multi-line value parsing, in the style of Python's /* 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 configparser. If allowed, ini_parse() will call the handler with the same

View File

@ -187,7 +187,6 @@ int l_getBBSInfo(lua_State *L) {
return 4; return 4;
} }
int l_getUserHandle(lua_State *L) { int l_getUserHandle(lua_State *L) {
lua_pushstring(L, gUser->loginname); lua_pushstring(L, gUser->loginname);
@ -203,7 +202,7 @@ int l_messageFound(lua_State *L) {
s_JamBase *jb; s_JamBase *jb;
s_JamBaseHeader jbh; s_JamBaseHeader jbh;
s_JamMsgHeader jmh; s_JamMsgHeader jmh;
s_JamSubPacket* jsp; s_JamSubPacket *jsp;
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
if (!jb) { if (!jb) {
@ -243,7 +242,7 @@ int l_readMessageHdr(lua_State *L) {
s_JamBase *jb; s_JamBase *jb;
s_JamBaseHeader jbh; s_JamBaseHeader jbh;
s_JamMsgHeader jmh; s_JamMsgHeader jmh;
s_JamSubPacket* jsp; s_JamSubPacket *jsp;
char *subject = NULL; char *subject = NULL;
char *sender = NULL; char *sender = NULL;
@ -265,7 +264,7 @@ int l_readMessageHdr(lua_State *L) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb); free(jb);
} else { } else {
for (z=0;z<jsp->NumFields;z++) { for (z = 0; z < jsp->NumFields; z++) {
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
subject = (char *)malloc(jsp->Fields[z]->DatLen + 1); subject = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(subject, 0, jsp->Fields[z]->DatLen + 1); memset(subject, 0, jsp->Fields[z]->DatLen + 1);
@ -281,7 +280,6 @@ int l_readMessageHdr(lua_State *L) {
memset(recipient, 0, jsp->Fields[z]->DatLen + 1); memset(recipient, 0, jsp->Fields[z]->DatLen + 1);
memcpy(recipient, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); memcpy(recipient, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} }
} }
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
@ -307,7 +305,6 @@ int l_readMessageHdr(lua_State *L) {
free(sender); free(sender);
free(recipient); free(recipient);
return 3; return 3;
} }
@ -401,7 +398,7 @@ int l_postMessage(lua_State *L) {
s_JamBase *jb; s_JamBase *jb;
s_JamMsgHeader jmh; s_JamMsgHeader jmh;
s_JamSubPacket* jsp; s_JamSubPacket *jsp;
s_JamSubfield jsf; s_JamSubfield jsf;
int z; int z;
int j; int j;
@ -416,11 +413,10 @@ int l_postMessage(lua_State *L) {
return 0; return 0;
} }
JAM_ClearMsgHeader( &jmh ); JAM_ClearMsgHeader(&jmh);
jmh.DateWritten = dwritten; jmh.DateWritten = dwritten;
jmh.Attribute |= JAM_MSG_LOCAL; jmh.Attribute |= JAM_MSG_LOCAL;
jsp = JAM_NewSubPacket(); jsp = JAM_NewSubPacket();
jsf.LoID = JAMSFLD_SENDERNAME; jsf.LoID = JAMSFLD_SENDERNAME;
@ -530,7 +526,7 @@ int l_postMessage(lua_State *L) {
j = 0; j = 0;
for (i=0;i<strlen(body);i++) { for (i = 0; i < strlen(body); i++) {
if (body[i] == '\n') { if (body[i] == '\n') {
continue; continue;
} }

File diff suppressed because it is too large Load Diff

View File

@ -17,16 +17,16 @@
#include <string.h> #include <string.h>
#include <poll.h> #include <poll.h>
#if defined(linux) #if defined(linux)
# include <pty.h> #include <pty.h>
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
# include <util.h> #include <util.h>
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
# include <libutil.h> #include <libutil.h>
#elif defined(__sun) #elif defined(__sun)
# include "os/sunos.h" #include "os/sunos.h"
#endif #endif
#if defined(ENABLE_WWW) #if defined(ENABLE_WWW)
# include <microhttpd.h> #include <microhttpd.h>
#endif #endif
#include <termios.h> #include <termios.h>
#include "bbs.h" #include "bbs.h"
@ -51,8 +51,7 @@ int bbs_stderr;
struct MHD_Daemon *www_daemon; struct MHD_Daemon *www_daemon;
#endif #endif
void sigterm_handler(int s) void sigterm_handler(int s) {
{
if (ssh_pid != -1) { if (ssh_pid != -1) {
kill(ssh_pid, SIGTERM); kill(ssh_pid, SIGTERM);
} }
@ -71,23 +70,22 @@ void sigterm_handler(int s)
exit(0); exit(0);
} }
void sigchld_handler(int s) void sigchld_handler(int s) {
{
// waitpid() might overwrite errno, so we save and restore it: // waitpid() might overwrite errno, so we save and restore it:
int saved_errno = errno; 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, static int protocol_config_handler(void *user, const char *section, const char *name,
const char* value) const char *value) {
{
struct bbs_config *conf = (struct bbs_config *)user; struct bbs_config *conf = (struct bbs_config *)user;
int i; int i;
for (i=0;i<conf->protocol_count;i++) { for (i = 0; i < conf->protocol_count; i++) {
if (strcasecmp(conf->protocols[i]->name, section) == 0) { if (strcasecmp(conf->protocols[i]->name, section) == 0) {
// found it // found it
if (strcasecmp(name, "upload command") == 0) { if (strcasecmp(name, "upload command") == 0) {
@ -158,13 +156,12 @@ static int protocol_config_handler(void* user, const char* section, const char*
return 1; return 1;
} }
static int archiver_config_handler(void* user, const char* section, const char* name, static int archiver_config_handler(void *user, const char *section, const char *name,
const char* value) const char *value) {
{
struct bbs_config *conf = (struct bbs_config *)user; struct bbs_config *conf = (struct bbs_config *)user;
int i; int i;
for (i=0;i<conf->archiver_count;i++) { for (i = 0; i < conf->archiver_count; i++) {
if (strcasecmp(conf->archivers[i]->name, section) == 0) { if (strcasecmp(conf->archivers[i]->name, section) == 0) {
// found it // found it
if (strcasecmp(name, "extension") == 0) { if (strcasecmp(name, "extension") == 0) {
@ -200,13 +197,12 @@ static int archiver_config_handler(void* user, const char* section, const char*
return 1; return 1;
} }
static int door_config_handler(void* user, const char* section, const char* name, static int door_config_handler(void *user, const char *section, const char *name,
const char* value) const char *value) {
{
struct bbs_config *conf = (struct bbs_config *)user; struct bbs_config *conf = (struct bbs_config *)user;
int i; int i;
for (i=0;i<conf->door_count;i++) { for (i = 0; i < conf->door_count; i++) {
if (strcasecmp(conf->doors[i]->name, section) == 0) { if (strcasecmp(conf->doors[i]->name, section) == 0) {
// found it // found it
if (strcasecmp(name, "command") == 0) { if (strcasecmp(name, "command") == 0) {
@ -251,9 +247,8 @@ static int door_config_handler(void* user, const char* section, const char* name
return 1; return 1;
} }
static int file_sub_handler(void* user, const char* section, const char* name, static int file_sub_handler(void *user, const char *section, const char *name,
const char* value) const char *value) {
{
struct file_directory *fd = (struct file_directory *)user; struct file_directory *fd = (struct file_directory *)user;
int i; int i;
@ -269,7 +264,7 @@ static int file_sub_handler(void* user, const char* section, const char* name,
} }
} else { } else {
// check if it's partially filled in // check if it's partially filled in
for (i=0;i<fd->file_sub_count;i++) { for (i = 0; i < fd->file_sub_count; i++) {
if (strcasecmp(fd->file_subs[i]->name, section) == 0) { if (strcasecmp(fd->file_subs[i]->name, section) == 0) {
if (strcasecmp(name, "upload sec level") == 0) { if (strcasecmp(name, "upload sec level") == 0) {
fd->file_subs[i]->upload_sec_level = atoi(value); 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; return 1;
} }
static int mail_area_handler(void *user, const char *section, const char *name,
static int mail_area_handler(void* user, const char* section, const char* name, const char *value) {
const char* value)
{
struct mail_conference *mc = (struct mail_conference *)user; struct mail_conference *mc = (struct mail_conference *)user;
int i; int i;
@ -351,7 +344,7 @@ static int mail_area_handler(void* user, const char* section, const char* name,
} }
} else { } else {
// check if it's partially filled in // check if it's partially filled in
for (i=0;i<mc->mail_area_count;i++) { for (i = 0; i < mc->mail_area_count; i++) {
if (strcasecmp(mc->mail_areas[i]->name, section) == 0) { if (strcasecmp(mc->mail_areas[i]->name, section) == 0) {
if (strcasecmp(name, "read sec level") == 0) { if (strcasecmp(name, "read sec level") == 0) {
mc->mail_areas[i]->read_sec_level = atoi(value); mc->mail_areas[i]->read_sec_level = atoi(value);
@ -416,9 +409,8 @@ static int mail_area_handler(void* user, const char* section, const char* name,
return 1; return 1;
} }
static int handler(void* user, const char* section, const char* name, static int handler(void *user, const char *section, const char *name,
const char* value) const char *value) {
{
struct bbs_config *conf = (struct bbs_config *)user; struct bbs_config *conf = (struct bbs_config *)user;
struct passwd *pwd; struct passwd *pwd;
@ -548,7 +540,7 @@ static int handler(void* user, const char* section, const char* name,
conf->gid = pwd->pw_gid; conf->gid = pwd->pw_gid;
} }
} }
} else if (strcasecmp(section, "paths") == 0){ } else if (strcasecmp(section, "paths") == 0) {
if (strcasecmp(name, "ansi path") == 0) { if (strcasecmp(name, "ansi path") == 0) {
conf->ansi_path = strdup(value); conf->ansi_path = strdup(value);
} else if (strcasecmp(name, "bbs path") == 0) { } 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]->name = strdup(name);
conf->text_files[conf->text_file_count]->path = strdup(value); conf->text_files[conf->text_file_count]->path = strdup(value);
conf->text_file_count++; conf->text_file_count++;
} }
return 1; return 1;
@ -631,9 +622,9 @@ int ssh_authenticate(ssh_session p_ssh_session) {
return 0; return 0;
} }
switch(ssh_message_type(message)) { switch (ssh_message_type(message)) {
case SSH_REQUEST_AUTH: case SSH_REQUEST_AUTH:
switch(ssh_message_subtype(message)) { switch (ssh_message_subtype(message)) {
case SSH_AUTH_METHOD_PASSWORD: case SSH_AUTH_METHOD_PASSWORD:
username = ssh_message_auth_user(message); username = ssh_message_auth_user(message);
password = ssh_message_auth_password(message); password = ssh_message_auth_password(message);
@ -666,7 +657,7 @@ int ssh_authenticate(ssh_session p_ssh_session) {
} }
ssh_message_free(message); ssh_message_free(message);
} while(1); } while (1);
} }
/* /*
char *ssh_getip(ssh_session session) { char *ssh_getip(ssh_session session) {
@ -687,17 +678,17 @@ static int ssh_copy_fd_to_chan(socket_t fd, int revents, void *userdata) {
char buf[2048]; char buf[2048];
int sz = 0; int sz = 0;
if(!chan) { if (!chan) {
close(fd); close(fd);
return -1; return -1;
} }
if(revents & POLLIN) { if (revents & POLLIN) {
sz = read(fd, buf, 2048); sz = read(fd, buf, 2048);
if(sz > 0) { if (sz > 0) {
ssh_channel_write(chan, buf, sz); ssh_channel_write(chan, buf, sz);
} }
} }
if(revents & POLLHUP) { if (revents & POLLHUP) {
ssh_channel_close(chan); ssh_channel_close(chan);
sz = -1; sz = -1;
} }
@ -710,7 +701,7 @@ static int ssh_copy_chan_to_fd(ssh_session session,
uint32_t len, uint32_t len,
int is_stderr, int is_stderr,
void *userdata) { void *userdata) {
int fd = *(int*)userdata; int fd = *(int *)userdata;
int sz; int sz;
(void)session; (void)session;
(void)channel; (void)channel;
@ -721,7 +712,7 @@ static int ssh_copy_chan_to_fd(ssh_session session,
} }
static void ssh_chan_close(ssh_session session, ssh_channel channel, void *userdata) { static void ssh_chan_close(ssh_session session, ssh_channel channel, void *userdata) {
int fd = *(int*)userdata; int fd = *(int *)userdata;
int status; int status;
(void)session; (void)session;
(void)channel; (void)channel;
@ -732,8 +723,7 @@ struct ssh_channel_callbacks_struct ssh_cb = {
.channel_data_function = ssh_copy_chan_to_fd, .channel_data_function = ssh_copy_chan_to_fd,
.channel_eof_function = ssh_chan_close, .channel_eof_function = ssh_chan_close,
.channel_close_function = ssh_chan_close, .channel_close_function = ssh_chan_close,
.userdata = NULL .userdata = NULL};
};
void serverssh(int port, int ipv6) { void serverssh(int port, int ipv6) {
ssh_session p_ssh_session; ssh_session p_ssh_session;
@ -789,7 +779,6 @@ void serverssh(int port, int ipv6) {
exit(-1); exit(-1);
} }
if (setsockopt(ssh_sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { if (setsockopt(ssh_sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
fprintf(stderr, "setsockopt(SO_REUSEADDR) failed"); fprintf(stderr, "setsockopt(SO_REUSEADDR) failed");
exit(-1); exit(-1);
@ -879,7 +868,6 @@ void serverssh(int port, int ipv6) {
free(ip); free(ip);
ssh_disconnect(p_ssh_session); ssh_disconnect(p_ssh_session);
continue; continue;
} }
} else { } else {
ip_guard->connection_count = 0; ip_guard->connection_count = 0;
@ -912,7 +900,7 @@ void serverssh(int port, int ipv6) {
} else { } else {
break; break;
} }
} while(!chan); } while (!chan);
if (!chan) { if (!chan) {
fprintf(stderr, "Failed to get channel\n"); fprintf(stderr, "Failed to get channel\n");
ssh_finalize(); ssh_finalize();
@ -945,10 +933,6 @@ void serverssh(int port, int ipv6) {
exit(-1); exit(-1);
} }
bbs_pid = forkpty(&fd, NULL, NULL, NULL); bbs_pid = forkpty(&fd, NULL, NULL, NULL);
if (bbs_pid == 0) { if (bbs_pid == 0) {
tcgetattr(STDIN_FILENO, &tios); tcgetattr(STDIN_FILENO, &tios);
@ -966,22 +950,22 @@ void serverssh(int port, int ipv6) {
events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL;
event = ssh_event_new(); event = ssh_event_new();
if(event == NULL) { if (event == NULL) {
ssh_finalize(); ssh_finalize();
exit(0); 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(); ssh_finalize();
exit(0); 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(); ssh_finalize();
exit(0); exit(0);
} }
do { do {
ssh_event_dopoll(event, 1000); ssh_event_dopoll(event, 1000);
} while(!ssh_channel_is_closed(chan)); } while (!ssh_channel_is_closed(chan));
ssh_event_remove_fd(event, fd); ssh_event_remove_fd(event, fd);
@ -998,7 +982,6 @@ void serverssh(int port, int ipv6) {
close(csock); close(csock);
free(ip); free(ip);
} else { } else {
} }
} }
} }
@ -1035,7 +1018,7 @@ void server(int port, int ipv6) {
if (fptr) { if (fptr) {
fgets(buffer, 1024, fptr); fgets(buffer, 1024, fptr);
while (!feof(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') { if (buffer[i] == '\r' || buffer[i] == '\n') {
buffer[i] = '\0'; buffer[i] = '\0';
} else { } else {
@ -1058,7 +1041,7 @@ void server(int port, int ipv6) {
if (fptr) { if (fptr) {
fgets(buffer, 1024, fptr); fgets(buffer, 1024, fptr);
while (!feof(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') { if (buffer[i] == '\r' || buffer[i] == '\n') {
buffer[i] = '\0'; buffer[i] = '\0';
} else { } else {
@ -1134,7 +1117,6 @@ void server(int port, int ipv6) {
exit(1); exit(1);
} }
if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
remove(conf.pid_file); remove(conf.pid_file);
fprintf(stderr, "setsockopt(SO_REUSEADDR) failed"); fprintf(stderr, "setsockopt(SO_REUSEADDR) failed");
@ -1145,7 +1127,6 @@ void server(int port, int ipv6) {
printf(" - Telnet Starting on Port %d (IPv%d)\n", port, (ipv6 ? 6 : 4)); printf(" - Telnet Starting on Port %d (IPv%d)\n", port, (ipv6 ? 6 : 4));
} }
if (ipv6) { if (ipv6) {
if (setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) { if (setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) {
fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed"); fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed");
@ -1196,7 +1177,7 @@ void server(int port, int ipv6) {
} }
www_init(); www_init();
if (ipv6) { 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 { } 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); 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); listen(server_socket, 3);
while ((client_sock = accept(server_socket, (struct sockaddr *)client_p, (socklen_t *)&c))) { while ((client_sock = accept(server_socket, (struct sockaddr *)client_p, (socklen_t *)&c))) {
if (ipv6) { if (ipv6) {
ip = strdup(inet_ntop(AF_INET6, &((struct sockaddr_in6 *)client_p)->sin6_addr, str, sizeof(str))); ip = strdup(inet_ntop(AF_INET6, &((struct sockaddr_in6 *)client_p)->sin6_addr, str, sizeof(str)));
@ -1249,7 +1229,6 @@ void server(int port, int ipv6) {
free(ip); free(ip);
close(client_sock); close(client_sock);
continue; continue;
} }
} else { } else {
ip_guard->connection_count = 0; ip_guard->connection_count = 0;
@ -1326,7 +1305,7 @@ int main(int argc, char **argv) {
conf.uid = getuid(); conf.uid = getuid();
conf.gid = getgid(); conf.gid = getgid();
// Load BBS data // 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]); fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]);
exit(-1); exit(-1);
} }
@ -1342,15 +1321,15 @@ int main(int argc, char **argv) {
} }
// Load mail Areas // Load mail Areas
for (i=0;i<conf.mail_conference_count;i++) { 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) { 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); fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.mail_conferences[i]->path);
exit(-1); exit(-1);
} }
} }
// Load file Subs // Load file Subs
for (i=0;i<conf.file_directory_count;i++) { 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) { 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); fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.file_directories[i]->path);
exit(-1); exit(-1);
} }
@ -1358,24 +1337,23 @@ int main(int argc, char **argv) {
snprintf(buffer, 1024, "%s/doors.ini", conf.config_path); 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"); fprintf(stderr, "Unable to load configuration ini (doors.ini)!\n");
exit(-1); exit(-1);
} }
snprintf(buffer, 1024, "%s/archivers.ini", conf.config_path); 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); fprintf(stderr, "Unable to load configuration ini %s\n", buffer);
exit(-1); exit(-1);
} }
snprintf(buffer, 1024, "%s/protocols.ini", conf.config_path); 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); fprintf(stderr, "Unable to load configuration ini %s\n", buffer);
exit(-1); exit(-1);
} }
load_strings(); load_strings();
if (conf.fork) { if (conf.fork) {
@ -1389,8 +1367,7 @@ int main(int argc, char **argv) {
if (main_pid < 0) { if (main_pid < 0) {
fprintf(stderr, "Error forking.\n"); fprintf(stderr, "Error forking.\n");
exit(-1); exit(-1);
} else } else if (main_pid > 0) {
if (main_pid > 0) {
if (conf.uid != getuid()) { if (conf.uid != getuid()) {
if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) { if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) {
perror("Setuid Error: "); perror("Setuid Error: ");
@ -1405,7 +1382,7 @@ int main(int argc, char **argv) {
fclose(fptr); fclose(fptr);
} }
} else { } 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); snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i);
if (stat(buffer, &s) == 0) { if (stat(buffer, &s) == 0) {
unlink(buffer); unlink(buffer);
@ -1429,7 +1406,7 @@ int main(int argc, char **argv) {
} else { } else {
printf("Magicka BBS Server Starting....\n"); 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); snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i);
if (stat(buffer, &s) == 0) { if (stat(buffer, &s) == 0) {
printf(" - Removing stale file: nodeinuse.%d\n", i); printf(" - Removing stale file: nodeinuse.%d\n", i);

View File

@ -37,15 +37,15 @@ void active_nodes() {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
FILE *fptr; FILE *fptr;
for (i=0;i<conf.nodes;i++) { for (i = 0; i < conf.nodes; i++) {
snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i+1); snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i + 1);
if (stat(buffer, &s) == 0) { if (stat(buffer, &s) == 0) {
fptr = fopen(buffer, "r"); fptr = fopen(buffer, "r");
if (fptr) { if (fptr) {
fgets(buffer, PATH_MAX, fptr); fgets(buffer, PATH_MAX, fptr);
fclose(fptr); fclose(fptr);
chomp(buffer); chomp(buffer);
s_printf(get_string(216), i+1, buffer); s_printf(get_string(216), i + 1, buffer);
} }
} }
} }
@ -107,7 +107,7 @@ void display_textfiles() {
s_printf("\e[2J\e[1;1H"); s_printf("\e[2J\e[1;1H");
s_printf(get_string(143)); s_printf(get_string(143));
s_printf(get_string(144)); s_printf(get_string(144));
for (i=start;i<start+22 && i < conf.text_file_count;i++) { for (i = start; i < start + 22 && i < conf.text_file_count; i++) {
if (i == selected) { if (i == selected) {
s_printf(get_string(249), i - start + 2, i, conf.text_files[i]->name); s_printf(get_string(249), i - start + 2, i, conf.text_files[i]->name);
} else { } else {
@ -193,7 +193,7 @@ void display_textfiles() {
// PAGE DOWN // PAGE DOWN
selected = selected + 22; selected = selected + 22;
if (selected >= conf.text_file_count) { if (selected >= conf.text_file_count) {
selected = conf.text_file_count -1; selected = conf.text_file_count - 1;
} }
start = selected; start = selected;
redraw = 1; redraw = 1;

View File

@ -97,7 +97,6 @@ int menu_system(char *menufile) {
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); broadcast("USER: %s; NODE:%d; STATUS: Browsing menu %s.", gUser->loginname, mynode, menufile);
if (menufile[0] == '/') { if (menufile[0] == '/') {
snprintf(buffer, PATH_MAX, "%s.mnu", menufile); snprintf(buffer, PATH_MAX, "%s.mnu", menufile);
} else { } else {
@ -113,11 +112,9 @@ int menu_system(char *menufile) {
lua_script = NULL; lua_script = NULL;
ansi_file = NULL; ansi_file = NULL;
fgets(buffer, 256, fptr); fgets(buffer, 256, fptr);
while (!feof(fptr)) { while (!feof(fptr)) {
chomp(buffer); chomp(buffer);
if (strncasecmp(buffer, "HOTKEY", 6) == 0) { if (strncasecmp(buffer, "HOTKEY", 6) == 0) {
@ -127,133 +124,133 @@ int menu_system(char *menufile) {
} else { } else {
menu = (struct menu_item **)realloc(menu, sizeof(struct menu_item *) * (menu_items)); 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] = (struct menu_item *)malloc(sizeof(struct menu_item));
menu[menu_items-1]->hotkey = buffer[7]; menu[menu_items - 1]->hotkey = buffer[7];
menu[menu_items-1]->command = NULL; menu[menu_items - 1]->command = NULL;
menu[menu_items-1]->data = NULL; menu[menu_items - 1]->data = NULL;
menu[menu_items-1]->command_count = 0; menu[menu_items - 1]->command_count = 0;
menu[menu_items-1]->seclevel = 0; menu[menu_items - 1]->seclevel = 0;
} else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) { } else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) {
if (menu[menu_items-1]->command_count == 0) { if (menu[menu_items - 1]->command_count == 0) {
menu[menu_items-1]->command = (int *)malloc(sizeof(int)); menu[menu_items - 1]->command = (int *)malloc(sizeof(int));
menu[menu_items-1]->data = (char **)malloc(sizeof(char *)); menu[menu_items - 1]->data = (char **)malloc(sizeof(char *));
} else { } 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]->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]->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_count++;
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = 0; 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; menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1] = NULL;
if (strncasecmp(&buffer[8], "SUBMENU", 7) == 0) { if (strncasecmp(&buffer[8], "SUBMENU", 7) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SUBMENU; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SUBMENU;
} else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) { } else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LOGOFF; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LOGOFF;
} else if (strncasecmp(&buffer[8], "PREVMENU", 8) == 0) { } else if (strncasecmp(&buffer[8], "PREVMENU", 8) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMENU; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMENU;
} else if (strncasecmp(&buffer[8], "AUTOMESSAGE", 11) == 0) { } else if (strncasecmp(&buffer[8], "AUTOMESSAGE", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_AUTOMESSAGE; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_AUTOMESSAGE;
} else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) { } else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_TEXTFILES; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_TEXTFILES;
} else if (strncasecmp(&buffer[8], "CHATSYSTEM", 10) == 0) { } else if (strncasecmp(&buffer[8], "CHATSYSTEM", 10) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHATSYSTEM; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHATSYSTEM;
} else if (strncasecmp(&buffer[8], "BBSLIST", 7) == 0) { } else if (strncasecmp(&buffer[8], "BBSLIST", 7) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BBSLIST; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BBSLIST;
} else if (strncasecmp(&buffer[8], "LISTUSERS", 9) == 0) { } else if (strncasecmp(&buffer[8], "LISTUSERS", 9) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTUSERS; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTUSERS;
} else if (strncasecmp(&buffer[8], "BULLETINS", 9) == 0) { } else if (strncasecmp(&buffer[8], "BULLETINS", 9) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BULLETINS; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BULLETINS;
} else if (strncasecmp(&buffer[8], "LAST10CALLERS", 13) == 0) { } else if (strncasecmp(&buffer[8], "LAST10CALLERS", 13) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LAST10; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LAST10;
} else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) { } else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SETTINGS; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SETTINGS;
} else if (strncasecmp(&buffer[8], "RUNDOOR", 7) == 0) { } else if (strncasecmp(&buffer[8], "RUNDOOR", 7) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOOR; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOOR;
} else if (strncasecmp(&buffer[8], "MAILSCAN", 8) == 0) { } else if (strncasecmp(&buffer[8], "MAILSCAN", 8) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_MAILSCAN; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_MAILSCAN;
} else if (strncasecmp(&buffer[8], "READMAIL", 8) == 0) { } else if (strncasecmp(&buffer[8], "READMAIL", 8) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_READMAIL; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_READMAIL;
} else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) { } else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_POSTMESSAGE; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_POSTMESSAGE;
} else if (strncasecmp(&buffer[8], "CHOOSEMAILCONF", 14) == 0) { } else if (strncasecmp(&buffer[8], "CHOOSEMAILCONF", 14) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEMAILCONF; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEMAILCONF;
} else if (strncasecmp(&buffer[8], "CHOOSEMAILAREA", 14) == 0) { } else if (strncasecmp(&buffer[8], "CHOOSEMAILAREA", 14) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEMAILAREA; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEMAILAREA;
} else if (strncasecmp(&buffer[8], "SENDEMAIL", 9) == 0) { } else if (strncasecmp(&buffer[8], "SENDEMAIL", 9) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDEMAIL; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDEMAIL;
} else if (strncasecmp(&buffer[8], "LISTEMAIL", 9) == 0) { } else if (strncasecmp(&buffer[8], "LISTEMAIL", 9) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTEMAIL; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTEMAIL;
} else if (strncasecmp(&buffer[8], "NEXTMAILCONF", 12) == 0) { } else if (strncasecmp(&buffer[8], "NEXTMAILCONF", 12) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTMAILCONF; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTMAILCONF;
} else if (strncasecmp(&buffer[8], "PREVMAILCONF", 12) == 0) { } else if (strncasecmp(&buffer[8], "PREVMAILCONF", 12) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMAILCONF; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMAILCONF;
} else if (strncasecmp(&buffer[8], "NEXTMAILAREA", 12) == 0) { } else if (strncasecmp(&buffer[8], "NEXTMAILAREA", 12) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTMAILAREA; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTMAILAREA;
} else if (strncasecmp(&buffer[8], "PREVMAILAREA", 12) == 0) { } else if (strncasecmp(&buffer[8], "PREVMAILAREA", 12) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMAILAREA; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMAILAREA;
} else if (strncasecmp(&buffer[8], "BLUEWAVEDOWNLOAD", 16) == 0) { } else if (strncasecmp(&buffer[8], "BLUEWAVEDOWNLOAD", 16) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLUEWAVEDOWN; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLUEWAVEDOWN;
} else if (strncasecmp(&buffer[8], "BLUEWAVEUPLOAD", 14) == 0) { } else if (strncasecmp(&buffer[8], "BLUEWAVEUPLOAD", 14) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLUEWAVEUP; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLUEWAVEUP;
} else if (strncasecmp(&buffer[8], "CHOOSEFILEDIR", 13) == 0) { } else if (strncasecmp(&buffer[8], "CHOOSEFILEDIR", 13) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEFILEDIR; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEFILEDIR;
} else if (strncasecmp(&buffer[8], "CHOOSEFILESUB", 13) == 0) { } else if (strncasecmp(&buffer[8], "CHOOSEFILESUB", 13) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEFILESUB; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEFILESUB;
} else if (strncasecmp(&buffer[8], "LISTFILES", 9) == 0) { } else if (strncasecmp(&buffer[8], "LISTFILES", 9) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTFILES; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTFILES;
} else if (strncasecmp(&buffer[8], "UPLOAD", 6) == 0) { } else if (strncasecmp(&buffer[8], "UPLOAD", 6) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_UPLOAD; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_UPLOAD;
} else if (strncasecmp(&buffer[8], "DOWNLOAD", 8) == 0) { } else if (strncasecmp(&buffer[8], "DOWNLOAD", 8) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOWNLOAD; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOWNLOAD;
} else if (strncasecmp(&buffer[8], "CLEARTAGGED", 11) == 0) { } else if (strncasecmp(&buffer[8], "CLEARTAGGED", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CLEARTAGGEDFILES; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CLEARTAGGEDFILES;
} else if (strncasecmp(&buffer[8], "NEXTFILEDIR", 11) == 0) { } else if (strncasecmp(&buffer[8], "NEXTFILEDIR", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTFILEDIR; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTFILEDIR;
} else if (strncasecmp(&buffer[8], "PREVFILEDIR", 11) == 0) { } else if (strncasecmp(&buffer[8], "PREVFILEDIR", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVFILEDIR; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVFILEDIR;
} else if (strncasecmp(&buffer[8], "NEXTFILESUB", 11) == 0) { } else if (strncasecmp(&buffer[8], "NEXTFILESUB", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTFILESUB; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTFILESUB;
} else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) { } else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVFILESUB; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVFILESUB;
} else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) { } else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTMESSAGES; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTMESSAGES;
} else if (strncasecmp(&buffer[8], "DOSCRIPT", 8) == 0) { } else if (strncasecmp(&buffer[8], "DOSCRIPT", 8) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOSCRIPT; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOSCRIPT;
} else if (strncasecmp(&buffer[8], "SENDNODEMSG", 11) == 0) { } else if (strncasecmp(&buffer[8], "SENDNODEMSG", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDNODEMSG; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDNODEMSG;
} else if (strncasecmp(&buffer[8], "SUBUNSUBCONF", 12) == 0) { } else if (strncasecmp(&buffer[8], "SUBUNSUBCONF", 12) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SUBUNSUBCONF; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SUBUNSUBCONF;
} else if (strncasecmp(&buffer[8], "RESETMSGPTRS", 12) == 0) { } 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) { } 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) { } 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) { } 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) { } 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) { } 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) { } 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) { } else if (strncasecmp(&buffer[8], "GENWWWURLS", 10) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_GENWWWURLS; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_GENWWWURLS;
} else if (strncasecmp(&buffer[8], "NLBROWSER", 9) == 0) { } else if (strncasecmp(&buffer[8], "NLBROWSER", 9) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NLBROWSER; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NLBROWSER;
} else if (strncasecmp(&buffer[8], "SENDFEEDBACK", 12) == 0) { } else if (strncasecmp(&buffer[8], "SENDFEEDBACK", 12) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDFEEDBACK; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDFEEDBACK;
} else if (strncasecmp(&buffer[8], "BLOGDISPLAY", 11) == 0) { } else if (strncasecmp(&buffer[8], "BLOGDISPLAY", 11) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLOGDISPLAY; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLOGDISPLAY;
} else if (strncasecmp(&buffer[8], "BLOGWRITE", 9) == 0) { } else if (strncasecmp(&buffer[8], "BLOGWRITE", 9) == 0) {
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLOGWRITE; menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLOGWRITE;
} }
} else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) { } else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) {
menu[menu_items-1]->seclevel = atoi(&buffer[9]); menu[menu_items - 1]->seclevel = atoi(&buffer[9]);
} else if (strncasecmp(buffer, "DATA", 4) == 0) { } else if (strncasecmp(buffer, "DATA", 4) == 0) {
if (menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] != NULL) { 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]); 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]); menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1] = strdup(&buffer[5]);
} else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) { } else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) {
if (lua_script != NULL) { if (lua_script != NULL) {
free(lua_script); free(lua_script);
@ -301,7 +298,6 @@ int menu_system(char *menufile) {
} }
} }
while (!doquit) { while (!doquit) {
if (gUser->nodemsgs) { if (gUser->nodemsgs) {
snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode); snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode);
@ -349,11 +345,11 @@ int menu_system(char *menufile) {
lua_pop(L, 1); lua_pop(L, 1);
} }
for (i=0;i<menu_items;i++) { for (i = 0; i < menu_items; i++) {
if (tolower(menu[i]->hotkey) == tolower(c)) { if (tolower(menu[i]->hotkey) == tolower(c)) {
if (menu[i]->seclevel <= gUser->sec_level) { if (menu[i]->seclevel <= gUser->sec_level) {
for (j=0; j<menu[i]->command_count;j++) { for (j = 0; j < menu[i]->command_count; j++) {
switch(menu[i]->command[j]) { switch (menu[i]->command[j]) {
case MENU_SUBMENU: case MENU_SUBMENU:
doquit = menu_system(menu[i]->data[j]); doquit = menu_system(menu[i]->data[j]);
if (doquit == 1) { if (doquit == 1) {
@ -367,8 +363,8 @@ int menu_system(char *menufile) {
if (ansi_file != NULL) { if (ansi_file != NULL) {
free(ansi_file); free(ansi_file);
} }
for (i=0;i<menu_items;i++) { for (i = 0; i < menu_items; i++) {
for (j=0;j<menu[i]->command_count;j++) { for (j = 0; j < menu[i]->command_count; j++) {
if (menu[i]->data[j] != NULL) { if (menu[i]->data[j] != NULL) {
free(menu[i]->data[j]); free(menu[i]->data[j]);
} }
@ -391,8 +387,8 @@ int menu_system(char *menufile) {
if (ansi_file != NULL) { if (ansi_file != NULL) {
free(ansi_file); free(ansi_file);
} }
for (i=0;i<menu_items;i++) { for (i = 0; i < menu_items; i++) {
for (j=0;j<menu[i]->command_count;j++) { for (j = 0; j < menu[i]->command_count; j++) {
if (menu[i]->data[j] != NULL) { if (menu[i]->data[j] != NULL) {
free(menu[i]->data[j]); free(menu[i]->data[j]);
} }
@ -413,8 +409,8 @@ int menu_system(char *menufile) {
if (ansi_file != NULL) { if (ansi_file != NULL) {
free(ansi_file); free(ansi_file);
} }
for (i=0;i<menu_items;i++) { for (i = 0; i < menu_items; i++) {
for (j=0;j<menu[i]->command_count;j++) { for (j = 0; j < menu[i]->command_count; j++) {
if (menu[i]->data[j] != NULL) { if (menu[i]->data[j] != NULL) {
free(menu[i]->data[j]); free(menu[i]->data[j]);
} }
@ -456,9 +452,8 @@ int menu_system(char *menufile) {
case MENU_SETTINGS: case MENU_SETTINGS:
settings_menu(gUser); settings_menu(gUser);
break; break;
case MENU_DOOR: case MENU_DOOR: {
{ for (m = 0; m < conf.door_count; m++) {
for (m=0;m<conf.door_count;m++) {
if (strcasecmp(menu[i]->data[j], conf.doors[m]->name) == 0) { 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); 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); broadcast("USER: %s; NODE:%d; STATUS: Executing Door %s.", gUser->loginname, mynode, conf.doors[m]->name);
@ -467,8 +462,7 @@ int menu_system(char *menufile) {
break; break;
} }
} }
} } break;
break;
case MENU_MAILSCAN: case MENU_MAILSCAN:
broadcast("USER: %s; NODE:%d; STATUS: Performing Mail Scan.", gUser->loginname, mynode); broadcast("USER: %s; NODE:%d; STATUS: Performing Mail Scan.", gUser->loginname, mynode);
mail_scan(gUser); mail_scan(gUser);

View File

@ -121,7 +121,7 @@ void nl_browser() {
s_printf("\e[2J\e[1;1H"); s_printf("\e[2J\e[1;1H");
s_printf(get_string(145)); s_printf(get_string(145));
s_printf(get_string(146)); s_printf(get_string(146));
for (i=start;i<start+22 && i < entry_count;i++) { for (i = start; i < start + 22 && i < entry_count; i++) {
if (i == selected) { if (i == selected) {
s_printf(get_string(147), i - start + 2, i, entries[i]->address, entries[i]->bbsname); s_printf(get_string(147), i - start + 2, i, entries[i]->address, entries[i]->bbsname);
} else { } else {
@ -207,7 +207,7 @@ void nl_browser() {
// PAGE DOWN // PAGE DOWN
selected = selected + 22; selected = selected + 22;
if (selected >= entry_count) { if (selected >= entry_count) {
selected = entry_count -1; selected = entry_count - 1;
} }
start = selected; start = selected;
redraw = 1; redraw = 1;
@ -227,7 +227,7 @@ void nl_browser() {
redraw = 1; redraw = 1;
} }
} }
for (i=0;i<entry_count;i++) { for (i = 0; i < entry_count; i++) {
free(entries[i]->address); free(entries[i]->address);
free(entries[i]->bbsname); free(entries[i]->bbsname);
free(entries[i]->sysop); free(entries[i]->sysop);

View File

@ -34,7 +34,6 @@ int openpty(int *amaster, int *aslave, char *name, void *termp, void *winp) {
ioctl(pts, TIOCSWINSZ, winp); ioctl(pts, TIOCSWINSZ, winp);
} }
*amaster = ptm; *amaster = ptm;
*aslave = pts; *aslave = pts;
@ -85,13 +84,12 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) {
return pid; return pid;
} }
static long difftm(struct tm *a, struct tm *b) { static long difftm(struct tm *a, struct tm *b) {
int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
int by = b->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) { long gmtoff(time_t value) {

View File

@ -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 int forkpty(int *amaster, char *name, void *termp, void *winp);
extern long gmtoff(time_t value); extern long gmtoff(time_t value);
#endif #endif

View File

@ -44,17 +44,14 @@ void settings_menu(struct user_record *user) {
c = s_getc(); c = s_getc();
switch(tolower(c)) { switch (tolower(c)) {
case 27: case 27: {
{
c = s_getc(); c = s_getc();
if (c == 91) { if (c == 91) {
c = s_getc(); c = s_getc();
} }
} } break;
break; case 'p': {
case 'p':
{
s_printf(get_string(155)); s_printf(get_string(155));
s_readpass(buffer, 16); s_readpass(buffer, 16);
hash = hash_sha256(buffer, user->salt); hash = hash_sha256(buffer, user->salt);
@ -76,23 +73,19 @@ void settings_menu(struct user_record *user) {
} else { } else {
s_printf(get_string(159)); s_printf(get_string(159));
} }
} } break;
break; case 'l': {
case 'l':
{
s_printf(get_string(160)); s_printf(get_string(160));
s_readstring(buffer, 32); s_readstring(buffer, 32);
free(user->location); free(user->location);
user->location = (char *)malloc(strlen(buffer) + 1); user->location = (char *)malloc(strlen(buffer) + 1);
strcpy(user->location, buffer); strcpy(user->location, buffer);
save_user(user); save_user(user);
} } break;
break; case 'a': {
case 'a':
{
s_printf(get_string(206)); s_printf(get_string(206));
for (i=0;i<conf.archiver_count;i++) { for (i = 0; i < conf.archiver_count; i++) {
s_printf(get_string(207), i + 1, conf.archivers[i]->name); s_printf(get_string(207), i + 1, conf.archivers[i]->name);
} }
@ -106,14 +99,12 @@ void settings_menu(struct user_record *user) {
user->defarchiver = new_arc; user->defarchiver = new_arc;
save_user(user); save_user(user);
} }
} } break;
break;
case 'o': case 'o': {
{
s_printf(get_string(212)); s_printf(get_string(212));
for (i=0;i<conf.protocol_count;i++) { for (i = 0; i < conf.protocol_count; i++) {
s_printf(get_string(207), i + 1, conf.protocols[i]->name); s_printf(get_string(207), i + 1, conf.protocols[i]->name);
} }
@ -127,38 +118,28 @@ void settings_menu(struct user_record *user) {
user->defprotocol = new_arc; user->defprotocol = new_arc;
save_user(user); save_user(user);
} }
} } break;
break; case 'm': {
case 'm':
{
user->nodemsgs = !user->nodemsgs; user->nodemsgs = !user->nodemsgs;
save_user(user); save_user(user);
} } break;
break; case 'c': {
case 'c':
{
user->codepage = !user->codepage; user->codepage = !user->codepage;
save_user(user); save_user(user);
} } break;
break; case 'e': {
case 'e':
{
user->exteditor++; user->exteditor++;
if (user->exteditor == 3) { if (user->exteditor == 3) {
user->exteditor = 0; user->exteditor = 0;
} }
save_user(user); save_user(user);
} } break;
break; case 'b': {
case 'b':
{
user->bwavepktno = 0; user->bwavepktno = 0;
user->bwavestyle = !user->bwavestyle; user->bwavestyle = !user->bwavestyle;
save_user(user); save_user(user);
} } break;
break; case 's': {
case 's':
{
// set signature // set signature
if (user->signature != NULL) { if (user->signature != NULL) {
free(user->signature); free(user->signature);
@ -168,14 +149,11 @@ void settings_menu(struct user_record *user) {
user->signature = sig; user->signature = sig;
save_user(user); save_user(user);
} }
} } break;
break; case 't': {
case 't':
{
user->autosig = !user->autosig; user->autosig = !user->autosig;
save_user(user); save_user(user);
} } break;
break;
case 'q': case 'q':
dosettings = 1; dosettings = 1;
break; break;

View File

@ -10,8 +10,8 @@ char **strings;
int string_count; int string_count;
void chomp(char *string) { void chomp(char *string) {
while (strlen(string) && (string[strlen(string)-1] == '\r' || string[strlen(string)-1] == '\n')) { while (strlen(string) && (string[strlen(string) - 1] == '\r' || string[strlen(string) - 1] == '\n')) {
string[strlen(string)-1] = '\0'; string[strlen(string) - 1] = '\0';
} }
} }
@ -19,7 +19,7 @@ char *parse_newlines(char *string) {
char *newstring = (char *)malloc(strlen(string) + 1); char *newstring = (char *)malloc(strlen(string) + 1);
int pos = 0; int pos = 0;
int i; int i;
for (i=0;i<strlen(string);i++) { for (i = 0; i < strlen(string); i++) {
if (string[i] == '\\') { if (string[i] == '\\') {
if (i < strlen(string) - 1) { if (i < strlen(string) - 1) {
i++; i++;

View File

@ -7,7 +7,7 @@
#include "bbs.h" #include "bbs.h"
#include "inih/ini.h" #include "inih/ini.h"
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined (LIBRESSL_VERSION_NUMBER) #if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
#define EVP_MD_CTX_new EVP_MD_CTX_create #define EVP_MD_CTX_new EVP_MD_CTX_create
#define EVP_MD_CTX_free EVP_MD_CTX_destroy #define EVP_MD_CTX_free EVP_MD_CTX_destroy
#endif #endif
@ -29,18 +29,16 @@ char *hash_sha256(char *pass, char *salt) {
sprintf(buffer, "%s%s", pass, salt); sprintf(buffer, "%s%s", pass, salt);
EVP_MD_CTX *context = EVP_MD_CTX_new(); EVP_MD_CTX *context = EVP_MD_CTX_new();
if (context != NULL) { if (context != NULL) {
if(EVP_DigestInit_ex(context, EVP_sha256(), NULL)) { if (EVP_DigestInit_ex(context, EVP_sha256(), NULL)) {
if(EVP_DigestUpdate(context, buffer, strlen(buffer))) { if (EVP_DigestUpdate(context, buffer, strlen(buffer))) {
if(EVP_DigestFinal_ex(context, hash, &length_of_hash)) { if (EVP_DigestFinal_ex(context, hash, &length_of_hash)) {
shash = (char *)malloc(length_of_hash * 2 + 1); shash = (char *)malloc(length_of_hash * 2 + 1);
for(i = 0; i < length_of_hash; i++) { for (i = 0; i < length_of_hash; i++) {
sprintf(shash + (i * 2), "%02x", (int)hash[i]); sprintf(shash + (i * 2), "%02x", (int)hash[i]);
} }
EVP_MD_CTX_free(context); EVP_MD_CTX_free(context);
free(buffer); free(buffer);
@ -73,7 +71,7 @@ void gen_salt(char **s) {
dolog("Unable to open /dev/urandom!"); dolog("Unable to open /dev/urandom!");
exit(-1); exit(-1);
} }
for (i=0;i<10;i++) { for (i = 0; i < 10; i++) {
fread(&c, 1, 1, fptr); fread(&c, 1, 1, fptr);
salt[i] = (char)((abs(c) % 93) + 33); salt[i] = (char)((abs(c) % 93) + 33);
} }
@ -81,9 +79,8 @@ void gen_salt(char **s) {
salt[10] = '\0'; salt[10] = '\0';
} }
static int secLevel(void* user, const char* section, const char* name, static int secLevel(void *user, const char *section, const char *name,
const char* value) const char *value) {
{
struct sec_level_t *conf = (struct sec_level_t *)user; struct sec_level_t *conf = (struct sec_level_t *)user;
if (strcasecmp(section, "main") == 0) { if (strcasecmp(section, "main") == 0) {
@ -145,7 +142,6 @@ int save_user(struct user_record *user) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
} }
rc = sqlite3_step(res); rc = sqlite3_step(res);
if (rc != SQLITE_DONE) { if (rc != SQLITE_DONE) {
sqlite3_finalize(res); sqlite3_finalize(res);
@ -156,7 +152,6 @@ int save_user(struct user_record *user) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
} }
int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, int msgid) { int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, int msgid) {
@ -170,7 +165,6 @@ int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, i
char *err_msg = 0; char *err_msg = 0;
int flagunflag = 0; int flagunflag = 0;
flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid); flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid);
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
@ -185,7 +179,7 @@ int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, i
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg); dolog("SQL error: %s", err_msg);
@ -266,7 +260,6 @@ int msgbase_sub_unsub(int conference, int msgbase) {
char *err_msg = 0; char *err_msg = 0;
int subunsub = 0; int subunsub = 0;
subunsub = msgbase_is_subscribed(conference, msgbase); subunsub = msgbase_is_subscribed(conference, msgbase);
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
@ -281,7 +274,7 @@ int msgbase_sub_unsub(int conference, int msgbase) {
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg); dolog("SQL error: %s", err_msg);
@ -316,8 +309,6 @@ int msgbase_is_subscribed(int conference, int msgbase) {
char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?"; char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
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); rc = sqlite3_open(buffer, &db);
@ -399,7 +390,7 @@ int inst_user(struct user_record *user) {
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg); dolog("SQL error: %s", err_msg);
@ -442,7 +433,6 @@ int inst_user(struct user_record *user) {
exit(1); exit(1);
} }
rc = sqlite3_step(res); rc = sqlite3_step(res);
if (rc != SQLITE_DONE) { if (rc != SQLITE_DONE) {
@ -547,7 +537,7 @@ struct user_record *check_user_pass(char *loginname, char *password) {
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); snprintf(buffer, 1024, "%s/s%d.ini", conf.config_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); dolog("Unable to load sec Level ini (%s)!", buffer);
exit(-1); exit(-1);
} }
@ -567,7 +557,6 @@ struct user_record *check_user_pass(char *loginname, char *password) {
user->cur_file_sub = 0; user->cur_file_sub = 0;
} }
return user; return user;
} }
@ -726,7 +715,7 @@ struct user_record *new_user() {
s_printf(get_string(240)); s_printf(get_string(240));
continue; continue;
} }
for (i=0;i<strlen(buffer);i++) { for (i = 0; i < strlen(buffer); i++) {
if (!(tolower(buffer[i]) >= 97 && tolower(buffer[i]) <= 122) && buffer[i] != 32 && !(buffer[i] >= '0' && buffer[i] <= '9')) { if (!(tolower(buffer[i]) >= 97 && tolower(buffer[i]) <= 122) && buffer[i] != 32 && !(buffer[i] >= '0' && buffer[i] <= '9')) {
s_printf(get_string(168)); s_printf(get_string(168));
nameok = 1; nameok = 1;
@ -870,7 +859,7 @@ struct user_record *new_user() {
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, PATH_MAX, "%s/config/s%d.ini", conf.bbs_path, user->sec_level); 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); dolog("Unable to load sec Level ini (%s)!", buffer);
exit(-1); exit(-1);
} }

103
src/www.c
View File

@ -40,7 +40,7 @@ struct connection_info_s {
struct MHD_PostProcessor *pp; 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; struct sockaddr *so = (struct sockaddr *)MHD_get_connection_info(con, MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr;
char *ipaddr; char *ipaddr;
if (so->sa_family == AF_INET) { if (so->sa_family == AF_INET) {
@ -66,7 +66,7 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void **
if (con_info->connection_type == POST) { if (con_info->connection_type == POST) {
if (con_info->count > 0) { if (con_info->count > 0) {
for (i=0;i<con_info->count;i++) { for (i = 0; i < con_info->count; i++) {
free(con_info->values[i]); free(con_info->values[i]);
free(con_info->keys[i]); free(con_info->keys[i]);
} }
@ -94,7 +94,7 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void **
free(con_info); 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; struct connection_info_s *con_info = coninfo_cls;
int i; int i;
@ -103,10 +103,9 @@ static int iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char
return MHD_NO; return MHD_NO;
} }
if (con_info != NULL) { if (con_info != NULL) {
if (con_info->connection_type == POST) { if (con_info->connection_type == POST) {
for (i=0;i<con_info->count;i++) { for (i = 0; i < con_info->count; i++) {
if (strcmp(con_info->keys[i], key) == 0) { 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); con_info->values[i] = (char *)realloc(con_info->values[i], strlen(con_info->values[i]) + size + 1);
strcat(con_info->values[i], data); strcat(con_info->values[i], data);
@ -150,7 +149,7 @@ void www_init() {
while (!feof(fptr)) { while (!feof(fptr)) {
chomp(buffer); chomp(buffer);
for (i=0;i<strlen(buffer);i++) { for (i = 0; i < strlen(buffer); i++) {
if (buffer[i] == ' ') { if (buffer[i] == ' ') {
buffer[i] = '\0'; buffer[i] = '\0';
if (mime_types_count == 0) { if (mime_types_count == 0) {
@ -162,7 +161,7 @@ void www_init() {
mime_types[mime_types_count] = (struct mime_type *)malloc(sizeof(struct mime_type)); mime_types[mime_types_count] = (struct mime_type *)malloc(sizeof(struct mime_type));
mime_types[mime_types_count]->mime = strdup(buffer); mime_types[mime_types_count]->mime = 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++; mime_types_count++;
break; break;
@ -183,7 +182,7 @@ char *www_get_mime_type(const char *extension) {
return default_mime_type; return default_mime_type;
} }
for (i=0;i<mime_types_count;i++) { for (i = 0; i < mime_types_count; i++) {
if (strcasecmp(extension, mime_types[i]->ext) == 0) { if (strcasecmp(extension, mime_types[i]->ext) == 0) {
return mime_types[i]->mime; return mime_types[i]->mime;
} }
@ -191,7 +190,7 @@ char *www_get_mime_type(const char *extension) {
return default_mime_type; 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 buffer[PATH_MAX];
char *page, *page_tmp; char *page, *page_tmp;
struct stat s; struct stat s;
@ -235,18 +234,18 @@ int www_401(char *header, char *footer, struct MHD_Connection * connection) {
sprintf(whole_page, "%s%s%s", header, page, footer); 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\""); MHD_add_response_header(response, "WWW-Authenticate", "Basic realm=\"BBS Area\"");
ret = MHD_queue_response (connection, 401, response); ret = MHD_queue_response(connection, 401, response);
MHD_destroy_response (response); MHD_destroy_response(response);
free(page); free(page);
return 0; 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 buffer[PATH_MAX];
char *page, *page_tmp; char *page, *page_tmp;
struct stat s; struct stat s;
@ -290,16 +289,16 @@ int www_404(char *header, char *footer, struct MHD_Connection * connection) {
sprintf(whole_page, "%s%s%s", header, page, footer); 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);
ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response); ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response);
MHD_destroy_response (response); MHD_destroy_response(response);
free(page); free(page);
return 0; 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 buffer[PATH_MAX];
char *page, *page_tmp; char *page, *page_tmp;
struct stat s; struct stat s;
@ -344,10 +343,10 @@ int www_403(char *header, char *footer, struct MHD_Connection * connection) {
sprintf(whole_page, "%s%s%s", header, page, footer); 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);
ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response); ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response);
MHD_destroy_response (response); MHD_destroy_response(response);
free(page); free(page);
return 0; return 0;
@ -377,10 +376,10 @@ struct user_record *www_auth_ok(struct MHD_Connection *connection, const char *u
decoded_pass[len] = '\0'; decoded_pass[len] = '\0';
username = decoded_pass; username = decoded_pass;
for (i=0;i<strlen(decoded_pass);i++) { for (i = 0; i < strlen(decoded_pass); i++) {
if (decoded_pass[i] == ':') { if (decoded_pass[i] == ':') {
decoded_pass[i] = '\0'; decoded_pass[i] = '\0';
password = &decoded_pass[i+1]; password = &decoded_pass[i + 1];
break; break;
} }
} }
@ -394,7 +393,7 @@ struct user_record *www_auth_ok(struct MHD_Connection *connection, const char *u
return NULL; return NULL;
} }
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) { 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) {
struct MHD_Response *response; struct MHD_Response *response;
int ret; int ret;
@ -423,7 +422,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
int file_dir; int file_dir;
int file_sub; int file_sub;
char *filen; char *filen;
// char *static_buffer; // char *static_buffer;
page = NULL; page = NULL;
@ -604,7 +603,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); 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/new") == 0) { } else if (strcasecmp(url, "/email/new") == 0) {
con_inf->user = www_auth_ok(connection, url_); con_inf->user = www_auth_ok(connection, url_);
if (con_inf->user == NULL) { if (con_inf->user == NULL) {
@ -738,11 +737,11 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
if (conference != -1 && area != -1 && msg != -1) { if (conference != -1 && area != -1 && msg != -1) {
msgbase_flag_unflag(con_inf->user, conference, area, msg); 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); snprintf(buffer, PATH_MAX, "%smsgs/%d/%d/%d", conf.www_url, conference, area, msg);
MHD_add_response_header (response, "Location", buffer); MHD_add_response_header(response, "Location", buffer);
MHD_queue_response (connection, MHD_HTTP_FOUND, response); MHD_queue_response(connection, MHD_HTTP_FOUND, response);
MHD_destroy_response(response); MHD_destroy_response(response);
free(header); free(header);
free(footer); free(footer);
@ -828,7 +827,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
} }
free(url_copy); 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) { if (val != NULL) {
skip = atoi(val); skip = atoi(val);
@ -842,7 +841,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
page = www_msgs_messageview(con_inf->user, conference, area, msg); page = www_msgs_messageview(con_inf->user, conference, area, msg);
} }
if (page == NULL) { if (page == NULL) {
if (www_403(header, footer, connection) != 0) { if (www_403(header, footer, connection) != 0) {
free(header); free(header);
@ -866,9 +864,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
mime = NULL; mime = NULL;
// get mimetype // get mimetype
for (i=strlen(url);i>0;--i) { for (i = strlen(url); i > 0; --i) {
if (url[i] == '.') { if (url[i] == '.') {
mime = www_get_mime_type(&url[i+1]); mime = www_get_mime_type(&url[i + 1]);
break; break;
} }
if (url[i] == '/') { if (url[i] == '/') {
@ -881,7 +879,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
mime = www_get_mime_type(NULL); mime = www_get_mime_type(NULL);
} }
// load file // load file
sprintf(buffer, "%s%s", conf.www_path, url); sprintf(buffer, "%s%s", conf.www_path, url);
@ -894,8 +891,8 @@ 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_fd(s.st_size, fno);
//response = MHD_create_response_from_buffer (s.st_size, (void*) static_buffer, MHD_RESPMEM_MUST_FREE); //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); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime);
ret = MHD_queue_response (connection, MHD_HTTP_OK, response); ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
MHD_destroy_response (response); MHD_destroy_response(response);
free(header); free(header);
free(footer); free(footer);
return ret; return ret;
@ -964,9 +961,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
if (filename != NULL) { if (filename != NULL) {
mime = NULL; mime = NULL;
// get mimetype // get mimetype
for (i=strlen(filename);i>0;--i) { for (i = strlen(filename); i > 0; --i) {
if (filename[i] == '.') { if (filename[i] == '.') {
mime = www_get_mime_type(&filename[i+1]); mime = www_get_mime_type(&filename[i + 1]);
break; break;
} }
if (filename[i] == '/') { if (filename[i] == '/') {
@ -982,7 +979,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
fno = open(filename, O_RDONLY); fno = open(filename, O_RDONLY);
if (fno != -1) { if (fno != -1) {
response = MHD_create_response_from_fd(s.st_size, fno); response = MHD_create_response_from_fd(s.st_size, fno);
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime);
sprintf(buffer, "%ld", s.st_size); sprintf(buffer, "%ld", s.st_size);
@ -990,8 +986,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename)); snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename));
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer);
ret = MHD_queue_response (connection, MHD_HTTP_OK, response); ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
MHD_destroy_response (response); MHD_destroy_response(response);
free(header); free(header);
free(footer); free(footer);
free(filename); free(filename);
@ -1033,9 +1029,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
if (filename != NULL) { if (filename != NULL) {
mime = NULL; mime = NULL;
// get mimetype // get mimetype
for (i=strlen(filename);i>0;--i) { for (i = strlen(filename); i > 0; --i) {
if (filename[i] == '.') { if (filename[i] == '.') {
mime = www_get_mime_type(&filename[i+1]); mime = www_get_mime_type(&filename[i + 1]);
break; break;
} }
if (filename[i] == '/') { if (filename[i] == '/') {
@ -1059,8 +1055,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename)); snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename));
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer);
ret = MHD_queue_response (connection, MHD_HTTP_OK, response); ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
MHD_destroy_response (response); MHD_destroy_response(response);
free(header); free(header);
free(footer); free(footer);
free(filename); free(filename);
@ -1098,11 +1094,11 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
return MHD_YES; return MHD_YES;
} }
if (con_inf->pp == NULL) { if (con_inf->pp == NULL) {
con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void*) con_inf); con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void *)con_inf);
} }
if (*upload_data_size != 0) { 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; *upload_data_size = 0;
return MHD_YES; return MHD_YES;
@ -1110,7 +1106,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
subj = NULL; subj = NULL;
to = NULL; to = NULL;
body = NULL; body = NULL;
for (i=0;i<con_inf->count;i++) { for (i = 0; i < con_inf->count; i++) {
if (strcmp(con_inf->keys[i], "recipient") == 0) { if (strcmp(con_inf->keys[i], "recipient") == 0) {
to = con_inf->values[i]; to = con_inf->values[i];
} else if (strcmp(con_inf->keys[i], "subject") == 0) { } else if (strcmp(con_inf->keys[i], "subject") == 0) {
@ -1150,11 +1146,11 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
return MHD_YES; return MHD_YES;
} }
if (con_inf->pp == NULL) { if (con_inf->pp == NULL) {
con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void*) con_inf); con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void *)con_inf);
} }
if (*upload_data_size != 0) { 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; *upload_data_size = 0;
return MHD_YES; return MHD_YES;
@ -1166,7 +1162,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
conference = -1; conference = -1;
area = -1; area = -1;
for (i=0;i<con_inf->count;i++) { for (i = 0; i < con_inf->count; i++) {
if (strcmp(con_inf->keys[i], "recipient") == 0) { if (strcmp(con_inf->keys[i], "recipient") == 0) {
to = con_inf->values[i]; to = con_inf->values[i];
} else if (strcmp(con_inf->keys[i], "subject") == 0) { } else if (strcmp(con_inf->keys[i], "subject") == 0) {
@ -1209,7 +1205,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
sprintf(whole_page, "%s%s%s", header, page, footer); sprintf(whole_page, "%s%s%s", header, page, footer);
} else { } else {
free(header); free(header);
free(footer); free(footer);
@ -1220,12 +1215,12 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
free(footer); free(footer);
return MHD_NO; 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"); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html");
ret = MHD_queue_response (connection, MHD_HTTP_OK, response); ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
MHD_destroy_response (response); MHD_destroy_response(response);
free(page); free(page);
free(header); free(header);
free(footer); free(footer);

View File

@ -5,7 +5,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "bbs.h" #include "bbs.h"
extern struct bbs_config conf; extern struct bbs_config conf;
char *www_blog() { char *www_blog() {
@ -21,7 +20,7 @@ char *www_blog() {
int hour; int hour;
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
@ -47,14 +46,14 @@ char *www_blog() {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} else { } else {
for (i=0;i<blog_entry_count;i++) { for (i = 0; i < blog_entry_count; i++) {
localtime_r(&blog_entries[i]->date, &thetime); localtime_r(&blog_entries[i]->date, &thetime);
if (thetime.tm_hour >= 12) { if (thetime.tm_hour >= 12) {
hour = thetime.tm_hour - 12; hour = thetime.tm_hour - 12;
} else { } else {
hour = thetime.tm_hour; hour = thetime.tm_hour;
} }
sprintf(buffer, "<div class=\"blog-header\"><div class=\"blog-title\"><h3>%s</h3></div><div class=\"blog-date\">%d:%02d%s %s, %s %d %d</div><div class=\"blog-author\">by %s</div></div>", 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); sprintf(buffer, "<div class=\"blog-header\"><div class=\"blog-title\"><h3>%s</h3></div><div class=\"blog-date\">%d:%02d%s %s, %s %d %d</div><div class=\"blog-author\">by %s</div></div>", 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) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
@ -70,9 +69,9 @@ char *www_blog() {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
for (j=0;j<strlen(blog_entries[i]->body);j++) { for (j = 0; j < strlen(blog_entries[i]->body); j++) {
if (blog_entries[i]->body[j] == '\r') { if (blog_entries[i]->body[j] == '\r') {
if (blog_entries[i]->body[j+1] == '\r') { if (blog_entries[i]->body[j + 1] == '\r') {
sprintf(buffer, "</p><p>"); sprintf(buffer, "</p><p>");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -106,7 +105,7 @@ char *www_blog() {
len += strlen(buffer); len += strlen(buffer);
} }
for (i=0;i<blog_entry_count;i++) { for (i = 0; i < blog_entry_count; i++) {
free(blog_entries[i]->subject); free(blog_entries[i]->subject);
free(blog_entries[i]->author); free(blog_entries[i]->author);
free(blog_entries[i]->body); free(blog_entries[i]->body);

View File

@ -7,7 +7,6 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include "bbs.h" #include "bbs.h"
extern struct bbs_config conf; extern struct bbs_config conf;
int www_email_delete(struct user_record *user, int id) { int www_email_delete(struct user_record *user, int id) {
@ -36,7 +35,7 @@ int www_email_delete(struct user_record *user, int id) {
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, csql, 0, 0, &err_msg); rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
sqlite3_free(err_msg); sqlite3_free(err_msg);
sqlite3_close(db); sqlite3_close(db);
@ -88,8 +87,6 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
return 0; return 0;
} }
uname(&name); 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); 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);
@ -97,7 +94,7 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
body = (char *)malloc(strlen(ibody) + strlen(buffer) + 1); body = (char *)malloc(strlen(ibody) + strlen(buffer) + 1);
memset(body, 0, strlen(ibody) + strlen(buffer) + 1); memset(body, 0, strlen(ibody) + strlen(buffer) + 1);
pos = 0; pos = 0;
for (i = 0;i<strlen(ibody);i++) { for (i = 0; i < strlen(ibody); i++) {
if (ibody[i] != '\n') { if (ibody[i] != '\n') {
body[pos] = ibody[i]; body[pos] = ibody[i];
pos++; pos++;
@ -117,7 +114,7 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, csql, 0, 0, &err_msg); rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
sqlite3_free(err_msg); sqlite3_free(err_msg);
sqlite3_close(db); sqlite3_close(db);
@ -139,8 +136,6 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
} }
sqlite3_step(res); sqlite3_step(res);
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
@ -205,7 +200,6 @@ char *www_new_email() {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "</form>\n"); sprintf(buffer, "</form>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -261,7 +255,7 @@ char *www_email_display(struct user_record *user, int email) {
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, email_create_sql, 0, 0, &err_msg); rc = sqlite3_exec(db, email_create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
sqlite3_free(err_msg); sqlite3_free(err_msg);
sqlite3_close(db); sqlite3_close(db);
@ -346,7 +340,7 @@ char *www_email_display(struct user_record *user, int email) {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
for (i=0;i<strlen(body);i++) { for (i = 0; i < strlen(body); i++) {
if (body[i] == '\r') { if (body[i] == '\r') {
sprintf(buffer, "<br />"); sprintf(buffer, "<br />");
} else if (body[i] == '<') { } else if (body[i] == '<') {
@ -440,7 +434,7 @@ char *www_email_display(struct user_record *user, int email) {
chars = 0; chars = 0;
for (i=0;i<strlen(body);i++) { for (i = 0; i < strlen(body); i++) {
if (body[i] == '\r') { if (body[i] == '\r') {
sprintf(buffer, "\n> "); sprintf(buffer, "\n> ");
chars = 0; chars = 0;
@ -449,7 +443,7 @@ char *www_email_display(struct user_record *user, int email) {
chars = 1; chars = 1;
} else { } else {
sprintf(buffer, "%c", body[i]); sprintf(buffer, "%c", body[i]);
chars ++; chars++;
} }
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -475,7 +469,6 @@ char *www_email_display(struct user_record *user, int email) {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "</form>\n"); sprintf(buffer, "</form>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -552,7 +545,6 @@ char *www_email_summary(struct user_record *user) {
"date INTEGER," "date INTEGER,"
"seen INTEGER);"; "seen INTEGER);";
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
len = 0; len = 0;
@ -582,9 +574,9 @@ char *www_email_summary(struct user_record *user) {
free(page); 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); rc = sqlite3_exec(db, email_create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) { if (rc != SQLITE_OK) {
sqlite3_free(err_msg); sqlite3_free(err_msg);
sqlite3_close(db); sqlite3_close(db);
@ -642,7 +634,6 @@ sqlite3_busy_timeout(db, 5000);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);

View File

@ -7,10 +7,9 @@
#include "bbs.h" #include "bbs.h"
#include "../deps/hashids/hashids.h" #include "../deps/hashids/hashids.h"
extern struct bbs_config conf; extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
extern char * aha(char *input); extern char *aha(char *input);
static char *www_decode(char *clean_url) { static char *www_decode(char *clean_url) {
char *url = (char *)malloc(strlen(clean_url) + 1); char *url = (char *)malloc(strlen(clean_url) + 1);
@ -22,12 +21,12 @@ static char *www_decode(char *clean_url) {
return NULL; return NULL;
} }
for (i=0;i<strlen(clean_url);i++) { for (i = 0; i < strlen(clean_url); i++) {
if (clean_url[i] == '%') { if (clean_url[i] == '%') {
c = clean_url[i+1] * 16 + clean_url[i+2]; c = clean_url[i + 1] * 16 + clean_url[i + 2];
url[j++] = (char)c; url[j++] = (char)c;
url[j] = '\0'; url[j] = '\0';
i+=2; i += 2;
} else { } else {
url[j++] = clean_url[i]; url[j++] = clean_url[i];
url[j] = '\0'; url[j] = '\0';
@ -50,13 +49,13 @@ static char *www_encode(char *url) {
j = 0; j = 0;
memset(clean_url, 0, strlen(url) * 3); memset(clean_url, 0, strlen(url) * 3);
for (i=0;i<strlen(url);i++) { for (i = 0; i < strlen(url); i++) {
if (isalnum(url[i]) || url[i] == '~' || url[i] == '.' || url[i] == '_') { if (isalnum(url[i]) || url[i] == '~' || url[i] == '.' || url[i] == '_') {
sprintf(&clean_url[j], "%c", url[i]); sprintf(&clean_url[j], "%c", url[i]);
j++; j++;
} else { } else {
sprintf(&clean_url[j], "%%%02X", url[i]); sprintf(&clean_url[j], "%%%02X", url[i]);
j+=3; j += 3;
} }
} }
@ -372,7 +371,7 @@ char *www_files_display_listing(int dir, int sub) {
description = strdup((char *)sqlite3_column_text(res, 2)); description = strdup((char *)sqlite3_column_text(res, 2));
for (i=0;i<strlen(description);i++) { for (i = 0; i < strlen(description); i++) {
if (description[i] == '\n') { if (description[i] == '\n') {
description[i] = '\r'; description[i] = '\r';
} }
@ -405,7 +404,6 @@ char *www_files_display_listing(int dir, int sub) {
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} }
snprintf(buffer, 4096, "</tbody></table>\n"); snprintf(buffer, 4096, "</tbody></table>\n");
@ -443,7 +441,7 @@ char *www_files_areas() {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
for (i=0;i<conf.file_directory_count;i++) { for (i = 0; i < conf.file_directory_count; i++) {
if (conf.file_directories[i]->display_on_web) { if (conf.file_directories[i]->display_on_web) {
sprintf(buffer, "<div class=\"conference-list-item\">%s</div>\n", conf.file_directories[i]->name); sprintf(buffer, "<div class=\"conference-list-item\">%s</div>\n", conf.file_directories[i]->name);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
@ -452,7 +450,7 @@ char *www_files_areas() {
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
for (j=0;j<conf.file_directories[i]->file_sub_count;j++) { for (j = 0; j < conf.file_directories[i]->file_sub_count; j++) {
sprintf(buffer, "<div class=\"area-list-item\"><a href=\"%sfiles/areas/%d/%d/\">%s</a></div>\n", conf.www_url, i, j, conf.file_directories[i]->file_subs[j]->name); sprintf(buffer, "<div class=\"area-list-item\"><a href=\"%sfiles/areas/%d/%d/\">%s</a></div>\n", conf.www_url, i, j, conf.file_directories[i]->file_subs[j]->name);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -482,7 +480,7 @@ char *www_files_get_from_area(int dir, int sub, char *clean_file) {
file = www_decode(clean_file); file = www_decode(clean_file);
for (i=0;i<strlen(file);i++) { for (i = 0; i < strlen(file); i++) {
if (file[i] == '^' || file[i] == '%' || file[i] == '_') { if (file[i] == '^' || file[i] == '%' || file[i] == '_') {
extra++; extra++;
} }
@ -495,7 +493,7 @@ char *www_files_get_from_area(int dir, int sub, char *clean_file) {
filenamelike[i] = '\0'; filenamelike[i] = '\0';
for (j = 0; j < strlen(file); j++) { for (j = 0; j < strlen(file); j++) {
switch(file[j]) { switch (file[j]) {
case '^': case '^':
filenamelike[i++] = '^'; filenamelike[i++] = '^';
filenamelike[i++] = '^'; filenamelike[i++] = '^';
@ -539,7 +537,6 @@ char *www_files_get_from_area(int dir, int sub, char *clean_file) {
rc = sqlite3_step(res); rc = sqlite3_step(res);
if (rc == SQLITE_ROW) { if (rc == SQLITE_ROW) {
ret = strdup(sqlite3_column_text(res, 0)); ret = strdup(sqlite3_column_text(res, 0));
} }
free(filenamelike); free(filenamelike);

View File

@ -5,7 +5,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "bbs.h" #include "bbs.h"
extern struct bbs_config conf; extern struct bbs_config conf;
char *www_last10() { char *www_last10() {
@ -15,13 +14,13 @@ char *www_last10() {
char buffer[4096]; char buffer[4096];
struct last10_callers callers[10]; struct last10_callers callers[10];
int i,z; int i, z;
struct tm l10_time; struct tm l10_time;
FILE *fptr = fopen("last10v2.dat", "rb"); FILE *fptr = fopen("last10v2.dat", "rb");
if (fptr != NULL) { 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) { if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) {
break; break;
} }
@ -53,7 +52,7 @@ char *www_last10() {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
for (z=0;z<i;z++) { for (z = 0; z < i; z++) {
localtime_r(&callers[z].time, &l10_time); localtime_r(&callers[z].time, &l10_time);
if (conf.date_style == 1) { if (conf.date_style == 1) {
if (callers[z].calls == 1) { if (callers[z].calls == 1) {

View File

@ -12,16 +12,15 @@
#define IN 0 #define IN 0
#define OUT 1 #define OUT 1
extern char * aha(char *input); extern char *aha(char *input);
extern struct bbs_config conf; extern struct bbs_config conf;
static char *www_wordwrap(char *content, int cutoff); static char *www_wordwrap(char *content, int cutoff);
char *www_sanitize(char *inp) { char *www_sanitize(char *inp) {
int i; int i;
char *result; char *result;
int len = 0; int len = 0;
for (i=0;i<strlen(inp);i++) { for (i = 0; i < strlen(inp); i++) {
if ((inp[i] == '<') || (inp[i] == '>')) { if ((inp[i] == '<') || (inp[i] == '>')) {
len += 4; len += 4;
} else if (inp[i] == '&') { } else if (inp[i] == '&') {
@ -34,7 +33,7 @@ char *www_sanitize(char *inp) {
result = (char *)malloc(len + 1); result = (char *)malloc(len + 1);
memset(result, 0, len + 1); memset(result, 0, len + 1);
len = 0; len = 0;
for (i=0;i<strlen(inp);i++) { for (i = 0; i < strlen(inp); i++) {
if (inp[i] == '<') { if (inp[i] == '<') {
result[len++] = '&'; result[len++] = '&';
result[len++] = 'l'; result[len++] = 'l';
@ -79,7 +78,7 @@ char *www_msgs_arealist(struct user_record *user) {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
for (i=0;i<conf.mail_conference_count;i++) { for (i = 0; i < conf.mail_conference_count; i++) {
if (conf.mail_conferences[i]->sec_level <= user->sec_level) { if (conf.mail_conferences[i]->sec_level <= user->sec_level) {
sprintf(buffer, "<div class=\"conference-list-item\">%s</div>\n", conf.mail_conferences[i]->name); sprintf(buffer, "<div class=\"conference-list-item\">%s</div>\n", conf.mail_conferences[i]->name);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
@ -89,7 +88,7 @@ char *www_msgs_arealist(struct user_record *user) {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
for (j=0;j<conf.mail_conferences[i]->mail_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 (conf.mail_conferences[i]->mail_areas[j]->read_sec_level <= user->sec_level) {
if (new_messages(user, i, j) > 0) { if (new_messages(user, i, j) > 0) {
@ -191,7 +190,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
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; date = (time_t)mhrs->msgs[i]->msg_h->DateWritten;
gmtime_r(&date, &msg_date); gmtime_r(&date, &msg_date);
to = www_sanitize(mhrs->msgs[i]->to); to = www_sanitize(mhrs->msgs[i]->to);
@ -266,7 +265,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) { char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) {
s_JamBase *jb; s_JamBase *jb;
s_JamMsgHeader jmh; s_JamMsgHeader jmh;
s_JamSubPacket* jsp; s_JamSubPacket *jsp;
s_JamSubfield jsf; s_JamSubfield jsf;
s_JamLastRead jlr; s_JamLastRead jlr;
s_JamBaseHeader jbh; s_JamBaseHeader jbh;
@ -325,7 +324,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
return NULL; return NULL;
} }
for (z=0;z<jsp->NumFields;z++) { for (z = 0; z < jsp->NumFields; z++) {
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
subject = (char *)malloc(jsp->Fields[z]->DatLen + 1); subject = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(subject, 0, jsp->Fields[z]->DatLen + 1); memset(subject, 0, jsp->Fields[z]->DatLen + 1);
@ -411,7 +410,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
body = (char *)malloc(jmh.TxtLen + 1); body = (char *)malloc(jmh.TxtLen + 1);
memset(body, 0, 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) { if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) {
jlr.UserCRC = JAM_Crc32(user->loginname, strlen(user->loginname)); jlr.UserCRC = JAM_Crc32(user->loginname, strlen(user->loginname));
@ -543,7 +542,6 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
aha_text = (char *)malloc(jmh.TxtLen + 1); aha_text = (char *)malloc(jmh.TxtLen + 1);
memcpy(aha_text, body, jmh.TxtLen); memcpy(aha_text, body, jmh.TxtLen);
@ -567,8 +565,6 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "<div class=\"msg-reply-form\">\n"); sprintf(buffer, "<div class=\"msg-reply-form\">\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -654,13 +650,13 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
replybody = (char *)malloc(strlen(body) + 1); replybody = (char *)malloc(strlen(body) + 1);
l2 = 0; l2 = 0;
for (l1=0;l1<strlen(body);l1++){ for (l1 = 0; l1 < strlen(body); l1++) {
if (body[l1] == '\e' && body[l1+1] == '[') { if (body[l1] == '\e' && body[l1 + 1] == '[') {
while (strchr("ABCDEFGHIGJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", body[l1]) == NULL && l1 < strlen(body)) while (strchr("ABCDEFGHIGJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", body[l1]) == NULL && l1 < strlen(body))
l1++; l1++;
} else { } else {
replybody[l2++] = body[l1]; replybody[l2++] = body[l1];
replybody[l2] ='\0'; replybody[l2] = '\0';
} }
} }
@ -674,7 +670,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
free(replybody); free(replybody);
} }
for (i=0;i<strlen(body2);i++) { for (i = 0; i < strlen(body2); i++) {
if (body2[i] == '\r') { if (body2[i] == '\r') {
sprintf(buffer, "\n %c> ", from[0]); sprintf(buffer, "\n %c> ", from[0]);
chars = 0; chars = 0;
@ -683,7 +679,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
chars = 1; chars = 1;
} else { } else {
sprintf(buffer, "%c", body2[i]); sprintf(buffer, "%c", body2[i]);
chars ++; chars++;
} }
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -701,7 +697,6 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "<input type=\"submit\" name=\"submit\" value=\"Reply\" />\n<br />"); sprintf(buffer, "<input type=\"submit\" name=\"submit\" value=\"Reply\" />\n<br />");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -710,7 +705,6 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "</form>\n"); sprintf(buffer, "</form>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -765,7 +759,7 @@ static char *www_wordwrap(char *content, int cutoff) {
int quote_line = 0; int quote_line = 0;
int z; int z;
for (i=0;i<len;i++) { for (i = 0; i < len; i++) {
if (content[i] == '\n') { if (content[i] == '\n') {
continue; continue;
} }
@ -776,19 +770,20 @@ static char *www_wordwrap(char *content, int cutoff) {
at = 0; at = 0;
len = strlen(content); len = strlen(content);
for (i=0;i<len-1;i++) { for (i = 0; i < len - 1; i++) {
if (content[i] == '>' && line_count < 4) { if (content[i] == '>' && line_count < 4) {
quote_line = 1; quote_line = 1;
} }
if (content[i] == '\r' && content[i+1] != '\r') { if (content[i] == '\r' && content[i + 1] != '\r') {
if (content[i+1] == ' ' && quote_line != 1) { if (content[i + 1] == ' ' && quote_line != 1) {
content[at++] = '\r'; content[at++] = '\r';
line_count = 0; line_count = 0;
quote_line = 0; quote_line = 0;
} else if (quote_line != 1) { } else if (quote_line != 1) {
for (z = i+1;content[z] != ' ' && z < len;z++); for (z = i + 1; content[z] != ' ' && z < len; z++)
if (at > 0 && content[at-1] != '\r' && content[at-1] != ' ' && cutoff - line_count < z - i) { ;
if (at > 0 && content[at - 1] != '\r' && content[at - 1] != ' ' && cutoff - line_count < z - i) {
content[at++] = ' '; content[at++] = ' ';
line_count++; line_count++;
} else { } else {
@ -801,7 +796,7 @@ static char *www_wordwrap(char *content, int cutoff) {
line_count = 0; 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';
content[at++] = '\r'; content[at++] = '\r';
line_count = 0; line_count = 0;
@ -815,7 +810,6 @@ static char *www_wordwrap(char *content, int cutoff) {
content[at++] = content[i]; content[at++] = content[i];
content[at] = '\0'; content[at] = '\0';
at = 0; at = 0;
len = strlen(content); len = strlen(content);
@ -827,7 +821,7 @@ static char *www_wordwrap(char *content, int cutoff) {
line_count = 0; line_count = 0;
quote_line = 0; quote_line = 0;
for (i=0;i<len;i++) { for (i = 0; i < len; i++) {
if (content[i] != '\r') { if (content[i] != '\r') {
ret[at] = content[i]; ret[at] = content[i];
if (content[i] == ' ') { if (content[i] == ' ') {
@ -882,7 +876,7 @@ static char *www_wordwrap(char *content, int cutoff) {
int www_send_msg(struct user_record *user, char *to, char *subj, int conference, int area, char *replyid, char *body) { int www_send_msg(struct user_record *user, char *to, char *subj, int conference, int area, char *replyid, char *body) {
s_JamBase *jb; s_JamBase *jb;
s_JamMsgHeader jmh; s_JamMsgHeader jmh;
s_JamSubPacket* jsp; s_JamSubPacket *jsp;
s_JamSubfield jsf; s_JamSubfield jsf;
s_JamLastRead jlr; s_JamLastRead jlr;
s_JamBaseHeader jbh; s_JamBaseHeader jbh;
@ -918,7 +912,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
return 0; return 0;
} }
JAM_ClearMsgHeader( &jmh ); JAM_ClearMsgHeader(&jmh);
jmh.DateWritten = (uint32_t)utc_to_local(time(NULL)); jmh.DateWritten = (uint32_t)utc_to_local(time(NULL));
jmh.Attribute |= JAM_MSG_LOCAL; jmh.Attribute |= JAM_MSG_LOCAL;
@ -1034,8 +1028,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
return 0; return 0;
} }
if (conf.mail_conferences[conference]->tagline != NULL) { if (conf.mail_conferences[conference]->tagline != NULL) {
tagline = conf.mail_conferences[conference]->tagline; tagline = conf.mail_conferences[conference]->tagline;
} else { } else {
@ -1078,7 +1070,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
return 0; return 0;
} }
memset(body3, 0, strlen(body2) + 2 + strlen(buffer)); memset(body3, 0, strlen(body2) + 2 + strlen(buffer));
pos = 0; pos = 0;
sprintf(body3, "%s%s", body2, buffer); sprintf(body3, "%s%s", body2, buffer);
@ -1113,7 +1104,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
} }
} }
free(body2); free(body2);
JAM_UnlockMB(jb); JAM_UnlockMB(jb);
@ -1209,7 +1199,6 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "</form>\n"); sprintf(buffer, "</form>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;