Skip to content

Commit ccb223e

Browse files
committed
first add httpclient
0 parents  commit ccb223e

File tree

241 files changed

+117759
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+117759
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

CMakeLists.txt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
project(http-client)
4+
5+
set(TARGETS "http-client")
6+
set(SUBDIRS "test" "platform" "network" "common" "httpclient")
7+
set(INCDIRS "platform/linux" "common" "common/log" "common/mbedtls/include" "network" "httpclient")
8+
set(OUTDIRS "build")
9+
set(LIBNAMES "platform" "network" "common" "salof" "mbedtls" "httpclient")
10+
set(CMAKE_C_COMPILER "gcc")
11+
set(CMAKE_CXX_COMPILER "clang++" )
12+
set(CMAKE_BUILE_TYPE "RELEASE")
13+
set(PROJECT_ROOT_PATH "${PROJECT_SOURCE_DIR}")
14+
set(LIBRARY_OUTPUT_PATH "${PROJECT_ROOT_PATH}/${OUTDIRS}/lib/")
15+
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_ROOT_PATH}/${OUTDIRS}/bin/")
16+
17+
set(CMAKE_C_FLAGS "-Wall")
18+
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb")
19+
set(CMAKE_C_FLAGS_RELEASE "-O1 -DNDEBUG ")
20+
21+
if(CMAKE_COMPILER_IS_GNUCXX)
22+
set(CMAKE_CXX_FLAGS "-std=c++11")
23+
set(CMAKE_CXX_FLAGS "-lpthread")
24+
set(CMAKE_CXX_FLAGS "-g")
25+
set(CMAKE_CXX_FLAGS "-Wall")
26+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb")
27+
endif(CMAKE_COMPILER_IS_GNUCXX)
28+
29+
foreach(incdir ${INCDIRS})
30+
include_directories(${incdir})
31+
endforeach()
32+
33+
foreach(subdir ${SUBDIRS})
34+
add_subdirectory(${PROJECT_ROOT_PATH}/${subdir})
35+
endforeach()
36+
37+
link_directories(${LIBRARY_OUTPUT_PATH})
38+

LICENSE

+674
Large diffs are not rendered by default.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# httpclient
2+
3+
一个基于socket API之上的跨平台HTTP客户端,拥有非常简洁的API接口,以极少的资源实现HTTP/HTTPS协议,并且无缝衔接了mbedtls加密库。

build.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
mkdir -p build build/bin build/lib
4+
cd build
5+
cmake ..
6+
make

common/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set(SUBDIRS "log" "mbedtls")
2+
3+
aux_source_directory(. DIR_SRCS)
4+
5+
string(REGEX REPLACE ".*/(.*)" "\\1" LIB_NAME ${CMAKE_CURRENT_SOURCE_DIR})
6+
7+
if (DIR_SRCS)
8+
foreach(libname ${LIBNAMES})
9+
if (${LIB_NAME} STREQUAL ${libname})
10+
add_library(${libname} STATIC ${DIR_SRCS})
11+
endif()
12+
endforeach()
13+
14+
else()
15+
message(WARNING "not find is src file!")
16+
endif()
17+
18+
19+
foreach(subdir ${SUBDIRS})
20+
add_subdirectory(${subdir})
21+
endforeach()

