55 unsigned int count = 0;
63 while ( (
c = *(encoded++) ) ) {
65 snprintf ( hexbuf,
sizeof ( hexbuf ),
"%s", encoded );
66 decoded =
strtoul ( hexbuf, &hexbuf_end, 16 );
67 skip = ( hexbuf_end - hexbuf );
85 char *decoded = encoded;
151 static const char *escaped[
URI_EPATH] = {
176 if ( ( !
isprint (
c ) ) || (
c ==
' ' ) )
184 if ( (
c ==
'%' ) ||
strchr ( escaped[field],
c ) )
215 used =
ssnprintf ( buf, remaining,
"%%%02X",
c );
223 return (
len - remaining );
313 raw = ( ( (
void * )
uri ) +
sizeof ( *uri ) );
325 uri->
params = claim_parameters ( params );
386 authority = ( epath + 2 );
387 if ( (
tmp =
strchr ( authority,
'/' ) ) ) {
390 memmove ( ( authority - 1 ), authority,
391 (
tmp - authority ) );
414 if ( (
tmp =
strchr ( authority,
'@' ) ) ) {
419 if ( (
tmp =
strchr ( authority,
':' ) ) ) {
438 for ( field = 0 ; field <
URI_EPATH ; field++ )
441 DBGC (
uri,
"URI parsed \"%s\" to", uri_string );
491 for ( field = 0 ; field <
URI_FIELDS ; field++ ) {
512 ( buf + used ), (
len - used ) );
517 ":%s", (
uri->
host ?
"//" :
"" ) );
524 DBGC (
uri,
" to \"%s%s\"\n", buf,
525 ( ( used >
len ) ?
"<TRUNCATED>" :
"" ) );
559 size_t len =
sizeof ( *dest );
565 for ( field = 0 ; field <
URI_FIELDS ; field++ ) {
611 DBGC (
uri,
"URI duplicated" );
633 const char *relative_path ) {
639 if ( relative_path[0] ==
'/' )
640 return strdup ( relative_path );
643 base_copy =
strdup ( base_path );
648 base_tmp =
dirname ( base_copy );
651 while ( *relative_path ==
'.' ) {
653 if ( *relative_path == 0 ) {
655 }
else if ( *relative_path ==
'/' ) {
657 }
else if ( *relative_path ==
'.' ) {
659 if ( *relative_path == 0 ) {
660 base_tmp =
dirname ( base_tmp );
661 }
else if ( *relative_path ==
'/' ) {
662 base_tmp =
dirname ( base_tmp );
675 if (
asprintf ( &resolved,
"%s%s%s", base_tmp,
676 ( ( base_tmp[
strlen ( base_tmp ) - 1 ] ==
'/' ) ?
677 "" :
"/" ), relative_path ) < 0 )
695 struct uri *relative_uri ) {
697 char *tmp_epath =
NULL;
698 char *tmp_path =
NULL;
703 return uri_get ( relative_uri );
706 memcpy ( &tmp_uri, base_uri,
sizeof ( tmp_uri ) );
707 if ( relative_uri->
epath ) {
709 base_uri->
epath :
"/" ),
710 relative_uri->
epath );
713 tmp_path =
strdup ( tmp_epath );
717 tmp_uri.
epath = tmp_epath;
718 tmp_uri.
path = tmp_path;
722 }
else if ( relative_uri->
equery ) {
729 }
else if ( relative_uri->
params ) {
734 new_uri =
uri_dup ( &tmp_uri );
754 const char *filename ) {
773 snprintf ( buf,
sizeof ( buf ),
"%d",
812 if ( ! ( filename && filename[0] ) )
826 return tftp_uri ( sa_server, filename );
const char * equery
Query (with original URI encoding)
static __always_inline void off_t int c
static void uri_put(struct uri *uri)
Decrement URI reference count.
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
size_t uri_encode_string(unsigned int field, const char *string, char *buf, ssize_t len)
Encode URI field string.
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
static void uri_dump(const struct uri *uri)
Dump URI for debugging.
static int uri_is_absolute(const struct uri *uri)
URI is an absolute URI.
char * strrchr(const char *src, int character)
Find rightmost character within a string.
char * dirname(char *path)
Return directory name from path.
#define ref_init(refcnt, free)
Initialise a reference counter.
struct uri * pxe_uri(struct sockaddr *sa_server, const char *filename)
Construct URI from server address and filename.
A request parameter list.
static int isalpha(int character)
Check if character is alphabetic.
Uniform Resource Identifiers.
struct parameters * find_parameters(const char *name)
Find request parameter list by name.
int strncmp(const char *first, const char *second, size_t max)
Compare strings.
static size_t uri_copy_fields(const struct uri *src, struct uri *dest)
Copy URI fields.
static int isprint(int character)
Check if character is printable.
const char * port
Port number.
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.
char * strstr(const char *haystack, const char *needle)
Find substring.
const char * scheme
Scheme.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
size_t uri_encode(unsigned int field, const void *raw, size_t raw_len, char *buf, ssize_t len)
Encode URI field.
#define container_of(ptr, type, field)
Get containing structure.
const char * path
Path (after URI decoding)
Transport-network layer interface.
uint16_t count
Number of entries.
size_t format_uri(const struct uri *uri, char *buf, size_t len)
Format URI.
char * strcpy(char *dest, const char *src)
Copy string.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
char * format_uri_alloc(const struct uri *uri)
Format URI.
char * resolve_path(const char *base_path, const char *relative_path)
Resolve base+relative path.
struct parameters * params
Request parameters.
static void uri_decode_inplace(char *encoded)
Decode URI field in-place.
uint16_t st_port
TCP/IP port.
Generalized socket address structure.
static void(* free)(struct refcnt *refcnt))
static int uri_character_escaped(char c, unsigned int field)
Check if character should be escaped within a URI field.
void * zalloc(size_t size)
Allocate cleared memory.
char * strchr(const char *src, int character)
Find character within a string.
int asprintf(char **strp, const char *fmt,...)
Write a formatted string to newly allocated memory.
struct uri * uri_dup(const struct uri *uri)
Duplicate URI.
size_t uri_decode(const char *encoded, void *buf, size_t len)
Decode URI field.
char * strdup(const char *src)
Duplicate string.
size_t strlen(const char *src)
Get length of string.
static struct uri * tftp_uri(struct sockaddr *sa_server, const char *filename)
Construct TFTP URI from server address and filename.
void * malloc(size_t size)
Allocate memory.
const char * host
Host name.
void * memmove(void *dest, const void *src, size_t len) __nonnull
const char * sock_ntoa(struct sockaddr *sa)
Transcribe socket address.
const char * efragment
Fragment (with original URI encoding)
#define uri_field(uri, field)
Access URI field.
const char * opaque
Opaque part.
struct refcnt refcnt
Reference count.
static void uri_free(struct refcnt *refcnt)
Free URI.
unsigned int uri_port(const struct uri *uri, unsigned int default_port)
Get port from URI.
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
const char * password
Password.
const char * epath
Path (with original URI encoding)
const char * user
User name.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
A Uniform Resource Identifier.
struct uri * resolve_uri(const struct uri *base_uri, struct uri *relative_uri)
Resolve base+relative URI.
#define NULL
NULL pointer (VOID *)
struct bofm_section_header done
struct uri * parse_uri(const char *uri_string)
Parse URI.
void * memset(void *dest, int character, size_t len) __nonnull