libmongo-client 0.1.4
|
00001 /* bson.h - libmongo-client's BSON implementation 00002 * Copyright 2011 Gergely Nagy <algernon@balabit.hu> 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00021 #ifndef LIBMONGO_CLIENT_BSON_H 00022 #define LIBMONGO_CLIENT_BSON_H 1 00023 00024 #include <glib.h> 00025 #include <string.h> 00026 00027 G_BEGIN_DECLS 00028 00053 typedef struct _bson bson; 00054 00059 typedef struct _bson_cursor bson_cursor; 00060 00063 typedef enum 00064 { 00065 BSON_TYPE_NONE = 0, 00066 BSON_TYPE_DOUBLE = 0x01, 00067 BSON_TYPE_STRING, 00068 BSON_TYPE_DOCUMENT, 00069 BSON_TYPE_ARRAY, 00070 BSON_TYPE_BINARY, 00071 BSON_TYPE_UNDEFINED, /* Deprecated*/ 00072 BSON_TYPE_OID, 00073 BSON_TYPE_BOOLEAN, 00074 BSON_TYPE_UTC_DATETIME, 00076 BSON_TYPE_NULL, 00077 BSON_TYPE_REGEXP, 00079 BSON_TYPE_DBPOINTER, /* Deprecated */ 00080 BSON_TYPE_JS_CODE, 00081 BSON_TYPE_SYMBOL, 00082 BSON_TYPE_JS_CODE_W_SCOPE, 00084 BSON_TYPE_INT32, 00085 BSON_TYPE_TIMESTAMP, 00086 BSON_TYPE_INT64, 00087 BSON_TYPE_MIN = 0xff, 00088 BSON_TYPE_MAX = 0x7f 00089 } bson_type; 00090 00097 const gchar *bson_type_as_string (bson_type type); 00098 00101 typedef enum 00102 { 00103 BSON_BINARY_SUBTYPE_GENERIC = 0x00, 00105 BSON_BINARY_SUBTYPE_FUNCTION = 0x01, 00107 BSON_BINARY_SUBTYPE_BINARY = 0x02, 00108 BSON_BINARY_SUBTYPE_UUID = 0x03, 00110 BSON_BINARY_SUBTYPE_MD5 = 0x05, 00112 BSON_BINARY_SUBTYPE_USER_DEFINED = 0x80 00115 } bson_binary_subtype; 00116 00137 bson *bson_new (void); 00138 00153 bson *bson_new_sized (gint32 size); 00154 00174 bson *bson_new_from_data (const guint8 *data, gint32 size); 00175 00207 bson *bson_build_full (bson_type type, const gchar *name, 00208 gboolean free_after, ...); 00209 00223 bson *bson_build (bson_type type, const gchar *name, ...); 00224 00236 gboolean bson_finish (bson *b); 00237 00248 gboolean bson_reset (bson *b); 00249 00257 void bson_free (bson *b); 00258 00268 gint32 bson_size (const bson *b); 00269 00280 const guint8 *bson_data (const bson *b); 00281 00300 gboolean bson_validate_key (const gchar *key, gboolean forbid_dots, 00301 gboolean no_dollar); 00302 00318 static __inline__ gint32 bson_stream_doc_size (const guint8 *doc, gint32 pos) 00319 { 00320 gint32 size; 00321 00322 memcpy (&size, doc + pos, sizeof (gint32)); 00323 return GINT32_FROM_LE (size); 00324 } 00325 00354 gboolean bson_append_string (bson *b, const gchar *name, const gchar *val, 00355 gint32 length); 00356 00365 gboolean bson_append_double (bson *b, const gchar *name, gdouble d); 00366 00377 gboolean bson_append_document (bson *b, const gchar *name, const bson *doc); 00378 00395 gboolean bson_append_array (bson *b, const gchar *name, const bson *array); 00396 00407 gboolean bson_append_binary (bson *b, const gchar *name, 00408 bson_binary_subtype subtype, 00409 const guint8 *data, gint32 size); 00410 00427 gboolean bson_append_oid (bson *b, const gchar *name, const guint8 *oid); 00428 00437 gboolean bson_append_boolean (bson *b, const gchar *name, gboolean value); 00438 00448 gboolean bson_append_utc_datetime (bson *b, const gchar *name, gint64 ts); 00449 00457 gboolean bson_append_null (bson *b, const gchar *name); 00458 00469 gboolean bson_append_regex (bson *b, const gchar *name, const gchar *regexp, 00470 const gchar *options); 00471 00482 gboolean bson_append_javascript (bson *b, const gchar *name, const gchar *js, 00483 gint32 len); 00484 00495 gboolean bson_append_symbol (bson *b, const gchar *name, const gchar *symbol, 00496 gint32 len); 00497 00509 gboolean bson_append_javascript_w_scope (bson *b, const gchar *name, 00510 const gchar *js, gint32 len, 00511 const bson *scope); 00512 00521 gboolean bson_append_int32 (bson *b, const gchar *name, gint32 i); 00522 00535 gboolean bson_append_timestamp (bson *b, const gchar *name, gint64 ts); 00536 00545 gboolean bson_append_int64 (bson *b, const gchar *name, gint64 i); 00546 00578 bson_cursor *bson_cursor_new (const bson *b); 00579 00590 bson_cursor *bson_find (const bson *b, const gchar *name); 00591 00596 void bson_cursor_free (bson_cursor *c); 00597 00604 gboolean bson_cursor_next (bson_cursor *c); 00605 00617 gboolean bson_cursor_find_next (bson_cursor *c, const gchar *name); 00618 00630 gboolean bson_cursor_find (bson_cursor *c, const gchar *name); 00631 00638 bson_type bson_cursor_type (const bson_cursor *c); 00639 00649 const gchar *bson_cursor_type_as_string (const bson_cursor *c); 00650 00660 const gchar *bson_cursor_key (const bson_cursor *c); 00661 00673 gboolean bson_cursor_get_string (const bson_cursor *c, const gchar **dest); 00674 00683 gboolean bson_cursor_get_double (const bson_cursor *c, gdouble *dest); 00684 00696 gboolean bson_cursor_get_document (const bson_cursor *c, bson **dest); 00697 00709 gboolean bson_cursor_get_array (const bson_cursor *c, bson **dest); 00710 00723 gboolean bson_cursor_get_binary (const bson_cursor *c, 00724 bson_binary_subtype *subtype, 00725 const guint8 **data, gint32 *size); 00726 00738 gboolean bson_cursor_get_oid (const bson_cursor *c, const guint8 **dest); 00739 00748 gboolean bson_cursor_get_boolean (const bson_cursor *c, gboolean *dest); 00749 00758 gboolean bson_cursor_get_utc_datetime (const bson_cursor *c, gint64 *dest); 00759 00774 gboolean bson_cursor_get_regex (const bson_cursor *c, const gchar **regex, 00775 const gchar **options); 00776 00788 gboolean bson_cursor_get_javascript (const bson_cursor *c, const gchar **dest); 00789 00801 gboolean bson_cursor_get_symbol (const bson_cursor *c, const gchar **dest); 00802 00816 gboolean bson_cursor_get_javascript_w_scope (const bson_cursor *c, 00817 const gchar **js, 00818 bson **scope); 00819 00828 gboolean bson_cursor_get_int32 (const bson_cursor *c, gint32 *dest); 00829 00838 gboolean bson_cursor_get_timestamp (const bson_cursor *c, gint64 *dest); 00839 00848 gboolean bson_cursor_get_int64 (const bson_cursor *c, gint64 *dest); 00849 00854 G_END_DECLS 00855 00856 #endif