faststep 0.0.8.1 → 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/ext/faststep/bson.h CHANGED
@@ -1,6 +1,9 @@
1
- /* bson.h */
1
+ /**
2
+ * @file bson.h
3
+ * @brief BSON Declarations
4
+ */
2
5
 
3
- /* Copyright 2009, 2010 10gen Inc.
6
+ /* Copyright 2009, 2010, 2011 10gen Inc.
4
7
  *
5
8
  * Licensed under the Apache License, Version 2.0 (the "License");
6
9
  * you may not use this file except in compliance with the License.
@@ -21,6 +24,20 @@
21
24
  #include "platform_hacks.h"
22
25
  #include <time.h>
23
26
 
27
+ /* Generic error and warning flags. */
28
+ #define BSON_OK 0
29
+ #define BSON_ERROR -1
30
+ #define BSON_WARNING -2
31
+
32
+ /* BSON validity flags. */
33
+ #define BSON_VALID 0x0
34
+ #define BSON_NOT_UTF8 0x2 /**< Either a key or a string is not valid UTF-8. */
35
+ #define BSON_FIELD_HAS_DOT 0x4 /**< Warning: key contains '.' character. */
36
+ #define BSON_FIELD_INIT_DOLLAR 0x8 /**< Warning: key starts with '$' character. */
37
+
38
+ /* BSON error codes. */
39
+ #define BSON_OBJECT_FINISHED 1 /**< Trying to modify a finished BSON object. */
40
+
24
41
  MONGO_EXTERN_C_START
25
42
 
