- session constructor doesn't login to the server anymore, it calls MAPIInitialize().
authorAlan Alvarez <alan.alvarez@us.army.mil>
Sun, 27 Jul 2008 18:28:24 +0000 (18:28 +0000)
committerAlan Alvarez <alan.alvarez@us.army.mil>
Sun, 27 Jul 2008 18:28:24 +0000 (18:28 +0000)
- Created session::login() members.
- test applications use default profile.

libmapi++/impl/session.ipp
libmapi++/libmapi++.h
libmapi++/profile.h
libmapi++/session.h
libmapi++/tests/attach_test.cpp
libmapi++/tests/test.cpp
libmapi/property.c

index cdfad2d1c33628d70e02ba0b843678f7038c05a7..1cfb35514696050c21d0e47d70f20d5121c3af6b 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include <libmapi++/message_store.h>
+#include <libmapi++/profile.h>
 
 namespace libmapipp {
 
@@ -34,8 +35,8 @@ inline std::string session::get_default_profile_path()
        return retval;
 }
 
-session::session(const std::string& profile_name, const std::string& profiledb, const std::string& password, bool debug
-throw(std::runtime_error, mapi_exception) : m_session(NULL), m_memory_ctx(talloc_init("libmapi++")), m_message_store(new message_store(*this))
+session::session(const std::string& profiledb, bool debug)throw(std::runtime_error, mapi_exception
+: m_session(NULL), m_memory_ctx(talloc_init("libmapi++")), m_message_store(new message_store(*this))
 {
        mapi_exception::fill_status_map();
 
@@ -50,8 +51,7 @@ throw(std::runtime_error, mapi_exception) : m_session(NULL), m_memory_ctx(talloc
                        delete m_message_store;
                        throw std::runtime_error("libmapipp::session(): Failed to get $HOME env variable");
                }
-       }
-       else {
+       } else {
                profile_path = profiledb;
        }
 
@@ -62,16 +62,28 @@ throw(std::runtime_error, mapi_exception) : m_session(NULL), m_memory_ctx(talloc
        }
 
        if (debug) global_mapi_ctx->dumpdata = true;
+}
 
-       if (MapiLogonEx(&m_session, profile_name.c_str(), (password != "") ? password.c_str() : 0 ) != MAPI_E_SUCCESS) {
+void session::login(const std::string& profile_name, const std::string& password) throw (mapi_exception)
+{
+       m_profile_name = profile_name;
+       if (m_profile_name == "") { // if profile is not set, try to get default profile
+               try {
+                       m_profile_name = profile::get_default_profile();
+               } catch(mapi_exception e) {
+                       uninitialize();
+                       throw;
+               }
+       }
+
+       if (MapiLogonEx(&m_session, m_profile_name.c_str(), (password != "") ? password.c_str() : 0 ) != MAPI_E_SUCCESS) {
                uninitialize();
                throw mapi_exception(GetLastError(), "session::session : MapiLogonEx");
        }
 
        try {
                m_message_store->open();
-       }
-       catch (mapi_exception e) {
+       } catch (mapi_exception e) {
                throw;
        }
 }
index 116ecaaedc1f35706070cff0f28da59a288d0bd5..830b0df4dc1d8d507fb3d8956dec1bb933aca9c9 100644 (file)
@@ -2,7 +2,7 @@
    libmapi C++ Wrapper
    MAPI Exception Class
 
-   Copyright (C) Alan Alvarez 2007.
+   Copyright (C) Alan Alvarez 2008.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -29,5 +29,6 @@
 #include <libmapi++/message.h>
 #include <libmapi++/attachment.h>
 #include <libmapi++/property_container.h>
+#include <libmapi++/profile.h>
 
 #endif /* ! __LIBMAPIPP_H */
index 21fd76b59700d84dbf5a799cab364519f77d9d8f..4b2917caf40bf27a3314e2a9819bf3601044b86f 100644 (file)
@@ -32,7 +32,7 @@ class profile
 
                bool static set_default(const char* profname)
                {
-                       return (setDefaultProfile(profname) == MAPI_E_SUCCESS);
+                       return (SetDefaultProfile(profname) == MAPI_E_SUCCESS);
                }
 
                bool static set_default(const std::string& profname)
@@ -40,6 +40,15 @@ class profile
                        return set_default(profname.c_str());
                }
 
+               std::string static get_default_profile() throw (mapi_exception)
+               {
+                       const char* profname = NULL;
+                       if (GetDefaultProfile(&profname) != MAPI_E_SUCCESS)
+                               throw mapi_exception(GetLastError(), "profile::get_default_profile : GetDefaultProfile()");
+
+                       return std::string(profname);
+               }
+
                ~profile()
                {
                        if (m_profile)
index 39ba6698580336fac9691cd6d4f7d9a6910a2910..575470a302fa1f01a86dbf4b6639738909ee95da 100644 (file)
@@ -42,20 +42,25 @@ class session {
        public:
                /**
                 * \brief Constructor
-                * \param profile_name The name of the profile
                 * \param profiledb An absolute path specifying where the profile database is.\n
                 *        If none or ""  is specified the default location will be used (~/.openchange.profiles.ldb).
+                *
+                * \param debug Whether to output debug information to stdout
+                */
+               session(const std::string& profiledb = "", const bool debug = false) throw(std::runtime_error, mapi_exception);
 
+               /**
+                * \brief Log-in to the Exchange Server
+                * \param profile_name The name of the profile, if left blank the default profile will be used.
                 * \param password The password to use to login with.\n
-                *        It is possible to omit this if the password is stored in the profile.
-                *
-                * \param debug Whether to output debug information to stdout
+                *        It is possible to omit this if the password is stored in the profile database.
                 */
-               session(const std::string& profile_name, const std::string& profiledb = "", const std::string& password = "", bool debug = false) 
-               throw(std::runtime_error, mapi_exception); 
+               void login(const std::string& profile_name = "", const std::string& password = "") throw(mapi_exception); 
 
                static std::string get_default_profile_path();
 
+               std::string get_profile_name() const { return m_profile_name; }
+
                /** \brief Returns a reference to the message_store associated with this session
                 *  \return The message_store associated with this session.
                 */
@@ -74,6 +79,7 @@ class session {
                mapi_session    *m_session;
                TALLOC_CTX      *m_memory_ctx;
                message_store   *m_message_store;
+               std::string     m_profile_name;
 
                void uninitialize() throw();
 };
index b9b7647da953487a0d4fd0685869e1043fd56585..58b04f11c4e20a6cf378fa30c3a01d3cf60bc912 100644 (file)
@@ -72,7 +72,9 @@ void print_folder_tree(folder& up_folder, session& mapi_session, unsigned int de
 int main()
 {
        try {
-               session mapi_session("FIXME");
+               session mapi_session;
+
+               mapi_session.login();
 
                // Get Default Top Information Store folder ID
                mapi_id_t top_folder_id = mapi_session.get_message_store().get_default_folder(olFolderTopInformationStore);
index 2c4f407c3c611f3d1707bbb98f544395acf9eb92..987816d6225edbefa17765d94c9b0540d934f4f7 100644 (file)
@@ -65,7 +65,9 @@ int main ()
 {
        try {
                // Initialize MAPI Session
-               session mapi_session("FIXME");
+               session mapi_session;
+
+               mapi_session.login();
 
                property_container store_properties = mapi_session.get_message_store().get_property_container();
                store_properties << PR_DISPLAY_NAME;
index 6ef9e05e551cd671a0029533f07f395013b2a9a6..54b1ca75bd881b27e247565da7737ef4e49d44f5 100644 (file)
@@ -260,6 +260,8 @@ const void *get_mapi_SPropValue_data(struct mapi_SPropValue *lpProp)
                return (const void *)(struct SBinary_short *)&lpProp->value.bin;
        case PT_MV_STRING8:
                return (const void *)(struct mapi_SLPSTRArray *)&lpProp->value.MVszA;
+       case PT_MV_BINARY:
+               return (const void *)(struct mapi_SBinaryArray *)&lpProp->value.MVbin;
        default:
                return NULL;
        }