iPXE
Functions
open.c File Reference

Data transfer interface opening. More...

#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <ipxe/xfer.h>
#include <ipxe/uri.h>
#include <ipxe/socket.h>
#include <ipxe/open.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
struct uri_openerxfer_uri_opener (const char *scheme)
 Find opener for URI scheme.
int xfer_open_uri (struct interface *intf, struct uri *uri)
 Open URI.
int xfer_open_uri_string (struct interface *intf, const char *uri_string)
 Open URI string.
int xfer_open_socket (struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
 Open socket.
int xfer_vopen (struct interface *intf, int type, va_list args)
 Open location.
int xfer_open (struct interface *intf, int type,...)
 Open location.
int xfer_vreopen (struct interface *intf, int type, va_list args)
 Reopen location.

Detailed Description

Data transfer interface opening.

Definition in file open.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
struct uri_opener* xfer_uri_opener ( const char *  scheme) [read]

Find opener for URI scheme.

Parameters:
schemeURI scheme
Return values:
openerOpener, or NULL

Definition at line 46 of file open.c.

References for_each_table_entry, NULL, uri_opener::scheme, strcmp(), and URI_OPENERS.

Referenced by netboot(), and xfer_open_uri().

                                                           {
        struct uri_opener *opener;

        for_each_table_entry ( opener, URI_OPENERS ) {
                if ( strcmp ( scheme, opener->scheme ) == 0 )
                        return opener;
        }
        return NULL;
}
int xfer_open_uri ( struct interface intf,
struct uri uri 
)

Open URI.

Parameters:
intfData transfer interface
uriURI
Return values:
rcReturn status code

The URI will be regarded as being relative to the current working URI (see churi()).

Definition at line 66 of file open.c.

References cwuri, DBGC, ENOMEM, ENOTSUP, INTF_COL, INTF_DBG, INTF_FMT, uri_opener::open, rc, resolve_uri(), uri::scheme, strerror(), uri_put(), and xfer_uri_opener().

Referenced by create_downloader(), efi_pxe_tftp_open(), pxe_tftp_open(), sanpath_open(), xfer_open_uri_string(), and xfer_vopen().

                                                              {
        struct uri_opener *opener;
        struct uri *resolved_uri;
        int rc;

        /* Resolve URI */
        resolved_uri = resolve_uri ( cwuri, uri );
        if ( ! resolved_uri ) {
                rc = -ENOMEM;
                goto err_resolve_uri;
        }

        /* Find opener which supports this URI scheme */
        opener = xfer_uri_opener ( resolved_uri->scheme );
        if ( ! opener ) {
                DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
                       "unsupported URI scheme \"%s\"\n",
                       INTF_DBG ( intf ), resolved_uri->scheme );
                rc = -ENOTSUP;
                goto err_opener;
        }

        /* Call opener */
        DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening %s URI\n",
               INTF_DBG ( intf ), resolved_uri->scheme );
        if ( ( rc = opener->open ( intf, resolved_uri ) ) != 0 ) {
                DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " could not open: "
                       "%s\n", INTF_DBG ( intf ), strerror ( rc ) );
                goto err_open;
        }

 err_open:
 err_opener:
        uri_put ( resolved_uri );
 err_resolve_uri:
        return rc;
}
int xfer_open_uri_string ( struct interface intf,
const char *  uri_string 
)

Open URI string.

Parameters:
intfData transfer interface
uri_stringURI string (e.g. "http://ipxe.org/kernel")
Return values:
rcReturn status code

The URI will be regarded as being relative to the current working URI (see churi()).

Definition at line 114 of file open.c.

References DBGC, ENOMEM, INTF_COL, INTF_DBG, INTF_FMT, parse_uri(), rc, uri_put(), and xfer_open_uri().

Referenced by open(), validator_start_download(), validator_start_ocsp(), and xfer_vopen().

                                                    {
        struct uri *uri;
        int rc;

        DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening URI %s\n",
               INTF_DBG ( intf ), uri_string );

        uri = parse_uri ( uri_string );
        if ( ! uri )
                return -ENOMEM;

        rc = xfer_open_uri ( intf, uri );

        uri_put ( uri );
        return rc;
}
int xfer_open_socket ( struct interface intf,
int  semantics,
struct sockaddr peer,
struct sockaddr local 
)

