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

288
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,12 +45,11 @@ 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, ...) {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
if (conf.broadcast_enable && conf.broadcast_port != 0 && conf.broadcast_address != NULL) { if (conf.broadcast_enable && conf.broadcast_port != 0 && conf.broadcast_address != NULL) {
va_list ap; va_list ap;
va_start(ap, mess); va_start(ap, mess);
@ -79,7 +75,7 @@ void dolog_www(char *ipaddr, char *fmt, ...) {
snprintf(buffer, PATH_MAX, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday); snprintf(buffer, PATH_MAX, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday);
logfptr = fopen(buffer, "a"); logfptr = fopen(buffer, "a");
if (!logfptr) { if (!logfptr) {
return; return;
} }
va_list ap; va_list ap;
@ -107,7 +103,7 @@ void dolog(char *fmt, ...) {
snprintf(buffer, PATH_MAX, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday); snprintf(buffer, PATH_MAX, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday);
logfptr = fopen(buffer, "a"); logfptr = fopen(buffer, "a");
if (!logfptr) { if (!logfptr) {
return; return;
} }
va_list ap; va_list ap;
@ -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,24 +149,22 @@ 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'); break;
break; case 1:
case 1: ret->net = ret->net * 10 + (str[c] - '0');
ret->net = ret->net * 10 + (str[c] - '0'); break;
break; case 2:
case 2: ret->node = ret->node * 10 + (str[c] - '0');
ret->node = ret->node * 10 + (str[c] - '0'); break;
break; case 3:
case 3: 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';
} }
@ -227,7 +218,7 @@ void s_printf(char *fmt, ...) {
int should_convert_utf8() { int should_convert_utf8() {
if (gUser != NULL) { if (gUser != NULL) {
return gUser->codepage; return gUser->codepage;
} }
return conf.codepage; return conf.codepage;
} }
@ -246,11 +237,11 @@ void s_putchar(char c) {
if (sshBBS) { if (sshBBS) {
putchar(c); putchar(c);
} else { } else {
ret = send(gSocket, &c, 1, 0); ret = send(gSocket, &c, 1, 0);
if (ret == -1) { if (ret == -1) {
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
} else { } else {
@ -272,7 +263,7 @@ void s_putchar(char c) {
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
iconv_close(ic); iconv_close(ic);
free(ptr1); free(ptr1);
@ -281,7 +272,7 @@ void s_putchar(char c) {
} }
void s_putstring(char *c) { void s_putstring(char *c) {
iconv_t ic; iconv_t ic;
char *inbuf; char *inbuf;
char *outbuf; char *outbuf;
size_t inc; size_t inc;
@ -298,7 +289,7 @@ void s_putstring(char *c) {
if (ret == -1) { if (ret == -1) {
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
} else { } else {
@ -308,7 +299,7 @@ void s_putstring(char *c) {
outbuf = (char *)malloc(inc * 4); outbuf = (char *)malloc(inc * 4);
memset(outbuf, 0, inc * 4); memset(outbuf, 0, inc * 4);
ptr1 = outbuf; ptr1 = outbuf;
ptr2 = inbuf; ptr2 = inbuf;
ouc = inc * 4; ouc = inc * 4;
sz = iconv(ic, &inbuf, &inc, &outbuf, &ouc); sz = iconv(ic, &inbuf, &inc, &outbuf, &ouc);
if (sshBBS) { if (sshBBS) {
@ -318,8 +309,8 @@ void s_putstring(char *c) {
if (ret == -1) { if (ret == -1) {
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
iconv_close(ic); iconv_close(ic);
free(ptr1); free(ptr1);
@ -365,7 +356,7 @@ void s_displayansi_pause(char *file, int pause) {
s_putchar(c); s_putchar(c);
lastch = c; lastch = c;
if (pause) { if (pause) {
if (c == '\n') { if (c == '\n') {
lines++; lines++;
@ -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;
@ -463,9 +452,9 @@ char s_getchar() {
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
} }
break; break;
case IAC_WONT: case IAC_WONT:
if (d == 0) { if (d == 0) {
@ -476,9 +465,9 @@ char s_getchar() {
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
} }
break; break;
case IAC_DO: case IAC_DO:
if (d == 0) { if (d == 0) {
@ -490,7 +479,6 @@ char s_getchar() {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
} }
break; break;
@ -503,10 +491,10 @@ char s_getchar() {
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
disconnect("Disconnected"); disconnect("Disconnected");
} }
} }
} }
} }
break; break;
} }
} else if (c == 250) { } else if (c == 250) {
do { do {
@ -516,9 +504,9 @@ char s_getchar() {
if (len <= 0) { if (len <= 0) {
disconnect("Socket Closed"); disconnect("Socket Closed");
} }
} while(c != 240); } while (c != 240);
} }
do { do {
len = read(gSocket, &c, 1); len = read(gSocket, &c, 1);
} while (len == -1 && errno == EINTR); } while (len == -1 && errno == EINTR);
@ -543,7 +531,7 @@ char s_getc() {
void s_readstring_inject(char *buffer, int max, char *inject) { void s_readstring_inject(char *buffer, int max, char *inject) {
int i; int i;
char c; char c;
memset(buffer, 0, max); memset(buffer, 0, max);
if (strlen(inject) > max) { if (strlen(inject) > max) {
@ -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,8 +567,8 @@ 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';
} }
} }
void s_readstring(char *buffer, int max) { void s_readstring(char *buffer, int max) {
@ -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';
} }
} }
@ -661,7 +649,7 @@ void exit_bbs() {
mosquitto_loop_stop(mosq, 0); mosquitto_loop_stop(mosq, 0);
mosquitto_destroy(mosq); mosquitto_destroy(mosq);
mosquitto_lib_cleanup(); mosquitto_lib_cleanup();
} }
} }
void disconnect(char *calledby) { void disconnect(char *calledby) {
@ -676,7 +664,7 @@ void disconnect(char *calledby) {
if (!sshBBS) { if (!sshBBS) {
close(gSocket); close(gSocket);
} }
exit(0); exit(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;
@ -883,22 +871,21 @@ void runbbs_real(int socket, char *ip, int ssh) {
int fno; int fno;
atexit(exit_bbs); atexit(exit_bbs);
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,13 +902,12 @@ 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;
if (send(socket, iac_echo, 3, 0) != 3) { if (send(socket, iac_echo, 3, 0) != 3) {
dolog("Failed to send iac_echo"); dolog("Failed to send iac_echo");
exit(0); exit(0);
} }
if (send(socket, iac_sga, 3, 0) != 3) { if (send(socket, iac_sga, 3, 0) != 3) {
dolog("Failed to send iac_sga"); dolog("Failed to send iac_sga");
@ -930,11 +916,11 @@ void runbbs_real(int socket, char *ip, int ssh) {
} else { } else {
sshBBS = 1; sshBBS = 1;
} }
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) {
@ -946,7 +932,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
} }
write(fno, "UNKNOWN", 7); write(fno, "UNKNOWN", 7);
close(fno); close(fno);
break; break;
} }
@ -963,18 +949,18 @@ void runbbs_real(int socket, char *ip, int ssh) {
// initialize mqtt // initialize mqtt
if (conf.broadcast_enable && conf.broadcast_address != NULL && conf.broadcast_port != 0) { if (conf.broadcast_enable && conf.broadcast_address != NULL && conf.broadcast_port != 0) {
mosquitto_lib_init(); mosquitto_lib_init();
mosq = mosquitto_new(NULL, 1, NULL); mosq = mosquitto_new(NULL, 1, NULL);
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 {
if (mosquitto_loop_start(mosq) != MOSQ_ERR_SUCCESS) { if (mosquitto_loop_start(mosq) != MOSQ_ERR_SUCCESS) {
dolog("Unable to start MQTT loop."); dolog("Unable to start MQTT loop.");
conf.broadcast_enable = 0; conf.broadcast_enable = 0;
} }
} }
} }
@ -983,11 +969,11 @@ void runbbs_real(int socket, char *ip, int ssh) {
dolog("Incoming %s connection on node %d", (ssh ? "SSH" : "Telnet"), mynode); dolog("Incoming %s connection on node %d", (ssh ? "SSH" : "Telnet"), mynode);
s_displayansi("issue"); s_displayansi("issue");
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));
@ -1001,7 +987,7 @@ tryagain:
s_printf(get_string(203)); s_printf(get_string(203));
goto tryagain; goto tryagain;
} }
if (usernotfound) { if (usernotfound) {
dolog("New user on node %d", mynode); dolog("New user on node %d", mynode);
user = new_user(); user = new_user();
@ -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");
@ -1068,7 +1054,7 @@ tryagain:
} else { } else {
s_printf(get_string(25), conf.bbs_name); s_printf(get_string(25), conf.bbs_name);
s_getc(); s_getc();
gUser = new_user(); gUser = new_user();
user = gUser; user = gUser;
} }
} }
@ -1094,14 +1080,11 @@ tryagain:
if (stat(buffer, &s) == 0) { if (stat(buffer, &s) == 0) {
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) {
@ -1142,7 +1124,7 @@ tryagain:
display_bulletins(); display_bulletins();
blog_display(); blog_display();
// display info // display info
display_info(); display_info();
@ -1166,9 +1148,9 @@ tryagain:
// main menu // main menu
menu_system(conf.root_menu); menu_system(conf.root_menu);
do_logout(); do_logout();
dolog("%s is logging out, on node %d", user->loginname, mynode); dolog("%s is logging out, on node %d", user->loginname, mynode);
broadcast("USER: %s; NODE:%d; STATUS: Logging out.", user->loginname, mynode); broadcast("USER: %s; NODE:%d; STATUS: Logging out.", user->loginname, mynode);
disconnect("Log out"); disconnect("Log out");
@ -1182,7 +1164,7 @@ void do_logout() {
char c; char c;
int result; int result;
int do_internal_logout = 1; int do_internal_logout = 1;
if (conf.script_path != NULL) { if (conf.script_path != NULL) {
snprintf(buffer, PATH_MAX, "%s/logout_stanza.lua", conf.script_path); snprintf(buffer, PATH_MAX, "%s/logout_stanza.lua", conf.script_path);
if (stat(buffer, &s) == 0) { if (stat(buffer, &s) == 0) {
@ -1231,54 +1213,54 @@ void runbbs_ssh(char *ip) {
} }
int recursive_delete(const char *dir) { int recursive_delete(const char *dir) {
int ret = 0; int ret = 0;
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) {
dolog("%s: fts_open failed: %s", dir, strerror(errno)); dolog("%s: fts_open failed: %s", dir, strerror(errno));
ret = -1; ret = -1;
goto finish; goto finish;
} }
while ((curr = fts_read(ftsp))) { while ((curr = fts_read(ftsp))) {
switch (curr->fts_info) { switch (curr->fts_info) {
case FTS_NS: case FTS_NS:
case FTS_DNR: case FTS_DNR:
case FTS_ERR: case FTS_ERR:
dolog("%s: fts_read error: %s", curr->fts_accpath, strerror(curr->fts_errno)); dolog("%s: fts_read error: %s", curr->fts_accpath, strerror(curr->fts_errno));
break; break;
case FTS_DC: case FTS_DC:
case FTS_DOT: case FTS_DOT:
case FTS_NSOK: case FTS_NSOK:
break; break;
case FTS_D: case FTS_D:
break; break;
case FTS_DP: case FTS_DP:
case FTS_F: case FTS_F:
case FTS_SL: case FTS_SL:
case FTS_SLNONE: case FTS_SLNONE:
case FTS_DEFAULT: case FTS_DEFAULT:
if (remove(curr->fts_accpath) < 0) { if (remove(curr->fts_accpath) < 0) {
dolog("%s: Failed to remove: %s", curr->fts_path, strerror(errno)); dolog("%s: Failed to remove: %s", curr->fts_path, strerror(errno));
ret = -1; ret = -1;
} }
break; break;
} }
} }
finish: finish:
if (ftsp) { if (ftsp) {
fts_close(ftsp); fts_close(ftsp);
} }
return ret; return ret;
} }
int copy_file(char *src, char *dest) { int copy_file(char *src, char *dest) {
@ -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

@ -20,17 +20,17 @@
#define NETWORK_FIDO 1 #define NETWORK_FIDO 1
#define NETWORK_WWIV 2 #define NETWORK_WWIV 2
#define NETWORK_MAGI 3 #define NETWORK_MAGI 3
#define NETWORK_QWK 4 #define NETWORK_QWK 4
#define TYPE_LOCAL_AREA 0 #define TYPE_LOCAL_AREA 0
#define TYPE_NETMAIL_AREA 1 #define TYPE_NETMAIL_AREA 1
#define TYPE_ECHOMAIL_AREA 2 #define TYPE_ECHOMAIL_AREA 2
#define TYPE_NEWSGROUP_AREA 3 #define TYPE_NEWSGROUP_AREA 3
#define IAC 255 #define IAC 255
#define IAC_WILL 251 #define IAC_WILL 251
#define IAC_WONT 252 #define IAC_WONT 252
#define IAC_DO 253 #define IAC_DO 253
#define IAC_DONT 254 #define IAC_DONT 254
#define IAC_TRANSMIT_BINARY 0 #define IAC_TRANSMIT_BINARY 0
#define IAC_SUPPRESS_GO_AHEAD 3 #define IAC_SUPPRESS_GO_AHEAD 3
@ -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;
@ -120,9 +120,9 @@ struct protocol {
int upload_prompt; int upload_prompt;
}; };
#define IP_STATUS_UNKNOWN 0 #define IP_STATUS_UNKNOWN 0
#define IP_STATUS_WHITELISTED 1 #define IP_STATUS_WHITELISTED 1
#define IP_STATUS_BLACKLISTED 2 #define IP_STATUS_BLACKLISTED 2
struct ip_address_guard { struct ip_address_guard {
int status; int status;
@ -162,14 +162,14 @@ struct bbs_config {
int bwave_max_msgs; int bwave_max_msgs;
int date_style; int date_style;
struct fido_addr *main_aka; struct fido_addr *main_aka;
char *root_menu; char *root_menu;
char *menu_path; char *menu_path;
char *external_editor_cmd; char *external_editor_cmd;
int external_editor_stdio; int external_editor_stdio;
char *external_editor_codepage; char *external_editor_codepage;
int fork; int fork;
int nodes; int nodes;
int newuserlvl; int newuserlvl;
int automsgwritelvl; int automsgwritelvl;
@ -179,11 +179,11 @@ struct bbs_config {
char *broadcast_topic; char *broadcast_topic;
char *broadcast_user; char *broadcast_user;
char *broadcast_pass; char *broadcast_pass;
int ipguard_enable; int ipguard_enable;
int ipguard_timeout; int ipguard_timeout;
int ipguard_tries; int ipguard_tries;
int mail_conference_count; int mail_conference_count;
struct mail_conference **mail_conferences; struct mail_conference **mail_conferences;
int door_count; int door_count;
@ -192,11 +192,11 @@ struct bbs_config {
struct file_directory **file_directories; struct file_directory **file_directories;
int text_file_count; int text_file_count;
struct text_file **text_files; struct text_file **text_files;
char *config_path; char *config_path;
int archiver_count; int archiver_count;
struct archiver **archivers; struct archiver **archivers;
int protocol_count; int protocol_count;
struct protocol **protocols; struct protocol **protocols;
}; };
@ -252,10 +252,10 @@ struct msg_headers {
}; };
struct blog_entry_t { struct blog_entry_t {
char *subject; char *subject;
char *author; char *author;
char *body; char *body;
time_t date; time_t date;
}; };
extern char *str_replace(const char *orig, const char *rep, const char *with); extern char *str_replace(const char *orig, const char *rep, const char *with);
@ -373,9 +373,9 @@ extern void chomp(char *string);
#if defined(ENABLE_WWW) #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

@ -8,20 +8,20 @@
extern struct bbs_config conf; extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
struct bbs_list_entry_t { struct bbs_list_entry_t {
int id; int id;
char *bbsname; char *bbsname;
char *sysopname; char *sysopname;
char *telnet; char *telnet;
int owner; int owner;
}; };
int add_bbs(struct bbs_list_entry_t *new_entry) { int add_bbs(struct bbs_list_entry_t *new_entry) {
char *create_sql = "CREATE TABLE IF NOT EXISTS bbslist (" char *create_sql = "CREATE TABLE IF NOT EXISTS bbslist ("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"bbsname TEXT," "bbsname TEXT,"
"sysop TEXT," "sysop TEXT,"
"telnet TEXT," "telnet TEXT,"
"owner INTEGER);"; "owner INTEGER);";
char *insert_sql = "INSERT INTO bbslist (bbsname, sysop, telnet, owner) VALUES(?,?, ?, ?)"; char *insert_sql = "INSERT INTO bbslist (bbsname, sysop, telnet, owner) VALUES(?,?, ?, ?)";
@ -32,11 +32,11 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
char c; char c;
char *err_msg = 0; char *err_msg = 0;
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
int id; int id;
s_printf("\e[2J\e[1;1H"); s_printf("\e[2J\e[1;1H");
s_printf(get_string(28)); s_printf(get_string(28));
s_readstring(bbsname, 18); s_readstring(bbsname, 18);
@ -60,14 +60,14 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
return 0; return 0;
} }
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);
@ -86,69 +86,68 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
sqlite3_bind_int(res, 4, gUser->id); sqlite3_bind_int(res, 4, gUser->id);
} else { } else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
rc = sqlite3_step(res); rc = sqlite3_step(res);
if (rc != SQLITE_DONE) { if (rc != SQLITE_DONE) {
dolog("execution failed: %s", sqlite3_errmsg(db)); dolog("execution failed: %s", sqlite3_errmsg(db));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
id = sqlite3_last_insert_rowid(db); id = sqlite3_last_insert_rowid(db);
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_printf(get_string(38)); s_printf(get_string(38));
if (new_entry != NULL) { if (new_entry != NULL) {
new_entry->id = id; new_entry->id = id;
new_entry->bbsname = strdup(bbsname); new_entry->bbsname = strdup(bbsname);
new_entry->sysopname = strdup(sysop); new_entry->sysopname = strdup(sysop);
new_entry->telnet = strdup(telnet); new_entry->telnet = strdup(telnet);
new_entry->owner = gUser->id; new_entry->owner = gUser->id;
} }
return 1; return 1;
} else { } else {
s_printf(get_string(39)); s_printf(get_string(39));
return 0; return 0;
} }
} }
int delete_bbs(int id) { int delete_bbs(int id) {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *sql = "SELECT bbsname FROM bbslist WHERE id=? and owner=?"; char *sql = "SELECT bbsname FROM bbslist WHERE id=? and owner=?";
char *dsql = "DELETE FROM bbslist WHERE id=?"; char *dsql = "DELETE FROM bbslist WHERE id=?";
char c; char c;
s_printf("\e[2J\e[1;1H");
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path); s_printf("\e[2J\e[1;1H");
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
return 0; return 0;
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_int(res, 1, id); sqlite3_bind_int(res, 1, id);
sqlite3_bind_int(res, 2, gUser->id); sqlite3_bind_int(res, 2, gUser->id);
} else { } else {
sqlite3_close(db); sqlite3_close(db);
s_printf(get_string(41)); s_printf(get_string(41));
return 0; return 0;
} }
if (sqlite3_step(res) == SQLITE_ROW) { if (sqlite3_step(res) == SQLITE_ROW) {
s_printf(get_string(42), sqlite3_column_text(res, 0)); s_printf(get_string(42), sqlite3_column_text(res, 0));
sqlite3_finalize(res); sqlite3_finalize(res);
c = s_getc(); c = s_getc();
@ -164,18 +163,18 @@ int delete_bbs(int id) {
sqlite3_step(res); sqlite3_step(res);
s_printf(get_string(43)); s_printf(get_string(43));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
} else { } else {
s_printf(get_string(39)); s_printf(get_string(39));
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
} else { } else {
sqlite3_finalize(res); sqlite3_finalize(res);
s_printf(get_string(44)); s_printf(get_string(44));
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
} }
@ -187,207 +186,207 @@ void bbs_list() {
char c; char c;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist"; char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist";
struct bbs_list_entry_t **entries; struct bbs_list_entry_t **entries;
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);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
return; return;
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite3_close(db); sqlite3_close(db);
} else { } else {
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
if (entrycount == 0) { if (entrycount == 0) {
entries = (struct bbs_list_entry_t **)malloc(sizeof(struct bbs_list_entry_t *)); entries = (struct bbs_list_entry_t **)malloc(sizeof(struct bbs_list_entry_t *));
} else { } else {
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1)); entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1));
} }
entries[entrycount] = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t)); entries[entrycount] = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t));
entries[entrycount]->id = sqlite3_column_int(res, 0); entries[entrycount]->id = sqlite3_column_int(res, 0);
entries[entrycount]->bbsname = strdup(sqlite3_column_text(res, 1)); entries[entrycount]->bbsname = strdup(sqlite3_column_text(res, 1));
entries[entrycount]->sysopname = strdup(sqlite3_column_text(res, 2)); entries[entrycount]->sysopname = strdup(sqlite3_column_text(res, 2));
entries[entrycount]->telnet = strdup(sqlite3_column_text(res, 3)); entries[entrycount]->telnet = strdup(sqlite3_column_text(res, 3));
entrycount++; entrycount++;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
} }
if (entrycount > 0) { if (entrycount > 0) {
while (1) { while (1) {
if (redraw) { if (redraw) {
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 {
s_printf(get_string(268), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet); s_printf(get_string(268), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet);
} }
} }
s_printf("\e[%d;5H", selected - start + 2); s_printf("\e[%d;5H", selected - start + 2);
redraw = 0; redraw = 0;
} }
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);
free(entries[i]); free(entries[i]);
} }
free(entries); free(entries);
return; return;
} else if (tolower(c) == 'a') { } else if (tolower(c) == 'a') {
newentry = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t)); newentry = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t));
if (add_bbs(newentry)) { if (add_bbs(newentry)) {
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1)); entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1));
entries[entrycount] = newentry; entries[entrycount] = newentry;
entrycount++; entrycount++;
redraw = 1; redraw = 1;
} else { } else {
free(newentry); free(newentry);
redraw = 1; redraw = 1;
} }
} else if (tolower(c) == 'd') { } else if (tolower(c) == 'd') {
if (delete_bbs(entries[selected]->id)) { if (delete_bbs(entries[selected]->id)) {
free(entries[selected]->bbsname); free(entries[selected]->bbsname);
free(entries[selected]->sysopname); free(entries[selected]->sysopname);
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];
} }
entrycount--; entrycount--;
if (entrycount == 0) { if (entrycount == 0) {
free(entries); free(entries);
return; return;
} }
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * entrycount); entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * entrycount);
if (selected >= entrycount) { if (selected >= entrycount) {
selected = entrycount - 1; selected = entrycount - 1;
} }
} }
redraw = 1; redraw = 1;
} else if (c == 27) { } else if (c == 27) {
c = s_getchar(); c = s_getchar();
if (c == 91) { if (c == 91) {
c = s_getchar(); c = s_getchar();
if (c == 66) { if (c == 66) {
// down // down
if (selected + 1 >= start + 22) { if (selected + 1 >= start + 22) {
start += 22; start += 22;
if (start >= entrycount) { if (start >= entrycount) {
start = entrycount - 22; start = entrycount - 22;
} }
redraw = 1; redraw = 1;
} }
selected++; selected++;
if (selected >= entrycount) { if (selected >= entrycount) {
selected = entrycount - 1; selected = entrycount - 1;
} else { } else {
if (!redraw) { if (!redraw) {
s_printf(get_string(268), selected - start + 1, selected - 1, entries[selected - 1]->bbsname, entries[selected - 1]->sysopname, entries[selected - 1]->telnet); s_printf(get_string(268), selected - start + 1, selected - 1, entries[selected - 1]->bbsname, entries[selected - 1]->sysopname, entries[selected - 1]->telnet);
s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet); s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet);
s_printf("\e[%d;4H", selected - start + 2); s_printf("\e[%d;4H", selected - start + 2);
} }
} }
} else if (c == 65) { } else if (c == 65) {
// up // up
if (selected - 1 < start) { if (selected - 1 < start) {
start -= 22; start -= 22;
if (start < 0) { if (start < 0) {
start = 0; start = 0;
} }
redraw = 1; redraw = 1;
} }
selected--; selected--;
if (selected < 0) { if (selected < 0) {
selected = 0; selected = 0;
} else { } else {
if (!redraw) { if (!redraw) {
s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet); s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet);
s_printf(get_string(268), selected - start + 3, selected + 1, entries[selected + 1]->bbsname, entries[selected + 1]->sysopname, entries[selected + 1]->telnet); s_printf(get_string(268), selected - start + 3, selected + 1, entries[selected + 1]->bbsname, entries[selected + 1]->sysopname, entries[selected + 1]->telnet);
s_printf("\e[%d;4H", selected - start + 2); s_printf("\e[%d;4H", selected - start + 2);
} }
} }
} else if (c == 75) { } else if (c == 75) {
// END KEY // END KEY
selected = entrycount - 1; selected = entrycount - 1;
start = entrycount - 22; start = entrycount - 22;
if (start < 0) { if (start < 0) {
start = 0; start = 0;
} }
redraw = 1; redraw = 1;
} else if (c == 72) { } else if (c == 72) {
// HOME KEY // HOME KEY
selected = 0; selected = 0;
start = 0; start = 0;
redraw = 1; redraw = 1;
} else if (c == 86 || c == '5') { } else if (c == 86 || c == '5') {
if (c == '5') { if (c == '5') {
s_getchar(); s_getchar();
} }
// PAGE UP // PAGE UP
selected = selected - 22; selected = selected - 22;
if (selected < 0) { if (selected < 0) {
selected = 0; selected = 0;
} }
start = selected; start = selected;
redraw = 1; redraw = 1;
} else if (c == 85 || c == '6') { } else if (c == 85 || c == '6') {
if (c == '6') { if (c == '6') {
s_getchar(); s_getchar();
} }
// 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;
} }
} }
} }
} }
} else { } else {
// no entries // no entries
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));
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') {
add_bbs(NULL); add_bbs(NULL);
break; break;
} else if (tolower(c) == 'q') { } else if (tolower(c) == 'q') {
return; return;
} }
} }
} }
} }
} }

