dict-client.c revision 9844b5359f5cab77e4c31a7ac9e4a60a0073929e
/* Copyright (C) 2005 Timo Sirainen */
#include "lib.h"
#include "str.h"
#include "network.h"
#include "istream.h"
#include "ostream.h"
#include "dict-private.h"
#include "dict-client.h"
#include <unistd.h>
#include <fcntl.h>
struct client_dict {
int fd;
const char *uri;
const char *username;
const char *path;
unsigned int connect_counter;
unsigned int transaction_id_counter;
unsigned int in_iteration:1;
unsigned int handshaked:1;
};
struct client_dict_iterate_context {
struct dict_iterate_context ctx;
bool failed;
};
struct client_dict_transaction_context {
struct dict_transaction_context ctx;
unsigned int id;
unsigned int connect_counter;
bool failed;
};
const char *dict_client_escape(const char *src)
{
const char *p;
/* first do a quick lookup to see if there's anything to escape.
probably not. */
for (p = src; *p != '\0'; p++) {
if (*p == '\t' || *p == '\n' || *p == '\001')
break;
}
if (*p == '\0')
return src;
for (; *p != '\0'; p++) {
switch (*p) {
case '\t':
break;
case '\n':
break;
case '\001':
break;
default:
str_append_c(dest, *p);
break;
}
}
}
const char *dict_client_unescape(const char *src)
{
const char *p;
/* first do a quick lookup to see if there's anything to unescape.
probably not. */
for (p = src; *p != '\0'; p++) {
if (*p == '\001')
break;
}
if (*p == '\0')
return src;
for (; *p != '\0'; p++) {
if (*p != '\001')
str_append_c(dest, *p);
else if (p[1] != '\0') {
p++;
switch (*p) {
case '1':
break;
case 't':
break;
case 'n':
break;
}
}
}
}
{
/* Send failed */
if (!dict->handshaked) {
/* we're trying to send hello, don't try to reconnect */
return -1;
}
/* Reconnect and try again. */
if (client_dict_connect(dict) < 0)
return -1;
return -1;
}
}
return 0;
}
{
char *line;
int ret;
return line;
}
return NULL;
}
{
const char *query;
return -1;
}
/* Dictionary lookups are blocking */
4096, FALSE);
dict->transaction_id_counter = 0;
t_push();
return -1;
}
t_pop();
return 0;
}
{
dict->connect_counter++;
}
}
const char *username)
{
struct client_dict *dict;
const char *dest_uri;
/* uri = [<path>] ":" <uri> */
return NULL;
}
if (*uri != ':') {
/* path given */
} else {
}
(void)client_dict_connect(dict);
}
{
}
{
const char *line;
return -1;
t_push();
t_pop();
return -1;
}
t_pop();
/* read reply */
return -1;
if (*line == DICT_PROTOCOL_REPLY_OK) {
return 1;
} else {
}
}
static struct dict_iterate_context *
{
struct client_dict_iterate_context *ctx;
const char *query;
if (dict->in_iteration)
i_panic("dict-client: Only one iteration supported");
t_push();
t_pop();
}
{
struct client_dict_iterate_context *ctx =
(struct client_dict_iterate_context *)_ctx;
return -1;
/* read next reply */
return -1;
if (*line == '\0') {
/* end of iteration */
return 0;
}
/* line contains key \t value */
/* broken protocol */
return -1;
}
*value++ = '\0';
return 1;
}
{
struct client_dict_iterate_context *ctx =
(struct client_dict_iterate_context *)_ctx;
}
static struct dict_transaction_context *
{
struct client_dict_transaction_context *ctx;
}
{
struct client_dict_transaction_context *ctx =
(struct client_dict_transaction_context *)_ctx;
ret = -1;
else {
t_push();
ret = -1;
else if (ret == 0) {
/* read reply */
return -1;
if (*line != DICT_PROTOCOL_REPLY_OK)
ret = -1;
}
t_pop();
}
return ret;
}
static void
{
struct client_dict_transaction_context *ctx =
(struct client_dict_transaction_context *)_ctx;
const char *query;
t_push();
t_pop();
}
}
{
struct client_dict_transaction_context *ctx =
(struct client_dict_transaction_context *)_ctx;
const char *query;
return;
t_push();
t_pop();
}
{
struct client_dict_transaction_context *ctx =
(struct client_dict_transaction_context *)_ctx;
const char *query;
return;
t_push();
t_pop();
}
static struct dict client_dict = {
{
}
};
void dict_client_register(void)
{
}
void dict_client_unregister(void)
{
}