Commit 4fb44f22 authored by yiwenshao's avatar yiwenshao

add tools

parent 034e2c64
...@@ -104,6 +104,11 @@ mtl/test_redisbio_exe/%:$(OBJDIR)/test_redisbio/%.o $(OBJDIR)/libredisbio.so ...@@ -104,6 +104,11 @@ mtl/test_redisbio_exe/%:$(OBJDIR)/test_redisbio/%.o $(OBJDIR)/libredisbio.so
@mkdir -p $(@D) @mkdir -p $(@D)
$(CXX) -g -o $@ $< $(CXXFLAGS) $(LDFLAGS) -lredisbio $(CXX) -g -o $@ $< $(CXXFLAGS) $(LDFLAGS) -lredisbio
mtl/tools/%:$(OBJDIR)/tools/%.o $(OBJDIR)/libredisbio.so $(OBJDIR)/libwrapper.so
@mkdir -p $(@D)
$(CXX) -g -o $@ $< $(CXXFLAGS) $(LDFLAGS) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -lwrapper -lcryptdb -ledbcrypto -ledbutil -ledbparser -lntl -lcrypto -lredisbio
include crypto/Makefrag include crypto/Makefrag
include parser/Makefrag include parser/Makefrag
include main/Makefrag include main/Makefrag
...@@ -119,6 +124,7 @@ include wrapper/Makefrag ...@@ -119,6 +124,7 @@ include wrapper/Makefrag
include test_parser_helper/Makefrag include test_parser_helper/Makefrag
include redisbio/Makefrag include redisbio/Makefrag
include test_redisbio/Makefrag include test_redisbio/Makefrag
include tools/Makefrag
$(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d)) $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
@mkdir -p $(@D) @mkdir -p $(@D)
......
...@@ -15,3 +15,4 @@ extern ...@@ -15,3 +15,4 @@ extern
int(*userFunction)(unsigned long,void*); int(*userFunction)(unsigned long,void*);
const unsigned int REDIS_BIO_NUM_OPS = 10; const unsigned int REDIS_BIO_NUM_OPS = 10;
OBJDIRS += tools
##note that xx=*.cc will not expand. wildcard *.cc will include files from other directories.
##%.o will include testall
TESTTOOLS_OBJS := $(patsubst %.cc,$(OBJDIR)/%.o,$(wildcard tools/*.cc))
TESTTOOLS_EXES := $(patsubst tools/%.cc,mtl/tools/%,$(wildcard tools/*.cc))
all: $(TESTTOOLS_OBJS) $(TESTTOOLS_EXES)
#include <string>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include "parser/sql_utils.hh"
#include "parser/lex_util.hh"
#include "parser/embedmysql.hh"
#include "util/util.hh"
#include "util/constants.hh"
#include "test_parser_helper/showparser.hh"
#include "test_parser_helper/showitem.hh"
#include "test_parser_helper/showselect_lex.hh"
#include "test_parser_helper/showstring.hh"
static std::string embeddedDir="/t/cryt/shadow";
int main() {
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
free(buffer);
embeddedDir = std::string(buffer)+"/shadow";
init_mysql(embeddedDir);
/* std::string filename = std::string(cryptdb_dir)+"/test_parser/"+"select";
std::string line;
std::ifstream infile(filename);
while(std::getline(infile,line)) {
std::cout<<"=================================================================="<<std::endl;
std::cout<<line<<std::endl;
std::unique_ptr<query_parse> p;
p = std::unique_ptr<query_parse>(
new query_parse("tdb", line));
LEX *const lex = p->lex();
(void)lex;
// std::cout<<SHOW::SQLCOM::trans[lex->sql_command]<<std::endl;
// show_select_lex(lex->select_lex);
// std::cout<<get_lex_string(*lex)<<std::endl;
}*/
return 0;
}
#include <iostream>
#include <vector>
#include <functional>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <main/Connect.hh>
#include <main/rewrite_util.hh>
#include <main/sql_handler.hh>
#include <main/dml_handler.hh>
#include <main/ddl_handler.hh>
#include <main/CryptoHandlers.hh>
#include <main/rewrite_main.hh>
#include "util/util.hh"
extern CItemTypesDir itemTypes;
static std::string embeddedDir="/t/cryt/shadow";
//expand the item
template <typename ContainerType>
void myRewriteInsertHelper(const Item &i, const FieldMeta &fm, Analysis &a,
ContainerType *const append_list){
std::vector<Item *> l;
itemTypes.do_rewrite_insert(i, fm, a, &l);
for (auto it : l) {
append_list->push_back(it);
}
}
static std::string getInsertResults(Analysis a,LEX* lex){
LEX *const new_lex = copyWithTHD(lex);
const std::string &table =
lex->select_lex.table_list.first->table_name;
const std::string &db_name =
lex->select_lex.table_list.first->db;
//from databasemeta to tablemeta.
const TableMeta &tm = a.getTableMeta(db_name, table);
//rewrite table name
new_lex->select_lex.table_list.first =
rewrite_table_list(lex->select_lex.table_list.first, a);
std::vector<FieldMeta *> fmVec;
std::vector<Item *> implicit_defaults;
// No field list, use the table order.
assert(fmVec.empty());
std::vector<FieldMeta *> fmetas = tm.orderedFieldMetas();
fmVec.assign(fmetas.begin(), fmetas.end());
if (lex->many_values.head()) {
//start processing many values
auto it = List_iterator<List_item>(lex->many_values);
List<List_item> newList;
for (;;) {
List_item *const li = it++;
if (!li) {
break;
}
List<Item> *const newList0 = new List<Item>();
if (li->elements != fmVec.size()) {
TEST_TextMessageError(0 == li->elements
&& NULL == lex->field_list.head(),
"size mismatch between fields"
" and values!");
} else {
auto it0 = List_iterator<Item>(*li);
auto fmVecIt = fmVec.begin();
for (;;) {
const Item *const i = it0++;
assert(!!i == (fmVec.end() != fmVecIt));
if (!i) {
break;
}
//fetch values, and use fieldMeta to facilitate rewrite
//every filed should be encrypted with onions of encryption
myRewriteInsertHelper(*i, **fmVecIt, a, newList0);
++fmVecIt;
}
for (auto def_it : implicit_defaults) {
newList0->push_back(def_it);
}
}
newList.push_back(newList0);
}
new_lex->many_values = newList;
}
return lexToQuery(*new_lex);
}
static void testInsertHandler(std::string query){
std::unique_ptr<Connect> e_conn(Connect::getEmbedded(embeddedDir));
std::unique_ptr<SchemaInfo> schema(new SchemaInfo());
std::function<DBMeta *(DBMeta *const)> loadChildren =
[&loadChildren, &e_conn](DBMeta *const parent) {
auto kids = parent->fetchChildren(e_conn);
for (auto it : kids) {
loadChildren(it);
}
return parent;
};
//load all metadata and then store it in schema
loadChildren(schema.get());
const std::unique_ptr<AES_KEY> &TK = std::unique_ptr<AES_KEY>(getKey(std::string("113341234")));
//just like what we do in Rewrite::rewrite,dispatchOnLex
Analysis analysis(std::string("tdb"),*schema,TK,
SECURITY_RATING::SENSITIVE);
std::unique_ptr<query_parse> p;
p = std::unique_ptr<query_parse>(
new query_parse("tdb", query));
LEX *const lex = p->lex();
std::cout<<getInsertResults(analysis,lex)<<std::endl;
}
int
main() {
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
//Free to remove memory leak
embeddedDir = std::string(buffer)+"/shadow";
const std::string master_key = "113341234";
ConnectionInfo ci("localhost", "root", "letmein",3306);
UNUSED(ci);
//Clean!!
free(buffer);
//this function alone has memory leak
SharedProxyState *shared_ps = new SharedProxyState(ci, embeddedDir , master_key, determineSecurityRating());
assert(shared_ps!=NULL);
UNUSED(testInsertHandler);
UNUSED(getInsertResults);
// std::string query1 = "insert into student values(1,\"zhangfei\")";
/* std::vector<std::string> querys{query1};
for(auto item:querys){
std::cout<<item<<std::endl;
testInsertHandler(item);
std::cout<<std::endl;
}
*/
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment