~ubuntu-branches/ubuntu/trusty/dovecot/trusty-updates

« back to all changes in this revision

Viewing changes to src/plugins/fts-solr/fts-backend-solr-old.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (1.15.3) (96.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140108093549-814nkqdcxfbvgktg
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2006-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2006-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
6
6
#include "hash.h"
7
7
#include "strescape.h"
8
8
#include "unichar.h"
 
9
#include "http-url.h"
9
10
#include "imap-utf7.h"
10
11
#include "mail-storage-private.h"
11
12
#include "mailbox-list-private.h"
21
22
 
22
23
struct solr_fts_backend {
23
24
        struct fts_backend backend;
 
25
        struct solr_connection *solr_conn;
24
26
        char *id_username, *id_namespace;
25
27
        struct mail_namespace *default_ns;
26
28
};
40
42
        bool documents_added;
41
43
};
42
44
 
43
 
static struct solr_connection *solr_conn = NULL;
44
 
 
45
45
static bool is_valid_xml_char(unichar_t chr)
46
46
{
47
47
        /* Valid characters in XML:
151
151
static void solr_quote_http(string_t *dest, const char *str)
152
152
{
153
153
        str_append(dest, "%22");
154
 
        solr_connection_http_escape(solr_conn, dest, str);
 
154
        http_url_escape_param(dest, str);
155
155
        str_append(dest, "%22");
156
156
}
157
157
 
226
226
}
227
227
 
228
228
static int
229
 
fts_backend_solr_init(struct fts_backend *_backend,
230
 
                      const char **error_r ATTR_UNUSED)
 
229
fts_backend_solr_init(struct fts_backend *_backend, const char **error_r)
231
230
{
232
231
        struct solr_fts_backend *backend = (struct solr_fts_backend *)_backend;
233
232
        struct fts_solr_user *fuser = FTS_SOLR_USER_CONTEXT(_backend->ns->user);
234
 
        const struct fts_solr_settings *set = &fuser->set;
235
233
        const char *str;
236
234
 
237
 
        if (solr_conn == NULL)
238
 
                solr_conn = solr_connection_init(set->url, set->debug);
 
235
        if (fuser == NULL) {
 
236
                *error_r = "Invalid fts_solr setting";
 
237
                return -1;
 
238
        }
 
239
        if (solr_connection_init(fuser->set.url, fuser->set.debug,
 
240
                                 &backend->solr_conn, error_r) < 0)
 
241
                return -1;
239
242
 
240
243
        str = solr_escape_id_str(_backend->ns->user->username);
241
244
        backend->id_username = i_strdup(str);
280
283
 
281
284
        tmp = t_str_new(64);
282
285
        solr_add_ns_query(tmp, backend, ns, FALSE);
283
 
        solr_connection_http_escape(solr_conn, str, str_c(tmp));
 
286
        http_url_escape_param(str, str_c(tmp));
284
287
}
285
288
 
286
289
static int
311
314
        solr_quote_http(str, ns->user->username);
312
315
 
313
316
        pool = pool_alloconly_create("solr last uid lookup", 1024);
314
 
        if (solr_connection_select(solr_conn, str_c(str),
 
317
        if (solr_connection_select(backend->solr_conn, str_c(str),
315
318
                                   pool, &results) < 0)
316
319
                ret = -1;
317
320
        else if (results[0] == NULL) {
349
352
        if (fts_backend_solr_get_last_uid_fallback(backend, box, last_uid_r) < 0)
350
353
                return -1;
351
354
 
352
 
        (void)fts_index_set_last_uid(box, *last_uid_r);
 
355
        fts_index_set_last_uid(box, *last_uid_r);
353
356
        return 0;
354
357
}
355
358
 
438
441
{
439
442
        struct solr_fts_backend_update_context *ctx =
440
443
                (struct solr_fts_backend_update_context *)_ctx;
 
444
        struct solr_fts_backend *backend =
 
445
                (struct solr_fts_backend *)_ctx->backend;
441
446
        const char *str;
442
447
        int ret;
443
448
 
448
453
        str = t_strdup_printf("<commit waitFlush=\"false\" "
449
454
                              "waitSearcher=\"%s\"/>",
450
455
                              ctx->documents_added ? "true" : "false");
451
 
        if (solr_connection_post(solr_conn, str) < 0)
 
456
        if (solr_connection_post(backend->solr_conn, str) < 0)
452
457
                ret = -1;
453
458
 
454
459
        str_free(&ctx->cmd);
468
473
        struct mail_namespace *ns;
469
474
 
470
475
        if (ctx->prev_uid != 0) {
471
 
                (void)fts_index_set_last_uid(ctx->cur_box, ctx->prev_uid);
 
476
                fts_index_set_last_uid(ctx->cur_box, ctx->prev_uid);
472
477
                ctx->prev_uid = 0;
473
478
        }
474
479
 
490
495
{
491
496
        struct solr_fts_backend_update_context *ctx =
492
497
                (struct solr_fts_backend_update_context *)_ctx;
 
498
        struct solr_fts_backend *backend =
 
499
                (struct solr_fts_backend *)_ctx->backend;
493
500
 
494
501
        T_BEGIN {
495
502
                string_t *cmd;
499
506
                xml_encode_id(ctx, cmd, uid);
500
507
                str_append(cmd, "</id></delete>");
501
508
 
502
 
                (void)solr_connection_post(solr_conn, str_c(cmd));
 
509
                (void)solr_connection_post(backend->solr_conn, str_c(cmd));
503
510
        } T_END;
504
511
}
505
512
 
507
514
fts_backend_solr_uid_changed(struct solr_fts_backend_update_context *ctx,
508
515
                             uint32_t uid)
509
516
{
 
517
        struct solr_fts_backend *backend =
 
518
                (struct solr_fts_backend *)ctx->ctx.backend;
 
519
 
510
520
        if (ctx->post == NULL) {
511
521
                i_assert(ctx->prev_uid == 0);
512
522
 
513
 
                ctx->post = solr_connection_post_begin(solr_conn);
 
523
                ctx->post = solr_connection_post_begin(backend->solr_conn);
514
524
                str_append(ctx->cmd, "<add>");
515
525
        } else {
516
526
                ctx->headers_open = FALSE;
691
701
        solr_add_ns_query_http(str, backend, ns);
692
702
 
693
703
        pool = pool_alloconly_create("fts solr search", 1024);
694
 
        ret = solr_connection_select(solr_conn, str_c(str), pool, &results);
 
704
        ret = solr_connection_select(backend->solr_conn, str_c(str),
 
705
                                     pool, &results);
695
706
        if (ret == 0 && results[0] != NULL) {
696
707
                array_append_array(&result->definite_uids, &results[0]->uids);
697
708
                array_append_array(&result->scores, &results[0]->scores);
721
732
{
722
733
        struct solr_result **solr_results;
723
734
        struct fts_result *fts_result;
724
 
        ARRAY_DEFINE(fts_results, struct fts_result);
 
735
        ARRAY(struct fts_result) fts_results;
725
736
        struct mail_namespace *ns;
726
737
        struct mailbox_status status;
727
 
        struct hash_table *mailboxes;
 
738
        HASH_TABLE(char *, struct mailbox *) mailboxes;
728
739
        struct mailbox *box;
729
740
        const char *box_name;
730
741
        char *box_id;
738
749
        else
739
750
                str_append(str, "%22%22");
740
751
 
741
 
        mailboxes = hash_table_create(default_pool, default_pool, 0,
742
 
                                      str_hash, (hash_cmp_callback_t *)strcmp);
 
752
        hash_table_create(&mailboxes, default_pool, 0, str_hash, strcmp);
743
753
        str_append(str, "%2B(");
744
754
        len = str_len(str);
745
755
        for (i = 0; boxes[i] != NULL; i++) {
758
768
        }
759
769
        str_append_c(str, ')');
760
770
 
761
 
        if (solr_connection_select(solr_conn, str_c(str),
 
771
        if (solr_connection_select(backend->solr_conn, str_c(str),
762
772
                                   result->pool, &solr_results) < 0) {
763
773
                hash_table_destroy(&mailboxes);
764
774
                return -1;
778
788
                fts_result->scores = solr_results[i]->scores;
779
789
                fts_result->scores_sorted = TRUE;
780
790
        }
781
 
        (void)array_append_space(&fts_results);
 
791
        array_append_zero(&fts_results);
782
792
        result->box_results = array_idx_modifiable(&fts_results, 0);
783
793
        hash_table_destroy(&mailboxes);
784
794
        return 0;