kbaum-mongo_ext 0.18.3p

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 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 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('mongo_ext/cbson')
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2009 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 "0.18.3p"
@@ -0,0 +1,23 @@
1
+ require 'lib/mongo'
2
+ VERSION_HEADER = File.open(File.join(File.dirname(__FILE__), 'ext', 'cbson', 'version.h'), "r")
3
+ VERSION = VERSION_HEADER.read.scan(/VERSION\s+"(\d+\.\d+(\.\d+\w*)?)\"/)[0][0]
4
+ Gem::Specification.new do |s|
5
+ s.name = 'kbaum-mongo_ext'
6
+
7
+ s.version = VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = 'C extensions for the MongoDB Ruby driver'
10
+ s.description = 'C extensions to accelerate the MongoDB Ruby driver. For more information about Mongo, see http://www.mongodb.org.'
11
+
12
+ s.require_paths = ['ext']
13
+ s.files = ['Rakefile', 'mongo-extensions.gemspec']
14
+ s.files += Dir['ext/**/*.rb'] + Dir['ext/**/*.c'] + Dir['ext/**/*.h']
15
+ s.test_files = []
16
+
17
+ s.has_rdoc = false
18
+ s.extensions << 'ext/cbson/extconf.rb'
19
+
20
+ s.author = 'Mike Dirolf'
21
+ s.email = 'mongodb-dev@googlegroups.com'
22
+ s.homepage = 'http://www.mongodb.org'
23
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kbaum-mongo_ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.18.3p
5
+ platform: ruby
6
+ authors:
7
+ - Mike Dirolf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-24 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: C extensions to accelerate the MongoDB Ruby driver. For more information about Mongo, see http://www.mongodb.org.
17
+ email: mongodb-dev@googlegroups.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/cbson/extconf.rb
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - Rakefile
26
+ - mongo-extensions.gemspec
27
+ - ext/cbson/extconf.rb
28
+ - ext/cbson/buffer.c
29
+ - ext/cbson/cbson.c
30
+ - ext/cbson/encoding_helpers.c
31
+ - ext/cbson/buffer.h
32
+ - ext/cbson/encoding_helpers.h
33
+ - ext/cbson/version.h
34
+ has_rdoc: true
35
+ homepage: http://www.mongodb.org
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - ext
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.1
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.5
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: C extensions for the MongoDB Ruby driver
62
+ test_files: []
63
+