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
218
src/bbs.c
218
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,8 +45,7 @@ void sigterm_handler2(int s)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void sigint_handler(int s)
|
||||
{
|
||||
void sigint_handler(int s) {
|
||||
// do nothing...
|
||||
}
|
||||
void broadcast(char *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';
|
||||
}
|
||||
@ -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;
|
||||
@ -490,7 +479,6 @@ char s_getchar() {
|
||||
disconnect("Disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -516,7 +504,7 @@ char s_getchar() {
|
||||
if (len <= 0) {
|
||||
disconnect("Socket Closed");
|
||||
}
|
||||
} while(c != 240);
|
||||
} while (c != 240);
|
||||
}
|
||||
|
||||
do {
|
||||
@ -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,7 +567,7 @@ void s_readstring_inject(char *buffer, int max, char *inject) {
|
||||
}
|
||||
s_putchar(c);
|
||||
buffer[i] = c;
|
||||
buffer[i+1] = '\0';
|
||||
buffer[i + 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
@ -589,11 +577,11 @@ void s_readstring(char *buffer, int max) {
|
||||
|
||||
memset(buffer, 0, max);
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -887,18 +875,17 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
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,7 +902,6 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
}
|
||||
gSocket = socket;
|
||||
|
||||
|
||||
if (!ssh) {
|
||||
gUser = NULL;
|
||||
sshBBS = 0;
|
||||
@ -934,7 +920,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
s_printf("Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR);
|
||||
|
||||
// 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) {
|
||||
@ -963,11 +949,11 @@ 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 {
|
||||
@ -987,7 +973,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
|
||||
tries = 0;
|
||||
|
||||
if (!ssh) {
|
||||
tryagain:
|
||||
tryagain:
|
||||
s_printf(get_string(19));
|
||||
s_printf(get_string(20));
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -1095,13 +1081,10 @@ tryagain:
|
||||
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) {
|
||||
@ -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;
|
||||
}
|
||||
|
30
src/bbs.h
30
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;
|
||||
@ -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);
|
||||
|
483
src/bbs_list.c
483
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;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int id;
|
||||
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
|
||||
s_printf(get_string(28));
|
||||
s_readstring(bbsname, 18);
|
||||
@ -63,11 +63,11 @@ int add_bbs(struct bbs_list_entry_t *new_entry) {
|
||||
|
||||
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;
|
||||
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");
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
|
||||
snprintf(buffer, PATH_MAX, "%s/bbslist.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
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();
|
||||
while (1) {
|
||||
c = s_getchar();
|
||||
|
||||
if (tolower(c) == 'a') {
|
||||
add_bbs(NULL);
|
||||
break;
|
||||
} else if (tolower(c) == 'q') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tolower(c) == 'a') {
|
||||
add_bbs(NULL);
|
||||
break;
|
||||
} else if (tolower(c) == 'q') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
421
src/blog.c
421
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);
|
||||
|
||||
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));
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
|
||||
blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0));
|
||||
blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1));
|
||||
blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2));
|
||||
blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3);
|
||||
blog_entry_count++;
|
||||
}
|
||||
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));
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
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++;
|
||||
}
|
||||
|
||||
*entries = blog_entries;
|
||||
return blog_entry_count;
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
*entries = blog_entries;
|
||||
return blog_entry_count;
|
||||
}
|
||||
|
||||
void blog_display() {
|
||||
|
||||
struct blog_entry_t **blog_entries;
|
||||
int blog_entry_count = 0;
|
||||
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));
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
c = 'y';
|
||||
c = 'y';
|
||||
|
||||
for (i=0;i<blog_entry_count;i++) {
|
||||
localtime_r(&blog_entries[i]->date, &thetime);
|
||||
for (i = 0; i < blog_entry_count; i++) {
|
||||
localtime_r(&blog_entries[i]->date, &thetime);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
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]);
|
||||
}
|
||||
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();
|
||||
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);
|
||||
}
|
223
src/bluewave.c
223
src/bluewave.c
@ -23,10 +23,10 @@ tLONG convertl(tLONG l) {
|
||||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
unsigned char result_bytes[4];
|
||||
unsigned int result;
|
||||
result_bytes[0] = (unsigned char) ((l >> 24) & 0xFF);
|
||||
result_bytes[1] = (unsigned char) ((l >> 16) & 0xFF);
|
||||
result_bytes[2] = (unsigned char) ((l >> 8) & 0xFF);
|
||||
result_bytes[3] = (unsigned char) (l & 0xFF);
|
||||
result_bytes[0] = (unsigned char)((l >> 24) & 0xFF);
|
||||
result_bytes[1] = (unsigned char)((l >> 16) & 0xFF);
|
||||
result_bytes[2] = (unsigned char)((l >> 8) & 0xFF);
|
||||
result_bytes[3] = (unsigned char)(l & 0xFF);
|
||||
memcpy(&result, result_bytes, 4);
|
||||
return result;
|
||||
#else
|
||||
@ -38,8 +38,8 @@ tWORD converts(tWORD s) {
|
||||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
unsigned char result_bytes[2];
|
||||
unsigned short result;
|
||||
result_bytes[0] = (unsigned char) ((s >> 8) & 0xFF);
|
||||
result_bytes[1] = (unsigned char) (s & 0xFF);
|
||||
result_bytes[0] = (unsigned char)((s >> 8) & 0xFF);
|
||||
result_bytes[1] = (unsigned char)(s & 0xFF);
|
||||
memcpy(&result, result_bytes, 4);
|
||||
return result;
|
||||
#else
|
||||
@ -66,8 +66,8 @@ int bwave_scan_email(int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FI
|
||||
snprintf(buffer, PATH_MAX, "%s/email.sq3", conf.bbs_path);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
return totmsgs;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
@ -175,17 +175,16 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file
|
||||
} else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) {
|
||||
all_unread = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (all_unread == 0) {
|
||||
k = jlr.HighReadMsg;
|
||||
for (i=0;i<msghs->msg_count;i++) {
|
||||
for (i = 0; i < msghs->msg_count; i++) {
|
||||
if (msghs->msgs[i]->msg_h->MsgNum == k) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
i+=1;
|
||||
i += 1;
|
||||
} else {
|
||||
i = 0;
|
||||
}
|
||||
@ -194,7 +193,7 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file
|
||||
area_msgs = 0;
|
||||
personal_msgs = 0;
|
||||
|
||||
for (k=i;k<msghs->msg_count;k++) {
|
||||
for (k = i; k < msghs->msg_count; k++) {
|
||||
|
||||
if (totmsgs == conf.bwave_max_msgs) {
|
||||
break;
|
||||
@ -274,13 +273,13 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file
|
||||
|
||||
//if (area_msgs) {
|
||||
|
||||
memset(&mix, 0, sizeof(MIX_REC));
|
||||
memset(&mix, 0, sizeof(MIX_REC));
|
||||
|
||||
snprintf(mix.areanum, 6, "%d", areano);
|
||||
mix.totmsgs = converts(area_msgs);
|
||||
mix.numpers = converts(personal_msgs);
|
||||
mix.msghptr = convertl(mixptr);
|
||||
fwrite(&mix, sizeof(MIX_REC), 1, mix_file);
|
||||
snprintf(mix.areanum, 6, "%d", areano);
|
||||
mix.totmsgs = converts(area_msgs);
|
||||
mix.numpers = converts(personal_msgs);
|
||||
mix.msghptr = convertl(mixptr);
|
||||
fwrite(&mix, sizeof(MIX_REC), 1, mix_file);
|
||||
//}
|
||||
JAM_CloseMB(jb);
|
||||
free(jb);
|
||||
@ -321,8 +320,8 @@ void bwave_create_packet() {
|
||||
char *cmd;
|
||||
pid_t pid;
|
||||
|
||||
for (i=0;i<conf.mail_conference_count;i++) {
|
||||
for (j=0;j<conf.mail_conferences[i]->mail_area_count;j++) {
|
||||
for (i = 0; i < conf.mail_conference_count; i++) {
|
||||
for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) {
|
||||
if (msgbase_is_subscribed(i, j)) {
|
||||
tot_areas++;
|
||||
}
|
||||
@ -385,7 +384,7 @@ void bwave_create_packet() {
|
||||
|
||||
s_printf("\r\n");
|
||||
|
||||
totmsgs = bwave_scan_email(area_count+1, totmsgs, fti_file, mix_file, dat_file, &last_ptr);
|
||||
totmsgs = bwave_scan_email(area_count + 1, totmsgs, fti_file, mix_file, dat_file, &last_ptr);
|
||||
s_printf(get_string(195), "Private Email", "Private Email", totmsgs);
|
||||
areas = (INF_AREA_INFO **)malloc(sizeof(INF_AREA_INFO *));
|
||||
|
||||
@ -410,11 +409,11 @@ void bwave_create_packet() {
|
||||
|
||||
if (totmsgs < conf.bwave_max_msgs) {
|
||||
|
||||
for (i=0;i<conf.mail_conference_count;i++) {
|
||||
for (j=0;j<conf.mail_conferences[i]->mail_area_count;j++) {
|
||||
for (i = 0; i < conf.mail_conference_count; i++) {
|
||||
for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) {
|
||||
if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level <= gUser->sec_level && conf.mail_conferences[i]->mail_areas[j]->qwkname != NULL && msgbase_is_subscribed(i, j)) {
|
||||
lasttot = totmsgs;
|
||||
totmsgs = bwave_scan_area(i, j, area_count+1, totmsgs, fti_file, mix_file, dat_file, &last_ptr);
|
||||
totmsgs = bwave_scan_area(i, j, area_count + 1, totmsgs, fti_file, mix_file, dat_file, &last_ptr);
|
||||
s_printf(get_string(195), conf.mail_conferences[i]->name, conf.mail_conferences[i]->mail_areas[j]->name, totmsgs - lasttot);
|
||||
//if (lasttot == totmsgs) {
|
||||
// continue;
|
||||
@ -461,7 +460,6 @@ void bwave_create_packet() {
|
||||
if (totmsgs == conf.bwave_max_msgs) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (totmsgs == conf.bwave_max_msgs) {
|
||||
@ -479,13 +477,13 @@ void bwave_create_packet() {
|
||||
inf_file = fopen(buffer, "wb");
|
||||
fwrite(&hdr, sizeof(INF_HEADER), 1, inf_file);
|
||||
|
||||
for (i=0;i<area_count;i++) {
|
||||
for (i = 0; i < area_count; i++) {
|
||||
fwrite(areas[i], sizeof(INF_AREA_INFO), 1, inf_file);
|
||||
}
|
||||
|
||||
fclose(inf_file);
|
||||
|
||||
for (i=0;i<area_count;i++) {
|
||||
for (i = 0; i < area_count; i++) {
|
||||
free(areas[i]);
|
||||
}
|
||||
if (areas != NULL) {
|
||||
@ -508,21 +506,21 @@ void bwave_create_packet() {
|
||||
snprintf(archive, 1024, "%s/node%d/%s.%03d", conf.bbs_path, mynode, conf.bwave_name, gUser->bwavepktno);
|
||||
}
|
||||
|
||||
for (i=0;i<strlen(conf.archivers[gUser->defarchiver-1]->pack);i++) {
|
||||
if (conf.archivers[gUser->defarchiver-1]->pack[i] == '*') {
|
||||
for (i = 0; i < strlen(conf.archivers[gUser->defarchiver - 1]->pack); i++) {
|
||||
if (conf.archivers[gUser->defarchiver - 1]->pack[i] == '*') {
|
||||
i++;
|
||||
if (conf.archivers[gUser->defarchiver-1]->pack[i] == 'a') {
|
||||
if (conf.archivers[gUser->defarchiver - 1]->pack[i] == 'a') {
|
||||
sprintf(&buffer[bpos], "%s", archive);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.archivers[gUser->defarchiver-1]->pack[i] == 'f') {
|
||||
} else if (conf.archivers[gUser->defarchiver - 1]->pack[i] == 'f') {
|
||||
sprintf(&buffer[bpos], "%s/node%d/bwave/%s.INF %s/node%d/bwave/%s.MIX %s/node%d/bwave/%s.FTI %s/node%d/bwave/%s.DAT", conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.archivers[gUser->defarchiver-1]->pack[i] == '*') {
|
||||
} else if (conf.archivers[gUser->defarchiver - 1]->pack[i] == '*') {
|
||||
buffer[bpos++] = '*';
|
||||
buffer[bpos] = '\0';
|
||||
}
|
||||
} else {
|
||||
buffer[bpos++] = conf.archivers[gUser->defarchiver-1]->pack[i];
|
||||
buffer[bpos++] = conf.archivers[gUser->defarchiver - 1]->pack[i];
|
||||
buffer[bpos] = '\0';
|
||||
}
|
||||
}
|
||||
@ -536,7 +534,7 @@ void bwave_create_packet() {
|
||||
dup2(bbs_stdin, STDIN_FILENO);
|
||||
}
|
||||
|
||||
args = (char **)malloc(sizeof (char *));
|
||||
args = (char **)malloc(sizeof(char *));
|
||||
arg_count = 0;
|
||||
args[arg_count] = strtok(buffer, " ");
|
||||
while (args[arg_count] != NULL) {
|
||||
@ -588,11 +586,10 @@ void bwave_create_packet() {
|
||||
s_getc();
|
||||
}
|
||||
|
||||
|
||||
int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char *subject, struct fido_addr *destaddr, char *msg) {
|
||||
s_JamBase *jb;
|
||||
s_JamMsgHeader jmh;
|
||||
s_JamSubPacket* jsp;
|
||||
s_JamSubPacket *jsp;
|
||||
s_JamSubfield jsf;
|
||||
int z;
|
||||
char buffer[256];
|
||||
@ -604,7 +601,7 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
|
||||
return 1;
|
||||
}
|
||||
|
||||
JAM_ClearMsgHeader( &jmh );
|
||||
JAM_ClearMsgHeader(&jmh);
|
||||
jmh.DateWritten = dwritten;
|
||||
jmh.Attribute |= JAM_MSG_LOCAL;
|
||||
if (conf.mail_conferences[confr]->realnames == 0) {
|
||||
@ -613,33 +610,32 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
|
||||
sprintf(buffer, "%s %s", gUser->firstname, gUser->lastname);
|
||||
}
|
||||
|
||||
|
||||
jsp = JAM_NewSubPacket();
|
||||
|
||||
jsf.LoID = JAMSFLD_SENDERNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_SENDERNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) {
|
||||
sprintf(buffer, "ALL");
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
} else {
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_RECVRNAME;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(to);
|
||||
jsf.Buffer = (char *)to;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
}
|
||||
|
||||
jsf.LoID = JAMSFLD_SUBJECT;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_SUBJECT;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(subject);
|
||||
jsf.Buffer = (char *)subject;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -647,57 +643,55 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
|
||||
if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) {
|
||||
jmh.Attribute |= JAM_MSG_TYPEECHO;
|
||||
|
||||
|
||||
if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) {
|
||||
if (conf.mail_conferences[confr]->fidoaddr->point) {
|
||||
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
} else {
|
||||
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
}
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point,
|
||||
generate_msgid());
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point,
|
||||
generate_msgid());
|
||||
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
|
||||
} else if (conf.mail_conferences[confr]->nettype == NETWORK_MAGI) {
|
||||
sprintf(buffer, "%d", conf.mail_conferences[confr]->maginode);
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
|
||||
|
||||
uuid_generate(magi_msgid);
|
||||
uuid_unparse_lower(magi_msgid, buffer);
|
||||
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
|
||||
} else if (conf.mail_conferences[confr]->nettype == NETWORK_QWK) {
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(conf.bwave_name);
|
||||
jsf.Buffer = (char *)conf.bwave_name;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -708,16 +702,16 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
|
||||
|
||||
if (conf.mail_conferences[confr]->fidoaddr->point) {
|
||||
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
} else {
|
||||
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
}
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_OADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -725,29 +719,29 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
|
||||
if (destaddr != NULL) {
|
||||
if (destaddr->point) {
|
||||
sprintf(buffer, "%d:%d/%d.%d", destaddr->zone,
|
||||
destaddr->net,
|
||||
destaddr->node,
|
||||
destaddr->point);
|
||||
destaddr->net,
|
||||
destaddr->node,
|
||||
destaddr->point);
|
||||
} else {
|
||||
sprintf(buffer, "%d:%d/%d", destaddr->zone,
|
||||
destaddr->net,
|
||||
destaddr->node);
|
||||
destaddr->net,
|
||||
destaddr->node);
|
||||
}
|
||||
jsf.LoID = JAMSFLD_DADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_DADDRESS;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
}
|
||||
|
||||
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point,
|
||||
generate_msgid());
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point,
|
||||
generate_msgid());
|
||||
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.LoID = JAMSFLD_MSGID;
|
||||
jsf.HiID = 0;
|
||||
jsf.DatLen = strlen(buffer);
|
||||
jsf.Buffer = (char *)buffer;
|
||||
JAM_PutSubfield(jsp, &jsf);
|
||||
@ -811,18 +805,18 @@ void bwave_upload_reply() {
|
||||
int stin;
|
||||
int sterr;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
|
||||
char *err_msg = 0;
|
||||
char *err_msg = 0;
|
||||
char **args;
|
||||
int arg_count;
|
||||
char *cmd;
|
||||
@ -850,21 +844,21 @@ void bwave_upload_reply() {
|
||||
}
|
||||
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(conf.archivers[gUser->defarchiver-1]->unpack);i++) {
|
||||
if (conf.archivers[gUser->defarchiver-1]->unpack[i] == '*') {
|
||||
for (i = 0; i < strlen(conf.archivers[gUser->defarchiver - 1]->unpack); i++) {
|
||||
if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == '*') {
|
||||
i++;
|
||||
if (conf.archivers[gUser->defarchiver-1]->unpack[i] == 'a') {
|
||||
if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == 'a') {
|
||||
sprintf(&buffer[bpos], "%s", upload_filename);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.archivers[gUser->defarchiver-1]->unpack[i] == 'd') {
|
||||
} else if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == 'd') {
|
||||
sprintf(&buffer[bpos], "%s/node%d/bwave/", conf.bbs_path, mynode);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.archivers[gUser->defarchiver-1]->unpack[i] == '*') {
|
||||
} else if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == '*') {
|
||||
buffer[bpos++] = '*';
|
||||
buffer[bpos] = '\0';
|
||||
}
|
||||
} else {
|
||||
buffer[bpos++] = conf.archivers[gUser->defarchiver-1]->unpack[i];
|
||||
buffer[bpos++] = conf.archivers[gUser->defarchiver - 1]->unpack[i];
|
||||
buffer[bpos] = '\0';
|
||||
}
|
||||
}
|
||||
@ -877,7 +871,7 @@ void bwave_upload_reply() {
|
||||
dup2(bbs_stderr, STDERR_FILENO);
|
||||
dup2(bbs_stdin, STDIN_FILENO);
|
||||
}
|
||||
args = (char **)malloc(sizeof (char *));
|
||||
args = (char **)malloc(sizeof(char *));
|
||||
arg_count = 0;
|
||||
args[arg_count] = strtok(buffer, " ");
|
||||
while (args[arg_count] != NULL) {
|
||||
@ -957,7 +951,7 @@ void bwave_upload_reply() {
|
||||
body[s.st_size] = '\0';
|
||||
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(body);i++) {
|
||||
for (i = 0; i < strlen(body); i++) {
|
||||
if (body[i] != '\n') {
|
||||
body[bpos++] = body[i];
|
||||
}
|
||||
@ -977,7 +971,7 @@ void bwave_upload_reply() {
|
||||
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);
|
||||
|
||||
@ -1014,8 +1008,8 @@ void bwave_upload_reply() {
|
||||
confr = -1;
|
||||
area = -1;
|
||||
|
||||
for (i=0;i<conf.mail_conference_count;i++) {
|
||||
for (j=0;j<conf.mail_conferences[i]->mail_area_count;j++) {
|
||||
for (i = 0; i < conf.mail_conference_count; i++) {
|
||||
for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) {
|
||||
if (strcmp(conf.mail_conferences[i]->mail_areas[j]->qwkname, upl_rec.echotag) == 0) {
|
||||
confr = i;
|
||||
area = j;
|
||||
@ -1076,14 +1070,14 @@ void bwave_upload_reply() {
|
||||
if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) {
|
||||
if (conf.mail_conferences[confr]->fidoaddr->point == 0) {
|
||||
snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (%d:%d/%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node);
|
||||
} else {
|
||||
|
||||
snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (%d:%d/%d.%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->fidoaddr->zone,
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
conf.mail_conferences[confr]->fidoaddr->net,
|
||||
conf.mail_conferences[confr]->fidoaddr->node,
|
||||
conf.mail_conferences[confr]->fidoaddr->point);
|
||||
}
|
||||
} else if (conf.mail_conferences[confr]->nettype == NETWORK_MAGI) {
|
||||
snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (@%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->maginode);
|
||||
@ -1111,14 +1105,13 @@ void bwave_upload_reply() {
|
||||
strcat(body, originlinebuffer);
|
||||
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(body);i++) {
|
||||
for (i = 0; i < strlen(body); i++) {
|
||||
if (body[i] != '\n') {
|
||||
body[bpos++] = body[i];
|
||||
}
|
||||
}
|
||||
body[bpos] = '\0';
|
||||
|
||||
|
||||
if (bwave_add_message(confr, area, convertl(upl_rec.unix_date), upl_rec.to, upl_rec.subj, &addr, body) != 0) {
|
||||
// failed to add message
|
||||
s_printf(get_string(197));
|
||||
|
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);
|
||||
@ -66,13 +65,13 @@ void scroll_up() {
|
||||
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,19 +164,19 @@ 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--;
|
||||
}
|
||||
@ -191,19 +190,19 @@ 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++;
|
||||
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--;
|
||||
}
|
||||
@ -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,13 +312,13 @@ 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,38 +333,36 @@ 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;
|
||||
@ -404,7 +399,7 @@ void chat_system(struct user_record *user) {
|
||||
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,7 +432,7 @@ 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);
|
||||
@ -448,10 +443,10 @@ void chat_system(struct user_record *user) {
|
||||
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 {
|
||||
|
||||
@ -459,22 +454,22 @@ void chat_system(struct user_record *user) {
|
||||
// json parse
|
||||
jsmn_init(&parser);
|
||||
// we got some data from a client
|
||||
r = jsmn_parse(&parser, message, strlen(message), tokens, sizeof(tokens)/sizeof(tokens[0]));
|
||||
r = jsmn_parse(&parser, message, strlen(message), tokens, sizeof(tokens) / sizeof(tokens[0]));
|
||||
|
||||
if ((r < 0) || (r < 1 || tokens[0].type != JSMN_OBJECT)) {
|
||||
if ((r < 0) || (r < 1 || tokens[0].type != JSMN_OBJECT)) {
|
||||
// invalid json
|
||||
} 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++;
|
||||
}
|
||||
}
|
||||
@ -493,11 +488,9 @@ void chat_system(struct user_record *user) {
|
||||
append_screenbuffer(outputbuffer);
|
||||
do_update = 1;
|
||||
|
||||
|
||||
memset(buffer, 0, 513);
|
||||
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));
|
||||
|
42
src/doors.c
42
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;
|
||||
}
|
||||
@ -192,8 +192,6 @@ 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;
|
||||
@ -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;
|
||||
|
||||
@ -320,7 +316,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
gotiac = 0;
|
||||
flush = 0;
|
||||
|
||||
while(running_door || !flush) {
|
||||
while (running_door || !flush) {
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(master, &fdset);
|
||||
FD_SET(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') {
|
||||
@ -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);
|
||||
@ -510,7 +506,7 @@ 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);
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
|
246
src/email.c
246
src/email.c
@ -24,13 +24,13 @@ void commit_email(char *recipient, char *subject, char *msg) {
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"sender TEXT COLLATE NOCASE,"
|
||||
"recipient TEXT COLLATE NOCASE,"
|
||||
"subject TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER,"
|
||||
"seen INTEGER);";
|
||||
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
|
||||
char *err_msg = 0;
|
||||
|
||||
@ -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=?";
|
||||
@ -156,95 +155,94 @@ 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;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
lines = 0;
|
||||
position = 0;
|
||||
should_break = 0;
|
||||
|
||||
position = 0;
|
||||
should_break = 0;
|
||||
while (!should_break) {
|
||||
s_printf("\e[5;1H");
|
||||
for (z = position; z < msg_line_count; z++) {
|
||||
|
||||
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]);
|
||||
|
||||
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 (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;
|
||||
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);
|
||||
|
||||
@ -272,7 +270,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) {
|
||||
if (strncasecmp(emails[msgno]->subject, "RE:", 3) != 0) {
|
||||
@ -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) {
|
||||
@ -346,7 +343,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
|
||||
sqlite3_close(db);
|
||||
quit = 1;
|
||||
} else if (tolower(c) == ' ') {
|
||||
msgno ++;
|
||||
msgno++;
|
||||
if (msgno == email_count) {
|
||||
quit = 1;
|
||||
}
|
||||
@ -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);
|
||||
@ -432,34 +429,34 @@ void list_emails(struct user_record *user) {
|
||||
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,18 +487,18 @@ 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);
|
||||
@ -525,7 +522,7 @@ void list_emails(struct user_record *user) {
|
||||
// up
|
||||
position--;
|
||||
if (position < start) {
|
||||
start -=22;
|
||||
start -= 22;
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
@ -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;
|
||||
@ -611,7 +608,7 @@ void list_emails(struct user_record *user) {
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<email_count;i++) {
|
||||
for (i = 0; i < email_count; i++) {
|
||||
free(emails[i]->from);
|
||||
free(emails[i]->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);
|
||||
}
|
||||
|
||||
|
352
src/files.c
352
src/files.c
@ -50,30 +50,30 @@ struct tagged_file **tagged_files;
|
||||
int tagged_count = 0;
|
||||
|
||||
int ttySetRaw(int fd, struct termios *prevTermios) {
|
||||
struct termios t;
|
||||
struct termios t;
|
||||
|
||||
if (tcgetattr(fd, &t) == -1)
|
||||
return -1;
|
||||
if (tcgetattr(fd, &t) == -1)
|
||||
return -1;
|
||||
|
||||
if (prevTermios != NULL)
|
||||
*prevTermios = t;
|
||||
if (prevTermios != NULL)
|
||||
*prevTermios = t;
|
||||
|
||||
t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO);
|
||||
t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP | IXON | PARMRK);
|
||||
t.c_oflag &= ~OPOST;
|
||||
t.c_cc[VMIN] = 1;
|
||||
t.c_cc[VTIME] = 0;
|
||||
t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO);
|
||||
t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP | IXON | PARMRK);
|
||||
t.c_oflag &= ~OPOST;
|
||||
t.c_cc[VMIN] = 1;
|
||||
t.c_cc[VTIME] = 0;
|
||||
|
||||
if (tcsetattr(fd, TCSAFLUSH, &t) == -1)
|
||||
return -1;
|
||||
if (tcsetattr(fd, TCSAFLUSH, &t) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZXmitStr(u_char *str, int len, ZModem *info) {
|
||||
int i;
|
||||
|
||||
for (i=0;i<len;i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (str[i] == 255 && !sshBBS) {
|
||||
if (write(info->ofd, &str[i], 1) == 0) {
|
||||
return ZmErrSys;
|
||||
@ -94,18 +94,18 @@ void ZOFlush(ZModem *info) {
|
||||
}
|
||||
|
||||
int ZAttn(ZModem *info) {
|
||||
char *ptr ;
|
||||
char *ptr;
|
||||
|
||||
if( info->attn == NULL )
|
||||
return 0 ;
|
||||
if (info->attn == NULL)
|
||||
return 0;
|
||||
|
||||
for(ptr = info->attn; *ptr != '\0'; ++ptr) {
|
||||
if( *ptr == ATTNBRK ) {
|
||||
for (ptr = info->attn; *ptr != '\0'; ++ptr) {
|
||||
if (*ptr == ATTNBRK) {
|
||||
|
||||
} else if( *ptr == ATTNPSE ) {
|
||||
} else if (*ptr == ATTNPSE) {
|
||||
sleep(1);
|
||||
} else {
|
||||
write(info->ifd, ptr, 1) ;
|
||||
write(info->ifd, ptr, 1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -117,7 +117,6 @@ void ZFlowControl(int onoff, ZModem *info) {
|
||||
void ZStatus(int type, int value, char *status) {
|
||||
}
|
||||
|
||||
|
||||
char *upload_path;
|
||||
char upload_filename[1024];
|
||||
|
||||
@ -136,11 +135,11 @@ FILE *ZOpenFile(char *name, u_long crc, ZModem *info) {
|
||||
return fptr;
|
||||
}
|
||||
|
||||
int ZWriteFile(u_char *buffer, int len, FILE *file, ZModem *info) {
|
||||
int ZWriteFile(u_char *buffer, int len, FILE *file, ZModem *info) {
|
||||
return fwrite(buffer, 1, len, file) == len ? 0 : ZmErrSys;
|
||||
}
|
||||
|
||||
int ZCloseFile(ZModem *info) {
|
||||
int ZCloseFile(ZModem *info) {
|
||||
fclose(info->file);
|
||||
return 0;
|
||||
}
|
||||
@ -153,25 +152,25 @@ int doIO(ZModem *zm) {
|
||||
struct timeval timeout;
|
||||
u_char buffer[2048];
|
||||
u_char buffer2[1024];
|
||||
int len;
|
||||
int len;
|
||||
int pos;
|
||||
int done = 0;
|
||||
int i;
|
||||
int i;
|
||||
int j;
|
||||
char iac_binary_will[] = {IAC, IAC_WILL, IAC_TRANSMIT_BINARY, '\0'};
|
||||
char iac_binary_do[] = {IAC, IAC_DO, IAC_TRANSMIT_BINARY, '\0'};
|
||||
char iac_binary_wont[] = {IAC, IAC_WONT, IAC_TRANSMIT_BINARY, '\0'};
|
||||
char iac_binary_dont[] = {IAC, IAC_DONT, IAC_TRANSMIT_BINARY, '\0'};
|
||||
|
||||
while(!done) {
|
||||
while (!done) {
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(zm->ifd, &readfds) ;
|
||||
timeout.tv_sec = zm->timeout ;
|
||||
timeout.tv_usec = 0 ;
|
||||
i = select(zm->ifd+1, &readfds,NULL,NULL, &timeout) ;
|
||||
FD_SET(zm->ifd, &readfds);
|
||||
timeout.tv_sec = zm->timeout;
|
||||
timeout.tv_usec = 0;
|
||||
i = select(zm->ifd + 1, &readfds, NULL, NULL, &timeout);
|
||||
|
||||
if( i==0 ) {
|
||||
done = ZmodemTimeout(zm) ;
|
||||
if (i == 0) {
|
||||
done = ZmodemTimeout(zm);
|
||||
} else if (i > 0) {
|
||||
len = read(zm->ifd, buffer, 2048);
|
||||
if (len == 0) {
|
||||
@ -179,18 +178,18 @@ int doIO(ZModem *zm) {
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
for (j=0;j<len;j++) {
|
||||
for (j = 0; j < len; j++) {
|
||||
if (buffer[j] == 255 && !sshBBS) {
|
||||
if (buffer[j+1] == 255) {
|
||||
if (buffer[j + 1] == 255) {
|
||||
buffer2[pos] = 255;
|
||||
pos++;
|
||||
j++;
|
||||
} else {
|
||||
// IAC command
|
||||
if (buffer[j+1] == IAC_WILL || buffer[j+1] == IAC_WONT || buffer[j+1] == IAC_DO || buffer[j+1] == IAC_DONT) {
|
||||
switch (buffer[j+1]) {
|
||||
if (buffer[j + 1] == IAC_WILL || buffer[j + 1] == IAC_WONT || buffer[j + 1] == IAC_DO || buffer[j + 1] == IAC_DONT) {
|
||||
switch (buffer[j + 1]) {
|
||||
case IAC_WILL:
|
||||
if (buffer[j+2] == 0) {
|
||||
if (buffer[j + 2] == 0) {
|
||||
if (telnet_bin_mode != 1) {
|
||||
telnet_bin_mode = 1;
|
||||
write(gSocket, iac_binary_do, 3);
|
||||
@ -198,7 +197,7 @@ int doIO(ZModem *zm) {
|
||||
}
|
||||
break;
|
||||
case IAC_WONT:
|
||||
if (buffer[j+2] == 0) {
|
||||
if (buffer[j + 2] == 0) {
|
||||
if (telnet_bin_mode != 0) {
|
||||
telnet_bin_mode = 0;
|
||||
write(gSocket, iac_binary_dont, 3);
|
||||
@ -206,7 +205,7 @@ int doIO(ZModem *zm) {
|
||||
}
|
||||
break;
|
||||
case IAC_DO:
|
||||
if (buffer[j+2] == 0) {
|
||||
if (buffer[j + 2] == 0) {
|
||||
if (telnet_bin_mode != 1) {
|
||||
telnet_bin_mode = 1;
|
||||
write(gSocket, iac_binary_will, 3);
|
||||
@ -214,7 +213,7 @@ int doIO(ZModem *zm) {
|
||||
}
|
||||
break;
|
||||
case IAC_DONT:
|
||||
if (buffer[j+2] == 0) {
|
||||
if (buffer[j + 2] == 0) {
|
||||
if (telnet_bin_mode != 0) {
|
||||
telnet_bin_mode = 0;
|
||||
write(gSocket, iac_binary_wont, 3);
|
||||
@ -222,12 +221,12 @@ int doIO(ZModem *zm) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
j+= 2;
|
||||
} else if (buffer[j+1] == 250) {
|
||||
j += 2;
|
||||
} else if (buffer[j + 1] == 250) {
|
||||
j++;
|
||||
do {
|
||||
j++;
|
||||
} while(buffer[j] != 240);
|
||||
} while (buffer[j] != 240);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -236,7 +235,7 @@ int doIO(ZModem *zm) {
|
||||
}
|
||||
}
|
||||
if (pos > 0) {
|
||||
done = ZmodemRcv(buffer2, pos, zm) ;
|
||||
done = ZmodemRcv(buffer2, pos, zm);
|
||||
}
|
||||
} else {
|
||||
// SIG INT catch
|
||||
@ -305,7 +304,7 @@ char *get_file_id_diz(char *filename) {
|
||||
ext = 0;
|
||||
arch = -1;
|
||||
|
||||
for (i=strlen(filename)-1;i>=0;i--) {
|
||||
for (i = strlen(filename) - 1; i >= 0; i--) {
|
||||
if (filename[i] == '.') {
|
||||
ext = i + 1;
|
||||
break;
|
||||
@ -316,7 +315,7 @@ char *get_file_id_diz(char *filename) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0;i<conf.archiver_count;i++) {
|
||||
for (i = 0; i < conf.archiver_count; i++) {
|
||||
if (strcasecmp(&filename[ext], conf.archivers[i]->extension) == 0) {
|
||||
arch = i;
|
||||
break;
|
||||
@ -343,7 +342,7 @@ char *get_file_id_diz(char *filename) {
|
||||
mkdir(buffer, 0755);
|
||||
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(conf.archivers[arch]->unpack);i++) {
|
||||
for (i = 0; i < strlen(conf.archivers[arch]->unpack); i++) {
|
||||
if (conf.archivers[arch]->unpack[i] == '*') {
|
||||
i++;
|
||||
if (conf.archivers[arch]->unpack[i] == 'a') {
|
||||
@ -371,7 +370,7 @@ char *get_file_id_diz(char *filename) {
|
||||
dup2(bbs_stderr, STDERR_FILENO);
|
||||
dup2(bbs_stdin, STDIN_FILENO);
|
||||
}
|
||||
args = (char **)malloc(sizeof (char *));
|
||||
args = (char **)malloc(sizeof(char *));
|
||||
arg_count = 0;
|
||||
args[arg_count] = strtok(buffer, " ");
|
||||
while (args[arg_count] != NULL) {
|
||||
@ -423,12 +422,11 @@ char *get_file_id_diz(char *filename) {
|
||||
|
||||
bpos = 0;
|
||||
len = strlen(description);
|
||||
for (i=0;i<len;i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (description[i] == '\r') {
|
||||
continue;
|
||||
} else {
|
||||
description[bpos++] = description[i];
|
||||
|
||||
}
|
||||
}
|
||||
description[bpos] = '\0';
|
||||
@ -472,7 +470,7 @@ int do_download(struct user_record *user, char *file) {
|
||||
return 1;
|
||||
} else {
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(conf.protocols[user->defprotocol - 1]->download);i++) {
|
||||
for (i = 0; i < strlen(conf.protocols[user->defprotocol - 1]->download); i++) {
|
||||
if (conf.protocols[user->defprotocol - 1]->download[i] == '*') {
|
||||
i++;
|
||||
if (conf.protocols[user->defprotocol - 1]->download[i] == '*') {
|
||||
@ -501,7 +499,7 @@ int do_download(struct user_record *user, char *file) {
|
||||
}
|
||||
argc = 1;
|
||||
last_char_space = 0;
|
||||
for (i=0;i<strlen(download_command);i++) {
|
||||
for (i = 0; i < strlen(download_command); i++) {
|
||||
if (download_command[i] == ' ') {
|
||||
if (!last_char_space) {
|
||||
argc++;
|
||||
@ -514,7 +512,7 @@ int do_download(struct user_record *user, char *file) {
|
||||
bpos = 1;
|
||||
arguments = (char **)malloc(sizeof(char *) * (argc + 1));
|
||||
len = strlen(download_command);
|
||||
for (i=0;i<len;) {
|
||||
for (i = 0; i < len;) {
|
||||
if (download_command[i] != ' ') {
|
||||
i++;
|
||||
continue;
|
||||
@ -579,7 +577,7 @@ int do_upload(struct user_record *user, char *final_path) {
|
||||
s_printf("\r\n");
|
||||
}
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(conf.protocols[user->defprotocol - 1]->upload);i++) {
|
||||
for (i = 0; i < strlen(conf.protocols[user->defprotocol - 1]->upload); i++) {
|
||||
if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') {
|
||||
i++;
|
||||
if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') {
|
||||
@ -609,7 +607,7 @@ int do_upload(struct user_record *user, char *final_path) {
|
||||
}
|
||||
argc = 1;
|
||||
last_char_space = 0;
|
||||
for (i=0;i<strlen(upload_command);i++) {
|
||||
for (i = 0; i < strlen(upload_command); i++) {
|
||||
if (upload_command[i] == ' ') {
|
||||
if (!last_char_space) {
|
||||
argc++;
|
||||
@ -622,7 +620,7 @@ int do_upload(struct user_record *user, char *final_path) {
|
||||
bpos = 1;
|
||||
arguments = (char **)malloc(sizeof(char *) * (argc + 1));
|
||||
len = strlen(upload_command);
|
||||
for (i=0;i<len;) {
|
||||
for (i = 0; i < len;) {
|
||||
if (upload_command[i] != ' ') {
|
||||
i++;
|
||||
continue;
|
||||
@ -710,7 +708,6 @@ int do_upload(struct user_record *user, char *final_path) {
|
||||
recursive_delete(upload_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
closedir(inb);
|
||||
@ -725,13 +722,13 @@ void upload(struct user_record *user) {
|
||||
|
||||
int i;
|
||||
char *create_sql = "CREATE TABLE IF NOT EXISTS files ("
|
||||
"Id INTEGER PRIMARY KEY,"
|
||||
"filename TEXT,"
|
||||
"description TEXT,"
|
||||
"size INTEGER,"
|
||||
"dlcount INTEGER,"
|
||||
"uploaddate INTEGER,"
|
||||
"approved INTEGER);";
|
||||
"Id INTEGER PRIMARY KEY,"
|
||||
"filename TEXT,"
|
||||
"description TEXT,"
|
||||
"size INTEGER,"
|
||||
"dlcount INTEGER,"
|
||||
"uploaddate INTEGER,"
|
||||
"approved INTEGER);";
|
||||
char *sql = "INSERT INTO files (filename, description, size, dlcount, approved, uploaddate) VALUES(?, ?, ?, 0, 0, ?)";
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
@ -755,7 +752,7 @@ void upload(struct user_record *user) {
|
||||
s_printf(get_string(199));
|
||||
s_printf(get_string(200));
|
||||
buffer[0] = '\0';
|
||||
for (i=0;i<5;i++) {
|
||||
for (i = 0; i < 5; i++) {
|
||||
s_printf("\r\n%d: ", i);
|
||||
s_readstring(buffer2, 65);
|
||||
if (strlen(buffer2) == 0) {
|
||||
@ -773,59 +770,59 @@ void upload(struct user_record *user) {
|
||||
rc = sqlite3_open(buffer3, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
dolog("SQL error: %s", err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("SQL error: %s", err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
free(description);
|
||||
}
|
||||
return;
|
||||
}
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
return;
|
||||
}
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
if (rc == SQLITE_OK) {
|
||||
stat(upload_filename, &s);
|
||||
|
||||
sqlite3_bind_text(res, 1, upload_filename, -1, 0);
|
||||
if (description == NULL) {
|
||||
sqlite3_bind_text(res, 1, upload_filename, -1, 0);
|
||||
if (description == NULL) {
|
||||
sqlite3_bind_text(res, 2, buffer, -1, 0);
|
||||
} else {
|
||||
sqlite3_bind_text(res, 2, description, -1, 0);
|
||||
}
|
||||
sqlite3_bind_int(res, 3, s.st_size);
|
||||
curtime = time(NULL);
|
||||
sqlite3_bind_int(res, 4, curtime);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_bind_int(res, 3, s.st_size);
|
||||
curtime = time(NULL);
|
||||
sqlite3_bind_int(res, 4, curtime);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
free(description);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rc = sqlite3_step(res);
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
if (rc != SQLITE_DONE) {
|
||||
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
if (rc != SQLITE_DONE) {
|
||||
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
free(description);
|
||||
}
|
||||
return;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
free(description);
|
||||
}
|
||||
|
||||
@ -836,7 +833,7 @@ void upload(struct user_record *user) {
|
||||
|
||||
void download_zmodem(struct user_record *user, char *filename) {
|
||||
ZModem zm;
|
||||
int done ;
|
||||
int done;
|
||||
|
||||
dolog("Attempting to upload %s", filename);
|
||||
|
||||
@ -856,39 +853,38 @@ void download_zmodem(struct user_record *user, char *filename) {
|
||||
|
||||
zm.packetsize = 1024;
|
||||
|
||||
|
||||
ZmodemTInit(&zm) ;
|
||||
ZmodemTInit(&zm);
|
||||
done = doIO(&zm);
|
||||
if ( done != ZmDone ) {
|
||||
if (done != ZmDone) {
|
||||
return;
|
||||
}
|
||||
|
||||
done = ZmodemTFile(filename, basename(filename), ZCBIN,0,0,0,0,0, &zm) ;
|
||||
done = ZmodemTFile(filename, basename(filename), ZCBIN, 0, 0, 0, 0, 0, &zm);
|
||||
|
||||
switch( done ) {
|
||||
case 0:
|
||||
break ;
|
||||
switch (done) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case ZmErrCantOpen:
|
||||
dolog("cannot open file \"%s\": %s", filename, strerror(errno)) ;
|
||||
return;
|
||||
case ZmErrCantOpen:
|
||||
dolog("cannot open file \"%s\": %s", filename, strerror(errno));
|
||||
return;
|
||||
|
||||
case ZmFileTooLong:
|
||||
dolog("filename \"%s\" too long, skipping...", filename) ;
|
||||
return;
|
||||
case ZmFileTooLong:
|
||||
dolog("filename \"%s\" too long, skipping...", filename);
|
||||
return;
|
||||
|
||||
case ZmDone:
|
||||
return;
|
||||
case ZmDone:
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!done) {
|
||||
done = doIO(&zm);
|
||||
}
|
||||
|
||||
if ( done != ZmDone ) {
|
||||
if (done != ZmDone) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -899,13 +895,12 @@ void download_zmodem(struct user_record *user, char *filename) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void genurls() {
|
||||
#if defined(ENABLE_WWW)
|
||||
int i;
|
||||
char *url;
|
||||
if (conf.www_server) {
|
||||
for (i=0;i<tagged_count;i++) {
|
||||
for (i = 0; i < tagged_count; i++) {
|
||||
if (i % 6 == 0 && i != 0) {
|
||||
// pause
|
||||
s_printf(get_string(6));
|
||||
@ -922,7 +917,7 @@ void genurls() {
|
||||
s_printf(get_string(257));
|
||||
}
|
||||
}
|
||||
for (i=0;i<tagged_count;i++) {
|
||||
for (i = 0; i < tagged_count; i++) {
|
||||
free(tagged_files[i]->filename);
|
||||
free(tagged_files[i]);
|
||||
}
|
||||
@ -942,7 +937,6 @@ void genurls() {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void download(struct user_record *user) {
|
||||
int i;
|
||||
char *ssql = "select dlcount from files where filename like ?";
|
||||
@ -953,8 +947,7 @@ void download(struct user_record *user) {
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
|
||||
|
||||
for (i=0;i<tagged_count;i++) {
|
||||
for (i = 0; i < tagged_count; i++) {
|
||||
s_printf(get_string(254), basename(tagged_files[i]->filename));
|
||||
|
||||
do_download(user, tagged_files[i]->filename);
|
||||
@ -1005,9 +998,7 @@ void download(struct user_record *user) {
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (i=0;i<tagged_count;i++) {
|
||||
for (i = 0; i < tagged_count; i++) {
|
||||
free(tagged_files[i]->filename);
|
||||
free(tagged_files[i]);
|
||||
}
|
||||
@ -1028,7 +1019,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
|
||||
|
||||
s_printf("\r\n");
|
||||
|
||||
for (i=0;i<files_c;i++) {
|
||||
for (i = 0; i < files_c; i++) {
|
||||
file_size = files_e[i]->size;
|
||||
if (file_size > 1024 * 1024 * 1024) {
|
||||
file_size = file_size / 1024 / 1024 / 1024;
|
||||
@ -1047,8 +1038,8 @@ void do_list_files(struct file_entry **files_e, int files_c) {
|
||||
} else {
|
||||
s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename));
|
||||
}
|
||||
lines+=3;
|
||||
for (j=0;j<strlen(files_e[i]->description);j++) {
|
||||
lines += 3;
|
||||
for (j = 0; j < strlen(files_e[i]->description); j++) {
|
||||
if (files_e[i]->description[j] == '\n') {
|
||||
s_printf("\r\n");
|
||||
lines++;
|
||||
@ -1061,7 +1052,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
|
||||
s_printf("\r\n");
|
||||
break;
|
||||
} else if (tolower(buffer[0]) == 'q') {
|
||||
for (z=0;z<files_c;z++) {
|
||||
for (z = 0; z < files_c; z++) {
|
||||
free(files_e[z]->filename);
|
||||
free(files_e[z]->description);
|
||||
free(files_e[z]);
|
||||
@ -1069,12 +1060,12 @@ void do_list_files(struct file_entry **files_e, int files_c) {
|
||||
free(files_e);
|
||||
s_printf("\r\n");
|
||||
return;
|
||||
} else {
|
||||
} else {
|
||||
z = atoi(buffer);
|
||||
if (z >= 0 && z < files_c) {
|
||||
if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) {
|
||||
match = 0;
|
||||
for (k=0;k<tagged_count;k++) {
|
||||
for (k = 0; k < tagged_count; k++) {
|
||||
if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) {
|
||||
match = 1;
|
||||
break;
|
||||
@ -1119,7 +1110,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
|
||||
s_printf("\r\n");
|
||||
break;
|
||||
} else if (tolower(buffer[0]) == 'q') {
|
||||
for (z=0;z<files_c;z++) {
|
||||
for (z = 0; z < files_c; z++) {
|
||||
free(files_e[z]->filename);
|
||||
free(files_e[z]->description);
|
||||
free(files_e[z]);
|
||||
@ -1127,12 +1118,12 @@ void do_list_files(struct file_entry **files_e, int files_c) {
|
||||
free(files_e);
|
||||
s_printf("\r\n");
|
||||
return;
|
||||
} else {
|
||||
} else {
|
||||
z = atoi(buffer);
|
||||
if (z >= 0 && z < files_c) {
|
||||
if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) {
|
||||
match = 0;
|
||||
for (k=0;k<tagged_count;k++) {
|
||||
for (k = 0; k < tagged_count; k++) {
|
||||
if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) {
|
||||
match = 1;
|
||||
break;
|
||||
@ -1166,7 +1157,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
|
||||
s_printf(get_string(75));
|
||||
s_readstring(buffer, 5);
|
||||
if (strlen(buffer) == 0) {
|
||||
for (z=0;z<files_c;z++) {
|
||||
for (z = 0; z < files_c; z++) {
|
||||
free(files_e[z]->filename);
|
||||
free(files_e[z]->description);
|
||||
free(files_e[z]);
|
||||
@ -1179,7 +1170,7 @@ void do_list_files(struct file_entry **files_e, int files_c) {
|
||||
if (z >= 0 && z < files_c) {
|
||||
if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) {
|
||||
match = 0;
|
||||
for (k=0;k<tagged_count;k++) {
|
||||
for (k = 0; k < tagged_count; k++) {
|
||||
if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) {
|
||||
match = 1;
|
||||
break;
|
||||
@ -1223,15 +1214,15 @@ void file_search() {
|
||||
int search_dir;
|
||||
int search_sub;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int files_c;
|
||||
struct file_entry **files_e;
|
||||
|
||||
s_printf(get_string(236));
|
||||
ch = s_getc();
|
||||
|
||||
switch(tolower(ch)) {
|
||||
switch (tolower(ch)) {
|
||||
case 'd':
|
||||
stype = 1;
|
||||
break;
|
||||
@ -1270,25 +1261,25 @@ void file_search() {
|
||||
}
|
||||
if (stype == 0) {
|
||||
snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename LIKE ?");
|
||||
for (i=1; i < searchterm_count; i++) {
|
||||
for (i = 1; i < searchterm_count; i++) {
|
||||
strncat(sqlbuffer, " OR filename LIKE ?", 1024);
|
||||
}
|
||||
strncat(sqlbuffer, ")", 1024);
|
||||
}
|
||||
if (stype == 1) {
|
||||
snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (description LIKE ?");
|
||||
for (i=1; i < searchterm_count; i++) {
|
||||
for (i = 1; i < searchterm_count; i++) {
|
||||
strncat(sqlbuffer, " OR description LIKE ?", 1024);
|
||||
}
|
||||
strncat(sqlbuffer, ")", 1024);
|
||||
}
|
||||
if (stype == 2) {
|
||||
snprintf(sqlbuffer, 1024, "select id, filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename LIKE ?");
|
||||
for (i=1; i < searchterm_count; i++) {
|
||||
for (i = 1; i < searchterm_count; i++) {
|
||||
strncat(sqlbuffer, " OR filename LIKE ?", 1024);
|
||||
}
|
||||
strncat(sqlbuffer, " OR description LIKE ?", 1024);
|
||||
for (i=1; i < searchterm_count; i++) {
|
||||
for (i = 1; i < searchterm_count; i++) {
|
||||
strncat(sqlbuffer, " OR description LIKE ?", 1024);
|
||||
}
|
||||
strncat(sqlbuffer, ")", 1024);
|
||||
@ -1311,26 +1302,24 @@ void file_search() {
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
for (i=0;i<searchterm_count;i++) {
|
||||
for (i = 0; i < searchterm_count; i++) {
|
||||
free(searchterms[i]);
|
||||
}
|
||||
free(searchterms);
|
||||
return;
|
||||
}
|
||||
if (stype == 2) {
|
||||
for (j=0;j<2;j++) {
|
||||
for (i=0;i<searchterm_count;i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
for (i = 0; i < searchterm_count; i++) {
|
||||
sqlite3_bind_text(res, j * searchterm_count + i + 1, searchterms[i], -1, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i=0;i<searchterm_count;i++) {
|
||||
for (i = 0; i < searchterm_count; i++) {
|
||||
sqlite3_bind_text(res, i + 1, searchterms[i], -1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (files_c == 0) {
|
||||
files_e = (struct file_entry **)malloc(sizeof(struct file_entry *));
|
||||
@ -1382,13 +1371,13 @@ void file_search() {
|
||||
continue;
|
||||
}
|
||||
if (stype == 2) {
|
||||
for (j=0;j<2;j++) {
|
||||
for (i=0;i<searchterm_count;i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
for (i = 0; i < searchterm_count; i++) {
|
||||
sqlite3_bind_text(res, j * searchterm_count + i + 1, searchterms[i], -1, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i=0;i<searchterm_count;i++) {
|
||||
for (i = 0; i < searchterm_count; i++) {
|
||||
sqlite3_bind_text(res, i + 1, searchterms[i], -1, 0);
|
||||
}
|
||||
}
|
||||
@ -1419,7 +1408,7 @@ void file_search() {
|
||||
do_list_files(files_e, files_c);
|
||||
}
|
||||
}
|
||||
for (i=0;i<searchterm_count;i++) {
|
||||
for (i = 0; i < searchterm_count; i++) {
|
||||
free(searchterms[i]);
|
||||
}
|
||||
free(searchterms);
|
||||
@ -1433,8 +1422,8 @@ void list_files(struct user_record *user) {
|
||||
char *sql;
|
||||
char buffer[PATH_MAX];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
int files_c;
|
||||
|
||||
char ch;
|
||||
@ -1443,7 +1432,7 @@ void list_files(struct user_record *user) {
|
||||
s_printf(get_string(233));
|
||||
ch = s_getc();
|
||||
|
||||
switch(tolower(ch)) {
|
||||
switch (tolower(ch)) {
|
||||
case 'u':
|
||||
sql = dsql;
|
||||
break;
|
||||
@ -1456,32 +1445,29 @@ void list_files(struct user_record *user) {
|
||||
default:
|
||||
sql = fsql;
|
||||
break;
|
||||
|
||||
}
|
||||
s_printf("\r\n");
|
||||
snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
s_printf(get_string(68));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (sql == nsql) {
|
||||
sqlite3_bind_int(res, 1, userlaston);
|
||||
}
|
||||
|
||||
|
||||
|
||||
files_c = 0;
|
||||
files_c = 0;
|
||||
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (files_c == 0) {
|
||||
@ -1525,7 +1511,7 @@ void choose_subdir() {
|
||||
int selected = 0;
|
||||
char c;
|
||||
|
||||
for (i=0;i<conf.file_directories[gUser->cur_file_dir]->file_sub_count;i++) {
|
||||
for (i = 0; i < conf.file_directories[gUser->cur_file_dir]->file_sub_count; i++) {
|
||||
if (conf.file_directories[gUser->cur_file_dir]->file_subs[i]->download_sec_level <= gUser->sec_level) {
|
||||
if (list_tmp == 0) {
|
||||
sub_tmp = (struct subdir_tmp_t **)malloc(sizeof(struct subdir_tmp_t *));
|
||||
@ -1545,7 +1531,7 @@ void choose_subdir() {
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(252), conf.file_directories[gUser->cur_file_dir]->name);
|
||||
s_printf(get_string(248));
|
||||
for (i=start;i<start+22 && i < list_tmp;i++) {
|
||||
for (i = start; i < start + 22 && i < list_tmp; i++) {
|
||||
if (i == selected) {
|
||||
s_printf(get_string(249), i - start + 2, sub_tmp[i]->index, sub_tmp[i]->sub->name);
|
||||
} else {
|
||||
@ -1631,7 +1617,7 @@ void choose_subdir() {
|
||||
// PAGE DOWN
|
||||
selected = selected + 22;
|
||||
if (selected >= list_tmp) {
|
||||
selected = list_tmp -1;
|
||||
selected = list_tmp - 1;
|
||||
}
|
||||
start = selected;
|
||||
redraw = 1;
|
||||
@ -1643,7 +1629,7 @@ void choose_subdir() {
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<list_tmp;i++) {
|
||||
for (i = 0; i < list_tmp; i++) {
|
||||
free(sub_tmp[i]);
|
||||
}
|
||||
free(sub_tmp);
|
||||
@ -1663,7 +1649,7 @@ void choose_directory() {
|
||||
int selected = 0;
|
||||
char c;
|
||||
|
||||
for (i=0;i<conf.file_directory_count;i++) {
|
||||
for (i = 0; i < conf.file_directory_count; i++) {
|
||||
if (conf.file_directories[i]->sec_level <= gUser->sec_level) {
|
||||
if (list_tmp == 0) {
|
||||
dir_tmp = (struct dir_tmp_t **)malloc(sizeof(struct dir_tmp_t *));
|
||||
@ -1683,7 +1669,7 @@ void choose_directory() {
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(253));
|
||||
s_printf(get_string(248));
|
||||
for (i=start;i<start+22 && i < list_tmp;i++) {
|
||||
for (i = start; i < start + 22 && i < list_tmp; i++) {
|
||||
if (i == selected) {
|
||||
s_printf(get_string(249), i - start + 2, dir_tmp[i]->index, dir_tmp[i]->dir->name);
|
||||
} else {
|
||||
@ -1769,7 +1755,7 @@ void choose_directory() {
|
||||
// PAGE DOWN
|
||||
selected = selected + 22;
|
||||
if (selected >= list_tmp) {
|
||||
selected = list_tmp -1;
|
||||
selected = list_tmp - 1;
|
||||
}
|
||||
start = selected;
|
||||
redraw = 1;
|
||||
@ -1782,7 +1768,7 @@ void choose_directory() {
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<list_tmp;i++) {
|
||||
for (i = 0; i < list_tmp; i++) {
|
||||
free(dir_tmp[i]);
|
||||
}
|
||||
free(dir_tmp);
|
||||
@ -1792,7 +1778,7 @@ void clear_tagged_files() {
|
||||
int i;
|
||||
// Clear tagged files
|
||||
if (tagged_count > 0) {
|
||||
for (i=0;i<tagged_count;i++) {
|
||||
for (i = 0; i < tagged_count; i++) {
|
||||
free(tagged_files[i]->filename);
|
||||
free(tagged_files[i]);
|
||||
}
|
||||
@ -1803,11 +1789,11 @@ void clear_tagged_files() {
|
||||
|
||||
void next_file_dir(struct user_record *user) {
|
||||
int i;
|
||||
for (i=user->cur_file_dir;i<conf.file_directory_count;i++) {
|
||||
for (i = user->cur_file_dir; i < conf.file_directory_count; i++) {
|
||||
if (i + 1 == conf.file_directory_count) {
|
||||
i = -1;
|
||||
}
|
||||
if (conf.file_directories[i+1]->sec_level <= user->sec_level) {
|
||||
if (conf.file_directories[i + 1]->sec_level <= user->sec_level) {
|
||||
user->cur_file_dir = i + 1;
|
||||
user->cur_file_sub = 0;
|
||||
break;
|
||||
@ -1817,11 +1803,11 @@ void next_file_dir(struct user_record *user) {
|
||||
|
||||
void prev_file_dir(struct user_record *user) {
|
||||
int i;
|
||||
for (i=user->cur_file_dir;i>=0;i--) {
|
||||
for (i = user->cur_file_dir; i >= 0; i--) {
|
||||
if (i - 1 == -1) {
|
||||
i = conf.file_directory_count;
|
||||
}
|
||||
if (conf.file_directories[i-1]->sec_level <= user->sec_level) {
|
||||
if (conf.file_directories[i - 1]->sec_level <= user->sec_level) {
|
||||
user->cur_file_dir = i - 1;
|
||||
user->cur_file_sub = 0;
|
||||
break;
|
||||
@ -1831,7 +1817,7 @@ void prev_file_dir(struct user_record *user) {
|
||||
|
||||
void next_file_sub(struct user_record *user) {
|
||||
int i;
|
||||
i=user->cur_file_sub;
|
||||
i = user->cur_file_sub;
|
||||
if (i + 1 == conf.file_directories[user->cur_file_dir]->file_sub_count) {
|
||||
i = -1;
|
||||
}
|
||||
@ -1840,7 +1826,7 @@ void next_file_sub(struct user_record *user) {
|
||||
|
||||
void prev_file_sub(struct user_record *user) {
|
||||
int i;
|
||||
i=user->cur_file_sub;
|
||||
i = user->cur_file_sub;
|
||||
if (i - 1 == -1) {
|
||||
i = conf.file_directories[user->cur_file_dir]->file_sub_count;
|
||||
}
|
||||
@ -1855,7 +1841,7 @@ void file_scan() {
|
||||
char sql[] = "SELECT COUNT(*) FROM files WHERE uploaddate > ? AND approved=1";
|
||||
int rc;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
sqlite3_stmt *res;
|
||||
int new_files;
|
||||
int lines = 0;
|
||||
|
||||
@ -1863,7 +1849,7 @@ void file_scan() {
|
||||
c = s_getc();
|
||||
|
||||
if (tolower(c) == 'y') {
|
||||
for (i=0;i<conf.file_directory_count;i++) {
|
||||
for (i = 0; i < conf.file_directory_count; i++) {
|
||||
if (conf.file_directories[i]->sec_level > gUser->sec_level) {
|
||||
continue;
|
||||
}
|
||||
@ -1874,7 +1860,7 @@ void file_scan() {
|
||||
s_getc();
|
||||
lines = 0;
|
||||
}
|
||||
for (j=0;j<conf.file_directories[i]->file_sub_count;j++) {
|
||||
for (j = 0; j < conf.file_directories[i]->file_sub_count; j++) {
|
||||
if (conf.file_directories[i]->file_subs[j]->download_sec_level > gUser->sec_level) {
|
||||
continue;
|
||||
}
|
||||
|
@ -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;
|
||||
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;
|
||||
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,11 +236,11 @@ 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)
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
|
||||
/* 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;
|
||||
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();
|
||||
mymap = hashmap_new();
|
||||
|
||||
/* 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;
|
||||
/* 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;
|
||||
|
||||
error = hashmap_put(mymap, value->key_string, value);
|
||||
assert(error==MAP_OK);
|
||||
}
|
||||
error = hashmap_put(mymap, value->key_string, value);
|
||||
assert(error == MAP_OK);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
/* 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));
|
||||
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 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);
|
||||
/* Make sure that a value that wasn't in the map can't be found */
|
||||
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT);
|
||||
|
||||
error = hashmap_get(mymap, key_string, (void**)(&value));
|
||||
error = hashmap_get(mymap, key_string, (void **)(&value));
|
||||
|
||||
/* Make sure the value was not found */
|
||||
assert(error==MAP_MISSING);
|
||||
/* Make sure the value was not found */
|
||||
assert(error == MAP_MISSING);
|
||||
|
||||
/* 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);
|
||||
/* 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_get(mymap, key_string, (void **)(&value));
|
||||
assert(error == MAP_OK);
|
||||
|
||||
error = hashmap_remove(mymap, key_string);
|
||||
assert(error==MAP_OK);
|
||||
error = hashmap_remove(mymap, key_string);
|
||||
assert(error == MAP_OK);
|
||||
|
||||
free(value);
|
||||
}
|
||||
free(value);
|
||||
}
|
||||
|
||||
/* Now, destroy the map */
|
||||
hashmap_free(mymap);
|
||||
/* Now, destroy the map */
|
||||
hashmap_free(mymap);
|
||||
|
||||
return 1;
|
||||
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
|
||||
|
@ -187,7 +187,6 @@ int l_getBBSInfo(lua_State *L) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
int l_getUserHandle(lua_State *L) {
|
||||
lua_pushstring(L, gUser->loginname);
|
||||
|
||||
@ -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) {
|
||||
@ -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,7 +280,6 @@ 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);
|
||||
@ -307,7 +305,6 @@ int l_readMessageHdr(lua_State *L) {
|
||||
free(sender);
|
||||
free(recipient);
|
||||
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
@ -514,13 +510,13 @@ 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);
|
||||
@ -530,7 +526,7 @@ int l_postMessage(lua_State *L) {
|
||||
|
||||
j = 0;
|
||||
|
||||
for (i=0;i<strlen(body);i++) {
|
||||
for (i = 0; i < strlen(body); i++) {
|
||||
if (body[i] == '\n') {
|
||||
continue;
|
||||
}
|
||||
|
818
src/mail_menu.c
818
src/mail_menu.c
File diff suppressed because it is too large
Load Diff
225
src/main.c
225
src/main.c
@ -17,16 +17,16 @@
|
||||
#include <string.h>
|
||||
#include <poll.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
|
||||
#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);
|
||||
}
|
||||
@ -71,23 +70,22 @@ void sigterm_handler(int s)
|
||||
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) {
|
||||
@ -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);
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
@ -631,9 +622,9 @@ int ssh_authenticate(ssh_session p_ssh_session) {
|
||||
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;
|
||||
@ -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);
|
||||
@ -879,7 +868,6 @@ void serverssh(int port, int ipv6) {
|
||||
free(ip);
|
||||
ssh_disconnect(p_ssh_session);
|
||||
continue;
|
||||
|
||||
}
|
||||
} else {
|
||||
ip_guard->connection_count = 0;
|
||||
@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1035,7 +1018,7 @@ void server(int port, int ipv6) {
|
||||
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 {
|
||||
@ -1058,7 +1041,7 @@ void server(int port, int ipv6) {
|
||||
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 {
|
||||
@ -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) {
|
||||
@ -1134,7 +1117,6 @@ void server(int port, int ipv6) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
|
||||
remove(conf.pid_file);
|
||||
fprintf(stderr, "setsockopt(SO_REUSEADDR) failed");
|
||||
@ -1145,7 +1127,6 @@ void server(int port, int ipv6) {
|
||||
printf(" - Telnet Starting on Port %d (IPv%d)\n", port, (ipv6 ? 6 : 4));
|
||||
}
|
||||
|
||||
|
||||
if (ipv6) {
|
||||
if (setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) {
|
||||
fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed");
|
||||
@ -1196,7 +1177,7 @@ void server(int port, int ipv6) {
|
||||
}
|
||||
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)));
|
||||
@ -1249,7 +1229,6 @@ void server(int port, int ipv6) {
|
||||
free(ip);
|
||||
close(client_sock);
|
||||
continue;
|
||||
|
||||
}
|
||||
} else {
|
||||
ip_guard->connection_count = 0;
|
||||
@ -1326,7 +1305,7 @@ int main(int argc, char **argv) {
|
||||
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);
|
||||
}
|
||||
@ -1342,15 +1321,15 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
// 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);
|
||||
@ -1429,7 +1406,7 @@ 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);
|
||||
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 {
|
||||
@ -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;
|
||||
|
1210
src/menus.c
1210
src/menus.c
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,7 @@ 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;
|
||||
@ -19,9 +19,9 @@ char *nl_get_bbsname(struct fido_addr *addr, char *domain) {
|
||||
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);
|
||||
@ -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;
|
||||
@ -81,9 +81,9 @@ void nl_browser() {
|
||||
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);
|
||||
@ -93,7 +93,7 @@ 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) {
|
||||
@ -109,7 +109,7 @@ void nl_browser() {
|
||||
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) {
|
||||
@ -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 {
|
||||
@ -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;
|
||||
@ -227,7 +227,7 @@ void nl_browser() {
|
||||
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);
|
||||
|
@ -27,13 +27,12 @@ int openpty(int *amaster, int *aslave, char *name, void *termp, void *winp) {
|
||||
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;
|
||||
@ -85,13 +84,12 @@ int forkpty(int *amaster, char *name, void *termp, void *winp) {
|
||||
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++;
|
||||
|
593
src/users.c
593
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,125 +94,122 @@ 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;
|
||||
char *err_msg = 0;
|
||||
int flagunflag = 0;
|
||||
|
||||
flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid);
|
||||
|
||||
flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid);
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
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);
|
||||
rc = sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
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];
|
||||
|
||||
@ -226,11 +220,11 @@ int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, in
|
||||
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_buf, -1, &res, 0);
|
||||
@ -240,9 +234,9 @@ 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) {
|
||||
@ -257,77 +251,74 @@ 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);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
|
||||
dolog("SQL error: %s", err_msg);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
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);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int msgbase_is_subscribed(int conference, int msgbase) {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char buffer[PATH_MAX];
|
||||
|
||||
char *sql_buf = "SELECT * 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);
|
||||
|
||||
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);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
dolog("SQL error: %s", err_msg);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
|
||||
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);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int msgbase_is_subscribed(int conference, int msgbase) {
|
||||
sqlite3 *db;
|
||||
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);
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
||||
@ -337,9 +328,9 @@ 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);
|
||||
@ -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() {
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
|
105
src/www.c
105
src/www.c
@ -40,7 +40,7 @@ struct connection_info_s {
|
||||
struct MHD_PostProcessor *pp;
|
||||
};
|
||||
|
||||
void *www_logger(void * cls, const char * uri, struct MHD_Connection *con) {
|
||||
void *www_logger(void *cls, const char *uri, struct MHD_Connection *con) {
|
||||
struct sockaddr *so = (struct sockaddr *)MHD_get_connection_info(con, MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr;
|
||||
char *ipaddr;
|
||||
if (so->sa_family == AF_INET) {
|
||||
@ -66,7 +66,7 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void **
|
||||
if (con_info->connection_type == POST) {
|
||||
|
||||
if (con_info->count > 0) {
|
||||
for (i=0;i<con_info->count;i++) {
|
||||
for (i = 0; i < con_info->count; i++) {
|
||||
free(con_info->values[i]);
|
||||
free(con_info->keys[i]);
|
||||
}
|
||||
@ -94,7 +94,7 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void **
|
||||
free(con_info);
|
||||
}
|
||||
|
||||
static int iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) {
|
||||
static int iterate_post(void *coninfo_cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) {
|
||||
struct connection_info_s *con_info = coninfo_cls;
|
||||
|
||||
int i;
|
||||
@ -103,10 +103,9 @@ static int iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
|
||||
if (con_info != NULL) {
|
||||
if (con_info->connection_type == POST) {
|
||||
for (i=0;i<con_info->count;i++) {
|
||||
for (i = 0; i < con_info->count; i++) {
|
||||
if (strcmp(con_info->keys[i], key) == 0) {
|
||||
con_info->values[i] = (char *)realloc(con_info->values[i], strlen(con_info->values[i]) + size + 1);
|
||||
strcat(con_info->values[i], data);
|
||||
@ -150,7 +149,7 @@ void www_init() {
|
||||
while (!feof(fptr)) {
|
||||
chomp(buffer);
|
||||
|
||||
for (i=0;i<strlen(buffer);i++) {
|
||||
for (i = 0; i < strlen(buffer); i++) {
|
||||
if (buffer[i] == ' ') {
|
||||
buffer[i] = '\0';
|
||||
if (mime_types_count == 0) {
|
||||
@ -162,7 +161,7 @@ void www_init() {
|
||||
mime_types[mime_types_count] = (struct mime_type *)malloc(sizeof(struct mime_type));
|
||||
|
||||
mime_types[mime_types_count]->mime = strdup(buffer);
|
||||
mime_types[mime_types_count]->ext = strdup(&buffer[i+1]);
|
||||
mime_types[mime_types_count]->ext = strdup(&buffer[i + 1]);
|
||||
|
||||
mime_types_count++;
|
||||
break;
|
||||
@ -183,7 +182,7 @@ char *www_get_mime_type(const char *extension) {
|
||||
return default_mime_type;
|
||||
}
|
||||
|
||||
for (i=0;i<mime_types_count;i++) {
|
||||
for (i = 0; i < mime_types_count; i++) {
|
||||
if (strcasecmp(extension, mime_types[i]->ext) == 0) {
|
||||
return mime_types[i]->mime;
|
||||
}
|
||||
@ -191,7 +190,7 @@ char *www_get_mime_type(const char *extension) {
|
||||
return default_mime_type;
|
||||
}
|
||||
|
||||
int www_401(char *header, char *footer, struct MHD_Connection * connection) {
|
||||
int www_401(char *header, char *footer, struct MHD_Connection *connection) {
|
||||
char buffer[PATH_MAX];
|
||||
char *page, *page_tmp;
|
||||
struct stat s;
|
||||
@ -235,18 +234,18 @@ int www_401(char *header, char *footer, struct MHD_Connection * connection) {
|
||||
|
||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||
|
||||
response = MHD_create_response_from_buffer (strlen(whole_page), (void*)whole_page, MHD_RESPMEM_MUST_FREE);
|
||||
response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE);
|
||||
|
||||
MHD_add_response_header(response, "WWW-Authenticate", "Basic realm=\"BBS Area\"");
|
||||
|
||||
ret = MHD_queue_response (connection, 401, response);
|
||||
MHD_destroy_response (response);
|
||||
ret = MHD_queue_response(connection, 401, response);
|
||||
MHD_destroy_response(response);
|
||||
free(page);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int www_404(char *header, char *footer, struct MHD_Connection * connection) {
|
||||
int www_404(char *header, char *footer, struct MHD_Connection *connection) {
|
||||
char buffer[PATH_MAX];
|
||||
char *page, *page_tmp;
|
||||
struct stat s;
|
||||
@ -290,16 +289,16 @@ int www_404(char *header, char *footer, struct MHD_Connection * connection) {
|
||||
|
||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||
|
||||
response = MHD_create_response_from_buffer (strlen(whole_page), (void*)whole_page, MHD_RESPMEM_MUST_FREE);
|
||||
response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE);
|
||||
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
|
||||
MHD_destroy_response (response);
|
||||
ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response);
|
||||
MHD_destroy_response(response);
|
||||
free(page);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int www_403(char *header, char *footer, struct MHD_Connection * connection) {
|
||||
int www_403(char *header, char *footer, struct MHD_Connection *connection) {
|
||||
char buffer[PATH_MAX];
|
||||
char *page, *page_tmp;
|
||||
struct stat s;
|
||||
@ -344,10 +343,10 @@ int www_403(char *header, char *footer, struct MHD_Connection * connection) {
|
||||
|
||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||
|
||||
response = MHD_create_response_from_buffer (strlen(whole_page), (void*)whole_page, MHD_RESPMEM_MUST_FREE);
|
||||
response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE);
|
||||
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
|
||||
MHD_destroy_response (response);
|
||||
ret = MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response);
|
||||
MHD_destroy_response(response);
|
||||
free(page);
|
||||
|
||||
return 0;
|
||||
@ -377,10 +376,10 @@ struct user_record *www_auth_ok(struct MHD_Connection *connection, const char *u
|
||||
decoded_pass[len] = '\0';
|
||||
|
||||
username = decoded_pass;
|
||||
for (i=0;i<strlen(decoded_pass);i++) {
|
||||
for (i = 0; i < strlen(decoded_pass); i++) {
|
||||
if (decoded_pass[i] == ':') {
|
||||
decoded_pass[i] = '\0';
|
||||
password = &decoded_pass[i+1];
|
||||
password = &decoded_pass[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -394,7 +393,7 @@ struct user_record *www_auth_ok(struct MHD_Connection *connection, const char *u
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int www_handler(void * cls, struct MHD_Connection * connection, const char * url, const char * method, const char * version, const char * upload_data, size_t * upload_data_size, void ** ptr) {
|
||||
int www_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr) {
|
||||
struct MHD_Response *response;
|
||||
|
||||
int ret;
|
||||
@ -423,7 +422,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
int file_dir;
|
||||
int file_sub;
|
||||
char *filen;
|
||||
// char *static_buffer;
|
||||
// char *static_buffer;
|
||||
|
||||
page = NULL;
|
||||
|
||||
@ -604,7 +603,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
|
||||
|
||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||
} else if(strcasecmp(url, "/email/new") == 0) {
|
||||
} else if (strcasecmp(url, "/email/new") == 0) {
|
||||
con_inf->user = www_auth_ok(connection, url_);
|
||||
|
||||
if (con_inf->user == NULL) {
|
||||
@ -738,11 +737,11 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
|
||||
if (conference != -1 && area != -1 && msg != -1) {
|
||||
msgbase_flag_unflag(con_inf->user, conference, area, msg);
|
||||
response = MHD_create_response_from_buffer (0, (void*) "", MHD_RESPMEM_PERSISTENT);
|
||||
response = MHD_create_response_from_buffer(0, (void *)"", MHD_RESPMEM_PERSISTENT);
|
||||
snprintf(buffer, PATH_MAX, "%smsgs/%d/%d/%d", conf.www_url, conference, area, msg);
|
||||
|
||||
MHD_add_response_header (response, "Location", buffer);
|
||||
MHD_queue_response (connection, MHD_HTTP_FOUND, response);
|
||||
MHD_add_response_header(response, "Location", buffer);
|
||||
MHD_queue_response(connection, MHD_HTTP_FOUND, response);
|
||||
MHD_destroy_response(response);
|
||||
free(header);
|
||||
free(footer);
|
||||
@ -828,7 +827,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
}
|
||||
free(url_copy);
|
||||
|
||||
val = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "skip");
|
||||
val = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "skip");
|
||||
|
||||
if (val != NULL) {
|
||||
skip = atoi(val);
|
||||
@ -842,7 +841,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
page = www_msgs_messageview(con_inf->user, conference, area, msg);
|
||||
}
|
||||
|
||||
|
||||
if (page == NULL) {
|
||||
if (www_403(header, footer, connection) != 0) {
|
||||
free(header);
|
||||
@ -866,9 +864,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
|
||||
mime = NULL;
|
||||
// get mimetype
|
||||
for (i=strlen(url);i>0;--i) {
|
||||
for (i = strlen(url); i > 0; --i) {
|
||||
if (url[i] == '.') {
|
||||
mime = www_get_mime_type(&url[i+1]);
|
||||
mime = www_get_mime_type(&url[i + 1]);
|
||||
break;
|
||||
}
|
||||
if (url[i] == '/') {
|
||||
@ -881,7 +879,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
mime = www_get_mime_type(NULL);
|
||||
}
|
||||
|
||||
|
||||
// load file
|
||||
|
||||
sprintf(buffer, "%s%s", conf.www_path, url);
|
||||
@ -894,8 +891,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
response = MHD_create_response_from_fd(s.st_size, fno);
|
||||
//response = MHD_create_response_from_buffer (s.st_size, (void*) static_buffer, MHD_RESPMEM_MUST_FREE);
|
||||
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response(response);
|
||||
free(header);
|
||||
free(footer);
|
||||
return ret;
|
||||
@ -964,9 +961,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
if (filename != NULL) {
|
||||
mime = NULL;
|
||||
// get mimetype
|
||||
for (i=strlen(filename);i>0;--i) {
|
||||
for (i = strlen(filename); i > 0; --i) {
|
||||
if (filename[i] == '.') {
|
||||
mime = www_get_mime_type(&filename[i+1]);
|
||||
mime = www_get_mime_type(&filename[i + 1]);
|
||||
break;
|
||||
}
|
||||
if (filename[i] == '/') {
|
||||
@ -982,7 +979,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
fno = open(filename, O_RDONLY);
|
||||
if (fno != -1) {
|
||||
|
||||
|
||||
response = MHD_create_response_from_fd(s.st_size, fno);
|
||||
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime);
|
||||
sprintf(buffer, "%ld", s.st_size);
|
||||
@ -990,8 +986,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
|
||||
snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename));
|
||||
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response(response);
|
||||
free(header);
|
||||
free(footer);
|
||||
free(filename);
|
||||
@ -1033,9 +1029,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
if (filename != NULL) {
|
||||
mime = NULL;
|
||||
// get mimetype
|
||||
for (i=strlen(filename);i>0;--i) {
|
||||
for (i = strlen(filename); i > 0; --i) {
|
||||
if (filename[i] == '.') {
|
||||
mime = www_get_mime_type(&filename[i+1]);
|
||||
mime = www_get_mime_type(&filename[i + 1]);
|
||||
break;
|
||||
}
|
||||
if (filename[i] == '/') {
|
||||
@ -1059,8 +1055,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
|
||||
snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename));
|
||||
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response(response);
|
||||
free(header);
|
||||
free(footer);
|
||||
free(filename);
|
||||
@ -1097,12 +1093,12 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
free(footer);
|
||||
return MHD_YES;
|
||||
}
|
||||
if (con_inf->pp == NULL) {
|
||||
con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void*) con_inf);
|
||||
if (con_inf->pp == NULL) {
|
||||
con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void *)con_inf);
|
||||
}
|
||||
if (*upload_data_size != 0) {
|
||||
|
||||
MHD_post_process (con_inf->pp, upload_data, *upload_data_size);
|
||||
MHD_post_process(con_inf->pp, upload_data, *upload_data_size);
|
||||
*upload_data_size = 0;
|
||||
|
||||
return MHD_YES;
|
||||
@ -1110,7 +1106,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
subj = NULL;
|
||||
to = NULL;
|
||||
body = NULL;
|
||||
for (i=0;i<con_inf->count;i++) {
|
||||
for (i = 0; i < con_inf->count; i++) {
|
||||
if (strcmp(con_inf->keys[i], "recipient") == 0) {
|
||||
to = con_inf->values[i];
|
||||
} else if (strcmp(con_inf->keys[i], "subject") == 0) {
|
||||
@ -1150,11 +1146,11 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
return MHD_YES;
|
||||
}
|
||||
if (con_inf->pp == NULL) {
|
||||
con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void*) con_inf);
|
||||
con_inf->pp = MHD_create_post_processor(connection, POSTBUFFERSIZE, iterate_post, (void *)con_inf);
|
||||
}
|
||||
|
||||
if (*upload_data_size != 0) {
|
||||
MHD_post_process (con_inf->pp, upload_data, *upload_data_size);
|
||||
MHD_post_process(con_inf->pp, upload_data, *upload_data_size);
|
||||
*upload_data_size = 0;
|
||||
|
||||
return MHD_YES;
|
||||
@ -1166,7 +1162,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
conference = -1;
|
||||
area = -1;
|
||||
|
||||
for (i=0;i<con_inf->count;i++) {
|
||||
for (i = 0; i < con_inf->count; i++) {
|
||||
if (strcmp(con_inf->keys[i], "recipient") == 0) {
|
||||
to = con_inf->values[i];
|
||||
} else if (strcmp(con_inf->keys[i], "subject") == 0) {
|
||||
@ -1209,7 +1205,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
|
||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||
|
||||
|
||||
} else {
|
||||
free(header);
|
||||
free(footer);
|
||||
@ -1220,12 +1215,12 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
free(footer);
|
||||
return MHD_NO;
|
||||
}
|
||||
response = MHD_create_response_from_buffer (strlen (whole_page), (void*) whole_page, MHD_RESPMEM_MUST_FREE);
|
||||
response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE);
|
||||
|
||||
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html");
|
||||
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response(response);
|
||||
free(page);
|
||||
free(header);
|
||||
free(footer);
|
||||
|
163
src/www_blog.c
163
src/www_blog.c
@ -5,7 +5,6 @@
|
||||
#include <stdlib.h>
|
||||
#include "bbs.h"
|
||||
|
||||
|
||||
extern struct bbs_config conf;
|
||||
|
||||
char *www_blog() {
|
||||
@ -14,14 +13,14 @@ 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;
|
||||
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", "???"};
|
||||
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;
|
||||
@ -36,84 +35,84 @@ 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;
|
||||
}
|
||||
|
@ -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,14 +14,14 @@ 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;
|
||||
|
||||
@ -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,14 +64,14 @@ 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;
|
||||
@ -88,8 +87,6 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
|
||||
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);
|
||||
@ -97,7 +94,7 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
|
||||
body = (char *)malloc(strlen(ibody) + strlen(buffer) + 1);
|
||||
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++;
|
||||
@ -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;
|
||||
@ -205,7 +200,6 @@ char *www_new_email() {
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</form>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -235,13 +229,13 @@ 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=?";
|
||||
@ -261,7 +255,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
}
|
||||
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);
|
||||
|
||||
@ -346,7 +340,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
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] == '<') {
|
||||
@ -440,7 +434,7 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
|
||||
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,7 +443,7 @@ 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;
|
||||
@ -475,7 +469,6 @@ char *www_email_display(struct user_record *user, int email) {
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</form>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -544,14 +537,13 @@ 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;
|
||||
@ -582,9 +574,9 @@ char *www_email_summary(struct user_record *user) {
|
||||
free(page);
|
||||
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);
|
||||
|
||||
@ -642,7 +634,6 @@ 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);
|
||||
|
709
src/www_files.c
709
src/www_files.c
@ -7,305 +7,304 @@
|
||||
#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(?, ?)";
|
||||
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;
|
||||
char *ret;
|
||||
char *err_msg = 0;
|
||||
|
||||
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);
|
||||
if (rc != SQLITE_OK) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
|
||||
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK) {
|
||||
rc = sqlite3_exec(db, csql, 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);
|
||||
return;
|
||||
}
|
||||
|
||||
// first check if hash is in database
|
||||
rc = sqlite3_prepare_v2(db, chsql, -1, &res, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
sqlite3_free(err_msg);
|
||||
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);
|
||||
// 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);
|
||||
sqlite3_bind_int(res, 2, expiry);
|
||||
sqlite3_step(res);
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
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);
|
||||
}
|
||||
@ -316,18 +315,18 @@ char *www_files_display_listing(int dir, int sub) {
|
||||
|
||||
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);
|
||||
}
|
||||
@ -335,21 +334,21 @@ char *www_files_display_listing(int dir, int sub) {
|
||||
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,29 +361,29 @@ 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);
|
||||
|
||||
@ -398,18 +397,17 @@ char *www_files_display_listing(int dir, int sub) {
|
||||
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);
|
||||
}
|
||||
@ -419,133 +417,132 @@ char *www_files_display_listing(int dir, int sub) {
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
@ -53,7 +52,7 @@ 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) {
|
||||
|
135
src/www_msgs.c
135
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';
|
||||
@ -79,7 +78,7 @@ 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,7 +88,7 @@ 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) {
|
||||
@ -191,7 +190,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
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);
|
||||
@ -266,7 +265,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) {
|
||||
s_JamBase *jb;
|
||||
s_JamMsgHeader jmh;
|
||||
s_JamSubPacket* jsp;
|
||||
s_JamSubPacket *jsp;
|
||||
s_JamSubfield jsf;
|
||||
s_JamLastRead jlr;
|
||||
s_JamBaseHeader jbh;
|
||||
@ -325,7 +324,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
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);
|
||||
@ -378,9 +377,9 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
|
||||
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));
|
||||
@ -543,7 +542,6 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
aha_text = (char *)malloc(jmh.TxtLen + 1);
|
||||
|
||||
memcpy(aha_text, body, jmh.TxtLen);
|
||||
@ -567,9 +565,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
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);
|
||||
@ -654,13 +650,13 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
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,7 +679,7 @@ 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;
|
||||
@ -701,7 +697,6 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
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;
|
||||
@ -710,7 +705,6 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</form>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
@ -765,7 +759,7 @@ 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;
|
||||
}
|
||||
@ -776,19 +770,20 @@ 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 {
|
||||
@ -801,7 +796,7 @@ static char *www_wordwrap(char *content, int cutoff) {
|
||||
line_count = 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);
|
||||
@ -827,7 +821,7 @@ static char *www_wordwrap(char *content, int cutoff) {
|
||||
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] == ' ') {
|
||||
@ -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;
|
||||
@ -918,7 +912,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
return 0;
|
||||
}
|
||||
|
||||
JAM_ClearMsgHeader( &jmh );
|
||||
JAM_ClearMsgHeader(&jmh);
|
||||
jmh.DateWritten = (uint32_t)utc_to_local(time(NULL));
|
||||
jmh.Attribute |= JAM_MSG_LOCAL;
|
||||
|
||||
@ -929,20 +923,20 @@ 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);
|
||||
@ -953,36 +947,36 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
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);
|
||||
@ -1034,8 +1028,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (conf.mail_conferences[conference]->tagline != NULL) {
|
||||
tagline = conf.mail_conferences[conference]->tagline;
|
||||
} else {
|
||||
@ -1047,13 +1039,13 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
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);
|
||||
@ -1078,7 +1070,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
memset(body3, 0, strlen(body2) + 2 + strlen(buffer));
|
||||
pos = 0;
|
||||
sprintf(body3, "%s%s", body2, buffer);
|
||||
@ -1113,7 +1104,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(body2);
|
||||
|
||||
JAM_UnlockMB(jb);
|
||||
@ -1209,7 +1199,6 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
|
||||
sprintf(buffer, "</form>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
|
Reference in New Issue
Block a user