Retrieve files via http
Retrieve files via http
Can someone provide an example of source as to the best way to retrieve files via http (port 80, and http GET) in the same basic operation as wget?
Many thanks,
Michael
Many thanks,
Michael
Re: Retrieve files via http
See this topic http://forums.ps2dev.org/viewtopic.php?t=4216 and my sample program. You have to strip the HTTP-headers and perhaps find a cleaner way for detecting the file end, or you have to wait until mrbrown adds the code to the PSPSDK wlan sample and cleans it up :-)
A full documentation of all the sce* API functions (i.e. parameter lists/usages nstuff) would be nice. Not that I know C or anything.PspPet wrote:FWIW: there is a more elaborate/robust library built into the system that does all of this. However it hasn't been completely reverse engineered (yet/ever?)
If interested, look for the "sceHttp" APIs.
Proud Dvorak User
US 1.5 PSP (Original)
US 1.5 PSP (Original)
It's used in PSPRadio. I've included it in Lua Player, see luawlan.cpp and the WLAN Lua example how to use it (should be no problem to see how the Lua script calls the C functions).planetusa wrote:I hear tale using those same API's, there is a DNS resolve function....anybody know how to use it? Can you post in a function to return the hosts IP address?
I've updated it again, now it works with the latest SVN and the headers from the HTTP result are ignored. Now it is nearly ready for a new sample in the PSPSDK sample folder.
main.c:
Makefile:
main.c:
Code: Select all
#include <string.h>
#include <errno.h>
#include <malloc.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <psputility.h>
#include <pspnet_apctl.h>
#include <pspnet_inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
// TODO: should be moved to PSPSDK
int sceNetResolverCreate(int *rid, void *buf, SceSize buflen);
int sceNetResolverStartNtoA(int rid, const char* hostname, struct in_addr* addr, unsigned int timeout, int retry);
int sceNetResolverStartAtoN(int rid, const struct in_addr* addr, char *hostname, SceSize hostname_len, unsigned int timeout, int retry);
int sceNetResolverStop(int rid);
int sceNetInetInetAton(const char* host, struct in_addr* addr);
static char resolverBuffer[1024];
static int resolverId;
/* Define the module info section */
PSP_MODULE_INFO("WGET", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(32); /* smaller stack for kernel thread */
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
void wget()
{
///////////// PSP specific part ///////////////
// init wlan
int err = pspSdkInetInit();
if (err != 0) {
pspDebugScreenPrintf("pspSdkInetInit failed: %i", err);
return;
}
// print available connections
pspDebugScreenPrintf("available connections:\n");
int i;
for (i = 1; i < 100; i++) // skip the 0th connection
{
if (sceUtilityCheckNetParam(i) != 0) break; // no more
char name[64];
sceUtilityGetNetParam(i, 0, (netData*) name);
pspDebugScreenPrintf("%i: %s\n", i, name);
}
// use connection 1
pspDebugScreenPrintf("using first connection\n");
err = sceNetApctlConnect(1);
if (err != 0) {
pspDebugScreenPrintf("sceNetApctlConnect failed: %i", err);
return;
}
// WLAN is initialized when PSP IP address is available
pspDebugScreenPrintf("init WLAN and getting IP address");
char pspIPAddr[32];
while (1) {
if (sceNetApctlGetInfo(8, pspIPAddr) == 0) break;
pspDebugScreenPrintf(".");
sceKernelDelayThread(1000 * 1000); // wait a second
}
pspDebugScreenPrintf("\nPSP IP address: %s\n", pspIPAddr);
// start DNS resolver
err = sceNetResolverCreate(&resolverId, resolverBuffer, sizeof(resolverBuffer));
if (err != 0) {
pspDebugScreenPrintf("sceNetResolverCreate failed: %i", err);
return;
}
// resolve host
pspDebugScreenPrintf("resolving host...\n");
const char *host = "www.luaplayer.org";
int port = 80;
struct sockaddr_in addrTo;
addrTo.sin_family = AF_INET;
addrTo.sin_port = htons(port);
err = sceNetInetInetAton(host, &addrTo.sin_addr);
if (err == 0) {
err = sceNetResolverStartNtoA(resolverId, host, &addrTo.sin_addr, 2, 3);
if (err != 0) {
pspDebugScreenPrintf("sceNetResolverStartNtoA failed: %i", err);
return;
}
}
///////////// standard socket part ///////////////
// create socket (in blocking mode)
pspDebugScreenPrintf("creating socket...\n");
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
pspDebugScreenPrintf("socket failed, errno: %i", errno);
return;
}
// connect (this may block some time)
pspDebugScreenPrintf("connecting...\n");
err = connect(sock, (struct sockaddr*) &addrTo, sizeof(addrTo));
if (err != 0) {
pspDebugScreenPrintf("connect failed");
return;
}
// send HTTP request
pspDebugScreenPrintf("loading page");
const char* request =
"GET /wlan-pspsdk-test.txt HTTP/1.0\r\n"
"host: www.luaplayer.org\r\n\r\n";
err = send(sock, request, strlen(request), 0);
if (err < 0) {
pspDebugScreenPrintf("send failed, errno: %i", errno);
return;
}
// read all
int capacity = 256;
int len = 0;
u8* buffer = (u8*) malloc(capacity);
while (1) {
pspDebugScreenPrintf(".");
// read data
int count = recv(sock, (u8*) &buffer[len], capacity - len, 0);
// in blocking mode it has to return something, otherwise it is closed
// (which is the default for HTTP/1.0 connections)
if (count == 0) break;
if (count < 0) {
pspDebugScreenPrintf("read error: %i\n", errno);
break;
}
// adjust buffer, if needed
len += count;
if (len + 256 > capacity) {
capacity *= 2;
buffer = realloc(buffer, capacity);
if (!buffer) break;
}
}
// now "len" bytes data are in buffer, add a 0 at end for printing and search for header end
if (buffer) {
buffer[len] = 0;
char* page = strstr((char*) buffer, "\r\n\r\n");
if (page) {
page += 4;
pspDebugScreenPrintf("\n\n%s", page);
}
free(buffer);
}
///////////// PSP specific part ///////////////
// term, TODO: this doesn't work
sceNetApctlDisconnect();
pspSdkInetTerm();
}
int user_main(SceSize argc, void* argv)
{
SetupCallbacks();
// test wlan
wget();
pspDebugScreenPrintf("\ntest finished, wlan should be deactivated now");
// wait until user ends the program
sceKernelSleepThread();
return 0;
}
__attribute__((constructor)) void wlanInit()
{
// TODO: wlan initialization should work in a kernel mode constructor
// pspSdkLoadInetModules();
}
int main(void)
{
pspDebugScreenInit();
int err = pspSdkLoadInetModules();
if (err != 0) {
pspDebugScreenPrintf("pspSdkLoadInetModules failed with %x\n", err);
sceKernelDelayThread(5*1000000); // 5 sec to read error
return 1;
}
// create user thread, tweek stack size here if necessary
SceUID thid = sceKernelCreateThread("User Mode Thread", user_main,
0x11, // default priority
256 * 1024, // stack size (256KB is regular default)
PSP_THREAD_ATTR_USER, NULL);
// start user thread, then wait for it to do everything else
sceKernelStartThread(thid, 0, NULL);
sceKernelWaitThreadEnd(thid, NULL);
sceKernelExitGame();
return 0;
}
Code: Select all
TARGET = wget
OBJS = main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lpspdebug -lpspsdk -lpspwlan -lpspnet_apctl -lpspnet_resolver -lc -lpspnet_inet -lpspnet
# TODO: without -lpspsdk the linker reports many undefined references in pspSdkInetInit
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = wget
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Last edited by Shine on Sun Dec 11, 2005 8:59 am, edited 1 time in total.
Is anyone working on the socket support for the PSPSDK? With the latest changes in the socket files in SVN from today the program I posted doesn't even compile anymore, the linker says:
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libc.a(connect.o): In function `connect':
../../../../../../newlib/libc/sys/psp/socket.c:178: undefined reference to `sceNetInetGetErrno'
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libc.a(recv.o): In function `recv':
../../../../../../newlib/libc/sys/psp/socket.c:268: undefined reference to `sceNetInetRecv'
../../../../../../newlib/libc/sys/psp/socket.c:271: undefined reference to `sceNetInetGetErrno'
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libc.a(send.o): In function `send':
../../../../../../newlib/libc/sys/psp/socket.c:330: undefined reference to `sceNetInetSend'
../../../../../../newlib/libc/sys/psp/socket.c:333: undefined reference to `sceNetInetGetErrno'
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libc.a(socket.o): In function `socket':
../../../../../../newlib/libc/sys/psp/socket.c:43: undefined reference to `sceNetInetClose'
../../../../../../newlib/libc/sys/psp/socket.c:33: undefined reference to `sceNetInetGetErrno'
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libc.a(socket.o): In function `__psp_socket_close':
../../../../../../newlib/libc/sys/psp/socket.c:66: undefined reference to `sceNetInetClose'
../../../../../../newlib/libc/sys/psp/socket.c:70: undefined reference to `sceNetInetGetErrno'
collect2: ld returned 1 exit status
make: *** [wget.elf] Error 1
yes, see above for my LIBS definition. The compiler is called like this:mrbrown wrote:Are you linking with libpspnet_inet.a?
Code: Select all
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local/pspdev/psp/sdk/lib main.o -lpspdebug -lpspsdk -lpspwlan -lpspnet_apctl -lpspnet_resolver -lpspnet_inet -lpspnet -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpsputility -lpspuser -lpspkernel -o wget.elf
thanks, now the LIBS line looks like this and it works:mrbrown wrote:-lpspnet_inet needs to be specified after -lc because the socket code in -lc depends on it.
Code: Select all
LIBS = -lpspdebug -lpspsdk -lpspwlan -lpspnet_apctl -lpspnet_resolver -lc -lpspnet_inet -lpspnet
missing socket.h
Hello,
I installed the latest pspdev using both cygwin (+ pspchain) and devkitPro but I got this error when I try to compile this example :
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o mai
n.c
main.c:10:25: error: netinet/in.h: No such file or directory
main.c:11:25: error: sys/socket.h: No such file or directory
main.c:15: warning: 'struct in_addr' declared inside parameter list
main.c:15: warning: its scope is only this definition or declaration, which is p
robably not what you want
main.c:16: warning: 'struct in_addr' declared inside parameter list
main.c:18: warning: 'struct in_addr' declared inside parameter list
main.c: In function 'wget':
main.c:113: error: storage size of 'addrTo' isn't known
main.c:114: error: 'AF_INET' undeclared (first use in this function)
main.c:114: error: (Each undeclared identifier is reported only once
main.c:114: error: for each function it appears in.)
main.c:115: warning: implicit declaration of function 'htons'
main.c:130: warning: implicit declaration of function 'socket'
main.c:130: error: 'SOCK_STREAM' undeclared (first use in this function)
main.c:138: warning: implicit declaration of function 'connect'
main.c:149: warning: implicit declaration of function 'send'
main.c:163: warning: implicit declaration of function 'recv'
main.c:113: warning: unused variable 'addrTo'
make: *** [main.o] Error 1
I suppose that the problem lies in an incorrect library path when compiling the example (it doesn't found sys/socket.h and other include files)
the only file I found (under cygwin installation that seems the missing ones are under the /home/local/include but when I include those files I got another error).
Thanks in advance for the help.
Francesco.
I installed the latest pspdev using both cygwin (+ pspchain) and devkitPro but I got this error when I try to compile this example :
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o mai
n.c
main.c:10:25: error: netinet/in.h: No such file or directory
main.c:11:25: error: sys/socket.h: No such file or directory
main.c:15: warning: 'struct in_addr' declared inside parameter list
main.c:15: warning: its scope is only this definition or declaration, which is p
robably not what you want
main.c:16: warning: 'struct in_addr' declared inside parameter list
main.c:18: warning: 'struct in_addr' declared inside parameter list
main.c: In function 'wget':
main.c:113: error: storage size of 'addrTo' isn't known
main.c:114: error: 'AF_INET' undeclared (first use in this function)
main.c:114: error: (Each undeclared identifier is reported only once
main.c:114: error: for each function it appears in.)
main.c:115: warning: implicit declaration of function 'htons'
main.c:130: warning: implicit declaration of function 'socket'
main.c:130: error: 'SOCK_STREAM' undeclared (first use in this function)
main.c:138: warning: implicit declaration of function 'connect'
main.c:149: warning: implicit declaration of function 'send'
main.c:163: warning: implicit declaration of function 'recv'
main.c:113: warning: unused variable 'addrTo'
make: *** [main.o] Error 1
I suppose that the problem lies in an incorrect library path when compiling the example (it doesn't found sys/socket.h and other include files)
the only file I found (under cygwin installation that seems the missing ones are under the /home/local/include but when I include those files I got another error).
Thanks in advance for the help.
Francesco.
I have modified Shine's example heavily (sent him a PM), it now supports URI parsing, and both the GET and POST methods, and I will be happy to share the code, as soon as I can get binary files to transfer correctly. Currently, plaintext works flawlessly, if you can help, please see thread
http://forums.ps2dev.org/viewtopic.php? ... highlight=
This code can be used for many many things, the possibilities are endless.
Thanks,
Michael
http://forums.ps2dev.org/viewtopic.php? ... highlight=
This code can be used for many many things, the possibilities are endless.
Thanks,
Michael
Code: Select all
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <malloc.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <psputility.h>
#include <pspnet_apctl.h>
#include <pspnet_inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <util.h>
// TODO: should be moved to PSPSDK
int sceNetResolverCreate(int *rid, void *buf, SceSize buflen);
int sceNetResolverStartNtoA(int rid, const char* hostname, struct in_addr* addr, unsigned int timeout, int retry);
int sceNetResolverStartAtoN(int rid, const struct in_addr* addr, char *hostname, SceSize hostname_len, unsigned int timeout, int retry);
int sceNetResolverStop(int rid);
int sceNetInetInetAton(const char* host, struct in_addr* addr);
#define SOCKET int
#define MAX_URL_LENGTH 750
#define MAX_JPEG 30000
typedef struct {
char uri[256];
char sheme[256];
char host[256];
char abs_path[256];
int port;
char query[256];
} URI;
static char resolverBuffer[1024];
static int resolverId;
/* Define the module info section */
PSP_MODULE_INFO("WGET", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(32); /* smaller stack for kernel thread */
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
unsigned short htons(unsigned short wIn)
{
u8 bHi = (wIn >> 8) & 0xFF;
u8 bLo = wIn & 0xFF;
return ((unsigned short)bLo << 8) | bHi;
}
void ParseURI(URI *uri)
{
/* parsing address
http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
*/
*uri->sheme=0;
*uri->host=0;
strcpy(uri->abs_path,"/");
*uri->query=0;
uri->port=0;
char *start;
char *end;
char portstr[256];
start=uri->uri;
//end=strstr(start,"://");
end=strchr(start,':');
if ( end != NULL) {
char *end1=strstr(end,"//");
if (end1 != NULL) {
if (end < end1 ) {
strncpy(uri->sheme,start,end-start+1);
uri->sheme[end-start+1]=0;
strlwr(uri->sheme);
}
start=end1+2;
}
else {
int num=atoi(end+1);
if ( num <= 0 ) {
strncpy(uri->sheme,start,end-start+1);
uri->sheme[end-start+1]=0;
strlwr(uri->sheme);
start=end+1;
}
}
}
end=uri->uri+strlen(uri->uri);
char *slash=strchr(start,'/');
char *colon=strchr(start,':');
char *qmark=strchr(start,'\?');
if (qmark != NULL ) { // query
strcpy(uri->query,qmark);
end=qmark;
}
if (slash != NULL ) { // abs_path
if (slash < end) {
strncpy(uri->abs_path,slash,end-slash);
uri->abs_path[end-slash]=0;
end=slash;
}
}
if ( colon != NULL && colon < end ) {
strncpy(portstr,colon+1,end-colon-1);
portstr[end-colon-1]=0;
end=colon;
uri->port=atoi(portstr);
}
if (end > start) {
strncpy(uri->host,start,end-start);
uri->host[end-start]=0;
strlwr(uri->host);
}
}
void wget(URI *uri, char* method, char* formdata)
{
///////////// PSP specific part ///////////////
pspDebugScreenPrintf("downloading %s now\n", uri);
// init wlan
int err = pspSdkInetInit();
if (err != 0) {
pspDebugScreenPrintf("pspSdkInetInit failed: %i", err);
return;
}
//init_file("ms0:/custom.html");
// print available connections
//pspDebugScreenPrintf("available connections:\n"); //removed
ParseURI(uri);
int i;
for (i = 1; i < 100; i++) // skip the 0th connection
{
if (sceUtilityCheckNetParam(i) != 0) break; // no more
char name[64];
sceUtilityGetNetParam(i, 0, (netData*) name);
pspDebugScreenPrintf("%i: %s\n", i, name);
}
// use connection 1
//pspDebugScreenPrintf("using first connection\n"); //removed
err = sceNetApctlConnect(1);
if (err != 0) {
pspDebugScreenPrintf("sceNetApctlConnect failed: %i", err);
return;
}
// WLAN is initialized when PSP IP address is available
//pspDebugScreenPrintf("init WLAN and getting IP address"); //removed
char pspIPAddr[32];
while (1) {
if (sceNetApctlGetInfo(8, pspIPAddr) == 0) break;
pspDebugScreenPrintf(".");
sceKernelDelayThread(1000 * 1000); // wait a second
}
//pspDebugScreenPrintf("\nPSP IP address: %s\n", pspIPAddr); //removed
// start DNS resolver
err = sceNetResolverCreate(&resolverId, resolverBuffer, sizeof(resolverBuffer));
if (err != 0) {
pspDebugScreenPrintf("sceNetResolverCreate failed: %i", err);
return;
}
// resolve host
//pspDebugScreenPrintf("resolving host...\n"); //removed
const char *host = uri->host;
int port = 80;
struct sockaddr_in addrTo;
addrTo.sin_family = AF_INET;
addrTo.sin_port = htons(port);
err = sceNetInetInetAton(host, &addrTo.sin_addr);
if (err == 0) {
err = sceNetResolverStartNtoA(resolverId, host, &addrTo.sin_addr, 2, 3);
if (err != 0) {
pspDebugScreenPrintf("sceNetResolverStartNtoA failed: %i", err);
return;
}
}
///////////// standard socket part ///////////////
// create socket (in blocking mode)
//pspDebugScreenPrintf("creating socket...\n"); //removed
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
pspDebugScreenPrintf("socket failed, errno: %i", errno);
return;
}
// connect (this may block some time)
//pspDebugScreenPrintf("connecting...\n"); //removed
err = connect(sock, (struct sockaddr*) &addrTo, sizeof(addrTo));
if (err != 0) {
pspDebugScreenPrintf("connect failed");
return;
}
// send HTTP request
//pspDebugScreenPrintf("loading page"); //removed
//const char* request =
//"GET / HTTP/1.0\r\n"
//"host: www.google.com\r\n\r\n";
const char request[MAX_URL_LENGTH + 1] = { '\0' };
if (method == "GET") {
sprintf(request,
"GET %s HTTP/1.0\r\n"
"host: %s\r\n\r\n",
uri->abs_path, uri->host);
}
if (method == "POST") {
sprintf(request,
"POST %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: PSP\r\nContent-type: application/x-www-form-urlencoded\r\nContent-length: %u\r\n\r\n%s",
uri->abs_path, uri->host, strlen(formdata), formdata);
}
pspDebugScreenPrintf(request); //for testing
err = send(sock, request, strlen(request), 0);
if (err < 0) {
pspDebugScreenPrintf("send failed, errno: %i", errno);
return;
}
int capacity = 256;
int len = 0;
u8* buffer = (u8*) malloc(capacity);
while (1) {
pspDebugScreenPrintf(".");
// read data
int count = recv(sock, (u8*) &buffer[len], capacity - len, 0);
// in blocking mode it has to return something, otherwise it is closed
// (which is the default for HTTP/1.0 connections)
if (count == 0) break;
if (count < 0) {
pspDebugScreenPrintf("read error: %i\n", errno);
break;
}
// adjust buffer, if needed
len += count;
if (len + 256 > capacity) {
capacity *= 2;
buffer = realloc(buffer, capacity);
if (!buffer) break;
}
}
// now "len" bytes data are in buffer, add a 0 at end for printing and search for header end
//pspDebugScreenPrintf(buffer); //used for debugging
if (buffer) {
buffer[len] = 0;
char* page = strstr((char*) buffer, "\r\n\r\n");
if (page) {
page += 4;
//pspDebugScreenPrintf(page); //only for testing output
//parse_html(page);
//write_to_file("ms0:/custom.html", page);
pspDebugScreenPrintf("\n\nPage saved to ms0:/custom.html");
}
free(buffer);
}
///////////// PSP specific part ///////////////
// term, TODO: this doesn't work
sceNetApctlDisconnect();
pspSdkInetTerm();
}
int user_main(SceSize argc, void* argv)
{
SetupCallbacks();
// test wlan
// wget(URL, HTTP METHOD, FORM DATA) POST for POST GET for GET
wget("www.google.com","GET","field1=this&field2=is&field3=nota&field4=test"); // Any plaintext url should work
//pspDebugScreenPrintf("\ntest finished, wlan should be deactivated now"); //removed
// wait until user ends the program
sceKernelSleepThread();
return 0;
}
__attribute__((constructor)) void wlanInit()
{
// TODO: wlan initialization should work in a kernel mode constructor
// pspSdkLoadInetModules();
}
int main(void)
{
pspDebugScreenInit();
int err = pspSdkLoadInetModules();
if (err != 0) {
pspDebugScreenPrintf("pspSdkLoadInetModules failed with %x\n", err);
sceKernelDelayThread(5*1000000); // 5 sec to read error
return 1;
}
// create user thread, tweek stack size here if necessary
SceUID thid = sceKernelCreateThread("User Mode Thread", user_main,
0x11, // default priority
256 * 1024, // stack size (256KB is regular default)
PSP_THREAD_ATTR_USER, NULL);
// start user thread, then wait for it to do everything else
sceKernelStartThread(thid, 0, NULL);
sceKernelWaitThreadEnd(thid, NULL);
sceKernelExitGame();
return 0;
}
Michael
-
- Posts: 81
- Joined: Mon Dec 19, 2005 4:09 pm
Code: Select all
TARGET = wget
OBJS = main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lpspdebug -lpspsdk -lpspwlan -lpspnet_apctl -lpspnet_resolver -lc -lpspnet_inet -lpspnet
#LIBS = -lpspdebug -lpspwlan -lpspsdk -lpspnet_apctl -lpspnet_resolver -lpspnet_inet -lpspnet
# TODO: without -lpspsdk it says: libpspsdk.a(inethelper.o): In function `pspSdkInetInit': inethelper.c:67: undefined reference to `sceNetInit'
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = wget
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Wouldn't it be much nicer to use libcurl ;)
Here, I've just finished porting it.
http://localhost.geek.nz/crap/curl-psp.tar.bz2
Edit: Woops, its actually a .bz2 file *renamed*
Instructions:
Download the latest curl source code (I used 7.15.1).
Apply the patch and build curl: (change ../patch-curl to the location of the patch)
(buildit is a short script to create some empty folders needed and also contains the huge configure line)
now you should have libcurl.a inside curl-7.15.1/lib/.libs/
To use libcurl you will need to link against libpsp_req.a from inside the psp_req folder and libcurl.a
(psp_req is a quick implementation of gethostbyname)
Copy both of these to the example directory and compile it with make.
(You will probally need to change the -I../curl-7.15.1 line in the Makefile)
The included example downloads my website and throws all the html on the screen :)
I haven't tryed to build an ssl library to get https support, but it will likely work, I also haven't got zlib installed so I dont know if that works ;)
Oh, The example seems to hang when you try to quit, not sure why... might be the resolver created in gethostbyname.
Here, I've just finished porting it.
http://localhost.geek.nz/crap/curl-psp.tar.bz2
Edit: Woops, its actually a .bz2 file *renamed*
Instructions:
Download the latest curl source code (I used 7.15.1).
Apply the patch and build curl: (change ../patch-curl to the location of the patch)
Code: Select all
tar -jxf curl-7.15.1.tar.bz2
cd curl-7.15.1
cat ../curl-psp-patch | patch -p1
chmod +x buildit
./buildit
now you should have libcurl.a inside curl-7.15.1/lib/.libs/
To use libcurl you will need to link against libpsp_req.a from inside the psp_req folder and libcurl.a
(psp_req is a quick implementation of gethostbyname)
Copy both of these to the example directory and compile it with make.
(You will probally need to change the -I../curl-7.15.1 line in the Makefile)
The included example downloads my website and throws all the html on the screen :)
I haven't tryed to build an ssl library to get https support, but it will likely work, I also haven't got zlib installed so I dont know if that works ;)
Oh, The example seems to hang when you try to quit, not sure why... might be the resolver created in gethostbyname.
Last edited by danzel on Fri Jan 20, 2006 7:47 am, edited 1 time in total.
-
- Posts: 81
- Joined: Mon Dec 19, 2005 4:09 pm
Did you get binary transfers working with this?danzel wrote:Wouldn't it be much nicer to use libcurl ;)
Here, I've just finished porting it.
http://localhost.geek.nz/crap/curl-psp.tar.gz
Instructions:
Download the latest curl source code (I used 7.15.1).
Apply the patch and build curl: (change ../patch-curl to the location of the patch)(buildit is a short script to create some empty folders needed and also contains the huge configure line)Code: Select all
tar -jxf curl-7.15.1.tar.bz2 cd curl-7.15.1 cat ../curl-psp-patch | patch -p1 chmod +x buildit ./buildit
now you should have libcurl.a inside curl-7.15.1/lib/.libs/
To use libcurl you will need to link against libpsp_req.a from inside the psp_req folder and libcurl.a
(psp_req is a quick implementation of gethostbyname)
Copy both of these to the example directory and compile it with make.
(You will probally need to change the -I../curl-7.15.1 line in the Makefile)
The included example downloads my website and throws all the html on the screen :)
I haven't tryed to build an ssl library to get https support, but it will likely work, I also haven't got zlib installed so I dont know if that works ;)
Oh, The example seems to hang when you try to quit, not sure why... might be the resolver created in gethostbyname.
David Beyer
I see no reason that binary transfers wouldnt work with this, but I haven't tested it. (peldet can do binary transfers fine, so its not a psp issue)
I've uploaded a prebuilt version here: http://localhost.geek.nz/crap/curl_psp_prebuilt.tar.bz2
The example is included, and should build straight off.
Another lib you may want (although it may be a bit big) is libxml2 http://xmlsoft.org
You can build it (atleast version 2.6.22) with the following lines:
It errors out partway through when building the tests, however this is after it successfully builds the library in the .libs dir.
I haven't played with this yet, just tryed to build it to see if it would. This is also probally not the most minimal build, you could definately make it smaller.
There is a libcurl + libxml example here: http://curl.haxx.se/lxr/source/docs/exa ... mltitle.cc
I've uploaded a prebuilt version here: http://localhost.geek.nz/crap/curl_psp_prebuilt.tar.bz2
The example is included, and should build straight off.
Another lib you may want (although it may be a bit big) is libxml2 http://xmlsoft.org
You can build it (atleast version 2.6.22) with the following lines:
Code: Select all
CC=psp-gcc CXX=psp-g++ LIBS="-lpspdebug -lpspdisplay -lpspge -lc -lpspuser -lpspkernel" LDFLAGS="-L/usr/local/pspdev/psp/sdk/lib" ./configure --host=mips --with-minimum --without-threads --without-writer --without-modules
make
I haven't played with this yet, just tryed to build it to see if it would. This is also probally not the most minimal build, you could definately make it smaller.
There is a libcurl + libxml example here: http://curl.haxx.se/lxr/source/docs/exa ... mltitle.cc
<sys/select.h> is part of the pspsdk, make sure you have the latest version and the latest newlib patch, as there has been a few changes in there to do with the networking stuff lately.
copy the .tar.bz2/gz of the newlib/gcc/binutils/gdb source files into the psptoolchain folder before running ./toolchain.sh if you want to save on downloading them again.
Edit: Duh, figured out why the sample wont let you quit, its because of this:
There was no sceKernelExitGame(); in there. Add it and you can quit.
Code: Select all
svn checkout svn://svn.pspdev.org/psp/trunk/psptoolchain
cd psptoolchain
./toolchain.sh
Edit: Duh, figured out why the sample wont let you quit, its because of this:
Code: Select all
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
+++ sceKernelExitGame();
return 0;
}
Updated my toolchain, that fixed it.....now....it downloads binary files, but my old method for writing to the MS causes the PSP to crash....so I'm looking for a new way to store the data it downloads. I've tried a few different things in place of your "spamming the screen", but so far, they either crash the psp, or don't work. Recommendations to save the returned data to a buffer so we can read it into libjpeg, or our parser, or such?
Michael
Michael