Skip to content

Commit

Permalink
- Import Alan Alvarez work from libmapi++ into trunk
Browse files Browse the repository at this point in the history
- Add a g++ check in configure.ac: don't call libmapi++ rules if g++
  is missing
- Add libmapi++ to the build system
- Add a patch function to installsamba4.sh: rename private to
  private_data in samba4 events.h header file
- Change #include directives so it uses <libmapi++ ... rather than
  relative paths.
  • Loading branch information
jkerihuel committed Jul 26, 2008
1 parent ee298d6 commit 33c0197
Show file tree
Hide file tree
Showing 20 changed files with 1,743 additions and 2 deletions.
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,72 @@ libmapi/mapitags.c libmapi/mapicode.c mapitags_enum.h mapicodes_enum.h: \
libmapi/conf/mparse.pl
@./libmapi/conf/build.sh

#################################################################
# libmapi++ compilation rules
#################################################################

libmapixx: libmapi libmapixx-tests

libmapixx-installpc:

libmapixx-clean: libmapixx-tests-clean

libmapixx-install: libmapixx-installheader

libmapixx-uninstall: libmapixx-uninstallheader

libmapixx-installheader:
@echo "[*] install: libmapi++ headers"
$(INSTALL) -d $(DESTDIR)$(includedir)/libmapi++
$(INSTALL) -m 0644 libmapi++/attachment.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/clibmapi.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/folder.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/libmapi++.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/mapi_exception.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/message.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/message_store.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/object.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/profile.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/property_container.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -m 0644 libmapi++/session.h $(DESTDIR)$(includedir)/libmapi++/
$(INSTALL) -d $(DESTDIR)$(includedir)/libmapi++/impl
$(INSTALL) -m 0644 libmapi++/impl/* $(DESTDIR)$(includedir)/libmapi++/impl/

libmapixx-uninstallheader:
rm -rf $(DESTDIR)$(includedir)/libmapi++


libmapixx-tests: libmapixx-test \
libmapixx-attach

libmapixx-tests-clean: libmapixx-test-clean \
libmapixx-attach-clean

libmapixx-test: bin/libmapixx-test

libmapixx-test-clean:
rm -f bin/libmapixx-test
rm -f libmapi++/tests/*.o

bin/libmapixx-test: libmapi++/tests/test.cpp \
libmapi.$(SHLIBEXT).$(PACKAGE_VERSION)
@echo "Linking sample application $@"
@$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)

clean:: libmapixx-test-clean

libmapixx-attach: bin/libmapixx-attach

libmapixx-attach-clean:
rm -f bin/libmapixx-attach
rm -f libmapi++/tests/*.o

bin/libmapixx-attach: libmapi++/tests/attach_test.cpp \
libmapi.$(SHLIBEXT).$(PACKAGE_VERSION)
@echo "Linking sample application $@"
@$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)

clean:: libmapixx-attach-clean

#################################################################
# libmapiadmin compilation rules
Expand Down
4 changes: 4 additions & 0 deletions config.mk.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# Binary
CC=@CC@
CXX=@CXX@
BISON=@BISON@
FLEX=@FLEX@
PIDL=@PIDL@
Expand Down Expand Up @@ -36,6 +37,9 @@ CFLAGS+=-Duint_t="unsigned int"
CFLAGS+=@SAMBA_CFLAGS@ @LDB_CFLAGS@ @TALLOC_CFLAGS@
LIBS+=@SAMBA_LIBS@ @LDB_LIBS@ @TALLOC_LIBS@

# Assign CFLAGS to CXXFLAGS
CXXFLAGS=@CFLAGS@ -I. @SAMBA_CFLAGS@ @LDB_CFLAGS@ @TALLOC_CFLAGS@

# OPENCHANGE LIBRARIES
OC_IDL=@OC_IDL@
OC_LIBS=@OC_LIBS@
Expand Down
21 changes: 21 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,26 @@ dnl libraries require libmapi and libmapi require IDL
OC_IDL="idl"
AC_SUBST(OC_IDL)

dnl ###########################################################################
dnl libmapi++ dependencies
dnl ###########################################################################

dnl ---------------------------------------------------------------------------
dnl Check for g++
dnl ---------------------------------------------------------------------------
AC_CACHE_CHECK([C++ compiler availability], [libmapixx_gxx_works],
[
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([int main() { return 0; }],
[libmapixx_gxx_works=yes],
[libmapixx_gxx_works=no])
AC_LANG_POP([C++])
])

if test x"$libmapixx_gxx_works" = "xyes"; then
AC_PROG_CXX
OC_RULE_ADD(libmapixx, LIBS)
fi

dnl ###########################################################################
dnl libocpf dependencies
Expand Down Expand Up @@ -372,6 +391,7 @@ dnl ##########################################################################
OC_SETVAL(libmapi)
OC_SETVAL(libmapiadmin)
OC_SETVAL(libocpf)
OC_SETVAL(libmapixx)

OC_SETVAL(openchangeclient)
OC_SETVAL(mapiprofile)
Expand All @@ -397,6 +417,7 @@ OpenChange Configuration (Please review)
* OpenChange MAPI library: $enable_libmapi
* OpenChange Libraries:
- libmapi++: $enable_libmapixx
- libmapiadmin: $enable_libmapiadmin
- libocpf: $enable_libocpf
Expand Down
124 changes: 124 additions & 0 deletions libmapi++/attachment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
libmapi C++ Wrapper
Attachment Class
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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef LIBMAPIPP__ATTACHMENT_H__
#define LIBMAPIPP__ATTACHMENT_H__

#include <iostream> //for debugging
#include <string>

#include <libmapi++/clibmapi.h>
#include <libmapi++/message.h>

namespace libmapipp
{
class object;

/// \brief This class represents a message attachment
class attachment : public object {
public:
/** \brief Constructor
* \param mapi_message message this attachment belongs to.
* \param attach_num Attachment Number.
*/
attachment(message& mapi_message, const uint32_t attach_num) throw(mapi_exception)
: object(mapi_message.get_session(), "attachment"), m_attach_num(attach_num), m_bin_data(NULL), m_data_size(0), m_filename("")
{
if (OpenAttach(&mapi_message.data(), attach_num, &m_object) != MAPI_E_SUCCESS)
throw mapi_exception(GetLastError(), "attachment::attachment : OpenAttach");

property_container properties = get_property_container();
properties << PR_ATTACH_FILENAME << PR_ATTACH_LONG_FILENAME << PR_ATTACH_SIZE << PR_ATTACH_DATA_BIN << PR_ATTACH_METHOD;
properties.fetch();

const char* filename = static_cast<const char*>(properties[PR_ATTACH_LONG_FILENAME]);
if (!filename) {
filename = static_cast<const char*>(properties[PR_ATTACH_FILENAME]);
}

if (filename) {
m_filename = filename;
}

m_data_size = *(static_cast<const uint32_t*>(properties[PR_ATTACH_SIZE]));

const SBinary* attachment_data = static_cast<const SBinary*>(properties[PR_ATTACH_DATA_BIN]);

// Don't load PR_ATTACH_DATA_BIN if it's embedded in message.
// NOTE: Use RopOpenEmbeddedMessage when it is implemented.
const uint32_t attach_method = *static_cast<const uint32_t*>(properties[PR_ATTACH_METHOD]);
if (attach_method == ATTACH_EMBEDDED_MSG)
return;

// Get Binary Data.
if (attachment_data) {
m_data_size = attachment_data->cb;
m_bin_data = new uint8_t[m_data_size];
memcpy(m_bin_data, attachment_data->lpb, attachment_data->cb);
} else {
mapi_object_t obj_stream;
mapi_object_init(&obj_stream);
if (OpenStream(&m_object, PR_ATTACH_DATA_BIN, 0, &obj_stream) != MAPI_E_SUCCESS)
throw mapi_exception(GetLastError(), "attachment::attachment : OpenStream");

if (GetStreamSize(&obj_stream, &m_data_size) != MAPI_E_SUCCESS)
throw mapi_exception(GetLastError(), "attachment::attachment : GetStreamSize");

m_bin_data = new uint8_t[m_data_size];

uint32_t pos = 0;
uint16_t bytes_read = 0;
do {
if (ReadStream(&obj_stream, m_bin_data+pos, 1024, &bytes_read) != MAPI_E_SUCCESS)
throw mapi_exception(GetLastError(), "attachment::attachment : ReadStream");

pos += bytes_read;

} while (bytes_read && pos < m_data_size);

mapi_object_release(&obj_stream);
}

}

/// \brief Get Attachment number.
uint32_t get_num() const { return m_attach_num; }

const uint8_t* get_data() const { return m_bin_data; }
uint32_t get_data_size() const { return m_data_size; }
std::string get_filename() const { return m_filename; }

/// Destructor
virtual ~attachment() throw()
{
if (m_bin_data) delete m_bin_data;
}

private:
uint32_t m_attach_num;
uint8_t* m_bin_data; // (same as unsigned char* ?)
uint32_t m_data_size;
std::string m_filename;
};

} // namespace libmapipp

#endif //!LIBMAPIPP__ATTACHMENT_H__
27 changes: 27 additions & 0 deletions libmapi++/clibmapi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
libmapi C++ Wrapper
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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __CLIBMAPI_H
#define __CLIBMAPI_H

extern "C" {
#include <libmapi/libmapi.h>
}

#endif /* ! __CLIBMAPI_H */
Loading

0 comments on commit 33c0197

Please sign in to comment.