solr-connection.c revision df1713bd29d29a3e3f3ebfdf05f929525825a7d3
/* Copyright (c) 2006-2012 Dovecot authors, see the included COPYING file */
/* curl: 7.16.0 curl_multi_timeout */
#include "lib.h"
#include "array.h"
#include "hash.h"
#include "str.h"
#include "strescape.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 hash_table *mailboxes;
};
struct solr_connection_post {
struct solr_connection *conn;
const unsigned char *data;
char *url;
unsigned int failed:1;
};
struct solr_connection {
char curl_errorbuf[CURL_ERROR_SIZE];
char *url, *last_sent_url;
char *http_failure;
unsigned int debug:1;
unsigned int posting:1;
unsigned int xml_failed:1;
};
static size_t
{
/* @UNSAFE */
return size;
}
{
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;
}
static size_t
{
return size;
}
static size_t
{
const unsigned char *p;
size_t i;
return size;
if (p[i] == ' ') {
i++;
break;
}
}
i = 0;
return size;
}
{
struct solr_connection *conn;
"fts_solr: Failed to allocate curl");
}
/* set global curl options */
"Transfer-Encoding: chunked");
"Expect:");
"fts_solr: Failed to allocate XML parser");
}
return conn;
}
{
}
const char *str)
{
char *encoded;
}
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: Query didn't return uid");
return;
}
/* looking up from a single mailbox only */
box_id = "";
} else if (ctx->uidvalidity != 0) {
/* old style lookup */
} else {
/* new style lookup */
}
}
}
{
/* mailbox is namespace prefix */
}
T_BEGIN {
} T_END;
}
}
}
{
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");
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;
}
}
{
long httpret;
int parse_ret;
/* curl v7.16 and older don't strdup() the URL */
if (ret != 0) {
i_error("fts_solr: HTTP GET failed: %s",
return -1;
}
if (httpret != 200) {
return -1;
}
return parse_ret;
}
struct solr_connection_post *
{
struct solr_connection_post *post;
i_error("fts_solr: curl_multi_add_handle() failed: %s",
} else {
/* curl v7.16 and older don't strdup() the URL */
conn->headers_post);
}
return post;
}
{
struct timeval timeout_tv;
long timeout;
return;
for (;;) {
if (merr == CURLM_CALL_MULTI_PERFORM)
continue;
i_error("fts_solr: curl_multi_perform() failed: %s",
break;
}
/* everything sent successfully */
return;
}
i_error("fts_solr: curl post failed: %s",
break;
}
/* everything wasn't sent - wait. just use select,
since libcurl interface is easiest with it. */
i_error("fts_solr: curl_multi_fdset() failed: %s",
break;
}
i_error("fts_solr: curl_multi_timeout() failed: %s",
break;
}
if (timeout < 0) {
timeout_tv.tv_usec = 0;
} else {
}
if (ret < 0) {
i_error("fts_solr: select() failed: %m");
break;
}
}
}
{
long httpret;
ret = -1;
}
return ret;
}
{
struct solr_connection_post *post;
return solr_connection_post_end(post);
}