client.c revision 83bb013a99f0936995f9c7a1077822662d8fefdb
/* 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 "mail-namespace.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 */
{
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) {
(void)mailbox_transaction_commit(&t, 0);
break;
}
if (!failed) {
return TRUE;
}
/* well, sync and try again. we might have cached virtual
sizes, make sure they get committed. */
(void)mailbox_transaction_commit(&t, 0);
}
if (i == 2)
return FALSE;
}
struct mail_namespace *namespaces)
{
struct mail_storage *storage;
const char *inbox;
enum mailbox_open_flags flags;
const char *errmsg;
enum mail_error error;
/* always use nonblocking I/O */
inbox = "INBOX";
return NULL;
}
flags = 0;
if (no_flag_updates)
if (lock_session)
&error));
return NULL;
}
if (!init_mailbox(client)) {
i_error("Couldn't init INBOX: %s",
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 },
{ 'i', NULL },
{ 'o', NULL },
{ '\0', NULL }
};
struct var_expand_table *tab;
}
{
if (!client->disconnected) {
reason = "Disconnected";
}
/* deinitialize command */
}
/* client didn't QUIT, but we still want to save any changes
done in this transaction. especially the cached virtual
message sizes. */
}
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;
}
{
enum mail_error error;
"state, please relogin.");
return;
}
&error));
}
{
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++ = '\0';
t_push();
t_pop();
if (ret >= 0) {
client->bad_counter = 0;
TRUE);
break;
}
}
}
}
{
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)
{
}
}