upload 2.0_beta code
authorWonYoung Choi <wy80.choi@samsung.com>
Tue, 21 Aug 2012 09:21:38 +0000 (18:21 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Tue, 21 Aug 2012 09:21:38 +0000 (18:21 +0900)
19 files changed:
debian/README [deleted file]
debian/capi-messaging-messages-dev.install [deleted file]
debian/capi-messaging-messages-dev.postinst [deleted file]
debian/capi-messaging-messages.install [deleted file]
debian/capi-messaging-messages.postinst [deleted file]
debian/changelog [deleted file]
debian/compat [deleted file]
debian/control [deleted file]
debian/rules [deleted file]
include/messages.h
include/messages_error.h
include/messages_private.h
include/messages_types.h
packaging/capi-messaging-messages.spec
src/messages.c
test/messages_incoming_test.c [new file with mode: 0644]
test/messages_search_test.c
test/messages_send_mms_test.c
test/messages_send_sms_test.c

diff --git a/debian/README b/debian/README
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/debian/capi-messaging-messages-dev.install b/debian/capi-messaging-messages-dev.install
deleted file mode 100644 (file)
index 8e40cf3..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-/usr/include/*
-/usr/include/*/*
-/usr/lib/pkgconfig/*.pc
-/usr/lib/lib*.so
diff --git a/debian/capi-messaging-messages-dev.postinst b/debian/capi-messaging-messages-dev.postinst
deleted file mode 100644 (file)
index 1a24852..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#!/bin/sh
diff --git a/debian/capi-messaging-messages.install b/debian/capi-messaging-messages.install
deleted file mode 100644 (file)
index eeaf559..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/usr/lib/lib*.so.*
diff --git a/debian/capi-messaging-messages.postinst b/debian/capi-messaging-messages.postinst
deleted file mode 100644 (file)
index 1a24852..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#!/bin/sh
diff --git a/debian/changelog b/debian/changelog
deleted file mode 100644 (file)
index 932b411..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-capi-messaging-messages (0.1.0-3) unstable; urgency=low
-
-  * fix messages_search_cb() callback.
-  * Git: slp/api/messages
-  * Tag: capi-messaging-messages_0.1.0-3
-
- -- WonYoung Choi <wy80.choi@samsung.com>  Thu, 05 Apr 2012 19:00:23 +0900
-
-capi-messaging-messages (0.1.0-2) unstable; urgency=low
-
-  * fix bugs, added DTS.
-  * Git: slp/api/messages
-  * Tag: capi-messaging-messages_0.1.0-2
-
- -- WonYoung Choi <wy80.choi@samsung.com>  Mon, 02 Apr 2012 17:17:52 +0900
-
-capi-messaging-messages (0.1.0-1) unstable; urgency=low
-
-  * Initial release.
-
- -- WonYoung Choi <wy80.choi@samsung.com>  Thu, 08 Mar 2012 15:04:37 +0900
diff --git a/debian/compat b/debian/compat
deleted file mode 100644 (file)
index 7ed6ff8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-5
diff --git a/debian/control b/debian/control
deleted file mode 100644 (file)
index 0cc178c..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-Source: capi-messaging-messages
-Section: libs
-Priority: extra
-Maintainer: WonYoung Choi <wy80.choi@samsung.com>
-Build-Depends: debhelper (>= 5), dlog-dev, libglib2.0-dev, libslp-msg-service-dev, capi-base-common-dev
-
-Package: capi-messaging-messages
-Architecture: any
-Depends: ${shilbs:Depends}, ${misc:Depends}
-Description: A SMS/MMS library in Tizen Native API
-
-Package: capi-messaging-messages-dev
-Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, capi-messaging-messages (= ${Source-Version}), dlog-dev, libglib2.0-dev, libslp-msg-service-dev, capi-base-common-dev
-Description: A SMS/MMS library in Tizen Native API (DEV)
-
-Package: capi-messaging-messages-dbg
-Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, capi-messaging-messages (= ${Source-Version})
-Description: A SMS/MMS library in Tizen Native API (DBG)
-
diff --git a/debian/rules b/debian/rules
deleted file mode 100755 (executable)
index 5d29f0d..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/make -f
-
-FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1)
-MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1)
-
-CFLAGS = -Wall -g
-
-ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
-       CFLAGS += -O0
-else
-       CFLAGS += -O2
-endif
-CMAKE_ROOT_DIR ?= $(CURDIR)
-CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp
-
-configure: configure-stamp
-configure-stamp:
-       dh_testdir
-       mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER}
-
-       touch configure-stamp
-
-
-build: build-stamp
-build-stamp: configure-stamp 
-       dh_testdir
-       cd $(CMAKE_BUILD_DIR) && $(MAKE)
-       touch $@
-
-clean:
-       cd $(CMAKE_ROOT_DIR)
-       dh_testdir
-       dh_testroot
-       rm -f build-stamp configure-stamp
-       rm -f `find . -name *.pc`
-       rm -rf $(CMAKE_BUILD_DIR)
-       dh_clean
-       
-install: build
-       dh_testdir
-       dh_testroot
-       dh_clean -k 
-       dh_installdirs
-
-       cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
-
-binary-indep: build install
-
-binary-arch: build install
-       dh_testdir
-       dh_testroot
-       dh_installchangelogs 
-       dh_installdocs
-       dh_installexamples
-       dh_install --sourcedir=debian/tmp
-       dh_installman
-       dh_link
-       dh_strip --dbg-package=capi-messaging-messages-dbg
-       dh_fixperms
-       dh_makeshlibs
-       dh_installdeb
-       dh_shlibdeps
-       dh_gencontrol
-       dh_md5sums
-       dh_builddeb
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install configure
-
index 6529dea..09e7a96 100644 (file)
@@ -18,6 +18,7 @@
 #define __TIZEN_MESSAGING_H__
 
 
+#include <time.h>
 #include <messages_types.h>
 #include <messages_error.h>
 
@@ -26,8 +27,14 @@ extern "C"
 {
 #endif
 
+/*
+ * @file messages.h
+ * @brief This file contains the messages API.
+ */
+
+
 /**
- * @addtogroup TIZEN_MESSAGING_MODULE
+ * @addtogroup CAPI_MESSAGING_MESSAGES_MODULE
  * @{
  */
 
@@ -97,6 +104,46 @@ int messages_create_message(messages_message_type_e type, messages_message_h *ms
  */
 int messages_destroy_message(messages_message_h msg);
 
+/**
+ * @brief Gets the message id of the message.
+ *
+ * @param[in] msg The message handle
+ * @param[out] msg_id The message id
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGES_ERROR_NONE Successful
+ * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGES_ERROR_OPERATION_FAILED Messaging operation failed
+ *
+ * @see messages_search_message_by_id()
+ */
+int messages_get_message_id(messages_message_h msg, int *msg_id);
+
+/**
+ * @brief Gets the message box type of the message.
+ *
+ * @param[in] msg The message handle
+ * @param[out] mbox The message box type
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGES_ERROR_NONE Successful
+ * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int messages_get_mbox_type(messages_message_h msg, messages_message_box_e *mbox);
+
+/**
+ * @brief Gets the destination port of the message.
+ *
+ * @param[in] msg The message handle
+ * @param[out] port The destination port of the message
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGES_ERROR_NONE Successful
+ * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see messages_add_sms_listening_port()
+ */
+int messages_get_message_port(messages_message_h msg, int *port);
 
 /**
  * @brief Gets the type of the message.
@@ -107,8 +154,6 @@ int messages_destroy_message(messages_message_h msg);
  * @return 0 on success, otherwise a negative error value.
  * @retval #MESSAGES_ERROR_NONE Successful
  * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see        messages_create_message()
  */
 int messages_get_message_type(messages_message_h msg, messages_message_type_e *type);
 
@@ -120,6 +165,7 @@ int messages_get_message_type(messages_message_h msg, messages_message_type_e *t
  * @param[in] msg The message handle
  * @param[in] address The recipient's address to receive a message \n
  *                   The maximum length of @a address is 254.
+ * @param[in] type The recipient's type of the @a address
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #MESSAGES_ERROR_NONE Successful
@@ -128,7 +174,7 @@ int messages_get_message_type(messages_message_h msg, messages_message_type_e *t
  * @see        messages_get_address()
  * @see        messages_remove_all_addresses()
  */
-int messages_add_address(messages_message_h msg, const char *address);
+int messages_add_address(messages_message_h msg, const char *address, messages_recipient_type_e type);
 
 
 /**
@@ -155,6 +201,7 @@ int messages_get_address_count(messages_message_h msg, int *count);
  * @param[in] msg The message handle
  * @param[in] index The zero-based index of address to receive a message.
  * @param[out] address The recipient's address with specified index
+ * @param[out] type The recipient's type of the @a address.
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #MESSAGES_ERROR_NONE Successful
@@ -164,7 +211,7 @@ int messages_get_address_count(messages_message_h msg, int *count);
  * @see        messages_add_address()
  * @see        messages_remove_all_addresses()
  */
-int messages_get_address(messages_message_h msg, int index, char **address);
+int messages_get_address(messages_message_h msg, int index, char **address, messages_recipient_type_e *type);
 
 
 /**
@@ -218,6 +265,18 @@ int messages_get_text(messages_message_h msg, char **text);
 
 
 /**
+ * @brief Gets the time of the message.
+ *
+ * @param[in] msg The message handle
+ * @param[out] time The time of the message
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGES_ERROR_NONE Successful
+ * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int messages_get_time(messages_message_h msg, time_t *time);
+
+/**
  * @brief Sends the message to all recipients.
  *
  * @remarks In order to check whether sending a message succeeds, 
@@ -225,6 +284,9 @@ int messages_get_text(messages_message_h msg, char **text);
  *
  * @param[in] service The message service handle
  * @param[in] msg The message handle
+ * @param[in] save_to_sentbox Set to true to save the message in the sentbox, else false
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #MESSAGES_ERROR_NONE Successful
@@ -234,22 +296,46 @@ int messages_get_text(messages_message_h msg, char **text);
  *
  * @see messages_sent_cb()
  */
-int messages_send_message(messages_service_h service, messages_message_h msg);
+int messages_send_message(messages_service_h service, messages_message_h msg, bool save_to_sentbox, messages_sent_cb callback, void *user_data);
+
+/**
+ * @brief Gets the message count in the specific message box
+ *
+ * @param[in] service The message service handle
+ * @param[in] mbox The message box type
+ * @param[in] type The message type \n
+ *                     If @a type is #MESSAGES_TYPE_UNKNOWN, all sms and mms messages are counted.
+ * @param[out] count The number of messages
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGES_ERROR_NONE Successful
+ * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGES_ERROR_OPERATION_FAILED Messaging operation failed
+ */
+int messages_get_message_count(messages_service_h service, 
+                                                       messages_message_box_e mbox, messages_message_type_e type,
+                                                       int *count);
+
 
 
 /**
  * @brief Searches for messages.
  *
+ * @details @a message_array must be released with messages_free_message_array() by you.
+ *
  * @param[in] service The message service handle
  * @param[in] mbox The message box type
  * @param[in] type The message type \n
  *                If @a type is #MESSAGES_TYPE_UNKNOWN, all sms and mms messages are searched.
  * @param[in] keyword The keyword search in text and subject
- * @param[in] address The recepient address
+ * @param[in] address The recipient address
  * @param[in] offset The start position (base 0)
- * @param[in] limit The maximum amount of messages to get (In case of 0, this method passes to thecallback all searched messages.)
- * @param[in] callback The callback function to get a message
- * @param[in] user_data The user data to be passed to the callback function
+ * @param[in] limit The maximum amount of messages to get (In case of 0, this method passes to the callback all searched messages.)
+ * @param[out] message_array The array of the message handle
+ * @param[out] length The number of messages of the message_array
+ * @param[out] total The count of the messages that have been retrieved as a result without applying @a limit and @a offset. \n
+ *                     The value can be used to calculate the total number of page views for the searched messages.\n
+ *                     For example, if the count of message search is 50 and the limit is 20, then using this value, you can notice the total page is 3.
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #MESSAGES_ERROR_NONE Successful
@@ -257,54 +343,77 @@ int messages_send_message(messages_service_h service, messages_message_h msg);
  * @retval #MESSAGES_ERROR_OUT_OF_MEMORY Out of memory
  * @retval #MESSAGES_ERROR_OPERATION_FAILED Messaging operation failed
  *
- * @post It invokes messages_search_cb().
- * @see messages_search_cb()
+ * @see messages_free_message_array()
  */
-int messages_foreach_message_from_db(messages_service_h service,
-                                                        messages_message_box_e mbox,
-                                                        messages_message_type_e type,
-                                                        const char *keyword, const char *address,
-                                                        int offset, int limit,
-                                                        messages_search_cb callback, void *user_data);
-
+int messages_search_message(messages_service_h service,
+                                                       messages_message_box_e mbox,
+                                                       messages_message_type_e type,
+                                                       const char *keyword, const char *address,
+                                                       int offset, int limit,
+                                                       messages_message_h **message_array, int *length, int *total);
+                                                       
 /**
- * @brief Registers a callback to be invoked when a message is sent.
+ * @brief Searches a message with the given message id.
  *
- * @details You will be notified when sending a message finishes and check whether it succeeds using messages_sent_cb().
+ * @remark @a msg must be released with messages_destroy_message() by you.
  *
  * @param[in] service The message service handle
- * @param[in] callback The callback function
- * @param[in] user_data The user data to be passed to the callback function
+ * @param[in] msg_id The message id
+ * @param[out] msg A message handle to be newly created if successful
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #MESSAGES_ERROR_NONE Successful
  * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #MESSAGES_ERROR_OPERATION_FAILED Messaging operation failed
+ * @retval #MESSAGES_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see messages_get_message_id()
+ */
+int messages_search_message_by_id(messages_service_h service, int msg_id, messages_message_h *msg);
+
+
+/**
+ * @brief Frees message array.
  *
- * @post It will invoke messages_sent_cb().
+ * @param[in] message_array The array of the message handle
  *
- * @see messages_unset_message_sent_cb()
- * @see messages_sent_cb()
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGES_ERROR_NONE Successful
+ * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see messages_search_message()
  */
-int messages_set_message_sent_cb(messages_service_h service, messages_sent_cb callback, void *user_data);
+int messages_free_message_array(messages_message_h *message_array);
 
 
 /**
- * @brief Unregisters the callback function.
+ * @brief Retrieves the searched messages by invoking the given callback function iteratively.
  *
  * @param[in] service The message service handle
+ * @param[in] mbox The message box type
+ * @param[in] type The message type \n
+ *                If @a type is #MESSAGES_TYPE_UNKNOWN, all sms and mms messages are searched.
+ * @param[in] keyword The keyword search in text and subject
+ * @param[in] address The recipient address
+ * @param[in] offset The start position (base 0)
+ * @param[in] limit The maximum amount of messages to get (In case of 0, this method passes to the callback all searched messages.)
+ * @param[in] callback The callback function to get a message
+ * @param[in] user_data The user data to be passed to the callback function
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #MESSAGES_ERROR_NONE Successful
  * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGES_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGES_ERROR_OPERATION_FAILED Messaging operation failed
  *
- * @post It will invoke messages_sent_cb().
- *
- * @see messages_set_message_sent_cb()
- * @see messages_sent_cb()
+ * @post It invokes messages_search_cb().
+ * @see messages_search_cb()
  */
-int messages_unset_message_sent_cb(messages_service_h service);
-
+int messages_foreach_message(messages_service_h service,
+                                                        messages_message_box_e mbox,
+                                                        messages_message_type_e type,
+                                                        const char *keyword, const char *address,
+                                                        int offset, int limit,
+                                                        messages_search_cb callback, void *user_data);
 
 /**
  * @brief Registers a callback to be invoked when an incoming message is received.
@@ -340,9 +449,23 @@ int messages_set_message_incoming_cb(messages_service_h service, messages_incomi
  */
 int messages_unset_message_incoming_cb(messages_service_h service);
 
+/**
+ * @brief Adds an additional listening port for the incoming SMS messages.
+ *
+ * @param[in] service The message service handle
+ * @param[in] port The listening port for the SMS messages
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MESSAGES_ERROR_NONE Successful
+ * @retval #MESSAGES_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see messages_set_message_incoming_cb()
+ * @see messages_get_message_port()
+ */
+int messages_add_sms_listening_port(messages_service_h service, int port);
 
 /**
- * @addtogroup TIZEN_MESSAGING_MMS_MODULE
+ * @addtogroup CAPI_MESSAGING_MESSAGES_MMS_MODULE
  * @{
  */
 /**
index c42781e..9299113 100644 (file)
@@ -26,7 +26,7 @@ extern "C"
 
 
 /**
- * @addtogroup TIZEN_MESSAGING_MODULE
+ * @addtogroup CAPI_MESSAGING_MESSAGES_MODULE
  * @{
  */
 
@@ -42,7 +42,7 @@ typedef enum {
        MESSAGES_ERROR_COMMUNICATION_WITH_SERVER_FAILED = TIZEN_ERROR_MESSAGING_CLASS|0x502, /**< Communication with server failed */
        MESSAGES_ERROR_SENDING_FAILED = TIZEN_ERROR_MESSAGING_CLASS|0x504, /**< Sending a message failed */
        MESSAGES_ERROR_OPERATION_FAILED = TIZEN_ERROR_MESSAGING_CLASS|0x505, /**< Messaging operation failed */
-} MESSAGES_error_e;
+} messages_error_e;
 
 /**
  * @}
index 33759c9..b7f7cd4 100644 (file)
@@ -23,26 +23,29 @@ extern "C"
 #endif
 
 typedef struct _messages_service_s {
-       MSG_HANDLE_T service_h;
-       void*        sent_cb;
-       void*        sent_cb_user_data;
-       bool         sent_cb_enabled;
+       msg_handle_t service_h;
        void*        incoming_cb;
        void*        incoming_cb_user_data;
        bool         incoming_cb_enabled;
+       GSList*      sent_cb_list;
 } messages_service_s;
 
 typedef struct _messages_message_s {
-       msg_message_t msg_h;    
-       char *text;
-       GSList *attachment_list;
+       msg_struct_t  msg_h;    
+       char*         text;
+       GSList*       attachment_list;
 } messages_message_s;
 
 typedef struct _messages_attachment_s {
-    int media_type;
-    char filepath[MSG_FILEPATH_LEN_MAX];
+    int           media_type;
+    char          filepath[MSG_FILEPATH_LEN_MAX];
 } messages_attachment_s;
 
+typedef struct _messages_sent_callback_s {
+       int               req_id;
+       void*             callback;
+       void*             user_data;
+} messages_sent_callback_s;
 
 #ifdef __cplusplus
 }
index a2efcba..b7f10d2 100644 (file)
@@ -25,7 +25,7 @@ extern "C"
 #endif
 
 /**
- * @addtogroup TIZEN_MESSAGING_MODULE
+ * @addtogroup CAPI_MESSAGING_MESSAGES_MODULE
  * @{
  */
 
@@ -40,7 +40,6 @@ typedef struct messages_service_s *messages_service_h;
  */
 typedef struct messages_message_s *messages_message_h;
 
-
 /**
  * @brief The message box type.
  */
@@ -73,6 +72,15 @@ typedef enum {
        MESSAGES_MEDIA_VIDEO = 3, /**< The video */
 } messages_media_type_e;
 
+/**
+ * @brief The recipient type of a message.
+ */
+typedef enum {
+       MESSAGES_RECIPIENT_UNKNOWN = 0,
+       MESSAGES_RECIPIENT_TO = 1,
+       MESSAGES_RECIPIENT_CC = 2,
+       MESSAGES_RECIPIENT_BCC = 3,
+} messages_recipient_type_e;
 
 /**
  * @brief The result of sending a message.
@@ -83,7 +91,6 @@ typedef enum {
 } messages_sending_result_e;
 
 
-
 /**
  * @brief Called when the process of sending a message to all recipients finishes. 
  *
@@ -129,9 +136,9 @@ typedef void (* messages_incoming_cb)(messages_message_h incoming_msg, void *use
  *
  * @return @c true to continue with the next iteration of the loop or return @c false to break out of the loop.
  *
- * @pre messages_foreach_message_from_db() will invoke this callback function.
+ * @pre messages_foreach_message() will invoke this callback function.
  *
- * @see messages_foreach_message_from_db()
+ * @see messages_foreach_message()
  */
 typedef bool (* messages_search_cb)(messages_message_h msg, int index, int result_count, int total_count, void *user_data);
 
index 1ee5ca0..234a63c 100644 (file)
@@ -1,7 +1,7 @@
 Name:       capi-messaging-messages
 Summary:    A SMS/MMS library in Tizen Native API
 Version: 0.1.0
-Release:    3
+Release:    11
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 BuildRequires:  cmake
@@ -31,13 +31,16 @@ Requires:  pkgconfig(capi-base-common)
 
 %build
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+rm -fr cmake_build_tmp; mkdir cmake_build_tmp
+cd cmake_build_tmp
+cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
 
 
 make %{?jobs:-j%jobs}
 
 %install
 rm -rf %{buildroot}
+cd cmake_build_tmp
 %make_install
 
 %post -p /sbin/ldconfig
index b46dbd8..3b648b2 100644 (file)
  * limitations under the License. 
  */
 
-#include <memory.h>
-
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+
 #include <glib.h>
 
 #include <dlog.h>
-#include <MapiMessage.h>
-#include <MapiTransport.h>
-#include <MapiStorage.h>
-#include <MapiControl.h>
-#include <MsgTypes.h>
+#include <msg.h>
+#include <msg_transport.h>
+#include <msg_storage.h>
 
 #include <messages.h>
 #include <messages_types.h>
 #include <messages_private.h>
 
-
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
 int _messages_error_converter(int err, const char *func, int line);
 int _messages_get_media_type_from_filepath(const char *filepath);
 int _messages_save_mms_data(messages_message_s *msg);
-int _messages_load_mms_data(messages_message_s *msg, MSG_HANDLE_T handle);
+int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle);
 int _messages_save_textfile(const char *text, char **filepath);
 int _messages_load_textfile(const char *filepath, char **text);
-MSG_FOLDER_ID_T _messages_convert_mbox_to_fw(messages_message_box_e mbox);
-MSG_MESSAGE_TYPE_T _messages_convert_msgtype_to_fw(messages_message_type_e type);
+void _messages_sent_mediator_cb(msg_handle_t handle, msg_struct_t pStatus, void *user_param);
+
+int _messages_convert_mbox_to_fw(messages_message_box_e mbox);
+int _messages_convert_msgtype_to_fw(messages_message_type_e type);
+int _messages_convert_recipient_to_fw(messages_recipient_type_e type);
 
 
 #define ERROR_CONVERT(err) _messages_error_converter(err, __FUNCTION__, __LINE__);
@@ -60,10 +62,6 @@ MSG_MESSAGE_TYPE_T _messages_convert_msgtype_to_fw(messages_message_type_e type)
                return MESSAGES_ERROR_INVALID_PARAMETER; \
        }       
 
-
-
-
-
 int messages_open_service(messages_service_h *svc)
 {
        int ret;
@@ -79,22 +77,40 @@ int messages_open_service(messages_service_h *svc)
                return MESSAGES_ERROR_OUT_OF_MEMORY;
        }
 
-       _svc->sent_cb = NULL;
-       _svc->sent_cb_user_data = NULL;
-       _svc->sent_cb_enabled = false;
+       _svc->sent_cb_list = NULL;
+       _svc->incoming_cb = NULL;
+       _svc->incoming_cb_enabled = false;
 
        ret = msg_open_msg_handle(&_svc->service_h);
+       if (MSG_SUCCESS != ret) {
+               free(_svc);
+               return ERROR_CONVERT(ret);
+       }
+       
+       ret = msg_reg_sent_status_callback(_svc->service_h, &_messages_sent_mediator_cb, (void*)_svc);
+       if (MSG_SUCCESS != ret) {
+               free(_svc);
+               return ERROR_CONVERT(ret);
+       }       
 
        *svc = (messages_service_h)_svc;
 
-       return ERROR_CONVERT(ret);
+       return MESSAGES_ERROR_NONE;
 }
 
 int messages_close_service(messages_service_h svc)
 {
        int ret;
+       
+       messages_service_s *_svc = (messages_service_s *)svc;
 
-       ret = msg_close_msg_handle(&((messages_service_s*)svc)->service_h);
+       ret = msg_close_msg_handle(&_svc->service_h);
+       
+       if (_svc->sent_cb_list) {       
+               g_slist_foreach(_svc->sent_cb_list, (GFunc)g_free, NULL);
+               g_slist_free(_svc->sent_cb_list);
+               _svc->sent_cb_list = NULL;
+       }
 
        free(svc);
 
@@ -116,7 +132,7 @@ int messages_create_message(messages_message_type_e type, messages_message_h *ms
                return MESSAGES_ERROR_OUT_OF_MEMORY;
        }
        
-       _msg->msg_h = msg_new_message();
+       _msg->msg_h = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
        if (NULL == _msg->msg_h)
        {
                LOGE("[%s] OUT_OF_MEMORY(0x%08x) fail to create '_msg->msg_h'."
@@ -130,20 +146,20 @@ int messages_create_message(messages_message_type_e type, messages_message_h *ms
 
        if (MESSAGES_TYPE_SMS == type)
        {
-               ret = ERROR_CONVERT(msg_set_message_type(_msg->msg_h, MSG_TYPE_SMS));
+               ret = ERROR_CONVERT(msg_set_int_value(_msg->msg_h, MSG_MESSAGE_TYPE_INT, MSG_TYPE_SMS));
                if (MESSAGES_ERROR_NONE != ret)
                {
-                       msg_release_message(&_msg->msg_h);
+                       msg_release_struct(&_msg->msg_h);
                        free(_msg);
                        return ret;
                }
        }
        else if (MESSAGES_TYPE_MMS == type)
        {
-               ret = ERROR_CONVERT(msg_set_message_type(_msg->msg_h, MSG_TYPE_MMS));
+               ret = ERROR_CONVERT(msg_set_int_value(_msg->msg_h, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS));
                if (MESSAGES_ERROR_NONE != ret)
                {
-                       msg_release_message(&_msg->msg_h);
+                       msg_release_struct(&_msg->msg_h);
                        free(_msg);
                        return ret;
                }                               
@@ -152,7 +168,7 @@ int messages_create_message(messages_message_type_e type, messages_message_h *ms
        {
                LOGE("[%s] INVALID_PARAMETER(0x%08x) : the message type is unknown."
                        , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER);
-               msg_release_message(&_msg->msg_h);
+               msg_release_struct(&_msg->msg_h);
                free(_msg);
                return MESSAGES_ERROR_INVALID_PARAMETER;
        }
@@ -177,7 +193,7 @@ int messages_destroy_message(messages_message_h msg)
                _msg->text = NULL;
        }
 
-       ret = msg_release_message(&_msg->msg_h);
+       ret = msg_release_struct(&_msg->msg_h);
 
        free(msg);
 
@@ -187,13 +203,18 @@ int messages_destroy_message(messages_message_h msg)
 int messages_get_message_type(messages_message_h msg, messages_message_type_e *type)
 {
        int msgType;
+       int ret;
 
        messages_message_s *_msg = (messages_message_s*)msg;
        CHECK_NULL(_msg);
        CHECK_NULL(_msg->msg_h);
        CHECK_NULL(type);
-
-       msgType = msg_get_message_type(_msg->msg_h);
+       
+       ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_TYPE_INT, &msgType);
+       if (ret != MSG_SUCCESS)
+       {
+               return ERROR_CONVERT(ret);
+       }
 
        switch (msgType)
        {
@@ -219,46 +240,107 @@ int messages_get_message_type(messages_message_h msg, messages_message_type_e *t
        return MESSAGES_ERROR_NONE;
 }
 
-int messages_add_address(messages_message_h msg, const char *address)
+int messages_add_address(messages_message_h msg, const char *address, messages_recipient_type_e type)
 {
        int ret;
 
+       int msgType;
+       msg_struct_list_s *addr_list = NULL;
+       msg_struct_t addr_info;
+       
        messages_message_s *_msg = (messages_message_s*)msg;
        
        CHECK_NULL(_msg);
        CHECK_NULL(_msg->msg_h);
        CHECK_NULL(address);
+       
+       msg_get_int_value(_msg->msg_h, MSG_MESSAGE_TYPE_INT, (int *)&msgType);
+       
+       ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+       if (MSG_SUCCESS != ret) {
+               return ERROR_CONVERT(ret);
+       }
+       
+       addr_info = addr_list->msg_struct_info[addr_list->nCount];
+       
+       if (MSG_TYPE_SMS == msgType)
+       {
+               msg_set_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_TO);
+       }
+       else if (MSG_TYPE_MMS == msgType)
+       {
+               msg_set_int_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
+               msg_set_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, _messages_convert_recipient_to_fw(type));
+       }
+       else
+       {
+               LOGE("[%s] INVALID_PARAMETER(0x%08x) : the message type is unknown."
+                       , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER);
+               return MESSAGES_ERROR_INVALID_PARAMETER;
+       }
 
-       ret = msg_add_address(_msg->msg_h, address, MSG_RECIPIENTS_TYPE_TO);
+       ret = msg_set_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)address, strlen(address));
+       if (MSG_SUCCESS != ret) {
+               return ERROR_CONVERT(ret);
+       }
+       
+       addr_list->nCount++;
 
-       return ERROR_CONVERT(ret);
+       return MESSAGES_ERROR_NONE;
 }
 
 int messages_get_address_count(messages_message_h msg, int *count)
 {
+       int ret;
+       msg_struct_list_s *addr_list = NULL;
+       
        messages_message_s *_msg = (messages_message_s*)msg;
 
        CHECK_NULL(_msg);
        CHECK_NULL(_msg->msg_h);
        CHECK_NULL(count);
+       
+       ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+       if (MSG_SUCCESS != ret) {
+               return ERROR_CONVERT(ret);
+       }
 
-       *count = msg_get_address_count(_msg->msg_h);
+       *count = addr_list->nCount;
 
        return MESSAGES_ERROR_NONE;
 }
 
-int messages_get_address(messages_message_h msg, int index, char **address)
+int messages_get_address(messages_message_h msg, int index, char **address, messages_recipient_type_e *type)
 {
-       const char *_address;
+       int ret;
+       char _address[MAX_ADDRESS_VAL_LEN] = {0, };
+       int _type;
+       
+       msg_struct_list_s *addr_list = NULL;
+       msg_struct_t addr_info;
 
        messages_message_s *_msg = (messages_message_s*)msg;
 
        CHECK_NULL(_msg);
        CHECK_NULL(_msg->msg_h);
        CHECK_NULL(address);
-
-       _address = msg_get_ith_address(_msg->msg_h, index);
-       if (NULL == _address)
+       
+       ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+       if (MSG_SUCCESS != ret) {
+               return ERROR_CONVERT(ret);
+       }
+       
+       if (index > addr_list->nCount)
+       {
+               LOGE("[%s] INVALID_PARAMETER(0x%08x) : index(%d) > addr_list->nCount(%d) "
+                       , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER, index, addr_list->nCount);
+               return MESSAGES_ERROR_INVALID_PARAMETER;
+       }
+       
+       addr_info = addr_list->msg_struct_info[index];
+       
+       ret = msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, _address, MAX_ADDRESS_VAL_LEN);
+       if (MSG_SUCCESS != ret)
        {
                *address = NULL;
        }
@@ -273,96 +355,96 @@ int messages_get_address(messages_message_h msg, int index, char **address)
                }
        }
 
