add http_version_string() to utils
This commit is contained in:
parent
3d058707b1
commit
2fb007bd3d
|
@ -32,6 +32,8 @@ LI_API void path_simplify(GString *path);
|
|||
LI_API gchar *http_status_string(guint status_code, guint *len);
|
||||
/* returns the http method as a string and sets len to the length of the returned string */
|
||||
LI_API gchar *http_method_string(http_method_t method, guint *len);
|
||||
/* returns the http version as a string and sets len to the length of the returned string */
|
||||
LI_API gchar *http_version_string(http_version_t method, guint *len);
|
||||
/* converts a given 3 digit http status code to a gchar[3] string. e.g. 403 to {'4','0','3'} */
|
||||
LI_API void http_status_to_str(gint status_code, gchar status_str[]);
|
||||
|
||||
|
@ -58,4 +60,6 @@ LI_API GString *sockaddr_to_string(sock_addr *saddr, GString *dest);
|
|||
LI_API sockaddr sockaddr_from_string(GString *str, guint tcp_default_port);
|
||||
LI_API void sockaddr_clear(sockaddr *saddr);
|
||||
|
||||
LI_API void gstring_replace_char_with_str_len(GString *gstr, gchar c, gchar *str, guint len);
|
||||
|
||||
#endif
|
||||
|
|
16
src/utils.c
16
src/utils.c
|
@ -276,6 +276,17 @@ gchar *http_method_string(http_method_t method, guint *len) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
gchar *http_version_string(http_version_t method, guint *len) {
|
||||
switch (method) {
|
||||
case HTTP_VERSION_1_1: SET_LEN_AND_RETURN_STR("HTTP/1.1");
|
||||
case HTTP_VERSION_1_0: SET_LEN_AND_RETURN_STR("HTTP/1.0");
|
||||
case HTTP_VERSION_UNSET: SET_LEN_AND_RETURN_STR("HTTP/??");
|
||||
}
|
||||
|
||||
*len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#undef SET_LEN_AND_RETURN_STR
|
||||
|
||||
void http_status_to_str(gint status_code, gchar status_str[]) {
|
||||
|
@ -429,6 +440,7 @@ GString *counter_format2(guint64 count, counter_type t, gint accuracy) {
|
|||
return str;
|
||||
}
|
||||
|
||||
|
||||
gchar *ev_backend_string(guint backend) {
|
||||
switch (backend) {
|
||||
case EVBACKEND_SELECT: return "select";
|
||||
|
@ -448,12 +460,12 @@ void string_destroy_notify(gpointer str) {
|
|||
|
||||
|
||||
guint hash_ipv4(gconstpointer key) {
|
||||
return *((guint*)key);
|
||||
return *((guint*)key) * 2654435761;
|
||||
}
|
||||
|
||||
guint hash_ipv6(gconstpointer key) {
|
||||
guint *i = ((guint*)key);
|
||||
return i[0] ^ i[1] ^ i[2] ^ i[3];
|
||||
return (i[0] ^ i[1] ^ i[2] ^ i[3]) * 2654435761;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue