static void tims_handle_input(void *arg) { int l = 0; char buffer[MAX_LINESIZE]; /* connection buffer */ ClientSession_t *session = (ClientSession_t *)arg; ci_cork(session->ci); while (TRUE) { memset(buffer, 0, sizeof(buffer)); l = ci_readln(session->ci, buffer); if (l == 0) break; if ((l = tims_tokenizer(session, buffer))) { if (l == -3) { client_session_bailout(&session); return; } if (tims(session) == -3) { client_session_bailout(&session); return; } client_session_reset_parser(session); } } if (session->state < QUIT) ci_uncork(session->ci); }
static void lmtp_handle_input(void *arg) { int l; char buffer[MAX_LINESIZE]; /* connection buffer */ ClientSession_T *session = (ClientSession_T *)arg; while (TRUE) { memset(buffer, 0, sizeof(buffer)); l = ci_readln(session->ci, buffer); if (l==0) break; if ((l = lmtp_tokenizer(session, buffer))) { if (l == -3) { client_session_bailout(&session); return; } if (l > 0) { if (lmtp(session) == -3) { client_session_bailout(&session); return; } client_session_reset_parser(session); } if (l < 0) { client_session_reset_parser(session); } } } TRACE(TRACE_DEBUG,"[%p] done", session); }
static void pop3_handle_input(void *arg) { char buffer[MAX_LINESIZE]; /* connection buffer */ ClientSession_t *session = (ClientSession_t *)arg; if (session->ci->write_buffer->len) { ci_write(session->ci, NULL); return; } memset(buffer, 0, sizeof(buffer)); if (ci_readln(session->ci, buffer) == 0) return; pop3(session, buffer); }
static void pop3_handle_input(void *arg) { char buffer[MAX_LINESIZE]; /* connection buffer */ ClientSession_T *session = (ClientSession_T *)arg; if (p_string_len(session->ci->write_buffer)) { ci_write(session->ci, NULL); return; } memset(buffer, 0, sizeof(buffer)); if (ci_readln(session->ci, buffer) == 0) return; ci_cork(session->ci); if (pop3(session, buffer) <= 0) { client_session_bailout(&session); return; } ci_uncork(session->ci); }
void imap_handle_input(ImapSession *session) { char buffer[MAX_LINESIZE]; char *alloc_buf = NULL; uint64_t alloc_size = 0; int l, result; assert(session && session->ci && session->ci->write_buffer); // first flush the output buffer if (p_string_len(session->ci->write_buffer)) { TRACE(TRACE_DEBUG,"[%p] write buffer not empty", session); ci_write(session->ci, NULL); } // nothing left to handle if (p_string_len(session->ci->read_buffer) == 0) { TRACE(TRACE_DEBUG,"[%p] read buffer empty", session); return; } // command in progress if (session->command_state == FALSE && session->parser_state == TRUE) { TRACE(TRACE_DEBUG,"[%p] command in-progress", session); return; } // reset if we're done with the previous command if (session->command_state == TRUE) imap_session_reset(session); // Read in a line at a time if we don't have a string literal size defined // Otherwise read in rbuff_size amount of data while (TRUE) { char *input = NULL; FREE_ALLOC_BUF memset(buffer, 0, sizeof(buffer)); if (session->ci->rbuff_size <= 0) { l = ci_readln(session->ci, buffer); } else { alloc_size = session->ci->rbuff_size+1; alloc_buf = mempool_pop(session->pool, alloc_size); l = ci_read(session->ci, alloc_buf, session->ci->rbuff_size); } if (l == 0) break; // done if (session->error_count >= MAX_FAULTY_RESPONSES) { imap_session_printf(session, "* BYE [TRY RFC]\r\n"); imap_handle_abort(session); break; } // session is in a IDLE loop if (session->command_type == IMAP_COMM_IDLE && session->command_state == IDLE) { if (strlen(buffer) > 4 && strncasecmp(buffer,"DONE",4)==0) imap_session_printf(session, "%s OK IDLE terminated\r\n", session->tag); else imap_session_printf(session,"%s BAD Expecting DONE\r\n", session->tag); session->command_state = TRUE; // done imap_session_reset(session); continue; } if (alloc_buf != NULL) input = alloc_buf; else input = buffer; if (! imap4_tokenizer(session, input)) { FREE_ALLOC_BUF continue; } if ( session->parser_state < 0 ) { imap_session_printf(session, "%s BAD parse error\r\n", session->tag); imap_handle_retry(session); break; } if ( session->parser_state ) { result = imap4(session); TRACE(TRACE_DEBUG,"imap4 returned [%d]", result); if (result || (session->command_type == IMAP_COMM_IDLE && session->command_state == IDLE)) { imap_handle_exit(session, result); } break; } if (session->state == CLIENTSTATE_ERROR) { TRACE(TRACE_NOTICE, "session->state: ERROR. abort"); break; } }