+       if (NULL != type)
+       {       
+               ret = msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &_type);
+               if (MSG_SUCCESS != ret)
+               {
+                       *type = MESSAGES_RECIPIENT_UNKNOWN;
+               }
+               else
+               {
+                       switch (_type) {
+                               case MSG_RECIPIENTS_TYPE_TO:
+                                       *type = MESSAGES_RECIPIENT_TO;
+                                       break;
+                               case MSG_RECIPIENTS_TYPE_CC:
+                                       *type = MESSAGES_RECIPIENT_CC;
+                                       break;
+                               case MSG_RECIPIENTS_TYPE_BCC:
+                                       *type = MESSAGES_RECIPIENT_BCC;
+                                       break;
+                               default:
+                                       *type = MESSAGES_RECIPIENT_UNKNOWN;
+                                       break;  
+                       }
+               }
+       }
+
        return MESSAGES_ERROR_NONE;
 }
 
 int messages_remove_all_addresses(messages_message_h msg)
 {
        int ret;
+       msg_struct_list_s *addr_list = NULL;
 
        messages_message_s *_msg = (messages_message_s*)msg;
 
        CHECK_NULL(_msg);
        CHECK_NULL(_msg->msg_h);
 
-       ret = msg_reset_address(_msg->msg_h);
+       ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+       if (MSG_SUCCESS != ret)
+       {
+               addr_list->nCount = 0;
+       }
 
        return ERROR_CONVERT(ret);
 }
 
 void _dump_message(messages_message_h msg)
 {
-       int ret;
-       //messages_message_s *_msg = (messages_message_s*)msg;
-       
-       messages_message_type_e msgType;
-       char *buf;
-       int i, count;
-
-
-       
-       LOGD("=======================================================");
-       // type
-       ret = messages_get_message_type(msg, &msgType);
-       if (MESSAGES_ERROR_NONE == ret) {
-               switch(msgType) {
-                       case MESSAGES_TYPE_SMS: LOGD("Type: SMS"); break;
-                       case MESSAGES_TYPE_MMS: LOGD("Type: MMS"); break;
-                       default: LOGD("Type: Unknown (%d)", msgType); break;
-               }
-       } else {
-               LOGD("Type: Err (%d)", ret);
-       }
-
-       // text
-       ret = messages_get_text(msg, &buf);     
-       if (MESSAGES_ERROR_NONE == ret) {
-               LOGD("Text: %s", buf);
-               free(buf);
-       } else {
-               LOGD("Text: Err (%d)", ret);
-       }
-
-       // address
-       ret = messages_get_address_count(msg, &count);
-       if (MESSAGES_ERROR_NONE == ret) {
-               LOGD("Address_Count: %d", count);
-               for (i=0; i < count; i++) {
-                       ret = messages_get_address(msg, i, &buf);
-                       if (MESSAGES_ERROR_NONE == ret) {
-                               LOGD("Address[%d]: %s", i, buf);
-                               free(buf);
-                       } else {
-                               LOGD("Address[%d]: Err (%d)", ret);
-                       }
-               }               
-       } else {
-               LOGD("Address Count: Err (%d)", ret);
-       }
 
 }
 
