You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uri.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef _GPXE_URI_H
  2. #define _GPXE_URI_H
  3. /** @file
  4. *
  5. * Uniform Resource Identifiers
  6. *
  7. */
  8. #include <stdlib.h>
  9. /** A Uniform Resource Identifier
  10. *
  11. * Terminology for this data structure is as per uri(7), except that
  12. * "path" is defined to include the leading '/' for an absolute path.
  13. *
  14. * Note that all fields within a URI are optional and may be NULL.
  15. *
  16. * Some examples are probably helpful:
  17. *
  18. * http://www.etherboot.org/wiki :
  19. *
  20. * scheme = "http", host = "www.etherboot.org", path = "/wiki"
  21. *
  22. * /var/lib/tftpboot :
  23. *
  24. * path = "/var/lib/tftpboot"
  25. *
  26. * mailto:bob@nowhere.com :
  27. *
  28. * scheme = "mailto", opaque = "bob@nowhere.com"
  29. *
  30. * ftp://joe:secret@insecure.org:8081/hidden/path/to?what=is#this
  31. *
  32. * scheme = "ftp", user = "joe", password = "secret",
  33. * host = "insecure.org", port = "8081", path = "/hidden/path/to",
  34. * query = "what=is", fragment = "this"
  35. */
  36. struct uri {
  37. /** Scheme */
  38. const char *scheme;
  39. /** Opaque part */
  40. const char *opaque;
  41. /** User name */
  42. const char *user;
  43. /** Password */
  44. const char *password;
  45. /** Host name */
  46. const char *host;
  47. /** Port number */
  48. const char *port;
  49. /** Path */
  50. const char *path;
  51. /** Query */
  52. const char *query;
  53. /** Fragment */
  54. const char *fragment;
  55. };
  56. /**
  57. * URI is an absolute URI
  58. *
  59. * @v uri URI
  60. * @ret is_absolute URI is absolute
  61. *
  62. * An absolute URI begins with a scheme, e.g. "http:" or "mailto:".
  63. * Note that this is a separate concept from a URI with an absolute
  64. * path.
  65. */
  66. static inline int uri_is_absolute ( struct uri *uri ) {
  67. return ( uri->scheme != NULL );
  68. }
  69. /**
  70. * URI has an absolute path
  71. *
  72. * @v uri URI
  73. * @ret has_absolute_path URI has an absolute path
  74. *
  75. * An absolute path begins with a '/'. Note that this is a separate
  76. * concept from an absolute URI. Note also that a URI may not have a
  77. * path at all.
  78. */
  79. static inline int uri_has_absolute_path ( struct uri *uri ) {
  80. return ( uri->path && ( uri->path[0] == '/' ) );
  81. }
  82. /**
  83. * URI has a relative path
  84. *
  85. * @v uri URI
  86. * @ret has_relative_path URI has a relative path
  87. *
  88. * An relative path begins with something other than a '/'. Note that
  89. * this is a separate concept from a relative URI. Note also that a
  90. * URI may not have a path at all.
  91. */
  92. static inline int uri_has_relative_path ( struct uri *uri ) {
  93. return ( uri->path && ( uri->path[0] != '/' ) );
  94. }
  95. /**
  96. * Free URI structure
  97. *
  98. * @v uri URI
  99. *
  100. * Frees all the dynamically-allocated storage used by the URI
  101. * structure.
  102. */
  103. static inline void free_uri ( struct uri *uri ) {
  104. free ( uri );
  105. }
  106. extern struct uri * parse_uri ( const char *uri_string );
  107. unsigned int uri_port ( struct uri *uri, unsigned int default_port );
  108. #endif /* _GPXE_URI_H */