26
43
  typedef enum {
@@ -50,6 +67,8 @@ typedef int bson_bool_t;
50
67
  typedef struct {
51
68
  char * data;
52
69
  bson_bool_t owned;
70
+ int err; /**< Bitfield representing errors or warnings on this bson object. */
71
+ char* errstr; /**< A string representation of the most recent error or warning. */
53
72
  } bson;
54
73
 
55
74
  typedef struct {
@@ -64,6 +83,8 @@ typedef struct {
64
83
  bson_bool_t finished;
65
84
  int stack[32];
66
85
  int stackPos;
86
+ int err; /**< Bitfield representing errors or warnings on this buffer */
87
+ char* errstr; /**< A string representation of the most recent error or warning. */
67
88
  } bson_buffer;
68
89
 
69
90
  #pragma pack(1)
@@ -83,121 +104,738 @@ typedef struct {
83
104
  /* ----------------------------
84
105
  READING
85
106
  ------------------------------ */
86
-
107
+ /**
108
+ * Returns a pointer to a static empty BSON object.
109
+ *
110
+ * @param obj the BSON object to initialize.
111
+ *
112
+ * @return the empty initialized BSON object.
113
+ */
87
114
  bson * bson_empty(bson * obj); /* returns pointer to static empty bson object */
115
+
116
+ /**
117
+ * Copy BSON data from one object to another.
118
+ *
119
+ * @param out the copy destination BSON object.
120
+ * @param in the copy source BSON object.
121
+ */
88
122
  void bson_copy(bson* out, const bson* in); /* puts data in new buffer. NOOP if out==NULL */
89
- bson * bson_from_buffer(bson * b, bson_buffer * buf);
90
- bson * bson_init( bson * b , char * data , bson_bool_t mine );
123
+
124
+ /**
125
+ * Make a BSON object from a BSON buffer.
126
+ *
127
+ * @param b the destination BSON object.
128
+ * @param buf the source BSON buffer object.
129
+ *
130
+ * @return BSON_OK or BSON_ERROR.
131
+ */
132
+ int bson_from_buffer(bson * b, bson_buffer * buf);
133
+
134
+ /**
135
+ * Initialize a BSON object.
136
+ *
137
+ * @param b the BSON object to initialize.
138
+ * @param data the raw BSON data.
139
+ * @param mine whether or not the data's allocation should be freed by bson_destroy
140
+ *
141
+ * @return BSON_OK or BSON_ERROR.
142
+ */
143
+ int bson_init( bson * b , char * data , bson_bool_t mine );
144
+
145
+ /**
146
+ * Size of a BSON object.
147
+ *
148
+ * @param b the BSON object.
149
+ *
150
+ * @return the size.
151
+ */
91
152
  int bson_size(const bson * b );
153
+
154
+ /**
155
+ * Destroy a BSON object.
156
+ *
157
+ * @param b the object to destroy.
158
+ */
92
159
  void bson_destroy( bson * b );
93
160
 
161
+ /**
162
+ * Print a string representation of a BSON object.
163
+ *
164
+ * @param b the BSON object to print.
165
+ */
94
166
  void bson_print( bson * b );
167
+
168
+ /**
169
+ * Print a string representation of a BSON object.
170
+ *
171
+ * @param bson the raw data to print.
172
+ * @param depth the depth to recurse the object.x
173
+ */
95
174
  void bson_print_raw( const char * bson , int depth );
96
175
 
97
176
  /* advances iterator to named field */
98
177
  /* returns bson_eoo (which is false) if field not found */
178
+ /**
179
+ * Advance a bson_iterator to the named field.
180
+ *
181
+ * @param it the bson_iterator to use.
182
+ * @param obj the BSON object to use.
183
+ * @param name the name of the field to find.
184
+ *
185
+ * @return the type of the found object, bson_eoo if it is not found.
186
+ */
99
187
  bson_type bson_find(bson_iterator* it, const bson* obj, const char* name);
100
188
 
189
+ /**
190
+ * Initialize a bson_iterator.
191
+ *
192
+ * @param i the bson_iterator to initialize.
193
+ * @param bson the BSON object to associate with the iterator.
194
+ */
101
195
  void bson_iterator_init( bson_iterator * i , const char * bson );
102
196
 
103
197
  /* more returns true for eoo. best to loop with bson_iterator_next(&it) */
198
+ /**
199
+ * Check to see if the bson_iterator has more data.
200
+ *
201
+ * @param i the iterator.
202
+ *
203
+ * @return returns true if there is more data.
204
+ */
104
205
  bson_bool_t bson_iterator_more( const bson_iterator * i );
206
+
207
+ /**
208
+ * Point the iterator at the next BSON object.
209
+ *
210
+ * @param i the bson_iterator.
211
+ *
212
+ * @return the type of the next BSON object.
213
+ */
105
214
  bson_type bson_iterator_next( bson_iterator * i );
106
215
 
216
+ /**
217
+ * Get the type of the BSON object currently pointed to by the iterator.
218
+ *
219
+ * @param i the bson_iterator
220
+ *
221
+ * @return the type of the current BSON object.
222
+ */
107
223
  bson_type bson_iterator_type( const bson_iterator * i );
224
+
225
+ /**
226
+ * Get the key of the BSON object currently pointed to by the iterator.
227
+ *
228
+ * @param i the bson_iterator
229
+ *
230
+ * @return the key of the current BSON object.
231
+ */
108
232
  const char * bson_iterator_key( const bson_iterator * i );
233
+
234
+ /**
235
+ * Get the value of the BSON object currently pointed to by the iterator.
236
+ *
237
+ * @param i the bson_iterator
238
+ *
239
+ * @return the value of the current BSON object.
240
+ */
109
241
  const char * bson_iterator_value( const bson_iterator * i );
110
242
 
111
243
  /* these convert to the right type (return 0 if non-numeric) */
244
+ /**
245
+ * Get the double value of the BSON object currently pointed to by the
246
+ * iterator.
247
+ *
248
+ * @param i the bson_iterator
249
+ *
250
+ * @return the value of the current BSON object.
251
+ */
112
252
  double bson_iterator_double( const bson_iterator * i );
253
+
254
+ /**
255
+ * Get the int value of the BSON object currently pointed to by the iterator.
256
+ *
257
+ * @param i the bson_iterator
258
+ *
259
+ * @return the value of the current BSON object.
260
+ */
113
261
  int bson_iterator_int( const bson_iterator * i );
262
+
263
+ /**
264
+ * Get the long value of the BSON object currently pointed to by the iterator.
265
+ *
266
+ * @param i the bson_iterator
267
+ *
268
+ * @return the value of the current BSON object.
269
+ */
114
270
  int64_t bson_iterator_long( const bson_iterator * i );
115
271
 
116
272
  /* return the bson timestamp as a whole or in parts */
273
+ /**
274
+ * Get the timestamp value of the BSON object currently pointed to by
275
+ * the iterator.
276
+ *
277
+ * @param i the bson_iterator
278
+ *
279
+ * @return the value of the current BSON object.
280
+ */
117
281
  bson_timestamp_t bson_iterator_timestamp( const bson_iterator * i );
118
282
 
283
+ /**
284
+ * Get the boolean value of the BSON object currently pointed to by
285
+ * the iterator.
286
+ *
287
+ * @param i the bson_iterator
288
+ *
289
+ * @return the value of the current BSON object.
290
+ */
119
291
  /* false: boolean false, 0 in any type, or null */
120
292
  /* true: anything else (even empty strings and objects) */
121
293
  bson_bool_t bson_iterator_bool( const bson_iterator * i );
122
294
 
295
+ /**
296
+ * Get the double value of the BSON object currently pointed to by the
297
+ * iterator. Assumes the correct type is used.
298
+ *
299
+ * @param i the bson_iterator
300
+ *
301
+ * @return the value of the current BSON object.
302
+ */
123
303
  /* these assume you are using the right type */
124
304
  double bson_iterator_double_raw( const bson_iterator * i );
305
+
306
+ /**
307
+ * Get the int value of the BSON object currently pointed to by the
308
+ * iterator. Assumes the correct type is used.
309
+ *
310
+ * @param i the bson_iterator
311
+ *
312
+ * @return the value of the current BSON object.
313
+ */
125
314
  int bson_iterator_int_raw( const bson_iterator * i );
315
+
316
+ /**
317
+ * Get the long value of the BSON object currently pointed to by the
318
+ * iterator. Assumes the correct type is used.
319
+ *
320
+ * @param i the bson_iterator
321
+ *
322
+ * @return the value of the current BSON object.
323
+ */
126
324
  int64_t bson_iterator_long_raw( const bson_iterator * i );
325
+
326
+ /**
327
+ * Get the bson_bool_t value of the BSON object currently pointed to by the
328
+ * iterator. Assumes the correct type is used.
329
+ *
330
+ * @param i the bson_iterator
331
+ *
332
+ * @return the value of the current BSON object.
333
+ */
127
334
  bson_bool_t bson_iterator_bool_raw( const bson_iterator * i );
335
+
336
+ /**
337
+ * Get the bson_oid_t value of the BSON object currently pointed to by the
338
+ * iterator.
339
+ *
340
+ * @param i the bson_iterator
341
+ *
342
+ * @return the value of the current BSON object.
343
+ */
128
344
  bson_oid_t* bson_iterator_oid( const bson_iterator * i );
129
345
 
346
+ /**
347
+ * Get the string value of the BSON object currently pointed to by the
348
+ * iterator.
349
+ *
350
+ * @param i the bson_iterator
351
+ *
352
+ * @return the value of the current BSON object.
353
+ */
130
354
  /* these can also be used with bson_code and bson_symbol*/
131
355
  const char * bson_iterator_string( const bson_iterator * i );
356
+
357
+ /**
358
+ * Get the string length of the BSON object currently pointed to by the
359
+ * iterator.
360
+ *
361
+ * @param i the bson_iterator
362
+ *
363
+ * @return the length of the current BSON object.
364
+ */
132
365
  int bson_iterator_string_len( const bson_iterator * i );
133
366
 
367
+ /**
368
+ * Get the code value of the BSON object currently pointed to by the
369
+ * iterator. Works with bson_code, bson_codewscope, and bson_string
370
+ * returns NULL for everything else.
371
+ *
372
+ * @param i the bson_iterator
373
+ *
374
+ * @return the code value of the current BSON object.
375
+ */
134
376
  /* works with bson_code, bson_codewscope, and bson_string */
135
377
  /* returns NULL for everything else */
136
378
  const char * bson_iterator_code(const bson_iterator * i);
137
379
 
380
+ /**
381
+ * Calls bson_empty on scope if not a bson_codewscope
382
+ *
383
+ * @param i the bson_iterator.
384
+ * @param scope the bson scope.
385
+ */
138
386
  /* calls bson_empty on scope if not a bson_codewscope */
139
387
  void bson_iterator_code_scope(const bson_iterator * i, bson * scope);
140
388
 
389
+ /**
390
+ * Get the date value of the BSON object currently pointed to by the
391
+ * iterator.
392
+ *
393
+ * @param i the bson_iterator
394
+ *
395
+ * @return the date value of the current BSON object.
396
+ */
141
397
  /* both of these only work with bson_date */
142
398
  bson_date_t bson_iterator_date(const bson_iterator * i);
399
+
400
+ /**
401
+ * Get the time value of the BSON object currently pointed to by the
402
+ * iterator.
403
+ *
404
+ * @param i the bson_iterator
405
+ *
406
+ * @return the time value of the current BSON object.
407
+ */
143
408
  time_t bson_iterator_time_t(const bson_iterator * i);
144
409
 
410
+ /**
411
+ * Get the length of the BSON binary object currently pointed to by the
412
+ * iterator.
413
+ *
414
+ * @param i the bson_iterator
415
+ *
416
+ * @return the length of the current BSON binary object.
417
+ */
145
418
  int bson_iterator_bin_len( const bson_iterator * i );
419
+
420
+ /**
421
+ * Get the type of the BSON binary object currently pointed to by the
422
+ * iterator.
423
+ *
424
+ * @param i the bson_iterator
425
+ *
426
+ * @return the type of the current BSON binary object.
427
+ */
146
428
  char bson_iterator_bin_type( const bson_iterator * i );
429
+
430
+ /**
431
+ * Get the value of the BSON binary object currently pointed to by the
432
+ * iterator.
433
+ *
434
+ * @param i the bson_iterator
435
+ *
436
+ * @return the value of the current BSON binary object.
437
+ */
147
438
  const char * bson_iterator_bin_data( const bson_iterator * i );
148
439
 
440
+ /**
441
+ * Get the value of the BSON regex object currently pointed to by the
442
+ * iterator.
443
+ *
444
+ * @param i the bson_iterator
445
+ *
446
+ * @return the value of the current BSON regex object.
447
+ */
149
448
  const char * bson_iterator_regex( const bson_iterator * i );
449
+
450
+ /**
451
+ * Get the options of the BSON regex object currently pointed to by the
452
+ * iterator.
453
+ *
454
+ * @param i the bson_iterator.
455
+ *
456
+ * @return the options of the current BSON regex object.
457
+ */
150
458
  const char * bson_iterator_regex_opts( const bson_iterator * i );
151
459
 
152
460
  /* these work with bson_object and bson_array */
461
+ /**
462
+ * Get the BSON subobject currently pointed to by the
463
+ * iterator.
464
+ *
465
+ * @param i the bson_iterator.
466
+ * @param sub the BSON subobject destination.
467
+ */
153
468
  void bson_iterator_subobject(const bson_iterator * i, bson * sub);
469
+
470
+ /**
471
+ * Get a bson_iterator that on the BSON subobject.
472
+ *
473
+ * @param i the bson_iterator.
474
+ * @param sub the iterator to point at the BSON subobject.
475
+ */
154
476
  void bson_iterator_subiterator(const bson_iterator * i, bson_iterator * sub);
155
477
 
156
478
  /* str must be at least 24 hex chars + null byte */
479
+ /**
480
+ * Create a bson_oid_t from a string.
481
+ *
482
+ * @param oid the bson_oid_t destination.
483
+ * @param str a null terminated string comprised of at least 24 hex chars.
484
+ */
157
485
  void bson_oid_from_string(bson_oid_t* oid, const char* str);
486
+
487
+ /**
488
+ * Create a string representation of the bson_oid_t.
489
+ *
490
+ * @param oid the bson_oid_t source.
491
+ * @param str the string representation destination.
492
+ */
158
493
  void bson_oid_to_string(const bson_oid_t* oid, char* str);
494
+
495
+ /**
496
+ * Create a bson_oid object.
497
+ *
498
+ * @param oid the destination for the newly created bson_oid_t.
499
+ */
159
500
  void bson_oid_gen(bson_oid_t* oid);
160
501
 
502
+ /**
503
+ * Get the time a bson_oid_t was created.
504
+ *
505
+ * @param oid the bson_oid_t.
506
+ */
161
507
  time_t bson_oid_generated_time(bson_oid_t* oid); /* Gives the time the OID was created */
162
508
 
163
509
  /* ----------------------------
164
510
  BUILDING
165
511
  ------------------------------ */
512
+ /**
513
+ * Initialize a bson_buffer.
514
+ *
515
+ * @param b the bson_buffer object to initialize.
516
+ *
517
+ * @return 0. Exits if cannot allocate memory.
518
+ */
519
+ int bson_buffer_init( bson_buffer * b );
166
520
 
167
- bson_buffer * bson_buffer_init( bson_buffer * b );
168
- bson_buffer * bson_ensure_space( bson_buffer * b , const int bytesNeeded );
521
+ /**
522
+ * Grow a bson_buffer object.
523
+ *
524
+ * @param b the bson_buffer to grow.
525
+ * @param bytesNeeded the additional number of bytes needed.
526
+ *
527
+ * @return BSON_OK or BSON_ERROR with the bson_buffer error object set.
528
+ * Exits if allocation fails.
529
+ */
530
+ int bson_ensure_space( bson_buffer * b, const int bytesNeeded );
169
531
 
170
532
  /**
171
- * @return the raw data. you either should free this OR call bson_destroy not both
533
+ * Finalize a bson_buffer object.
534
+ *
535
+ * @param b the bson_buffer object to finalize.
536
+ *
537
+ * @return the standard error code. To deallocate memory,
538
+ * call bson_buffer_destroy on the bson_buffer object.
539
+ */
540
+ int bson_buffer_finish( bson_buffer * b );
541
+
542
+ /**
543
+ * Destroy a bson_buffer object.
544
+ *
545
+ * @param b the bson_buffer to destroy.
546
+ *
172
547
  */
173
- char * bson_buffer_finish( bson_buffer * b );
174
548
  void bson_buffer_destroy( bson_buffer * b );
175
549
 
176
- bson_buffer * bson_append_oid( bson_buffer * b , const char * name , const bson_oid_t* oid );
177
- bson_buffer * bson_append_new_oid( bson_buffer * b , const char * name );
178
- bson_buffer * bson_append_int( bson_buffer * b , const char * name , const int i );
179
- bson_buffer * bson_append_long( bson_buffer * b , const char * name , const int64_t i );
180
- bson_buffer * bson_append_double( bson_buffer * b , const char * name , const double d );
181
- bson_buffer * bson_append_string( bson_buffer * b , const char * name , const char * str );
182
- bson_buffer * bson_append_symbol( bson_buffer * b , const char * name , const char * str );
183
- bson_buffer * bson_append_code( bson_buffer * b , const char * name , const char * str );
184
- bson_buffer * bson_append_code_w_scope( bson_buffer * b , const char * name , const char * code , const bson * scope);
185
- bson_buffer * bson_append_binary( bson_buffer * b, const char * name, char type, const char * str, int len );
186
- bson_buffer * bson_append_bool( bson_buffer * b , const char * name , const bson_bool_t v );
187
- bson_buffer * bson_append_null( bson_buffer * b , const char * name );
188
- bson_buffer * bson_append_undefined( bson_buffer * b , const char * name );
189
- bson_buffer * bson_append_regex( bson_buffer * b , const char * name , const char * pattern, const char * opts );
190
- bson_buffer * bson_append_bson( bson_buffer * b , const char * name , const bson* bson);
191
- bson_buffer * bson_append_element( bson_buffer * b, const char * name_or_null, const bson_iterator* elem);
192
- bson_buffer * bson_append_timestamp( bson_buffer * b, const char * name, bson_timestamp_t * ts );
550
+ /**
551
+ * Append a previously created bson_oid_t to a bson_buffer.
552
+ *
553
+ * @param b the bson_buffer to append to.
554
+ * @param name the key for the bson_oid_t.
555
+ * @param oid the bson_oid_t to append.
556
+ *
557
+ * @return BSON_OK or BSON_ERROR.
558
+ */
559
+ int bson_append_oid( bson_buffer * b, const char * name, const bson_oid_t* oid );
560
+
561
+ /**
562
+ * Append a bson_oid_t to a bson_buffer.
563
+ *
564
+ * @param b the bson_buffer to append to.
565
+ * @param name the key for the bson_oid_t.
566
+ *
567
+ * @return BSON_OK or BSON_ERROR.
568
+ */
569
+ int bson_append_new_oid( bson_buffer * b, const char * name );
570
+
571
+ /**
572
+ * Append an int to a bson_buffer.
573
+ *
574
+ * @param b the bson_buffer to append to.
575
+ * @param name the key for the int.
576
+ * @param i the int to append.
577
+ *
578
+ * @return BSON_OK or BSON_ERROR.
579
+ */
580
+ int bson_append_int( bson_buffer * b, const char * name, const int i );
581
+
582
+ /**
583
+ * Append an long to a bson_buffer.
584
+ *
585
+ * @param b the bson_buffer to append to.
586
+ * @param name the key for the long.
587
+ * @param i the long to append.
588
+ *
589
+ * @return BSON_OK or BSON_ERROR.
590
+ */
591
+ int bson_append_long( bson_buffer * b, const char * name, const int64_t i );
592
+
593
+ /**
594
+ * Append an double to a bson_buffer.
595
+ *
596
+ * @param b the bson_buffer to append to.
597
+ * @param name the key for the double.
598
+ * @param d the double to append.
599
+ *
600
+ * @return BSON_OK or BSON_ERROR.
601
+ */
602
+ int bson_append_double( bson_buffer * b, const char * name, const double d );
603
+
604
+ /**
605
+ * Append a string to a bson_buffer.
606
+ *
607
+ * @param b the bson_buffer to append to.
608
+ * @param name the key for the string.
609
+ * @param str the string to append.
610
+ *
611
+ * @return BSON_OK or BSON_ERROR.
612
+ */
613
+ int bson_append_string( bson_buffer * b, const char * name, const char * str );
614
+
615
+ /**
616
+ * Append len bytes of a string to a bson_buffer.
617
+ *
618
+ * @param b the bson_buffer to append to.
619
+ * @param name the key for the string.
620
+ * @param str the string to append.
621
+ * @param len the number of bytes from str to append.
622
+ *
623
+ * @return BSON_OK or BSON_ERROR.
624
+ */
625
+ int bson_append_string_n( bson_buffer * b, const char * name, const char * str, int len);
626
+
627
+ /**
628
+ * Append a symbol to a bson_buffer.
629
+ *
630
+ * @param b the bson_buffer to append to.
631
+ * @param name the key for the symbol.
632
+ * @param str the symbol to append.
633
+ *
634
+ * @return BSON_OK or BSON_ERROR.
635
+ */
636
+ int bson_append_symbol( bson_buffer * b, const char * name, const char * str );
637
+
638
+ /**
639
+ * Append len bytes of a symbol to a bson_buffer.
640
+ *
641
+ * @param b the bson_buffer to append to.
642
+ * @param name the key for the symbol.
643
+ * @param str the symbol to append.
644
+ * @param len the number of bytes from str to append.
645
+ *
646
+ * @return BSON_OK or BSON_ERROR.
647
+ */
648
+ int bson_append_symbol_n( bson_buffer * b, const char * name, const char * str, int len );
649
+
650
+ /**
651
+ * Append code to a bson_buffer.
652
+ *
653
+ * @param b the bson_buffer to append to.
654
+ * @param name the key for the code.
655
+ * @param str the code to append.
656
+ * @param len the number of bytes from str to append.
657
+ *
658
+ * @return BSON_OK or BSON_ERROR.
659
+ */
660
+ int bson_append_code( bson_buffer * b, const char * name, const char * str );
661
+
662
+ /**
663
+ * Append len bytes of code to a bson_buffer.
664
+ *
665
+ * @param b the bson_buffer to append to.
666
+ * @param name the key for the code.
667
+ * @param str the code to append.
668
+ * @param len the number of bytes from str to append.
669
+ *
670
+ * @return BSON_OK or BSON_ERROR.
671
+ */
672
+ int bson_append_code_n( bson_buffer * b, const char * name, const char * str, int len );
673
+
674
+ /**
675
+ * Append code to a bson_buffer with scope.
676
+ *
677
+ * @param b the bson_buffer to append to.
678
+ * @param name the key for the code.
679
+ * @param str the string to append.
680
+ * @param scope a BSON object containing the scope.
681
+ *
682
+ * @return BSON_OK or BSON_ERROR.
683
+ */
684
+ int bson_append_code_w_scope( bson_buffer * b, const char * name, const char * code, const bson * scope);
685
+
686
+ /**
687
+ * Append len bytes of code to a bson_buffer with scope.
688
+ *
689
+ * @param b the bson_buffer to append to.
690
+ * @param name the key for the code.
691
+ * @param str the string to append.
692
+ * @param len the number of bytes from str to append.
693
+ * @param scope a BSON object containing the scope.
694
+ *
695
+ * @return BSON_OK or BSON_ERROR.
696
+ */
697
+ int bson_append_code_w_scope_n( bson_buffer * b, const char * name, const char * code, int size, const bson * scope);
698
+
699
+ /**
700
+ * Append binary data to a bson_buffer.
701
+ *
702
+ * @param b the bson_buffer to append to.
703
+ * @param name the key for the data.
704
+ * @param type the binary data type.
705
+ * @param str the binary data.
706
+ * @param len the length of the data.
707
+ *
708
+ * @return BSON_OK or BSON_ERROR.
709
+ */
710
+ int bson_append_binary( bson_buffer * b, const char * name, char type, const char * str, int len );
711
+
712
+ /**
713
+ * Append a bson_bool_t to a bson_buffer.
714
+ *
715
+ * @param b the bson_buffer to append to.
716
+ * @param name the key for the boolean value.
717
+ * @param v the bson_bool_t to append.
718
+ *
719
+ * @return BSON_OK or BSON_ERROR.
720
+ */
721
+ int bson_append_bool( bson_buffer * b, const char * name, const bson_bool_t v );
722
+
723
+ /**
724
+ * Append a null value to a bson_buffer.
725
+ *
726
+ * @param b the bson_buffer to append to.
727
+ * @param name the key for the null value.
728
+ *
729
+ * @return BSON_OK or BSON_ERROR.
730
+ */
731
+ int bson_append_null( bson_buffer * b, const char * name );
732
+
733
+ /**
734
+ * Append an undefined value to a bson_buffer.
735
+ *
736
+ * @param b the bson_buffer to append to.
737
+ * @param name the key for the undefined value.
738
+ *
739
+ * @return BSON_OK or BSON_ERROR.
740
+ */
741
+ int bson_append_undefined( bson_buffer * b, const char * name );
742
+
743
+ /**
744
+ * Append a regex value to a bson_buffer.
745
+ *
746
+ * @param b the bson_buffer to append to.
747
+ * @param name the key for the regex value.
748
+ * @param pattern the regex pattern to append.
749
+ * @param the regex options.
750
+ *
751
+ * @return BSON_OK or BSON_ERROR.
752
+ */
753
+ int bson_append_regex( bson_buffer * b, const char * name, const char * pattern, const char * opts );
754
+
755
+ /**
756
+ * Append bson data to a bson_buffer.
757
+ *
758
+ * @param b the bson_buffer to append to.
759
+ * @param name the key for the bson data.
760
+ * @param bson the bson object to append.
761
+ *
762
+ * @return BSON_OK or BSON_ERROR.
763
+ */
764
+ int bson_append_bson( bson_buffer * b, const char * name, const bson* bson);
765
+
766
+ /**
767
+ * Append a BSON element to a bson_buffer from the current point of an iterator.
768
+ *
769
+ * @param b the bson_buffer to append to.
770
+ * @param name_or_null the key for the BSON element, or NULL.
771
+ * @param elem the bson_iterator.
772
+ *
773
+ * @return BSON_OK or BSON_ERROR.
774
+ */
775
+ int bson_append_element( bson_buffer * b, const char * name_or_null, const bson_iterator* elem);
776
+
777
+ /**
778
+ * Append a bson_timestamp_t value to a bson_buffer.
779
+ *
780
+ * @param b the bson_buffer to append to.
781
+ * @param name the key for the timestampe value.
782
+ * @param ts the bson_timestamp_t value to append.
783
+ *
784
+ * @return BSON_OK or BSON_ERROR.
785
+ */
786
+ int bson_append_timestamp( bson_buffer * b, const char * name, bson_timestamp_t * ts );
193
787
 
194
788
  /* these both append a bson_date */
195
- bson_buffer * bson_append_date(bson_buffer * b, const char * name, bson_date_t millis);
196
- bson_buffer * bson_append_time_t(bson_buffer * b, const char * name, time_t secs);
789
+ /**
790
+ * Append a bson_date_t value to a bson_buffer.
791
+ *
792
+ * @param b the bson_buffer to append to.
793
+ * @param name the key for the date value.
794
+ * @param millis the bson_date_t to append.
795
+ *
796
+ * @return BSON_OK or BSON_ERROR.
797
+ */
798
+ int bson_append_date(bson_buffer * b, const char * name, bson_date_t millis);
197
799
 
198
- bson_buffer * bson_append_start_object( bson_buffer * b , const char * name );
199
- bson_buffer * bson_append_start_array( bson_buffer * b , const char * name );
200
- bson_buffer * bson_append_finish_object( bson_buffer * b );
800
+ /**
801
+ * Append a time_t value to a bson_buffer.
802
+ *
803
+ * @param b the bson_buffer to append to.
804
+ * @param name the key for the date value.
805
+ * @param secs the time_t to append.
806
+ *
807
+ * @return BSON_OK or BSON_ERROR.
808
+ */
809
+ int bson_append_time_t(bson_buffer * b, const char * name, time_t secs);
810
+
811
+ /**
812
+ * Start appending a new object to a bson_buffer.
813
+ *
814
+ * @param b the bson_buffer to append to.
815
+ * @param name the name of the new object.
816
+ *
817
+ * @return BSON_OK or BSON_ERROR.
818
+ */
819
+ int bson_append_start_object( bson_buffer * b, const char * name );
820
+
821
+ /**
822
+ * Start appending a new array to a bson_buffer.
823
+ *
824
+ * @param b the bson_buffer to append to.
825
+ * @param name the name of the new array.
826
+ *
827
+ * @return BSON_OK or BSON_ERROR.
828
+ */
829
+ int bson_append_start_array( bson_buffer * b, const char * name );
830
+
831
+ /**
832
+ * Finish appending a new object or array to a bson_buffer.
833
+ *
834
+ * @param b the bson_buffer to append to.
835
+ *
836
+ * @return BSON_OK or BSON_ERROR.
837
+ */
838
+ int bson_append_finish_object( bson_buffer * b );
201
839
 
202
840
  void bson_numstr(char* str, int i);
203
841
  void bson_incnumstr(char* str);
@@ -206,8 +844,26 @@ void bson_incnumstr(char* str);
206
844
  /* ------------------------------
207
845
  ERROR HANDLING - also used in mongo code
208
846
  ------------------------------ */
209
-
847
+ /**
848
+ * Allocates memory and checks return value, exiting fatally if malloc() fails.
849
+ *
850
+ * @param size bytes to allocate.
851
+ *
852
+ * @return a pointer to the allocated memory.
853
+ *
854
+ * @sa malloc(3)
855
+ */
210
856
  void * bson_malloc(int size); /* checks return value */
857
+
858
+ /**
859
+ * Changes the size of allocated memory and checks return value, exiting fatally if realloc() fails.
860
+ *
861
+ * @param size bytes to allocate.
862
+ *
863
+ * @return a pointer to the allocated memory.
864
+ *
865
+ * @sa malloc(3)
866
+ */
211
867
  void * bson_realloc(void * ptr, int size); /* checks return value */
212
868
 
213
869
  /* bson_err_handlers shouldn't return!!! */
@@ -215,11 +871,37 @@ typedef void(*bson_err_handler)(const char* errmsg);
215
871
 
216
872
  /* returns old handler or NULL */
217
873
  /* default handler prints error then exits with failure*/
874
+ /**
875
+ * Set a function for error handling.
876
+ *
877
+ * @param func a bson_err_handler function.
878
+ *
879
+ * @return the old error handling function, or NULL.
880
+ */
218
881
  bson_err_handler set_bson_err_handler(bson_err_handler func);
219
882
 
220
- /* does nothing is ok != 0 */
883
+ /* does nothing if ok != 0 */
884
+ /**
885
+ * Exit fatally.
886
+ *
887
+ * @param ok exits if ok is equal to 0.
888
+ */
221
889
  void bson_fatal( int ok );
890
+
891
+ /**
892
+ * Exit fatally with an error message.
893
+ *
894
+ * @param ok exits if ok is equal to 0.
895
+ * @param msg prints to stderr before exiting.
896
+ */
222
897
  void bson_fatal_msg( int ok, const char* msg );
223
898
 
899
+ /**
900
+ * Invoke the error handler but do not exit.
901
+ *
902
+ * @param b the buffer object.
903
+ */
904
+ void bson_builder_error( bson_buffer* b );
905
+
224
906
  MONGO_EXTERN_C_END
225
907
  #endif