Open socket.

Parameters:
intfData transfer interface
semanticsCommunication semantics (e.g. SOCK_STREAM)
peerPeer socket address
localLocal socket address, or NULL
Return values:
rcReturn status code

Definition at line 141 of file open.c.

References DBGC, ENOTSUP, socket_opener::family, for_each_table_entry, INTF_COL, INTF_DBG, INTF_FMT, socket_opener::open, sockaddr::sa_family, socket_opener::semantics, socket_family_name(), SOCKET_OPENERS, and socket_semantics_name().

Referenced by apply_syslog_settings(), dns_resolv(), ftp_reply(), peerdisc_socket_open(), slam_open(), start_dhcp(), start_dhcpv6(), start_pxebs(), tftp_reopen_mc(), and xfer_vopen().

                                                                       {
        struct socket_opener *opener;

        DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening (%s,%s) socket\n",
               INTF_DBG ( intf ), socket_semantics_name ( semantics ),
               socket_family_name ( peer->sa_family ) );

        for_each_table_entry ( opener, SOCKET_OPENERS ) {
                if ( ( opener->semantics == semantics ) &&
                     ( opener->family == peer->sa_family ) ) {
                        return opener->open ( intf, peer, local );
                }
        }

        DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
               "unsupported socket type (%s,%s)\n",
               INTF_DBG ( intf ), socket_semantics_name ( semantics ),
               socket_family_name ( peer->sa_family ) );
        return -ENOTSUP;
}
int xfer_vopen ( struct interface intf,
int  type,
va_list  args 
)

Open location.

Parameters:
intfData transfer interface
typeLocation type
argsRemaining arguments depend upon location type
Return values:
rcReturn status code

Definition at line 171 of file open.c.

References DBGC, ENOTSUP, INTF_COL, INTF_DBG, INTF_FMT, LOCATION_SOCKET, LOCATION_URI, LOCATION_URI_STRING, va_arg, xfer_open_socket(), xfer_open_uri(), and xfer_open_uri_string().

Referenced by xfer_open(), and xfer_vreopen().

                                                                  {
        switch ( type ) {
        case LOCATION_URI_STRING: {
                const char *uri_string = va_arg ( args, const char * );

                return xfer_open_uri_string ( intf, uri_string ); }
        case LOCATION_URI: {
                struct uri *uri = va_arg ( args, struct uri * );

                return xfer_open_uri ( intf, uri ); }
        case LOCATION_SOCKET: {
                int semantics = va_arg ( args, int );
                struct sockaddr *peer = va_arg ( args, struct sockaddr * );
                struct sockaddr *local = va_arg ( args, struct sockaddr * );

                return xfer_open_socket ( intf, semantics, peer, local ); }
        default:
                DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to "
                       "open unsupported location type %d\n",
                       INTF_DBG ( intf ), type );
                return -ENOTSUP;
        }
}
int xfer_open ( struct interface intf,
int  type,
  ... 
)

Open location.

Parameters:
intfData transfer interface
typeLocation type
...Remaining arguments depend upon location type
Return values:
rcReturn status code

Definition at line 203 of file open.c.

References rc, va_end, va_start, and xfer_vopen().

Referenced by efi_download_start().

                                                        {
        va_list args;
        int rc;

        va_start ( args, type );
        rc = xfer_vopen ( intf, type, args );
        va_end ( args );
        return rc;
}
int xfer_vreopen ( struct interface intf,
int  type,
va_list  args 
)

Reopen location.

Parameters:
intfData transfer interface
typeLocation type
argsRemaining arguments depend upon location type
Return values:
rcReturn status code

This will close the existing connection and open a new connection using xfer_vopen(). It is intended to be used as a .vredirect method handler.

Definition at line 225 of file open.c.

References intf_restart(), and xfer_vopen().

Referenced by downloader_vredirect(), iscsi_vredirect(), and xfer_vredirect().

                                                                    {

        /* Close existing connection */
        intf_restart ( intf, 0 );

        /* Open new location */
        return xfer_vopen ( intf, type, args );
}