Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

uri.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef _GPXE_URI_H
  2. #define _GPXE_URI_H
  3. /** @file
  4. *
  5. * Uniform Resource Identifiers
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stddef.h>
  10. #include <stdlib.h>
  11. #include <gpxe/refcnt.h>
  12. /** A Uniform Resource Identifier
  13. *
  14. * Terminology for this data structure is as per uri(7), except that
  15. * "path" is defined to include the leading '/' for an absolute path.
  16. *
  17. * Note that all fields within a URI are optional and may be NULL.
  18. *
  19. * Some examples are probably helpful:
  20. *
  21. * http://www.etherboot.org/wiki :
  22. *
  23. * scheme = "http", host = "www.etherboot.org", path = "/wiki"
  24. *
  25. * /var/lib/tftpboot :
  26. *
  27. * path = "/var/lib/tftpboot"
  28. *
  29. * mailto:bob@nowhere.com :
  30. *
  31. * scheme = "mailto", opaque = "bob@nowhere.com"
  32. *
  33. * ftp://joe:secret@insecure.org:8081/hidden/path/to?what=is#this
  34. *
  35. * scheme = "ftp", user = "joe", password = "secret",
  36. * host = "insecure.org", port = "8081", path = "/hidden/path/to",
  37. * query = "what=is", fragment = "this"
  38. */
  39. struct uri {
  40. /** Reference count */
  41. struct refcnt refcnt;
  42. /** Scheme */
  43. const char *scheme;
  44. /** Opaque part */
  45. const char *opaque;
  46. /** User name */
  47. const char *user;
  48. /** Password */
  49. const char *password;
  50. /** Host name */
  51. const char *host;
  52. /** Port number */
  53. const char *port;
  54. /** Path */
  55. const char *path;
  56. /** Query */
  57. const char *query;
  58. /** Fragment */
  59. const char *fragment;
  60. };
  61. /**
  62. * URI is an absolute URI
  63. *
  64. * @v uri URI
  65. * @ret is_absolute URI is absolute
  66. *
  67. * An absolute URI begins with a scheme, e.g. "http:" or "mailto:".
  68. * Note that this is a separate concept from a URI with an absolute
  69. * path.
  70. */
  71. static inline int uri_is_absolute ( struct uri *uri ) {
  72. return ( uri->scheme != NULL );
  73. }
  74. /**
  75. * URI has an absolute path
  76. *
  77. * @v uri URI
  78. * @ret has_absolute_path URI has an absolute path
  79. *
  80. * An absolute path begins with a '/'. Note that this is a separate
  81. * concept from an absolute URI. Note also that a URI may not have a
  82. * path at all.
  83. */
  84. static inline int uri_has_absolute_path ( struct uri *uri ) {
  85. return ( uri->path && ( uri->path[0] == '/' ) );
  86. }
  87. /**
  88. * URI has a relative path
  89. *
  90. * @v uri URI
  91. * @ret has_relative_path URI has a relative path
  92. *
  93. * A relative path begins with something other than a '/'. Note that
  94. * this is a separate concept from a relative URI. Note also that a
  95. * URI may not have a path at all.
  96. */
  97. static inline int uri_has_relative_path ( struct uri *uri ) {
  98. return ( uri->path && ( uri->path[0] != '/' ) );
  99. }
  100. /**
  101. * Increment URI reference count
  102. *
  103. * @v uri URI, or NULL
  104. * @ret uri URI as passed in
  105. */
  106. static inline __attribute__ (( always_inline )) struct uri *
  107. uri_get ( struct uri *uri ) {
  108. ref_get ( &uri->refcnt );
  109. return uri;
  110. }
  111. /**
  112. * Decrement URI reference count
  113. *
  114. * @v uri URI, or NULL
  115. */
  116. static inline __attribute__ (( always_inline )) void
  117. uri_put ( struct uri *uri ) {
  118. ref_put ( &uri->refcnt );
  119. }
  120. extern struct uri *cwuri;
  121. extern struct uri * parse_uri ( const char *uri_string );
  122. extern unsigned int uri_port ( struct uri *uri, unsigned int default_port );
  123. extern int unparse_uri ( char *buf, size_t size, struct uri *uri );
  124. extern struct uri * uri_dup ( struct uri *uri );
  125. extern char * resolve_path ( const char *base_path,
  126. const char *relative_path );
  127. extern struct uri * resolve_uri ( struct uri *base_uri,
  128. struct uri *relative_uri );
  129. extern void churi ( struct uri *uri );
  130. extern size_t uri_encode ( const char *raw_string, char *buf, size_t len );
  131. extern size_t uri_decode ( const char *encoded_string, char *buf, size_t len );
  132. #endif /* _GPXE_URI_H */