-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup travisci, add c++ header and example
- Loading branch information
Showing
11 changed files
with
199 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
sudo: required | ||
|
||
language: cpp | ||
|
||
os: linux | ||
|
||
install: | ||
- sudo pip install protobuf | ||
- wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz | ||
- tar -xzvf protobuf-2.6.1.tar.gz | ||
- cd protobuf-2.6.1 && ./configure --prefix=/usr && make && sudo make install && cd .. | ||
|
||
script: | ||
- ./travis.sh $CONFIG | ||
|
||
env: | ||
- CONFIG=cpp | ||
- CONFIG=python | ||
|
||
notifications: | ||
email: true |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
CXX := $(shell command -v clang++ || command -v g++) | ||
CXXFLAGS := -O2 | ||
LDFLAGS += -L./ -lsqlchop `pkg-config --libs protobuf` | ||
|
||
.PHONY: all clean | ||
|
||
all: | ||
protoc --python_out=. preprocessio.proto | ||
echo 'Done!' | ||
all: sqlchop_cpp sqlchop_python | ||
|
||
sqlchop_cpp: sqlchop_test | ||
sqlchop_python: sqlchopio_pb2.py | ||
|
||
sqlchopio_pb2.py: | ||
protoc --python_out=. sqlchopio.proto | ||
|
||
sqlchopio.pb.cc: | ||
protoc --cpp_out=. sqlchopio.proto | ||
|
||
sqlchop_test: sqlchopio.pb.cc | ||
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ test.cc sqlchopio.pb.cc | ||
|
||
clean: | ||
rm -f sqlchop_test | ||
rm -f sqlchop.pyc | ||
rm -f preprocessio_pb2.py{,c} | ||
rm -f sqlchopio_pb2.py{,c} | ||
rm -f sqlchopio.pb.{cc,h,o} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2015 Chaitin Tech. | ||
* | ||
* Licensed under: | ||
* https://github.com/chaitin/sqlchop/blob/master/LICENSE | ||
* | ||
*/ | ||
|
||
#ifndef __SQLCHOP_SQLCHOP_H__ | ||
#define __SQLCHOP_SQLCHOP_H__ | ||
|
||
#define SQLCHOP_API __attribute__((visibility("default"))) | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct sqlchop_object_t; | ||
|
||
enum { | ||
SQLCHOP_RET_SQLI = 1, | ||
SQLCHOP_RET_NORMAL = 0, | ||
SQLCHOP_ERR_SERIALIZE = -1, | ||
SQLCHOP_ERR_LENGTH = -2, | ||
}; | ||
|
||
SQLCHOP_API int sqlchop_init(const char config[], | ||
struct sqlchop_object_t **obj); | ||
SQLCHOP_API float sqlchop_score_sqli(const struct sqlchop_object_t *obj, | ||
const char buf[], size_t len); | ||
SQLCHOP_API int sqlchop_classify_request(const struct sqlchop_object_t *obj, | ||
const char request[], size_t rlen, | ||
char *payloads, size_t maxplen, | ||
size_t *plen, int detail); | ||
|
||
SQLCHOP_API int sqlchop_release(struct sqlchop_object_t *obj); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // __SQLCHOP_SQLCHOP_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2015 Chaitin Tech. | ||
* | ||
* Licensed under: | ||
* https://github.com/chaitin/sqlchop/blob/master/LICENSE | ||
* | ||
* Sample usage: | ||
* $ LD_LIBRARY_PATH=./ ./test | ||
* | ||
*/ | ||
|
||
|
||
#include <string> | ||
#include <iostream> | ||
|
||
#include "sqlchop.h" | ||
#include "sqlchopio.pb.h" | ||
|
||
#define MAXLEN 1 << 20 | ||
|
||
using namespace std; | ||
|
||
sqlchop_object_t *pdetector; | ||
string str_in; | ||
char out[MAXLEN]; | ||
|
||
Request req; | ||
ListOfPayload list_of_payload; | ||
|
||
int main() { | ||
|
||
req.set_urlpath("/chaitin/" | ||
"sqlchop?=" | ||
"c2VsZWN0JTIwc3FsY2hvcCUyMGZyb20lMjBjaGFpdGluJTIwd2hlcmUlMjBo" | ||
"ZWxsbyUyMCUzRCUyMHdvcmxkJTIwJTI2JTI2JTIwJTI3aG9wZSUyNyUyMCUy" | ||
"N3lvdSUyNyUyMGxpa2UlMjBpdAo="); | ||
req.SerializeToString(&str_in); | ||
|
||
size_t out_len; | ||
sqlchop_init(0, &pdetector); | ||
sqlchop_classify_request(pdetector, str_in.c_str(), str_in.length(), out, | ||
MAXLEN, &out_len, 1); | ||
|
||
list_of_payload.ParseFromString(string(out, out_len)); | ||
|
||
for (int pi = 0; pi < list_of_payload.payloads_size(); pi++) { | ||
cout << "Payload #" << pi << ":" << endl; | ||
const Payload& payload = list_of_payload.payloads(pi); | ||
cout << "Value:" << endl; | ||
cout << payload.value() << endl; | ||
if (payload.has_key()) { | ||
cout << "Key:" << endl; | ||
cout << payload.key() << endl; | ||
} | ||
if (payload.has_source()) { | ||
cout << "Source:" << endl; | ||
cout << payload.source() << endl; | ||
} | ||
if (payload.has_score()) { | ||
cout << "Score:" << endl; | ||
cout << payload.score() << endl; | ||
} | ||
cout << endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
test_cpp() { | ||
LD_LIBRARY_PATH=./ ./sqlchop_test | ||
} | ||
|
||
test_python() { | ||
python test.py | ||
} | ||
|
||
# -------- main -------- | ||
|
||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 { cpp | python }" | ||
exit 1 | ||
fi | ||
|
||
set -e # exit immediately on error | ||
set -x # display all commands | ||
make sqlchop_$1 | ||
eval "test_$1" |