common/error.h

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @Author: jiejie
3+
* @Github: https://github.com/jiejieTop
4+
* @Date: 2019-12-15 00:42:16
5+
* @LastEditTime : 2020-01-10 01:01:26
6+
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
7+
*/
8+
#ifndef _ERROR_H_
9+
#define _ERROR_H_
10+
11+
typedef enum http_error {
12+
HTTP_SOCKET_FAILED = -0x001B, /* socket fd failed */
13+
HTTP_SOCKET_UNKNOWN_HOST = -0x001A, /* socket unknown host ip or domain */
14+
HTTP_SET_PUBLISH_DUP_FAILED = -0x0019, /* http publish packet set udp bit failed */
15+
HTTP_CLOSE_SESSION_ERROR = -0x0018, /* http close session error */
16+
HTTP_ACK_NODE_IS_EXIST = -0x0017, /* http ack list is exist ack node */
17+
HTTP_ACK_HANDLER_NUM_TOO_MUCH = -0x0016, /* http ack handler number is too much */
18+
HTTP_RESUBSCRIBE_ERROR = -0x0015, /* http resubscribe error */
19+
HTTP_SUBSCRIBE_ERROR = -0x0014, /* http subscribe error */
20+
HTTP_SEND_PACKET_ERROR = -0x0013, /* http send a packet */
21+
HTTP_SERIALIZE_PUBLISH_ACK_PACKET_ERROR = -0x0012, /* http serialize publish ack packet error */
22+
HTTP_PUBLISH_PACKET_ERROR = -0x0011, /* http publish packet error */
23+
HTTP_RECONNECT_TIMEOUT_ERROR = -0x0010, /* http try reconnect, but timeout */
24+
HTTP_SUBSCRIBE_NOT_ACK_ERROR = -0x000F, /* http subscribe, but not ack */
25+
HTTP_NOT_CONNECT_ERROR = -0x000E, /* http not connect */
26+
HTTP_SUBSCRIBE_ACK_PACKET_ERROR = -0x000D, /* http subscribe, but ack packet error */
27+
HTTP_UNSUBSCRIBE_ACK_PACKET_ERROR = -0x000C, /* http unsubscribe, but ack packet error */
28+
HTTP_PUBLISH_ACK_PACKET_ERROR = -0x000B, /* http pubilsh ack packet error */
29+
HTTP_PUBLISH_ACK_TYPE_ERROR = -0x000A, /* http pubilsh ack type error */
30+
HTTP_PUBREC_PACKET_ERROR = -0x0009, /* http pubrec packet error */
31+
HTTP_BUFFER_TOO_SHORT_ERROR = -0x0008, /* http buffer too short */
32+
HTTP_NOTHING_TO_READ_ERROR = -0x0007, /* http nothing to read */
33+
HTTP_SUBSCRIBE_QOS_ERROR = -0x0006, /* http subsrcibe qos error */
34+
HTTP_BUFFER_OVERFLOW_ERROR = -0x0005, /* http buffer overflow */
35+
HTTP_CONNECT_FAILED_ERROR = -0x0004, /* http connect failed */
36+
HTTP_MEM_NOT_ENOUGH_ERROR = -0x0003, /* http memory not enough */
37+
HTTP_NULL_VALUE_ERROR = -0x0002, /* http value is null */
38+
HTTP_FAILED_ERROR = -0x0001, /* failed */
39+
HTTP_SUCCESS_ERROR = 0x0000 /* success */
40+
} http_error_t;
41+
42+
#define RETURN_ERROR(x) { return x; }
43+
44+
#endif

common/list.c

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* @Author: jiejie
3+
* @Github: https://github.com/jiejieTop
4+
* @Date: 2019-12-11 22:46:33
5+
* @LastEditTime : 2020-01-05 17:01:51
6+
* @Description: the following code references TencentOS tiny, please keep the author information and source code according to the license.
7+
*/
8+
9+
# include "list.h"
10+
11+
static void _list_add(list_t *node, list_t *prev, list_t *next)
12+
{
13+
next->prev = node;
14+
node->next = next;
15+
node->prev = prev;
16+
prev->next = node;
17+
}
18+
19+
static void _list_del(list_t *prev, list_t *next)
20+
{
21+
next->prev = prev;
22+
prev->next = next;
23+
}
24+
25+
static void _list_del_entry(list_t *entry)
26+
{
27+
_list_del(entry->prev, entry->next);
28+
}
29+
30+
void list_init(list_t *list)
31+
{
32+
list->next = list;
33+
list->prev = list;
34+
}
35+
36+
void list_add(list_t *node, list_t *list)
37+
{
38+
_list_add(node, list, list->next);
39+
}
40+
41+
void list_add_tail(list_t *node, list_t *list)
42+
{
43+
_list_add(node, list->prev, list);
44+
}
45+
46+
void list_del(list_t *entry)
47+
{
48+
_list_del(entry->prev, entry->next);
49+
}
50+
51+
void list_del_init(list_t *entry)
52+
{
53+
_list_del_entry(entry);
54+
list_init(entry);
55+
}
56+
57+
void list_move(list_t *node, list_t *list)
58+
{
59+
_list_del_entry(node);
60+
list_add(node, list);
61+
}
62+
63+
void list_move_tail(list_t *node, list_t *list)
64+
{
65+
_list_del_entry(node);
66+
list_add_tail(node, list);
67+
}
68+
69+
int list_is_empty(list_t *list)
70+
{
71+
return list->next == list;
72+
}

