if (tx != NULL) {
HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
if (tx_ud->request_uri_normalized != NULL) {
- char *s = SCStrndup((char *) bstr_ptr(tx_ud->request_uri_normalized),
- bstr_len(tx_ud->request_uri_normalized));
- js = json_string(s);
- if (s != NULL)
+ char *s = bstr_util_strdup_to_c(tx_ud->request_uri_normalized);
+ if (s != NULL) {
+ js = json_string(s);
SCFree(s);
+ }
}
return js;
}
if (htp_state != NULL) {
htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, htp_state, ff->txid);
if (tx != NULL && tx->request_hostname != NULL) {
- char *s = SCStrndup((char *) bstr_ptr(tx->request_hostname),
- bstr_len(tx->request_hostname));
- js = json_string(s);
- if (s != NULL)
+ char *s = bstr_util_strdup_to_c(tx->request_hostname);
+ if (s != NULL) {
+ js = json_string(s);
SCFree(s);
+ }
return js;
}
}
h = (htp_header_t *)htp_table_get_c(tx->request_headers,
"Referer");
if (h != NULL) {
- char *s = SCStrndup((char *)bstr_ptr(h->value),
- bstr_len(h->value));
- js = json_string(s);
- if (s != NULL)
+ char *s = bstr_util_strdup_to_c(h->value);
+ if (s != NULL) {
+ js = json_string(s);
SCFree(s);
+ }
return js;
}
}
h = (htp_header_t *)htp_table_get_c(tx->request_headers,
"User-Agent");
if (h != NULL) {
- char *s = SCStrndup((char *)bstr_ptr(h->value),
- bstr_len(h->value));
- js = json_string(s);
- if (s != NULL)
+ char *s = bstr_util_strdup_to_c(h->value);
+ if (s != NULL) {
+ js = json_string(s);
SCFree(s);
+ }
return js;
}
}
/* hostname */
if (tx->request_hostname != NULL)
{
- c = SCStrndup((char *)bstr_ptr(tx->request_hostname),
- bstr_len(tx->request_hostname));
+ c = bstr_util_strdup_to_c(tx->request_hostname);
if (c != NULL) {
json_object_set_new(hjs, "hostname", json_string(c));
SCFree(c);
/* uri */
if (tx->request_uri != NULL)
{
- c = SCStrndup((char *)bstr_ptr(tx->request_uri),
- bstr_len(tx->request_uri));
+ c = bstr_util_strdup_to_c(tx->request_uri);
if (c != NULL) {
json_object_set_new(hjs, "url", json_string(c));
SCFree(c);
h_user_agent = htp_table_get_c(tx->request_headers, "user-agent");
}
if (h_user_agent != NULL) {
- c = SCStrndup((char *)bstr_ptr(h_user_agent->value),
- bstr_len(h_user_agent->value));
+ c = bstr_util_strdup_to_c(h_user_agent->value);
if (c != NULL) {
json_object_set_new(hjs, "http_user_agent", json_string(c));
SCFree(c);
h_x_forwarded_for = htp_table_get_c(tx->request_headers, "x-forwarded-for");
}
if (h_x_forwarded_for != NULL) {
- c = SCStrndup((char *)bstr_ptr(h_x_forwarded_for->value),
- bstr_len(h_x_forwarded_for->value));
+ c = bstr_util_strdup_to_c(h_x_forwarded_for->value);
if (c != NULL) {
json_object_set_new(hjs, "xff", json_string(c));
SCFree(c);
}
if (h_content_type != NULL) {
char *p;
- c = SCStrndup((char *)bstr_ptr(h_content_type->value),
- bstr_len(h_content_type->value));
+ c = bstr_util_strdup_to_c(h_content_type->value);
if (c != NULL) {
p = strchrnul(c, ';');
*p = '\0';
h_referer = htp_table_get_c(tx->request_headers, "referer");
}
if (h_referer != NULL) {
- c = SCStrndup((char *)bstr_ptr(h_referer->value),
- bstr_len(h_referer->value));
+ c = bstr_util_strdup_to_c(h_referer->value);
if (c != NULL) {
json_object_set_new(hjs, "http_refer", json_string(c));
SCFree(c);
/* method */
if (tx->request_method != NULL) {
- c = SCStrndup((char *)bstr_ptr(tx->request_method),
- bstr_len(tx->request_method));
+ c = bstr_util_strdup_to_c(tx->request_method);
if (c != NULL) {
json_object_set_new(hjs, "http_method", json_string(c));
SCFree(c);
/* protocol */
if (tx->request_protocol != NULL) {
- c = SCStrndup((char *)bstr_ptr(tx->request_protocol),
- bstr_len(tx->request_protocol));
+ c = bstr_util_strdup_to_c(tx->request_protocol);
if (c != NULL) {
json_object_set_new(hjs, "protocol", json_string(c));
SCFree(c);
/* response status */
if (tx->response_status != NULL) {
- c = SCStrndup((char *)bstr_ptr(tx->response_status),
- bstr_len(tx->response_status));
+ c = bstr_util_strdup_to_c(tx->response_status);
if (c != NULL) {
json_object_set_new(hjs, "status", json_string(c));
SCFree(c);
htp_header_t *h_location = htp_table_get_c(tx->response_headers, "location");
if (h_location != NULL) {
- c = SCStrndup((char *)bstr_ptr(h_location->value),
- bstr_len(h_location->value));
+ c = bstr_util_strdup_to_c(h_location->value);
if (c != NULL) {
json_object_set_new(hjs, "redirect", json_string(c));
SCFree(c);