-int messages_send_message(messages_service_h svc, messages_message_h msg)
+int messages_send_message(messages_service_h svc, messages_message_h msg, bool save_to_sentbox,
+                                                       messages_sent_cb callback, void *user_data)
 {
        int ret;
-       MSG_REQUEST_S req = {0};
+       int reqId;
+       msg_struct_t req;
+       msg_struct_t sendOpt;
+       msg_struct_t option = NULL;
        messages_message_type_e msgType;
 
        messages_service_s *_svc = (messages_service_s*)svc;
        messages_message_s *_msg = (messages_message_s*)msg;
+       
+       messages_sent_callback_s *_cb;
 
        CHECK_NULL(_svc);
        CHECK_NULL(_svc->service_h);
        CHECK_NULL(_msg);
        CHECK_NULL(_msg->msg_h);
 
-       req.msg = (msg_message_t)_msg->msg_h;
+
+       sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+       msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, true);
+       msg_set_bool_value(sendOpt, MSG_SEND_OPT_DELIVER_REQ_BOOL, false);
+       msg_set_bool_value(sendOpt, MSG_SEND_OPT_KEEPCOPY_BOOL, save_to_sentbox);       
 
        messages_get_message_type(msg, &msgType);
 
        if (MESSAGES_TYPE_SMS == msgType)
