bson_ext_ns 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright 2009-2010 10gen, 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
+ #include "encoding_helpers.h"
18
+
19
+ /*
20
+ * Portions Copyright 2001 Unicode, Inc.
21
+ *
22
+ * Disclaimer
23
+ *
24
+ * This source code is provided as is by Unicode, Inc. No claims are
25
+ * made as to fitness for any particular purpose. No warranties of any
26
+ * kind are expressed or implied. The recipient agrees to determine
27
+ * applicability of information provided. If this file has been
28
+ * purchased on magnetic or optical media from Unicode, Inc., the
29
+ * sole remedy for any claim will be exchange of defective media
30
+ * within 90 days of receipt.
31
+ *
32
+ * Limitations on Rights to Redistribute This Code
33
+ *
34
+ * Unicode, Inc. hereby grants the right to freely use the information
35
+ * supplied in this file in the creation of products supporting the
36
+ * Unicode Standard, and to make copies of this file in any form
37
+ * for internal or external distribution as long as this notice
38
+ * remains attached.
39
+ */
40
+
41
+ /*
42
+ * Index into the table below with the first byte of a UTF-8 sequence to
43
+ * get the number of trailing bytes that are supposed to follow it.
44
+ */
45
+ static const char trailingBytesForUTF8[256] = {
46
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
47
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
48
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
49
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
50
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
51
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
52
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
53
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
54
+ };
55
+
56
+ /* --------------------------------------------------------------------- */
57
+
58
+ /*
59
+ * Utility routine to tell whether a sequence of bytes is legal UTF-8.
60
+ * This must be called with the length pre-determined by the first byte.
61
+ * The length can be set by:
62
+ * length = trailingBytesForUTF8[*source]+1;
63
+ * and the sequence is illegal right away if there aren't that many bytes
64
+ * available.
65
+ * If presented with a length > 4, this returns 0. The Unicode
66
+ * definition of UTF-8 goes up to 4-byte sequences.
67
+ */
68
+ static unsigned char isLegalUTF8(const unsigned char* source, int length) {
69
+ unsigned char a;
70
+ const unsigned char* srcptr = source + length;
71
+ switch (length) {
72
+ default: return 0;
73
+ /* Everything else falls through when "true"... */
74
+ case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
75
+ case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
76
+ case 2: if ((a = (*--srcptr)) > 0xBF) return 0;
77
+ switch (*source) {
78
+ /* no fall-through in this inner switch */
79
+ case 0xE0: if (a < 0xA0) return 0; break;
80
+ case 0xF0: if (a < 0x90) return 0; break;
81
+ case 0xF4: if (a > 0x8F) return 0; break;
82
+ default: if (a < 0x80) return 0;
83
+ }
84
+ case 1: if (*source >= 0x80 && *source < 0xC2) return 0;
85
+ if (*source > 0xF4) return 0;
86
+ }
87
+ return 1;
88
+ }
89
+
90
+ result_t check_string(const unsigned char* string, const int length,
91
+ const char check_utf8, const char check_null) {
92
+ int position = 0;
93
+ /* By default we go character by character. Will be different for checking
94
+ * UTF-8 */
95
+ int sequence_length = 1;
96
+
97
+ if (!check_utf8 && !check_null) {
98
+ return VALID;
99
+ }
100
+
101
+ while (position < length) {
102
+ if (check_null && *(string + position) == 0) {
103
+ return HAS_NULL;
104
+ }
105
+ if (check_utf8) {
106
+ sequence_length = trailingBytesForUTF8[*(string + position)] + 1;
107
+ if ((position + sequence_length) > length) {
108
+ return NOT_UTF_8;
109
+ }
110
+ if (!isLegalUTF8(string + position, sequence_length)) {
111
+ return NOT_UTF_8;
112
+ }
113
+ }
114
+ position += sequence_length;
115
+ }
116
+
117
+ return VALID;
118
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright 2009-2010 10gen, 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
+ #ifndef ENCODING_HELPERS_H
18
+ #define ENCODING_HELPERS_H
19
+
20
+ typedef enum {
21
+ VALID,
22
+ NOT_UTF_8,
23
+ HAS_NULL
24
+ } result_t;
25
+
26
+ result_t check_string(const unsigned char* string, const int length,
27
+ const char check_utf8, const char check_null);
28
+
29
+ #endif
@@ -0,0 +1,10 @@
1
+ require 'mkmf'
2
+
3
+ have_func("asprintf")
4
+
5
+ have_header("ruby/st.h") || have_header("st.h")
6
+ have_header("ruby/regex.h") || have_header("regex.h")
7
+ have_header("ruby/encoding.h")
8
+
9
+ dir_config('cbson')
10
+ create_makefile('bson_ext/cbson')
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2009-2010 10gen, 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
+ #define VERSION "1.3.1"
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bson_ext_ns
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 1
10
+ version: 1.3.1
11
+ platform: ruby
12
+ authors:
13
+ - Mike Dirolf
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-08 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: C extensions to accelerate the Ruby BSON serialization. For more information about BSON, see http://bsonspec.org. For information about MongoDB, see http://www.mongodb.org.
23
+ email: mongodb-dev@googlegroups.com
24
+ executables: []
25
+
26
+ extensions:
27
+ - ext/cbson/extconf.rb
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - Rakefile
32
+ - bson_ext.gemspec
33
+ - ext/cbson/extconf.rb
34
+ - ext/cbson/buffer.c
35
+ - ext/cbson/cbson.c
36
+ - ext/cbson/encoding_helpers.c
37
+ - ext/cbson/buffer.h
38
+ - ext/cbson/encoding_helpers.h
39
+ - ext/cbson/version.h
40
+ has_rdoc: true
41
+ homepage: http://www.mongodb.org
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - ext
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: C extensions for Ruby BSON.
74
+ test_files: []
75
+