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:
parent
ff966a6b4d
commit
d6826137dd
288
src/bbs.c
288
src/bbs.c
@ -21,13 +21,11 @@
|
||||
#include "lua/lualib.h"
|
||||
#include "lua/lauxlib.h"
|
||||
|
||||
|
||||
int telnet_bin_mode = 0;
|
||||
|
||||
int mynode = 0;
|
||||
struct bbs_config conf;
|
||||
|
||||
|
||||
struct user_record *gUser;
|
||||
int gSocket;
|
||||
int sshBBS;
|
||||
@ -39,8 +37,7 @@ struct mosquitto *mosq = NULL;
|
||||
|
||||
char *ipaddress = NULL;
|
||||
|
||||
void sigterm_handler2(int s)
|
||||
{
|
||||
void sigterm_handler2(int s) {
|
||||
if (mynode != 0) {
|
||||
disconnect("Terminated.");
|
||||
}
|
||||
@ -48,12 +45,11 @@ void sigterm_handler2(int s)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void sigint_handler(int s)
|
||||
{
|
||||
void sigint_handler(int s) {
|
||||
// do nothing...
|
||||
}
|
||||
void broadcast(char *mess, ...) {
|
||||
char buffer[PATH_MAX];
|
||||
char buffer[PATH_MAX];
|
||||
if (conf.broadcast_enable && conf.broadcast_port != 0 && conf.broadcast_address != NULL) {
|
||||
va_list ap;
|
||||
va_start(ap, mess);
|
||||
@ -79,7 +75,7 @@ void dolog_www(char *ipaddr, char *fmt, ...) {
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday);
|
||||
logfptr = fopen(buffer, "a");
|
||||
if (!logfptr) {
|
||||
if (!logfptr) {
|
||||
return;
|
||||
}
|
||||
va_list ap;
|
||||
@ -107,7 +103,7 @@ void dolog(char *fmt, ...) {
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday);
|
||||
logfptr = fopen(buffer, "a");
|
||||
if (!logfptr) {
|
||||
if (!logfptr) {
|
||||
return;
|
||||
}
|
||||
va_list ap;
|
||||
@ -133,8 +129,8 @@ struct fido_addr *parse_fido_addr(const char *str) {
|
||||
ret->node = 0;
|
||||
ret->point = 0;
|
||||
|
||||
for (c=0;c<strlen(str);c++) {
|
||||
switch(str[c]) {
|
||||
for (c = 0; c < strlen(str); c++) {
|
||||
switch (str[c]) {
|
||||
case ':':
|
||||
state = 1;
|
||||
break;
|
||||
@ -153,24 +149,22 @@ struct fido_addr *parse_fido_addr(const char *str) {
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
{
|
||||
switch (state) {
|
||||
case 0:
|
||||
ret->zone = ret->zone * 10 + (str[c] - '0');
|
||||
break;
|
||||
case 1:
|
||||
ret->net = ret->net * 10 + (str[c] - '0');
|
||||
break;
|
||||
case 2:
|
||||
ret->node = ret->node * 10 + (str[c] - '0');
|
||||
break;
|
||||
case 3:
|
||||
ret->point = ret->point * 10 + (str[c] - '0');
|
||||
break;
|
||||
}
|
||||
case '9': {
|
||||
switch (state) {
|
||||
case 0:
|
||||
ret->zone = ret->zone * 10 + (str[c] - '0');
|
||||
break;
|
||||
case 1:
|
||||
ret->net = ret->net * 10 + (str[c] - '0');
|
||||
break;
|
||||
case 2:
|
||||
ret->node = ret->node * 10 + (str[c] - '0');
|
||||
break;
|
||||
case 3:
|
||||
ret->point = ret->point * 10 + (str[c] - '0');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
default:
|
||||
free(ret);
|
||||
return NULL;
|
||||
@ -179,7 +173,6 @@ struct fido_addr *parse_fido_addr(const char *str) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void timer_handler(int signum) {
|
||||
if (signum == SIGALRM) {
|
||||
if (gUser != NULL) {
|
||||
@ -189,8 +182,6 @@ void timer_handler(int signum) {
|
||||
s_printf(get_string(0));
|
||||
disconnect("Out of Time");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (timeoutpaused == 0) {
|
||||
usertimeout--;
|
||||
@ -212,9 +203,9 @@ void s_printf(char *fmt, ...) {
|
||||
vsnprintf(buffer, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] == '@' && fmt[1] == '@' && fmt[strlen(fmt)-1] == '@' && fmt[strlen(fmt)-2] == '@') {
|
||||
if (fmt[0] == '@' && fmt[1] == '@' && fmt[strlen(fmt) - 1] == '@' && fmt[strlen(fmt) - 2] == '@') {
|
||||
pos = 0;
|
||||
for (i=2;i<strlen(fmt) - 2;i++) {
|
||||
for (i = 2; i < strlen(fmt) - 2; i++) {
|
||||
buffer[pos++] = fmt[i];
|
||||
buffer[pos] = '\0';
|
||||
}
|
||||
@ -227,7 +218,7 @@ void s_printf(char *fmt, ...) {
|
||||
int should_convert_utf8() {
|
||||
if (gUser != NULL) {
|
||||
return gUser->codepage;
|
||||
}
|
||||
}
|
||||
return conf.codepage;
|
||||
}
|
||||
|
||||
@ -246,11 +237,11 @@ void s_putchar(char c) {
|
||||
if (sshBBS) {
|
||||
putchar(c);
|
||||
} else {
|
||||
ret = send(gSocket, &c, 1, 0);
|
||||
ret = send(gSocket, &c, 1, 0);
|
||||
if (ret == -1) {
|
||||
if (errno == ECONNRESET) {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -272,7 +263,7 @@ void s_putchar(char c) {
|
||||
if (errno == ECONNRESET) {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iconv_close(ic);
|
||||
free(ptr1);
|
||||
@ -281,7 +272,7 @@ void s_putchar(char c) {
|
||||
}
|
||||
|
||||
void s_putstring(char *c) {
|
||||
iconv_t ic;
|
||||
iconv_t ic;
|
||||
char *inbuf;
|
||||
char *outbuf;
|
||||
size_t inc;
|
||||
@ -298,7 +289,7 @@ void s_putstring(char *c) {
|
||||
if (ret == -1) {
|
||||
if (errno == ECONNRESET) {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -308,7 +299,7 @@ void s_putstring(char *c) {
|
||||
outbuf = (char *)malloc(inc * 4);
|
||||
memset(outbuf, 0, inc * 4);
|
||||
ptr1 = outbuf;
|
||||
ptr2 = inbuf;
|
||||
ptr2 = inbuf;
|
||||
ouc = inc * 4;
|
||||
sz = iconv(ic, &inbuf, &inc, &outbuf, &ouc);
|
||||
if (sshBBS) {
|
||||
@ -318,8 +309,8 @@ void s_putstring(char *c) {
|
||||
if (ret == -1) {
|
||||
if (errno == ECONNRESET) {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iconv_close(ic);
|
||||
free(ptr1);
|
||||
@ -365,7 +356,7 @@ void s_displayansi_pause(char *file, int pause) {
|
||||
s_putchar(c);
|
||||
|
||||
lastch = c;
|
||||
|
||||
|
||||
if (pause) {
|
||||
if (c == '\n') {
|
||||
lines++;
|
||||
@ -373,7 +364,7 @@ void s_displayansi_pause(char *file, int pause) {
|
||||
s_printf(get_string(223));
|
||||
ch = s_getchar();
|
||||
s_printf("\r\n");
|
||||
switch(tolower(ch)) {
|
||||
switch (tolower(ch)) {
|
||||
case 'c':
|
||||
pause = 0;
|
||||
break;
|
||||
@ -396,7 +387,6 @@ void s_displayansi_p(char *file) {
|
||||
s_displayansi_pause(file, 0);
|
||||
}
|
||||
|
||||
|
||||
void s_displayansi(char *file) {
|
||||
FILE *fptr;
|
||||
char c;
|
||||
@ -411,7 +401,6 @@ void s_displayansi(char *file) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char s_getchar() {
|
||||
unsigned char c;
|
||||
unsigned char d;
|
||||
@ -463,9 +452,9 @@ char s_getchar() {
|
||||
if (errno == ECONNRESET) {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IAC_WONT:
|
||||
if (d == 0) {
|
||||
@ -476,9 +465,9 @@ char s_getchar() {
|
||||
if (errno == ECONNRESET) {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IAC_DO:
|
||||
if (d == 0) {
|
||||
@ -490,7 +479,6 @@ char s_getchar() {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -503,10 +491,10 @@ char s_getchar() {
|
||||
if (errno == ECONNRESET) {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (c == 250) {
|
||||
do {
|
||||
@ -516,9 +504,9 @@ char s_getchar() {
|
||||
if (len <= 0) {
|
||||
disconnect("Socket Closed");
|
||||
}
|
||||
} while(c != 240);
|
||||
}
|
||||
|
||||
} while (c != 240);
|
||||
}
|
||||
|
||||
do {
|
||||
len = read(gSocket, &c, 1);
|
||||
} while (len == -1 && errno == EINTR);
|
||||
@ -543,7 +531,7 @@ char s_getc() {
|
||||
void s_readstring_inject(char *buffer, int max, char *inject) {
|
||||
int i;
|
||||
char c;
|
||||
|
||||
|
||||
memset(buffer, 0, max);
|
||||
|
||||
if (strlen(inject) > max) {
|
||||
@ -554,11 +542,11 @@ void s_readstring_inject(char *buffer, int max, char *inject) {
|
||||
|
||||
s_printf("%s", inject);
|
||||
|
||||
for (i=strlen(buffer);i<max;i++) {
|
||||
for (i = strlen(buffer); i < max; i++) {
|
||||
c = s_getchar();
|
||||
|
||||
if ((c == '\b' || c == 127) && i > 0) {
|
||||
buffer[i-1] = '\0';
|
||||
buffer[i - 1] = '\0';
|
||||
i -= 2;
|
||||
s_printf("\e[D \e[D");
|
||||
continue;
|
||||
@ -579,8 +567,8 @@ void s_readstring_inject(char *buffer, int max, char *inject) {
|
||||
}
|
||||
s_putchar(c);
|
||||
buffer[i] = c;
|
||||
buffer[i+1] = '\0';
|
||||
}
|
||||
buffer[i + 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void s_readstring(char *buffer, int max) {
|
||||
@ -589,11 +577,11 @@ void s_readstring(char *buffer, int max) {
|
||||
|
||||
memset(buffer, 0, max);
|
||||
|
||||
for (i=0;i<max;i++) {
|
||||
for (i = 0; i < max; i++) {
|
||||
c = s_getchar();
|
||||
|
||||
if ((c == '\b' || c == 127) && i > 0) {
|
||||
buffer[i-1] = '\0';
|
||||
buffer[i - 1] = '\0';
|
||||
i -= 2;
|
||||
s_printf("\e[D \e[D");
|
||||
continue;
|
||||
@ -614,7 +602,7 @@ void s_readstring(char *buffer, int max) {
|
||||
}
|
||||
s_putchar(c);
|
||||
buffer[i] = c;
|
||||
buffer[i+1] = '\0';
|
||||
buffer[i + 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
@ -622,12 +610,12 @@ void s_readpass(char *buffer, int max) {
|
||||
int i;
|
||||
char c;
|
||||
|
||||
for (i=0;i<max;i++) {
|
||||
for (i = 0; i < max; i++) {
|
||||
c = s_getchar();
|
||||
|
||||
if ((c == '\b' || c == 127) && i > 0) {
|
||||
buffer[i-1] = '\0';
|
||||
i-=2;
|
||||
buffer[i - 1] = '\0';
|
||||
i -= 2;
|
||||
s_printf("\e[D \e[D");
|
||||
continue;
|
||||
} else if (c == '\b' || c == 127) {
|
||||
@ -647,7 +635,7 @@ void s_readpass(char *buffer, int max) {
|
||||
}
|
||||
s_putchar('*');
|
||||
buffer[i] = c;
|
||||
buffer[i+1] = '\0';
|
||||
buffer[i + 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
@ -661,7 +649,7 @@ void exit_bbs() {
|
||||
mosquitto_loop_stop(mosq, 0);
|
||||
mosquitto_destroy(mosq);
|
||||
mosquitto_lib_cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void disconnect(char *calledby) {
|
||||
@ -676,7 +664,7 @@ void disconnect(char *calledby) {
|
||||
|
||||
if (!sshBBS) {
|
||||
close(gSocket);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -684,11 +672,11 @@ void record_last10_callers(struct user_record *user) {
|
||||
struct last10_callers new_entry;
|
||||
struct last10_callers callers[10];
|
||||
|
||||
int i,j;
|
||||
int i, j;
|
||||
FILE *fptr = fopen("last10v2.dat", "rb");
|
||||
|
||||
if (fptr != NULL) {
|
||||
for (i=0;i<10;i++) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) {
|
||||
break;
|
||||
}
|
||||
@ -698,7 +686,7 @@ void record_last10_callers(struct user_record *user) {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
if (strcasecmp(conf.sysop_name, user->loginname) != 0 ) {
|
||||
if (strcasecmp(conf.sysop_name, user->loginname) != 0) {
|
||||
memset(&new_entry, 0, sizeof(struct last10_callers));
|
||||
strcpy(new_entry.name, user->loginname);
|
||||
strcpy(new_entry.location, user->location);
|
||||
@ -710,7 +698,7 @@ void record_last10_callers(struct user_record *user) {
|
||||
j = 0;
|
||||
}
|
||||
fptr = fopen("last10v2.dat", "wb");
|
||||
for (;j<i;j++) {
|
||||
for (; j < i; j++) {
|
||||
fwrite(&callers[j], 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) {
|
||||
struct last10_callers callers[10];
|
||||
|
||||
int i,z;
|
||||
int i, z;
|
||||
struct tm l10_time;
|
||||
FILE *fptr = fopen("last10v2.dat", "rb");
|
||||
time_t l10_timet;
|
||||
@ -733,7 +721,7 @@ void display_last10_callers(struct user_record *user) {
|
||||
|
||||
if (fptr != NULL) {
|
||||
|
||||
for (i=0;i<10;i++) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) {
|
||||
break;
|
||||
}
|
||||
@ -744,7 +732,7 @@ void display_last10_callers(struct user_record *user) {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
for (z=0;z<i;z++) {
|
||||
for (z = 0; z < i; z++) {
|
||||
l10_timet = callers[z].time;
|
||||
localtime_r(&l10_timet, &l10_time);
|
||||
if (conf.date_style == 1) {
|
||||
@ -796,7 +784,7 @@ void automessage_write() {
|
||||
automsg[strlen(automsg) - 1] = '\r';
|
||||
automsg[strlen(automsg)] = '\n';
|
||||
s_printf(get_string(16));
|
||||
for (i=0;i<4;i++) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
s_printf("\r\n%d: ", i);
|
||||
s_readstring(buffer, 75);
|
||||
strcat(automsg, buffer);
|
||||
@ -822,7 +810,7 @@ void automessage_display() {
|
||||
if (stat("automessage.txt", &s) == 0) {
|
||||
fptr = fopen("automessage.txt", "r");
|
||||
if (fptr) {
|
||||
for (i=0;i<5;i++) {
|
||||
for (i = 0; i < 5; i++) {
|
||||
memset(buffer, 0, 90);
|
||||
fgets(buffer, 88, fptr);
|
||||
buffer[strlen(buffer) - 1] = '\r';
|
||||
@ -846,7 +834,7 @@ void automessage() {
|
||||
s_printf(get_string(275));
|
||||
c = s_getchar();
|
||||
s_printf("\r\n");
|
||||
switch(tolower(c)) {
|
||||
switch (tolower(c)) {
|
||||
case 'v':
|
||||
automessage_display();
|
||||
break;
|
||||
@ -883,22 +871,21 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
int fno;
|
||||
|
||||
atexit(exit_bbs);
|
||||
|
||||
|
||||
usertimeout = 10;
|
||||
timeoutpaused = 0;
|
||||
|
||||
|
||||
memset (&sa, 0, sizeof (sa));
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = &timer_handler;
|
||||
sa.sa_flags = SA_RESTART;
|
||||
sigaction (SIGALRM, &sa, 0);
|
||||
sigaction(SIGALRM, &sa, 0);
|
||||
|
||||
itime.it_interval.tv_sec = 60;
|
||||
itime.it_interval.tv_usec = 0;
|
||||
itime.it_value.tv_sec = 60;
|
||||
itime.it_value.tv_usec = 0;
|
||||
|
||||
setitimer (ITIMER_REAL, &itime, 0);
|
||||
setitimer(ITIMER_REAL, &itime, 0);
|
||||
|
||||
ipaddress = ip;
|
||||
|
||||
@ -915,13 +902,12 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
}
|
||||
gSocket = socket;
|
||||
|
||||
|
||||
if (!ssh) {
|
||||
gUser = NULL;
|
||||
sshBBS = 0;
|
||||
if (send(socket, iac_echo, 3, 0) != 3) {
|
||||
dolog("Failed to send iac_echo");
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
if (send(socket, iac_sga, 3, 0) != 3) {
|
||||
dolog("Failed to send iac_sga");
|
||||
@ -930,11 +916,11 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
} else {
|
||||
sshBBS = 1;
|
||||
}
|
||||
|
||||
|
||||
s_printf("Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR);
|
||||
|
||||
// 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);
|
||||
|
||||
if (stat(buffer, &s) != 0) {
|
||||
@ -946,7 +932,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
}
|
||||
|
||||
write(fno, "UNKNOWN", 7);
|
||||
|
||||
|
||||
close(fno);
|
||||
break;
|
||||
}
|
||||
@ -963,18 +949,18 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
// initialize mqtt
|
||||
if (conf.broadcast_enable && conf.broadcast_address != NULL && conf.broadcast_port != 0) {
|
||||
mosquitto_lib_init();
|
||||
mosq = mosquitto_new(NULL, 1, NULL);
|
||||
mosq = mosquitto_new(NULL, 1, NULL);
|
||||
if (conf.broadcast_user != NULL && conf.broadcast_pass != NULL) {
|
||||
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.");
|
||||
conf.broadcast_enable = 0;
|
||||
} else {
|
||||
if (mosquitto_loop_start(mosq) != MOSQ_ERR_SUCCESS) {
|
||||
dolog("Unable to start MQTT loop.");
|
||||
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);
|
||||
|
||||
s_displayansi("issue");
|
||||
|
||||
|
||||
tries = 0;
|
||||
|
||||
if (!ssh) {
|
||||
tryagain:
|
||||
tryagain:
|
||||
s_printf(get_string(19));
|
||||
s_printf(get_string(20));
|
||||
|
||||
@ -1001,7 +987,7 @@ tryagain:
|
||||
s_printf(get_string(203));
|
||||
goto tryagain;
|
||||
}
|
||||
|
||||
|
||||
if (usernotfound) {
|
||||
dolog("New user on node %d", mynode);
|
||||
user = new_user();
|
||||
@ -1023,7 +1009,7 @@ tryagain:
|
||||
|
||||
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);
|
||||
if (stat(buffer, &s) == 0) {
|
||||
nodefile = fopen(buffer, "r");
|
||||
@ -1047,7 +1033,7 @@ tryagain:
|
||||
user = gUser;
|
||||
s_printf(get_string(24), gUser->loginname);
|
||||
s_getc();
|
||||
for (i=1;i<=conf.nodes;i++) {
|
||||
for (i = 1; i <= conf.nodes; i++) {
|
||||
snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i);
|
||||
if (stat(buffer, &s) == 0) {
|
||||
nodefile = fopen(buffer, "r");
|
||||
@ -1068,7 +1054,7 @@ tryagain:
|
||||
} else {
|
||||
s_printf(get_string(25), conf.bbs_name);
|
||||
s_getc();
|
||||
gUser = new_user();
|
||||
gUser = new_user();
|
||||
user = gUser;
|
||||
}
|
||||
}
|
||||
@ -1094,14 +1080,11 @@ tryagain:
|
||||
if (stat(buffer, &s) == 0) {
|
||||
recursive_delete(buffer);
|
||||
}
|
||||
|
||||
|
||||
#if defined(ENABLE_WWW)
|
||||
www_expire_old_links();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// do post-login
|
||||
dolog("%s logged in, on node %d", user->loginname, mynode);
|
||||
broadcast("USER: %s; NODE:%d; STATUS: Logged in.", user->loginname, mynode);
|
||||
@ -1120,7 +1103,6 @@ tryagain:
|
||||
|
||||
user->timeson++;
|
||||
|
||||
|
||||
if (conf.script_path != NULL) {
|
||||
snprintf(buffer, PATH_MAX, "%s/login_stanza.lua", conf.script_path);
|
||||
if (stat(buffer, &s) == 0) {
|
||||
@ -1142,7 +1124,7 @@ tryagain:
|
||||
display_bulletins();
|
||||
|
||||
blog_display();
|
||||
|
||||
|
||||
// display info
|
||||
display_info();
|
||||
|
||||
@ -1166,9 +1148,9 @@ tryagain:
|
||||
// main menu
|
||||
|
||||
menu_system(conf.root_menu);
|
||||
|
||||
|
||||
do_logout();
|
||||
|
||||
|
||||
dolog("%s is logging out, on node %d", user->loginname, mynode);
|
||||
broadcast("USER: %s; NODE:%d; STATUS: Logging out.", user->loginname, mynode);
|
||||
disconnect("Log out");
|
||||
@ -1182,7 +1164,7 @@ void do_logout() {
|
||||
char c;
|
||||
int result;
|
||||
int do_internal_logout = 1;
|
||||
|
||||
|
||||
if (conf.script_path != NULL) {
|
||||
snprintf(buffer, PATH_MAX, "%s/logout_stanza.lua", conf.script_path);
|
||||
if (stat(buffer, &s) == 0) {
|
||||
@ -1231,54 +1213,54 @@ void runbbs_ssh(char *ip) {
|
||||
}
|
||||
|
||||
int recursive_delete(const char *dir) {
|
||||
int ret = 0;
|
||||
FTS *ftsp = NULL;
|
||||
FTSENT *curr;
|
||||
int ret = 0;
|
||||
FTS *ftsp = NULL;
|
||||
FTSENT *curr;
|
||||
|
||||
char *files[] = { (char *) dir, NULL };
|
||||
char *files[] = {(char *)dir, NULL};
|
||||
|
||||
ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL);
|
||||
if (!ftsp) {
|
||||
dolog("%s: fts_open failed: %s", dir, strerror(errno));
|
||||
ret = -1;
|
||||
goto finish;
|
||||
}
|
||||
ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL);
|
||||
if (!ftsp) {
|
||||
dolog("%s: fts_open failed: %s", dir, strerror(errno));
|
||||
ret = -1;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
while ((curr = fts_read(ftsp))) {
|
||||
switch (curr->fts_info) {
|
||||
case FTS_NS:
|
||||
case FTS_DNR:
|
||||
case FTS_ERR:
|
||||
dolog("%s: fts_read error: %s", curr->fts_accpath, strerror(curr->fts_errno));
|
||||
break;
|
||||
while ((curr = fts_read(ftsp))) {
|
||||
switch (curr->fts_info) {
|
||||
case FTS_NS:
|
||||
case FTS_DNR:
|
||||
case FTS_ERR:
|
||||
dolog("%s: fts_read error: %s", curr->fts_accpath, strerror(curr->fts_errno));
|
||||
break;
|
||||
|
||||
case FTS_DC:
|
||||
case FTS_DOT:
|
||||
case FTS_NSOK:
|
||||
break;
|
||||
case FTS_DC:
|
||||
case FTS_DOT:
|
||||
case FTS_NSOK:
|
||||
break;
|
||||
|
||||
case FTS_D:
|
||||
break;
|
||||
case FTS_D:
|
||||
break;
|
||||
|
||||
case FTS_DP:
|
||||
case FTS_F:
|
||||
case FTS_SL:
|
||||
case FTS_SLNONE:
|
||||
case FTS_DEFAULT:
|
||||
if (remove(curr->fts_accpath) < 0) {
|
||||
dolog("%s: Failed to remove: %s", curr->fts_path, strerror(errno));
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
case FTS_DP:
|
||||
case FTS_F:
|
||||
case FTS_SL:
|
||||
case FTS_SLNONE:
|
||||
case FTS_DEFAULT:
|
||||
if (remove(curr->fts_accpath) < 0) {
|
||||
dolog("%s: Failed to remove: %s", curr->fts_path, strerror(errno));
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
finish:
|
||||
if (ftsp) {
|
||||
fts_close(ftsp);
|
||||
}
|
||||
if (ftsp) {
|
||||
fts_close(ftsp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int copy_file(char *src, char *dest) {
|
||||
@ -1297,7 +1279,7 @@ int copy_file(char *src, char *dest) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
while (1) {
|
||||
c = fgetc(src_file);
|
||||
if (!feof(src_file)) {
|
||||
fputc(c, dest_file);
|
||||
@ -1339,14 +1321,15 @@ char *str_replace(const char *str, const char *from, const char *to) {
|
||||
pos_cache_tmp = realloc(pos_cache, sizeof(*pos_cache) * cache_sz);
|
||||
if (pos_cache_tmp == NULL) {
|
||||
goto end_repl_str;
|
||||
} else pos_cache = pos_cache_tmp;
|
||||
} else
|
||||
pos_cache = pos_cache_tmp;
|
||||
cache_sz_inc *= cache_sz_inc_factor;
|
||||
if (cache_sz_inc > cache_sz_inc_max) {
|
||||
cache_sz_inc = cache_sz_inc_max;
|
||||
}
|
||||
}
|
||||
|
||||
pos_cache[count-1] = pstr2 - str;
|
||||
pos_cache[count - 1] = pstr2 - str;
|
||||
pstr = pstr2 + fromlen;
|
||||
}
|
||||
|
||||
@ -1356,7 +1339,8 @@ char *str_replace(const char *str, const char *from, const char *to) {
|
||||
if (count > 0) {
|
||||
tolen = strlen(to);
|
||||
retlen = orglen + (tolen - fromlen) * count;
|
||||
} else retlen = orglen;
|
||||
} else
|
||||
retlen = orglen;
|
||||
ret = malloc(retlen + 1);
|
||||
if (ret == NULL) {
|
||||
goto end_repl_str;
|
||||
@ -1375,7 +1359,7 @@ char *str_replace(const char *str, const char *from, const char *to) {
|
||||
memcpy(pret, to, tolen);
|
||||
pret += tolen;
|
||||
pstr = str + pos_cache[i] + fromlen;
|
||||
cpylen = (i == count-1 ? orglen : pos_cache[i+1]) - pos_cache[i] - fromlen;
|
||||
cpylen = (i == count - 1 ? orglen : pos_cache[i + 1]) - pos_cache[i] - fromlen;
|
||||
memcpy(pret, pstr, cpylen);
|
||||
pret += cpylen;
|
||||
}
|
||||
|
42
src/bbs.h
42
src/bbs.h
@ -20,17 +20,17 @@
|
||||
#define NETWORK_FIDO 1
|
||||
#define NETWORK_WWIV 2
|
||||
#define NETWORK_MAGI 3
|
||||
#define NETWORK_QWK 4
|
||||
#define NETWORK_QWK 4
|
||||
|
||||
#define TYPE_LOCAL_AREA 0
|
||||
#define TYPE_NETMAIL_AREA 1
|
||||
#define TYPE_LOCAL_AREA 0
|
||||
#define TYPE_NETMAIL_AREA 1
|
||||
#define TYPE_ECHOMAIL_AREA 2
|
||||
#define TYPE_NEWSGROUP_AREA 3
|
||||
|
||||
#define IAC 255
|
||||
#define IAC 255
|
||||
#define IAC_WILL 251
|
||||
#define IAC_WONT 252
|
||||
#define IAC_DO 253
|
||||
#define IAC_DO 253
|
||||
#define IAC_DONT 254
|
||||
#define IAC_TRANSMIT_BINARY 0
|
||||
#define IAC_SUPPRESS_GO_AHEAD 3
|
||||
@ -48,7 +48,7 @@ struct last10_callers {
|
||||
char location[33];
|
||||
time_t time;
|
||||
int calls;
|
||||
}__attribute__((packed));
|
||||
} __attribute__((packed));
|
||||
|
||||
struct text_file {
|
||||
char *name;
|
||||
@ -120,9 +120,9 @@ struct protocol {
|
||||
int upload_prompt;
|
||||
};
|
||||
|
||||
#define IP_STATUS_UNKNOWN 0
|
||||
#define IP_STATUS_WHITELISTED 1
|
||||
#define IP_STATUS_BLACKLISTED 2
|
||||
#define IP_STATUS_UNKNOWN 0
|
||||
#define IP_STATUS_WHITELISTED 1
|
||||
#define IP_STATUS_BLACKLISTED 2
|
||||
|
||||
struct ip_address_guard {
|
||||
int status;
|
||||
@ -162,14 +162,14 @@ struct bbs_config {
|
||||
int bwave_max_msgs;
|
||||
int date_style;
|
||||
struct fido_addr *main_aka;
|
||||
|
||||
|
||||
char *root_menu;
|
||||
char *menu_path;
|
||||
char *external_editor_cmd;
|
||||
int external_editor_stdio;
|
||||
char *external_editor_codepage;
|
||||
int fork;
|
||||
|
||||
|
||||
int nodes;
|
||||
int newuserlvl;
|
||||
int automsgwritelvl;
|
||||
@ -179,11 +179,11 @@ struct bbs_config {
|
||||
char *broadcast_topic;
|
||||
char *broadcast_user;
|
||||
char *broadcast_pass;
|
||||
|
||||
|
||||
int ipguard_enable;
|
||||
int ipguard_timeout;
|
||||
int ipguard_tries;
|
||||
|
||||
|
||||
int mail_conference_count;
|
||||
struct mail_conference **mail_conferences;
|
||||
int door_count;
|
||||
@ -192,11 +192,11 @@ struct bbs_config {
|
||||
struct file_directory **file_directories;
|
||||
int text_file_count;
|
||||
struct text_file **text_files;
|
||||
|
||||
|
||||
char *config_path;
|
||||
int archiver_count;
|
||||
struct archiver **archivers;
|
||||
|
||||
|
||||
int protocol_count;
|
||||
struct protocol **protocols;
|
||||
};
|
||||
@ -252,10 +252,10 @@ struct msg_headers {
|
||||
};
|
||||
|
||||
struct blog_entry_t {
|
||||
char *subject;
|
||||
char *author;
|
||||
char *body;
|
||||
time_t date;
|
||||
char *subject;
|
||||
char *author;
|
||||
char *body;
|
||||
time_t date;
|
||||
};
|
||||
|
||||
extern char *str_replace(const char *orig, const char *rep, const char *with);
|
||||
@ -373,9 +373,9 @@ extern void chomp(char *string);
|
||||
|
||||
#if defined(ENABLE_WWW)
|
||||
extern void www_init();
|
||||
extern void *www_logger(void * cls, const char * uri, struct MHD_Connection *con);
|
||||
extern void *www_logger(void *cls, const char *uri, struct MHD_Connection *con);
|
||||
extern void www_request_completed(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe);
|
||||
extern int www_handler(void * cls, struct MHD_Connection * connection, const char * url, const char * method, const char * version, const char * upload_data, size_t * upload_data_size, void ** ptr);
|
||||
extern int www_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr);
|
||||
extern char *www_email_summary(struct user_record *user);
|
||||
extern char *www_email_display(struct user_record *user, int email);
|
||||
extern int www_send_email(struct user_record *user, char *recipient, char *subject, char *body);
|
||||
|
493
src/bbs_list.c
493
src/bbs_list.c
@ -8,20 +8,20 @@
|
||||
extern struct bbs_config conf;
|
||||
extern struct user_record *gUser;
|
||||
struct bbs_list_entry_t {
|
||||
int id;
|
||||
char *bbsname;
|
||||
char *sysopname;
|
||||
char *telnet;
|
||||
int owner;
|
||||
int id;
|
||||
char *bbsname;
|
||||
char *sysopname;
|
||||
char *telnet;
|
||||
int owner;
|
||||
};
|
||||
|
||||
int add_bbs(struct bbs_list_entry_t *new_entry) {
|
||||
char *create_sql = "CREATE TABLE IF NOT EXISTS bbslist ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"bbsname TEXT,"
|
||||
"sysop TEXT,"
|
||||
"telnet TEXT,"
|
||||
"owner INTEGER);";
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"bbsname TEXT,"
|
||||
"sysop TEXT,"
|
||||
"telnet TEXT,"
|
||||
"owner INTEGER);";
|
||||
|
||||
char *insert_sql = "INSERT INTO bbslist (bbsname, sysop, telnet, owner) VALUES(?,?, ?, ?)";
|
||||
|
||||
@ -32,11 +32,11 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
|
||||
char c;
|
||||
char *err_msg = 0;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int id;
|
||||
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int id;
|
||||
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
|
||||
s_printf(get_string(28));
|
||||
s_readstring(bbsname, 18);
|
||||
@ -60,14 +60,14 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
|
||||
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
dolog("SQL error: %s", err_msg);
|
||||
|
||||
@ -86,69 +86,68 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
|
||||
sqlite3_bind_int(res, 4, gUser->id);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
if (rc != SQLITE_DONE) {
|
||||
|
||||
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
id = sqlite3_last_insert_rowid(db);
|
||||
id = sqlite3_last_insert_rowid(db);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
s_printf(get_string(38));
|
||||
|
||||
if (new_entry != NULL) {
|
||||
new_entry->id = id;
|
||||
new_entry->bbsname = strdup(bbsname);
|
||||
new_entry->sysopname = strdup(sysop);
|
||||
new_entry->telnet = strdup(telnet);
|
||||
new_entry->owner = gUser->id;
|
||||
}
|
||||
return 1;
|
||||
if (new_entry != NULL) {
|
||||
new_entry->id = id;
|
||||
new_entry->bbsname = strdup(bbsname);
|
||||
new_entry->sysopname = strdup(sysop);
|
||||
new_entry->telnet = strdup(telnet);
|
||||
new_entry->owner = gUser->id;
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
s_printf(get_string(39));
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int delete_bbs(int id) {
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT bbsname FROM bbslist WHERE id=? and owner=?";
|
||||
char *dsql = "DELETE FROM bbslist WHERE id=?";
|
||||
char c;
|
||||
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT bbsname FROM bbslist WHERE id=? and owner=?";
|
||||
char *dsql = "DELETE FROM bbslist WHERE id=?";
|
||||
char c;
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
return 0;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_int(res, 1, id);
|
||||
sqlite3_bind_int(res, 2, gUser->id);
|
||||
} else {
|
||||
sqlite3_close(db);
|
||||
s_printf(get_string(41));
|
||||
return 0;
|
||||
}
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
sqlite3_close(db);
|
||||
s_printf(get_string(41));
|
||||
return 0;
|
||||
}
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
s_printf(get_string(42), sqlite3_column_text(res, 0));
|
||||
sqlite3_finalize(res);
|
||||
c = s_getc();
|
||||
@ -164,18 +163,18 @@ int delete_bbs(int id) {
|
||||
sqlite3_step(res);
|
||||
s_printf(get_string(43));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
} else {
|
||||
s_printf(get_string(39));
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
sqlite3_finalize(res);
|
||||
s_printf(get_string(44));
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,207 +186,207 @@ void bbs_list() {
|
||||
char c;
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist";
|
||||
struct bbs_list_entry_t **entries;
|
||||
int entrycount;
|
||||
struct bbs_list_entry_t *newentry;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist";
|
||||
struct bbs_list_entry_t **entries;
|
||||
int entrycount;
|
||||
struct bbs_list_entry_t *newentry;
|
||||
|
||||
while(1) {
|
||||
entrycount = 0;
|
||||
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
|
||||
while (1) {
|
||||
entrycount = 0;
|
||||
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return;
|
||||
}
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return;
|
||||
}
|
||||
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
|
||||
} else {
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (entrycount == 0) {
|
||||
entries = (struct bbs_list_entry_t **)malloc(sizeof(struct bbs_list_entry_t *));
|
||||
} else {
|
||||
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1));
|
||||
}
|
||||
entries[entrycount] = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t));
|
||||
} else {
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (entrycount == 0) {
|
||||
entries = (struct bbs_list_entry_t **)malloc(sizeof(struct bbs_list_entry_t *));
|
||||
} else {
|
||||
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1));
|
||||
}
|
||||
entries[entrycount] = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t));
|
||||
|
||||
entries[entrycount]->id = sqlite3_column_int(res, 0);
|
||||
entries[entrycount]->bbsname = strdup(sqlite3_column_text(res, 1));
|
||||
entries[entrycount]->sysopname = strdup(sqlite3_column_text(res, 2));
|
||||
entries[entrycount]->telnet = strdup(sqlite3_column_text(res, 3));
|
||||
entrycount++;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
entries[entrycount]->id = sqlite3_column_int(res, 0);
|
||||
entries[entrycount]->bbsname = strdup(sqlite3_column_text(res, 1));
|
||||
entries[entrycount]->sysopname = strdup(sqlite3_column_text(res, 2));
|
||||
entries[entrycount]->telnet = strdup(sqlite3_column_text(res, 3));
|
||||
entrycount++;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
if (entrycount > 0) {
|
||||
while (1) {
|
||||
if (redraw) {
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(270));
|
||||
s_printf(get_string(271));
|
||||
for (i=start;i<start+22 && i < entrycount;i++) {
|
||||
if (i == selected) {
|
||||
s_printf(get_string(269), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet);
|
||||
} else {
|
||||
s_printf(get_string(268), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet);
|
||||
}
|
||||
}
|
||||
s_printf("\e[%d;5H", selected - start + 2);
|
||||
redraw = 0;
|
||||
}
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'q') {
|
||||
for (i=0;i<entrycount;i++) {
|
||||
free(entries[i]->bbsname);
|
||||
free(entries[i]->sysopname);
|
||||
free(entries[i]->telnet);
|
||||
free(entries[i]);
|
||||
}
|
||||
free(entries);
|
||||
return;
|
||||
} else if (tolower(c) == 'a') {
|
||||
newentry = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t));
|
||||
if (add_bbs(newentry)) {
|
||||
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1));
|
||||
entries[entrycount] = newentry;
|
||||
entrycount++;
|
||||
redraw = 1;
|
||||
} else {
|
||||
free(newentry);
|
||||
redraw = 1;
|
||||
}
|
||||
} else if (tolower(c) == 'd') {
|
||||
if (delete_bbs(entries[selected]->id)) {
|
||||
free(entries[selected]->bbsname);
|
||||
free(entries[selected]->sysopname);
|
||||
free(entries[selected]->telnet);
|
||||
free(entries[selected]);
|
||||
if (entrycount > 0) {
|
||||
while (1) {
|
||||
if (redraw) {
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(270));
|
||||
s_printf(get_string(271));
|
||||
for (i = start; i < start + 22 && i < entrycount; i++) {
|
||||
if (i == selected) {
|
||||
s_printf(get_string(269), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet);
|
||||
} else {
|
||||
s_printf(get_string(268), i - start + 2, i, entries[i]->bbsname, entries[i]->sysopname, entries[i]->telnet);
|
||||
}
|
||||
}
|
||||
s_printf("\e[%d;5H", selected - start + 2);
|
||||
redraw = 0;
|
||||
}
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'q') {
|
||||
for (i = 0; i < entrycount; i++) {
|
||||
free(entries[i]->bbsname);
|
||||
free(entries[i]->sysopname);
|
||||
free(entries[i]->telnet);
|
||||
free(entries[i]);
|
||||
}
|
||||
free(entries);
|
||||
return;
|
||||
} else if (tolower(c) == 'a') {
|
||||
newentry = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t));
|
||||
if (add_bbs(newentry)) {
|
||||
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1));
|
||||
entries[entrycount] = newentry;
|
||||
entrycount++;
|
||||
redraw = 1;
|
||||
} else {
|
||||
free(newentry);
|
||||
redraw = 1;
|
||||
}
|
||||
} else if (tolower(c) == 'd') {
|
||||
if (delete_bbs(entries[selected]->id)) {
|
||||
free(entries[selected]->bbsname);
|
||||
free(entries[selected]->sysopname);
|
||||
free(entries[selected]->telnet);
|
||||
free(entries[selected]);
|
||||
|
||||
for (i=selected;i<entrycount - 1;i++) {
|
||||
entries[selected] = entries[selected + 1];
|
||||
}
|
||||
for (i = selected; i < entrycount - 1; i++) {
|
||||
entries[selected] = entries[selected + 1];
|
||||
}
|
||||
|
||||
entrycount--;
|
||||
if (entrycount == 0) {
|
||||
free(entries);
|
||||
return;
|
||||
}
|
||||
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * entrycount);
|
||||
entrycount--;
|
||||
if (entrycount == 0) {
|
||||
free(entries);
|
||||
return;
|
||||
}
|
||||
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * entrycount);
|
||||
|
||||
if (selected >= entrycount) {
|
||||
selected = entrycount - 1;
|
||||
}
|
||||
}
|
||||
redraw = 1;
|
||||
} else if (c == 27) {
|
||||
c = s_getchar();
|
||||
if (c == 91) {
|
||||
c = s_getchar();
|
||||
if (c == 66) {
|
||||
// down
|
||||
if (selected + 1 >= start + 22) {
|
||||
start += 22;
|
||||
if (start >= entrycount) {
|
||||
start = entrycount - 22;
|
||||
}
|
||||
redraw = 1;
|
||||
}
|
||||
selected++;
|
||||
if (selected >= entrycount) {
|
||||
selected = entrycount - 1;
|
||||
} else {
|
||||
if (!redraw) {
|
||||
s_printf(get_string(268), selected - start + 1, selected - 1, entries[selected - 1]->bbsname, entries[selected - 1]->sysopname, entries[selected - 1]->telnet);
|
||||
s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet);
|
||||
s_printf("\e[%d;4H", selected - start + 2);
|
||||
}
|
||||
}
|
||||
} else if (c == 65) {
|
||||
// up
|
||||
if (selected - 1 < start) {
|
||||
start -= 22;
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
redraw = 1;
|
||||
}
|
||||
selected--;
|
||||
if (selected < 0) {
|
||||
selected = 0;
|
||||
} else {
|
||||
if (!redraw) {
|
||||
s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet);
|
||||
s_printf(get_string(268), selected - start + 3, selected + 1, entries[selected + 1]->bbsname, entries[selected + 1]->sysopname, entries[selected + 1]->telnet);
|
||||
s_printf("\e[%d;4H", selected - start + 2);
|
||||
}
|
||||
}
|
||||
} else if (c == 75) {
|
||||
// END KEY
|
||||
selected = entrycount - 1;
|
||||
start = entrycount - 22;
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
redraw = 1;
|
||||
} else if (c == 72) {
|
||||
// HOME KEY
|
||||
selected = 0;
|
||||
start = 0;
|
||||
redraw = 1;
|
||||
} else if (c == 86 || c == '5') {
|
||||
if (c == '5') {
|
||||
s_getchar();
|
||||
}
|
||||
// PAGE UP
|
||||
selected = selected - 22;
|
||||
if (selected < 0) {
|
||||
selected = 0;
|
||||
}
|
||||
start = selected;
|
||||
redraw = 1;
|
||||
} else if (c == 85 || c == '6') {
|
||||
if (c == '6') {
|
||||
s_getchar();
|
||||
}
|
||||
// PAGE DOWN
|
||||
selected = selected + 22;
|
||||
if (selected >= entrycount) {
|
||||
selected = entrycount -1;
|
||||
}
|
||||
start = selected;
|
||||
redraw = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no entries
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(270));
|
||||
s_printf(get_string(271));
|
||||
s_printf(get_string(272));
|
||||
s_printf(get_string(273));
|
||||
if (selected >= entrycount) {
|
||||
selected = entrycount - 1;
|
||||
}
|
||||
}
|
||||
redraw = 1;
|
||||
} else if (c == 27) {
|
||||
c = s_getchar();
|
||||
if (c == 91) {
|
||||
c = s_getchar();
|
||||
if (c == 66) {
|
||||
// down
|
||||
if (selected + 1 >= start + 22) {
|
||||
start += 22;
|
||||
if (start >= entrycount) {
|
||||
start = entrycount - 22;
|
||||
}
|
||||
redraw = 1;
|
||||
}
|
||||
selected++;
|
||||
if (selected >= entrycount) {
|
||||
selected = entrycount - 1;
|
||||
} else {
|
||||
if (!redraw) {
|
||||
s_printf(get_string(268), selected - start + 1, selected - 1, entries[selected - 1]->bbsname, entries[selected - 1]->sysopname, entries[selected - 1]->telnet);
|
||||
s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet);
|
||||
s_printf("\e[%d;4H", selected - start + 2);
|
||||
}
|
||||
}
|
||||
} else if (c == 65) {
|
||||
// up
|
||||
if (selected - 1 < start) {
|
||||
start -= 22;
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
redraw = 1;
|
||||
}
|
||||
selected--;
|
||||
if (selected < 0) {
|
||||
selected = 0;
|
||||
} else {
|
||||
if (!redraw) {
|
||||
s_printf(get_string(269), selected - start + 2, selected, entries[selected]->bbsname, entries[selected]->sysopname, entries[selected]->telnet);
|
||||
s_printf(get_string(268), selected - start + 3, selected + 1, entries[selected + 1]->bbsname, entries[selected + 1]->sysopname, entries[selected + 1]->telnet);
|
||||
s_printf("\e[%d;4H", selected - start + 2);
|
||||
}
|
||||
}
|
||||
} else if (c == 75) {
|
||||
// END KEY
|
||||
selected = entrycount - 1;
|
||||
start = entrycount - 22;
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
redraw = 1;
|
||||
} else if (c == 72) {
|
||||
// HOME KEY
|
||||
selected = 0;
|
||||
start = 0;
|
||||
redraw = 1;
|
||||
} else if (c == 86 || c == '5') {
|
||||
if (c == '5') {
|
||||
s_getchar();
|
||||
}
|
||||
// PAGE UP
|
||||
selected = selected - 22;
|
||||
if (selected < 0) {
|
||||
selected = 0;
|
||||
}
|
||||
start = selected;
|
||||
redraw = 1;
|
||||
} else if (c == 85 || c == '6') {
|
||||
if (c == '6') {
|
||||
s_getchar();
|
||||
}
|
||||
// PAGE DOWN
|
||||
selected = selected + 22;
|
||||
if (selected >= entrycount) {
|
||||
selected = entrycount - 1;
|
||||
}
|
||||
start = selected;
|
||||
redraw = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no entries
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(270));
|
||||
s_printf(get_string(271));
|
||||
s_printf(get_string(272));
|
||||
s_printf(get_string(273));
|
||||
|
||||
while(1) {
|
||||
c = s_getchar();
|
||||
|
||||
if (tolower(c) == 'a') {
|
||||
add_bbs(NULL);
|
||||
break;
|
||||
} else if (tolower(c) == 'q') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (1) {
|
||||
c = s_getchar();
|
||||
|
||||
if (tolower(c) == 'a') {
|
||||
add_bbs(NULL);
|
||||
break;
|
||||
} else if (tolower(c) == 'q') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
425
src/blog.c
425
src/blog.c
@ -7,250 +7,249 @@ extern struct bbs_config conf;
|
||||
extern struct user_record *gUser;
|
||||
|
||||
int blog_load(struct blog_entry_t ***entries) {
|
||||
int blog_entry_count = 0;
|
||||
struct blog_entry_t **blog_entries;
|
||||
char *sql = "SELECT author, title, body, date FROM blog ORDER BY date DESC";
|
||||
int blog_entry_count = 0;
|
||||
struct blog_entry_t **blog_entries;
|
||||
char *sql = "SELECT author, title, body, date FROM blog ORDER BY date DESC";
|
||||
|
||||
char buffer[PATH_MAX];
|
||||
int rc;
|
||||
sqlite3 *db;
|
||||
char buffer[PATH_MAX];
|
||||
int rc;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
|
||||
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
*entries = NULL;
|
||||
*entries = NULL;
|
||||
return 0;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
*entries = NULL;
|
||||
return 0;
|
||||
}
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (blog_entry_count == 0) {
|
||||
blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *));
|
||||
} else {
|
||||
blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1));
|
||||
}
|
||||
blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t));
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
*entries = NULL;
|
||||
return 0;
|
||||
}
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (blog_entry_count == 0) {
|
||||
blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *));
|
||||
} else {
|
||||
blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1));
|
||||
}
|
||||
blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t));
|
||||
|
||||
blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0));
|
||||
blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1));
|
||||
blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2));
|
||||
blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3);
|
||||
blog_entry_count++;
|
||||
}
|
||||
blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0));
|
||||
blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1));
|
||||
blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2));
|
||||
blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3);
|
||||
blog_entry_count++;
|
||||
}
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
*entries = blog_entries;
|
||||
return blog_entry_count;
|
||||
*entries = blog_entries;
|
||||
return blog_entry_count;
|
||||
}
|
||||
|
||||
void blog_display() {
|
||||
|
||||
struct blog_entry_t **blog_entries;
|
||||
int blog_entry_count = 0;
|
||||
|
||||
int i;
|
||||
struct tm thetime;
|
||||
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
|
||||
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
|
||||
char c;
|
||||
int hour;
|
||||
int j;
|
||||
int lines = 2;
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(280));
|
||||
s_printf(get_string(281));
|
||||
|
||||
blog_entry_count = blog_load(&blog_entries);
|
||||
if (blog_entry_count == 0) {
|
||||
s_printf(get_string(282));
|
||||
s_printf(get_string(6));
|
||||
s_getchar();
|
||||
return;
|
||||
}
|
||||
struct blog_entry_t **blog_entries;
|
||||
int blog_entry_count = 0;
|
||||
|
||||
c = 'y';
|
||||
int i;
|
||||
struct tm thetime;
|
||||
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
|
||||
char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
|
||||
char c;
|
||||
int hour;
|
||||
int j;
|
||||
int lines = 2;
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(280));
|
||||
s_printf(get_string(281));
|
||||
|
||||
for (i=0;i<blog_entry_count;i++) {
|
||||
localtime_r(&blog_entries[i]->date, &thetime);
|
||||
blog_entry_count = blog_load(&blog_entries);
|
||||
if (blog_entry_count == 0) {
|
||||
s_printf(get_string(282));
|
||||
s_printf(get_string(6));
|
||||
s_getchar();
|
||||
return;
|
||||
}
|
||||
|
||||
s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author);
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
if (thetime.tm_hour >= 12) {
|
||||
hour = thetime.tm_hour - 12;
|
||||
} else {
|
||||
hour = thetime.tm_hour;
|
||||
}
|
||||
s_printf(get_string(284), (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900);
|
||||
c = 'y';
|
||||
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
|
||||
s_printf("\r\n\e[0m");
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
for (j=0; 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]);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < blog_entry_count; i++) {
|
||||
localtime_r(&blog_entries[i]->date, &thetime);
|
||||
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n");
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
}
|
||||
for (i=0;i<blog_entry_count;i++) {
|
||||
free(blog_entries[i]->subject);
|
||||
free(blog_entries[i]->author);
|
||||
free(blog_entries[i]->body);
|
||||
free(blog_entries[i]);
|
||||
}
|
||||
s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author);
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
if (thetime.tm_hour >= 12) {
|
||||
hour = thetime.tm_hour - 12;
|
||||
} else {
|
||||
hour = thetime.tm_hour;
|
||||
}
|
||||
s_printf(get_string(284), (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900);
|
||||
|
||||
free(blog_entries);
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
|
||||
s_printf(get_string(6));
|
||||
s_getchar();
|
||||
s_printf("\r\n\e[0m");
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
for (j = 0; j < strlen(blog_entries[i]->body); j++) {
|
||||
if (blog_entries[i]->body[j] == '\r') {
|
||||
s_printf("\r\n");
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
} else {
|
||||
s_printf("%c", blog_entries[i]->body[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n");
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < blog_entry_count; i++) {
|
||||
free(blog_entries[i]->subject);
|
||||
free(blog_entries[i]->author);
|
||||
free(blog_entries[i]->body);
|
||||
free(blog_entries[i]);
|
||||
}
|
||||
|
||||
free(blog_entries);
|
||||
|
||||
s_printf(get_string(6));
|
||||
s_getchar();
|
||||
}
|
||||
|
||||
void blog_write() {
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS blog ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"author TEXT COLLATE NOCASE,"
|
||||
"title TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER);";
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS blog ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"author TEXT COLLATE NOCASE,"
|
||||
"title TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER);";
|
||||
|
||||
char *isql = "INSERT INTO blog (author, title, body, date) VALUES(?, ?, ?, ?)";
|
||||
int rc;
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
char *blog_entry;
|
||||
char buffer[PATH_MAX];
|
||||
char *blog_subject;
|
||||
char *err_msg = 0;
|
||||
char *blog_entry;
|
||||
char buffer[PATH_MAX];
|
||||
char *blog_subject;
|
||||
char *err_msg = 0;
|
||||
|
||||
s_printf(get_string(285));
|
||||
s_readstring(buffer, 64);
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(285));
|
||||
s_readstring(buffer, 64);
|
||||
s_printf("\r\n");
|
||||
|
||||
if (strlen(buffer) == 0) {
|
||||
s_printf(get_string(39));
|
||||
return;
|
||||
}
|
||||
|
||||
blog_subject = strdup(buffer);
|
||||
|
||||
blog_entry = external_editor(gUser, "No-One", "No-One", NULL, 0, "No-One", "Blog Editor", 0, 1);
|
||||
|
||||
if (blog_entry != NULL) {
|
||||
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
dolog("SQL error: %s", err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, gUser->loginname, -1, 0);
|
||||
sqlite3_bind_text(res, 2, blog_subject, -1, 0);
|
||||
sqlite3_bind_text(res, 3, blog_entry, -1, 0);
|
||||
sqlite3_bind_int(res, 4, time(NULL));
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
if (strlen(buffer) == 0) {
|
||||
s_printf(get_string(39));
|
||||
return;
|
||||
}
|
||||
free(blog_subject);
|
||||
|
||||
blog_subject = strdup(buffer);
|
||||
|
||||
blog_entry = external_editor(gUser, "No-One", "No-One", NULL, 0, "No-One", "Blog Editor", 0, 1);
|
||||
|
||||
if (blog_entry != NULL) {
|
||||
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("SQL error: %s", err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, gUser->loginname, -1, 0);
|
||||
sqlite3_bind_text(res, 2, blog_subject, -1, 0);
|
||||
sqlite3_bind_text(res, 3, blog_entry, -1, 0);
|
||||
sqlite3_bind_int(res, 4, time(NULL));
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
free(blog_subject);
|
||||
}
|
493
src/bluewave.c
493
src/bluewave.c
File diff suppressed because it is too large
Load Diff
1186
src/bluewave.h
1186
src/bluewave.h
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#if defined(__OpenBSD__)
|
||||
# include <sys/select.h>
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#include "../deps/jsmn/jsmn.h"
|
||||
#include "bbs.h"
|
||||
@ -32,15 +32,14 @@ extern struct user_record gUser;
|
||||
extern int usertimeout;
|
||||
|
||||
struct chat_msg {
|
||||
char nick[16];
|
||||
char bbstag[16];
|
||||
char msg[512];
|
||||
char nick[16];
|
||||
char bbstag[16];
|
||||
char msg[512];
|
||||
};
|
||||
|
||||
|
||||
static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {
|
||||
if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&
|
||||
strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
|
||||
if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
|
||||
strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@ -50,12 +49,12 @@ static char *encapsulate_quote(char *in) {
|
||||
char out[512];
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (j=0;j<strlen(in);j++) {
|
||||
for (j = 0; j < strlen(in); j++) {
|
||||
if (in[j] == '\"' || in[j] == '\\') {
|
||||
out[i++] = '\\';
|
||||
}
|
||||
out[i] = in[j];
|
||||
out[i+1] = '\0';
|
||||
out[i + 1] = '\0';
|
||||
i++;
|
||||
}
|
||||
return strdup(out);
|
||||
@ -65,14 +64,14 @@ void scroll_up() {
|
||||
int y;
|
||||
int x;
|
||||
int color;
|
||||
|
||||
for (y=1;y<23;y++) {
|
||||
for (x=0;x<80;x++) {
|
||||
memcpy(screenbuffer[y-1][x], screenbuffer[y][x], sizeof(struct character_t));
|
||||
|
||||
for (y = 1; y < 23; y++) {
|
||||
for (x = 0; x < 80; x++) {
|
||||
memcpy(screenbuffer[y - 1][x], screenbuffer[y][x], sizeof(struct character_t));
|
||||
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]->color = color;
|
||||
}
|
||||
@ -81,14 +80,14 @@ void scroll_up() {
|
||||
|
||||
void raw(char *fmt, ...) {
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(sbuf, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
write(chat_socket, sbuf, strlen(sbuf));
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(sbuf, 512, fmt, ap);
|
||||
va_end(ap);
|
||||
write(chat_socket, sbuf, strlen(sbuf));
|
||||
}
|
||||
|
||||
int hostname_to_ip6(char * hostname , char* ip) {
|
||||
int hostname_to_ip6(char *hostname, char *ip) {
|
||||
struct addrinfo hints, *res, *p;
|
||||
int status;
|
||||
struct sockaddr_in6 *ipv6;
|
||||
@ -103,7 +102,7 @@ int hostname_to_ip6(char * hostname , char* ip) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (p=res; p!= NULL; p=p->ai_next) {
|
||||
for (p = res; p != NULL; p = p->ai_next) {
|
||||
if (p->ai_family == AF_INET6) {
|
||||
ipv6 = (struct sockaddr_in6 *)p->ai_addr;
|
||||
inet_ntop(p->ai_family, &(ipv6->sin6_addr), ip, INET6_ADDRSTRLEN);
|
||||
@ -115,7 +114,7 @@ int hostname_to_ip6(char * hostname , char* ip) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int hostname_to_ip(char * hostname , char* ip) {
|
||||
int hostname_to_ip(char *hostname, char *ip) {
|
||||
struct addrinfo hints, *res, *p;
|
||||
int status;
|
||||
struct sockaddr_in *ipv4;
|
||||
@ -130,7 +129,7 @@ int hostname_to_ip(char * hostname , char* ip) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (p=res; p!= NULL; p=p->ai_next) {
|
||||
for (p = res; p != NULL; p = p->ai_next) {
|
||||
if (p->ai_family == AF_INET) {
|
||||
ipv4 = (struct sockaddr_in *)p->ai_addr;
|
||||
inet_ntop(p->ai_family, &(ipv4->sin_addr), ip, INET_ADDRSTRLEN);
|
||||
@ -149,15 +148,15 @@ void append_screenbuffer(char *buffer) {
|
||||
int last_pos = 0;
|
||||
int curr_color = 7;
|
||||
|
||||
for (z=0;z<strlen(buffer);z++) {
|
||||
for (z = 0; z < strlen(buffer); z++) {
|
||||
if (buffer[z] == '\\') {
|
||||
z++;
|
||||
}
|
||||
if (buffer[z] == '|') {
|
||||
z++;
|
||||
if ((buffer[z] - '0' <= 2 && buffer[z] - '0' >= 0) && (buffer[z+1] - '0' <= 9 && buffer[z+1] - '0' >= 0)) {
|
||||
curr_color = (buffer[z] - '0') * 10 + (buffer[z+1] - '0');
|
||||
z+=2;
|
||||
if ((buffer[z] - '0' <= 2 && buffer[z] - '0' >= 0) && (buffer[z + 1] - '0' <= 9 && buffer[z + 1] - '0' >= 0)) {
|
||||
curr_color = (buffer[z] - '0') * 10 + (buffer[z + 1] - '0');
|
||||
z += 2;
|
||||
} else {
|
||||
z--;
|
||||
}
|
||||
@ -165,23 +164,23 @@ void append_screenbuffer(char *buffer) {
|
||||
if (row_at == 79) {
|
||||
if (line_at == 22) {
|
||||
if (last_space > 0) {
|
||||
for (i=last_space;i<=row_at;i++) {
|
||||
for (i = last_space; i <= row_at; i++) {
|
||||
screenbuffer[line_at][i]->c = '\0';
|
||||
screenbuffer[line_at][i]->color = curr_color;
|
||||
}
|
||||
}
|
||||
scroll_up();
|
||||
row_at = 0;
|
||||
for (i=last_pos+1;i<z;i++) {
|
||||
for (i = last_pos + 1; i < z; i++) {
|
||||
if (buffer[i] == '|') {
|
||||
i++;
|
||||
if ((buffer[i] - '0' <= 2 && buffer[i] - '0' >= 0) && (buffer[i+1] - '0' <= 9 && buffer[i+1] - '0' >= 0)) {
|
||||
curr_color = (buffer[i] - '0') * 10 + (buffer[i+1] - '0');
|
||||
i+=2;
|
||||
if ((buffer[i] - '0' <= 2 && buffer[i] - '0' >= 0) && (buffer[i + 1] - '0' <= 9 && buffer[i + 1] - '0' >= 0)) {
|
||||
curr_color = (buffer[i] - '0') * 10 + (buffer[i + 1] - '0');
|
||||
i += 2;
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i < strlen(buffer)) {
|
||||
screenbuffer[line_at][row_at]->c = buffer[i];
|
||||
screenbuffer[line_at][row_at++]->color = curr_color;
|
||||
@ -191,23 +190,23 @@ void append_screenbuffer(char *buffer) {
|
||||
last_pos = 0;
|
||||
} else {
|
||||
if (last_space > 0) {
|
||||
for (i=last_space;i<=row_at;i++) {
|
||||
for (i = last_space; i <= row_at; i++) {
|
||||
screenbuffer[line_at][i]->c = '\0';
|
||||
screenbuffer[line_at][i]->color = curr_color;
|
||||
}
|
||||
}
|
||||
line_at++;
|
||||
line_at++;
|
||||
row_at = 0;
|
||||
for (i=last_pos+1;i<z;i++) {
|
||||
for (i = last_pos + 1; i < z; i++) {
|
||||
if (buffer[i] == '|') {
|
||||
i++;
|
||||
if ((buffer[i] - '0' <= 2 && buffer[i] - '0' >= 0) && (buffer[i+1] - '0' <= 9 && buffer[i+1] - '0' >= 0)) {
|
||||
curr_color = (buffer[i] - '0') * 10 + (buffer[i+1] - '0');
|
||||
i+=2;
|
||||
if ((buffer[i] - '0' <= 2 && buffer[i] - '0' >= 0) && (buffer[i + 1] - '0' <= 9 && buffer[i + 1] - '0' >= 0)) {
|
||||
curr_color = (buffer[i] - '0') * 10 + (buffer[i + 1] - '0');
|
||||
i += 2;
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i < strlen(buffer)) {
|
||||
screenbuffer[line_at][row_at]->c = buffer[i];
|
||||
screenbuffer[line_at][row_at++]->color = curr_color;
|
||||
@ -261,9 +260,9 @@ void chat_system(struct user_record *user) {
|
||||
int i;
|
||||
int j;
|
||||
int chat_in;
|
||||
jsmn_parser parser;
|
||||
jsmntok_t tokens[8];
|
||||
int r;
|
||||
jsmn_parser parser;
|
||||
jsmntok_t tokens[8];
|
||||
int r;
|
||||
struct chat_msg msg;
|
||||
char *input_b;
|
||||
char *ptr;
|
||||
@ -284,8 +283,6 @@ void chat_system(struct user_record *user) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
row_at = 0;
|
||||
line_at = 0;
|
||||
s_putstring("\e[2J\e[23;1H");
|
||||
@ -299,13 +296,13 @@ void chat_system(struct user_record *user) {
|
||||
if (!inet_pton(AF_INET6, buffer, &servaddr6.sin6_addr)) {
|
||||
chat_connected = 0;
|
||||
} else {
|
||||
servaddr6.sin6_family = AF_INET6;
|
||||
servaddr6.sin6_port = htons(conf.mgchat_port);
|
||||
if ( (chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
|
||||
chat_connected = 0;
|
||||
} else {
|
||||
if (connect(chat_socket, (struct sockaddr*)&servaddr6, sizeof(servaddr6)) < 0 ) {
|
||||
chat_connected = 0;
|
||||
servaddr6.sin6_family = AF_INET6;
|
||||
servaddr6.sin6_port = htons(conf.mgchat_port);
|
||||
if ((chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
|
||||
chat_connected = 0;
|
||||
} else {
|
||||
if (connect(chat_socket, (struct sockaddr *)&servaddr6, sizeof(servaddr6)) < 0) {
|
||||
chat_connected = 0;
|
||||
} else {
|
||||
chat_connected = 1;
|
||||
}
|
||||
@ -315,17 +312,17 @@ void chat_system(struct user_record *user) {
|
||||
chat_connected = 0;
|
||||
}
|
||||
} else {
|
||||
servaddr6.sin6_family = AF_INET6;
|
||||
servaddr6.sin6_family = AF_INET6;
|
||||
servaddr6.sin6_port = htons(conf.mgchat_port);
|
||||
if ( (chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
|
||||
chat_connected = 0;
|
||||
} else {
|
||||
if (connect(chat_socket, (struct sockaddr*)&servaddr6, sizeof(servaddr6)) < 0 ) {
|
||||
chat_connected = 0;
|
||||
if ((chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
|
||||
chat_connected = 0;
|
||||
} else {
|
||||
if (connect(chat_socket, (struct sockaddr *)&servaddr6, sizeof(servaddr6)) < 0) {
|
||||
chat_connected = 0;
|
||||
} else {
|
||||
chat_connected = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,45 +333,43 @@ void chat_system(struct user_record *user) {
|
||||
if (!inet_pton(AF_INET, buffer, &servaddr.sin_addr)) {
|
||||
return;
|
||||
} else {
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(conf.mgchat_port);
|
||||
if ( (chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
return;
|
||||
}
|
||||
if (connect(chat_socket, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0 ) {
|
||||
return;
|
||||
}
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(conf.mgchat_port);
|
||||
if ((chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
return;
|
||||
}
|
||||
if (connect(chat_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(conf.mgchat_port);
|
||||
if ( (chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
return;
|
||||
}
|
||||
if (connect(chat_socket, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0 ) {
|
||||
return;
|
||||
}
|
||||
if ((chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
return;
|
||||
}
|
||||
if (connect(chat_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
memset(buffer, 0, 513);
|
||||
|
||||
screenbuffer = (struct character_t ***)malloc(sizeof(struct character_t **) * 23);
|
||||
for (i=0;i<23;i++) {
|
||||
for (i = 0; i < 23; i++) {
|
||||
screenbuffer[i] = (struct character_t **)malloc(sizeof(struct character_t *) * 80);
|
||||
for (z=0;z<80;z++) {
|
||||
for (z = 0; z < 80; z++) {
|
||||
screenbuffer[i][z] = (struct character_t *)malloc(sizeof(struct character_t));
|
||||
screenbuffer[i][z]->c = '\0';
|
||||
screenbuffer[i][z]->color = 7;
|
||||
}
|
||||
}
|
||||
memset(partmessage, 0, 1024);
|
||||
|
||||
|
||||
raw("{ \"bbs\": \"%s\", \"nick\": \"%s\", \"msg\": \"LOGIN\" }\n", conf.mgchat_bbstag, user->loginname);
|
||||
|
||||
while (1) {
|
||||
@ -397,14 +392,14 @@ void chat_system(struct user_record *user) {
|
||||
close(chat_socket);
|
||||
disconnect("Socket closed");
|
||||
}
|
||||
|
||||
|
||||
usertimeout = 10;
|
||||
|
||||
|
||||
if (c == '\r') {
|
||||
if (inputbuffer[0] == '/') {
|
||||
if (strcasecmp(&inputbuffer[1], "quit") == 0) {
|
||||
close(chat_socket);
|
||||
for (i=0;i<22;i++) {
|
||||
for (i = 0; i < 22; i++) {
|
||||
free(screenbuffer[i]);
|
||||
}
|
||||
free(screenbuffer);
|
||||
@ -437,47 +432,47 @@ void chat_system(struct user_record *user) {
|
||||
len = read(chat_socket, readbuffer, 512);
|
||||
if (len == 0) {
|
||||
s_putstring("\r\n\r\n\r\nLost connection to chat server!\r\n");
|
||||
for (i=0;i<22;i++) {
|
||||
for (i = 0; i < 22; i++) {
|
||||
free(screenbuffer[i]);
|
||||
}
|
||||
free(screenbuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
strncat(partmessage, readbuffer, len);
|
||||
strcpy(readbuffer, partmessage);
|
||||
|
||||
y = 0;
|
||||
for (z = 0;z < strlen(readbuffer); z++) {
|
||||
for (z = 0; z < strlen(readbuffer); z++) {
|
||||
if (readbuffer[z] != '\n') {
|
||||
message[y] = readbuffer[z];
|
||||
message[y+1] = '\0';
|
||||
message[y + 1] = '\0';
|
||||
y++;
|
||||
} else {
|
||||
|
||||
|
||||
y = 0;
|
||||
// json parse
|
||||
jsmn_init(&parser);
|
||||
jsmn_init(&parser);
|
||||
// we got some data from a client
|
||||
r = jsmn_parse(&parser, message, strlen(message), tokens, sizeof(tokens)/sizeof(tokens[0]));
|
||||
|
||||
if ((r < 0) || (r < 1 || tokens[0].type != JSMN_OBJECT)) {
|
||||
r = jsmn_parse(&parser, message, strlen(message), tokens, sizeof(tokens) / sizeof(tokens[0]));
|
||||
|
||||
if ((r < 0) || (r < 1 || tokens[0].type != JSMN_OBJECT)) {
|
||||
// invalid json
|
||||
} else {
|
||||
for (j = 1; j < r; j++) {
|
||||
if (jsoneq(message, &tokens[j], "bbs") == 0) {
|
||||
sprintf(msg.bbstag, "%.*s", tokens[j+1].end-tokens[j+1].start, message + tokens[j+1].start);
|
||||
sprintf(msg.bbstag, "%.*s", tokens[j + 1].end - tokens[j + 1].start, message + tokens[j + 1].start);
|
||||
j++;
|
||||
}
|
||||
if (jsoneq(message, &tokens[j], "nick") == 0) {
|
||||
sprintf(msg.nick, "%.*s", tokens[j+1].end-tokens[j+1].start, message + tokens[j+1].start);
|
||||
sprintf(msg.nick, "%.*s", tokens[j + 1].end - tokens[j + 1].start, message + tokens[j + 1].start);
|
||||
j++;
|
||||
}
|
||||
if (jsoneq(message, &tokens[j], "msg") == 0) {
|
||||
sprintf(msg.msg, "%.*s", tokens[j+1].end-tokens[j+1].start, message + tokens[j+1].start);
|
||||
sprintf(msg.msg, "%.*s", tokens[j + 1].end - tokens[j + 1].start, message + tokens[j + 1].start);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// set outputbuffer
|
||||
if (strcmp(msg.bbstag, "SYSTEM") == 0 && strcmp(msg.nick, "SYSTEM") == 0) {
|
||||
@ -493,11 +488,9 @@ void chat_system(struct user_record *user) {
|
||||
append_screenbuffer(outputbuffer);
|
||||
do_update = 1;
|
||||
|
||||
|
||||
memset(buffer, 0, 513);
|
||||
buffer_at = 0;
|
||||
buffer_at = 0;
|
||||
}
|
||||
|
||||
}
|
||||
if (z < len) {
|
||||
memset(partmessage, 0, 1024);
|
||||
@ -509,8 +502,8 @@ void chat_system(struct user_record *user) {
|
||||
}
|
||||
if (do_update == 1) {
|
||||
s_putstring("\e[2J\e[1;1H");
|
||||
for (i=0;i<=line_at;i++) {
|
||||
for (z = 0;z < 80; z++) {
|
||||
for (i = 0; i <= line_at; i++) {
|
||||
for (z = 0; z < 80; z++) {
|
||||
if (screenbuffer[i][z]->color != last_color) {
|
||||
switch (screenbuffer[i][z]->color) {
|
||||
case 0:
|
||||
@ -572,7 +565,7 @@ void chat_system(struct user_record *user) {
|
||||
}
|
||||
s_printf("\r\n");
|
||||
}
|
||||
for (i=line_at+1;i<22;i++) {
|
||||
for (i = line_at + 1; i < 22; i++) {
|
||||
s_putstring("\r\n");
|
||||
}
|
||||
s_putstring(get_string(50));
|
||||
|
86
src/doors.c
86
src/doors.c
@ -11,13 +11,13 @@
|
||||
#include <fcntl.h>
|
||||
#include <iconv.h>
|
||||
#if defined(linux)
|
||||
# include <pty.h>
|
||||
#include <pty.h>
|
||||
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
|
||||
# include <util.h>
|
||||
#include <util.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
# include <libutil.h>
|
||||
#include <libutil.h>
|
||||
#elif defined(__sun)
|
||||
# include "os/sunos.h"
|
||||
#include "os/sunos.h"
|
||||
#endif
|
||||
#include "bbs.h"
|
||||
#include "lua/lua.h"
|
||||
@ -36,10 +36,10 @@ int running_door = 0;
|
||||
extern int telnet_bin_mode;
|
||||
extern int timeoutpaused;
|
||||
|
||||
void doorchld_handler(int s)
|
||||
{
|
||||
// waitpid() might overwrite errno, so we save and restore it:
|
||||
while(waitpid(-1, NULL, WNOHANG) > 0);
|
||||
void doorchld_handler(int s) {
|
||||
// waitpid() might overwrite errno, so we save and restore it:
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0)
|
||||
;
|
||||
|
||||
running_door = 0;
|
||||
}
|
||||
@ -66,9 +66,9 @@ int write_door32sys(struct user_record *user) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(fptr, "2\r\n"); // telnet type
|
||||
fprintf(fptr, "2\r\n"); // telnet type
|
||||
fprintf(fptr, "%d\r\n", gSocket); // socket
|
||||
fprintf(fptr, "38400\r\n"); // baudrate
|
||||
fprintf(fptr, "38400\r\n"); // baudrate
|
||||
fprintf(fptr, "Magicka %d.%d\r\n", VERSION_MAJOR, VERSION_MINOR);
|
||||
fprintf(fptr, "%d\r\n", user->id);
|
||||
fprintf(fptr, "%s %s\r\n", user->firstname, user->lastname);
|
||||
@ -95,9 +95,9 @@ int write_door32sys(struct user_record *user) {
|
||||
|
||||
ptr = NULL;
|
||||
|
||||
for (i=0;i<strlen(buffer);i++) {
|
||||
for (i = 0; i < strlen(buffer); i++) {
|
||||
if (buffer[i] == ' ') {
|
||||
ptr = &buffer[i+1];
|
||||
ptr = &buffer[i + 1];
|
||||
buffer[i] = '\0';
|
||||
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->timeleft);
|
||||
fprintf(fptr, "-1\r\n");
|
||||
|
||||
|
||||
fclose(fptr);
|
||||
|
||||
// create door.sys
|
||||
@ -173,7 +173,7 @@ int write_door32sys(struct user_record *user) {
|
||||
fprintf(fptr, "none\r\n");
|
||||
fprintf(fptr, "Y\r\n");
|
||||
fprintf(fptr, "N\r\n");
|
||||
fprintf(fptr, "Y\r\n");
|
||||
fprintf(fptr, "Y\r\n");
|
||||
fprintf(fptr, "7\r\n");
|
||||
fprintf(fptr, "0\r\n");
|
||||
fprintf(fptr, "01-01-1971\r\n");
|
||||
@ -192,13 +192,11 @@ int write_door32sys(struct user_record *user) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage) {
|
||||
char *arguments[4];
|
||||
int door_out;
|
||||
char buffer[10];
|
||||
|
||||
|
||||
if (sshBBS) {
|
||||
door_out = STDOUT_FILENO;
|
||||
} else {
|
||||
@ -209,17 +207,17 @@ void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage) {
|
||||
arguments[1] = strdup(buffer);
|
||||
sprintf(buffer, "%d", door_out);
|
||||
arguments[2] = strdup(buffer);
|
||||
arguments[3] = NULL;
|
||||
|
||||
arguments[3] = NULL;
|
||||
|
||||
runexternal(user, cmd, stdio, arguments, NULL, 0, codepage);
|
||||
|
||||
|
||||
free(arguments[0]);
|
||||
free(arguments[1]);
|
||||
free(arguments[2]);
|
||||
}
|
||||
|
||||
void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], char *cwd, int raw, char *codepage) {
|
||||
|
||||
|
||||
char buffer[1024];
|
||||
int ret;
|
||||
unsigned char c;
|
||||
@ -276,8 +274,6 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
door_out = gSocket;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ws.ws_row = 24;
|
||||
ws.ws_col = 80;
|
||||
|
||||
@ -306,8 +302,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
close(master);
|
||||
|
||||
dup2(slave, 0);
|
||||
dup2(slave, 1);
|
||||
|
||||
dup2(slave, 1);
|
||||
|
||||
close(slave);
|
||||
|
||||
setsid();
|
||||
@ -319,8 +315,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
running_door_pid = pid;
|
||||
gotiac = 0;
|
||||
flush = 0;
|
||||
|
||||
while(running_door || !flush) {
|
||||
|
||||
while (running_door || !flush) {
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(master, &fdset);
|
||||
FD_SET(door_in, &fdset);
|
||||
@ -329,10 +325,10 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
} else {
|
||||
t = door_in + 1;
|
||||
}
|
||||
|
||||
|
||||
thetimeout.tv_sec = 5;
|
||||
thetimeout.tv_usec = 0;
|
||||
|
||||
|
||||
ret = select(t, &fdset, NULL, NULL, &thetimeout);
|
||||
if (ret > 0) {
|
||||
if (FD_ISSET(door_in, &fdset)) {
|
||||
@ -343,7 +339,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
return;
|
||||
}
|
||||
g = 0;
|
||||
for (h=0;h<len;h++) {
|
||||
for (h = 0; h < len; h++) {
|
||||
c = inbuf[h];
|
||||
if (!raw) {
|
||||
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;
|
||||
write(master, iac_binary_do, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IAC_WONT:
|
||||
if (c == 0) {
|
||||
@ -387,7 +383,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
telnet_bin_mode = 0;
|
||||
write(master, iac_binary_dont, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IAC_DO:
|
||||
if (c == 0) {
|
||||
@ -403,8 +399,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
telnet_bin_mode = 0;
|
||||
write(master, iac_binary_wont, 3);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
gotiac = 0;
|
||||
} else if (gotiac == 3) {
|
||||
@ -444,12 +440,12 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
break;
|
||||
}
|
||||
g = 0;
|
||||
for (h=0;h<len;h++) {
|
||||
for (h = 0; h < len; h++) {
|
||||
c = inbuf[h];
|
||||
if (c == 255) {
|
||||
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)) {
|
||||
write(door_out, outbuf, g);
|
||||
@ -472,7 +468,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
}
|
||||
write(door_out, ptr2p, ptr2 - ptr2p);
|
||||
|
||||
free(ptr2p);
|
||||
free(ptr2p);
|
||||
iconv_close(ic);
|
||||
}
|
||||
}
|
||||
@ -482,16 +478,16 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
if (raw) {
|
||||
ttySetRaw(STDIN_FILENO, &oldit);
|
||||
ttySetRaw(STDOUT_FILENO, &oldot);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sa.sa_handler = doorchld_handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
@ -510,11 +506,11 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
dup2(bbs_stderr, 2);
|
||||
execvp(cmd, argv);
|
||||
} else {
|
||||
while(running_door) {
|
||||
while (running_door) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (raw) {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldit);
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &oldot);
|
||||
@ -523,13 +519,13 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
} else {
|
||||
if (!sshBBS) {
|
||||
snprintf(buffer, 1024, "%s", cmd);
|
||||
for (i=1;argv[i] != NULL; i++) {
|
||||
for (i = 1; argv[i] != NULL; i++) {
|
||||
snprintf(&buffer[strlen(buffer)], 1024 - strlen(buffer), " %s", argv[i]);
|
||||
}
|
||||
if (cwd != NULL) {
|
||||
chdir(cwd);
|
||||
}
|
||||
args = (char **)malloc(sizeof (char *));
|
||||
args = (char **)malloc(sizeof(char *));
|
||||
arg_count = 0;
|
||||
args[arg_count] = strtok(buffer, " ");
|
||||
while (args[arg_count] != NULL) {
|
||||
|
304
src/email.c
304
src/email.c
@ -22,22 +22,22 @@ void commit_email(char *recipient, char *subject, char *msg) {
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int rc;
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
|
||||
char *err_msg = 0;
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/email.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return;
|
||||
@ -45,7 +45,7 @@ void commit_email(char *recipient, char *subject, char *msg) {
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
dolog("SQL error: %s", err_msg);
|
||||
|
||||
@ -78,10 +78,9 @@ void commit_email(char *recipient, char *subject, char *msg) {
|
||||
void send_email(struct user_record *user) {
|
||||
char buffer[26];
|
||||
|
||||
char *recipient;
|
||||
char *subject;
|
||||
char *msg;
|
||||
|
||||
char *recipient;
|
||||
char *subject;
|
||||
char *msg;
|
||||
|
||||
s_printf(get_string(54));
|
||||
s_readstring(buffer, 16);
|
||||
@ -112,13 +111,13 @@ void send_email(struct user_record *user) {
|
||||
commit_email(recipient, subject, msg);
|
||||
free(msg);
|
||||
}
|
||||
free(subject);
|
||||
free(recipient);
|
||||
free(subject);
|
||||
free(recipient);
|
||||
}
|
||||
|
||||
void show_email(struct user_record *user, int msgno, int email_count, struct email_msg **emails) {
|
||||
char buffer[256];
|
||||
sqlite3 *db;
|
||||
char buffer[256];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *dsql = "DELETE FROM email WHERE id=?";
|
||||
@ -155,101 +154,100 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
|
||||
|
||||
lines = 0;
|
||||
chars = 0;
|
||||
|
||||
|
||||
msg_line_count = 0;
|
||||
start_line = 0;
|
||||
|
||||
// count the number of lines...
|
||||
for (z=0;z<strlen(emails[msgno]->body);z++) {
|
||||
if (emails[msgno]->body[z] == '\r' || chars == 79) {
|
||||
if (msg_line_count == 0) {
|
||||
msg_lines = (char **)malloc(sizeof(char *));
|
||||
} else {
|
||||
msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1));
|
||||
}
|
||||
|
||||
msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1));
|
||||
|
||||
if (z == start_line) {
|
||||
msg_lines[msg_line_count][0] = '\0';
|
||||
} else {
|
||||
strncpy(msg_lines[msg_line_count], &emails[msgno]->body[start_line], z - start_line);
|
||||
msg_lines[msg_line_count][z-start_line] = '\0';
|
||||
}
|
||||
msg_line_count++;
|
||||
if (emails[msgno]->body[z] == '\r') {
|
||||
start_line = z + 1;
|
||||
} else {
|
||||
start_line = z;
|
||||
}
|
||||
chars = 0;
|
||||
} else {
|
||||
chars ++;
|
||||
}
|
||||
}
|
||||
|
||||
lines = 0;
|
||||
|
||||
position = 0;
|
||||
should_break = 0;
|
||||
|
||||
while (!should_break) {
|
||||
s_printf("\e[5;1H");
|
||||
for (z=position;z<msg_line_count;z++) {
|
||||
|
||||
s_printf("%s\e[K\r\n", msg_lines[z]);
|
||||
|
||||
if (z - position >= 17) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
s_printf(get_string(187));
|
||||
s_printf(get_string(191));
|
||||
c = s_getchar();
|
||||
|
||||
if (tolower(c) == 'r') {
|
||||
should_break = 1;
|
||||
} else if (tolower(c) == 'q') {
|
||||
should_break = 1;
|
||||
quit = 1;
|
||||
|
||||
msg_line_count = 0;
|
||||
start_line = 0;
|
||||
|
||||
// count the number of lines...
|
||||
for (z = 0; z < strlen(emails[msgno]->body); z++) {
|
||||
if (emails[msgno]->body[z] == '\r' || chars == 79) {
|
||||
if (msg_line_count == 0) {
|
||||
msg_lines = (char **)malloc(sizeof(char *));
|
||||
} else {
|
||||
msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1));
|
||||
}
|
||||
|
||||
msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1));
|
||||
|
||||
if (z == start_line) {
|
||||
msg_lines[msg_line_count][0] = '\0';
|
||||
} else {
|
||||
strncpy(msg_lines[msg_line_count], &emails[msgno]->body[start_line], z - start_line);
|
||||
msg_lines[msg_line_count][z - start_line] = '\0';
|
||||
}
|
||||
msg_line_count++;
|
||||
if (emails[msgno]->body[z] == '\r') {
|
||||
start_line = z + 1;
|
||||
} else {
|
||||
start_line = z;
|
||||
}
|
||||
chars = 0;
|
||||
} else {
|
||||
chars++;
|
||||
}
|
||||
}
|
||||
|
||||
lines = 0;
|
||||
|
||||
position = 0;
|
||||
should_break = 0;
|
||||
|
||||
while (!should_break) {
|
||||
s_printf("\e[5;1H");
|
||||
for (z = position; z < msg_line_count; z++) {
|
||||
|
||||
s_printf("%s\e[K\r\n", msg_lines[z]);
|
||||
|
||||
if (z - position >= 17) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
s_printf(get_string(187));
|
||||
s_printf(get_string(191));
|
||||
c = s_getchar();
|
||||
|
||||
if (tolower(c) == 'r') {
|
||||
should_break = 1;
|
||||
} else if (tolower(c) == 'q') {
|
||||
should_break = 1;
|
||||
quit = 1;
|
||||
} else if (tolower(c) == 'd') {
|
||||
should_break = 1;
|
||||
} else if (c == '\e') {
|
||||
c = s_getchar();
|
||||
if (c == 91) {
|
||||
c = s_getchar();
|
||||
if (c == 65) {
|
||||
position--;
|
||||
if (position < 0) {
|
||||
position = 0;
|
||||
}
|
||||
} else if (c == 66) {
|
||||
position++;
|
||||
if (position + 17 >= msg_line_count) {
|
||||
position--;
|
||||
}
|
||||
} else if (c == 67) {
|
||||
} else if (c == '\e') {
|
||||
c = s_getchar();
|
||||
if (c == 91) {
|
||||
c = s_getchar();
|
||||
if (c == 65) {
|
||||
position--;
|
||||
if (position < 0) {
|
||||
position = 0;
|
||||
}
|
||||
} else if (c == 66) {
|
||||
position++;
|
||||
if (position + 17 >= msg_line_count) {
|
||||
position--;
|
||||
}
|
||||
} else if (c == 67) {
|
||||
c = ' ';
|
||||
should_break = 1;
|
||||
} else if (c == 68) {
|
||||
c = 'b';
|
||||
should_break = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < msg_line_count; i++) {
|
||||
free(msg_lines[i]);
|
||||
}
|
||||
free(msg_lines);
|
||||
msg_line_count = 0;
|
||||
|
||||
for (i=0;i<msg_line_count;i++) {
|
||||
free(msg_lines[i]);
|
||||
}
|
||||
free(msg_lines);
|
||||
msg_line_count = 0;
|
||||
|
||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
@ -271,7 +269,6 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
|
||||
if (tolower(c) == 'r') {
|
||||
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);
|
||||
if (replybody != NULL) {
|
||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
@ -329,7 +326,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
|
||||
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
@ -341,12 +338,12 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
|
||||
return;
|
||||
}
|
||||
sqlite3_step(res);
|
||||
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
quit = 1;
|
||||
} else if (tolower(c) == ' ') {
|
||||
msgno ++;
|
||||
msgno++;
|
||||
if (msgno == email_count) {
|
||||
quit = 1;
|
||||
}
|
||||
@ -356,7 +353,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
|
||||
quit = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void list_emails(struct user_record *user) {
|
||||
@ -380,8 +377,8 @@ void list_emails(struct user_record *user) {
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
@ -406,9 +403,9 @@ void list_emails(struct user_record *user) {
|
||||
} else {
|
||||
emails = (struct email_msg **)realloc(emails, sizeof(struct email_msg *) * (email_count + 1));
|
||||
}
|
||||
|
||||
|
||||
emails[email_count] = (struct email_msg *)malloc(sizeof(struct email_msg));
|
||||
|
||||
|
||||
emails[email_count]->from = strdup((char *)sqlite3_column_text(res, 0));
|
||||
emails[email_count]->subject = strdup((char *)sqlite3_column_text(res, 1));
|
||||
emails[email_count]->seen = sqlite3_column_int(res, 2);
|
||||
@ -417,49 +414,49 @@ void list_emails(struct user_record *user) {
|
||||
emails[email_count]->id = sqlite3_column_int(res, 5);
|
||||
email_count++;
|
||||
}
|
||||
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
|
||||
if (email_count == 0) {
|
||||
s_printf(get_string(194));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
redraw = 1;
|
||||
start = 0;
|
||||
position = 0;
|
||||
while (!closed) {
|
||||
if (redraw) {
|
||||
s_printf(get_string(126));
|
||||
for (i=start;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);
|
||||
if (i == position) {
|
||||
if (!emails[i]->seen) {
|
||||
if (conf.date_style == 1) {
|
||||
s_printf(get_string(192), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
s_printf(get_string(192), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
} else {
|
||||
s_printf(get_string(192), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
s_printf(get_string(192), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
} else {
|
||||
if (conf.date_style == 1) {
|
||||
s_printf(get_string(193), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
s_printf(get_string(193), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
} else {
|
||||
s_printf(get_string(193), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
s_printf(get_string(193), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!emails[i]->seen) {
|
||||
if (conf.date_style == 1) {
|
||||
s_printf(get_string(64), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
s_printf(get_string(64), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
} else {
|
||||
s_printf(get_string(64), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
s_printf(get_string(64), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
} else {
|
||||
if (conf.date_style == 1) {
|
||||
s_printf(get_string(65), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
s_printf(get_string(65), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
} else {
|
||||
s_printf(get_string(65), i + 1, emails[i]->subject, emails[i]->from,msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
s_printf(get_string(65), i + 1, emails[i]->subject, emails[i]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -490,20 +487,20 @@ void list_emails(struct user_record *user) {
|
||||
s_printf("\e[%d;5H", position - start + 2);
|
||||
} else if (!redraw) {
|
||||
s_printf("\e[%d;1H", position - start + 1);
|
||||
localtime_r((time_t *)&emails[position-1]->date, &msg_date);
|
||||
localtime_r((time_t *)&emails[position - 1]->date, &msg_date);
|
||||
if (!emails[position - 1]->seen) {
|
||||
if (conf.date_style == 1) {
|
||||
s_printf(get_string(64), position, emails[position-1]->subject, emails[position-1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
s_printf(get_string(64), position, emails[position - 1]->subject, emails[position - 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
} else {
|
||||
s_printf(get_string(64), position, emails[position-1]->subject, emails[position-1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
s_printf(get_string(64), position, emails[position - 1]->subject, emails[position - 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
} else {
|
||||
if (conf.date_style == 1) {
|
||||
s_printf(get_string(65), position, emails[position-1]->subject, emails[position-1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
s_printf(get_string(65), position, emails[position - 1]->subject, emails[position - 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100);
|
||||
} else {
|
||||
s_printf(get_string(65), position, emails[position-1]->subject, emails[position-1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
s_printf(get_string(65), position, emails[position - 1]->subject, emails[position - 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
s_printf("\e[%d;1H", position - start + 2);
|
||||
localtime_r((time_t *)&emails[position]->date, &msg_date);
|
||||
if (!emails[position]->seen) {
|
||||
@ -518,14 +515,14 @@ void list_emails(struct user_record *user) {
|
||||
} else {
|
||||
s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
s_printf("\e[%d;5H", position - start + 2);
|
||||
}
|
||||
} else if (c == 65) {
|
||||
// up
|
||||
position--;
|
||||
if (position < start) {
|
||||
start -=22;
|
||||
start -= 22;
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
@ -550,7 +547,7 @@ void list_emails(struct user_record *user) {
|
||||
} else {
|
||||
s_printf(get_string(65), position + 2, emails[position + 1]->subject, emails[position + 1]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
s_printf("\e[%d;1H", position - start + 2);
|
||||
localtime_r((time_t *)&emails[position]->date, &msg_date);
|
||||
if (!emails[position]->seen) {
|
||||
@ -565,9 +562,9 @@ void list_emails(struct user_record *user) {
|
||||
} else {
|
||||
s_printf(get_string(193), position + 1, emails[position]->subject, emails[position]->from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
s_printf("\e[%d;5H", position - start + 3);
|
||||
}
|
||||
}
|
||||
} else if (c == 75) {
|
||||
// END KEY
|
||||
position = email_count - 1;
|
||||
@ -599,7 +596,7 @@ void list_emails(struct user_record *user) {
|
||||
// PAGE DOWN
|
||||
position = position + 22;
|
||||
if (position >= email_count) {
|
||||
position = email_count -1;
|
||||
position = email_count - 1;
|
||||
}
|
||||
start = position;
|
||||
redraw = 1;
|
||||
@ -609,9 +606,9 @@ void list_emails(struct user_record *user) {
|
||||
closed = 1;
|
||||
show_email(user, position, email_count, emails);
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<email_count;i++) {
|
||||
}
|
||||
|
||||
for (i = 0; i < email_count; i++) {
|
||||
free(emails[i]->from);
|
||||
free(emails[i]->subject);
|
||||
free(emails[i]->body);
|
||||
@ -620,40 +617,39 @@ void list_emails(struct user_record *user) {
|
||||
free(emails);
|
||||
}
|
||||
|
||||
|
||||
int mail_getemailcount(struct user_record *user) {
|
||||
char *sql = "SELECT COUNT(*) FROM email WHERE recipient LIKE ?";
|
||||
int count;
|
||||
char buffer[256];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
|
||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
count = 0;
|
||||
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
count = sqlite3_column_int(res, 0);
|
||||
}
|
||||
|
||||
|
544
src/files.c
544
src/files.c
File diff suppressed because it is too large
Load Diff
@ -11,15 +11,15 @@
|
||||
#define MAX_CHAIN_LENGTH (8)
|
||||
|
||||
/* We need to keep keys and values */
|
||||
typedef struct _hashmap_element{
|
||||
char* key;
|
||||
typedef struct _hashmap_element {
|
||||
char *key;
|
||||
int in_use;
|
||||
any_t data;
|
||||
} hashmap_element;
|
||||
|
||||
/* A hashmap has some maximum size and current size,
|
||||
* as well as the data to hold. */
|
||||
typedef struct _hashmap_map{
|
||||
typedef struct _hashmap_map {
|
||||
int table_size;
|
||||
int size;
|
||||
hashmap_element *data;
|
||||
@ -29,144 +29,141 @@ typedef struct _hashmap_map{
|
||||
* Return an empty hashmap, or NULL on failure.
|
||||
*/
|
||||
map_t hashmap_new() {
|
||||
hashmap_map* m = (hashmap_map*) malloc(sizeof(hashmap_map));
|
||||
if(!m) goto err;
|
||||
hashmap_map *m = (hashmap_map *)malloc(sizeof(hashmap_map));
|
||||
if (!m) goto err;
|
||||
|
||||
m->data = (hashmap_element*) calloc(INITIAL_SIZE, sizeof(hashmap_element));
|
||||
if(!m->data) goto err;
|
||||
m->data = (hashmap_element *)calloc(INITIAL_SIZE, sizeof(hashmap_element));
|
||||
if (!m->data) goto err;
|
||||
|
||||
m->table_size = INITIAL_SIZE;
|
||||
m->size = 0;
|
||||
|
||||
return m;
|
||||
err:
|
||||
if (m)
|
||||
hashmap_free(m);
|
||||
return NULL;
|
||||
err:
|
||||
if (m)
|
||||
hashmap_free(m);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The implementation here was originally done by Gary S. Brown. I have
|
||||
borrowed the tables directly, and made some minor changes to the
|
||||
crc32-function (including changing the interface). //ylo */
|
||||
|
||||
/* ============================================================= */
|
||||
/* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or */
|
||||
/* code or tables extracted from it, as desired without restriction. */
|
||||
/* */
|
||||
/* First, the polynomial itself and its table of feedback terms. The */
|
||||
/* polynomial is */
|
||||
/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
|
||||
/* */
|
||||
/* Note that we take it "backwards" and put the highest-order term in */
|
||||
/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */
|
||||
/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */
|
||||
/* the MSB being 1. */
|
||||
/* */
|
||||
/* Note that the usual hardware shift register implementation, which */
|
||||
/* is what we're using (we're merely optimizing it by doing eight-bit */
|
||||
/* chunks at a time) shifts bits into the lowest-order term. In our */
|
||||
/* implementation, that means shifting towards the right. Why do we */
|
||||
/* do it this way? Because the calculated CRC must be transmitted in */
|
||||
/* order from highest-order term to lowest-order term. UARTs transmit */
|
||||
/* characters in order from LSB to MSB. By storing the CRC this way, */
|
||||
/* we hand it to the UART in the order low-byte to high-byte; the UART */
|
||||
/* sends each low-bit to hight-bit; and the result is transmission bit */
|
||||
/* by bit from highest- to lowest-order term without requiring any bit */
|
||||
/* shuffling on our part. Reception works similarly. */
|
||||
/* */
|
||||
/* The feedback terms table consists of 256, 32-bit entries. Notes: */
|
||||
/* */
|
||||
/* The table can be generated at runtime if desired; code to do so */
|
||||
/* is shown later. It might not be obvious, but the feedback */
|
||||
/* terms simply represent the results of eight shift/xor opera- */
|
||||
/* tions for all combinations of data and CRC register values. */
|
||||
/* */
|
||||
/* The values must be right-shifted by eight bits by the "updcrc" */
|
||||
/* logic; the shift must be unsigned (bring in zeroes). On some */
|
||||
/* hardware you could probably optimize the shift in assembler by */
|
||||
/* using byte-swap instructions. */
|
||||
/* polynomial $edb88320 */
|
||||
/* */
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* ============================================================= */
|
||||
/* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or */
|
||||
/* code or tables extracted from it, as desired without restriction. */
|
||||
/* */
|
||||
/* First, the polynomial itself and its table of feedback terms. The */
|
||||
/* polynomial is */
|
||||
/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
|
||||
/* */
|
||||
/* Note that we take it "backwards" and put the highest-order term in */
|
||||
/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */
|
||||
/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */
|
||||
/* the MSB being 1. */
|
||||
/* */
|
||||
/* Note that the usual hardware shift register implementation, which */
|
||||
/* is what we're using (we're merely optimizing it by doing eight-bit */
|
||||
/* chunks at a time) shifts bits into the lowest-order term. In our */
|
||||
/* implementation, that means shifting towards the right. Why do we */
|
||||
/* do it this way? Because the calculated CRC must be transmitted in */
|
||||
/* order from highest-order term to lowest-order term. UARTs transmit */
|
||||
/* characters in order from LSB to MSB. By storing the CRC this way, */
|
||||
/* we hand it to the UART in the order low-byte to high-byte; the UART */
|
||||
/* sends each low-bit to hight-bit; and the result is transmission bit */
|
||||
/* by bit from highest- to lowest-order term without requiring any bit */
|
||||
/* shuffling on our part. Reception works similarly. */
|
||||
/* */
|
||||
/* The feedback terms table consists of 256, 32-bit entries. Notes: */
|
||||
/* */
|
||||
/* The table can be generated at runtime if desired; code to do so */
|
||||
/* is shown later. It might not be obvious, but the feedback */
|
||||
/* terms simply represent the results of eight shift/xor opera- */
|
||||
/* tions for all combinations of data and CRC register values. */
|
||||
/* */
|
||||
/* The values must be right-shifted by eight bits by the "updcrc" */
|
||||
/* logic; the shift must be unsigned (bring in zeroes). On some */
|
||||
/* hardware you could probably optimize the shift in assembler by */
|
||||
/* using byte-swap instructions. */
|
||||
/* polynomial $edb88320 */
|
||||
/* */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static unsigned long crc32_tab[] = {
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
|
||||
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
|
||||
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
|
||||
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
|
||||
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
|
||||
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
|
||||
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
|
||||
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
|
||||
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
|
||||
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
|
||||
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
|
||||
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
|
||||
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
|
||||
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
|
||||
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
|
||||
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
|
||||
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
|
||||
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
|
||||
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
|
||||
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
|
||||
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
|
||||
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
|
||||
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
|
||||
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
|
||||
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
|
||||
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
|
||||
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
|
||||
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
|
||||
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
|
||||
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
|
||||
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
|
||||
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
|
||||
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
|
||||
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
|
||||
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
|
||||
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
|
||||
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
|
||||
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
|
||||
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
|
||||
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
|
||||
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
|
||||
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
|
||||
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
|
||||
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
|
||||
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
|
||||
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
|
||||
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
|
||||
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
|
||||
0x2d02ef8dL
|
||||
};
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
|
||||
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
|
||||
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
|
||||
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
|
||||
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
|
||||
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
|
||||
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
|
||||
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
|
||||
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
|
||||
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
|
||||
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
|
||||
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
|
||||
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
|
||||
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
|
||||
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
|
||||
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
|
||||
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
|
||||
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
|
||||
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
|
||||
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
|
||||
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
|
||||
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
|
||||
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
|
||||
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
|
||||
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
|
||||
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
|
||||
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
|
||||
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
|
||||
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
|
||||
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
|
||||
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
|
||||
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
|
||||
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
|
||||
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
|
||||
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
|
||||
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
|
||||
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
|
||||
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
|
||||
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
|
||||
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
|
||||
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
|
||||
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
|
||||
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
|
||||
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
|
||||
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
|
||||
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
|
||||
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
|
||||
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
|
||||
0x2d02ef8dL};
|
||||
|
||||
/* Return a 32-bit CRC of the contents of the buffer. */
|
||||
|
||||
unsigned long crc32(const unsigned char *s, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned long crc32val;
|
||||
|
||||
crc32val = 0;
|
||||
for (i = 0; i < len; i ++)
|
||||
{
|
||||
crc32val =
|
||||
crc32_tab[(crc32val ^ s[i]) & 0xff] ^
|
||||
(crc32val >> 8);
|
||||
}
|
||||
return crc32val;
|
||||
unsigned long crc32(const unsigned char *s, unsigned int len) {
|
||||
unsigned int i;
|
||||
unsigned long crc32val;
|
||||
|
||||
crc32val = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
crc32val =
|
||||
crc32_tab[(crc32val ^ s[i]) & 0xff] ^
|
||||
(crc32val >> 8);
|
||||
}
|
||||
return crc32val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Hashing function for a string
|
||||
*/
|
||||
unsigned int hashmap_hash_int(hashmap_map * m, char* keystring){
|
||||
unsigned int hashmap_hash_int(hashmap_map *m, char *keystring) {
|
||||
|
||||
unsigned long key = crc32((unsigned char*)(keystring), strlen(keystring));
|
||||
unsigned long key = crc32((unsigned char *)(keystring), strlen(keystring));
|
||||
|
||||
/* Robert Jenkins' 32 bit Mix Function */
|
||||
key += (key << 12);
|
||||
@ -188,25 +185,25 @@ unsigned int hashmap_hash_int(hashmap_map * m, char* keystring){
|
||||
* Return the integer of the location in data
|
||||
* to store the point to the item, or MAP_FULL.
|
||||
*/
|
||||
int hashmap_hash(map_t in, char* key){
|
||||
int hashmap_hash(map_t in, char *key) {
|
||||
int curr;
|
||||
int i;
|
||||
|
||||
/* Cast the hashmap */
|
||||
hashmap_map* m = (hashmap_map *) in;
|
||||
hashmap_map *m = (hashmap_map *)in;
|
||||
|
||||
/* If full, return immediately */
|
||||
if(m->size >= (m->table_size/2)) return MAP_FULL;
|
||||
if (m->size >= (m->table_size / 2)) return MAP_FULL;
|
||||
|
||||
/* Find the best index */
|
||||
curr = hashmap_hash_int(m, key);
|
||||
|
||||
/* Linear probing */
|
||||
for(i = 0; i< MAX_CHAIN_LENGTH; i++){
|
||||
if(m->data[curr].in_use == 0)
|
||||
for (i = 0; i < MAX_CHAIN_LENGTH; i++) {
|
||||
if (m->data[curr].in_use == 0)
|
||||
return curr;
|
||||
|
||||
if(m->data[curr].in_use == 1 && (strcmp(m->data[curr].key,key)==0))
|
||||
if (m->data[curr].in_use == 1 && (strcmp(m->data[curr].key, key) == 0))
|
||||
return curr;
|
||||
|
||||
curr = (curr + 1) % m->table_size;
|
||||
@ -218,16 +215,16 @@ int hashmap_hash(map_t in, char* key){
|
||||
/*
|
||||
* Doubles the size of the hashmap, and rehashes all the elements
|
||||
*/
|
||||
int hashmap_rehash(map_t in){
|
||||
int hashmap_rehash(map_t in) {
|
||||
int i;
|
||||
int old_size;
|
||||
hashmap_element* curr;
|
||||
hashmap_element *curr;
|
||||
|
||||
/* Setup the new elements */
|
||||
hashmap_map *m = (hashmap_map *) in;
|
||||
hashmap_element* temp = (hashmap_element *)
|
||||
calloc(2 * m->table_size, sizeof(hashmap_element));
|
||||
if(!temp) return MAP_OMEM;
|
||||
hashmap_map *m = (hashmap_map *)in;
|
||||
hashmap_element *temp = (hashmap_element *)
|
||||
calloc(2 * m->table_size, sizeof(hashmap_element));
|
||||
if (!temp) return MAP_OMEM;
|
||||
|
||||
/* Update the array */
|
||||
curr = m->data;
|
||||
@ -239,12 +236,12 @@ int hashmap_rehash(map_t in){
|
||||
m->size = 0;
|
||||
|
||||
/* Rehash the elements */
|
||||
for(i = 0; i < old_size; i++){
|
||||
int status;
|
||||
for (i = 0; i < old_size; i++) {
|
||||
int status;
|
||||
|
||||
if (curr[i].in_use == 0)
|
||||
continue;
|
||||
|
||||
if (curr[i].in_use == 0)
|
||||
continue;
|
||||
|
||||
status = hashmap_put(m, curr[i].key, curr[i].data);
|
||||
if (status != MAP_OK)
|
||||
return status;
|
||||
@ -258,16 +255,16 @@ int hashmap_rehash(map_t in){
|
||||
/*
|
||||
* Add a pointer to the hashmap with some key
|
||||
*/
|
||||
int hashmap_put(map_t in, char* key, any_t value){
|
||||
int hashmap_put(map_t in, char *key, any_t value) {
|
||||
int index;
|
||||
hashmap_map* m;
|
||||
hashmap_map *m;
|
||||
|
||||
/* Cast the hashmap */
|
||||
m = (hashmap_map *) in;
|
||||
m = (hashmap_map *)in;
|
||||
|
||||
/* Find a place to put our value */
|
||||
index = hashmap_hash(in, key);
|
||||
while(index == MAP_FULL){
|
||||
while (index == MAP_FULL) {
|
||||
if (hashmap_rehash(in) == MAP_OMEM) {
|
||||
return MAP_OMEM;
|
||||
}
|
||||
@ -278,7 +275,7 @@ int hashmap_put(map_t in, char* key, any_t value){
|
||||
m->data[index].data = value;
|
||||
m->data[index].key = key;
|
||||
m->data[index].in_use = 1;
|
||||
m->size++;
|
||||
m->size++;
|
||||
|
||||
return MAP_OK;
|
||||
}
|
||||
@ -286,26 +283,26 @@ int hashmap_put(map_t in, char* key, any_t value){
|
||||
/*
|
||||
* Get your pointer out of the hashmap with a key
|
||||
*/
|
||||
int hashmap_get(map_t in, char* key, any_t *arg){
|
||||
int hashmap_get(map_t in, char *key, any_t *arg) {
|
||||
int curr;
|
||||
int i;
|
||||
hashmap_map* m;
|
||||
hashmap_map *m;
|
||||
|
||||
/* Cast the hashmap */
|
||||
m = (hashmap_map *) in;
|
||||
m = (hashmap_map *)in;
|
||||
|
||||
/* Find data location */
|
||||
curr = hashmap_hash_int(m, key);
|
||||
|
||||
/* Linear probing, if necessary */
|
||||
for(i = 0; i<MAX_CHAIN_LENGTH; i++){
|
||||
for (i = 0; i < MAX_CHAIN_LENGTH; i++) {
|
||||
|
||||
int in_use = m->data[curr].in_use;
|
||||
if (in_use == 1){
|
||||
if (strcmp(m->data[curr].key,key)==0){
|
||||
*arg = (m->data[curr].data);
|
||||
return MAP_OK;
|
||||
}
|
||||
int in_use = m->data[curr].in_use;
|
||||
if (in_use == 1) {
|
||||
if (strcmp(m->data[curr].key, key) == 0) {
|
||||
*arg = (m->data[curr].data);
|
||||
return MAP_OK;
|
||||
}
|
||||
}
|
||||
|
||||
curr = (curr + 1) % m->table_size;
|
||||
@ -326,54 +323,54 @@ int hashmap_iterate(map_t in, PFany f, any_t item) {
|
||||
int i;
|
||||
|
||||
/* Cast the hashmap */
|
||||
hashmap_map* m = (hashmap_map*) in;
|
||||
hashmap_map *m = (hashmap_map *)in;
|
||||
|
||||
/* On empty hashmap, return immediately */
|
||||
if (hashmap_length(m) <= 0)
|
||||
return MAP_MISSING;
|
||||
return MAP_MISSING;
|
||||
|
||||
/* Linear probing */
|
||||
for(i = 0; i< m->table_size; i++)
|
||||
if(m->data[i].in_use != 0) {
|
||||
any_t data = (any_t) (m->data[i].data);
|
||||
for (i = 0; i < m->table_size; i++)
|
||||
if (m->data[i].in_use != 0) {
|
||||
any_t data = (any_t)(m->data[i].data);
|
||||
int status = f(item, data);
|
||||
if (status != MAP_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return MAP_OK;
|
||||
return MAP_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove an element with that key from the map
|
||||
*/
|
||||
int hashmap_remove(map_t in, char* key){
|
||||
int hashmap_remove(map_t in, char *key) {
|
||||
int i;
|
||||
int curr;
|
||||
hashmap_map* m;
|
||||
hashmap_map *m;
|
||||
|
||||
/* Cast the hashmap */
|
||||
m = (hashmap_map *) in;
|
||||
m = (hashmap_map *)in;
|
||||
|
||||
/* Find key */
|
||||
curr = hashmap_hash_int(m, key);
|
||||
|
||||
/* Linear probing, if necessary */
|
||||
for(i = 0; i<MAX_CHAIN_LENGTH; i++){
|
||||
for (i = 0; i < MAX_CHAIN_LENGTH; i++) {
|
||||
|
||||
int in_use = m->data[curr].in_use;
|
||||
if (in_use == 1){
|
||||
if (strcmp(m->data[curr].key,key)==0){
|
||||
/* Blank out the fields */
|
||||
m->data[curr].in_use = 0;
|
||||
m->data[curr].data = NULL;
|
||||
m->data[curr].key = NULL;
|
||||
int in_use = m->data[curr].in_use;
|
||||
if (in_use == 1) {
|
||||
if (strcmp(m->data[curr].key, key) == 0) {
|
||||
/* Blank out the fields */
|
||||
m->data[curr].in_use = 0;
|
||||
m->data[curr].data = NULL;
|
||||
m->data[curr].key = NULL;
|
||||
|
||||
/* Reduce the size */
|
||||
m->size--;
|
||||
return MAP_OK;
|
||||
}
|
||||
/* Reduce the size */
|
||||
m->size--;
|
||||
return MAP_OK;
|
||||
}
|
||||
}
|
||||
curr = (curr + 1) % m->table_size;
|
||||
}
|
||||
@ -383,15 +380,17 @@ int hashmap_remove(map_t in, char* key){
|
||||
}
|
||||
|
||||
/* Deallocate the hashmap */
|
||||
void hashmap_free(map_t in){
|
||||
hashmap_map* m = (hashmap_map*) in;
|
||||
void hashmap_free(map_t in) {
|
||||
hashmap_map *m = (hashmap_map *)in;
|
||||
free(m->data);
|
||||
free(m);
|
||||
}
|
||||
|
||||
/* Return the length of the hashmap */
|
||||
int hashmap_length(map_t in){
|
||||
hashmap_map* m = (hashmap_map *) in;
|
||||
if(m != NULL) return m->size;
|
||||
else return 0;
|
||||
int hashmap_length(map_t in) {
|
||||
hashmap_map *m = (hashmap_map *)in;
|
||||
if (m != NULL)
|
||||
return m->size;
|
||||
else
|
||||
return 0;
|
||||
}
|
@ -9,10 +9,10 @@
|
||||
#ifndef __HASHMAP_H__
|
||||
#define __HASHMAP_H__
|
||||
|
||||
#define MAP_MISSING -3 /* No such element */
|
||||
#define MAP_FULL -2 /* Hashmap is full */
|
||||
#define MAP_OMEM -1 /* Out of Memory */
|
||||
#define MAP_OK 0 /* OK */
|
||||
#define MAP_MISSING -3 /* No such element */
|
||||
#define MAP_FULL -2 /* Hashmap is full */
|
||||
#define MAP_OMEM -1 /* Out of Memory */
|
||||
#define MAP_OK 0 /* OK */
|
||||
|
||||
/*
|
||||
* any_t is a pointer. This allows you to put arbitrary structures in
|
||||
@ -50,17 +50,17 @@ extern int hashmap_iterate(map_t in, PFany f, any_t item);
|
||||
/*
|
||||
* Add an element to the hashmap. Return MAP_OK or MAP_OMEM.
|
||||
*/
|
||||
extern int hashmap_put(map_t in, char* key, any_t value);
|
||||
extern int hashmap_put(map_t in, char *key, any_t value);
|
||||
|
||||
/*
|
||||
* Get an element from the hashmap. Return MAP_OK or MAP_MISSING.
|
||||
*/
|
||||
extern int hashmap_get(map_t in, char* key, any_t *arg);
|
||||
extern int hashmap_get(map_t in, char *key, any_t *arg);
|
||||
|
||||
/*
|
||||
* Remove an element from the hashmap. Return MAP_OK or MAP_MISSING.
|
||||
*/
|
||||
extern int hashmap_remove(map_t in, char* key);
|
||||
extern int hashmap_remove(map_t in, char *key);
|
||||
|
||||
/*
|
||||
* Get any element. Return MAP_OK or MAP_MISSING.
|
||||
|
@ -10,72 +10,67 @@
|
||||
|
||||
#define KEY_MAX_LENGTH (256)
|
||||
#define KEY_PREFIX ("somekey")
|
||||
#define KEY_COUNT (1024*1024)
|
||||
#define KEY_COUNT (1024 * 1024)
|
||||
|
||||
typedef struct data_struct_s
|
||||
{
|
||||
char key_string[KEY_MAX_LENGTH];
|
||||
int number;
|
||||
typedef struct data_struct_s {
|
||||
char key_string[KEY_MAX_LENGTH];
|
||||
int number;
|
||||
} data_struct_t;
|
||||
|
||||
int main(char* argv, int argc)
|
||||
{
|
||||
int index;
|
||||
int error;
|
||||
map_t mymap;
|
||||
char key_string[KEY_MAX_LENGTH];
|
||||
data_struct_t* value;
|
||||
|
||||
mymap = hashmap_new();
|
||||
int main(char *argv, int argc) {
|
||||
int index;
|
||||
int error;
|
||||
map_t mymap;
|
||||
char key_string[KEY_MAX_LENGTH];
|
||||
data_struct_t *value;
|
||||
|
||||
/* First, populate the hash map with ascending values */
|
||||
for (index=0; 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;
|
||||
mymap = hashmap_new();
|
||||
|
||||
error = hashmap_put(mymap, value->key_string, value);
|
||||
assert(error==MAP_OK);
|
||||
}
|
||||
/* First, populate the hash map with ascending values */
|
||||
for (index = 0; index < KEY_COUNT; index += 1) {
|
||||
/* Store the key string along side the numerical value so we can free it later */
|
||||
value = malloc(sizeof(data_struct_t));
|
||||
snprintf(value->key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
|
||||
value->number = index;
|
||||
|
||||
/* Now, check all of the expected values are there */
|
||||
for (index=0; index<KEY_COUNT; index+=1)
|
||||
{
|
||||
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
|
||||
error = hashmap_put(mymap, value->key_string, value);
|
||||
assert(error == MAP_OK);
|
||||
}
|
||||
|
||||
error = hashmap_get(mymap, key_string, (void**)(&value));
|
||||
|
||||
/* Make sure the value was both found and the correct number */
|
||||
assert(error==MAP_OK);
|
||||
assert(value->number==index);
|
||||
}
|
||||
|
||||
/* Make sure that a value that wasn't in the map can't be found */
|
||||
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT);
|
||||
/* Now, check all of the expected values are there */
|
||||
for (index = 0; index < KEY_COUNT; index += 1) {
|
||||
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
|
||||
|
||||
error = hashmap_get(mymap, key_string, (void**)(&value));
|
||||
|
||||
/* Make sure the value was not found */
|
||||
assert(error==MAP_MISSING);
|
||||
error = hashmap_get(mymap, key_string, (void **)(&value));
|
||||
|
||||
/* Free all of the values we allocated and remove them from the map */
|
||||
for (index=0; index<KEY_COUNT; index+=1)
|
||||
{
|
||||
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
|
||||
/* Make sure the value was both found and the correct number */
|
||||
assert(error == MAP_OK);
|
||||
assert(value->number == index);
|
||||
}
|
||||
|
||||
error = hashmap_get(mymap, key_string, (void**)(&value));
|
||||
assert(error==MAP_OK);
|
||||
/* Make sure that a value that wasn't in the map can't be found */
|
||||
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT);
|
||||
|
||||
error = hashmap_remove(mymap, key_string);
|
||||
assert(error==MAP_OK);
|
||||
error = hashmap_get(mymap, key_string, (void **)(&value));
|
||||
|
||||
free(value);
|
||||
}
|
||||
|
||||
/* Now, destroy the map */
|
||||
hashmap_free(mymap);
|
||||
/* Make sure the value was not found */
|
||||
assert(error == MAP_MISSING);
|
||||
|
||||
return 1;
|
||||
/* Free all of the values we allocated and remove them from the map */
|
||||
for (index = 0; index < KEY_COUNT; index += 1) {
|
||||
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
|
||||
|
||||
error = hashmap_get(mymap, key_string, (void **)(&value));
|
||||
assert(error == MAP_OK);
|
||||
|
||||
error = hashmap_remove(mymap, key_string);
|
||||
assert(error == MAP_OK);
|
||||
|
||||
free(value);
|
||||
}
|
||||
|
||||
/* Now, destroy the map */
|
||||
hashmap_free(mymap);
|
||||
|
||||
return 1;
|
||||
}
|
222
src/inih/ini.c
222
src/inih/ini.c
@ -25,170 +25,160 @@ https://github.com/benhoyt/inih
|
||||
#define MAX_NAME 50
|
||||
|
||||
/* Strip whitespace chars off end of given string, in place. Return s. */
|
||||
static char* rstrip(char* s)
|
||||
{
|
||||
char* p = s + strlen(s);
|
||||
while (p > s && isspace((unsigned char)(*--p)))
|
||||
*p = '\0';
|
||||
return s;
|
||||
static char *rstrip(char *s) {
|
||||
char *p = s + strlen(s);
|
||||
while (p > s && isspace((unsigned char)(*--p)))
|
||||
*p = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Return pointer to first non-whitespace char in given string. */
|
||||
static char* lskip(const char* s)
|
||||
{
|
||||
while (*s && isspace((unsigned char)(*s)))
|
||||
s++;
|
||||
return (char*)s;
|
||||
static char *lskip(const char *s) {
|
||||
while (*s && isspace((unsigned char)(*s)))
|
||||
s++;
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
/* Return pointer to first char (of chars) or inline comment in given string,
|
||||
or pointer to null at end of string if neither found. Inline comment must
|
||||
be prefixed by a whitespace character to register as a comment. */
|
||||
static char* find_chars_or_comment(const char* s, const char* chars)
|
||||
{
|
||||
static char *find_chars_or_comment(const char *s, const char *chars) {
|
||||
#if INI_ALLOW_INLINE_COMMENTS
|
||||
int was_space = 0;
|
||||
while (*s && (!chars || !strchr(chars, *s)) &&
|
||||
!(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
|
||||
was_space = isspace((unsigned char)(*s));
|
||||
s++;
|
||||
}
|
||||
int was_space = 0;
|
||||
while (*s && (!chars || !strchr(chars, *s)) &&
|
||||
!(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
|
||||
was_space = isspace((unsigned char)(*s));
|
||||
s++;
|
||||
}
|
||||
#else
|
||||
while (*s && (!chars || !strchr(chars, *s))) {
|
||||
s++;
|
||||
}
|
||||
while (*s && (!chars || !strchr(chars, *s))) {
|
||||
s++;
|
||||
}
|
||||
#endif
|
||||
return (char*)s;
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
|
||||
static char* strncpy0(char* dest, const char* src, size_t size)
|
||||
{
|
||||
strncpy(dest, src, size);
|
||||
dest[size - 1] = '\0';
|
||||
return dest;
|
||||
static char *strncpy0(char *dest, const char *src, size_t size) {
|
||||
strncpy(dest, src, size);
|
||||
dest[size - 1] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
void* user)
|
||||
{
|
||||
/* Uses a fair bit of stack (use heap instead if you need to) */
|
||||
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
|
||||
void *user) {
|
||||
/* Uses a fair bit of stack (use heap instead if you need to) */
|
||||
#if INI_USE_STACK
|
||||
char line[INI_MAX_LINE];
|
||||
char line[INI_MAX_LINE];
|
||||
#else
|
||||
char* line;
|
||||
char *line;
|
||||
#endif
|
||||
char section[MAX_SECTION] = "";
|
||||
char prev_name[MAX_NAME] = "";
|
||||
char section[MAX_SECTION] = "";
|
||||
char prev_name[MAX_NAME] = "";
|
||||
|
||||
char* start;
|
||||
char* end;
|
||||
char* name;
|
||||
char* value;
|
||||
int lineno = 0;
|
||||
int error = 0;
|
||||
char *start;
|
||||
char *end;
|
||||
char *name;
|
||||
char *value;
|
||||
int lineno = 0;
|
||||
int error = 0;
|
||||
|
||||
#if !INI_USE_STACK
|
||||
line = (char*)malloc(INI_MAX_LINE);
|
||||
if (!line) {
|
||||
return -2;
|
||||
}
|
||||
line = (char *)malloc(INI_MAX_LINE);
|
||||
if (!line) {
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Scan through stream line by line */
|
||||
while (reader(line, INI_MAX_LINE, stream) != NULL) {
|
||||
lineno++;
|
||||
/* Scan through stream line by line */
|
||||
while (reader(line, INI_MAX_LINE, stream) != NULL) {
|
||||
lineno++;
|
||||
|
||||
start = line;
|
||||
start = line;
|
||||
#if INI_ALLOW_BOM
|
||||
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
|
||||
(unsigned char)start[1] == 0xBB &&
|
||||
(unsigned char)start[2] == 0xBF) {
|
||||
start += 3;
|
||||
}
|
||||
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
|
||||
(unsigned char)start[1] == 0xBB &&
|
||||
(unsigned char)start[2] == 0xBF) {
|
||||
start += 3;
|
||||
}
|
||||
#endif
|
||||
start = lskip(rstrip(start));
|
||||
start = lskip(rstrip(start));
|
||||
|
||||
if (*start == ';' || *start == '#') {
|
||||
/* Per Python configparser, allow both ; and # comments at the
|
||||
if (*start == ';' || *start == '#') {
|
||||
/* Per Python configparser, allow both ; and # comments at the
|
||||
start of a line */
|
||||
}
|
||||
}
|
||||
#if INI_ALLOW_MULTILINE
|
||||
else if (*prev_name && *start && start > line) {
|
||||
/* Non-blank line with leading whitespace, treat as continuation
|
||||
else if (*prev_name && *start && start > line) {
|
||||
/* Non-blank line with leading whitespace, treat as continuation
|
||||
of previous name's value (as per Python configparser). */
|
||||
if (!handler(user, section, prev_name, start) && !error)
|
||||
error = lineno;
|
||||
}
|
||||
if (!handler(user, section, prev_name, start) && !error)
|
||||
error = lineno;
|
||||
}
|
||||
#endif
|
||||
else if (*start == '[') {
|
||||
/* A "[section]" line */
|
||||
end = find_chars_or_comment(start + 1, "]");
|
||||
if (*end == ']') {
|
||||
*end = '\0';
|
||||
strncpy0(section, start + 1, sizeof(section));
|
||||
*prev_name = '\0';
|
||||
}
|
||||
else if (!error) {
|
||||
/* No ']' found on section line */
|
||||
error = lineno;
|
||||
}
|
||||
}
|
||||
else if (*start) {
|
||||
/* Not a comment, must be a name[=:]value pair */
|
||||
end = find_chars_or_comment(start, "=:");
|
||||
if (*end == '=' || *end == ':') {
|
||||
*end = '\0';
|
||||
name = rstrip(start);
|
||||
value = lskip(end + 1);
|
||||
else if (*start == '[') {
|
||||
/* A "[section]" line */
|
||||
end = find_chars_or_comment(start + 1, "]");
|
||||
if (*end == ']') {
|
||||
*end = '\0';
|
||||
strncpy0(section, start + 1, sizeof(section));
|
||||
*prev_name = '\0';
|
||||
} else if (!error) {
|
||||
/* No ']' found on section line */
|
||||
error = lineno;
|
||||
}
|
||||
} else if (*start) {
|
||||
/* Not a comment, must be a name[=:]value pair */
|
||||
end = find_chars_or_comment(start, "=:");
|
||||
if (*end == '=' || *end == ':') {
|
||||
*end = '\0';
|
||||
name = rstrip(start);
|
||||
value = lskip(end + 1);
|
||||
#if INI_ALLOW_INLINE_COMMENTS
|
||||
end = find_chars_or_comment(value, NULL);
|
||||
if (*end)
|
||||
*end = '\0';
|
||||
end = find_chars_or_comment(value, NULL);
|
||||
if (*end)
|
||||
*end = '\0';
|
||||
#endif
|
||||
rstrip(value);
|
||||
rstrip(value);
|
||||
|
||||
/* Valid name[=:]value pair found, call handler */
|
||||
strncpy0(prev_name, name, sizeof(prev_name));
|
||||
if (!handler(user, section, name, value) && !error)
|
||||
error = lineno;
|
||||
}
|
||||
else if (!error) {
|
||||
/* No '=' or ':' found on name[=:]value line */
|
||||
error = lineno;
|
||||
}
|
||||
}
|
||||
/* Valid name[=:]value pair found, call handler */
|
||||
strncpy0(prev_name, name, sizeof(prev_name));
|
||||
if (!handler(user, section, name, value) && !error)
|
||||
error = lineno;
|
||||
} else if (!error) {
|
||||
/* No '=' or ':' found on name[=:]value line */
|
||||
error = lineno;
|
||||
}
|
||||
}
|
||||
|
||||
#if INI_STOP_ON_FIRST_ERROR
|
||||
if (error)
|
||||
break;
|
||||
if (error)
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if !INI_USE_STACK
|
||||
free(line);
|
||||
free(line);
|
||||
#endif
|
||||
|
||||
return error;
|
||||
return error;
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse_file(FILE* file, ini_handler handler, void* user)
|
||||
{
|
||||
return ini_parse_stream((ini_reader)fgets, file, handler, user);
|
||||
int ini_parse_file(FILE *file, ini_handler handler, void *user) {
|
||||
return ini_parse_stream((ini_reader)fgets, file, handler, user);
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse(const char* filename, ini_handler handler, void* user)
|
||||
{
|
||||
FILE* file;
|
||||
int error;
|
||||
int ini_parse(const char *filename, ini_handler handler, void *user) {
|
||||
FILE *file;
|
||||
int error;
|
||||
|
||||
file = fopen(filename, "r");
|
||||
if (!file)
|
||||
return -1;
|
||||
error = ini_parse_file(file, handler, user);
|
||||
fclose(file);
|
||||
return error;
|
||||
file = fopen(filename, "r");
|
||||
if (!file)
|
||||
return -1;
|
||||
error = ini_parse_file(file, handler, user);
|
||||
fclose(file);
|
||||
return error;
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ extern "C" {
|
||||
#include <stdio.h>
|
||||
|
||||
/* Typedef for prototype of handler function. */
|
||||
typedef int (*ini_handler)(void* user, const char* section,
|
||||
const char* name, const char* value);
|
||||
typedef int (*ini_handler)(void *user, const char *section,
|
||||
const char *name, const char *value);
|
||||
|
||||
/* Typedef for prototype of fgets-style reader function. */
|
||||
typedef char* (*ini_reader)(char* str, int num, void* stream);
|
||||
typedef char *(*ini_reader)(char *str, int num, void *stream);
|
||||
|
||||
/* Parse given INI-style file. May have [section]s, name=value pairs
|
||||
(whitespace stripped), and comments starting with ';' (semicolon). Section
|
||||
@ -37,16 +37,16 @@ typedef char* (*ini_reader)(char* str, int num, void* stream);
|
||||
stop on first error), -1 on file open error, or -2 on memory allocation
|
||||
error (only when INI_USE_STACK is zero).
|
||||
*/
|
||||
int ini_parse(const char* filename, ini_handler handler, void* user);
|
||||
int ini_parse(const char *filename, ini_handler handler, void *user);
|
||||
|
||||
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
|
||||
close the file when it's finished -- the caller must do that. */
|
||||
int ini_parse_file(FILE* file, ini_handler handler, void* user);
|
||||
int ini_parse_file(FILE *file, ini_handler handler, void *user);
|
||||
|
||||
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
|
||||
filename. Used for implementing custom or string-based I/O. */
|
||||
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
void* user);
|
||||
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
|
||||
void *user);
|
||||
|
||||
/* Nonzero to allow multi-line value parsing, in the style of Python's
|
||||
configparser. If allowed, ini_parse() will call the handler with the same
|
||||
|
102
src/lua_glue.c
102
src/lua_glue.c
@ -55,7 +55,7 @@ int l_bbsRChar(lua_State *L) {
|
||||
int l_bbsDisplayAnsiPause(lua_State *L) {
|
||||
char *str = (char *)lua_tostring(L, -1);
|
||||
char buffer[256];
|
||||
|
||||
|
||||
if (strchr(str, '/') == NULL) {
|
||||
sprintf(buffer, "%s/%s.ans", conf.ansi_path, str);
|
||||
s_displayansi_pause(buffer, 1);
|
||||
@ -187,8 +187,7 @@ int l_getBBSInfo(lua_State *L) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
int l_getUserHandle(lua_State *L) {
|
||||
int l_getUserHandle(lua_State *L) {
|
||||
lua_pushstring(L, gUser->loginname);
|
||||
|
||||
return 1;
|
||||
@ -203,7 +202,7 @@ int l_messageFound(lua_State *L) {
|
||||
s_JamBase *jb;
|
||||
s_JamBaseHeader jbh;
|
||||
s_JamMsgHeader jmh;
|
||||
s_JamSubPacket* jsp;
|
||||
s_JamSubPacket *jsp;
|
||||
|
||||
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
|
||||
if (!jb) {
|
||||
@ -226,12 +225,12 @@ int l_messageFound(lua_State *L) {
|
||||
lua_pushnumber(L, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
JAM_DelSubPacket(jsp);
|
||||
JAM_CloseMB(jb);
|
||||
free(jb);
|
||||
lua_pushnumber(L, 1);
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_readMessageHdr(lua_State *L) {
|
||||
@ -243,7 +242,7 @@ int l_readMessageHdr(lua_State *L) {
|
||||
s_JamBase *jb;
|
||||
s_JamBaseHeader jbh;
|
||||
s_JamMsgHeader jmh;
|
||||
s_JamSubPacket* jsp;
|
||||
s_JamSubPacket *jsp;
|
||||
|
||||
char *subject = NULL;
|
||||
char *sender = NULL;
|
||||
@ -265,7 +264,7 @@ int l_readMessageHdr(lua_State *L) {
|
||||
JAM_CloseMB(jb);
|
||||
free(jb);
|
||||
} else {
|
||||
for (z=0;z<jsp->NumFields;z++) {
|
||||
for (z = 0; z < jsp->NumFields; z++) {
|
||||
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
|
||||
subject = (char *)malloc(jsp->Fields[z]->DatLen + 1);
|
||||
memset(subject, 0, jsp->Fields[z]->DatLen + 1);
|
||||
@ -281,11 +280,10 @@ int l_readMessageHdr(lua_State *L) {
|
||||
memset(recipient, 0, jsp->Fields[z]->DatLen + 1);
|
||||
memcpy(recipient, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
|
||||
}
|
||||
|
||||
}
|
||||
JAM_DelSubPacket(jsp);
|
||||
JAM_CloseMB(jb);
|
||||
free(jb);
|
||||
free(jb);
|
||||
}
|
||||
if (subject == NULL) {
|
||||
subject = strdup("(No Subject)");
|
||||
@ -307,7 +305,6 @@ int l_readMessageHdr(lua_State *L) {
|
||||
free(sender);
|
||||
free(recipient);
|
||||
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
@ -350,7 +347,7 @@ int l_readMessage(lua_State *L) {
|
||||
lua_pushstring(L, body);
|
||||
|
||||
free(body);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -362,7 +359,7 @@ int l_dataPath(lua_State *L) {
|
||||
if (stat(buffer, &s) != 0) {
|
||||
mkdir(buffer, 0755);
|
||||
}
|
||||
|
||||
|
||||
lua_pushstring(L, buffer);
|
||||
|
||||
return 1;
|
||||
@ -376,7 +373,7 @@ int l_tempPath(lua_State *L) {
|
||||
if (stat(buffer, &s) != 0) {
|
||||
mkdir(buffer, 0755);
|
||||
}
|
||||
|
||||
|
||||
lua_pushstring(L, buffer);
|
||||
|
||||
return 1;
|
||||
@ -401,7 +398,7 @@ int l_postMessage(lua_State *L) {
|
||||
|
||||
s_JamBase *jb;
|
||||
s_JamMsgHeader jmh;
|
||||
s_JamSubPacket* jsp;
|
||||
s_JamSubPacket *jsp;
|
||||
s_JamSubfield jsf;
|
||||
int z;
|
||||
int j;
|
||||
@ -416,37 +413,36 @@ int l_postMessage(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
JAM_ClearMsgHeader( &jmh );
|
||||
JAM_ClearMsgHeader(&jmh);
|
||||
jmh.DateWritten = dwritten;
|
||||
jmh.Attribute |= JAM_MSG_LOCAL;
|
||||
|
||||
|
||||
jsp = JAM_NewSubPacket();
|
||||
|
||||
jsf.LoID = JAMSFLD_SENDERNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_SENDERNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(from);
|
||||
jsf.Buffer = (char *)from;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) {
|
||||
sprintf(buffer, "ALL");
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
} else {
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(to);
|
||||
jsf.Buffer = (char *)to;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
}
|
||||
|
||||
jsf.LoID = JAMSFLD_SUBJECT;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_SUBJECT;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(subject);
|
||||
jsf.Buffer = (char *)subject;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -456,28 +452,28 @@ int l_postMessage(lua_State *L) {
|
||||
|
||||
if (conf.mail_conferences[confr]->fidoaddr->point) {
|
||||
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
} else {
|
||||
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
}
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point,
|
||||
generate_msgid());
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point,
|
||||
generate_msgid());
|
||||
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -499,7 +495,7 @@ int l_postMessage(lua_State *L) {
|
||||
} else {
|
||||
dolog("Failed to lock msg base!");
|
||||
JAM_CloseMB(jb);
|
||||
free(jb);
|
||||
free(jb);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -514,23 +510,23 @@ int l_postMessage(lua_State *L) {
|
||||
if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) {
|
||||
if (conf.mail_conferences[confr]->fidoaddr->point == 0) {
|
||||
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
} else {
|
||||
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
}
|
||||
} else {
|
||||
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline);
|
||||
}
|
||||
|
||||
msg = (char *)malloc(strlen(body) + 2 + strlen(buffer));
|
||||
|
||||
|
||||
j = 0;
|
||||
|
||||
for (i=0;i<strlen(body);i++) {
|
||||
for (i = 0; i < strlen(body); i++) {
|
||||
if (body[i] == '\n') {
|
||||
continue;
|
||||
}
|
||||
@ -543,7 +539,7 @@ int l_postMessage(lua_State *L) {
|
||||
if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) {
|
||||
dolog("Failed to add message");
|
||||
JAM_UnlockMB(jb);
|
||||
|
||||
|
||||
JAM_DelSubPacket(jsp);
|
||||
JAM_CloseMB(jb);
|
||||
free(msg);
|
||||
@ -573,7 +569,7 @@ void lua_push_cfunctions(lua_State *L) {
|
||||
lua_pushcfunction(L, l_bbsRString);
|
||||
lua_setglobal(L, "bbs_read_string");
|
||||
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_setglobal(L, "bbs_display_ansi");
|
||||
lua_pushcfunction(L, l_bbsRChar);
|
||||
@ -601,15 +597,15 @@ void lua_push_cfunctions(lua_State *L) {
|
||||
lua_pushcfunction(L, l_getBBSInfo);
|
||||
lua_setglobal(L, "bbs_get_info");
|
||||
lua_pushcfunction(L, l_bbsFileScan);
|
||||
lua_setglobal(L, "bbs_file_scan");
|
||||
lua_setglobal(L, "bbs_file_scan");
|
||||
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_setglobal(L, "bbs_get_userhandle");
|
||||
lua_setglobal(L, "bbs_get_userhandle");
|
||||
lua_pushcfunction(L, l_messageFound);
|
||||
lua_setglobal(L, "bbs_message_found");
|
||||
lua_setglobal(L, "bbs_message_found");
|
||||
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_setglobal(L, "bbs_read_message");
|
||||
lua_pushcfunction(L, l_tempPath);
|
||||
|
1066
src/mail_menu.c
1066
src/mail_menu.c
File diff suppressed because it is too large
Load Diff
307
src/main.c
307
src/main.c
@ -17,16 +17,16 @@
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
#if defined(linux)
|
||||
# include <pty.h>
|
||||
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
|
||||
# include <util.h>
|
||||
#include <pty.h>
|
||||
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
|
||||
#include <util.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
# include <libutil.h>
|
||||
#include <libutil.h>
|
||||
#elif defined(__sun)
|
||||
# include "os/sunos.h"
|
||||
#include "os/sunos.h"
|
||||
#endif
|
||||
#if defined(ENABLE_WWW)
|
||||
# include <microhttpd.h>
|
||||
#include <microhttpd.h>
|
||||
#endif
|
||||
#include <termios.h>
|
||||
#include "bbs.h"
|
||||
@ -51,8 +51,7 @@ int bbs_stderr;
|
||||
struct MHD_Daemon *www_daemon;
|
||||
#endif
|
||||
|
||||
void sigterm_handler(int s)
|
||||
{
|
||||
void sigterm_handler(int s) {
|
||||
if (ssh_pid != -1) {
|
||||
kill(ssh_pid, SIGTERM);
|
||||
}
|
||||
@ -66,28 +65,27 @@ void sigterm_handler(int s)
|
||||
#endif
|
||||
if (ipv6_pid != -1) {
|
||||
kill(ipv6_pid, SIGTERM);
|
||||
}
|
||||
}
|
||||
remove(conf.pid_file);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void sigchld_handler(int s)
|
||||
{
|
||||
// waitpid() might overwrite errno, so we save and restore it:
|
||||
int saved_errno = errno;
|
||||
void sigchld_handler(int s) {
|
||||
// waitpid() might overwrite errno, so we save and restore it:
|
||||
int saved_errno = errno;
|
||||
|
||||
while(waitpid(-1, NULL, WNOHANG) > 0);
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0)
|
||||
;
|
||||
|
||||
errno = saved_errno;
|
||||
errno = saved_errno;
|
||||
}
|
||||
|
||||
static int protocol_config_handler(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
static int protocol_config_handler(void *user, const char *section, const char *name,
|
||||
const char *value) {
|
||||
struct bbs_config *conf = (struct bbs_config *)user;
|
||||
int i;
|
||||
|
||||
for (i=0;i<conf->protocol_count;i++) {
|
||||
for (i = 0; i < conf->protocol_count; i++) {
|
||||
if (strcasecmp(conf->protocols[i]->name, section) == 0) {
|
||||
// found it
|
||||
if (strcasecmp(name, "upload command") == 0) {
|
||||
@ -129,7 +127,7 @@ static int protocol_config_handler(void* user, const char* section, const char*
|
||||
conf->protocols[conf->protocol_count]->internal_zmodem = 0;
|
||||
conf->protocols[conf->protocol_count]->upload_prompt = 0;
|
||||
conf->protocols[conf->protocol_count]->stdio = 0;
|
||||
|
||||
|
||||
if (strcasecmp(name, "upload command") == 0) {
|
||||
conf->protocols[conf->protocol_count]->upload = strdup(value);
|
||||
} else if (strcasecmp(name, "download command") == 0) {
|
||||
@ -158,13 +156,12 @@ static int protocol_config_handler(void* user, const char* section, const char*
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int archiver_config_handler(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
static int archiver_config_handler(void *user, const char *section, const char *name,
|
||||
const char *value) {
|
||||
struct bbs_config *conf = (struct bbs_config *)user;
|
||||
int i;
|
||||
|
||||
for (i=0;i<conf->archiver_count;i++) {
|
||||
for (i = 0; i < conf->archiver_count; i++) {
|
||||
if (strcasecmp(conf->archivers[i]->name, section) == 0) {
|
||||
// found it
|
||||
if (strcasecmp(name, "extension") == 0) {
|
||||
@ -200,13 +197,12 @@ static int archiver_config_handler(void* user, const char* section, const char*
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int door_config_handler(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
static int door_config_handler(void *user, const char *section, const char *name,
|
||||
const char *value) {
|
||||
struct bbs_config *conf = (struct bbs_config *)user;
|
||||
int i;
|
||||
|
||||
for (i=0;i<conf->door_count;i++) {
|
||||
for (i = 0; i < conf->door_count; i++) {
|
||||
if (strcasecmp(conf->doors[i]->name, section) == 0) {
|
||||
// found it
|
||||
if (strcasecmp(name, "command") == 0) {
|
||||
@ -251,9 +247,8 @@ static int door_config_handler(void* user, const char* section, const char* name
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int file_sub_handler(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
static int file_sub_handler(void *user, const char *section, const char *name,
|
||||
const char *value) {
|
||||
struct file_directory *fd = (struct file_directory *)user;
|
||||
int i;
|
||||
|
||||
@ -269,7 +264,7 @@ static int file_sub_handler(void* user, const char* section, const char* name,
|
||||
}
|
||||
} else {
|
||||
// check if it's partially filled in
|
||||
for (i=0;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(name, "upload sec level") == 0) {
|
||||
fd->file_subs[i]->upload_sec_level = atoi(value);
|
||||
@ -306,10 +301,8 @@ static int file_sub_handler(void* user, const char* section, const char* name,
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int mail_area_handler(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
static int mail_area_handler(void *user, const char *section, const char *name,
|
||||
const char *value) {
|
||||
struct mail_conference *mc = (struct mail_conference *)user;
|
||||
int i;
|
||||
|
||||
@ -351,7 +344,7 @@ static int mail_area_handler(void* user, const char* section, const char* name,
|
||||
}
|
||||
} else {
|
||||
// check if it's partially filled in
|
||||
for (i=0;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(name, "read sec level") == 0) {
|
||||
mc->mail_areas[i]->read_sec_level = atoi(value);
|
||||
@ -385,9 +378,9 @@ static int mail_area_handler(void* user, const char* section, const char* name,
|
||||
}
|
||||
|
||||
mc->mail_areas[mc->mail_area_count] = (struct mail_area *)malloc(sizeof(struct mail_area));
|
||||
|
||||
|
||||
mc->mail_areas[mc->mail_area_count]->qwkname = NULL;
|
||||
|
||||
|
||||
mc->mail_areas[mc->mail_area_count]->name = strdup(section);
|
||||
if (strcasecmp(name, "read sec level") == 0) {
|
||||
mc->mail_areas[mc->mail_area_count]->read_sec_level = atoi(value);
|
||||
@ -416,9 +409,8 @@ static int mail_area_handler(void* user, const char* section, const char* name,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int handler(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
static int handler(void *user, const char *section, const char *name,
|
||||
const char *value) {
|
||||
struct bbs_config *conf = (struct bbs_config *)user;
|
||||
struct passwd *pwd;
|
||||
|
||||
@ -432,7 +424,7 @@ static int handler(void* user, const char* section, const char* name,
|
||||
conf->ssh_server = 1;
|
||||
} else {
|
||||
conf->ssh_server = 0;
|
||||
}
|
||||
}
|
||||
} else if (strcasecmp(name, "enable ipv6") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->ipv6 = 1;
|
||||
@ -486,7 +478,7 @@ static int handler(void* user, const char* section, const char* name,
|
||||
}
|
||||
} else if (strcasecmp(name, "automessage write level") == 0) {
|
||||
conf->automsgwritelvl = atoi(value);
|
||||
} else if (strcasecmp(name, "fork") == 0) {
|
||||
} else if (strcasecmp(name, "fork") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->fork = 1;
|
||||
} else {
|
||||
@ -548,7 +540,7 @@ static int handler(void* user, const char* section, const char* name,
|
||||
conf->gid = pwd->pw_gid;
|
||||
}
|
||||
}
|
||||
} else if (strcasecmp(section, "paths") == 0){
|
||||
} else if (strcasecmp(section, "paths") == 0) {
|
||||
if (strcasecmp(name, "ansi path") == 0) {
|
||||
conf->ansi_path = strdup(value);
|
||||
} else if (strcasecmp(name, "bbs path") == 0) {
|
||||
@ -612,7 +604,6 @@ static int handler(void* user, const char* section, const char* name,
|
||||
conf->text_files[conf->text_file_count]->name = strdup(name);
|
||||
conf->text_files[conf->text_file_count]->path = strdup(value);
|
||||
conf->text_file_count++;
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -625,15 +616,15 @@ int ssh_authenticate(ssh_session p_ssh_session) {
|
||||
|
||||
do {
|
||||
message = ssh_message_get(p_ssh_session);
|
||||
|
||||
|
||||
if (message == NULL) {
|
||||
gUser = NULL;
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch(ssh_message_type(message)) {
|
||||
switch (ssh_message_type(message)) {
|
||||
case SSH_REQUEST_AUTH:
|
||||
switch(ssh_message_subtype(message)) {
|
||||
switch (ssh_message_subtype(message)) {
|
||||
case SSH_AUTH_METHOD_PASSWORD:
|
||||
username = ssh_message_auth_user(message);
|
||||
password = ssh_message_auth_password(message);
|
||||
@ -666,7 +657,7 @@ int ssh_authenticate(ssh_session p_ssh_session) {
|
||||
}
|
||||
|
||||
ssh_message_free(message);
|
||||
} while(1);
|
||||
} while (1);
|
||||
}
|
||||
/*
|
||||
char *ssh_getip(ssh_session session) {
|
||||
@ -683,57 +674,56 @@ char *ssh_getip(ssh_session session) {
|
||||
}
|
||||
*/
|
||||
static int ssh_copy_fd_to_chan(socket_t fd, int revents, void *userdata) {
|
||||
ssh_channel chan = (ssh_channel)userdata;
|
||||
char buf[2048];
|
||||
int sz = 0;
|
||||
ssh_channel chan = (ssh_channel)userdata;
|
||||
char buf[2048];
|
||||
int sz = 0;
|
||||
|
||||
if(!chan) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if(revents & POLLIN) {
|
||||
sz = read(fd, buf, 2048);
|
||||
if(sz > 0) {
|
||||
ssh_channel_write(chan, buf, sz);
|
||||
}
|
||||
}
|
||||
if(revents & POLLHUP) {
|
||||
ssh_channel_close(chan);
|
||||
sz = -1;
|
||||
}
|
||||
return sz;
|
||||
if (!chan) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if (revents & POLLIN) {
|
||||
sz = read(fd, buf, 2048);
|
||||
if (sz > 0) {
|
||||
ssh_channel_write(chan, buf, sz);
|
||||
}
|
||||
}
|
||||
if (revents & POLLHUP) {
|
||||
ssh_channel_close(chan);
|
||||
sz = -1;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
static int ssh_copy_chan_to_fd(ssh_session session,
|
||||
ssh_channel channel,
|
||||
void *data,
|
||||
uint32_t len,
|
||||
int is_stderr,
|
||||
void *userdata) {
|
||||
int fd = *(int*)userdata;
|
||||
int sz;
|
||||
(void)session;
|
||||
(void)channel;
|
||||
(void)is_stderr;
|
||||
ssh_channel channel,
|
||||
void *data,
|
||||
uint32_t len,
|
||||
int is_stderr,
|
||||
void *userdata) {
|
||||
int fd = *(int *)userdata;
|
||||
int sz;
|
||||
(void)session;
|
||||
(void)channel;
|
||||
(void)is_stderr;
|
||||
|
||||
sz = write(fd, data, len);
|
||||
return sz;
|
||||
sz = write(fd, data, len);
|
||||
return sz;
|
||||
}
|
||||
|
||||
static void ssh_chan_close(ssh_session session, ssh_channel channel, void *userdata) {
|
||||
int fd = *(int*)userdata;
|
||||
int fd = *(int *)userdata;
|
||||
int status;
|
||||
(void)session;
|
||||
(void)channel;
|
||||
close(fd);
|
||||
(void)session;
|
||||
(void)channel;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
struct ssh_channel_callbacks_struct ssh_cb = {
|
||||
.channel_data_function = ssh_copy_chan_to_fd,
|
||||
.channel_eof_function = ssh_chan_close,
|
||||
.channel_close_function = ssh_chan_close,
|
||||
.userdata = NULL
|
||||
};
|
||||
.channel_data_function = ssh_copy_chan_to_fd,
|
||||
.channel_eof_function = ssh_chan_close,
|
||||
.channel_close_function = ssh_chan_close,
|
||||
.userdata = NULL};
|
||||
|
||||
void serverssh(int port, int ipv6) {
|
||||
ssh_session p_ssh_session;
|
||||
@ -762,7 +752,7 @@ void serverssh(int port, int ipv6) {
|
||||
bbs_stdin = dup(STDIN_FILENO);
|
||||
bbs_stdout = dup(STDOUT_FILENO);
|
||||
bbs_stderr = dup(STDERR_FILENO);
|
||||
|
||||
|
||||
err = ssh_init();
|
||||
if (err == -1) {
|
||||
fprintf(stderr, "Error starting SSH server.\n");
|
||||
@ -789,7 +779,6 @@ void serverssh(int port, int ipv6) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
if (setsockopt(ssh_sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
|
||||
fprintf(stderr, "setsockopt(SO_REUSEADDR) failed");
|
||||
exit(-1);
|
||||
@ -799,7 +788,7 @@ void serverssh(int port, int ipv6) {
|
||||
if (setsockopt(ssh_sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) {
|
||||
fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed");
|
||||
}
|
||||
|
||||
|
||||
memset(&server, 0, sizeof(server));
|
||||
server.sin6_family = AF_INET6;
|
||||
server.sin6_addr = in6addr_any;
|
||||
@ -828,7 +817,7 @@ void serverssh(int port, int ipv6) {
|
||||
}
|
||||
c = sizeof(struct sockaddr_in);
|
||||
}
|
||||
|
||||
|
||||
if (conf.uid != getuid()) {
|
||||
if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) {
|
||||
perror("SetUID Failed: ");
|
||||
@ -838,23 +827,23 @@ void serverssh(int port, int ipv6) {
|
||||
}
|
||||
|
||||
listen(ssh_sock, 3);
|
||||
|
||||
|
||||
while ((csock = accept(ssh_sock, (struct sockaddr *)client_p, (socklen_t *)&c))) {
|
||||
p_ssh_session = ssh_new();
|
||||
if (p_ssh_session == NULL) {
|
||||
fprintf(stderr, "Error starting SSH session.\n");
|
||||
close(csock);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (ssh_bind_accept_fd(p_ssh_bind, p_ssh_session, csock) == SSH_OK) {
|
||||
if (ipv6) {
|
||||
ip = strdup(inet_ntop(AF_INET6, &((struct sockaddr_in6 *)client_p)->sin6_addr, str, sizeof(str)));
|
||||
} else {
|
||||
ip = strdup(inet_ntop(AF_INET, &((struct sockaddr_in *)client_p)->sin_addr, str, sizeof(str)));
|
||||
}
|
||||
}
|
||||
if (conf.ipguard_enable) {
|
||||
i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard));
|
||||
|
||||
|
||||
if (i == MAP_MISSING) {
|
||||
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
|
||||
ip_guard->status = IP_STATUS_UNKNOWN;
|
||||
@ -862,7 +851,7 @@ void serverssh(int port, int ipv6) {
|
||||
ip_guard->connection_count = 1;
|
||||
hashmap_put(ip_guard_map, strdup(ip), ip_guard);
|
||||
} else if (i == MAP_OK) {
|
||||
|
||||
|
||||
if (ip_guard->status == IP_STATUS_BLACKLISTED) {
|
||||
free(ip);
|
||||
ssh_disconnect(p_ssh_session);
|
||||
@ -879,16 +868,15 @@ void serverssh(int port, int ipv6) {
|
||||
free(ip);
|
||||
ssh_disconnect(p_ssh_session);
|
||||
continue;
|
||||
|
||||
}
|
||||
} else {
|
||||
ip_guard->connection_count = 0;
|
||||
ip_guard->last_connection = time(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
close(ssh_sock);
|
||||
@ -912,7 +900,7 @@ void serverssh(int port, int ipv6) {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while(!chan);
|
||||
} while (!chan);
|
||||
if (!chan) {
|
||||
fprintf(stderr, "Failed to get channel\n");
|
||||
ssh_finalize();
|
||||
@ -924,7 +912,7 @@ void serverssh(int port, int ipv6) {
|
||||
if (message) {
|
||||
if (ssh_message_type(message) == SSH_REQUEST_CHANNEL) {
|
||||
if (ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_SHELL) {
|
||||
shell = 1;
|
||||
shell = 1;
|
||||
ssh_message_channel_request_reply_success(message);
|
||||
ssh_message_free(message);
|
||||
break;
|
||||
@ -945,10 +933,6 @@ void serverssh(int port, int ipv6) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bbs_pid = forkpty(&fd, NULL, NULL, NULL);
|
||||
if (bbs_pid == 0) {
|
||||
tcgetattr(STDIN_FILENO, &tios);
|
||||
@ -966,22 +950,22 @@ void serverssh(int port, int ipv6) {
|
||||
events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL;
|
||||
|
||||
event = ssh_event_new();
|
||||
if(event == NULL) {
|
||||
if (event == NULL) {
|
||||
ssh_finalize();
|
||||
exit(0);
|
||||
}
|
||||
if(ssh_event_add_fd(event, fd, events, ssh_copy_fd_to_chan, chan) != SSH_OK) {
|
||||
if (ssh_event_add_fd(event, fd, events, ssh_copy_fd_to_chan, chan) != SSH_OK) {
|
||||
ssh_finalize();
|
||||
exit(0);
|
||||
}
|
||||
if(ssh_event_add_session(event, p_ssh_session) != SSH_OK) {
|
||||
if (ssh_event_add_session(event, p_ssh_session) != SSH_OK) {
|
||||
ssh_finalize();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
do {
|
||||
ssh_event_dopoll(event, 1000);
|
||||
} while(!ssh_channel_is_closed(chan));
|
||||
} while (!ssh_channel_is_closed(chan));
|
||||
|
||||
ssh_event_remove_fd(event, fd);
|
||||
|
||||
@ -998,7 +982,6 @@ void serverssh(int port, int ipv6) {
|
||||
close(csock);
|
||||
free(ip);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1028,49 +1011,49 @@ void server(int port, int ipv6) {
|
||||
if (conf.ipguard_enable) {
|
||||
|
||||
ip_guard_map = hashmap_new();
|
||||
|
||||
|
||||
snprintf(buffer, 1024, "%s/whitelist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4));
|
||||
|
||||
|
||||
fptr = fopen(buffer, "r");
|
||||
if (fptr) {
|
||||
fgets(buffer, 1024, fptr);
|
||||
while (!feof(fptr)) {
|
||||
for (i=strlen(buffer)-1;i> 0; i--) {
|
||||
for (i = strlen(buffer) - 1; i > 0; i--) {
|
||||
if (buffer[i] == '\r' || buffer[i] == '\n') {
|
||||
buffer[i] = '\0';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
|
||||
ip_guard->status = IP_STATUS_WHITELISTED;
|
||||
|
||||
|
||||
hashmap_put(ip_guard_map, strdup(buffer), ip_guard);
|
||||
|
||||
|
||||
fgets(buffer, 1024, fptr);
|
||||
}
|
||||
fclose(fptr);
|
||||
}
|
||||
snprintf(buffer, 1024, "%s/blacklist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4));
|
||||
|
||||
|
||||
fptr = fopen(buffer, "r");
|
||||
if (fptr) {
|
||||
fgets(buffer, 1024, fptr);
|
||||
while (!feof(fptr)) {
|
||||
for (i=strlen(buffer)-1;i> 0; i--) {
|
||||
for (i = strlen(buffer) - 1; i > 0; i--) {
|
||||
if (buffer[i] == '\r' || buffer[i] == '\n') {
|
||||
buffer[i] = '\0';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
|
||||
ip_guard->status = IP_STATUS_BLACKLISTED;
|
||||
|
||||
|
||||
hashmap_put(ip_guard_map, strdup(buffer), ip_guard);
|
||||
|
||||
|
||||
fgets(buffer, 1024, fptr);
|
||||
}
|
||||
fclose(fptr);
|
||||
@ -1080,27 +1063,27 @@ void server(int port, int ipv6) {
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
|
||||
perror("sigaction - sigchld");
|
||||
remove(conf.pid_file);
|
||||
exit(1);
|
||||
perror("sigaction - sigchld");
|
||||
remove(conf.pid_file);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
st.sa_handler = sigterm_handler;
|
||||
sigemptyset(&st.sa_mask);
|
||||
st.sa_flags = SA_SIGINFO;
|
||||
if (sigaction(SIGTERM, &st, NULL) == -1) {
|
||||
perror("sigaction - sigterm");
|
||||
remove(conf.pid_file);
|
||||
exit(1);
|
||||
perror("sigaction - sigterm");
|
||||
remove(conf.pid_file);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sq.sa_handler = sigterm_handler;
|
||||
sigemptyset(&sq.sa_mask);
|
||||
sq.sa_flags = SA_SIGINFO;
|
||||
if (sigaction(SIGQUIT, &sq, NULL) == -1) {
|
||||
perror("sigaction - sigquit");
|
||||
remove(conf.pid_file);
|
||||
exit(1);
|
||||
perror("sigaction - sigquit");
|
||||
remove(conf.pid_file);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (conf.ssh_server) {
|
||||
@ -1133,7 +1116,6 @@ void server(int port, int ipv6) {
|
||||
fprintf(stderr, "Couldn't create socket..\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
|
||||
remove(conf.pid_file);
|
||||
@ -1145,7 +1127,6 @@ void server(int port, int ipv6) {
|
||||
printf(" - Telnet Starting on Port %d (IPv%d)\n", port, (ipv6 ? 6 : 4));
|
||||
}
|
||||
|
||||
|
||||
if (ipv6) {
|
||||
if (setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) {
|
||||
fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed");
|
||||
@ -1189,14 +1170,14 @@ void server(int port, int ipv6) {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ENABLE_WWW)
|
||||
#if defined(ENABLE_WWW)
|
||||
if (conf.www_server && conf.www_path != NULL && conf.www_url != NULL) {
|
||||
if (!conf.fork) {
|
||||
printf(" - HTTP Starting on Port %d (IPv%d)\n", conf.www_port, (ipv6 ? 6 : 4));
|
||||
}
|
||||
www_init();
|
||||
if (ipv6) {
|
||||
www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION|MHD_USE_IPv6, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END);
|
||||
www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END);
|
||||
} else {
|
||||
www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END);
|
||||
}
|
||||
@ -1205,7 +1186,6 @@ void server(int port, int ipv6) {
|
||||
|
||||
listen(server_socket, 3);
|
||||
|
||||
|
||||
while ((client_sock = accept(server_socket, (struct sockaddr *)client_p, (socklen_t *)&c))) {
|
||||
if (ipv6) {
|
||||
ip = strdup(inet_ntop(AF_INET6, &((struct sockaddr_in6 *)client_p)->sin6_addr, str, sizeof(str)));
|
||||
@ -1219,10 +1199,10 @@ void server(int port, int ipv6) {
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (conf.ipguard_enable) {
|
||||
i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard));
|
||||
|
||||
|
||||
if (i == MAP_MISSING) {
|
||||
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
|
||||
ip_guard->status = IP_STATUS_UNKNOWN;
|
||||
@ -1230,7 +1210,7 @@ void server(int port, int ipv6) {
|
||||
ip_guard->connection_count = 1;
|
||||
hashmap_put(ip_guard_map, strdup(ip), ip_guard);
|
||||
} else if (i == MAP_OK) {
|
||||
|
||||
|
||||
if (ip_guard->status == IP_STATUS_BLACKLISTED) {
|
||||
write(client_sock, "BLOCKED\r\n", 9);
|
||||
free(ip);
|
||||
@ -1249,14 +1229,13 @@ void server(int port, int ipv6) {
|
||||
free(ip);
|
||||
close(client_sock);
|
||||
continue;
|
||||
|
||||
}
|
||||
} else {
|
||||
ip_guard->connection_count = 0;
|
||||
ip_guard->last_connection = time(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pid = fork();
|
||||
|
||||
@ -1284,7 +1263,7 @@ int main(int argc, char **argv) {
|
||||
FILE *fptr;
|
||||
struct stat s;
|
||||
char buffer[1024];
|
||||
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage ./magicka config/bbs.ini\n");
|
||||
exit(1);
|
||||
@ -1319,38 +1298,38 @@ int main(int argc, char **argv) {
|
||||
conf.ipguard_enable = 0;
|
||||
conf.ipguard_tries = 4;
|
||||
conf.ipguard_timeout = 120;
|
||||
conf.protocol_count = 0;
|
||||
conf.protocol_count = 0;
|
||||
conf.codepage = 0;
|
||||
conf.date_style = 0;
|
||||
conf.ipv6 = 0;
|
||||
conf.uid = getuid();
|
||||
conf.gid = getgid();
|
||||
// Load BBS data
|
||||
if (ini_parse(argv[1], handler, &conf) <0) {
|
||||
if (ini_parse(argv[1], handler, &conf) < 0) {
|
||||
fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
if (conf.config_path == NULL) {
|
||||
fprintf(stderr, "Config Path must be set in your bbs ini!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
if (conf.root_menu == NULL) {
|
||||
fprintf(stderr, "Root Menu must be set in your bbs ini!\n");
|
||||
exit(-1);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Load mail Areas
|
||||
for (i=0;i<conf.mail_conference_count;i++) {
|
||||
if (ini_parse(conf.mail_conferences[i]->path, mail_area_handler, conf.mail_conferences[i]) <0) {
|
||||
for (i = 0; i < conf.mail_conference_count; i++) {
|
||||
if (ini_parse(conf.mail_conferences[i]->path, mail_area_handler, conf.mail_conferences[i]) < 0) {
|
||||
fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.mail_conferences[i]->path);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
// Load file Subs
|
||||
for (i=0;i<conf.file_directory_count;i++) {
|
||||
if (ini_parse(conf.file_directories[i]->path, file_sub_handler, conf.file_directories[i]) <0) {
|
||||
for (i = 0; i < conf.file_directory_count; i++) {
|
||||
if (ini_parse(conf.file_directories[i]->path, file_sub_handler, conf.file_directories[i]) < 0) {
|
||||
fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.file_directories[i]->path);
|
||||
exit(-1);
|
||||
}
|
||||
@ -1358,24 +1337,23 @@ int main(int argc, char **argv) {
|
||||
|
||||
snprintf(buffer, 1024, "%s/doors.ini", conf.config_path);
|
||||
|
||||
if (ini_parse(buffer, door_config_handler, &conf) <0) {
|
||||
if (ini_parse(buffer, door_config_handler, &conf) < 0) {
|
||||
fprintf(stderr, "Unable to load configuration ini (doors.ini)!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
snprintf(buffer, 1024, "%s/archivers.ini", conf.config_path);
|
||||
if (ini_parse(buffer, archiver_config_handler, &conf) <0) {
|
||||
if (ini_parse(buffer, archiver_config_handler, &conf) < 0) {
|
||||
fprintf(stderr, "Unable to load configuration ini %s\n", buffer);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
snprintf(buffer, 1024, "%s/protocols.ini", conf.config_path);
|
||||
if (ini_parse(buffer, protocol_config_handler, &conf) <0) {
|
||||
if (ini_parse(buffer, protocol_config_handler, &conf) < 0) {
|
||||
fprintf(stderr, "Unable to load configuration ini %s\n", buffer);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
load_strings();
|
||||
|
||||
if (conf.fork) {
|
||||
@ -1389,8 +1367,7 @@ int main(int argc, char **argv) {
|
||||
if (main_pid < 0) {
|
||||
fprintf(stderr, "Error forking.\n");
|
||||
exit(-1);
|
||||
} else
|
||||
if (main_pid > 0) {
|
||||
} else if (main_pid > 0) {
|
||||
if (conf.uid != getuid()) {
|
||||
if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) {
|
||||
perror("Setuid Error: ");
|
||||
@ -1405,7 +1382,7 @@ int main(int argc, char **argv) {
|
||||
fclose(fptr);
|
||||
}
|
||||
} else {
|
||||
for (i=1;i<=conf.nodes;i++) {
|
||||
for (i = 1; i <= conf.nodes; i++) {
|
||||
snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i);
|
||||
if (stat(buffer, &s) == 0) {
|
||||
unlink(buffer);
|
||||
@ -1415,7 +1392,7 @@ int main(int argc, char **argv) {
|
||||
ipv6_pid = fork();
|
||||
if (ipv6_pid < 0) {
|
||||
fprintf(stderr, "Error forking.\n");
|
||||
exit(-1);
|
||||
exit(-1);
|
||||
} else if (ipv6_pid > 0) {
|
||||
server(conf.telnet_port, 0);
|
||||
} else {
|
||||
@ -1429,18 +1406,18 @@ int main(int argc, char **argv) {
|
||||
} else {
|
||||
printf("Magicka BBS Server Starting....\n");
|
||||
|
||||
for (i=1;i<=conf.nodes;i++) {
|
||||
for (i = 1; i <= conf.nodes; i++) {
|
||||
snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i);
|
||||
if (stat(buffer, &s) == 0) {
|
||||
printf(" - Removing stale file: nodeinuse.%d\n", i);
|
||||
unlink(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (conf.ipv6) {
|
||||
ipv6_pid = fork();
|
||||
if (ipv6_pid < 0) {
|
||||
fprintf(stderr, "Error forking.\n");
|
||||
exit(-1);
|
||||
exit(-1);
|
||||
} else if (ipv6_pid > 0) {
|
||||
server(conf.telnet_port, 0);
|
||||
} else {
|
||||
|
@ -17,7 +17,7 @@ void display_bulletins() {
|
||||
char buffer[PATH_MAX];
|
||||
struct stat s;
|
||||
i = 0;
|
||||
|
||||
|
||||
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
|
||||
|
||||
while (stat(buffer, &s) == 0) {
|
||||
@ -37,15 +37,15 @@ void active_nodes() {
|
||||
char buffer[PATH_MAX];
|
||||
FILE *fptr;
|
||||
|
||||
for (i=0;i<conf.nodes;i++) {
|
||||
snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i+1);
|
||||
for (i = 0; i < conf.nodes; i++) {
|
||||
snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i + 1);
|
||||
if (stat(buffer, &s) == 0) {
|
||||
fptr = fopen(buffer, "r");
|
||||
if (fptr) {
|
||||
if (fptr) {
|
||||
fgets(buffer, PATH_MAX, fptr);
|
||||
fclose(fptr);
|
||||
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(185));
|
||||
s_getc();
|
||||
s_printf("\r\n");
|
||||
s_printf("\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ void display_textfiles() {
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(143));
|
||||
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) {
|
||||
s_printf(get_string(249), i - start + 2, i, conf.text_files[i]->name);
|
||||
} else {
|
||||
@ -137,7 +137,7 @@ void display_textfiles() {
|
||||
if (selected >= conf.text_file_count) {
|
||||
selected = conf.text_file_count - 1;
|
||||
} else {
|
||||
if (!redraw) {
|
||||
if (!redraw) {
|
||||
s_printf(get_string(250), selected - start + 1, selected - 1, conf.text_files[selected - 1]->name);
|
||||
s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name);
|
||||
s_printf("\e[%d;5H", selected - start + 2);
|
||||
@ -156,11 +156,11 @@ void display_textfiles() {
|
||||
if (selected < 0) {
|
||||
selected = 0;
|
||||
} else {
|
||||
if (!redraw) {
|
||||
if (!redraw) {
|
||||
s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name);
|
||||
s_printf(get_string(250), selected - start + 3, selected + 1, conf.text_files[selected + 1]->name);
|
||||
s_printf("\e[%d;5H", selected - start + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (c == 75) {
|
||||
// END KEY
|
||||
@ -193,7 +193,7 @@ void display_textfiles() {
|
||||
// PAGE DOWN
|
||||
selected = selected + 22;
|
||||
if (selected >= conf.text_file_count) {
|
||||
selected = conf.text_file_count -1;
|
||||
selected = conf.text_file_count - 1;
|
||||
}
|
||||
start = selected;
|
||||
redraw = 1;
|
||||
@ -204,7 +204,7 @@ void display_textfiles() {
|
||||
s_displayansi_p(conf.text_files[selected]->path);
|
||||
s_printf(get_string(185));
|
||||
s_getc();
|
||||
s_printf("\r\n");
|
||||
s_printf("\r\n");
|
||||
redraw = 1;
|
||||
}
|
||||
}
|
||||
|
1214
src/menus.c
1214
src/menus.c
File diff suppressed because it is too large
Load Diff
@ -8,22 +8,22 @@ extern struct user_record *gUser;
|
||||
|
||||
char *nl_get_bbsname(struct fido_addr *addr, char *domain) {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
char *ret;
|
||||
char *sql_buf = "SELECT bbsname FROM nodelist WHERE nodeno=? AND domain=?";
|
||||
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path);
|
||||
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return strdup("Unknown");
|
||||
}
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return strdup("Unknown");
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
@ -31,22 +31,22 @@ char *nl_get_bbsname(struct fido_addr *addr, char *domain) {
|
||||
return strdup("Unknown");
|
||||
}
|
||||
|
||||
if (addr->point == 0) {
|
||||
snprintf(buffer, PATH_MAX, "%d:%d/%d", addr->zone, addr->net, addr->node);
|
||||
} else {
|
||||
// no support for point addresses yet.
|
||||
return strdup("Unknown");
|
||||
}
|
||||
if (addr->point == 0) {
|
||||
snprintf(buffer, PATH_MAX, "%d:%d/%d", addr->zone, addr->net, addr->node);
|
||||
} else {
|
||||
// no support for point addresses yet.
|
||||
return strdup("Unknown");
|
||||
}
|
||||
|
||||
sqlite3_bind_text(res, 1, buffer, -1, 0);
|
||||
sqlite3_bind_text(res, 2, domain, -1, 0);
|
||||
|
||||
sqlite3_bind_text(res, 1, buffer, -1, 0);
|
||||
sqlite3_bind_text(res, 2, domain, -1, 0);
|
||||
|
||||
if (sqlite3_step(res) != SQLITE_ROW) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return strdup("Unknown");
|
||||
}
|
||||
ret = strdup(sqlite3_column_text(res, 0));
|
||||
}
|
||||
ret = strdup(sqlite3_column_text(res, 0));
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
@ -64,7 +64,7 @@ void nl_browser() {
|
||||
int entry_count = 0;
|
||||
struct nl_temp **entries;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
char *ret;
|
||||
@ -77,15 +77,15 @@ void nl_browser() {
|
||||
|
||||
// load nodelist
|
||||
snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path);
|
||||
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return;
|
||||
}
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
@ -93,8 +93,8 @@ void nl_browser() {
|
||||
return;
|
||||
}
|
||||
|
||||
sqlite3_bind_text(res, 1, conf.mail_conferences[gUser->cur_mail_conf]->domain, -1, 0);
|
||||
|
||||
sqlite3_bind_text(res, 1, conf.mail_conferences[gUser->cur_mail_conf]->domain, -1, 0);
|
||||
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (entry_count == 0) {
|
||||
entries = (struct nl_temp **)malloc(sizeof(struct nl_temp *));
|
||||
@ -108,10 +108,10 @@ void nl_browser() {
|
||||
entries[entry_count]->sysop = strdup(sqlite3_column_text(res, 2));
|
||||
entries[entry_count]->bbsname = strdup(sqlite3_column_text(res, 3));
|
||||
entry_count++;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
|
||||
if (entry_count == 0) {
|
||||
return;
|
||||
}
|
||||
@ -121,7 +121,7 @@ void nl_browser() {
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(145));
|
||||
s_printf(get_string(146));
|
||||
for (i=start;i<start+22 && i < entry_count;i++) {
|
||||
for (i = start; i < start + 22 && i < entry_count; i++) {
|
||||
if (i == selected) {
|
||||
s_printf(get_string(147), i - start + 2, i, entries[i]->address, entries[i]->bbsname);
|
||||
} else {
|
||||
@ -151,7 +151,7 @@ void nl_browser() {
|
||||
if (selected >= entry_count) {
|
||||
selected = entry_count - 1;
|
||||
} else {
|
||||
if (!redraw) {
|
||||
if (!redraw) {
|
||||
s_printf(get_string(261), selected - start + 1, selected - 1, entries[selected - 1]->address, entries[selected - 1]->bbsname);
|
||||
s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname);
|
||||
s_printf("\e[%d;5H", selected - start + 2);
|
||||
@ -170,11 +170,11 @@ void nl_browser() {
|
||||
if (selected < 0) {
|
||||
selected = 0;
|
||||
} else {
|
||||
if (!redraw) {
|
||||
if (!redraw) {
|
||||
s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname);
|
||||
s_printf(get_string(261), selected - start + 3, selected + 1, entries[selected + 1]->address, entries[selected + 1]->bbsname);
|
||||
s_printf("\e[%d;5H", selected - start + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (c == 75) {
|
||||
// END KEY
|
||||
@ -207,7 +207,7 @@ void nl_browser() {
|
||||
// PAGE DOWN
|
||||
selected = selected + 22;
|
||||
if (selected >= entry_count) {
|
||||
selected = entry_count -1;
|
||||
selected = entry_count - 1;
|
||||
}
|
||||
start = selected;
|
||||
redraw = 1;
|
||||
@ -223,11 +223,11 @@ void nl_browser() {
|
||||
s_printf(get_string(267));
|
||||
s_printf(get_string(185));
|
||||
s_getc();
|
||||
s_printf("\r\n");
|
||||
s_printf("\r\n");
|
||||
redraw = 1;
|
||||
}
|
||||
}
|
||||
for (i=0;i<entry_count;i++) {
|
||||
for (i = 0; i < entry_count; i++) {
|
||||
free(entries[i]->address);
|
||||
free(entries[i]->bbsname);
|
||||
free(entries[i]->sysop);
|
||||
|
@ -12,32 +12,31 @@ int openpty(int *amaster, int *aslave, char *name, void *termp, void *winp) {
|
||||
int pts;
|
||||
|
||||
ptm = open("/dev/ptmx", O_RDWR);
|
||||
|
||||
|
||||
grantpt(ptm);
|
||||
unlockpt(ptm);
|
||||
|
||||
pname = ptsname(ptm);
|
||||
|
||||
|
||||
if (name != NULL) {
|
||||
strcpy(name, pname);
|
||||
}
|
||||
}
|
||||
|
||||
pts = open(pname, O_RDWR);
|
||||
ioctl(pts, I_PUSH, "ptem");
|
||||
ioctl(pts, I_PUSH, "ldterm");
|
||||
ioctl(pts, I_PUSH, "ttcompat");
|
||||
|
||||
if (termp != NULL) {
|
||||
tcsetattr(pts, TCSAFLUSH, termp);
|
||||
}
|
||||
if (winp != NULL) {
|
||||
ioctl(pts, TIOCSWINSZ, winp);
|
||||
}
|
||||
|
||||
if (termp != NULL) {
|
||||
tcsetattr(pts, TCSAFLUSH, termp);
|
||||
}
|
||||
if (winp != NULL) {
|
||||
ioctl(pts, TIOCSWINSZ, winp);
|
||||
}
|
||||
|
||||
*amaster = ptm;
|
||||
*aslave = pts;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -52,7 +51,7 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) {
|
||||
|
||||
grantpt(ptm);
|
||||
unlockpt(ptm);
|
||||
|
||||
|
||||
pname = ptsname(ptm);
|
||||
|
||||
if (name != NULL) {
|
||||
@ -71,7 +70,7 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) {
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
|
||||
|
||||
if (!pid) {
|
||||
close(ptm);
|
||||
dup2(pts, 0);
|
||||
@ -82,16 +81,15 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) {
|
||||
*amaster = ptm;
|
||||
}
|
||||
|
||||
return pid;
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
||||
static long difftm(struct tm *a, struct tm *b) {
|
||||
int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
|
||||
int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
|
||||
long days = (a->tm_yday - b->tm_yday + ((ay >> 2) - (by >> 2)) - (ay / 100 - by/100) + ((ay/100 >> 2) - (by / 100 >> 2)) + (long)(ay-by) * 365);
|
||||
long days = (a->tm_yday - b->tm_yday + ((ay >> 2) - (by >> 2)) - (ay / 100 - by / 100) + ((ay / 100 >> 2) - (by / 100 >> 2)) + (long)(ay - by) * 365);
|
||||
|
||||
return (60 * (60 * (24 *days + (a->tm_hour - b->tm_hour)) + (a->tm_min - b->tm_min)) + (a->tm_sec - b->tm_sec));
|
||||
return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) + (a->tm_min - b->tm_min)) + (a->tm_sec - b->tm_sec));
|
||||
}
|
||||
|
||||
long gmtoff(time_t value) {
|
||||
|
@ -5,4 +5,3 @@ extern int openpty(int *amaster, int *aslave, char *name, void *termp, void *win
|
||||
extern int forkpty(int *amaster, char *name, void *termp, void *winp);
|
||||
extern long gmtoff(time_t value);
|
||||
#endif
|
||||
|
||||
|
214
src/settings.c
214
src/settings.c
@ -44,138 +44,116 @@ void settings_menu(struct user_record *user) {
|
||||
|
||||
c = s_getc();
|
||||
|
||||
switch(tolower(c)) {
|
||||
case 27:
|
||||
{
|
||||
switch (tolower(c)) {
|
||||
case 27: {
|
||||
c = s_getc();
|
||||
if (c == 91) {
|
||||
c = s_getc();
|
||||
if (c == 91) {
|
||||
c = s_getc();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
{
|
||||
s_printf(get_string(155));
|
||||
s_readpass(buffer, 16);
|
||||
hash = hash_sha256(buffer, user->salt);
|
||||
if (strcmp(hash, user->password) == 0) {
|
||||
s_printf(get_string(156));
|
||||
s_readstring(buffer, 16);
|
||||
if (strlen(buffer) >= 8) {
|
||||
free(user->password);
|
||||
free(user->salt);
|
||||
} break;
|
||||
case 'p': {
|
||||
s_printf(get_string(155));
|
||||
s_readpass(buffer, 16);
|
||||
hash = hash_sha256(buffer, user->salt);
|
||||
if (strcmp(hash, user->password) == 0) {
|
||||
s_printf(get_string(156));
|
||||
s_readstring(buffer, 16);
|
||||
if (strlen(buffer) >= 8) {
|
||||
free(user->password);
|
||||
free(user->salt);
|
||||
|
||||
gen_salt(&user->salt);
|
||||
user->password = hash_sha256(buffer, user->salt);
|
||||
gen_salt(&user->salt);
|
||||
user->password = hash_sha256(buffer, user->salt);
|
||||
|
||||
save_user(user);
|
||||
s_printf(get_string(157));
|
||||
} else {
|
||||
s_printf(get_string(158));
|
||||
}
|
||||
} else {
|
||||
s_printf(get_string(159));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
{
|
||||
s_printf(get_string(160));
|
||||
s_readstring(buffer, 32);
|
||||
free(user->location);
|
||||
user->location = (char *)malloc(strlen(buffer) + 1);
|
||||
strcpy(user->location, buffer);
|
||||
save_user(user);
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
{
|
||||
s_printf(get_string(206));
|
||||
|
||||
for (i=0;i<conf.archiver_count;i++) {
|
||||
s_printf(get_string(207), i + 1, conf.archivers[i]->name);
|
||||
}
|
||||
|
||||
s_printf(get_string(208));
|
||||
s_readstring(buffer, 5);
|
||||
new_arc = atoi(buffer);
|
||||
|
||||
if (new_arc - 1 < 0 || new_arc > conf.archiver_count) {
|
||||
break;
|
||||
} else {
|
||||
user->defarchiver = new_arc;
|
||||
save_user(user);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case '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;
|
||||
s_printf(get_string(157));
|
||||
} else {
|
||||
user->defprotocol = new_arc;
|
||||
save_user(user);
|
||||
s_printf(get_string(158));
|
||||
}
|
||||
} else {
|
||||
s_printf(get_string(159));
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
{
|
||||
user->nodemsgs = !user->nodemsgs;
|
||||
} break;
|
||||
case 'l': {
|
||||
s_printf(get_string(160));
|
||||
s_readstring(buffer, 32);
|
||||
free(user->location);
|
||||
user->location = (char *)malloc(strlen(buffer) + 1);
|
||||
strcpy(user->location, buffer);
|
||||
save_user(user);
|
||||
} break;
|
||||
case 'a': {
|
||||
s_printf(get_string(206));
|
||||
|
||||
for (i = 0; i < conf.archiver_count; i++) {
|
||||
s_printf(get_string(207), i + 1, conf.archivers[i]->name);
|
||||
}
|
||||
|
||||
s_printf(get_string(208));
|
||||
s_readstring(buffer, 5);
|
||||
new_arc = atoi(buffer);
|
||||
|
||||
if (new_arc - 1 < 0 || new_arc > conf.archiver_count) {
|
||||
break;
|
||||
} else {
|
||||
user->defarchiver = new_arc;
|
||||
save_user(user);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
{
|
||||
user->codepage = !user->codepage;
|
||||
} break;
|
||||
|
||||
case 'o': {
|
||||
s_printf(get_string(212));
|
||||
|
||||
for (i = 0; i < conf.protocol_count; i++) {
|
||||
s_printf(get_string(207), i + 1, conf.protocols[i]->name);
|
||||
}
|
||||
|
||||
s_printf(get_string(208));
|
||||
s_readstring(buffer, 5);
|
||||
new_arc = atoi(buffer);
|
||||
|
||||
if (new_arc - 1 < 0 || new_arc > conf.protocol_count) {
|
||||
break;
|
||||
} else {
|
||||
user->defprotocol = new_arc;
|
||||
save_user(user);
|
||||
}
|
||||
break;
|
||||
case 'e':
|
||||
{
|
||||
user->exteditor++;
|
||||
if (user->exteditor == 3) {
|
||||
user->exteditor = 0;
|
||||
}
|
||||
} break;
|
||||
case 'm': {
|
||||
user->nodemsgs = !user->nodemsgs;
|
||||
save_user(user);
|
||||
} break;
|
||||
case 'c': {
|
||||
user->codepage = !user->codepage;
|
||||
save_user(user);
|
||||
} break;
|
||||
case 'e': {
|
||||
user->exteditor++;
|
||||
if (user->exteditor == 3) {
|
||||
user->exteditor = 0;
|
||||
}
|
||||
save_user(user);
|
||||
} break;
|
||||
case 'b': {
|
||||
user->bwavepktno = 0;
|
||||
user->bwavestyle = !user->bwavestyle;
|
||||
save_user(user);
|
||||
} break;
|
||||
case 's': {
|
||||
// set signature
|
||||
if (user->signature != NULL) {
|
||||
free(user->signature);
|
||||
}
|
||||
sig = external_editor(user, "No-One", "No-One", NULL, 0, "No-One", "Signature Editor", 0, 1);
|
||||
if (sig != NULL) {
|
||||
user->signature = sig;
|
||||
save_user(user);
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
{
|
||||
user->bwavepktno = 0;
|
||||
user->bwavestyle = !user->bwavestyle;
|
||||
save_user(user);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
{
|
||||
// set signature
|
||||
if (user->signature != NULL) {
|
||||
free(user->signature);
|
||||
}
|
||||
sig = external_editor(user, "No-One", "No-One", NULL, 0, "No-One", "Signature Editor", 0, 1);
|
||||
if (sig != NULL) {
|
||||
user->signature = sig;
|
||||
save_user(user);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
{
|
||||
user->autosig = !user->autosig;
|
||||
save_user(user);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case 't': {
|
||||
user->autosig = !user->autosig;
|
||||
save_user(user);
|
||||
} break;
|
||||
case 'q':
|
||||
dosettings = 1;
|
||||
break;
|
||||
|
@ -10,8 +10,8 @@ char **strings;
|
||||
int string_count;
|
||||
|
||||
void chomp(char *string) {
|
||||
while (strlen(string) && (string[strlen(string)-1] == '\r' || string[strlen(string)-1] == '\n')) {
|
||||
string[strlen(string)-1] = '\0';
|
||||
while (strlen(string) && (string[strlen(string) - 1] == '\r' || string[strlen(string) - 1] == '\n')) {
|
||||
string[strlen(string) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ char *parse_newlines(char *string) {
|
||||
char *newstring = (char *)malloc(strlen(string) + 1);
|
||||
int pos = 0;
|
||||
int i;
|
||||
for (i=0;i<strlen(string);i++) {
|
||||
for (i = 0; i < strlen(string); i++) {
|
||||
if (string[i] == '\\') {
|
||||
if (i < strlen(string) - 1) {
|
||||
i++;
|
||||
|
611
src/users.c
611
src/users.c
@ -7,7 +7,7 @@
|
||||
#include "bbs.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_free EVP_MD_CTX_destroy
|
||||
#endif
|
||||
@ -29,23 +29,21 @@ char *hash_sha256(char *pass, char *salt) {
|
||||
|
||||
sprintf(buffer, "%s%s", pass, salt);
|
||||
|
||||
|
||||
EVP_MD_CTX *context = EVP_MD_CTX_new();
|
||||
|
||||
if (context != NULL) {
|
||||
if(EVP_DigestInit_ex(context, EVP_sha256(), NULL)) {
|
||||
if(EVP_DigestUpdate(context, buffer, strlen(buffer))) {
|
||||
if(EVP_DigestFinal_ex(context, hash, &length_of_hash)) {
|
||||
if (EVP_DigestInit_ex(context, EVP_sha256(), NULL)) {
|
||||
if (EVP_DigestUpdate(context, buffer, strlen(buffer))) {
|
||||
if (EVP_DigestFinal_ex(context, hash, &length_of_hash)) {
|
||||
|
||||
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]);
|
||||
|
||||
}
|
||||
}
|
||||
EVP_MD_CTX_free(context);
|
||||
free(buffer);
|
||||
return shash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EVP_MD_CTX_free(context);
|
||||
@ -73,7 +71,7 @@ void gen_salt(char **s) {
|
||||
dolog("Unable to open /dev/urandom!");
|
||||
exit(-1);
|
||||
}
|
||||
for (i=0;i<10;i++) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
fread(&c, 1, 1, fptr);
|
||||
salt[i] = (char)((abs(c) % 93) + 33);
|
||||
}
|
||||
@ -81,9 +79,8 @@ void gen_salt(char **s) {
|
||||
salt[10] = '\0';
|
||||
}
|
||||
|
||||
static int secLevel(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
static int secLevel(void *user, const char *section, const char *name,
|
||||
const char *value) {
|
||||
struct sec_level_t *conf = (struct sec_level_t *)user;
|
||||
|
||||
if (strcasecmp(section, "main") == 0) {
|
||||
@ -97,142 +94,139 @@ static int secLevel(void* user, const char* section, const char* name,
|
||||
int save_user(struct user_record *user) {
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
|
||||
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);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, update_sql, -1, &res, 0);
|
||||
rc = sqlite3_prepare_v2(db, update_sql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, user->password, -1, 0);
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, user->password, -1, 0);
|
||||
sqlite3_bind_text(res, 2, user->salt, -1, 0);
|
||||
sqlite3_bind_text(res, 3, user->firstname, -1, 0);
|
||||
sqlite3_bind_text(res, 4, user->lastname, -1, 0);
|
||||
sqlite3_bind_text(res, 5, user->email, -1, 0);
|
||||
sqlite3_bind_text(res, 6, user->location, -1, 0);
|
||||
sqlite3_bind_int(res, 7, user->sec_level);
|
||||
sqlite3_bind_int(res, 8, user->laston);
|
||||
sqlite3_bind_int(res, 9, user->timeleft);
|
||||
sqlite3_bind_int(res, 10, user->cur_mail_conf);
|
||||
sqlite3_bind_int(res, 11, user->cur_mail_area);
|
||||
sqlite3_bind_int(res, 12, user->cur_file_dir);
|
||||
sqlite3_bind_int(res, 13, user->cur_file_sub);
|
||||
sqlite3_bind_int(res, 14, user->timeson);
|
||||
sqlite3_bind_int(res, 15, user->bwavepktno);
|
||||
sqlite3_bind_int(res, 16, user->defarchiver);
|
||||
sqlite3_bind_int(res, 17, user->defprotocol);
|
||||
sqlite3_bind_text(res, 3, user->firstname, -1, 0);
|
||||
sqlite3_bind_text(res, 4, user->lastname, -1, 0);
|
||||
sqlite3_bind_text(res, 5, user->email, -1, 0);
|
||||
sqlite3_bind_text(res, 6, user->location, -1, 0);
|
||||
sqlite3_bind_int(res, 7, user->sec_level);
|
||||
sqlite3_bind_int(res, 8, user->laston);
|
||||
sqlite3_bind_int(res, 9, user->timeleft);
|
||||
sqlite3_bind_int(res, 10, user->cur_mail_conf);
|
||||
sqlite3_bind_int(res, 11, user->cur_mail_area);
|
||||
sqlite3_bind_int(res, 12, user->cur_file_dir);
|
||||
sqlite3_bind_int(res, 13, user->cur_file_sub);
|
||||
sqlite3_bind_int(res, 14, user->timeson);
|
||||
sqlite3_bind_int(res, 15, user->bwavepktno);
|
||||
sqlite3_bind_int(res, 16, user->defarchiver);
|
||||
sqlite3_bind_int(res, 17, user->defprotocol);
|
||||
sqlite3_bind_int(res, 18, user->nodemsgs);
|
||||
sqlite3_bind_int(res, 19, user->codepage);
|
||||
sqlite3_bind_int(res, 20, user->exteditor);
|
||||
sqlite3_bind_int(res, 21, user->bwavestyle);
|
||||
sqlite3_bind_text(res, 22, user->signature, -1, 0);
|
||||
sqlite3_bind_int(res, 23, user->autosig);
|
||||
sqlite3_bind_text(res, 24, user->loginname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
}
|
||||
sqlite3_bind_text(res, 24, user->loginname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
if (rc != SQLITE_DONE) {
|
||||
rc = sqlite3_step(res);
|
||||
if (rc != SQLITE_DONE) {
|
||||
sqlite3_finalize(res);
|
||||
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, int msgid) {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
char *create_sql = "CREATE TABLE IF NOT EXISTS msg_flags (conference INTEGER, msgbase INTEGER, uid INTEGER, msg INTEGER);";
|
||||
char *flag_buf = "INSERT INTO msg_flags (conference, msgbase, uid, msg) VALUES(?, ?, ?, ?)";
|
||||
char *unflag_buf = "DELETE FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?";
|
||||
char *err_msg = 0;
|
||||
int flagunflag = 0;
|
||||
|
||||
|
||||
flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid);
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
char *err_msg = 0;
|
||||
int flagunflag = 0;
|
||||
|
||||
flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid);
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
dolog("SQL error: %s", err_msg);
|
||||
dolog("SQL error: %s", err_msg);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (flagunflag == 1) {
|
||||
return 0;
|
||||
}
|
||||
if (flagunflag == 1) {
|
||||
rc = sqlite3_prepare_v2(db, unflag_buf, -1, &res, 0);
|
||||
} else {
|
||||
rc = sqlite3_prepare_v2(db, flag_buf, -1, &res, 0);
|
||||
}
|
||||
|
||||
sqlite3_bind_int(res, 1, conference);
|
||||
sqlite3_bind_int(res, 2, msgbase);
|
||||
sqlite3_bind_int(res, 3, user->id);
|
||||
sqlite3_bind_int(res, 4, msgid);
|
||||
sqlite3_bind_int(res, 1, conference);
|
||||
sqlite3_bind_int(res, 2, msgbase);
|
||||
sqlite3_bind_int(res, 3, user->id);
|
||||
sqlite3_bind_int(res, 4, msgid);
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, int msgid) {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
|
||||
char *sql_buf = "SELECT * FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?";
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
char *sql_buf = "SELECT * FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?";
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
@ -240,16 +234,16 @@ int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, in
|
||||
return 0;
|
||||
}
|
||||
|
||||
sqlite3_bind_int(res, 1, conference);
|
||||
sqlite3_bind_int(res, 2, msgbase);
|
||||
sqlite3_bind_int(res, 3, user->id);
|
||||
sqlite3_bind_int(res, 1, conference);
|
||||
sqlite3_bind_int(res, 2, msgbase);
|
||||
sqlite3_bind_int(res, 3, user->id);
|
||||
sqlite3_bind_int(res, 4, msgid);
|
||||
|
||||
|
||||
if (sqlite3_step(res) != SQLITE_ROW) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
@ -257,79 +251,76 @@ int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, in
|
||||
|
||||
int msgbase_sub_unsub(int conference, int msgbase) {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
char *create_sql = "CREATE TABLE IF NOT EXISTS msg_subs (conference INTEGER, msgbase INTEGER, uid INTEGER);";
|
||||
char *sub_buf = "INSERT INTO msg_subs (conference, msgbase, uid) VALUES(?, ?, ?)";
|
||||
char *unsub_buf = "DELETE FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
|
||||
char *err_msg = 0;
|
||||
int subunsub = 0;
|
||||
|
||||
|
||||
subunsub = msgbase_is_subscribed(conference, msgbase);
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
char *err_msg = 0;
|
||||
int subunsub = 0;
|
||||
|
||||
subunsub = msgbase_is_subscribed(conference, msgbase);
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
dolog("SQL error: %s", err_msg);
|
||||
dolog("SQL error: %s", err_msg);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (subunsub == 1) {
|
||||
return 0;
|
||||
}
|
||||
if (subunsub == 1) {
|
||||
rc = sqlite3_prepare_v2(db, unsub_buf, -1, &res, 0);
|
||||
} else {
|
||||
rc = sqlite3_prepare_v2(db, sub_buf, -1, &res, 0);
|
||||
}
|
||||
|
||||
sqlite3_bind_int(res, 1, conference);
|
||||
sqlite3_bind_int(res, 2, msgbase);
|
||||
sqlite3_bind_int(res, 3, gUser->id);
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
sqlite3_bind_int(res, 1, conference);
|
||||
sqlite3_bind_int(res, 2, msgbase);
|
||||
sqlite3_bind_int(res, 3, gUser->id);
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int msgbase_is_subscribed(int conference, int msgbase) {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
|
||||
char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
|
||||
|
||||
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
@ -337,15 +328,15 @@ int msgbase_is_subscribed(int conference, int msgbase) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sqlite3_bind_int(res, 1, conference);
|
||||
sqlite3_bind_int(res, 2, msgbase);
|
||||
sqlite3_bind_int(res, 3, gUser->id);
|
||||
|
||||
sqlite3_bind_int(res, 1, conference);
|
||||
sqlite3_bind_int(res, 2, msgbase);
|
||||
sqlite3_bind_int(res, 3, gUser->id);
|
||||
|
||||
if (sqlite3_step(res) != SQLITE_ROW) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
@ -354,79 +345,79 @@ int msgbase_is_subscribed(int conference, int msgbase) {
|
||||
int inst_user(struct user_record *user) {
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *create_sql = "CREATE TABLE IF NOT EXISTS users ("
|
||||
"Id INTEGER PRIMARY KEY,"
|
||||
"loginname TEXT COLLATE NOCASE,"
|
||||
"password TEXT,"
|
||||
"salt TEXT,"
|
||||
"firstname TEXT,"
|
||||
"lastname TEXT,"
|
||||
"email TEXT,"
|
||||
"location TEXT,"
|
||||
"sec_level INTEGER,"
|
||||
"last_on INTEGER,"
|
||||
"time_left INTEGER,"
|
||||
"cur_mail_conf INTEGER,"
|
||||
"cur_mail_area INTEGER,"
|
||||
"cur_file_sub INTEGER,"
|
||||
"cur_file_dir INTEGER,"
|
||||
"times_on INTEGER,"
|
||||
"bwavepktno INTEGER,"
|
||||
"archiver INTEGER,"
|
||||
"protocol INTEGER,"
|
||||
"nodemsgs INTEGER,"
|
||||
"codepage INTEGER,"
|
||||
"exteditor INTEGER,"
|
||||
"bwavestyle INTEGER,"
|
||||
"signature TEXT,"
|
||||
"autosig INTEGER);";
|
||||
char *create_sql = "CREATE TABLE IF NOT EXISTS users ("
|
||||
"Id INTEGER PRIMARY KEY,"
|
||||
"loginname TEXT COLLATE NOCASE,"
|
||||
"password TEXT,"
|
||||
"salt TEXT,"
|
||||
"firstname TEXT,"
|
||||
"lastname TEXT,"
|
||||
"email TEXT,"
|
||||
"location TEXT,"
|
||||
"sec_level INTEGER,"
|
||||
"last_on INTEGER,"
|
||||
"time_left INTEGER,"
|
||||
"cur_mail_conf INTEGER,"
|
||||
"cur_mail_area INTEGER,"
|
||||
"cur_file_sub INTEGER,"
|
||||
"cur_file_dir INTEGER,"
|
||||
"times_on INTEGER,"
|
||||
"bwavepktno INTEGER,"
|
||||
"archiver INTEGER,"
|
||||
"protocol INTEGER,"
|
||||
"nodemsgs INTEGER,"
|
||||
"codepage INTEGER,"
|
||||
"exteditor INTEGER,"
|
||||
"bwavestyle INTEGER,"
|
||||
"signature TEXT,"
|
||||
"autosig INTEGER);";
|
||||
|
||||
char *insert_sql = "INSERT INTO users (loginname, password, salt, firstname,"
|
||||
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage, exteditor, bwavestyle, signature, autosig) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
char *err_msg = 0;
|
||||
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage, exteditor, bwavestyle, signature, autosig) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
char *err_msg = 0;
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
dolog("SQL error: %s", err_msg);
|
||||
dolog("SQL error: %s", err_msg);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
|
||||
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||
sqlite3_bind_text(res, 2, user->password, -1, 0);
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||
sqlite3_bind_text(res, 2, user->password, -1, 0);
|
||||
sqlite3_bind_text(res, 3, user->salt, -1, 0);
|
||||
sqlite3_bind_text(res, 4, user->firstname, -1, 0);
|
||||
sqlite3_bind_text(res, 5, user->lastname, -1, 0);
|
||||
sqlite3_bind_text(res, 6, user->email, -1, 0);
|
||||
sqlite3_bind_text(res, 7, user->location, -1, 0);
|
||||
sqlite3_bind_int(res, 8, user->sec_level);
|
||||
sqlite3_bind_int(res, 9, user->laston);
|
||||
sqlite3_bind_int(res, 10, user->timeleft);
|
||||
sqlite3_bind_int(res, 11, user->cur_mail_conf);
|
||||
sqlite3_bind_int(res, 12, user->cur_mail_area);
|
||||
sqlite3_bind_int(res, 13, user->cur_file_dir);
|
||||
sqlite3_bind_int(res, 14, user->cur_file_sub);
|
||||
sqlite3_bind_int(res, 15, user->timeson);
|
||||
sqlite3_bind_text(res, 4, user->firstname, -1, 0);
|
||||
sqlite3_bind_text(res, 5, user->lastname, -1, 0);
|
||||
sqlite3_bind_text(res, 6, user->email, -1, 0);
|
||||
sqlite3_bind_text(res, 7, user->location, -1, 0);
|
||||
sqlite3_bind_int(res, 8, user->sec_level);
|
||||
sqlite3_bind_int(res, 9, user->laston);
|
||||
sqlite3_bind_int(res, 10, user->timeleft);
|
||||
sqlite3_bind_int(res, 11, user->cur_mail_conf);
|
||||
sqlite3_bind_int(res, 12, user->cur_mail_area);
|
||||
sqlite3_bind_int(res, 13, user->cur_file_dir);
|
||||
sqlite3_bind_int(res, 14, user->cur_file_sub);
|
||||
sqlite3_bind_int(res, 15, user->timeson);
|
||||
sqlite3_bind_int(res, 16, user->bwavepktno);
|
||||
sqlite3_bind_int(res, 17, user->defarchiver);
|
||||
sqlite3_bind_int(res, 18, user->defprotocol);
|
||||
@ -436,24 +427,23 @@ int inst_user(struct user_record *user) {
|
||||
sqlite3_bind_int(res, 22, user->bwavestyle);
|
||||
sqlite3_bind_text(res, 23, user->signature, -1, 0);
|
||||
sqlite3_bind_int(res, 24, user->autosig);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
if (rc != SQLITE_DONE) {
|
||||
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
user->id = sqlite3_last_insert_rowid(db);
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
if (rc != SQLITE_DONE) {
|
||||
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
user->id = sqlite3_last_insert_rowid(db);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
}
|
||||
@ -462,36 +452,36 @@ struct user_record *check_user_pass(char *loginname, char *password) {
|
||||
struct user_record *user;
|
||||
char buffer[1024];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT Id, loginname, password, salt, firstname,"
|
||||
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs, codepage, exteditor, bwavestyle, signature, autosig FROM users WHERE loginname LIKE ?";
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT Id, loginname, password, salt, firstname,"
|
||||
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs, codepage, exteditor, bwavestyle, signature, autosig FROM users WHERE loginname LIKE ?";
|
||||
char *pass_hash;
|
||||
|
||||
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, loginname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, loginname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int step = sqlite3_step(res);
|
||||
int step = sqlite3_step(res);
|
||||
|
||||
if (step == SQLITE_ROW) {
|
||||
if (step == SQLITE_ROW) {
|
||||
user = (struct user_record *)malloc(sizeof(struct user_record));
|
||||
user->id = sqlite3_column_int(res, 0);
|
||||
user->loginname = strdup((char *)sqlite3_column_text(res, 1));
|
||||
@ -530,24 +520,24 @@ struct user_record *check_user_pass(char *loginname, char *password) {
|
||||
free(user->signature);
|
||||
free(user);
|
||||
free(pass_hash);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return NULL;
|
||||
}
|
||||
free(pass_hash);
|
||||
} else {
|
||||
} else {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
|
||||
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
|
||||
|
||||
snprintf(buffer, 1024, "%s/s%d.ini", conf.config_path, user->sec_level);
|
||||
if (ini_parse(buffer, secLevel, user->sec_info) <0) {
|
||||
snprintf(buffer, 1024, "%s/s%d.ini", conf.config_path, user->sec_level);
|
||||
if (ini_parse(buffer, secLevel, user->sec_info) < 0) {
|
||||
dolog("Unable to load sec Level ini (%s)!", buffer);
|
||||
exit(-1);
|
||||
}
|
||||
@ -567,16 +557,15 @@ struct user_record *check_user_pass(char *loginname, char *password) {
|
||||
user->cur_file_sub = 0;
|
||||
}
|
||||
|
||||
|
||||
return user;
|
||||
return user;
|
||||
}
|
||||
|
||||
void list_users(struct user_record *user) {
|
||||
char buffer[256];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int i;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
char *sql = "SELECT loginname,location,times_on FROM users";
|
||||
|
||||
@ -585,22 +574,22 @@ void list_users(struct user_record *user) {
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot prepare statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
s_printf(get_string(161));
|
||||
s_printf(get_string(162));
|
||||
s_printf(get_string(163));
|
||||
i = 0;
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
dolog("Cannot prepare statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
s_printf(get_string(161));
|
||||
s_printf(get_string(162));
|
||||
s_printf(get_string(163));
|
||||
i = 0;
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
s_printf(get_string(164), sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2));
|
||||
|
||||
i++;
|
||||
@ -610,91 +599,91 @@ void list_users(struct user_record *user) {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
s_printf(get_string(165));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
s_printf(get_string(165));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
s_printf(get_string(6));
|
||||
s_printf(get_string(6));
|
||||
s_getc();
|
||||
}
|
||||
|
||||
int check_fullname(char *firstname, char *lastname) {
|
||||
char buffer[256];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT * FROM users WHERE firstname = ? AND lastname = ?";
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT * FROM users WHERE firstname = ? AND lastname = ?";
|
||||
|
||||
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, firstname, -1, 0);
|
||||
sqlite3_bind_text(res, 2, lastname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
}
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, firstname, -1, 0);
|
||||
sqlite3_bind_text(res, 2, lastname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
int step = sqlite3_step(res);
|
||||
int step = sqlite3_step(res);
|
||||
|
||||
if (step == SQLITE_ROW) {
|
||||
if (step == SQLITE_ROW) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int check_user(char *loginname) {
|
||||
char buffer[256];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT * FROM users WHERE loginname = ?";
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *sql = "SELECT * FROM users WHERE loginname = ?";
|
||||
|
||||
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, loginname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
}
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, loginname, -1, 0);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
int step = sqlite3_step(res);
|
||||
int step = sqlite3_step(res);
|
||||
|
||||
if (step == SQLITE_ROW) {
|
||||
if (step == SQLITE_ROW) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct user_record *new_user() {
|
||||
@ -706,7 +695,7 @@ struct user_record *new_user() {
|
||||
int passok = 0;
|
||||
int i;
|
||||
int fullnameok = 0;
|
||||
|
||||
|
||||
user = (struct user_record *)malloc(sizeof(struct user_record));
|
||||
s_printf("\r\n\r\n");
|
||||
s_displayansi("newuser");
|
||||
@ -726,7 +715,7 @@ struct user_record *new_user() {
|
||||
s_printf(get_string(240));
|
||||
continue;
|
||||
}
|
||||
for (i=0;i<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')) {
|
||||
s_printf(get_string(168));
|
||||
nameok = 1;
|
||||
@ -756,7 +745,7 @@ struct user_record *new_user() {
|
||||
if (strcasecmp(buffer, "ftp") == 0) {
|
||||
s_printf(get_string(169));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
user->loginname = strdup(buffer);
|
||||
nameok = check_user(user->loginname);
|
||||
if (!nameok) {
|
||||
@ -782,14 +771,14 @@ struct user_record *new_user() {
|
||||
if (strchr(buffer, ' ') != NULL) {
|
||||
s_printf(get_string(244));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
s_printf("\r\n");
|
||||
user->firstname = strdup(buffer);
|
||||
nameok = 1;
|
||||
} while (!nameok);
|
||||
nameok = 0;
|
||||
|
||||
do {
|
||||
|
||||
do {
|
||||
s_printf(get_string(172));
|
||||
memset(buffer, 0, 256);
|
||||
s_readstring(buffer, 32);
|
||||
@ -870,7 +859,7 @@ struct user_record *new_user() {
|
||||
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
|
||||
snprintf(buffer, PATH_MAX, "%s/config/s%d.ini", conf.bbs_path, user->sec_level);
|
||||
|
||||
if (ini_parse(buffer, secLevel, user->sec_info) <0) {
|
||||
if (ini_parse(buffer, secLevel, user->sec_info) < 0) {
|
||||
dolog("Unable to load sec Level ini (%s)!", buffer);
|
||||
exit(-1);
|
||||
}
|
||||
|
169
src/www_blog.c
169
src/www_blog.c
@ -5,7 +5,6 @@
|
||||
#include <stdlib.h>
|
||||
#include "bbs.h"
|
||||
|
||||
|
||||
extern struct bbs_config conf;
|
||||
|
||||
char *www_blog() {
|
||||
@ -14,20 +13,20 @@ char *www_blog() {
|
||||
int len;
|
||||
char buffer[4096];
|
||||
|
||||
struct blog_entry_t **blog_entries;
|
||||
int blog_entry_count = 0;
|
||||
int i, j;
|
||||
struct tm thetime;
|
||||
int hour;
|
||||
|
||||
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
|
||||
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
|
||||
struct blog_entry_t **blog_entries;
|
||||
int blog_entry_count = 0;
|
||||
int i, j;
|
||||
struct tm thetime;
|
||||
int hour;
|
||||
|
||||
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
|
||||
char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
memset(page, 0, 4096);
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"content-header\"><h2>System Blog</h2></div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -36,85 +35,85 @@ char *www_blog() {
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
blog_entry_count = blog_load(&blog_entries);
|
||||
blog_entry_count = blog_load(&blog_entries);
|
||||
|
||||
if (blog_entry_count == 0) {
|
||||
sprintf(buffer, "<p>No Entries</p>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
} else {
|
||||
for (i=0;i<blog_entry_count;i++) {
|
||||
localtime_r(&blog_entries[i]->date, &thetime);
|
||||
if (thetime.tm_hour >= 12) {
|
||||
hour = thetime.tm_hour - 12;
|
||||
} else {
|
||||
hour = thetime.tm_hour;
|
||||
}
|
||||
sprintf(buffer, "<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) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
if (blog_entry_count == 0) {
|
||||
sprintf(buffer, "<p>No Entries</p>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
} else {
|
||||
for (i = 0; i < blog_entry_count; i++) {
|
||||
localtime_r(&blog_entries[i]->date, &thetime);
|
||||
if (thetime.tm_hour >= 12) {
|
||||
hour = thetime.tm_hour - 12;
|
||||
} else {
|
||||
hour = thetime.tm_hour;
|
||||
}
|
||||
sprintf(buffer, "<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) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
sprintf(buffer, "<div class=\"blog-entry\"><p>");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
sprintf(buffer, "<div class=\"blog-entry\"><p>");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
for (j=0;j<strlen(blog_entries[i]->body);j++) {
|
||||
if (blog_entries[i]->body[j] == '\r') {
|
||||
if (blog_entries[i]->body[j+1] == '\r') {
|
||||
sprintf(buffer, "</p><p>");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
} else {
|
||||
if (len + 1 > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
page[len++] = ' ';
|
||||
page[len] = '\0';
|
||||
}
|
||||
} else {
|
||||
if (len + 1 > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
page[len++] = blog_entries[i]->body[j];
|
||||
page[len] = '\0';
|
||||
}
|
||||
}
|
||||
sprintf(buffer, "</p></div>");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
for (j = 0; j < strlen(blog_entries[i]->body); j++) {
|
||||
if (blog_entries[i]->body[j] == '\r') {
|
||||
if (blog_entries[i]->body[j + 1] == '\r') {
|
||||
sprintf(buffer, "</p><p>");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
} else {
|
||||
if (len + 1 > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
page[len++] = ' ';
|
||||
page[len] = '\0';
|
||||
}
|
||||
} else {
|
||||
if (len + 1 > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
page[len++] = blog_entries[i]->body[j];
|
||||
page[len] = '\0';
|
||||
}
|
||||
}
|
||||
sprintf(buffer, "</p></div>");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
|
||||
for (i = 0; i < blog_entry_count; i++) {
|
||||
free(blog_entries[i]->subject);
|
||||
free(blog_entries[i]->author);
|
||||
free(blog_entries[i]->body);
|
||||
free(blog_entries[i]);
|
||||
}
|
||||
free(blog_entries);
|
||||
}
|
||||
|
||||
for (i=0;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;
|
||||
}
|
||||
|
||||
|
217
src/www_email.c
217
src/www_email.c
@ -7,7 +7,6 @@
|
||||
#include <sys/utsname.h>
|
||||
#include "bbs.h"
|
||||
|
||||
|
||||
extern struct bbs_config conf;
|
||||
|
||||
int www_email_delete(struct user_record *user, int id) {
|
||||
@ -15,17 +14,17 @@ int www_email_delete(struct user_record *user, int id) {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
char *dsql = "DELETE FROM email WHERE id=? AND recipient LIKE ?";
|
||||
char *err_msg = 0;
|
||||
|
||||
|
||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
@ -36,7 +35,7 @@ int www_email_delete(struct user_record *user, int id) {
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
@ -65,21 +64,21 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
|
||||
char *err_msg = 0;
|
||||
char *body;
|
||||
struct utsname name;
|
||||
int i;
|
||||
int pos;
|
||||
|
||||
|
||||
if (recipient == NULL || subject == NULL || ibody == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@ -87,25 +86,23 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
|
||||
if (check_user(recipient)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uname(&name);
|
||||
|
||||
|
||||
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, conf.default_tagline);
|
||||
|
||||
|
||||
body = (char *)malloc(strlen(ibody) + strlen(buffer) + 1);
|
||||
memset(body, 0, strlen(ibody) + strlen(buffer) + 1);
|
||||
pos = 0;
|
||||
for (i = 0;i<strlen(ibody);i++) {
|
||||
for (i = 0; i < strlen(ibody); i++) {
|
||||
if (ibody[i] != '\n') {
|
||||
body[pos] = ibody[i];
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
strcat(body, buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||
|
||||
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);
|
||||
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
@ -139,8 +136,6 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
|
||||
}
|
||||
sqlite3_step(res);
|
||||
|
||||
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
@ -151,7 +146,7 @@ char *www_new_email() {
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[4096];
|
||||
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
@ -169,7 +164,7 @@ char *www_new_email() {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -177,7 +172,7 @@ char *www_new_email() {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -185,7 +180,7 @@ char *www_new_email() {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -193,7 +188,7 @@ char *www_new_email() {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -201,20 +196,19 @@ char *www_new_email() {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</form>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
return page;
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
char *www_email_display(struct user_record *user, int email) {
|
||||
@ -235,17 +229,17 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
int chars;
|
||||
char *err_msg = 0;
|
||||
char *email_create_sql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
char *email_show_sql = "SELECT id,sender,subject,body,date FROM email WHERE recipient LIKE ? LIMIT ?, 1";
|
||||
|
||||
|
||||
char *update_seen_sql = "UPDATE email SET seen=1 WHERE id=?";
|
||||
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
@ -257,11 +251,11 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
free(page);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, email_create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
@ -277,16 +271,16 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(page);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
id = sqlite3_column_int(res, 0);
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
id = sqlite3_column_int(res, 0);
|
||||
from = strdup((char *)sqlite3_column_text(res, 1));
|
||||
subject = strdup((char *)sqlite3_column_text(res, 2));
|
||||
body = strdup((char *)sqlite3_column_text(res, 3));
|
||||
date = (time_t)sqlite3_column_int(res, 4);
|
||||
localtime_r(&date, &msg_date);
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"content-header\"><h2>Your Email</h2></div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -299,26 +293,26 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"email-view-subject\">%s</div>\n", subject);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"email-view-from\">From: %s</div>\n", from);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
if (conf.date_style == 1) {
|
||||
sprintf(buffer, "<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 {
|
||||
@ -327,26 +321,26 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
sprintf(buffer, "<div id=\"msgbody\">\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
for (i=0;i<strlen(body);i++) {
|
||||
for (i = 0; i < strlen(body); i++) {
|
||||
if (body[i] == '\r') {
|
||||
sprintf(buffer, "<br />");
|
||||
} else if (body[i] == '<') {
|
||||
@ -359,7 +353,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
@ -367,7 +361,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -375,7 +369,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
sprintf(buffer, "<h3>Reply</h3>\n");
|
||||
@ -385,12 +379,12 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "<form action=\"%semail/\" method=\"POST\" enctype=\"application/x-www-form-urlencoded\">\n", conf.www_url);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -398,7 +392,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -410,7 +404,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -418,7 +412,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -426,7 +420,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -434,13 +428,13 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
chars = 0;
|
||||
|
||||
for (i=0;i<strlen(body);i++) {
|
||||
|
||||
for (i = 0; i < strlen(body); i++) {
|
||||
if (body[i] == '\r') {
|
||||
sprintf(buffer, "\n> ");
|
||||
chars = 0;
|
||||
@ -449,21 +443,21 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
chars = 1;
|
||||
} else {
|
||||
sprintf(buffer, "%c", body[i]);
|
||||
chars ++;
|
||||
chars++;
|
||||
}
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
|
||||
|
||||
sprintf(buffer, "</textarea>\n<br />");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -471,16 +465,15 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</form>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -488,16 +481,16 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
free(from);
|
||||
free(body);
|
||||
free(subject);
|
||||
|
||||
|
||||
sqlite3_finalize(res);
|
||||
|
||||
|
||||
rc = sqlite3_prepare_v2(db, update_seen_sql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
@ -506,9 +499,9 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(page);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
sqlite3_step(res);
|
||||
} else {
|
||||
sprintf(buffer, "<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;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
|
||||
sqlite3_finalize(res);
|
||||
@ -544,15 +537,14 @@ char *www_email_summary(struct user_record *user) {
|
||||
int msgid = 0;
|
||||
char *err_msg = 0;
|
||||
char *email_create_sql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
|
||||
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
@ -565,7 +557,7 @@ char *www_email_summary(struct user_record *user) {
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"button\"><a href=\"%semail/new\">New Email</a></div>\n", conf.www_url);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -573,18 +565,18 @@ char *www_email_summary(struct user_record *user) {
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
free(page);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, email_create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
@ -599,9 +591,9 @@ sqlite3_busy_timeout(db, 5000);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(page);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"div-table\">\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -609,7 +601,7 @@ sqlite3_busy_timeout(db, 5000);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
id = sqlite3_column_int(res, 0);
|
||||
from = strdup((char *)sqlite3_column_text(res, 1));
|
||||
@ -642,11 +634,10 @@ sqlite3_busy_timeout(db, 5000);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return page;
|
||||
|
741
src/www_files.c
741
src/www_files.c
@ -7,349 +7,348 @@
|
||||
#include "bbs.h"
|
||||
#include "../deps/hashids/hashids.h"
|
||||
|
||||
|
||||
extern struct bbs_config conf;
|
||||
extern struct user_record *gUser;
|
||||
extern char * aha(char *input);
|
||||
extern char *aha(char *input);
|
||||
|
||||
static char *www_decode(char *clean_url) {
|
||||
char *url = (char *)malloc(strlen(clean_url) + 1);
|
||||
int i;
|
||||
int j = 0;
|
||||
unsigned char c;
|
||||
if (clean_url == NULL) {
|
||||
free(url);
|
||||
return NULL;
|
||||
}
|
||||
char *url = (char *)malloc(strlen(clean_url) + 1);
|
||||
int i;
|
||||
int j = 0;
|
||||
unsigned char c;
|
||||
if (clean_url == NULL) {
|
||||
free(url);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0;i<strlen(clean_url);i++) {
|
||||
if (clean_url[i] == '%') {
|
||||
c = clean_url[i+1] * 16 + clean_url[i+2];
|
||||
url[j++] = (char)c;
|
||||
url[j] = '\0';
|
||||
i+=2;
|
||||
} else {
|
||||
url[j++] = clean_url[i];
|
||||
url[j] = '\0';
|
||||
}
|
||||
}
|
||||
for (i = 0; i < strlen(clean_url); i++) {
|
||||
if (clean_url[i] == '%') {
|
||||
c = clean_url[i + 1] * 16 + clean_url[i + 2];
|
||||
url[j++] = (char)c;
|
||||
url[j] = '\0';
|
||||
i += 2;
|
||||
} else {
|
||||
url[j++] = clean_url[i];
|
||||
url[j] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
return url;
|
||||
}
|
||||
|
||||
static char *www_encode(char *url) {
|
||||
char *clean_url = (char *)malloc(strlen(url) * 3 + 1);
|
||||
int i;
|
||||
int j;
|
||||
char *clean_url = (char *)malloc(strlen(url) * 3 + 1);
|
||||
int i;
|
||||
int j;
|
||||
|
||||
if (url == NULL) {
|
||||
free(clean_url);
|
||||
return NULL;
|
||||
}
|
||||
if (url == NULL) {
|
||||
free(clean_url);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
memset(clean_url, 0, strlen(url) * 3);
|
||||
j = 0;
|
||||
memset(clean_url, 0, strlen(url) * 3);
|
||||
|
||||
for (i=0;i<strlen(url);i++) {
|
||||
if (isalnum(url[i]) || url[i] == '~' || url[i] == '.' || url[i] == '_') {
|
||||
sprintf(&clean_url[j], "%c", url[i]);
|
||||
j++;
|
||||
} else {
|
||||
sprintf(&clean_url[j], "%%%02X", url[i]);
|
||||
j+=3;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < strlen(url); i++) {
|
||||
if (isalnum(url[i]) || url[i] == '~' || url[i] == '.' || url[i] == '_') {
|
||||
sprintf(&clean_url[j], "%c", url[i]);
|
||||
j++;
|
||||
} else {
|
||||
sprintf(&clean_url[j], "%%%02X", url[i]);
|
||||
j += 3;
|
||||
}
|
||||
}
|
||||
|
||||
return clean_url;
|
||||
return clean_url;
|
||||
}
|
||||
|
||||
void www_expire_old_links() {
|
||||
char buffer[PATH_MAX];
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char sql[] = "delete from wwwhash where expiry <= ?";
|
||||
char *ret;
|
||||
time_t now = time(NULL);
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char sql[] = "delete from wwwhash where expiry <= ?";
|
||||
char *ret;
|
||||
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) {
|
||||
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);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
return;
|
||||
}
|
||||
sqlite3_bind_int(res, 1, now);
|
||||
sqlite3_step(res);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return;
|
||||
}
|
||||
sqlite3_bind_int(res, 1, now);
|
||||
sqlite3_step(res);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
int www_check_hash_expired(char *hash) {
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
time_t now = time(NULL);
|
||||
char sql[] = "select id from wwwhash where hash = ? and expiry > ?";
|
||||
snprintf(buffer, PATH_MAX, "%s/www_file_hashes.sq3", conf.bbs_path);
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
time_t now = time(NULL);
|
||||
char sql[] = "select id from wwwhash where hash = ? and expiry > ?";
|
||||
snprintf(buffer, PATH_MAX, "%s/www_file_hashes.sq3", conf.bbs_path);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_bind_text(res, 1, hash, -1, 0);
|
||||
sqlite3_bind_int(res, 2, now);
|
||||
sqlite3_bind_text(res, 1, hash, -1, 0);
|
||||
sqlite3_bind_int(res, 2, now);
|
||||
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void www_add_hash_to_db(char *hash, time_t expiry) {
|
||||
char buffer[PATH_MAX];
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
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 usql[] = "update wwwhash SET expiry = ? WHERE hash = ?";
|
||||
char isql[] = "insert into wwwhash (hash, expiry) values(?, ?)";
|
||||
|
||||
char *ret;
|
||||
char *err_msg = 0;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
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 usql[] = "update wwwhash SET expiry = ? WHERE hash = ?";
|
||||
char isql[] = "insert into wwwhash (hash, expiry) values(?, ?)";
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
return;
|
||||
}
|
||||
// if not add hash
|
||||
sqlite3_finalize(res);
|
||||
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
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;
|
||||
}
|
||||
sqlite3_bind_text(res, 1, hash, -1, 0);
|
||||
sqlite3_bind_int(res, 2, expiry);
|
||||
sqlite3_step(res);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
// first check if hash is in database
|
||||
rc = sqlite3_prepare_v2(db, chsql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
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) {
|
||||
unsigned long long numbers[4];
|
||||
int dir, sub, fid, uid;
|
||||
hashids_t *hashids = hashids_init(conf.bbs_name);
|
||||
char buffer[PATH_MAX];
|
||||
unsigned long long numbers[4];
|
||||
int dir, sub, fid, uid;
|
||||
hashids_t *hashids = hashids_init(conf.bbs_name);
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char sql[] = "select filename from files where approved = 1 and id = ?";
|
||||
char *ret;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char sql[] = "select filename from files where approved = 1 and id = ?";
|
||||
char *ret;
|
||||
|
||||
if (www_check_hash_expired(hash)) {
|
||||
return NULL;
|
||||
}
|
||||
if (www_check_hash_expired(hash)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (hashids_decode(hashids, hash, numbers) != 4) {
|
||||
hashids_free(hashids);
|
||||
return NULL;
|
||||
}
|
||||
hashids_free(hashids);
|
||||
if (hashids_decode(hashids, hash, numbers) != 4) {
|
||||
hashids_free(hashids);
|
||||
return NULL;
|
||||
}
|
||||
hashids_free(hashids);
|
||||
|
||||
uid = (int)numbers[0];
|
||||
dir = (int)numbers[1];
|
||||
sub = (int)numbers[2];
|
||||
fid = (int)numbers[3];
|
||||
uid = (int)numbers[0];
|
||||
dir = (int)numbers[1];
|
||||
sub = (int)numbers[2];
|
||||
fid = (int)numbers[3];
|
||||
|
||||
if (dir >= conf.file_directory_count || sub >= conf.file_directories[dir]->file_sub_count) {
|
||||
return NULL;
|
||||
}
|
||||
if (dir >= conf.file_directory_count || sub >= conf.file_directories[dir]->file_sub_count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// get filename from database
|
||||
snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database);
|
||||
// get filename from database
|
||||
snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
return NULL;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return NULL;
|
||||
}
|
||||
sqlite3_bind_int(res, 1, fid);
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
ret = strdup(sqlite3_column_text(res, 0));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return NULL;
|
||||
}
|
||||
sqlite3_bind_int(res, 1, fid);
|
||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||
ret = strdup(sqlite3_column_text(res, 0));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *www_create_link(int dir, int sub, int fid) {
|
||||
char url[PATH_MAX];
|
||||
char *ret;
|
||||
char *hashid;
|
||||
int sizereq;
|
||||
time_t expiry;
|
||||
char url[PATH_MAX];
|
||||
char *ret;
|
||||
char *hashid;
|
||||
int sizereq;
|
||||
time_t expiry;
|
||||
|
||||
hashids_t *hashids = hashids_init(conf.bbs_name);
|
||||
hashids_t *hashids = hashids_init(conf.bbs_name);
|
||||
|
||||
sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid);
|
||||
sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid);
|
||||
|
||||
hashid = (char *)malloc(sizereq + 1);
|
||||
hashid = (char *)malloc(sizereq + 1);
|
||||
|
||||
memset(hashid, 0, sizereq + 1);
|
||||
memset(hashid, 0, sizereq + 1);
|
||||
|
||||
if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) {
|
||||
hashids_free(hashids);
|
||||
free(hashid);
|
||||
return NULL;
|
||||
}
|
||||
if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) {
|
||||
hashids_free(hashids);
|
||||
free(hashid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hashids_free(hashids);
|
||||
hashids_free(hashids);
|
||||
|
||||
snprintf(url, PATH_MAX, "%sfiles/%s", conf.www_url, hashid);
|
||||
snprintf(url, PATH_MAX, "%sfiles/%s", conf.www_url, hashid);
|
||||
|
||||
// add link into hash database
|
||||
expiry = time(NULL) + 86400;
|
||||
www_add_hash_to_db(hashid, expiry);
|
||||
// add link into hash database
|
||||
expiry = time(NULL) + 86400;
|
||||
www_add_hash_to_db(hashid, expiry);
|
||||
|
||||
free(hashid);
|
||||
free(hashid);
|
||||
|
||||
ret = strdup(url);
|
||||
ret = strdup(url);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
char *www_files_display_listing(int dir, int sub) {
|
||||
char *page;
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[4096];
|
||||
char *page;
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[4096];
|
||||
char *sql = "select id, filename, description, size, dlcount, uploaddate from files where approved=1 ORDER BY filename";
|
||||
char *filename;
|
||||
char c;
|
||||
int size;
|
||||
char *aha_out;
|
||||
char *description;
|
||||
char *filename;
|
||||
char c;
|
||||
int size;
|
||||
char *aha_out;
|
||||
char *description;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int i;
|
||||
char *clean_url;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int i;
|
||||
char *clean_url;
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
memset(page, 0, 4096);
|
||||
|
||||
|
||||
snprintf(buffer, 4096, "<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;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
len += strlen(buffer);
|
||||
|
||||
snprintf(buffer, 4096, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
free(page);
|
||||
return NULL;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
free(page);
|
||||
free(page);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
free(page);
|
||||
return NULL;
|
||||
}
|
||||
snprintf(buffer, 4096, "<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;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
len += strlen(buffer);
|
||||
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
filename = strdup(sqlite3_column_text(res, 1));
|
||||
clean_url = www_encode(basename(filename));
|
||||
snprintf(buffer, 4096, "<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(filename);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
filename = strdup(sqlite3_column_text(res, 1));
|
||||
clean_url = www_encode(basename(filename));
|
||||
snprintf(buffer, 4096, "<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(filename);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
size = sqlite3_column_int(res, 3);
|
||||
size = sqlite3_column_int(res, 3);
|
||||
|
||||
if (size > 1024 * 1024 * 1024) {
|
||||
if (size > 1024 * 1024 * 1024) {
|
||||
size = size / 1024 / 1024 / 1024;
|
||||
c = 'G';
|
||||
} else if (size > 1024 * 1024) {
|
||||
@ -362,190 +361,188 @@ char *www_files_display_listing(int dir, int sub) {
|
||||
c = 'b';
|
||||
}
|
||||
|
||||
snprintf(buffer, 4096, "<td class=\"filesize\">%d%c</td>", size, c);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
snprintf(buffer, 4096, "<td class=\"filesize\">%d%c</td>", size, c);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
description = strdup((char *)sqlite3_column_text(res, 2));
|
||||
description = strdup((char *)sqlite3_column_text(res, 2));
|
||||
|
||||
for (i=0;i<strlen(description);i++) {
|
||||
if (description[i] == '\n') {
|
||||
description[i] = '\r';
|
||||
}
|
||||
}
|
||||
for (i = 0; i < strlen(description); i++) {
|
||||
if (description[i] == '\n') {
|
||||
description[i] = '\r';
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(buffer, 4096, "<td class=\"filedesc\">");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
snprintf(buffer, 4096, "<td class=\"filedesc\">");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
aha_out = aha(description);
|
||||
|
||||
while (len + strlen(aha_out) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, aha_out);
|
||||
len += strlen(aha_out);
|
||||
|
||||
len += strlen(aha_out);
|
||||
|
||||
free(aha_out);
|
||||
free(description);
|
||||
|
||||
snprintf(buffer, 4096, "</td></tr>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
snprintf(buffer, 4096, "</td></tr>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
|
||||
snprintf(buffer, 4096, "</tbody></table>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
snprintf(buffer, 4096, "</tbody></table>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
return page;
|
||||
return page;
|
||||
}
|
||||
|
||||
char *www_files_areas() {
|
||||
char *page;
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[4096];
|
||||
int i;
|
||||
int j;
|
||||
char *page;
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[4096];
|
||||
int i;
|
||||
int j;
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
memset(page, 0, 4096);
|
||||
|
||||
|
||||
sprintf(buffer, "<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;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
for (i=0;i<conf.file_directory_count;i++) {
|
||||
if (conf.file_directories[i]->display_on_web) {
|
||||
sprintf(buffer, "<div class=\"conference-list-item\">%s</div>\n", conf.file_directories[i]->name);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
for (j=0;j<conf.file_directories[i]->file_sub_count;j++) {
|
||||
sprintf(buffer, "<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) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < conf.file_directory_count; i++) {
|
||||
if (conf.file_directories[i]->display_on_web) {
|
||||
sprintf(buffer, "<div class=\"conference-list-item\">%s</div>\n", conf.file_directories[i]->name);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
for (j = 0; j < conf.file_directories[i]->file_sub_count; j++) {
|
||||
sprintf(buffer, "<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) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return page;
|
||||
return page;
|
||||
}
|
||||
|
||||
char *www_files_get_from_area(int dir, int sub, char *clean_file) {
|
||||
char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\"";
|
||||
char *filenamelike;
|
||||
char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\"";
|
||||
char *filenamelike;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
char *ret = NULL;
|
||||
int i;
|
||||
int extra = 0;
|
||||
int j;
|
||||
char *file;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
char *ret = NULL;
|
||||
int i;
|
||||
int extra = 0;
|
||||
int j;
|
||||
char *file;
|
||||
|
||||
file = www_decode(clean_file);
|
||||
file = www_decode(clean_file);
|
||||
|
||||
for (i=0;i<strlen(file);i++) {
|
||||
if (file[i] == '^' || file[i] == '%' || file[i] == '_') {
|
||||
extra++;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < strlen(file); i++) {
|
||||
if (file[i] == '^' || file[i] == '%' || file[i] == '_') {
|
||||
extra++;
|
||||
}
|
||||
}
|
||||
|
||||
filenamelike = (char *)malloc(strlen(file) + 3 + extra);
|
||||
filenamelike = (char *)malloc(strlen(file) + 3 + extra);
|
||||
|
||||
i = 0;
|
||||
filenamelike[i++] = '%';
|
||||
filenamelike[i] = '\0';
|
||||
i = 0;
|
||||
filenamelike[i++] = '%';
|
||||
filenamelike[i] = '\0';
|
||||
|
||||
for (j = 0; j < strlen(file); j++) {
|
||||
switch(file[j]) {
|
||||
case '^':
|
||||
filenamelike[i++] = '^';
|
||||
filenamelike[i++] = '^';
|
||||
filenamelike[i] = '\0';
|
||||
break;
|
||||
case '_':
|
||||
filenamelike[i++] = '^';
|
||||
filenamelike[i++] = '_';
|
||||
filenamelike[i] = '\0';
|
||||
break;
|
||||
case '%':
|
||||
filenamelike[i++] = '^';
|
||||
filenamelike[i++] = '%';
|
||||
filenamelike[i] = '\0';
|
||||
break;
|
||||
default:
|
||||
filenamelike[i++] = file[j];
|
||||
filenamelike[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (j = 0; j < strlen(file); j++) {
|
||||
switch (file[j]) {
|
||||
case '^':
|
||||
filenamelike[i++] = '^';
|
||||
filenamelike[i++] = '^';
|
||||
filenamelike[i] = '\0';
|
||||
break;
|
||||
case '_':
|
||||
filenamelike[i++] = '^';
|
||||
filenamelike[i++] = '_';
|
||||
filenamelike[i] = '\0';
|
||||
break;
|
||||
case '%':
|
||||
filenamelike[i++] = '^';
|
||||
filenamelike[i++] = '%';
|
||||
filenamelike[i] = '\0';
|
||||
break;
|
||||
default:
|
||||
filenamelike[i++] = file[j];
|
||||
filenamelike[i] = '\0';
|
||||
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);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return NULL;
|
||||
}
|
||||
sqlite3_bind_text(res, 1, filenamelike, -1, 0);
|
||||
}
|
||||
sqlite3_bind_text(res, 1, filenamelike, -1, 0);
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
if (rc == SQLITE_ROW) {
|
||||
ret = strdup(sqlite3_column_text(res, 0));
|
||||
rc = sqlite3_step(res);
|
||||
if (rc == SQLITE_ROW) {
|
||||
ret = strdup(sqlite3_column_text(res, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
free(filenamelike);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return ret;
|
||||
free(filenamelike);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <stdlib.h>
|
||||
#include "bbs.h"
|
||||
|
||||
|
||||
extern struct bbs_config conf;
|
||||
|
||||
char *www_last10() {
|
||||
@ -15,13 +14,13 @@ char *www_last10() {
|
||||
char buffer[4096];
|
||||
struct last10_callers callers[10];
|
||||
|
||||
int i,z;
|
||||
int i, z;
|
||||
struct tm l10_time;
|
||||
FILE *fptr = fopen("last10v2.dat", "rb");
|
||||
|
||||
if (fptr != NULL) {
|
||||
|
||||
for (i=0;i<10;i++) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) {
|
||||
break;
|
||||
}
|
||||
@ -36,7 +35,7 @@ char *www_last10() {
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
memset(page, 0, 4096);
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"content-header\"><h2>Last 10 Callers</h2></div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -52,8 +51,8 @@ char *www_last10() {
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
for (z=0;z<i;z++) {
|
||||
|
||||
for (z = 0; z < i; z++) {
|
||||
localtime_r(&callers[z].time, &l10_time);
|
||||
if (conf.date_style == 1) {
|
||||
if (callers[z].calls == 1) {
|
||||
@ -75,7 +74,7 @@ char *www_last10() {
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
|
||||
|
||||
sprintf(buffer, "</div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -83,7 +82,7 @@ char *www_last10() {
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
|
333
src/www_msgs.c
333
src/www_msgs.c
@ -12,16 +12,15 @@
|
||||
|
||||
#define IN 0
|
||||
#define OUT 1
|
||||
extern char * aha(char *input);
|
||||
extern char *aha(char *input);
|
||||
extern struct bbs_config conf;
|
||||
|
||||
|
||||
static char *www_wordwrap(char *content, int cutoff);
|
||||
char *www_sanitize(char *inp) {
|
||||
int i;
|
||||
char *result;
|
||||
int len = 0;
|
||||
for (i=0;i<strlen(inp);i++) {
|
||||
for (i = 0; i < strlen(inp); i++) {
|
||||
if ((inp[i] == '<') || (inp[i] == '>')) {
|
||||
len += 4;
|
||||
} else if (inp[i] == '&') {
|
||||
@ -34,8 +33,8 @@ char *www_sanitize(char *inp) {
|
||||
result = (char *)malloc(len + 1);
|
||||
memset(result, 0, len + 1);
|
||||
len = 0;
|
||||
for (i=0;i<strlen(inp);i++) {
|
||||
if (inp[i] == '<') {
|
||||
for (i = 0; i < strlen(inp); i++) {
|
||||
if (inp[i] == '<') {
|
||||
result[len++] = '&';
|
||||
result[len++] = 'l';
|
||||
result[len++] = 't';
|
||||
@ -44,7 +43,7 @@ char *www_sanitize(char *inp) {
|
||||
result[len++] = '&';
|
||||
result[len++] = 'g';
|
||||
result[len++] = 't';
|
||||
result[len++] = ';';
|
||||
result[len++] = ';';
|
||||
} else if (inp[i] == '&') {
|
||||
result[len++] = '&';
|
||||
result[len++] = 'a';
|
||||
@ -65,7 +64,7 @@ char *www_msgs_arealist(struct user_record *user) {
|
||||
int len;
|
||||
char buffer[4096];
|
||||
int i, j;
|
||||
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
@ -78,8 +77,8 @@ char *www_msgs_arealist(struct user_record *user) {
|
||||
}
|
||||
strcat(page, 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) {
|
||||
sprintf(buffer, "<div class=\"conference-list-item\">%s</div>\n", conf.mail_conferences[i]->name);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
@ -89,9 +88,9 @@ char *www_msgs_arealist(struct user_record *user) {
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
for (j=0;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 (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);
|
||||
} else {
|
||||
@ -134,7 +133,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
memset(page, 0, 4096);
|
||||
|
||||
|
||||
sprintf(buffer, "<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) {
|
||||
max_len += 4096;
|
||||
@ -142,7 +141,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) {
|
||||
sprintf(buffer, "<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) {
|
||||
@ -150,10 +149,10 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
mhrs = read_message_headers(conference, area, user, 0);
|
||||
|
||||
|
||||
if (mhrs == NULL) {
|
||||
sprintf(buffer, "<h3>No Messages</h3>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
@ -164,14 +163,14 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
len += strlen(buffer);
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"div-table\">\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
|
||||
if (!jb) {
|
||||
@ -190,8 +189,8 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
if (skip_t < 0) {
|
||||
skip_t = 0;
|
||||
}
|
||||
|
||||
for (i=skip_f -1; i>=skip_t;i--) {
|
||||
|
||||
for (i = skip_f - 1; i >= skip_t; i--) {
|
||||
date = (time_t)mhrs->msgs[i]->msg_h->DateWritten;
|
||||
gmtime_r(&date, &msg_date);
|
||||
to = www_sanitize(mhrs->msgs[i]->to);
|
||||
@ -226,7 +225,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
sprintf(buffer, "</div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
@ -234,7 +233,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
if (skip + 50 <= mhrs->msg_count) {
|
||||
sprintf(buffer, "<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) {
|
||||
@ -256,21 +255,21 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
|
||||
|
||||
free_message_headers(mhrs);
|
||||
return page;
|
||||
return page;
|
||||
}
|
||||
|
||||
char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) {
|
||||
s_JamBase *jb;
|
||||
s_JamMsgHeader jmh;
|
||||
s_JamSubPacket* jsp;
|
||||
s_JamSubPacket *jsp;
|
||||
s_JamSubfield jsf;
|
||||
s_JamLastRead jlr;
|
||||
s_JamBaseHeader jbh;
|
||||
|
||||
|
||||
char *subject = NULL;
|
||||
char *from = NULL;
|
||||
char *to = NULL;
|
||||
@ -287,7 +286,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
char *page;
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[4096];
|
||||
char buffer[4096];
|
||||
int chars;
|
||||
int i;
|
||||
char *from_s;
|
||||
@ -302,15 +301,15 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level) {
|
||||
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
|
||||
if (!jb) {
|
||||
if (!jb) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
JAM_ReadMBHeader(jb, &jbh);
|
||||
|
||||
|
||||
memset(&jmh, 0, sizeof(s_JamMsgHeader));
|
||||
z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp);
|
||||
if (z != 0) {
|
||||
@ -323,9 +322,9 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
JAM_CloseMB(jb);
|
||||
free(jb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (z=0;z<jsp->NumFields;z++) {
|
||||
}
|
||||
|
||||
for (z = 0; z < jsp->NumFields; z++) {
|
||||
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
|
||||
subject = (char *)malloc(jsp->Fields[z]->DatLen + 1);
|
||||
memset(subject, 0, jsp->Fields[z]->DatLen + 1);
|
||||
@ -362,8 +361,8 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
memcpy(replyid, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
|
||||
}
|
||||
}
|
||||
JAM_DelSubPacket(jsp);
|
||||
|
||||
JAM_DelSubPacket(jsp);
|
||||
|
||||
if (subject == NULL) {
|
||||
subject = strdup("(No Subject)");
|
||||
}
|
||||
@ -375,12 +374,12 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (to == NULL) {
|
||||
to = strdup("(No Recipient)");
|
||||
}
|
||||
|
||||
|
||||
if (jmh.Attribute & JAM_MSG_PRIVATE) {
|
||||
if (!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) &&
|
||||
!msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) &&
|
||||
!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) &&
|
||||
!msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) {
|
||||
!msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) &&
|
||||
!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) &&
|
||||
!msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) {
|
||||
|
||||
if (subject != NULL) {
|
||||
free(subject);
|
||||
@ -411,7 +410,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
body = (char *)malloc(jmh.TxtLen + 1);
|
||||
memset(body, 0, jmh.TxtLen + 1);
|
||||
|
||||
JAM_ReadMsgText(jb, jmh.TxtOffset,jmh.TxtLen, (char *)body);
|
||||
JAM_ReadMsgText(jb, jmh.TxtOffset, jmh.TxtLen, (char *)body);
|
||||
|
||||
if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) {
|
||||
jlr.UserCRC = JAM_Crc32(user->loginname, strlen(user->loginname));
|
||||
@ -422,17 +421,17 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
jlr.LastReadMsg = msg;
|
||||
if (jlr.HighReadMsg < msg) {
|
||||
jlr.HighReadMsg = msg;
|
||||
}
|
||||
}
|
||||
|
||||
JAM_WriteLastRead(jb, user->id, &jlr);
|
||||
JAM_CloseMB(jb);
|
||||
free(jb);
|
||||
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
memset(page, 0, 4096);
|
||||
|
||||
|
||||
sprintf(buffer, "<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) {
|
||||
max_len += 4096;
|
||||
@ -440,7 +439,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
if (msgbase_is_flagged(user, conference, area, msg)) {
|
||||
sprintf(buffer, "<div class=\"msg-view-header-flagged\">\n");
|
||||
} else {
|
||||
@ -449,7 +448,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
subject_s = www_sanitize(subject);
|
||||
@ -457,14 +456,14 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
free(subject_s);
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
from_s = www_sanitize(from);
|
||||
if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) {
|
||||
|
||||
|
||||
if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
|
||||
sprintf(buffer, "<div class=\"msg-view-from\">From: %s (@%s)</div>\n", from_s, oaddress);
|
||||
} else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
|
||||
@ -492,7 +491,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
to_s = www_sanitize(to);
|
||||
@ -500,11 +499,11 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
free(to_s);
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
date = (time_t)jmh.DateWritten;
|
||||
gmtime_r(&date, &msg_date);
|
||||
if (conf.date_style == 1) {
|
||||
@ -512,11 +511,11 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
} else {
|
||||
sprintf(buffer, "<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) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -524,26 +523,25 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
sprintf(buffer, "<div id=\"msgbody\">\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
|
||||
aha_text = (char *)malloc(jmh.TxtLen + 1);
|
||||
|
||||
memcpy(aha_text, body, jmh.TxtLen);
|
||||
@ -552,28 +550,26 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
while (len + strlen(aha_out) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, aha_out);
|
||||
len += strlen(aha_out);
|
||||
|
||||
len += strlen(aha_out);
|
||||
|
||||
free(aha_out);
|
||||
free(aha_text);
|
||||
|
||||
|
||||
sprintf(buffer, "</div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"msg-reply-form\">\n");
|
||||
sprintf(buffer, "<div class=\"msg-reply-form\">\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) {
|
||||
@ -588,7 +584,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -596,22 +592,22 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
sprintf(buffer, "<input type=\"hidden\" name=\"area\" value=\"%d\" />\n", area);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
sprintf(buffer, "<input type=\"hidden\" name=\"replyid\" value=\"%s\" />\n", msgid);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -619,7 +615,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -631,7 +627,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -639,7 +635,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -647,20 +643,20 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
replybody = (char *)malloc(strlen(body) + 1);
|
||||
|
||||
l2 = 0;
|
||||
for (l1=0;l1<strlen(body);l1++){
|
||||
if (body[l1] == '\e' && body[l1+1] == '[') {
|
||||
for (l1 = 0; l1 < strlen(body); l1++) {
|
||||
if (body[l1] == '\e' && body[l1 + 1] == '[') {
|
||||
while (strchr("ABCDEFGHIGJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", body[l1]) == NULL && l1 < strlen(body))
|
||||
l1++;
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
for (i=0;i<strlen(body2);i++) {
|
||||
for (i = 0; i < strlen(body2); i++) {
|
||||
if (body2[i] == '\r') {
|
||||
sprintf(buffer, "\n %c> ", from[0]);
|
||||
chars = 0;
|
||||
@ -683,39 +679,37 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
chars = 1;
|
||||
} else {
|
||||
sprintf(buffer, "%c", body2[i]);
|
||||
chars ++;
|
||||
chars++;
|
||||
}
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
free(body2);
|
||||
sprintf(buffer, "</textarea>\n<br />");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "<input type=\"submit\" name=\"submit\" value=\"Reply\" />\n<br />");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</form>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -723,7 +717,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
@ -747,7 +741,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
}
|
||||
if (replyid != NULL) {
|
||||
free(replyid);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
} else {
|
||||
return NULL;
|
||||
@ -765,10 +759,10 @@ static char *www_wordwrap(char *content, int cutoff) {
|
||||
int quote_line = 0;
|
||||
int z;
|
||||
|
||||
for (i=0;i<len;i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (content[i] == '\n') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
content[at++] = content[i];
|
||||
}
|
||||
|
||||
@ -776,32 +770,33 @@ static char *www_wordwrap(char *content, int cutoff) {
|
||||
at = 0;
|
||||
len = strlen(content);
|
||||
|
||||
for (i=0;i<len-1;i++) {
|
||||
for (i = 0; i < len - 1; i++) {
|
||||
if (content[i] == '>' && line_count < 4) {
|
||||
quote_line = 1;
|
||||
}
|
||||
|
||||
if (content[i] == '\r' && content[i+1] != '\r') {
|
||||
if (content[i+1] == ' ' && quote_line != 1) {
|
||||
if (content[i] == '\r' && content[i + 1] != '\r') {
|
||||
if (content[i + 1] == ' ' && quote_line != 1) {
|
||||
content[at++] = '\r';
|
||||
line_count = 0;
|
||||
quote_line = 0;
|
||||
} else if (quote_line != 1) {
|
||||
for (z = i+1;content[z] != ' ' && z < len;z++);
|
||||
if (at > 0 && content[at-1] != '\r' && content[at-1] != ' ' && cutoff - line_count < z - i) {
|
||||
for (z = i + 1; content[z] != ' ' && z < len; z++)
|
||||
;
|
||||
if (at > 0 && content[at - 1] != '\r' && content[at - 1] != ' ' && cutoff - line_count < z - i) {
|
||||
content[at++] = ' ';
|
||||
line_count++;
|
||||
} else {
|
||||
content[at++] = '\r';
|
||||
line_count = 0;
|
||||
quote_line = 0;
|
||||
quote_line = 0;
|
||||
}
|
||||
} else if (quote_line == 1) {
|
||||
content[at++] = '\r';
|
||||
line_count = 0;
|
||||
quote_line = 0;
|
||||
quote_line = 0;
|
||||
}
|
||||
} else if (content[i] == '\r' && content[i+1] == '\r') {
|
||||
} else if (content[i] == '\r' && content[i + 1] == '\r') {
|
||||
content[at++] = '\r';
|
||||
content[at++] = '\r';
|
||||
line_count = 0;
|
||||
@ -815,7 +810,6 @@ static char *www_wordwrap(char *content, int cutoff) {
|
||||
content[at++] = content[i];
|
||||
content[at] = '\0';
|
||||
|
||||
|
||||
at = 0;
|
||||
|
||||
len = strlen(content);
|
||||
@ -823,11 +817,11 @@ static char *www_wordwrap(char *content, int cutoff) {
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
line_count = 0;
|
||||
quote_line = 0;
|
||||
|
||||
for (i=0;i<len;i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (content[i] != '\r') {
|
||||
ret[at] = content[i];
|
||||
if (content[i] == ' ') {
|
||||
@ -841,7 +835,7 @@ static char *www_wordwrap(char *content, int cutoff) {
|
||||
ret[at++] = content[i];
|
||||
}
|
||||
ret[at] = '\0';
|
||||
|
||||
|
||||
if (content[i] == '\r') {
|
||||
line_count = 0;
|
||||
last_space = NULL;
|
||||
@ -854,7 +848,7 @@ static char *www_wordwrap(char *content, int cutoff) {
|
||||
}
|
||||
last_space = NULL;
|
||||
line_count = 0;
|
||||
quote_line = 0;
|
||||
quote_line = 0;
|
||||
} else if (last_space != NULL) {
|
||||
*last_space = '\r';
|
||||
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) {
|
||||
s_JamBase *jb;
|
||||
s_JamMsgHeader jmh;
|
||||
s_JamSubPacket* jsp;
|
||||
s_JamSubPacket *jsp;
|
||||
s_JamSubfield jsf;
|
||||
s_JamLastRead jlr;
|
||||
s_JamBaseHeader jbh;
|
||||
@ -891,7 +885,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
char *page;
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[256];
|
||||
char buffer[256];
|
||||
char *body2;
|
||||
char *tagline;
|
||||
struct utsname name;
|
||||
@ -917,11 +911,11 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
if (!jb) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
JAM_ClearMsgHeader( &jmh );
|
||||
|
||||
JAM_ClearMsgHeader(&jmh);
|
||||
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) {
|
||||
strcpy(buffer, user->loginname);
|
||||
} else {
|
||||
@ -929,60 +923,60 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
}
|
||||
jsp = JAM_NewSubPacket();
|
||||
|
||||
jsf.LoID = JAMSFLD_SENDERNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_SENDERNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(to);
|
||||
jsf.Buffer = (char *)to;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
jsf.LoID = JAMSFLD_SUBJECT;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_SUBJECT;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(subj);
|
||||
jsf.Buffer = (char *)subj;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
|
||||
if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) {
|
||||
jmh.Attribute |= JAM_MSG_TYPEECHO;
|
||||
|
||||
if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
|
||||
if (conf.mail_conferences[conference]->fidoaddr->point) {
|
||||
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[conference]->fidoaddr->zone,
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node,
|
||||
conf.mail_conferences[conference]->fidoaddr->point);
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node,
|
||||
conf.mail_conferences[conference]->fidoaddr->point);
|
||||
} else {
|
||||
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[conference]->fidoaddr->zone,
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node);
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node);
|
||||
}
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[conference]->fidoaddr->zone,
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node,
|
||||
conf.mail_conferences[conference]->fidoaddr->point,
|
||||
generate_msgid());
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node,
|
||||
conf.mail_conferences[conference]->fidoaddr->point,
|
||||
generate_msgid());
|
||||
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
|
||||
|
||||
|
||||
if (strcasecmp(replyid, "NULL") != 0) {
|
||||
jsf.LoID = JAMSFLD_REPLYID;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_REPLYID;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(replyid);
|
||||
jsf.Buffer = (char *)replyid;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -990,8 +984,8 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
}
|
||||
} else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
|
||||
sprintf(buffer, "%d", conf.mail_conferences[conference]->maginode);
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -999,16 +993,16 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
uuid_generate(magi_msgid);
|
||||
uuid_unparse_lower(magi_msgid, buffer);
|
||||
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
|
||||
|
||||
|
||||
if (strcasecmp(replyid, "NULL") != 0) {
|
||||
jsf.LoID = JAMSFLD_REPLYID;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_REPLYID;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(replyid);
|
||||
jsf.Buffer = (char *)replyid;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -1033,27 +1027,25 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
free(jb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (conf.mail_conferences[conference]->tagline != NULL) {
|
||||
tagline = conf.mail_conferences[conference]->tagline;
|
||||
} else {
|
||||
tagline = conf.default_tagline;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uname(&name);
|
||||
|
||||
if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
|
||||
if (conf.mail_conferences[conference]->fidoaddr->point == 0) {
|
||||
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone,
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node);
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node);
|
||||
} else {
|
||||
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone,
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node,
|
||||
conf.mail_conferences[conference]->fidoaddr->point);
|
||||
conf.mail_conferences[conference]->fidoaddr->net,
|
||||
conf.mail_conferences[conference]->fidoaddr->node,
|
||||
conf.mail_conferences[conference]->fidoaddr->point);
|
||||
}
|
||||
} else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
|
||||
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->maginode);
|
||||
@ -1068,7 +1060,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
free(jb);
|
||||
return 0;
|
||||
}
|
||||
body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer));
|
||||
body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer));
|
||||
if (body3 == NULL) {
|
||||
free(body2);
|
||||
JAM_UnlockMB(jb);
|
||||
@ -1077,7 +1069,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
free(jb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
memset(body3, 0, strlen(body2) + 2 + strlen(buffer));
|
||||
pos = 0;
|
||||
@ -1087,7 +1078,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
body2 = (char *)malloc(strlen(body3) + 1);
|
||||
|
||||
ic = iconv_open("CP437", "UTF-8");
|
||||
|
||||
|
||||
inc = strlen(body3);
|
||||
ouc = strlen(body3);
|
||||
|
||||
@ -1097,7 +1088,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
free(body3);
|
||||
|
||||
if (JAM_AddMessage(jb, &jmh, jsp, (char *)body2, oubuf - body2)) {
|
||||
free(body2);
|
||||
free(body2);
|
||||
JAM_UnlockMB(jb);
|
||||
JAM_DelSubPacket(jsp);
|
||||
JAM_CloseMB(jb);
|
||||
@ -1113,13 +1104,12 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(body2);
|
||||
|
||||
JAM_UnlockMB(jb);
|
||||
|
||||
JAM_DelSubPacket(jsp);
|
||||
JAM_CloseMB(jb);
|
||||
JAM_CloseMB(jb);
|
||||
free(jb);
|
||||
iconv_close(ic);
|
||||
return 1;
|
||||
@ -1132,12 +1122,12 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[4096];
|
||||
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
memset(page, 0, 4096);
|
||||
|
||||
|
||||
sprintf(buffer, "<div class=\"content-header\"><h2>New Message</h2></div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -1150,7 +1140,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -1158,22 +1148,22 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
sprintf(buffer, "<input type=\"hidden\" name=\"area\" value=\"%d\" />\n", area);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
sprintf(buffer, "<input type=\"hidden\" name=\"replyid\" value=\"NULL\" />\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -1181,7 +1171,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -1189,7 +1179,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -1197,7 +1187,7 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
@ -1205,20 +1195,19 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</form>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
return page;
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user