dict-server.c revision dd2053135901c770b80745869d9200b491773dc4
/* Copyright (C) 2005 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "network.h"
#include "istream.h"
#include "ostream.h"
#include "dict.h"
#include "dict-cache.h"
#include "dict-client.h"
#include "dict-server.h"
#include <stdlib.h>
#include <unistd.h>
struct dict_server_transaction {
unsigned int id;
struct dict_transaction_context *ctx;
};
struct dict_client_connection {
struct dict_server *server;
char *username;
enum dict_data_type value_type;
int fd;
/* There are only a few transactions per client, so keeping them in
array is fast enough */
};
struct dict_server {
char *path;
int fd;
struct dict_cache *cache;
};
struct dict_client_cmd {
int cmd;
};
{
const char *reply;
const char *value;
int ret;
/* <key> */
if (ret > 0) {
} else {
}
return 0;
}
{
struct dict_iterate_context *ctx;
const char *const *args;
int ret;
i_error("dict client: ITERATE: broken input");
return -1;
}
/* <flags> <path> */
/* FIXME: we don't want to keep blocking here. set a flush
function and send the replies there when buffer gets full */
t_push();
t_pop();
}
return 0;
}
static struct dict_server_transaction *
unsigned int id)
{
struct dict_server_transaction *transactions;
unsigned int i, count;
return NULL;
for (i = 0; i < count; i++) {
return &transactions[i];
}
return NULL;
}
static void
struct dict_server_transaction *trans)
{
const struct dict_server_transaction *transactions;
unsigned int i, count;
for (i = 0; i < count; i++) {
if (&transactions[i] == trans) {
break;
}
}
}
{
struct dict_server_transaction *trans;
unsigned int id;
return -1;
}
return -1;
}
struct dict_server_transaction, 4);
}
/* <id> */
return 0;
}
static int
const char *line,
struct dict_server_transaction **trans_r)
{
unsigned int id;
return -1;
}
return -1;
}
return 0;
}
{
struct dict_server_transaction *trans;
const char *reply;
int ret;
return -1;
return 0;
}
{
struct dict_server_transaction *trans;
return -1;
return 0;
}
{
struct dict_server_transaction *trans;
const char *const *args;
/* <id> <key> <value> */
i_error("dict client: SET: broken input");
return -1;
}
return -1;
return 0;
}
{
struct dict_server_transaction *trans;
const char *const *args;
/* <id> <key> */
i_error("dict client: UNSET: broken input");
return -1;
}
return -1;
return 0;
}
{
struct dict_server_transaction *trans;
const char *const *args;
long long arg;
/* <id> <key> <diff> */
i_error("dict client: ATOMIC_INC: broken input");
return -1;
}
return -1;
else
return 0;
}
static struct dict_client_cmd cmds[] = {
{ DICT_PROTOCOL_CMD_SET, cmd_set },
{ 0, NULL }
};
const char *line)
{
if (*line++ != DICT_PROTOCOL_CMD_HELLO)
return -1;
/* check major version */
*line++ != '\t')
return -1;
/* skip minor version */
if (*line++ != '\t')
return -1;
/* get value type */
value_type = line;
if (*line++ != '\t')
return -1;
/* get username */
if (*line++ != '\t')
return -1;
/* the rest is dict name. since we're looking it with getenv(),
disallow all funny characters that might confuse it, just in case. */
if (*line != '\0')
return -1;
return 0;
}
{
const char *uri;
i_error("dict client: Unconfigured dictionary name '%s'",
return -1;
}
/* dictionary initialization failed */
return -1;
}
return 0;
}
static void dict_client_connection_input(void *context)
{
const char *line;
unsigned int i;
int ret;
case 0:
return;
case -1:
/* disconnected */
return;
case -2:
/* buffer full */
i_error("dict client: Sent us more than %d bytes",
(int)DICT_CLIENT_MAX_LINE_LENGTH);
return;
}
/* handshake not received yet */
return;
i_error("dict client: Broken handshake");
return;
}
if (dict_client_dict_init(conn)) {
return;
}
}
ret = 0;
t_push();
t_pop();
break;
}
}
if (ret < 0) {
break;
}
}
}
{
const struct dict_server_transaction *transactions;
unsigned int i, count;
for (i = 0; i < count; i++)
}
i_error("close(dict client) failed: %m");
}
static struct dict_client_connection *
{
struct dict_client_connection *conn;
return conn;
}
static void dict_server_listener_accept(void *context)
{
int fd;
if (fd < 0) {
if (fd < -1)
} else {
}
}
{
struct dict_server *server;
int i= 0;
break;
/* see if it really exists */
/* delete and try again */
}
return server;
}
{
}