WiiFlow_Lite/source/network/proxysettings.cpp

76 lines
2.1 KiB
C++
Raw Normal View History

#include <ogcsys.h>
#include <ogc/isfs.h>
#include <string.h>
#include "proxysettings.h"
#include "menu/menu.hpp"
#define ALIGN32(x) (((x) + 31) & ~31)
bool proxy_enabled;
bool proxy_creds_enabled;
char proxy_address[256];
u16 proxy_port;
char proxy_username[33];
char proxy_password[33];
void getProxyInfo()
{
2020-10-17 19:29:03 +02:00
char *buffer;
int fd = ISFS_Open("/shared2/sys/net/02/config.dat", ISFS_OPEN_READ);
if (fd >= 0)
{
fstats stats ATTRIBUTE_ALIGN(32);
if (ISFS_GetFileStats(fd, &stats) >= 0)
{
if (stats.file_length == 7004)
{
buffer = (char *)MEM2_alloc(ALIGN32(stats.file_length));
if (buffer)
{
if (ISFS_Read(fd, buffer, stats.file_length) == 7004)
{
proxy_enabled = buffer[44];
proxy_creds_enabled = buffer[45];
strncpy(proxy_address, buffer + 48, sizeof(proxy_address) - 1);
proxy_port = ((buffer[304] & 0xFF) << 8) | (buffer[305] & 0xFF);
strncpy(proxy_username, buffer + 306, sizeof(proxy_username) - 1);
strncpy(proxy_password, buffer + 338, sizeof(proxy_password) - 1);
}
}
MEM2_free(buffer);
}
}
ISFS_Close(fd);
}
}
2020-09-14 19:23:54 +02:00
char *getProxyAddress()
{
2020-10-17 19:29:03 +02:00
if (mainMenu.proxyUseSystem)
return proxy_enabled ? proxy_address : NULL;
return (strlen(mainMenu.proxyAddress) > 6) ? mainMenu.proxyAddress : NULL;
}
u16 getProxyPort()
{
2020-10-17 19:29:03 +02:00
if (mainMenu.proxyUseSystem)
return proxy_enabled ? proxy_port : 0;
return mainMenu.proxyPort;
}
2020-09-14 19:23:54 +02:00
char *getProxyUsername()
{
2020-10-17 19:29:03 +02:00
if (mainMenu.proxyUseSystem)
return proxy_enabled && proxy_creds_enabled ? proxy_username : NULL;
return (strlen(mainMenu.proxyUsername) > 0) ? mainMenu.proxyUsername : NULL;
}
2020-09-14 19:23:54 +02:00
char *getProxyPassword()
{
2020-10-17 19:29:03 +02:00
if (mainMenu.proxyUseSystem)
return proxy_enabled && proxy_creds_enabled ? proxy_password : NULL;
return (strlen(mainMenu.proxyPassword) > 0) ? mainMenu.proxyPassword : NULL;
}