trilogy 2.1.1 → 2.2.0

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
  SHA256:
3
- metadata.gz: dfc4650b825c98729088e61bc236c2eff05aa0f3d535266452c24102af549c76
4
- data.tar.gz: 630c3fbf67cf7c1b0dc70e680bd7bce7983217034706bff5abe9e71eb0de5f42
3
+ metadata.gz: ff98f0678711dd36bae4c5f8a7e0f399d3391f393816bc8df4c4281dbfd5d53f
4
+ data.tar.gz: 13914f66cde555a81814e4f2b1761895bb1e33b026a2e7d8e3b74888862e9b69
5
5
  SHA512:
6
- metadata.gz: 67596acf1ce6f0ac50008cce49cecff33cf7f33053a2e24a3ed70cc702beb71d9a5c92a8d72b6ff25d1c4d588ab84fcfccbba9d155d52739044ce1eb302f18ad
7
- data.tar.gz: d00a2e65e8fb73fa0bfb7a82054007a619075fbd5863602958119047df08e0881425b3612b947542449ee988cc2b21557925b29b26992958d5aa6d48ccf7f150
6
+ metadata.gz: 8f629502bc41dc22b8ebb65a00fb207d0bd41951d085b7bdd1d9de9956caf2b2c5f9504a533194b6fc5de30883330305482128091f4d417913b576233bf199e6
7
+ data.tar.gz: 2342f373109f087b89e6802a2d7e6c05f4c6c1ed938a820af404b87c961b8ef455dad3c3ec1d8b32270340583a3cbb31bf38251d9ff0a7fa892c13c3f55c8307
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/extensiontask"
3
+ require "rake/testtask"
3
4
 
4
5
  Rake::ExtensionTask.new do |ext|
5
6
  ext.name = "cext"
@@ -7,9 +8,12 @@ Rake::ExtensionTask.new do |ext|
7
8
  ext.lib_dir = "lib/trilogy"
8
9
  end
9
10
 
10
- task :test => :compile do
11
- system('script/test')
11
+ Rake::TestTask.new do |t|
12
+ t.libs << "test"
13
+ t.test_files = FileList['test/*_test.rb']
14
+ t.verbose = true
12
15
  end
16
+ task :test => :compile
13
17
 
14
18
  task :default => :test
15
19
 
@@ -31,10 +31,39 @@ struct trilogy_ctx {
31
31
  unsigned int query_flags;
32
32
  };
33
33
 
34
+ static void free_trilogy(void *ptr)
35
+ {
36
+ struct trilogy_ctx *ctx = ptr;
37
+ if (ctx->conn.socket != NULL) {
38
+ trilogy_free(&ctx->conn);
39
+ }
40
+ xfree(ptr);
41
+ }
42
+
43
+ static size_t trilogy_memsize(const void *ptr) {
44
+ const struct trilogy_ctx *ctx = ptr;
45
+ size_t memsize = sizeof(struct trilogy_ctx);
46
+ if (ctx->conn.socket != NULL) {
47
+ memsize += sizeof(trilogy_sock_t);
48
+ }
49
+ memsize += ctx->conn.packet_buffer.cap;
50
+ return memsize;
51
+ }
52
+
53
+ const rb_data_type_t trilogy_data_type = {
54
+ .wrap_struct_name = "trilogy",
55
+ .function = {
56
+ .dmark = NULL,
57
+ .dfree = free_trilogy,
58
+ .dsize = trilogy_memsize,
59
+ },
60
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
61
+ };
62
+
34
63
  static struct trilogy_ctx *get_ctx(VALUE obj)
35
64
  {
36
65
  struct trilogy_ctx *ctx;
37
- Data_Get_Struct(obj, struct trilogy_ctx, ctx);
66
+ TypedData_Get_Struct(obj, struct trilogy_ctx, &trilogy_data_type, ctx);
38
67
  return ctx;
39
68
  }
40
69
 
@@ -91,20 +120,11 @@ static void handle_trilogy_error(struct trilogy_ctx *ctx, int rc, const char *ms
91
120
  }
92
121
  }
93
122
 
94
- static void free_trilogy(struct trilogy_ctx *ctx)
95
- {
96
- if (ctx->conn.socket != NULL) {
97
- trilogy_free(&ctx->conn);
98
- }
99
- }
100
-
101
123
  static VALUE allocate_trilogy(VALUE klass)
102
124
  {
103
125
  struct trilogy_ctx *ctx;
104
126
 
105
- VALUE obj = Data_Make_Struct(klass, struct trilogy_ctx, NULL, free_trilogy, ctx);
106
-
107
- memset(ctx->server_version, 0, sizeof(ctx->server_version));
127
+ VALUE obj = TypedData_Make_Struct(klass, struct trilogy_ctx, &trilogy_data_type, ctx);
108
128
 
109
129
  ctx->query_flags = TRILOGY_FLAGS_DEFAULT;
110
130
 
@@ -826,6 +846,17 @@ static VALUE rb_trilogy_close(VALUE self)
826
846
  return Qnil;
827
847
  }
