bson_ext 1.10.2 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d278c9a30ed181d9c15cb67516357e850293be7
4
- data.tar.gz: 18337c3f95e788c04cc147f6ca70d363ad85e235
3
+ metadata.gz: 1adf4cc8e415e8905f01a81bb7a843cc480e0718
4
+ data.tar.gz: 4fc4a02485a5732bbc114186a6187d8e0ded4e7c
5
5
  SHA512:
6
- metadata.gz: dec066058371de96c436826fbeb6338cd13bfdf4e993aa752c9fbab3fc13a06347efa2492d9db809decb28ca1c926bdda18f3e5b4aa1322a0d4e57d37e0c1ce6
7
- data.tar.gz: e66e105459077d49f22cf84a958c1de785dd731889380e4771570a6f9240ffcbebb7089e7beae16bc68a90999a688c0d2a3865fb6facc28d4f459ef1039c4381
6
+ metadata.gz: 19e73866ad7299986a2ecb705de815d9074be2c903000b7c04b44a4e901c3810078b07f1137ebc84966b0ec4fd32ce1cc2a6a1dbc37f0d6c13943c62b34d27f0
7
+ data.tar.gz: 7a8a5c6c39a00b27a929eadbf06753785b7f0dc03fe713409532f3024be0284860951e933fd36e21b7de1618d3dee0bff67ab7d9d61d221595c672436bd65bea
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1 +1,2 @@
1
- 0~]�W8��2 ��:wA�X����|M�5Tv��l��z��^�?g�1���Eל�.�|!D;M#��$潊H(��S��H��?�k�Y� ��R'YN�3�YP�������7� ���P{� :�c�i��֞��쪣�Z��0�r襕�੒���\�e�]��?0y���ğ )8`����!�͆��oj�Qujt��4��q��Cs~4��� $�]��:B�Džh�=u��0�_%��I�J����S�a
1
+ }������Օ�ؖ�"fg����͛��6�az��3_
2
+ �#��-}zeUI *��\;��?X�1i�)�rFiӳ��)��I�xF�����,�u����E|}���Z�s>+���yT������)'_8a��J�rJ5͊�q� W��#��
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.10.2
1
+ 1.11.1
data/ext/cbson/cbson.c CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  #include "ruby.h"
24
24
  #include "version.h"
25
+ #include <arpa/inet.h>
25
26
 
26
27
  /* Ensure compatibility with early releases of Ruby 1.8.5 */
27
28
  #ifndef RSTRING_PTR
