client.c revision 8e7123b5a7bc814b11ac4bcf3afd30ef8110a9be
/* Copyright (C) 2002-2004 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "network.h"
#include "istream.h"
#include "ostream.h"
#include "commands.h"
#include "namespace.h"
#include <stdlib.h>
extern struct mail_storage_callbacks mail_storage_callbacks;
{
/* always use nonblocking I/O */
while (namespaces != NULL) {
}
if (hook_client_created != NULL)
return client;
}
{
/* try to deinitialize the command */
}
/* quit the program */
}
{
}
{
}
{
return -1;
return -1;
}
{
return;
tag = "*";
}
{
int fatal;
if (fatal) {
return;
}
}
else {
}
"Too many invalid IMAP commands.");
}
/* client_read_args() failures rely on this being set, so that the
command processing is stopped even while command function returns
FALSE. */
}
{
int ret;
/* all parameters read successfully */
return TRUE;
} else if (ret == -2) {
/* need more data */
return FALSE;
} else {
/* error, or missing arguments */
"Missing arguments");
return FALSE;
}
}
{
const char *str;
unsigned int i;
return FALSE;
for (i = 0; i < count; i++) {
break;
}
break;
}
}
return i == count;
}
{
/* reset input idle time because command output might have taken a
long time and we don't want to disconnect client immediately then */
}
}
/* 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') {
i++;
break;
}
}
return !client->input_skip_line;
}
{
/* command is being executed - continue it */
/* command execution was finished */
client->bad_counter = 0;
return TRUE;
}
return FALSE;
}
if (client->input_skip_line) {
/* we're just waiting for new line.. */
if (!client_skip_line(client))
return FALSE;
/* got the newline */
/* pass through to parse next command */
}
return FALSE; /* need more data */
}
return FALSE; /* need more data */
}
/* command not given - cmd_func is already NULL. */
} else {
/* find the command function */
}
/* unknown command */
} else {
/* command execution was finished. */
client->bad_counter = 0;
} else {
/* unfinished */
return FALSE;
}
}
return TRUE;
}
void _client_input(void *context)
{
if (client->command_pending) {
/* already processing one command. wait. */
return;
}
case -1:
/* disconnected */
return;
case -2:
/* parameter word is longer than max. input buffer size.
this is most likely an error, so skip the new data
until newline is found. */
break;
}
while (client_handle_input(client))
;
if (client->command_pending)
}
int _client_output(void *context)
{
return 1;
}
if (!client->command_pending)
return 1;
/* continue processing command */
/* a bit kludgy. normally we would want to get back here, but IDLE
is a special case which has command pending but without necessarily
anything to write. */
if (finished) {
/* command execution was finished */
client->bad_counter = 0;
if (client->input_pending)
}
return ret;
}
{
return;
idle_time = ioloop_time -
if (my_client->command_pending &&
/* client isn't reading our output */
} else if (idle_time >= CLIENT_IDLE_TIMEOUT) {
/* client isn't sending us anything */
if (!my_client->command_pending) {
"* BYE Disconnected for inactivity.");
}
}
}
void clients_init(void)
{
}
void clients_deinit(void)
{
}
}