uri.h
Go to the documentation of this file.00001 #ifndef _GPXE_URI_H
00002 #define _GPXE_URI_H
00003
00004
00005
00006
00007
00008
00009
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011
00012 #include <stddef.h>
00013 #include <stdlib.h>
00014 #include <gpxe/refcnt.h>
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 struct uri {
00048
00049 struct refcnt refcnt;
00050
00051 const char *scheme;
00052
00053 const char *opaque;
00054
00055 const char *user;
00056
00057 const char *password;
00058
00059 const char *host;
00060
00061 const char *port;
00062
00063 const char *path;
00064
00065 const char *query;
00066
00067 const char *fragment;
00068 } __attribute__ (( packed ));
00069
00070
00071
00072
00073
00074
00075 enum {
00076 URI_SCHEME = 0, URI_SCHEME_BIT = ( 1 << URI_SCHEME ),
00077 URI_OPAQUE = 1, URI_OPAQUE_BIT = ( 1 << URI_OPAQUE ),
00078 URI_USER = 2, URI_USER_BIT = ( 1 << URI_USER ),
00079 URI_PASSWORD = 3, URI_PASSWORD_BIT = ( 1 << URI_PASSWORD ),
00080 URI_HOST = 4, URI_HOST_BIT = ( 1 << URI_HOST ),
00081 URI_PORT = 5, URI_PORT_BIT = ( 1 << URI_PORT ),
00082 URI_PATH = 6, URI_PATH_BIT = ( 1 << URI_PATH ),
00083 URI_QUERY = 7, URI_QUERY_BIT = ( 1 << URI_QUERY ),
00084 URI_FRAGMENT = 8, URI_FRAGMENT_BIT = ( 1 << URI_FRAGMENT ),
00085
00086 URI_FIRST_FIELD = URI_SCHEME,
00087 URI_LAST_FIELD = URI_FRAGMENT,
00088 };
00089
00090
00091 #define uri_get_field( uri, field ) (&uri->scheme)[field]
00092
00093
00094 #define URI_ALL ( URI_SCHEME_BIT | URI_OPAQUE_BIT | URI_USER_BIT | \
00095 URI_PASSWORD_BIT | URI_HOST_BIT | URI_PORT_BIT | \
00096 URI_PATH_BIT | URI_QUERY_BIT | URI_FRAGMENT_BIT )
00097
00098
00099 #define URI_ENCODED ( URI_USER_BIT | URI_PASSWORD_BIT | URI_HOST_BIT | \
00100 URI_PATH_BIT | URI_QUERY_BIT | URI_FRAGMENT_BIT )
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 static inline int uri_is_absolute ( struct uri *uri ) {
00113 return ( uri->scheme != NULL );
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 static inline int uri_has_absolute_path ( struct uri *uri ) {
00127 return ( uri->path && ( uri->path[0] == '/' ) );
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 static inline int uri_has_relative_path ( struct uri *uri ) {
00141 return ( uri->path && ( uri->path[0] != '/' ) );
00142 }
00143
00144
00145
00146
00147
00148
00149
00150 static inline __attribute__ (( always_inline )) struct uri *
00151 uri_get ( struct uri *uri ) {
00152 ref_get ( &uri->refcnt );
00153 return uri;
00154 }
00155
00156
00157
00158
00159
00160
00161 static inline __attribute__ (( always_inline )) void
00162 uri_put ( struct uri *uri ) {
00163 ref_put ( &uri->refcnt );
00164 }
00165
00166 extern struct uri *cwuri;
00167
00168 extern struct uri * parse_uri ( const char *uri_string );
00169 extern unsigned int uri_port ( struct uri *uri, unsigned int default_port );
00170 extern int unparse_uri ( char *buf, size_t size, struct uri *uri,
00171 unsigned int fields );
00172 extern struct uri * uri_dup ( struct uri *uri );
00173 extern char * resolve_path ( const char *base_path,
00174 const char *relative_path );
00175 extern struct uri * resolve_uri ( struct uri *base_uri,
00176 struct uri *relative_uri );
00177 extern void churi ( struct uri *uri );
00178 extern size_t uri_encode ( const char *raw_string, char *buf, ssize_t len,
00179 int field );
00180 extern size_t uri_decode ( const char *encoded_string, char *buf, ssize_t len );
00181
00182 #endif