Merge "Remove unnecessary free to prevent double free" into tizen
[platform/core/api/notification.git] / notification-ex / shared_file.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef NOTIFICATION_EX_SHARED_FILE_H_
18 #define NOTIFICATION_EX_SHARED_FILE_H_
19
20 #include <security-manager.h>
21
22 #include <string>
23 #include <memory>
24 #include <list>
25 #include <map>
26 #include <vector>
27
28 #include "notification-ex/abstract_item.h"
29
30 #ifndef EXPORT_API
31 #define EXPORT_API __attribute__((visibility("default")))
32 #endif
33
34 namespace notification {
35 namespace item {
36
37 class EXPORT_API SharedFile {
38  public:
39   SharedFile();
40   virtual ~SharedFile();
41
42   bool IsPrivatePath(std::string path) const;
43   std::string GetDataPath(std::string app_id, std::string path) const;
44   int SetPrivateSharing(std::list<std::shared_ptr<AbstractItem>> item,
45           std::multimap<std::string, std::string> receiver_group_map);
46   int UpdatePrivateSharing(std::shared_ptr<AbstractItem>item,
47           std::multimap<std::string, std::string> receiver_group_map);
48   int RemovePrivateSharing(std::shared_ptr<AbstractItem>item,
49           std::multimap<std::string, std::string> receiver_group_map);
50   int CopyPrivateFile(std::shared_ptr<item::AbstractItem>added_item);
51
52  private:
53   class SharingData {
54    public:
55     SharingData();
56     ~SharingData();
57     std::string app_id;
58     std::string dir;
59     std::list<std::string> noti_id_list;
60     std::list<std::string> shared_file_list;
61     std::list<std::string> receiver_group_list;
62   };
63   class SharingTarget {
64    public:
65     SharingTarget();
66     ~SharingTarget();
67     std::string target_id;
68   };
69   const char* GetLastIndex(const char* path, const char* search) const;
70   bool MakeDir(const char* path);
71   std::string GetDir(std::string path);
72   int CopyFile(const char* source, const char* dest);
73   std::vector<char*> ConvertListToArray(const std::list<std::string>& data);
74   SharingData FindSharingData(std::string appid);
75   int SetSharingData(SharingData sharing_data,
76           std::list<std::string> new_shared_file_list,
77           std::list<std::string> new_receiver_group_list,
78           std::multimap<std::string, std::string> receiver_group_map);
79   int UnsetSharingData(SharingData sharing_data,
80           std::multimap<std::string, std::string> receiver_group_map);
81
82   std::list<SharingData> sharing_data_list_;
83   std::list<SharingTarget> sharing_target_list_;
84 };  // class SharedFile
85
86 }  // namespace item
87 }  // namespace notification
88
89 #endif  // NOTIFICATION_EX_SHARED_FILE_H_