Skip to content

Commit 1c6b760

Browse files
committed
auth support for the perl client
1 parent fc8962d commit 1c6b760

File tree

5 files changed

+43
-54
lines changed

5 files changed

+43
-54
lines changed

docs-en/protocol.en.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Basic syntax
1111
distinguish NULL from an empty string, as most DBMs does so.
1212
- NULL is expressed as a single NUL(0x00).
1313
- An encoded string is a string with the following encoding rules.
14-
- Characters in the range [0x10 - 0xff] are not encoded.
14+
- Characters in the range [0x10 - 0xff] are encoded as itselves.
1515
- A character in the range [0x00 - 0x0f] is prefixed by 0x01 and
1616
shifted by 0x40. For example, 0x03 is encoded as 0x01 0x43.
1717
- Note that a string can be empty. A continuation of 0x09 0x09 means that

libhsclient/hstcpcli.cpp

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,7 @@ struct hstcpcli : public hstcpcli_i, private noncopyable {
3131
virtual bool stable_point();
3232
virtual void request_buf_open_index(size_t pst_id, const char *dbn,
3333
const char *tbl, const char *idx, const char *retflds, const char *filflds);
34-
virtual void request_buf_auth(const char *secret);
35-
#if 0
36-
virtual void request_buf_find(size_t pst_id, const string_ref& op,
37-
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip);
38-
virtual void request_buf_insert(size_t pst_id, const string_ref *fvs,
39-
size_t fvslen);
40-
virtual void request_buf_update(size_t pst_id, const string_ref& op,
41-
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip,
42-
const string_ref *mvs, size_t mvslen);
43-
virtual void request_buf_delete(size_t pst_id, const string_ref& op,
44-
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip);
45-
#endif
34+
virtual void request_buf_auth(const char *secret, const char *typ);
4635
virtual void request_buf_exec_generic(size_t pst_id, const string_ref& op,
4736
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip,
4837
const string_ref& mod_op, const string_ref *mvs, size_t mvslen,
@@ -199,15 +188,21 @@ hstcpcli::request_buf_open_index(size_t pst_id, const char *dbn,
199188
}
200189

201190
void
202-
hstcpcli::request_buf_auth(const char *secret)
191+
hstcpcli::request_buf_auth(const char *secret, const char *typ)
203192
{
204193
if (num_req_sent > 0 || num_req_rcvd > 0) {
205194
close();
206195
set_error(-1, "request_buf_auth: protocol out of sync");
207196
return;
208197
}
198+
if (typ == 0) {
199+
typ = "1";
200+
}
201+
const string_ref typ_ref(typ, strlen(typ));
209202
const string_ref secret_ref(secret, strlen(secret));
210-
writebuf.append_literal("A\t1\t");
203+
writebuf.append_literal("A\t");
204+
writebuf.append(typ_ref.begin(), typ_ref.end());
205+
writebuf.append_literal("\t");
211206
writebuf.append(secret_ref.begin(), secret_ref.end());
212207
writebuf.append_literal("\n");
213208
++num_req_bufd;
@@ -295,44 +290,6 @@ hstcpcli::request_buf_exec_generic(size_t pst_id, const string_ref& op,
295290
++num_req_bufd;
296291
}
297292

298-
#if 0
299-
void
300-
hstcpcli::request_buf_find(size_t pst_id, const string_ref& op,
301-
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip)
302-
{
303-
return request_buf_exec_generic(pst_id, op, kvs, kvslen, limit, skip,
304-
0, 0, 0);
305-
}
306-
307-
void
308-
hstcpcli::request_buf_insert(size_t pst_id, const string_ref *fvs,
309-
size_t fvslen)
310-
{
311-
const string_ref insert_op("+", 1);
312-
return request_buf_exec_generic(pst_id, insert_op, fvs, fvslen,
313-
0, 0, string_ref(), 0, 0);
314-
}
315-
316-
void
317-
hstcpcli::request_buf_update(size_t pst_id, const string_ref& op,
318-
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip,
319-
const string_ref *mvs, size_t mvslen)
320-
{
321-
const string_ref modop_update("U", 1);
322-
return request_buf_exec_generic(pst_id, op, kvs, kvslen, limit, skip,
323-
modop_update, mvs, mvslen);
324-
}
325-
326-
void
327-
hstcpcli::request_buf_delete(size_t pst_id, const string_ref& op,
328-
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip)
329-
{
330-
const string_ref modop_delete("D", 1);
331-
return request_buf_exec_generic(pst_id, op, kvs, kvslen, limit, skip,
332-
modop_delete, 0, 0);
333-
}
334-
#endif
335-
336293
int
337294
hstcpcli::request_send()
338295
{

libhsclient/hstcpcli.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct hstcpcli_i {
3737
virtual void close() = 0;
3838
virtual int reconnect() = 0;
3939
virtual bool stable_point() = 0;
40-
virtual void request_buf_auth(const char *secret) = 0;
40+
virtual void request_buf_auth(const char *secret, const char *typ) = 0;
4141
virtual void request_buf_open_index(size_t pst_id, const char *dbn,
4242
const char *tbl, const char *idx, const char *retflds,
4343
const char *filflds = 0) = 0;

perl-Net-HandlerSocket/HandlerSocket.xs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,34 @@ CODE:
431431
OUTPUT:
432432
RETVAL
433433

434+
int
435+
auth(obj, key, typ = 0)
436+
SV *obj
437+
const char *key
438+
const char *typ
439+
CODE:
440+
RETVAL = 0;
441+
dena::hstcpcli_i *const ptr =
442+
reinterpret_cast<dena::hstcpcli_i *>(SvIV(SvRV(obj)));
443+
do {
444+
ptr->request_buf_auth(key, typ);
445+
if (ptr->request_send() != 0) {
446+
break;
447+
}
448+
size_t nflds = 0;
449+
ptr->response_recv(nflds);
450+
const int e = ptr->get_error_code();
451+
DBG(fprintf(stderr, "errcode=%d\n", ptr->get_error_code()));
452+
if (e >= 0) {
453+
ptr->response_buf_remove();
454+
}
455+
DBG(fprintf(stderr, "errcode=%d\n", ptr->get_error_code()));
456+
} while (0);
457+
RETVAL = ptr->get_error_code();
458+
OUTPUT:
459+
RETVAL
460+
461+
434462
int
435463
open_index(obj, id, db, table, index, fields, ffields = 0)
436464
SV *obj

regtest/common/hstest.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ sub init_conf {
2121
$conf{user} = get_conf_env("MYSQLUSER", "root");
2222
$conf{pass} = get_conf_env("MYSQLPASS", "");
2323
$conf{hsport} = get_conf_env("HSPORT", 9998);
24+
$conf{hspass} = get_conf_env("HSPASS", undef);
2425
}
2526

2627
sub get_dbi_connection {
@@ -52,6 +53,9 @@ sub get_hs_connection {
5253
$port ||= $conf{hsport};
5354
my $hsargs = { 'host' => $host, 'port' => $port };
5455
my $conn = new Net::HandlerSocket($hsargs);
56+
if (defined($conn) && defined($conf{hspass})) {
57+
$conn->auth($conf{hspass});
58+
}
5559
return $conn;
5660
}
5761

0 commit comments

Comments
 (0)