@pact-foundation/pact-core 13.13.2 → 13.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/bin/pact-broker.js +3 -3
  3. package/bin/pact-broker.js.map +1 -1
  4. package/bin/pact-message.js +3 -3
  5. package/bin/pact-message.js.map +1 -1
  6. package/bin/pact-mock-service.js +2 -2
  7. package/bin/pact-mock-service.js.map +1 -1
  8. package/bin/pact-provider-verifier.js +3 -3
  9. package/bin/pact-provider-verifier.js.map +1 -1
  10. package/bin/pact-stub-service.js +3 -3
  11. package/bin/pact-stub-service.js.map +1 -1
  12. package/bin/pact.js +3 -3
  13. package/bin/pact.js.map +1 -1
  14. package/bin/pactflow.js +3 -3
  15. package/bin/pactflow.js.map +1 -1
  16. package/build/Makefile +2 -2
  17. package/build/pact.target.mk +14 -14
  18. package/ffi/libpact_ffi.dylib +0 -0
  19. package/ffi/libpact_ffi.so +0 -0
  20. package/ffi/libpact_ffi.so.gz +0 -0
  21. package/ffi/linuxaarch64/libpact_ffi.so +0 -0
  22. package/ffi/osxaarch64/libpact_ffi.dylib +0 -0
  23. package/ffi/pact-cpp.h +1497 -669
  24. package/ffi/pact.h +1505 -676
  25. package/ffi/pact_ffi.dll +0 -0
  26. package/ffi/pact_ffi.dll.lib +0 -0
  27. package/native/consumer.cc +34 -7
  28. package/package.json +17 -11
  29. package/src/can-deploy/CannotDeployError.d.ts +5 -0
  30. package/src/can-deploy/CannotDeployError.js +12 -0
  31. package/src/can-deploy/CannotDeployError.js.map +1 -0
  32. package/src/can-deploy/can-deploy.d.ts +10 -0
  33. package/src/{can-deploy.js → can-deploy/can-deploy.js} +23 -24
  34. package/src/can-deploy/can-deploy.js.map +1 -0
  35. package/src/can-deploy/index.d.ts +4 -0
  36. package/src/can-deploy/index.js +24 -0
  37. package/src/can-deploy/index.js.map +1 -0
  38. package/src/{can-deploy.d.ts → can-deploy/types.d.ts} +0 -13
  39. package/src/can-deploy/types.js +3 -0
  40. package/src/can-deploy/types.js.map +1 -0
  41. package/src/consumer/checkErrors.js +1 -1
  42. package/src/consumer/checkErrors.js.map +1 -1
  43. package/src/consumer/index.d.ts +0 -1
  44. package/src/consumer/index.js +72 -200
  45. package/src/consumer/index.js.map +1 -1
  46. package/src/consumer/internals.d.ts +4 -0
  47. package/src/consumer/internals.js +43 -0
  48. package/src/consumer/internals.js.map +1 -0
  49. package/src/ffi/index.d.ts +1 -1
  50. package/src/ffi/index.js +7 -3
  51. package/src/ffi/index.js.map +1 -1
  52. package/src/ffi/types.js.map +1 -1
  53. package/src/index.d.ts +3 -0
  54. package/src/index.js +8 -1
  55. package/src/index.js.map +1 -1
  56. package/src/logger/index.d.ts +2 -2
  57. package/src/logger/index.js +3 -3
  58. package/src/logger/index.js.map +1 -1
  59. package/src/logger/pino.js +1 -1
  60. package/src/logger/pino.js.map +1 -1
  61. package/src/message.d.ts +2 -9
  62. package/src/message.js +30 -10
  63. package/src/message.js.map +1 -1
  64. package/src/pact-environment.js +5 -1
  65. package/src/pact-environment.js.map +1 -1
  66. package/src/pact-standalone.d.ts +1 -1
  67. package/src/pact-standalone.js +8 -6
  68. package/src/pact-standalone.js.map +1 -1
  69. package/src/pact.d.ts +2 -3
  70. package/src/pact.js +20 -14
  71. package/src/pact.js.map +1 -1
  72. package/src/publisher.d.ts +2 -15
  73. package/src/publisher.js +37 -35
  74. package/src/publisher.js.map +1 -1
  75. package/src/server.d.ts +2 -2
  76. package/src/server.js +4 -3
  77. package/src/server.js.map +1 -1
  78. package/src/service.d.ts +5 -22
  79. package/src/service.js +14 -10
  80. package/src/service.js.map +1 -1
  81. package/src/spawn/arguments.d.ts +2 -4
  82. package/src/spawn/arguments.js.map +1 -1
  83. package/src/spawn/index.d.ts +2 -1
  84. package/src/spawn/index.js +7 -4
  85. package/src/spawn/index.js.map +1 -1
  86. package/src/spawn/spawn.js +15 -8
  87. package/src/spawn/spawn.js.map +1 -1
  88. package/src/stub.d.ts +2 -2
  89. package/src/stub.js +3 -3
  90. package/src/stub.js.map +1 -1
  91. package/src/types.d.ts +41 -0
  92. package/src/types.js +3 -0
  93. package/src/types.js.map +1 -0
  94. package/src/verifier/argumentMapper/arguments.js +21 -23
  95. package/src/verifier/argumentMapper/arguments.js.map +1 -1
  96. package/src/verifier/argumentMapper/index.js +11 -7
  97. package/src/verifier/argumentMapper/index.js.map +1 -1
  98. package/src/verifier/index.js +2 -2
  99. package/src/verifier/index.js.map +1 -1
  100. package/src/verifier/nativeVerifier.js +9 -5
  101. package/src/verifier/nativeVerifier.js.map +1 -1
  102. package/src/verifier/validateOptions.js +25 -22
  103. package/src/verifier/validateOptions.js.map +1 -1
  104. package/standalone/install.js +7 -11
  105. package/standalone/install.js.map +1 -1
  106. package/tsconfig.build.json +4 -0
  107. package/tsconfig.json +5 -5
  108. package/src/can-deploy.js.map +0 -1
  109. package/tsconfig.spec.json +0 -7
package/ffi/pact-cpp.h CHANGED
@@ -47,6 +47,40 @@ enum class ExpressionValueType {
47
47
  ExpressionValueType_Boolean,
48
48
  };
49
49
 
50
+ /**
51
+ * Enum defining the categories that generators can be applied to
52
+ */
53
+ enum class GeneratorCategory {
54
+ /**
55
+ * Request Method
56
+ */
57
+ GeneratorCategory_METHOD,
58
+ /**
59
+ * Request Path
60
+ */
61
+ GeneratorCategory_PATH,
62
+ /**
63
+ * Request/Response Header
64
+ */
65
+ GeneratorCategory_HEADER,
66
+ /**
67
+ * Request Query Parameter
68
+ */
69
+ GeneratorCategory_QUERY,
70
+ /**
71
+ * Body
72
+ */
73
+ GeneratorCategory_BODY,
74
+ /**
75
+ * Response Status
76
+ */
77
+ GeneratorCategory_STATUS,
78
+ /**
79
+ * Message metadata
80
+ */
81
+ GeneratorCategory_METADATA,
82
+ };
83
+
50
84
  /**
51
85
  * Request or Response enum
52
86
  */
@@ -76,6 +110,44 @@ enum class LevelFilter {
76
110
  LevelFilter_Trace,
77
111
  };
78
112
 
113
+ /**
114
+ * Enum defining the categories that matching rules can be applied to
115
+ */
116
+ enum class MatchingRuleCategory {
117
+ /**
118
+ * Request Method
119
+ */
120
+ MatchingRuleCategory_METHOD,
121
+ /**
122
+ * Request Path
123
+ */
124
+ MatchingRuleCategory_PATH,
125
+ /**
126
+ * Request/Response Header
127
+ */
128
+ MatchingRuleCategory_HEADER,
129
+ /**
130
+ * Request Query Parameter
131
+ */
132
+ MatchingRuleCategory_QUERY,
133
+ /**
134
+ * Body
135
+ */
136
+ MatchingRuleCategory_BODY,
137
+ /**
138
+ * Response Status
139
+ */
140
+ MatchingRuleCategory_STATUS,
141
+ /**
142
+ * Message contents (body)
143
+ */
144
+ MatchingRuleCategory_CONTENTS,
145
+ /**
146
+ * Message metadata
147
+ */
148
+ MatchingRuleCategory_METADATA,
149
+ };
150
+
79
151
  /**
80
152
  * Enum defining the pact specification versions supported by the library
81
153
  */
@@ -106,6 +178,11 @@ enum class PactSpecification {
106
178
  PactSpecification_V4,
107
179
  };
108
180
 
181
+ /**
182
+ * Asynchronous interactions as a sequence of messages
183
+ */
184
+ struct AsynchronousMessage;
185
+
109
186
  /**
110
187
  * Struct that defines the consumer of the pact.
111
188
  */
@@ -116,11 +193,33 @@ struct Consumer;
116
193
  */
117
194
  struct Generator;
118
195
 
196
+ /**
197
+ * An iterator that enables FFI iteration over the generators for a particular generator
198
+ * category.
199
+ */
200
+ struct GeneratorCategoryIterator;
201
+
202
+ /**
203
+ * Struct that defines the HTTP request.
204
+ */
205
+ struct HttpRequest;
206
+
207
+ /**
208
+ * Struct that defines the HTTP response.
209
+ */
210
+ struct HttpResponse;
211
+
119
212
  /**
120
213
  * Set of all matching rules
121
214
  */
122
215
  struct MatchingRule;
123
216
 
217
+ /**
218
+ * An iterator that enables FFI iteration over the matching rules for a particular matching rule
219
+ * category.
220
+ */
221
+ struct MatchingRuleCategoryIterator;
222
+
124
223
  /**
125
224
  * Result of parsing a matching rule definition
126
225
  */
@@ -168,6 +267,11 @@ struct MatchingRuleResult;
168
267
  */
169
268
  struct Message;
170
269
 
270
+ /**
271
+ * Contents of a message interaction
272
+ */
273
+ struct MessageContents;
274
+
171
275
  /**
172
276
  * An iterator that enables FFI iteration over metadata by putting all the keys on the heap
173
277
  * and tracking which one we're currently at.
@@ -216,18 +320,28 @@ struct MismatchesIterator;
216
320
  */
217
321
  struct Pact;
218
322
 
323
+ /**
324
+ * Opaque type for use as a pointer to a Pact interaction model
325
+ */
326
+ struct PactInteraction;
327
+
328
+ /**
329
+ * An iterator over the interactions in a pact.
330
+ */
331
+ struct PactInteractionIterator;
332
+
219
333
  /**
220
334
  * An iterator over messages in a pact.
221
335
  */
222
336
  struct PactMessageIterator;
223
337
 
224
338
  /**
225
- * An iterator over synchronous HTTP request/response interactions in a pact.
339
+ * An iterator over synchronous HTTP request/response interactions in a V4 pact.
226
340
  */
227
341
  struct PactSyncHttpIterator;
228
342
 
229
343
  /**
230
- * An iterator over synchronous request/response messages in a pact.
344
+ * An iterator over synchronous request/response messages in a V4 pact.
231
345
  */
232
346
  struct PactSyncMessageIterator;
233
347
 
@@ -269,6 +383,34 @@ struct SynchronousMessage;
269
383
  */
270
384
  struct VerifierHandle;
271
385
 
386
+ /**
387
+ * A single key-value pair of a path and generator exported to the C-side.
388
+ */
389
+ struct GeneratorKeyValuePair {
390
+ /**
391
+ * The generator path
392
+ */
393
+ const char *path;
394
+ /**
395
+ * The generator
396
+ */
397
+ const Generator *generator;
398
+ };
399
+
400
+ /**
401
+ * A single key-value pair of a path and matching rule exported to the C-side.
402
+ */
403
+ struct MatchingRuleKeyValuePair {
404
+ /**
405
+ * The matching rule path
406
+ */
407
+ const char *path;
408
+ /**
409
+ * The matching rule
410
+ */
411
+ const MatchingRule *rule;
412
+ };
413
+
272
414
  /**
273
415
  * A single key-value pair exported to the C-side.
274
416
  */
@@ -632,42 +774,28 @@ Pact *pactffi_parse_pact_json(const char *json);
632
774
  void pactffi_pact_model_delete(Pact *pact);
633
775
 
634
776
  /**
635
- * Get a copy of this consumer's name.
636
- *
637
- * The copy must be deleted with `pactffi_string_delete`.
638
- *
639
- * # Usage
640
- *
641
- * ```c
642
- * // Assuming `file_name` and `json_str` are already defined.
643
- *
644
- * MessagePact *message_pact = pactffi_message_pact_new_from_json(file_name, json_str);
645
- * if (message_pact == NULLPTR) {
646
- * // handle error.
647
- * }
648
- *
649
- * Consumer *consumer = pactffi_message_pact_get_consumer(message_pact);
650
- * if (consumer == NULLPTR) {
651
- * // handle error.
652
- * }
777
+ * Returns an iterator over all the interactions in the Pact. The iterator will have to be
778
+ * deleted using the `pactffi_pact_interaction_iter_delete` function. The iterator will
779
+ * contain a copy of the interactions, so it will not be affected but mutations to the Pact
780
+ * model and will still function if the Pact model is deleted.
653
781
  *
654
- * char *name = pactffi_consumer_get_name(consumer);
655
- * if (name == NULL) {
656
- * // handle error.
657
- * }
658
- *
659
- * printf("%s\n", name);
660
- *
661
- * pactffi_string_delete(name);
662
- * ```
782
+ * # Safety
783
+ * This function is safe as long as the Pact pointer is a valid pointer.
663
784
  *
664
785
  * # Errors
665
- *
666
- * This function will fail if it is passed a NULL pointer,
667
- * or the Rust string contains an embedded NULL byte.
668
- * In the case of error, a NULL pointer will be returned.
786
+ * On any error, this function will return a NULL pointer.
669
787
  */
670
- const char *pactffi_consumer_get_name(const Consumer *consumer);
788
+ PactInteractionIterator *pactffi_pact_model_interaction_iterator(Pact *pact);
789
+
790
+ /**
791
+ * Returns the Pact specification enum that the Pact is for.
792
+ */
793
+ PactSpecification pactffi_pact_spec_version(const Pact *pact);
794
+
795
+ /**
796
+ * Frees the memory used by the Pact interaction model
797
+ */
798
+ void pactffi_pact_interaction_delete(const PactInteraction *interaction);
671
799
 
672
800
  /**
673
801
  * Get a mutable pointer to a newly-created default message on the heap.
@@ -680,43 +808,29 @@ const char *pactffi_consumer_get_name(const Consumer *consumer);
680
808
  *
681
809
  * Returns NULL on error.
682
810
  */
683
- Message *pactffi_message_new();
811
+ AsynchronousMessage *pactffi_async_message_new();
684
812
 
685
813
  /**
686
- * Constructs a `Message` from the JSON string
687
- *
688
- * # Safety
689
- *
690
- * This function is safe.
691
- *
692
- * # Error Handling
693
- *
694
- * If the JSON string is invalid or not UTF-8 encoded, returns a NULL.
814
+ * Destroy the `AsynchronousMessage` being pointed to.
695
815
  */
696
- Message *pactffi_message_new_from_json(unsigned int index,
697
- const char *json_str,
698
- PactSpecification spec_version);
816
+ void pactffi_async_message_delete(const AsynchronousMessage *message);
699
817
 
700
818
  /**
701
- * Constructs a `Message` from a body with a given content-type.
819
+ * Get the message contents of an `AsynchronousMessage` as a `MessageContents` pointer.
702
820
  *
703
821
  * # Safety
704
822
  *
705
- * This function is safe.
823
+ * The data pointed to by the pointer this function returns will be deleted when the message
824
+ * is deleted. Trying to use if after the message is deleted will result in undefined behaviour.
706
825
  *
707
826
  * # Error Handling
708
827
  *
709
- * If the body or content type are invalid or not UTF-8 encoded, returns NULL.
710
- */
711
- Message *pactffi_message_new_from_body(const char *body, const char *content_type);
712
-
713
- /**
714
- * Destroy the `Message` being pointed to.
828
+ * If the message is NULL, returns NULL.
715
829
  */
716
- void pactffi_message_delete(Message *message);
830
+ const MessageContents *pactffi_async_message_get_contents(const AsynchronousMessage *message);
717
831
 
718
832
  /**
719
- * Get the contents of a `Message` in string form.
833
+ * Get the message contents of an `AsynchronousMessage` in string form.
720
834
  *
721
835
  * # Safety
722
836
  *
@@ -731,10 +845,14 @@ void pactffi_message_delete(Message *message);
731
845
  * no mechanism to differentiate with this function call alone between
732
846
  * a NULL message and a missing message body.
733
847
  */
734
- const char *pactffi_message_get_contents(const Message *message);
848
+ const char *pactffi_async_message_get_contents_str(const AsynchronousMessage *message);
735
849
 
