Compare commits
No commits in common. "da9c5ff82adfc66445ae942db958190b93124723" and "160dbcd50f7f6c58e2657709cac4ce992f3ffd7a" have entirely different histories.
da9c5ff82a
...
160dbcd50f
@ -1,9 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.6)
|
cmake_minimum_required(VERSION 3.6)
|
||||||
project(magidoor)
|
project(magidoor)
|
||||||
|
|
||||||
if (WIN32)
|
set(SOURCE_FILES MD_Sendfile.c MD_Getc.c MD_Printf.c MD_Init.c MagiDoor.h)
|
||||||
set(SOURCE_FILES MD_Sendfile.c MD_Getc.c MD_Printf.c MD_Init.c MD_AnsiCons.c MD_AnsiCons.h MagiDoor.h)
|
|
||||||
else()
|
|
||||||
set(SOURCE_FILES MD_Sendfile.c MD_Getc.c MD_Printf.c MD_Init.c MagiDoor.h)
|
|
||||||
endif()
|
|
||||||
add_library(mdoor STATIC ${SOURCE_FILES})
|
add_library(mdoor STATIC ${SOURCE_FILES})
|
@ -1,4 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern int ansi_write(FILE* fp, const char* buf, int len);
|
extern int ansi_write(FILE* fp, const char* buf, int len);
|
102
MD_Getc.c
102
MD_Getc.c
@ -2,59 +2,34 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#if defined(_MSC_VER) || defined(WIN32)
|
#if defined(_MSC_VER) || defined(WIN32)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#define STDIN_FILENO 0
|
|
||||||
#define STDOUT_FILENO 1
|
|
||||||
#else
|
#else
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/select.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "MagiDoor.h"
|
#include "MagiDoor.h"
|
||||||
|
|
||||||
#define IAC 255
|
|
||||||
|
|
||||||
extern time_t mdtimeout;
|
extern time_t mdtimeout;
|
||||||
extern time_t mdtimeremaining;
|
extern time_t mdtimeremaining;
|
||||||
|
|
||||||
char md_getc() {
|
char md_getc() {
|
||||||
char c;
|
char c;
|
||||||
do {
|
ssize_t ret;
|
||||||
c = md_getche(60, 0);
|
|
||||||
} while(c == -1);
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
char md_getche(uint32_t sec, uint32_t usec) {
|
|
||||||
char c = 'x';
|
|
||||||
int ret;
|
|
||||||
int rs;
|
|
||||||
|
|
||||||
int stage = 0;
|
|
||||||
|
|
||||||
struct timeval tv;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
fd_set rfd;
|
|
||||||
FD_ZERO(&rfd);
|
|
||||||
if (mdcontrol.socket == -1) {
|
if (mdcontrol.socket == -1) {
|
||||||
FD_SET(STDIN_FILENO, &rfd);
|
ret = read(STDIN_FILENO, &c, 1);
|
||||||
} else {
|
} else {
|
||||||
FD_SET(mdcontrol.socket, &rfd);
|
ret = recv(mdcontrol.socket, &c, 1, 0);
|
||||||
}
|
}
|
||||||
|
if (ret == 0) {
|
||||||
tv.tv_sec = sec;
|
md_exit(0);
|
||||||
tv.tv_usec = usec;
|
|
||||||
|
|
||||||
if (mdcontrol.socket == -1) {
|
|
||||||
rs = select(STDIN_FILENO + 1, &rfd, NULL, NULL, &tv);
|
|
||||||
} else {
|
|
||||||
rs = select(mdcontrol.socket + 1, &rfd, NULL, NULL, &tv);
|
|
||||||
}
|
}
|
||||||
|
#if defined(_MSC_VER) || defined(WIN32)
|
||||||
if (rs == 0) {
|
if (ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) {
|
||||||
|
#else
|
||||||
|
if (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
|
||||||
|
#endif
|
||||||
if (mdtimeout <= time(NULL)) {
|
if (mdtimeout <= time(NULL)) {
|
||||||
md_printf("\r\nIdle timeout!\r\n");
|
md_printf("\r\nIdle timeout!\r\n");
|
||||||
md_exit(0);
|
md_exit(0);
|
||||||
@ -63,54 +38,15 @@ char md_getche(uint32_t sec, uint32_t usec) {
|
|||||||
md_printf("\r\nOut of time!\r\n");
|
md_printf("\r\nOut of time!\r\n");
|
||||||
md_exit(0);
|
md_exit(0);
|
||||||
}
|
}
|
||||||
return -1;
|
usleep(100);
|
||||||
} else if (rs == -1 && errno != EINTR) {
|
continue;
|
||||||
md_exit(0);
|
|
||||||
} else if (mdcontrol.socket != -1 && FD_ISSET(mdcontrol.socket, &rfd)) {
|
|
||||||
ret = recv(mdcontrol.socket, &c, 1, 0);
|
|
||||||
if (ret <= 0) {
|
|
||||||
md_exit(0);
|
|
||||||
}
|
|
||||||
if ((unsigned char)c == IAC && stage == 0) {
|
|
||||||
stage = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (stage == 1) {
|
|
||||||
if ((unsigned char)c == IAC) {
|
|
||||||
stage = 0;
|
|
||||||
} else if ((unsigned char)c == 250) {
|
|
||||||
stage = 3;
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
stage = 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (stage == 2) {
|
|
||||||
stage = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (stage == 3) {
|
|
||||||
if ((unsigned char)c == 240) {
|
|
||||||
stage = 0;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mdtimeout = time(NULL) + 900;
|
|
||||||
return c;
|
|
||||||
} else if (mdcontrol.socket == -1 && FD_ISSET(STDIN_FILENO, &rfd)) {
|
|
||||||
ret = read(STDIN_FILENO, &c, 1);
|
|
||||||
if (ret <= 0) {
|
|
||||||
md_exit(0);
|
|
||||||
}
|
|
||||||
mdtimeout = time(NULL) + 900;
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
mdtimeout = time(NULL) + 900;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char md_get_answer(const char *options) {
|
char md_get_answer(char *options) {
|
||||||
char c;
|
char c;
|
||||||
c = md_getc();
|
c = md_getc();
|
||||||
while (strchr(options, c) == NULL) {
|
while (strchr(options, c) == NULL) {
|
||||||
@ -124,8 +60,6 @@ int md_getstring(char *ptr, int maxlen, char minchar, char maxchar) {
|
|||||||
int len = 0;
|
int len = 0;
|
||||||
static char lastc = 'x';
|
static char lastc = 'x';
|
||||||
|
|
||||||
*ptr = '\0';
|
|
||||||
|
|
||||||
while (len < maxlen) {
|
while (len < maxlen) {
|
||||||
c = md_getc();
|
c = md_getc();
|
||||||
if (c == '\n' || c == '\0') {
|
if (c == '\n' || c == '\0') {
|
||||||
@ -142,7 +76,7 @@ int md_getstring(char *ptr, int maxlen, char minchar, char maxchar) {
|
|||||||
}
|
}
|
||||||
if (c == '\b' || c == 127) {
|
if (c == '\b' || c == 127) {
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
md_printf("\b \b");
|
md_printf("\x1b[D \x1b[D");
|
||||||
len--;
|
len--;
|
||||||
ptr[len] = '\0';
|
ptr[len] = '\0';
|
||||||
}
|
}
|
||||||
@ -158,4 +92,4 @@ int md_getstring(char *ptr, int maxlen, char minchar, char maxchar) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
16
MD_Init.c
16
MD_Init.c
@ -1,14 +1,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#if defined(WIN32) || defined(_MSC_VER)
|
#if defined(WIN32) || defined(_MSC_VER)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#define strcasecmp stricmp
|
|
||||||
#else
|
#else
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
#endif
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "MagiDoor.h"
|
#include "MagiDoor.h"
|
||||||
|
|
||||||
@ -174,16 +172,6 @@ int read_doorsys(const char *dropfile) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(WIN32) && !defined(_MSC_VER)
|
|
||||||
|
|
||||||
void md_sighuphandler(int i)
|
|
||||||
{
|
|
||||||
md_exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void md_exit(int exitcode) {
|
void md_exit(int exitcode) {
|
||||||
if (mdcontrol.socket == -1) {
|
if (mdcontrol.socket == -1) {
|
||||||
#if !defined(WIN32) && !defined(_MSC_VER)
|
#if !defined(WIN32) && !defined(_MSC_VER)
|
||||||
@ -199,8 +187,6 @@ void md_init(const char *dropfile, int socket) {
|
|||||||
char *filename = strrchr(dropfile, PATH_SEP);
|
char *filename = strrchr(dropfile, PATH_SEP);
|
||||||
#if !defined(WIN32) && !defined(_MSC_VER)
|
#if !defined(WIN32) && !defined(_MSC_VER)
|
||||||
struct termios ttystate;
|
struct termios ttystate;
|
||||||
signal(SIGHUP, &md_sighuphandler);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#if defined(_MSC_VER) || defined(WIN32)
|
#if defined(_MSC_VER) || defined(WIN32)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include "MD_AnsiCons.h"
|
#include "MD_AnsiCons.h"
|
||||||
#define STDOUT_FILENO 1
|
|
||||||
#else
|
#else
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
#endif
|
||||||
#include "MagiDoor.h"
|
#include "MagiDoor.h"
|
||||||
|
|
||||||
|
19
MagiDoor.h
19
MagiDoor.h
@ -1,11 +1,6 @@
|
|||||||
#ifndef __MAGIDOOR_H__
|
#ifndef __MAGIDOOR_H__
|
||||||
#define __MAGIDOOR_H__
|
#define __MAGIDOOR_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define MAGIDOOR_VERSION_MAJOR 1
|
|
||||||
#define MAGIDOOR_VERSION_MINOR 3
|
|
||||||
|
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
|
||||||
@ -23,16 +18,14 @@ typedef struct MDDoorControl {
|
|||||||
|
|
||||||
extern MDDoorControl_t mdcontrol;
|
extern MDDoorControl_t mdcontrol;
|
||||||
|
|
||||||
|
extern void md_init(const char *dropfile, int socket);
|
||||||
extern char md_getche(uint32_t sec, uint32_t usec);
|
|
||||||
extern void md_init(const char* dropfile, int socket);
|
|
||||||
extern void md_exit(int exitcode);
|
extern void md_exit(int exitcode);
|
||||||
extern void md_putchar(char c);
|
extern void md_putchar(char c);
|
||||||
extern void md_printf(const char* fmt, ...);
|
extern void md_printf(const char *fmt, ...);
|
||||||
extern char md_getc();
|
extern char md_getc();
|
||||||
extern int md_getstring(char* ptr, int maxlen, char minchar, char maxchar);
|
extern int md_getstring(char *ptr, int maxlen, char minchar, char maxchar);
|
||||||
extern void md_sendfile(const char* filename, int pause);
|
extern void md_sendfile(const char *filename, int pause);
|
||||||
extern void md_clr_scr();
|
extern void md_clr_scr();
|
||||||
extern void md_set_cursor(int y, int x);
|
extern void md_set_cursor(int y, int x);
|
||||||
extern char md_get_answer(const char* options);
|
extern char md_get_answer(char *options);
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user