esdl_script.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2020 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 ESDL_SCRIPT_HPP_
  14. #define ESDL_SCRIPT_HPP_
  15. #ifdef ESDLLIB_EXPORTS
  16. #define esdl_decl DECL_EXPORT
  17. #else
  18. #define esdl_decl
  19. #endif
  20. #include "jlib.hpp"
  21. #include "jstring.hpp"
  22. #include "jptree.hpp"
  23. #include "jlog.hpp"
  24. #include "esp.hpp"
  25. #include "esdl_def.hpp"
  26. #include <map>
  27. #include <mutex>
  28. #include <thread>
  29. #include <initializer_list>
  30. #include "tokenserialization.hpp"
  31. #include "xpathprocessor.hpp"
  32. #define ESDL_SCRIPT_Error 5700
  33. #define ESDL_SCRIPT_MissingOperationAttr 5710
  34. #define ESDL_SCRIPT_UnknownOperation 5720
  35. interface IEsdlCustomTransform : extends IInterface
  36. {
  37. virtual void processTransform(IEsdlScriptContext * context, const char *srcSection, const char *tgtSection) = 0;
  38. virtual void processTransformImpl(IEsdlScriptContext * scriptContext, const char *srcSection, const char *tgtSection, IXpathContext *xpathContext, const char *target) = 0;
  39. virtual void appendPrefixes(StringArray &prefixes) = 0;
  40. virtual void toDBGLog() = 0;
  41. };
  42. interface IEsdlTransformSet : extends IInterface
  43. {
  44. virtual void processTransformImpl(IEsdlScriptContext * scriptContext, const char *srcSection, const char *tgtSection, IXpathContext *xpathContext, const char *target) = 0;
  45. virtual void appendPrefixes(StringArray &prefixes) = 0;
  46. virtual aindex_t length() = 0;
  47. };
  48. inline bool isEmptyTransformSet(IEsdlTransformSet *set)
  49. {
  50. if (!set)
  51. return true;
  52. return (set->length()==0);
  53. }
  54. #define ESDLScriptEntryPoint_Legacy "CustomRequestTransform"
  55. #define ESDLScriptEntryPoint_BackendRequest "BackendRequest"
  56. #define ESDLScriptEntryPoint_BackendResponse "BackendResponse"
  57. #define ESDLScriptEntryPoint_PreLogging "PreLogging"
  58. interface IEsdlTransformEntryPointMap : extends IInterface
  59. {
  60. virtual IEsdlTransformSet *queryEntryPoint(const char *name) = 0;
  61. virtual void removeEntryPoint(const char *name) = 0;
  62. };
  63. interface IEsdlTransformMethodMap : extends IInterface
  64. {
  65. virtual IEsdlTransformEntryPointMap *queryMethod(const char *method) = 0;
  66. virtual IEsdlTransformSet *queryMethodEntryPoint(const char *method, const char *name) = 0;
  67. virtual void removeMethod(const char *method) = 0;
  68. virtual void addMethodTransforms(const char *method, const char *script, bool &foundNonLegacyTransforms) = 0;
  69. };
  70. esdl_decl IEsdlTransformMethodMap *createEsdlTransformMethodMap();
  71. esdl_decl IEsdlCustomTransform *createEsdlCustomTransform(const char *scriptXml, const char *ns_prefix);
  72. esdl_decl void processServiceAndMethodTransforms(IEsdlScriptContext * scriptCtx, std::initializer_list<IEsdlTransformSet *> const &transforms, const char *srcSection, const char *tgtSection);
  73. esdl_decl void registerEsdlXPathExtensions(IXpathContext *xpathCtx, IEsdlScriptContext *scriptCtx, const StringArray &prefixes);
  74. #endif /* ESDL_SCRIPT_HPP_ */