downloading a file through http

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

downloading a file through http

Post by JorDy »

Ive been trying to download a file from a server thought ftp, had no luck and want to try and download it via http. Ive seen in the mysp2 source a function that does this but i cant compile the ps2sdk changes without compilation errors and the programme wont compile otherwise. Ive seen the iop irx ps2http.irx but have found no headers or any code that uses this.

Is there any other example code on how to download a file from a server?
fr0st m0nkey
Posts: 10
Joined: Sun Jan 30, 2005 4:52 pm
Contact:

Post by fr0st m0nkey »

Bump!
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

This is a standard part of ps2sdk. There is no header because it just looks like standard file io from the viewpoint of the EE. You can look at the code for an idea of what it is doing:

http://svn.ps2dev.org/filedetails.php?r ... rev=0&sc=0
/*

The HTTP file io driver is a read only driver that slots into the PS2
IO subsystem and provides access to HTTP.

For each open request a file handle is allocated and any read request
is directed to the socket. After close has been called the file
handle slot is free'd for the next request.

No header information normally returned from a HTTP request is returned.
The client must know the content of the data stream and how to deal with it.

lseek is currently only supported in order to get the size of a file. With
the current implimentation, it is not possible to seek to different positions
in a file.

With the current implimentation, hostnames may only be specified as an IP
address. This will change once we get a DNS resolver up & running with lwip.
*/
Looks like you can just load ps2http.irx, then open the file using a url instead of a path. You'll need an already running network so you should look into adding ps2eth/ps2smap as well if you're not going to run under ps2link.
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

okay thanks il look into getting it working
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

i seem to be having trouble with this, when i load my irx either builtin or from the host im getting an ID of -200 and a ret of 0 which isn't right for a start.

Does ps2http.irx need any arguments?

and on a side note if i get this workin i should be able to open the file through a simple fioOpen() correct?
ubergeek42
Posts: 83
Joined: Wed Jul 13, 2005 12:25 am

Post by ubergeek42 »

The IRX source code has no indication of anything dealing with arguments passed to it, so I don't know what the error might be.

It also appears that you just use the normal io functions to access it.

Why not just code up a "simple" function to download a file; there is a great example in the myps2 source code.
http://svn.ps2dev.org/filedetails.php?r ... rev=0&sc=0

