forked from vmrp/mrpdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrc_network_http.h
171 lines (134 loc) · 3.7 KB
/
mrc_network_http.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef _MRC_NETWORK_HTTP_H_
#define _MRC_NETWORK_HTTP_H_
#include "mrc_base.h"
#include "mrc_network.h"
/*
以下是基于HTTP协议的网络接口,
由于HTTP是基于socket上的数据包格式重定义,所以熟悉HTTP协议及socket开发
的朋友,可以自己开发定义,该部分的源码可以到freesky.51mrp.com上下载
*/
/**
* \brief max http header size in bytes
*/
#ifndef HTTP_HEADER_SIZE
#define HTTP_HEADER_SIZE 1024
#endif
/**
* \brief max field value length in response header
*/
#ifndef HTTP_FIELDVALUE_SIZE
#define HTTP_FIELDVALUE_SIZE 128
#endif
/**
* \brief supported http method
*/
typedef enum HTTP_METHOD_E
{
GET = 0, //"GET"
HEAD, //"HEAD"
POST//"POST"
}HTTPMETHOD;
/**
* \brief http events
*/
typedef enum HTTP_EVENT_E
{
/** sent when http socket connected */
HTTPEVT_CONNECTED = SOCKEVT_CONNECTED,
/** sent when http socket connect failed */
HTTPEVT_CONNECTFAILED = SOCKEVT_CONNECTFAILED,
/** sent when error happen */
HTTPEVT_ERROR = SOCKEVT_ERROR,
/** sent when socket closed */
HTTPEVT_CLOSED = SOCKEVT_CLOSED,
/** sent when get the http response header */
HTTPEVT_RESPONSE_HEADER,
/** sent when get the http response data */
HTTPEVT_RESPONSE_DATA,
/** sent when one http response finished */
HTTPEVT_RESPONSE_END
}HTTPEVENT;
/**
* 函数名称:mrc_Http_Initialize
* 函数功能: HTTP初始化
* 返回值:无
*/
VOID mrc_Http_Initialize(VOID);
/**
* \brief Terminate the http module.
*
* When the http module is not needed by the application anymore, this function could
* be called to release the http module.
*
* \sa Socket_Initialize
*/
VOID mrc_Http_Terminate(VOID);
/**
* \brief Open a socket for http.
*
* \param ip_string the server ip address or host name,just like 192.168.0.1 or http://www.163.com
* only the authorization user can use this function
* \param port the server port number
* \param fnEvent the http events handler
* \return http socket handle on success, NULL otherwise
*/
PSOCKET mrc_Http_OpenEx(char*ip_string,uint16 port,FN_SOCKEVENT fnEvent);
/**
* \brief Close a http socket .
*
* \param socket the socket handle
* \param evt the close event
* \return TRUE on success, FALSE otherwise
*/
BOOL mrc_Http_Close(PSOCKET socket, DWORD evt);
/**
* \brief Send http get command.
*
* \param socket the http socket handle
* \param url the request url
* \param from the start position of the content
* \param to the end position of the content
* \return TRUE on success, FALSE otherwise
*/
BOOL mrc_Http_GetEx(PSOCKET socket, PCSTR url, uint32 from, uint32 to);
/**
* \brief Post the http data.
*
* \param socket the http socket
* \param url the request url
* \param buffer the post data
* \param size post data size
* \return TRUE on success, FALSE otherwise
*/
BOOL mrc_Http_PostEx(PSOCKET socket, PCSTR url, PCSTR buffer, uint32 size);
/**
* \brief Get the http response code.
*
* This can only be called after receive the EVENT HTTPEVT_RESPONSE_HEADER event.
* otherwise undefined.
*
* \param socket the http socket handle
* \return the response code
*/
uint32 mrc_Http_GetResponseCode(PSOCKET socket);
/**
* \brief Get the field value of the http header
*
* This can only be called after receive the EVENT HTTPEVT_RESPONSE_HEADER event.
* otherwise undefined.
*
* \param socket the http socket handle
* \param field the http header field
* \return the value of the filed on success, NULL otherwise
*/
PCSTR mrc_Http_GetResponseField(PSOCKET socket, PCSTR field);
/**
* \brief Get http response head content
*
*\param socket the http socket handle
* \param buffer the http head point
*\param size the http head data length
* \return the value of MR_SUCCESS on success, MR_FAILED otherwise
*/
int mrc_Http_GetResponseHead(PSOCKET socket,uint8** buf, uint32* size);
#endif