736
850
  /**
737
- * Sets the contents of the message.
851
+ * Sets the contents of the message as a string.
852
+ *
853
+ * * `message` - the message to set the contents for
854
+ * * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
855
+ * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
738
856
  *
739
857
  * # Safety
740
858
  *
@@ -746,10 +864,12 @@ const char *pactffi_message_get_contents(const Message *message);
746
864
  * If the contents is a NULL pointer, it will set the message contents as null. If the content
747
865
  * type is a null pointer, or can't be parsed, it will set the content type as unknown.
748
866
  */
749
- void pactffi_message_set_contents(Message *message, const char *contents, const char *content_type);
867
+ void pactffi_async_message_set_contents_str(AsynchronousMessage *message,
868
+ const char *contents,
869
+ const char *content_type);
750
870
 
751
871
  /**
752
- * Get the length of the contents of a `Message`.
872
+ * Get the length of the contents of a `AsynchronousMessage`.
753
873
  *
754
874
  * # Safety
755
875
  *
@@ -757,17 +877,17 @@ void pactffi_message_set_contents(Message *message, const char *contents, const
757
877
  *
758
878
  * # Error Handling
759
879
  *
760
- * If the message is NULL, returns 0. If the body of the message
880
+ * If the message is NULL, returns 0. If the body of the request
761
881
  * is missing, then this function also returns 0.
762
882
  */
763
- size_t pactffi_message_get_contents_length(const Message *message);
883
+ size_t pactffi_async_message_get_contents_length(const AsynchronousMessage *message);
764
884
 
765
885
  /**
766
- * Get the contents of a `Message` as a pointer to an array of bytes.
886
+ * Get the contents of an `AsynchronousMessage` as a pointer to an array of bytes.
767
887
  *
768
888
  * # Safety
769
889
  *
770
- * The number of bytes in the buffer will be returned by `pactffi_message_get_contents_length`.
890
+ * The number of bytes in the buffer will be returned by `pactffi_async_message_get_contents_length`.
771
891
  * It is safe to use the pointer while the message is not deleted or changed. Using the pointer
772
892
  * after the message is mutated or deleted may lead to undefined behaviour.
773
893
  *
@@ -776,11 +896,16 @@ size_t pactffi_message_get_contents_length(const Message *message);
776
896
  * If the message is NULL, returns NULL. If the body of the message
777
897
  * is missing, then this function also returns NULL.
778
898
  */
779
- const unsigned char *pactffi_message_get_contents_bin(const Message *message);
899
+ const unsigned char *pactffi_async_message_get_contents_bin(const AsynchronousMessage *message);
780
900
 
781
901
  /**
782
902
  * Sets the contents of the message as an array of bytes.
783
903
  *
904
+ * * `message` - the message to set the contents for
905
+ * * `contents` - pointer to contents to copy from
906
+ * * `len` - number of bytes to copy from the contents pointer
907
+ * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
908
+ *
784
909
  * # Safety
785
910
  *
786
911
  * The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
@@ -791,10 +916,10 @@ const unsigned char *pactffi_message_get_contents_bin(const Message *message);
791
916
  * If the contents is a NULL pointer, it will set the message contents as null. If the content
792
917
  * type is a null pointer, or can't be parsed, it will set the content type as unknown.
793
918
  */
794
- void pactffi_message_set_contents_bin(Message *message,
795
- const unsigned char *contents,
796
- size_t len,
797
- const char *content_type);
919
+ void pactffi_async_message_set_contents_bin(AsynchronousMessage *message,
920
+ const unsigned char *contents,
921
+ size_t len,
922
+ const char *content_type);
798
923
 
799
924
  /**
800
925
  * Get a copy of the description.
@@ -803,8 +928,7 @@ void pactffi_message_set_contents_bin(Message *message,
803
928
  *
804
929
  * The returned string must be deleted with `pactffi_string_delete`.
805
930
  *
806
- * Since it is a copy, the returned string may safely outlive
807
- * the `Message`.
931
+ * Since it is a copy, the returned string may safely outlive the `AsynchronousMessage`.
808
932
  *
809
933
  * # Errors
810
934
  *
@@ -813,10 +937,10 @@ void pactffi_message_set_contents_bin(Message *message,
813
937
  * This function may fail if the Rust string contains embedded
814
938
  * null ('\0') bytes.
815
939
  */
816
- const char *pactffi_message_get_description(const Message *message);
940
+ const char *pactffi_async_message_get_description(const AsynchronousMessage *message);
817
941
 
818
942
  /**
819
- * Write the `description` field on the `Message`.
943
+ * Write the `description` field on the `AsynchronousMessage`.
820
944
  *
821
945
  * # Safety
822
946
  *
@@ -830,7 +954,7 @@ const char *pactffi_message_get_description(const Message *message);
830
954
  *
831
955
  * Errors will be reported with a non-zero return value.
832
956
  */
833
- int pactffi_message_set_description(Message *message, const char *description);
957
+ int pactffi_async_message_set_description(AsynchronousMessage *message, const char *description);
834
958
 
835
959
  /**
836
960
  * Get a copy of the provider state at the given index from this message.
@@ -839,8 +963,7 @@ int pactffi_message_set_description(Message *message, const char *description);
839
963
  *
840
964
  * The returned structure must be deleted with `provider_state_delete`.
841
965
  *
842
- * Since it is a copy, the returned structure may safely outlive
843
- * the `Message`.
966
+ * Since it is a copy, the returned structure may safely outlive the `AsynchronousMessage`.
844
967
  *
845
968
  * # Error Handling
846
969
  *
@@ -849,7 +972,8 @@ int pactffi_message_set_description(Message *message, const char *description);
849
972
  * This function may fail if the index requested is out of bounds,
850
973
  * or if any of the Rust strings contain embedded null ('\0') bytes.
851
974
  */
852
- const ProviderState *pactffi_message_get_provider_state(const Message *message, unsigned int index);
975
+ const ProviderState *pactffi_async_message_get_provider_state(const AsynchronousMessage *message,
976
+ unsigned int index);
853
977
 
854
978
  /**
855
979
  * Get an iterator over provider states.
@@ -862,381 +986,385 @@ const ProviderState *pactffi_message_get_provider_state(const Message *message,
862
986
  *
863
987
  * Returns NULL if an error occurs.
864
988
  */
865
- ProviderStateIterator *pactffi_message_get_provider_state_iter(Message *message);
989
+ ProviderStateIterator *pactffi_async_message_get_provider_state_iter(AsynchronousMessage *message);
866
990
 
867
991
  /**
868
- * Get the next value from the iterator.
992
+ * Get a copy of this consumer's name.
869
993
  *
870
- * # Safety
994
+ * The copy must be deleted with `pactffi_string_delete`.
871
995
  *
872
- * The underlying data must not change during iteration.
996
+ * # Usage
873
997
  *
874
- * If a previous call panicked, then the internal mutex will have been poisoned and this
875
- * function will return NULL.
998
+ * ```c
999
+ * // Assuming `file_name` and `json_str` are already defined.
876
1000
  *
877
- * # Error Handling
1001
+ * MessagePact *message_pact = pactffi_message_pact_new_from_json(file_name, json_str);
1002
+ * if (message_pact == NULLPTR) {
1003
+ * // handle error.
1004
+ * }
878
1005
  *
879
- * Returns NULL if an error occurs.
1006
+ * Consumer *consumer = pactffi_message_pact_get_consumer(message_pact);
1007
+ * if (consumer == NULLPTR) {
1008
+ * // handle error.
1009
+ * }
1010
+ *
1011
+ * char *name = pactffi_consumer_get_name(consumer);
1012
+ * if (name == NULL) {
1013
+ * // handle error.
1014
+ * }
1015
+ *
1016
+ * printf("%s\n", name);
1017
+ *
1018
+ * pactffi_string_delete(name);
1019
+ * ```
1020
+ *
1021
+ * # Errors
1022
+ *
1023
+ * This function will fail if it is passed a NULL pointer,
1024
+ * or the Rust string contains an embedded NULL byte.
1025
+ * In the case of error, a NULL pointer will be returned.
880
1026
  */
881
- ProviderState *pactffi_provider_state_iter_next(ProviderStateIterator *iter);
1027
+ const char *pactffi_consumer_get_name(const Consumer *consumer);
882
1028
 
883
1029
  /**
884
- * Delete the iterator.
1030
+ * Get the consumer from a Pact. This returns a copy of the consumer model, and needs to
1031
+ * be cleaned up with `pactffi_pact_consumer_delete` when no longer required.
1032
+ *
1033
+ * # Errors
1034
+ *
1035
+ * This function will fail if it is passed a NULL pointer.
1036
+ * In the case of error, a NULL pointer will be returned.
885
1037
  */
886
- void pactffi_provider_state_iter_delete(ProviderStateIterator *iter);
1038
+ const Consumer *pactffi_pact_get_consumer(const Pact *pact);
887
1039
 
888
1040
  /**
889
- * Get a copy of the metadata value indexed by `key`.
1041
+ * Frees the memory used by the Pact consumer
1042
+ */
1043
+ void pactffi_pact_consumer_delete(const Consumer *consumer);
1044
+
1045
+ /**
1046
+ * Get the message contents in string form.
890
1047
  *
891
1048
  * # Safety
892
1049
  *
893
1050
  * The returned string must be deleted with `pactffi_string_delete`.
894
1051
  *
895
- * Since it is a copy, the returned string may safely outlive
896
- * the `Message`.
897
- *
898
- * The returned pointer will be NULL if the metadata does not contain
899
- * the given key, or if an error occurred.
1052
+ * The returned string can outlive the message.
900
1053
  *
901
1054
  * # Error Handling
902
1055
  *
903
- * On failure, this function will return a NULL pointer.
904
- *
905
- * This function may fail if the provided `key` string contains
906
- * invalid UTF-8, or if the Rust string contains embedded null ('\0')
907
- * bytes.
1056
+ * If the message contents is NULL, returns NULL. If the body of the message
1057
+ * is missing, then this function also returns NULL. This means there's
1058
+ * no mechanism to differentiate with this function call alone between
1059
+ * a NULL message and a missing message body.
908
1060
  */
909
- const char *pactffi_message_find_metadata(const Message *message, const char *key);
1061
+ const char *pactffi_message_contents_get_contents_str(const MessageContents *contents);
910
1062
 
911
1063
  /**
912
- * Insert the (`key`, `value`) pair into this Message's
913
- * `metadata` HashMap.
1064
+ * Sets the contents of the message as a string.
1065
+ *
1066
+ * * `contents` - the message contents to set the contents for
1067
+ * * `contents_str` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
1068
+ * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
914
1069
  *
915
1070
  * # Safety
916
1071
  *
917
- * This function returns an enum indicating the result;
918
- * see the comments on HashMapInsertStatus for details.
1072
+ * The message contents and content type must either be NULL pointers, or point to valid
1073
+ * UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
919
1074
  *
920
1075
  * # Error Handling
921
1076
  *
922
- * This function may fail if the provided `key` or `value` strings
923
- * contain invalid UTF-8.
1077
+ * If the contents string is a NULL pointer, it will set the message contents as null. If the content
1078
+ * type is a null pointer, or can't be parsed, it will set the content type as unknown.
924
1079
  */
925
- int pactffi_message_insert_metadata(Message *message, const char *key, const char *value);
1080
+ void pactffi_message_contents_set_contents_str(MessageContents *contents,
1081
+ const char *contents_str,
1082
+ const char *content_type);
926
1083
 
927
1084
  /**
928
- * Get an iterator over the metadata of a message.
1085
+ * Get the length of the message contents.
929
1086
  *
930
1087
  * # Safety
931
1088
  *
932
- * This iterator carries a pointer to the message, and must
933
- * not outlive the message.
934
- *
935
- * The message metadata also must not be modified during iteration. If it is,
936
- * the old iterator must be deleted and a new iterator created.
1089
+ * This function is safe.
937
1090
  *
938
1091
  * # Error Handling
939
1092
  *
940
- * On failure, this function will return a NULL pointer.
941
- *
942
- * This function may fail if any of the Rust strings contain
943
- * embedded null ('\0') bytes.
1093
+ * If the message is NULL, returns 0. If the body of the message
1094
+ * is missing, then this function also returns 0.
944
1095
  */
945
- MessageMetadataIterator *pactffi_message_get_metadata_iter(Message *message);
1096
+ size_t pactffi_message_contents_get_contents_length(const MessageContents *contents);
946
1097
 
947
1098
  /**
948
- * Get the next key and value out of the iterator, if possible
1099
+ * Get the contents of a message as a pointer to an array of bytes.
949
1100
  *
950
1101
  * # Safety
951
1102
  *
952
- * The underlying data must not change during iteration.
1103
+ * The number of bytes in the buffer will be returned by `pactffi_message_contents_get_contents_length`.
1104
+ * It is safe to use the pointer while the message is not deleted or changed. Using the pointer
1105
+ * after the message is mutated or deleted may lead to undefined behaviour.
953
1106
  *
954
1107
  * # Error Handling
955
1108
  *
956
- * If no further data is present, returns NULL.
957
- */
958
- MessageMetadataPair *pactffi_message_metadata_iter_next(MessageMetadataIterator *iter);
959
-
960
- /**
961
- * Free the metadata iterator when you're done using it.
962
- */
963
- void pactffi_message_metadata_iter_delete(MessageMetadataIterator *iter);
964
-
965
- /**
966
- * Free a pair of key and value returned from `message_metadata_iter_next`.
1109
+ * If the message is NULL, returns NULL. If the body of the message
1110
+ * is missing, then this function also returns NULL.
967
1111
  */
968
- void pactffi_message_metadata_pair_delete(MessageMetadataPair *pair);
1112
+ const unsigned char *pactffi_message_contents_get_contents_bin(const MessageContents *contents);
969
1113
 
970
1114
  /**
971
- * Construct a new `MessagePact` from the JSON string.
972
- * The provided file name is used when generating error messages.
1115
+ * Sets the contents of the message as an array of bytes.
1116
+ *
1117
+ * * `message` - the message contents to set the contents for
1118
+ * * `contents_bin` - pointer to contents to copy from
1119
+ * * `len` - number of bytes to copy from the contents pointer
1120
+ * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
973
1121
  *
974
1122
  * # Safety
975
1123
  *
976
- * The `file_name` and `json_str` parameters must both be valid UTF-8
977
- * encoded strings.
1124
+ * The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
1125
+ * and consecutive. Otherwise behaviour is undefined.
978
1126
  *
979
1127
  * # Error Handling
980
1128
  *
981
- * On error, this function will return a null pointer.
982
- */
983
- MessagePact *pactffi_message_pact_new_from_json(const char *file_name, const char *json_str);
984
-
985
- /**
986
- * Delete the `MessagePact` being pointed to.
1129
+ * If the contents is a NULL pointer, it will set the message contents as null. If the content
1130
+ * type is a null pointer, or can't be parsed, it will set the content type as unknown.
987
1131
  */
988
- void pactffi_message_pact_delete(MessagePact *message_pact);
1132
+ void pactffi_message_contents_set_contents_bin(MessageContents *contents,
1133
+ const unsigned char *contents_bin,
1134
+ size_t len,
1135
+ const char *content_type);
989
1136
 
990
1137
  /**
991
- * Get a pointer to the Consumer struct inside the MessagePact.
992
- * This is a mutable borrow: The caller may mutate the Consumer
993
- * through this pointer.
1138
+ * Get an iterator over the metadata of a message.
1139
+ *
1140
+ * The returned pointer must be deleted with `pactffi_message_metadata_iter_delete` when done
1141
+ * with it.
994
1142
  *
995
1143
  * # Safety
996
1144
  *
997
- * This function is safe.
1145
+ * This iterator carries a pointer to the message contents, and must
1146
+ * not outlive the message.
1147
+ *
1148
+ * The message metadata also must not be modified during iteration. If it is,
1149
+ * the old iterator must be deleted and a new iterator created.
998
1150
  *
999
1151
  * # Error Handling
1000
1152
  *
1001
- * This function will only fail if it is passed a NULL pointer.
1002
- * In the case of error, a NULL pointer will be returned.
1153
+ * On failure, this function will return a NULL pointer.
1154
+ *
1155
+ * This function may fail if any of the Rust strings contain
1156
+ * embedded null ('\0') bytes.
1003
1157
  */
1004
- Consumer *pactffi_message_pact_get_consumer(MessagePact *message_pact);
1158
+ MessageMetadataIterator *pactffi_message_contents_get_metadata_iter(const MessageContents *contents);
1005
1159
 
