• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _GPXE_OPEN_H
2 #define _GPXE_OPEN_H
3 
4 /** @file
5  *
6  * Data transfer interface opening
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER );
11 
12 #include <stdarg.h>
13 #include <gpxe/tables.h>
14 #include <gpxe/socket.h>
15 
16 struct xfer_interface;
17 struct uri;
18 
19 /** Location types */
20 enum {
21 	/** Location is a URI
22 	 *
23 	 * Parameter list for open() is:
24 	 *
25 	 * struct uri *uri;
26 	 */
27 	LOCATION_URI = 1,
28 	/** Location is a URI string
29 	 *
30 	 * Parameter list for open() is:
31 	 *
32 	 * const char *uri_string;
33 	 */
34 	LOCATION_URI_STRING,
35 	/** Location is a socket
36 	 *
37 	 * Parameter list for open() is:
38 	 *
39 	 * int semantics;
40 	 * struct sockaddr *peer;
41 	 * struct sockaddr *local;
42 	 */
43 	LOCATION_SOCKET,
44 };
45 
46 /** A URI opener */
47 struct uri_opener {
48 	/** URI protocol name
49 	 *
50 	 * This is the "scheme" portion of the URI, e.g. "http" or
51 	 * "file".
52 	 */
53 	const char *scheme;
54 	/** Open URI
55 	 *
56 	 * @v xfer		Data transfer interface
57 	 * @v uri		URI
58 	 * @ret rc		Return status code
59 	 */
60 	int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
61 };
62 
63 /** URI opener table */
64 #define URI_OPENERS __table ( struct uri_opener, "uri_openers" )
65 
66 /** Register a URI opener */
67 #define __uri_opener __table_entry ( URI_OPENERS, 01 )
68 
69 /** A socket opener */
70 struct socket_opener {
71 	/** Communication semantics (e.g. SOCK_STREAM) */
72 	int semantics;
73 	/** Address family (e.g. AF_INET) */
74 	int family;
75 	/** Open socket
76 	 *
77 	 * @v xfer		Data transfer interface
78 	 * @v peer		Peer socket address
79 	 * @v local		Local socket address, or NULL
80 	 * @ret rc		Return status code
81 	 */
82 	int ( * open ) ( struct xfer_interface *xfer, struct sockaddr *peer,
83 			 struct sockaddr *local );
84 };
85 
86 /** Socket opener table */
87 #define SOCKET_OPENERS __table ( struct socket_opener, "socket_openers" )
88 
89 /** Register a socket opener */
90 #define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
91 
92 extern int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri );
93 extern int xfer_open_uri_string ( struct xfer_interface *xfer,
94 				  const char *uri_string );
95 extern int xfer_open_named_socket ( struct xfer_interface *xfer,
96 				    int semantics, struct sockaddr *peer,
97 				    const char *name, struct sockaddr *local );
98 extern int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
99 			      struct sockaddr *peer, struct sockaddr *local );
100 extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
101 extern int xfer_open ( struct xfer_interface *xfer, int type, ... );
102 extern int xfer_vreopen ( struct xfer_interface *xfer, int type,
103 			  va_list args );
104 
105 #endif /* _GPXE_OPEN_H */
106