Added ndpi_http_method ndpi_http_str2method(const char* method) API call

This commit is contained in:
Luca Deri
2020-08-26 23:17:19 +02:00
parent 487d915262
commit 2e8aa9f08e
3 changed files with 33 additions and 26 deletions
+3
View File
@@ -929,6 +929,9 @@ extern "C" {
void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]); void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]);
const char* ndpi_http_method2str(ndpi_http_method m);
ndpi_http_method ndpi_http_str2method(const char* method);
/* ptree (trie) API */ /* ptree (trie) API */
ndpi_ptree_t* ndpi_ptree_create(void); ndpi_ptree_t* ndpi_ptree_create(void);
int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, u_int32_t user_data); int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, u_int32_t user_data);
+25 -1
View File
@@ -1550,7 +1550,7 @@ const char* ndpi_risk2str(ndpi_risk_enum risk) {
const char* ndpi_http_method2str(ndpi_http_method m) { const char* ndpi_http_method2str(ndpi_http_method m) {
switch(m) { switch(m) {
// case NDPI_HTTP_METHOD_UNKNOWN: return("Unknown"); case NDPI_HTTP_METHOD_UNKNOWN: break;
case NDPI_HTTP_METHOD_OPTIONS: return("OPTIONS"); case NDPI_HTTP_METHOD_OPTIONS: return("OPTIONS");
case NDPI_HTTP_METHOD_GET: return("GET"); case NDPI_HTTP_METHOD_GET: return("GET");
case NDPI_HTTP_METHOD_HEAD: return("HEAD"); case NDPI_HTTP_METHOD_HEAD: return("HEAD");
@@ -1564,3 +1564,27 @@ const char* ndpi_http_method2str(ndpi_http_method m) {
return("Unknown HTTP method"); return("Unknown HTTP method");
} }
/* ******************************************************************** */
ndpi_http_method ndpi_http_str2method(const char* method) {
switch(method[0]) {
case 'O': return(NDPI_HTTP_METHOD_OPTIONS);
case 'G': return(NDPI_HTTP_METHOD_GET);
case 'H': return(NDPI_HTTP_METHOD_HEAD);
case 'P':
switch(method[1]) {
case 'A':return(NDPI_HTTP_METHOD_PATCH);
case 'O':return(NDPI_HTTP_METHOD_POST);
case 'U':return(NDPI_HTTP_METHOD_PUT);
}
break;
case 'D': return(NDPI_HTTP_METHOD_DELETE);
case 'T': return(NDPI_HTTP_METHOD_TRACE);
case 'C': return(NDPI_HTTP_METHOD_CONNECT);
}
return(NDPI_HTTP_METHOD_UNKNOWN);
}
+2 -22
View File
@@ -339,28 +339,8 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if(flow->packet.http_method.len < 3) if(flow->packet.http_method.len < 3)
flow->http.method = NDPI_HTTP_METHOD_UNKNOWN; flow->http.method = NDPI_HTTP_METHOD_UNKNOWN;
else { else
switch(flow->packet.http_method.ptr[0]) { flow->http.method = ndpi_http_str2method((const char*)flow->packet.http_method.ptr);
case 'O': flow->http.method = NDPI_HTTP_METHOD_OPTIONS; break;
case 'G': flow->http.method = NDPI_HTTP_METHOD_GET; break;
case 'H': flow->http.method = NDPI_HTTP_METHOD_HEAD; break;
case 'P':
switch(flow->packet.http_method.ptr[1]) {
case 'A': flow->http.method = NDPI_HTTP_METHOD_PATCH; break;
case 'O': flow->http.method = NDPI_HTTP_METHOD_POST; break;
case 'U': flow->http.method = NDPI_HTTP_METHOD_PUT; break;
}
break;
case 'D': flow->http.method = NDPI_HTTP_METHOD_DELETE; break;
case 'T': flow->http.method = NDPI_HTTP_METHOD_TRACE; break;
case 'C': flow->http.method = NDPI_HTTP_METHOD_CONNECT; break;
default:
flow->http.method = NDPI_HTTP_METHOD_UNKNOWN;
break;
}
}
} }
if(packet->user_agent_line.ptr != NULL && packet->user_agent_line.len != 0) { if(packet->user_agent_line.ptr != NULL && packet->user_agent_line.len != 0) {