client.c revision c0a708fa3f7b8f4fbca32052da5faf7a0125189d
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "buffer.h"
#include "hash.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "process-title.h"
#include "safe-memset.h"
#include "strescape.h"
#include "imap-parser.h"
#include "client.h"
#include "client-authenticate.h"
#include "ssl-proxy.h"
/* max. size of one parameter in line */
#define MAX_INBUF_SIZE 512
/* max. number of IMAP argument elements to accept. The maximum memory usage
for command from user is around MAX_INBUF_SIZE * MAX_IMAP_ARG_ELEMENTS */
#define MAX_IMAP_ARG_ELEMENTS 4
/* Disconnect client after idling this many seconds */
#define CLIENT_LOGIN_IDLE_TIMEOUT 60
/* Disconnect client when it sends too many bad commands */
#define CLIENT_MAX_BAD_COMMANDS 10
/* When max. number of simultaneous connections is reached, few of the
oldest connections are disconnected. Since we have to go through the whole
client hash, it's faster if we disconnect multiple clients. */
#define CLIENT_DESTROY_OLDEST_COUNT 16
static struct hash_table *clients;
{
const char *host;
if (!verbose_proctitle || !process_per_connection)
return;
host = "??";
host));
}
{
const char *capability;
" LOGINDISABLED" : "",
NULL);
return TRUE;
}
{
int fd_ssl;
return TRUE;
}
if (!ssl_initialized) {
return TRUE;
}
/* must be removed before ssl_proxy_new(), since it may
io_add() the same fd. */
}
if (fd_ssl != -1) {
8192, FALSE);
1024, IO_PRIORITY_DEFAULT,
FALSE);
} else {
}
return TRUE;
}
{
return TRUE;
}
{
return TRUE;
}
{
return cmd_capability(client);
return cmd_starttls(client);
return cmd_logout(client);
return FALSE;
}
/* Skip incoming data until newline is found,
returns TRUE if newline was found. */
{
const unsigned char *data;
for (i = 0; i < data_size; i++) {
if (data[i] == '\n') {
return TRUE;
}
}
return FALSE;
}
{
if (client->cmd_finished) {
/* clear the previous command from memory. don't do this
immediately after handling command since we need the
cmd_tag to stay some time after authentication commands. */
/* remove \r\n */
if (!client_skip_line(client))
return;
}
}
return; /* need more data */
}
return; /* need more data */
}
case -1:
/* error */
return;
case -2:
/* not enough data */
return;
}
"* BYE Too many invalid IMAP commands.");
"Too many invalid commands");
return;
}
"BAD Error in IMAP command received by server.");
}
}
{
case -2:
/* buffer full */
return FALSE;
case -1:
/* disconnected */
return FALSE;
default:
/* something was read */
return TRUE;
}
}
void client_input(void *context)
{
if (!client_read(client))
return;
if (client_unref(client))
}
void *context)
{
struct imap_client *const *destroy_clients;
count /= sizeof(struct imap_client *);
for (i = 0; i < count; i++) {
i * sizeof(struct imap_client *),
&client, sizeof(struct imap_client *));
break;
}
}
}
static void client_destroy_oldest(void)
{
struct imap_client *const *destroy_clients;
/* find the oldest clients and put them to destroy-buffer */
sizeof(struct imap_client *) *
/* then kill them */
count /= sizeof(struct imap_client *);
for (i = 0; i < count; i++) {
"Disconnected: Connection queue full");
}
}
{
struct imap_client *client;
/* reached max. users count, kill few of the
oldest connections */
}
/* always use nonblocking I/O */
main_ref();
}
{
}
}
{
}
{
return TRUE;
main_unref();
return FALSE;
}
{
}
{
}
{
const char *host;
host = "??";
}
void *context __attr_unused__)
{
}
}
{
}
unsigned int clients_get_count(void)
{
}
void *context __attr_unused__)
{
}
void clients_destroy_all(void)
{
}
void clients_init(void)
{
}
void clients_deinit(void)
{
}