1006
1160
  /**
1007
- * Get a pointer to the Provider struct inside the MessagePact.
1008
- * This is a mutable borrow: The caller may mutate the Provider
1009
- * through this pointer.
1161
+ * Get an iterator over the matching rules for a category of a message.
1010
1162
  *
1011
- * # Safety
1163
+ * The returned pointer must be deleted with `pactffi_matching_rules_iter_delete` when done
1164
+ * with it.
1012
1165
  *
1013
- * This function is safe.
1166
+ * Note that there could be multiple matching rules for the same key, so this iterator will
1167
+ * sequentially return each rule with the same key.
1014
1168
  *
1015
- * # Error Handling
1169
+ * For sample, given the following rules:
1170
+ * "$.a" => Type,
1171
+ * "$.b" => Regex("\\d+"), Number
1016
1172
  *
1017
- * This function will only fail if it is passed a NULL pointer.
1018
- * In the case of error, a NULL pointer will be returned.
1019
- */
1020
- Provider *pactffi_message_pact_get_provider(MessagePact *message_pact);
1021
-
1022
- /**
1023
- * Get an iterator over the messages of a message pact.
1173
+ * This iterator will return a sequence of 3 values: ("$.a", Type), ("$.b", Regex("\\d+")), ("$.b", Number)
1024
1174
  *
1025
1175
  * # Safety
1026
1176
  *
1027
- * This iterator carries a pointer to the message pact, and must
1028
- * not outlive the message pact.
1029
- *
1030
- * The message pact messages also must not be modified during iteration.
1031
- * If they are, the old iterator must be deleted and a new iterator created.
1177
+ * The iterator contains a copy of the data, so is safe to use when the message or message
1178
+ * contents has been deleted.
1032
1179
  *
1033
1180
  * # Error Handling
1034
1181
  *
1035
1182
  * On failure, this function will return a NULL pointer.
1036
- *
1037
- * This function may fail if any of the Rust strings contain embedded
1038
- * null ('\0') bytes.
1039
1183
  */
1040
- MessagePactMessageIterator *pactffi_message_pact_get_message_iter(MessagePact *message_pact);
1184
+ MatchingRuleCategoryIterator *pactffi_message_contents_get_matching_rule_iter(const MessageContents *contents,
1185
+ MatchingRuleCategory category);
1041
1186
 
1042
1187
  /**
1043
- * Get the next message from the message pact.
1044
- *
1045
- * # Safety
1188
+ * Get an iterator over the matching rules for a category of an HTTP request.
1046
1189
  *
1047
- * This function is safe.
1190
+ * The returned pointer must be deleted with `pactffi_matching_rules_iter_delete` when done
1191
+ * with it.
1048
1192
  *
1049
- * # Error Handling
1193
+ * For sample, given the following rules:
1194
+ * "$.a" => Type,
1195
+ * "$.b" => Regex("\\d+"), Number
1050
1196
  *
1051
- * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1052
- */
1053
- Message *pactffi_message_pact_message_iter_next(MessagePactMessageIterator *iter);
1054
-
1055
- /**
1056
- * Delete the iterator.
1057
- */
1058
- void pactffi_message_pact_message_iter_delete(MessagePactMessageIterator *iter);
1059
-
1060
- /**
1061
- * Get a copy of the metadata value indexed by `key1` and `key2`.
1197
+ * This iterator will return a sequence of 3 values: ("$.a", Type), ("$.b", Regex("\\d+")), ("$.b", Number)
1062
1198
  *
1063
1199
  * # Safety
1064
1200
  *
1065
- * Since it is a copy, the returned string may safely outlive
1066
- * the `Message`.
1067
- *
1068
- * The returned string must be deleted with `pactffi_string_delete`.
1069
- *
1070
- * The returned pointer will be NULL if the metadata does not contain
1071
- * the given key, or if an error occurred.
1201
+ * The iterator contains a copy of the data, so is safe to use when the interaction or request
1202
+ * contents has been deleted.
1072
1203
  *
1073
1204
  * # Error Handling
1074
1205
  *
1075
1206
  * On failure, this function will return a NULL pointer.
1076
- *
1077
- * This function may fail if the provided `key1` or `key2` strings contains
1078
- * invalid UTF-8, or if the Rust string contains embedded null ('\0')
1079
- * bytes.
1080
1207
  */
1081
- const char *pactffi_message_pact_find_metadata(const MessagePact *message_pact,
1082
- const char *key1,
1083
- const char *key2);
1208
+ MatchingRuleCategoryIterator *pactffi_request_contents_get_matching_rule_iter(const HttpRequest *request,
1209
+ MatchingRuleCategory category);
1084
1210
 
1085
1211
  /**
1086
- * Get an iterator over the metadata of a message pact.
1212
+ * Get an iterator over the matching rules for a category of an HTTP response.
1087
1213
  *
1088
- * # Safety
1214
+ * The returned pointer must be deleted with `pactffi_matching_rules_iter_delete` when done
1215
+ * with it.
1089
1216
  *
1090
- * This iterator carries a pointer to the message pact, and must
1091
- * not outlive the message pact.
1217
+ * For sample, given the following rules:
1218
+ * "$.a" => Type,
1219
+ * "$.b" => Regex("\\d+"), Number
1092
1220
  *
1093
- * The message pact metadata also must not be modified during iteration. If it is,
1094
- * the old iterator must be deleted and a new iterator created.
1221
+ * This iterator will return a sequence of 3 values: ("$.a", Type), ("$.b", Regex("\\d+")), ("$.b", Number)
1222
+ *
1223
+ * # Safety
1224
+ *
1225
+ * The iterator contains a copy of the data, so is safe to use when the interaction or response
1226
+ * contents has been deleted.
1095
1227
  *
1096
1228
  * # Error Handling
1097
1229
  *
1098
1230
  * On failure, this function will return a NULL pointer.
1099
- *
1100
- * This function may fail if any of the Rust strings contain
1101
- * embedded null ('\0') bytes.
1102
1231
  */
1103
- MessagePactMetadataIterator *pactffi_message_pact_get_metadata_iter(MessagePact *message_pact);
1232
+ MatchingRuleCategoryIterator *pactffi_response_contents_get_matching_rule_iter(const HttpResponse *response,
1233
+ MatchingRuleCategory category);
1104
1234
 
1105
1235
  /**
1106
- * Get the next triple out of the iterator, if possible
1236
+ * Get an iterator over the generators for a category of a message.
1237
+ *
1238
+ * The returned pointer must be deleted with `pactffi_generators_iter_delete` when done
1239
+ * with it.
1107
1240
  *
1108
1241
  * # Safety
1109
1242
  *
1110
- * This operation is invalid if the underlying data has been changed during iteration.
1243
+ * The iterator contains a copy of the data, so is safe to use when the message or message
1244
+ * contents has been deleted.
1111
1245
  *
1112
1246
  * # Error Handling
1113
1247
  *
1114
- * Returns null if no next element is present.
1115
- */
1116
- MessagePactMetadataTriple *pactffi_message_pact_metadata_iter_next(MessagePactMetadataIterator *iter);
1117
-
1118
- /**
1119
- * Free the metadata iterator when you're done using it.
1120
- */
1121
- void pactffi_message_pact_metadata_iter_delete(MessagePactMetadataIterator *iter);
1122
-
1123
- /**
1124
- * Free a triple returned from `pactffi_message_pact_metadata_iter_next`.
1248
+ * On failure, this function will return a NULL pointer.
1125
1249
  */
1126
- void pactffi_message_pact_metadata_triple_delete(MessagePactMetadataTriple *triple);
1250
+ GeneratorCategoryIterator *pactffi_message_contents_get_generators_iter(const MessageContents *contents,
1251
+ GeneratorCategory category);
1127
1252
 
1128
1253
  /**
1129
- * Get a copy of this provider's name.
1130
- *
1131
- * The copy must be deleted with `pactffi_string_delete`.
1132
- *
1133
- * # Usage
1134
- *
1135
- * ```c
1136
- * // Assuming `file_name` and `json_str` are already defined.
1137
- *
1138
- * MessagePact *message_pact = pactffi_message_pact_new_from_json(file_name, json_str);
1139
- * if (message_pact == NULLPTR) {
1140
- * // handle error.
1141
- * }
1142
- *
1143
- * Provider *provider = pactffi_message_pact_get_provider(message_pact);
1144
- * if (provider == NULLPTR) {
1145
- * // handle error.
1146
- * }
1254
+ * Get an iterator over the generators for a category of an HTTP request.
1147
1255
  *
1148
- * char *name = pactffi_provider_get_name(provider);
1149
- * if (name == NULL) {
1150
- * // handle error.
1151
- * }
1256
+ * The returned pointer must be deleted with `pactffi_generators_iter_delete` when done
1257
+ * with it.
1152
1258
  *
1153
- * printf("%s\n", name);
1259
+ * # Safety
1154
1260
  *
1155
- * pactffi_string_delete(name);
1156
- * ```
1261
+ * The iterator contains a copy of the data, so is safe to use when the interaction or request
1262
+ * contents has been deleted.
1157
1263
  *
1158
- * # Errors
1264
+ * # Error Handling
1159
1265
  *
1160
- * This function will fail if it is passed a NULL pointer,
1161
- * or the Rust string contains an embedded NULL byte.
1162
- * In the case of error, a NULL pointer will be returned.
1266
+ * On failure, this function will return a NULL pointer.
1163
1267
  */
1164
- const char *pactffi_provider_get_name(const Provider *provider);
1268
+ GeneratorCategoryIterator *pactffi_request_contents_get_generators_iter(const HttpRequest *request,
1269
+ GeneratorCategory category);
1165
1270
 
1166
1271
  /**
1167
- * Get the name of the provider state as a string, which needs to be deleted with `pactffi_string_delete`.
1272
+ * Get an iterator over the generators for a category of an HTTP response.
1273
+ *
1274
+ * The returned pointer must be deleted with `pactffi_generators_iter_delete` when done
1275
+ * with it.
1168
1276
  *
1169
1277
  * # Safety
1170
1278
  *
1171
- * This function is safe.
1279
+ * The iterator contains a copy of the data, so is safe to use when the interaction or response
1280
+ * contents has been deleted.
1172
1281
  *
1173
1282
  * # Error Handling
1174
1283
  *
1175
- * If the provider_state param is NULL, this returns NULL.
1284
+ * On failure, this function will return a NULL pointer.
1176
1285
  */
1177
- const char *pactffi_provider_state_get_name(const ProviderState *provider_state);
1286
+ GeneratorCategoryIterator *pactffi_response_contents_get_generators_iter(const HttpResponse *response,
1287
+ GeneratorCategory category);
1178
1288
 
1179
1289
  /**
1180
- * Get an iterator over the params of a provider state.
1290
+ * Parse a matcher definition string into a MatchingRuleDefinition containing the example value,
1291
+ * and matching rules and any generator.
1181
1292
  *
1182
- * # Safety
1293
+ * The following are examples of matching rule definitions:
1294
+ * * `matching(type,'Name')` - type matcher with string value 'Name'
1295
+ * * `matching(number,100)` - number matcher
1296
+ * * `matching(datetime, 'yyyy-MM-dd','2000-01-01')` - datetime matcher with format string
1183
1297
  *
1184
- * This iterator carries a pointer to the provider state, and must
1185
- * not outlive the provider state.
1298
+ * See [Matching Rule definition expressions](https://docs.rs/pact_models/latest/pact_models/matchingrules/expressions/index.html).
1186
1299
  *
1187
- * The provider state params also must not be modified during iteration. If it is,
1188
- * the old iterator must be deleted and a new iterator created.
1300
+ * The returned value needs to be freed up with the `pactffi_matcher_definition_delete` function.
1189
1301
  *
1190
1302
  * # Errors
1303
+ * If the expression is invalid, the MatchingRuleDefinition error will be set. You can check for
1304
+ * this value with the `pactffi_matcher_definition_error` function.
1191
1305
  *
1192
- * On failure, this function will return a NULL pointer.
1306
+ * # Safety
1193
1307
  *
1194
- * This function may fail if any of the Rust strings contain
1195
- * embedded null ('\0') bytes.
1308
+ * This function is safe if the expression is a valid NULL terminated string pointer.
1196
1309
  */
1197
- ProviderStateParamIterator *pactffi_provider_state_get_param_iter(ProviderState *provider_state);
1310
+ const MatchingRuleDefinitionResult *pactffi_parse_matcher_definition(const char *expression);
1198
1311
 
1199
1312
  /**
1200
- * Get the next key and value out of the iterator, if possible
1201
- *
1202
- * Returns a pointer to a heap allocated array of 2 elements, the pointer to the
1203
- * key string on the heap, and the pointer to the value string on the heap.
1204
- *
1205
- * # Safety
1206
- *
1207
- * The underlying data must not be modified during iteration.
1208
- *
1209
- * The user needs to free both the contained strings and the array.
1210
- *
1211
- * # Error Handling
1313
+ * Returns any error message from parsing a matching definition expression. If there is no error,
1314
+ * it will return a NULL pointer, otherwise returns the error message as a NULL-terminated string.
1315
+ * The returned string must be freed using the `pactffi_string_delete` function once done with it.
1316
+ */
1317
+ const char *pactffi_matcher_definition_error(const MatchingRuleDefinitionResult *definition);
1318
+
1319
+ /**
1320
+ * Returns the value from parsing a matching definition expression. If there was an error,
1321
+ * it will return a NULL pointer, otherwise returns the value as a NULL-terminated string.
1322
+ * The returned string must be freed using the `pactffi_string_delete` function once done with it.
1212
1323
  *
1213
- * Returns NULL if there's no further elements or the iterator is NULL.
1324
+ * Note that different expressions values can have types other than a string. Use
1325
+ * `pactffi_matcher_definition_value_type` to get the actual type of the value. This function
1326
+ * will always return the string representation of the value.
1214
1327
  */
1215
- ProviderStateParamPair *pactffi_provider_state_param_iter_next(ProviderStateParamIterator *iter);
1328
+ const char *pactffi_matcher_definition_value(const MatchingRuleDefinitionResult *definition);
1216
1329
 
1217
1330
  /**
1218
- * Free the provider state when you're done using it.
1331
+ * Frees the memory used by the result of parsing the matching definition expression
1219
1332
  */
1220
- void pactffi_provider_state_delete(ProviderState *provider_state);
1333
+ void pactffi_matcher_definition_delete(const MatchingRuleDefinitionResult *definition);
1221
1334
 
1222
1335
  /**
1223
- * Free the provider state param iterator when you're done using it.
1336
+ * Returns the generator from parsing a matching definition expression. If there was an error or
1337
+ * there is no associated generator, it will return a NULL pointer, otherwise returns the generator
1338
+ * as a pointer.
1339
+ *
1340
+ * The generator pointer will be a valid pointer as long as `pactffi_matcher_definition_delete`
1341
+ * has not been called on the definition. Using the generator pointer after the definition
1342
+ * has been deleted will result in undefined behaviour.
1224
1343
  */
1225
- void pactffi_provider_state_param_iter_delete(ProviderStateParamIterator *iter);
1344
+ const Generator *pactffi_matcher_definition_generator(const MatchingRuleDefinitionResult *definition);
1226
1345
 
1227
1346
  /**
1228
- * Free a pair of key and value returned from `pactffi_provider_state_param_iter_next`.
1347
+ * Returns the type of the value from parsing a matching definition expression. If there was an
1348
+ * error parsing the expression, it will return Unknown.
1229
1349
  */
1230
- void pactffi_provider_state_param_pair_delete(ProviderStateParamPair *pair);
1350
+ ExpressionValueType pactffi_matcher_definition_value_type(const MatchingRuleDefinitionResult *definition);
1231
1351
 
1232
1352
  /**
1233
1353
  * Free the iterator when you're done using it.
1234
1354
  */
1235
- void pactffi_pact_message_iter_delete(PactMessageIterator *iter);
1355
+ void pactffi_matching_rule_iter_delete(MatchingRuleIterator *iter);
1236
1356
 
1237
1357
  /**
1238
- * Get the next message from the message pact. As the messages returned are owned by the
1239
- * iterator, they do not need to be deleted but will be cleaned up when the iterator is
1358
+ * Returns an iterator over the matching rules from the parsed definition. The iterator needs to
1359
+ * be deleted with the `pactffi_matching_rule_iter_delete` function once done with it.
1360
+ *
1361
+ * If there was an error parsing the expression, this function will return a NULL pointer.
1362
+ */
1363
+ MatchingRuleIterator *pactffi_matcher_definition_iter(const MatchingRuleDefinitionResult *definition);
1364
+
1365
+ /**
1366
+ * Get the next matching rule or reference from the iterator. As the values returned are owned
1367
+ * by the iterator, they do not need to be deleted but will be cleaned up when the iterator is
1240
1368
  * deleted.
1241
1369
  *
1242
1370
  * Will return a NULL pointer when the iterator has advanced past the end of the list.
@@ -1245,64 +1373,184 @@ void pactffi_pact_message_iter_delete(PactMessageIterator *iter);
1245
1373
  *
1246
1374
  * This function is safe.
1247
1375
  *
1248
- * Deleting a message returned by the iterator can lead to undefined behaviour.
1249
- *
1250
1376
  * # Error Handling
1251
1377
  *
1252
1378
  * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1253
1379
  */
1254
- Message *pactffi_pact_message_iter_next(PactMessageIterator *iter);
1380
+ const MatchingRuleResult *pactffi_matching_rule_iter_next(MatchingRuleIterator *iter);
1255
1381
 