-       {
-               ret = msg_sms_send_message(_svc->service_h, &req);
+       {       
+               req = msg_create_struct(MSG_STRUCT_REQUEST_INFO);
+               msg_set_struct_handle(req, MSG_REQUEST_MESSAGE_HND, _msg->msg_h);
+               msg_set_struct_handle(req, MSG_REQUEST_SENDOPT_HND, sendOpt);   
+               
+               ret = msg_sms_send_message(_svc->service_h, req);
+               
+               msg_release_struct(&req);
        }
        else if (MESSAGES_TYPE_MMS == msgType)
        {
@@ -373,52 +455,167 @@ int messages_send_message(messages_service_h svc, messages_message_h msg)
                        {
                                _dump_message(msg);
                        }
-                       ret = msg_mms_send_message(_svc->service_h, &req);
+               
+                       req = msg_create_struct(MSG_STRUCT_REQUEST_INFO);
+                       msg_set_struct_handle(req, MSG_REQUEST_MESSAGE_HND, _msg->msg_h);
+                       msg_set_struct_handle(req, MSG_REQUEST_SENDOPT_HND, sendOpt);   
+               
+                       msg_get_struct_handle(sendOpt, MSG_SEND_OPT_MMS_OPT_HND, &option);
+                       msg_set_bool_value(option, MSG_MMS_SENDOPTION_READ_REQUEST_BOOL, false);
+                       msg_set_int_value(option, MSG_MMS_SENDOPTION_PRIORITY_INT, MSG_MESSAGE_PRIORITY_NORMAL);
+                       msg_set_int_value(option, MSG_MMS_SENDOPTION_EXPIRY_TIME_INT, MSG_EXPIRY_TIME_MAXIMUM);
+                       msg_set_int_value(option, MSG_MMS_SENDOPTION_DELIVERY_TIME_INT, MSG_DELIVERY_TIME_IMMEDIATLY);                  
+                       
+                       ret = msg_mms_send_message(_svc->service_h, req);
+                       
+                       msg_release_struct(&req);
                }
        }
        else
        {
                LOGE("[%s] INVALID_PARAMETER(0x%08x) : Invalid Message Type.", 
-                               __FUNCTION__, TIZEN_ERROR_INVALID_PARAMETER);
+                               __FUNCTION__, TIZEN_ERROR_INVALID_PARAMETER);           
                return TIZEN_ERROR_INVALID_PARAMETER;
        }
+       
+       msg_release_struct(&sendOpt);
+       
+       if (NULL != callback && MSG_SUCCESS == ret)
+       {
+               // Add callback to mapping table
+               _cb = (messages_sent_callback_s *)malloc(sizeof(messages_sent_callback_s));
+               if (NULL != _cb) {
+                       msg_get_int_value(req, MSG_REQUEST_REQUESTID_INT, &reqId);
+                       _cb->req_id = reqId;
+                       _cb->callback = (void *)callback;
+                       _cb->user_data = user_data;
+                       
+                       _svc->sent_cb_list = g_slist_append(_svc->sent_cb_list, _cb);
+               }
+       }
 
        return ERROR_CONVERT(ret);
 }
 
-int messages_foreach_message_from_db(messages_service_h svc,
-                                                        messages_message_box_e mbox,
-                                                        messages_message_type_e type,
-                                                        const char *keyword, const char *address,
-                                                        int offset, int limit,
-                                                        messages_search_cb callback, void *user_data)
+int messages_get_message_count(messages_service_h service, 
+                                                       messages_message_box_e mbox, messages_message_type_e type,
+                                                       int *count)
+{
+       int ret;
+       msg_folder_id_t folderId;
+       msg_struct_t countInfo = NULL;
+       int nSms, nMms;
+       
+       messages_service_s *_svc = (messages_service_s*)service;
+       
+       CHECK_NULL(_svc);
+       CHECK_NULL(count);
+       
+       nSms = 0;
+       nMms = 0;
+       
+       if (MESSAGES_MBOX_ALL == mbox)
+       {
+               if (MESSAGES_TYPE_SMS == type || MESSAGES_TYPE_UNKNOWN == type)
+               {
+                       ret = ERROR_CONVERT(msg_count_msg_by_type(_svc->service_h, MSG_TYPE_SMS, &nSms));
+                       if (MESSAGES_ERROR_NONE != ret)
+                       {
+                               return ret;
+                       }
+               }
+
+               if (MESSAGES_TYPE_MMS == type || MESSAGES_TYPE_UNKNOWN == type)
+               {
+                       ret = ERROR_CONVERT(msg_count_msg_by_type(_svc->service_h, MSG_TYPE_MMS, &nMms));
+                       if (MESSAGES_ERROR_NONE != ret)
+                       {
+                               return ret;
+                       }
+               }
+
+               *count = nSms + nMms;
+       }
+       else
+       {
+               countInfo = msg_create_struct(MSG_STRUCT_COUNT_INFO);
+               folderId = _messages_convert_mbox_to_fw(mbox);
+               ret = ERROR_CONVERT(msg_count_message(_svc->service_h, folderId, countInfo));
+               if (MESSAGES_ERROR_NONE != ret)
+               {
+                       return ret;
+               }
+               
+               msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &nSms);
+               msg_get_int_value(countInfo, MSG_COUNT_INFO_MMS_INT, &nMms);
+
+               msg_release_struct(&countInfo);
+
+               switch (type)
+               {
+               case MESSAGES_TYPE_SMS: *count = nSms; break;
+               case MESSAGES_TYPE_MMS: *count = nMms; break;
+               case MESSAGES_TYPE_UNKNOWN: *count = nSms + nMms; break;
+               default: *count = 0; break;
+               }
+       }
+       
+       return MESSAGES_ERROR_NONE;
+}
+
+int messages_search_message(messages_service_h service,
+                                                       messages_message_box_e mbox,
+                                                       messages_message_type_e type,
+                                                       const char *keyword, const char *address,
+                                                       int offset, int limit,
+                                                       messages_message_h **message_array, int *length, int *total)
 {
        int i;
        int ret;
-       bool ret_cb;
 
-       MSG_LIST_S msg_list;
-       MSG_SEARCH_CONDITION_S searchCon;
+       msg_struct_list_s msg_list;
+       msg_struct_t searchCon;
        messages_message_type_e _msgType;
        
-       messages_service_s *_svc = (messages_service_s*)svc;
+       messages_service_s *_svc = (messages_service_s*)service;
        messages_message_s *_msg = NULL;
+       messages_message_h *_array;
+       
 
        CHECK_NULL(_svc);
-       CHECK_NULL(callback);
-
+       CHECK_NULL(message_array);
+       
        // Set Condition
-       searchCon.folderId = _messages_convert_mbox_to_fw(mbox);
-       searchCon.msgType = _messages_convert_msgtype_to_fw(type);      
-       searchCon.pSearchVal = NULL == keyword ? NULL : strdup(keyword);
-       searchCon.pAddressVal = NULL == address ? NULL : strdup(address);
+       searchCon = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION);
+       msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_FOLDERID_INT, _messages_convert_mbox_to_fw(mbox));
+       msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_MSGTYPE_INT, _messages_convert_msgtype_to_fw(type));
+       if (NULL != keyword)
+       {
+               msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, strdup(keyword), sizeof(keyword));
+       }
+       if (NULL != address)
+       {
+               msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_ADDRESS_VALUE_STR, strdup(address), sizeof(address));
+       }
 
