Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support v4 signature #10

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.o
*.pb.cc
*.pb.h
.vscode/
lib/libsls_logs_pb.a
lib/libslssdk.a
build/
57 changes: 50 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,68 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.8.12)
project(sls-sdk-cpp)

# using c++ 11
set(CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

# set output dir
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# find lib protobuf & pthread & curl
find_package(Protobuf REQUIRED)
find_package(Threads REQUIRED)
find_package(CURL REQUIRED)
include_directories(${CMAKE_BINARY_DIR}
${PROJECT_SOURCE_DIR}
${PROTOBUF_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
${PROTOBUF_INCLUDE_DIRS})

include_directories(${PROTOBUF_INCLUDE_DIRS})
# generate protobuf files
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS sls_logs.proto)

include_directories(${CURL_INCLUDE_DIR})

add_library(slssdk
client.cpp
# target lib [slssdk]
add_library(slssdk client.cpp
resource.cpp
adapter.cpp
common.cpp
signer.cpp
${PROTO_SRCS})

# link protobuf & curl & lz4
target_link_libraries(slssdk
${PROTOBUF_LIBRARIES}
${CURL_LIBRARIES}
${PROJECT_SOURCE_DIR}/lib/liblz4.a)

# link pthread, compatiable with cmake 2.8.12+
if(THREADS_HAVE_PTHREAD_ARG)
target_compile_options(slssdk PUBLIC "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(slssdk "${CMAKE_THREAD_LIBS_INIT}")
endif()


# build bin [sample]
add_executable(sample sample.cpp)
target_link_libraries(sample slssdk)


# unittest
enable_testing()
add_definitions(-D__ALIYUN_LOG_UNITTEST__)
add_subdirectory(test)

# install lib slssdk
install(TARGETS slssdk
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

# install header files
install(FILES client.h RestfulApiCommon.h resource.h ${PROTO_HDRS}
DESTINATION include)
install(DIRECTORY rapidjson
DESTINATION include)

27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
CFLAGS= -O2 -L./lib/ -std=gnu++11
CFLAGS= -O2 -g -std=gnu++11
LIBDIR=-L./lib/
LIBS=-lslssdk
LIBS+=-lsls_logs_pb
LIBS+=-llz4
LIBS+=-lcurl
LIBS+=-lprotobuf
LIBS+= -lpthread


main: sample.o libslssdk.a libsls_logs_pb.a
g++ -o sample sample.o $(CFLAGS) $(LIBS)
g++ -o sample sample.o $(CFLAGS) $(LIBDIR) $(LIBS)

libslssdk.a:client.o resource.o adapter.o common.o
ar rc lib/libslssdk.a client.o resource.o adapter.o common.o
libslssdk.a:client.o resource.o adapter.o common.o signer.o
ar rc lib/libslssdk.a client.o resource.o adapter.o common.o signer.o

libsls_logs_pb.a : sls_logs.pb.cc
g++ -c sls_logs.pb.cc
g++ -c sls_logs.pb.cc $(CFLAGS)
ar rc lib/libsls_logs_pb.a sls_logs.pb.o

proto.cc: sls_logs.proto
protoc --cpp_out=./ sls_logs.proto

adapter.o: adapter.cpp
g++ -c adapter.cpp
g++ -c -g adapter.cpp $(CFLAGS)

common.o: common.cpp
g++ -c common.cpp
g++ -c -g common.cpp $(CFLAGS)

resource.o: resource.cpp
g++ -c resource.cpp
g++ -c resource.cpp $(CFLAGS)

client.o: client.cpp proto.cc
g++ -c client.cpp
g++ -c client.cpp $(CFLAGS)

signer.o: signer.cpp
g++ -c signer.cpp $(CFLAGS)

sample.o:sample.cpp proto.cc
g++ -c sample.cpp
g++ -c sample.cpp $(CFLAGS)



clean:
rm -f adapter.o common.o resource.o client.o sample.o sample sls_logs.pb.o lib/libslssdk.a sls_logs.pb.h sls_logs.pb.cc lib/libsls_logs_pb.a
rm -f adapter.o common.o resource.o client.o sample.o sample signer.o sls_logs.pb.o lib/libslssdk.a sls_logs.pb.h sls_logs.pb.cc lib/libsls_logs_pb.a
83 changes: 57 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
# desciption

this is the C++ SDK version 0.6.0 for SLS
this is the C++ SDK version 0.6.0 for SLS

# dependency

protobuf: require version 2.4.1 ,
install protoc on your machine or use lib/libprotobuf_static.a
install protoc on your machine or use lib/libprotobuf_static.a

curl: use the system curl or your own curl

lz4 : use lib/liblz4.a


# build
# build

## using make file

+ execute "make" in this dir, then get
```
lib/libslssdk.a
lib/libsls_logs_pb.a
lib/liblz4.a
```
+ build your own program
- execute "make" in this dir, then get
```
lib/libslssdk.a
lib/libsls_logs_pb.a
lib/liblz4.a
```
- build your own program

```
g++ -o your_program your_program.o -O2 -L./lib/ -lslssdk -llz4 -lcurl -lprotobuf
g++ -o your_program your_program.o -O2 -L./lib/ -lslssdk -llz4 -lcurl -lprotobuf

```

## using SConscript

+ suppose your working directory is $root
- suppose your working directory is $root

- mkdir $root/slssdk

- copy

+ mkdir $root/slssdk
```
adapter.cpp client.cpp common.cpp resource.cpp signer.cpp
adapter.h client.h common.h resource.h signer.h RestfulApiCommon.h
sls_logs.proto
lz4 rapidjson
```

+ copy
```
adapter.cpp client.cpp common.cpp resource.cpp
adapter.h client.h common.h resource.h RestfulApiCommon.h
sls_logs.proto
lz4 rapidjson
```
to $root/slssdk
to $root/slssdk

+ build sls sdk lib
- build sls sdk lib

```
env.aProto('sls_logs.proto')
Expand All @@ -54,17 +55,47 @@ slssdk_obj = env.Object([Glob('*.cpp')])
env.aStaticLibrary(target = 'slssdk' ,source = [slssdk_obj])
```

+ copy
- copy

```
lib/liblz4.a lib/libprotobuf_static.a
```

to $root/slssdk/

+ build your own program
- build your own program

```
env.aProgram(target= 'sample1' ,source=['sample.cpp'], LIBS=['slssdk','sls_logs_pb_cpp','lz4','curl','protobuf_static'])
```

## using Cmake

Protobuf and curl are required.

- build lib slssdk

```
mkdir -p build && cd build
cmake .. && make
```

> The target files are in `build/bin` and `build/lib`


- install libs and header files

```
make install
```

- build your own program

```
g++ -o your_program your_program.o -O2 -lslssdk
```

- run unittest
```
make test
```
18 changes: 17 additions & 1 deletion RestfulApiCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
namespace aliyun_log_sdk_v6
{
extern const char * const DATE_FORMAT_RFC822;// "%a, %d %b %Y %H:%M:%S GMT" ///<RFC822 date formate, GMT time.
//typedef enum {REQUEST_GET= 1, REQUEST_POST } LOG_Request_Mode;///<Http Request Method.
extern const char* const DATE_FORMAT_ISO8601;// "%Y%m%d"
extern const char* const DATETIME_FORMAT_ISO8601;// "%Y%m%dT%H%M%SZ"
// typedef enum {REQUEST_GET= 1, REQUEST_POST } LOG_Request_Mode;///<Http
// Request Method.
typedef enum {CURSOR_MODE_BEGIN = 1, CURSOR_MODE_END} LOG_Cursor_Mode;
const uint32_t LOG_REQUEST_TIMEOUT = 20; //second
extern const char* const LOG_HEADSIGNATURE_PREFIX;///< "";
Expand Down Expand Up @@ -68,6 +71,7 @@ extern const char* const HOST;//= "Host";
extern const char* const DATE;//= "Date";
extern const char* const USER_AGENT;//= "User-Agent";
extern const char* const LOG_HEADER_PREFIX;//= "x-log-";
extern const char* const ACS_HEADER_PREFIX;//= "x-acs-";
extern const char* const LOG_OLD_HEADER_PREFIX;//= "x-sls-";
extern const char* const X_LOG_KEYPROVIDER;// = "x-log-keyprovider";
extern const char* const X_LOG_APIVERSION;// = "x-log-apiversion";
Expand All @@ -77,6 +81,8 @@ extern const char* const X_LOG_SIGNATUREMETHOD;// = "x-log-signaturemethod";
extern const char* const X_ACS_SECURITY_TOKEN;// = "x-acs-security-token";
extern const char* const X_LOG_CURSOR;// = "cursor";
extern const char* const X_LOG_REQUEST_ID;// = "x-log-requestid";
extern const char* const X_LOG_CONTENT_SHA256;// = "x-log-content-sha256";
extern const char* const X_LOG_DATE;// = "x-log-date";

extern const char* const X_LOG_PROGRESS;// = "x-log-progress";
extern const char* const X_LOG_COUNT;// = "x-log-count";
Expand Down Expand Up @@ -110,13 +116,23 @@ extern const char* const LOGE_SHARD_NOT_EXIST;
extern const char* const LOGE_INVALID_CURSOR;
extern const char* const LOGE_SHARD_WRITE_QUOTA_EXCEED;
extern const char* const LOGE_SHARD_READ_QUOTA_EXCEED;
extern const char* const LOGE_URL_ENCODE_ERROR;//= "UrlEncodeError";
extern const char* const LOGE_SIGNV4_REGION_REQUIRED; // = "SignV4RegionRequired";
extern const char* const LOG_LZ4;//= "lz4";

extern const char* const LOG_ERROR_CODE;//= "errorCode";
extern const char* const LOG_ERROR_MESSAGE;//= "errorMessage";

extern const char* const LOG_SHARD_STATUS_READWRITE;// "readwrite";
extern const char* const LOG_SHARD_STATUS_READONLY ;// "readonly";

// sign version
typedef enum
{
V1,
V4
} LOGSignVersion;

/**
*This class enumerates LOG ErrorCode with HTTP status.
*/
Expand Down
Loading