2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <gpxe/xfer.h>
24 #include <gpxe/socket.h>
25 #include <gpxe/open.h>
29 * Data transfer interface opening
33 /** Registered URI openers */
34 static struct uri_opener uri_openers[0]
35 __table_start ( struct uri_opener, uri_openers );
36 static struct uri_opener uri_openers_end[0]
37 __table_end ( struct uri_opener, uri_openers );
39 /** Registered socket openers */
40 static struct socket_opener socket_openers[0]
41 __table_start ( struct socket_opener, socket_openers );
42 static struct socket_opener socket_openers_end[0]
43 __table_end ( struct socket_opener, socket_openers );
48 * @v xfer Data transfer interface
49 * @v uri_string URI string (e.g. "http://etherboot.org/kernel")
50 * @ret rc Return status code
52 int open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
54 struct uri_opener *opener;
56 DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
58 uri = parse_uri ( uri_string );
62 for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
63 if ( strcmp ( uri->scheme, opener->scheme ) == 0 ) {
64 return opener->open ( xfer, uri );
68 DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
69 "\"%s\"\n", xfer, uri->scheme );
77 * @v xfer Data transfer interface
78 * @v domain Communication domain (e.g. PF_INET)
79 * @v type Communication semantics (e.g. SOCK_STREAM)
81 int open_socket ( struct xfer_interface *xfer,
82 int domain, int type, struct sockaddr *sa ) {
83 struct socket_opener *opener;
85 DBGC ( xfer, "XFER %p opening (%s,%s) socket\n", xfer,
86 socket_domain_name ( domain ), socket_type_name ( type ) );
88 for ( opener = socket_openers; opener < socket_openers_end; opener++ ){
89 if ( ( opener->domain == domain ) &&
90 ( opener->type == type ) ) {
91 return opener->open ( xfer, sa );
95 DBGC ( xfer, "XFER %p attempted to open unsupported socket type "
96 "(%s,%s)\n", xfer, socket_domain_name ( domain ),
97 socket_type_name ( type ) );
104 * @v xfer Data transfer interface
105 * @v type Location type
106 * @v args Remaining arguments depend upon location type
107 * @ret rc Return status code
109 int vopen ( struct xfer_interface *xfer, int type, va_list args ) {
112 const char *uri_string = va_arg ( args, const char * );
114 return open_uri ( xfer, uri_string ); }
115 case LOCATION_SOCKET: {
116 int domain = va_arg ( args, int );
117 int type = va_arg ( args, int );
118 struct sockaddr *sa = va_arg ( args, struct sockaddr * );
120 return open_socket ( xfer, domain, type, sa ); }
122 DBGC ( xfer, "XFER %p attempted to open unsupported location "
123 "type %d\n", xfer, type );
131 * @v xfer Data transfer interface
132 * @v type Location type
133 * @v ... Remaining arguments depend upon location type
134 * @ret rc Return status code
136 int open ( struct xfer_interface *xfer, int type, ... ) {
140 va_start ( args, type );
141 rc = vopen ( xfer, type, args );