-       ret = msg_search_message(_svc->service_h, &searchCon, offset, limit, &msg_list);
+       // Search
+       ret = msg_search_message(_svc->service_h, searchCon, offset, limit, &msg_list);
        if (MSG_SUCCESS != ret)
        {
+               msg_release_struct(&searchCon);
                return ERROR_CONVERT(ret);
        }
+       msg_release_struct(&searchCon);
 
+       // Result
+       _array = (messages_message_h*)calloc(msg_list.nCount + 1, sizeof(messages_message_h));
+       if (NULL == _array)
+       {
+               LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_array'."
+                       , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY);
+               return MESSAGES_ERROR_OUT_OF_MEMORY;
+       }
+       
        for (i=0; i < msg_list.nCount; i++)
        {
                _msg = (messages_message_s*)calloc(1, sizeof(messages_message_s));
@@ -427,12 +624,13 @@ int messages_foreach_message_from_db(messages_service_h svc,
                if (NULL == _msg)
                {
                        LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_msg'."
-                               , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY);
+                               , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY);                        
+                       free(_array);
                        return MESSAGES_ERROR_OUT_OF_MEMORY;
                }
 
-               _msg->msg_h = msg_list.msgInfo[i];
-
+               _msg->msg_h = msg_list.msg_struct_info[i];
+               
                messages_get_message_type((messages_message_h)_msg, &_msgType);
 
                if (MESSAGES_TYPE_MMS == _msgType)
@@ -441,81 +639,125 @@ int messages_foreach_message_from_db(messages_service_h svc,
                        // Shoud I load mms data at here?
                        _messages_load_mms_data(_msg, _svc->service_h);
                }
+               
+               _array[i] = (messages_message_h)_msg;
+       }
+       
+       *message_array = (messages_message_h*)_array;
+       
+       if (NULL != length)
+       {
+               *length = msg_list.nCount;
+       }
+       
+       if (NULL != total)
+       {
+               *total = -1; // TODO: total count is not supported yet.
+       }
+       
+       // TODO: where should I free msg_list?
+       
 
-               // do callback
-               // TODO: total count is not supported yet.
-               ret_cb = callback((messages_message_h)_msg, i, msg_list.nCount, -1, user_data);
+       return MESSAGES_ERROR_NONE;
+}
 
-               messages_mms_remove_all_attachments((messages_message_h)_msg);
-               msg_release_message(&_msg->msg_h);
-               free(_msg);
+int messages_free_message_array(messages_message_h *message_array)
+{
+       int ret;
+       int i=0;
 
-               if (false == ret_cb)
+       messages_message_h* _array = (messages_message_h*)message_array;
+       CHECK_NULL(_array);
+       
+       while (_array[i] != NULL)
+       {
+               ret = messages_destroy_message(_array[i]);
+               if (MESSAGES_ERROR_NONE != ret)
                {
-                       break;
+                       LOGW("[%s:%d] messages_destroy_message() is fail. ret = %d"
+                               , __FUNCTION__, __LINE__, ret);
                }
+               
+               i++;
        }
-
+       
+       free(message_array);
+       
        return MESSAGES_ERROR_NONE;
 }
 
-void _messages_sent_mediator_cb(MSG_HANDLE_T handle, MSG_SENT_STATUS_S *pStatus, void *user_param)
+int messages_foreach_message(messages_service_h svc,
+                                                        messages_message_box_e mbox,
+                                                        messages_message_type_e type,
+                                                        const char *keyword, const char *address,
+                                                        int offset, int limit,
+                                                        messages_search_cb callback, void *user_data)
 {
-       messages_sending_result_e ret;
-       messages_service_s *_svc = (messages_service_s*)user_param;
+       int i;
+       int ret;
+       bool ret_cb;
 
-       if (NULL == _svc)
+       messages_message_h* msg_array;
+       int length;
+       int total;
+       
+       ret = messages_search_message(svc, mbox, type, keyword, address, offset, limit,
+                                                               &msg_array, &length, &total);
+       if (MESSAGES_ERROR_NONE != ret)
        {
-               return;
+               return ret;                     
        }
-
-       if (_svc->sent_cb_enabled && _svc->sent_cb != NULL)
+       
+       for (i=0; i < length; i++)
        {
-               ret = (pStatus->status == MSG_NETWORK_SEND_SUCCESS) ? 
-                                       MESSAGES_SENDING_SUCCEEDED : MESSAGES_SENDING_FAILED;
-               ((messages_sent_cb)_svc->sent_cb)(ret, _svc->sent_cb_user_data);        
+               ret_cb = callback((messages_message_h)msg_array[i], i, length, total, user_data);
        }
-}
-
-int messages_set_message_sent_cb(messages_service_h svc, messages_sent_cb callback, void *user_data)
-{
-       int ret;
-
-       messages_service_s *_svc = (messages_service_s*)svc;
-
-       CHECK_NULL(_svc);
-       CHECK_NULL(callback);
-
-       if (NULL == _svc->sent_cb)
+       
+       ret = messages_free_message_array(msg_array);
+       if (MESSAGES_ERROR_NONE != ret)
        {
-               ret = ERROR_CONVERT(
-                               msg_reg_sent_status_callback(_svc->service_h, &_messages_sent_mediator_cb, (void*)_svc)
-                       );
-               if (MESSAGES_ERROR_NONE != ret)
-               {
-                       return ret;
-               }
+               return ret;                     
        }
-
-       _svc->sent_cb = (void*)callback;
-       _svc->sent_cb_user_data = (void*)user_data;
-       _svc->sent_cb_enabled = true;
        
        return MESSAGES_ERROR_NONE;
 }
 
-int messages_unset_message_sent_cb(messages_service_h svc)
+void _messages_sent_mediator_cb(msg_handle_t handle, msg_struct_t pStatus, void *user_param)
 {
-       messages_service_s *_svc = (messages_service_s*)svc;
+       messages_sending_result_e ret;
+       messages_service_s *_svc = (messages_service_s*)user_param;
 
-       CHECK_NULL(_svc);
+       int i;
+       int status = MSG_NETWORK_SEND_FAIL;
+       int reqId = 0;
+       messages_sent_callback_s *_cb;
 
-       _svc->sent_cb_enabled = false;
+       msg_get_int_value(pStatus, MSG_SENT_STATUS_REQUESTID_INT, &reqId);
+       msg_get_int_value(pStatus, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
 
-       return MESSAGES_ERROR_NONE;
+       if (NULL == _svc)
+       {
+               return;
+       }
+
+       for (i=0; i < g_slist_length(_svc->sent_cb_list); i++)
+       {
+               _cb = (messages_sent_callback_s *)g_slist_nth_data(_svc->sent_cb_list, i);
+               
+               if (NULL != _cb && _cb->req_id == reqId)
+               {
+                       ret = (status == MSG_NETWORK_SEND_SUCCESS) ? 
+                                       MESSAGES_SENDING_SUCCEEDED : MESSAGES_SENDING_FAILED;
+
+                       ((messages_sent_cb)_cb->callback)(ret, _cb->user_data);
+                       _svc->sent_cb_list = g_slist_remove(_svc->sent_cb_list, _cb);
+                       free(_cb);
+                       break;
+               }
+       }
 }
 
-void _messages_incoming_mediator_cb(MSG_HANDLE_T handle, msg_message_t msg, void *user_param)
+void _messages_incoming_mediator_cb(msg_handle_t handle, msg_struct_t msg, void *user_param)
 {
        messages_message_type_e msgType;
        messages_message_s *_msg;
@@ -586,6 +828,29 @@ int messages_set_message_incoming_cb(messages_service_h svc, messages_incoming_c
        return MESSAGES_ERROR_NONE;
 }
 
+int messages_add_sms_listening_port(messages_service_h service, int port)
+{
+       int ret;
+       messages_service_s *_svc = (messages_service_s*)service;
+       CHECK_NULL(_svc);
+       
+       if (port <= 0)
+       {
+               return MESSAGES_ERROR_INVALID_PARAMETER;
+       }
+       
+       ret = ERROR_CONVERT(
+                       msg_reg_sms_message_callback(_svc->service_h, &_messages_incoming_mediator_cb, port, (void*)_svc)
+               );
+               
+       if (MESSAGES_ERROR_NONE != ret)
+       {
+               return ret;
+       }
+       
+       return MESSAGES_ERROR_NONE;
+}
+
 int messages_unset_message_incoming_cb(messages_service_h svc)
 {
        messages_service_s *_svc = (messages_service_s*)svc;
@@ -597,6 +862,27 @@ int messages_unset_message_incoming_cb(messages_service_h svc)
        return MESSAGES_ERROR_NONE;
 }
 
+int messages_get_message_port(messages_message_h msg, int *port)
+{
+       int ret;
+       int _port;
+       
+       messages_message_s *_msg = (messages_message_s*)msg;
+       CHECK_NULL(_msg);
+       CHECK_NULL(_msg->msg_h);
+       CHECK_NULL(port);
+       
+       ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_DEST_PORT_INT, &_port);
+       if (MSG_SUCCESS != ret) {
+               return ERROR_CONVERT(ret);
+       }
+       
+       *port = _port;
+       
+       return MESSAGES_ERROR_NONE;
+}
+
+
 int messages_set_text(messages_message_h msg, const char *text)
 {
        int ret;
@@ -622,9 +908,7 @@ int messages_set_text(messages_message_h msg, const char *text)
                                , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER);
                        return MESSAGES_ERROR_INVALID_PARAMETER;
                }