1256
1382
  /**
1257
- * Get the next synchronous request/response message from the pact. As the messages returned are owned by the
1258
- * iterator, they do not need to be deleted but will be cleaned up when the iterator is
1259
- * deleted.
1383
+ * Return the ID of the matching rule.
1260
1384
  *
1261
- * Will return a NULL pointer when the iterator has advanced past the end of the list.
1385
+ * The ID corresponds to the following rules:
1386
+ * | Rule | ID |
1387
+ * | ---- | -- |
1388
+ * | Equality | 1 |
1389
+ * | Regex | 2 |
1390
+ * | Type | 3 |
1391
+ * | MinType | 4 |
1392
+ * | MaxType | 5 |
1393
+ * | MinMaxType | 6 |
1394
+ * | Timestamp | 7 |
1395
+ * | Time | 8 |
1396
+ * | Date | 9 |
1397
+ * | Include | 10 |
1398
+ * | Number | 11 |
1399
+ * | Integer | 12 |
1400
+ * | Decimal | 13 |
1401
+ * | Null | 14 |
1402
+ * | ContentType | 15 |
1403
+ * | ArrayContains | 16 |
1404
+ * | Values | 17 |
1405
+ * | Boolean | 18 |
1406
+ * | StatusCode | 19 |
1407
+ * | NotEmpty | 20 |
1408
+ * | Semver | 21 |
1409
+ * | EachKey | 22 |
1410
+ * | EachValue | 23 |
1262
1411
  *
1263
1412
  * # Safety
1264
1413
  *
1265
- * This function is safe.
1414
+ * This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the
1415
+ * iterator has not been deleted.
1416
+ */
1417
+ uint16_t pactffi_matching_rule_id(const MatchingRuleResult *rule_result);
1418
+
1419
+ /**
1420
+ * Returns the associated value for the matching rule. If the matching rule does not have an
1421
+ * associated value, will return a NULL pointer.
1266
1422
  *
1267
- * Deleting a message returned by the iterator can lead to undefined behaviour.
1423
+ * The associated values for the rules are:
1424
+ * | Rule | ID | VALUE |
1425
+ * | ---- | -- | ----- |
1426
+ * | Equality | 1 | NULL |
1427
+ * | Regex | 2 | Regex value |
1428
+ * | Type | 3 | NULL |
1429
+ * | MinType | 4 | Minimum value |
1430
+ * | MaxType | 5 | Maximum value |
1431
+ * | MinMaxType | 6 | "min:max" |
1432
+ * | Timestamp | 7 | Format string |
1433
+ * | Time | 8 | Format string |
1434
+ * | Date | 9 | Format string |
1435
+ * | Include | 10 | String value |
1436
+ * | Number | 11 | NULL |
1437
+ * | Integer | 12 | NULL |
1438
+ * | Decimal | 13 | NULL |
1439
+ * | Null | 14 | NULL |
1440
+ * | ContentType | 15 | Content type |
1441
+ * | ArrayContains | 16 | NULL |
1442
+ * | Values | 17 | NULL |
1443
+ * | Boolean | 18 | NULL |
1444
+ * | StatusCode | 19 | NULL |
1445
+ * | NotEmpty | 20 | NULL |
1446
+ * | Semver | 21 | NULL |
1447
+ * | EachKey | 22 | NULL |
1448
+ * | EachValue | 23 | NULL |
1268
1449
  *
1269
- * # Error Handling
1450
+ * Will return a NULL pointer if the matching rule was a reference or does not have an
1451
+ * associated value.
1270
1452
  *
1271
- * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1453
+ * # Safety
1454
+ *
1455
+ * This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the
1456
+ * iterator it came from has not been deleted.
1272
1457
  */
1273
- SynchronousMessage *pactffi_pact_sync_message_iter_next(PactSyncMessageIterator *iter);
1458
+ const char *pactffi_matching_rule_value(const MatchingRuleResult *rule_result);
1274
1459
 
1275
1460
  /**
1276
- * Free the iterator when you're done using it.
1461
+ * Returns the matching rule pointer for the matching rule. Will return a NULL pointer if the
1462
+ * matching rule result was a reference.
1463
+ *
1464
+ * # Safety
1465
+ *
1466
+ * This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the
1467
+ * iterator it came from has not been deleted.
1277
1468
  */
1278
- void pactffi_pact_sync_message_iter_delete(PactSyncMessageIterator *iter);
1469
+ const MatchingRule *pactffi_matching_rule_pointer(const MatchingRuleResult *rule_result);
1279
1470
 
1280
1471
  /**
1281
- * Get the next synchronous HTTP request/response interaction from the pact. As the
1282
- * interactions returned are owned by the iterator, they do not need to be deleted but
1283
- * will be cleaned up when the iterator is deleted.
1472
+ * Return any matching rule reference to a attribute by name. This is when the matcher should
1473
+ * be configured to match the type of a structure. I.e.,
1284
1474
  *
1285
- * Will return a NULL pointer when the iterator has advanced past the end of the list.
1475
+ * ```json
1476
+ * {
1477
+ * "pact:match": "eachValue(matching($'person'))",
1478
+ * "person": {
1479
+ * "name": "Fred",
1480
+ * "age": 100
1481
+ * }
1482
+ * }
1483
+ * ```
1484
+ *
1485
+ * Will return a NULL pointer if the matching rule was not a reference.
1286
1486
  *
1287
1487
  * # Safety
1288
1488
  *
1289
- * This function is safe.
1489
+ * This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the
1490
+ * iterator has not been deleted.
1491
+ */
1492
+ const char *pactffi_matching_rule_reference_name(const MatchingRuleResult *rule_result);
1493
+
1494
+ /**
1495
+ * Get the JSON form of the generator.
1290
1496
  *
1291
- * Deleting an interaction returned by the iterator can lead to undefined behaviour.
1497
+ * The returned string must be deleted with `pactffi_string_delete`.
1292
1498
  *
1293
- * # Error Handling
1499
+ * # Safety
1294
1500
  *
1295
- * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1501
+ * This function will fail if it is passed a NULL pointer, or the owner of the generator has
1502
+ * been deleted.
1296
1503
  */
1297
- SynchronousHttp *pactffi_pact_sync_http_iter_next(PactSyncHttpIterator *iter);
1504
+ const char *pactffi_generator_to_json(const Generator *generator);
1505
+
1506
+ /**
1507
+ * Generate a string value using the provided generator and an optional JSON payload containing
1508
+ * any generator context. The context value is used for generators like `MockServerURL` (which
1509
+ * should contain details about the running mock server) and `ProviderStateGenerator` (which
1510
+ * should be the values returned from the Provider State callback function).
1511
+ *
1512
+ * If anything goes wrong, it will return a NULL pointer.
1513
+ */
1514
+ const char *pactffi_generator_generate_string(const Generator *generator, const char *context_json);
1515
+
1516
+ /**
1517
+ * Generate an integer value using the provided generator and an optional JSON payload containing
1518
+ * any generator context. The context value is used for generators like `ProviderStateGenerator`
1519
+ * (which should be the values returned from the Provider State callback function).
1520
+ *
1521
+ * If anything goes wrong or the generator is not a type that can generate an integer value, it
1522
+ * will return a zero value.
1523
+ */
1524
+ unsigned short pactffi_generator_generate_integer(const Generator *generator,
1525
+ const char *context_json);
1298
1526
 
1299
1527
  /**
1300
1528
  * Free the iterator when you're done using it.
1301
1529
  */
1302
- void pactffi_pact_sync_http_iter_delete(PactSyncHttpIterator *iter);
1530
+ void pactffi_generators_iter_delete(GeneratorCategoryIterator *iter);
1303
1531
 
1304
1532
  /**
1305
- * Get a mutable pointer to a newly-created default message on the heap.
1533
+ * Get the next path and generator out of the iterator, if possible.
1534
+ *
1535
+ * The returned pointer must be deleted with `pactffi_generator_iter_pair_delete`.
1536
+ *
1537
+ * # Safety
1538
+ *
1539
+ * The underlying data is owned by the `GeneratorKeyValuePair`, so is always safe to use.
1540
+ *
1541
+ * # Error Handling
1542
+ *
1543
+ * If no further data is present, returns NULL.
1544
+ */
1545
+ const GeneratorKeyValuePair *pactffi_generators_iter_next(GeneratorCategoryIterator *iter);
1546
+
1547
+ /**
1548
+ * Free a pair of key and value returned from `pactffi_generators_iter_next`.
1549
+ */
1550
+ void pactffi_generators_iter_pair_delete(const GeneratorKeyValuePair *pair);
1551
+
1552
+ /**
1553
+ * Get a mutable pointer to a newly-created default interaction on the heap.
1306
1554
  *
1307
1555
  * # Safety
1308
1556
  *
@@ -1312,54 +1560,68 @@ void pactffi_pact_sync_http_iter_delete(PactSyncHttpIterator *iter);
1312
1560
  *
1313
1561
  * Returns NULL on error.
1314
1562
  */
1315
- SynchronousMessage *pactffi_sync_message_new();
1563
+ SynchronousHttp *pactffi_sync_http_new();
1316
1564
 
1317
1565
  /**
1318
- * Destroy the `Message` being pointed to.
1566
+ * Destroy the `SynchronousHttp` interaction being pointed to.
1319
1567
  */
1320
- void pactffi_sync_message_delete(SynchronousMessage *message);
1568
+ void pactffi_sync_http_delete(const SynchronousHttp *interaction);
1321
1569
 
1322
1570
  /**
1323
- * Get the request contents of a `SynchronousMessage` in string form.
1571
+ * Get the request of a `SynchronousHttp` interaction.
1572
+ *
1573
+ * # Safety
1574
+ *
1575
+ * The data pointed to by the pointer this function returns will be deleted when the interaction
1576
+ * is deleted. Trying to use if after the interaction is deleted will result in undefined behaviour.
1577
+ *
1578
+ * # Error Handling
1579
+ *
1580
+ * If the interaction is NULL, returns NULL.
1581
+ */
1582
+ const HttpRequest *pactffi_sync_http_get_request(const SynchronousHttp *interaction);
1583
+
1584
+ /**
1585
+ * Get the request contents of a `SynchronousHttp` interaction in string form.
1324
1586
  *
1325
1587
  * # Safety
1326
1588
  *
1327
1589
  * The returned string must be deleted with `pactffi_string_delete`.
1328
1590
  *
1329
- * The returned string can outlive the message.
1591
+ * The returned string can outlive the interaction.
1330
1592
  *
1331
1593
  * # Error Handling
1332
1594
  *
1333
- * If the message is NULL, returns NULL. If the body of the request message
1595
+ * If the interaction is NULL, returns NULL. If the body of the request
1334
1596
  * is missing, then this function also returns NULL. This means there's
1335
1597
  * no mechanism to differentiate with this function call alone between
1336
- * a NULL message and a missing message body.
1598
+ * a NULL body and a missing body.
1337
1599
  */
1338
- const char *pactffi_sync_message_get_request_contents(const SynchronousMessage *message);
1600
+ const char *pactffi_sync_http_get_request_contents(const SynchronousHttp *interaction);
1339
1601
 
1340
1602
  /**
1341
- * Sets the request contents of the message.
1603
+ * Sets the request contents of the interaction.
1342
1604
  *
1343
- * * `message` - the message to set the request contents for
1605
+ * * `interaction` - the interaction to set the request contents for
1344
1606
  * * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
1345
1607
  * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
1346
1608
  *
1347
1609
  * # Safety
1348
1610
  *
1349
- * The message contents and content type must either be NULL pointers, or point to valid
1611
+ * The request contents and content type must either be NULL pointers, or point to valid
1350
1612
  * UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
1351
1613
  *
1352
1614
  * # Error Handling
1353
1615
  *
1354
- * If the contents is a NULL pointer, it will set the message contents as null. If the content
1616
+ * If the contents is a NULL pointer, it will set the request contents as null. If the content
1355
1617
  * type is a null pointer, or can't be parsed, it will set the content type as unknown.
1356
1618
  */
1357
- void pactffi_sync_message_set_request_contents(SynchronousMessage *message,
1358
- const char *contents,
1359
- const char *content_type);
1619
+ void pactffi_sync_http_set_request_contents(SynchronousHttp *interaction,
1620
+ const char *contents,
1621
+ const char *content_type);
1360
1622
 
1361
1623
  /**
1362
- * Get the length of the request contents of a `SynchronousMessage`.
1624
+ * Get the length of the request contents of a `SynchronousHttp` interaction.
1363
1625
  *
1364
1626
  * # Safety
1365
1627
  *
@@ -1367,31 +1629,31 @@ void pactffi_sync_message_set_request_contents(SynchronousMessage *message,
1367
1629
  *
1368
1630
  * # Error Handling
1369
1631
  *
1370
- * If the message is NULL, returns 0. If the body of the request
1632
+ * If the interaction is NULL, returns 0. If the body of the request
1371
1633
  * is missing, then this function also returns 0.
1372
1634
  */
1373
- size_t pactffi_sync_message_get_request_contents_length(const SynchronousMessage *message);
1635
+ size_t pactffi_sync_http_get_request_contents_length(const SynchronousHttp *interaction);
1374
1636
 
1375
1637
  /**
1376
- * Get the request contents of a `SynchronousMessage` as a pointer to an array of bytes.
1638
+ * Get the request contents of a `SynchronousHttp` interaction as a pointer to an array of bytes.
1377
1639
  *
1378
1640
  * # Safety
1379
1641
  *
1380
- * The number of bytes in the buffer will be returned by `pactffi_sync_message_get_request_contents_length`.
1381
- * It is safe to use the pointer while the message is not deleted or changed. Using the pointer
1382
- * after the message is mutated or deleted may lead to undefined behaviour.
1642
+ * The number of bytes in the buffer will be returned by `pactffi_sync_http_get_request_contents_length`.
1643
+ * It is safe to use the pointer while the interaction is not deleted or changed. Using the pointer
1644
+ * after the interaction is mutated or deleted may lead to undefined behaviour.
1383
1645
  *
1384
1646
  * # Error Handling
1385
1647
  *
1386
- * If the message is NULL, returns NULL. If the body of the message
1648
+ * If the interaction is NULL, returns NULL. If the body of the request
1387
1649
  * is missing, then this function also returns NULL.
1388
1650
  */
1389
- const unsigned char *pactffi_sync_message_get_request_contents_bin(const SynchronousMessage *message);
1651
+ const unsigned char *pactffi_sync_http_get_request_contents_bin(const SynchronousHttp *interaction);
1390
1652
 
1391
1653
  /**
1392
- * Sets the request contents of the message as an array of bytes.
1654
+ * Sets the request contents of the interaction as an array of bytes.
1393
1655
  *
1394
- * * `message` - the message to set the request contents for
1656
+ * * `interaction` - the interaction to set the request contents for
1395
1657
  * * `contents` - pointer to contents to copy from
1396
1658
  * * `len` - number of bytes to copy from the contents pointer
1397
1659
  * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
@@ -1403,59 +1665,57 @@ const unsigned char *pactffi_sync_message_get_request_contents_bin(const Synchro
1403
1665
  *
1404
1666
  * # Error Handling
1405
1667
  *
1406
- * If the contents is a NULL pointer, it will set the message contents as null. If the content
1668
+ * If the contents is a NULL pointer, it will set the request contents as null. If the content
1407
1669
  * type is a null pointer, or can't be parsed, it will set the content type as unknown.
1408
1670
  */
1409
- void pactffi_sync_message_set_request_contents_bin(SynchronousMessage *message,
1410
- const unsigned char *contents,
1411
- size_t len,
1412
- const char *content_type);
1671
+ void pactffi_sync_http_set_request_contents_bin(SynchronousHttp *interaction,
1672
+ const unsigned char *contents,
1673
+ size_t len,
1674
+ const char *content_type);
1413
1675
 
1414
1676
  /**
1415
- * Get the number of response messages in the `SynchronousMessage`.
1677
+ * Get the response of a `SynchronousHttp` interaction.
1416
1678
  *
1417
1679
  * # Safety
1418
1680
  *
1419
- * The message pointer must point to a valid SynchronousMessage.
1681
+ * The data pointed to by the pointer this function returns will be deleted when the interaction
1682
+ * is deleted. Trying to use if after the interaction is deleted will result in undefined behaviour.
1420
1683
  *
1421
1684
  * # Error Handling
1422
1685
  *
1423
- * If the message is NULL, returns 0.
1686
+ * If the interaction is NULL, returns NULL.
1424
1687
  */
1425
- size_t pactffi_sync_message_get_number_responses(const SynchronousMessage *message);
1688
+ const HttpResponse *pactffi_sync_http_get_response(const SynchronousHttp *interaction);
1426
1689
 
1427
1690
  /**
1428
- * Get the response contents of a `SynchronousMessage` in string form.
1691
+ * Get the response contents of a `SynchronousHttp` interaction in string form.
1429
1692
  *
1430
1693
  * # Safety
1431
1694
  *
1432
1695
  * The returned string must be deleted with `pactffi_string_delete`.
1433
1696
  *
1434
- * The returned string can outlive the message.
1697
+ * The returned string can outlive the interaction.
1435
1698
  *
1436
1699
  * # Error Handling
1437
1700
  *
1438
- * If the message is NULL or the index is not valid, returns NULL.
1701
+ * If the interaction is NULL, returns NULL.
1439
1702
  *
1440
- * If the body of the response message is missing, then this function also returns NULL.
1703
+ * If the body of the response is missing, then this function also returns NULL.
1441
1704
  * This means there's no mechanism to differentiate with this function call alone between
1442
- * a NULL message and a missing message body.
1705
+ * a NULL body and a missing body.
1443
1706
  */
