espcontext.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 _ESPCONTEXT_HPP__
  14. #define _ESPCONTEXT_HPP__
  15. /*#ifndef ESP_BUILTIN
  16. #ifdef _WIN32
  17. #define ESP_CONTEXT_API DECL_EXPORT
  18. #endif
  19. #endif
  20. #ifndef ESP_CONTEXT_API
  21. #define ESP_CONTEXT_API
  22. #endif*/
  23. #include "esp.hpp"
  24. #include "esphttp.hpp"
  25. #define SESSION_SDS_LOCK_TIMEOUT (30*1000) // 30 seconds
  26. #define ESP_SESSION_TIMEOUT (120) // 120 Mins
  27. #define ESP_SESSION_NEVER_TIMEOUT -1
  28. #define ESP_CHECK_SESSION_TIMEOUT (30) // 30 seconds
  29. static const char* const USER_NAME_COOKIE = "ESPUserName";
  30. static const char* const SESSION_ID_COOKIE = "ESPSessionID";
  31. static const char* const SESSION_START_URL_COOKIE = "ESPAuthURL";
  32. static const char* const SESSION_TIMEOUT_COOKIE = "ESPSessionTimeoutSeconds";
  33. static const char* const SESSION_ID_TEMP_COOKIE = "ESPAuthIDTemp";
  34. static const char* const SESSION_AUTH_OK_COOKIE = "ESPAuthenticated";
  35. static const char* const SESSION_AUTH_MSG_COOKIE = "ESPAuthenticationMSG";
  36. static const char* const DEFAULT_LOGIN_URL = "/esp/files/Login.html";
  37. static const char* const DEFAULT_LOGIN_LOGO_URL = "/esp/files/eclwatch/img/Loginlogo.png";
  38. static const char* const DEFAULT_GET_USER_NAME_URL = "/esp/files/GetUserName.html";
  39. static const char* const ECLWATCH_STUB_REQ = "/esp/files/stub.htm";
  40. static const char* const DEFAULT_UNRESTRICTED_RESOURCES = "/favicon.ico,/esp/files/*,/esp/xslt/*";
  41. static const char* const AUTH_STATUS_NA = "NA";
  42. static const char* const AUTH_STATUS_FAIL = "Fail";
  43. static const char* const AUTH_STATUS_OK = "Ok";
  44. static const char* const AUTH_STATUS_NOACCESS = "NoAccess"; //failed for feature level authorization
  45. static const char* const AUTH_TYPE_NONE = "None";
  46. static const char* const AUTH_TYPE_USERNAMEONLY = "UserNameOnly";
  47. static const char* const AUTH_TYPE_PERREQUESTONLY = "PerRequestOnly";
  48. static const char* const AUTH_TYPE_PERSESSIONONLY = "PerSessionOnly";
  49. static const char* const AUTH_TYPE_MIXED = "Mixed";
  50. //xpath in dali
  51. static const char* const PathSessionRoot="Sessions";
  52. static const char* const PathSessionProcess="Process";
  53. static const char* const PathSessionApplication="Application";
  54. static const char* const PathSessionSession="Session_";
  55. static const char* const PropSessionID = "@id";
  56. static const char* const PropSessionExternalID = "@externalid";
  57. static const char* const PropSessionUserID = "@userid";
  58. static const char* const PropSessionNetworkAddress = "@netaddr";
  59. static const char* const PropSessionState = "@state";
  60. static const char* const PropSessionCreateTime = "@createtime";
  61. static const char* const PropSessionLastAccessed = "@lastaccessed";
  62. static const char* const PropSessionTimeoutAt = "@timeoutAt";
  63. static const char* const PropSessionTimeoutByAdmin = "@timeoutByAdmin";
  64. static const char* const PropSessionLoginURL = "@loginurl";
  65. /* The following is an example of session data stored in Dali.
  66. <Sessions>
  67. <Process name="myesp">
  68. <Application port="8010">
  69. <Session_3831947145 createtime="1497376914"
  70. id="3831947145"
  71. lastaccessed="1497377015"
  72. timeoutAt="1497477015"
  73. loginurl="/"
  74. netaddr="10.176.152.200"
  75. userid="user1"/>
  76. <Session_4106750941 createtime="1497377427"
  77. id="4106750941"
  78. lastaccessed="1497377427"
  79. timeoutAt="1497477427"
  80. loginurl="/"
  81. netaddr="10.176.152.200"
  82. userid="user2"/>
  83. </Application>
  84. <Application port="8002">
  85. <Session_3680948651 createtime="1497376989"
  86. id="3680948651"
  87. lastaccessed="1497377003"
  88. timeoutAt="1497477003"
  89. loginurl="/"
  90. netaddr="10.176.152.200"
  91. userid="user1"/>
  92. </Application>
  93. </Process>
  94. </Sessions>
  95. */
  96. interface IEspSecureContext;
  97. esp_http_decl IEspContext* createEspContext(IEspSecureContext* secureContext = NULL);
  98. // Get URL parameters (include these from Content)
  99. // Return: a=b&c=d format.
  100. esp_http_decl bool getUrlParams(IProperties *props, StringBuffer& params);
  101. // Only the original URL (not these from Content: URL form encoded)
  102. // Also remove these params that start with dot (.).
  103. // Return: a=b&c=d format.
  104. esp_http_decl void getEspUrlParams(IEspContext& ctx, StringBuffer& params, const char* excludeParams[]);
  105. esp_http_decl void addEspNativeArray(StringBuffer& schema, const char* xsdType, const char* arrayType);
  106. esp_http_decl void checkRequest(IEspContext& ctx);
  107. esp_http_decl LogRequest readLogRequest(char const* req);
  108. esp_http_decl StringBuffer& getLogRequestString(LogRequest req, StringBuffer& out);
  109. esp_http_decl LogLevel getEspLogLevel(IEspContext* );
  110. esp_http_decl LogLevel getEspLogLevel();
  111. esp_http_decl LogRequest getEspLogRequests();
  112. esp_http_decl bool getEspLogResponses();
  113. esp_http_decl LogLevel getTxSummaryLevel();
  114. esp_http_decl bool getTxSummaryResourceReq();
  115. esp_http_decl unsigned getSlowProcessingTime();
  116. esp_http_decl void ESPLOG(IEspContext* ctx, LogLevel level, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
  117. esp_http_decl void ESPLOG(LogLevel level, const char* fmt, ...) __attribute__((format(printf, 2, 3)));
  118. esp_http_decl void setEspContainer(IEspContainer* container);
  119. esp_http_decl IEspContainer* getESPContainer();
  120. esp_http_decl void setCFD(const char* cfd);
  121. esp_http_decl const char* getCFD();
  122. esp_http_decl void setBuildVersion(const char* buildVersion);
  123. esp_http_decl const char* getBuildVersion();
  124. esp_http_decl void setBuildLevel(const char* buildLevel);
  125. esp_http_decl const char* getBuildLevel();
  126. esp_http_decl IEspServer* queryEspServer();
  127. #endif