p≡p engine
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.

210 lines
6.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. // This file is under GNU General Public License 3.0
  2. // see LICENSE.txt
  3. // generate conditions and actions
  4. // Copyleft (c) 2017, 2018, p≡p foundation
  5. // Written by Volker Birk
  6. include yslt.yml2
  7. decl _func *name (*type) alias - {
  8. template %name=*name, %type=*type, "%type[@name='%name']"
  9. call *type with "content" content;
  10. };
  11. decl condition is _func (*type="condition");
  12. decl action is _func (*type="action");
  13. decl timeout is _func (*type="fsm");
  14. tstylesheet {
  15. include standardlib.ysl2
  16. include ./functions.ysl2
  17. include ./cond_act_*.yml2
  18. template "/protocol" {
  19. document "generated/{@name}_actions.c", "text" {
  20. ||
  21. /**
  22. * @file «@name»_actions.c
  23. * @brief Implementation of «@name» conditions, actions, and timeout handlers defined in «@name»_impl.h,
  24. * with supporting static (internal) functions
  25. * @generated from ../sync/gen_actions.ysl2
  26. *
  27. * @license GNU General Public License 3.0 - see LICENSE.txt
  28. */
  29. #include "pEp_internal.h"
  30. #include "map_asn1.h"
  31. #include "«@name»_impl.h"
  32. `` for "fsm" | #include "«@name»_fsm.h"
  33. /**
  34. * <!-- _TID_greater() -->
  35. *
  36. * @internal
  37. *
  38. * @brief Compare two traffic identifiers and see if the first is greater than the second
  39. *
  40. * @param[in] t1 pointer to the first TID
  41. * @param[in] t2 pointer to the second TID
  42. *
  43. * @retval true if t2 is NULL and t1 is not, or the size of t1 is greater than t2, or
  44. * the first non-matching byte of t1 is greater than that of t2
  45. * false otherwise
  46. */
  47. static bool _TID_greater(TID_t *t1, TID_t *t2)
  48. {
  49. assert(t1 && t2);
  50. if (t1 && !t2)
  51. return true;
  52. if (!t1)
  53. return false;
  54. if (t1->size > t2->size)
  55. return true;
  56. if (t2->size > t1->size)
  57. return false;
  58. return memcmp(t1->buf, t2->buf, t1->size) > 0;
  59. }
  60. /**
  61. * <!-- _same_identity() -->
  62. *
  63. * @internal
  64. *
  65. * @brief Determine if two identity refer to the same identity (by comparing the unique identifier
  66. * of user_id + address)
  67. *
  68. * @param[in] ident1 pointer to the first identity
  69. * @param[in] ident2 pointer to the second identity
  70. *
  71. * @retval true if user_id and address match on both identities
  72. * false otherwise
  73. */
  74. static bool _same_identity(pEp_identity *ident1, pEp_identity *ident2)
  75. {
  76. if (!(ident1 && ident1->user_id && ident1->address && ident2 && ident2->user_id && ident2->address))
  77. return false;
  78. return strcmp(ident1->user_id, ident2->user_id) == 0
  79. && strcmp(ident1->address, ident2->address) == 0;
  80. }
  81. /**
  82. * <!-- _have_identity_in() -->
  83. *
  84. * @internal
  85. *
  86. * @brief Given an identity list and an identity, determine if there is an identity in
  87. * the list that refers to the same identity as the identity struct.
  88. *
  89. * @param[in] il pointer to the identity list
  90. * @param[in] ident pointer to the identity to search for
  91. * @param[out] found true if an identity with matching unique identifiers is in the list, else false
  92. *
  93. * @retval PEP_ILLEGAL_VALUE any of the input pointers are NULL
  94. * PEP_OUT_OF_MEMORY if memory problems occur
  95. * PEP_STATUS_OK otherwise
  96. */
  97. static PEP_STATUS _have_identity_in(identity_list *il, pEp_identity *ident, bool *found)
  98. {
  99. assert(il && ident && found);
  100. if (!(il && ident && found))
  101. return PEP_ILLEGAL_VALUE;
  102. bool _found = false;
  103. for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
  104. if (_same_identity(_il->ident, ident)) {
  105. _found = true;
  106. break;
  107. }
  108. }
  109. if (!_found) {
  110. pEp_identity *_ident = identity_dup(ident);
  111. if (!_ident)
  112. return PEP_OUT_OF_MEMORY;
  113. identity_list *_il = identity_list_add(il, _ident);
  114. if (!_il) {
  115. free(_ident);
  116. return PEP_OUT_OF_MEMORY;
  117. }
  118. }
  119. *found = _found;
  120. return PEP_STATUS_OK;
  121. }
  122. ||
  123. apply "func:distinctName(//condition)", 0;
  124. apply "func:distinctName(//action)", 0;
  125. apply "/protocol/fsm", 0;
  126. }
  127. }
  128. template "condition" | #error condition «@name» not implemented\n
  129. template "action" | #error action «@name» not implemented\n
  130. function "condition" {
  131. param "content";
  132. ||
  133. PEP_STATUS «@name»(PEP_SESSION session, bool *result)
  134. {
  135. assert(session && result);
  136. if (!(session && result))
  137. return PEP_ILLEGAL_VALUE;
  138. ||
  139. copy "$content";
  140. ||
  141. return PEP_STATUS_OK;
  142. }
  143. ||
  144. }
  145. function "action" {
  146. param "content";
  147. ||
  148. PEP_STATUS «@name»(PEP_SESSION session)
  149. {
  150. assert(session);
  151. if (!session)
  152. return PEP_ILLEGAL_VALUE;
  153. ||
  154. copy "$content";
  155. ||
  156. return PEP_STATUS_OK;
  157. }
  158. ||
  159. }
  160. function "fsm" {
  161. param "content";
  162. ||
  163. PEP_STATUS «@name»TimeoutHandler(PEP_SESSION session)
  164. {
  165. assert(session);
  166. if (!session)
  167. return PEP_ILLEGAL_VALUE;
  168. ||
  169. copy "$content";
  170. ||
  171. return PEP_STATUS_OK;
  172. }
  173. ||
  174. }
  175. }