solr-connection.c revision 34a41fd572d2516549b3a3b340c36730f284612a
/* Copyright (c) 2006-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "hash.h"
#include "str.h"
#include "strescape.h"
#include "ioloop.h"
#include "istream.h"
#include "http-url.h"
#include "http-client.h"
#include "fts-solr-plugin.h"
#include "solr-connection.h"
#include <expat.h>
enum solr_xml_response_state {
};
enum solr_xml_content_state {
};
struct solr_lookup_xml_context {
enum solr_xml_response_state state;
int depth;
float score;
/* box_id -> solr_result */
};
struct solr_connection_post {
struct solr_connection *conn;
struct http_client_request *http_req;
unsigned int failed:1;
};
struct solr_connection {
char *http_host;
char *http_base_url;
char *http_failure;
int request_status;
unsigned int debug:1;
unsigned int posting:1;
unsigned int xml_failed:1;
unsigned int http_ssl:1;
};
{
if (conn->xml_failed)
return -1;
return 0;
if (err != XML_ERROR_FINISHED) {
i_error("fts_solr: Invalid XML input at %d:%d: %s "
return -1;
}
return 0;
}
{
struct http_client_settings http_set;
struct solr_connection *conn;
const char *error;
"fts_solr: Failed to parse HTTP url: %s", error);
return -1;
}
if (solr_http_client == NULL) {
}
"fts_solr: Failed to allocate XML parser");
}
return 0;
}
{
}
static const char *attrs_get_name(const char **attrs)
{
return attrs[1];
}
return "";
}
static void
{
const char *name_attr;
/* skipping over unwanted elements */
return;
}
/* response -> result -> doc */
break;
break;
ctx->uidvalidity = 0;
}
break;
else
break;
break;
break;
}
}
static struct solr_result *
{
struct solr_result *result;
char *box_id_dup;
return result;
return result;
}
{
struct fts_score_map *score;
struct solr_result *result;
const char *box_id;
i_error("fts_solr: uid missing from inside doc");
return -1;
}
/* looking up from a single mailbox only */
box_id = "";
} else if (ctx->uidvalidity != 0) {
/* old style lookup */
} else {
/* new style lookup */
}
/* duplicate result */
}
return 0;
}
{
int ret;
return;
/* mailbox is namespace prefix */
}
ret = 0;
T_BEGIN {
} T_END;
}
if (ret < 0)
else
}
}
{
int i;
for (i = 0; i < len; i++) {
break;
}
if (i != len)
return -1;
return 0;
}
{
char *new_name;
switch (ctx->content_state) {
break;
i_error("fts_solr: received invalid uid '%s'",
}
break;
T_BEGIN {
} T_END;
break;
/* this may be called multiple times, for example if input
contains '&' characters */
break;
break;
i_error("fts_solr: received invalid uidvalidity");
break;
break;
}
}
{
const unsigned char *data;
int ret;
/* read payload */
}
if (ret == 0) {
/* we will be called again for more data */
} else {
i_error("fts_solr: failed to read payload from HTTP server: %m");
}
}
}
static void
struct solr_connection *conn)
{
i_error("fts_solr: Lookup failed: %u %s",
return;
}
i_error("fts_solr: Lookup failed: Empty response payload");
return;
}
}
{
struct http_client_request *http_req;
const char *url;
int parse_ret;
conn->request_status = 0;
if (conn->request_status < 0 ||
return -1;
return parse_ret;
}
static void
struct solr_connection *conn)
{
i_error("fts_solr: Indexing failed: %u %s",
}
}
static struct http_client_request *
{
struct http_client_request *http_req;
const char *url;
return http_req;
}
struct solr_connection_post *
{
struct solr_connection_post *post;
return post;
}
{
return;
if (conn->request_status == 0)
if (conn->request_status < 0)
}
{
conn->request_status < 0) {
ret = -1;
}
} else {
}
return ret;
}
{
struct http_client_request *http_req;
struct istream *post_payload;
conn->request_status = 0;
return conn->request_status;
}