david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Add HTTP test support

This commit is contained in:
Michael Brown 2007-01-12 19:19:59 +00:00
parent 497c3a5aad
commit 341c0b9cfb
1 changed files with 22 additions and 3 deletions

View File

@ -30,8 +30,9 @@
#include <usr/fetch.h>
#include <byteswap.h>
#include <gpxe/tftp.h>
#include <gpxe/dhcp.h>
#include <gpxe/tftp.h>
#include <gpxe/http.h>
/**
* Fetch file
@ -53,23 +54,41 @@ int fetch ( const char *filename, userptr_t *data, size_t *len ) {
if ( ( rc = ebuffer_alloc ( &buffer, 0 ) ) != 0 )
return rc;
#warning "Temporary pseudo-URL parsing code"
/* Retrieve the file */
struct tftp_session tftp;
union {
struct sockaddr_tcpip st;
struct sockaddr_in sin;
} server;
struct tftp_session tftp;
struct http_request http;
struct async_operation *aop;
memset ( &tftp, 0, sizeof ( tftp ) );
memset ( &http, 0, sizeof ( http ) );
memset ( &server, 0, sizeof ( server ) );
server.sin.sin_family = AF_INET;
find_global_dhcp_ipv4_option ( DHCP_EB_SIADDR,
&server.sin.sin_addr );
#if 0
server.sin.sin_port = htons ( TFTP_PORT );
udp_connect ( &tftp.udp, &server.st );
tftp.filename = filename;
tftp.buffer = &buffer;
if ( ( rc = async_wait ( tftp_get ( &tftp ) ) ) != 0 ) {
aop = tftp_get ( &tftp );
#else
server.sin.sin_port = htons ( HTTP_PORT );
memcpy ( &http.server, &server, sizeof ( http.server ) );
http.hostname = inet_ntoa ( server.sin.sin_addr );
http.filename = filename;
http.buffer = &buffer;
aop = http_get ( &http );
#endif
if ( ( rc = async_wait ( aop ) ) != 0 ) {
efree ( buffer.addr );
return rc;
}