summaryrefslogtreecommitdiff
path: root/mobile_src/Messaging/IAttachment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mobile_src/Messaging/IAttachment.cpp')
-rwxr-xr-xmobile_src/Messaging/IAttachment.cpp239
1 files changed, 239 insertions, 0 deletions
diff --git a/mobile_src/Messaging/IAttachment.cpp b/mobile_src/Messaging/IAttachment.cpp
new file mode 100755
index 0000000..20028b6
--- /dev/null
+++ b/mobile_src/Messaging/IAttachment.cpp
@@ -0,0 +1,239 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <algorithm>
+#include <dpl/errno_string.h>
+#include <Commons/Exception.h>
+#include "IAttachment.h"
+
+extern "C" {
+#include <sys/stat.h>
+#include <stdlib.h>
+}
+
+#include <Logger.h>
+
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+//--------------------------------------------------------------------------
+namespace DeviceAPI {
+namespace Messaging {
+
+IAttachment::IAttachment() :
+ m_validAttachment(false),
+ m_hasDummyFile(false),
+ m_attachmentID(-1)
+{
+}
+
+void IAttachment::init(const string& fullPath,
+ bool isVirtualPath)
+{
+ Try
+ {
+ struct stat buffer;
+ std::string l_fullPath;
+ LoggerD("FULL Path : " << fullPath);
+
+ if (isVirtualPath) {
+ LoggerD("translating path");
+ l_fullPath = getRealPath(fullPath);
+ } else {
+ l_fullPath = fullPath;
+ }
+ LoggerD("real path " << l_fullPath);
+
+ char buff[PATH_MAX + 1];
+ if ((NULL == realpath(l_fullPath.c_str(), buff)) || (l_fullPath.size() > PATH_MAX + 1)) {
+ std::string errnoString = DPL::GetErrnoString();
+ LoggerE("get full path problem " << errnoString);
+ m_fileSize = 0;
+ m_attachFullPath = "";
+ m_attachShortName = "";
+ m_isCreatedProperly = true;
+ m_validAttachment = false;
+ }
+ else
+ {
+ if (-1 == lstat(buff, &buffer)) {
+ LoggerE("Attachment file not exist");
+ m_validAttachment = false;
+ }
+
+ if (!S_ISREG(buffer.st_mode)) {
+ LoggerE("Attachment file not exist");
+ m_validAttachment = false;
+ }
+ m_fileSize = buffer.st_size;
+ m_attachFullPath = l_fullPath;
+ makeShortName();
+ m_isCreatedProperly = true;
+ m_validAttachment = true;
+ }
+ }
+ Catch(WrtDeviceApis::Commons::Exception) {
+ LoggerE("attachment not created properly");
+ m_isCreatedProperly = false;
+ }
+}
+
+IAttachment::~IAttachment()
+{
+ LoggerD("enter");
+}
+
+string IAttachment::getShortName() const
+{
+ return m_attachShortName;
+}
+
+string IAttachment::getFullPath() const
+{
+ return m_attachFullPath;
+}
+
+unsigned int IAttachment::getFileSize() const
+{
+ return m_fileSize;
+}
+
+std::string IAttachment::getMimeType() const
+{
+ return m_mimeType;
+}
+
+void IAttachment::setMimeType(const std::string &mimeType)
+{
+ m_mimeType = mimeType;
+}
+
+void IAttachment::setDummyFilePath(const std::string& dummyFilePath)
+{
+ m_dummyFilePath = dummyFilePath;
+
+ char buff[PATH_MAX + 1];
+ if ( NULL != realpath(m_dummyFilePath.c_str(), buff))
+ {
+ LoggerD("dummy File is valided " << m_dummyFilePath);
+ m_hasDummyFile = true;
+ }
+ else
+ {
+ std::string errnoString = DPL::GetErrnoString();
+ LoggerE("get full path problem " << errnoString);
+ m_hasDummyFile = false;
+ }
+
+}
+
+std::string IAttachment::getDummyFilePath() const
+{
+ return m_dummyFilePath;
+}
+
+bool IAttachment::hasDummyFile() const
+{
+ return m_hasDummyFile;
+}
+
+
+#if 0
+//for security
+void IAttachment::setVirtualPath(const std::string& virtualPath)
+{
+ m_virtualPath = m_virtualPath;
+}
+
+std::string IAttachment::getVirtualPath()
+{
+ return m_virtualPath;
+}
+#endif
+
+IMessagePtr IAttachment::getMessage() const
+{
+ return m_message;
+}
+
+void IAttachment::setMessage(const IMessagePtr& message)
+{
+ m_message = message;
+}
+
+int IAttachment::getAttachmentID() const
+{
+ return m_attachmentID;
+}
+
+void IAttachment::setAttachmentID(int id)
+{
+ m_attachmentID = id;
+}
+
+bool IAttachment::getDownloaded() const
+{
+ return m_isDownloaded;
+}
+
+void IAttachment::setDownloaded(bool downloaded)
+{
+ m_isDownloaded = downloaded;
+}
+
+bool IAttachment::getIsInlineAttachment() const
+{
+ return m_isInlineAttachment;
+}
+
+void IAttachment::setIsInlineAttachment(bool isInlineAttachment)
+{
+ m_isInlineAttachment = isInlineAttachment;
+}
+
+
+bool IAttachment::getIsCreatedProperly() const
+{
+ return m_isCreatedProperly;
+}
+
+bool IAttachment::getIsValidAttachment() const
+{
+ LoggerE("m_validAttachment : " << m_validAttachment);
+ return m_validAttachment;
+}
+
+void IAttachment::rename(const string& newName)
+{
+ // path for attachment is still not changed
+ m_attachShortName = newName;
+ m_validAttachment = false;
+}
+
+void IAttachment::makeShortName()
+{
+ size_t pos;
+ // find position of last occurence of / sign (get only file name from all path
+ pos = m_attachFullPath.find_last_of("/");
+ if ((pos + 1) >= m_attachFullPath.size()) {
+ LoggerE("Problem with short name creation");
+ Throw(InvalidArgumentException);
+ }
+ m_attachShortName = m_attachFullPath.substr(pos + 1);
+}
+}
+}