View File

@ -7,250 +7,249 @@ extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
int blog_load(struct blog_entry_t ***entries) { int blog_load(struct blog_entry_t ***entries) {
int blog_entry_count = 0; int blog_entry_count = 0;
struct blog_entry_t **blog_entries; struct blog_entry_t **blog_entries;
char *sql = "SELECT author, title, body, date FROM blog ORDER BY date DESC"; char *sql = "SELECT author, title, body, date FROM blog ORDER BY date DESC";
char buffer[PATH_MAX]; char buffer[PATH_MAX];
int rc; int rc;
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
*entries = NULL; *entries = NULL;
return 0; return 0;
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
*entries = NULL; *entries = NULL;
return 0; return 0;
} }
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
if (blog_entry_count == 0) { if (blog_entry_count == 0) {
blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *)); blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *));
} else { } else {
blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1)); blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1));
} }
blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t)); blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t));
blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0)); blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0));
blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1)); blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1));
blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2)); blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2));
blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3); blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3);
blog_entry_count++; blog_entry_count++;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
*entries = blog_entries; *entries = blog_entries;
return blog_entry_count; return blog_entry_count;
} }
void blog_display() { void blog_display() {
struct blog_entry_t **blog_entries;
int blog_entry_count = 0;
int i;
struct tm thetime;
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
char c;
int hour;
int j;
int lines = 2;
s_printf("\e[2J\e[1;1H");
s_printf(get_string(280));
s_printf(get_string(281));
blog_entry_count = blog_load(&blog_entries); struct blog_entry_t **blog_entries;
if (blog_entry_count == 0) { int blog_entry_count = 0;
s_printf(get_string(282));
s_printf(get_string(6));
s_getchar();
return;
}
c = 'y'; int i;
struct tm thetime;
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
char c;
int hour;
int j;
int lines = 2;
s_printf("\e[2J\e[1;1H");
s_printf(get_string(280));
s_printf(get_string(281));
for (i=0;i<blog_entry_count;i++) { blog_entry_count = blog_load(&blog_entries);
localtime_r(&blog_entries[i]->date, &thetime); if (blog_entry_count == 0) {
s_printf(get_string(282));
s_printf(get_string(6));
s_getchar();
return;
}
s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author); c = 'y';
lines++;
if (lines == 22 && tolower(c) != 'c') {
s_printf("\r\n");
s_printf(get_string(223));
c = s_getchar();
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n\r\n");
lines = 0;
}
if (thetime.tm_hour >= 12) {
hour = thetime.tm_hour - 12;
} else {
hour = thetime.tm_hour;
}
s_printf(get_string(284), (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900);
lines++; for (i = 0; i < blog_entry_count; i++) {
if (lines == 22 && tolower(c) != 'c') { localtime_r(&blog_entries[i]->date, &thetime);
s_printf("\r\n");
s_printf(get_string(223));
c = s_getchar();
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n\r\n");
lines = 0;
}
s_printf("\r\n\e[0m");
lines++;
if (lines == 22 && tolower(c) != 'c') {
s_printf("\r\n");
s_printf(get_string(223));
c = s_getchar();
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n\r\n");
lines = 0;
}
for (j=0; j<strlen(blog_entries[i]->body); j++) {
if (blog_entries[i]->body[j] == '\r') {
s_printf("\r\n");
lines++;
if (lines == 22 && tolower(c) != 'c') {
s_printf("\r\n");
s_printf(get_string(223));
c = s_getchar();
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n\r\n");
lines = 0;
}
} else {
s_printf("%c", blog_entries[i]->body[j]);
}
}
if (tolower(c) == 'n') { s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author);
break; lines++;
} if (lines == 22 && tolower(c) != 'c') {
s_printf("\r\n"); s_printf("\r\n");
lines++; s_printf(get_string(223));
if (lines == 22 && tolower(c) != 'c') { c = s_getchar();
s_printf("\r\n"); if (tolower(c) == 'n') {
s_printf(get_string(223)); break;
c = s_getchar(); }
if (tolower(c) == 'n') { s_printf("\r\n\r\n");
break; lines = 0;
} }
s_printf("\r\n\r\n"); if (thetime.tm_hour >= 12) {
lines = 0; hour = thetime.tm_hour - 12;
} } else {
} hour = thetime.tm_hour;
for (i=0;i<blog_entry_count;i++) { }
free(blog_entries[i]->subject); s_printf(get_string(284), (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900);
free(blog_entries[i]->author);
free(blog_entries[i]->body);
free(blog_entries[i]);
}
free(blog_entries); lines++;
if (lines == 22 && tolower(c) != 'c') {
s_printf("\r\n");
s_printf(get_string(223));
c = s_getchar();
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n\r\n");
lines = 0;
}
s_printf(get_string(6)); s_printf("\r\n\e[0m");
s_getchar(); lines++;
if (lines == 22 && tolower(c) != 'c') {
s_printf("\r\n");
s_printf(get_string(223));
c = s_getchar();
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n\r\n");
lines = 0;
}
for (j = 0; j < strlen(blog_entries[i]->body); j++) {
if (blog_entries[i]->body[j] == '\r') {
s_printf("\r\n");
lines++;
if (lines == 22 && tolower(c) != 'c') {
s_printf("\r\n");
s_printf(get_string(223));
c = s_getchar();
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n\r\n");
lines = 0;
}
} else {
s_printf("%c", blog_entries[i]->body[j]);
}
}
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n");
lines++;
if (lines == 22 && tolower(c) != 'c') {
s_printf("\r\n");
s_printf(get_string(223));
c = s_getchar();
if (tolower(c) == 'n') {
break;
}
s_printf("\r\n\r\n");
lines = 0;
}
}
for (i = 0; i < blog_entry_count; i++) {
free(blog_entries[i]->subject);
free(blog_entries[i]->author);
free(blog_entries[i]->body);
free(blog_entries[i]);
}
free(blog_entries);
s_printf(get_string(6));
s_getchar();
} }
void blog_write() { void blog_write() {
char *csql = "CREATE TABLE IF NOT EXISTS blog (" char *csql = "CREATE TABLE IF NOT EXISTS blog ("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"author TEXT COLLATE NOCASE," "author TEXT COLLATE NOCASE,"
"title TEXT," "title TEXT,"
"body TEXT," "body TEXT,"
"date INTEGER);"; "date INTEGER);";
char *isql = "INSERT INTO blog (author, title, body, date) VALUES(?, ?, ?, ?)"; char *isql = "INSERT INTO blog (author, title, body, date) VALUES(?, ?, ?, ?)";
int rc; int rc;
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
char *blog_entry; char *blog_entry;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char *blog_subject; char *blog_subject;
char *err_msg = 0; char *err_msg = 0;
s_printf(get_string(285)); s_printf(get_string(285));
s_readstring(buffer, 64); s_readstring(buffer, 64);
s_printf("\r\n"); s_printf("\r\n");
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
s_printf(get_string(39)); s_printf(get_string(39));
return; return;
}
blog_subject = strdup(buffer);
blog_entry = external_editor(gUser, "No-One", "No-One", NULL, 0, "No-One", "Blog Editor", 0, 1);
if (blog_entry != NULL) {
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db));
free(blog_entry);
free(blog_subject);
return;
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) {
dolog("SQL error: %s", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
free(blog_entry);
free(blog_subject);
return;
}
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, gUser->loginname, -1, 0);
sqlite3_bind_text(res, 2, blog_subject, -1, 0);
sqlite3_bind_text(res, 3, blog_entry, -1, 0);
sqlite3_bind_int(res, 4, time(NULL));
} else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res);
sqlite3_close(db);
free(blog_entry);
free(blog_subject);
return;
}
sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
free(blog_entry);
free(blog_subject);
return;
} }
free(blog_subject);
blog_subject = strdup(buffer);
blog_entry = external_editor(gUser, "No-One", "No-One", NULL, 0, "No-One", "Blog Editor", 0, 1);
if (blog_entry != NULL) {
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db));
free(blog_entry);
free(blog_subject);
return;
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
free(blog_entry);
free(blog_subject);
return;
}
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, gUser->loginname, -1, 0);
sqlite3_bind_text(res, 2, blog_subject, -1, 0);
sqlite3_bind_text(res, 3, blog_entry, -1, 0);
sqlite3_bind_int(res, 4, time(NULL));
} else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res);
sqlite3_close(db);
free(blog_entry);
free(blog_subject);
return;
}
sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
free(blog_entry);
free(blog_subject);
return;
}
free(blog_subject);
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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"
@ -32,15 +32,14 @@ extern struct user_record gUser;
extern int usertimeout; extern int usertimeout;
struct chat_msg { struct chat_msg {
char nick[16]; char nick[16];
char bbstag[16]; char bbstag[16];
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;
} }
return -1; return -1;
@ -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);
@ -65,14 +64,14 @@ void scroll_up() {
int y; int y;
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;
} }
@ -81,14 +80,14 @@ void scroll_up() {
void raw(char *fmt, ...) { void raw(char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(sbuf, 512, fmt, ap); vsnprintf(sbuf, 512, fmt, ap);
va_end(ap); va_end(ap);
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,23 +164,23 @@ 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--;
} }
} }
if (i < strlen(buffer)) { if (i < strlen(buffer)) {
screenbuffer[line_at][row_at]->c = buffer[i]; screenbuffer[line_at][row_at]->c = buffer[i];
screenbuffer[line_at][row_at++]->color = curr_color; screenbuffer[line_at][row_at++]->color = curr_color;
@ -191,23 +190,23 @@ 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--;
} }
} }
if (i < strlen(buffer)) { if (i < strlen(buffer)) {
screenbuffer[line_at][row_at]->c = buffer[i]; screenbuffer[line_at][row_at]->c = buffer[i];
screenbuffer[line_at][row_at++]->color = curr_color; screenbuffer[line_at][row_at++]->color = curr_color;
@ -261,9 +260,9 @@ void chat_system(struct user_record *user) {
int i; int i;
int j; int j;
int chat_in; int chat_in;
jsmn_parser parser; jsmn_parser parser;
jsmntok_t tokens[8]; jsmntok_t tokens[8];
int r; int r;
struct chat_msg msg; struct chat_msg msg;
char *input_b; char *input_b;
char *ptr; char *ptr;
@ -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");
@ -299,13 +296,13 @@ void chat_system(struct user_record *user) {
if (!inet_pton(AF_INET6, buffer, &servaddr6.sin6_addr)) { if (!inet_pton(AF_INET6, buffer, &servaddr6.sin6_addr)) {
chat_connected = 0; chat_connected = 0;
} 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;
} }
@ -315,17 +312,17 @@ void chat_system(struct user_record *user) {
chat_connected = 0; chat_connected = 0;
} }
} 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;
} }
} }
} }
} }
@ -336,45 +333,43 @@ void chat_system(struct user_record *user) {
if (!inet_pton(AF_INET, buffer, &servaddr.sin_addr)) { if (!inet_pton(AF_INET, buffer, &servaddr.sin_addr)) {
return; return;
} 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;
} }
} }
} else { } else {
return; return;
} }
} 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;
} }
} }
memset(partmessage, 0, 1024); memset(partmessage, 0, 1024);
raw("{ \"bbs\": \"%s\", \"nick\": \"%s\", \"msg\": \"LOGIN\" }\n", conf.mgchat_bbstag, user->loginname); raw("{ \"bbs\": \"%s\", \"nick\": \"%s\", \"msg\": \"LOGIN\" }\n", conf.mgchat_bbstag, user->loginname);
while (1) { while (1) {
@ -397,14 +392,14 @@ void chat_system(struct user_record *user) {
close(chat_socket); close(chat_socket);
disconnect("Socket closed"); disconnect("Socket closed");
} }
usertimeout = 10; usertimeout = 10;
if (c == '\r') { if (c == '\r') {
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,47 +432,47 @@ 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);
return; return;
} }
strncat(partmessage, readbuffer, len); strncat(partmessage, readbuffer, len);
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 {
y = 0; y = 0;
// 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++;
} }
} }
} }
// set outputbuffer // set outputbuffer
if (strcmp(msg.bbstag, "SYSTEM") == 0 && strcmp(msg.nick, "SYSTEM") == 0) { if (strcmp(msg.bbstag, "SYSTEM") == 0 && strcmp(msg.nick, "SYSTEM") == 0) {
@ -493,11 +488,9 @@ void chat_system(struct user_record *user) {
append_screenbuffer(outputbuffer); 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;
} }
@ -66,9 +66,9 @@ int write_door32sys(struct user_record *user) {
return 1; return 1;
} }
fprintf(fptr, "2\r\n"); // telnet type fprintf(fptr, "2\r\n"); // telnet type
fprintf(fptr, "%d\r\n", gSocket); // socket fprintf(fptr, "%d\r\n", gSocket); // socket
fprintf(fptr, "38400\r\n"); // baudrate fprintf(fptr, "38400\r\n"); // baudrate
fprintf(fptr, "Magicka %d.%d\r\n", VERSION_MAJOR, VERSION_MINOR); fprintf(fptr, "Magicka %d.%d\r\n", VERSION_MAJOR, VERSION_MINOR);
fprintf(fptr, "%d\r\n", user->id); fprintf(fptr, "%d\r\n", user->id);
fprintf(fptr, "%s %s\r\n", user->firstname, user->lastname); fprintf(fptr, "%s %s\r\n", user->firstname, user->lastname);
@ -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;
} }
@ -120,7 +120,7 @@ int write_door32sys(struct user_record *user) {
fprintf(fptr, "%d\r\n", user->sec_level); fprintf(fptr, "%d\r\n", user->sec_level);
fprintf(fptr, "%d\r\n", user->timeleft); fprintf(fptr, "%d\r\n", user->timeleft);
fprintf(fptr, "-1\r\n"); fprintf(fptr, "-1\r\n");
fclose(fptr); fclose(fptr);
// create door.sys // create door.sys
@ -173,7 +173,7 @@ int write_door32sys(struct user_record *user) {
fprintf(fptr, "none\r\n"); fprintf(fptr, "none\r\n");
fprintf(fptr, "Y\r\n"); fprintf(fptr, "Y\r\n");
fprintf(fptr, "N\r\n"); fprintf(fptr, "N\r\n");
fprintf(fptr, "Y\r\n"); fprintf(fptr, "Y\r\n");
fprintf(fptr, "7\r\n"); fprintf(fptr, "7\r\n");
fprintf(fptr, "0\r\n"); fprintf(fptr, "0\r\n");
fprintf(fptr, "01-01-1971\r\n"); fprintf(fptr, "01-01-1971\r\n");
@ -192,13 +192,11 @@ 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;
char buffer[10]; char buffer[10];
if (sshBBS) { if (sshBBS) {
door_out = STDOUT_FILENO; door_out = STDOUT_FILENO;
} else { } else {
@ -209,17 +207,17 @@ void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage) {
arguments[1] = strdup(buffer); arguments[1] = strdup(buffer);
sprintf(buffer, "%d", door_out); sprintf(buffer, "%d", door_out);
arguments[2] = strdup(buffer); arguments[2] = strdup(buffer);
arguments[3] = NULL; arguments[3] = NULL;
runexternal(user, cmd, stdio, arguments, NULL, 0, codepage); runexternal(user, cmd, stdio, arguments, NULL, 0, codepage);
free(arguments[0]); free(arguments[0]);
free(arguments[1]); free(arguments[1]);
free(arguments[2]); free(arguments[2]);
} }
void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], char *cwd, int raw, char *codepage) { void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], char *cwd, int raw, char *codepage) {
char buffer[1024]; char buffer[1024];
int ret; int ret;
unsigned char c; unsigned char c;
@ -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;
@ -306,8 +302,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
close(master); close(master);
dup2(slave, 0); dup2(slave, 0);
dup2(slave, 1); dup2(slave, 1);
close(slave); close(slave);
setsid(); setsid();
@ -319,8 +315,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
running_door_pid = pid; running_door_pid = pid;
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);
@ -329,10 +325,10 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
} else { } else {
t = door_in + 1; t = door_in + 1;
} }
thetimeout.tv_sec = 5; thetimeout.tv_sec = 5;
thetimeout.tv_usec = 0; thetimeout.tv_usec = 0;
ret = select(t, &fdset, NULL, NULL, &thetimeout); ret = select(t, &fdset, NULL, NULL, &thetimeout);
if (ret > 0) { if (ret > 0) {
if (FD_ISSET(door_in, &fdset)) { if (FD_ISSET(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') {
@ -379,7 +375,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
telnet_bin_mode = 1; telnet_bin_mode = 1;
write(master, iac_binary_do, 3); write(master, iac_binary_do, 3);
} }
} }
break; break;
case IAC_WONT: case IAC_WONT:
if (c == 0) { if (c == 0) {
@ -387,7 +383,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
telnet_bin_mode = 0; telnet_bin_mode = 0;
write(master, iac_binary_dont, 3); write(master, iac_binary_dont, 3);
} }
} }
break; break;
case IAC_DO: case IAC_DO:
if (c == 0) { if (c == 0) {
@ -403,8 +399,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
telnet_bin_mode = 0; telnet_bin_mode = 0;
write(master, iac_binary_wont, 3); write(master, iac_binary_wont, 3);
} }
} }
break; break;
} }
gotiac = 0; gotiac = 0;
} else if (gotiac == 3) { } else if (gotiac == 3) {
@ -444,12 +440,12 @@ 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;
} }
outbuf[g++] = c; outbuf[g++] = c;
} }
if (codepage == NULL || (strcmp(codepage, "CP437") == 0 && user->codepage == 0) || (strcmp(codepage, "UTF-8") == 0 && user->codepage == 1)) { if (codepage == NULL || (strcmp(codepage, "CP437") == 0 && user->codepage == 0) || (strcmp(codepage, "UTF-8") == 0 && user->codepage == 1)) {
write(door_out, outbuf, g); write(door_out, outbuf, g);
@ -472,7 +468,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
} }
write(door_out, ptr2p, ptr2 - ptr2p); write(door_out, ptr2p, ptr2 - ptr2p);
free(ptr2p); free(ptr2p);
iconv_close(ic); iconv_close(ic);
} }
} }
@ -482,16 +478,16 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
} }
} }
} }
} }
} }
} else { } else {
if (raw) { if (raw) {
ttySetRaw(STDIN_FILENO, &oldit); ttySetRaw(STDIN_FILENO, &oldit);
ttySetRaw(STDOUT_FILENO, &oldot); ttySetRaw(STDOUT_FILENO, &oldot);
} }
sa.sa_handler = doorchld_handler; sa.sa_handler = doorchld_handler;
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO; sa.sa_flags = SA_RESTART | SA_SIGINFO;
@ -510,11 +506,11 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
dup2(bbs_stderr, 2); dup2(bbs_stderr, 2);
execvp(cmd, argv); execvp(cmd, argv);
} else { } else {
while(running_door) { while (running_door) {
sleep(1); sleep(1);
} }
} }
if (raw) { if (raw) {
tcsetattr(STDIN_FILENO, TCSANOW, &oldit); tcsetattr(STDIN_FILENO, TCSANOW, &oldit);
tcsetattr(STDOUT_FILENO, TCSANOW, &oldot); tcsetattr(STDOUT_FILENO, TCSANOW, &oldot);
@ -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

@ -22,22 +22,22 @@ void commit_email(char *recipient, char *subject, char *msg) {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *csql = "CREATE TABLE IF NOT EXISTS email (" char *csql = "CREATE TABLE IF NOT EXISTS email ("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"sender TEXT COLLATE NOCASE," "sender TEXT COLLATE NOCASE,"
"recipient TEXT COLLATE NOCASE," "recipient TEXT COLLATE NOCASE,"
"subject TEXT," "subject TEXT,"
"body TEXT," "body TEXT,"
"date INTEGER," "date INTEGER,"
"seen INTEGER);"; "seen INTEGER);";
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
char *err_msg = 0; char *err_msg = 0;
snprintf(buffer, PATH_MAX, "%s/email.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/email.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
return; return;
@ -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);
@ -78,10 +78,9 @@ void commit_email(char *recipient, char *subject, char *msg) {
void send_email(struct user_record *user) { void send_email(struct user_record *user) {
char buffer[26]; char buffer[26];
char *recipient; char *recipient;
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);
@ -112,13 +111,13 @@ void send_email(struct user_record *user) {
commit_email(recipient, subject, msg); commit_email(recipient, subject, msg);
free(msg); free(msg);
} }
free(subject); free(subject);
free(recipient); free(recipient);
} }
void show_email(struct user_record *user, int msgno, int email_count, struct email_msg **emails) { void show_email(struct user_record *user, int msgno, int email_count, struct email_msg **emails) {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *dsql = "DELETE FROM email WHERE id=?"; char *dsql = "DELETE FROM email WHERE id=?";
@ -155,101 +154,100 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
lines = 0; 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 *)); } else {
} else { msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1));
msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1)); }
}
msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1));
msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1));
if (z == start_line) {
if (z == start_line) { 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') { start_line = z + 1;
start_line = z + 1; } else {
} else { start_line = z;
start_line = z; }
} chars = 0;
chars = 0; } else {
} else { chars++;
chars ++; }
} }
}
lines = 0;
lines = 0;
position = 0;
position = 0; should_break = 0;
should_break = 0;
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]);
if (z - position >= 17) {
if (z - position >= 17) { break;
break; }
} }
} s_printf(get_string(187));
s_printf(get_string(187)); s_printf(get_string(191));
s_printf(get_string(191)); c = s_getchar();
c = s_getchar();
if (tolower(c) == 'r') {
if (tolower(c) == 'r') { should_break = 1;
should_break = 1; } else if (tolower(c) == 'q') {
} else if (tolower(c) == 'q') { should_break = 1;
should_break = 1; quit = 1;
quit = 1;
} else if (tolower(c) == 'd') { } else if (tolower(c) == 'd') {
should_break = 1; should_break = 1;
} else if (c == '\e') { } else if (c == '\e') {
c = s_getchar(); c = s_getchar();
if (c == 91) { if (c == 91) {
c = s_getchar(); c = s_getchar();
if (c == 65) { if (c == 65) {
position--; position--;
if (position < 0) { if (position < 0) {
position = 0; position = 0;
} }
} else if (c == 66) { } else if (c == 66) {
position++; position++;
if (position + 17 >= msg_line_count) { if (position + 17 >= msg_line_count) {
position--; position--;
} }
} else if (c == 67) { } else if (c == 67) {
c = ' '; c = ' ';
should_break = 1; should_break = 1;
} else if (c == 68) { } else if (c == 68) {
c = 'b'; c = 'b';
should_break = 1; should_break = 1;
} }
} }
} }
} }
for (i = 0; i < msg_line_count; i++) {
free(msg_lines[i]);
}
free(msg_lines);
msg_line_count = 0;
for (i=0;i<msg_line_count;i++) {
free(msg_lines[i]);
}
free(msg_lines);
msg_line_count = 0;
sprintf(buffer, "%s/email.sq3", conf.bbs_path); sprintf(buffer, "%s/email.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
@ -271,7 +269,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) {
@ -286,7 +283,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
replybody = external_editor(user, user->loginname, emails[msgno]->from, emails[msgno]->body, strlen(emails[msgno]->body), emails[msgno]->from, subject, 1, 0); replybody = external_editor(user, user->loginname, emails[msgno]->from, emails[msgno]->body, strlen(emails[msgno]->body), emails[msgno]->from, subject, 1, 0);
if (replybody != NULL) { if (replybody != NULL) {
sprintf(buffer, "%s/email.sq3", conf.bbs_path); sprintf(buffer, "%s/email.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
@ -329,7 +326,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
exit(1); exit(1);
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0); rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
@ -341,12 +338,12 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
return; return;
} }
sqlite3_step(res); sqlite3_step(res);
sqlite3_finalize(res); sqlite3_finalize(res);
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;
} }
@ -356,7 +353,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
quit = 1; quit = 1;
} }
} }
} }
} }
void list_emails(struct user_record *user) { void list_emails(struct user_record *user) {
@ -380,8 +377,8 @@ void list_emails(struct user_record *user) {
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
@ -406,9 +403,9 @@ void list_emails(struct user_record *user) {
} else { } else {
emails = (struct email_msg **)realloc(emails, sizeof(struct email_msg *) * (email_count + 1)); emails = (struct email_msg **)realloc(emails, sizeof(struct email_msg *) * (email_count + 1));
} }
emails[email_count] = (struct email_msg *)malloc(sizeof(struct email_msg)); emails[email_count] = (struct email_msg *)malloc(sizeof(struct email_msg));
emails[email_count]->from = strdup((char *)sqlite3_column_text(res, 0)); emails[email_count]->from = strdup((char *)sqlite3_column_text(res, 0));
emails[email_count]->subject = strdup((char *)sqlite3_column_text(res, 1)); emails[email_count]->subject = strdup((char *)sqlite3_column_text(res, 1));
emails[email_count]->seen = sqlite3_column_int(res, 2); emails[email_count]->seen = sqlite3_column_int(res, 2);
@ -417,49 +414,49 @@ void list_emails(struct user_record *user) {
emails[email_count]->id = sqlite3_column_int(res, 5); emails[email_count]->id = sqlite3_column_int(res, 5);
email_count++; email_count++;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
if (email_count == 0) { if (email_count == 0) {
s_printf(get_string(194)); s_printf(get_string(194));
return; return;
} }
redraw = 1; redraw = 1;
start = 0; start = 0;
position = 0; position = 0;
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,20 +487,20 @@ 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);
localtime_r((time_t *)&emails[position]->date, &msg_date); localtime_r((time_t *)&emails[position]->date, &msg_date);
if (!emails[position]->seen) { if (!emails[position]->seen) {
@ -518,14 +515,14 @@ void list_emails(struct user_record *user) {
} else { } else {
s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
} }
s_printf("\e[%d;5H", position - start + 2); s_printf("\e[%d;5H", position - start + 2);
} }
} else if (c == 65) { } else if (c == 65) {
// up // up
position--; position--;
if (position < start) { if (position < start) {
start -=22; start -= 22;
if (start < 0) { if (start < 0) {
start = 0; start = 0;
} }
@ -550,7 +547,7 @@ void list_emails(struct user_record *user) {
} else { } else {
s_printf(get_string(65), position + 2, emails[position + 1]->subject, emails[position + 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); s_printf(get_string(65), position + 2, emails[position + 1]->subject, emails[position + 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
} }
s_printf("\e[%d;1H", position - start + 2); s_printf("\e[%d;1H", position - start + 2);
localtime_r((time_t *)&emails[position]->date, &msg_date); localtime_r((time_t *)&emails[position]->date, &msg_date);
if (!emails[position]->seen) { if (!emails[position]->seen) {
@ -565,9 +562,9 @@ void list_emails(struct user_record *user) {
} else { } else {
s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
} }
s_printf("\e[%d;5H", position - start + 3); s_printf("\e[%d;5H", position - start + 3);
} }
} else if (c == 75) { } else if (c == 75) {
// END KEY // END KEY
position = email_count - 1; position = email_count - 1;
@ -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;
@ -609,9 +606,9 @@ void list_emails(struct user_record *user) {
closed = 1; closed = 1;
show_email(user, position, email_count, emails); show_email(user, position, email_count, emails);
} }
} }
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,40 +617,39 @@ 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;
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
sprintf(buffer, "%s/email.sq3", conf.bbs_path); sprintf(buffer, "%s/email.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, user->loginname, -1, 0); sqlite3_bind_text(res, 1, user->loginname, -1, 0);
} else { } else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
count = 0; count = 0;
if (sqlite3_step(res) == SQLITE_ROW) { if (sqlite3_step(res) == SQLITE_ROW) {
count = sqlite3_column_int(res, 0); count = sqlite3_column_int(res, 0);
} }

File diff suppressed because it is too large Load Diff

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,144 +29,141 @@ 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;
} }
/* The implementation here was originally done by Gary S. Brown. I have /* The implementation here was originally done by Gary S. Brown. I have
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,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
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 =
{ crc32_tab[(crc32val ^ s[i]) & 0xff] ^
crc32val = (crc32val >> 8);
crc32_tab[(crc32val ^ s[i]) & 0xff] ^ }
(crc32val >> 8); return crc32val;
}
return crc32val;
} }
/* /*
* 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,12 +236,12 @@ 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)
continue;
if (curr[i].in_use == 0)
continue;
status = hashmap_put(m, curr[i].key, curr[i].data); status = hashmap_put(m, curr[i].key, curr[i].data);
if (status != MAP_OK) if (status != MAP_OK)
return status; return status;
@ -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;
} }
@ -278,7 +275,7 @@ int hashmap_put(map_t in, char* key, any_t value){
m->data[index].data = value; m->data[index].data = value;
m->data[index].key = key; m->data[index].key = key;
m->data[index].in_use = 1; m->data[index].in_use = 1;
m->size++; m->size++;
return MAP_OK; return MAP_OK;
} }
@ -286,26 +283,26 @@ int hashmap_put(map_t in, char* key, any_t value){
/* /*
* Get your pointer out of the hashmap with a key * 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;
} }
} }
curr = (curr + 1) % m->table_size; curr = (curr + 1) % m->table_size;
@ -326,54 +323,54 @@ 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;
} }
} }
return MAP_OK; return MAP_OK;
} }
/* /*
* 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;
m->data[curr].key = NULL; m->data[curr].key = NULL;
/* Reduce the size */ /* Reduce the size */
m->size--; m->size--;
return MAP_OK; return MAP_OK;
} }
} }
curr = (curr + 1) % m->table_size; curr = (curr + 1) % m->table_size;
} }
@ -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

