line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* Copyright 2014 MongoDB, Inc. |
3
|
|
|
|
|
|
|
* |
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 |
7
|
|
|
|
|
|
|
* |
8
|
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
|
|
|
|
* |
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
|
|
|
|
|
|
|
*/ |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#include "bson-memory.h" |
19
|
|
|
|
|
|
|
#include "bson-string.h" |
20
|
|
|
|
|
|
|
#include "bson-value.h" |
21
|
|
|
|
|
|
|
#include "bson-oid.h" |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
void |
25
|
0
|
|
|
|
|
|
bson_value_copy (const bson_value_t *src, /* IN */ |
26
|
|
|
|
|
|
|
bson_value_t *dst) /* OUT */ |
27
|
|
|
|
|
|
|
{ |
28
|
0
|
0
|
|
|
|
|
BSON_ASSERT (src); |
29
|
0
|
0
|
|
|
|
|
BSON_ASSERT (dst); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
dst->value_type = src->value_type; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
switch (src->value_type) { |
34
|
|
|
|
|
|
|
case BSON_TYPE_DOUBLE: |
35
|
0
|
|
|
|
|
|
dst->value.v_double = src->value.v_double; |
36
|
0
|
|
|
|
|
|
break; |
37
|
|
|
|
|
|
|
case BSON_TYPE_UTF8: |
38
|
0
|
|
|
|
|
|
dst->value.v_utf8.len = src->value.v_utf8.len; |
39
|
0
|
|
|
|
|
|
dst->value.v_utf8.str = bson_malloc (src->value.v_utf8.len + 1); |
40
|
0
|
|
|
|
|
|
memcpy (dst->value.v_utf8.str, |
41
|
0
|
|
|
|
|
|
src->value.v_utf8.str, |
42
|
0
|
|
|
|
|
|
dst->value.v_utf8.len); |
43
|
0
|
|
|
|
|
|
dst->value.v_utf8.str [dst->value.v_utf8.len] = '\0'; |
44
|
0
|
|
|
|
|
|
break; |
45
|
|
|
|
|
|
|
case BSON_TYPE_DOCUMENT: |
46
|
|
|
|
|
|
|
case BSON_TYPE_ARRAY: |
47
|
0
|
|
|
|
|
|
dst->value.v_doc.data_len = src->value.v_doc.data_len; |
48
|
0
|
|
|
|
|
|
dst->value.v_doc.data = bson_malloc (src->value.v_doc.data_len); |
49
|
0
|
|
|
|
|
|
memcpy (dst->value.v_doc.data, |
50
|
0
|
|
|
|
|
|
src->value.v_doc.data, |
51
|
0
|
|
|
|
|
|
dst->value.v_doc.data_len); |
52
|
0
|
|
|
|
|
|
break; |
53
|
|
|
|
|
|
|
case BSON_TYPE_BINARY: |
54
|
0
|
|
|
|
|
|
dst->value.v_binary.subtype = src->value.v_binary.subtype; |
55
|
0
|
|
|
|
|
|
dst->value.v_binary.data_len = src->value.v_binary.data_len; |
56
|
0
|
|
|
|
|
|
dst->value.v_binary.data = bson_malloc (src->value.v_binary.data_len); |
57
|
0
|
|
|
|
|
|
memcpy (dst->value.v_binary.data, |
58
|
0
|
|
|
|
|
|
src->value.v_binary.data, |
59
|
0
|
|
|
|
|
|
dst->value.v_binary.data_len); |
60
|
0
|
|
|
|
|
|
break; |
61
|
|
|
|
|
|
|
case BSON_TYPE_OID: |
62
|
0
|
|
|
|
|
|
bson_oid_copy (&src->value.v_oid, &dst->value.v_oid); |
63
|
0
|
|
|
|
|
|
break; |
64
|
|
|
|
|
|
|
case BSON_TYPE_BOOL: |
65
|
0
|
|
|
|
|
|
dst->value.v_bool = src->value.v_bool; |
66
|
0
|
|
|
|
|
|
break; |
67
|
|
|
|
|
|
|
case BSON_TYPE_DATE_TIME: |
68
|
0
|
|
|
|
|
|
dst->value.v_datetime = src->value.v_datetime; |
69
|
0
|
|
|
|
|
|
break; |
70
|
|
|
|
|
|
|
case BSON_TYPE_REGEX: |
71
|
0
|
|
|
|
|
|
dst->value.v_regex.regex = bson_strdup (src->value.v_regex.regex); |
72
|
0
|
|
|
|
|
|
dst->value.v_regex.options = bson_strdup (src->value.v_regex.options); |
73
|
0
|
|
|
|
|
|
break; |
74
|
|
|
|
|
|
|
case BSON_TYPE_DBPOINTER: |
75
|
0
|
|
|
|
|
|
dst->value.v_dbpointer.collection_len = src->value.v_dbpointer.collection_len; |
76
|
0
|
|
|
|
|
|
dst->value.v_dbpointer.collection = bson_malloc (src->value.v_dbpointer.collection_len + 1); |
77
|
0
|
|
|
|
|
|
memcpy (dst->value.v_dbpointer.collection, |
78
|
0
|
|
|
|
|
|
src->value.v_dbpointer.collection, |
79
|
0
|
|
|
|
|
|
dst->value.v_dbpointer.collection_len); |
80
|
0
|
|
|
|
|
|
dst->value.v_dbpointer.collection [dst->value.v_dbpointer.collection_len] = '\0'; |
81
|
0
|
|
|
|
|
|
bson_oid_copy (&src->value.v_dbpointer.oid, &dst->value.v_dbpointer.oid); |
82
|
0
|
|
|
|
|
|
break; |
83
|
|
|
|
|
|
|
case BSON_TYPE_CODE: |
84
|
0
|
|
|
|
|
|
dst->value.v_code.code_len = src->value.v_code.code_len; |
85
|
0
|
|
|
|
|
|
dst->value.v_code.code = bson_malloc (src->value.v_code.code_len + 1); |
86
|
0
|
|
|
|
|
|
memcpy (dst->value.v_code.code, |
87
|
0
|
|
|
|
|
|
src->value.v_code.code, |
88
|
0
|
|
|
|
|
|
dst->value.v_code.code_len); |
89
|
0
|
|
|
|
|
|
dst->value.v_code.code [dst->value.v_code.code_len] = '\0'; |
90
|
0
|
|
|
|
|
|
break; |
91
|
|
|
|
|
|
|
case BSON_TYPE_SYMBOL: |
92
|
0
|
|
|
|
|
|
dst->value.v_symbol.len = src->value.v_symbol.len; |
93
|
0
|
|
|
|
|
|
dst->value.v_symbol.symbol = bson_malloc (src->value.v_symbol.len + 1); |
94
|
0
|
|
|
|
|
|
memcpy (dst->value.v_symbol.symbol, |
95
|
0
|
|
|
|
|
|
src->value.v_symbol.symbol, |
96
|
0
|
|
|
|
|
|
dst->value.v_symbol.len); |
97
|
0
|
|
|
|
|
|
dst->value.v_symbol.symbol [dst->value.v_symbol.len] = '\0'; |
98
|
0
|
|
|
|
|
|
break; |
99
|
|
|
|
|
|
|
case BSON_TYPE_CODEWSCOPE: |
100
|
0
|
|
|
|
|
|
dst->value.v_codewscope.code_len = src->value.v_codewscope.code_len; |
101
|
0
|
|
|
|
|
|
dst->value.v_codewscope.code = bson_malloc (src->value.v_codewscope.code_len + 1); |
102
|
0
|
|
|
|
|
|
memcpy (dst->value.v_codewscope.code, |
103
|
0
|
|
|
|
|
|
src->value.v_codewscope.code, |
104
|
0
|
|
|
|
|
|
dst->value.v_codewscope.code_len); |
105
|
0
|
|
|
|
|
|
dst->value.v_codewscope.code [dst->value.v_codewscope.code_len] = '\0'; |
106
|
0
|
|
|
|
|
|
dst->value.v_codewscope.scope_len = src->value.v_codewscope.scope_len; |
107
|
0
|
|
|
|
|
|
dst->value.v_codewscope.scope_data = bson_malloc (src->value.v_codewscope.scope_len); |
108
|
0
|
|
|
|
|
|
memcpy (dst->value.v_codewscope.scope_data, |
109
|
0
|
|
|
|
|
|
src->value.v_codewscope.scope_data, |
110
|
0
|
|
|
|
|
|
dst->value.v_codewscope.scope_len); |
111
|
0
|
|
|
|
|
|
break; |
112
|
|
|
|
|
|
|
case BSON_TYPE_INT32: |
113
|
0
|
|
|
|
|
|
dst->value.v_int32 = src->value.v_int32; |
114
|
0
|
|
|
|
|
|
break; |
115
|
|
|
|
|
|
|
case BSON_TYPE_TIMESTAMP: |
116
|
0
|
|
|
|
|
|
dst->value.v_timestamp.timestamp = src->value.v_timestamp.timestamp; |
117
|
0
|
|
|
|
|
|
dst->value.v_timestamp.increment = src->value.v_timestamp.increment; |
118
|
0
|
|
|
|
|
|
break; |
119
|
|
|
|
|
|
|
case BSON_TYPE_INT64: |
120
|
0
|
|
|
|
|
|
dst->value.v_int64 = src->value.v_int64; |
121
|
0
|
|
|
|
|
|
break; |
122
|
|
|
|
|
|
|
case BSON_TYPE_DECIMAL128: |
123
|
0
|
|
|
|
|
|
dst->value.v_decimal128 = src->value.v_decimal128; |
124
|
0
|
|
|
|
|
|
break; |
125
|
|
|
|
|
|
|
case BSON_TYPE_UNDEFINED: |
126
|
|
|
|
|
|
|
case BSON_TYPE_NULL: |
127
|
|
|
|
|
|
|
case BSON_TYPE_MAXKEY: |
128
|
|
|
|
|
|
|
case BSON_TYPE_MINKEY: |
129
|
0
|
|
|
|
|
|
break; |
130
|
|
|
|
|
|
|
case BSON_TYPE_EOD: |
131
|
|
|
|
|
|
|
default: |
132
|
0
|
|
|
|
|
|
BSON_ASSERT (false); |
133
|
|
|
|
|
|
|
return; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
void |
139
|
0
|
|
|
|
|
|
bson_value_destroy (bson_value_t *value) /* IN */ |
140
|
|
|
|
|
|
|
{ |
141
|
0
|
|
|
|
|
|
switch (value->value_type) { |
142
|
|
|
|
|
|
|
case BSON_TYPE_UTF8: |
143
|
0
|
|
|
|
|
|
bson_free (value->value.v_utf8.str); |
144
|
0
|
|
|
|
|
|
break; |
145
|
|
|
|
|
|
|
case BSON_TYPE_DOCUMENT: |
146
|
|
|
|
|
|
|
case BSON_TYPE_ARRAY: |
147
|
0
|
|
|
|
|
|
bson_free (value->value.v_doc.data); |
148
|
0
|
|
|
|
|
|
break; |
149
|
|
|
|
|
|
|
case BSON_TYPE_BINARY: |
150
|
0
|
|
|
|
|
|
bson_free (value->value.v_binary.data); |
151
|
0
|
|
|
|
|
|
break; |
152
|
|
|
|
|
|
|
case BSON_TYPE_REGEX: |
153
|
0
|
|
|
|
|
|
bson_free (value->value.v_regex.regex); |
154
|
0
|
|
|
|
|
|
bson_free (value->value.v_regex.options); |
155
|
0
|
|
|
|
|
|
break; |
156
|
|
|
|
|
|
|
case BSON_TYPE_DBPOINTER: |
157
|
0
|
|
|
|
|
|
bson_free (value->value.v_dbpointer.collection); |
158
|
0
|
|
|
|
|
|
break; |
159
|
|
|
|
|
|
|
case BSON_TYPE_CODE: |
160
|
0
|
|
|
|
|
|
bson_free (value->value.v_code.code); |
161
|
0
|
|
|
|
|
|
break; |
162
|
|
|
|
|
|
|
case BSON_TYPE_SYMBOL: |
163
|
0
|
|
|
|
|
|
bson_free (value->value.v_symbol.symbol); |
164
|
0
|
|
|
|
|
|
break; |
165
|
|
|
|
|
|
|
case BSON_TYPE_CODEWSCOPE: |
166
|
0
|
|
|
|
|
|
bson_free (value->value.v_codewscope.code); |
167
|
0
|
|
|
|
|
|
bson_free (value->value.v_codewscope.scope_data); |
168
|
0
|
|
|
|
|
|
break; |
169
|
|
|
|
|
|
|
case BSON_TYPE_DOUBLE: |
170
|
|
|
|
|
|
|
case BSON_TYPE_UNDEFINED: |
171
|
|
|
|
|
|
|
case BSON_TYPE_OID: |
172
|
|
|
|
|
|
|
case BSON_TYPE_BOOL: |
173
|
|
|
|
|
|
|
case BSON_TYPE_DATE_TIME: |
174
|
|
|
|
|
|
|
case BSON_TYPE_NULL: |
175
|
|
|
|
|
|
|
case BSON_TYPE_INT32: |
176
|
|
|
|
|
|
|
case BSON_TYPE_TIMESTAMP: |
177
|
|
|
|
|
|
|
case BSON_TYPE_INT64: |
178
|
|
|
|
|
|
|
case BSON_TYPE_DECIMAL128: |
179
|
|
|
|
|
|
|
case BSON_TYPE_MAXKEY: |
180
|
|
|
|
|
|
|
case BSON_TYPE_MINKEY: |
181
|
|
|
|
|
|
|
case BSON_TYPE_EOD: |
182
|
|
|
|
|
|
|
default: |
183
|
0
|
|
|
|
|
|
break; |
184
|
|
|
|
|
|
|
} |
185
|
0
|
|
|
|
|
|
} |