fts-language.c revision a9b3887f4d9ed75a76fed964c1930432bf84f4f5
/* Copyright (c) 2014-2015 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "fts-language.h"
#include "strfuncs.h"
#include "llist.h"
#ifdef HAVE_LIBEXTTEXTCAT_TEXTCAT_H
# include <libexttextcat/textcat.h>
#elif defined (HAVE_FTS_EXTTEXTCAT)
# include <textcat.h>
#endif
#ifndef TEXTCAT_RESULT_UNKNOWN /* old textcat.h has typos */
# ifdef TEXTCAT_RESULT_UNKOWN
# endif
#endif
#define DETECT_STR_MAX_LEN 200
struct fts_language_list {
const char *textcat_config;
const char *textcat_datadir;
void *textcat_handle;
bool textcat_failed;
};
const struct fts_language fts_languages[] = {
{ "en" },
{ "fi" },
{ "fr" },
{ "de" }
};
const struct fts_language fts_language_data = {
"data"
};
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(fts_languages); i++) {
return &fts_languages[i];
}
return NULL;
}
int fts_language_list_init(const char *const *settings,
struct fts_language_list **list_r,
const char **error_r)
{
struct fts_language_list *lp;
unsigned int i;
else {
return -1;
}
}
else
else
return 0;
}
{
#ifdef HAVE_FTS_EXTTEXTCAT
#endif
}
static const struct fts_language *
{
const struct fts_language *const *langp;
return *langp;
}
return NULL;
}
const struct fts_language *lang)
{
}
const char *names,
const char **unknown_name_r)
{
const char *const *langs;
const struct fts_language *lang;
/* unknown language */
*unknown_name_r = *langs;
return FALSE;
}
}
return TRUE;
}
const ARRAY_TYPE(fts_language) *
{
}
const struct fts_language *
{
const struct fts_language *const *langp;
return *langp;
}
#ifdef HAVE_FTS_EXTTEXTCAT
const struct fts_language **lang_r)
{
const char *name;
for (int i = 0; i < candp_len; i++) {
/* name is <lang>-<optional country or characterset>-<encoding>
eg, fi--utf8 or pt-PT-utf8 */
return TRUE;
}
return FALSE;
}
#endif
#ifdef HAVE_FTS_EXTTEXTCAT
{
const char *config_path;
const char *data_dir;
return 0;
if (list->textcat_failed)
return -1;
TEXTCAT_DATADIR"/";
i_error("special_textcat_Init(%s, %s) failed",
return -1;
}
/* The textcat minimum document size could be set here. It
currently defaults to 3. UTF8 is enabled by default. */
return 0;
}
#endif
static enum fts_language_result
const unsigned char *text ATTR_UNUSED,
{
#ifdef HAVE_FTS_EXTTEXTCAT
int cnt;
if (fts_language_textcat_init(list) < 0)
return FTS_LANGUAGE_RESULT_ERROR;
if (cnt > 0) {
T_BEGIN {
} T_END;
if (match)
return FTS_LANGUAGE_RESULT_OK;
else
return FTS_LANGUAGE_RESULT_UNKNOWN;
} else {
switch (cnt) {
case TEXTCAT_RESULT_SHORT:
return FTS_LANGUAGE_RESULT_SHORT;
case TEXTCAT_RESULT_UNKNOWN:
return FTS_LANGUAGE_RESULT_UNKNOWN;
default:
i_unreached();
}
}
#else
return FTS_LANGUAGE_RESULT_UNKNOWN;
#endif
}
enum fts_language_result
const unsigned char *text ATTR_UNUSED,
const struct fts_language **lang_r)
{
/* if there's only a single wanted language, return it always. */
const struct fts_language *const *langp =
return FTS_LANGUAGE_RESULT_OK;
}
}