diff --git a/CMakeCache.txt b/CMakeCache.txt new file mode 100644 index 0000000..6e1099c --- /dev/null +++ b/CMakeCache.txt @@ -0,0 +1,359 @@ +# This is the CMakeCache file. +# For build in directory: /Users/wangjwchn/Documents/aliyun-log-c-sdk +# It was generated by CMake: /usr/local/Cellar/cmake/3.4.3/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//Path to a program. +APR_CONFIG_BIN:FILEPATH=/usr/bin/apr-1-config + +//Path to a library. +APR_LIBRARY:FILEPATH=/usr/lib/libapr-1.dylib + +//Path to a library. +APR_UTIL_LIBRARY:FILEPATH=/usr/lib/libaprutil-1.dylib + +//Path to a program. +APU_CONFIG_BIN:FILEPATH=/usr/bin/apu-1-config + +//Path to a program. +CMAKE_AR:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar + +//Choose the type of build, options are: None(CMAKE_CXX_FLAGS or +// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel. +CMAKE_BUILD_TYPE:STRING= + +//Enable/Disable color output during build. +CMAKE_COLOR_MAKEFILE:BOOL=ON + +//CXX compiler +CMAKE_CXX_COMPILER:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ + +//Flags used by the compiler during all build types. +CMAKE_CXX_FLAGS:STRING= + +//Flags used by the compiler during debug builds. +CMAKE_CXX_FLAGS_DEBUG:STRING=-g + +//Flags used by the compiler during release builds for minimum +// size. +CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the compiler during release builds. +CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the compiler during release builds with debug info. +CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//C compiler +CMAKE_C_COMPILER:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc + +//Flags used by the compiler during all build types. +CMAKE_C_FLAGS:STRING= + +//Flags used by the compiler during debug builds. +CMAKE_C_FLAGS_DEBUG:STRING=-g + +//Flags used by the compiler during release builds for minimum +// size. +CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the compiler during release builds. +CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the compiler during release builds with debug info. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//Flags used by the linker. +CMAKE_EXE_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Enable/Disable output of compile commands during generation. +CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF + +//Path to a program. +CMAKE_INSTALL_NAME_TOOL:FILEPATH=/usr/bin/install_name_tool + +//Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=/usr/local + +//Path to a program. +CMAKE_LINKER:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld + +//Path to a program. +CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make + +//Flags used by the linker during the creation of modules. +CMAKE_MODULE_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_NM:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm + +//Path to a program. +CMAKE_OBJCOPY:FILEPATH=CMAKE_OBJCOPY-NOTFOUND + +//Path to a program. +CMAKE_OBJDUMP:FILEPATH=CMAKE_OBJDUMP-NOTFOUND + +//Build architectures for OSX +CMAKE_OSX_ARCHITECTURES:STRING= + +//Minimum OS X version to target for deployment (at runtime); newer +// APIs weak linked. Set to empty string for default value. +CMAKE_OSX_DEPLOYMENT_TARGET:STRING= + +//The product will be built against the headers and libraries located +// inside the indicated SDK. +CMAKE_OSX_SYSROOT:PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=log_c_sdk + +//Path to a program. +CMAKE_RANLIB:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib + +//Flags used by the linker during the creation of dll's. +CMAKE_SHARED_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//If set, runtime paths are not added when installing shared libraries, +// but are added when building. +CMAKE_SKIP_INSTALL_RPATH:BOOL=NO + +//If set, runtime paths are not added when using shared libraries. +CMAKE_SKIP_RPATH:BOOL=NO + +//Flags used by the linker during the creation of static libraries. +CMAKE_STATIC_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_STRIP:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip + +//If this value is on, makefiles will be generated without the +// .SILENT directive, and all commands will be echoed to the console +// during the make. This is useful for debugging only. With Visual +// Studio IDE projects all commands are done without /nologo. +CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE + +//Path to a program. +CURL_CONFIG_BIN:FILEPATH=/usr/local/bin/curl-config + +//Path to a library. +CURL_LIBRARY:FILEPATH=/usr/local/lib/libcurl.dylib + +//Path to a library. +M_LIBRARY:FILEPATH=/usr/lib/libm.dylib + +//Path to a library. +PTHREAD_LIBRARY:FILEPATH=/usr/lib/libpthread.dylib + +//Path to a library. +RT_LIBRARY:FILEPATH=RT_LIBRARY-NOTFOUND + +//Value Computed by CMake +log_c_sdk_BINARY_DIR:STATIC=/Users/wangjwchn/Documents/aliyun-log-c-sdk + +//Dependencies for target +log_c_sdk_LIB_DEPENDS:STATIC= + +//Value Computed by CMake +log_c_sdk_SOURCE_DIR:STATIC=/Users/wangjwchn/Documents/aliyun-log-c-sdk + +//Value Computed by CMake +log_c_sdk_sample_BINARY_DIR:STATIC=/Users/wangjwchn/Documents/aliyun-log-c-sdk/sample + +//Value Computed by CMake +log_c_sdk_sample_SOURCE_DIR:STATIC=/Users/wangjwchn/Documents/aliyun-log-c-sdk/sample + +//Dependencies for target +log_c_sdk_static_LIB_DEPENDS:STATIC= + + +######################## +# INTERNAL cache entries +######################## + +//ADVANCED property for variable: CMAKE_AR +CMAKE_AR-ADVANCED:INTERNAL=1 +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/Users/wangjwchn/Documents/aliyun-log-c-sdk +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=4 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 +//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE +CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/usr/local/Cellar/cmake/3.4.3/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/usr/local/Cellar/cmake/3.4.3/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/usr/local/Cellar/cmake/3.4.3/bin/ctest +//ADVANCED property for variable: CMAKE_CXX_COMPILER +CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS +CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG +CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL +CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER +CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//Path to cache edit program executable. +CMAKE_EDIT_COMMAND:INTERNAL=/usr/local/Cellar/cmake/3.4.3/bin/ccmake +//Executable file format +CMAKE_EXECUTABLE_FORMAT:INTERNAL=Unknown +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS +CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG +CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE +CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS +CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Unix Makefiles +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=/Users/wangjwchn/Documents/aliyun-log-c-sdk +//ADVANCED property for variable: CMAKE_INSTALL_NAME_TOOL +CMAKE_INSTALL_NAME_TOOL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_LINKER +CMAKE_LINKER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MAKE_PROGRAM +CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS +CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG +CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE +CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_NM +CMAKE_NM-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=2 +//ADVANCED property for variable: CMAKE_OBJCOPY +CMAKE_OBJCOPY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_OBJDUMP +CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RANLIB +CMAKE_RANLIB-ADVANCED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/usr/local/Cellar/cmake/3.4.3/share/cmake +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS +CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG +CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE +CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH +CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_RPATH +CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS +CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG +CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE +CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STRIP +CMAKE_STRIP-ADVANCED:INTERNAL=1 +//uname command +CMAKE_UNAME:INTERNAL=/usr/bin/uname +//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE +CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 + diff --git a/CMakeLists.txt b/CMakeLists.txt index 47131d7..ed4eab4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,7 @@ INSTALL(FILES src/log_define.h src/log_util.h src/log_api.h + src/log_http_cont.h src/log_builder.h src/protobuf-c.h src/sls_logstores.pb-c.h diff --git a/sample/.DS_Store b/sample/.DS_Store new file mode 100644 index 0000000..bd99b39 Binary files /dev/null and b/sample/.DS_Store differ diff --git a/sample/log_post_logs_sample.c b/sample/log_post_logs_sample.c index d291fcc..ca3eeac 100644 --- a/sample/log_post_logs_sample.c +++ b/sample/log_post_logs_sample.c @@ -6,13 +6,14 @@ #include "log_util.h" #include "log_api.h" #include "log_config.h" - +#include +#include void log_post_logs_sample() { aos_pool_t *p = NULL; aos_status_t *s = NULL; aos_pool_create(&p, NULL); - + cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "__source__", "127.0.0.1"); cJSON_AddStringToObject(root, "__topic__", "topic"); @@ -40,53 +41,123 @@ void log_post_logs_sample() printf("%s\n",s->error_code); printf("%s\n",s->error_msg); printf("%s\n",s->req_id); - printf("put logs failed\n"); + printf("put logs failed\n"); } cJSON_Delete(root); aos_pool_destroy(p); } +double log_build_http_cont_test(const char* path){ + + apr_initialize(); + + FILE* f = fopen(path, "r"); + if(!f) return -1; + + const int content_number = 10*2000*28*2; + char **buf = malloc(sizeof(char*)*content_number); + for(int i=0;icode); - printf("%s\n",s->error_code); - printf("%s\n",s->error_msg); - printf("%s\n",s->req_id); - printf("put logs failed\n"); + for(int j=0;j<65536;j++){ + char k[] = "k"; + char v[] = "v"; + add_log_key_value(bder, k, strlen(k), v, strlen(v)); } - - log_group_destroy(bder); - } + */ + + + //s = log_post_logs_from_proto_buf(LOG_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET,NULL, PROJECT_NAME, LOGSTORE_NAME, bder); + + log_http_cont* cont = log_create_http_cont(LOG_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET,NULL, PROJECT_NAME, LOGSTORE_NAME, bder); + s = log_post_logs_from_http_cont(cont); + if (aos_status_is_ok(s)) { + printf("post logs succeeded\n"); + } else { + printf("%d\n",s->code); + printf("%s\n",s->error_code); + printf("%s\n",s->error_msg); + printf("%s\n",s->req_id); + printf("put logs failed\n"); + } + + log_clean_http_cont(cont); } int main(int argc, char *argv[]) { - if (aos_http_io_initialize("linux-x86_64", 0) != AOSE_OK) { - exit(1); - } - log_post_logs_sample2(); - aos_http_io_deinitialize(); + printf("%lf\n",log_build_http_cont_test("/Users/wangjwchn/Downloads/sample_log.log")); return 0; } diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..4d47ba5 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/aos_define.h b/src/aos_define.h index e83891c..08038dc 100644 --- a/src/aos_define.h +++ b/src/aos_define.h @@ -10,7 +10,7 @@ #include #include -#include + #include #include #include diff --git a/src/aos_string.h b/src/aos_string.h index aaeab4c..202ab54 100644 --- a/src/aos_string.h +++ b/src/aos_string.h @@ -13,7 +13,7 @@ typedef struct { #define aos_string(str) { sizeof(str) - 1, (char *) str } #define aos_null_string { 0, NULL } #define aos_str_set(str, text) \ - (str)->len = strlen(text); (str)->data = (char *) text + (str)->len = (int)strlen(text); (str)->data = (char *) text #define aos_str_null(str) (str)->len = 0; (str)->data = NULL #define aos_tolower(c) (char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c) diff --git a/src/aos_transport.h b/src/aos_transport.h index fe46e83..a53e9be 100644 --- a/src/aos_transport.h +++ b/src/aos_transport.h @@ -3,7 +3,7 @@ #include "aos_define.h" #include "aos_buf.h" - +#include AOS_CPP_START typedef struct aos_http_request_s aos_http_request_t; diff --git a/src/aos_util.c b/src/aos_util.c index 030580d..13e7f3e 100644 --- a/src/aos_util.c +++ b/src/aos_util.c @@ -150,7 +150,7 @@ int aos_query_params_to_string(aos_pool_t *p, aos_table_t *query_params, aos_str // result querystr->data = (char *)querybuf->pos; - querystr->len = aos_buf_size(querybuf); + querystr->len = (int)aos_buf_size(querybuf); return AOSE_OK; } @@ -223,7 +223,7 @@ int aos_base64_encode(const unsigned char *in, int inLen, char *out) in++, inLen--; } - return (out - original_out); + return (int)(out - original_out); } // HMAC-SHA-1: diff --git a/src/log_api.c b/src/log_api.c index 88b57bb..17b7ce8 100644 --- a/src/log_api.c +++ b/src/log_api.c @@ -7,100 +7,37 @@ #include "log_util.h" #include "log_api.h" -log_http_cont* log_get_http_cont(const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken,const char* project,const char* logstore,log_group_builder* bder) -{ - aos_pool_t* tmp; - apr_pool_create(&tmp, NULL); - aos_http_request_t *req = (aos_http_request_t*)apr_palloc(tmp, sizeof(aos_http_request_t)); - req->pool = tmp; +aos_status_t* log_post_logs_from_http_cont(log_http_cont* cont){ - aos_string_t project_name, logstore_name; - aos_table_t *headers = NULL; - log_request_options_t *options = NULL; - aos_list_t buffer; - unsigned char *md5 = NULL; - char *buf = NULL; - int64_t buf_len; - char *b64_value = NULL; - aos_buf_t *content = NULL; - aos_status_t *s = NULL; + aos_http_request_t *req = (aos_http_request_t*)apr_palloc(cont->root, sizeof(aos_http_request_t)); + req->pool = cont->root; + req->headers = cont->headers; + req->body_len = cont->body.length; + req->method = HTTP_POST; + req->signed_url = cont->url; + req->file_path = NULL; + req->file_buf = NULL; - options = log_request_options_create(tmp); - options->config = log_config_create(tmp); - aos_str_set(&(options->config->endpoint), endpoint); - aos_str_set(&(options->config->access_key_id), accesskeyId); - aos_str_set(&(options->config->access_key_secret), accessKey); - if(stsToken != NULL) - { - aos_str_set(&(options->config->sts_token), stsToken); - } - options->ctl = aos_http_controller_create(tmp, 0); - headers = aos_table_make(options->pool, 5); - apr_table_set(headers, LOG_API_VERSION, "0.6.0"); - apr_table_set(headers, LOG_COMPRESS_TYPE, "lz4"); - apr_table_set(headers, LOG_SIGNATURE_METHOD, "hmac-sha1"); - apr_table_set(headers, LOG_CONTENT_TYPE, "application/x-protobuf"); - aos_str_set(&project_name, project); - aos_str_set(&logstore_name, logstore); + log_request_options_t *options = log_request_options_create(cont->root); + options->ctl = aos_http_controller_create(cont->root, 0); + options->ctl->pool = cont->root; + + aos_list_t buffer; aos_list_init(&buffer); - log_buf* buff = serialize_to_proto_buf(bder); - char *body = buff->data; - int org_body_size = (int)buff->length; - apr_table_set(headers, LOG_BODY_RAW_SIZE, apr_itoa(options->pool, org_body_size)); - int compress_bound = LZ4_compressBound(org_body_size); - char *compress_data = aos_pcalloc(tmp, compress_bound); - int compressed_size = LZ4_compress(body, compress_data, org_body_size); - content = aos_buf_pack(tmp, compress_data, compressed_size); + aos_buf_t *content = aos_buf_pack(cont->root, cont->body.data, (int)cont->body.length); aos_list_add_tail(&content->node, &buffer); - - //add Content-MD5 - buf_len = aos_buf_list_len(&buffer); - buf = aos_buf_list_content(tmp, &buffer); - md5 = aos_md5(tmp, buf, (apr_size_t)buf_len); - b64_value = aos_pcalloc(tmp, 50); - int loop = 0; - for(; loop < 16; ++loop) - { - unsigned char a = ((*md5)>>4) & 0xF, b = (*md5) & 0xF; - b64_value[loop<<1] = a > 9 ? (a - 10 + 'A') : (a + '0'); - b64_value[(loop<<1)|1] = b > 9 ? (b - 10 + 'A') : (b + '0'); - ++md5; - } - b64_value[loop<<1] = '\0'; - apr_table_set(headers, LOG_CONTENT_MD5, b64_value); - - aos_http_response_t *resp = NULL; - aos_table_t *query_params = NULL; - headers = aos_table_create_if_null(options, headers, 0); - - query_params = aos_table_create_if_null(options, query_params, 0); - - log_post_logs_request(options, &project_name, &logstore_name, HTTP_POST, - &req, query_params, headers, &resp); log_write_request_body_from_buffer(&buffer, req); - int res = AOSE_OK; - s = aos_status_create(options->pool); - res = log_sign_request(req, options->config); - - log_http_cont* cont_out = (log_http_cont*)apr_palloc(req->pool, sizeof(log_http_cont)); - cont_out->body.data = compress_data; - cont_out->body.length = compressed_size; - cont_out->root = req->pool; - cont_out->headers = req->headers; - cont_out->host = req->host; - cont_out->proto = req->proto; - cont_out->uri = req->uri; + aos_http_response_t *resp = aos_http_response_create(options->pool); + + req->read_body = aos_read_http_body_memory; + aos_status_t* s = log_send_request(options->ctl, req, resp); - return cont_out; + return s; } -void log_clean_http_cont(log_http_cont* cont) -{ - apr_pool_destroy(cont->root); -} aos_status_t *log_post_logs_from_proto_buf(const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken, const char *project, const char *logstore, log_group_builder* bder) { @@ -254,7 +191,7 @@ aos_status_t *log_post_logs_with_sts_token(aos_pool_t *p, const char *endpoint, b64_value[loop<<1] = '\0'; apr_table_set(headers, LOG_CONTENT_MD5, b64_value); - s = log_post_logs_from_buffer(options, &project_name, &logstore_name, + s = log_post_logs_from_buffer(options, &project_name, &logstore_name, &buffer, headers, &resp_headers); free(body); return s; diff --git a/src/log_api.h b/src/log_api.h index 8a3d402..7ad2e1c 100644 --- a/src/log_api.h +++ b/src/log_api.h @@ -5,14 +5,15 @@ #include "aos_string.h" #include "aos_status.h" #include "log_define.h" -#include "log_builder.h" +#include "log_builder.h" +#include "log_http_cont.h" LOG_CPP_START aos_status_t *log_post_logs_with_sts_token(aos_pool_t *p, const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken, const char *project, const char *logstore, cJSON *root); aos_status_t *log_post_logs(aos_pool_t *p, const char *endpoint, const char * accesskeyId, const char *accessKey, const char *project, const char *logstore, cJSON *root); aos_status_t *log_post_logs_from_proto_buf(const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken, const char *project, const char *logstore, log_group_builder* bder); -log_http_cont* log_get_http_cont(const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken,const char* project,const char* logstore,log_group_builder* bder); -void log_clean_http_cont(log_http_cont* cont); +aos_status_t* log_post_logs_from_http_cont(log_http_cont* cont); + LOG_CPP_END #endif diff --git a/src/log_auth.c b/src/log_auth.c index 279753b..e0eb29f 100644 --- a/src/log_auth.c +++ b/src/log_auth.c @@ -266,9 +266,6 @@ int log_sign_request(aos_http_request_t *req, res = log_get_signed_headers(req->pool, &config->access_key_id, &config->access_key_secret, &canon_res, req); - - - return res; } diff --git a/src/log_builder.c b/src/log_builder.c index ef47105..061cc2f 100644 --- a/src/log_builder.c +++ b/src/log_builder.c @@ -10,7 +10,6 @@ log_group_builder* log_group_create() { - apr_pool_initialize(); apr_pool_t *tmp; apr_pool_create(&tmp, NULL); log_group_builder* bder = (log_group_builder*)apr_palloc(tmp,sizeof(log_group_builder)); diff --git a/src/log_builder.h b/src/log_builder.h index 0484a11..653c7f4 100644 --- a/src/log_builder.h +++ b/src/log_builder.h @@ -50,21 +50,13 @@ typedef struct _log_header_pair{ } log_header_pair; typedef struct _log_http_cont{ - char* proto; - char* host; - char* uri; + char* url; apr_table_t *headers; log_buf body; apr_pool_t *root; } log_http_cont; - -extern void log_http_cont_set_url(log_http_cont* cont,char* url); -extern void log_http_cont_set_body(log_http_cont* cont,log_buf* body); -extern void log_http_cont_set_header(log_http_cont* cont,char* h_k,char* h_v); - - extern log_buf* serialize_to_proto_buf(log_group_builder* bder); extern log_group_builder* log_group_create(); extern void log_group_destroy(log_group_builder* bder); @@ -74,4 +66,6 @@ extern void add_source(log_group_builder* bder,char* src,size_t len); extern void add_topic(log_group_builder* bder,char* tpc,size_t len); extern void add_log_time(log_group_builder* bder,uint32_t time); extern void add_log_key_value(log_group_builder* bder,char* v,size_t v_len,char* k,size_t k_len); + + #endif /* log_builder_h */ diff --git a/src/log_http_cont.c b/src/log_http_cont.c new file mode 100644 index 0000000..6b9f7d1 --- /dev/null +++ b/src/log_http_cont.c @@ -0,0 +1,148 @@ +// +// log_http_cont.c +// log-c-sdk-new +// +// Created by 王佳玮 on 16/8/31. +// Copyright © 2016年 wangjwchn. All rights reserved. +// + +#include "log_http_cont.h" + +void log_clean_http_cont(log_http_cont* cont) +{ + apr_pool_destroy(cont->root); +} + +int _starts_with(const aos_string_t *str, const char *prefix) { + uint32_t i; + if(NULL != str && prefix && str->len > 0 && strlen(prefix)) { + for(i = 0; str->data[i] != '\0' && prefix[i] != '\0'; i++) { + if(prefix[i] != str->data[i]) return 0; + } + return 1; + } + return 0; +} + +log_buf* _compressed_buffer(apr_pool_t* pool,log_buf* before) +{ + char *body = before->data; + int compress_bound = LZ4_compressBound(before->length); + char *compress_data = aos_pcalloc(pool, compress_bound); + int compressed_size = LZ4_compress(body, compress_data, before->length); + + log_buf* after = aos_pcalloc(pool, sizeof(log_buf)); + + after->data = compress_data; + after->length = compressed_size; + return after; +} + +char* _get_url(apr_pool_t* pool,aos_string_t _endpoint,aos_string_t logstore_name,aos_string_t project_name) +{ + const char *proto; + proto = _starts_with(&_endpoint, AOS_HTTP_PREFIX) ? AOS_HTTP_PREFIX : ""; + proto = _starts_with(&_endpoint, AOS_HTTPS_PREFIX) ? AOS_HTTPS_PREFIX : proto; + int32_t proto_len = strlen(proto); + char *resource = apr_psprintf(pool, "logstores/%.*s/shards/lb",(int)logstore_name.len, logstore_name.data); + aos_string_t raw_endpoint = {_endpoint.len - proto_len, + _endpoint.data + proto_len}; + char* host = apr_psprintf(pool, "%.*s.%.*s", + project_name.len, project_name.data, + raw_endpoint.len, raw_endpoint.data); + char* url = apr_psprintf(pool, "%.*s%.*s/logstores/%.*s/shards/lb", (int)strlen(proto),proto,(int)strlen(host), host,logstore_name.len, logstore_name.data); + return url; +} +char* _get_md5(apr_pool_t* pool,log_buf* buff) +{ + aos_buf_t* content = aos_buf_pack(pool, buff->data, (int)buff->length); + aos_list_t buffer; + aos_list_init(&buffer); + aos_list_add_tail(&content->node, &buffer); + + //add Content-MD5 + int64_t buf_len = aos_buf_list_len(&buffer); + char* buf = aos_buf_list_content(pool, &buffer); + unsigned char* md5 = aos_md5(pool, buf, (apr_size_t)buf_len); + char* b64_value = aos_pcalloc(pool, 50); + int loop = 0; + for(; loop < 16; ++loop) + { + unsigned char a = ((*md5)>>4) & 0xF, b = (*md5) & 0xF; + b64_value[loop<<1] = a > 9 ? (a - 10 + 'A') : (a + '0'); + b64_value[(loop<<1)|1] = b > 9 ? (b - 10 + 'A') : (b + '0'); + ++md5; + } + b64_value[loop<<1] = '\0'; + return b64_value; + +} +log_http_cont* log_create_http_cont(const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken,const char* project,const char* logstore,log_group_builder* bder) +{ + aos_string_t project_name; + aos_string_t logstore_name; + aos_string_t _endpoint; + aos_string_t _access_key_id; + aos_string_t _access_key_secret; + aos_string_t _sts_token; + + aos_table_t *headers = NULL; + + aos_table_t *query_params = NULL; + + aos_str_set(&(_endpoint), endpoint); + aos_str_set(&(_access_key_id), accesskeyId); + aos_str_set(&(_access_key_secret), accessKey); + + if(stsToken != NULL) + aos_str_set(&(_sts_token), stsToken); + + + headers = aos_table_make(bder->root, 5); + apr_table_set(headers, LOG_API_VERSION, "0.6.0"); + apr_table_set(headers, LOG_COMPRESS_TYPE, "lz4"); + apr_table_set(headers, LOG_SIGNATURE_METHOD, "hmac-sha1"); + apr_table_set(headers, LOG_CONTENT_TYPE, "application/x-protobuf"); + aos_str_set(&project_name, project); + aos_str_set(&logstore_name, logstore); + if (stsToken != NULL) + { + apr_table_set(headers, ACS_SECURITY_TOKEN, stsToken); + } + + log_buf* buff = serialize_to_proto_buf(bder); + apr_table_set(headers, LOG_BODY_RAW_SIZE, apr_itoa(bder->root, buff->length)); + buff = _compressed_buffer(bder->root, buff); + + char* b64_value = _get_md5(bder->root, buff); + apr_table_set(headers, LOG_CONTENT_MD5, b64_value); + char* url = _get_url(bder->root, _endpoint, logstore_name, project_name); + + char *resource = apr_psprintf(bder->root, "logstores/%.*s/shards/lb",(int)logstore_name.len, logstore_name.data); + aos_string_t canon_res; + char canon_buf[AOS_MAX_URI_LEN]; + char datestr[AOS_MAX_GMT_TIME_LEN]; + const char *value; + canon_res.data = canon_buf; + canon_res.len = apr_snprintf(canon_buf, sizeof(canon_buf), "/%s",resource); + + if ((value = apr_table_get(headers, LOG_CANNONICALIZED_HEADER_DATE)) == NULL) { + aos_get_gmt_str_time(datestr); + apr_table_set(headers, LOG_DATE, datestr); + } + + aos_string_t signstr; + log_get_string_to_sign(bder->root, HTTP_POST, &canon_res, + headers, query_params, &signstr); + log_sign_headers(bder->root, &signstr, &_access_key_id, &_access_key_secret, headers); + + log_http_cont* cont_out = (log_http_cont*)apr_palloc(bder->root, sizeof(log_http_cont)); + cont_out->body.data = buff->data; + cont_out->body.length = buff->length; + cont_out->root = bder->root; + cont_out->headers = headers; + cont_out->url = url; + + return cont_out; +} + diff --git a/src/log_http_cont.h b/src/log_http_cont.h new file mode 100644 index 0000000..ee483d3 --- /dev/null +++ b/src/log_http_cont.h @@ -0,0 +1,21 @@ +// +// log_http_cont.h +// log-c-sdk-new +// +// Created by 王佳玮 on 16/8/31. +// Copyright © 2016年 wangjwchn. All rights reserved. +// + +#ifndef log_http_cont_h +#define log_http_cont_h + +#include "aos_util.h" +#include "aos_log.h" +#include "log_define.h" +#include "log_builder.h" + +log_http_cont* log_create_http_cont(const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken,const char* project,const char* logstore,log_group_builder* bder); + +void log_clean_http_cont(log_http_cont* cont); + +#endif /* log_http_cont_h */ diff --git a/src/log_util.c b/src/log_util.c index db124f9..a33393e 100644 --- a/src/log_util.c +++ b/src/log_util.c @@ -66,6 +66,9 @@ void log_post_logs_uri(const log_request_options_t *options, req->host = apr_psprintf(options->pool, "%.*s.%.*s", project->len, project->data, raw_endpoint.len, raw_endpoint.data); + + //req->uri = apr_psprintf(options->pool, "%.*s%.*s/logstores/%.*s/shards/lb", (int)strlen(req->proto),req->proto,(int)strlen(req->host), req->host,logstore->len, logstore->data); + req->uri = apr_psprintf(options->pool, "logstores/%.*s/shards/lb", logstore->len, logstore->data); } diff --git a/src/log_util.h b/src/log_util.h index d54b916..65d8482 100644 --- a/src/log_util.h +++ b/src/log_util.h @@ -43,6 +43,11 @@ aos_status_t *log_post_logs_from_buffer(const log_request_options_t *options, aos_table_t *headers, aos_table_t **resp_headers); aos_table_t* aos_table_create_if_null(const log_request_options_t *options, aos_table_t *table, int table_size); - +void log_init_request(const log_request_options_t *options, + http_method_e method, + aos_http_request_t **req, + aos_table_t *params, + aos_table_t *headers, + aos_http_response_t **resp); LOG_CPP_END #endif