-               ret = ERROR_CONVERT(
-                               msg_sms_set_message_body(_msg->msg_h, text,  len)
-                               );
+               ret = ERROR_CONVERT(msg_set_str_value(_msg->msg_h, MSG_MESSAGE_SMS_DATA_STR, (char *)text, len));
        }
        else if (MESSAGES_TYPE_MMS == type)
        {
@@ -656,7 +940,7 @@ int messages_set_text(messages_message_h msg, const char *text)
 int messages_get_text(messages_message_h msg, char **text)
 {
        int ret;
-       const char *_text;
+       char _text[MAX_MSG_TEXT_LEN];
        messages_message_type_e type;
 
        messages_message_s *_msg = (messages_message_s*)msg;
@@ -670,8 +954,8 @@ int messages_get_text(messages_message_h msg, char **text)
 
        if (MESSAGES_TYPE_SMS == type)
        {
-               _text = msg_sms_get_message_body(_msg->msg_h);
-               if (NULL == _text)
+               ret = msg_get_str_value(_msg->msg_h, MSG_MESSAGE_SMS_DATA_STR, _text, MAX_MSG_TEXT_LEN);
+               if (MSG_SUCCESS != ret)
                {
                        *text = NULL;
                }
@@ -715,6 +999,137 @@ int messages_get_text(messages_message_h msg, char **text)
 
 
 
+int messages_get_time(messages_message_h msg, time_t *time)
+{
+       int ret;
+       int _time;
+       
+       messages_message_s *_msg = (messages_message_s*)msg;
+       CHECK_NULL(_msg);
+       CHECK_NULL(_msg->msg_h);
+       CHECK_NULL(time);
+       
+       ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_DISPLAY_TIME_INT, &_time);
+       if (MSG_SUCCESS != ret)
+       {
+               return ERROR_CONVERT(ret);
+       }
+
+       *time = (time_t)_time;
+
+       return MESSAGES_ERROR_NONE;
+}
+
+int messages_get_message_id(messages_message_h msg, int *msg_id)
+{
+       int ret;
+       int _id;
+       
+       messages_message_s *_msg = (messages_message_s*)msg;
+       CHECK_NULL(_msg);
+       CHECK_NULL(_msg->msg_h);
+       CHECK_NULL(msg_id);
+       
+       ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_ID_INT, &_id);
+       if (MSG_SUCCESS != ret)
+       {
+               return ERROR_CONVERT(ret);
+       }
+       
+       *msg_id = _id;
+       
+       return MESSAGES_ERROR_NONE;
+}
+
+int messages_search_message_by_id(messages_service_h service, int msg_id, messages_message_h *msg)
+{
+       int ret;
+       msg_struct_t new_msg_h;
+       messages_message_type_e _msgType;
+       msg_struct_t sendOpt;
+
+       messages_service_s *_svc = (messages_service_s*)service;
+       messages_message_s *_msg = NULL;
+       
+       CHECK_NULL(_svc);
+       CHECK_NULL(_svc->service_h);
+       CHECK_NULL(msg);
+       
+       new_msg_h = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+       sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+       ret = msg_get_message(_svc->service_h, msg_id, new_msg_h, sendOpt);
+       if (MSG_SUCCESS != ret)
+       {
+               LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_message failed.", 
+                       __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED);
+               return MESSAGES_ERROR_OPERATION_FAILED;                 
+       }
+       
+       _msg = (messages_message_s*)calloc(1, sizeof(messages_message_s));
+       _msg->text = NULL;
+       _msg->attachment_list = NULL;
+       if (NULL == _msg)
+       {
+               LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_msg'."
+                       , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY);
+               return MESSAGES_ERROR_OUT_OF_MEMORY;
+       }
+       
+       _msg->msg_h = new_msg_h;
+       
+       messages_get_message_type((messages_message_h)_msg, &_msgType); 
+       if (MESSAGES_TYPE_MMS == _msgType)
+       {
+               ret = _messages_load_mms_data(_msg, _svc->service_h);
+               if (MESSAGES_ERROR_NONE != ret) {
+                       free(_msg);
+                       return ret;
+               }
+       }
+       
+       *msg = (messages_message_h)_msg;
+       
+       return MESSAGES_ERROR_NONE;
+}
+
+int messages_get_mbox_type(messages_message_h msg, messages_message_box_e *mbox)
+{
+       int ret;
+       int folder_id;
+       
+       messages_message_s *_msg = (messages_message_s*)msg;
+       CHECK_NULL(_msg);
+       CHECK_NULL(_msg->msg_h);
+       CHECK_NULL(mbox);
+       
+       ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_FOLDER_ID_INT, &folder_id);
+       if (MSG_SUCCESS != ret)
+       {
+               return ERROR_CONVERT(ret);
+       }
+       
+       switch (folder_id) {
+       case MSG_INBOX_ID: 
+               *mbox = MESSAGES_MBOX_INBOX;
+               break;
+       case MSG_OUTBOX_ID:
+               *mbox = MESSAGES_MBOX_OUTBOX;
+               break;
+       case MSG_SENTBOX_ID:
+               *mbox = MESSAGES_MBOX_SENTBOX;
+               break;
+       case MSG_DRAFT_ID:
+               *mbox = MESSAGES_MBOX_DRAFT;
+               break;
+       default:
+               *mbox = MESSAGES_MBOX_ALL;
+               break;
+       }
+       
+       return MESSAGES_ERROR_NONE;
+}
+
+
 // MMS /////////////////////////////////////////////////////////////////////
 
 int messages_mms_set_subject(messages_message_h msg, const char *subject)
@@ -738,8 +1153,8 @@ int messages_mms_set_subject(messages_message_h msg, const char *subject)
                        , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER);
                return MESSAGES_ERROR_INVALID_PARAMETER;                
        }
-
-       ret = msg_set_subject(_msg->msg_h, subject);
+       
+       ret = msg_set_str_value(_msg->msg_h, MSG_MESSAGE_SUBJECT_STR, (char *)subject, strlen(subject));
 
        return ERROR_CONVERT(ret);
 }
@@ -747,7 +1162,7 @@ int messages_mms_set_subject(messages_message_h msg, const char *subject)
 int messages_mms_get_subject(messages_message_h msg, char **subject)
 {
        int ret;
-       const char *_subject;
+       char _subject[MAX_SUBJECT_LEN];
        messages_message_type_e type;
 
        messages_message_s *_msg = (messages_message_s*)msg;
@@ -766,9 +1181,9 @@ int messages_mms_get_subject(messages_message_h msg, char **subject)
                        , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER);
                return MESSAGES_ERROR_INVALID_PARAMETER;                
        }
-
-       _subject = msg_get_subject(_msg->msg_h);
-       if (NULL == _subject) 
+               
+       ret = msg_get_str_value(_msg->msg_h, MSG_MESSAGE_SUBJECT_STR, _subject, MAX_SUBJECT_LEN);
+       if (MSG_SUCCESS != ret)
        {
                *subject = NULL;
        }
@@ -913,10 +1328,13 @@ int _messages_save_mms_data(messages_message_s *msg)
        int i;
        int ret;
 
-       MMS_MESSAGE_DATA_S *mms_data;
-       MMS_SMIL_ROOTLAYOUT *layout;
-       MMS_PAGE_S *page;
-       MMS_MEDIA_S *media;
+       msg_struct_t mms_data;
+       msg_struct_t region;
+       
+       msg_struct_t page;
+       msg_struct_t media;
+       msg_struct_t smil_text;
+       msg_struct_t mms_attach;
 
        messages_attachment_s *attach;
        messages_attachment_s *image;
@@ -925,8 +1343,8 @@ int _messages_save_mms_data(messages_message_s *msg)
        char *filepath = NULL;
 
        CHECK_NULL(msg);
-
-       mms_data = msg_mms_create_message();
+       
+       mms_data = msg_create_struct(MSG_STRUCT_MMS);
        if (NULL == mms_data)
        {
                LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_create_message failed.", 
@@ -964,66 +1382,79 @@ int _messages_save_mms_data(messages_message_s *msg)
        }
 
        // Layout Setting
-       layout = msg_mms_set_rootlayout(mms_data, 100, 100, 0xffffff);
-       if (NULL == layout)
-       {
-               LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_set_rootlayout failed.", 
-                       __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED);
-               msg_mms_destroy_message(mms_data);
-               return MESSAGES_ERROR_OPERATION_FAILED;
-       }
+       msg_set_int_value(mms_data, MSG_MMS_ROOTLAYOUT_WIDTH_INT, 100);
+       msg_set_int_value(mms_data, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, 100);
+       msg_set_int_value(mms_data, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, 0xffffff);
+       msg_set_bool_value(mms_data, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
+       msg_set_bool_value(mms_data, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
 
        if (NULL == image)
        {
-               msg_mms_add_region(mms_data, "Text", 0, 0, 100, 100, 0xffffff);
+               msg_mms_add_item(mms_data, MSG_STRUCT_MMS_REGION, &region);
+               msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Text", 4);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 0);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, 100);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 100);
+               msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff);                
        }
        else if (NULL == msg->text)
        {
-               msg_mms_add_region(mms_data, "Image", 0, 0, 100, 100, 0xffffff);
+               msg_mms_add_item(mms_data, MSG_STRUCT_MMS_REGION, &region);
+               msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Image", 5);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 0);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, 100);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 100);
+               msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff);                
        }
        else
        {
-               msg_mms_add_region(mms_data, "Image", 0, 0, 100, 50, 0xffffff);
-               msg_mms_add_region(mms_data, "Text", 0, 50, 100, 50, 0xffffff);
+               msg_mms_add_item(mms_data, MSG_STRUCT_MMS_REGION, &region);
+               msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Image", 5);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 0);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, 100);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 50);
+               msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff);
+               
+               msg_mms_add_item(mms_data, MSG_STRUCT_MMS_REGION, &region);
+               msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Text", 4);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 50);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, 100);
+               msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 50);
+               msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff);
        }
 
        // Add Media
-       page = msg_mms_add_page(mms_data, 5440);
-       if (NULL == page)
-       {
-               LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_add_page failed.", 
-                       __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED);
-               msg_mms_destroy_message(mms_data);
-               return MESSAGES_ERROR_OPERATION_FAILED;
-       }
+       msg_mms_add_item(mms_data, MSG_STRUCT_MMS_PAGE, &page);
+       msg_set_int_value(page, MSG_MMS_PAGE_PAGE_DURATION_INT, 5440);
 
        if (NULL != image)
        {
                if (MESSAGES_MEDIA_IMAGE == image->media_type)
                {
-                       media = msg_mms_add_media(page, MMS_SMIL_MEDIA_IMG, "Image", (char *)image->filepath);
-                       if (NULL == media)
-                       {
-                               LOGW("msg_mms_add_media failed, filepath=%s", image->filepath);
-                       }
+                       msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media);
+                       msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_IMG);
+                       msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Image", 5);
+                       msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)image->filepath, MAX_IMAGE_PATH_LEN);
                }
                else if (MESSAGES_MEDIA_VIDEO == image->media_type)
                {
-                       media = msg_mms_add_media(page, MMS_SMIL_MEDIA_VIDEO, "Image", (char *)image->filepath);
-                       if (NULL == media)
-                       {
-                               LOGW("msg_mms_add_media failed, filepath=%s", image->filepath);
-                       }
+                       msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media);
+                       msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_VIDEO);
+                       msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Image", 5);
+                       msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)image->filepath, MAX_IMAGE_PATH_LEN);
                }
        }
 
        if (NULL != audio)
        {
-               media = msg_mms_add_media(page, MMS_SMIL_MEDIA_AUDIO, NULL, (char *)audio->filepath);
-               if (NULL == media)
-               {
-                       LOGW("msg_mms_add_media failed, filepath=%s", audio->filepath);
-               }
+               msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media);
+               msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_AUDIO);
+               msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Image", 5);
+               msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)image->filepath, MAX_IMAGE_PATH_LEN);
        }
 
        if (NULL != msg->text)
