return enabled;
}
+#ifdef DEBUG
static void FrameDebug(const char *prefix, const Frames *frames, const Frame *frame)
{
-#ifdef DEBUG
const char *type_name = "unknown";
if (frame->type == FRAME_STREAM_TYPE) {
type_name = "stream";
prefix, frames, frame, frame->type, type_name, frame->id, frame->flags, frame->offset,
frame->len, frame->inspect_progress, frame->event_cnt, frame->events[0],
frame->events[1], frame->events[2], frame->events[3]);
-#endif
}
+#else
+#define FrameDebug(prefix, frames, frame)
+#endif
/**
* \note "open" means a frame that has no length set (len == -1)
memcpy(dst, src, sizeof(*dst));
}
+#ifdef DEBUG
static void AppLayerFrameDumpForFrames(const char *prefix, const Frames *frames)
{
SCLogDebug("prefix: %s", prefix);
}
SCLogDebug("prefix: %s", prefix);
}
+#endif
static inline uint64_t FrameLeftEdge(const TcpStream *stream, const Frame *frame)
{
void AppLayerFrameDump(Flow *f)
{
+#ifdef DEBUG
if (f->proto == IPPROTO_TCP && f->protoctx && f->alparser) {
FramesContainer *frames_container = AppLayerFramesGetContainer(f);
if (frames_container != NULL) {
AppLayerFrameDumpForFrames("toclient::dump", &frames_container->toclient);
}
}
+#endif
}
/** \brief create new frame using the absolute offset from the start of the stream
} FtpInput;
static AppLayerResult FTPGetLineForDirection(
- FtpState *state, FtpLineState *line, FtpInput *input, bool *current_line_truncated)
+ FtpLineState *line, FtpInput *input, bool *current_line_truncated)
{
SCEnter();
uint8_t direction = STREAM_TOSERVER;
AppLayerResult res;
while (1) {
- res = FTPGetLineForDirection(state, &line, &ftpi, &state->current_line_truncated_ts);
+ res = FTPGetLineForDirection(&line, &ftpi, &state->current_line_truncated_ts);
if (res.status == 1) {
return res;
} else if (res.status == -1) {
SCReturnStruct(APP_LAYER_OK);
}
-static int FTPParsePassiveResponse(Flow *f, FtpState *state, const uint8_t *input, uint32_t input_len)
+static int FTPParsePassiveResponse(FtpState *state, const uint8_t *input, uint32_t input_len)
{
uint16_t dyn_port = rs_ftp_pasv_response(input, input_len);
if (dyn_port == 0) {
return 0;
}
-static int FTPParsePassiveResponseV6(Flow *f, FtpState *state, const uint8_t *input, uint32_t input_len)
+static int FTPParsePassiveResponseV6(FtpState *state, const uint8_t *input, uint32_t input_len)
{
uint16_t dyn_port = rs_ftp_epsv_response(input, input_len);
if (dyn_port == 0) {
FTPTransaction *lasttx = TAILQ_FIRST(&state->tx_list);
AppLayerResult res;
while (1) {
- res = FTPGetLineForDirection(state, &line, &ftpi, &state->current_line_truncated_tc);
+ res = FTPGetLineForDirection(&line, &ftpi, &state->current_line_truncated_tc);
if (res.status == 1) {
return res;
} else if (res.status == -1) {
case FTP_COMMAND_PASV:
if (line.len >= 4 && SCMemcmp("227 ", line.buf, 4) == 0) {
- FTPParsePassiveResponse(f, ftp_state, line.buf, line.len);
+ FTPParsePassiveResponse(ftp_state, line.buf, line.len);
}
break;
case FTP_COMMAND_EPSV:
if (line.len >= 4 && SCMemcmp("229 ", line.buf, 4) == 0) {
- FTPParsePassiveResponseV6(f, ftp_state, line.buf, line.len);
+ FTPParsePassiveResponseV6(ftp_state, line.buf, line.len);
}
break;
default:
static void HtpTxUserDataFree(HtpState *state, HtpTxUserData *htud)
{
if (likely(htud)) {
- HtpBodyFree(&state->cfg->request, &htud->request_body);
- HtpBodyFree(&state->cfg->response, &htud->response_body);
+ HtpBodyFree(&htud->request_body);
+ HtpBodyFree(&htud->response_body);
bstr_free(htud->request_uri_normalized);
if (htud->request_headers_raw)
HTPFree(htud->request_headers_raw, htud->request_headers_raw_len);
(uint32_t)d->len);
BUG_ON(len > (uint32_t)d->len);
- HtpBodyAppendChunk(&hstate->cfg->request, &tx_ud->request_body, d->data, len);
+ HtpBodyAppendChunk(&tx_ud->request_body, d->data, len);
const uint8_t *chunks_buffer = NULL;
uint32_t chunks_buffer_len = 0;
(uint32_t)d->len);
BUG_ON(len > (uint32_t)d->len);
- HtpBodyAppendChunk(&hstate->cfg->response, &tx_ud->response_body, d->data, len);
+ HtpBodyAppendChunk(&tx_ud->response_body, d->data, len);
HtpResponseBodyHandle(hstate, tx_ud, d->tx, (uint8_t *)d->data, len);
} else {
uint8_t chunk1[] = "--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
uint8_t chunk2[] = "POST /uri HTTP/1.1\r\nHost: hostname.com\r\nKeep-Alive: 115\r\nAccept-Charset: utf-8\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nConnection: keep-alive\r\nContent-length: 68102\r\nReferer: http://otherhost.com\r\nAccept-Encoding: gzip\r\nContent-Type: multipart/form-data; boundary=e5a320f21416a02493a0a6f561b1c494\r\nCookie: blah\r\nAccept-Language: us\r\n\r\n--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
- int r = HtpBodyAppendChunk(NULL, &htud.request_body, chunk1, sizeof(chunk1)-1);
+ int r = HtpBodyAppendChunk(&htud.request_body, chunk1, sizeof(chunk1) - 1);
BUG_ON(r != 0);
- r = HtpBodyAppendChunk(NULL, &htud.request_body, chunk2, sizeof(chunk2)-1);
+ r = HtpBodyAppendChunk(&htud.request_body, chunk2, sizeof(chunk2) - 1);
BUG_ON(r != 0);
const uint8_t *chunks_buffer = NULL;
}
}
-static int SMTPInsertCommandIntoCommandBuffer(uint8_t command, SMTPState *state, Flow *f)
+static int SMTPInsertCommandIntoCommandBuffer(uint8_t command, SMTPState *state)
{
SCEnter();
void *ptmp;
return 0;
}
-static int SMTPProcessCommandBDAT(
- SMTPState *state, Flow *f, AppLayerParserState *pstate, const SMTPLine *line)
+static int SMTPProcessCommandBDAT(SMTPState *state, const SMTPLine *line)
{
SCEnter();
* \retval 0 ok
* \retval -1 error
*/
-static int SMTPProcessCommandDATA(SMTPState *state, SMTPTransaction *tx, Flow *f,
- AppLayerParserState *pstate, const SMTPLine *line)
+static int SMTPProcessCommandDATA(
+ SMTPState *state, SMTPTransaction *tx, Flow *f, const SMTPLine *line)
{
SCEnter();
DEBUG_VALIDATE_BUG_ON(tx == NULL);
* acknowledged with a reply. We insert a dummy command to
* the command buffer to be used by the reply handler to match
* the reply received */
- SMTPInsertCommandIntoCommandBuffer(SMTP_COMMAND_DATA_MODE, state, f);
+ SMTPInsertCommandIntoCommandBuffer(SMTP_COMMAND_DATA_MODE, state);
if (smtp_config.raw_extraction) {
/* we use this as the signal that message data is complete. */
FileCloseFile(&tx->files_ts, &smtp_config.sbcfg, NULL, 0, 0);
return 0;
}
-static int SMTPProcessCommandSTARTTLS(SMTPState *state, Flow *f,
- AppLayerParserState *pstate)
-{
- return 0;
-}
-
static inline bool IsReplyToCommand(const SMTPState *state, const uint8_t cmd)
{
return (state->cmds_idx < state->cmds_buffer_len &&
state->cmds[state->cmds_idx] == cmd);
}
-static int SMTPProcessReply(SMTPState *state, Flow *f, AppLayerParserState *pstate,
- SMTPThreadCtx *td, SMTPInput *input, const SMTPLine *line)
+static int SMTPProcessReply(
+ SMTPState *state, Flow *f, SMTPThreadCtx *td, SMTPInput *input, const SMTPLine *line)
{
SCEnter();
* -1 for errors and inconsistent states
* -2 if MIME state could not be allocated
* */
-static int SMTPProcessRequest(SMTPState *state, Flow *f, AppLayerParserState *pstate,
- SMTPInput *input, const SMTPLine *line, const StreamSlice *slice)
+static int SMTPProcessRequest(
+ SMTPState *state, Flow *f, SMTPInput *input, const SMTPLine *line, const StreamSlice *slice)
{
SCEnter();
SMTPTransaction *tx = state->curr_tx;
/* Every command is inserted into a command buffer, to be matched
* against reply(ies) sent by the server */
- if (SMTPInsertCommandIntoCommandBuffer(state->current_command,
- state, f) == -1) {
+ if (SMTPInsertCommandIntoCommandBuffer(state->current_command, state) == -1) {
SCReturnInt(-1);
}
}
switch (state->current_command) {
- case SMTP_COMMAND_STARTTLS:
- return SMTPProcessCommandSTARTTLS(state, f, pstate);
-
case SMTP_COMMAND_DATA:
- return SMTPProcessCommandDATA(state, tx, f, pstate, line);
+ return SMTPProcessCommandDATA(state, tx, f, line);
case SMTP_COMMAND_BDAT:
- return SMTPProcessCommandBDAT(state, f, pstate, line);
+ return SMTPProcessCommandBDAT(state, line);
default:
/* we have nothing to do with any other command at this instant.
* 1 for handing control over to GetLine
* -1 for errors and inconsistent states
* */
-static int SMTPPreProcessCommands(SMTPState *state, Flow *f, AppLayerParserState *pstate,
- StreamSlice *slice, SMTPInput *input, SMTPLine *line)
+static int SMTPPreProcessCommands(
+ SMTPState *state, Flow *f, StreamSlice *slice, SMTPInput *input, SMTPLine *line)
{
DEBUG_VALIDATE_BUG_ON((state->parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE) == 0);
DEBUG_VALIDATE_BUG_ON(line->len != 0);
input->consumed = total_consumed;
input->len -= current_line_consumed;
DEBUG_VALIDATE_BUG_ON(input->consumed + input->len != input->orig_len);
- if (SMTPProcessRequest(state, f, pstate, input, line, slice) == -1) {
+ if (SMTPProcessRequest(state, f, input, line, slice) == -1) {
return -1;
}
line_complete = false;
if (((state->current_command == SMTP_COMMAND_DATA) ||
(state->current_command == SMTP_COMMAND_BDAT)) &&
(state->parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE)) {
- int ret = SMTPPreProcessCommands(state, f, pstate, &stream_slice, &input, &line);
+ int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
DEBUG_VALIDATE_BUG_ON(ret != 0 && ret != -1 && ret != 1);
if (ret == 0 && input.consumed == input.orig_len) {
SCReturnStruct(APP_LAYER_OK);
}
AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
while (res.status == 0) {
- int retval = SMTPProcessRequest(state, f, pstate, &input, &line, &stream_slice);
+ int retval = SMTPProcessRequest(state, f, &input, &line, &stream_slice);
if (retval != 0)
SCReturnStruct(APP_LAYER_ERROR);
if (line.delim_len == 0 && line.len == SMTP_LINE_BUFFER_LIMIT) {
* In case of another boundary, the control should be passed to SMTPGetLine */
if ((input.len > 0) && (state->current_command == SMTP_COMMAND_DATA) &&
(state->parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE)) {
- int ret = SMTPPreProcessCommands(state, f, pstate, &stream_slice, &input, &line);
+ int ret = SMTPPreProcessCommands(state, f, &stream_slice, &input, &line);
DEBUG_VALIDATE_BUG_ON(ret != 0 && ret != -1 && ret != 1);
if (ret == 0 && input.consumed == input.orig_len) {
SCReturnStruct(APP_LAYER_OK);
} else {
AppLayerResult res = SMTPGetLine(f, &stream_slice, state, &input, &line, direction);
while (res.status == 0) {
- if (SMTPProcessReply(state, f, pstate, thread_data, &input, &line) != 0)
+ if (SMTPProcessReply(state, f, thread_data, &input, &line) != 0)
SCReturnStruct(APP_LAYER_ERROR);
if (line.delim_len == 0 && line.len == SMTP_LINE_BUFFER_LIMIT) {
if (!line.lf_found) {