1444
- const char *pactffi_sync_message_get_response_contents(const SynchronousMessage *message,
1445
- size_t index);
1707
+ const char *pactffi_sync_http_get_response_contents(const SynchronousHttp *interaction);
1446
1708
 
1447
1709
  /**
1448
- * Sets the response contents of the message. If index is greater than the number of responses
1449
- * in the message, the responses will be padded with default values.
1710
+ * Sets the response contents of the interaction.
1450
1711
  *
1451
- * * `message` - the message to set the response contents for
1452
- * * `index` - index of the response to set. 0 is the first response.
1712
+ * * `interaction` - the interaction to set the response contents for
1453
1713
  * * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
1454
1714
  * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
1455
1715
  *
1456
1716
  * # Safety
1457
1717
  *
1458
- * The message contents and content type must either be NULL pointers, or point to valid
1718
+ * The response contents and content type must either be NULL pointers, or point to valid
1459
1719
  * UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
1460
1720
  *
1461
1721
  * # Error Handling
@@ -1463,13 +1723,12 @@ const char *pactffi_sync_message_get_response_contents(const SynchronousMessage
1463
1723
  * If the contents is a NULL pointer, it will set the response contents as null. If the content
1464
1724
  * type is a null pointer, or can't be parsed, it will set the content type as unknown.
1465
1725
  */
1466
- void pactffi_sync_message_set_response_contents(SynchronousMessage *message,
1467
- size_t index,
1468
- const char *contents,
1469
- const char *content_type);
1726
+ void pactffi_sync_http_set_response_contents(SynchronousHttp *interaction,
1727
+ const char *contents,
1728
+ const char *content_type);
1470
1729
 
1471
1730
  /**
1472
- * Get the length of the response contents of a `SynchronousMessage`.
1731
+ * Get the length of the response contents of a `SynchronousHttp` interaction.
1473
1732
  *
1474
1733
  * # Safety
1475
1734
  *
@@ -1477,36 +1736,31 @@ void pactffi_sync_message_set_response_contents(SynchronousMessage *message,
1477
1736
  *
1478
1737
  * # Error Handling
1479
1738
  *
1480
- * If the message is NULL or the index is not valid, returns 0. If the body of the request
1739
+ * If the interaction is NULL or the index is not valid, returns 0. If the body of the response
1481
1740
  * is missing, then this function also returns 0.
1482
1741
  */
1483
- size_t pactffi_sync_message_get_response_contents_length(const SynchronousMessage *message,
1484
- size_t index);
1742
+ size_t pactffi_sync_http_get_response_contents_length(const SynchronousHttp *interaction);
1485
1743
 
1486
1744
  /**
1487
- * Get the response contents of a `SynchronousMessage` as a pointer to an array of bytes.
1745
+ * Get the response contents of a `SynchronousHttp` interaction as a pointer to an array of bytes.
1488
1746
  *
1489
1747
  * # Safety
1490
1748
  *
1491
- * The number of bytes in the buffer will be returned by `pactffi_sync_message_get_response_contents_length`.
1492
- * It is safe to use the pointer while the message is not deleted or changed. Using the pointer
1493
- * after the message is mutated or deleted may lead to undefined behaviour.
1749
+ * The number of bytes in the buffer will be returned by `pactffi_sync_http_get_response_contents_length`.
1750
+ * It is safe to use the pointer while the interaction is not deleted or changed. Using the pointer
1751
+ * after the interaction is mutated or deleted may lead to undefined behaviour.
1494
1752
  *
1495
1753
  * # Error Handling
1496
1754
  *
1497
- * If the message is NULL or the index is not valid, returns NULL. If the body of the message
1755
+ * If the interaction is NULL, returns NULL. If the body of the response
1498
1756
  * is missing, then this function also returns NULL.
1499
1757
  */
1500
- const unsigned char *pactffi_sync_message_get_response_contents_bin(const SynchronousMessage *message,
1501
- size_t index);
1758
+ const unsigned char *pactffi_sync_http_get_response_contents_bin(const SynchronousHttp *interaction);
1502
1759
 
1503
1760
  /**
1504
- * Sets the response contents of the message at the given index as an array of bytes. If index
1505
- * is greater than the number of responses in the message, the responses will be padded with
1506
- * default values.
1761
+ * Sets the response contents of the `SynchronousHttp` interaction as an array of bytes.
1507
1762
  *
1508
- * * `message` - the message to set the response contents for
1509
- * * `index` - index of the response to set. 0 is the first response
1763
+ * * `interaction` - the interaction to set the response contents for
1510
1764
  * * `contents` - pointer to contents to copy from
1511
1765
  * * `len` - number of bytes to copy
1512
1766
  * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
@@ -1518,14 +1772,13 @@ const unsigned char *pactffi_sync_message_get_response_contents_bin(const Synchr
1518
1772
  *
1519
1773
  * # Error Handling
1520
1774
  *
1521
- * If the contents is a NULL pointer, it will set the message contents as null. If the content
1775
+ * If the contents is a NULL pointer, it will set the response contents as null. If the content
1522
1776
  * type is a null pointer, or can't be parsed, it will set the content type as unknown.
1523
1777
  */
1524
- void pactffi_sync_message_set_response_contents_bin(SynchronousMessage *message,
1525
- size_t index,
1526
- const unsigned char *contents,
1527
- size_t len,
1528
- const char *content_type);
1778
+ void pactffi_sync_http_set_response_contents_bin(SynchronousHttp *interaction,
1779
+ const unsigned char *contents,
1780
+ size_t len,
1781
+ const char *content_type);
1529
1782
 
1530
1783
  /**
1531
1784
  * Get a copy of the description.
@@ -1535,7 +1788,7 @@ void pactffi_sync_message_set_response_contents_bin(SynchronousMessage *message,
1535
1788
  * The returned string must be deleted with `pactffi_string_delete`.
1536
1789
  *
1537
1790
  * Since it is a copy, the returned string may safely outlive
1538
- * the `SynchronousMessage`.
1791
+ * the `SynchronousHttp` interaction.
1539
1792
  *
1540
1793
  * # Errors
1541
1794
  *
@@ -1544,10 +1797,10 @@ void pactffi_sync_message_set_response_contents_bin(SynchronousMessage *message,
1544
1797
  * This function may fail if the Rust string contains embedded
1545
1798
  * null ('\0') bytes.
1546
1799
  */
1547
- const char *pactffi_sync_message_get_description(const SynchronousMessage *message);
1800
+ const char *pactffi_sync_http_get_description(const SynchronousHttp *interaction);
1548
1801
 
1549
1802
  /**
1550
- * Write the `description` field on the `SynchronousMessage`.
1803
+ * Write the `description` field on the `SynchronousHttp`.
1551
1804
  *
1552
1805
  * # Safety
1553
1806
  *
@@ -1561,17 +1814,17 @@ const char *pactffi_sync_message_get_description(const SynchronousMessage *messa
1561
1814
  *
1562
1815
  * Errors will be reported with a non-zero return value.
1563
1816
  */
1564
- int pactffi_sync_message_set_description(SynchronousMessage *message, const char *description);
1817
+ int pactffi_sync_http_set_description(SynchronousHttp *interaction, const char *description);
1565
1818
 
1566
1819
  /**
1567
- * Get a copy of the provider state at the given index from this message.
1820
+ * Get a copy of the provider state at the given index from this interaction.
1568
1821
  *
1569
1822
  * # Safety
1570
1823
  *
1571
1824
  * The returned structure must be deleted with `provider_state_delete`.
1572
1825
  *
1573
1826
  * Since it is a copy, the returned structure may safely outlive
1574
- * the `SynchronousMessage`.
1827
+ * the `SynchronousHttp`.
1575
1828
  *
1576
1829
  * # Error Handling
1577
1830
  *
@@ -1580,8 +1833,8 @@ int pactffi_sync_message_set_description(SynchronousMessage *message, const char
1580
1833
  * This function may fail if the index requested is out of bounds,
1581
1834
  * or if any of the Rust strings contain embedded null ('\0') bytes.
1582
1835
  */
1583
- const ProviderState *pactffi_sync_message_get_provider_state(const SynchronousMessage *message,
1584
- unsigned int index);
1836
+ const ProviderState *pactffi_sync_http_get_provider_state(const SynchronousHttp *interaction,
1837
+ unsigned int index);
1585
1838
 
1586
1839
  /**
1587
1840
  * Get an iterator over provider states.
@@ -1594,160 +1847,205 @@ const ProviderState *pactffi_sync_message_get_provider_state(const SynchronousMe
1594
1847
  *
1595
1848
  * Returns NULL if an error occurs.
1596
1849
  */
1597
- ProviderStateIterator *pactffi_sync_message_get_provider_state_iter(SynchronousMessage *message);
1850
+ ProviderStateIterator *pactffi_sync_http_get_provider_state_iter(SynchronousHttp *interaction);
1598
1851
 
1599
1852
  /**
1600
- * Get a mutable pointer to a newly-created default interaction on the heap.
1853
+ * Casts this interaction to a `SynchronousHttp` interaction. Returns a NULL pointer if the
1854
+ * interaction can not be casted to a `SynchronousHttp` interaction (for instance, it is a
1855
+ * message interaction). The returned pointer must be freed with `pactffi_sync_http_delete`
1856
+ * when no longer required.
1601
1857
  *
1602
1858
  * # Safety
1859
+ * This function is safe as long as the interaction pointer is a valid pointer.
1603
1860
  *
1604
- * This function is safe.
1605
- *
1606
- * # Error Handling
1607
- *
1608
- * Returns NULL on error.
1861
+ * # Errors
1862
+ * On any error, this function will return a NULL pointer.
1609
1863
  */
1610
- SynchronousHttp *pactffi_sync_http_new();
1864
+ const SynchronousHttp *pactffi_pact_interaction_as_synchronous_http(const PactInteraction *interaction);
1611
1865
 
1612
1866
  /**
1613
- * Destroy the `SynchronousHttp` interaction being pointed to.
1867
+ * Casts this interaction to a `Message` interaction. Returns a NULL pointer if the
1868
+ * interaction can not be casted to a `Message` interaction (for instance, it is a
1869
+ * http interaction). The returned pointer must be freed with `pactffi_message_delete`
1870
+ * when no longer required.
1871
+ *
1872
+ * Note that if the interaction is a V4 `AsynchronousMessage`, it will be converted to a V3
1873
+ * `Message` before being returned.
1874
+ *
1875
+ * # Safety
1876
+ * This function is safe as long as the interaction pointer is a valid pointer.
1877
+ *
1878
+ * # Errors
1879
+ * On any error, this function will return a NULL pointer.
1614
1880
  */
1615
- void pactffi_sync_http_delete(SynchronousHttp *interaction);
1881
+ const Message *pactffi_pact_interaction_as_message(const PactInteraction *interaction);
1616
1882
 
1617
1883
  /**
1618
- * Get the request contents of a `SynchronousHttp` interaction in string form.
1884
+ * Casts this interaction to a `AsynchronousMessage` interaction. Returns a NULL pointer if the
1885
+ * interaction can not be casted to a `AsynchronousMessage` interaction (for instance, it is a
1886
+ * http interaction). The returned pointer must be freed with `pactffi_async_message_delete`
1887
+ * when no longer required.
1619
1888
  *
1620
- * # Safety
1889
+ * Note that if the interaction is a V3 `Message`, it will be converted to a V4
1890
+ * `AsynchronousMessage` before being returned.
1621
1891
  *
1622
- * The returned string must be deleted with `pactffi_string_delete`.
1892
+ * # Safety
1893
+ * This function is safe as long as the interaction pointer is a valid pointer.
1623
1894
  *
1624
- * The returned string can outlive the interaction.
1895
+ * # Errors
1896
+ * On any error, this function will return a NULL pointer.
1897
+ */
1898
+ const AsynchronousMessage *pactffi_pact_interaction_as_asynchronous_message(const PactInteraction *interaction);
1899
+
1900
+ /**
1901
+ * Casts this interaction to a `SynchronousMessage` interaction. Returns a NULL pointer if the
1902
+ * interaction can not be casted to a `SynchronousMessage` interaction (for instance, it is a
1903
+ * http interaction). The returned pointer must be freed with `pactffi_sync_message_delete`
1904
+ * when no longer required.
1625
1905
  *
1626
- * # Error Handling
1906
+ * # Safety
1907
+ * This function is safe as long as the interaction pointer is a valid pointer.
1627
1908
  *
1628
- * If the interaction is NULL, returns NULL. If the body of the request
1629
- * is missing, then this function also returns NULL. This means there's
1630
- * no mechanism to differentiate with this function call alone between
1631
- * a NULL body and a missing body.
1909
+ * # Errors
1910
+ * On any error, this function will return a NULL pointer.
1632
1911
  */
1633
- const char *pactffi_sync_http_get_request_contents(const SynchronousHttp *interaction);
1912
+ const SynchronousMessage *pactffi_pact_interaction_as_synchronous_message(const PactInteraction *interaction);
1634
1913
 
1635
1914
  /**
1636
- * Sets the request contents of the interaction.
1915
+ * Free the iterator when you're done using it.
1916
+ */
1917
+ void pactffi_pact_message_iter_delete(PactMessageIterator *iter);
1918
+
1919
+ /**
1920
+ * Get the next message from the message pact. As the messages returned are owned by the
1921
+ * iterator, they do not need to be deleted but will be cleaned up when the iterator is
1922
+ * deleted.
1637
1923
  *
1638
- * * `interaction` - the interaction to set the request contents for
1639
- * * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
1640
- * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
1924
+ * Will return a NULL pointer when the iterator has advanced past the end of the list.
1641
1925
  *
1642
1926
  * # Safety
1643
1927
  *
1644
- * The request contents and content type must either be NULL pointers, or point to valid
1645
- * UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
1928
+ * This function is safe.
1929
+ *
1930
+ * Deleting a message returned by the iterator can lead to undefined behaviour.
1646
1931
  *
1647
1932
  * # Error Handling
1648
1933
  *
1649
- * If the contents is a NULL pointer, it will set the request contents as null. If the content
1650
- * type is a null pointer, or can't be parsed, it will set the content type as unknown.
1934
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1651
1935
  */
1652
- void pactffi_sync_http_set_request_contents(SynchronousHttp *interaction,
1653
- const char *contents,
1654
- const char *content_type);
1936
+ Message *pactffi_pact_message_iter_next(PactMessageIterator *iter);
1655
1937
 
1656
1938
  /**
1657
- * Get the length of the request contents of a `SynchronousHttp` interaction.
1939
+ * Get the next synchronous request/response message from the V4 pact. As the messages returned are owned by the
1940
+ * iterator, they do not need to be deleted but will be cleaned up when the iterator is
1941
+ * deleted.
1942
+ *
1943
+ * Will return a NULL pointer when the iterator has advanced past the end of the list.
1658
1944
  *
1659
1945
  * # Safety
1660
1946
  *
1661
1947
  * This function is safe.
1662
1948
  *
1949
+ * Deleting a message returned by the iterator can lead to undefined behaviour.
1950
+ *
1663
1951
  * # Error Handling
1664
1952
  *
1665
- * If the interaction is NULL, returns 0. If the body of the request
1666
- * is missing, then this function also returns 0.
1953
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1667
1954
  */
1668
- size_t pactffi_sync_http_get_request_contents_length(const SynchronousHttp *interaction);
1955
+ SynchronousMessage *pactffi_pact_sync_message_iter_next(PactSyncMessageIterator *iter);
1669
1956
 
1670
1957
  /**
1671
- * Get the request contents of a `SynchronousHttp` interaction as a pointer to an array of bytes.
1958
+ * Free the iterator when you're done using it.
1959
+ */
1960
+ void pactffi_pact_sync_message_iter_delete(PactSyncMessageIterator *iter);
1961
+
1962
+ /**
1963
+ * Get the next synchronous HTTP request/response interaction from the V4 pact. As the
1964
+ * interactions returned are owned by the iterator, they do not need to be deleted but
1965
+ * will be cleaned up when the iterator is deleted.
1966
+ *
1967
+ * Will return a NULL pointer when the iterator has advanced past the end of the list.
1672
1968
  *
1673
1969
  * # Safety
1674
1970
  *
1675
- * The number of bytes in the buffer will be returned by `pactffi_sync_http_get_request_contents_length`.
1676
- * It is safe to use the pointer while the interaction is not deleted or changed. Using the pointer
1677
- * after the interaction is mutated or deleted may lead to undefined behaviour.
1971
+ * This function is safe.
1972
+ *
1973
+ * Deleting an interaction returned by the iterator can lead to undefined behaviour.
1678
1974
  *
1679
1975
  * # Error Handling
1680
1976
  *
1681
- * If the interaction is NULL, returns NULL. If the body of the request
1682
- * is missing, then this function also returns NULL.
1977
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1683
1978
  */
