/
field.h
1107 lines (1028 loc) · 26.3 KB
/
field.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
* Licensed to Qualys, Inc. (QUALYS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* QUALYS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
****************************************************************************/
#ifndef _IB_FIELD_H_
#define _IB_FIELD_H_
/**
* @file
* @brief IronBee --- Field Utility Functions
*
* @author Brian Rectanus <brectanus@qualys.com>
* @author Christopher Alfeld <calfeld@qualys.com>
*/
#include <ironbee/build.h>
#include <ironbee/bytestr.h>
#include <ironbee/clock.h>
#include <ironbee/list.h>
#include <ironbee/mm.h>
#include <ironbee/stream.h>
#include <ironbee/types.h>
#include <stdbool.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup IronBeeUtilField Field
* @ingroup IronBeeUtil
*
* A field is a name and a value. The values can be one of several types.
* Values can be stored in the field or they can alias another location in
* memory. Fields can also be 'dynamic' where set/get operations are passed
* to functions.
*
* As fields can have various types, the field code constitutes a run-time
* typing system. In order to avoid large number of functions, it uses
* @c void *in many places. To avoid bugs, it provides a number of helper
* functions that have no runtime effect but act as a compile time assertions
* on the type of the inputs. For example, to extra a null string value from
* a null string field:
*
* @code
* const char *v;
* ib_status_t rc;
*
* rc = ib_field_value(f, ib_ftype_nulstr_out(&v));
* @endcode
*
* In the above example, ib_field_value() is the general function to access
* the value of a field. It takes a @c void *as the second parameter.
* The ib_ftype_nulstr_out() function takes the appropriate type (@c const
* @c char @c **) and returns its argument cast to @c void*. In this way, if
* you provide the wrong type to ib_ftype_nulstr_out(), the compiler will
* warn you.
*
* There are @c ib_ftype_* functions for every field type and every needed
* passing convention. The @c void *arguments are all named by passing
* convention. Thus:
*
* - @a in_pval --- @c ib_ftype_X_in
* - @a out_pval --- @c ib_ftype_X_out
* - @a mutable_in_pval --- @c ib_ftype_X_mutable_in
* - @a mutable_out_pval --- @c ib_ftype_X_mutable_out
* - @a storage_pval --- @c ib_ftype_X_storage
*
* The storage type is used by ib_field_create_alias() and is the way to
* pass the location to use for field storage.
*
* The following table describes the types for every field type.
*
* <table>
* <tr>
* <th>Field Type</th>
* <th>Value</th>
* <th>In</th>
* <th>Mutable In</th>
* <th>Out</th>
* <th>Mutable Out</th>
* <th>Storage</th>
* </tr>
*
* <tr>
* <td>@c IB_FTYPE_GENERIC</td>
* <td>@c void*</td>
* <td>@c void*</td>
* <td>@c void*</td>
* <td>@c void*</td>
* <td>@c void*</td>
* <td>@c void*</td>
* </tr>
*
* <tr>
* <td>@c IB_FTYPE_NUM</td>
* <td>@c ib_num_t</td>
* <td>@c const @c ib_num_t*</td>
* <td>@c ib_num_t*</td>
* <td>@c const @c ib_num_t*</td>
* <td>@c ib_num_t**</td>
* <td>@c ib_num_t*</td>
* </tr>
*
* <tr>
* <td>@c IB_FTYPE_FLOAT</td>
* <td>@c ib_float_t</td>
* <td>@c const @c ib_float_t*</td>
* <td>@c ib_float_t*</td>
* <td>@c const @c ib_float_t*</td>
* <td>@c ib_float_t**</td>
* <td>@c ib_float_t*</td>
* </tr>
*
* <tr>
* <td>@c IB_FTYPE_TIME</td>
* <td>@c ib_time_t</td>
* <td>@c const @c ib_time_t*</td>
* <td>@c ib_time_t*</td>
* <td>@c const @c ib_time_t*</td>
* <td>@c ib_time_t**</td>
* <td>@c ib_time_t*</td>
* </tr>
*
* <tr>
* <td>@c IB_FTYPE_NULSTR</td>
* <td>@c char*</td>
* <td>@c const @c char*</td>
* <td>@c char*</td>
* <td>@c const @c char**</td>
* <td>@c char**</td>
* <td>@c char**</td>
* </tr>
*
* <tr>
* <td>@c IB_FTYPE_BYTESTR</td>
* <td>@c ib_bytestr_t*</td>
* <td>@c const @c ib_bytestr_t*</td>
* <td>@c ib_bytestr_t*</td>
* <td>@c const @c ib_bytestr_t**</td>
* <td>@c ib_bytestr_t**</td>
* <td>@c ib_bytestr_t**</td>
* </tr>
*
* <tr>
* <td>@c IB_FTYPE_LIST</td>
* <td>@c ib_list_t*</td>
* <td>@c const @c ib_list_t*</td>
* <td>@c ib_list_t*</td>
* <td>@c const @c ib_list_t**</td>
* <td>@c ib_list_t**</td>
* <td>@c ib_list_t**</td>
* </tr>
*
* <tr>
* <td>@c IB_FTYPE_SBUFFER</td>
* <td>@c ib_stream_t*</td>
* <td>@c const @c ib_stream_t*</td>
* <td>@c ib_stream_t*</td>
* <td>@c const @c ib_stream_t**</td>
* <td>@c ib_stream_t**</td>
* <td>@c ib_stream_t**</td>
* </tr>
* </table>
*
* Notes:
* - The in type for IB_FTYPE_NUM is @c ib_num_t* instead of ib_num_t because
* an ib_num_t will not fit in a @c void *parameter on 32 bit architectures.
* - The mutable out types for IB_FTYPE_NUM is @c ib_num_t** so that a pointer
* to the value can be passed out. This allows the caller to mutate the
* actual number as expected for a mutable value. The same applies
* to IB_FTYPE_FLOAT.
* - The use of `void *` instead of `void **` for IB_FTYPE_GENERIC may seem
* surprising, but using `void *` allows the user to express specific
* knowledge of the held type without an awkward cast.
*
* @{
*/
/**
* Field type.
*/
typedef enum {
IB_FTYPE_GENERIC = 0, /**< Generic pointer value */
IB_FTYPE_NUM, /**< Numeric value */
IB_FTYPE_TIME, /**< Milliseconds since epoch. */
IB_FTYPE_FLOAT, /**< Floating point value. */
IB_FTYPE_NULSTR, /**< NUL terminated string value */
IB_FTYPE_BYTESTR, /**< Binary data value */
IB_FTYPE_LIST, /**< List of fields */
IB_FTYPE_SBUFFER /**< Stream buffer */
} ib_ftype_t;
/**
* Private Implementation Detail.
*/
typedef struct ib_field_val_t ib_field_val_t;
/** Field Structure */
typedef struct ib_field_t ib_field_t;
struct ib_field_t {
ib_mm_t mm; /**< Memory manager */
ib_ftype_t type; /**< Field type */
const char *name; /**< Field name; not '\0' terminated! */
size_t nlen; /**< Field name length */
const char *tfn; /**< Transformations performed */
ib_field_val_t *val; /**< Private value store */
};
/**
* Field numerical signed value type
*/
typedef int64_t ib_num_t;
/**
* Field float value type
*/
typedef long double ib_float_t;
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_generic_mutable_in(void *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_generic_in(void *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_generic_out(void *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_generic_mutable_out(void *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_generic_storage(void *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_float_mutable_in(ib_float_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_float_in(const ib_float_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_float_mutable_out(ib_float_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_float_out(ib_float_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_float_storage(ib_float_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_num_mutable_in(ib_num_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_num_in(const ib_num_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_num_out(ib_num_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_num_mutable_out(ib_num_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_num_storage(ib_num_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_time_mutable_in(ib_time_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_time_in(const ib_time_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_time_out(ib_time_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_time_mutable_out(ib_time_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_time_storage(ib_time_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_nulstr_mutable_in(char *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_nulstr_in(const char *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_nulstr_out(const char **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_nulstr_mutable_out(char **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_nulstr_storage(char **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_bytestr_mutable_in(ib_bytestr_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_bytestr_in(const ib_bytestr_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_bytestr_out(const ib_bytestr_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_bytestr_mutable_out(ib_bytestr_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_bytestr_storage(ib_bytestr_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_list_mutable_in(ib_list_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_list_in(const ib_list_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_list_out(const ib_list_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_list_mutable_out(ib_list_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_list_storage(ib_list_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_sbuffer_mutable_in(ib_stream_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_sbuffer_in(const ib_stream_t *v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_sbuffer_out(const ib_stream_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_sbuffer_mutable_out(ib_stream_t **v)
{
return (void *)(v);
}
/**
* Assert @a v is proper type.
*/
static inline void *ib_ftype_sbuffer_storage(ib_stream_t **v)
{
return (void *)(v);
}
/**
* Dynamic field get function type.
*
* Note that @a out_pval is an out value not a mutable out value. Dynamic
* fields do not support mutable values.
*
* The field type is available via @c field->type.
*
* @param[in] field Field in question.
* @param[out] out_pval Where to write value.
* @param[in] arg Optional argument.
* @param[in] alen Length of @a arg.
* @param[in] data Callback data.
*
* @returns Status code
*/
typedef ib_status_t (*ib_field_get_fn_t)(
const ib_field_t *field,
void *out_pval,
const void *arg,
size_t alen,
void *data
);
/**
* Dynamic field set function.
*
* Note that @a in_pval is an in value not a mutable in value. Dynamic
* fields do not support mutable values.
*
* The field type is available via @c field->type.
*
* @param[in] field Field in question.
* @param[in] arg Optional argument.
* @param[in] alen Length of @a arg.
* @param[in] in_pval Value to set.
* @param[in] data Callback data.
*
* @returns Status code
*/
typedef ib_status_t (*ib_field_set_fn_t)(
ib_field_t *field,
const void *arg,
size_t alen,
void *in_pval,
void *data
);
/**
* Create a field, copying name/data into the field.
*
* @warning At present, this function will create copies of integral types,
* null strings, and byte strings. However, for lists and streams it will
* act the same as ib_field_create_no_copy(), casting away the const of
* @a in_pval. This will be fixed in a future version.
*
* @param[out] pf Address to write new field to.
* @param[in] mm Memory manager.
* @param[in] name Field name.
* @param[in] nlen Field name length.
* @param[in] type Field type.
* @param[in] in_pval Value to store in field.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_create(
ib_field_t **pf,
ib_mm_t mm,
const char *name,
size_t nlen,
ib_ftype_t type,
void *in_pval
);
/**
* Create a field without copying data.
*
* This will place @a mutable_in_pval directly into the field value without
* any copying. This is different than ib_field_create_alias() which
* uses a user provided pointer for where to store the field value.
*
* @param[out] pf Address to write new field to.
* @param[in] mm Memory manager.
* @param[in] name Field name.
* @param[in] nlen Field name length.
* @param[in] type Field type.
* @param[in] mutable_in_pval Value to store in field.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_create_no_copy(
ib_field_t **pf,
ib_mm_t mm,
const char *name,
size_t nlen,
ib_ftype_t type,
void *mutable_in_pval
);
/**
* Create a field but use @a *mutable_out_pval as the storage.
*
* When the field is set @a *storage_pval is changed and any get
* reflects the value of @a *storage_pval.
*
* @note For null string and bytestring types, @a storage_pval should be
* treated as a pointer to a `char *`. Thus, use the
* @c ib_ftype_T_mutable_out() functions for this parameter for these types.
* For numeric and related types, @a storage_pval should be treated as a
* pointer to the value type, and the developer should use the
* ib_ftype_T_in() functions for this parameter.
*
* @param[out] pf Address to write new field to.
* @param[in] mm Memory manager.
* @param[in] name Field name.
* @param[in] nlen Field name length.
* @param[in] type Field type.
* @param[in] storage_pval Where to store field value.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_create_alias(
ib_field_t **pf,
ib_mm_t mm,
const char *name,
size_t nlen,
ib_ftype_t type,
void *storage_pval
);
/**
* Create a dynamic field.
*
* Dynamic fields only support non-mutable values.
*
* @param[out] pf Address to write new field to.
* @param[in] mm Memory manager.
* @param[in] name Field name..
* @param[in] nlen Field name length.
* @param[in] type Field type.
* @param[in] fn_get Getter.
* @param[in] cbdata_get Getter data.
* @param[in] fn_set Setter.
* @param[in] cbdata_set Setter data.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_create_dynamic(
ib_field_t **pf,
ib_mm_t mm,
const char *name,
size_t nlen,
ib_ftype_t type,
ib_field_get_fn_t fn_get,
void *cbdata_get,
ib_field_set_fn_t fn_set,
void *cbdata_set
);
/**
* Make a copy of a field, aliasing data.
*
* The new field will use the same value storage as @a src. Any changes to
* one will be reflected in the other and in the underlying storage.
*
* @param[out] pf Address to write new field to.
* @param[in] mm Memory manager.
* @param[in] name Field name.
* @param[in] nlen Field name length.
* @param[in] src Source field.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_alias(
ib_field_t **pf,
ib_mm_t mm,
const char *name,
size_t nlen,
const ib_field_t *src
);
/**
* Make a copy of a field.
*
* This makes a copy of the field. The new field will have separate
* storage.
*
* @warning For number and string fields, the underlying data will also be
* duplicated. For list and stream fields, the data will not be duplicated.
* This may be fixed in the future.
*
* @param[out] pf Address to write new field to.
* @param[in] mm Memory manager.
* @param[in] name Field name.
* @param[in] nlen Field name length.
* @param[in] src Source field.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_copy(
ib_field_t **pf,
ib_mm_t mm,
const char *name,
size_t nlen,
const ib_field_t *src
);
/**
* Create a bytestr field which directly aliases a value in memory.
*
* This is a equivalent to create a byte string alias of @a val and @a vlen
* and passing it ib_field_create_no_copy().
*
* @param[out] pf Address to write new field to.
* @param[in] mm Memory manager.
* @param[in] name Field name.
* @param[in] nlen Field name length.
* @param[in] val Value.
* @param[in] vlen Value length.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_create_bytestr_alias(
ib_field_t **pf,
ib_mm_t mm,
const char *name,
size_t nlen,
const uint8_t *val,
size_t vlen
);
/**
* Add a field to a IB_FTYPE_LIST field.
*
* @param[in] f Field.
* @param[in] val Field to add to the list.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_list_add(
ib_field_t *f,
ib_field_t *val
);
/**
* Add a const field to a IB_FTYPE_LIST field.
*
* @param[in] f Field.
* @param[in] val Field to add to the list.
*
* @returns Status code
*/
ib_status_t ib_field_list_add_const(
ib_field_t *f,
const ib_field_t *val
);
/**
* Add a buffer to a IB_FTYPE_SBUFFER type field.
*
* @param[in] f Field.
* @param[in] dtype Data type.
* @param[in] buf Buffer.
* @param[in] blen Length of @a buf.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_buf_add(
ib_field_t *f,
int dtype,
uint8_t *buf,
size_t blen
);
/**
* Turn a dynamic field, @a f into a static field.
*
* This call should immediately be followed by a @c setv call to set a
* (static) value.
*
* This method removes the setter and getters and sets up internal storage for
* the field value. The actual value is undefined, hence the need to follow
* up with a set.
*
* Returns IB_EINVAL if @a f is not dynamic.
*
* @param[in] f Field to make static.
*
* @returns Status code.
*/
ib_status_t DLL_PUBLIC ib_field_make_static(
ib_field_t* f
);
/**
* Set a field value, copying.
*
* @warning This function will not actually copy lists or streams. It
* behaves as ib_field_setv_no_copy() for those types. This may be fixed in
* the future.
*
* @param[in] f Field to set value of.
* @param[in] in_pval Pointer to value to store in field (based on type)
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_setv(
ib_field_t *f,
void *in_pval
);
/**
* Set a field directly without copying.
*
* Can not be called on dynamic fields.
* @param[in] f Field to set value.
* @param[in] mutable_in_pval Pointer to store in field.
*
* @returns Status code.
*/
ib_status_t DLL_PUBLIC ib_field_setv_no_copy(
ib_field_t *f,
void *mutable_in_pval
);
/**
* Set a field value, passing the argument on to dynamic fields.
*
* This will result in an error if @a f is not dynamic.
*
* @param[in] f Field.
* @param[in] in_pval Pointer to value to store in field (based on type).
* @param[in] arg Arbitrary argument.
* @param[in] alen Argument length.
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_setv_ex(
ib_field_t *f,
void *in_pval,
const void *arg,
size_t alen
);
/**
* Get the value stored in the field, passing the argument on to dynamic
* fields.
*
* This will result in an error if @a f is not dynamic.
*
* @param[in] f Field.
* @param[out] out_pval Where to write value.
* @param[in] arg Arbitrary argument.
* @param[in] alen Argument length
*
* @returns Status code
*/
ib_status_t DLL_PUBLIC ib_field_value_ex(
const ib_field_t *f,
void *out_pval,
const void *arg,
size_t alen
);
/**
* Get the value stored in the field, passing the argument on to dynamic
* fields, with type checking.
*
* @param[in] f Field.
* @param[out] out_pval Where to write value.
* @param[in] t Field type number.
* @param[in] arg Arbitrary argument. Use NULL for non-dynamic fields.
* @param[in] alen Argument length.
*
* @returns
* - IB_OK On success.
* - IB_EINVAL If the type does not match @a t or the field is invalid.
*/
ib_status_t DLL_PUBLIC ib_field_value_type_ex(
const ib_field_t *f,
void *out_pval,
ib_ftype_t t,
const void *arg,
size_t alen
);
/**
* Get the value stored in the field.
*
* @param[in] f Field.
* @param[out] out_pval Where to store value.
*
* @returns Status code.
*/
ib_status_t DLL_PUBLIC ib_field_value(
const ib_field_t *f,
void *out_pval
);
/**
* Get the value stored in the field, with type checking.
*
* @param[in] f Field.
* @param[out] out_pval Where to store value.
* @param[in] t Expected type.
*
* @returns
* - IB_OK On success.
* - IB_EINVAL If the type does not match @a t or the field is invalid.
*/
ib_status_t DLL_PUBLIC ib_field_value_type(
const ib_field_t *f,
void *out_pval,
ib_ftype_t t
);
/**
* Get the value stored in the field. Non-dynamic only.
*
* @param[in] f Field.
* @param[out] mutable_out_pval Where to store value.
*
* @returns Status code.
*/
ib_status_t DLL_PUBLIC ib_field_mutable_value(
ib_field_t *f,
void *mutable_out_pval
);
/**
* Get the value stored in the field, with type checking. Non-dynamic only.
*
* @param[in] f Field.
* @param[out] mutable_out_pval Where to store value.
* @param[in] t Expected type
*
* @returns Status code.
*/
ib_status_t DLL_PUBLIC ib_field_mutable_value_type(
ib_field_t *f,
void *mutable_out_pval,
ib_ftype_t t
);
/**
* Determine if a field is dynamic.
*
* @param[in] f Field
*