Skip to content
Browse files

auth support for the perl client

  • Loading branch information...
1 parent fc8962d commit 1c6b7602715aef363212df65be0427b346c6eb08 @ahiguti committed
View
2 docs-en/protocol.en.txt
@@ -11,7 +11,7 @@ Basic syntax
distinguish NULL from an empty string, as most DBMs does so.
- NULL is expressed as a single NUL(0x00).
- An encoded string is a string with the following encoding rules.
- - Characters in the range [0x10 - 0xff] are not encoded.
+ - Characters in the range [0x10 - 0xff] are encoded as itselves.
- A character in the range [0x00 - 0x0f] is prefixed by 0x01 and
shifted by 0x40. For example, 0x03 is encoded as 0x01 0x43.
- Note that a string can be empty. A continuation of 0x09 0x09 means that
View
61 libhsclient/hstcpcli.cpp
@@ -31,18 +31,7 @@ struct hstcpcli : public hstcpcli_i, private noncopyable {
virtual bool stable_point();
virtual void request_buf_open_index(size_t pst_id, const char *dbn,
const char *tbl, const char *idx, const char *retflds, const char *filflds);
- virtual void request_buf_auth(const char *secret);
- #if 0
- virtual void request_buf_find(size_t pst_id, const string_ref& op,
- const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip);
- virtual void request_buf_insert(size_t pst_id, const string_ref *fvs,
- size_t fvslen);
- virtual void request_buf_update(size_t pst_id, const string_ref& op,
- const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip,
- const string_ref *mvs, size_t mvslen);
- virtual void request_buf_delete(size_t pst_id, const string_ref& op,
- const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip);
- #endif
+ virtual void request_buf_auth(const char *secret, const char *typ);
virtual void request_buf_exec_generic(size_t pst_id, const string_ref& op,
const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip,
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,
}
void
-hstcpcli::request_buf_auth(const char *secret)
+hstcpcli::request_buf_auth(const char *secret, const char *typ)
{
if (num_req_sent > 0 || num_req_rcvd > 0) {
close();
set_error(-1, "request_buf_auth: protocol out of sync");
return;
}
+ if (typ == 0) {
+ typ = "1";
+ }
+ const string_ref typ_ref(typ, strlen(typ));
const string_ref secret_ref(secret, strlen(secret));
- writebuf.append_literal("A\t1\t");
+ writebuf.append_literal("A\t");
+ writebuf.append(typ_ref.begin(), typ_ref.end());
+ writebuf.append_literal("\t");
writebuf.append(secret_ref.begin(), secret_ref.end());
writebuf.append_literal("\n");
++num_req_bufd;
@@ -295,44 +290,6 @@ hstcpcli::request_buf_exec_generic(size_t pst_id, const string_ref& op,
++num_req_bufd;
}
-#if 0
-void
-hstcpcli::request_buf_find(size_t pst_id, const string_ref& op,
- const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip)
-{
- return request_buf_exec_generic(pst_id, op, kvs, kvslen, limit, skip,
- 0, 0, 0);
-}
-
-void
-hstcpcli::request_buf_insert(size_t pst_id, const string_ref *fvs,
- size_t fvslen)
-{
- const string_ref insert_op("+", 1);
- return request_buf_exec_generic(pst_id, insert_op, fvs, fvslen,
- 0, 0, string_ref(), 0, 0);
-}
-
-void
-hstcpcli::request_buf_update(size_t pst_id, const string_ref& op,
- const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip,
- const string_ref *mvs, size_t mvslen)
-{
- const string_ref modop_update("U", 1);
- return request_buf_exec_generic(pst_id, op, kvs, kvslen, limit, skip,
- modop_update, mvs, mvslen);
-}
-
-void
-hstcpcli::request_buf_delete(size_t pst_id, const string_ref& op,
- const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip)
-{
- const string_ref modop_delete("D", 1);
- return request_buf_exec_generic(pst_id, op, kvs, kvslen, limit, skip,
- modop_delete, 0, 0);
-}
-#endif
-
int
hstcpcli::request_send()
{
View
2 libhsclient/hstcpcli.hpp
@@ -37,7 +37,7 @@ struct hstcpcli_i {
virtual void close() = 0;
virtual int reconnect() = 0;
virtual bool stable_point() = 0;
- virtual void request_buf_auth(const char *secret) = 0;
+ virtual void request_buf_auth(const char *secret, const char *typ) = 0;
virtual void request_buf_open_index(size_t pst_id, const char *dbn,
const char *tbl, const char *idx, const char *retflds,
const char *filflds = 0) = 0;
View
28 perl-Net-HandlerSocket/HandlerSocket.xs
@@ -432,6 +432,34 @@ OUTPUT:
RETVAL
int
+auth(obj, key, typ = 0)
+ SV *obj
+ const char *key
+ const char *typ
+CODE:
+ RETVAL = 0;
+ dena::hstcpcli_i *const ptr =
+ reinterpret_cast<dena::hstcpcli_i *>(SvIV(SvRV(obj)));
+ do {
+ ptr->request_buf_auth(key, typ);
+ if (ptr->request_send() != 0) {
+ break;
+ }
+ size_t nflds = 0;
+ ptr->response_recv(nflds);
+ const int e = ptr->get_error_code();
+ DBG(fprintf(stderr, "errcode=%d\n", ptr->get_error_code()));
+ if (e >= 0) {
+ ptr->response_buf_remove();
+ }
+ DBG(fprintf(stderr, "errcode=%d\n", ptr->get_error_code()));
+ } while (0);
+ RETVAL = ptr->get_error_code();
+OUTPUT:
+ RETVAL
+
+
+int
open_index(obj, id, db, table, index, fields, ffields = 0)
SV *obj
int id
View
4 regtest/common/hstest.pm
@@ -21,6 +21,7 @@ sub init_conf {
$conf{user} = get_conf_env("MYSQLUSER", "root");
$conf{pass} = get_conf_env("MYSQLPASS", "");
$conf{hsport} = get_conf_env("HSPORT", 9998);
+ $conf{hspass} = get_conf_env("HSPASS", undef);
}
sub get_dbi_connection {
@@ -52,6 +53,9 @@ sub get_hs_connection {
$port ||= $conf{hsport};
my $hsargs = { 'host' => $host, 'port' => $port };
my $conn = new Net::HandlerSocket($hsargs);
+ if (defined($conn) && defined($conf{hspass})) {
+ $conn->auth($conf{hspass});
+ }
return $conn;
}

0 comments on commit 1c6b760

Please sign in to comment.
Something went wrong with that request. Please try again.