Counter Strike : Global Offensive Source Code
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.

103 lines
3.4 KiB

  1. //========= Copyright �, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose: CWAPI header for GC access to the Web API server
  4. //
  5. //=============================================================================
  6. #ifndef GCWEBAPI_H
  7. #define GCWEBAPI_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/memdbgon.h"
  12. enum EWebAPIPrivilege
  13. {
  14. k_EWebApiPriv_Invalid = -1,
  15. k_EWebApiPriv_None = 0, // fully public, no auth needed
  16. k_EWebApiPriv_Key = 1, // Requires valid key
  17. k_EWebApiPriv_PublisherKey = 2, // Requires publisher key
  18. k_EWebApiPriv_PublisherKeyOwnsApp = 3, // Requires publisher key and publisher owns appid
  19. //k_EWebApiPriv_Account = 1, // user must have a Steam account with password set
  20. };
  21. enum EWebApiParamType
  22. {
  23. k_EWebApiParamTypeInvalid = -1,
  24. k_EWebApiParamTypeInt32 = 0,
  25. k_EWebApiParamTypeUInt32 = 1,
  26. k_EWebApiParamTypeInt64 = 2,
  27. k_EWebApiParamTypeUInt64 = 3,
  28. k_EWebApiParamTypeFloat = 4,
  29. k_EWebApiParamTypeString = 5,
  30. k_EWebApiParamTypeBool = 6,
  31. k_EWebApiParamTypeRawBinary = 7,
  32. };
  33. const char *PchNameFromEWebApiParamType( int eWebApiParamType );
  34. typedef KeyValues *(*GCWebAPIInterfaceMapCreationFunc_t)();
  35. class CGCWebAPIInterfaceMapRegistrar
  36. {
  37. public:
  38. CGCWebAPIInterfaceMapRegistrar( GCWebAPIInterfaceMapCreationFunc_t pFunc )
  39. {
  40. VecInstance().AddToTail( pFunc );
  41. }
  42. static CUtlVector< GCWebAPIInterfaceMapCreationFunc_t > & VecInstance();
  43. };
  44. //
  45. // Macros for use registering interfaces in webapi_interfacemap.h
  46. //
  47. #define BEGIN_GCWEB_INTERFACE_BLOCK( pchInterfaceName ) \
  48. KeyValues *CreateWebAPIInterfaceMap_##pchInterfaceName() \
  49. { \
  50. KeyValues *pkvInterface = new KeyValues( #pchInterfaceName );
  51. #define DECLARE_GCWEBAPI_METHOD( pchMethodName, unVersion, eHTTPMethod, pchJobName, ePriv ) \
  52. { \
  53. KeyValues *pkvMethod = pkvInterface->FindKey( pchMethodName #unVersion, true ); \
  54. pkvMethod->SetString( "name", pchMethodName ); \
  55. pkvMethod->SetInt( "version", unVersion ); \
  56. pkvMethod->SetInt( "http_method", eHTTPMethod ); \
  57. pkvMethod->SetString( "job_name", pchJobName); \
  58. pkvMethod->SetInt( "priv", ePriv );
  59. #define REQUIRED_GCWEBAPI_PARAM( pchName, eType, pchDescription ) \
  60. { \
  61. KeyValues *pkvParams = pkvMethod->FindKey( "params", true ); \
  62. AssertMsg( Q_stricmp( pchName, "format" ) != 0, "'format' is a magic reserved API param for specifying output format!" ); \
  63. KeyValues *pkvParam = pkvParams->FindKey( pchName, true ); \
  64. pkvParam->SetString( "description", pchDescription ); \
  65. pkvParam->SetInt( "type", eType ); \
  66. pkvParam->SetInt( "optional", 0 ); \
  67. }
  68. #define OPTIONAL_GCWEBAPI_PARAM( pchName, eType, pchDescription ) \
  69. { \
  70. KeyValues *pkvParams = pkvMethod->FindKey( "params", true ); \
  71. AssertMsg( Q_stricmp( pchName, "format" ) != 0, "'format' is a magic reserved API param for specifying output format!" ); \
  72. KeyValues *pkvParam = pkvParams->FindKey( pchName, true ); \
  73. pkvParam->SetString( "description", pchDescription ); \
  74. pkvParam->SetInt( "type", eType ); \
  75. pkvParam->SetInt( "optional", 1 ); \
  76. }
  77. #define END_GCWEBAPI_METHOD() \
  78. }
  79. #define END_GCWEB_INTERFACE_BLOCK( pchInterfaceName ) \
  80. return pkvInterface; \
  81. } \
  82. CGCWebAPIInterfaceMapRegistrar g_Register_GCWebAPIInterfaceMapCreator_##pchInterfaceName( &CreateWebAPIInterfaceMap_##pchInterfaceName );
  83. #include "tier0/memdbgoff.h"
  84. #endif // GCWEBAPI_H