-updated the progress bar design (thanks mamule)

-updated the ftp server gui side, now displays a few information on screen while the server is running so you can see a bit debugging information on screen
-added user labels for themes to the ftp server menu
This commit is contained in:
fix94.1 2013-09-06 23:40:32 +00:00
parent 5886fbdbe4
commit c1465f849a
10 changed files with 93 additions and 25 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 B

After

Width:  |  Height:  |  Size: 117 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 B

After

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 291 B

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 187 B

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

After

Width:  |  Height:  |  Size: 224 B

View File

@ -21,30 +21,38 @@
#include "network/gcard.h" #include "network/gcard.h"
#include "network/FTP_Dir.hpp" #include "network/FTP_Dir.hpp"
s16 m_ftpLblTitle;
s16 m_ftpBtnBack; s16 m_ftpBtnBack;
s16 m_ftpBtnToggle; s16 m_ftpBtnToggle;
s16 m_ftpLblInfo;
s16 m_ftpLblUser[4];
void CMenu::_updateFTP(void) void CMenu::_updateFTP(void)
{ {
_hideFTP(true);
if(m_ftp_inited == true) if(m_ftp_inited == true)
{ {
in_addr addr; in_addr addr;
addr.s_addr = net_gethostip(); addr.s_addr = net_gethostip();
m_btnMgr.setText(m_wbfsLblDialog, wfmt(_fmt("dlmsg28", L"Running FTP Server on %s:%d"), inet_ntoa(addr), ftp_server_port)); m_btnMgr.hide(m_wbfsLblDialog, true);
m_btnMgr.setText(m_ftpLblTitle, wfmt(_t("dlmsg28", L"Running FTP Server on %s:%d"), inet_ntoa(addr), ftp_server_port));
m_btnMgr.show(m_ftpLblTitle);
m_btnMgr.setText(m_ftpBtnToggle, _t("ftp2", L"Stop")); m_btnMgr.setText(m_ftpBtnToggle, _t("ftp2", L"Stop"));
m_btnMgr.show(m_ftpLblInfo);
} }
else else
{ {
m_btnMgr.hide(m_ftpLblTitle, true);
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg29", L"FTP Server is currently stopped.")); m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg29", L"FTP Server is currently stopped."));
m_btnMgr.setText(m_ftpBtnToggle, _t("ftp1", L"Start")); m_btnMgr.setText(m_ftpBtnToggle, _t("ftp1", L"Start"));
m_btnMgr.show(m_wbfsLblDialog);
} }
_showFTP();
} }
void CMenu::_FTP(void) void CMenu::_FTP(void)
{ {
_showFTP();
_updateFTP(); _updateFTP();
m_btnMgr.show(m_wbfsLblDialog);
while(!m_exit) while(!m_exit)
{ {
_mainLoopCommon(); _mainLoopCommon();
@ -56,13 +64,13 @@ void CMenu::_FTP(void)
break; break;
else if(m_btnMgr.selected(m_ftpBtnToggle)) else if(m_btnMgr.selected(m_ftpBtnToggle))
{ {
gprintf("%d\n", m_ftp_inited);
if(m_ftp_inited == true) if(m_ftp_inited == true)
{ {
ftp_endTread(); ftp_endTread();
m_init_ftp = false; m_init_ftp = false;
m_ftp_inited = false; m_ftp_inited = false;
init_network = (m_cfg.getBool("GENERAL", "async_network") || has_enabled_providers() || m_use_wifi_gecko); init_network = (m_cfg.getBool("GENERAL", "async_network") || has_enabled_providers() || m_use_wifi_gecko);
ftp_dbg_print_update();
} }
else else
{ {
@ -82,6 +90,11 @@ void CMenu::_FTP(void)
_updateFTP(); _updateFTP();
} }
} }
if(ftp_dbg_print_update())
{
m_btnMgr.setText(m_ftpLblInfo, wfmt(L"%s%s%s%s%s%s", ftp_get_prints(5), ftp_get_prints(4),
ftp_get_prints(3), ftp_get_prints(2), ftp_get_prints(1), ftp_get_prints(0)));
}
} }
m_btnMgr.hide(m_wbfsLblDialog); m_btnMgr.hide(m_wbfsLblDialog);
_hideFTP(); _hideFTP();
@ -91,21 +104,35 @@ void CMenu::_showFTP(void)
{ {
m_btnMgr.show(m_ftpBtnToggle); m_btnMgr.show(m_ftpBtnToggle);
m_btnMgr.show(m_ftpBtnBack); m_btnMgr.show(m_ftpBtnBack);
for(u8 i = 0; i < ARRAY_SIZE(m_ftpLblUser); ++i)
if(m_ftpLblUser[i] != -1)
m_btnMgr.show(m_ftpLblUser[i]);
} }
void CMenu::_hideFTP(bool instant) void CMenu::_hideFTP(bool instant)
{ {
m_btnMgr.hide(m_ftpLblTitle, instant);
m_btnMgr.hide(m_ftpBtnToggle, instant); m_btnMgr.hide(m_ftpBtnToggle, instant);
m_btnMgr.hide(m_ftpBtnBack, instant); m_btnMgr.hide(m_ftpBtnBack, instant);
m_btnMgr.hide(m_ftpLblInfo, instant);
for(u8 i = 0; i < ARRAY_SIZE(m_ftpLblUser); ++i)
if(m_ftpLblUser[i] != -1)
m_btnMgr.hide(m_ftpLblUser[i], instant);
} }
void CMenu::_initFTP(void) void CMenu::_initFTP(void)
{ {
_addUserLabels(m_ftpLblUser, ARRAY_SIZE(m_ftpLblUser), "FTP");
m_ftpLblTitle = _addTitle("FTP/TITLE", theme.titleFont, L"", 20, 30, 600, 60, theme.titleFontColor, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
m_ftpBtnToggle = _addButton("FTP/TOGGLE_BTN", theme.btnFont, L"", 20, 400, 200, 56, theme.btnFontColor); m_ftpBtnToggle = _addButton("FTP/TOGGLE_BTN", theme.btnFont, L"", 20, 400, 200, 56, theme.btnFontColor);
m_ftpBtnBack = _addButton("FTP/BACK_BTN", theme.btnFont, L"", 420, 400, 200, 56, theme.btnFontColor); m_ftpBtnBack = _addButton("FTP/BACK_BTN", theme.btnFont, L"", 420, 400, 200, 56, theme.btnFontColor);
m_ftpLblInfo = _addText("FTP/INFO", theme.txtFont, L"", 40, 115, 560, 270, theme.txtFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP);
_setHideAnim(m_ftpLblTitle, "FTP/TITLE", 0, -200, 0.f, 1.f);
_setHideAnim(m_ftpBtnToggle, "FTP/TOGGLE_BTN", 0, 0, 1.f, -1.f); _setHideAnim(m_ftpBtnToggle, "FTP/TOGGLE_BTN", 0, 0, 1.f, -1.f);
_setHideAnim(m_ftpBtnBack, "FTP/BACK_BTN", 0, 0, 1.f, -1.f); _setHideAnim(m_ftpBtnBack, "FTP/BACK_BTN", 0, 0, 1.f, -1.f);
_setHideAnim(m_ftpLblInfo, "FTP/INFO", 0, 100, 0.f, 0.f);
_textFTP(); _textFTP();
_hideFTP(true); _hideFTP(true);
@ -113,7 +140,9 @@ void CMenu::_initFTP(void)
void CMenu::_textFTP(void) void CMenu::_textFTP(void)
{ {
m_btnMgr.setText(m_ftpLblTitle, L"");
m_btnMgr.setText(m_ftpBtnToggle, L""); m_btnMgr.setText(m_ftpBtnToggle, L"");
m_btnMgr.setText(m_ftpBtnBack, _t("cfg10", L"Back")); m_btnMgr.setText(m_ftpBtnBack, _t("cfg10", L"Back"));
m_btnMgr.setText(m_ftpLblInfo, L"");
} }

View File

@ -33,12 +33,16 @@ char main_path[MAXPATHLEN];
char real_path[MAXPATHLEN]; char real_path[MAXPATHLEN];
u8 cur_part = 0; u8 cur_part = 0;
char dbg_messages[6][128];
void ftp_init(void) void ftp_init(void)
{ {
memset(main_path, 0, MAXPATHLEN); memset(main_path, 0, MAXPATHLEN);
main_path[0] = '/'; main_path[0] = '/';
memset(real_path, 0, MAXPATHLEN); memset(real_path, 0, MAXPATHLEN);
cur_part = 0; cur_part = 0;
for(u8 i = 0; i < 6; ++i)
memset(dbg_messages[i], 0, 128);
} }
const char *ftp_getpath(void) const char *ftp_getpath(void)
@ -310,6 +314,34 @@ void ftp_endTread(void)
cur_server_num = -1; cur_server_num = -1;
} }
bool dbg_msg_change = false;
void ftp_dbg_print(char *dbg_info)
{
dbg_msg_change = true;
/* for gecko and stuff */
gprintf(dbg_info);
/* for our gui */
for(u8 i = 5; i > 0; --i)
memcpy(dbg_messages[i], dbg_messages[i-1], 128);
memcpy(dbg_messages[0], dbg_info, 127);
*(dbg_messages[0]+127) = '\0';
}
const char *ftp_get_prints(u8 i)
{
return dbg_messages[i];
}
bool ftp_dbg_print_update(void)
{
if(dbg_msg_change)
{
dbg_msg_change = false;
return true;
}
return false;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -46,6 +46,10 @@ int ftp_delete(char *path);
bool ftp_startThread(void); bool ftp_startThread(void);
void ftp_endTread(void); void ftp_endTread(void);
void ftp_dbg_print(char *dbg_info);
bool ftp_dbg_print_update(void);
const char *ftp_get_prints(u8 i);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -80,7 +80,7 @@ static s32 write_reply(client_t *client, u16 code, char *msg) {
char msgbuf[msglen + 1]; char msgbuf[msglen + 1];
if (msgbuf == NULL) return -ENOMEM; if (msgbuf == NULL) return -ENOMEM;
strncpy(msgbuf, fmt("%u %s\r\n", code, msg), msglen + 1); strncpy(msgbuf, fmt("%u %s\r\n", code, msg), msglen + 1);
gprintf("Wrote reply: %s", msgbuf); ftp_dbg_print(fmt("Wrote reply: %s", msgbuf));
return send_exact(client->socket, msgbuf, msglen); return send_exact(client->socket, msgbuf, msglen);
} }
@ -295,7 +295,7 @@ static s32 ftp_PASV(client_t *client, char *rest __attribute__((unused))) {
u32 ip = net_gethostip(); u32 ip = net_gethostip();
struct in_addr addr; struct in_addr addr;
addr.s_addr = ip; addr.s_addr = ip;
gprintf("Listening for data connections at %s:%u...\n", inet_ntoa(addr), port); ftp_dbg_print(fmt("Listening for data connections at %s:%u...\n", inet_ntoa(addr), port));
strncpy(reply, fmt("Entering Passive Mode (%u,%u,%u,%u,%u,%u).", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, (port >> 8) & 0xff, port & 0xff), 49); strncpy(reply, fmt("Entering Passive Mode (%u,%u,%u,%u,%u,%u).", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, (port >> 8) & 0xff, port & 0xff), 49);
return write_reply(client, 227, reply); return write_reply(client, 227, reply);
} }
@ -318,7 +318,7 @@ static s32 ftp_PORT(client_t *client, char *portspec) {
u16 port = ((p1 &0xff) << 8) | (p2 & 0xff); u16 port = ((p1 &0xff) << 8) | (p2 & 0xff);
client->address.sin_addr = sin_addr; client->address.sin_addr = sin_addr;
client->address.sin_port = htons(port); client->address.sin_port = htons(port);
gprintf("Set client address to %s:%u\n", addr_str, port); ftp_dbg_print(fmt("Set client address to %s:%u\n", addr_str, port));
return write_reply(client, 200, "PORT command successful."); return write_reply(client, 200, "PORT command successful.");
} }
@ -340,13 +340,14 @@ static s32 prepare_data_connection_active(client_t *client) {
} }
client->data_socket = data_socket; client->data_socket = data_socket;
gprintf("Attempting to connect to client at %s:%u\n", inet_ntoa(client->address.sin_addr), ntohs(client->address.sin_port)); ftp_dbg_print(fmt("Attempting to connect to client at %s:%u\n",
inet_ntoa(client->address.sin_addr), ntohs(client->address.sin_port)));
return 0; return 0;
} }
static s32 prepare_data_connection_passive(client_t *client) { static s32 prepare_data_connection_passive(client_t *client) {
client->data_socket = client->passive_socket; client->data_socket = client->passive_socket;
gprintf("Waiting for data connections...\n"); ftp_dbg_print("Waiting for data connections...\n");
return 0; return 0;
} }
@ -554,7 +555,7 @@ static s32 process_command(client_t *client, char *cmd_line) {
return 0; return 0;
} }
gprintf("Got command: %s\n", cmd_line); ftp_dbg_print(fmt("Got command: %s\n", cmd_line));
const char **commands = unauthenticated_commands; const char **commands = unauthenticated_commands;
const ftp_command_handler *handlers = unauthenticated_handlers; const ftp_command_handler *handlers = unauthenticated_handlers;
@ -597,7 +598,7 @@ static void cleanup_client(client_t *client) {
num_clients--; num_clients--;
if(num_clients == 0) if(num_clients == 0)
ftp_init(); /* reinit for new clients */ ftp_init(); /* reinit for new clients */
gprintf("Client disconnected.\n"); ftp_dbg_print("Client disconnected.\n");
} }
void cleanup_ftp() { void cleanup_ftp() {
@ -617,21 +618,21 @@ static bool process_accept_events(s32 server) {
socklen_t addrlen = sizeof(client_address); socklen_t addrlen = sizeof(client_address);
while ((peer = net_accept(server, (struct sockaddr *)&client_address, &addrlen)) != -EAGAIN) { while ((peer = net_accept(server, (struct sockaddr *)&client_address, &addrlen)) != -EAGAIN) {
if (peer < 0) { if (peer < 0) {
gprintf("Error accepting connection: [%i] %s\n", -peer, strerror(-peer)); ftp_dbg_print(fmt("Error accepting connection: [%i] %s\n", -peer, strerror(-peer)));
return false; return false;
} }
gprintf("Accepted connection from %s!\n", inet_ntoa(client_address.sin_addr)); ftp_dbg_print(fmt("Accepted connection from %s!\n", inet_ntoa(client_address.sin_addr)));
if (num_clients == MAX_CLIENTS) { if (num_clients == MAX_CLIENTS) {
gprintf("Maximum of %u clients reached, not accepting client.\n", MAX_CLIENTS); ftp_dbg_print(fmt("Maximum of %u clients reached, not accepting client.\n", MAX_CLIENTS));
net_close(peer); net_close(peer);
return true; return true;
} }
client_t *client = malloc(sizeof(client_t)); client_t *client = malloc(sizeof(client_t));
if (!client) { if (!client) {
gprintf("Could not allocate memory for client state, not accepting client.\n"); ftp_dbg_print("Could not allocate memory for client state, not accepting client.\n");
net_close(peer); net_close(peer);
return true; return true;
} }
@ -653,7 +654,7 @@ static bool process_accept_events(s32 server) {
int client_index; int client_index;
char *welcome = fmt("Welcome to %s (%s-r%s)! This is the ftpii server core.", APP_NAME, APP_VERSION, SVN_REV); char *welcome = fmt("Welcome to %s (%s-r%s)! This is the ftpii server core.", APP_NAME, APP_VERSION, SVN_REV);
if (write_reply(client, 220, welcome) < 0) { if (write_reply(client, 220, welcome) < 0) {
gprintf("Error writing greeting.\n"); ftp_dbg_print("Error writing greeting.\n");
net_close_blocking(peer); net_close_blocking(peer);
free(client); free(client);
} else { } else {
@ -682,8 +683,10 @@ static void process_data_events(client_t *client) {
} }
} else if(ftp_allow_active == true) { } else if(ftp_allow_active == true) {
if ((result = net_connect(client->data_socket, (struct sockaddr *)&client->address, sizeof(client->address))) < 0) { if ((result = net_connect(client->data_socket, (struct sockaddr *)&client->address, sizeof(client->address))) < 0) {
if (result == -EINPROGRESS || result == -EALREADY) result = -EAGAIN; if(result == -EINPROGRESS || result == -EALREADY)
if (result != -EAGAIN && result != -EISCONN) gprintf("Unable to connect to client: [%i] %s\n", -result, strerror(-result)); result = -EAGAIN;
if(result != -EAGAIN && result != -EISCONN)
ftp_dbg_print(fmt("Unable to connect to client: [%i] %s\n", -result, strerror(-result)));
} }
if (result >= 0 || result == -EISCONN) { if (result >= 0 || result == -EISCONN) {
client->data_connection_connected = true; client->data_connection_connected = true;
@ -691,10 +694,10 @@ static void process_data_events(client_t *client) {
} }
if (client->data_connection_connected) { if (client->data_connection_connected) {
result = 1; result = 1;
gprintf("Connected to client! Transferring data...\n"); ftp_dbg_print("Connected to client! Transferring data...\n");
} else if (gettime() > client->data_connection_timer) { } else if (gettime() > client->data_connection_timer) {
result = -1; result = -1;
gprintf("Timed out waiting for data connection.\n"); ftp_dbg_print("Timed out waiting for data connection.\n");
} }
} else { } else {
result = client->data_callback(client->data_socket, client->data_connection_callback_arg); result = client->data_callback(client->data_socket, client->data_connection_callback_arg);
@ -722,7 +725,7 @@ static void process_control_events(client_t *client) {
char *offset_buf = client->buf + client->offset; char *offset_buf = client->buf + client->offset;
if ((bytes_read = net_read(client->socket, offset_buf, FTP_BUFFER_SIZE - 1 - client->offset)) < 0) { if ((bytes_read = net_read(client->socket, offset_buf, FTP_BUFFER_SIZE - 1 - client->offset)) < 0) {
if (bytes_read != -EAGAIN) { if (bytes_read != -EAGAIN) {
gprintf("Read error %i occurred, closing client.\n", bytes_read); ftp_dbg_print(fmt("Read error %i occurred, closing client.\n", bytes_read));
goto recv_loop_end; goto recv_loop_end;
} }
return; return;
@ -733,7 +736,7 @@ static void process_control_events(client_t *client) {
client->buf[client->offset] = '\0'; client->buf[client->offset] = '\0';
if (strchr(offset_buf, '\0') != (client->buf + client->offset)) { if (strchr(offset_buf, '\0') != (client->buf + client->offset)) {
gprintf("Received a null byte from client, closing connection ;-)\n"); // i have decided this isn't allowed =P ftp_dbg_print("Received a null byte from client, closing connection ;-)\n"); // i have decided this isn't allowed =P
goto recv_loop_end; goto recv_loop_end;
} }
@ -742,7 +745,7 @@ static void process_control_events(client_t *client) {
for (next = client->buf; (end = strstr(next, CRLF)) && !client->data_callback; next = end + CRLF_LENGTH) { for (next = client->buf; (end = strstr(next, CRLF)) && !client->data_callback; next = end + CRLF_LENGTH) {
*end = '\0'; *end = '\0';
if (strchr(next, '\n')) { if (strchr(next, '\n')) {
gprintf("Received a line-feed from client without preceding carriage return, closing connection ;-)\n"); // i have decided this isn't allowed =P ftp_dbg_print("Received a line-feed from client without preceding carriage return, closing connection ;-)\n"); // i have decided this isn't allowed =P
goto recv_loop_end; goto recv_loop_end;
} }
@ -750,7 +753,7 @@ static void process_control_events(client_t *client) {
s32 result; s32 result;
if ((result = process_command(client, next)) < 0) { if ((result = process_command(client, next)) < 0) {
if (result != -EQUIT) { if (result != -EQUIT) {
gprintf("Closing connection due to error while processing command: %s\n", next); ftp_dbg_print(fmt("Closing connection due to error while processing command: %s\n", next));
} }
goto recv_loop_end; goto recv_loop_end;
} }
@ -765,7 +768,7 @@ static void process_control_events(client_t *client) {
memcpy(client->buf, tmp_buf, client->offset); memcpy(client->buf, tmp_buf, client->offset);
} }
} }
gprintf("Received line longer than %u bytes, closing client.\n", FTP_BUFFER_SIZE - 1); ftp_dbg_print(fmt("Received line longer than %u bytes, closing client.\n", FTP_BUFFER_SIZE - 1));
recv_loop_end: recv_loop_end:
cleanup_client(client); cleanup_client(client);