@ -9,10 +9,10 @@
#ifndef __HASHMAP_H__ #ifndef __HASHMAP_H__
#define __HASHMAP_H__ #define __HASHMAP_H__
#define MAP_MISSING -3 /* No such element */ #define MAP_MISSING -3 /* No such element */
#define MAP_FULL -2 /* Hashmap is full */ #define MAP_FULL -2 /* Hashmap is full */
#define MAP_OMEM -1 /* Out of Memory */ #define MAP_OMEM -1 /* Out of Memory */
#define MAP_OK 0 /* OK */ #define MAP_OK 0 /* OK */
/* /*
* any_t is a pointer. This allows you to put arbitrary structures in * any_t is a pointer. This allows you to put arbitrary structures in
@ -50,17 +50,17 @@ extern int hashmap_iterate(map_t in, PFany f, any_t item);
/* /*
* Add an element to the hashmap. Return MAP_OK or MAP_OMEM. * 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,72 +10,67 @@
#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();
/* First, populate the hash map with ascending values */ mymap = hashmap_new();
for (index=0; index<KEY_COUNT; index+=1)
{
/* Store the key string along side the numerical value so we can free it later */
value = malloc(sizeof(data_struct_t));
snprintf(value->key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
value->number = index;
error = hashmap_put(mymap, value->key_string, value); /* First, populate the hash map with ascending values */
assert(error==MAP_OK); for (index = 0; index < KEY_COUNT; index += 1) {
} /* Store the key string along side the numerical value so we can free it later */
value = malloc(sizeof(data_struct_t));
snprintf(value->key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
value->number = index;
/* Now, check all of the expected values are there */ error = hashmap_put(mymap, value->key_string, value);
for (index=0; index<KEY_COUNT; index+=1) assert(error == MAP_OK);
{ }
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
error = hashmap_get(mymap, key_string, (void**)(&value)); /* Now, check all of the expected values are there */
for (index = 0; index < KEY_COUNT; index += 1) {
/* Make sure the value was both found and the correct number */ snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
assert(error==MAP_OK);
assert(value->number==index);
}
/* Make sure that a value that wasn't in the map can't be found */
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT);
error = hashmap_get(mymap, key_string, (void**)(&value)); error = hashmap_get(mymap, key_string, (void **)(&value));
/* Make sure the value was not found */
assert(error==MAP_MISSING);
/* Free all of the values we allocated and remove them from the map */ /* Make sure the value was both found and the correct number */
for (index=0; index<KEY_COUNT; index+=1) assert(error == MAP_OK);
{ assert(value->number == index);
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); }
error = hashmap_get(mymap, key_string, (void**)(&value)); /* Make sure that a value that wasn't in the map can't be found */
assert(error==MAP_OK); snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT);
error = hashmap_remove(mymap, key_string); error = hashmap_get(mymap, key_string, (void **)(&value));
assert(error==MAP_OK);
free(value); /* Make sure the value was not found */
} assert(error == MAP_MISSING);
/* Now, destroy the map */
hashmap_free(mymap);
return 1; /* Free all of the values we allocated and remove them from the map */
for (index = 0; index < KEY_COUNT; index += 1) {
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
error = hashmap_get(mymap, key_string, (void **)(&value));
assert(error == MAP_OK);
error = hashmap_remove(mymap, key_string);
assert(error == MAP_OK);
free(value);
}
/* Now, destroy the map */
hashmap_free(mymap);
return 1;
} }

View File