common/list.h

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* @Author: jiejie
3+
* @Github: https://github.com/jiejieTop
4+
* @Date: 2019-12-11 22:47:55
5+
* @LastEditTime : 2020-01-08 20:39:26
6+
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
7+
*/
8+
#ifndef _LIST_H_
9+
#define _LIST_H_
10+
11+
typedef struct list_node {
12+
struct list_node *next;
13+
struct list_node *prev;
14+
} list_t;
15+
16+
#define OFFSET_OF_FIELD(type, field) \
17+
((size_t)&(((type *)0)->field))
18+
19+
#define CONTAINER_OF_FIELD(ptr, type, field) \
20+
((type *)((unsigned char *)(ptr) - OFFSET_OF_FIELD(type, field)))
21+
22+
#define LIST_NODE(node) \
23+
{ &(node), &(node) }
24+
25+
#define LIST_DEFINE(list) \
26+
list_t list = { &(list), &(list) }
27+
28+
#define LIST_ENTRY(list, type, field) \
29+
CONTAINER_OF_FIELD(list, type, field)
30+
31+
#define LIST_FIRST_ENTRY(list, type, field) \
32+
LIST_ENTRY((list)->next, type, field)
33+
34+
#define LIST_FIRST_ENTRY_OR_NULL(list, type, field) \
35+
(list_is_empty(list) ? NULL : LIST_FIRST_ENTRY(list, type, field))
36+
37+
#define LIST_FOR_EACH(curr, list) \
38+
for (curr = (list)->next; curr != (list); curr = curr->next)
39+
40+
#define LIST_FOR_EACH_PREV(curr, list) \
41+
for (curr = (list)->prev; curr != (list); curr = curr->prev)
42+
43+
#define LIST_FOR_EACH_SAFE(curr, next, list) \
44+
for (curr = (list)->next, next = curr->next; curr != (list); \
45+
curr = next, next = curr->next)
46+
47+
#define LIST_FOR_EACH_PREV_SAFE(curr, next, list) \
48+
for (curr = (list)->prev, next = curr->prev; \
49+
curr != (list); \
50+
curr = next, next = curr->prev)
51+
52+
void list_init(list_t *list);
53+
void list_add(list_t *node, list_t *list);
54+
void list_add_tail(list_t *node, list_t *list);
55+
void list_del(list_t *entry);
56+
void list_del_init(list_t *entry);
57+
void list_move(list_t *node, list_t *list);
58+
void list_move_tail(list_t *node, list_t *list);
59+
int list_is_empty(list_t *list);
60+
61+
#endif /* _LIST_H_ */
62+

common/log.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @Author: jiejie
3+
* @Github: https://github.com/jiejieTop
4+
* @Date: 2019-12-27 03:25:58
5+
* @LastEditTime : 2020-01-15 22:11:21
6+
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
7+
*/
8+
#ifndef _LOG_H_
9+
#define _LOG_H_
10+
11+
#define LOG_IS_SALOF 1
12+
13+
#if LOG_IS_SALOF
14+
#include "salof.h"
15+
16+
#define LOG_D(fmt, ...) LOG_DEBUG(fmt, ##__VA_ARGS__)
17+
#define LOG_I(fmt, ...) LOG_INFO(fmt, ##__VA_ARGS__)
18+
#define LOG_W(fmt, ...) LOG_WARN(fmt, ##__VA_ARGS__)
19+
#define LOG_E(fmt, ...) LOG_ERR(fmt, ##__VA_ARGS__)
20+
#define log_init salof_init
21+
#else
22+
#include <stdio.h>
23+
#define LOG_D(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
24+
#define LOG_I(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
25+
#define LOG_W(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
26+
#define LOG_E(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
27+
#define log_init()
28+
#endif
29+
30+
31+
#endif /* _LOG_H_ */

common/log/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required (VERSION 2.8)
2+
3+
set(INCDIRS ${CMAKE_CURRENT_SOURCE_DIR})
4+
set(SUBDIRS "arch")
5+
set(LIBNAMES "arch" "salof")
6+
set(OUTDIRS "build")
7+
8+
aux_source_directory(. LOG_DIR_SRCS)
9+
10+
add_library("salof" STATIC ${LOG_DIR_SRCS})
11+
target_link_libraries("salof" "arch")
12+
13+
foreach(incdir ${INCDIRS})
14+
include_directories(${incdir})
15+
endforeach()
16+
17+
foreach(subdir ${SUBDIRS})
18+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${subdir})
19+
endforeach()
20+
21+
link_directories(${LIBRARY_OUTPUT_PATH})

common/log/arch/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(SUBDIRS "linux")
2+
3+
foreach(subdir ${SUBDIRS})
4+
add_subdirectory(${subdir})
5+
endforeach()
6+
7+

0 commit comments

Comments
 (0)