You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jo...@apache.org on 2023/03/05 23:48:18 UTC
[age] branch GDBMS_gp updated: Gdbms gp (#700)
This is an automated email from the ASF dual-hosted git repository.
joshinnis pushed a commit to branch GDBMS_gp
in repository https://gitbox.apache.org/repos/asf/age.git
The following commit(s) were added to refs/heads/GDBMS_gp by this push:
new 1b169c8b Gdbms gp (#700)
1b169c8b is described below
commit 1b169c8bef7f40497a72237dfd2977b83368c679
Author: Umar Hayat <um...@bitnine.net>
AuthorDate: Mon Mar 6 08:48:13 2023 +0900
Gdbms gp (#700)
* AGE code clean up
* GDBMS_GP (Graph Protocol) initial commit
---
.gitignore | 1 +
Makefile | 11 -
Makefile.am | 72 +++++
agensgraph--0.0.0.sql | 7 -
agensgraph.c | 20 --
agensgraph.control | 4 -
configure.ac | 40 +++
expected/cypher.out | 8 -
sql/cypher.sql | 6 -
src/communication/ag/receiver.c | 26 ++
src/communication/ag/sender.c | 118 ++++++++
src/communication/agbolt_ws_hook.c | 228 +++++++++++++++
src/communication/bolt/receiver.c | 29 ++
src/communication/bolt/sender.c | 36 +++
src/communication/socket_manager.c | 130 +++++++++
src/include/communication/ag/receiver.h | 35 +++
src/include/communication/ag/sender.h | 31 +++
src/include/communication/agbolt_ws_hook.h | 55 ++++
src/include/communication/bolt/receiver.h | 29 ++
src/include/communication/bolt/sender.h | 31 +++
src/include/communication/socket_manager.h | 72 +++++
src/include/graph_protocol_stddef.h | 91 ++++++
src/include/interface/bolt_adapter.h | 28 ++
src/include/interface/pgwired_facade.h | 43 +++
src/include/interface/translator.h | 30 ++
src/include/libwebsocket/callback/lws_callback.h | 58 ++++
src/include/libwebsocket/lws.h | 84 ++++++
src/include/spec/bolt/handshake/handshake.h | 28 ++
.../spec/bolt/handshake/v430/handshake_v430.h | 39 +++
src/include/spec/bolt/message/message_utils.h | 49 ++++
src/include/spec/bolt/message/v440/chunk.h | 35 +++
src/include/spec/bolt/message/v440/message.h | 68 +++++
src/include/spec/bolt/message/v440/signature.h | 49 ++++
src/include/spec/bolt/message/v440/tag.h | 45 +++
src/include/spec/bolt/message/v500/message.h | 28 ++
src/include/spec/packstream/pack_utils.h | 60 ++++
src/include/spec/packstream/v100/coretypes.h | 20 ++
src/include/spec/packstream/v100/marker.h | 69 +++++
src/include/spec/packstream/v100/packstream_v100.h | 24 ++
.../spec/server_state/v440/server_state_v440.h | 39 +++
src/include/stubs/stubs.h | 46 ++++
src/include/utils/config_helper.h | 28 ++
src/include/utils/logging.h | 10 +
src/include/utils/option_helper.h | 15 +
src/include/utils/process.h | 10 +
src/include/utils/utils.h | 17 ++
src/lib/libwebsocket/callback/callback_closed.c | 41 +++
.../libwebsocket/callback/callback_established.c | 44 +++
src/lib/libwebsocket/callback/callback_init.c | 56 ++++
src/lib/libwebsocket/callback/callback_receive.c | 39 +++
src/lib/libwebsocket/callback/callback_writable.c | 31 +++
src/lib/libwebsocket/lws_extensions.c | 23 ++
src/lib/libwebsocket/lws_lejp_parser.c | 179 ++++++++++++
src/lib/libwebsocket/lws_main.c | 116 ++++++++
src/lib/libwebsocket/lws_protocol.c | 219 +++++++++++++++
src/lib/libwebsocket/lws_utils.c | 59 ++++
src/lib/libwebsocket/lws_vhost.c | 25 ++
src/main.c | 68 +++++
src/resources/graph_protocol.conf | 6 +
src/spec/bolt/bolt_utils.c | 112 ++++++++
src/spec/bolt/handshake/handshake_utils.c | 23 ++
src/spec/bolt/handshake/v430/common/handshake.c | 45 +++
src/spec/bolt/handshake/v430/handshake_430.c | 205 ++++++++++++++
src/spec/bolt/message/v440/detailed/record.c | 62 +++++
src/spec/bolt/message/v440/message_utils.c | 306 +++++++++++++++++++++
src/spec/bolt/message/v440/summary/failed.c | 43 +++
src/spec/bolt/message/v440/summary/ignored.c | 43 +++
src/spec/bolt/message/v440/summary/success.c | 255 +++++++++++++++++
src/spec/bolt/server_state/v440/server_state.c | 24 ++
src/spec/bolt/structures/bolt_node.c | 46 ++++
src/spec/packstream/pack_utils.c | 239 ++++++++++++++++
src/spec/packstream/v100/coretypes/pack_boolean.c | 40 +++
src/spec/packstream/v100/coretypes/pack_dict.c | 45 +++
src/spec/packstream/v100/coretypes/pack_integer.c | 88 ++++++
src/spec/packstream/v100/coretypes/pack_list.c | 63 +++++
src/spec/packstream/v100/coretypes/pack_string.c | 92 +++++++
.../packstream/v100/coretypes/pack_structure.c | 42 +++
src/stubs/stubs.c | 134 +++++++++
src/types/dict.c | 23 ++
src/types/list.c | 23 ++
src/utils/config_helper.c | 109 ++++++++
src/utils/logging.c | 4 +
src/utils/option_helper.c | 18 ++
src/utils/process.c | 47 ++++
src/utils/utils.c | 49 ++++
85 files changed, 5032 insertions(+), 56 deletions(-)
diff --git a/.gitignore b/.gitignore
index cd3e0e15..0624bdb9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/results/
*.o
*.so
+*.dirstamp
\ No newline at end of file
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 9942b87d..00000000
--- a/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-MODULES = agensgraph
-
-EXTENSION = agensgraph
-
-DATA = agensgraph--0.0.0.sql
-
-REGRESS = cypher
-
-PG_CONFIG = pg_config
-PGXS := $(shell $(PG_CONFIG) --pgxs)
-include $(PGXS)
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 00000000..fb9b9517
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,72 @@
+bin_PROGRAMS = graph_protocol
+
+AM_CPPFLAGS = \
+-I@PGSQL_LIB_DIR@ \
+-I@PGSQL_INCLUDE_DIR@ \
+-I@PGSQL_INCLUDE_SERVER_DIR@ \
+-I/usr/local/lib \
+-I/usr/local/include/libwebsockets \
+-Isrc/include
+
+graph_protocol_LDADD = \
+-L@PGSQL_LIB_DIR@ \
+-L@PGSQL_INCLUDE_DIR@ \
+-L@PGSQL_INCLUDE_SERVER_DIR@ \
+-L/usr/local/lib -lwebsockets \
+-L/usr/local/include/libwebsockets \
+-Lsrc/include \
+-lpq -lpthread
+
+graph_protocol_SOURCES = \
+src/main.c \
+\
+src/utils/utils.c \
+src/utils/config_helper.c \
+src/utils/logging.c \
+src/utils/process.c \
+src/utils/option_helper.c \
+\
+src/spec/bolt/server_state/v440/server_state.c \
+\
+src/spec/bolt/handshake/v430/handshake_430.c \
+src/spec/bolt/handshake/v430/common/handshake.c \
+src/spec/bolt/handshake/handshake_utils.c \
+\
+src/communication/ag/receiver.c \
+src/communication/ag/sender.c \
+src/communication/bolt/receiver.c \
+src/communication/bolt/sender.c \
+src/communication/agbolt_ws_hook.c \
+src/communication/socket_manager.c \
+\
+src/spec/packstream/v100/coretypes/pack_string.c \
+src/spec/packstream/v100/coretypes/pack_list.c \
+src/spec/packstream/v100/coretypes/pack_dict.c \
+src/spec/packstream/v100/coretypes/pack_boolean.c \
+src/spec/packstream/v100/coretypes/pack_integer.c \
+src/spec/packstream/v100/coretypes/pack_structure.c \
+src/spec/packstream/pack_utils.c \
+\
+src/spec/bolt/structures/bolt_node.c \
+src/spec/bolt/message/v440/message_utils.c \
+src/spec/bolt/bolt_utils.c \
+src/stubs/stubs.c \
+\
+src/lib/libwebsocket/lws_extensions.c \
+src/lib/libwebsocket/lws_main.c \
+src/lib/libwebsocket/lws_protocol.c \
+src/lib/libwebsocket/lws_utils.c \
+src/lib/libwebsocket/lws_vhost.c \
+src/lib/libwebsocket/lws_lejp_parser.c \
+\
+src/lib/libwebsocket/callback/callback_closed.c \
+src/lib/libwebsocket/callback/callback_established.c \
+src/lib/libwebsocket/callback/callback_init.c \
+src/lib/libwebsocket/callback/callback_receive.c \
+src/lib/libwebsocket/callback/callback_writable.c\
+\
+src/spec/bolt/message/v440/summary/failed.c \
+src/spec/bolt/message/v440/summary/ignored.c \
+src/spec/bolt/message/v440/detailed/record.c \
+src/spec/bolt/message/v440/summary/success.c
+
diff --git a/agensgraph--0.0.0.sql b/agensgraph--0.0.0.sql
deleted file mode 100644
index 4ccec0e3..00000000
--- a/agensgraph--0.0.0.sql
+++ /dev/null
@@ -1,7 +0,0 @@
--- complain if script is sourced in psql, rather than via CREATE EXTENSION
-\echo Use "CREATE EXTENSION agensgraph" to load this file. \quit
-
-CREATE FUNCTION "cypher"(text)
-RETURNS SETOF "record"
-LANGUAGE "c"
-AS 'MODULE_PATHNAME';
diff --git a/agensgraph.c b/agensgraph.c
deleted file mode 100644
index 7fde4a7c..00000000
--- a/agensgraph.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "postgres.h"
-
-#include "fmgr.h"
-#include "utils/builtins.h"
-
-PG_MODULE_MAGIC;
-
-PG_FUNCTION_INFO_V1(cypher);
-
-Datum cypher(PG_FUNCTION_ARGS)
-{
- const char *s;
-
- s = PG_ARGISNULL(0) ? "NULL" : text_to_cstring(PG_GETARG_TEXT_PP(0));
-
- ereport(ERROR, (errmsg_internal("unhandled cypher(text) function call"),
- errdetail_internal("%s", s)));
-
- PG_RETURN_NULL();
-}
diff --git a/agensgraph.control b/agensgraph.control
deleted file mode 100644
index 6111b55d..00000000
--- a/agensgraph.control
+++ /dev/null
@@ -1,4 +0,0 @@
-default_version = '0.0.0'
-module_pathname = '$libdir/agensgraph'
-
-schema = 'ag_catalog'
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 00000000..10561025
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,40 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.71])
+AC_INIT([agbolt],[0.1])
+AC_CONFIG_SRCDIR([config.h.in])
+AC_CONFIG_HEADERS([config.h])
+
+AM_INIT_AUTOMAKE([foreign no-dependencies subdir-objects])
+
+# Checks for programs.
+AC_PROG_CC
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_TYPE_PID_T
+
+# Checks for library functions.
+AC_FUNC_FORK
+
+# postgres dependancy check
+AC_CHECK_PROGS(PGCONFIG, pg_config)
+PGSQL_INCLUDE_DIR=`pg_config --includedir`
+PGSQL_LIB_DIR=`pg_config --libdir`
+PGSQL_BIN_DIR=`pg_config --bindir`
+PGSQL_INCLUDE_SERVER_DIR=`pg_config --includedir-server`
+
+AC_SUBST(PGSQL_INCLUDE_DIR)
+AC_SUBST(PGSQL_LIB_DIR)
+AC_SUBST(PGSQL_BIN_DIR)
+AC_SUBST(PGSQL_INCLUDE_SERVER_DIR)
+
+AM_CONDITIONAL([enable_rpath], test x$rpath = xyes)
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
\ No newline at end of file
diff --git a/expected/cypher.out b/expected/cypher.out
deleted file mode 100644
index fce3ab5a..00000000
--- a/expected/cypher.out
+++ /dev/null
@@ -1,8 +0,0 @@
-CREATE EXTENSION agensgraph;
-SET search_path TO ag_catalog;
-SELECT * FROM cypher(NULL) AS r(c text);
-ERROR: unhandled cypher(text) function call
-DETAIL: NULL
-SELECT * FROM cypher($$RETURN 0$$) AS r(c text);
-ERROR: unhandled cypher(text) function call
-DETAIL: RETURN 0
diff --git a/sql/cypher.sql b/sql/cypher.sql
deleted file mode 100644
index 944e1f59..00000000
--- a/sql/cypher.sql
+++ /dev/null
@@ -1,6 +0,0 @@
-CREATE EXTENSION agensgraph;
-
-SET search_path TO ag_catalog;
-
-SELECT * FROM cypher(NULL) AS r(c text);
-SELECT * FROM cypher($$RETURN 0$$) AS r(c text);
diff --git a/src/communication/ag/receiver.c b/src/communication/ag/receiver.c
new file mode 100644
index 00000000..f5839cdd
--- /dev/null
+++ b/src/communication/ag/receiver.c
@@ -0,0 +1,26 @@
+/*
+ * receiver.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/communication/ag/receiver.c
+ */
+
+
+#include "communication/ag/receiver.h"
diff --git a/src/communication/ag/sender.c b/src/communication/ag/sender.c
new file mode 100644
index 00000000..525861e9
--- /dev/null
+++ b/src/communication/ag/sender.c
@@ -0,0 +1,118 @@
+/*
+ * sender.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/communication/ag/sender.c
+ */
+
+
+#include "interface/pgwired_facade.h"
+#include "graph_protocol_stddef.h"
+
+
+#include <libpq-fe.h>
+#include <assert.h>
+
+void pq_result_check(PGresult *result) {
+ ExecStatusType s;
+ s = PQresultStatus(result);
+ switch (s) {
+ case PGRES_TUPLES_OK:
+ fprintf(stdout, "%s", "\ntuples ok\n");
+ break;
+ case PGRES_SINGLE_TUPLE:
+ case PGRES_EMPTY_QUERY:
+ case PGRES_COMMAND_OK:
+ case PGRES_COPY_OUT:
+ case PGRES_COPY_IN:
+ case PGRES_BAD_RESPONSE:
+ case PGRES_NONFATAL_ERROR:
+ case PGRES_FATAL_ERROR:
+ case PGRES_COPY_BOTH:
+ case PGRES_PIPELINE_SYNC:
+ case PGRES_PIPELINE_ABORTED:
+ fprintf(stdout, "%s", PQresultErrorMessage(result));
+ fprintf(stdout, "%s", PQresStatus(s));
+ default:
+ break;
+ }
+}
+
+void pq_connection_check(PGconn *conn) {
+ ConnStatusType status_type = PQstatus(conn);
+ switch (status_type) {
+ case CONNECTION_OK:
+ break;
+ case CONNECTION_BAD:
+ perror("ConnStatusType is CONNECTION_BAD");
+ exit(1);
+ case CONNECTION_STARTED:
+ break;
+ case CONNECTION_MADE:
+ break;
+ case CONNECTION_AWAITING_RESPONSE:
+ break;
+ case CONNECTION_AUTH_OK:
+ break;
+ case CONNECTION_SETENV:
+ break;
+ case CONNECTION_SSL_STARTUP:
+ break;
+ case CONNECTION_NEEDED:
+ break;
+ case CONNECTION_CHECK_WRITABLE:
+ break;
+ case CONNECTION_CONSUME:
+ break;
+ case CONNECTION_GSS_STARTUP:
+ break;
+ case CONNECTION_CHECK_TARGET:
+ break;
+ case CONNECTION_CHECK_STANDBY:
+ break;
+ }
+}
+
+PGconn *connect_ag(const char *conn_str) {
+
+ printf("%s", conn_str);
+ if (conn_str == NULL) {
+ perror("conn_str is null");
+ }
+
+ PGconn *conn = PQconnectdb(conn_str);
+ assert(conn);
+ return conn;
+}
+
+PGresult *execute_cypher(PGconn *conn, char *cypher) {
+ PGresult *result = PQexec(conn, cypher);
+ assert(result);
+ return result;
+}
+
+PGresult *exec_cypher(PGconn *conn, char *cypher_str) {
+ PGresult *result;
+// conn = connect_ag(conn_str);
+ pq_connection_check(conn);
+ result = execute_cypher(conn, cypher_str);
+ pq_result_check(result);
+ return result;
+}
\ No newline at end of file
diff --git a/src/communication/agbolt_ws_hook.c b/src/communication/agbolt_ws_hook.c
new file mode 100644
index 00000000..47a209df
--- /dev/null
+++ b/src/communication/agbolt_ws_hook.c
@@ -0,0 +1,228 @@
+/*
+ * agbolt_ws_hook.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/communication/agbolt_ws_hook.c
+ */
+
+#include "graph_protocol_stddef.h"
+
+#include "communication/agbolt_ws_hook.h"
+
+#include "interface/pgwired_facade.h"
+#include "utils/utils.h"
+#include "utils/config_helper.h"
+
+#include "spec/bolt/handshake/v430/handshake_v430.h"
+#include "spec/bolt/message/v440/signature.h"
+#include "spec/bolt/message/v440/message.h"
+#include "spec/bolt/message/v440/chunk.h"
+#include "spec/bolt/message/v440/tag.h"
+
+#include "stubs/stubs.h"
+
+#include "libwebsocket/lws.h"
+
+
+extern struct garph_protocol_conf garph_protocol_conf;
+
+
+extern int in_transaction;
+
+uint8 server_ver[] = {0x00, 0x02, 0x04, 0x04};
+uint8 ident[] = {0x60, 0x60, 0xb0, 0x17};
+
+
+struct msg *mock_match_matrix_return_result(struct pg_conn *conn, const struct msg *m);
+
+struct msg *mallocating_msg_with_length(uint8 *raw, size_t len);
+
+struct msg *ws_cypher_parser(struct pg_conn *conn, const struct msg *m) {
+
+ BOLT_CHUNK cnk;
+ char *src;
+ char *cat;
+ size_t src_len = 0;
+ size_t cat_len = 0;
+
+ src_len = 0;
+ cat_len = 0;
+
+ size_t extracted;
+ char *extracted_cypher;
+ extracted = extract_ws_cypher_string(m->payload, &extracted_cypher);
+
+ char *cypher = concaternating_default_graphpath(garph_protocol_conf.graph_path, extracted_cypher);
+ assert(conn);
+
+ PGresult *pg_result = exec_cypher(conn, cypher);
+ assert(pg_result);
+
+ char *pgresult_bytearray;
+ int field_count = PQnfields(pg_result);
+ char **field_names = malloc(sizeof(char *) * field_count);
+
+ printf("field: %d", field_count);
+
+ for (int i = 0; i < field_count; ++i) {
+ char *fname = PQfname(pg_result, i);
+ field_names[i] = malloc(strlen(fname) + 1);//with null
+ field_names[i] = memcpy(field_names[i], fname, strlen(fname) + 1);
+ }
+
+ //commit-success
+ if (in_transaction == 1) {
+ cnk = bolt_commit_success();
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+ }
+
+ //run-success
+ cnk = bolt_run_success(field_names, field_count);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+
+ //record
+ src_len = extract_cnk_from_pgresult(pg_result, &pgresult_bytearray);
+ cat_len = concaternating_byte_array(&cat, cat_len, pgresult_bytearray, src_len);
+
+ //pull-success
+ cnk = bolt_pull_success(NULL, 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+
+ assert(cat);
+
+ return mallocating_msg_with_length(cat, cat_len);
+}
+
+struct msg *agbolt_ws_hook(struct pg_conn *conn, const struct msg *m) {
+ assert(conn); // conn assertion
+
+ struct msg *result_msg;
+
+ if (((char *) (m->payload))[3] == 0x10) // run
+ {
+ switch (m->len) {
+ case 74:// bolt-RUN:CALL dbms.components() YIELD name, versions, edition + bolt-PULL: n
+ result_msg = stub_lws_msg_maker(CALL_DBMS_COMPONENTS);
+ break;
+ case 35: // SHOW DATABASES.......=
+ result_msg = stub_lws_msg_maker(SHOW_DATABASES);
+ break;
+ case 49: // bolt-RUN: CALL dbms.showCurrentUser() + bolt-PULL: n
+ result_msg = stub_lws_msg_maker(SHOW_CURRENT_USER);
+ break;
+ case 536: // COLLECT(label)[..1000]} AS result.UNION ALL.CALL db.relationshi ....
+ case 44: // ......CALL dbms.procedures()
+ case 43: // .....CALL dbms.functions()
+ result_msg = stub_lws_msg_maker(SUCCESS);
+ break;
+ default:
+ result_msg = ws_cypher_parser(conn, m);
+ break;
+ }
+ return result_msg;
+ }
+
+ switch (m->len) {
+
+ case 77: // explain.. match(n) where n.title = 'The Matrix' return(n);
+ perror("unintended explain query.");
+ return stub_lws_msg_maker(SUCCESS);
+ case 70: //match(n) where n.title = 'The Matrix' return(n);
+
+ return stub_lws_msg_maker(SHOW_CURRENT_USER);
+ case 63: // begin
+ return stub_lws_msg_maker(SUCCESS);
+ case 65: // begin
+ return stub_lws_msg_maker(SUCCESS);
+
+ case 75: // begin
+ return stub_lws_msg_maker(SUCCESS);
+ case 35:
+ return stub_lws_msg_maker(SHOW_DATABASES);
+ case 20:
+ return ws_handshake();
+ case 6:
+ if (((char *) (m->payload))[3] == 0x12) {
+ return stub_lws_msg_maker(COMMIT);
+ }
+ return stub_lws_msg_maker(SUCCESS);
+ case 103:
+ case 104:
+ case 135:
+ case 136:
+ case 137:
+ return ws_hello();
+ case 32:
+ return ws_route();
+ case 74:// bolt-RUN:CALL dbms.components() YIELD name, versions, edition + bolt-PULL: n
+ return stub_lws_msg_maker(CALL_DBMS_COMPONENTS);
+ case 68:
+ return stub_lws_msg_maker(SUCCESS);
+ default:
+ perror("non of case detected");
+ return stub_lws_msg_maker(SUCCESS);
+ }
+}
+
+
+struct msg *ws_route() {
+ BOLT_CHUNK cnk;
+ char *src;
+ char *cat;
+ size_t src_len = 0;
+ size_t cat_len = 0;
+ cnk = bolt_route_success("", 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+ return mallocating_msg_with_length(cat, cat_len);
+}
+
+struct msg *ws_hello() {
+ BOLT_CHUNK cnk;
+ char *src;
+ char *cat;
+ size_t src_len = 0;
+ size_t cat_len = 0;
+ cnk = bolt_hello_success("", 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+
+ return mallocating_msg_with_length(cat, cat_len);
+}
+
+struct msg *ws_handshake() {
+ struct msg *server_version = malloc(sizeof(struct msg));
+ server_version->payload = (uint8 *) server_ver;
+ server_version->final = 1;
+ server_version->first = 1;
+ server_version->len = 4;
+ server_version->binary = LWS_WRITE_BINARY;
+
+ return server_version;
+}
+
diff --git a/src/communication/bolt/receiver.c b/src/communication/bolt/receiver.c
new file mode 100644
index 00000000..f4cdde98
--- /dev/null
+++ b/src/communication/bolt/receiver.c
@@ -0,0 +1,29 @@
+/*
+ * receiver.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/communication/bolt/receiver.c
+ */
+#include "communication/bolt/receiver.h"
+
+
+
+
+
diff --git a/src/communication/bolt/sender.c b/src/communication/bolt/sender.c
new file mode 100644
index 00000000..7e3b6435
--- /dev/null
+++ b/src/communication/bolt/sender.c
@@ -0,0 +1,36 @@
+/*
+ * sender.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/communication/bolt/sender.c
+ */
+
+#include "communication/bolt/sender.h"
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/communication/socket_manager.c b/src/communication/socket_manager.c
new file mode 100644
index 00000000..9c5f213d
--- /dev/null
+++ b/src/communication/socket_manager.c
@@ -0,0 +1,130 @@
+/*
+ * conn_manager.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/communication/conn_manager.c
+ */
+
+#include "communication/socket_manager.h"
+#include "utils/process.h"
+
+
+client_info cinfo[MAX_CLIENT_CONNECTION];
+size_t client_info_index = 0;
+
+
+
+void accept_sock(int *new_socket, const int *listen_fd,
+ struct sockaddr_in *address, int addrlen) {
+ *new_socket = accept(*listen_fd, (struct sockaddr *) address,
+ (socklen_t *) &addrlen);
+
+ if (*new_socket < 0) {
+ perror("accept failed : ");
+ exit(EXIT_FAILURE);
+ }
+}
+
+ssize_t recv_data(const int *conn, char dest[]) {
+ ssize_t len = 0;
+ char buf[TCP_BUF_SIZE];
+ len = recv(*conn, buf, TCP_BUF_SIZE, 0);
+ memcpy(dest, buf, len);
+ return len;
+}
+
+ssize_t send_data(const int *conn, const char src[], size_t src_len) {
+ return send(*conn, src, src_len, 0);
+}
+
+size_t listening_connection(int *server_sock, int *client_sock, int port) {
+
+ pid_t pid;
+ struct sigaction act;
+// int state;
+// act.sa_handler = read_childproc;
+// sigemptyset(&act.sa_mask);
+// act.sa_flags = 0;
+// state = sigaction(SIGCHLD, &act, 0);
+
+ char msg[TCP_BUF_SIZE];
+ struct sockaddr_in server_address;
+ struct sockaddr_in client_address;
+ socklen_t client_address_size;
+ client_address_size = sizeof(client_address);
+ int optval = 1;
+
+
+ *server_sock = socket(PF_INET, SOCK_STREAM, 0);
+ if (*server_sock == -1) {
+ perror("socket failed \n");
+ exit(EXIT_FAILURE);
+ }
+ memset(&server_address, 0, sizeof(server_address));
+ server_address.sin_family = AF_INET;
+ server_address.sin_addr.s_addr = htonl(INADDR_ANY);
+ server_address.sin_port = htons(port);
+
+ setsockopt(*server_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
+
+ if (bind(*server_sock, (struct sockaddr *) &server_address, sizeof(server_address)) == -1) {
+ perror("bind failed : \n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (listen(*server_sock, 5) == -1) {
+ perror("listen failed\n");
+ exit(EXIT_FAILURE);
+ }
+
+ *client_sock = accept(*server_sock, (struct sockaddr *) &client_address, &client_address_size);
+ if (*client_sock == -1) {
+ perror("accept failed\n");
+ }
+
+ cinfo[client_info_index].c_address = client_address;
+ cinfo[client_info_index].c_sock = client_sock;
+ cinfo[client_info_index].c_conn_id = client_info_index;
+
+ return client_info_index;
+}
+
+
+CLIENT_REQUESTED_PROTOCOL checking_connection_procotol(client_info client_info) {
+
+ size_t recv_len;
+ char buf[TCP_BUF_SIZE];
+ const char http_get[] = {0x47, 0x45, 0x54}; // 0x47=G, 0x45=E, 0x54=T
+ const char bolt_id[] = {0x60, 0x60, 0xB0, 0x17};
+
+ recv_len = recv(*client_info.c_sock, buf, TCP_BUF_SIZE, 0);
+ memcpy(client_info.c_handshake_request, buf, recv_len);
+
+ if (strncmp(client_info.c_handshake_request, http_get, 3) == 0) {
+ client_info.c_protocol = WEBSOCKET;
+ } else if (strncmp(client_info.c_handshake_request, bolt_id, 4) == 0) {
+ client_info.c_protocol = IPC_BOLT;
+ } else {
+ perror("no supported protocol detected");
+ }
+
+ return client_info.c_protocol;
+}
+
diff --git a/src/include/communication/ag/receiver.h b/src/include/communication/ag/receiver.h
new file mode 100644
index 00000000..e93e58d8
--- /dev/null
+++ b/src/include/communication/ag/receiver.h
@@ -0,0 +1,35 @@
+/*
+ * receiver.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/communication/ag/receiver.h
+ */
+#ifndef AG_RECEIVER_H
+#define AG_RECEIVER_H
+
+
+#include "interface/pgwired_facade.h"
+#include "graph_protocol_stddef.h"
+#include "communication/socket_manager.h"
+#include "utils/utils.h"
+#include "utils/logging.h"
+#include "communication/bolt/receiver.h"
+
+#endif
diff --git a/src/include/communication/ag/sender.h b/src/include/communication/ag/sender.h
new file mode 100644
index 00000000..c76e5485
--- /dev/null
+++ b/src/include/communication/ag/sender.h
@@ -0,0 +1,31 @@
+/*
+ * sender.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/communication/ag/sender.h
+ */
+#ifndef AG_SENDER_H
+#define AG_SENDER_H
+
+#include "interface/pgwired_facade.h"
+#include "graph_protocol_stddef.h"
+
+
+#endif
diff --git a/src/include/communication/agbolt_ws_hook.h b/src/include/communication/agbolt_ws_hook.h
new file mode 100644
index 00000000..84489283
--- /dev/null
+++ b/src/include/communication/agbolt_ws_hook.h
@@ -0,0 +1,55 @@
+/*
+ * agbolt_ws_hook.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/communication/agbolt_ws_hook.h
+ */
+#ifndef AGBOLT_WS_HOOK_H
+#define AGBOLT_WS_HOOK_H
+
+#if !defined (LWS_PLUGIN_STATIC)
+#define LWS_DLL
+#define LWS_INTERNAL
+
+#include <libwebsockets.h>
+//#include <libwebsockets/lws-ws-ext.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <libpq-fe.h>
+
+#endif
+
+typedef enum {
+ BOLT_IDENT
+} bolt_msg;
+
+struct msg *ws_handshake();
+
+struct msg *ws_hello();
+
+
+struct msg *agbolt_ws_hook(struct pg_conn *conn, const struct msg *m);
+
+struct msg *ws_route();
+
+
+
+#endif
diff --git a/src/include/communication/bolt/receiver.h b/src/include/communication/bolt/receiver.h
new file mode 100644
index 00000000..efea1306
--- /dev/null
+++ b/src/include/communication/bolt/receiver.h
@@ -0,0 +1,29 @@
+/*
+ * receiver.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/communication/bolt/receiver.h
+ */
+#ifndef BOLT_RECEIVER_H
+#define BOLT_RECEIVER_H
+
+#include "interface/bolt_adapter.h"
+
+#endif
diff --git a/src/include/communication/bolt/sender.h b/src/include/communication/bolt/sender.h
new file mode 100644
index 00000000..eb202bfa
--- /dev/null
+++ b/src/include/communication/bolt/sender.h
@@ -0,0 +1,31 @@
+/*
+ * sender.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/communication/bolt/sender.h
+ */
+#ifndef BOLT_SENDER_H
+#define BOLT_SENDER_H
+
+
+#include "interface/bolt_adapter.h"
+
+
+#endif
diff --git a/src/include/communication/socket_manager.h b/src/include/communication/socket_manager.h
new file mode 100644
index 00000000..a843905c
--- /dev/null
+++ b/src/include/communication/socket_manager.h
@@ -0,0 +1,72 @@
+/*
+ * conn_manager.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/communication/conn_manager.h
+ */
+
+#ifndef CONN_MANAGER_H
+#define CONN_MANAGER_H
+
+#define TCP_BUF_SIZE 2048
+#define CLIENT_CONNECTION_MAX 20
+
+#include "interface/translator.h"
+
+#include "communication/bolt/receiver.h"
+#include "communication/bolt/sender.h"
+#include "communication/ag/receiver.h"
+#include "communication/ag/sender.h"
+
+
+#define MAX_CLIENT_CONNECTION 50
+
+typedef enum {
+ WEBSOCKET,
+ IPC_BOLT
+} CLIENT_REQUESTED_PROTOCOL;
+
+typedef struct {
+ uint64_t c_conn_id;
+ struct sockaddr_in c_address;
+ int *c_sock;
+ CLIENT_REQUESTED_PROTOCOL c_protocol;
+ char c_handshake_request[TCP_BUF_SIZE];
+} client_info;
+
+extern client_info cinfo[MAX_CLIENT_CONNECTION];
+
+extern size_t client_info_index;
+
+
+
+
+void accept_sock(int *new_socket, const int *listen_fd, struct sockaddr_in *address,
+ int addrlen);
+
+ssize_t recv_data(const int *conn, char dest[]);
+
+ssize_t send_data(const int *conn, const char src[], size_t src_len);
+
+size_t listening_connection(int *server_sock, int *client_sock, int port);
+
+CLIENT_REQUESTED_PROTOCOL checking_connection_procotol(client_info cinfo);
+
+#endif
diff --git a/src/include/graph_protocol_stddef.h b/src/include/graph_protocol_stddef.h
new file mode 100644
index 00000000..cbbdf953
--- /dev/null
+++ b/src/include/graph_protocol_stddef.h
@@ -0,0 +1,91 @@
+/*
+ * adapter_stddef.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/adapter_stddef.h
+ */
+#ifndef ADAPTER_STDDEF_H
+#define ADAPTER_STDDEF_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <netinet/in.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#ifndef NIBBLE_HIGH
+#define NIBBLE_HIGH (0b11110000)
+#endif
+
+#ifndef NIBBLE_LOW
+#define NIBBLE_LOW (0b00001111)
+#endif
+
+#ifndef HAVE_INT8
+#define HAVE_INT8
+typedef signed char int8;
+#endif
+
+#ifndef HAVE_INT16
+#define HAVE_INT16
+typedef signed short int16;
+#endif
+
+#ifndef HAVE_INT32
+#define HAVE_INT32
+typedef signed int int32;
+#endif
+
+#ifndef HAVE_INT64
+#define HAVE_INT64
+typedef long int int64;
+#endif
+
+#ifndef HAVE_UINT8
+#define HAVE_UINT8
+typedef unsigned char uint8;
+#endif
+
+#ifndef HAVE_UINT16
+#define HAVE_UINT16
+typedef unsigned short uint16;
+#endif
+
+#ifndef HAVE_UINT32
+#define HAVE_UINT32
+typedef unsigned int uint32;
+#endif
+
+#ifndef HAVE_UINT64
+#define HAVE_UINT64
+typedef unsigned long int uint64;
+#endif
+
+#endif
diff --git a/src/include/interface/bolt_adapter.h b/src/include/interface/bolt_adapter.h
new file mode 100644
index 00000000..8f21056c
--- /dev/null
+++ b/src/include/interface/bolt_adapter.h
@@ -0,0 +1,28 @@
+/*
+ * agbolt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/interface/agbolt.h
+ */
+#ifndef AGBOLT_H
+#define AGBOLT_H
+
+
+#endif
diff --git a/src/include/interface/pgwired_facade.h b/src/include/interface/pgwired_facade.h
new file mode 100644
index 00000000..593f12e0
--- /dev/null
+++ b/src/include/interface/pgwired_facade.h
@@ -0,0 +1,43 @@
+/*
+ * agwired.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/interface/agwired.h
+ */
+#ifndef AGWIRED_H
+#define AGWIRED_H
+
+#define GRAPHIDARRAYOID 7001
+#define GRAPHIDOID 7002
+#define VERTEXARRAYOID 7011
+#define VERTEXOID 7012
+#define EDGEARRAYOID 7021
+#define EDGEOID 7022
+#define GRAPHPATHARRAYOID 7031
+#define GRAPHPATHOID 7032
+#define ROWIDARRAYOID 7061
+#define ROWIDOID 7062
+
+#include <libpq-fe.h>
+
+PGconn *connect_ag(const char *conn_str);
+PGresult *exec_cypher(PGconn *conn, char *cypher_str);
+
+#endif
diff --git a/src/include/interface/translator.h b/src/include/interface/translator.h
new file mode 100644
index 00000000..1c553810
--- /dev/null
+++ b/src/include/interface/translator.h
@@ -0,0 +1,30 @@
+/*
+ * translator.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/interface/translator.h
+ */
+#ifndef TRANSLATOR_H
+#define TRANSLATOR_H
+
+#include "interface/bolt_adapter.h"
+#include "interface/pgwired_facade.h"
+
+#endif
diff --git a/src/include/libwebsocket/callback/lws_callback.h b/src/include/libwebsocket/callback/lws_callback.h
new file mode 100644
index 00000000..9e1076a8
--- /dev/null
+++ b/src/include/libwebsocket/callback/lws_callback.h
@@ -0,0 +1,58 @@
+/*
+ * lws_callback.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/libwebsocket/callback/lws_callback.h
+ */
+#ifndef LWS_CALLBACK_H
+#define LWS_CALLBACK_H
+
+
+enum CALLBACK_STATUS {
+ CALLBACK_SUCCESS,
+ CALLBACK_INIT_VHD_IS_FALSE,
+ CALLBACK_ESTABLISHED_RING_IS_FALSE,
+ CALLBACK_BREAK
+};
+
+
+//init
+uint8 lws_callback_init(struct lws *wsi, struct per_vhost_storage *vhd, void *in);
+
+struct pg_conn *get_postgres_connection(char *conn_string);
+
+//establish
+uint8 lws_callback_established(struct per_session_data *pss);
+
+//writable
+
+//receive
+uint8 lws_callback_receive(
+ struct lws *wsi, struct per_session_data *pss, size_t len, uint32 *n,
+ const struct msg *pmsg, struct msg *amsg, void *in);
+
+
+//closed
+uint8 lws_callback_closed(struct per_session_data *pss, struct per_vhost_storage *vhd, struct lws *wsi);
+
+
+#endif
+
+
diff --git a/src/include/libwebsocket/lws.h b/src/include/libwebsocket/lws.h
new file mode 100644
index 00000000..30b94cdb
--- /dev/null
+++ b/src/include/libwebsocket/lws.h
@@ -0,0 +1,84 @@
+/*
+ * lws.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/libwebsocket/lws.h
+ */
+#ifndef LWS_H
+#define LWS_H
+
+
+#include <libwebsockets.h>
+#include "graph_protocol_stddef.h"
+
+#define RING_DEPTH 4096
+
+
+/* one of these created for each message */
+struct msg {
+ void *payload; /* is malloc'd */
+ size_t len;
+ char binary;
+ char first;
+ char final;
+};
+
+struct per_session_data {
+ struct lws_ring *ring;
+ uint32_t msglen;
+ uint32_t tail;
+ uint8_t completed: 1;
+ uint8_t flow_controlled: 1;
+ uint8_t write_consume_pending: 1;
+ struct pg_conn *conn;
+};
+
+struct per_vhost_storage {
+ struct lws_context *context;
+ struct lws_vhost *vhost;
+ int *interrupted;
+ int *options;
+};
+
+
+int callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason,
+ void *user, void *in, size_t len);
+
+int ws_server(int32 port);
+
+
+//lws_utils
+void minimal_destroy_message(void *_msg);
+
+void sigint_handler(int sig);
+
+
+//lws_lejp_parser
+
+struct lejp_json {
+ char *key;
+ void *value;
+ struct lejp_json *next;
+};
+
+int lws_lejp_parser(char json_str[]);
+
+
+#endif
diff --git a/src/include/spec/bolt/handshake/handshake.h b/src/include/spec/bolt/handshake/handshake.h
new file mode 100644
index 00000000..631fdb79
--- /dev/null
+++ b/src/include/spec/bolt/handshake/handshake.h
@@ -0,0 +1,28 @@
+/*
+ * handshake.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/handshake/common/handshake.h
+ */
+#ifndef BOLT_HANDSHAKE_H
+#define BOLT_HANDSHAKE_H
+
+
+#endif
diff --git a/src/include/spec/bolt/handshake/v430/handshake_v430.h b/src/include/spec/bolt/handshake/v430/handshake_v430.h
new file mode 100644
index 00000000..f065a94a
--- /dev/null
+++ b/src/include/spec/bolt/handshake/v430/handshake_v430.h
@@ -0,0 +1,39 @@
+
+
+
+#ifndef SPEC_BOLT_HANDSHAKE_H
+#define SPEC_BOLT_HANDSHAKE_H
+
+
+#define SERVER_VERSION_MAJOR (0x04)
+#define SERVER_VERSION_MINOR (0x04)
+#define SERVER_VERSION_HOTFIX (0x02)
+
+void simple_handshake(int listen_fd, int new_socket,
+ struct sockaddr_in address);
+
+
+#define BOLT_CONN_IDENT_SIZE (4)
+#define BOLT_NEGO_VERSION_SIZE (4)
+#define BOLT_NEGO_VERSION_CANDIDATE_LIST_SIZE (4)
+
+extern const char BOLT_CONN_IDENT_BYTEARRAY[BOLT_CONN_IDENT_SIZE];
+
+typedef struct {
+ char version_candidates[4][4];
+ struct sockaddr_in *client_address;
+} client_version_info;
+
+
+typedef struct {
+ char bolt_ident[4];
+ char avail_versions[4][4];
+} bolt_client_identification;
+
+typedef struct {
+ char avail_version[4];
+} bolt_server_identification;
+
+#endif
+
+
diff --git a/src/include/spec/bolt/message/message_utils.h b/src/include/spec/bolt/message/message_utils.h
new file mode 100644
index 00000000..eb5378f1
--- /dev/null
+++ b/src/include/spec/bolt/message/message_utils.h
@@ -0,0 +1,49 @@
+/*
+ * message_utils.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/bolt/message/message_utils.h
+ */
+#ifndef BOLT_MESSAGE_UTILS_H
+#define BOLT_MESSAGE_UTILS_H
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/message/v440/signature.h"
+
+
+struct node_info {
+ char *label;
+ int32 nid;
+ char *properties;
+};
+
+
+char *bolt_signature_to_string(BOLT_SIGNATURE bs);
+
+bool is_bolt_tag(uint8 c);
+
+bool is_bolt_signature(uint8 c);
+
+bool byte_to_bolt_signature(uint8 c);
+
+struct node_info node_string_to_structure(char libpq_node_str_arr[]);
+
+#endif
diff --git a/src/include/spec/bolt/message/v440/chunk.h b/src/include/spec/bolt/message/v440/chunk.h
new file mode 100644
index 00000000..9e4df9b2
--- /dev/null
+++ b/src/include/spec/bolt/message/v440/chunk.h
@@ -0,0 +1,35 @@
+/*
+ * chunk.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/bolt/message/v440/chunk.h
+ */
+#ifndef BOLT_CHUNK_H
+#define BOLT_CHUNK_H
+
+#include "graph_protocol_stddef.h"
+
+typedef struct {
+ unsigned short header;
+ unsigned short ender;
+ char *body;
+} BOLT_CHUNK;
+
+#endif
diff --git a/src/include/spec/bolt/message/v440/message.h b/src/include/spec/bolt/message/v440/message.h
new file mode 100644
index 00000000..8f8b6bc4
--- /dev/null
+++ b/src/include/spec/bolt/message/v440/message.h
@@ -0,0 +1,68 @@
+/*
+ * message_4_4_0.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/message/message_4_4_0.h
+ */
+#ifndef SPEC_BOLT_MESSAGE_440_H
+#define SPEC_BOLT_MESSAGE_440_H
+
+#include <libpq-fe.h>
+#include "graph_protocol_stddef.h"
+#include "chunk.h"
+
+
+#define BOLT_CHUNK_HEADER_SIZE 2
+#define BOLT_CHUNK_ENDHEADER_SIZE 2
+
+
+size_t extract_cnk_from_pgresult(const PGresult *r, char **dest_bytearray);
+
+char *bolt_chunk_to_byte_array(BOLT_CHUNK *cnk);
+
+size_t extract_ws_cypher_string(char buf[], char **dest);
+
+size_t extract_cypher_string(char buf[], char **dest);
+
+
+
+//failed
+
+//ignored
+
+//record
+BOLT_CHUNK bolt_run_dbping_record(char recv[], int len);
+
+//success
+BOLT_CHUNK bolt_run_success(char **field_str, int field_count);
+
+BOLT_CHUNK bolt_pull_success(char recv[], int len);
+
+BOLT_CHUNK bolt_commit_success();
+
+BOLT_CHUNK bolt_route_success(char recv[], int len);
+
+BOLT_CHUNK bolt_hello_success(char recv[], int len);
+
+BOLT_CHUNK bolt_run_dbping_success(char recv[], int len);
+
+BOLT_CHUNK bolt_run_dbping_bookmark_success(char recv[], int len);
+
+#endif
diff --git a/src/include/spec/bolt/message/v440/signature.h b/src/include/spec/bolt/message/v440/signature.h
new file mode 100644
index 00000000..f4ac2a08
--- /dev/null
+++ b/src/include/spec/bolt/message/v440/signature.h
@@ -0,0 +1,49 @@
+/*
+ * signature.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/bolt/message/v440/signature.h
+ */
+#ifndef BOLT_SIGNATURE_H
+#define BOLT_SIGNATURE_H
+
+#define BOLT_SIGNATURE_SIZE 1
+
+typedef enum {
+ BS_HELLO = 0x01,
+ BS_GOODBYE = 0x02,
+ BS_RESET = 0x0F,
+ BS_RUN = 0x10,
+ BS_DISCARD = 0x2F,
+ BS_PULL = 0x3F,
+ BS_BEGIN = 0x11,
+ BS_COMMIT = 0x12,
+ BS_ROLLBACK = 0x13,
+ BS_SUCCESS = 0x70,
+ BS_ROUTE = 0x66,
+ BS_IGNORED = 0x7E,
+ BS_FAILURE = 0x7F,
+ BS_RECORD = 0x71
+} BOLT_SIGNATURE;
+
+char *write_bolt_signature(BOLT_SIGNATURE bs);
+
+
+#endif
diff --git a/src/include/spec/bolt/message/v440/tag.h b/src/include/spec/bolt/message/v440/tag.h
new file mode 100644
index 00000000..655bf9da
--- /dev/null
+++ b/src/include/spec/bolt/message/v440/tag.h
@@ -0,0 +1,45 @@
+/*
+ * structure.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/message/common/structure.h
+ */
+#ifndef BOLT_TAG_H
+#define BOLT_TAG_H
+
+#define BOLT_TAG_SIZE 1
+
+typedef enum {
+ BT_NODE = 0x4E,
+ BT_RELATIONSHIP = 0x52,
+ BT_UNBOUNDRELATIONSHIP = 0x72,
+ BT_PATH = 0x50,
+ BT_DATE = 0x44,
+ BT_TIME = 0x54,
+ BT_LOCALTIME = 0x74,
+ BT_DATETIME = 0x46,
+ BT_DATETIMEZONEID = 0x66,
+ BT_LOCALDATETIME = 0x64,
+ BT_DURATION = 0x45,
+ BT_POINT2D = 0x58,
+ BT_POINT3D = 0x59
+} BOLT_TAG;
+
+#endif
diff --git a/src/include/spec/bolt/message/v500/message.h b/src/include/spec/bolt/message/v500/message.h
new file mode 100644
index 00000000..da46b6b0
--- /dev/null
+++ b/src/include/spec/bolt/message/v500/message.h
@@ -0,0 +1,28 @@
+/*
+ * message_4_4_0.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/message/message_4_4_0.h
+ */
+#ifndef SPEC_BOLT_MESSAGE_500_H
+#define SPEC_BOLT_MESSAGE_500_H
+
+
+#endif
diff --git a/src/include/spec/packstream/pack_utils.h b/src/include/spec/packstream/pack_utils.h
new file mode 100644
index 00000000..7009a921
--- /dev/null
+++ b/src/include/spec/packstream/pack_utils.h
@@ -0,0 +1,60 @@
+/*
+ * pack_utils.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/packstream/pack_utils.h
+ */
+#ifndef PACK_UTILS_H
+#define PACK_UTILS_H
+
+#include "graph_protocol_stddef.h"
+
+typedef enum {
+ PM_TINY_INT_MIN = -16,
+} PACK_MARKER_MIN;
+
+typedef enum {
+ PM_TINY_STRING_MAX = 15,
+ PM_TINY_INT_MAX = 127,
+ PM_TINY_LIST_MAX = 15,
+ PM_TINY_LIST8_MAX = 255,
+ PM_TINY_DICT_MAX = 15,
+ PM_TINY_STRUCT_MAX = 15,
+ PM_STRING8_MAX = 255,
+ PM_STRING16_MAX = 65535,
+ PM_STRING32_MAX = 2147483647,
+} PACK_MARKER_MAX;
+
+
+int pack_appender(size_t dest_size, char **dest, char *pack);
+
+bool is_marker_data_itself(uint8 c);
+
+bool is_tiny_container_marker(uint8 c);
+
+bool is_tiny_marker(uint8 c);
+
+bool is_container_marker(uint8 c);
+
+bool is_marker_with_sizebyte(uint8 c);
+
+int extract_pack_length(const char pack[]);
+
+#endif
diff --git a/src/include/spec/packstream/v100/coretypes.h b/src/include/spec/packstream/v100/coretypes.h
new file mode 100644
index 00000000..54e4adfc
--- /dev/null
+++ b/src/include/spec/packstream/v100/coretypes.h
@@ -0,0 +1,20 @@
+
+
+#ifndef SPEC_PACKSTREAM_DATATYPES_H
+#define SPEC_PACKSTREAM_DATATYPES_H
+
+
+
+typedef enum {
+ PACK_NULL,
+ BYTES,
+ BOOLEAN,
+ FLOAT,
+ INT,
+ LIST,
+ MAP,
+ STRING,
+ STRUCT
+} PACK_TYPE;
+
+#endif
diff --git a/src/include/spec/packstream/v100/marker.h b/src/include/spec/packstream/v100/marker.h
new file mode 100644
index 00000000..8fa6f1b9
--- /dev/null
+++ b/src/include/spec/packstream/v100/marker.h
@@ -0,0 +1,69 @@
+/*
+ * marker.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/spec/packstream/v100/marker.h
+ */
+#ifndef MARKER_H
+#define MARKER_H
+
+#define PACK_MARKER_LENGTH 1
+#define PACK_SIZE_LENGTH 1
+
+typedef enum {
+ PM_NULL = 0xC0,
+ PM_FALSE = 0xC2,
+ PM_TRUE = 0xC3,
+
+ PM_TINY_INT = 0x00, // 0xF0(-16) ~ 0x7F(127)
+ PM_INT8 = 0xC8,
+ PM_INT16 = 0xC9,
+ PM_INT32 = 0xCA,
+ PM_INT64 = 0xCB,
+
+ PM_FLOAT64 = 0xC1,
+
+ PM_BYTES8 = 0xCC,
+ PM_BYTES16 = 0xCD,
+ PM_BYTES32 = 0xCE,
+
+ PM_TINY_STRING = 0x80,
+ PM_STRING8 = 0xD0,
+ PM_STRING16 = 0xD1,
+ PM_STRING32 = 0xD3,
+
+ PM_TINY_LIST = 0x90,
+ PM_LIST8 = 0xD4,
+ PM_LIST16 = 0xD5,
+ PM_LIST32 = 0xD6,
+
+ PM_TINY_DICT = 0xA0,
+ PM_DICT8 = 0xD8,
+ PM_DICT16 = 0xD9,
+ PM_DICT32 = 0xDA,
+
+ PM_TINY_STRUCT = 0xB0,
+ PM_STRUCT8 = 0xDC,
+ PM_STRUCT16 = 0xDD,
+ PM_STRUCT32 = 0xDE,
+
+} PACK_MARKER;
+
+#endif
diff --git a/src/include/spec/packstream/v100/packstream_v100.h b/src/include/spec/packstream/v100/packstream_v100.h
new file mode 100644
index 00000000..127b5299
--- /dev/null
+++ b/src/include/spec/packstream/v100/packstream_v100.h
@@ -0,0 +1,24 @@
+
+
+#ifndef SPEC_PACKSTREAM_H
+#define SPEC_PACKSTREAM_H
+
+#include "graph_protocol_stddef.h"
+
+#define STRING8_SIZE 1
+
+char *write_tiny_boolean(bool b);
+
+char *write_tiny_string(char str[]);
+char *write_string8(char str[]);
+char *write_string16(char str[]);
+char *write_tiny_int(int integer);
+
+char *write_int16(int16 i);
+
+char *write_tiny_list_marker(int element_count);
+char *write_list8_marker(int element_count);
+char *write_tiny_dict_marker(int element_count);
+char *write_tiny_struct_marker(size_t element_count);
+
+#endif
\ No newline at end of file
diff --git a/src/include/spec/server_state/v440/server_state_v440.h b/src/include/spec/server_state/v440/server_state_v440.h
new file mode 100644
index 00000000..c934127f
--- /dev/null
+++ b/src/include/spec/server_state/v440/server_state_v440.h
@@ -0,0 +1,39 @@
+/*
+ * server_state_4_4_0.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/state/server/server_state_4_4_0.h
+ */
+#ifndef SPEC_BOLT_SERVER_STATE_4_4_0_H
+#define SPEC_BOLT_SERVER_STATE_4_4_0_H
+
+
+typedef enum {
+ DISCONNECTED //no socket connection
+ , CONNECTED // protocol handshake is completed successfully
+ , DEFUNCT //the socket connection is permanently closed
+ , READY //ready to accept a RUN message
+ , STREAMING //Auto-commit Transaction, a result is available for streaming from the server
+ , TX_READY //Explicit Transaction, ready to accept a RUN message
+ , TX_STREAMING //Explicit Transaction, a result is available for streaming from the server
+ , FAILED //a connection is in a temporarily unusable state
+ , INTERRUPTED //the server got an <INTERRUPT> signal
+} BOLT_SERVER_STATE;
+#endif
diff --git a/src/include/stubs/stubs.h b/src/include/stubs/stubs.h
new file mode 100644
index 00000000..43ed932f
--- /dev/null
+++ b/src/include/stubs/stubs.h
@@ -0,0 +1,46 @@
+/*
+ * stubs.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/include/stubs/stubs.h
+ */
+#ifndef STUBS_H
+#define STUBS_H
+
+#include "graph_protocol_stddef.h"
+
+
+enum STUB_NAME {
+ SUCCESS, COMMIT, SHOW_DATABASES, BOOKMARK, SHOW_CURRENT_USER, CALL_DBMS_COMPONENTS
+};
+
+struct STUB {
+ enum STUB_NAME name;
+ uint8 *data;
+ size_t len;
+};
+
+extern struct STUB STUBS[];
+
+struct STUB stub_finder(enum STUB_NAME name);
+
+struct msg *stub_lws_msg_maker(enum STUB_NAME stub_name);
+
+#endif
diff --git a/src/include/utils/config_helper.h b/src/include/utils/config_helper.h
new file mode 100644
index 00000000..941a9422
--- /dev/null
+++ b/src/include/utils/config_helper.h
@@ -0,0 +1,28 @@
+
+
+#ifndef AGBOLT_CONFIG_HELPER_H
+#define AGBOLT_CONFIG_HELPER_H
+
+#include "graph_protocol_stddef.h"
+
+struct garph_protocol_conf {
+ bool log_debug;
+ uint32 bolt_port;
+ char *socket_dir;
+ char *pid_file_name;
+ char *conn_string;
+ char *graph_path;
+};
+
+bool bool_conf_parser(char *str);
+
+int64 long_conf_parser(char *str);
+
+char *str_conf_parser(char *str);
+
+char *str_connstr_parser(char *str);
+
+
+void free_configuration(struct garph_protocol_conf s);
+
+#endif
diff --git a/src/include/utils/logging.h b/src/include/utils/logging.h
new file mode 100644
index 00000000..1e7d9e77
--- /dev/null
+++ b/src/include/utils/logging.h
@@ -0,0 +1,10 @@
+
+#ifndef LOGGING_H
+#define LOGGING_H
+
+
+#include "graph_protocol_stddef.h"
+
+
+#endif
+
diff --git a/src/include/utils/option_helper.h b/src/include/utils/option_helper.h
new file mode 100644
index 00000000..b8024f0c
--- /dev/null
+++ b/src/include/utils/option_helper.h
@@ -0,0 +1,15 @@
+
+#ifndef OPTION_HELPER_H
+#define OPTION_HELPER_H
+
+
+#include "graph_protocol_stddef.h"
+#include "config.h"
+
+void usage(void);
+
+void show_version(void);
+
+
+#endif
+
diff --git a/src/include/utils/process.h b/src/include/utils/process.h
new file mode 100644
index 00000000..92335a42
--- /dev/null
+++ b/src/include/utils/process.h
@@ -0,0 +1,10 @@
+
+#ifndef PROCESS_H
+#define PROCESS_H
+
+#include "graph_protocol_stddef.h"
+pid_t fork_bolt_connection(const int *server_sock, const int *client_sock);
+
+#endif
+
+
diff --git a/src/include/utils/utils.h b/src/include/utils/utils.h
new file mode 100644
index 00000000..c2bb200d
--- /dev/null
+++ b/src/include/utils/utils.h
@@ -0,0 +1,17 @@
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#include "graph_protocol_stddef.h"
+
+size_t concaternating_byte_array(char **dest, size_t dest_size, char *src, size_t src_size);
+
+char *replace_double_quote_to_single_quote(char **dest, char *src, size_t src_size);
+
+char *concaternating_default_graphpath(char *graphpath, char *query);
+
+int32 read_from_conf(char *conf_abs_path);
+
+
+#endif
+
diff --git a/src/lib/libwebsocket/callback/callback_closed.c b/src/lib/libwebsocket/callback/callback_closed.c
new file mode 100644
index 00000000..c0130a92
--- /dev/null
+++ b/src/lib/libwebsocket/callback/callback_closed.c
@@ -0,0 +1,41 @@
+/*
+ * callback_closed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/callback/callback_closed.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "interface/pgwired_facade.h"
+#include "libwebsocket/lws.h"
+#include "libwebsocket/callback/lws_callback.h"
+
+
+uint8 lws_callback_closed(struct per_session_data *pss, struct per_vhost_storage *vhd, struct lws *wsi) {
+ lwsl_user("LWS_CALLBACK_CLOSED\n");
+ lws_ring_destroy(pss->ring);
+
+ if (*vhd->options & 1) {
+ if (!*vhd->interrupted)
+ *vhd->interrupted = 1 + pss->completed;
+ lws_cancel_service(lws_get_context(wsi));
+ }
+ return CALLBACK_SUCCESS;
+}
diff --git a/src/lib/libwebsocket/callback/callback_established.c b/src/lib/libwebsocket/callback/callback_established.c
new file mode 100644
index 00000000..e2541844
--- /dev/null
+++ b/src/lib/libwebsocket/callback/callback_established.c
@@ -0,0 +1,44 @@
+/*
+/*
+ * callback_established.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/callback/callback_established.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "interface/pgwired_facade.h"
+#include "libwebsocket/lws.h"
+#include "libwebsocket/callback/lws_callback.h"
+
+
+uint8 lws_callback_established(struct per_session_data *pss) {
+ /* generate a block of output before travis times us out */
+ lwsl_warn("LWS_CALLBACK_ESTABLISHED\n");
+ pss->ring = lws_ring_create(
+ sizeof(struct msg),
+ RING_DEPTH,
+ minimal_destroy_message);
+ if (!pss->ring)
+ return CALLBACK_ESTABLISHED_RING_IS_FALSE;
+ pss->tail = 0;
+
+ return CALLBACK_SUCCESS;
+}
\ No newline at end of file
diff --git a/src/lib/libwebsocket/callback/callback_init.c b/src/lib/libwebsocket/callback/callback_init.c
new file mode 100644
index 00000000..09f074c5
--- /dev/null
+++ b/src/lib/libwebsocket/callback/callback_init.c
@@ -0,0 +1,56 @@
+/*
+ * callback_init.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/callback/callback_init.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "interface/pgwired_facade.h"
+#include "libwebsocket/lws.h"
+#include "libwebsocket/callback/lws_callback.h"
+
+uint8 lws_callback_init(struct lws *wsi, struct per_vhost_storage *vhd, void *in) {
+
+ vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi),
+ lws_get_protocol(wsi),
+ sizeof(struct per_vhost_storage));
+
+ if (!vhd)
+ return CALLBACK_INIT_VHD_IS_FALSE;
+
+ vhd->context = lws_get_context(wsi);
+ vhd->vhost = lws_get_vhost(wsi);
+
+ /* get the pointers we were passed in pvo */
+ vhd->interrupted = (int *) lws_pvo_search(
+ (const struct lws_protocol_vhost_options *) in,
+ "interrupted")->value;
+
+ vhd->options = (int *) lws_pvo_search(
+ (const struct lws_protocol_vhost_options *) in,
+ "options")->value;
+
+ return CALLBACK_SUCCESS;
+}
+
+struct pg_conn *get_postgres_connection(char *conn_string) {
+ return connect_ag(conn_string);
+}
diff --git a/src/lib/libwebsocket/callback/callback_receive.c b/src/lib/libwebsocket/callback/callback_receive.c
new file mode 100644
index 00000000..b29d8b9d
--- /dev/null
+++ b/src/lib/libwebsocket/callback/callback_receive.c
@@ -0,0 +1,39 @@
+/*
+ * callback_receive.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/callback/callback_receive.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "interface/pgwired_facade.h"
+#include "libwebsocket/lws.h"
+#include "libwebsocket/callback/lws_callback.h"
+
+extern int in_transaction;
+
+uint8 lws_callback_receive(
+ struct lws *wsi, struct per_session_data *pss, size_t len, uint32 *n,
+ const struct msg *pmsg, struct msg *amsg, void *in
+) {
+
+
+
+}
diff --git a/src/lib/libwebsocket/callback/callback_writable.c b/src/lib/libwebsocket/callback/callback_writable.c
new file mode 100644
index 00000000..0faef611
--- /dev/null
+++ b/src/lib/libwebsocket/callback/callback_writable.c
@@ -0,0 +1,31 @@
+/*
+ * callback_writable.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/callback/callback_writable.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "interface/pgwired_facade.h"
+#include "libwebsocket/lws.h"
+#include "libwebsocket/callback/lws_callback.h"
+
+
+uint8 lws_callback_writable(struct per_session_data *pss);
diff --git a/src/lib/libwebsocket/lws_extensions.c b/src/lib/libwebsocket/lws_extensions.c
new file mode 100644
index 00000000..eaf3aecd
--- /dev/null
+++ b/src/lib/libwebsocket/lws_extensions.c
@@ -0,0 +1,23 @@
+/*
+ * lws_extensions.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/lws_extensions.c
+ */
\ No newline at end of file
diff --git a/src/lib/libwebsocket/lws_lejp_parser.c b/src/lib/libwebsocket/lws_lejp_parser.c
new file mode 100644
index 00000000..8f585cd9
--- /dev/null
+++ b/src/lib/libwebsocket/lws_lejp_parser.c
@@ -0,0 +1,179 @@
+/*
+ * lws_lejp_parser.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/lws_lejp_parser.c
+ */
+#include <stdio.h>
+#include <stddef.h>
+#include "libwebsockets.h"
+
+#include "spec/packstream/pack_utils.h"
+#include "spec/packstream/v100/packstream_v100.h"
+#include "libwebsocket/lws.h"
+
+#define LEJP_JSON_BUFFER 100
+
+static struct lejp_json *lj;
+
+static const char *const reason_names[] = {
+ "LEJPCB_CONSTRUCTED",
+ "LEJPCB_DESTRUCTED",
+ "LEJPCB_START",
+ "LEJPCB_COMPLETE",
+ "LEJPCB_FAILED",
+ "LEJPCB_PAIR_NAME",
+ "LEJPCB_VAL_TRUE",
+ "LEJPCB_VAL_FALSE",
+ "LEJPCB_VAL_NULL",
+ "LEJPCB_VAL_NUM_INT",
+ "LEJPCB_VAL_NUM_FLOAT",
+ "LEJPCB_VAL_STR_START",
+ "LEJPCB_VAL_STR_CHUNK",
+ "LEJPCB_VAL_STR_END",
+ "LEJPCB_ARRAY_START",
+ "LEJPCB_ARRAY_END",
+ "LEJPCB_OBJECT_START",
+ "LEJPCB_OBJECT_END",
+ "LEJPCB_OBJECT_END_PRE",
+};
+
+static const char *const tok[] = {
+ "dummy___"
+};
+
+static signed char
+cb(struct lejp_ctx *ctx, char reason) {
+ char buf[1024];
+ char *p = buf;
+ char *end = &buf[sizeof(buf)];
+ int n;
+
+ // user code
+ static size_t dict_len;
+ static char *pack_dict_key = NULL;
+ static size_t pack_dict_key_len = 0;
+ static char *pack_dict_val = NULL;
+ static size_t pack_dict_val_len = 0;
+
+ for (n = 0; n < ctx->sp; n++)
+ *p++ = ' ';
+ *p = '\0';
+
+ if (reason & LEJP_FLAG_CB_IS_VALUE) {
+ switch (reason) {
+ case LEJPCB_VAL_TRUE:
+ case LEJPCB_VAL_FALSE:
+ case LEJPCB_VAL_NULL:
+ case LEJPCB_VAL_NUM_INT:
+ case LEJPCB_VAL_NUM_FLOAT:
+ case LEJPCB_VAL_STR_CHUNK:
+ case LEJPCB_VAL_STR_END:
+ pack_dict_val = ctx->buf;
+ pack_dict_val_len = strlen(buf);
+ lj->value = ctx->buf;
+ break;
+ default:
+ p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), " value '%s' ", ctx->buf);
+ if (ctx->ipos) {
+ p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "(array indexes: ");
+ for (n = 0; n < ctx->ipos; n++) {
+ p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "%d ", ctx->i[n]);
+ }
+ p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ") ");
+ }
+ }
+ lwsl_notice("%s (%s)\r\n", buf, reason_names[(unsigned int) (reason) & (LEJP_FLAG_CB_IS_VALUE - 1)]);
+ return 0;
+ }
+
+ switch (reason) {
+ case LEJPCB_COMPLETE:
+// lwsl_notice("%sParsing Completed (LEJPCB_COMPLETE)\n", buf);
+ break;
+ case LEJPCB_PAIR_NAME:
+ lwsl_notice("%spath: '%s' (LEJPCB_PAIR_NAME)\n", buf, ctx->path);
+ pack_dict_key = ctx->path;
+ pack_dict_key_len = strlen(buf);
+ lj->key = ctx->path;
+ break;
+ }
+ return 0;
+}
+
+int lws_lejp_parser(char json_str[]) {
+ int n = 1;
+ int ret = 1;
+ int m = 0;
+ struct lejp_ctx ctx;
+ char buf[512];
+
+ lejp_construct(&ctx, cb, NULL, tok, LWS_ARRAY_SIZE(tok));
+
+ memcpy(buf, json_str, strlen(json_str) + 1);
+ n = strlen(json_str) + 1;
+
+ m = lejp_parse(&ctx, (uint8_t *) buf, n);
+
+ if (m < 0 && m != LEJP_CONTINUE) {
+ lwsl_err("parse failed %d\n", m);
+ }
+ lwsl_notice("parse okay (%d)\n", m);
+ lejp_destruct(&ctx);
+ return 0;
+}
+
+struct lejp_json *get_lejp_json() {
+ return lj;
+}
+
+struct lejp_json *insert_lejp_json(struct lejp_json *top, struct lejp_json *target) {
+ struct lejp_json *tmp = top;
+
+ while (1) {
+ if (tmp->next == NULL)
+ break;
+ else {
+ tmp = tmp->next;
+ }
+ }
+ top->next = target;
+ return lj;
+}
+
+char *lejp_to_pack(struct lejp_json *l) {
+ char *ret;
+ char *pack_concat = NULL;
+ size_t pack_concat_len = 0;
+ char *k;
+ char *v;
+
+ size_t total_count = 0;
+ for (struct lejp_json *i = l; i->next != NULL; i = i->next) {
+ k = i->key;
+ v = i->value;
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_string8(k));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_string8(v));
+ total_count++;
+ }
+
+ pack_concat_len += pack_appender(pack_concat_len, &ret, write_tiny_struct_marker(total_count));
+ return "";
+}
\ No newline at end of file
diff --git a/src/lib/libwebsocket/lws_main.c b/src/lib/libwebsocket/lws_main.c
new file mode 100644
index 00000000..05bb1a87
--- /dev/null
+++ b/src/lib/libwebsocket/lws_main.c
@@ -0,0 +1,116 @@
+/*
+ * lws.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/lws.c
+ */
+
+#include "libwebsocket/lws.h"
+
+
+//int port = 7681;
+int interrupted;
+int options;
+
+struct per_session_data pss = {
+ NULL, 0, 0, 0, 0, 0, NULL};
+
+struct lws_protocols protocols[] = {
+ {
+ "lws-minimal-server-echo",
+ callback_minimal_server_echo,
+ sizeof(struct per_session_data),
+ 1024,
+ 0,
+ &pss,
+ 0
+ },
+ LWS_PROTOCOL_LIST_TERM
+};
+
+
+static const struct lws_protocol_vhost_options pvo_options = {
+ NULL,
+ NULL,
+ "options", /* pvo name */
+ (void *) &options /* pvo value */
+};
+
+static const struct lws_protocol_vhost_options pvo_interrupted = {
+ &pvo_options,
+ NULL,
+ "interrupted", /* pvo name */
+ (void *) &interrupted /* pvo value */
+};
+
+static const struct lws_protocol_vhost_options pvo = {
+ NULL, /* "next" pvo linked-list */
+ &pvo_interrupted, /* "child" pvo linked-list */
+ "lws-minimal-server-echo", /* protocol name we belong to on this vhost */
+ "" /* ignored */
+};
+
+static const struct lws_extension extensions[] = {
+ {
+ "permessage-deflate",
+ lws_extension_callback_pm_deflate,
+ "permessage-deflate"
+ "; client_no_context_takeover"
+ "; client_max_window_bits"
+ },
+ {NULL, NULL, NULL /* terminator */ }
+};
+
+
+int ws_server(int32 port) {
+
+ struct lws_context_creation_info info;
+ struct lws_context *context;
+
+ int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE;
+
+ signal(SIGINT, sigint_handler);
+
+ lws_set_log_level(logs, NULL);
+
+ memset(&info, 0, sizeof(struct lws_context_creation_info)); /* otherwise uninitialized garbage */
+ info.port = port;
+ info.protocols = protocols;
+ info.pvo = &pvo;
+ info.extensions = extensions;
+ info.pt_serv_buf_size = 32 * 1024;
+ info.options = LWS_SERVER_OPTION_VALIDATE_UTF8 |
+ LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
+
+ context = lws_create_context(&info);
+
+ if (!context) {
+ lwsl_err("lws init failed\n");
+ return 1;
+ }
+
+ while (n >= 0 && !interrupted) {
+ n = lws_service(context, 0);
+ }
+
+ lws_context_destroy(context);
+ lwsl_user("Completed %s\n", interrupted == 2 ? "OK" : "failed");
+ return interrupted != 2;
+}
diff --git a/src/lib/libwebsocket/lws_protocol.c b/src/lib/libwebsocket/lws_protocol.c
new file mode 100644
index 00000000..a9c18e81
--- /dev/null
+++ b/src/lib/libwebsocket/lws_protocol.c
@@ -0,0 +1,219 @@
+/*
+ * lws_protocol.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/lws_protocol.c
+ */
+
+#include "libwebsocket/lws.h"
+#include "interface/pgwired_facade.h"
+#include "communication/agbolt_ws_hook.h"
+#include "libwebsocket/callback/lws_callback.h"
+
+#include "utils/config_helper.h"
+
+
+static struct pg_conn *conn;
+int in_transaction = 0;
+extern int interrupted;
+
+extern struct garph_protocol_conf garph_protocol_conf;
+
+
+int
+callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason,
+ void *user, void *in, size_t len) {
+
+ /* This will be different for every connected peer */
+ struct per_session_data *pss =
+ (struct per_session_data *) user;
+
+ struct per_vhost_storage *vhd = (struct per_vhost_storage *)
+ lws_protocol_vh_priv_get(lws_get_vhost(wsi),
+ lws_get_protocol(wsi));
+
+ const struct msg *pmsg;
+ struct msg amsg;
+ int writable_m;
+ int receive_n;
+ int flags;
+
+ switch (reason) {
+ case LWS_CALLBACK_PROTOCOL_INIT:
+ switch (lws_callback_init(wsi, vhd, in)) {
+ case CALLBACK_INIT_VHD_IS_FALSE:
+ return -1;
+ case CALLBACK_SUCCESS:
+ break;
+ }
+
+ conn = get_postgres_connection(garph_protocol_conf.conn_string);
+ break;
+ case LWS_CALLBACK_ESTABLISHED:
+ switch (lws_callback_established(pss)) {
+ case CALLBACK_ESTABLISHED_RING_IS_FALSE:
+ return -1;
+ case CALLBACK_SUCCESS:
+ break;
+ }
+
+ break;
+ case LWS_CALLBACK_SERVER_WRITEABLE:
+ lwsl_user("LWS_CALLBACK_SERVER_WRITEABLE\n");
+ if (pss->write_consume_pending) {
+ /* perform the deferred fifo consume */
+ lws_ring_consume_single_tail(pss->ring, &pss->tail, 1);
+ pss->write_consume_pending = 0;
+ }
+ pmsg = lws_ring_get_element(pss->ring, &pss->tail);
+ if (!pmsg) {
+ lwsl_user(" (nothing in ring)\n");
+ break;
+ }
+
+ struct msg *resp;
+ resp = agbolt_ws_hook(conn, pmsg);
+ assert(resp);
+
+ flags = lws_write_ws_flags(resp->binary,
+ resp->first, resp->final);
+
+ /* notice we allowed for LWS_PRE in the payload already */
+ writable_m = lws_write(
+ wsi, ((uint8 *) resp->payload)
+// + LWS_PRE
+ , resp->len, (enum lws_write_protocol) flags);
+
+ if (writable_m < (int) resp->len) {
+ lwsl_err("ERROR %d writing to ws socket\n", writable_m);
+ return -1;
+ }
+
+ if (resp->len) { ;
+ puts((const char *) resp->payload);
+ lwsl_hexdump_notice(resp->payload, resp->len);
+ }
+
+ lwsl_user(" wrote %d: flags: 0x%x first: %d final %d\n",
+ writable_m, flags, resp->first, resp->final);
+
+ /*
+ * Workaround deferred deflate in pmd extension by only
+ * consuming the fifo entry when we are certain it has been
+ * fully deflated at the next WRITABLE callback. You only need
+ * this if you're using pmd.
+ */
+
+ pss->write_consume_pending = 1;
+ lws_callback_on_writable(wsi);
+
+ if (pss->flow_controlled &&
+ (int) lws_ring_get_count_free_elements(pss->ring) > RING_DEPTH - 5) {
+ lws_rx_flow_control(wsi, 1);
+ pss->flow_controlled = 0;
+ }
+
+ if ((*vhd->options & 1) && resp && resp->final)
+ pss->completed = 1;
+ break;
+
+ case LWS_CALLBACK_RECEIVE:
+
+
+ lwsl_user("LWS_CALLBACK_RECEIVE: %4d (rpp %5d, first %d, "
+ "last %d, bin %d, msglen %d (+ %d = %d))\n",
+ (int) len, (int) lws_remaining_packet_payload(wsi),
+ lws_is_first_fragment(wsi),
+ lws_is_final_fragment(wsi),
+ lws_frame_is_binary(wsi), pss->msglen, (int) len,
+ (int) pss->msglen + (int) len);
+ if (len) { ;
+ puts((const char *) in);
+ lwsl_hexdump_notice(in, len);
+ }
+ (amsg).first = (char) lws_is_first_fragment(wsi);
+ (amsg).final = (char) lws_is_final_fragment(wsi);
+ (amsg).binary = (char) lws_frame_is_binary(wsi);
+
+ receive_n = (int) lws_ring_get_count_free_elements(pss->ring);
+
+ if (!receive_n) {
+ lwsl_user("dropping!\n");
+ return CALLBACK_BREAK;
+ }
+ if ((amsg).final)
+ pss->msglen = 0;
+ else
+ pss->msglen += (uint32_t) len;
+
+ (amsg).len = len;
+ (amsg).payload = malloc(len); // LWS_PRE eleminated
+
+ if (!(amsg).payload) {
+ lwsl_user("OOM: dropping\n");
+ return CALLBACK_BREAK;
+
+ }
+
+ switch (len) {
+ case 75: // begin
+ case 63: // begin
+ case 65: // begin
+ lwsl_user("begin detected, return 0.\n");
+ in_transaction = 1;
+ return 0; // don't write
+ default:
+ break;
+ }
+
+ memcpy((char *) (amsg).payload, in, len); // LWS_PRE eleminated
+ if (!lws_ring_insert(pss->ring, &amsg, 1)) {
+ minimal_destroy_message(&amsg);
+ lwsl_user("dropping!\n");
+ return CALLBACK_BREAK;
+
+ }
+
+ lws_callback_on_writable(wsi);
+ if (receive_n < 3 && !pss->flow_controlled) {
+ pss->flow_controlled = 1;
+ lws_rx_flow_control(wsi, 0);
+ }
+
+ break;
+ case LWS_CALLBACK_CLOSED:
+
+ lwsl_user("LWS_CALLBACK_CLOSED\n");
+ lws_ring_destroy(pss->ring);
+
+ if (*vhd->options & 1) {
+ if (!*vhd->interrupted)
+ *vhd->interrupted = 1 + pss->completed;
+ lws_cancel_service(lws_get_context(wsi));
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+
diff --git a/src/lib/libwebsocket/lws_utils.c b/src/lib/libwebsocket/lws_utils.c
new file mode 100644
index 00000000..3442ab72
--- /dev/null
+++ b/src/lib/libwebsocket/lws_utils.c
@@ -0,0 +1,59 @@
+/*
+ * lws_utils.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/lws_utils.c
+ */
+
+#include "libwebsocket/lws.h"
+#include "stubs/stubs.h"
+
+extern int interrupted;
+extern int port;
+
+
+void minimal_destroy_message(void *_msg) {
+ struct msg *msg = _msg;
+
+ free(msg->payload);
+ msg->payload = NULL;
+ msg->len = 0;
+}
+
+void sigint_handler(int sig) {
+ interrupted = 1;
+}
+
+struct msg *mallocating_msg_with_length(uint8 *raw, size_t len) {
+ struct msg *r = malloc(sizeof(struct msg *));
+ r->payload = (uint8 *) raw;
+ r->final = 1;
+ r->first = 1;
+ r->len = len;
+ r->binary = LWS_WRITE_BINARY;
+ return r;
+}
+
+
+struct msg *stub_lws_msg_maker(enum STUB_NAME stub_name) {
+ struct STUB s = stub_finder(stub_name);
+ return mallocating_msg_with_length(s.data, s.len);
+}
+
diff --git a/src/lib/libwebsocket/lws_vhost.c b/src/lib/libwebsocket/lws_vhost.c
new file mode 100644
index 00000000..e906cf0a
--- /dev/null
+++ b/src/lib/libwebsocket/lws_vhost.c
@@ -0,0 +1,25 @@
+/*
+ * lws_vhost.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/lib/libwebsocket/lws_vhost.c
+ */
+
+#include "libwebsocket/lws.h"
\ No newline at end of file
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 00000000..780d461b
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,68 @@
+#include <getopt.h>
+
+#include "utils/option_helper.h"
+#include "utils/config_helper.h"
+#include "communication/socket_manager.h"
+#include "libwebsocket/lws.h"
+
+static struct option long_opts[] = {
+ {"debug", no_argument, NULL, 'd'},
+ {"config-file", required_argument, NULL, 'f'},
+ {"help", no_argument, NULL, 'h'},
+ {"version", no_argument, NULL, 'v'},
+ {NULL, 0, NULL, 0}
+};
+
+
+struct garph_protocol_conf garph_protocol_conf;
+
+int main(int argc, char **argv) {
+ int opt;
+ int debug_level = 0;
+ int *long_opt_index = NULL;
+
+ char *target;
+
+ if (argc == 1) { goto TEST; }
+ if (argc == 2) { goto TEMP; }
+
+ while ((opt = getopt_long(argc, argv, "df:hv", long_opts, long_opt_index)) != -1) {
+ switch (opt) {
+ case 'd':
+ debug_level = 1;
+ break;
+ case 'f':
+ if (!optarg) {
+ usage();
+ exit(1);
+ }
+ TEMP:
+ read_from_conf(argv[1]);
+ ws_server(garph_protocol_conf.bolt_port);
+ exit(0);
+ case 'h':
+ usage();
+ exit(0);
+ case 'v':
+ show_version();
+ exit(0);
+ default:
+ if (!optarg) {
+ usage();
+ exit(1);
+ }
+ }
+ }
+
+ free_configuration(garph_protocol_conf);
+
+
+ TEST:
+ target = "{\"title\": \"The Matrix\", \"tagline\": \"Welcome to the Real World\", \"released\": 1999}";
+ target = "{\"ID\":null,\"name\":\"Doe\",\"first-name\":\"John\",\"age\":25,\"hobbies\":[\"reading\",\"cinema\",{\"sports\":[\"volley-ball\",\"snowboard\"]}],\"address\":{}}";
+ lws_lejp_parser(target);
+
+ return 0;
+}
+
+
diff --git a/src/resources/graph_protocol.conf b/src/resources/graph_protocol.conf
new file mode 100644
index 00000000..c7f46e06
--- /dev/null
+++ b/src/resources/graph_protocol.conf
@@ -0,0 +1,6 @@
+log_debug:true
+bolt_port:7681
+socket_dir:/tmp
+pid_file_name:graph_protocol.pid
+conn_string:host=localhost port=5432 dbname=postgres user=seo password=postgres
+graph_path:movies
\ No newline at end of file
diff --git a/src/spec/bolt/bolt_utils.c b/src/spec/bolt/bolt_utils.c
new file mode 100644
index 00000000..8c3efffc
--- /dev/null
+++ b/src/spec/bolt/bolt_utils.c
@@ -0,0 +1,112 @@
+/*
+ * bolt_utils.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/bolt/bolt_utils.c
+ */
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/message/message_utils.h"
+#include "spec/bolt/message/v440/tag.h"
+#include "spec/bolt/message/v440/message.h"
+#include "spec/bolt/message/v440/chunk.h"
+#include "spec/bolt/message/v440/signature.h"
+
+bool is_bolt_tag(uint8 c) {
+ switch (c) {
+ case 0x4E:
+ case 0x52:
+ case 0x72:
+ case 0x50:
+ case 0x44:
+ case 0x54:
+ case 0x74:
+ case 0x46:
+ case 0x66:
+ case 0x64:
+ case 0x45:
+ case 0x58:
+ case 0x59:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool is_bolt_signature(uint8 c) {
+ switch (c) {
+ case 0x01:
+ case 0x02:
+ case 0x0F:
+ case 0x10:
+ case 0x2F:
+ case 0x3F:
+ case 0x11:
+ case 0x12:
+ case 0x13:
+ case 0x66:
+ case 0x70:
+ case 0x7E:
+ case 0x7F:
+ case 0x71:
+ return true;
+ default:
+ return false;
+ }
+}
+
+
+bool byte_to_bolt_signature(uint8 c) {
+ switch (c) {
+ case 0x01:
+ return BS_HELLO;
+ case 0x02:
+ return BS_GOODBYE;
+ case 0x0F:
+ return BS_RESET;
+ case 0x10:
+ return BS_RUN;
+ case 0x2F:
+ return BS_DISCARD;
+ case 0x3F:
+ return BS_PULL;
+ case 0x11:
+ return BS_BEGIN;
+ case 0x12:
+ return BS_COMMIT;
+ case 0x13:
+ return BS_ROLLBACK;
+ case 0x66:
+ return BS_ROUTE;
+ case 0x70:
+ return BS_SUCCESS;
+ case 0x7E:
+ return BS_IGNORED;
+ case 0x7F:
+ return BS_FAILURE;
+ case 0x71:
+ return BS_RECORD;
+ default:
+ return false;
+ }
+}
+
+
diff --git a/src/spec/bolt/handshake/handshake_utils.c b/src/spec/bolt/handshake/handshake_utils.c
new file mode 100644
index 00000000..be875cd3
--- /dev/null
+++ b/src/spec/bolt/handshake/handshake_utils.c
@@ -0,0 +1,23 @@
+/*
+ * handshake_utils.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/bolt/handshake/handshake_utils.c
+ */
\ No newline at end of file
diff --git a/src/spec/bolt/handshake/v430/common/handshake.c b/src/spec/bolt/handshake/v430/common/handshake.c
new file mode 100644
index 00000000..0e7cd5c7
--- /dev/null
+++ b/src/spec/bolt/handshake/v430/common/handshake.c
@@ -0,0 +1,45 @@
+
+
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/handshake/handshake.h"
+#include "spec/bolt/handshake/v430/handshake_v430.h"
+
+const char BOLT_CONN_IDENT_BYTEARRAY[BOLT_CONN_IDENT_SIZE] = {0x60, 0x60, 0xB0, 0x17};
+
+bool is_bolt_conn(const char recv[]) {
+ for (int i = 0; i < BOLT_CONN_IDENT_SIZE; ++i) {
+ if (recv[i] != BOLT_CONN_IDENT_BYTEARRAY[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+void copy_client_info(char recv[]) {
+
+}
+
+
+bolt_server_identification
+bolt_version_negotiation(char recv[]) {
+ char server_available_ver[4] = {0x00, SERVER_VERSION_HOTFIX, SERVER_VERSION_MINOR, SERVER_VERSION_MAJOR};
+ bolt_server_identification bolt_server_ident;
+ memcpy(bolt_server_ident.avail_version, server_available_ver, 4);
+ return bolt_server_ident;
+}
+
+
+void bolt_handshake(int *conn, char recv[]) {
+ int i = 0;
+
+ if (is_bolt_conn(recv)) {
+ i += BOLT_CONN_IDENT_SIZE;
+ copy_client_info(recv);
+ bolt_version_negotiation(&recv[i]);
+ } else {
+ perror("not a bolt connection. socket distruct");
+ }
+}
\ No newline at end of file
diff --git a/src/spec/bolt/handshake/v430/handshake_430.c b/src/spec/bolt/handshake/v430/handshake_430.c
new file mode 100644
index 00000000..40c7035d
--- /dev/null
+++ b/src/spec/bolt/handshake/v430/handshake_430.c
@@ -0,0 +1,205 @@
+/*
+ * handshake_4_3_0.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/handshake/handshake_4_3_0.c
+ */
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/handshake/v430/handshake_v430.h"
+#include "communication/socket_manager.h"
+#include "spec/bolt/message/v440/message.h"
+#include "spec/bolt/message/v440/chunk.h"
+#include "stubs/stubs.h"
+
+
+void bytestream_handshake(int *data_len, int *new_socket, char *buffer) {
+
+// *data_len = recv_data(new_socket, buffer);
+//
+// bolt_server_identification bolt_server_ident;
+// bolt_server_ident = bolt_handshake(new_socket, buffer);
+//
+// *data_len = send_data(new_socket, bolt_server_ident.avail_version,
+// sizeof(bolt_server_identification));
+}
+
+char server_available_ver[4] = {0x00, 0x02, 0x04, 0x04};
+
+
+size_t version_neogotiation(int *client_socket) {
+ size_t data_len;
+
+ data_len = send_data(client_socket, server_available_ver, 4);
+ return data_len;
+}
+
+void simple_handshake(int listen_fd, int new_socket,
+ struct sockaddr_in address) {
+
+ //socket var
+ int addrlen = sizeof(address);
+ char buffer[TCP_BUF_SIZE] = {0};
+ int data_len;
+
+
+ //chunking var
+ BOLT_CHUNK cnk;
+ char *src;
+ char *cat;
+ size_t src_len = 0;
+ size_t cat_len = 0;
+
+ data_len = version_neogotiation(&new_socket);
+
+ //recv bolt:hello
+ data_len = recv_data(&new_socket, buffer);
+
+ //send bolt:hello-success
+ cnk = bolt_hello_success("", 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+ data_len = send_data(&new_socket, cat, cat_len);
+
+ data_len = recv_data(&new_socket, buffer);
+
+ char route_success[] = {
+ 0x00, 0x91, 0xb1, 0x70, 0xa1, 0x82, 0x72, 0x74, 0xa3, 0x87, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x93,
+ 0xa2, 0x89, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x91, 0x8e, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
+ 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x37, 0x36, 0x38, 0x37, 0x84, 0x72, 0x6f, 0x6c, 0x65, 0x85, 0x57, 0x52, 0x49,
+ 0x54, 0x45, 0xa2, 0x89, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x91, 0x8e, 0x6c, 0x6f, 0x63,
+ 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x37, 0x36, 0x38, 0x37, 0x84, 0x72, 0x6f, 0x6c, 0x65, 0x84, 0x52,
+ 0x45, 0x41, 0x44, 0xa2, 0x89, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x91, 0x8e, 0x6c, 0x6f,
+ 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x37, 0x36, 0x38, 0x37, 0x84, 0x72, 0x6f, 0x6c, 0x65, 0x85,
+ 0x52, 0x4f, 0x55, 0x54, 0x45, 0x83, 0x74, 0x74, 0x6c, 0xc9, 0x01, 0x2c, 0x82, 0x64, 0x62, 0x85, 0x6e, 0x65,
+ 0x6f, 0x34, 0x6a, 0x00, 0x00
+ };
+ data_len = send_data(&new_socket, route_success, 149);
+
+ data_len = recv_data(&new_socket, buffer);
+
+ char reset_success[] = {
+ 0x00, 0x03, 0xb1, 0x70, 0xa0, 0x00, 0x00
+ };
+ data_len = send_data(&new_socket, reset_success, 7);
+
+
+ //routed cluster, handshake again.
+ shutdown(new_socket, 3);
+
+ accept_sock(&new_socket, &listen_fd, &address, addrlen);
+ data_len = recv_data(&new_socket, buffer);
+ data_len = send_data(&new_socket, server_available_ver, 4);
+
+
+ data_len = recv_data(&new_socket, buffer);
+
+ // neo4j auth success
+ cat_len = 0;
+ cnk = bolt_hello_success("", 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+ data_len = send_data(&new_socket, cat, cat_len);
+
+// data_len = send_data(&new_socket, hello_n4j_success_default_auth, 71);
+ data_len = recv_data(&new_socket, buffer);
+
+
+
+ //chunk-bolt:run-success(call db.ping~~)
+ cat_len = 0;
+ cnk = bolt_run_dbping_success("", 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+
+ //chunk-bolt:record(call db.ping~~)
+ cnk = bolt_run_dbping_record("", 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+
+ //chunk-bolt:success(bookmark~~)
+ cnk = bolt_run_dbping_bookmark_success(NULL, 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+
+ data_len = send_data(&new_socket, cat, cat_len);
+
+ cat_len = 0;
+
+ // resetting conn
+
+ data_len = recv_data(&new_socket, buffer);
+
+ struct STUB s = stub_finder(SUCCESS);
+ data_len = send_data(&new_socket, s.data, s.len);
+
+ // C: RUN { .. }
+ // C: PULL { ..}
+ // pipelined client msg
+ data_len = recv_data(&new_socket, buffer);
+
+
+ char *cypher_query;
+ size_t cypher_query_len;
+ cypher_query_len = extract_cypher_string(buffer, &cypher_query);
+
+ PGconn *conn = connect_ag("");
+ PGresult *pg_result = exec_cypher(conn, cypher_query);
+ char *pgresult_bytearray;
+
+ int field_count = PQnfields(pg_result);
+ char **field_names = malloc(sizeof(char *) * field_count);
+
+ for (int i = 0; i < field_count; ++i) {
+ char *fname = PQfname(pg_result, i);
+ field_names[i] = malloc(strlen(fname) + 1);//with null
+ field_names[i] = memcpy(field_names[i], fname, strlen(fname) + 1);
+ }
+
+
+ //
+ src_len = 0;
+ cat_len = 0;
+
+ //run-success
+ cnk = bolt_run_success(field_names, field_count);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+
+ //record
+ src_len = extract_cnk_from_pgresult(pg_result, &pgresult_bytearray);
+ cat_len = concaternating_byte_array(&cat, cat_len, pgresult_bytearray, src_len);
+
+ //pull-success
+ cnk = bolt_pull_success(NULL, 0);
+ src = bolt_chunk_to_byte_array(&cnk);
+ src_len = ntohs(cnk.header) + BOLT_CHUNK_HEADER_SIZE * 2;
+ cat_len = concaternating_byte_array(&cat, cat_len, src, src_len);
+
+
+ data_len = send_data(&new_socket, cat, cat_len);
+}
diff --git a/src/spec/bolt/message/v440/detailed/record.c b/src/spec/bolt/message/v440/detailed/record.c
new file mode 100644
index 00000000..69f47e0e
--- /dev/null
+++ b/src/spec/bolt/message/v440/detailed/record.c
@@ -0,0 +1,62 @@
+/*
+ * record.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/bolt/message/v440/record.c
+ */
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/message/v440/message.h"
+#include "spec/bolt/message/v440/chunk.h"
+#include "spec/bolt/message/v440/signature.h"
+#include "spec/bolt/message/v440/tag.h"
+
+
+#include "spec/packstream/v100/packstream_v100.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/pack_utils.h"
+#include "utils/utils.h"
+
+#include "communication/socket_manager.h"
+#include "stubs/stubs.h"
+#include "spec/bolt/message/v440/tag.h"
+
+#include "libwebsockets.h"
+
+
+BOLT_CHUNK bolt_run_dbping_record(char recv[], int len) {
+ BOLT_CHUNK cnk;
+
+ size_t c = 0; //count
+ char *b = NULL;
+
+ c += pack_appender(c, &b, write_tiny_struct_marker(1));
+ c += pack_appender(c, &b, write_bolt_signature(BS_RECORD));
+ c += pack_appender(c, &b, write_tiny_list_marker(1));
+ c += pack_appender(c, &b, write_tiny_boolean(true));
+
+ cnk.header = htons((unsigned short) (c));
+ cnk.body = b;
+ cnk.ender = (unsigned short) 0x0000;
+
+ return cnk;
+}
diff --git a/src/spec/bolt/message/v440/message_utils.c b/src/spec/bolt/message/v440/message_utils.c
new file mode 100644
index 00000000..6ccc1573
--- /dev/null
+++ b/src/spec/bolt/message/v440/message_utils.c
@@ -0,0 +1,306 @@
+
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/message/v440/message.h"
+#include "spec/bolt/message/v440/chunk.h"
+#include "spec/bolt/message/v440/signature.h"
+#include "spec/bolt/message/v440/tag.h"
+
+
+#include "spec/packstream/v100/packstream_v100.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/pack_utils.h"
+#include "utils/utils.h"
+
+#include "communication/socket_manager.h"
+#include "stubs/stubs.h"
+#include "spec/bolt/message/v440/tag.h"
+#include "spec/bolt/message/message_utils.h"
+
+#include "libwebsockets.h"
+#include "libwebsocket/lws.h"
+
+char *write_bolt_signature(BOLT_SIGNATURE bs) {
+ char *result;
+ result = malloc(BOLT_SIGNATURE_SIZE);
+ result[0] = bs;
+ return result;
+}
+
+char *write_bolt_tag(BOLT_TAG bt) {
+ char *result;
+ result = malloc(BOLT_TAG_SIZE);
+ result[0] = bt;
+ return result;
+}
+
+
+size_t extract_ws_cypher_string(char buf[], char **dest) {
+
+ uint8 marker_byte = buf[4];
+ size_t sizebyte_len;
+ size_t size;
+
+ union extract_by_union {
+ uint8 c[8];
+ uint16 s[4];
+ uint32 i[2];
+ uint64 d[1];
+ } extract_size;
+
+ if (PM_TINY_STRING == (marker_byte & NIBBLE_HIGH)) {
+ sizebyte_len = 0;
+ size = marker_byte & NIBBLE_LOW;
+
+ *dest = (char *) malloc(sizebyte_len + 1);
+ memcpy(*dest, &buf[6], sizebyte_len);
+ (*dest)[sizebyte_len] = '\0';
+
+ } else {
+ switch (marker_byte) {
+ case PM_STRING8:
+ extract_size.c[0] = buf[5];
+ sizebyte_len = extract_size.c[0];
+ size = extract_size.c[0];
+
+ *dest = (char *) malloc(sizebyte_len + 1);
+ memcpy(*dest, &buf[6], sizebyte_len);
+ (*dest)[sizebyte_len] = '\0';
+ break;
+ case PM_STRING16:
+ extract_size.c[0] = buf[5];
+ extract_size.c[1] = buf[6];
+ size = extract_size.s[0];
+ break;
+ case PM_STRING32:
+ extract_size.c[0] = buf[5];
+ extract_size.c[1] = buf[6];
+ extract_size.c[2] = buf[7];
+ extract_size.c[3] = buf[8];
+ size = extract_size.i[0];
+ break;
+ default:
+ size = 0;
+ perror("undefined size from socket");
+ break;
+ }
+ }
+ return size;
+}
+
+size_t extract_cypher_string(char buf[], char **dest) {
+
+ uint8 marker_byte = buf[4];
+ uint8 size_byte = buf[5];
+ unsigned short *short_size;
+ size_t size;
+
+ if (PM_TINY_STRING == (marker_byte & NIBBLE_HIGH)) {
+ size = marker_byte & NIBBLE_LOW;
+ } else {
+ switch (marker_byte) {
+ case PM_STRING8:
+ size = size_byte;
+ break;
+ case PM_STRING16:
+ short_size = memcpy(short_size, &buf[5], 2);
+ size = *short_size;
+ break;
+ default:
+ size = 0;
+ perror("undefined size from socket");
+ break;
+ }
+ }
+ *dest = (char *) malloc(size);
+ memcpy(*dest, &buf[6], size);
+ return size;
+}
+
+
+char *bolt_chunk_to_byte_array(BOLT_CHUNK *cnk) {
+
+ size_t header = ntohs(cnk->header);
+ char *byte_array = malloc(sizeof(cnk->header) + header + sizeof(cnk->ender));
+ memcpy(&byte_array[0], &cnk->header, BOLT_CHUNK_HEADER_SIZE);
+ memcpy(&byte_array[2], cnk->body, header);
+ memcpy(&byte_array[2 + header], &cnk->ender, BOLT_CHUNK_HEADER_SIZE);
+ return byte_array;
+}
+
+size_t extract_cnk_from_pgresult(const PGresult *r, char **dest_bytearray) {
+
+ assert(r);
+
+ ExecStatusType pg_exec_status = PQresultStatus(r);
+
+ int tuple_count;
+ int field_count;
+ char *tuple_value;
+ size_t tuple_value_len;
+
+ char *pack_concat = NULL;
+ size_t pack_concat_len = 0;
+
+ char *cat = NULL;
+ size_t cat_size = 0;
+ size_t bytearray_size = 0;
+ char *bytearray_record = NULL;
+
+ BOLT_CHUNK **record_all;
+ while (1) {
+ switch (pg_exec_status) {
+ case PGRES_COMMAND_OK:
+ case PGRES_TUPLES_OK:
+ tuple_count = PQntuples(r);
+ field_count = PQnfields(r);
+ record_all = malloc(sizeof(BOLT_CHUNK *) * tuple_count);
+ break;
+ case PGRES_EMPTY_QUERY:
+ case PGRES_COPY_OUT:
+ case PGRES_COPY_IN:
+ case PGRES_BAD_RESPONSE:
+ case PGRES_NONFATAL_ERROR:
+ case PGRES_FATAL_ERROR:
+ case PGRES_COPY_BOTH:
+ case PGRES_SINGLE_TUPLE:
+ case PGRES_PIPELINE_SYNC:
+ case PGRES_PIPELINE_ABORTED:
+ pg_exec_status = PQresultStatus(r);
+ printf("pg_exec_status : %d\n", pg_exec_status);
+ perror("pg_exec failed. exit.\n");
+ exit(1);
+ }
+ break;
+ }
+
+ size_t bolt_chunk_size = 0;
+ Oid field_oid;
+ int nid = 0;
+ struct node_info ni;
+
+ for (int i = 0; i < tuple_count; ++i) {
+ pack_concat = NULL;
+ pack_concat_len = 0;
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_tiny_struct_marker(1));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_bolt_signature(BS_RECORD));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_tiny_list_marker(1));
+
+ for (int j = 0; j < field_count; ++j) {
+ tuple_value = PQgetvalue(r, i, j);
+ tuple_value_len = strlen(tuple_value);
+ field_oid = PQftype(r, j);
+
+ switch (field_oid) {
+ case VERTEXOID:
+ fprintf(stdout, "VERTEXOID\n");
+
+ //node structure
+ ni = node_string_to_structure(tuple_value);
+ printf("label:%s\nnid:%d\nprop:%s\n\n\n", ni.label, ni.nid, ni.properties);
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_tiny_struct_marker(3));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_bolt_tag(BT_NODE));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_int16((int16) ni.nid));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_tiny_list_marker(1));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_string8(ni.label));
+
+ //property parse(temporal)
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_tiny_dict_marker(1));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_tiny_string("test_key"));
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_tiny_string("test_val"));
+ break;
+ case GRAPHIDARRAYOID :
+ fprintf(stdout, "GRAPHIDARRAYOID\n");
+ break;
+ case GRAPHIDOID:
+ fprintf(stdout, "GRAPHIDOID\n");
+ break;
+ case VERTEXARRAYOID :
+ fprintf(stdout, "VERTEXARRAYOID\n");
+ break;
+ case EDGEARRAYOID :
+ fprintf(stdout, "EDGEARRAYOID\n");
+ break;
+ case EDGEOID :
+ fprintf(stdout, "EDGEOID\n");
+ break;
+ case GRAPHPATHARRAYOID :
+ fprintf(stdout, "GRAPHPATHARRAYOID\n");
+ break;
+ case GRAPHPATHOID:
+ fprintf(stdout, "GRAPHPATHOID\n");
+ break;
+ case ROWIDARRAYOID :
+ fprintf(stdout, "ROWIDARRAYOID\n");
+ break;
+ case ROWIDOID :
+ fprintf(stdout, "ROWIDOID\n");
+ break;
+ default:
+ fprintf(stdout, "field_oid :::: %d\n", field_oid);
+ if (tuple_value_len > 15) {
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_string8(tuple_value));
+ } else {
+ pack_concat_len += pack_appender(pack_concat_len, &pack_concat, write_tiny_string(tuple_value));
+ }
+ break;
+ }
+ }
+
+ record_all[i] = malloc(sizeof(BOLT_CHUNK));
+ record_all[i]->header = pack_concat_len;
+ record_all[i]->header = htons(record_all[i]->header);
+ record_all[i]->body = malloc(pack_concat_len);
+ memcpy(record_all[i]->body, pack_concat, pack_concat_len);
+ record_all[i]->ender = 0x0000;
+
+ bytearray_record = bolt_chunk_to_byte_array(record_all[i]);
+ bytearray_size = (pack_concat_len + BOLT_CHUNK_HEADER_SIZE + BOLT_CHUNK_ENDHEADER_SIZE);
+
+ concaternating_byte_array(&cat, cat_size, bytearray_record, bytearray_size);
+ cat_size += bytearray_size;
+ }
+
+ *dest_bytearray = cat;
+ return cat_size;
+}
+
+
+/**
+ * for example, libpq pg_exec output is such formed char*. <br>
+ * movie[13.1]{"title": "The Matrix", "tagline": "Welcome to the Real World", "released": 1999} <br>
+ * movie as label name. <br>
+ * 13.1 as node id. <br>
+ * { ... } as properties. <br>
+ * @param libpq_node_str_arr
+ */
+struct node_info node_string_to_structure(char libpq_node_str_arr[]) {
+ char *str1;
+ char *token;
+ char *saveptr1;
+ const char *delim = "[]";
+ struct node_info ni;
+
+
+ str1 = libpq_node_str_arr;
+ for (int j = 1;; j++, str1 = NULL) {
+ token = strtok_r(str1, delim, &saveptr1);
+ switch (j) {
+ case 1:
+ ni.label = token;
+ break;
+ case 2:
+ (*strrchr(token, '.')) = '0';
+ ni.nid = atoi(token);
+ break;
+ case 3:
+ ni.properties = token;
+ break;
+ }
+ if (token == NULL)
+ break;
+ }
+ return ni;
+}
\ No newline at end of file
diff --git a/src/spec/bolt/message/v440/summary/failed.c b/src/spec/bolt/message/v440/summary/failed.c
new file mode 100644
index 00000000..32eccb76
--- /dev/null
+++ b/src/spec/bolt/message/v440/summary/failed.c
@@ -0,0 +1,43 @@
+/*
+ * failed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/bolt/message/v440/failed.c
+ */
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/message/v440/message.h"
+#include "spec/bolt/message/v440/chunk.h"
+#include "spec/bolt/message/v440/signature.h"
+#include "spec/bolt/message/v440/tag.h"
+
+
+#include "spec/packstream/v100/packstream_v100.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/pack_utils.h"
+#include "utils/utils.h"
+
+#include "communication/socket_manager.h"
+#include "stubs/stubs.h"
+#include "spec/bolt/message/v440/tag.h"
+
+#include "libwebsockets.h"
diff --git a/src/spec/bolt/message/v440/summary/ignored.c b/src/spec/bolt/message/v440/summary/ignored.c
new file mode 100644
index 00000000..52bf2ce0
--- /dev/null
+++ b/src/spec/bolt/message/v440/summary/ignored.c
@@ -0,0 +1,43 @@
+/*
+ * ignored.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/bolt/message/v440/ignored.c
+ */
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/message/v440/message.h"
+#include "spec/bolt/message/v440/chunk.h"
+#include "spec/bolt/message/v440/signature.h"
+#include "spec/bolt/message/v440/tag.h"
+
+
+#include "spec/packstream/v100/packstream_v100.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/pack_utils.h"
+#include "utils/utils.h"
+
+#include "communication/socket_manager.h"
+#include "stubs/stubs.h"
+#include "spec/bolt/message/v440/tag.h"
+
+#include "libwebsockets.h"
\ No newline at end of file
diff --git a/src/spec/bolt/message/v440/summary/success.c b/src/spec/bolt/message/v440/summary/success.c
new file mode 100644
index 00000000..b7a673b6
--- /dev/null
+++ b/src/spec/bolt/message/v440/summary/success.c
@@ -0,0 +1,255 @@
+/*
+ * success.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/bolt/message/v440/success.c
+ */
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/bolt/message/v440/message.h"
+#include "spec/bolt/message/v440/chunk.h"
+#include "spec/bolt/message/v440/signature.h"
+#include "spec/bolt/message/v440/tag.h"
+
+
+#include "spec/packstream/v100/packstream_v100.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/pack_utils.h"
+#include "utils/utils.h"
+
+#include "communication/socket_manager.h"
+#include "stubs/stubs.h"
+#include "spec/bolt/message/v440/tag.h"
+
+#include "libwebsockets.h"
+
+
+BOLT_CHUNK bolt_pull_success(char recv[], int len) {
+ BOLT_CHUNK cnk;
+
+ size_t c = 0; //count
+ char *b = NULL;
+
+
+ // bookmark is only for the implicit transaction situation.
+
+ c += pack_appender(c, &b, write_tiny_struct_marker(1));
+ c += pack_appender(c, &b, write_bolt_signature(BS_SUCCESS));
+// c += pack_appender(c, &b, write_tiny_dict_marker(4));
+// c += pack_appender(c, &b, write_tiny_string("bookmark"));
+// c += pack_appender(c, &b, write_tiny_string("b"));
+
+ c += pack_appender(c, &b, write_tiny_dict_marker(3));
+ c += pack_appender(c, &b, write_tiny_string("type"));
+ c += pack_appender(c, &b, write_tiny_string("r"));
+ c += pack_appender(c, &b, write_tiny_string("db"));
+ c += pack_appender(c, &b, write_tiny_string("neo4j"));
+ c += pack_appender(c, &b, write_tiny_string("t_last"));
+ c += pack_appender(c, &b, write_tiny_int(1));
+
+ cnk.header = htons((unsigned short) (c));
+ cnk.body = b;
+ cnk.ender = (unsigned short) 0x0000;
+ return cnk;
+}
+
+BOLT_CHUNK bolt_route_success(char recv[], int len) {
+ BOLT_CHUNK cnk;
+
+ size_t c = 0; //count
+ char *b = NULL;
+
+ char temp[3] = {0xc9, 0x01, 0x2c};
+
+ c += pack_appender(c, &b, write_tiny_struct_marker(1));
+ c += pack_appender(c, &b, write_bolt_signature(BS_SUCCESS));
+ c += pack_appender(c, &b, write_tiny_dict_marker(1));
+ c += pack_appender(c, &b, write_tiny_string("rt"));
+ c += pack_appender(c, &b, write_tiny_dict_marker(3));
+ c += pack_appender(c, &b, write_tiny_string("servers"));
+ c += pack_appender(c, &b, write_tiny_list_marker(3));
+ c += pack_appender(c, &b, write_tiny_dict_marker(2));
+ c += pack_appender(c, &b, write_tiny_string("addresses"));
+ c += pack_appender(c, &b, write_tiny_list_marker(1));
+ c += pack_appender(c, &b, write_tiny_string("localhost:7681"));
+ c += pack_appender(c, &b, write_tiny_string("role"));
+ c += pack_appender(c, &b, write_tiny_string("WRITE"));
+
+
+ c += pack_appender(c, &b, write_tiny_dict_marker(2));
+ c += pack_appender(c, &b, write_tiny_string("addresses"));
+ c += pack_appender(c, &b, write_tiny_list_marker(1));
+ c += pack_appender(c, &b, write_tiny_string("localhost:7681"));
+ c += pack_appender(c, &b, write_tiny_string("role"));
+ c += pack_appender(c, &b, write_tiny_string("READ"));
+ c += pack_appender(c, &b, write_tiny_dict_marker(2));
+ c += pack_appender(c, &b, write_tiny_string("addresses"));
+
+ c += pack_appender(c, &b, write_tiny_list_marker(1));
+ c += pack_appender(c, &b, write_tiny_string("localhost:7681"));
+ c += pack_appender(c, &b, write_tiny_string("role"));
+ c += pack_appender(c, &b, write_tiny_string("ROUTE"));
+ c += pack_appender(c, &b, write_tiny_string("ttl"));
+// c += pack_appender(c, &b, write_int16(300));
+
+ c += pack_appender(c, &b, write_tiny_int(14));
+
+ c += pack_appender(c, &b, write_tiny_string("db"));
+ c += pack_appender(c, &b, write_tiny_string("neo4j"));
+
+
+ cnk.header = htons((unsigned short) (c));
+ cnk.body = b;
+ cnk.ender = (unsigned short) 0x0000;
+
+ return cnk;
+
+}
+
+
+BOLT_CHUNK bolt_run_success(char **field_str, int field_count) {
+
+ BOLT_CHUNK cnk;
+
+ size_t c = 0;
+ char *b = NULL;
+
+ char **field_str_backup = malloc(sizeof(char *) * field_count);
+ memcpy(field_str_backup, field_str, sizeof(char *) * field_count);
+
+ c += pack_appender(c, &b, write_tiny_struct_marker(1));
+ c += pack_appender(c, &b, write_bolt_signature(BS_SUCCESS));
+ c += pack_appender(c, &b, write_tiny_dict_marker(2));
+ c += pack_appender(c, &b, write_tiny_string("fields"));
+ c += pack_appender(c, &b, write_tiny_list_marker(field_count));
+
+ for (int i = 0; i < field_count; ++i) {
+ c += pack_appender(c, &b, write_tiny_string(field_str_backup[i]));
+ }
+
+ c += pack_appender(c, &b, write_tiny_string("t_first"));
+ c += pack_appender(c, &b, write_tiny_int(2));
+ c += pack_appender(c, &b, write_tiny_string("qid"));
+ c += pack_appender(c, &b, write_tiny_int(4));
+
+ cnk.header = htons((unsigned short) (c));
+ cnk.body = b;
+ cnk.ender = (unsigned short) 0x0000;
+
+ free(field_str_backup);
+ return cnk;
+}
+
+
+BOLT_CHUNK bolt_commit_success() {
+ BOLT_CHUNK cnk;
+
+ size_t c = 0; //count
+ char *b = NULL;
+
+ c += pack_appender(c, &b, write_tiny_struct_marker(1));
+ c += pack_appender(c, &b, write_bolt_signature(BS_SUCCESS));
+ c += pack_appender(c, &b, write_tiny_dict_marker(0));
+
+ cnk.header = htons((unsigned short) (c));
+ cnk.body = b;
+ cnk.ender = (unsigned short) 0x0000;
+ return cnk;
+}
+
+
+BOLT_CHUNK bolt_hello_success(char recv[], int len) {
+ BOLT_CHUNK cnk;
+
+ size_t c = 0; //count
+ char *b = NULL;
+
+ c += pack_appender(c, &b, write_tiny_struct_marker(1));
+ c += pack_appender(c, &b, write_bolt_signature(BS_SUCCESS));
+ c += pack_appender(c, &b, write_tiny_dict_marker(4));
+ c += pack_appender(c, &b, write_tiny_string("server"));
+ c += pack_appender(c, &b, write_tiny_string("agbolt_4.4.2"));
+ c += pack_appender(c, &b, write_tiny_string("connection_id"));
+ c += pack_appender(c, &b, write_tiny_string("bolt-1"));
+
+ c += pack_appender(c, &b, write_tiny_string("hints"));
+ c += pack_appender(c, &b, write_tiny_dict_marker(0));
+
+ c += pack_appender(c, &b, write_tiny_string("patch_bolt"));
+ c += pack_appender(c, &b, write_tiny_list_marker(1));
+ c += pack_appender(c, &b, write_tiny_string("utc"));
+
+ cnk.header = htons((unsigned short) (c));
+ cnk.body = b;
+ cnk.ender = (unsigned short) 0x0000;
+
+ return cnk;
+}
+
+
+BOLT_CHUNK bolt_run_dbping_success(char recv[], int len) {
+
+ BOLT_CHUNK cnk;
+
+ size_t c = 0; //count
+ char *b = NULL;
+
+ c += pack_appender(c, &b, write_tiny_struct_marker(1));
+ c += pack_appender(c, &b, write_bolt_signature(BS_SUCCESS));
+ c += pack_appender(c, &b, write_tiny_dict_marker(2));
+ c += pack_appender(c, &b, write_tiny_string("t_first"));
+ c += pack_appender(c, &b, write_tiny_string("fields"));
+ c += pack_appender(c, &b, write_tiny_list_marker(1));
+ c += pack_appender(c, &b, write_tiny_string("success"));
+
+ cnk.header = htons((unsigned short) (c));
+ cnk.body = b;
+ cnk.ender = (unsigned short) 0x0000;
+
+ return cnk;
+
+}
+
+
+BOLT_CHUNK bolt_run_dbping_bookmark_success(char recv[], int len) {
+ BOLT_CHUNK cnk;
+
+ size_t c = 0; //count
+ char *b = NULL;
+
+ c += pack_appender(c, &b, write_tiny_struct_marker(1));
+ c += pack_appender(c, &b, write_bolt_signature(BS_SUCCESS));
+ c += pack_appender(c, &b, write_tiny_dict_marker(4));
+ c += pack_appender(c, &b, write_tiny_string("bookmark"));
+ c += pack_appender(c, &b, write_tiny_string("b"));
+ c += pack_appender(c, &b, write_tiny_string("type"));
+ c += pack_appender(c, &b, write_tiny_string("r"));
+ c += pack_appender(c, &b, write_tiny_string("t_last"));
+ c += pack_appender(c, &b, write_tiny_int(1));
+ c += pack_appender(c, &b, write_tiny_string("db"));
+ c += pack_appender(c, &b, write_tiny_string("neo4j"));
+ cnk.header = htons((unsigned short) (c));
+ cnk.body = b;
+ cnk.ender = (unsigned short) 0x0000;
+ return cnk;
+}
+
diff --git a/src/spec/bolt/server_state/v440/server_state.c b/src/spec/bolt/server_state/v440/server_state.c
new file mode 100644
index 00000000..487def31
--- /dev/null
+++ b/src/spec/bolt/server_state/v440/server_state.c
@@ -0,0 +1,24 @@
+/*
+ * server_state_4_4_0.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/server_state/server_state_4_4_0.c
+ */
+
diff --git a/src/spec/bolt/structures/bolt_node.c b/src/spec/bolt/structures/bolt_node.c
new file mode 100644
index 00000000..b5eb7258
--- /dev/null
+++ b/src/spec/bolt/structures/bolt_node.c
@@ -0,0 +1,46 @@
+/*
+ * bolt_node.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/bolt/structure/bolt_node.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/v100/packstream_v100.h"
+#include "spec/packstream/pack_utils.h"
+#include <libpq-fe.h>
+
+// id::Integer -> graphid
+// labels::List<String>,
+// properties::Dictionary,
+// element_id::String
+char *write_node(int id) {
+
+ char *result;
+
+ result = malloc(PACK_MARKER_LENGTH);
+
+ return result;
+
+}
+
+
diff --git a/src/spec/packstream/pack_utils.c b/src/spec/packstream/pack_utils.c
new file mode 100644
index 00000000..dad47472
--- /dev/null
+++ b/src/spec/packstream/pack_utils.c
@@ -0,0 +1,239 @@
+/*
+ * pack_utils.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/packstream/pack_utils.c
+ */
+
+#include "graph_protocol_stddef.h"
+
+#include "spec/packstream/v100/packstream_v100.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/pack_utils.h"
+#include "utils/utils.h"
+
+
+#include "spec/bolt/message/v440/signature.h"
+#include "spec/bolt/message/message_utils.h"
+
+int pack_appender(size_t dest_size, char **dest, char *pack) {
+
+ size_t cat_len;
+ int pack_len;
+ pack_len = extract_pack_length(pack);
+ cat_len = dest_size + pack_len;
+ cat_len = concaternating_byte_array(dest, dest_size, pack, pack_len);
+
+ free(pack);
+
+ return pack_len;
+}
+
+
+bool is_marker_data_itself(uint8 c) {
+ switch (c & NIBBLE_HIGH) {
+ case PM_TINY_INT:
+ return true;
+ }
+ return false;
+}
+
+bool is_marker_with_sizebyte(uint8 c) {
+ switch (c) {
+ case PM_STRING8:
+ case PM_STRING16:
+ case PM_INT8:
+ case PM_INT16:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool is_tiny_container_marker(uint8 c) {
+ switch (c) {
+ case BS_RECORD:
+ case BS_SUCCESS:
+ case BS_PULL:
+ return true;
+ default:
+ break;
+ }
+
+ switch (c & NIBBLE_HIGH) {
+ case PM_TINY_LIST:
+ case PM_TINY_DICT:
+ case PM_TINY_STRUCT:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
+bool is_tiny_marker(uint8 c) {
+ switch (c) {
+ case PM_NULL:
+ case PM_FALSE:
+ case PM_TRUE:
+ return true;
+ default:
+ switch (c & NIBBLE_HIGH) {
+ case PM_TINY_INT:
+ case PM_TINY_STRING:
+ return true;
+ default:
+ return false;
+ }
+ }
+}
+
+bool is_container_marker(uint8 c) {
+ switch (c) {
+ case PM_LIST8:
+ case PM_LIST16:
+ case PM_LIST32:
+ case PM_DICT8:
+ case PM_DICT16:
+ case PM_DICT32:
+ return true;
+ default:
+ return false;
+ }
+}
+
+
+int extract_size_byte_from_marker(uint8 c) {
+ int size_byte_length = 0;
+ switch (c) {
+ case PM_INT8:
+ case PM_BYTES8:
+ case PM_STRING8:
+ case PM_LIST8:
+ case PM_DICT8:
+ size_byte_length = 1;
+ break;
+ case PM_INT16:
+ case PM_BYTES16:
+ case PM_STRING16:
+ case PM_LIST16:
+ case PM_DICT16:
+ size_byte_length = 2;
+ break;
+ case PM_INT32:
+ case PM_BYTES32:
+ case PM_STRING32:
+ case PM_LIST32:
+ case PM_DICT32:
+ size_byte_length = 4;
+ break;
+ case PM_INT64:
+ case PM_FLOAT64:
+ size_byte_length = 8;
+ break;
+ default:
+ return 0;
+ }
+
+ return size_byte_length;
+}
+
+int extract_pack_length(const char pack[]) {
+
+ int pack_len = 0;
+
+ uint8 first_byte = pack[0]; // pack_type
+ uint8 second_byte = pack[1]; // if not a tiny type, pack_sizetype
+
+ union size_cal {
+ uint8 c[8];
+ uint16 s[4];
+ uint32 i[2];
+ uint64 l;
+ } pack_contents_size;
+ memset(&pack_contents_size, 0, sizeof(pack_contents_size));
+
+ size_t total_pack_len;
+ int size_byte_length = extract_size_byte_from_marker(first_byte);
+ printf("size_byte_length=%d", size_byte_length);
+
+ switch (first_byte) {
+ case PM_INT16:
+ return 3;
+ }
+
+// switch (size_byte_length) {
+// case 1:
+// pack_contents_size.c[0] = pack[2];
+// total_pack_len = PACK_MARKER_LENGTH + size_byte_length + pack_contents_size.c[0];
+// printf("total_pack_len:%ld", total_pack_len);
+// return total_pack_len;
+// case 2:
+// pack_contents_size.c[0] = pack[2];
+// pack_contents_size.c[1] = pack[3];
+// total_pack_len = PACK_MARKER_LENGTH + size_byte_length + ntohs(pack_contents_size.s[0]);
+// printf("total_pack_len:%ld", total_pack_len);
+// return total_pack_len;
+// case 4:
+// pack_contents_size.c[0] = pack[2];
+// pack_contents_size.c[1] = pack[3];
+// pack_contents_size.c[2] = pack[4];
+// pack_contents_size.c[3] = pack[5];
+// total_pack_len = PACK_MARKER_LENGTH + size_byte_length + ntohl(pack_contents_size.i[0]);
+// printf("total_pack_len:%ld", total_pack_len);
+// return total_pack_len;
+// case 8:
+// pack_contents_size.c[0] = pack[2];
+// pack_contents_size.c[1] = pack[3];
+// pack_contents_size.c[2] = pack[4];
+// pack_contents_size.c[3] = pack[5];
+// pack_contents_size.c[4] = pack[6];
+// pack_contents_size.c[5] = pack[7];
+// pack_contents_size.c[6] = pack[8];
+// pack_contents_size.c[7] = pack[9];
+// total_pack_len = PACK_MARKER_LENGTH + size_byte_length + ntohl(pack_contents_size.l);
+// printf("total_pack_len:%ld", total_pack_len);
+// return total_pack_len;
+// default:
+// break;
+// }
+
+
+ if (is_marker_data_itself(first_byte)
+ || is_tiny_container_marker(first_byte)) {
+ pack_len = PACK_MARKER_LENGTH;
+ } else if (is_tiny_marker(first_byte)) {
+ pack_len = (NIBBLE_LOW & first_byte) + PACK_MARKER_LENGTH;
+ } else if (is_bolt_signature(first_byte)) {
+ pack_len = 1;
+ } else if (is_bolt_tag(first_byte)) {
+ pack_len = 1;
+ } else if (is_container_marker(first_byte)) {
+ pack_len = PACK_MARKER_LENGTH + PACK_SIZE_LENGTH;
+ } else if (is_marker_with_sizebyte(first_byte)) {
+ pack_len = PACK_MARKER_LENGTH + PACK_SIZE_LENGTH + second_byte;
+ } else {
+ perror("non of pack_length extracted. pack_len=1 assigned");
+ pack_len = 1;
+ }
+
+ return pack_len;
+}
diff --git a/src/spec/packstream/v100/coretypes/pack_boolean.c b/src/spec/packstream/v100/coretypes/pack_boolean.c
new file mode 100644
index 00000000..611b8256
--- /dev/null
+++ b/src/spec/packstream/v100/coretypes/pack_boolean.c
@@ -0,0 +1,40 @@
+/*
+ * pack_dict.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/packstream/pack_dict.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/pack_utils.h"
+#include "spec/packstream/v100/packstream_v100.h"
+
+char *write_tiny_boolean(bool b) {
+ char *result;
+ result = malloc(PACK_MARKER_LENGTH);
+ if (b == true) {
+ result[0] = (char) (0xC3);
+ } else if (b == false) {
+ result[0] = (char) (0xC2);
+ }
+ return result;
+}
\ No newline at end of file
diff --git a/src/spec/packstream/v100/coretypes/pack_dict.c b/src/spec/packstream/v100/coretypes/pack_dict.c
new file mode 100644
index 00000000..47cd125f
--- /dev/null
+++ b/src/spec/packstream/v100/coretypes/pack_dict.c
@@ -0,0 +1,45 @@
+/*
+ * pack_dict.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/packstream/pack_dict.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/pack_utils.h"
+#include "spec/packstream/v100/packstream_v100.h"
+
+
+char *write_tiny_dict_marker(int element_count) {
+ char *result;
+
+ if (element_count > PM_TINY_DICT_MAX) {
+ perror("parameter value is exceed range of tiny_list");
+ return NULL;
+ }
+
+ result = malloc(PACK_MARKER_LENGTH);
+ result[0] = (char) (PM_TINY_DICT | (NIBBLE_LOW & element_count));
+
+ return result;
+}
+
diff --git a/src/spec/packstream/v100/coretypes/pack_integer.c b/src/spec/packstream/v100/coretypes/pack_integer.c
new file mode 100644
index 00000000..a808db23
--- /dev/null
+++ b/src/spec/packstream/v100/coretypes/pack_integer.c
@@ -0,0 +1,88 @@
+/*
+ * pack_integer.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/packstream/pack_integer.c
+ */
+
+
+#include "graph_protocol_stddef.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/pack_utils.h"
+#include "spec/packstream/v100/packstream_v100.h"
+
+
+char *write_tiny_int(int integer) {
+ char *result;
+
+ result = malloc(PACK_MARKER_LENGTH);
+
+ if (integer > PM_TINY_INT_MAX) {
+ perror("parameter value is exceed range of tinyint");
+ return NULL;
+ } else if (integer < PM_TINY_INT_MIN) {
+ perror("parameter value is under the range of tinyint");
+ return NULL;
+ }
+
+ if (integer == 0) {
+ result[0] = 0x00;
+ } else if (integer < 0) {
+ perror("skip impl");
+ } else {
+ result[0] = (char) (PM_TINY_INT | (integer & NIBBLE_LOW));
+ }
+ return result;
+}
+
+char *write_int8(int8 i) {
+ char *result;
+ result = malloc(PACK_MARKER_LENGTH + 1);
+
+ union seperate {
+ int8 c[2];
+ int16 s;
+ } a;
+ a.s = htons(i);
+
+ result[0] = (char) (PM_INT16);
+ result[1] = a.c[0];
+ result[2] = a.c[1];
+
+ return result;
+}
+
+char *write_int16(int16 i) {
+ char *result;
+ result = malloc(PACK_MARKER_LENGTH + 2);
+
+ union seperate {
+ int8 c[2];
+ int16 s;
+ } a;
+ a.s = htons(i);
+
+ result[0] = (char) (PM_INT16);
+ result[1] = a.c[0];
+ result[2] = a.c[1];
+
+ return result;
+}
diff --git a/src/spec/packstream/v100/coretypes/pack_list.c b/src/spec/packstream/v100/coretypes/pack_list.c
new file mode 100644
index 00000000..b26962de
--- /dev/null
+++ b/src/spec/packstream/v100/coretypes/pack_list.c
@@ -0,0 +1,63 @@
+/*
+ * pack_dict.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/packstream/pack_dict.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/pack_utils.h"
+#include "spec/packstream/v100/packstream_v100.h"
+
+
+char *write_tiny_list_marker(int element_count) {
+ char *result;
+
+ if (element_count > PM_TINY_LIST_MAX) {
+ perror("parameter value is exceed range of tiny_list");
+ return NULL;
+ }
+
+ result = malloc(PACK_MARKER_LENGTH);
+
+ char size;
+ size = NIBBLE_LOW & element_count;
+
+ result[0] = (char) (PM_TINY_LIST | (NIBBLE_LOW & element_count));
+
+ return result;
+}
+
+char *write_list8_marker(int element_count) {
+ char *result;
+
+ if (element_count > PM_TINY_LIST8_MAX) {
+ perror("parameter value is exceed range of list8");
+ return NULL;
+ }
+
+ result = malloc(PACK_MARKER_LENGTH + PACK_SIZE_LENGTH);
+
+ result[0] = PM_LIST8;
+ result[1] = element_count;
+ return result;
+}
\ No newline at end of file
diff --git a/src/spec/packstream/v100/coretypes/pack_string.c b/src/spec/packstream/v100/coretypes/pack_string.c
new file mode 100644
index 00000000..bbb883e0
--- /dev/null
+++ b/src/spec/packstream/v100/coretypes/pack_string.c
@@ -0,0 +1,92 @@
+/*
+ * pack_string.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/packstream/pack_string.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/pack_utils.h"
+#include "spec/packstream/v100/packstream_v100.h"
+
+char *write_tiny_string(char str[]) {
+
+ uint8 marker = (uint8) PM_TINY_STRING;
+ char *result;
+ uint8 str_len = strlen(str);
+
+ if (str_len > PM_TINY_STRING_MAX) {
+ perror("parameter string is exceed number of tiny_string");
+ return NULL;
+ }
+
+ result = malloc(PACK_MARKER_LENGTH + str_len);
+ result[0] = (char) (marker + str_len);
+
+ for (int i = 0; i < str_len; ++i) {
+ result[1 + i] = str[i];
+ }
+
+ return result;
+}
+
+char *write_string8(char str[]) {
+ uint8 marker = (uint8) PM_STRING8;
+
+ char *result;
+ uint8 str_len = strlen(str);
+
+ if (str_len > PM_STRING8_MAX) {
+ perror("parameter string is exceed number of string8");
+ exit(1);
+ }
+
+ result = malloc(PACK_MARKER_LENGTH + STRING8_SIZE + str_len);
+ result[0] = (char) (marker);
+ result[1] = (char) str_len;
+
+ memcpy(result + 2, str, str_len); // except null-terminated
+
+ for (int i = 0; i < str_len; ++i) {
+ result[i + 2] = str[i];
+ }
+
+ return result;
+}
+
+char *write_string16(char str[]) {
+ char marker = (char) PM_STRING8;
+ char *result;
+ int str_len = strlen(str);
+
+ if (str_len > PM_STRING16_MAX) {
+ perror("parameter string is exceed number of string16");
+ return NULL;
+ }
+
+ result = malloc(PACK_MARKER_LENGTH + str_len);
+ result[0] = marker | str_len;
+ for (int i = 0; i < str_len; ++i) {
+ result[i + 1] = str[i];
+ }
+ return result;
+}
diff --git a/src/spec/packstream/v100/coretypes/pack_structure.c b/src/spec/packstream/v100/coretypes/pack_structure.c
new file mode 100644
index 00000000..b729b123
--- /dev/null
+++ b/src/spec/packstream/v100/coretypes/pack_structure.c
@@ -0,0 +1,42 @@
+/*
+ * pack_structure.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/spec/packstream/pack_structure.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "spec/packstream/v100/marker.h"
+#include "spec/packstream/v100/coretypes.h"
+#include "spec/packstream/pack_utils.h"
+#include "spec/packstream/v100/packstream_v100.h"
+
+
+char *write_tiny_struct_marker(size_t element_count) {
+ char *result;
+
+ if (element_count > PM_TINY_STRUCT_MAX) {
+ perror("parameter value is exceed range of tiny_struct");
+ return NULL;
+ }
+ result = malloc(PACK_MARKER_LENGTH);
+ result[0] = (char) (PM_TINY_STRUCT | (NIBBLE_LOW & element_count));
+ return result;
+}
\ No newline at end of file
diff --git a/src/stubs/stubs.c b/src/stubs/stubs.c
new file mode 100644
index 00000000..0976807f
--- /dev/null
+++ b/src/stubs/stubs.c
@@ -0,0 +1,134 @@
+/*
+ * stubs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/stubs/stubs.c
+ */
+
+#include "graph_protocol_stddef.h"
+#include "stubs/stubs.h"
+
+static uint8 stubs_success_with_empty[] = {0x00, 0x03, 0xb1, 0x70, 0xa0, 0x00, 0x00};
+
+
+static uint8 stubs_bookmark_success[] = {0x00, 0x2d, 0xb1, 0x70,
+ 0xa1, 0x88, 0x62, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, 0x72, 0x6b, 0xd0, 0x1f, 0x46,
+ 0x42, 0x3a, 0x6b, 0x63, 0x77, 0x51, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
+ 0x41,
+ 0x41,
+ 0x41, 0x41,
+ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x53, 0x57, 0x51,
+ 0x00,
+ 0x00};
+
+static uint8 stubs_commit_success[] = {0x00, 0x0E, 0xb1, 0x70,
+ 0xa1,
+ 0x88, 0x62, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, 0x72, 0x6b,
+ 0x81, 0x62,
+ 0x00, 0x00};
+
+static uint8 stubs_show_databases_success[] = {
+ 0x00, 0x03, 0xb1, 0x70, 0xa0, 0x00, 0x00,
+
+ 0x00, 0x6d, 0xb1, 0x70, 0xa3, 0x87, 0x74,
+ 0x5f, 0x66, 0x69, 0x72, 0x73, 0x74, 0xc9, 0x04, 0x2d, 0x86, 0x66, 0x69, 0x65, 0x6c,
+ 0x64, 0x73, 0x9a, 0x84, 0x6e, 0x61, 0x6d, 0x65, 0x87, 0x61, 0x6c, 0x69, 0x61, 0x73,
+ 0x65, 0x73, 0x86, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x87, 0x61, 0x64, 0x64, 0x72,
+ 0x65, 0x73, 0x73, 0x84, 0x72, 0x6f, 0x6c, 0x65, 0x8f, 0x72, 0x65, 0x71, 0x75, 0x65,
+ 0x73, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x8d, 0x63, 0x75, 0x72,
+ 0x72, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x85, 0x65, 0x72, 0x72,
+ 0x6f, 0x72, 0x87, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x84, 0x68, 0x6f, 0x6d,
+ 0x65, 0x83, 0x71, 0x69, 0x64, 0x00,
+
+ 0x00, 0x00,
+
+ 0x00, 0x40, 0xb1, 0x71, 0x9a, 0x85,
+ 0x6e, 0x65, 0x6f, 0x34, 0x6a, 0x90, 0x8a, 0x72, 0x65, 0x61, 0x64, 0x2d, 0x77, 0x72,
+ 0x69, 0x74, 0x65, 0x8e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a,
+ 0x37, 0x36, 0x38, 0x31, 0x8a, 0x73, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x6c, 0x6f, 0x6e,
+ 0x65, 0x86, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x86, 0x6f, 0x6e, 0x6c, 0x69, 0x6e,
+ 0x65, 0x80, 0xc3, 0xc3, 0x00, 0x00,
+
+ 0x00, 0x41, 0xb1, 0x71, 0x9a, 0x86, 0x73, 0x79,
+ 0x73, 0x74, 0x65, 0x6d, 0x90, 0x8a, 0x72, 0x65, 0x61, 0x64, 0x2d, 0x77, 0x72, 0x69,
+ 0x74, 0x65, 0x8e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x37,
+ 0x36, 0x38, 0x31, 0x8a, 0x73, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x6c, 0x6f, 0x6e, 0x65,
+ 0x86, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x86, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65,
+ 0x80, 0xc2, 0xc2, 0x00, 0x00,
+
+ 0x00, 0x1c, 0xb1, 0x70, 0xa3, 0x84, 0x74, 0x79, 0x70,
+ 0x65, 0x81, 0x73, 0x86, 0x74, 0x5f, 0x6c, 0x61, 0x73, 0x74, 0x49, 0x82, 0x64, 0x62,
+ 0x86, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00};
+
+static uint8 stubs_CALL_dbms_components_success[] = {0x00, 0x2f, 0xb1, 0x70, 0xa3, 0x87, 0x74, 0x5f, 0x66, 0x69,
+ 0x72, 0x73, 0x74, 0x02, 0x86, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73,
+ 0x93, 0x84, 0x6e, 0x61, 0x6d, 0x65,
+ 0x88, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x87, 0x65,
+ 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e,
+ 0x83, 0x71, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x22, 0xb1, 0x71,
+ 0x93, 0x8c, 0x4e, 0x65, 0x6f, 0x34,
+ 0x6a, 0x20, 0x4b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x91, 0x86, 0x34,
+ 0x2e, 0x34, 0x2e, 0x31, 0x35, 0x89,
+ 0x63, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x74, 0x79, 0x00, 0x00,
+ 0x00, 0x1c, 0xb1, 0x70, 0xa3, 0x84,
+ 0x74, 0x79, 0x70, 0x65, 0x81, 0x73, 0x86, 0x74, 0x5f, 0x6c, 0x61,
+ 0x73, 0x74, 0x00, 0x82, 0x64, 0x62,
+ 0x86, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00};
+
+static uint8 stubs_CALL_dbms_showCurrentUser_success[] = {0x00, 0x2e, 0xb1, 0x70, 0xa3, 0x87, 0x74, 0x5f, 0x66, 0x69,
+ 0x72, 0x73, 0x74, 0x02, 0x86, 0x66, 0x69, 0x65, 0x6c, 0x64,
+ 0x73, 0x93, 0x88, 0x75, 0x73, 0x65, 0x72,
+ 0x6e, 0x61, 0x6d, 0x65, 0x85, 0x72, 0x6f, 0x6c, 0x65, 0x73,
+ 0x85, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x83,
+ 0x71, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x0b, 0xb1, 0x71,
+ 0x93, 0x85, 0x6e, 0x65, 0x6f, 0x34, 0x6a,
+ 0xc0, 0x90, 0x00, 0x00, 0x00, 0x1c, 0xb1, 0x70, 0xa3, 0x84,
+ 0x74, 0x79, 0x70, 0x65, 0x81, 0x73, 0x86,
+ 0x74, 0x5f, 0x6c, 0x61, 0x73, 0x74, 0x00, 0x82, 0x64, 0x62,
+ 0x86, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d,
+ 0x00, 0x00};
+static uint8 stubs_CALL_db_labels_yield_label_return_union_etc_success[] = {}; // TODO
+static uint8 stubs_CALL_dbms_procedures_success[] = {}; // TODO
+
+static const size_t STUB_SIZE = 6;
+
+struct STUB STUBS[] = {
+ {SUCCESS, stubs_success_with_empty, sizeof(stubs_success_with_empty) /
+ sizeof(uint8)},
+ {COMMIT, stubs_commit_success, sizeof(stubs_commit_success) / sizeof(uint8)},
+ {SHOW_DATABASES, stubs_show_databases_success, sizeof(stubs_show_databases_success) /
+ sizeof(uint8)},
+ {BOOKMARK, stubs_bookmark_success, sizeof(stubs_bookmark_success) / sizeof(uint8)},
+ {SHOW_CURRENT_USER, stubs_CALL_dbms_showCurrentUser_success, sizeof(stubs_CALL_dbms_showCurrentUser_success) /
+ sizeof(uint8)},
+ {CALL_DBMS_COMPONENTS, stubs_CALL_dbms_components_success, sizeof(stubs_CALL_dbms_components_success) /
+ sizeof(uint8)}
+
+};
+
+struct STUB stub_finder(enum STUB_NAME name) {
+ struct STUB ret;
+ for (int i = 0; i < STUB_SIZE; ++i) {
+ if (STUBS[i].name == name)
+ ret = STUBS[i];
+ }
+ return ret;
+}
+
diff --git a/src/types/dict.c b/src/types/dict.c
new file mode 100644
index 00000000..c9ac0617
--- /dev/null
+++ b/src/types/dict.c
@@ -0,0 +1,23 @@
+/*
+ * dict.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/types/dict.c
+ */
\ No newline at end of file
diff --git a/src/types/list.c b/src/types/list.c
new file mode 100644
index 00000000..5a203416
--- /dev/null
+++ b/src/types/list.c
@@ -0,0 +1,23 @@
+/*
+ * list.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/types/list.c
+ */
\ No newline at end of file
diff --git a/src/utils/config_helper.c b/src/utils/config_helper.c
new file mode 100644
index 00000000..14970f33
--- /dev/null
+++ b/src/utils/config_helper.c
@@ -0,0 +1,109 @@
+
+
+#include "utils/config_helper.h"
+
+extern struct garph_protocol_conf garph_protocol_conf;
+
+bool bool_conf_parser(char *str) {
+ char *token;
+ token = strtok(str, ":");
+ token = strtok(NULL, ":");
+
+ if (strlen(token) == 4)
+ return true;
+ else
+ return false;
+}
+
+int64 long_conf_parser(char *str) {
+ char *token;
+ token = strtok(str, ":");
+ token = strtok(NULL, ":");
+ long l = strtol(token, NULL, 10);
+ return l;
+}
+
+char *str_conf_parser(char *str) {
+ char *token;
+ token = strtok(str, ":");
+ token = strtok(NULL, ":");
+
+ return token;
+}
+
+
+char *str_connstr_parser(char *str) {
+ char *token;
+ token = strtok(str, ":");
+ token = strtok(NULL, ":");
+ return token;
+}
+
+
+void free_configuration(struct garph_protocol_conf s) {
+
+ free(s.socket_dir);
+ free(s.pid_file_name);
+ free(s.conn_string);
+ free(s.graph_path);
+}
+
+
+int32 read_from_conf(char *conf_abs_path) {
+
+ FILE *f;
+ char ch[200];
+ int i = 0;
+
+ char *tofree;
+ f = fopen(conf_abs_path, "r");
+ if (f != NULL) {
+ char *tmp = malloc(300);
+ tofree = tmp;
+
+ while (fgets(ch, sizeof(ch), f) != NULL) {
+ switch (i) {
+ case 0:
+ garph_protocol_conf.log_debug = bool_conf_parser(ch);
+ break;
+ case 1:
+ garph_protocol_conf.bolt_port = long_conf_parser(ch);
+ break;
+ case 2:
+ tmp = str_conf_parser(ch);
+ garph_protocol_conf.socket_dir = malloc(strlen(tmp) + 1);
+ memcpy(garph_protocol_conf.socket_dir, tmp, strlen(tmp) + 1);
+ garph_protocol_conf.socket_dir[strlen(tmp) + 1] = '\0';
+ break;
+ case 3:
+ tmp = str_conf_parser(ch);
+ garph_protocol_conf.pid_file_name = malloc(strlen(tmp) + 1);
+ memcpy(garph_protocol_conf.pid_file_name, tmp, strlen(tmp) + 1);
+ garph_protocol_conf.pid_file_name[strlen(tmp) + 1] = '\0';
+ break;
+ case 4:
+ tmp = str_connstr_parser(ch);
+ garph_protocol_conf.conn_string = malloc(strlen(tmp) + 1);
+ memcpy(garph_protocol_conf.conn_string, tmp, strlen(tmp) + 1);
+ garph_protocol_conf.conn_string[strlen(tmp) + 1] = '\0';
+ break;
+ case 5:
+ tmp = str_conf_parser(ch);
+ garph_protocol_conf.graph_path = malloc(strlen(tmp) + 1);
+ memcpy(garph_protocol_conf.graph_path, tmp, strlen(tmp) + 1);
+ garph_protocol_conf.graph_path[strlen(tmp) + 1] = '\0';
+ break;
+ default:
+ break;
+ }
+ i++;
+ }
+
+ free(tofree);
+ } else {
+ perror("configuration file not exists.");
+ return 1;
+ }
+ fclose(f);
+ return 0;
+}
diff --git a/src/utils/logging.c b/src/utils/logging.c
new file mode 100644
index 00000000..5d287be4
--- /dev/null
+++ b/src/utils/logging.c
@@ -0,0 +1,4 @@
+
+#include "utils/logging.h"
+
+
diff --git a/src/utils/option_helper.c b/src/utils/option_helper.c
new file mode 100644
index 00000000..94684e27
--- /dev/null
+++ b/src/utils/option_helper.c
@@ -0,0 +1,18 @@
+
+#include "utils/option_helper.h"
+
+
+void usage(void) {
+ fprintf(stdout, "%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
+ fprintf(stdout, "\t-h,\t--help Print this help.\n");
+ fprintf(stdout, "\t-f,\t--config Target configuration file, need filepath.\n");
+ fprintf(stdout, "\t-v,\t--version Print version string.\n");
+ fprintf(stdout, "\t-d,\t--debug Operating with debug mode.\n");
+}
+
+void show_version(void) {
+ fprintf(stdout, "%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
+}
+
+
+
diff --git a/src/utils/process.c b/src/utils/process.c
new file mode 100644
index 00000000..d3362c19
--- /dev/null
+++ b/src/utils/process.c
@@ -0,0 +1,47 @@
+/*
+ * process.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * IDENTIFICATION
+ * src/utils/process.c
+ */
+
+#include "utils/process.h"
+
+pid_t fork_bolt_connection(const int *server_sock, const int *client_sock) {
+ pid_t pid;
+ pid = fork();
+
+ if (pid == -1) {
+ perror("fork failed");
+ close(*client_sock);
+ close(*server_sock);
+ exit(1);
+ }
+
+ if (pid == 0) {
+ puts("child");
+ close(*server_sock);
+ } else {
+ puts("server");
+ close(*client_sock);
+ }
+ return pid;
+}
+
diff --git a/src/utils/utils.c b/src/utils/utils.c
new file mode 100644
index 00000000..02db8366
--- /dev/null
+++ b/src/utils/utils.c
@@ -0,0 +1,49 @@
+
+
+#include "utils/utils.h"
+#include "utils/config_helper.h"
+
+
+size_t concaternating_byte_array(char **dest, size_t dest_size, char *src, size_t src_size) {
+
+ char *dest_backup;
+ if (*dest == NULL || dest_size == 0) {
+ *dest = malloc(src_size);
+ memcpy(*dest, src, src_size);
+ } else {
+ dest_backup = (char *) malloc(dest_size);
+ memcpy(dest_backup, *dest, dest_size);
+// *dest = realloc((char *) *dest, dest_size + src_size+1);
+ free(*dest);
+
+ *dest = malloc(dest_size + src_size);
+ memcpy(*dest, dest_backup, dest_size);
+ memcpy(*dest + dest_size, src, src_size);
+
+ free(dest_backup);
+ }
+ return dest_size + src_size;
+}
+
+char *replace_double_quote_to_single_quote(char **dest, char *src, size_t src_size) {
+ for (int i = 0; i < src_size; ++i) {
+ if (src[i] == '\"') {
+ src[i] = '\'';
+ }
+ }
+ return *dest;
+}
+
+char *concaternating_default_graphpath(char *graphpath, char *query) {
+
+ printf("%s", graphpath);
+
+ char *f = "set graph_path='%s'; %s;";
+
+ char *query_with_graphpath = malloc((strlen(f) - 4) + strlen(graphpath) + strlen(query) + 1);
+ sprintf(query_with_graphpath, f, graphpath, query);
+
+ return query_with_graphpath;
+
+}
+