@ -25,170 +25,160 @@ 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)) &&
!(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) { !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
was_space = isspace((unsigned char)(*s)); was_space = isspace((unsigned char)(*s));
s++; s++;
} }
#else #else
while (*s && (!chars || !strchr(chars, *s))) { while (*s && (!chars || !strchr(chars, *s))) {
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;
} }
#endif #endif
/* Scan through stream line by line */ /* Scan through stream line by line */
while (reader(line, INI_MAX_LINE, stream) != NULL) { while (reader(line, INI_MAX_LINE, stream) != NULL) {
lineno++; lineno++;
start = line; start = line;
#if INI_ALLOW_BOM #if INI_ALLOW_BOM
if (lineno == 1 && (unsigned char)start[0] == 0xEF && if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
(unsigned char)start[1] == 0xBB && (unsigned char)start[1] == 0xBB &&
(unsigned char)start[2] == 0xBF) { (unsigned char)start[2] == 0xBF) {
start += 3; start += 3;
} }
#endif #endif
start = lskip(rstrip(start)); start = lskip(rstrip(start));
if (*start == ';' || *start == '#') { if (*start == ';' || *start == '#') {
/* Per Python configparser, allow both ; and # comments at the /* Per Python configparser, allow both ; and # comments at the
start of a line */ start of a line */
} }
#if INI_ALLOW_MULTILINE #if INI_ALLOW_MULTILINE
else if (*prev_name && *start && start > line) { else if (*prev_name && *start && start > line) {
/* Non-blank line with leading whitespace, treat as continuation /* Non-blank line with leading whitespace, treat as continuation
of previous name's value (as per Python configparser). */ of previous name's value (as per Python configparser). */
if (!handler(user, section, prev_name, start) && !error) if (!handler(user, section, prev_name, start) && !error)
error = lineno; error = lineno;
} }
#endif #endif
else if (*start == '[') { else if (*start == '[') {
/* A "[section]" line */ /* A "[section]" line */
end = find_chars_or_comment(start + 1, "]"); end = find_chars_or_comment(start + 1, "]");
if (*end == ']') { if (*end == ']') {
*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) {
} /* Not a comment, must be a name[=:]value pair */
else if (*start) { end = find_chars_or_comment(start, "=:");
/* Not a comment, must be a name[=:]value pair */ if (*end == '=' || *end == ':') {
end = find_chars_or_comment(start, "=:"); *end = '\0';
if (*end == '=' || *end == ':') { name = rstrip(start);
*end = '\0'; value = lskip(end + 1);
name = rstrip(start);
value = lskip(end + 1);
#if INI_ALLOW_INLINE_COMMENTS #if INI_ALLOW_INLINE_COMMENTS
end = find_chars_or_comment(value, NULL); end = find_chars_or_comment(value, NULL);
if (*end) if (*end)
*end = '\0'; *end = '\0';
#endif #endif
rstrip(value); rstrip(value);
/* Valid name[=:]value pair found, call handler */ /* Valid name[=:]value pair found, call 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; }
} }
}
#if INI_STOP_ON_FIRST_ERROR #if INI_STOP_ON_FIRST_ERROR
if (error) if (error)
break; break;
#endif #endif
} }
#if !INI_USE_STACK #if !INI_USE_STACK
free(line); free(line);
#endif #endif
return error; return error;
} }
/* 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");
if (!file) if (!file)
return -1; return -1;
error = ini_parse_file(file, handler, user); error = ini_parse_file(file, handler, user);
fclose(file); fclose(file);
return error; return error;
} }

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

@ -55,7 +55,7 @@ int l_bbsRChar(lua_State *L) {
int l_bbsDisplayAnsiPause(lua_State *L) { int l_bbsDisplayAnsiPause(lua_State *L) {
char *str = (char *)lua_tostring(L, -1); char *str = (char *)lua_tostring(L, -1);
char buffer[256]; char buffer[256];
if (strchr(str, '/') == NULL) { if (strchr(str, '/') == NULL) {
sprintf(buffer, "%s/%s.ans", conf.ansi_path, str); sprintf(buffer, "%s/%s.ans", conf.ansi_path, str);
s_displayansi_pause(buffer, 1); s_displayansi_pause(buffer, 1);
@ -187,8 +187,7 @@ 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);
return 1; return 1;
@ -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) {
@ -226,12 +225,12 @@ int l_messageFound(lua_State *L) {
lua_pushnumber(L, 0); lua_pushnumber(L, 0);
return 1; return 1;
} }
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb); free(jb);
lua_pushnumber(L, 1); lua_pushnumber(L, 1);
return 1; return 1;
} }
int l_readMessageHdr(lua_State *L) { int l_readMessageHdr(lua_State *L) {
@ -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,11 +280,10 @@ 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);
free(jb); free(jb);
} }
if (subject == NULL) { if (subject == NULL) {
subject = strdup("(No Subject)"); subject = strdup("(No Subject)");
@ -307,7 +305,6 @@ int l_readMessageHdr(lua_State *L) {
free(sender); free(sender);
free(recipient); free(recipient);
return 3; return 3;
} }
@ -350,7 +347,7 @@ int l_readMessage(lua_State *L) {
lua_pushstring(L, body); lua_pushstring(L, body);
free(body); free(body);
return 1; return 1;
} }
@ -362,7 +359,7 @@ int l_dataPath(lua_State *L) {
if (stat(buffer, &s) != 0) { if (stat(buffer, &s) != 0) {
mkdir(buffer, 0755); mkdir(buffer, 0755);
} }
lua_pushstring(L, buffer); lua_pushstring(L, buffer);
return 1; return 1;
@ -376,7 +373,7 @@ int l_tempPath(lua_State *L) {
if (stat(buffer, &s) != 0) { if (stat(buffer, &s) != 0) {
mkdir(buffer, 0755); mkdir(buffer, 0755);
} }
lua_pushstring(L, buffer); lua_pushstring(L, buffer);
return 1; return 1;
@ -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,37 +413,36 @@ 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;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(from); jsf.DatLen = strlen(from);
jsf.Buffer = (char *)from; jsf.Buffer = (char *)from;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) {
sprintf(buffer, "ALL"); sprintf(buffer, "ALL");
jsf.LoID = JAMSFLD_RECVRNAME; jsf.LoID = JAMSFLD_RECVRNAME;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
} else { } else {
jsf.LoID = JAMSFLD_RECVRNAME; jsf.LoID = JAMSFLD_RECVRNAME;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(to); jsf.DatLen = strlen(to);
jsf.Buffer = (char *)to; jsf.Buffer = (char *)to;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
} }
jsf.LoID = JAMSFLD_SUBJECT; jsf.LoID = JAMSFLD_SUBJECT;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(subject); jsf.DatLen = strlen(subject);
jsf.Buffer = (char *)subject; jsf.Buffer = (char *)subject;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
@ -456,28 +452,28 @@ int l_postMessage(lua_State *L) {
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,
conf.mail_conferences[confr]->fidoaddr->net, conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node, conf.mail_conferences[confr]->fidoaddr->node,
conf.mail_conferences[confr]->fidoaddr->point); conf.mail_conferences[confr]->fidoaddr->point);
} else { } else {
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone, sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net, conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node); conf.mail_conferences[confr]->fidoaddr->node);
} }
jsf.LoID = JAMSFLD_OADDRESS; jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone, sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net, conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node, conf.mail_conferences[confr]->fidoaddr->node,
conf.mail_conferences[confr]->fidoaddr->point, conf.mail_conferences[confr]->fidoaddr->point,
generate_msgid()); generate_msgid());
jsf.LoID = JAMSFLD_MSGID; jsf.LoID = JAMSFLD_MSGID;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
@ -499,7 +495,7 @@ int l_postMessage(lua_State *L) {
} else { } else {
dolog("Failed to lock msg base!"); dolog("Failed to lock msg base!");
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb); free(jb);
return 0; return 0;
} }
} }
@ -514,23 +510,23 @@ int l_postMessage(lua_State *L) {
if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) {
if (conf.mail_conferences[confr]->fidoaddr->point == 0) { if (conf.mail_conferences[confr]->fidoaddr->point == 0) {
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone, snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net, conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node); conf.mail_conferences[confr]->fidoaddr->node);
} else { } else {
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone, snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net, conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node, conf.mail_conferences[confr]->fidoaddr->node,
conf.mail_conferences[confr]->fidoaddr->point); conf.mail_conferences[confr]->fidoaddr->point);
} }
} else { } else {
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline); snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline);
} }
msg = (char *)malloc(strlen(body) + 2 + strlen(buffer)); msg = (char *)malloc(strlen(body) + 2 + strlen(buffer));
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;
} }
@ -543,7 +539,7 @@ int l_postMessage(lua_State *L) {
if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) { if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) {
dolog("Failed to add message"); dolog("Failed to add message");
JAM_UnlockMB(jb); JAM_UnlockMB(jb);
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(msg); free(msg);
@ -573,7 +569,7 @@ void lua_push_cfunctions(lua_State *L) {
lua_pushcfunction(L, l_bbsRString); lua_pushcfunction(L, l_bbsRString);
lua_setglobal(L, "bbs_read_string"); lua_setglobal(L, "bbs_read_string");
lua_pushcfunction(L, l_bbsDisplayAnsiPause); lua_pushcfunction(L, l_bbsDisplayAnsiPause);
lua_setglobal(L, "bbs_display_ansi_pause"); lua_setglobal(L, "bbs_display_ansi_pause");
lua_pushcfunction(L, l_bbsDisplayAnsi); lua_pushcfunction(L, l_bbsDisplayAnsi);
lua_setglobal(L, "bbs_display_ansi"); lua_setglobal(L, "bbs_display_ansi");
lua_pushcfunction(L, l_bbsRChar); lua_pushcfunction(L, l_bbsRChar);
@ -601,15 +597,15 @@ void lua_push_cfunctions(lua_State *L) {
lua_pushcfunction(L, l_getBBSInfo); lua_pushcfunction(L, l_getBBSInfo);
lua_setglobal(L, "bbs_get_info"); lua_setglobal(L, "bbs_get_info");
lua_pushcfunction(L, l_bbsFileScan); lua_pushcfunction(L, l_bbsFileScan);
lua_setglobal(L, "bbs_file_scan"); lua_setglobal(L, "bbs_file_scan");
lua_pushcfunction(L, l_bbsFullMailScan); lua_pushcfunction(L, l_bbsFullMailScan);
lua_setglobal(L, "bbs_full_mail_scan"); lua_setglobal(L, "bbs_full_mail_scan");
lua_pushcfunction(L, l_getUserHandle); lua_pushcfunction(L, l_getUserHandle);
lua_setglobal(L, "bbs_get_userhandle"); lua_setglobal(L, "bbs_get_userhandle");
lua_pushcfunction(L, l_messageFound); lua_pushcfunction(L, l_messageFound);
lua_setglobal(L, "bbs_message_found"); lua_setglobal(L, "bbs_message_found");
lua_pushcfunction(L, l_readMessageHdr); lua_pushcfunction(L, l_readMessageHdr);
lua_setglobal(L, "bbs_read_message_hdr"); lua_setglobal(L, "bbs_read_message_hdr");
lua_pushcfunction(L, l_readMessage); lua_pushcfunction(L, l_readMessage);
lua_setglobal(L, "bbs_read_message"); lua_setglobal(L, "bbs_read_message");
lua_pushcfunction(L, l_tempPath); lua_pushcfunction(L, l_tempPath);

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);
} }
@ -66,28 +65,27 @@ void sigterm_handler(int s)
#endif #endif
if (ipv6_pid != -1) { if (ipv6_pid != -1) {
kill(ipv6_pid, SIGTERM); kill(ipv6_pid, SIGTERM);
} }
remove(conf.pid_file); remove(conf.pid_file);
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) {
@ -129,7 +127,7 @@ static int protocol_config_handler(void* user, const char* section, const char*
conf->protocols[conf->protocol_count]->internal_zmodem = 0; conf->protocols[conf->protocol_count]->internal_zmodem = 0;
conf->protocols[conf->protocol_count]->upload_prompt = 0; conf->protocols[conf->protocol_count]->upload_prompt = 0;
conf->protocols[conf->protocol_count]->stdio = 0; conf->protocols[conf->protocol_count]->stdio = 0;
if (strcasecmp(name, "upload command") == 0) { if (strcasecmp(name, "upload command") == 0) {
conf->protocols[conf->protocol_count]->upload = strdup(value); conf->protocols[conf->protocol_count]->upload = strdup(value);
} else if (strcasecmp(name, "download command") == 0) { } else if (strcasecmp(name, "download command") == 0) {
@ -158,13 +156,12 @@ static int protocol_config_handler(void* user, const char* section, const char*
return 1; 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);
@ -385,9 +378,9 @@ static int mail_area_handler(void* user, const char* section, const char* name,
} }
mc->mail_areas[mc->mail_area_count] = (struct mail_area *)malloc(sizeof(struct mail_area)); mc->mail_areas[mc->mail_area_count] = (struct mail_area *)malloc(sizeof(struct mail_area));
mc->mail_areas[mc->mail_area_count]->qwkname = NULL; mc->mail_areas[mc->mail_area_count]->qwkname = NULL;
mc->mail_areas[mc->mail_area_count]->name = strdup(section); mc->mail_areas[mc->mail_area_count]->name = strdup(section);
if (strcasecmp(name, "read sec level") == 0) { if (strcasecmp(name, "read sec level") == 0) {
mc->mail_areas[mc->mail_area_count]->read_sec_level = atoi(value); mc->mail_areas[mc->mail_area_count]->read_sec_level = atoi(value);
@ -416,9 +409,8 @@ static int mail_area_handler(void* user, const char* section, const char* name,
return 1; 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;
@ -432,7 +424,7 @@ static int handler(void* user, const char* section, const char* name,
conf->ssh_server = 1; conf->ssh_server = 1;
} else { } else {
conf->ssh_server = 0; conf->ssh_server = 0;
} }
} else if (strcasecmp(name, "enable ipv6") == 0) { } else if (strcasecmp(name, "enable ipv6") == 0) {
if (strcasecmp(value, "true") == 0) { if (strcasecmp(value, "true") == 0) {
conf->ipv6 = 1; conf->ipv6 = 1;
@ -486,7 +478,7 @@ static int handler(void* user, const char* section, const char* name,
} }
} else if (strcasecmp(name, "automessage write level") == 0) { } else if (strcasecmp(name, "automessage write level") == 0) {
conf->automsgwritelvl = atoi(value); conf->automsgwritelvl = atoi(value);
} else if (strcasecmp(name, "fork") == 0) { } else if (strcasecmp(name, "fork") == 0) {
if (strcasecmp(value, "true") == 0) { if (strcasecmp(value, "true") == 0) {
conf->fork = 1; conf->fork = 1;
} else { } else {
@ -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;
@ -625,15 +616,15 @@ int ssh_authenticate(ssh_session p_ssh_session) {
do { do {
message = ssh_message_get(p_ssh_session); message = ssh_message_get(p_ssh_session);
if (message == NULL) { if (message == NULL) {
gUser = NULL; gUser = NULL;
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) {
@ -683,57 +674,56 @@ char *ssh_getip(ssh_session session) {
} }
*/ */
static int ssh_copy_fd_to_chan(socket_t fd, int revents, void *userdata) { static int ssh_copy_fd_to_chan(socket_t fd, int revents, void *userdata) {
ssh_channel chan = (ssh_channel)userdata; ssh_channel chan = (ssh_channel)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;
} }
return sz; return sz;
} }
static int ssh_copy_chan_to_fd(ssh_session session, static int ssh_copy_chan_to_fd(ssh_session session,
ssh_channel channel, ssh_channel channel,
void *data, void *data,
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;
(void)is_stderr; (void)is_stderr;
sz = write(fd, data, len); sz = write(fd, data, len);
return sz; return sz;
} }
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;
close(fd); close(fd);
} }
struct ssh_channel_callbacks_struct ssh_cb = { 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;
@ -762,7 +752,7 @@ void serverssh(int port, int ipv6) {
bbs_stdin = dup(STDIN_FILENO); bbs_stdin = dup(STDIN_FILENO);
bbs_stdout = dup(STDOUT_FILENO); bbs_stdout = dup(STDOUT_FILENO);
bbs_stderr = dup(STDERR_FILENO); bbs_stderr = dup(STDERR_FILENO);
err = ssh_init(); err = ssh_init();
if (err == -1) { if (err == -1) {
fprintf(stderr, "Error starting SSH server.\n"); fprintf(stderr, "Error starting SSH server.\n");
@ -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);
@ -799,7 +788,7 @@ void serverssh(int port, int ipv6) {
if (setsockopt(ssh_sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) { if (setsockopt(ssh_sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) {
fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed"); fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed");
} }
memset(&server, 0, sizeof(server)); memset(&server, 0, sizeof(server));
server.sin6_family = AF_INET6; server.sin6_family = AF_INET6;
server.sin6_addr = in6addr_any; server.sin6_addr = in6addr_any;
@ -828,7 +817,7 @@ void serverssh(int port, int ipv6) {
} }
c = sizeof(struct sockaddr_in); c = sizeof(struct sockaddr_in);
} }
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 Failed: "); perror("SetUID Failed: ");
@ -838,23 +827,23 @@ void serverssh(int port, int ipv6) {
} }
listen(ssh_sock, 3); listen(ssh_sock, 3);
while ((csock = accept(ssh_sock, (struct sockaddr *)client_p, (socklen_t *)&c))) { while ((csock = accept(ssh_sock, (struct sockaddr *)client_p, (socklen_t *)&c))) {
p_ssh_session = ssh_new(); p_ssh_session = ssh_new();
if (p_ssh_session == NULL) { if (p_ssh_session == NULL) {
fprintf(stderr, "Error starting SSH session.\n"); fprintf(stderr, "Error starting SSH session.\n");
close(csock); close(csock);
continue; continue;
} }
if (ssh_bind_accept_fd(p_ssh_bind, p_ssh_session, csock) == SSH_OK) { if (ssh_bind_accept_fd(p_ssh_bind, p_ssh_session, csock) == SSH_OK) {
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)));
} else { } else {
ip = strdup(inet_ntop(AF_INET, &((struct sockaddr_in *)client_p)->sin_addr, str, sizeof(str))); ip = strdup(inet_ntop(AF_INET, &((struct sockaddr_in *)client_p)->sin_addr, str, sizeof(str)));
} }
if (conf.ipguard_enable) { if (conf.ipguard_enable) {
i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard)); i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard));
if (i == MAP_MISSING) { if (i == MAP_MISSING) {
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard)); ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
ip_guard->status = IP_STATUS_UNKNOWN; ip_guard->status = IP_STATUS_UNKNOWN;
@ -862,7 +851,7 @@ void serverssh(int port, int ipv6) {
ip_guard->connection_count = 1; ip_guard->connection_count = 1;
hashmap_put(ip_guard_map, strdup(ip), ip_guard); hashmap_put(ip_guard_map, strdup(ip), ip_guard);
} else if (i == MAP_OK) { } else if (i == MAP_OK) {
if (ip_guard->status == IP_STATUS_BLACKLISTED) { if (ip_guard->status == IP_STATUS_BLACKLISTED) {
free(ip); free(ip);
ssh_disconnect(p_ssh_session); ssh_disconnect(p_ssh_session);
@ -879,16 +868,15 @@ 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;
ip_guard->last_connection = time(NULL); ip_guard->last_connection = time(NULL);
} }
} }
} }
} }
pid = fork(); pid = fork();
if (pid == 0) { if (pid == 0) {
close(ssh_sock); close(ssh_sock);
@ -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();
@ -924,7 +912,7 @@ void serverssh(int port, int ipv6) {
if (message) { if (message) {
if (ssh_message_type(message) == SSH_REQUEST_CHANNEL) { if (ssh_message_type(message) == SSH_REQUEST_CHANNEL) {
if (ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_SHELL) { if (ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_SHELL) {
shell = 1; shell = 1;
ssh_message_channel_request_reply_success(message); ssh_message_channel_request_reply_success(message);
ssh_message_free(message); ssh_message_free(message);
break; break;
@ -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 {
} }
} }
} }
@ -1028,49 +1011,49 @@ void server(int port, int ipv6) {
if (conf.ipguard_enable) { if (conf.ipguard_enable) {
ip_guard_map = hashmap_new(); ip_guard_map = hashmap_new();
snprintf(buffer, 1024, "%s/whitelist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4)); snprintf(buffer, 1024, "%s/whitelist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4));
fptr = fopen(buffer, "r"); fptr = fopen(buffer, "r");
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 {
break; break;
} }
} }
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard)); ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
ip_guard->status = IP_STATUS_WHITELISTED; ip_guard->status = IP_STATUS_WHITELISTED;
hashmap_put(ip_guard_map, strdup(buffer), ip_guard); hashmap_put(ip_guard_map, strdup(buffer), ip_guard);
fgets(buffer, 1024, fptr); fgets(buffer, 1024, fptr);
} }
fclose(fptr); fclose(fptr);
} }
snprintf(buffer, 1024, "%s/blacklist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4)); snprintf(buffer, 1024, "%s/blacklist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4));
fptr = fopen(buffer, "r"); fptr = fopen(buffer, "r");
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 {
break; break;
} }
} }
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard)); ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
ip_guard->status = IP_STATUS_BLACKLISTED; ip_guard->status = IP_STATUS_BLACKLISTED;
hashmap_put(ip_guard_map, strdup(buffer), ip_guard); hashmap_put(ip_guard_map, strdup(buffer), ip_guard);
fgets(buffer, 1024, fptr); fgets(buffer, 1024, fptr);
} }
fclose(fptr); fclose(fptr);
@ -1080,27 +1063,27 @@ void server(int port, int ipv6) {
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO; sa.sa_flags = SA_RESTART | SA_SIGINFO;
if (sigaction(SIGCHLD, &sa, NULL) == -1) { if (sigaction(SIGCHLD, &sa, NULL) == -1) {
perror("sigaction - sigchld"); perror("sigaction - sigchld");
remove(conf.pid_file); remove(conf.pid_file);
exit(1); exit(1);
} }
st.sa_handler = sigterm_handler; st.sa_handler = sigterm_handler;
sigemptyset(&st.sa_mask); sigemptyset(&st.sa_mask);
st.sa_flags = SA_SIGINFO; st.sa_flags = SA_SIGINFO;
if (sigaction(SIGTERM, &st, NULL) == -1) { if (sigaction(SIGTERM, &st, NULL) == -1) {
perror("sigaction - sigterm"); perror("sigaction - sigterm");
remove(conf.pid_file); remove(conf.pid_file);
exit(1); exit(1);
} }
sq.sa_handler = sigterm_handler; sq.sa_handler = sigterm_handler;
sigemptyset(&sq.sa_mask); sigemptyset(&sq.sa_mask);
sq.sa_flags = SA_SIGINFO; sq.sa_flags = SA_SIGINFO;
if (sigaction(SIGQUIT, &sq, NULL) == -1) { if (sigaction(SIGQUIT, &sq, NULL) == -1) {
perror("sigaction - sigquit"); perror("sigaction - sigquit");
remove(conf.pid_file); remove(conf.pid_file);
exit(1); exit(1);
} }
if (conf.ssh_server) { if (conf.ssh_server) {
@ -1133,7 +1116,6 @@ void server(int port, int ipv6) {
fprintf(stderr, "Couldn't create socket..\n"); fprintf(stderr, "Couldn't create socket..\n");
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);
@ -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");
@ -1189,14 +1170,14 @@ void server(int port, int ipv6) {
} }
} }
#if defined(ENABLE_WWW) #if defined(ENABLE_WWW)
if (conf.www_server && conf.www_path != NULL && conf.www_url != NULL) { if (conf.www_server && conf.www_path != NULL && conf.www_url != NULL) {
if (!conf.fork) { if (!conf.fork) {
printf(" - HTTP Starting on Port %d (IPv%d)\n", conf.www_port, (ipv6 ? 6 : 4)); printf(" - HTTP Starting on Port %d (IPv%d)\n", conf.www_port, (ipv6 ? 6 : 4));
} }
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)));
@ -1219,10 +1199,10 @@ void server(int port, int ipv6) {
exit(-1); exit(-1);
} }
} }
if (conf.ipguard_enable) { if (conf.ipguard_enable) {
i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard)); i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard));
if (i == MAP_MISSING) { if (i == MAP_MISSING) {
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard)); ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
ip_guard->status = IP_STATUS_UNKNOWN; ip_guard->status = IP_STATUS_UNKNOWN;
@ -1230,7 +1210,7 @@ void server(int port, int ipv6) {
ip_guard->connection_count = 1; ip_guard->connection_count = 1;
hashmap_put(ip_guard_map, strdup(ip), ip_guard); hashmap_put(ip_guard_map, strdup(ip), ip_guard);
} else if (i == MAP_OK) { } else if (i == MAP_OK) {
if (ip_guard->status == IP_STATUS_BLACKLISTED) { if (ip_guard->status == IP_STATUS_BLACKLISTED) {
write(client_sock, "BLOCKED\r\n", 9); write(client_sock, "BLOCKED\r\n", 9);
free(ip); free(ip);
@ -1249,14 +1229,13 @@ 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;
ip_guard->last_connection = time(NULL); ip_guard->last_connection = time(NULL);
} }
} }
} }
} }
pid = fork(); pid = fork();
@ -1284,7 +1263,7 @@ int main(int argc, char **argv) {
FILE *fptr; FILE *fptr;
struct stat s; struct stat s;
char buffer[1024]; char buffer[1024];
if (argc < 2) { if (argc < 2) {
fprintf(stderr, "Usage ./magicka config/bbs.ini\n"); fprintf(stderr, "Usage ./magicka config/bbs.ini\n");
exit(1); exit(1);
@ -1319,38 +1298,38 @@ int main(int argc, char **argv) {
conf.ipguard_enable = 0; conf.ipguard_enable = 0;
conf.ipguard_tries = 4; conf.ipguard_tries = 4;
conf.ipguard_timeout = 120; conf.ipguard_timeout = 120;
conf.protocol_count = 0; conf.protocol_count = 0;
conf.codepage = 0; conf.codepage = 0;
conf.date_style = 0; conf.date_style = 0;
conf.ipv6 = 0; conf.ipv6 = 0;
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);
} }
if (conf.config_path == NULL) { if (conf.config_path == NULL) {
fprintf(stderr, "Config Path must be set in your bbs ini!\n"); fprintf(stderr, "Config Path must be set in your bbs ini!\n");
exit(-1); exit(-1);
} }
if (conf.root_menu == NULL) { if (conf.root_menu == NULL) {
fprintf(stderr, "Root Menu must be set in your bbs ini!\n"); fprintf(stderr, "Root Menu must be set in your bbs ini!\n");
exit(-1); exit(-1);
} }
// 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);
@ -1415,7 +1392,7 @@ int main(int argc, char **argv) {
ipv6_pid = fork(); ipv6_pid = fork();
if (ipv6_pid < 0) { if (ipv6_pid < 0) {
fprintf(stderr, "Error forking.\n"); fprintf(stderr, "Error forking.\n");
exit(-1); exit(-1);
} else if (ipv6_pid > 0) { } else if (ipv6_pid > 0) {
server(conf.telnet_port, 0); server(conf.telnet_port, 0);
} else { } else {
@ -1429,18 +1406,18 @@ 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);
unlink(buffer); unlink(buffer);
} }
} }
if (conf.ipv6) { if (conf.ipv6) {
ipv6_pid = fork(); ipv6_pid = fork();
if (ipv6_pid < 0) { if (ipv6_pid < 0) {
fprintf(stderr, "Error forking.\n"); fprintf(stderr, "Error forking.\n");
exit(-1); exit(-1);
} else if (ipv6_pid > 0) { } else if (ipv6_pid > 0) {
server(conf.telnet_port, 0); server(conf.telnet_port, 0);
} else { } else {

View File

@ -17,7 +17,7 @@ void display_bulletins() {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
struct stat s; struct stat s;
i = 0; i = 0;
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
while (stat(buffer, &s) == 0) { while (stat(buffer, &s) == 0) {
@ -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);
} }
} }
} }
@ -98,7 +98,7 @@ void display_textfiles() {
s_printf(get_string(148)); s_printf(get_string(148));
s_printf(get_string(185)); s_printf(get_string(185));
s_getc(); s_getc();
s_printf("\r\n"); s_printf("\r\n");
return; return;
} }
@ -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 {
@ -137,7 +137,7 @@ void display_textfiles() {
if (selected >= conf.text_file_count) { if (selected >= conf.text_file_count) {
selected = conf.text_file_count - 1; selected = conf.text_file_count - 1;
} else { } else {
if (!redraw) { if (!redraw) {
s_printf(get_string(250), selected - start + 1, selected - 1, conf.text_files[selected - 1]->name); s_printf(get_string(250), selected - start + 1, selected - 1, conf.text_files[selected - 1]->name);
s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name); s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name);
s_printf("\e[%d;5H", selected - start + 2); s_printf("\e[%d;5H", selected - start + 2);
@ -156,11 +156,11 @@ void display_textfiles() {
if (selected < 0) { if (selected < 0) {
selected = 0; selected = 0;
} else { } else {
if (!redraw) { if (!redraw) {
s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name); s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name);
s_printf(get_string(250), selected - start + 3, selected + 1, conf.text_files[selected + 1]->name); s_printf(get_string(250), selected - start + 3, selected + 1, conf.text_files[selected + 1]->name);
s_printf("\e[%d;5H", selected - start + 2); s_printf("\e[%d;5H", selected - start + 2);
} }
} }
} else if (c == 75) { } else if (c == 75) {
// END KEY // END KEY
@ -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;
@ -204,7 +204,7 @@ void display_textfiles() {
s_displayansi_p(conf.text_files[selected]->path); s_displayansi_p(conf.text_files[selected]->path);
s_printf(get_string(185)); s_printf(get_string(185));
s_getc(); s_getc();
s_printf("\r\n"); s_printf("\r\n");
redraw = 1; redraw = 1;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -8,22 +8,22 @@ extern struct user_record *gUser;
char *nl_get_bbsname(struct fido_addr *addr, char *domain) { char *nl_get_bbsname(struct fido_addr *addr, char *domain) {
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char *ret; char *ret;
char *sql_buf = "SELECT bbsname FROM nodelist WHERE nodeno=? AND domain=?"; char *sql_buf = "SELECT bbsname FROM nodelist WHERE nodeno=? AND domain=?";
snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
return strdup("Unknown"); return strdup("Unknown");
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
@ -31,22 +31,22 @@ char *nl_get_bbsname(struct fido_addr *addr, char *domain) {
return strdup("Unknown"); return strdup("Unknown");
} }
if (addr->point == 0) { if (addr->point == 0) {
snprintf(buffer, PATH_MAX, "%d:%d/%d", addr->zone, addr->net, addr->node); snprintf(buffer, PATH_MAX, "%d:%d/%d", addr->zone, addr->net, addr->node);
} else { } else {
// no support for point addresses yet. // no support for point addresses yet.
return strdup("Unknown"); return strdup("Unknown");
} }
sqlite3_bind_text(res, 1, buffer, -1, 0);
sqlite3_bind_text(res, 2, domain, -1, 0);
sqlite3_bind_text(res, 1, buffer, -1, 0);
sqlite3_bind_text(res, 2, domain, -1, 0);
if (sqlite3_step(res) != SQLITE_ROW) { if (sqlite3_step(res) != SQLITE_ROW) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return strdup("Unknown"); return strdup("Unknown");
} }
ret = strdup(sqlite3_column_text(res, 0)); ret = strdup(sqlite3_column_text(res, 0));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
@ -64,7 +64,7 @@ void nl_browser() {
int entry_count = 0; int entry_count = 0;
struct nl_temp **entries; struct nl_temp **entries;
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char *ret; char *ret;
@ -77,15 +77,15 @@ void nl_browser() {
// load nodelist // load nodelist
snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
return; return;
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
@ -93,8 +93,8 @@ void nl_browser() {
return; return;
} }
sqlite3_bind_text(res, 1, conf.mail_conferences[gUser->cur_mail_conf]->domain, -1, 0); sqlite3_bind_text(res, 1, conf.mail_conferences[gUser->cur_mail_conf]->domain, -1, 0);
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
if (entry_count == 0) { if (entry_count == 0) {
entries = (struct nl_temp **)malloc(sizeof(struct nl_temp *)); entries = (struct nl_temp **)malloc(sizeof(struct nl_temp *));
@ -108,10 +108,10 @@ void nl_browser() {
entries[entry_count]->sysop = strdup(sqlite3_column_text(res, 2)); entries[entry_count]->sysop = strdup(sqlite3_column_text(res, 2));
entries[entry_count]->bbsname = strdup(sqlite3_column_text(res, 3)); entries[entry_count]->bbsname = strdup(sqlite3_column_text(res, 3));
entry_count++; entry_count++;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
if (entry_count == 0) { if (entry_count == 0) {
return; return;
} }
@ -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 {
@ -151,7 +151,7 @@ void nl_browser() {
if (selected >= entry_count) { if (selected >= entry_count) {
selected = entry_count - 1; selected = entry_count - 1;
} else { } else {
if (!redraw) { if (!redraw) {
s_printf(get_string(261), selected - start + 1, selected - 1, entries[selected - 1]->address, entries[selected - 1]->bbsname); s_printf(get_string(261), selected - start + 1, selected - 1, entries[selected - 1]->address, entries[selected - 1]->bbsname);
s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname); s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname);
s_printf("\e[%d;5H", selected - start + 2); s_printf("\e[%d;5H", selected - start + 2);
@ -170,11 +170,11 @@ void nl_browser() {
if (selected < 0) { if (selected < 0) {
selected = 0; selected = 0;
} else { } else {
if (!redraw) { if (!redraw) {
s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname); s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname);
s_printf(get_string(261), selected - start + 3, selected + 1, entries[selected + 1]->address, entries[selected + 1]->bbsname); s_printf(get_string(261), selected - start + 3, selected + 1, entries[selected + 1]->address, entries[selected + 1]->bbsname);
s_printf("\e[%d;5H", selected - start + 2); s_printf("\e[%d;5H", selected - start + 2);
} }
} }
} else if (c == 75) { } else if (c == 75) {
// END KEY // END KEY
@ -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;
@ -223,11 +223,11 @@ void nl_browser() {
s_printf(get_string(267)); s_printf(get_string(267));
s_printf(get_string(185)); s_printf(get_string(185));
s_getc(); s_getc();
s_printf("\r\n"); s_printf("\r\n");
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

@ -12,32 +12,31 @@ int openpty(int *amaster, int *aslave, char *name, void *termp, void *winp) {
int pts; int pts;
ptm = open("/dev/ptmx", O_RDWR); ptm = open("/dev/ptmx", O_RDWR);
grantpt(ptm); grantpt(ptm);
unlockpt(ptm); unlockpt(ptm);
pname = ptsname(ptm); pname = ptsname(ptm);
if (name != NULL) { if (name != NULL) {
strcpy(name, pname); strcpy(name, pname);
} }
pts = open(pname, O_RDWR); pts = open(pname, O_RDWR);
ioctl(pts, I_PUSH, "ptem"); ioctl(pts, I_PUSH, "ptem");
ioctl(pts, I_PUSH, "ldterm"); ioctl(pts, I_PUSH, "ldterm");
ioctl(pts, I_PUSH, "ttcompat"); ioctl(pts, I_PUSH, "ttcompat");
if (termp != NULL) { if (termp != NULL) {
tcsetattr(pts, TCSAFLUSH, termp); tcsetattr(pts, TCSAFLUSH, termp);
} }
if (winp != NULL) { if (winp != NULL) {
ioctl(pts, TIOCSWINSZ, winp); ioctl(pts, TIOCSWINSZ, winp);
} }
*amaster = ptm; *amaster = ptm;
*aslave = pts; *aslave = pts;
return 0; return 0;
} }
@ -52,7 +51,7 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) {
grantpt(ptm); grantpt(ptm);
unlockpt(ptm); unlockpt(ptm);
pname = ptsname(ptm); pname = ptsname(ptm);
if (name != NULL) { if (name != NULL) {
@ -71,7 +70,7 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) {
} }
pid = fork(); pid = fork();
if (!pid) { if (!pid) {
close(ptm); close(ptm);
dup2(pts, 0); dup2(pts, 0);
@ -82,16 +81,15 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) {
*amaster = ptm; *amaster = ptm;
} }
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,138 +44,116 @@ 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();
if (c == 91) {
c = s_getc(); c = s_getc();
if (c == 91) {
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); if (strcmp(hash, user->password) == 0) {
if (strcmp(hash, user->password) == 0) { s_printf(get_string(156));
s_printf(get_string(156)); s_readstring(buffer, 16);
s_readstring(buffer, 16); if (strlen(buffer) >= 8) {
if (strlen(buffer) >= 8) { free(user->password);
free(user->password); free(user->salt);
free(user->salt);
gen_salt(&user->salt); gen_salt(&user->salt);
user->password = hash_sha256(buffer, user->salt); user->password = hash_sha256(buffer, user->salt);
save_user(user);
s_printf(get_string(157));
} else {
s_printf(get_string(158));
}
} else {
s_printf(get_string(159));
}
}
break;
case 'l':
{
s_printf(get_string(160));
s_readstring(buffer, 32);
free(user->location);
user->location = (char *)malloc(strlen(buffer) + 1);
strcpy(user->location, buffer);
save_user(user);
}
break;
case 'a':
{
s_printf(get_string(206));
for (i=0;i<conf.archiver_count;i++) {
s_printf(get_string(207), i + 1, conf.archivers[i]->name);
}
s_printf(get_string(208));
s_readstring(buffer, 5);
new_arc = atoi(buffer);
if (new_arc - 1 < 0 || new_arc > conf.archiver_count) {
break;
} else {
user->defarchiver = new_arc;
save_user(user); save_user(user);
} s_printf(get_string(157));
}
break;
case 'o':
{
s_printf(get_string(212));
for (i=0;i<conf.protocol_count;i++) {
s_printf(get_string(207), i + 1, conf.protocols[i]->name);
}
s_printf(get_string(208));
s_readstring(buffer, 5);
new_arc = atoi(buffer);
if (new_arc - 1 < 0 || new_arc > conf.protocol_count) {
break;
} else { } else {
user->defprotocol = new_arc; s_printf(get_string(158));
save_user(user);
} }
} else {
s_printf(get_string(159));
} }
break; } break;
case 'm': case 'l': {
{ s_printf(get_string(160));
user->nodemsgs = !user->nodemsgs; s_readstring(buffer, 32);
free(user->location);
user->location = (char *)malloc(strlen(buffer) + 1);
strcpy(user->location, buffer);
save_user(user);
} break;
case 'a': {
s_printf(get_string(206));
for (i = 0; i < conf.archiver_count; i++) {
s_printf(get_string(207), i + 1, conf.archivers[i]->name);
}
s_printf(get_string(208));
s_readstring(buffer, 5);
new_arc = atoi(buffer);
if (new_arc - 1 < 0 || new_arc > conf.archiver_count) {
break;
} else {
user->defarchiver = new_arc;
save_user(user); save_user(user);
} }
break; } break;
case 'c':
{ case 'o': {
user->codepage = !user->codepage; s_printf(get_string(212));
for (i = 0; i < conf.protocol_count; i++) {
s_printf(get_string(207), i + 1, conf.protocols[i]->name);
}
s_printf(get_string(208));
s_readstring(buffer, 5);
new_arc = atoi(buffer);
if (new_arc - 1 < 0 || new_arc > conf.protocol_count) {
break;
} else {
user->defprotocol = new_arc;
save_user(user); save_user(user);
} }
break; } break;
case 'e': case 'm': {
{ user->nodemsgs = !user->nodemsgs;
user->exteditor++; save_user(user);
if (user->exteditor == 3) { } break;
user->exteditor = 0; case 'c': {
} user->codepage = !user->codepage;
save_user(user);
} break;
case 'e': {
user->exteditor++;
if (user->exteditor == 3) {
user->exteditor = 0;
}
save_user(user);
} break;
case 'b': {
user->bwavepktno = 0;
user->bwavestyle = !user->bwavestyle;
save_user(user);
} break;
case 's': {
// set signature
if (user->signature != NULL) {
free(user->signature);
}
sig = external_editor(user, "No-One", "No-One", NULL, 0, "No-One", "Signature Editor", 0, 1);
if (sig != NULL) {
user->signature = sig;
save_user(user); save_user(user);
} }
break; } break;
case 'b': case 't': {
{ user->autosig = !user->autosig;
user->bwavepktno = 0; save_user(user);
user->bwavestyle = !user->bwavestyle; } break;
save_user(user);
}
break;
case 's':
{
// set signature
if (user->signature != NULL) {
free(user->signature);
}
sig = external_editor(user, "No-One", "No-One", NULL, 0, "No-One", "Signature Editor", 0, 1);
if (sig != NULL) {
user->signature = sig;
save_user(user);
}
}
break;
case 't':
{
user->autosig = !user->autosig;
save_user(user);
}
break;
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,23 +29,21 @@ 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);
return shash; return shash;
} }
} }
} }
EVP_MD_CTX_free(context); EVP_MD_CTX_free(context);
@ -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) {
@ -97,142 +94,139 @@ static int secLevel(void* user, const char* section, const char* name,
int save_user(struct user_record *user) { int save_user(struct user_record *user) {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *update_sql = "UPDATE users SET password=?, salt=?, firstname=?," char *update_sql = "UPDATE users SET password=?, salt=?, firstname=?,"
"lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=?, bwavepktno=?, archiver=?, protocol=?,nodemsgs=?,codepage=?,exteditor=?,bwavestyle=?,signature=?,autosig=? where loginname LIKE ?"; "lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=?, bwavepktno=?, archiver=?, protocol=?,nodemsgs=?,codepage=?,exteditor=?,bwavestyle=?,signature=?,autosig=? where loginname LIKE ?";
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);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, update_sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, update_sql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, user->password, -1, 0); sqlite3_bind_text(res, 1, user->password, -1, 0);
sqlite3_bind_text(res, 2, user->salt, -1, 0); sqlite3_bind_text(res, 2, user->salt, -1, 0);
sqlite3_bind_text(res, 3, user->firstname, -1, 0); sqlite3_bind_text(res, 3, user->firstname, -1, 0);
sqlite3_bind_text(res, 4, user->lastname, -1, 0); sqlite3_bind_text(res, 4, user->lastname, -1, 0);
sqlite3_bind_text(res, 5, user->email, -1, 0); sqlite3_bind_text(res, 5, user->email, -1, 0);
sqlite3_bind_text(res, 6, user->location, -1, 0); sqlite3_bind_text(res, 6, user->location, -1, 0);
sqlite3_bind_int(res, 7, user->sec_level); sqlite3_bind_int(res, 7, user->sec_level);
sqlite3_bind_int(res, 8, user->laston); sqlite3_bind_int(res, 8, user->laston);
sqlite3_bind_int(res, 9, user->timeleft); sqlite3_bind_int(res, 9, user->timeleft);
sqlite3_bind_int(res, 10, user->cur_mail_conf); sqlite3_bind_int(res, 10, user->cur_mail_conf);
sqlite3_bind_int(res, 11, user->cur_mail_area); sqlite3_bind_int(res, 11, user->cur_mail_area);
sqlite3_bind_int(res, 12, user->cur_file_dir); sqlite3_bind_int(res, 12, user->cur_file_dir);
sqlite3_bind_int(res, 13, user->cur_file_sub); sqlite3_bind_int(res, 13, user->cur_file_sub);
sqlite3_bind_int(res, 14, user->timeson); sqlite3_bind_int(res, 14, user->timeson);
sqlite3_bind_int(res, 15, user->bwavepktno); sqlite3_bind_int(res, 15, user->bwavepktno);
sqlite3_bind_int(res, 16, user->defarchiver); sqlite3_bind_int(res, 16, user->defarchiver);
sqlite3_bind_int(res, 17, user->defprotocol); sqlite3_bind_int(res, 17, user->defprotocol);
sqlite3_bind_int(res, 18, user->nodemsgs); sqlite3_bind_int(res, 18, user->nodemsgs);
sqlite3_bind_int(res, 19, user->codepage); sqlite3_bind_int(res, 19, user->codepage);
sqlite3_bind_int(res, 20, user->exteditor); sqlite3_bind_int(res, 20, user->exteditor);
sqlite3_bind_int(res, 21, user->bwavestyle); sqlite3_bind_int(res, 21, user->bwavestyle);
sqlite3_bind_text(res, 22, user->signature, -1, 0); sqlite3_bind_text(res, 22, user->signature, -1, 0);
sqlite3_bind_int(res, 23, user->autosig); sqlite3_bind_int(res, 23, user->autosig);
sqlite3_bind_text(res, 24, user->loginname, -1, 0); sqlite3_bind_text(res, 24, user->loginname, -1, 0);
} else { } else {
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);
dolog("execution failed: %s", sqlite3_errmsg(db)); dolog("execution failed: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
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) {
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char *create_sql = "CREATE TABLE IF NOT EXISTS msg_flags (conference INTEGER, msgbase INTEGER, uid INTEGER, msg INTEGER);"; char *create_sql = "CREATE TABLE IF NOT EXISTS msg_flags (conference INTEGER, msgbase INTEGER, uid INTEGER, msg INTEGER);";
char *flag_buf = "INSERT INTO msg_flags (conference, msgbase, uid, msg) VALUES(?, ?, ?, ?)"; char *flag_buf = "INSERT INTO msg_flags (conference, msgbase, uid, msg) VALUES(?, ?, ?, ?)";
char *unflag_buf = "DELETE FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?"; char *unflag_buf = "DELETE FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?";
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);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
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);
return 0; return 0;
} }
if (flagunflag == 1) { if (flagunflag == 1) {
rc = sqlite3_prepare_v2(db, unflag_buf, -1, &res, 0); rc = sqlite3_prepare_v2(db, unflag_buf, -1, &res, 0);
} else { } else {
rc = sqlite3_prepare_v2(db, flag_buf, -1, &res, 0); rc = sqlite3_prepare_v2(db, flag_buf, -1, &res, 0);
} }
sqlite3_bind_int(res, 1, conference); sqlite3_bind_int(res, 1, conference);
sqlite3_bind_int(res, 2, msgbase); sqlite3_bind_int(res, 2, msgbase);
sqlite3_bind_int(res, 3, user->id); sqlite3_bind_int(res, 3, user->id);
sqlite3_bind_int(res, 4, msgid); sqlite3_bind_int(res, 4, msgid);
rc = sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
rc = sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
return 1; return 1;
} }
int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, int msgid) { int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, int msgid) {
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char *sql_buf = "SELECT * FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?";
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1); char *sql_buf = "SELECT * FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?";
}
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
@ -240,16 +234,16 @@ int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, in
return 0; return 0;
} }
sqlite3_bind_int(res, 1, conference); sqlite3_bind_int(res, 1, conference);
sqlite3_bind_int(res, 2, msgbase); sqlite3_bind_int(res, 2, msgbase);
sqlite3_bind_int(res, 3, user->id); sqlite3_bind_int(res, 3, user->id);
sqlite3_bind_int(res, 4, msgid); sqlite3_bind_int(res, 4, msgid);
if (sqlite3_step(res) != SQLITE_ROW) { if (sqlite3_step(res) != SQLITE_ROW) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
@ -257,79 +251,76 @@ int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, in
int msgbase_sub_unsub(int conference, int msgbase) { int msgbase_sub_unsub(int conference, int msgbase) {
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char *create_sql = "CREATE TABLE IF NOT EXISTS msg_subs (conference INTEGER, msgbase INTEGER, uid INTEGER);"; char *create_sql = "CREATE TABLE IF NOT EXISTS msg_subs (conference INTEGER, msgbase INTEGER, uid INTEGER);";
char *sub_buf = "INSERT INTO msg_subs (conference, msgbase, uid) VALUES(?, ?, ?)"; char *sub_buf = "INSERT INTO msg_subs (conference, msgbase, uid) VALUES(?, ?, ?)";
char *unsub_buf = "DELETE FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?"; char *unsub_buf = "DELETE FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
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);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
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);
return 0; return 0;
} }
if (subunsub == 1) { if (subunsub == 1) {
rc = sqlite3_prepare_v2(db, unsub_buf, -1, &res, 0); rc = sqlite3_prepare_v2(db, unsub_buf, -1, &res, 0);
} else { } else {
rc = sqlite3_prepare_v2(db, sub_buf, -1, &res, 0); rc = sqlite3_prepare_v2(db, sub_buf, -1, &res, 0);
} }
sqlite3_bind_int(res, 1, conference); sqlite3_bind_int(res, 1, conference);
sqlite3_bind_int(res, 2, msgbase); sqlite3_bind_int(res, 2, msgbase);
sqlite3_bind_int(res, 3, gUser->id); sqlite3_bind_int(res, 3, gUser->id);
rc = sqlite3_step(res); rc = sqlite3_step(res);
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
} }
int msgbase_is_subscribed(int conference, int msgbase) { int msgbase_is_subscribed(int conference, int msgbase) {
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1); char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
}
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
@ -337,15 +328,15 @@ int msgbase_is_subscribed(int conference, int msgbase) {
return 0; return 0;
} }
sqlite3_bind_int(res, 1, conference); sqlite3_bind_int(res, 1, conference);
sqlite3_bind_int(res, 2, msgbase); sqlite3_bind_int(res, 2, msgbase);
sqlite3_bind_int(res, 3, gUser->id); sqlite3_bind_int(res, 3, gUser->id);
if (sqlite3_step(res) != SQLITE_ROW) { if (sqlite3_step(res) != SQLITE_ROW) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
@ -354,79 +345,79 @@ int msgbase_is_subscribed(int conference, int msgbase) {
int inst_user(struct user_record *user) { int inst_user(struct user_record *user) {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *create_sql = "CREATE TABLE IF NOT EXISTS users (" char *create_sql = "CREATE TABLE IF NOT EXISTS users ("
"Id INTEGER PRIMARY KEY," "Id INTEGER PRIMARY KEY,"
"loginname TEXT COLLATE NOCASE," "loginname TEXT COLLATE NOCASE,"
"password TEXT," "password TEXT,"
"salt TEXT," "salt TEXT,"
"firstname TEXT," "firstname TEXT,"
"lastname TEXT," "lastname TEXT,"
"email TEXT," "email TEXT,"
"location TEXT," "location TEXT,"
"sec_level INTEGER," "sec_level INTEGER,"
"last_on INTEGER," "last_on INTEGER,"
"time_left INTEGER," "time_left INTEGER,"
"cur_mail_conf INTEGER," "cur_mail_conf INTEGER,"
"cur_mail_area INTEGER," "cur_mail_area INTEGER,"
"cur_file_sub INTEGER," "cur_file_sub INTEGER,"
"cur_file_dir INTEGER," "cur_file_dir INTEGER,"
"times_on INTEGER," "times_on INTEGER,"
"bwavepktno INTEGER," "bwavepktno INTEGER,"
"archiver INTEGER," "archiver INTEGER,"
"protocol INTEGER," "protocol INTEGER,"
"nodemsgs INTEGER," "nodemsgs INTEGER,"
"codepage INTEGER," "codepage INTEGER,"
"exteditor INTEGER," "exteditor INTEGER,"
"bwavestyle INTEGER," "bwavestyle INTEGER,"
"signature TEXT," "signature TEXT,"
"autosig INTEGER);"; "autosig INTEGER);";
char *insert_sql = "INSERT INTO users (loginname, password, salt, firstname," char *insert_sql = "INSERT INTO users (loginname, password, salt, firstname,"
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage, exteditor, bwavestyle, signature, autosig) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage, exteditor, bwavestyle, signature, autosig) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
char *err_msg = 0; char *err_msg = 0;
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
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);
exit(1); exit(1);
} }
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, user->loginname, -1, 0); sqlite3_bind_text(res, 1, user->loginname, -1, 0);
sqlite3_bind_text(res, 2, user->password, -1, 0); sqlite3_bind_text(res, 2, user->password, -1, 0);
sqlite3_bind_text(res, 3, user->salt, -1, 0); sqlite3_bind_text(res, 3, user->salt, -1, 0);
sqlite3_bind_text(res, 4, user->firstname, -1, 0); sqlite3_bind_text(res, 4, user->firstname, -1, 0);
sqlite3_bind_text(res, 5, user->lastname, -1, 0); sqlite3_bind_text(res, 5, user->lastname, -1, 0);
sqlite3_bind_text(res, 6, user->email, -1, 0); sqlite3_bind_text(res, 6, user->email, -1, 0);
sqlite3_bind_text(res, 7, user->location, -1, 0); sqlite3_bind_text(res, 7, user->location, -1, 0);
sqlite3_bind_int(res, 8, user->sec_level); sqlite3_bind_int(res, 8, user->sec_level);
sqlite3_bind_int(res, 9, user->laston); sqlite3_bind_int(res, 9, user->laston);
sqlite3_bind_int(res, 10, user->timeleft); sqlite3_bind_int(res, 10, user->timeleft);
sqlite3_bind_int(res, 11, user->cur_mail_conf); sqlite3_bind_int(res, 11, user->cur_mail_conf);
sqlite3_bind_int(res, 12, user->cur_mail_area); sqlite3_bind_int(res, 12, user->cur_mail_area);
sqlite3_bind_int(res, 13, user->cur_file_dir); sqlite3_bind_int(res, 13, user->cur_file_dir);
sqlite3_bind_int(res, 14, user->cur_file_sub); sqlite3_bind_int(res, 14, user->cur_file_sub);
sqlite3_bind_int(res, 15, user->timeson); sqlite3_bind_int(res, 15, user->timeson);
sqlite3_bind_int(res, 16, user->bwavepktno); sqlite3_bind_int(res, 16, user->bwavepktno);
sqlite3_bind_int(res, 17, user->defarchiver); sqlite3_bind_int(res, 17, user->defarchiver);
sqlite3_bind_int(res, 18, user->defprotocol); sqlite3_bind_int(res, 18, user->defprotocol);
@ -436,24 +427,23 @@ int inst_user(struct user_record *user) {
sqlite3_bind_int(res, 22, user->bwavestyle); sqlite3_bind_int(res, 22, user->bwavestyle);
sqlite3_bind_text(res, 23, user->signature, -1, 0); sqlite3_bind_text(res, 23, user->signature, -1, 0);
sqlite3_bind_int(res, 24, user->autosig); sqlite3_bind_int(res, 24, user->autosig);
} else { } else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_step(res);
if (rc != SQLITE_DONE) {
dolog("execution failed: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
user->id = sqlite3_last_insert_rowid(db); rc = sqlite3_step(res);
sqlite3_finalize(res); if (rc != SQLITE_DONE) {
dolog("execution failed: %s", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
user->id = sqlite3_last_insert_rowid(db);
sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
} }
@ -462,36 +452,36 @@ struct user_record *check_user_pass(char *loginname, char *password) {
struct user_record *user; struct user_record *user;
char buffer[1024]; char buffer[1024];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *sql = "SELECT Id, loginname, password, salt, firstname," char *sql = "SELECT Id, loginname, password, salt, firstname,"
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs, codepage, exteditor, bwavestyle, signature, autosig FROM users WHERE loginname LIKE ?"; "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs, codepage, exteditor, bwavestyle, signature, autosig FROM users WHERE loginname LIKE ?";
char *pass_hash; char *pass_hash;
sprintf(buffer, "%s/users.sq3", conf.bbs_path); sprintf(buffer, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, loginname, -1, 0); sqlite3_bind_text(res, 1, loginname, -1, 0);
} else { } else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return NULL; return NULL;
} }
int step = sqlite3_step(res); int step = sqlite3_step(res);
if (step == SQLITE_ROW) { if (step == SQLITE_ROW) {
user = (struct user_record *)malloc(sizeof(struct user_record)); user = (struct user_record *)malloc(sizeof(struct user_record));
user->id = sqlite3_column_int(res, 0); user->id = sqlite3_column_int(res, 0);
user->loginname = strdup((char *)sqlite3_column_text(res, 1)); user->loginname = strdup((char *)sqlite3_column_text(res, 1));
@ -530,24 +520,24 @@ struct user_record *check_user_pass(char *loginname, char *password) {
free(user->signature); free(user->signature);
free(user); free(user);
free(pass_hash); free(pass_hash);
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return NULL; return NULL;
} }
free(pass_hash); free(pass_hash);
} else { } else {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return NULL; return NULL;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t)); user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
snprintf(buffer, 1024, "%s/s%d.ini", conf.config_path, user->sec_level); 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,16 +557,15 @@ struct user_record *check_user_pass(char *loginname, char *password) {
user->cur_file_sub = 0; user->cur_file_sub = 0;
} }
return user;
return user;
} }
void list_users(struct user_record *user) { void list_users(struct user_record *user) {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
int i; int i;
char *sql = "SELECT loginname,location,times_on FROM users"; char *sql = "SELECT loginname,location,times_on FROM users";
@ -585,22 +574,22 @@ void list_users(struct user_record *user) {
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot prepare statement: %s", sqlite3_errmsg(db)); dolog("Cannot prepare statement: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
s_printf(get_string(161)); s_printf(get_string(161));
s_printf(get_string(162)); s_printf(get_string(162));
s_printf(get_string(163)); s_printf(get_string(163));
i = 0; i = 0;
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
s_printf(get_string(164), sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2)); s_printf(get_string(164), sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2));
i++; i++;
@ -610,91 +599,91 @@ void list_users(struct user_record *user) {
i = 0; i = 0;
} }
} }
s_printf(get_string(165)); s_printf(get_string(165));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_printf(get_string(6)); s_printf(get_string(6));
s_getc(); s_getc();
} }
int check_fullname(char *firstname, char *lastname) { int check_fullname(char *firstname, char *lastname) {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *sql = "SELECT * FROM users WHERE firstname = ? AND lastname = ?"; char *sql = "SELECT * FROM users WHERE firstname = ? AND lastname = ?";
sprintf(buffer, "%s/users.sq3", conf.bbs_path); sprintf(buffer, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, firstname, -1, 0); sqlite3_bind_text(res, 1, firstname, -1, 0);
sqlite3_bind_text(res, 2, lastname, -1, 0); sqlite3_bind_text(res, 2, lastname, -1, 0);
} else { } else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
} }
int step = sqlite3_step(res); int step = sqlite3_step(res);
if (step == SQLITE_ROW) { if (step == SQLITE_ROW) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
} }
int check_user(char *loginname) { int check_user(char *loginname) {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *sql = "SELECT * FROM users WHERE loginname = ?"; char *sql = "SELECT * FROM users WHERE loginname = ?";
sprintf(buffer, "%s/users.sq3", conf.bbs_path); sprintf(buffer, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, loginname, -1, 0); sqlite3_bind_text(res, 1, loginname, -1, 0);
} else { } else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
} }
int step = sqlite3_step(res); int step = sqlite3_step(res);
if (step == SQLITE_ROW) { if (step == SQLITE_ROW) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
} }
struct user_record *new_user() { struct user_record *new_user() {
@ -706,7 +695,7 @@ struct user_record *new_user() {
int passok = 0; int passok = 0;
int i; int i;
int fullnameok = 0; int fullnameok = 0;
user = (struct user_record *)malloc(sizeof(struct user_record)); user = (struct user_record *)malloc(sizeof(struct user_record));
s_printf("\r\n\r\n"); s_printf("\r\n\r\n");
s_displayansi("newuser"); s_displayansi("newuser");
@ -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;
@ -756,7 +745,7 @@ struct user_record *new_user() {
if (strcasecmp(buffer, "ftp") == 0) { if (strcasecmp(buffer, "ftp") == 0) {
s_printf(get_string(169)); s_printf(get_string(169));
continue; continue;
} }
user->loginname = strdup(buffer); user->loginname = strdup(buffer);
nameok = check_user(user->loginname); nameok = check_user(user->loginname);
if (!nameok) { if (!nameok) {
@ -782,14 +771,14 @@ struct user_record *new_user() {
if (strchr(buffer, ' ') != NULL) { if (strchr(buffer, ' ') != NULL) {
s_printf(get_string(244)); s_printf(get_string(244));
continue; continue;
} }
s_printf("\r\n"); s_printf("\r\n");
user->firstname = strdup(buffer); user->firstname = strdup(buffer);
nameok = 1; nameok = 1;
} while (!nameok); } while (!nameok);
nameok = 0; nameok = 0;
do { do {
s_printf(get_string(172)); s_printf(get_string(172));
memset(buffer, 0, 256); memset(buffer, 0, 256);
s_readstring(buffer, 32); s_readstring(buffer, 32);
@ -870,7 +859,7 @@ struct user_record *new_user() {
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t)); 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);
} }

425
src/www.c

File diff suppressed because it is too large Load Diff

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() {
@ -14,20 +13,20 @@ char *www_blog() {
int len; int len;
char buffer[4096]; char buffer[4096];
struct blog_entry_t **blog_entries; struct blog_entry_t **blog_entries;
int blog_entry_count = 0; int blog_entry_count = 0;
int i, j; int i, j;
struct tm thetime; struct tm thetime;
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;
len = 0; len = 0;
memset(page, 0, 4096); memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>System Blog</h2></div>\n"); sprintf(buffer, "<div class=\"content-header\"><h2>System Blog</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -36,85 +35,85 @@ char *www_blog() {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
blog_entry_count = blog_load(&blog_entries); blog_entry_count = blog_load(&blog_entries);
if (blog_entry_count == 0) { if (blog_entry_count == 0) {
sprintf(buffer, "<p>No Entries</p>\n"); sprintf(buffer, "<p>No Entries</p>\n");
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);
} 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);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "<div class=\"blog-entry\"><p>"); sprintf(buffer, "<div class=\"blog-entry\"><p>");
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);
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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} else { } else {
if (len + 1 > max_len - 1) { if (len + 1 > max_len - 1) {
max_len += 4096; max_len += 4096;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
page[len++] = ' '; page[len++] = ' ';
page[len] = '\0'; page[len] = '\0';
} }
} else { } else {
if (len + 1 > max_len - 1) { if (len + 1 > max_len - 1) {
max_len += 4096; max_len += 4096;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
page[len++] = blog_entries[i]->body[j]; page[len++] = blog_entries[i]->body[j];
page[len] = '\0'; page[len] = '\0';
} }
} }
sprintf(buffer, "</p></div>"); sprintf(buffer, "</p></div>");
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);
} }
for (i = 0; i < blog_entry_count; i++) {
free(blog_entries[i]->subject);
free(blog_entries[i]->author);
free(blog_entries[i]->body);
free(blog_entries[i]);
}
free(blog_entries);
}
for (i=0;i<blog_entry_count;i++) {
free(blog_entries[i]->subject);
free(blog_entries[i]->author);
free(blog_entries[i]->body);
free(blog_entries[i]);
}
free(blog_entries);
}
return page; return page;
} }

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) {
@ -15,17 +14,17 @@ int www_email_delete(struct user_record *user, int id) {
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *csql = "CREATE TABLE IF NOT EXISTS email (" char *csql = "CREATE TABLE IF NOT EXISTS email ("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"sender TEXT COLLATE NOCASE," "sender TEXT COLLATE NOCASE,"
"recipient TEXT COLLATE NOCASE," "recipient TEXT COLLATE NOCASE,"
"subject TEXT," "subject TEXT,"
"body TEXT," "body TEXT,"
"date INTEGER," "date INTEGER,"
"seen INTEGER);"; "seen INTEGER);";
char *dsql = "DELETE FROM email WHERE id=? AND recipient LIKE ?"; char *dsql = "DELETE FROM email WHERE id=? AND recipient LIKE ?";
char *err_msg = 0; char *err_msg = 0;
sprintf(buffer, "%s/email.sq3", conf.bbs_path); sprintf(buffer, "%s/email.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
@ -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);
@ -65,21 +64,21 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *csql = "CREATE TABLE IF NOT EXISTS email (" char *csql = "CREATE TABLE IF NOT EXISTS email ("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"sender TEXT COLLATE NOCASE," "sender TEXT COLLATE NOCASE,"
"recipient TEXT COLLATE NOCASE," "recipient TEXT COLLATE NOCASE,"
"subject TEXT," "subject TEXT,"
"body TEXT," "body TEXT,"
"date INTEGER," "date INTEGER,"
"seen INTEGER);"; "seen INTEGER);";
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
char *err_msg = 0; char *err_msg = 0;
char *body; char *body;
struct utsname name; struct utsname name;
int i; int i;
int pos; int pos;
if (recipient == NULL || subject == NULL || ibody == NULL) { if (recipient == NULL || subject == NULL || ibody == NULL) {
return 0; return 0;
} }
@ -87,25 +86,23 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
if (check_user(recipient)) { if (check_user(recipient)) {
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);
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++;
} }
} }
strcat(body, buffer); strcat(body, buffer);
sprintf(buffer, "%s/email.sq3", conf.bbs_path); sprintf(buffer, "%s/email.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
@ -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;
@ -151,7 +146,7 @@ char *www_new_email() {
int max_len; int max_len;
int len; int len;
char buffer[4096]; char buffer[4096];
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
len = 0; len = 0;
@ -169,7 +164,7 @@ char *www_new_email() {
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);
@ -177,7 +172,7 @@ char *www_new_email() {
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);
@ -185,7 +180,7 @@ char *www_new_email() {
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);
@ -193,7 +188,7 @@ char *www_new_email() {
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);
@ -201,20 +196,19 @@ char *www_new_email() {
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);
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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
return page; return page;
} }
char *www_email_display(struct user_record *user, int email) { char *www_email_display(struct user_record *user, int email) {
@ -235,17 +229,17 @@ char *www_email_display(struct user_record *user, int email) {
int chars; int chars;
char *err_msg = 0; char *err_msg = 0;
char *email_create_sql = "CREATE TABLE IF NOT EXISTS email (" char *email_create_sql = "CREATE TABLE IF NOT EXISTS email ("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"sender TEXT COLLATE NOCASE," "sender TEXT COLLATE NOCASE,"
"recipient TEXT COLLATE NOCASE," "recipient TEXT COLLATE NOCASE,"
"subject TEXT," "subject TEXT,"
"body TEXT," "body TEXT,"
"date INTEGER," "date INTEGER,"
"seen INTEGER);"; "seen INTEGER);";
char *email_show_sql = "SELECT id,sender,subject,body,date FROM email WHERE recipient LIKE ? LIMIT ?, 1"; char *email_show_sql = "SELECT id,sender,subject,body,date FROM email WHERE recipient LIKE ? LIMIT ?, 1";
char *update_seen_sql = "UPDATE email SET seen=1 WHERE id=?"; char *update_seen_sql = "UPDATE email SET seen=1 WHERE id=?";
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
len = 0; len = 0;
@ -257,11 +251,11 @@ char *www_email_display(struct user_record *user, int email) {
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite3_close(db); sqlite3_close(db);
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);
@ -277,16 +271,16 @@ char *www_email_display(struct user_record *user, int email) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
free(page); free(page);
return NULL; return NULL;
} }
if (sqlite3_step(res) == SQLITE_ROW) { if (sqlite3_step(res) == SQLITE_ROW) {
id = sqlite3_column_int(res, 0); id = sqlite3_column_int(res, 0);
from = strdup((char *)sqlite3_column_text(res, 1)); from = strdup((char *)sqlite3_column_text(res, 1));
subject = strdup((char *)sqlite3_column_text(res, 2)); subject = strdup((char *)sqlite3_column_text(res, 2));
body = strdup((char *)sqlite3_column_text(res, 3)); body = strdup((char *)sqlite3_column_text(res, 3));
date = (time_t)sqlite3_column_int(res, 4); date = (time_t)sqlite3_column_int(res, 4);
localtime_r(&date, &msg_date); localtime_r(&date, &msg_date);
sprintf(buffer, "<div class=\"content-header\"><h2>Your Email</h2></div>\n"); sprintf(buffer, "<div class=\"content-header\"><h2>Your Email</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -299,26 +293,26 @@ char *www_email_display(struct user_record *user, int email) {
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);
sprintf(buffer, "<div class=\"email-view-subject\">%s</div>\n", subject); sprintf(buffer, "<div class=\"email-view-subject\">%s</div>\n", subject);
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);
sprintf(buffer, "<div class=\"email-view-from\">From: %s</div>\n", from); sprintf(buffer, "<div class=\"email-view-from\">From: %s</div>\n", from);
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);
if (conf.date_style == 1) { if (conf.date_style == 1) {
sprintf(buffer, "<div class=\"email-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); sprintf(buffer, "<div class=\"email-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
} else { } else {
@ -327,26 +321,26 @@ char *www_email_display(struct user_record *user, int email) {
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);
sprintf(buffer, "</div>\n"); sprintf(buffer, "</div>\n");
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);
sprintf(buffer, "<div id=\"msgbody\">\n"); sprintf(buffer, "<div id=\"msgbody\">\n");
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);
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] == '<') {
@ -359,7 +353,7 @@ char *www_email_display(struct user_record *user, int email) {
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);
} }
@ -367,7 +361,7 @@ char *www_email_display(struct user_record *user, int email) {
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);
@ -375,7 +369,7 @@ char *www_email_display(struct user_record *user, int email) {
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);
sprintf(buffer, "<h3>Reply</h3>\n"); sprintf(buffer, "<h3>Reply</h3>\n");
@ -385,12 +379,12 @@ 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 action=\"%semail/\" method=\"POST\" enctype=\"application/x-www-form-urlencoded\">\n", conf.www_url); sprintf(buffer, "<form action=\"%semail/\" method=\"POST\" enctype=\"application/x-www-form-urlencoded\">\n", conf.www_url);
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);
@ -398,7 +392,7 @@ char *www_email_display(struct user_record *user, int email) {
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);
@ -410,7 +404,7 @@ char *www_email_display(struct user_record *user, int email) {
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);
@ -418,7 +412,7 @@ char *www_email_display(struct user_record *user, int email) {
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);
@ -426,7 +420,7 @@ char *www_email_display(struct user_record *user, int email) {
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);
@ -434,13 +428,13 @@ char *www_email_display(struct user_record *user, int email) {
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);
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,21 +443,21 @@ 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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} }
sprintf(buffer, "</textarea>\n<br />"); sprintf(buffer, "</textarea>\n<br />");
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);
@ -471,16 +465,15 @@ char *www_email_display(struct user_record *user, int email) {
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);
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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
@ -488,16 +481,16 @@ char *www_email_display(struct user_record *user, int email) {
if (len + strlen(buffer) > max_len - 1) { 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);
free(from); free(from);
free(body); free(body);
free(subject); free(subject);
sqlite3_finalize(res); sqlite3_finalize(res);
rc = sqlite3_prepare_v2(db, update_seen_sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, update_seen_sql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
@ -506,9 +499,9 @@ char *www_email_display(struct user_record *user, int email) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
free(page); free(page);
return NULL; return NULL;
} }
sqlite3_step(res); sqlite3_step(res);
} else { } else {
sprintf(buffer, "<div class=\"content-header\"><h2>No Such Email</h2></div>\n"); sprintf(buffer, "<div class=\"content-header\"><h2>No Such Email</h2></div>\n");
@ -516,8 +509,8 @@ char *www_email_display(struct user_record *user, int email) {
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);
} }
sqlite3_finalize(res); sqlite3_finalize(res);
@ -544,15 +537,14 @@ char *www_email_summary(struct user_record *user) {
int msgid = 0; int msgid = 0;
char *err_msg = 0; char *err_msg = 0;
char *email_create_sql = "CREATE TABLE IF NOT EXISTS email (" char *email_create_sql = "CREATE TABLE IF NOT EXISTS email ("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"sender TEXT COLLATE NOCASE," "sender TEXT COLLATE NOCASE,"
"recipient TEXT COLLATE NOCASE," "recipient TEXT COLLATE NOCASE,"
"subject TEXT," "subject TEXT,"
"body TEXT," "body TEXT,"
"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;
@ -565,7 +557,7 @@ char *www_email_summary(struct user_record *user) {
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "<div class=\"button\"><a href=\"%semail/new\">New Email</a></div>\n", conf.www_url); sprintf(buffer, "<div class=\"button\"><a href=\"%semail/new\">New Email</a></div>\n", conf.www_url);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -573,18 +565,18 @@ char *www_email_summary(struct user_record *user) {
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
sprintf(buffer, "%s/email.sq3", conf.bbs_path); sprintf(buffer, "%s/email.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite3_close(db); sqlite3_close(db);
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);
@ -599,9 +591,9 @@ sqlite3_busy_timeout(db, 5000);
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
free(page); free(page);
return NULL; return NULL;
} }
sprintf(buffer, "<div class=\"div-table\">\n"); sprintf(buffer, "<div class=\"div-table\">\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -609,7 +601,7 @@ sqlite3_busy_timeout(db, 5000);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
id = sqlite3_column_int(res, 0); id = sqlite3_column_int(res, 0);
from = strdup((char *)sqlite3_column_text(res, 1)); from = strdup((char *)sqlite3_column_text(res, 1));
@ -642,11 +634,10 @@ 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);
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return page; return page;

