/src/dynamic-preprocessors/include/sfPolicyUserData.h

https://github.com/andynunes/SSLCertSnorter · C Header · 143 lines · 90 code · 23 blank · 30 comment · 3 complexity · 0b14b2b14ff582d3b673961f08a8ed57 MD5 · raw file

  1. /****************************************************************************
  2. * Copyright (C) 2008-2011 Sourcefire, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License Version 2 as
  6. * published by the Free Software Foundation. You may not use, modify or
  7. * distribute this program under any other version of the GNU General
  8. * Public License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. *
  19. ****************************************************************************/
  20. #ifndef _SF_POLICY_USER_DATA_H_
  21. #define _SF_POLICY_USER_DATA_H_
  22. #include "sf_ip.h"
  23. #include "ipv6_port.h"
  24. #include "sfPolicy.h"
  25. #include "sf_dynamic_preprocessor.h"
  26. typedef struct
  27. {
  28. /**policy id of configuration file or packet being processed.
  29. */
  30. tSfPolicyId currentPolicyId;
  31. /**Number of policies currently allocated.
  32. */
  33. unsigned int numAllocatedPolicies;
  34. /**Number of policies active. Since we use an array of policy pointers,
  35. * number of allocated policies may be more than active policies. */
  36. unsigned int numActivePolicies;
  37. /**user configuration for a policy. This is a pointer to an array of pointers
  38. * to user configuration.
  39. */
  40. void **userConfig;
  41. } tSfPolicyUserContext;
  42. typedef tSfPolicyUserContext * tSfPolicyUserContextId;
  43. tSfPolicyUserContextId sfPolicyConfigCreate(
  44. void
  45. );
  46. void sfPolicyConfigDelete(
  47. tSfPolicyUserContextId pContext
  48. );
  49. //Functions for setting, getting and clearing policy ids
  50. static inline void sfPolicyUserPolicySet (
  51. tSfPolicyUserContextId pContext,
  52. tSfPolicyId policyId
  53. )
  54. {
  55. pContext->currentPolicyId = policyId;
  56. }
  57. static inline tSfPolicyId sfPolicyUserPolicyGet (
  58. tSfPolicyUserContextId pContext
  59. )
  60. {
  61. return pContext->currentPolicyId;
  62. }
  63. static inline unsigned int sfPolicyUserPolicyGetActive (
  64. tSfPolicyUserContextId pContext
  65. )
  66. {
  67. return (pContext->numActivePolicies);
  68. }
  69. //Functions for setting, getting and clearing user data specific to policies.
  70. int sfPolicyUserDataSet (
  71. tSfPolicyUserContextId pContext,
  72. tSfPolicyId policyId,
  73. void *config
  74. );
  75. static inline void * sfPolicyUserDataGet (
  76. tSfPolicyUserContextId pContext,
  77. tSfPolicyId policyId
  78. )
  79. {
  80. if ((pContext != NULL) && (policyId < pContext->numAllocatedPolicies))
  81. {
  82. return pContext->userConfig[policyId];
  83. }
  84. return NULL;
  85. }
  86. static inline int sfPolicyUserDataSetDefault (
  87. tSfPolicyUserContextId pContext,
  88. void *config
  89. )
  90. {
  91. return sfPolicyUserDataSet (pContext, _dpd.getDefaultPolicy(), config);
  92. }
  93. static inline void * sfPolicyUserDataGetDefault (
  94. tSfPolicyUserContextId pContext
  95. )
  96. {
  97. return sfPolicyUserDataGet (pContext, _dpd.getDefaultPolicy());
  98. }
  99. static inline int sfPolicyUserDataSetCurrent (
  100. tSfPolicyUserContextId pContext,
  101. void *config
  102. )
  103. {
  104. return sfPolicyUserDataSet (pContext, pContext->currentPolicyId, config);
  105. }
  106. static inline void * sfPolicyUserDataGetCurrent (
  107. tSfPolicyUserContextId pContext
  108. )
  109. {
  110. return sfPolicyUserDataGet (pContext, pContext->currentPolicyId);
  111. }
  112. void * sfPolicyUserDataClear (
  113. tSfPolicyUserContextId pContext,
  114. tSfPolicyId policyId
  115. );
  116. int sfPolicyUserDataIterate (
  117. tSfPolicyUserContextId pContext,
  118. int (*callback)(tSfPolicyUserContextId pContext, tSfPolicyId policyId, void* config)
  119. );
  120. #endif