Modify mapistore_indexing_record_get_fmid prototype to take an extra partial argument.
authorJulien Kerihuel <j.kerihuel@openchange.org>
Tue, 11 Oct 2011 17:11:42 +0000 (17:11 +0000)
committerJulien Kerihuel <j.kerihuel@openchange.org>
Tue, 11 Oct 2011 17:11:42 +0000 (17:11 +0000)
partial is set to True when mapistore_uri includes wildcard '*' (partial URI)
Add a tdb_traverse function to search partial URI.
Add a mapistore management function to check if a message is registered
Add associated python bindings code

mapiproxy/libmapistore/mapistore.h
mapiproxy/libmapistore/mapistore_indexing.c
mapiproxy/libmapistore/mgmt/mapistore_mgmt.c
mapiproxy/libmapistore/mgmt/mapistore_mgmt.h
mapiproxy/servers/default/emsmdb/emsmdbp_object.c
pyopenchange/mapistore/mgmt.c
pyopenchange/tests/mapistore_mgmt.py

index 4340e0cde8009c6a2caa8d303fabea1ea28c535c..339b1b1e3d52e486376b7650314bb3f20a3aa232 100644 (file)
@@ -295,7 +295,7 @@ int mapistore_indexing_record_del_fid(struct mapistore_context *, uint32_t, uint
 int mapistore_indexing_record_add_mid(struct mapistore_context *, uint32_t, uint64_t);
 int mapistore_indexing_record_del_mid(struct mapistore_context *, uint32_t, uint64_t, uint8_t);
 int mapistore_indexing_record_get_uri(struct mapistore_context *, const char *, TALLOC_CTX *, uint64_t, char **, bool *);
-int mapistore_indexing_record_get_fmid(struct mapistore_context *, const char *, const char *, uint64_t *, bool *);
+int mapistore_indexing_record_get_fmid(struct mapistore_context *, const char *, const char *, bool, uint64_t *, bool *);
 
 /* definitions from mapistore_replica_mapping.c */
 _PUBLIC_ int mapistore_replica_mapping_add(struct mapistore_context *, const char *);
index f007c535e6dbf995c8b222694663cfe835d740c5..d603756872d76026022696204fbbc38c5ba67447 100644 (file)
@@ -401,6 +401,9 @@ struct tdb_get_fid_data {
        uint64_t        fmid;
        char            *uri;
        size_t          uri_len;
+       uint32_t        wildcard_count;
+       char            *startswith;
+       char            *endswith;
 };
 
 static int tdb_get_fid_traverse(struct tdb_context *tdb_ctx, TDB_DATA key, TDB_DATA value, void *data)
@@ -431,13 +434,45 @@ static int tdb_get_fid_traverse(struct tdb_context *tdb_ctx, TDB_DATA key, TDB_D
        return ret;
 }
 
-_PUBLIC_ int mapistore_indexing_record_get_fmid(struct mapistore_context *mstore_ctx, const char *username, const char *uri, uint64_t *fmidp, bool *soft_deletedp)
+static int tdb_get_fid_traverse_partial(struct tdb_context *tdb_ctx, TDB_DATA key, TDB_DATA value, void *data)
+{
+       struct tdb_get_fid_data *tdb_data;
+       char                    *key_str, *cmp_uri, *slash_ptr;
+       TALLOC_CTX              *mem_ctx;
+       int                     ret = 0;
+
+       mem_ctx = talloc_zero(NULL, void);
+       tdb_data = data;
+       cmp_uri = talloc_array(mem_ctx, char, value.dsize + 1);
+       memcpy(cmp_uri, value.dptr, value.dsize);
+       *(cmp_uri + value.dsize) = 0;
+       slash_ptr = cmp_uri + value.dsize - 1;
+       if (*slash_ptr == '/') {
+               *slash_ptr = 0;
+       }
+
+       if (!strncmp(cmp_uri, tdb_data->startswith, strlen(tdb_data->startswith)) &&
+           !strncmp(cmp_uri + (strlen(cmp_uri) - strlen(tdb_data->endswith)), tdb_data->endswith, 
+                    strlen(tdb_data->endswith))) {
+                   key_str = talloc_strndup(mem_ctx, (char *) key.dptr, key.dsize);
+                   tdb_data->fmid = strtoull(key_str, NULL, 16);
+                   tdb_data->found = true;
+                   ret = 1;
+       }
+       
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+_PUBLIC_ int mapistore_indexing_record_get_fmid(struct mapistore_context *mstore_ctx, const char *username, const char *uri, bool partial, uint64_t *fmidp, bool *soft_deletedp)
 {
        struct indexing_context_list    *ictx;
        int                             ret;
        struct tdb_get_fid_data         tdb_data;
        char                            *slash_ptr;
-       
+       uint32_t                        i;
+
        /* SANITY checks */
        MAPISTORE_RETVAL_IF(!mstore_ctx, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
        MAPISTORE_RETVAL_IF(!username, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
@@ -452,12 +487,44 @@ _PUBLIC_ int mapistore_indexing_record_get_fmid(struct mapistore_context *mstore
        tdb_data.found = false;
        tdb_data.uri = talloc_strdup(NULL, uri);
        tdb_data.uri_len = strlen(uri);
+
+       tdb_data.startswith = NULL;
+       tdb_data.endswith = NULL;
+       tdb_data.wildcard_count = NULL;
+
        slash_ptr = tdb_data.uri + tdb_data.uri_len - 1;
        if (*slash_ptr == '/') {
                *slash_ptr = 0;
                tdb_data.uri_len--;
        }
-       tdb_traverse_read(ictx->index_ctx->tdb, tdb_get_fid_traverse, &tdb_data);
+       if (partial == false) {
+               tdb_traverse_read(ictx->index_ctx->tdb, tdb_get_fid_traverse, &tdb_data);
+       } else {
+               for (tdb_data.wildcard_count = 0, i = 0; i < strlen(uri); i++) {
+                       if (uri[i] == '*') tdb_data.wildcard_count += 1;
+               }
+
+               switch (tdb_data.wildcard_count) {
+               case 0: /* complete URI */
+                       partial = true;
+                       break;
+               case 1: /* start and end only */
+                       tdb_data.endswith = strchr(uri, '*') + 1;
+                       tdb_data.startswith = talloc_strndup(NULL, uri, strlen(uri) - strlen(tdb_data.endswith) - 1);
+                       break;
+               default:
+                       DEBUG(0, ("[%s:%d]: Too many wildcards found (1 maximum)\n", __FUNCTION__, __LINE__));
+                       talloc_free(tdb_data.uri);
+                       return MAPISTORE_ERR_NOT_FOUND;
+               }
+
+               if (partial == true) {
+                       tdb_traverse_read(ictx->index_ctx->tdb, tdb_get_fid_traverse_partial, &tdb_data);
+                       talloc_free(tdb_data.startswith);
+               } else {
+                       tdb_traverse_read(ictx->index_ctx->tdb, tdb_get_fid_traverse, &tdb_data);
+               }
+       }
 
        talloc_free(tdb_data.uri);
        if (tdb_data.found) {
index f26bf25cbd95a02e960f45cf5c6900013a60d78b..8102d1622b57e2f3d92b8a29350a3084f905047f 100644 (file)
@@ -505,3 +505,53 @@ _PUBLIC_ int mapistore_mgmt_generate_uri(struct mapistore_mgmt_context *mgmt_ctx
 
        return MAPISTORE_SUCCESS;
 }
+
+
+/**
+   \details Check if a message is already registered within indexing
+   database for the user.
+
+   \param mgmt_ctx Pointer to the mapistore management context
+   \param backend the name of the backend
+   \param sysuser the name of the mapistore user (openchange)
+   \param username the name of the user on the remote system the
+   backend manages
+   \param folder the name of the folder on the remote system the
+   backend manages
+   \param message the name of the message on the remote system the
+   backend manages
+
+   \return true if the message is registered, otherwise false
+ */
+_PUBLIC_ int mapistore_mgmt_registered_message(struct mapistore_mgmt_context *mgmt_ctx,
+                                              const char *backend, const char *sysuser,
+                                              const char *username,
+                                              const char *folder, const char *message)
+{
+       struct indexing_context_list    *ictxp;
+       char                            *uri;
+       int                             ret;
+       uint64_t                        mid;
+       bool                            retval;
+       bool                            softdeleted;
+
+       ret = mapistore_mgmt_generate_uri(mgmt_ctx, backend, username, folder, message, &uri);
+       if (ret != MAPISTORE_SUCCESS) return false;
+       
+       ret = mapistore_indexing_add(mgmt_ctx->mstore_ctx, sysuser, &ictxp);
+       if (ret != MAPISTORE_SUCCESS) {
+               talloc_free(uri);
+               return false;
+       }
+
+       ret = mapistore_indexing_record_get_fmid(mgmt_ctx->mstore_ctx, sysuser, uri, true, &mid, &softdeleted);
+       if (ret == MAPISTORE_SUCCESS) {
+               retval = true;
+       } else {
+               retval = false;
+       }
+
+       talloc_free(uri);
+       talloc_free(ictxp);
+       return retval;
+}
index d973cd6f587ae3a67371ff55dcc4e81410ad5491..03919afc848b5a98dcc8b6eb49bc3b56542e075a 100644 (file)
@@ -76,6 +76,7 @@ struct mapistore_mgmt_users_list *mapistore_mgmt_registered_users(struct mapisto
 int mapistore_mgmt_set_verbosity(struct mapistore_mgmt_context *, bool);
 
 int mapistore_mgmt_generate_uri(struct mapistore_mgmt_context *, const char *, const char *, const char *, const char *, char **);
+int mapistore_mgmt_registered_message(struct mapistore_mgmt_context *, const char *, const char *, const char *,const char *, const char *);
 
 __END_DECLS
 
index 133ff23f8c1d4a536b5df46447b2be7c82b805bc..81f00b0224336b0d39551feee69b1a52b245a1a2 100644 (file)
@@ -352,7 +352,7 @@ _PUBLIC_ int emsmdbp_get_fid_from_uri(struct emsmdbp_context *emsmdbp_ctx, const
 
        ret = openchangedb_get_fid(emsmdbp_ctx->oc_ctx, uri, fidp);
        if (ret != MAPI_E_SUCCESS) {
-               ret = mapistore_indexing_record_get_fmid(emsmdbp_ctx->mstore_ctx, emsmdbp_ctx->username, uri, fidp, &soft_deleted);
+               ret = mapistore_indexing_record_get_fmid(emsmdbp_ctx->mstore_ctx, emsmdbp_ctx->username, uri, false, fidp, &soft_deleted);
        }
 
        return ret;
index a268e3b550a0e2b76b6bdd66ca97eef9b4105398..42848be7b3c81088159d7848a864c32a96d342b8 100644 (file)
@@ -86,33 +86,22 @@ static PyObject *py_MAPIStoreMGMT_registered_users(PyMAPIStoreMGMTObject *self,
        return (PyObject *)dict;
 }
 
-static PyObject *py_MAPIStoreMGMT_get_folderID(PyMAPIStoreMGMTObject *self, PyObject *args)
+static PyObject *py_MAPIStoreMGMT_registered_message(PyMAPIStoreMGMTObject *self, PyObject *args)
 {
-       int             ret;
        const char      *backend;
        const char      *sysuser;
-       const char      *user;
+       const char      *vuser;
        const char      *folder;
-       char            *uri;
-       uint64_t        fid;
+       const char      *message;
+       int             ret;
 
-       if (!PyArg_ParseTuple(args, "ssss", &backend, &sysuser, &user, &folder)) {
+       if (!PyArg_ParseTuple(args, "sssss", &backend, &sysuser, &vuser, &folder, &message)) {
                return NULL;
        }
 
-       ret = mapistore_mgmt_generate_uri(self->mgmt_ctx, backend, user, folder, NULL, &uri);
-       printf("uri = %s\n", uri);
-       if (ret != MAPISTORE_SUCCESS) {
-               return PyLong_FromLongLong(-1);
-       }
-
-       ret = openchangedb_get_fid_from_partial_uri(self->parent->ocdb_ctx,
-                                                   uri, &fid);
-       if (ret != MAPI_E_SUCCESS) {
-               return PyLong_FromLongLong(-1);
-       }
+       ret = mapistore_mgmt_registered_message(self->mgmt_ctx, backend, sysuser, vuser, folder, message);
 
-       return PyLong_FromLongLong(fid);
+       return PyBool_FromLong(ret);
 }
 
 static PyObject *obj_get_verbose(PyMAPIStoreMGMTObject *self, void *closure)
@@ -131,7 +120,7 @@ static int obj_set_verbose(PyMAPIStoreMGMTObject *self, PyObject *verbose, void
 static PyMethodDef mapistore_mgmt_methods[] = {
        { "registered_backend", (PyCFunction)py_MAPIStoreMGMT_registered_backend, METH_VARARGS },
        { "registered_users", (PyCFunction)py_MAPIStoreMGMT_registered_users, METH_VARARGS },
-       { "folderID", (PyCFunction)py_MAPIStoreMGMT_get_folderID, METH_VARARGS },
+       { "registered_message", (PyCFunction)py_MAPIStoreMGMT_registered_message, METH_VARARGS },
        { NULL },
 };
 
index 778605ef0aad21e64e27f9195812217e0d151557..47dab9625b8ef30cca01d2ecbd36e51698d1bc7c 100755 (executable)
@@ -38,5 +38,6 @@ mgmt = MAPIStore.management()
 #    print d
 print "Is SOGo backend registered: %s" % mgmt.registered_backend("SOGo")
 print "Is NonExistent backend registered: %s" % mgmt.registered_backend("NonExistent")
-print "%s" % hex(mgmt.folderID("SOGo", "Administrator", "Administrator", "calendar"))
+print "Registered message: %s" % mgmt.registered_message("SOGo", "Administrator", "Administrator", "inbox", "61")
+print "Registered message: %s" % mgmt.registered_message("SOGo", "Administrator", "Administrator", "inbox", "74")