828
848
 
849
+ static VALUE rb_trilogy_closed(VALUE self)
850
+ {
851
+ struct trilogy_ctx *ctx = get_ctx(self);
852
+
853
+ if (ctx->conn.socket == NULL) {
854
+ return Qtrue;
855
+ } else {
856
+ return Qfalse;
857
+ }
858
+ }
859
+
829
860
  static VALUE rb_trilogy_last_insert_id(VALUE self) { return ULL2NUM(get_open_ctx(self)->conn.last_insert_id); }
830
861
 
831
862
  static VALUE rb_trilogy_affected_rows(VALUE self) { return ULL2NUM(get_open_ctx(self)->conn.affected_rows); }
@@ -897,6 +928,7 @@ void Init_cext()
897
928
  rb_define_method(Trilogy, "ping", rb_trilogy_ping, 0);
898
929
  rb_define_method(Trilogy, "escape", rb_trilogy_escape, 1);
899
930
  rb_define_method(Trilogy, "close", rb_trilogy_close, 0);
931
+ rb_define_method(Trilogy, "closed?", rb_trilogy_closed, 0);
900
932
  rb_define_method(Trilogy, "last_insert_id", rb_trilogy_last_insert_id, 0);
901
933
  rb_define_method(Trilogy, "affected_rows", rb_trilogy_affected_rows, 0);
902
934
  rb_define_method(Trilogy, "warning_count", rb_trilogy_warning_count, 0);
@@ -26,7 +26,7 @@ typedef struct {
26
26
  * buffer - A pre-initialized trilogy_buffer_t pointer
27
27
  * seq - The initial sequence number for the packet to be built. This is
28
28
  * the initial number because the builder API will automatically
29
- * split buffers that are larger than TRILOGY_MAX_PROTO_PACKET_LEN into
29
+ * split buffers that are larger than TRILOGY_MAX_PACKET_LEN into
30
30
  * multiple packets and increment the sequence number in each packet
31
31
  * following the initial.
32
32
  *
@@ -370,11 +370,6 @@ typedef enum {
370
370
  #undef XX
371
371
  } TRILOGY_COLUMN_FLAG_t;
372
372
 
373
- /*
374
- * Data between client and server is exchanged in packets of max 16MByte size.
375
- */
376
- #define TRILOGY_MAX_PROTO_PACKET_LEN 0xffffff
377
-
378
373
  // Typical response packet types
379
374
  typedef enum {
380
375
  TRILOGY_PACKET_OK = 0x0,
@@ -261,16 +261,7 @@ int trilogy_parse_handshake_packet(const uint8_t *buff, size_t len, trilogy_hand
261
261
  // This space is reserved. It should be all NULL bytes but some tools or
262
262
  // future versions of MySQL-compatible clients may use it. This library
263
263
  // opts to skip the validation as some servers don't respect the protocol.
264
- //
265
- static const uint8_t null_filler[10] = {0};
266
-
267
- const void *str;
268
- CHECKED(trilogy_reader_get_buffer(&reader, 10, &str));
269
-
270
- if (memcmp(str, null_filler, 10) != 0) {
271
- // corrupt handshake packet
272
- return TRILOGY_PROTOCOL_VIOLATION;
273
- }
264
+ CHECKED(trilogy_reader_get_buffer(&reader, 10, NULL));
274
265
 
275
266
  if (out_packet->capabilities & TRILOGY_CAPABILITIES_SECURE_CONNECTION && auth_data_len > 8) {
276
267
  uint8_t remaining_auth_data_len = auth_data_len - 8;
@@ -579,10 +570,12 @@ int trilogy_build_auth_switch_response_packet(trilogy_builder_t *builder, const
579
570
  unsigned int auth_response_len = 0;
580
571
  uint8_t auth_response[EVP_MAX_MD_SIZE];
581
572
 
582
- if (!strcmp("caching_sha2_password", auth_plugin)) {
583
- trilogy_pack_scramble_sha2_hash(scramble, pass, pass_len, auth_response, &auth_response_len);
584
- } else {
585
- trilogy_pack_scramble_native_hash(scramble, pass, pass_len, auth_response, &auth_response_len);
573
+ if (pass_len > 0) {
574
+ if (!strcmp("caching_sha2_password", auth_plugin)) {
575
+ trilogy_pack_scramble_sha2_hash(scramble, pass, pass_len, auth_response, &auth_response_len);
576
+ } else {
577
+ trilogy_pack_scramble_native_hash(scramble, pass, pass_len, auth_response, &auth_response_len);
578
+ }
586
579
  }
587
580
 
588
581
  CHECKED(trilogy_builder_write_buffer(builder, auth_response, auth_response_len));
@@ -1,3 +1,3 @@
1
1
  class Trilogy
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trilogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-31 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler