espprotocol.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef _ESPPROTOCOL_HPP__
  15. #define _ESPPROTOCOL_HPP__
  16. //Jlib
  17. #include "jliball.hpp"
  18. //SCM Interfaces
  19. #include "esp.hpp"
  20. #include "../../../system/xmllib/xslprocessor.hpp"
  21. //STL
  22. #include <algorithm>
  23. #include <string>
  24. #include <map>
  25. using namespace std;
  26. class ActiveRequests
  27. {
  28. public:
  29. ActiveRequests() { inc(); }
  30. ~ActiveRequests() { dec(); }
  31. void inc();
  32. void dec();
  33. static long getCount();
  34. };
  35. class CEspBindingEntry : public CInterface
  36. {
  37. private:
  38. Owned<ISocket> sock_;
  39. Owned<IEspRpcBinding> binding_;
  40. public:
  41. IMPLEMENT_IINTERFACE;
  42. CEspBindingEntry(ISocket *sock, IEspRpcBinding *binding)
  43. {
  44. sock->Link();
  45. sock_.set(sock);
  46. binding_.set(binding);
  47. }
  48. virtual ~CEspBindingEntry()
  49. {
  50. sock_.clear();
  51. binding_.clear();
  52. }
  53. unsigned getId()
  54. {
  55. if (sock_)
  56. return sock_->OShandle();
  57. return 0;
  58. }
  59. IEspRpcBinding *queryBinding()
  60. {
  61. return binding_.get();
  62. }
  63. };
  64. //MAKEPointerArray(CEspBindingEntry*, CEspBindingArray);
  65. class CEspApplicationPort
  66. {
  67. CEspBindingEntry* bindings[100];
  68. int bindingCount;
  69. int defBinding;
  70. StringBuffer titleBarHtml;
  71. StringBuffer appFrameHtml;
  72. const char *build_ver;
  73. bool viewConfig;
  74. bool rootAuth;
  75. bool navResize;
  76. bool navScroll;
  77. int navWidth;
  78. HINSTANCE hxsl;
  79. Owned<IXslProcessor> xslp;
  80. public:
  81. CEspApplicationPort(bool viewcfg);
  82. ~CEspApplicationPort()
  83. {
  84. while (bindingCount)
  85. bindings[--bindingCount]->Release();
  86. }
  87. const StringBuffer &getAppFrameHtml(time_t &modified, const char *inner_url, StringBuffer &html, IEspContext* ctx);
  88. const StringBuffer &getTitleBarHtml(IEspContext& ctx, bool rawXml);
  89. const StringBuffer &getNavBarContent(IEspContext &context, StringBuffer &content, StringBuffer &contentType, bool xml);
  90. const StringBuffer &getDynNavData(IEspContext &context, IProperties *params, StringBuffer &content,
  91. StringBuffer &contentType, bool& bVolatile);
  92. void buildNavTreeXML(IPropertyTree* navtree, StringBuffer& xmlBuf, bool insideFolder = false);
  93. int onGetNavEvent(IEspContext &context, IHttpMessage* request, IHttpMessage* response);
  94. int onBuildSoapRequest(IEspContext &context, IHttpMessage* request, IHttpMessage* response);
  95. int getBindingCount(){return bindingCount;}
  96. void appendBinding(CEspBindingEntry* entry, bool isdefault);
  97. bool rootAuthRequired(){return rootAuth;}
  98. CEspBindingEntry* queryBindingItem(int item){return (item<bindingCount) ? bindings[item] : NULL;}
  99. CEspBindingEntry* getDefaultBinding(){return bindings[(defBinding>=0) ? defBinding : 0];}
  100. };
  101. typedef map<int, CEspApplicationPort*> CApplicationPortMap;
  102. #define DEFAULT_MAX_REQUEST_ENTITY_LENGTH 8000000
  103. class CEspProtocol : public CInterface,
  104. implements IEspProtocol,
  105. implements ISocketSelectNotify
  106. {
  107. private:
  108. //map between socket port and one or more bindings
  109. CApplicationPortMap m_portmap;
  110. bool m_viewConfig;
  111. int m_MaxRequestEntityLength;
  112. IEspContainer *m_container;
  113. public:
  114. IMPLEMENT_IINTERFACE;
  115. void beforeDispose()
  116. {
  117. }
  118. CEspProtocol();
  119. virtual ~CEspProtocol();
  120. void clear()
  121. {
  122. map<int, CEspApplicationPort*>::iterator bndi = m_portmap.begin();
  123. for(;bndi!=m_portmap.end();bndi++)
  124. if(bndi->second)
  125. delete bndi->second;
  126. m_portmap.clear();
  127. }
  128. void clearBindingMap()
  129. {
  130. clear();
  131. }
  132. void setViewConfig(bool viewConfig){m_viewConfig=viewConfig;}
  133. bool getViewConfig(){return m_viewConfig;}
  134. virtual bool notifySelected(ISocket *sock,unsigned selected);
  135. //IEspProtocol
  136. virtual const char * getProtocolName();
  137. virtual void addBindingMap(ISocket *sock, IEspRpcBinding* binding, bool isdefault);
  138. virtual CEspApplicationPort* queryApplicationPort(int handle);
  139. virtual void setMaxRequestEntityLength(int len) {m_MaxRequestEntityLength = len;};
  140. virtual int getMaxRequestEntityLength() { return m_MaxRequestEntityLength; }
  141. virtual void setContainer(IEspContainer* container) { m_container = container; }
  142. };
  143. #endif