Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: code simplification #10368

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/app-layer-htp-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern StreamingBufferConfig htp_sbcfg;
* \retval -2 not handling files on this flow
*/
int HTPFileOpen(HtpState *s, HtpTxUserData *tx, const uint8_t *filename, uint16_t filename_len,
const uint8_t *data, uint32_t data_len, uint64_t txid, uint8_t direction)
const uint8_t *data, uint32_t data_len, uint8_t direction)
{
int retval = 0;
uint16_t flags = 0;
Expand Down Expand Up @@ -147,8 +147,8 @@ static int HTPParseAndCheckContentRange(
* \retval -1 error
*/
int HTPFileOpenWithRange(HtpState *s, HtpTxUserData *txud, const uint8_t *filename,
uint16_t filename_len, const uint8_t *data, uint32_t data_len, uint64_t txid,
bstr *rawvalue, HtpTxUserData *htud)
uint16_t filename_len, const uint8_t *data, uint32_t data_len, htp_tx_t *tx, bstr *rawvalue,
HtpTxUserData *htud)
{
SCEnter();
uint16_t flags;
Expand All @@ -159,7 +159,7 @@ int HTPFileOpenWithRange(HtpState *s, HtpTxUserData *txud, const uint8_t *filena
HTTPContentRange crparsed;
if (HTPParseAndCheckContentRange(rawvalue, &crparsed, s, htud) != 0) {
// range is invalid, fall back to classic open
return HTPFileOpen(s, txud, filename, filename_len, data, data_len, txid, STREAM_TOCLIENT);
return HTPFileOpen(s, txud, filename, filename_len, data, data_len, STREAM_TOCLIENT);
}
flags = FileFlowToFlags(s->f, STREAM_TOCLIENT);
FileContainer *files = &txud->files_tc;
Expand All @@ -179,11 +179,6 @@ int HTPFileOpenWithRange(HtpState *s, HtpTxUserData *txud, const uint8_t *filena
}

// Then, we will try to handle reassembly of different ranges of the same file
// TODO have the caller pass directly the tx
htp_tx_t *tx = htp_list_get(s->conn->transactions, txid - s->tx_freed);
if (!tx) {
SCReturnInt(-1);
}
uint8_t *keyurl;
uint32_t keylen;
if (tx->request_hostname != NULL) {
Expand Down
6 changes: 3 additions & 3 deletions src/app-layer-htp-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

#include "app-layer-htp.h"

int HTPFileOpen(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *, uint32_t,
uint64_t, uint8_t);
int HTPFileOpen(
HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint8_t);
int HTPFileOpenWithRange(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *,
uint32_t, uint64_t, bstr *rawvalue, HtpTxUserData *htud);
uint32_t, htp_tx_t *, bstr *rawvalue, HtpTxUserData *htud);
bool HTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *, const uint16_t,
HttpRangeContainerBlock *, const uint8_t *, uint32_t);
int HTPFileStoreChunk(HtpState *, HtpTxUserData *, const uint8_t *, uint32_t, uint8_t);
Expand Down
12 changes: 6 additions & 6 deletions src/app-layer-htp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud,
#endif

result = HTPFileOpen(hstate, htud, filename, filename_len, filedata, filedata_len,
HtpGetActiveRequestTxID(hstate), STREAM_TOSERVER);
STREAM_TOSERVER);
if (result == -1) {
goto end;
} else if (result == -2) {
Expand Down Expand Up @@ -1633,7 +1633,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud,
filedata_len = 0;
}
result = HTPFileOpen(hstate, htud, filename, filename_len, filedata,
filedata_len, HtpGetActiveRequestTxID(hstate), STREAM_TOSERVER);
filedata_len, STREAM_TOSERVER);
if (result == -1) {
goto end;
} else if (result == -2) {
Expand All @@ -1648,7 +1648,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud,
SCLogDebug("filedata_len %u", filedata_len);

result = HTPFileOpen(hstate, htud, filename, filename_len, filedata,
filedata_len, HtpGetActiveRequestTxID(hstate), STREAM_TOSERVER);
filedata_len, STREAM_TOSERVER);
if (result == -1) {
goto end;
} else if (result == -2) {
Expand Down Expand Up @@ -1725,7 +1725,7 @@ static int HtpRequestBodyHandlePOSTorPUT(HtpState *hstate, HtpTxUserData *htud,
HTPSetEvent(hstate, htud, STREAM_TOSERVER, HTTP_DECODER_EVENT_FILE_NAME_TOO_LONG);
}
result = HTPFileOpen(hstate, htud, filename, (uint16_t)filename_len, data, data_len,
HtpGetActiveRequestTxID(hstate), STREAM_TOSERVER);
STREAM_TOSERVER);
if (result == -1) {
goto end;
} else if (result == -2) {
Expand Down Expand Up @@ -1802,10 +1802,10 @@ static int HtpResponseBodyHandle(HtpState *hstate, HtpTxUserData *htud,
}
if (h_content_range != NULL) {
result = HTPFileOpenWithRange(hstate, htud, filename, (uint16_t)filename_len, data,
data_len, HtpGetActiveResponseTxID(hstate), h_content_range->value, htud);
data_len, tx, h_content_range->value, htud);
} else {
result = HTPFileOpen(hstate, htud, filename, (uint16_t)filename_len, data, data_len,
HtpGetActiveResponseTxID(hstate), STREAM_TOCLIENT);
STREAM_TOCLIENT);
}
SCLogDebug("result %d", result);
if (result == -1) {
Expand Down
Loading