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