You don't need to be able to compile myPS2, just base your own downloading function off of the one in myps2(or just copy that one). I had one for a while, but I can't find the source code for it anymore. I remember running into a few issues though, mainly when using sprintf() with HTTP/1.1 in the string, always caused it to crash, but any variations worked fine, like HTTP_1.1 etc. I guess there are some issues with sprintf?(Then again that was a long time ago, and I havn't messed with anything like that in a long while. I also had the problem with servers not returning the Content-Length header, so I gave up.
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

ive tried to compile that already and it just would not have any of it, constantly complaining that the socket, send, recv functions were not defined when they clearly were and all libraries were included
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

this is what i've got (taken from myps2)

Code: Select all

edited
and there is a main file that only loads the modules at the minute.
The problem with the above code is that upon compiling it says
net.c><38>column 17 : dns.h No such file. Which there is in the IOP include directory, now that i think of it its in the iop directory which is probably the problem but does that not mean it must be compiled as an IRX? I'm really confused on this and i need to get this working asap
Last edited by JorDy on Sat May 26, 2007 10:03 am, edited 1 time in total.
dlanor
Posts: 258
Joined: Thu Oct 28, 2004 6:28 pm
Location: Stockholm, Sweden

Post by dlanor »

JorDy wrote:this is what i've got (taken from myps2)
----- snip ----- re: I've cut away major parts of that source listing here
The part I've kept below differs significantly from the sources I have.

Your "net.c" included the following header:

Code: Select all

#include <tamtypes.h>
#include <string.h>
#include <stdio.h>
#include <ps2ip.h>

#include <net.h>
#include <loadfile.h>
#include "dns.h"

// ReadBufLine - Reads a line from a buffer. Newline character is
After that your code proceeds directly with the function definition of the ReadBufLine function.

My own copies of the myPS2 sources, both as downloaded in march 2006, and as updated from SVN very recently (may 2007) are very different from the above, including instead the following header, taken from the most recently updated version, starting from the same point below the copyright notice (which was identical, even as to the dates) as in the code quoted above.

Code: Select all

include <tamtypes.h>
#include <sysconf.h>	// ReadBufLine
#include <string.h>
#include <stdio.h>
#include <ps2ip.h>
#include <net.h>
#include <misc.h>
#include <loadfile.h>

//
// HttpDownload -  Attempts to download a file off an HTTP server.
After that my sources proceed directly with the function definition of the HttpDownload function.

Note the total absence of any reference to the dns.h file you had problems with...
Note also that in your own source that file name is surrounded by double quotes instead of angle brackets, which means that this header should have been present in your local project folder, not in any part of PS2SDK.

The function ReadBufLine is neither declared nor defined in my net.c, but is declared in sysconf.h and defined in sysconf.c, which is another major difference from your source.

and there is a main file that only loads the modules at the minute.
The problem with the above code is that upon compiling it says
net.c><38>column 17 : dns.h No such file. Which there is in the IOP include directory, now that i think of it its in the iop directory which is probably the problem but does that not mean it must be compiled as an IRX?
No. myPS2 must be an ELF.

I believe you have an outdated source, possibly partially updated with newer files that don't quite fit together with the old stuff.

I suggest you get the latest source updates from the SVN repository and work from those sources instead.

Best regards: dlanor
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

okay thanks! i took the ReadBufLine out of the sysconf.c file as net.c needed it but didnt need anything else from sysconf.c so i took the function straight out of that file and pasted it at the top with no changes and this function would compile on its own as it doesn't depend on anything else.

Right well ive got it compiling now, but if i am running this from ps2link what modules will i need to load since it already has some of the network modules loaded?
ubergeek42
Posts: 83
Joined: Wed Jul 13, 2005 12:25 am

Post by ubergeek42 »

I had made an IRC client a while back, it uses sockets and all that fun stuff. As for modules I can't remember off the top of my head, check in loadmodules.c in the source archive, I think its pretty easy to figure out exactly which modules you need:
http://www.sksapps.com/ubergeek42/ps2-i ... 8.5ish.zip
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

Thankyou! but as usual a problem...

this time my code hangs when its loading the DNS module adn ive basicly used the IRC code :s

Code: Select all

SifInitRpc&#40;0&#41;;

	init_scr&#40;&#41;;

	printf&#40;"Hello world\n"&#41;;
	int ret;
	_binary_dns_irx_size = _binary_dns_irx_end - _binary_dns_irx_start;
	_binary_ps2ips_irx_size = _binary_ps2ips_irx_end - _binary_ps2ips_irx_start;

	char dnsaddr&#91;15&#93;="208.67.222.222";// dns ip of OpenDNS server.
	// DNS IRX Module
	scr_printf&#40;"\tLoading Module DNS.IRX...."&#41;;
	SifExecModuleBuffer&#40; &_binary_dns_irx_start, _binary_dns_irx_size, 15, dnsaddr, &ret&#41;;
	if&#40;ret<0&#41;
		scr_printf&#40;"\tFailed!\n"&#41;;
		SleepThread&#40;&#41;;
	else
		scr_printf&#40;"\tOK!\n"&#41;;

	// PS2IPS IRX Module
	scr_printf&#40;"\tLoading Module PS2IPS...."&#41;;
	SifExecModuleBuffer&#40; &_binary_ps2ips_irx_start, _binary_ps2ips_irx_size, 0, NULL, &ret&#41;;
	if&#40;ret<0&#41;
		scr_printf&#40;"\tFailed!\n"&#41;;
		SleepThread&#40;&#41;;
	else
		scr_printf&#40;"\tOK!\n"&#41;;
		
	if&#40;ps2ip_init&#40;&#41; < 0&#41;&#123;
		scr_printf&#40;"\tFailed to call ps2ip_init&#40;&#41;\n"&#41;;
		SleepThread&#40;&#41;;
	&#125;

	while&#40;1&#41;;
	return 0;
On screen it stops at "Loading Module DNS.IRX...."
ubergeek42
Posts: 83
Joined: Wed Jul 13, 2005 12:25 am

Post by ubergeek42 »

I recall needing the changes to the ps2sdk that are in the myps2 source code. But as you said, those don't compile with the latest ps2sdk. Maybe checkout and older version of ps2sdk, and see if you can't get it working. Try one from around august of last year, then apply the changes, and go from there.

Sorry I can't be of more help, just reformatted my computer, and I'm have some kernel troubles in linux. Once I get that all sorted out I'll be back into ps2dev stuff, and will hopefully be able to provide some assistance.
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

if it was an SDK error then i wouldnt of been able to compile it, but i can it just hangs when loading the modules unless the modules need recompiled
ubergeek42
Posts: 83
Joined: Wed Jul 13, 2005 12:25 am

Post by ubergeek42 »

Ok, got some free time and put together a http file downloader thingy.
Source and binary here:
http://sksapps.com/ubergeek42/http_test.tar.gz

To get that to compile, you have to rebuild your ps2sdk. Download the newest version from subversion, and then apply the patched files from ps2ware/trunk/myPS2/ps2sdk/ps2sdksrc to the new ps2sdk. But this won't compile just yet. Edit the file ee/libc/src/unistd.c and change the #include <sys/stat.h> to #include <sys/ansistat.h>
Now compile, and install.

Once that is done you should be able to comple the program, it is commented in some places, if you have trouble understanding any of it just ask.

It will only run from ps2link(contrary to what the makefile says about running by itself), I don't know what the error was, and I'm a tad too lazy right now to figure it out. It uses the openDNS servers for name resolution, which only seem to work some of the time, so if you get it compiling, I suggest changing it to the DNS server your isp provided.

The sample program just connects to google.com and downloads their main page to a file on host:/

Hope this is useful.
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

thanks a load!! i think il start updating my sdk tomorrow it hasnt been done it a while
Post Reply