client.c revision f99fab9747beba303a64e7db9026e3185425833d
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "buffer.h"
#include "ioloop.h"
#include "network.h"
#include "istream.h"
#include "ostream.h"
#include "str.h"
#include "var-expand.h"
#include "mail-storage.h"
#include "commands.h"
#include "mail-search.h"
#include <stdlib.h>
#include <unistd.h>
/* max. length of input command line (spec says 512) */
#define MAX_INBUF_SIZE 2048
/* Stop reading input when output buffer has this many bytes. Once the buffer
size has dropped to half of it, start reading input again. */
#define OUTBUF_THROTTLE_SIZE 4096
/* If we can't send anything for 10 minutes, disconnect the client */
/* Disconnect client when it sends too many bad commands in a row */
#define CLIENT_MAX_BAD_COMMANDS 20
/* Disconnect client after idling this many seconds */
extern struct mail_storage_callbacks mail_storage_callbacks;
static void client_input(void *context);
static int client_output(void *context);
{
struct mailbox_sync_context *ctx;
struct mailbox_sync_rec sync_rec;
;
}
{
struct mail_search_arg search_arg;
struct mailbox_transaction_context *t;
struct mail_search_context *ctx;
struct mailbox_status status;
int i;
bool failed;
for (i = 0; i < 2; i++) {
break;
}
client->total_size = 0;
break;
}
}
if (mailbox_search_deinit(&ctx) < 0) {
break;
}
if (!failed) {
return TRUE;
}
/* well, sync and try again */
}
if (i == 2)
return FALSE;
}
struct mail_storage *storage)
{
enum mailbox_open_flags flags;
bool syntax_error, temporary_error;
/* always use nonblocking I/O */
flags = 0;
if (no_flag_updates)
if (lock_session)
i_error("Couldn't open INBOX: %s",
&temporary_error));
return NULL;
}
if (!init_mailbox(client)) {
return NULL;
}
if (hook_client_created != NULL)
return client;
}
{
static struct var_expand_table static_tab[] = {
{ 'p', NULL },
{ 't', NULL },
{ 'b', NULL },
{ 'r', NULL },
{ 'd', NULL },
{ 'm', NULL },
{ 's', NULL },
{ '\0', NULL }
};
struct var_expand_table *tab;
}
{
if (!client->disconnected) {
reason = "Disconnected";
}
/* deinitialize command */
}
i_error("close(client in) failed: %m");
i_error("close(client out) failed: %m");
}
/* quit the program */
}
{
if (client->disconnected)
return;
}
{
return -1;
t_push();
if (ret >= 0) {
ret = 1;
} else {
ret = 0;
/* no more input until client has read
our output */
/* If someone happens to flush output,
we want to get our IO handler back in
flush callback */
TRUE);
}
}
}
t_pop();
return (int)ret;
}
{
const char *error;
bool syntax, temporary_error;
"state, please relogin.");
return;
}
"BUG: Unknown error");
}
static void client_input(void *context)
{
int ret;
/* we're still processing a command. wait until it's
finished. */
return;
}
case -1:
/* disconnected */
return;
case -2:
/* line too long, kill it */
return;
}
args = "";
else
*args++ = '\0';
t_push();
t_pop();
if (ret >= 0) {
client->bad_counter = 0;
TRUE);
break;
}
}
}
}
static int client_output(void *context)
{
int ret;
return 1;
}
}
/* enable input again */
}
}
}
{
return;
"in reading our output");
}
} else {
"-ERR Disconnected for inactivity.");
}
}
}
void clients_init(void)
{
}
void clients_deinit(void)
{
}
}