1684
- const unsigned char *pactffi_sync_http_get_request_contents_bin(const SynchronousHttp *interaction);
1979
+ SynchronousHttp *pactffi_pact_sync_http_iter_next(PactSyncHttpIterator *iter);
1685
1980
 
1686
1981
  /**
1687
- * Sets the request contents of the interaction as an array of bytes.
1982
+ * Free the iterator when you're done using it.
1983
+ */
1984
+ void pactffi_pact_sync_http_iter_delete(PactSyncHttpIterator *iter);
1985
+
1986
+ /**
1987
+ * Get the next interaction from the pact. As the interactions returned are owned by the
1988
+ * iterator, they do not need to be deleted but will be cleaned up when the iterator is
1989
+ * deleted.
1688
1990
  *
1689
- * * `interaction` - the interaction to set the request contents for
1690
- * * `contents` - pointer to contents to copy from
1691
- * * `len` - number of bytes to copy from the contents pointer
1692
- * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
1991
+ * Will return a NULL pointer when the iterator has advanced past the end of the list.
1693
1992
  *
1694
1993
  * # Safety
1695
1994
  *
1696
- * The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
1697
- * and consecutive. Otherwise behaviour is undefined.
1995
+ * This function is safe.
1996
+ *
1997
+ * Deleting an interaction returned by the iterator can lead to undefined behaviour.
1698
1998
  *
1699
1999
  * # Error Handling
1700
2000
  *
1701
- * If the contents is a NULL pointer, it will set the request contents as null. If the content
1702
- * type is a null pointer, or can't be parsed, it will set the content type as unknown.
2001
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
1703
2002
  */
1704
- void pactffi_sync_http_set_request_contents_bin(SynchronousHttp *interaction,
1705
- const unsigned char *contents,
1706
- size_t len,
1707
- const char *content_type);
2003
+ const PactInteraction *pactffi_pact_interaction_iter_next(PactInteractionIterator *iter);
1708
2004
 
1709
2005
  /**
1710
- * Get the response contents of a `SynchronousHttp` interaction in string form.
1711
- *
1712
- * # Safety
2006
+ * Free the iterator when you're done using it.
2007
+ */
2008
+ void pactffi_pact_interaction_iter_delete(PactInteractionIterator *iter);
2009
+
2010
+ /**
2011
+ * Get the JSON form of the matching rule.
1713
2012
  *
1714
2013
  * The returned string must be deleted with `pactffi_string_delete`.
1715
2014
  *
1716
- * The returned string can outlive the interaction.
1717
- *
1718
- * # Error Handling
1719
- *
1720
- * If the interaction is NULL, returns NULL.
2015
+ * # Safety
1721
2016
  *
1722
- * If the body of the response is missing, then this function also returns NULL.
1723
- * This means there's no mechanism to differentiate with this function call alone between
1724
- * a NULL body and a missing body.
2017
+ * This function will fail if it is passed a NULL pointer, or the iterator that owns the
2018
+ * value of the matching rule has been deleted.
1725
2019
  */
1726
- const char *pactffi_sync_http_get_response_contents(const SynchronousHttp *interaction);
2020
+ const char *pactffi_matching_rule_to_json(const MatchingRule *rule);
1727
2021
 
1728
2022
  /**
1729
- * Sets the response contents of the interaction.
2023
+ * Free the iterator when you're done using it.
2024
+ */
2025
+ void pactffi_matching_rules_iter_delete(MatchingRuleCategoryIterator *iter);
2026
+
2027
+ /**
2028
+ * Get the next path and matching rule out of the iterator, if possible.
1730
2029
  *
1731
- * * `interaction` - the interaction to set the response contents for
1732
- * * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
1733
- * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
2030
+ * The returned pointer must be deleted with `pactffi_matching_rules_iter_pair_delete`.
1734
2031
  *
1735
2032
  * # Safety
1736
2033
  *
1737
- * The response contents and content type must either be NULL pointers, or point to valid
1738
- * UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
2034
+ * The underlying data is owned by the `MatchingRuleKeyValuePair`, so is always safe to use.
1739
2035
  *
1740
2036
  * # Error Handling
1741
2037
  *
1742
- * If the contents is a NULL pointer, it will set the response contents as null. If the content
1743
- * type is a null pointer, or can't be parsed, it will set the content type as unknown.
2038
+ * If no further data is present, returns NULL.
1744
2039
  */
1745
- void pactffi_sync_http_set_response_contents(SynchronousHttp *interaction,
1746
- const char *contents,
1747
- const char *content_type);
2040
+ const MatchingRuleKeyValuePair *pactffi_matching_rules_iter_next(MatchingRuleCategoryIterator *iter);
1748
2041
 
1749
2042
  /**
1750
- * Get the length of the response contents of a `SynchronousHttp` interaction.
2043
+ * Free a pair of key and value returned from `message_metadata_iter_next`.
2044
+ */
2045
+ void pactffi_matching_rules_iter_pair_delete(const MatchingRuleKeyValuePair *pair);
2046
+
2047
+ /**
2048
+ * Get a mutable pointer to a newly-created default message on the heap.
1751
2049
  *
1752
2050
  * # Safety
1753
2051
  *
@@ -1755,49 +2053,123 @@ void pactffi_sync_http_set_response_contents(SynchronousHttp *interaction,
1755
2053
  *
1756
2054
  * # Error Handling
1757
2055
  *
1758
- * If the interaction is NULL or the index is not valid, returns 0. If the body of the response
1759
- * is missing, then this function also returns 0.
2056
+ * Returns NULL on error.
1760
2057
  */
1761
- size_t pactffi_sync_http_get_response_contents_length(const SynchronousHttp *interaction);
2058
+ Message *pactffi_message_new();
1762
2059
 
1763
2060
  /**
1764
- * Get the response contents of a `SynchronousHttp` interaction as a pointer to an array of bytes.
2061
+ * Constructs a `Message` from the JSON string
1765
2062
  *
1766
2063
  * # Safety
1767
2064
  *
1768
- * The number of bytes in the buffer will be returned by `pactffi_sync_http_get_response_contents_length`.
1769
- * It is safe to use the pointer while the interaction is not deleted or changed. Using the pointer
1770
- * after the interaction is mutated or deleted may lead to undefined behaviour.
2065
+ * This function is safe.
1771
2066
  *
1772
2067
  * # Error Handling
1773
2068
  *
1774
- * If the interaction is NULL, returns NULL. If the body of the response
1775
- * is missing, then this function also returns NULL.
2069
+ * If the JSON string is invalid or not UTF-8 encoded, returns a NULL.
1776
2070
  */
1777
- const unsigned char *pactffi_sync_http_get_response_contents_bin(const SynchronousHttp *interaction);
2071
+ Message *pactffi_message_new_from_json(unsigned int index,
2072
+ const char *json_str,
2073
+ PactSpecification spec_version);
1778
2074
 
1779
2075
  /**
1780
- * Sets the response contents of the `SynchronousHttp` interaction as an array of bytes.
1781
- *
1782
- * * `interaction` - the interaction to set the response contents for
1783
- * * `contents` - pointer to contents to copy from
1784
- * * `len` - number of bytes to copy
1785
- * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
2076
+ * Constructs a `Message` from a body with a given content-type.
1786
2077
  *
1787
2078
  * # Safety
1788
2079
  *
1789
- * The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
1790
- * and consecutive. Otherwise behaviour is undefined.
2080
+ * This function is safe.
1791
2081
  *
1792
2082
  * # Error Handling
1793
2083
  *
1794
- * If the contents is a NULL pointer, it will set the response contents as null. If the content
1795
- * type is a null pointer, or can't be parsed, it will set the content type as unknown.
2084
+ * If the body or content type are invalid or not UTF-8 encoded, returns NULL.
1796
2085
  */
1797
- void pactffi_sync_http_set_response_contents_bin(SynchronousHttp *interaction,
1798
- const unsigned char *contents,
1799
- size_t len,
1800
- const char *content_type);
2086
+ Message *pactffi_message_new_from_body(const char *body, const char *content_type);
2087
+
2088
+ /**
2089
+ * Destroy the `Message` being pointed to.
2090
+ */
2091
+ void pactffi_message_delete(Message *message);
2092
+
2093
+ /**
2094
+ * Get the contents of a `Message` in string form.
2095
+ *
2096
+ * # Safety
2097
+ *
2098
+ * The returned string must be deleted with `pactffi_string_delete`.
2099
+ *
2100
+ * The returned string can outlive the message.
2101
+ *
2102
+ * # Error Handling
2103
+ *
2104
+ * If the message is NULL, returns NULL. If the body of the message
2105
+ * is missing, then this function also returns NULL. This means there's
2106
+ * no mechanism to differentiate with this function call alone between
2107
+ * a NULL message and a missing message body.
2108
+ */
2109
+ const char *pactffi_message_get_contents(const Message *message);
2110
+
2111
+ /**
2112
+ * Sets the contents of the message.
2113
+ *
2114
+ * # Safety
2115
+ *
2116
+ * The message contents and content type must either be NULL pointers, or point to valid
2117
+ * UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
2118
+ *
2119
+ * # Error Handling
2120
+ *
2121
+ * If the contents is a NULL pointer, it will set the message contents as null. If the content
2122
+ * type is a null pointer, or can't be parsed, it will set the content type as unknown.
2123
+ */
2124
+ void pactffi_message_set_contents(Message *message, const char *contents, const char *content_type);
2125
+
2126
+ /**
2127
+ * Get the length of the contents of a `Message`.
2128
+ *
2129
+ * # Safety
2130
+ *
2131
+ * This function is safe.
2132
+ *
2133
+ * # Error Handling
2134
+ *
2135
+ * If the message is NULL, returns 0. If the body of the message
2136
+ * is missing, then this function also returns 0.
2137
+ */
2138
+ size_t pactffi_message_get_contents_length(const Message *message);
2139
+
2140
+ /**
2141
+ * Get the contents of a `Message` as a pointer to an array of bytes.
2142
+ *
2143
+ * # Safety
2144
+ *
2145
+ * The number of bytes in the buffer will be returned by `pactffi_message_get_contents_length`.
2146
+ * It is safe to use the pointer while the message is not deleted or changed. Using the pointer
2147
+ * after the message is mutated or deleted may lead to undefined behaviour.
2148
+ *
2149
+ * # Error Handling
2150
+ *
2151
+ * If the message is NULL, returns NULL. If the body of the message
2152
+ * is missing, then this function also returns NULL.
2153
+ */
2154
+ const unsigned char *pactffi_message_get_contents_bin(const Message *message);
2155
+
2156
+ /**
2157
+ * Sets the contents of the message as an array of bytes.
2158
+ *
2159
+ * # Safety
2160
+ *
2161
+ * The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
2162
+ * and consecutive. Otherwise behaviour is undefined.
2163
+ *
2164
+ * # Error Handling
2165
+ *
2166
+ * If the contents is a NULL pointer, it will set the message contents as null. If the content
2167
+ * type is a null pointer, or can't be parsed, it will set the content type as unknown.
2168
+ */
2169
+ void pactffi_message_set_contents_bin(Message *message,
2170
+ const unsigned char *contents,
2171
+ size_t len,
2172
+ const char *content_type);
1801
2173
 
1802
2174
  /**
1803
2175
  * Get a copy of the description.
@@ -1807,7 +2179,7 @@ void pactffi_sync_http_set_response_contents_bin(SynchronousHttp *interaction,
1807
2179
  * The returned string must be deleted with `pactffi_string_delete`.
1808
2180
  *
1809
2181
  * Since it is a copy, the returned string may safely outlive
1810
- * the `SynchronousHttp` interaction.
2182
+ * the `Message`.
1811
2183
  *
1812
2184
  * # Errors
1813
2185
  *
@@ -1816,10 +2188,10 @@ void pactffi_sync_http_set_response_contents_bin(SynchronousHttp *interaction,
1816
2188
  * This function may fail if the Rust string contains embedded
1817
2189
  * null ('\0') bytes.
1818
2190
  */
1819
- const char *pactffi_sync_http_get_description(const SynchronousHttp *interaction);
2191
+ const char *pactffi_message_get_description(const Message *message);
1820
2192
 
1821
2193
  /**
1822
- * Write the `description` field on the `SynchronousHttp`.
2194
+ * Write the `description` field on the `Message`.
1823
2195
  *
1824
2196
  * # Safety
1825
2197
  *
@@ -1833,17 +2205,17 @@ const char *pactffi_sync_http_get_description(const SynchronousHttp *interaction
1833
2205
  *
1834
2206
  * Errors will be reported with a non-zero return value.
1835
2207
  */
1836
- int pactffi_sync_http_set_description(SynchronousHttp *interaction, const char *description);
2208
+ int pactffi_message_set_description(Message *message, const char *description);
1837
2209
 
1838
2210
  /**
1839
- * Get a copy of the provider state at the given index from this interaction.
2211
+ * Get a copy of the provider state at the given index from this message.
1840
2212
  *
1841
2213
  * # Safety
1842
2214
  *
1843
2215
  * The returned structure must be deleted with `provider_state_delete`.
1844
2216
  *
1845
2217
  * Since it is a copy, the returned structure may safely outlive
1846
- * the `SynchronousHttp`.
2218
+ * the `Message`.
1847
2219
  *
1848
2220
  * # Error Handling
1849
2221
  *
@@ -1852,8 +2224,7 @@ int pactffi_sync_http_set_description(SynchronousHttp *interaction, const char *
1852
2224
  * This function may fail if the index requested is out of bounds,
1853
2225
  * or if any of the Rust strings contain embedded null ('\0') bytes.
1854
2226
  */
1855
- const ProviderState *pactffi_sync_http_get_provider_state(const SynchronousHttp *interaction,
1856
- unsigned int index);
2227
+ const ProviderState *pactffi_message_get_provider_state(const Message *message, unsigned int index);
1857
2228
 
1858
2229
  /**
1859
2230
  * Get an iterator over provider states.
@@ -1866,90 +2237,137 @@ const ProviderState *pactffi_sync_http_get_provider_state(const SynchronousHttp
1866
2237
  *
1867
2238
  * Returns NULL if an error occurs.
1868
2239
  */
1869
- ProviderStateIterator *pactffi_sync_http_get_provider_state_iter(SynchronousHttp *interaction);
2240
+ ProviderStateIterator *pactffi_message_get_provider_state_iter(Message *message);
1870
2241
 
1871
2242
  /**
1872
- * Parse a matcher definition string into a MatchingRuleDefinition containing the example value,
1873
- * and matching rules and any generator.
1874
- *
1875
- * The following are examples of matching rule definitions:
1876
- * * `matching(type,'Name')` - type matcher with string value 'Name'
1877
- * * `matching(number,100)` - number matcher
1878
- * * `matching(datetime, 'yyyy-MM-dd','2000-01-01')` - datetime matcher with format string
2243
+ * Get the next value from the iterator.
1879
2244
  *
1880
- * See [Matching Rule definition expressions](https://docs.rs/pact_models/latest/pact_models/matchingrules/expressions/index.html).
2245
+ * # Safety
1881
2246
  *
1882
- * The returned value needs to be freed up with the `pactffi_matcher_definition_delete` function.
2247
+ * The underlying data must not change during iteration.
1883
2248
  *
1884
- * # Errors
1885
- * If the expression is invalid, the MatchingRuleDefinition error will be set. You can check for
1886
- * this value with the `pactffi_matcher_definition_error` function.
2249
+ * If a previous call panicked, then the internal mutex will have been poisoned and this
2250
+ * function will return NULL.
1887
2251
  *
1888
- * # Safety
2252
+ * # Error Handling
1889
2253
  *
1890
- * This function is safe if the expression is a valid NULL terminated string pointer.
2254
+ * Returns NULL if an error occurs.
1891
2255
  */
1892
- const MatchingRuleDefinitionResult *pactffi_parse_matcher_definition(const char *expression);
2256
+ ProviderState *pactffi_provider_state_iter_next(ProviderStateIterator *iter);
1893
2257
 
1894
2258
  /**
1895
- * Returns any error message from parsing a matching definition expression. If there is no error,
1896
- * it will return a NULL pointer, otherwise returns the error message as a NULL-terminated string.
1897
- * The returned string must be freed using the `pactffi_string_delete` function once done with it.
2259
+ * Delete the iterator.
1898
2260
  */
1899
- const char *pactffi_matcher_definition_error(const MatchingRuleDefinitionResult *definition);
2261
+ void pactffi_provider_state_iter_delete(ProviderStateIterator *iter);
1900
2262
 
