summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/stellar/http.h77
-rw-r--r--include/stellar/utils.h2
2 files changed, 40 insertions, 39 deletions
diff --git a/include/stellar/http.h b/include/stellar/http.h
index 1cc5bec..5f8fe80 100644
--- a/include/stellar/http.h
+++ b/include/stellar/http.h
@@ -12,16 +12,12 @@ extern "C"
{
HTTP_TRANSACTION_START,
- HTTP_MESSAGE_REQ_LINE,
- HTTP_MESSAGE_REQ_HEADER,
- HTTP_MESSAGE_REQ_HEADER_END, // todo, delete END, push all fileds at once
+ HTTP_MESSAGE_REQ_LINE_HEADERS,
HTTP_MESSAGE_REQ_BODY_START,
HTTP_MESSAGE_REQ_BODY,
HTTP_MESSAGE_REQ_BODY_END,
- HTTP_MESSAGE_RES_LINE,
- HTTP_MESSAGE_RES_HEADER,
- HTTP_MESSAGE_RES_HEADER_END, // todo, delete END, push all fileds at once
+ HTTP_MESSAGE_RES_LINE_HEADERS,
HTTP_MESSAGE_RES_BODY_START,
HTTP_MESSAGE_RES_BODY,
HTTP_MESSAGE_RES_BODY_END,
@@ -31,32 +27,44 @@ extern "C"
HTTP_MESSAGE_MAX
};
+ enum http_method_type
+ {
+ HTTP_METHOD_DELETE = 0,
+ HTTP_METHOD_GET = 1,
+ HTTP_METHOD_HEAD = 2,
+ HTTP_METHOD_POST = 3,
+ HTTP_METHOD_PUT = 4,
+ HTTP_METHOD_CONNECT = 5,
+ HTTP_METHOD_OPTIONS = 6,
+
+ HTTP_METHOD_UNKNOWN = 255,
+ };
+
struct http_header_field
{
- char *name;
+ const char *name;
size_t name_len;
- char *value;
+ const char *value;
size_t value_len;
};
struct http_request_line
{
- char *method;
+ const char *method;
size_t method_len;
- char *uri;
+ const char *uri;
size_t uri_len;
- char *version;
+ const char *version;
size_t version_len;
-
int major_version;
int minor_version;
};
struct http_response_line
{
- char *version;
+ const char *version;
size_t version_len;
- char *status;
+ const char *status;
size_t status_len;
int major_version;
int minor_version;
@@ -64,47 +72,40 @@ extern "C"
};
enum http_message_type http_message_get_type(const struct http_message *msg);
+ enum http_method_type http_get_method(const char *method, size_t method_len);
+ const struct http_request_line *http_message_get0_request_line(const struct http_message *msg);
+ const struct http_response_line *http_message_get0_response_line(const struct http_message *msg);
- void http_message_get0_request_line(const struct http_message *msg, struct http_request_line *line);
-
- void http_message_get0_response_line(const struct http_message *msg, struct http_response_line *line);
+ void http_message_get0_headers_intergration(const struct http_message *msg, const char **headers, size_t *headers_len);
/*
- * Pay attention: key->iov_base is case-insensitive.
- */
- void http_message_get0_header(const struct http_message *msg, const char *name, size_t name_len, struct http_header_field *field_result);
-
- /**
- * @brief loop reading all headers.
- *
- * @retval succeed( >= 0) failed(-1)
+ * Pay attention: field name is case-insensitive.
*/
- int http_message_get0_next_header(const struct http_message *msg, struct http_header_field *header);
+ const struct http_header_field *http_message_get0_header(const struct http_message *msg, const char *field_name, size_t field_name_len);
/**
- * @retval succeed( >= 0) failed(-1)
+ * The first time, set param 'header' as NULL, and the subsequent calls use return value until result is NULL.
+ * return value:
+ * not-NULL: success
+ * NULL: empty or EOF
*/
- int http_message_reset_header_iter(struct http_message *msg); // to do , obsoleted
-
- void http_message_get0_uncompressed_body(const struct http_message *msg, const char **body, size_t *body_len);
+ const struct http_header_field *http_message_get0_next_header(const struct http_message *msg, const struct http_header_field *header);
- /**
- * @brief If the body hasn't been compressed, same as http_message_get0_uncompressed_body().
- *
- */
- void http_message_get0_decompressed_body(const struct http_message *msg, const char **body, size_t *body_len);
+ void http_message_get0_uncompressed_body(const struct http_message *msg, const char **uncompressed_body, size_t *uncompressed_len);
+ void http_message_get0_decompressed_body(const struct http_message *msg, const char **decompressed_body, size_t *decompressed_len);
void http_message_get0_raw_url(const struct http_message *msg, const char **url, size_t *url_len);
-
/*
return value:
0: failed
- >1: success, length of decoded_url_buffer, not C string( no EOF with '\0' )
+ >1: success, length of decoded url. Pay attention: decoded url is not C string (no EOF with '\0')!
*/
size_t http_url_decode(const char *raw_url, size_t raw_url_len, char *decoded_url_buffer, size_t decoded_url_buffer_len);
/**
- * @retval succeed( >= 0) failed(-1)
+ * return value:
+ * >= 0 : success
+ * -1: failed
*/
int http_message_get_transaction_seq(const struct http_message *msg);
diff --git a/include/stellar/utils.h b/include/stellar/utils.h
index 3d6ab43..826ced0 100644
--- a/include/stellar/utils.h
+++ b/include/stellar/utils.h
@@ -10,7 +10,7 @@
#define FREE(p) \
{ \
- free(p); \
+ free((void *)p); \
p = NULL; \
}