@@ -115,7 +116,7 @@ struct deserialize_opts {
115
116
  #define STR_NEW(p,n) \
116
117
  ({ \
117
118
  VALUE _str = rb_enc_str_new((p), (n), rb_utf8_encoding()); \
118
- rb_encoding* internal_encoding = rb_default_internal_encoding(); \
119
+ rb_encoding* internal_encoding = rb_default_internal_encoding();\
119
120
  if (internal_encoding) { \
120
121
  _str = rb_str_export_to_enc(_str, internal_encoding); \
121
122
  } \
@@ -167,11 +168,11 @@ static void write_utf8(bson_buffer_t buffer, VALUE string, int allow_null) {
167
168
  }
168
169
  #define FREE_INTSTRING(buffer) free(buffer)
169
170
  #else
170
- #define INT2STRING(buffer, i) \
171
- { \
171
+ #define INT2STRING(buffer, i) \
172
+ { \
172
173
  int vslength = snprintf(NULL, 0, "%d", i) + 1; \
173
- *buffer = malloc(vslength); \
174
- snprintf(*buffer, vslength, "%d", i); \
174
+ *buffer = malloc(vslength); \
175
+ snprintf(*buffer, vslength, "%d", i); \
175
176
  }
176
177
  #define FREE_INTSTRING(buffer) free(buffer)
177
178
  #endif
@@ -435,10 +436,10 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) {
435
436
  const char* cls = rb_obj_classname(value);
436
437
  if (strcmp(cls, "BSON::Binary") == 0 ||
437
438
  strcmp(cls, "ByteBuffer") == 0) {
438
- const char subtype = strcmp(cls, "ByteBuffer") ?
439
- (const char)FIX2INT(rb_funcall(value, rb_intern("subtype"), 0)) : 2;
440
439
  VALUE string_data = rb_funcall(value, rb_intern("to_s"), 0);
441
440
  int length = RSTRING_LENINT(string_data);
441
+ const char subtype = strcmp(cls, "ByteBuffer") ?
442
+ (const char)FIX2INT(rb_funcall(value, rb_intern("subtype"), 0)) : 2;
442
443
  write_name_and_type(buffer, key, 0x05);
443
444
  if (subtype == 2) {
444
445
  const int other_length = length + 4;
@@ -453,8 +454,8 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) {
453
454
  break;
454
455
  }
455
456
  if (strcmp(cls, "BSON::ObjectId") == 0) {
456
- VALUE as_array = rb_funcall(value, rb_intern("to_a"), 0);
457
457
  int i;
458
+ VALUE as_array = rb_funcall(value, rb_intern("to_a"), 0);
458
459
  write_name_and_type(buffer, key, 0x07);
459
460
  for (i = 0; i < 12; i++) {
460
461
  char byte = (char)FIX2INT(rb_ary_entry(as_array, i));
@@ -658,9 +659,10 @@ static void write_doc(bson_buffer_t buffer, VALUE hash, VALUE check_keys, VALUE
658
659
 
659
660
  // we have to check for an OrderedHash and handle that specially
660
661
  if (strcmp(rb_obj_classname(hash), "BSON::OrderedHash") == 0) {
661
- VALUE keys = rb_funcall(hash, rb_intern("keys"), 0);
662
662
  int i;
663
- for(i = 0; i < RARRAY_LEN(keys); i++) {
663
+ VALUE keys = rb_funcall(hash, rb_intern("keys"), 0);
664
+
665
+ for(i = 0; i < RARRAY_LEN(keys); i++) {
664
666
  VALUE key = rb_ary_entry(keys, i);
665
667
  VALUE value = rb_hash_aref(hash, key);
666
668
 
@@ -739,10 +741,11 @@ static VALUE get_value(const char* buffer, int* position,
739
741
  int size;
740
742
  memcpy(&size, buffer + *position, 4);
741
743
  if (strcmp(buffer + *position + 5, "$ref") == 0) { // DBRef
742
- int offset = *position + 10;
743
744
  VALUE argv[2];
744
- int collection_length = *(int*)(buffer + offset) - 1;
745
745
  unsigned char id_type;
746
+ int offset = *position + 10;
747
+ int collection_length = *(int*)(buffer + offset) - 1;
748
+
746
749
  offset += 4;
747
750
 
748
751
  argv[0] = STR_NEW(buffer + offset, collection_length);
@@ -766,9 +769,9 @@ static VALUE get_value(const char* buffer, int* position,
766
769
 
767
770
  value = rb_ary_new();
768
771
  while (*position < end) {
772
+ VALUE to_append;
769
773
  unsigned char type = (unsigned char)buffer[(*position)++];
770
774
  int key_size = (int)strlen(buffer + *position);
771
- VALUE to_append;
772
775
 
773
776
  *position += key_size + 1; // just skip the key, they're in order.
774
777
  to_append = get_value(buffer, position, type, opts);
@@ -847,11 +850,11 @@ static VALUE get_value(const char* buffer, int* position,
847
850
  int pattern_length = (int)strlen(buffer + *position);
848
851
  VALUE pattern = STR_NEW(buffer + *position, pattern_length);
849
852
  int flags_length;
850
- VALUE argv[3];
853
+ VALUE argv[3], flags_str;
851
854
  *position += pattern_length + 1;
852
855
 
853
856
  flags_length = (int)strlen(buffer + *position);
854
- VALUE flags_str = STR_NEW(buffer + *position, flags_length);
857
+ flags_str = STR_NEW(buffer + *position, flags_length);
855
858
  argv[0] = pattern;
856
859
  argv[1] = flags_str;
857
860
  value = rb_class_new_instance(2, argv, BSONRegex);
@@ -951,13 +954,13 @@ static VALUE get_value(const char* buffer, int* position,
951
954
  }
952
955
 
953
956
  static VALUE elements_to_hash(const char* buffer, int max, struct deserialize_opts * opts) {
954
- VALUE hash = rb_class_new_instance(0, NULL, OrderedHash);
955
957
  int position = 0;
958
+ VALUE hash = rb_class_new_instance(0, NULL, OrderedHash);
956
959
  while (position < max) {
960
+ VALUE value;
957
961
  unsigned char type = (unsigned char)buffer[position++];
958
962
  int name_length = (int)strlen(buffer + position);
959
963
  VALUE name = STR_NEW(buffer + position, name_length);
960
- VALUE value;
961
964
  position += name_length + 1;
962
965
  value = get_value(buffer, &position, type, opts);
963
966
  rb_funcall(hash, element_assignment_method, 2, name, value);
@@ -969,6 +972,7 @@ static VALUE method_deserialize(VALUE self, VALUE bson, VALUE opts) {
969
972
  const char* buffer = RSTRING_PTR(bson);
970
973
  int remaining = RSTRING_LENINT(bson);
971
974
  struct deserialize_opts deserialize_opts;
975
+
972
976
  deserialize_opts.compile_regex = 1;
973
977
  if (rb_funcall(opts, rb_intern("has_key?"), 1, ID2SYM(rb_intern("compile_regex"))) == Qtrue &&
974
978
  rb_hash_aref(opts, ID2SYM(rb_intern("compile_regex"))) == Qfalse) {
data/ext/cbson/version.h CHANGED
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- #define VERSION "1.10.2"
17
+ #define VERSION "1.11.1"
data/ext/csasl/csasl.c ADDED
@@ -0,0 +1,167 @@
1
+ // Copyright (C) 2014 MongoDB, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include <ruby.h>
16
+ #include <sasl/sasl.h>
17
+ #include <sasl/saslutil.h>
18
+
19
+ static void mongo_sasl_conn_free(void* data) {
20
+ sasl_conn_t *conn = (sasl_conn_t*) data;
21
+ // Ideally we would use sasl_client_done() but that's only available as of cyrus sasl 2.1.25
22
+ if(conn) sasl_done();
23
+ }
24
+
25
+ static sasl_conn_t* mongo_sasl_context(VALUE self) {
26
+ sasl_conn_t* conn;
27
+ VALUE context;
28
+ context = rb_iv_get(self, "@context");
29
+ Data_Get_Struct(context, sasl_conn_t, conn);
30
+ return conn;
31
+ }
32
+
33
+ static VALUE a_init(VALUE self, VALUE user_name, VALUE host_name, VALUE service_name, VALUE canonicalize_host_name)
34
+ {
35
+ if (sasl_client_init(NULL) == SASL_OK) {
36
+ rb_iv_set(self, "@valid", Qtrue);
37
+ rb_iv_set(self, "@user_name", user_name);
38
+ rb_iv_set(self, "@host_name", host_name);
39
+ rb_iv_set(self, "@service_name", service_name);
40
+ rb_iv_set(self, "@canonicalize_host_name", canonicalize_host_name);
41
+ }
42
+
43
+ else {
44
+ rb_iv_set(self, "@valid", Qfalse);
45
+ }
46
+
47
+ return self;
48
+ }
49
+
50
+ static VALUE valid(VALUE self) {
51
+ return rb_iv_get(self, "@valid");
52
+ }
53
+
54
+ int is_sasl_failure(int result)
55
+ {
56
+ if (result < 0) {
57
+ return 1;
58
+ }
59
+
60
+ return 0;
61
+ }
62
+
63
+ static int sasl_interact(VALUE self, int id, const char **result, unsigned *len) {
64
+ switch (id) {
65
+ case SASL_CB_AUTHNAME:
66
+ case SASL_CB_USER:
67
+ {
68
+ VALUE user_name;
69
+ user_name = rb_iv_get(self, "@user_name");
70
+ *result = RSTRING_PTR(user_name);
71
+ if (len) {
72
+ *len = RSTRING_LEN(user_name);
73
+ }
74
+ return SASL_OK;
75
+ }
76
+ }
77
+
78
+ return SASL_FAIL;
79
+ }
80
+
81
+ static VALUE initialize_challenge(VALUE self) {
82
+ int result;
83
+ char encoded_payload[4096];
84
+ const char *raw_payload;
85
+ unsigned int raw_payload_len, encoded_payload_len;
86
+ const char *mechanism_list = "GSSAPI";
87
+ const char *mechanism_selected = "GSSAPI";
88
+ VALUE context;
89
+ sasl_conn_t *conn;
90
+ sasl_callback_t client_interact [] = {
91
+ { SASL_CB_AUTHNAME, (int (*)(void))sasl_interact, (void*)self },
92
+ { SASL_CB_USER, (int (*)(void))sasl_interact, (void*)self },
93
+ { SASL_CB_LIST_END, NULL, NULL }
94
+ };
95
+
96
+ const char *servicename = RSTRING_PTR(rb_iv_get(self, "@service_name"));
97
+ const char *hostname = RSTRING_PTR(rb_iv_get(self, "@host_name"));
98
+
99
+ result = sasl_client_new(servicename, hostname, NULL, NULL, client_interact, 0, &conn);
100
+
101
+ if (result != SASL_OK) {
102
+ sasl_dispose(&conn);
103
+ return Qfalse;
104
+ }
105
+
106
+ context = Data_Wrap_Struct(rb_cObject, NULL, mongo_sasl_conn_free, conn);
107
+ rb_iv_set(self, "@context", context);
108
+
109
+ result = sasl_client_start(conn, mechanism_list, NULL, &raw_payload, &raw_payload_len, &mechanism_selected);
110
+ if (is_sasl_failure(result)) {
111
+ return Qfalse;
112
+ }
113
+
114
+ if (result != SASL_CONTINUE) {
115
+ return Qfalse;
116
+ }
117
+
118
+ result = sasl_encode64(raw_payload, raw_payload_len, encoded_payload, sizeof(encoded_payload), &encoded_payload_len);
119
+ if (is_sasl_failure(result)) {
120
+ return Qfalse;
121
+ }
122
+
123
+ encoded_payload[encoded_payload_len] = 0;
124
+ return rb_str_new(encoded_payload, encoded_payload_len);
125
+ }
126
+
127
+ static VALUE evaluate_challenge(VALUE self, VALUE rb_payload) {
128
+ char base_payload[4096], payload[4096];
129
+ const char *step_payload, *out;
130
+ unsigned int step_payload_len, payload_len, base_payload_len, outlen;
131
+ int result;
132
+ sasl_conn_t *conn = mongo_sasl_context(self);
133
+
134
+ StringValue(rb_payload);
135
+ step_payload = RSTRING_PTR(rb_payload);
136
+ step_payload_len = RSTRING_LEN(rb_payload);
137
+
138
+ result = sasl_decode64(step_payload, step_payload_len, base_payload, sizeof(base_payload), &base_payload_len);
139
+ if (is_sasl_failure(result)) {
140
+ return Qfalse;
141
+ }
142
+
143
+ result = sasl_client_step(conn, base_payload, base_payload_len, NULL, &out, &outlen);
144
+ if (is_sasl_failure(result)) {
145
+ return Qfalse;
146
+ }
147
+
148
+ result = sasl_encode64(out, outlen, payload, sizeof(payload), &payload_len);
149
+ if (is_sasl_failure(result)) {
150
+ return Qfalse;
151
+ }
152
+
153
+ return rb_str_new(payload, payload_len);
154
+ }
155
+
156
+ VALUE c_GSSAPI_authenticator;
157
+
158
+ void Init_csasl() {
159
+ VALUE mongo, sasl;
160
+ mongo = rb_const_get(rb_cObject, rb_intern("Mongo"));
161
+ sasl = rb_const_get(mongo, rb_intern("Sasl"));
162
+ c_GSSAPI_authenticator = rb_define_class_under(sasl, "GSSAPIAuthenticator", rb_cObject);
163
+ rb_define_method(c_GSSAPI_authenticator, "initialize", a_init, 4);
164
+ rb_define_method(c_GSSAPI_authenticator, "initialize_challenge", initialize_challenge, 0);
165
+ rb_define_method(c_GSSAPI_authenticator, "evaluate_challenge", evaluate_challenge, 1);
166
+ rb_define_method(rb_cObject, "valid?", valid, 0);
167
+ }
@@ -0,0 +1,8 @@
1
+ require 'mkmf'
2
+ find_header('sasl/sasl.h')
3
+
4
+ if have_library('sasl2', 'sasl_version')
5
+ create_makefile('csasl/csasl')
6
+ else
7
+ abort "libsasl (cyrus sasl) is required in the system to install the mongo_kerberos gem."
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bson_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.2
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emily Stolfo
@@ -34,7 +34,7 @@ cert_chain:
34
34
  JrZM8w8wGbIOeLtoQqa7HB/jOYbTahH7KMNh2LHAbOR93hNIJxVRa4iwxiMQ75tN
35
35
  9WUIAJ4AEtjwRg1Bz0OwDo3aucPCBpx77+/FWhv7JYY=
36
36
  -----END CERTIFICATE-----
37
- date: 2014-06-16 00:00:00.000000000 Z
37
+ date: 2014-09-15 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: bson
@@ -42,14 +42,14 @@ dependencies:
42
42
  requirements:
43
43
  - - "~>"
44
44
  - !ruby/object:Gem::Version
45
- version: 1.10.2
45
+ version: 1.11.1
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: 1.10.2
52
+ version: 1.11.1
53
53
  description: C extensions to accelerate the Ruby BSON serialization. For more information
54
54
  about BSON, see http://bsonspec.org. For information about MongoDB, see http://www.mongodb.org.
55
55
  email: mongodb-dev@googlegroups.com
@@ -68,6 +68,8 @@ files:
68
68
  - ext/cbson/encoding_helpers.h
69
69
  - ext/cbson/extconf.rb
70
70
  - ext/cbson/version.h
71
+ - ext/csasl/csasl.c
72
+ - ext/csasl/extconf.rb
71
73
  homepage: http://www.mongodb.org
72
74
  licenses:
73
75
  - Apache License Version 2.0
metadata.gz.sig CHANGED
@@ -1 +1 @@
1
- c�S�:w���}�j���4�wz&�nX�猪@�N71����͎y1iU���o�`!�9�?��[��Kt�%!Y?���;��[�72D����L(��n? K)h]p$�S3㣑x �� �|BG L1��S�!�,�dIIz2%c��yǞ�u�����[�J�4�� M5B�Y�"f��(ghɘ����> 9��k���������"������+��;({��GiNcjdc�W�O�٨�3��
1
+ .kB��m�$�Ĕ׃���/�_$V{�%T��β*9.�9 ,l�j۫�Z���W\��q5tO�ڢ�E�osxQi�3�!���~LLP+pW�մ`~eV��#UG,Ҵ������p��SL�(\K���?L���iӉj8-��8a:�;rSHD?�K���=�C��dr��qZu,(����7��4�����e��CӪ�e��lŠ@qI8F_ҬM�pP(O�J��f�J R7�?���.�\�����#%H