1901
2263
  /**
1902
- * Returns the value from parsing a matching definition expression. If there was an error,
1903
- * it will return a NULL pointer, otherwise returns the value as a NULL-terminated string.
1904
- * The returned string must be freed using the `pactffi_string_delete` function once done with it.
2264
+ * Get a copy of the metadata value indexed by `key`.
1905
2265
  *
1906
- * Note that different expressions values can have types other than a string. Use
1907
- * `pactffi_matcher_definition_value_type` to get the actual type of the value. This function
1908
- * will always return the string representation of the value.
2266
+ * # Safety
2267
+ *
2268
+ * The returned string must be deleted with `pactffi_string_delete`.
2269
+ *
2270
+ * Since it is a copy, the returned string may safely outlive
2271
+ * the `Message`.
2272
+ *
2273
+ * The returned pointer will be NULL if the metadata does not contain
2274
+ * the given key, or if an error occurred.
2275
+ *
2276
+ * # Error Handling
2277
+ *
2278
+ * On failure, this function will return a NULL pointer.
2279
+ *
2280
+ * This function may fail if the provided `key` string contains
2281
+ * invalid UTF-8, or if the Rust string contains embedded null ('\0')
2282
+ * bytes.
1909
2283
  */
1910
- const char *pactffi_matcher_definition_value(const MatchingRuleDefinitionResult *definition);
2284
+ const char *pactffi_message_find_metadata(const Message *message, const char *key);
1911
2285
 
1912
2286
  /**
1913
- * Frees the memory used by the result of parsing the matching definition expression
2287
+ * Insert the (`key`, `value`) pair into this Message's
2288
+ * `metadata` HashMap.
2289
+ *
2290
+ * # Safety
2291
+ *
2292
+ * This function returns an enum indicating the result;
2293
+ * see the comments on HashMapInsertStatus for details.
2294
+ *
2295
+ * # Error Handling
2296
+ *
2297
+ * This function may fail if the provided `key` or `value` strings
2298
+ * contain invalid UTF-8.
1914
2299
  */
1915
- void pactffi_matcher_definition_delete(const MatchingRuleDefinitionResult *definition);
2300
+ int pactffi_message_insert_metadata(Message *message, const char *key, const char *value);
1916
2301
 
1917
2302
  /**
1918
- * Returns the generator from parsing a matching definition expression. If there was an error or
1919
- * there is no associated generator, it will return a NULL pointer, otherwise returns the generator
1920
- * as a pointer.
2303
+ * Get the next key and value out of the iterator, if possible.
1921
2304
  *
1922
- * The generator pointer will be a valid pointer as long as `pactffi_matcher_definition_delete`
1923
- * has not been called on the definition. Using the generator pointer after the definition
1924
- * has been deleted will result in undefined behaviour.
2305
+ * The returned pointer must be deleted with `pactffi_message_metadata_pair_delete`.
2306
+ *
2307
+ * # Safety
2308
+ *
2309
+ * The underlying data must not change during iteration.
2310
+ *
2311
+ * # Error Handling
2312
+ *
2313
+ * If no further data is present, returns NULL.
1925
2314
  */
1926
- const Generator *pactffi_matcher_definition_generator(const MatchingRuleDefinitionResult *definition);
2315
+ MessageMetadataPair *pactffi_message_metadata_iter_next(MessageMetadataIterator *iter);
1927
2316
 
1928
2317
  /**
1929
- * Returns the type of the value from parsing a matching definition expression. If there was an
1930
- * error parsing the expression, it will return Unknown.
2318
+ * Get an iterator over the metadata of a message.
2319
+ *
2320
+ * # Safety
2321
+ *
2322
+ * This iterator carries a pointer to the message, and must
2323
+ * not outlive the message.
2324
+ *
2325
+ * The message metadata also must not be modified during iteration. If it is,
2326
+ * the old iterator must be deleted and a new iterator created.
2327
+ *
2328
+ * # Error Handling
2329
+ *
2330
+ * On failure, this function will return a NULL pointer.
2331
+ *
2332
+ * This function may fail if any of the Rust strings contain
2333
+ * embedded null ('\0') bytes.
1931
2334
  */
1932
- ExpressionValueType pactffi_matcher_definition_value_type(const MatchingRuleDefinitionResult *definition);
2335
+ MessageMetadataIterator *pactffi_message_get_metadata_iter(Message *message);
1933
2336
 
1934
2337
  /**
1935
- * Free the iterator when you're done using it.
2338
+ * Free the metadata iterator when you're done using it.
1936
2339
  */
1937
- void pactffi_matching_rule_iter_delete(MatchingRuleIterator *iter);
2340
+ void pactffi_message_metadata_iter_delete(MessageMetadataIterator *iter);
1938
2341
 
1939
2342
  /**
1940
- * Returns an iterator over the matching rules from the parsed definition. The iterator needs to
1941
- * be deleted with the `pactffi_matching_rule_iter_delete` function once done with it.
1942
- *
1943
- * If there was an error parsing the expression, this function will return a NULL pointer.
2343
+ * Free a pair of key and value returned from `message_metadata_iter_next`.
1944
2344
  */
1945
- MatchingRuleIterator *pactffi_matcher_definition_iter(const MatchingRuleDefinitionResult *definition);
2345
+ void pactffi_message_metadata_pair_delete(MessageMetadataPair *pair);
1946
2346
 
1947
2347
  /**
1948
- * Get the next matching rule or reference from the iterator. As the values returned are owned
1949
- * by the iterator, they do not need to be deleted but will be cleaned up when the iterator is
1950
- * deleted.
2348
+ * Construct a new `MessagePact` from the JSON string.
2349
+ * The provided file name is used when generating error messages.
1951
2350
  *
1952
- * Will return a NULL pointer when the iterator has advanced past the end of the list.
2351
+ * # Safety
2352
+ *
2353
+ * The `file_name` and `json_str` parameters must both be valid UTF-8
2354
+ * encoded strings.
2355
+ *
2356
+ * # Error Handling
2357
+ *
2358
+ * On error, this function will return a null pointer.
2359
+ */
2360
+ MessagePact *pactffi_message_pact_new_from_json(const char *file_name, const char *json_str);
2361
+
2362
+ /**
2363
+ * Delete the `MessagePact` being pointed to.
2364
+ */
2365
+ void pactffi_message_pact_delete(MessagePact *message_pact);
2366
+
2367
+ /**
2368
+ * Get a pointer to the Consumer struct inside the MessagePact.
2369
+ * This is a mutable borrow: The caller may mutate the Consumer
2370
+ * through this pointer.
1953
2371
  *
1954
2372
  * # Safety
1955
2373
  *
@@ -1957,166 +2375,576 @@ MatchingRuleIterator *pactffi_matcher_definition_iter(const MatchingRuleDefiniti
1957
2375
  *
1958
2376
  * # Error Handling
1959
2377
  *
1960
- * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
2378
+ * This function will only fail if it is passed a NULL pointer.
2379
+ * In the case of error, a NULL pointer will be returned.
1961
2380
  */
1962
- const MatchingRuleResult *pactffi_matching_rule_iter_next(MatchingRuleIterator *iter);
2381
+ Consumer *pactffi_message_pact_get_consumer(MessagePact *message_pact);
1963
2382
 
1964
2383
  /**
1965
- * Return the ID of the matching rule.
1966
- *
1967
- * The ID corresponds to the following rules:
1968
- * | Rule | ID |
1969
- * | ---- | -- |
1970
- * | Equality | 1 |
1971
- * | Regex | 2 |
1972
- * | Type | 3 |
1973
- * | MinType | 4 |
1974
- * | MaxType | 5 |
1975
- * | MinMaxType | 6 |
1976
- * | Timestamp | 7 |
1977
- * | Time | 8 |
1978
- * | Date | 9 |
1979
- * | Include | 10 |
1980
- * | Number | 11 |
1981
- * | Integer | 12 |
1982
- * | Decimal | 13 |
1983
- * | Null | 14 |
1984
- * | ContentType | 15 |
1985
- * | ArrayContains | 16 |
1986
- * | Values | 17 |
1987
- * | Boolean | 18 |
1988
- * | StatusCode | 19 |
1989
- * | NotEmpty | 20 |
1990
- * | Semver | 21 |
1991
- * | EachKey | 22 |
1992
- * | EachValue | 23 |
2384
+ * Get a pointer to the Provider struct inside the MessagePact.
2385
+ * This is a mutable borrow: The caller may mutate the Provider
2386
+ * through this pointer.
2387
+ *
2388
+ * # Safety
2389
+ *
2390
+ * This function is safe.
2391
+ *
2392
+ * # Error Handling
2393
+ *
2394
+ * This function will only fail if it is passed a NULL pointer.
2395
+ * In the case of error, a NULL pointer will be returned.
2396
+ */
2397
+ Provider *pactffi_message_pact_get_provider(MessagePact *message_pact);
2398
+
2399
+ /**
2400
+ * Get an iterator over the messages of a message pact.
2401
+ *
2402
+ * # Safety
2403
+ *
2404
+ * This iterator carries a pointer to the message pact, and must
2405
+ * not outlive the message pact.
2406
+ *
2407
+ * The message pact messages also must not be modified during iteration.
2408
+ * If they are, the old iterator must be deleted and a new iterator created.
2409
+ *
2410
+ * # Error Handling
2411
+ *
2412
+ * On failure, this function will return a NULL pointer.
2413
+ *
2414
+ * This function may fail if any of the Rust strings contain embedded
2415
+ * null ('\0') bytes.
2416
+ */
2417
+ MessagePactMessageIterator *pactffi_message_pact_get_message_iter(MessagePact *message_pact);
2418
+
2419
+ /**
2420
+ * Get the next message from the message pact.
2421
+ *
2422
+ * # Safety
2423
+ *
2424
+ * This function is safe.
2425
+ *
2426
+ * # Error Handling
2427
+ *
2428
+ * This function will return a NULL pointer if passed a NULL pointer or if an error occurs.
2429
+ */
2430
+ Message *pactffi_message_pact_message_iter_next(MessagePactMessageIterator *iter);
2431
+
2432
+ /**
2433
+ * Delete the iterator.
2434
+ */
2435
+ void pactffi_message_pact_message_iter_delete(MessagePactMessageIterator *iter);
2436
+
2437
+ /**
2438
+ * Get a copy of the metadata value indexed by `key1` and `key2`.
2439
+ *
2440
+ * # Safety
2441
+ *
2442
+ * Since it is a copy, the returned string may safely outlive
2443
+ * the `Message`.
2444
+ *
2445
+ * The returned string must be deleted with `pactffi_string_delete`.
2446
+ *
2447
+ * The returned pointer will be NULL if the metadata does not contain
2448
+ * the given key, or if an error occurred.
2449
+ *
2450
+ * # Error Handling
2451
+ *
2452
+ * On failure, this function will return a NULL pointer.
2453
+ *
2454
+ * This function may fail if the provided `key1` or `key2` strings contains
2455
+ * invalid UTF-8, or if the Rust string contains embedded null ('\0')
2456
+ * bytes.
2457
+ */
2458
+ const char *pactffi_message_pact_find_metadata(const MessagePact *message_pact,
2459
+ const char *key1,
2460
+ const char *key2);
2461
+
2462
+ /**
2463
+ * Get an iterator over the metadata of a message pact.
2464
+ *
2465
+ * # Safety
2466
+ *
2467
+ * This iterator carries a pointer to the message pact, and must
2468
+ * not outlive the message pact.
2469
+ *
2470
+ * The message pact metadata also must not be modified during iteration. If it is,
2471
+ * the old iterator must be deleted and a new iterator created.
2472
+ *
2473
+ * # Error Handling
2474
+ *
2475
+ * On failure, this function will return a NULL pointer.
2476
+ *
2477
+ * This function may fail if any of the Rust strings contain
2478
+ * embedded null ('\0') bytes.
2479
+ */
2480
+ MessagePactMetadataIterator *pactffi_message_pact_get_metadata_iter(MessagePact *message_pact);
2481
+
2482
+ /**
2483
+ * Get the next triple out of the iterator, if possible
2484
+ *
2485
+ * # Safety
2486
+ *
2487
+ * This operation is invalid if the underlying data has been changed during iteration.
2488
+ *
2489
+ * # Error Handling
2490
+ *
2491
+ * Returns null if no next element is present.
2492
+ */
2493
+ MessagePactMetadataTriple *pactffi_message_pact_metadata_iter_next(MessagePactMetadataIterator *iter);
2494
+
2495
+ /**
2496
+ * Free the metadata iterator when you're done using it.
2497
+ */
2498
+ void pactffi_message_pact_metadata_iter_delete(MessagePactMetadataIterator *iter);
2499
+
2500
+ /**
2501
+ * Free a triple returned from `pactffi_message_pact_metadata_iter_next`.
2502
+ */
2503
+ void pactffi_message_pact_metadata_triple_delete(MessagePactMetadataTriple *triple);
2504
+
2505
+ /**
2506
+ * Get a copy of this provider's name.
2507
+ *
2508
+ * The copy must be deleted with `pactffi_string_delete`.
2509
+ *
2510
+ * # Usage
2511
+ *
2512
+ * ```c
2513
+ * // Assuming `file_name` and `json_str` are already defined.
2514
+ *
2515
+ * MessagePact *message_pact = pactffi_message_pact_new_from_json(file_name, json_str);
2516
+ * if (message_pact == NULLPTR) {
2517
+ * // handle error.
2518
+ * }
2519
+ *
2520
+ * Provider *provider = pactffi_message_pact_get_provider(message_pact);
2521
+ * if (provider == NULLPTR) {
2522
+ * // handle error.
2523
+ * }
2524
+ *
2525
+ * char *name = pactffi_provider_get_name(provider);
2526
+ * if (name == NULL) {
2527
+ * // handle error.
2528
+ * }
2529
+ *
2530
+ * printf("%s\n", name);
2531
+ *
2532
+ * pactffi_string_delete(name);
2533
+ * ```
2534
+ *
2535
+ * # Errors
2536
+ *
2537
+ * This function will fail if it is passed a NULL pointer,
2538
+ * or the Rust string contains an embedded NULL byte.
2539
+ * In the case of error, a NULL pointer will be returned.
2540
+ */
2541
+ const char *pactffi_provider_get_name(const Provider *provider);
2542
+
2543
+ /**
2544
+ * Get the provider from a Pact. This returns a copy of the provider model, and needs to
2545
+ * be cleaned up with `pactffi_pact_provider_delete` when no longer required.
2546
+ *
2547
+ * # Errors
2548
+ *
2549
+ * This function will fail if it is passed a NULL pointer.
2550
+ * In the case of error, a NULL pointer will be returned.
2551
+ */
2552
+ const Provider *pactffi_pact_get_provider(const Pact *pact);
2553
+
2554
+ /**
2555
+ * Frees the memory used by the Pact provider
2556
+ */
2557
+ void pactffi_pact_provider_delete(const Provider *provider);
2558
+
2559
+ /**
2560
+ * Get the name of the provider state as a string, which needs to be deleted with `pactffi_string_delete`.
2561
+ *
2562
+ * # Safety
2563
+ *
2564
+ * This function is safe.
2565
+ *
2566
+ * # Error Handling
2567
+ *
2568
+ * If the provider_state param is NULL, this returns NULL.
2569
+ */
2570
+ const char *pactffi_provider_state_get_name(const ProviderState *provider_state);
2571
+
2572
+ /**
2573
+ * Get an iterator over the params of a provider state.
2574
+ *
2575
+ * # Safety
2576
+ *
2577
+ * This iterator carries a pointer to the provider state, and must
2578
+ * not outlive the provider state.
2579
+ *
2580
+ * The provider state params also must not be modified during iteration. If it is,
2581
+ * the old iterator must be deleted and a new iterator created.
2582
+ *
2583
+ * # Errors
2584
+ *
2585
+ * On failure, this function will return a NULL pointer.
2586
+ *
2587
+ * This function may fail if any of the Rust strings contain
2588
+ * embedded null ('\0') bytes.
2589
+ */
2590
+ ProviderStateParamIterator *pactffi_provider_state_get_param_iter(ProviderState *provider_state);
2591
+
2592
+ /**
2593
+ * Get the next key and value out of the iterator, if possible
2594
+ *
2595
+ * Returns a pointer to a heap allocated array of 2 elements, the pointer to the
2596
+ * key string on the heap, and the pointer to the value string on the heap.
2597
+ *
2598
+ * # Safety
2599
+ *
2600
+ * The underlying data must not be modified during iteration.
2601
+ *
2602
+ * The user needs to free both the contained strings and the array.
2603
+ *
2604
+ * # Error Handling
2605
+ *
2606
+ * Returns NULL if there's no further elements or the iterator is NULL.
2607
+ */
2608
+ ProviderStateParamPair *pactffi_provider_state_param_iter_next(ProviderStateParamIterator *iter);
2609
+
2610
+ /**
2611
+ * Free the provider state when you're done using it.
2612
+ */
2613
+ void pactffi_provider_state_delete(ProviderState *provider_state);
2614
+
2615
+ /**
2616
+ * Free the provider state param iterator when you're done using it.
2617
+ */
2618
+ void pactffi_provider_state_param_iter_delete(ProviderStateParamIterator *iter);
2619
+
2620
+ /**
2621
+ * Free a pair of key and value returned from `pactffi_provider_state_param_iter_next`.
2622
+ */
2623
+ void pactffi_provider_state_param_pair_delete(ProviderStateParamPair *pair);
2624
+
2625
+ /**
2626
+ * Get a mutable pointer to a newly-created default message on the heap.
2627
+ *
2628
+ * # Safety
2629
+ *
2630
+ * This function is safe.
2631
+ *
2632
+ * # Error Handling
2633
+ *
2634
+ * Returns NULL on error.
2635
+ */
2636
+ SynchronousMessage *pactffi_sync_message_new();
2637
+
2638
+ /**
2639
+ * Destroy the `Message` being pointed to.
2640
+ */
2641
+ void pactffi_sync_message_delete(SynchronousMessage *message);
2642
+
2643
+ /**
2644
+ * Get the request contents of a `SynchronousMessage` in string form.
2645
+ *
2646
+ * # Safety
2647
+ *
2648
+ * The returned string must be deleted with `pactffi_string_delete`.
2649
+ *
2650
+ * The returned string can outlive the message.
2651
+ *
2652
+ * # Error Handling
2653
+ *
2654
+ * If the message is NULL, returns NULL. If the body of the request message
2655
+ * is missing, then this function also returns NULL. This means there's
2656
+ * no mechanism to differentiate with this function call alone between
2657
+ * a NULL message and a missing message body.
2658
+ */
2659
+ const char *pactffi_sync_message_get_request_contents_str(const SynchronousMessage *message);
2660
+
2661
+ /**
2662
+ * Sets the request contents of the message.
2663
+ *
2664
+ * * `message` - the message to set the request contents for
2665
+ * * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
2666
+ * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
2667
+ *
2668
+ * # Safety
2669
+ *
2670
+ * The message contents and content type must either be NULL pointers, or point to valid
2671
+ * UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
2672
+ *
2673
+ * # Error Handling
2674
+ *
2675
+ * If the contents is a NULL pointer, it will set the message contents as null. If the content
2676
+ * type is a null pointer, or can't be parsed, it will set the content type as unknown.
2677
+ */
2678
+ void pactffi_sync_message_set_request_contents_str(SynchronousMessage *message,
2679
+ const char *contents,
2680
+ const char *content_type);
2681
+
2682
+ /**
2683
+ * Get the length of the request contents of a `SynchronousMessage`.
2684
+ *
2685
+ * # Safety
2686
+ *
2687
+ * This function is safe.
2688
+ *
2689
+ * # Error Handling
2690
+ *
2691
+ * If the message is NULL, returns 0. If the body of the request
2692
+ * is missing, then this function also returns 0.
2693
+ */
2694
+ size_t pactffi_sync_message_get_request_contents_length(const SynchronousMessage *message);
2695
+
2696
+ /**
2697
+ * Get the request contents of a `SynchronousMessage` as a pointer to an array of bytes.
2698
+ *
2699
+ * # Safety
2700
+ *
2701
+ * The number of bytes in the buffer will be returned by `pactffi_sync_message_get_request_contents_length`.
2702
+ * It is safe to use the pointer while the message is not deleted or changed. Using the pointer
2703
+ * after the message is mutated or deleted may lead to undefined behaviour.
2704
+ *
2705
+ * # Error Handling
2706
+ *
2707
+ * If the message is NULL, returns NULL. If the body of the message
2708
+ * is missing, then this function also returns NULL.
2709
+ */
2710
+ const unsigned char *pactffi_sync_message_get_request_contents_bin(const SynchronousMessage *message);
2711
+
2712
+ /**
2713
+ * Sets the request contents of the message as an array of bytes.
2714
+ *
2715
+ * * `message` - the message to set the request contents for
2716
+ * * `contents` - pointer to contents to copy from
2717
+ * * `len` - number of bytes to copy from the contents pointer
2718
+ * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
1993
2719
  *
1994
2720
  * # Safety
1995
2721
  *
1996
- * This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the
1997
- * iterator has not been deleted.
2722
+ * The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
2723
+ * and consecutive. Otherwise behaviour is undefined.
2724
+ *
2725
+ * # Error Handling
2726
+ *
2727
+ * If the contents is a NULL pointer, it will set the message contents as null. If the content
2728
+ * type is a null pointer, or can't be parsed, it will set the content type as unknown.
1998
2729
  */
