Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 130 lines (110 sloc) 4.776 kB
cadfcf5 licenses
kristina authored
1 /**
8d57a56 @derickr Implemented PHP-565: Add license files to mcon/
derickr authored
2 * Copyright 2009-2012 10gen, Inc.
8936a67 @kchodorow ws
kchodorow authored
3 *
cadfcf5 licenses
kristina authored
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8936a67 @kchodorow ws
kchodorow authored
7 *
cadfcf5 licenses
kristina authored
8 * http://www.apache.org/licenses/LICENSE-2.0
8936a67 @kchodorow ws
kchodorow authored
9 *
cadfcf5 licenses
kristina authored
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
79be371 header ifdefs, more win compat
unknown authored
16 #ifndef PHP_BSON_H
17 #define PHP_BSON_H 1
b79c77c start
kristina authored
18
0fe8696 $ character can be something else, set in php.ini
kristina authored
19
0dca2ed deserialize
kristina authored
20 #define OID_SIZE 12
f46318e simple serialization
kristina authored
21
39f17e1 @derickr Change those all into HEX constants, and add the BSON spec link.
derickr authored
22 /* BSON type constants from http://bsonspec.org/#/specification */
23 #define BSON_DOUBLE 0x01
24 #define BSON_STRING 0x02
25 #define BSON_OBJECT 0x03
26 #define BSON_ARRAY 0x04
27 #define BSON_BINARY 0x05
28 #define BSON_UNDEF 0x06
29 #define BSON_OID 0x07
30 #define BSON_BOOL 0x08
31 #define BSON_DATE 0x09
32 #define BSON_NULL 0x0A
33 #define BSON_REGEX 0x0B
34 #define BSON_DBREF 0x0C
35 #define BSON_CODE__D 0x0D
36 #define BSON_SYMBOL 0x0E
37 #define BSON_CODE 0x0F
38 #define BSON_INT 0x10
39 #define BSON_TIMESTAMP 0x11
40 #define BSON_LONG 0x12
41 #define BSON_MINKEY 0xFF
42 #define BSON_MAXKEY 0x7F
f46318e simple serialization
kristina authored
43
03698f3 realloc buffer
kristina authored
44 #define GROW_SLOWLY 1048576
02cb7bb @kchodorow fix large bindata segfault
kchodorow authored
45 #define INVALID_STRING_LEN(len) (len < 0 || len > (64*1024*1024))
b6dfa98 added array type
kristina authored
46
f04f9c5 @kchodorow move bson funcs to bson.c & big endian fix PHP-151
kchodorow authored
47 #define CREATE_BUF_STATIC(n) char b[n]; \
48 buf.start = buf.pos = b; \
49 buf.end = b+n;
50
b900cc6 check for db max recv length
Kristina Chodorow authored
51 int php_mongo_serialize_size(char *start, buffer *buf TSRMLS_DC);
c1dc6d4 oid, better regex
kristina authored
52
d262804 bson_encode and bson_decode
kristina authored
53 /* driver */
8d666b6 removed inlines MINOR
kristina authored
54 int php_mongo_serialize_element(char*, zval**, buffer*, int TSRMLS_DC);
d262804 bson_encode and bson_decode
kristina authored
55
56 /* objects */
57 void php_mongo_serialize_date(buffer*, zval* TSRMLS_DC);
58 void php_mongo_serialize_regex(buffer*, zval* TSRMLS_DC);
59 void php_mongo_serialize_code(buffer*, zval* TSRMLS_DC);
60 void php_mongo_serialize_ts(buffer*, zval* TSRMLS_DC);
61 void php_mongo_serialize_bin_data(buffer*, zval* TSRMLS_DC);
e3003cc @derickr - Added the mongo.native_int setting, that tries to use the platform'…
derickr authored
62 void php_mongo_serialize_int32(buffer*, zval* TSRMLS_DC);
63 void php_mongo_serialize_int64(buffer*, zval* TSRMLS_DC);
d262804 bson_encode and bson_decode
kristina authored
64
65 /* simple types */
8d666b6 removed inlines MINOR
kristina authored
66 void php_mongo_serialize_double(buffer*, double);
67 void php_mongo_serialize_string(buffer*, char*, int);
d3881d9 next version prep MINOR
kristina authored
68 void php_mongo_serialize_long(buffer*, int64_t);
8d666b6 removed inlines MINOR
kristina authored
69 void php_mongo_serialize_int(buffer*, int);
70 void php_mongo_serialize_byte(buffer*, char);
71 void php_mongo_serialize_bytes(buffer*, char*, int);
0fe8696 $ character can be something else, set in php.ini
kristina authored
72 void php_mongo_serialize_key(buffer*, char*, int, int TSRMLS_DC);
5d4ded2 Windows 5.2 compilation MINOR
U-ACER-6E40E97492\Kristina Chodorow authored
73 void php_mongo_serialize_ns(buffer*, char* TSRMLS_DC);
5455e4a optimizing inserts
kristina authored
74
e62c3c6 @kchodorow added bson max size detection
kchodorow authored
75 int php_mongo_write_insert(buffer*, char*, zval*, int max TSRMLS_DC);
5f56d8b @derickr First step at doing PHP-233: Passing the flags around.
derickr authored
76 int php_mongo_write_batch_insert(buffer*, char*, int flags, zval*, int max TSRMLS_DC);
84400a4 extract buffer functions
Kristina Chodorow authored
77 int php_mongo_write_query(buffer*, mongo_cursor* TSRMLS_DC);
78 int php_mongo_write_get_more(buffer*, mongo_cursor* TSRMLS_DC);
79 int php_mongo_write_delete(buffer*, char*, int, zval* TSRMLS_DC);
80 int php_mongo_write_update(buffer*, char*, int, zval*, zval* TSRMLS_DC);
22c3707 @kchodorow Kill all cursors whenever a connection is disconnected PHP-313
kchodorow authored
81 int php_mongo_write_kill_cursors(buffer*, int64_t TSRMLS_DC);
84400a4 extract buffer functions
Kristina Chodorow authored
82
8d666b6 removed inlines MINOR
kristina authored
83 #define php_mongo_set_type(buf, type) php_mongo_serialize_byte(buf, (char)type)
84 #define php_mongo_serialize_null(buf) php_mongo_serialize_byte(buf, (char)0)
85 #define php_mongo_serialize_bool(buf, b) php_mongo_serialize_byte(buf, (char)b)
f46318e simple serialization
kristina authored
86
6d6059a better buf resize
kristina authored
87 int resize_buf(buffer*, int);
676cf3c added buffer type
kristina authored
88
cb7e515 objects can be saved/retrieved
kristina authored
89 int zval_to_bson(buffer*, HashTable*, int TSRMLS_DC);
3b74ca0 Revert "fix the way numeric keys are returned"
Kristina Chodorow authored
90 char* bson_to_zval(char*, HashTable* TSRMLS_DC);
79be371 header ifdefs, more win compat
unknown authored
91
8d35439 @kchodorow string append helpers
kchodorow authored
92 /**
93 * Initialize buffer to contain "\0", so mongo_buf_append will start appending
94 * at the beginning.
95 */
96 void mongo_buf_init(char *dest);
97
98 /**
99 * Takes a buffer and a string to add to the buffer. The buffer must be large
ff66bf4 @kchodorow Comment edit
kchodorow authored
100 * enough to append the string and the string must be null-terminated. This will
101 * not work for strings containing null characters (e.g., BSON).
8d35439 @kchodorow string append helpers
kchodorow authored
102 */
103 void mongo_buf_append(char *dest, char *piece);
104
260c5ca big endian support
Kristina Chodorow authored
105 #if PHP_C_BIGENDIAN
8ccdb51 big endian BUG PHP-32
Kristina Chodorow authored
106 // reverse the bytes in an int
107 // wheeee stupid byte tricks
0f016cd neater big-endian handling MINOR
Kristina Chodorow authored
108 #define BYTE1_32(b) ((b & 0xff000000) >> 24)
109 #define BYTE2_32(b) ((b & 0x00ff0000) >> 8)
110 #define BYTE3_32(b) ((b & 0x0000ff00) << 8)
111 #define BYTE4_32(b) ((b & 0x000000ff) << 24)
112 #define MONGO_32(b) (BYTE4_32(b) | BYTE3_32(b) | BYTE2_32(b) | BYTE1_32(b))
113
114 #define BYTE1_64(b) ((b & 0xff00000000000000ll) >> 56)
115 #define BYTE2_64(b) ((b & 0x00ff000000000000ll) >> 40)
116 #define BYTE3_64(b) ((b & 0x0000ff0000000000ll) >> 24)
117 #define BYTE4_64(b) ((b & 0x000000ff00000000ll) >> 8)
118 #define BYTE5_64(b) ((b & 0x00000000ff000000ll) << 8)
119 #define BYTE6_64(b) ((b & 0x0000000000ff0000ll) << 24)
120 #define BYTE7_64(b) ((b & 0x000000000000ff00ll) << 40)
121 #define BYTE8_64(b) ((b & 0x00000000000000ffll) << 56)
122 #define MONGO_64(b) (BYTE8_64(b) | BYTE7_64(b) | BYTE6_64(b) | BYTE5_64(b) | BYTE4_64(b) | BYTE3_64(b) | BYTE2_64(b) | BYTE1_64(b))
123
124 #else
125 #define MONGO_32(b) (b)
126 #define MONGO_64(b) (b)
127 #endif
260c5ca big endian support
Kristina Chodorow authored
128
79be371 header ifdefs, more win compat
unknown authored
129 #endif
Something went wrong with that request. Please try again.