uri.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef __JURI__
  14. #define __JURI__
  15. #include <uriparser/Uri.h>
  16. #include "jlib.hpp"
  17. // MORE - This is just a stub, structs below need to be commoned up with existing definitions elsewhere
  18. // Supported URI schemes
  19. enum URISchemeType
  20. {
  21. URIScheme_error,
  22. URIScheme_hpcc,
  23. URIScheme_file
  24. };
  25. // Supported server types
  26. enum URIServerType
  27. {
  28. URIServer_local, // Local file
  29. URIServer_dali, // Names resolved by Dali
  30. URIServer_host // Names resolved by DNS
  31. };
  32. // Supported file types
  33. enum URIFileType
  34. {
  35. URIFile_local, // Local files
  36. URIFile_logic, // Normal files
  37. URIFile_super, // Super files
  38. URIFile_stream // Stream files (to be implemented)
  39. };
  40. struct URIServerDescription
  41. {
  42. StringAttr user;
  43. StringAttr host;
  44. unsigned port;
  45. };
  46. struct URIPathDescription
  47. {
  48. StringAttr path;
  49. URIFileType type;
  50. StringAttr subname; // Super files' sub
  51. unsigned index; // Stream files
  52. };
  53. // ==================================================================================
  54. /*
  55. * URIFileResolver is the interface that any resolver should implement to be used
  56. * by the URIResolution scheme, to provide a seamless interface to any HPCC engine
  57. * to handle files in a plethora of environments.
  58. *
  59. * This has not be thought about properly and does not concern
  60. * much of the initial URI investigations.
  61. */
  62. //interface URIFileResolver
  63. //{
  64. // // Returns a Read-only descriptor of a file. No Dali locks.
  65. // virtual IFileDescriptor *getFileDescriptor(StringAttr &filePath) = 0;
  66. // // Returns a distributed dali / local file
  67. // virtual IResolvedFile *getFile(StringAttr &filePath) = 0;
  68. // // Returns a distributed dali / local file form a pre-existing descriptor
  69. // virtual IResolvedFile *getFile(IFileDescriptor &fileDesc) = 0;
  70. // // Releases any lock and re-reads the information
  71. // virtual IFileDescriptor *releaseFile(IResolvedFile &file) = 0;
  72. //};
  73. // ==================================================================================
  74. /*
  75. * URI deals with strings referring to paths that can be resolved in
  76. * many different ways. This object is immutable.
  77. *
  78. * Dali files (logic, super, stream), local files (on disk),
  79. * Web files (http, ftp, webdav) have different ways of resolving, and all of them
  80. * should have a consistent query mechanism from the HPCC engines point of view.
  81. *
  82. * The URI parser used is uriparser, from http://uriparser.sourceforge.net/
  83. */
  84. class URI
  85. {
  86. URISchemeType scheme;
  87. URIServerDescription server;
  88. URIPathDescription path;
  89. UriParserStateA state;
  90. UriUriA uri;
  91. void populateFields();
  92. public:
  93. URI(const char* path);
  94. // Helper, to validate URI before creating object
  95. static bool isURI(const char *path);
  96. // Immutable
  97. URISchemeType getScheme() const
  98. {
  99. return scheme;
  100. }
  101. // Immutable
  102. const URIServerDescription * const getServer() const
  103. {
  104. return &server;
  105. }
  106. // Immutable
  107. const URIPathDescription * const getPath() const
  108. {
  109. return &path;
  110. }
  111. // MORE - is this the best way?
  112. void appendSchemeStr(StringBuffer& buf);
  113. void appendServerStr(StringBuffer& buf);
  114. void appendPathStr(StringBuffer& buf);
  115. };
  116. #endif /* __JURI__ */