1999
- uint16_t pactffi_matching_rule_id(const MatchingRuleResult *rule_result);
2730
+ void pactffi_sync_message_set_request_contents_bin(SynchronousMessage *message,
2731
+ const unsigned char *contents,
2732
+ size_t len,
2733
+ const char *content_type);
2000
2734
 
2001
2735
  /**
2002
- * Returns the associated value for the matching rule. If the matching rule does not have an
2003
- * associated value, will return a NULL pointer.
2736
+ * Get the request contents of an `SynchronousMessage` as a `MessageContents` pointer.
2004
2737
  *
2005
- * The associated values for the rules are:
2006
- * | Rule | ID | VALUE |
2007
- * | ---- | -- | ----- |
2008
- * | Equality | 1 | NULL |
2009
- * | Regex | 2 | Regex value |
2010
- * | Type | 3 | NULL |
2011
- * | MinType | 4 | Minimum value |
2012
- * | MaxType | 5 | Maximum value |
2013
- * | MinMaxType | 6 | "min:max" |
2014
- * | Timestamp | 7 | Format string |
2015
- * | Time | 8 | Format string |
2016
- * | Date | 9 | Format string |
2017
- * | Include | 10 | String value |
2018
- * | Number | 11 | NULL |
2019
- * | Integer | 12 | NULL |
2020
- * | Decimal | 13 | NULL |
2021
- * | Null | 14 | NULL |
2022
- * | ContentType | 15 | Content type |
2023
- * | ArrayContains | 16 | NULL |
2024
- * | Values | 17 | NULL |
2025
- * | Boolean | 18 | NULL |
2026
- * | StatusCode | 19 | NULL |
2027
- * | NotEmpty | 20 | NULL |
2028
- * | Semver | 21 | NULL |
2029
- * | EachKey | 22 | NULL |
2030
- * | EachValue | 23 | NULL |
2738
+ * # Safety
2031
2739
  *
2032
- * Will return a NULL pointer if the matching rule was a reference or does not have an
2033
- * associated value.
2740
+ * The data pointed to by the pointer this function returns will be deleted when the message
2741
+ * is deleted. Trying to use if after the message is deleted will result in undefined behaviour.
2742
+ *
2743
+ * # Error Handling
2744
+ *
2745
+ * If the message is NULL, returns NULL.
2746
+ */
2747
+ const MessageContents *pactffi_sync_message_get_request_contents(const SynchronousMessage *message);
2748
+
2749
+ /**
2750
+ * Get the number of response messages in the `SynchronousMessage`.
2034
2751
  *
2035
2752
  * # Safety
2036
2753
  *
2037
- * This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the
2038
- * iterator it came from has not been deleted.
2754
+ * The message pointer must point to a valid SynchronousMessage.
2755
+ *
2756
+ * # Error Handling
2757
+ *
2758
+ * If the message is NULL, returns 0.
2039
2759
  */
2040
- const char *pactffi_matching_rule_value(const MatchingRuleResult *rule_result);
2760
+ size_t pactffi_sync_message_get_number_responses(const SynchronousMessage *message);
2041
2761
 
2042
2762
  /**
2043
- * Returns the matching rule pointer for the matching rule. Will return a NULL pointer if the
2044
- * matching rule result was a reference.
2763
+ * Get the response contents of a `SynchronousMessage` in string form.
2045
2764
  *
2046
2765
  * # Safety
2047
2766
  *
2048
- * This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the
2049
- * iterator it came from has not been deleted.
2767
+ * The returned string must be deleted with `pactffi_string_delete`.
2768
+ *
2769
+ * The returned string can outlive the message.
2770
+ *
2771
+ * # Error Handling
2772
+ *
2773
+ * If the message is NULL or the index is not valid, returns NULL.
2774
+ *
2775
+ * If the body of the response message is missing, then this function also returns NULL.
2776
+ * This means there's no mechanism to differentiate with this function call alone between
2777
+ * a NULL message and a missing message body.
2050
2778
  */
2051
- const MatchingRule *pactffi_matching_rule_pointer(const MatchingRuleResult *rule_result);
2779
+ const char *pactffi_sync_message_get_response_contents_str(const SynchronousMessage *message,
2780
+ size_t index);
2052
2781
 
2053
2782
  /**
2054
- * Return any matching rule reference to a attribute by name. This is when the matcher should
2055
- * be configured to match the type of a structure. I.e.,
2783
+ * Sets the response contents of the message as a string. If index is greater than the number of responses
2784
+ * in the message, the responses will be padded with default values.
2056
2785
  *
2057
- * ```json
2058
- * {
2059
- * "pact:match": "eachValue(matching($'person'))",
2060
- * "person": {
2061
- * "name": "Fred",
2062
- * "age": 100
2063
- * }
2064
- * }
2065
- * ```
2786
+ * * `message` - the message to set the response contents for
2787
+ * * `index` - index of the response to set. 0 is the first response.
2788
+ * * `contents` - pointer to contents to copy from. Must be a valid NULL-terminated UTF-8 string pointer.
2789
+ * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
2066
2790
  *
2067
- * Will return a NULL pointer if the matching rule was not a reference.
2791
+ * # Safety
2792
+ *
2793
+ * The message contents and content type must either be NULL pointers, or point to valid
2794
+ * UTF-8 encoded NULL-terminated strings. Otherwise behaviour is undefined.
2795
+ *
2796
+ * # Error Handling
2797
+ *
2798
+ * If the contents is a NULL pointer, it will set the response contents as null. If the content
2799
+ * type is a null pointer, or can't be parsed, it will set the content type as unknown.
2800
+ */
2801
+ void pactffi_sync_message_set_response_contents_str(SynchronousMessage *message,
2802
+ size_t index,
2803
+ const char *contents,
2804
+ const char *content_type);
2805
+
2806
+ /**
2807
+ * Get the length of the response contents of a `SynchronousMessage`.
2068
2808
  *
2069
2809
  * # Safety
2070
2810
  *
2071
- * This function is safe as long as the MatchingRuleResult pointer is a valid pointer and the
2072
- * iterator has not been deleted.
2811
+ * This function is safe.
2812
+ *
2813
+ * # Error Handling
2814
+ *
2815
+ * If the message is NULL or the index is not valid, returns 0. If the body of the request
2816
+ * is missing, then this function also returns 0.
2073
2817
  */
2074
- const char *pactffi_matching_rule_reference_name(const MatchingRuleResult *rule_result);
2818
+ size_t pactffi_sync_message_get_response_contents_length(const SynchronousMessage *message,
2819
+ size_t index);
2075
2820
 
2076
2821
  /**
2077
- * Get the JSON form of the matching rule.
2822
+ * Get the response contents of a `SynchronousMessage` as a pointer to an array of bytes.
2078
2823
  *
2079
- * The returned string must be deleted with `pactffi_string_delete`.
2824
+ * # Safety
2825
+ *
2826
+ * The number of bytes in the buffer will be returned by `pactffi_sync_message_get_response_contents_length`.
2827
+ * It is safe to use the pointer while the message is not deleted or changed. Using the pointer
2828
+ * after the message is mutated or deleted may lead to undefined behaviour.
2829
+ *
2830
+ * # Error Handling
2831
+ *
2832
+ * If the message is NULL or the index is not valid, returns NULL. If the body of the message
2833
+ * is missing, then this function also returns NULL.
2834
+ */
2835
+ const unsigned char *pactffi_sync_message_get_response_contents_bin(const SynchronousMessage *message,
2836
+ size_t index);
2837
+
2838
+ /**
2839
+ * Sets the response contents of the message at the given index as an array of bytes. If index
2840
+ * is greater than the number of responses in the message, the responses will be padded with
2841
+ * default values.
2842
+ *
2843
+ * * `message` - the message to set the response contents for
2844
+ * * `index` - index of the response to set. 0 is the first response
2845
+ * * `contents` - pointer to contents to copy from
2846
+ * * `len` - number of bytes to copy
2847
+ * * `content_type` - pointer to the NULL-terminated UTF-8 string containing the content type of the data.
2080
2848
  *
2081
2849
  * # Safety
2082
2850
  *
2083
- * This function will fail if it is passed a NULL pointer, or the iterator that owns the
2084
- * value of the matching rule has been deleted.
2851
+ * The contents pointer must be valid for reads of `len` bytes, and it must be properly aligned
2852
+ * and consecutive. Otherwise behaviour is undefined.
2853
+ *
2854
+ * # Error Handling
2855
+ *
2856
+ * If the contents is a NULL pointer, it will set the message contents as null. If the content
2857
+ * type is a null pointer, or can't be parsed, it will set the content type as unknown.
2085
2858
  */
2086
- const char *pactffi_matching_rule_to_json(const MatchingRule *rule);
2859
+ void pactffi_sync_message_set_response_contents_bin(SynchronousMessage *message,
2860
+ size_t index,
2861
+ const unsigned char *contents,
2862
+ size_t len,
2863
+ const char *content_type);
2087
2864
 
2088
2865
  /**
2089
- * Get the JSON form of the generator.
2866
+ * Get the response contents of an `SynchronousMessage` as a `MessageContents` pointer.
2867
+ *
2868
+ * # Safety
2869
+ *
2870
+ * The data pointed to by the pointer this function returns will be deleted when the message
2871
+ * is deleted. Trying to use if after the message is deleted will result in undefined behaviour.
2872
+ *
2873
+ * # Error Handling
2874
+ *
2875
+ * If the message is NULL or the index is not valid, returns NULL.
2876
+ */
2877
+ const MessageContents *pactffi_sync_message_get_response_contents(const SynchronousMessage *message,
2878
+ size_t index);
2879
+
2880
+ /**
2881
+ * Get a copy of the description.
2882
+ *
2883
+ * # Safety
2090
2884
  *
2091
2885
  * The returned string must be deleted with `pactffi_string_delete`.
2092
2886
  *
2887
+ * Since it is a copy, the returned string may safely outlive
2888
+ * the `SynchronousMessage`.
2889
+ *
2890
+ * # Errors
2891
+ *
2892
+ * On failure, this function will return a NULL pointer.
2893
+ *
2894
+ * This function may fail if the Rust string contains embedded
2895
+ * null ('\0') bytes.
2896
+ */
2897
+ const char *pactffi_sync_message_get_description(const SynchronousMessage *message);
2898
+
2899
+ /**
2900
+ * Write the `description` field on the `SynchronousMessage`.
2901
+ *
2093
2902
  * # Safety
2094
2903
  *
2095
- * This function will fail if it is passed a NULL pointer, or the owner of the generator has
2096
- * been deleted.
2904
+ * `description` must contain valid UTF-8. Invalid UTF-8
2905
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
2906
+ *
2907
+ * This function will only reallocate if the new string
2908
+ * does not fit in the existing buffer.
2909
+ *
2910
+ * # Error Handling
2911
+ *
2912
+ * Errors will be reported with a non-zero return value.
2097
2913
  */
2098
- const char *pactffi_generator_to_json(const Generator *generator);
2914
+ int pactffi_sync_message_set_description(SynchronousMessage *message, const char *description);
2099
2915
 
2100
2916
  /**
2101
- * Generate a string value using the provided generator and an optional JSON payload containing
2102
- * any generator context. The context value is used for generators like `MockServerURL` (which
2103
- * should contain details about the running mock server) and `ProviderStateGenerator` (which
2104
- * should be the values returned from the Provider State callback function).
2917
+ * Get a copy of the provider state at the given index from this message.
2105
2918
  *
2106
- * If anything goes wrong, it will return a NULL pointer.
2919
+ * # Safety
2920
+ *
2921
+ * The returned structure must be deleted with `provider_state_delete`.
2922
+ *
2923
+ * Since it is a copy, the returned structure may safely outlive
2924
+ * the `SynchronousMessage`.
2925
+ *
2926
+ * # Error Handling
2927
+ *
2928
+ * On failure, this function will return a variant other than Success.
2929
+ *
2930
+ * This function may fail if the index requested is out of bounds,
2931
+ * or if any of the Rust strings contain embedded null ('\0') bytes.
2107
2932
  */
2108
- const char *pactffi_generator_generate_string(const Generator *generator, const char *context_json);
2933
+ const ProviderState *pactffi_sync_message_get_provider_state(const SynchronousMessage *message,
2934
+ unsigned int index);
2109
2935
 
2110
2936
  /**
2111
- * Generate an integer value using the provided generator and an optional JSON payload containing
2112
- * any generator context. The context value is used for generators like `ProviderStateGenerator`
2113
- * (which should be the values returned from the Provider State callback function).
2937
+ * Get an iterator over provider states.
2114
2938
  *
2115
- * If anything goes wrong or the generator is not a type that can generate an integer value, it
2116
- * will return a zero value.
2939
+ * # Safety
2940
+ *
2941
+ * The underlying data must not change during iteration.
2942
+ *
2943
+ * # Error Handling
2944
+ *
2945
+ * Returns NULL if an error occurs.
2117
2946
  */
2118
- unsigned short pactffi_generator_generate_integer(const Generator *generator,
2119
- const char *context_json);
2947
+ ProviderStateIterator *pactffi_sync_message_get_provider_state_iter(SynchronousMessage *message);
2120
2948
 
2121
2949
  /**
2122
2950
  * Delete a string previously returned by this FFI.