clang-format

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

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

108
src/bbs.c
View File

@ -21,13 +21,11 @@
#include "lua/lualib.h"
#include "lua/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, ...) {
@ -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,8 +149,7 @@ struct fido_addr *parse_fido_addr(const char *str) {
case '6':
case '7':
case '8':
case '9':
{
case '9': {
switch (state) {
case 0:
ret->zone = ret->zone * 10 + (str[c] - '0');
@ -169,8 +164,7 @@ struct fido_addr *parse_fido_addr(const char *str) {
ret->point = ret->point * 10 + (str[c] - '0');
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) {
@ -967,7 +953,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
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");
@ -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) {
@ -1235,7 +1217,7 @@ int recursive_delete(const char *dir) {
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) {
@ -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;
}

View File

@ -48,7 +48,7 @@ struct last10_callers {
char location[33];
time_t time;
int calls;
}__attribute__((packed));
} __attribute__((packed));
struct text_file {
char *name;
@ -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);

View File

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

View File

@ -64,7 +64,7 @@ void blog_display() {
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 *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
char c;
int hour;
int j;
@ -83,7 +83,7 @@ void blog_display() {
c = 'y';
for (i=0;i<blog_entry_count;i++) {
for (i = 0; i < blog_entry_count; i++) {
localtime_r(&blog_entries[i]->date, &thetime);
s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author);
@ -129,7 +129,7 @@ void blog_display() {
s_printf("\r\n\r\n");
lines = 0;
}
for (j=0; j<strlen(blog_entries[i]->body); j++) {
for (j = 0; j < strlen(blog_entries[i]->body); j++) {
if (blog_entries[i]->body[j] == '\r') {
s_printf("\r\n");
lines++;
@ -164,7 +164,7 @@ void blog_display() {
lines = 0;
}
}
for (i=0;i<blog_entry_count;i++) {
for (i = 0; i < blog_entry_count; i++) {
free(blog_entries[i]->subject);
free(blog_entries[i]->author);
free(blog_entries[i]->body);
@ -175,7 +175,6 @@ void blog_display() {
s_printf(get_string(6));
s_getchar();
}
void blog_write() {
@ -220,7 +219,7 @@ void blog_write() {
}
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);
sqlite3_free(err_msg);
sqlite3_close(db);

View File

@ -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
@ -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;
@ -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,7 +610,6 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
sprintf(buffer, "%s %s", gUser->firstname, gUser->lastname);
}
jsp = JAM_NewSubPacket();
jsf.LoID = JAMSFLD_SENDERNAME;
@ -647,7 +643,6 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) {
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,
@ -685,7 +680,6 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf);
uuid_generate(magi_msgid);
uuid_unparse_lower(magi_msgid, buffer);
@ -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;
@ -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));

View File

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

View File

@ -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"
@ -37,9 +37,8 @@ struct chat_msg {
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 &&
if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
return 0;
}
@ -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;
}
@ -88,7 +87,7 @@ void raw(char *fmt, ...) {
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--;
}
@ -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");
@ -301,10 +298,10 @@ void chat_system(struct user_record *user) {
} else {
servaddr6.sin6_family = AF_INET6;
servaddr6.sin6_port = htons(conf.mgchat_port);
if ( (chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
if ((chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
chat_connected = 0;
} else {
if (connect(chat_socket, (struct sockaddr*)&servaddr6, sizeof(servaddr6)) < 0 ) {
if (connect(chat_socket, (struct sockaddr *)&servaddr6, sizeof(servaddr6)) < 0) {
chat_connected = 0;
} else {
chat_connected = 1;
@ -317,10 +314,10 @@ void chat_system(struct user_record *user) {
} else {
servaddr6.sin6_family = AF_INET6;
servaddr6.sin6_port = htons(conf.mgchat_port);
if ( (chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
if ((chat_socket = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
chat_connected = 0;
} else {
if (connect(chat_socket, (struct sockaddr*)&servaddr6, sizeof(servaddr6)) < 0 ) {
if (connect(chat_socket, (struct sockaddr *)&servaddr6, sizeof(servaddr6)) < 0) {
chat_connected = 0;
} else {
chat_connected = 1;
@ -338,10 +335,10 @@ void chat_system(struct user_record *user) {
} else {
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(conf.mgchat_port);
if ( (chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
if ((chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
return;
}
if (connect(chat_socket, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0 ) {
if (connect(chat_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
return;
}
}
@ -351,23 +348,21 @@ void chat_system(struct user_record *user) {
} else {
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(conf.mgchat_port);
if ( (chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
if ((chat_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
return;
}
if (connect(chat_socket, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0 ) {
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)) {
// 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));

View File

@ -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)
{
void doorchld_handler(int s) {
// waitpid() might overwrite errno, so we save and restore it:
while(waitpid(-1, NULL, WNOHANG) > 0);
while (waitpid(-1, NULL, WNOHANG) > 0)
;
running_door = 0;
}
@ -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,7 +440,7 @@ 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;
@ -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) {

View File

@ -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);
@ -82,7 +82,6 @@ void send_email(struct user_record *user) {
char *subject;
char *msg;
s_printf(get_string(54));
s_readstring(buffer, 16);
@ -156,12 +155,11 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
lines = 0;
chars = 0;
msg_line_count = 0;
start_line = 0;
// count the number of lines...
for (z=0;z<strlen(emails[msgno]->body);z++) {
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 *));
@ -175,7 +173,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
msg_lines[msg_line_count][0] = '\0';
} 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_lines[msg_line_count][z - start_line] = '\0';
}
msg_line_count++;
if (emails[msgno]->body[z] == '\r') {
@ -185,7 +183,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
}
chars = 0;
} else {
chars ++;
chars++;
}
}
@ -196,7 +194,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
while (!should_break) {
s_printf("\e[5;1H");
for (z=position;z<msg_line_count;z++) {
for (z = position; z < msg_line_count; z++) {
s_printf("%s\e[K\r\n", msg_lines[z]);
@ -240,7 +238,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
}
}
for (i=0;i<msg_line_count;i++) {
for (i = 0; i < msg_line_count; i++) {
free(msg_lines[i]);
}
free(msg_lines);
@ -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) {
@ -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;
}
@ -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,7 +617,6 @@ 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;

View File

@ -73,7 +73,7 @@ int ttySetRaw(int fd, struct termios *prevTermios) {
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];
@ -163,15 +162,15 @@ int doIO(ZModem *zm) {
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);
@ -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) {
@ -779,7 +776,7 @@ void upload(struct user_record *user) {
}
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);
sqlite3_free(err_msg);
sqlite3_close(db);
@ -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,25 +853,24 @@ 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 ) {
switch (done) {
case 0:
break ;
break;
case ZmErrCantOpen:
dolog("cannot open file \"%s\": %s", filename, strerror(errno)) ;
dolog("cannot open file \"%s\": %s", filename, strerror(errno));
return;
case ZmFileTooLong:
dolog("filename \"%s\" too long, skipping...", filename) ;
dolog("filename \"%s\" too long, skipping...", filename);
return;
case ZmDone:
@ -888,7 +884,7 @@ void download_zmodem(struct user_record *user, char *filename) {
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]);
@ -1074,7 +1065,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;
@ -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]);
@ -1132,7 +1123,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;
@ -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;
@ -1231,7 +1222,7 @@ void file_search() {
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);
@ -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,7 +1445,6 @@ 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);
@ -1479,8 +1467,6 @@ void list_files(struct user_record *user) {
sqlite3_bind_int(res, 1, userlaston);
}
files_c = 0;
while (sqlite3_step(res) == SQLITE_ROW) {
@ -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;
}
@ -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;
}

View File

@ -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,17 +29,17 @@ 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:
err:
if (m)
hashmap_free(m);
return NULL;
@ -49,45 +49,45 @@ map_t hashmap_new() {
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,
@ -141,19 +141,16 @@ static unsigned long crc32_tab[] = {
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
0x2d02ef8dL};
/* Return a 32-bit CRC of the contents of the buffer. */
unsigned long crc32(const unsigned char *s, unsigned int len)
{
unsigned long crc32(const unsigned char *s, unsigned int len) {
unsigned int i;
unsigned long crc32val;
crc32val = 0;
for (i = 0; i < len; i ++)
{
for (i = 0; i < len; i++) {
crc32val =
crc32_tab[(crc32val ^ s[i]) & 0xff] ^
(crc32val >> 8);
@ -164,9 +161,9 @@ unsigned long crc32(const unsigned char *s, unsigned int len)
/*
* 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 *)
hashmap_map *m = (hashmap_map *)in;
hashmap_element *temp = (hashmap_element *)
calloc(2 * m->table_size, sizeof(hashmap_element));
if(!temp) return MAP_OMEM;
if (!temp) return MAP_OMEM;
/* Update the array */
curr = m->data;
@ -239,7 +236,7 @@ int hashmap_rehash(map_t in){
m->size = 0;
/* Rehash the elements */
for(i = 0; i < old_size; i++){
for (i = 0; i < old_size; i++) {
int status;
if (curr[i].in_use == 0)
@ -258,16 +255,16 @@ int hashmap_rehash(map_t in){
/*
* Add a pointer to the hashmap with some key
*/
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,23 +283,23 @@ 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){
if (in_use == 1) {
if (strcmp(m->data[curr].key, key) == 0) {
*arg = (m->data[curr].data);
return MAP_OK;
}
@ -326,16 +323,16 @@ 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;
@ -348,23 +345,23 @@ int hashmap_iterate(map_t in, PFany f, any_t item) {
/*
* 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){
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;
@ -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;
}

View File

@ -50,17 +50,17 @@ extern int hashmap_iterate(map_t in, PFany f, any_t item);
/*
* Add an element to the hashmap. Return MAP_OK or MAP_OMEM.
*/
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.

View File

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

View File

@ -25,27 +25,24 @@ 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);
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)
{
static char *lskip(const char *s) {
while (*s && isspace((unsigned char)(*s)))
s++;
return (char*)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)) &&
@ -58,39 +55,37 @@ static char* find_chars_or_comment(const char* s, const char* chars)
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)
{
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];
#else
char* line;
char *line;
#endif
char section[MAX_SECTION] = "";
char prev_name[MAX_NAME] = "";
char* start;
char* end;
char* name;
char* value;
char *start;
char *end;
char *name;
char *value;
int lineno = 0;
int error = 0;
#if !INI_USE_STACK
line = (char*)malloc(INI_MAX_LINE);
line = (char *)malloc(INI_MAX_LINE);
if (!line) {
return -2;
}
@ -129,13 +124,11 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
*end = '\0';
strncpy0(section, start + 1, sizeof(section));
*prev_name = '\0';
}
else if (!error) {
} else if (!error) {
/* No ']' found on section line */
error = lineno;
}
}
else if (*start) {
} else if (*start) {
/* Not a comment, must be a name[=:]value pair */
end = find_chars_or_comment(start, "=:");
if (*end == '=' || *end == ':') {
@ -153,8 +146,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
strncpy0(prev_name, name, sizeof(prev_name));
if (!handler(user, section, name, value) && !error)
error = lineno;
}
else if (!error) {
} else if (!error) {
/* No '=' or ':' found on name[=:]value line */
error = lineno;
}
@ -174,15 +166,13 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
}
/* See documentation in header file. */
int ini_parse_file(FILE* file, ini_handler handler, void* user)
{
int ini_parse_file(FILE *file, ini_handler handler, void *user) {
return ini_parse_stream((ini_reader)fgets, file, handler, user);
}
/* See documentation in header file. */
int ini_parse(const char* filename, ini_handler handler, void* user)
{
FILE* file;
int ini_parse(const char *filename, ini_handler handler, void *user) {
FILE *file;
int error;
file = fopen(filename, "r");

View File

@ -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

View File

@ -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,11 +413,10 @@ 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;
@ -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;
}

File diff suppressed because it is too large Load Diff

View File

@ -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)
{
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;
}
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;
@ -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) {
@ -687,17 +678,17 @@ static int ssh_copy_fd_to_chan(socket_t fd, int revents, void *userdata) {
char buf[2048];
int sz = 0;
if(!chan) {
if (!chan) {
close(fd);
return -1;
}
if(revents & POLLIN) {
if (revents & POLLIN) {
sz = read(fd, buf, 2048);
if(sz > 0) {
if (sz > 0) {
ssh_channel_write(chan, buf, sz);
}
}
if(revents & POLLHUP) {
if (revents & POLLHUP) {
ssh_channel_close(chan);
sz = -1;
}
@ -710,7 +701,7 @@ static int ssh_copy_chan_to_fd(ssh_session session,
uint32_t len,
int is_stderr,
void *userdata) {
int fd = *(int*)userdata;
int fd = *(int *)userdata;
int sz;
(void)session;
(void)channel;
@ -721,7 +712,7 @@ static int ssh_copy_chan_to_fd(ssh_session session,
}
static void ssh_chan_close(ssh_session session, ssh_channel channel, void *userdata) {
int fd = *(int*)userdata;
int fd = *(int *)userdata;
int status;
(void)session;
(void)channel;
@ -732,8 +723,7 @@ 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
};
.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();
@ -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 {
@ -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);

View File

@ -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;

View File

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

View File

@ -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);

View File

@ -34,7 +34,6 @@ int openpty(int *amaster, int *aslave, char *name, void *termp, void *winp) {
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) {

View File

@ -5,4 +5,3 @@ extern int openpty(int *amaster, int *aslave, char *name, void *termp, void *win
extern int forkpty(int *amaster, char *name, void *termp, void *winp);
extern long gmtoff(time_t value);
#endif

View File

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

View File

@ -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++;

View File

@ -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,18 +29,16 @@ 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);
@ -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) {
@ -145,7 +142,6 @@ int save_user(struct user_record *user) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
}
rc = sqlite3_step(res);
if (rc != SQLITE_DONE) {
sqlite3_finalize(res);
@ -156,7 +152,6 @@ int save_user(struct user_record *user) {
sqlite3_finalize(res);
sqlite3_close(db);
return 1;
}
int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, int msgid) {
@ -170,7 +165,6 @@ int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, i
char *err_msg = 0;
int flagunflag = 0;
flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid);
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
@ -185,7 +179,7 @@ int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, i
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) {
if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg);
@ -266,7 +260,6 @@ int msgbase_sub_unsub(int conference, int msgbase) {
char *err_msg = 0;
int subunsub = 0;
subunsub = msgbase_is_subscribed(conference, msgbase);
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
@ -281,7 +274,7 @@ int msgbase_sub_unsub(int conference, int msgbase) {
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK ) {
if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg);
@ -316,8 +309,6 @@ int msgbase_is_subscribed(int conference, int msgbase) {
char *sql_buf = "SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
@ -399,7 +390,7 @@ int inst_user(struct user_record *user) {
}
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);
@ -442,7 +433,6 @@ int inst_user(struct user_record *user) {
exit(1);
}
rc = sqlite3_step(res);
if (rc != SQLITE_DONE) {
@ -547,7 +537,7 @@ struct user_record *check_user_pass(char *loginname, char *password) {
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
snprintf(buffer, 1024, "%s/s%d.ini", conf.config_path, user->sec_level);
if (ini_parse(buffer, secLevel, user->sec_info) <0) {
if (ini_parse(buffer, secLevel, user->sec_info) < 0) {
dolog("Unable to load sec Level ini (%s)!", buffer);
exit(-1);
}
@ -567,7 +557,6 @@ struct user_record *check_user_pass(char *loginname, char *password) {
user->cur_file_sub = 0;
}
return 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);
}

103
src/www.c
View File

@ -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);
@ -1098,11 +1094,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;
@ -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);

View File

@ -5,7 +5,6 @@
#include <stdlib.h>
#include "bbs.h"
extern struct bbs_config conf;
char *www_blog() {
@ -21,7 +20,7 @@ char *www_blog() {
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 *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
page = (char *)malloc(4096);
max_len = 4096;
@ -47,14 +46,14 @@ char *www_blog() {
strcat(page, buffer);
len += strlen(buffer);
} else {
for (i=0;i<blog_entry_count;i++) {
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);
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);
@ -70,9 +69,9 @@ char *www_blog() {
strcat(page, buffer);
len += strlen(buffer);
for (j=0;j<strlen(blog_entries[i]->body);j++) {
for (j = 0; j < strlen(blog_entries[i]->body); j++) {
if (blog_entries[i]->body[j] == '\r') {
if (blog_entries[i]->body[j+1] == '\r') {
if (blog_entries[i]->body[j + 1] == '\r') {
sprintf(buffer, "</p><p>");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
@ -106,7 +105,7 @@ char *www_blog() {
len += strlen(buffer);
}
for (i=0;i<blog_entry_count;i++) {
for (i = 0; i < blog_entry_count; i++) {
free(blog_entries[i]->subject);
free(blog_entries[i]->author);
free(blog_entries[i]->body);

View File

@ -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) {
@ -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);
@ -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;
@ -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;
@ -552,7 +545,6 @@ char *www_email_summary(struct user_record *user) {
"date INTEGER,"
"seen INTEGER);";
page = (char *)malloc(4096);
max_len = 4096;
len = 0;
@ -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);

View File

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

View File

@ -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) {

View File

@ -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,7 +33,7 @@ char *www_sanitize(char *inp) {
result = (char *)malloc(len + 1);
memset(result, 0, len + 1);
len = 0;
for (i=0;i<strlen(inp);i++) {
for (i = 0; i < strlen(inp); i++) {
if (inp[i] == '<') {
result[len++] = '&';
result[len++] = 'l';
@ -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);
@ -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,8 +565,6 @@ 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");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
@ -654,13 +650,13 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
replybody = (char *)malloc(strlen(body) + 1);
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;
@ -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 {
@ -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;