View File

@ -7,349 +7,348 @@
#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);
int i; int i;
int j = 0; int j = 0;
unsigned char c; unsigned char c;
if (clean_url == NULL) { if (clean_url == NULL) {
free(url); free(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';
} }
} }
return url; return url;
} }
static char *www_encode(char *url) { static char *www_encode(char *url) {
char *clean_url = (char *)malloc(strlen(url) * 3 + 1); char *clean_url = (char *)malloc(strlen(url) * 3 + 1);
int i; int i;
int j; int j;
if (url == NULL) { if (url == NULL) {
free(clean_url); free(clean_url);
return NULL; return NULL;
} }
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;
} }
} }
return clean_url; return clean_url;
} }
void www_expire_old_links() { void www_expire_old_links() {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char sql[] = "delete from wwwhash where expiry <= ?"; char sql[] = "delete from wwwhash where expiry <= ?";
char *ret; char *ret;
time_t now = time(NULL); time_t now = time(NULL);
snprintf(buffer, PATH_MAX, "%s/www_file_hashes.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/www_file_hashes.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db)); dolog("Cannot open database: %s", sqlite3_errmsg(db));
return;
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_close(db);
return; return;
} }
sqlite3_bind_int(res, 1, now); sqlite3_busy_timeout(db, 5000);
sqlite3_step(res); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
sqlite3_finalize(res); if (rc != SQLITE_OK) {
sqlite3_close(db); sqlite3_close(db);
return;
}
sqlite3_bind_int(res, 1, now);
sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
} }
int www_check_hash_expired(char *hash) { int www_check_hash_expired(char *hash) {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
time_t now = time(NULL); time_t now = time(NULL);
char sql[] = "select id from wwwhash where hash = ? and expiry > ?"; char sql[] = "select id from wwwhash where hash = ? and expiry > ?";
snprintf(buffer, PATH_MAX, "%s/www_file_hashes.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/www_file_hashes.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
return 1; return 1;
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
sqlite3_bind_text(res, 1, hash, -1, 0); sqlite3_bind_text(res, 1, hash, -1, 0);
sqlite3_bind_int(res, 2, now); sqlite3_bind_int(res, 2, now);
if (sqlite3_step(res) == SQLITE_ROW) { if (sqlite3_step(res) == SQLITE_ROW) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 0; return 0;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;
} }
void www_add_hash_to_db(char *hash, time_t expiry) { void www_add_hash_to_db(char *hash, time_t expiry) {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char csql[] = "create table if not exists wwwhash (id INTEGER PRIMARY KEY, hash TEXT, expiry INTEGER)"; char csql[] = "create table if not exists wwwhash (id INTEGER PRIMARY KEY, hash TEXT, expiry INTEGER)";
char chsql[] = "select id from wwwhash where hash = ?"; char chsql[] = "select id from wwwhash where hash = ?";
char usql[] = "update wwwhash SET expiry = ? WHERE hash = ?"; char usql[] = "update wwwhash SET expiry = ? WHERE hash = ?";
char isql[] = "insert into wwwhash (hash, expiry) values(?, ?)"; char isql[] = "insert into wwwhash (hash, expiry) values(?, ?)";
char *ret;
char *err_msg = 0;
snprintf(buffer, PATH_MAX, "%s/www_file_hashes.sq3", conf.bbs_path); char *ret;
char *err_msg = 0;
snprintf(buffer, PATH_MAX, "%s/www_file_hashes.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
return;
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
return;
}
// first check if hash is in database
rc = sqlite3_prepare_v2(db, chsql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_close(db);
return; return;
} }
sqlite3_bind_text(res, 1, hash, -1, 0); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_step(res);
if (rc == SQLITE_ROW) {
// if so, update hash
sqlite3_finalize(res);
rc = sqlite3_prepare_v2(db, usql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_close(db);
return;
}
sqlite3_bind_int(res, 1, expiry);
sqlite3_bind_text(res, 2, hash, -1, 0);
sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
return; rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
} if (rc != SQLITE_OK) {
// if not add hash
sqlite3_finalize(res); dolog("SQL error: %s", err_msg);
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
if (rc != SQLITE_OK) { sqlite3_free(err_msg);
sqlite3_close(db); sqlite3_close(db);
return; return;
} }
sqlite3_bind_text(res, 1, hash, -1, 0);
sqlite3_bind_int(res, 2, expiry); // first check if hash is in database
sqlite3_step(res); rc = sqlite3_prepare_v2(db, chsql, -1, &res, 0);
sqlite3_finalize(res); if (rc != SQLITE_OK) {
sqlite3_close(db); sqlite3_close(db);
return;
}
sqlite3_bind_text(res, 1, hash, -1, 0);
rc = sqlite3_step(res);
if (rc == SQLITE_ROW) {
// if so, update hash
sqlite3_finalize(res);
rc = sqlite3_prepare_v2(db, usql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_close(db);
return;
}
sqlite3_bind_int(res, 1, expiry);
sqlite3_bind_text(res, 2, hash, -1, 0);
sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
return;
}
// if not add hash
sqlite3_finalize(res);
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_close(db);
return;
}
sqlite3_bind_text(res, 1, hash, -1, 0);
sqlite3_bind_int(res, 2, expiry);
sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(db);
} }
char *www_decode_hash(char *hash) { char *www_decode_hash(char *hash) {
unsigned long long numbers[4]; unsigned long long numbers[4];
int dir, sub, fid, uid; int dir, sub, fid, uid;
hashids_t *hashids = hashids_init(conf.bbs_name); hashids_t *hashids = hashids_init(conf.bbs_name);
char buffer[PATH_MAX]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char sql[] = "select filename from files where approved = 1 and id = ?"; char sql[] = "select filename from files where approved = 1 and id = ?";
char *ret; char *ret;
if (www_check_hash_expired(hash)) { if (www_check_hash_expired(hash)) {
return NULL; return NULL;
} }
if (hashids_decode(hashids, hash, numbers) != 4) { if (hashids_decode(hashids, hash, numbers) != 4) {
hashids_free(hashids); hashids_free(hashids);
return NULL; return NULL;
} }
hashids_free(hashids); hashids_free(hashids);
uid = (int)numbers[0]; uid = (int)numbers[0];
dir = (int)numbers[1]; dir = (int)numbers[1];
sub = (int)numbers[2]; sub = (int)numbers[2];
fid = (int)numbers[3]; fid = (int)numbers[3];
if (dir >= conf.file_directory_count || sub >= conf.file_directories[dir]->file_sub_count) { if (dir >= conf.file_directory_count || sub >= conf.file_directories[dir]->file_sub_count) {
return NULL; return NULL;
} }
// get filename from database // get filename from database
snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
return NULL;
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_close(db);
return NULL; return NULL;
} }
sqlite3_bind_int(res, 1, fid); sqlite3_busy_timeout(db, 5000);
if (sqlite3_step(res) == SQLITE_ROW) { rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
ret = strdup(sqlite3_column_text(res, 0)); if (rc != SQLITE_OK) {
sqlite3_finalize(res); sqlite3_close(db);
sqlite3_close(db); return NULL;
}
sqlite3_bind_int(res, 1, fid);
if (sqlite3_step(res) == SQLITE_ROW) {
ret = strdup(sqlite3_column_text(res, 0));
sqlite3_finalize(res);
sqlite3_close(db);
return ret; return ret;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return NULL; return NULL;
} }
char *www_create_link(int dir, int sub, int fid) { char *www_create_link(int dir, int sub, int fid) {
char url[PATH_MAX]; char url[PATH_MAX];
char *ret; char *ret;
char *hashid; char *hashid;
int sizereq; int sizereq;
time_t expiry; time_t expiry;
hashids_t *hashids = hashids_init(conf.bbs_name); hashids_t *hashids = hashids_init(conf.bbs_name);
sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid); sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid);
hashid = (char *)malloc(sizereq + 1); hashid = (char *)malloc(sizereq + 1);
memset(hashid, 0, sizereq + 1); memset(hashid, 0, sizereq + 1);
if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) { if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) {
hashids_free(hashids); hashids_free(hashids);
free(hashid); free(hashid);
return NULL; return NULL;
} }
hashids_free(hashids); hashids_free(hashids);
snprintf(url, PATH_MAX, "%sfiles/%s", conf.www_url, hashid); snprintf(url, PATH_MAX, "%sfiles/%s", conf.www_url, hashid);
// add link into hash database // add link into hash database
expiry = time(NULL) + 86400; expiry = time(NULL) + 86400;
www_add_hash_to_db(hashid, expiry); www_add_hash_to_db(hashid, expiry);
free(hashid); free(hashid);
ret = strdup(url); ret = strdup(url);
return ret; return ret;
} }
char *www_files_display_listing(int dir, int sub) { char *www_files_display_listing(int dir, int sub) {
char *page; char *page;
int max_len; int max_len;
int len; int len;
char buffer[4096]; char buffer[4096];
char *sql = "select id, filename, description, size, dlcount, uploaddate from files where approved=1 ORDER BY filename"; char *sql = "select id, filename, description, size, dlcount, uploaddate from files where approved=1 ORDER BY filename";
char *filename; char *filename;
char c; char c;
int size; int size;
char *aha_out; char *aha_out;
char *description; char *description;
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
int i; int i;
char *clean_url; char *clean_url;
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
len = 0; len = 0;
memset(page, 0, 4096); memset(page, 0, 4096);
snprintf(buffer, 4096, "<div class=\"content-header\"><h2>Files: %s - %s</h2></div>\n", conf.file_directories[dir]->name, conf.file_directories[dir]->file_subs[sub]->name); snprintf(buffer, 4096, "<div class=\"content-header\"><h2>Files: %s - %s</h2></div>\n", conf.file_directories[dir]->name, conf.file_directories[dir]->file_subs[sub]->name);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; 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);
snprintf(buffer, 4096, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); snprintf(buffer, 4096, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
free(page); free(page);
return NULL;
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_close(db);
free(page);
return NULL; return NULL;
} }
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_close(db);
free(page);
return NULL;
}
snprintf(buffer, 4096, "<table class=\"fileentry\"><thead><tr><td>Filename</td><td>Size</td><td>Description</td></tr></thead><tbody>\n"); snprintf(buffer, 4096, "<table class=\"fileentry\"><thead><tr><td>Filename</td><td>Size</td><td>Description</td></tr></thead><tbody>\n");
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);
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
filename = strdup(sqlite3_column_text(res, 1)); filename = strdup(sqlite3_column_text(res, 1));
clean_url = www_encode(basename(filename)); clean_url = www_encode(basename(filename));
snprintf(buffer, 4096, "<tr><td class=\"filename\"><a href=\"%sfiles/areas/%d/%d/%s\">%s</a></td>", conf.www_url, dir, sub, basename(clean_url), basename(filename)); snprintf(buffer, 4096, "<tr><td class=\"filename\"><a href=\"%sfiles/areas/%d/%d/%s\">%s</a></td>", conf.www_url, dir, sub, basename(clean_url), basename(filename));
free(clean_url); free(clean_url);
free(filename); free(filename);
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);
size = sqlite3_column_int(res, 3); size = sqlite3_column_int(res, 3);
if (size > 1024 * 1024 * 1024) { if (size > 1024 * 1024 * 1024) {
size = size / 1024 / 1024 / 1024; size = size / 1024 / 1024 / 1024;
c = 'G'; c = 'G';
} else if (size > 1024 * 1024) { } else if (size > 1024 * 1024) {
@ -362,190 +361,188 @@ char *www_files_display_listing(int dir, int sub) {
c = 'b'; c = 'b';
} }
snprintf(buffer, 4096, "<td class=\"filesize\">%d%c</td>", size, c); snprintf(buffer, 4096, "<td class=\"filesize\">%d%c</td>", size, c);
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);
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';
} }
} }
snprintf(buffer, 4096, "<td class=\"filedesc\">"); snprintf(buffer, 4096, "<td class=\"filedesc\">");
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);
aha_out = aha(description); aha_out = aha(description);
while (len + strlen(aha_out) > max_len - 1) { while (len + strlen(aha_out) > max_len - 1) {
max_len += 4096; max_len += 4096;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, aha_out); strcat(page, aha_out);
len += strlen(aha_out); len += strlen(aha_out);
free(aha_out); free(aha_out);
free(description); free(description);
snprintf(buffer, 4096, "</td></tr>\n"); snprintf(buffer, 4096, "</td></tr>\n");
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);
} }
snprintf(buffer, 4096, "</tbody></table>\n"); snprintf(buffer, 4096, "</tbody></table>\n");
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);
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return page; return page;
} }
char *www_files_areas() { char *www_files_areas() {
char *page; char *page;
int max_len; int max_len;
int len; int len;
char buffer[4096]; char buffer[4096];
int i; int i;
int j; int j;
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
len = 0; len = 0;
memset(page, 0, 4096); memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>File Directories</h2></div>\n"); sprintf(buffer, "<div class=\"content-header\"><h2>File Directories</h2></div>\n");
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);
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) {
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);
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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} }
} }
} }
return page; return page;
} }
char *www_files_get_from_area(int dir, int sub, char *clean_file) { char *www_files_get_from_area(int dir, int sub, char *clean_file) {
char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\""; char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\"";
char *filenamelike; char *filenamelike;
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char *ret = NULL; char *ret = NULL;
int i; int i;
int extra = 0; int extra = 0;
int j; int j;
char *file; char *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++;
} }
} }
filenamelike = (char *)malloc(strlen(file) + 3 + extra); filenamelike = (char *)malloc(strlen(file) + 3 + extra);
i = 0; i = 0;
filenamelike[i++] = '%'; filenamelike[i++] = '%';
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++] = '^';
filenamelike[i] = '\0'; filenamelike[i] = '\0';
break; break;
case '_': case '_':
filenamelike[i++] = '^'; filenamelike[i++] = '^';
filenamelike[i++] = '_'; filenamelike[i++] = '_';
filenamelike[i] = '\0'; filenamelike[i] = '\0';
break; break;
case '%': case '%':
filenamelike[i++] = '^'; filenamelike[i++] = '^';
filenamelike[i++] = '%'; filenamelike[i++] = '%';
filenamelike[i] = '\0'; filenamelike[i] = '\0';
break; break;
default: default:
filenamelike[i++] = file[j]; filenamelike[i++] = file[j];
filenamelike[i] = '\0'; filenamelike[i] = '\0';
break; break;
} }
} }
// sprintf(filenamelike, "%%/%s", file); // sprintf(filenamelike, "%%/%s", file);
free(file); free(file);
snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
return NULL; return NULL;
} }
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite3_close(db); sqlite3_close(db);
return NULL; return NULL;
} }
sqlite3_bind_text(res, 1, filenamelike, -1, 0); sqlite3_bind_text(res, 1, filenamelike, -1, 0);
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);
sqlite3_finalize(res);
free(filenamelike); sqlite3_close(db);
sqlite3_finalize(res); return ret;
sqlite3_close(db);
return ret;
} }
#endif #endif

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;
} }
@ -36,7 +35,7 @@ char *www_last10() {
max_len = 4096; max_len = 4096;
len = 0; len = 0;
memset(page, 0, 4096); memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>Last 10 Callers</h2></div>\n"); sprintf(buffer, "<div class=\"content-header\"><h2>Last 10 Callers</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -52,8 +51,8 @@ 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) {
@ -75,7 +74,7 @@ char *www_last10() {
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} }
sprintf(buffer, "</div>\n"); sprintf(buffer, "</div>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -83,7 +82,7 @@ char *www_last10() {
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
return page; return page;
} }

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,8 +33,8 @@ 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';
result[len++] = 't'; result[len++] = 't';
@ -44,7 +43,7 @@ char *www_sanitize(char *inp) {
result[len++] = '&'; result[len++] = '&';
result[len++] = 'g'; result[len++] = 'g';
result[len++] = 't'; result[len++] = 't';
result[len++] = ';'; result[len++] = ';';
} else if (inp[i] == '&') { } else if (inp[i] == '&') {
result[len++] = '&'; result[len++] = '&';
result[len++] = 'a'; result[len++] = 'a';
@ -65,7 +64,7 @@ char *www_msgs_arealist(struct user_record *user) {
int len; int len;
char buffer[4096]; char buffer[4096];
int i, j; int i, j;
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
len = 0; len = 0;
@ -78,8 +77,8 @@ 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,9 +88,9 @@ 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) {
sprintf(buffer, "<div class=\"area-list-new\"><a href=\"%smsgs/%d/%d/\">%s</a></div>\n", conf.www_url, i, j, conf.mail_conferences[i]->mail_areas[j]->name); sprintf(buffer, "<div class=\"area-list-new\"><a href=\"%smsgs/%d/%d/\">%s</a></div>\n", conf.www_url, i, j, conf.mail_conferences[i]->mail_areas[j]->name);
} else { } else {
@ -134,7 +133,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
max_len = 4096; max_len = 4096;
len = 0; len = 0;
memset(page, 0, 4096); memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>%s - %s</h2></div>\n", conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name); sprintf(buffer, "<div class=\"content-header\"><h2>%s - %s</h2></div>\n", conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -142,7 +141,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) {
sprintf(buffer, "<div class=\"button\"><a href=\"%smsgs/new/%d/%d\">New Message</a></div>\n", conf.www_url, conference, area); sprintf(buffer, "<div class=\"button\"><a href=\"%smsgs/new/%d/%d\">New Message</a></div>\n", conf.www_url, conference, area);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
@ -150,10 +149,10 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} }
mhrs = read_message_headers(conference, area, user, 0); mhrs = read_message_headers(conference, area, user, 0);
if (mhrs == NULL) { if (mhrs == NULL) {
sprintf(buffer, "<h3>No Messages</h3>\n"); sprintf(buffer, "<h3>No Messages</h3>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
@ -164,14 +163,14 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
len += strlen(buffer); len += strlen(buffer);
return page; return page;
} }
sprintf(buffer, "<div class=\"div-table\">\n"); sprintf(buffer, "<div class=\"div-table\">\n");
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);
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) {
@ -190,8 +189,8 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
if (skip_t < 0) { if (skip_t < 0) {
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);
@ -226,7 +225,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} }
sprintf(buffer, "</div>\n"); sprintf(buffer, "</div>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
@ -234,7 +233,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
if (skip + 50 <= mhrs->msg_count) { if (skip + 50 <= mhrs->msg_count) {
sprintf(buffer, "<div class=\"msg-summary-next\"><a href=\"%smsgs/%d/%d/?skip=%d\">Next</a></div>\n", conf.www_url, conference, area, skip + 50); sprintf(buffer, "<div class=\"msg-summary-next\"><a href=\"%smsgs/%d/%d/?skip=%d\">Next</a></div>\n", conf.www_url, conference, area, skip + 50);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
@ -256,21 +255,21 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} }
free_message_headers(mhrs); free_message_headers(mhrs);
return page; return page;
} }
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;
char *subject = NULL; char *subject = NULL;
char *from = NULL; char *from = NULL;
char *to = NULL; char *to = NULL;
@ -287,7 +286,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
char *page; char *page;
int max_len; int max_len;
int len; int len;
char buffer[4096]; char buffer[4096];
int chars; int chars;
int i; int i;
char *from_s; char *from_s;
@ -302,15 +301,15 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) {
return NULL; return NULL;
} }
if (conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level) { if (conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level) {
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
if (!jb) { if (!jb) {
return NULL; return NULL;
} }
JAM_ReadMBHeader(jb, &jbh); JAM_ReadMBHeader(jb, &jbh);
memset(&jmh, 0, sizeof(s_JamMsgHeader)); memset(&jmh, 0, sizeof(s_JamMsgHeader));
z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp); z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp);
if (z != 0) { if (z != 0) {
@ -323,9 +322,9 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb); free(jb);
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);
@ -362,8 +361,8 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
memcpy(replyid, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); memcpy(replyid, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} }
} }
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
if (subject == NULL) { if (subject == NULL) {
subject = strdup("(No Subject)"); subject = strdup("(No Subject)");
} }
@ -375,12 +374,12 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
if (to == NULL) { if (to == NULL) {
to = strdup("(No Recipient)"); to = strdup("(No Recipient)");
} }
if (jmh.Attribute & JAM_MSG_PRIVATE) { if (jmh.Attribute & JAM_MSG_PRIVATE) {
if (!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && if (!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) &&
!msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) &&
!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) && !msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) &&
!msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) { !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) {
if (subject != NULL) { if (subject != NULL) {
free(subject); free(subject);
@ -411,7 +410,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
body = (char *)malloc(jmh.TxtLen + 1); 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));
@ -422,17 +421,17 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
jlr.LastReadMsg = msg; jlr.LastReadMsg = msg;
if (jlr.HighReadMsg < msg) { if (jlr.HighReadMsg < msg) {
jlr.HighReadMsg = msg; jlr.HighReadMsg = msg;
} }
JAM_WriteLastRead(jb, user->id, &jlr); JAM_WriteLastRead(jb, user->id, &jlr);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb); free(jb);
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
len = 0; len = 0;
memset(page, 0, 4096); memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><a href=\"%smsgs/%d/%d\"><h2>%s - %s</h2></a></div>\n", conf.www_url, conference, area, conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name); sprintf(buffer, "<div class=\"content-header\"><a href=\"%smsgs/%d/%d\"><h2>%s - %s</h2></a></div>\n", conf.www_url, conference, area, conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name);
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -440,7 +439,7 @@ 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);
if (msgbase_is_flagged(user, conference, area, msg)) { if (msgbase_is_flagged(user, conference, area, msg)) {
sprintf(buffer, "<div class=\"msg-view-header-flagged\">\n"); sprintf(buffer, "<div class=\"msg-view-header-flagged\">\n");
} else { } else {
@ -449,7 +448,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
if (len + strlen(buffer) > max_len - 1) { 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);
subject_s = www_sanitize(subject); subject_s = www_sanitize(subject);
@ -457,14 +456,14 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
if (len + strlen(buffer) > max_len - 1) { 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);
} }
free(subject_s); free(subject_s);
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
from_s = www_sanitize(from); from_s = www_sanitize(from);
if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) { if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) {
if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
sprintf(buffer, "<div class=\"msg-view-from\">From: %s (@%s)</div>\n", from_s, oaddress); sprintf(buffer, "<div class=\"msg-view-from\">From: %s (@%s)</div>\n", from_s, oaddress);
} else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { } else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
@ -492,7 +491,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
if (len + strlen(buffer) > max_len - 1) { 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);
to_s = www_sanitize(to); to_s = www_sanitize(to);
@ -500,11 +499,11 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
if (len + strlen(buffer) > max_len - 1) { 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);
} }
free(to_s); free(to_s);
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
date = (time_t)jmh.DateWritten; date = (time_t)jmh.DateWritten;
gmtime_r(&date, &msg_date); gmtime_r(&date, &msg_date);
if (conf.date_style == 1) { if (conf.date_style == 1) {
@ -512,11 +511,11 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
} else { } else {
sprintf(buffer, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); sprintf(buffer, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
if (len + strlen(buffer) > max_len - 1) { 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);
@ -524,26 +523,25 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
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);
sprintf(buffer, "</div>\n"); sprintf(buffer, "</div>\n");
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);
sprintf(buffer, "<div id=\"msgbody\">\n"); sprintf(buffer, "<div id=\"msgbody\">\n");
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);
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);
@ -552,28 +550,26 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
while (len + strlen(aha_out) > max_len - 1) { while (len + strlen(aha_out) > max_len - 1) {
max_len += 4096; max_len += 4096;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, aha_out); strcat(page, aha_out);
len += strlen(aha_out); len += strlen(aha_out);
free(aha_out); free(aha_out);
free(aha_text); free(aha_text);
sprintf(buffer, "</div>\n"); sprintf(buffer, "</div>\n");
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);
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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) {
@ -588,7 +584,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
if (len + strlen(buffer) > max_len - 1) { 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);
@ -596,22 +592,22 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
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);
sprintf(buffer, "<input type=\"hidden\" name=\"area\" value=\"%d\" />\n", area); sprintf(buffer, "<input type=\"hidden\" name=\"area\" value=\"%d\" />\n", area);
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);
sprintf(buffer, "<input type=\"hidden\" name=\"replyid\" value=\"%s\" />\n", msgid); sprintf(buffer, "<input type=\"hidden\" name=\"replyid\" value=\"%s\" />\n", msgid);
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);
@ -619,7 +615,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
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);
@ -631,7 +627,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
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);
@ -639,7 +635,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
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);
@ -647,20 +643,20 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
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);
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,39 +679,37 @@ 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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
} }
free(body2); free(body2);
sprintf(buffer, "</textarea>\n<br />"); sprintf(buffer, "</textarea>\n<br />");
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);
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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
@ -723,7 +717,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
if (len + strlen(buffer) > max_len - 1) { 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);
} }
@ -747,7 +741,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
} }
if (replyid != NULL) { if (replyid != NULL) {
free(replyid); free(replyid);
} }
return page; return page;
} else { } else {
return NULL; return NULL;
@ -765,10 +759,10 @@ 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;
} }
content[at++] = content[i]; content[at++] = content[i];
} }
@ -776,32 +770,33 @@ 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 {
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) {
content[at++] = '\r'; content[at++] = '\r';
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);
@ -823,11 +817,11 @@ static char *www_wordwrap(char *content, int cutoff) {
if (ret == NULL) { if (ret == NULL) {
return NULL; return NULL;
} }
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] == ' ') {
@ -841,7 +835,7 @@ static char *www_wordwrap(char *content, int cutoff) {
ret[at++] = content[i]; ret[at++] = content[i];
} }
ret[at] = '\0'; ret[at] = '\0';
if (content[i] == '\r') { if (content[i] == '\r') {
line_count = 0; line_count = 0;
last_space = NULL; last_space = NULL;
@ -854,7 +848,7 @@ static char *www_wordwrap(char *content, int cutoff) {
} }
last_space = NULL; last_space = NULL;
line_count = 0; line_count = 0;
quote_line = 0; quote_line = 0;
} else if (last_space != NULL) { } else if (last_space != NULL) {
*last_space = '\r'; *last_space = '\r';
line_count = strlen(&last_space[1]); line_count = strlen(&last_space[1]);
@ -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;
@ -891,7 +885,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
char *page; char *page;
int max_len; int max_len;
int len; int len;
char buffer[256]; char buffer[256];
char *body2; char *body2;
char *tagline; char *tagline;
struct utsname name; struct utsname name;
@ -917,11 +911,11 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
if (!jb) { if (!jb) {
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;
if (conf.mail_conferences[conference]->realnames == 0) { if (conf.mail_conferences[conference]->realnames == 0) {
strcpy(buffer, user->loginname); strcpy(buffer, user->loginname);
} else { } else {
@ -929,60 +923,60 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
} }
jsp = JAM_NewSubPacket(); jsp = JAM_NewSubPacket();
jsf.LoID = JAMSFLD_SENDERNAME; jsf.LoID = JAMSFLD_SENDERNAME;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
jsf.LoID = JAMSFLD_RECVRNAME; jsf.LoID = JAMSFLD_RECVRNAME;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(to); jsf.DatLen = strlen(to);
jsf.Buffer = (char *)to; jsf.Buffer = (char *)to;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
jsf.LoID = JAMSFLD_SUBJECT; jsf.LoID = JAMSFLD_SUBJECT;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(subj); jsf.DatLen = strlen(subj);
jsf.Buffer = (char *)subj; jsf.Buffer = (char *)subj;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) { if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) {
jmh.Attribute |= JAM_MSG_TYPEECHO; jmh.Attribute |= JAM_MSG_TYPEECHO;
if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
if (conf.mail_conferences[conference]->fidoaddr->point) { if (conf.mail_conferences[conference]->fidoaddr->point) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[conference]->fidoaddr->zone, sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[conference]->fidoaddr->zone,
conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->net,
conf.mail_conferences[conference]->fidoaddr->node, conf.mail_conferences[conference]->fidoaddr->node,
conf.mail_conferences[conference]->fidoaddr->point); conf.mail_conferences[conference]->fidoaddr->point);
} else { } else {
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[conference]->fidoaddr->zone, sprintf(buffer, "%d:%d/%d", conf.mail_conferences[conference]->fidoaddr->zone,
conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->net,
conf.mail_conferences[conference]->fidoaddr->node); conf.mail_conferences[conference]->fidoaddr->node);
} }
jsf.LoID = JAMSFLD_OADDRESS; jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[conference]->fidoaddr->zone, sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[conference]->fidoaddr->zone,
conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->net,
conf.mail_conferences[conference]->fidoaddr->node, conf.mail_conferences[conference]->fidoaddr->node,
conf.mail_conferences[conference]->fidoaddr->point, conf.mail_conferences[conference]->fidoaddr->point,
generate_msgid()); generate_msgid());
jsf.LoID = JAMSFLD_MSGID; jsf.LoID = JAMSFLD_MSGID;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
if (strcasecmp(replyid, "NULL") != 0) { if (strcasecmp(replyid, "NULL") != 0) {
jsf.LoID = JAMSFLD_REPLYID; jsf.LoID = JAMSFLD_REPLYID;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(replyid); jsf.DatLen = strlen(replyid);
jsf.Buffer = (char *)replyid; jsf.Buffer = (char *)replyid;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
@ -990,8 +984,8 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
} }
} else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { } else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
sprintf(buffer, "%d", conf.mail_conferences[conference]->maginode); sprintf(buffer, "%d", conf.mail_conferences[conference]->maginode);
jsf.LoID = JAMSFLD_OADDRESS; jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
@ -999,16 +993,16 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
uuid_generate(magi_msgid); uuid_generate(magi_msgid);
uuid_unparse_lower(magi_msgid, buffer); uuid_unparse_lower(magi_msgid, buffer);
jsf.LoID = JAMSFLD_MSGID; jsf.LoID = JAMSFLD_MSGID;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(buffer); jsf.DatLen = strlen(buffer);
jsf.Buffer = (char *)buffer; jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
if (strcasecmp(replyid, "NULL") != 0) { if (strcasecmp(replyid, "NULL") != 0) {
jsf.LoID = JAMSFLD_REPLYID; jsf.LoID = JAMSFLD_REPLYID;
jsf.HiID = 0; jsf.HiID = 0;
jsf.DatLen = strlen(replyid); jsf.DatLen = strlen(replyid);
jsf.Buffer = (char *)replyid; jsf.Buffer = (char *)replyid;
JAM_PutSubfield(jsp, &jsf); JAM_PutSubfield(jsp, &jsf);
@ -1033,27 +1027,25 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
free(jb); free(jb);
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 {
tagline = conf.default_tagline; tagline = conf.default_tagline;
} }
uname(&name); uname(&name);
if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
if (conf.mail_conferences[conference]->fidoaddr->point == 0) { if (conf.mail_conferences[conference]->fidoaddr->point == 0) {
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone, snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone,
conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->net,
conf.mail_conferences[conference]->fidoaddr->node); conf.mail_conferences[conference]->fidoaddr->node);
} else { } else {
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone, snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone,
conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->net,
conf.mail_conferences[conference]->fidoaddr->node, conf.mail_conferences[conference]->fidoaddr->node,
conf.mail_conferences[conference]->fidoaddr->point); conf.mail_conferences[conference]->fidoaddr->point);
} }
} else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { } else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->maginode); snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->maginode);
@ -1068,7 +1060,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
free(jb); free(jb);
return 0; return 0;
} }
body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer)); body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer));
if (body3 == NULL) { if (body3 == NULL) {
free(body2); free(body2);
JAM_UnlockMB(jb); JAM_UnlockMB(jb);
@ -1077,7 +1069,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
free(jb); free(jb);
return 0; return 0;
} }
memset(body3, 0, strlen(body2) + 2 + strlen(buffer)); memset(body3, 0, strlen(body2) + 2 + strlen(buffer));
pos = 0; pos = 0;
@ -1087,7 +1078,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
body2 = (char *)malloc(strlen(body3) + 1); body2 = (char *)malloc(strlen(body3) + 1);
ic = iconv_open("CP437", "UTF-8"); ic = iconv_open("CP437", "UTF-8");
inc = strlen(body3); inc = strlen(body3);
ouc = strlen(body3); ouc = strlen(body3);
@ -1097,7 +1088,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
free(body3); free(body3);
if (JAM_AddMessage(jb, &jmh, jsp, (char *)body2, oubuf - body2)) { if (JAM_AddMessage(jb, &jmh, jsp, (char *)body2, oubuf - body2)) {
free(body2); free(body2);
JAM_UnlockMB(jb); JAM_UnlockMB(jb);
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
@ -1113,13 +1104,12 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
} }
} }
free(body2); free(body2);
JAM_UnlockMB(jb); JAM_UnlockMB(jb);
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb); free(jb);
iconv_close(ic); iconv_close(ic);
return 1; return 1;
@ -1132,12 +1122,12 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
int max_len; int max_len;
int len; int len;
char buffer[4096]; char buffer[4096];
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
len = 0; len = 0;
memset(page, 0, 4096); memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>New Message</h2></div>\n"); sprintf(buffer, "<div class=\"content-header\"><h2>New Message</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {
max_len += 4096; max_len += 4096;
@ -1150,7 +1140,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
if (len + strlen(buffer) > max_len - 1) { 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);
@ -1158,22 +1148,22 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
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);
sprintf(buffer, "<input type=\"hidden\" name=\"area\" value=\"%d\" />\n", area); sprintf(buffer, "<input type=\"hidden\" name=\"area\" value=\"%d\" />\n", area);
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);
sprintf(buffer, "<input type=\"hidden\" name=\"replyid\" value=\"NULL\" />\n"); sprintf(buffer, "<input type=\"hidden\" name=\"replyid\" value=\"NULL\" />\n");
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);
@ -1181,7 +1171,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
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);
@ -1189,7 +1179,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
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);
@ -1197,7 +1187,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
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);
@ -1205,20 +1195,19 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
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);
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;
page = (char *)realloc(page, max_len); page = (char *)realloc(page, max_len);
} }
strcat(page, buffer); strcat(page, buffer);
len += strlen(buffer); len += strlen(buffer);
return page; return page;
} }
#endif #endif