@@ -1031,17 +1462,15 @@ int _messages_save_mms_data(messages_message_s *msg)
                ret = _messages_save_textfile(msg->text, &filepath);
                if (MESSAGES_ERROR_NONE == ret)
                {
-                       media = msg_mms_add_media(page, MMS_SMIL_MEDIA_TEXT, "Text", (char *)filepath);
-                       if (NULL != media)
-                       {
-                               media->sMedia.sText.nColor = 0x000000;
-                               media->sMedia.sText.nSize = MMS_SMIL_FONT_SIZE_NORMAL;
-                               media->sMedia.sText.bBold = false;
-                       }
-                       else
-                       {
-                               LOGW("msg_mms_add_media failed, filepath=%s", audio->filepath);
-                       }
+                       msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media);
+                       msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
+                       msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Text", 4);
+                       msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)filepath, MAX_IMAGE_PATH_LEN);
+                       
+                       msg_get_struct_handle(media, MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text);
+                       msg_set_int_value(smil_text, MSG_MMS_SMIL_TEXT_COLOR_INT, 0x000000);
+                       msg_set_int_value(smil_text, MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL);
+                       msg_set_bool_value(smil_text, MSG_MMS_SMIL_TEXT_BOLD_BOOL, false);
                }
 
                if (NULL != filepath)
@@ -1056,52 +1485,64 @@ int _messages_save_mms_data(messages_message_s *msg)
                attach = g_slist_nth_data(msg->attachment_list, i);
                if (image != attach && audio != attach)
                {
-                       msg_mms_add_attachment(mms_data, (char *)attach->filepath);
+                       msg_mms_add_item(mms_data, MSG_STRUCT_MMS_ATTACH, &mms_attach);
+                       msg_set_str_value(mms_attach, MSG_MMS_ATTACH_FILEPATH_STR, (char *)attach->filepath, MAX_IMAGE_PATH_LEN);
                }
        }
-
-
-       ret = msg_mms_set_message_body(msg->msg_h, mms_data);
+       
+       ret = msg_set_mms_struct(msg->msg_h, mms_data);
        if (MSG_SUCCESS != ret)
        {
-               LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_add_page failed.", 
+               LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_set_mms_struct failed.", 
                        __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED);
-               msg_mms_destroy_message(mms_data);
+               msg_release_struct(&mms_data);
                return MESSAGES_ERROR_OPERATION_FAILED;
        }
-
-       msg_mms_destroy_message(mms_data);
+       
+       msg_release_struct(&mms_data);
 
        return MESSAGES_ERROR_NONE;
 }
 
-int _messages_load_mms_data(messages_message_s *msg, MSG_HANDLE_T handle)
+int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle)
 {
        int i,j;
        int ret;
        int msg_id;
-       msg_message_t new_msg_h;
-       MSG_SENDINGOPT_S sendOpt = {0, };
-       MMS_MESSAGE_DATA_S *mms_data;
-       MMS_PAGE_S *mms_page;
-       MMS_MEDIA_S *mms_media;
-       MMS_ATTACH_S *mms_attach;
+       int media_type;
+       char filepath[MAX_IMAGE_PATH_LEN];
+       
+       msg_struct_t new_msg_h;
+       msg_struct_t sendOpt;
+       
+       msg_struct_t mms_data;
+       
+       msg_list_handle_t mms_page_list;
+       msg_list_handle_t mms_media_list;
+       msg_list_handle_t mms_attach_list;
+       
+       
+       msg_struct_t mms_page;
+       msg_struct_t mms_media;
+       msg_struct_t mms_attach;
+       
        messages_attachment_s *attach;
 
        CHECK_NULL(msg);
 
        // Get MessageId
-       msg_id = msg_get_message_id(msg->msg_h);
-       if (MSG_ERR_NULL_POINTER == msg_id)
+       ret = msg_get_int_value(msg->msg_h, MSG_MESSAGE_ID_INT, &msg_id);
+       if (MSG_SUCCESS != ret)
        {
-               LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_message_id failed.", 
+               LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_int_value(MSG_MESSAGE_ID_INT) failed.", 
                        __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED);
                return MESSAGES_ERROR_OPERATION_FAILED; 
        }
 
        // Load MMS_MESSAGE_DATA_S
-       new_msg_h = msg_new_message();
-       ret = msg_get_message(handle, msg_id, new_msg_h, &sendOpt);
+       new_msg_h = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+       sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+       ret = msg_get_message(handle, msg_id, new_msg_h, sendOpt);
        if (MSG_SUCCESS != ret)
        {
                LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_message failed.", 
@@ -1109,38 +1550,39 @@ int _messages_load_mms_data(messages_message_s *msg, MSG_HANDLE_T handle)
                return MESSAGES_ERROR_OPERATION_FAILED;                 
        }
 
-       mms_data = msg_mms_create_message();
+       mms_data = msg_create_struct(MSG_STRUCT_MMS);
        if (NULL == mms_data)
        {
                LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_create_message failed.", 
                        __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED);
-               msg_release_message(&new_msg_h);
+               msg_release_struct(&new_msg_h);
                return MESSAGES_ERROR_OPERATION_FAILED;
        }
 
-       ret = msg_mms_get_message_body(new_msg_h, mms_data);
+       ret = msg_get_mms_struct(new_msg_h, mms_data);
        if (MSG_SUCCESS != ret)
        {
                LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_get_message_body failed.", 
                        __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED);
-               msg_mms_destroy_message(mms_data);
-               msg_release_message(&new_msg_h);
+               msg_release_struct(&mms_data);
+               msg_release_struct(&new_msg_h);
                return MESSAGES_ERROR_OPERATION_FAILED;
        }
 
-       msg_release_message(&new_msg_h);
-
        // Load Media, Text
-       for (i=0; i < mms_data->pageCnt; i++)
+       msg_get_list_handle(mms_data, MSG_MMS_PAGE_LIST_HND, (void **)&mms_page_list);  
+       for (i=0; i < msg_list_length(mms_page_list); i++)
        {
-               mms_page = msg_mms_get_page(mms_data, i);
+               mms_page = (msg_struct_t)msg_list_nth_data(mms_page_list, i);
                if (NULL == mms_page)
                {
                        continue;
                }
-               for (j=0; j < mms_page->mediaCnt; j++)
+               
+               msg_get_list_handle(mms_page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&mms_media_list);           
+               for (j=0; j < msg_list_length(mms_media_list); j++)
                {
-                       mms_media = msg_mms_get_media(mms_page, j);
+                       mms_media = (msg_struct_t)msg_list_nth_data(mms_media_list, i);
                        if (NULL == mms_media)
                        {
                                continue;
@@ -1153,15 +1595,18 @@ int _messages_load_mms_data(messages_message_s *msg, MSG_HANDLE_T handle)
                                        , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY);
                                break;
                        }
-
-                       if (MMS_SMIL_MEDIA_TEXT == mms_media->mediatype)
+                       
+                       msg_get_int_value(mms_media, MSG_MMS_MEDIA_TYPE_INT, &media_type);
+                       msg_get_str_value(mms_media, MSG_MMS_MEDIA_FILEPATH_STR, filepath, MAX_IMAGE_PATH_LEN);
+                       
+                       if (MMS_SMIL_MEDIA_TEXT == media_type)
                        {
-                               _messages_load_textfile(mms_media->szFilePath, &msg->text);
+                               _messages_load_textfile(filepath, &msg->text);
                        }
                        else
                        {
-                               strncpy(attach->filepath, mms_media->szFilePath, MSG_FILEPATH_LEN_MAX);
-                               switch (mms_media->mediatype)
+                               strncpy(attach->filepath, filepath, MAX_IMAGE_PATH_LEN);
+                               switch (media_type)
                                {
                                        case MMS_SMIL_MEDIA_IMG:
                                                attach->media_type = MESSAGES_MEDIA_IMAGE;
@@ -1182,9 +1627,10 @@ int _messages_load_mms_data(messages_message_s *msg, MSG_HANDLE_T handle)
        }
 
        // Load Attachments
-       for (i=0; i < mms_data->attachCnt; i++)
+       msg_get_list_handle(mms_data, MSG_MMS_ATTACH_LIST_HND, (void **)&mms_attach_list);
+       for (i=0; i < msg_list_length(mms_attach_list); i++)
        {
-               mms_attach = msg_mms_get_attachment(mms_data, i);
+               mms_attach = (msg_struct_t)msg_list_nth_data(mms_attach_list, i);
                if (NULL == mms_attach)
                {
                        continue;
@@ -1197,12 +1643,13 @@ int _messages_load_mms_data(messages_message_s *msg, MSG_HANDLE_T handle)
                                , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY);
                        break;
                }
-
-               strncpy(attach->filepath, mms_attach->szFilePath, MSG_FILEPATH_LEN_MAX);
+               msg_get_str_value(mms_attach, MSG_MMS_ATTACH_FILEPATH_STR, filepath, MAX_IMAGE_PATH_LEN);
+               strncpy(attach->filepath, filepath, MAX_IMAGE_PATH_LEN);
                attach->media_type = _messages_get_media_type_from_filepath(attach->filepath);
        }
 
-       msg_mms_destroy_message(mms_data);
+       msg_release_struct(&new_msg_h);
+
 
        return MESSAGES_ERROR_NONE;
 }
@@ -1324,9 +1771,9 @@ int _messages_get_media_type_from_filepath(const char *filepath)
        return ret;
 }
 
