rendered paste body#include <string.h>
#include <errno.h>
#include <malloc.h>
#include <stdlib.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <psputility.h>
#include <pspnet_apctl.h>
#include <pspnet_inet.h>
#include <pspwlan.h>
#include <pspctrl.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <pspnet_resolver.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <pspnet.h>
#include <pspdebug.h>
#include <psptypes.h>
#include <curl/curl.h>
#define TRUE 1
#define FALSE 0
PSP_MODULE_INFO("EBAS_SAMPLE", 0x1000, 1, 0);
PSP_MAIN_THREAD_ATTR(0);
#define printf pspDebugScreenPrintf
char *HTML;
char *buffer;
int user_main(SceSize argc, void* argv)
{
pspDebugScreenInit();
SceCtrlData pad;
CURL *curl;
CURLcode res;
while (sceWlanGetSwitchState() != 1)
{
pspDebugScreenPrintf("Turn the wifi switch on!\n");
sceKernelDelayThread(1000*1000);
}
// init wlan
int err = pspSdkInetInit();
if (err != 0) {
pspDebugScreenPrintf("pspSdkInetInit failed: %i", err);
return 1;
}
connectWifi:
err = sceNetApctlConnect(1);
if (err != 0)
{
pspDebugScreenPrintf("sceNetApctlConnect returns $%x\n", err);
sceKernelDelayThread(4*1000000); // 4sec to read before exit
return 1;
}
// Report status while waiting for connection to access point
int stateLast = -1;
pspDebugScreenPrintf("Connecting To Wifi...\n");
while (1)
{
sceCtrlPeekBufferPositive(&pad, 1); //READ CONTROLS
if (pad.Buttons & PSP_CTRL_CIRCLE)
return 1;
int state;
err = sceNetApctlGetState(&state);
if (err != 0)
{
pspDebugScreenPrintf("sceNetApctlGetState returns $%x\n", err);
sceKernelDelayThread(10*1000000); // 10sec to read before exit
return 1;
}
if (state != stateLast)
{
if (stateLast == 2 && state == 0)
{
pspDebugScreenPrintf(" Connecting to wifi Failed, Retrying...\n");
sceKernelDelayThread(500*1000); // 500ms
goto connectWifi;
}
pspDebugScreenPrintf(" connection state %d of 4\n", state);
stateLast = state;
}
if (state == 4)
break; // connected
// wait a little before polling again
sceKernelDelayThread(50*1000); // 50ms
}
sceKernelDelayThread(2000 * 2000);
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(!curl) {
printf("ERROR INITIALIZING CURL\n");
sceKernelDelayThread(3000 * 3000);
sceKernelExitGame();
}
curl_easy_setopt(curl, CURLOPT_URL, "http://www.stapol.biaklan.com/txtnews.txt");
curl_easy_setopt(curl, CURLOPT_REFERER, "http://www.google.ca");
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Opera/9.00 (X11; Linux i686; U; en)");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
printf("RetRIEveD HTML CoDE\n");
memcpy(HTML, buffer, sizeof(buffer));
printf("CopYEID BuFFERS\n");
curl_easy_cleanup(curl);
printf("CleANIED UJP CURL\n");
if(strstr(HTML, "STAPOL")) printf("Success\n");
else printf("ERROR\n");
sceKernelDelayThread(5000 * 5000);
return 0;
}
int main(int argc, char *argv[])
{
pspDebugScreenInit();
SceUID thid = sceKernelCreateThread("User Mode Thread", user_main, 8, 256 * 1024, PSP_THREAD_ATTR_USER, NULL);
pspSdkLoadInetModules();
sceKernelStartThread(thid, 0, NULL);
sceKernelWaitThreadEnd(thid, NULL);
sceKernelExitGame();
return 0;
}