-MSG_FOLDER_ID_T _messages_convert_mbox_to_fw(messages_message_box_e mbox)
+int _messages_convert_mbox_to_fw(messages_message_box_e mbox)
 {
-       MSG_FOLDER_ID_T folderId;
+       int folderId;
        switch(mbox)
        {
                case MESSAGES_MBOX_INBOX:
@@ -1348,9 +1795,9 @@ MSG_FOLDER_ID_T _messages_convert_mbox_to_fw(messages_message_box_e mbox)
        return folderId;
 }
 
-MSG_MESSAGE_TYPE_T _messages_convert_msgtype_to_fw(messages_message_type_e type)
+int _messages_convert_msgtype_to_fw(messages_message_type_e type)
 {
-       MSG_MESSAGE_TYPE_T msgType;
+       int msgType;
        switch (type)
        {
                case MESSAGES_TYPE_SMS:
@@ -1366,6 +1813,27 @@ MSG_MESSAGE_TYPE_T _messages_convert_msgtype_to_fw(messages_message_type_e type)
        return msgType;
 }
 
+int _messages_convert_recipient_to_fw(messages_recipient_type_e type)
+{
+       int ret;
+       switch (type)
+       {
+               case MESSAGES_RECIPIENT_TO:
+                       ret = MSG_RECIPIENTS_TYPE_TO;
+                       break;
+               case MESSAGES_RECIPIENT_CC:
+                       ret = MSG_RECIPIENTS_TYPE_CC;
+                       break;
+               case MESSAGES_RECIPIENT_BCC:
+                       ret = MSG_RECIPIENTS_TYPE_BCC;
+                       break;
+               default:
+                       ret = MSG_RECIPIENTS_TYPE_UNKNOWN;
+                       break;
+       }
+       return ret;
+}
+
 
 int _messages_error_converter(int err, const char *func, int line)
 {
@@ -1410,4 +1878,4 @@ int _messages_error_converter(int err, const char *func, int line)
                        return MESSAGES_ERROR_OPERATION_FAILED;
 
        }
-}
\ No newline at end of file
+}
diff --git a/test/messages_incoming_test.c b/test/messages_incoming_test.c
new file mode 100644 (file)
index 0000000..8339b5f
--- /dev/null
@@ -0,0 +1,104 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <glib.h>
+
+#include <messages.h>
+
+#define ERROR_CHECK(ret) \
+       if (MESSAGES_ERROR_NONE != ret) { \
+               printf("%d: error, ret=%d \n", __LINE__, ret); \
+               exit(1); \
+       }
+
+static GMainLoop *mainloop;
+
+static void sig_quit(int signo)
+{
+        if(mainloop)
+        {
+                g_main_loop_quit(mainloop);
+        }
+}
+
+void incoming_cb(messages_message_h msg, void *user_data)
+{
+       int ret;
+       messages_message_type_e msgType;
+       char *text;
+       int i, nAddr;
+       char *addr = NULL;
+       time_t time;
+       struct tm *ptm;
+
+       printf("Incoming Message\n");
+
+       messages_get_address_count(msg, &nAddr);
+       for (i=0; i < nAddr; i++) {
+               ret = messages_get_address(msg, i, &addr, NULL);
+               if (MESSAGES_ERROR_NONE == ret) {
+                       printf("Address[%d]: %s\n", i, addr);
+                       free(addr);
+               }
+       }
+
+       ret = messages_get_text(msg, &text);
+       if (MESSAGES_ERROR_NONE == ret) {
+               printf("Text: %s\n", text);
+               free(text);
+       } else {
+               printf("%d: error, ret=%d\n", __LINE__, ret);
+       }
+
+       
+       messages_get_message_type(msg, &msgType);
+       switch(msgType) {
+       case MESSAGES_TYPE_SMS:
+               printf("Type: SMS\n");
+               break;
+       case MESSAGES_TYPE_MMS:
+               printf("Type: MMS\n");
+               break;
+       default:
+               printf("Type: Unknown\n");
+               break;
+       }
+       
+       messages_get_time(msg, &time);
+       printf("Time: %d, %s", (int)time, ctime(&time));
+
+        ptm = gmtime(&time);
+        printf("gmtime test: %d.%d.%d %d:%d:%d \n",
+                ptm->tm_year, ptm->tm_mon, ptm->tm_mday,
+                ptm->tm_hour, ptm->tm_min, ptm->tm_sec
+        );
+
+
+}
+
+int main(int argc, char *argv[])
+{
+       int ret;
+       messages_service_h svc;
+
+
+        signal(SIGINT, sig_quit);
+        signal(SIGTERM, sig_quit);
+        signal(SIGQUIT, sig_quit);
+       mainloop = g_main_loop_new(NULL, FALSE);
+
+       ret = messages_open_service(&svc);
+       ERROR_CHECK(ret);
+
+
+       messages_set_message_incoming_cb(svc, incoming_cb, NULL);
+
+        g_main_loop_run(mainloop);
+        g_main_loop_unref(mainloop);
+
+       messages_close_service(svc);
+
+
+       return 0;
+}
+
index 30bb295..5bca8bc 100644 (file)
@@ -6,11 +6,52 @@
 
 bool _search_cb(messages_message_h msg, int index, int result_count, int total_count, void *user_data)
 {
+       messages_message_type_e msgType;
+       messages_message_box_e mbox;
+       int ret;
        char *text;
+       int i, nAddr;
+       char *addr = NULL;
+       time_t time;
+
+       messages_get_message_type(msg, &msgType);
+
+       printf("=[%d/%d]==================================\n", index + 1, result_count);
+       messages_get_address_count(msg, &nAddr);
+       for (i=0; i < nAddr; i++) {
+               ret = messages_get_address(msg, i, &addr, NULL);
+               if (MESSAGES_ERROR_NONE == ret) {
+                       printf("Address[%d]: %s\n", i, addr);
+                       free(addr);
+               }
+       }
 
-       messages_get_text(msg, &text);
+       ret = messages_get_text(msg, &text);
+       if (MESSAGES_ERROR_NONE == ret) {
+               printf("Text: %s\n", text);
+               free(text);
+       }
+
+       if (MESSAGES_TYPE_SMS == msgType) {
+               printf("Type: SMS\n");
+       } else if (MESSAGES_TYPE_MMS == msgType) {
+               printf("Type: MMS\n");
+               ret = messages_mms_get_subject(msg, &text);
+               if (MESSAGES_ERROR_NONE == ret) {
+                       printf("Subject: %s\n", text);
+                       free(text);
+               }
+       } else {
+               printf("Type: Unknown");
+       }
+
+
+       ret = messages_get_time(msg, &time);
+       printf("Time: %d, %s", (int)time, ctime(&time));
+       
+       ret = messages_get_mbox_type(msg, &mbox);
+       printf("MBOX: %d\n", mbox);
 
-       printf(">>%s\n", text);
 
        return true;
 }
@@ -18,6 +59,7 @@ bool _search_cb(messages_message_h msg, int index, int result_count, int total_c
 int main(int argc, char *argv[])
 {
        int ret;
+       int count;
 
        messages_service_h svc;
 
@@ -28,15 +70,26 @@ int main(int argc, char *argv[])
                return 1;
        }
 
-       ret = messages_foreach_message_from_db(svc, 
-                       MESSAGES_MBOX_ALL, MESSAGES_TYPE_SMS
-                       "test", NULL, 
+       ret = messages_foreach_message(svc, 
+                       MESSAGES_MBOX_ALL, MESSAGES_TYPE_UNKNOWN
+                       NULL, NULL, 
                        0, 0, _search_cb, NULL);
        if (MESSAGES_ERROR_NONE != ret) {
                printf("error: messages_foreach_message_from_db() = %d", ret);
                return 1;
        }
 
+       printf("===============================================\n");
+       ret = messages_get_message_count(svc, MESSAGES_MBOX_INBOX, MESSAGES_TYPE_SMS, &count);
+       printf("INBOX: %d messages\n", count);
+       ret = messages_get_message_count(svc, MESSAGES_MBOX_SENTBOX, MESSAGES_TYPE_SMS, &count);
+       printf("SENTBOX: %d messages\n", count);
+       ret = messages_get_message_count(svc, MESSAGES_MBOX_OUTBOX, MESSAGES_TYPE_SMS, &count);
+       printf("OUTBOX: %d sms messages\n", count);
+       ret = messages_get_message_count(svc, MESSAGES_MBOX_OUTBOX, MESSAGES_TYPE_MMS, &count);
+       printf("OUTBOX: %d mms messages\n", count);
+
+
 
        // destroy
        messages_close_service(svc);    
index 0eead72..52c396c 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <messages.h>
 
+#define TEST_NUMBER "000000000"
+
 void _sent_cb(messages_sending_result_e result, void *user_data)
 {
 }
@@ -28,21 +30,17 @@ int main(int argc, char *argv[])
                return 1;
        }
 
-       messages_add_address(msg, "3488858734");
+       messages_add_address(msg, TEST_NUMBER, MESSAGES_RECIPIENT_TO);
        messages_set_text(msg, "This is a multi-media message!");
 
        messages_mms_set_subject(msg, "TEST!");
        messages_mms_add_attachment(msg, MESSAGES_MEDIA_VIDEO, "/opt/etc/msg-service/V091120_104905.3gp");
        messages_mms_add_attachment(msg, MESSAGES_MEDIA_IMAGE, "/opt/etc/msg-service/P091120_104633.jpg");
        
+       printf("Before Sending\n");
+       
        // send message
-       ret = messages_set_message_sent_cb(svc, _sent_cb, NULL);
-       if (MESSAGES_ERROR_NONE != ret) {
-               printf("error: messages_set_message_sent_cb() = %d", ret);
-               return 1;
-       }
-
-       ret = messages_send_message(svc, msg);
+       ret = messages_send_message(svc, msg, true, _sent_cb, NULL);
        if (MESSAGES_ERROR_NONE != ret) {
                printf("error: messages_send_message() = %d", ret);
                return 1;
index b4b96e3..d54cc53 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <messages.h>
 
+#define TEST_NUMBER "00000000000"
+
 void _sent_cb(messages_sending_result_e result, void *user_data)
 {
 }
@@ -28,18 +30,11 @@ int main(int argc, char *argv[])
                return 1;
        }
 
-       messages_add_address(msg, "3488858734");
+       messages_add_address(msg, TEST_NUMBER, MESSAGES_RECIPIENT_TO);
        messages_set_text(msg, "This is simple message!");
        
-
        // send message
-       ret = messages_set_message_sent_cb(svc, _sent_cb, NULL);
-       if (MESSAGES_ERROR_NONE != ret) {
-               printf("error: messages_set_message_sent_cb() = %d", ret);
-               return 1;
-       }
-
-       ret = messages_send_message(svc, msg);
+       ret = messages_send_message(svc, msg, true, _sent_cb, NULL);
        if (MESSAGES_ERROR_NONE != ret) {
                printf("error: messages_send_message() = %d", ret);
                return 1;