Imported Upstream version 0.8~alpha1
[platform/upstream/syncevolution.git] / src / client-api / src / include / symbian / spdm / DeviceManagementNode.h
1 /*
2  * Funambol is a mobile platform developed by Funambol, Inc. 
3  * Copyright (C) 2003 - 2007 Funambol, Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by
7  * the Free Software Foundation with the addition of the following permission 
8  * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
9  * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
10  * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License 
18  * along with this program; if not, see http://www.gnu.org/licenses or write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301 USA.
21  * 
22  * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
23  * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License
30  * version 3, these Appropriate Legal Notices must retain the display of the
31  * "Powered by Funambol" logo. If the display of the logo is not reasonably 
32  * feasible for technical reasons, the Appropriate Legal Notices must display
33  * the words "Powered by Funambol".
34  */
35
36 #ifndef INCL_POSIX_DEVICE_MANAGEMENT_NODE
37 #define INCL_POSIX_DEVICE_MANAGEMENT_NODE
38 /** @cond DEV */
39
40 #include <string.h>
41
42 #include "base/fscapi.h"
43 #include "base/util/ArrayElement.h"
44 #include "spdm/ManagementNode.h"
45 #include "base/util/StringBuffer.h"
46
47
48 /*
49  * File-based implementation of ManagementNode.
50  * Each node is mapped to one file, located in
51  *    $HOME/.sync4j/<node>
52  * with entries of the type
53  * <property>\s*=\s*<value>\n
54  *
55  * Comments look like:
56  * \s*# <comment>
57  */
58 class DeviceManagementNode : public ManagementNode {
59
60 protected:
61     ArrayList *lines;
62     bool modified;
63     char *prefix;
64     static StringBuffer configFile;
65
66     class line : public ArrayElement {
67         char *str;
68
69         public:
70             line(const char *newStr = NULL) { str = NULL; setLine(newStr); }
71             ~line() { free(str); }
72             ArrayElement *clone() { return new line(str); }
73
74             const char *getLine() { return str; }
75             void setLine(const char *newStr) { if (str) { free(str); } str = strdup(newStr ? newStr : ""); }
76     };
77
78     // the application's working directory
79     StringBuffer currentDir;
80
81     // change into directory which holds config file,
82     // creating directories if necessary for writing
83     //
84     // @return true for success, false for error - call returnFromDir() in both cases
85     bool gotoDir(bool read);
86
87     // return to original directory after a gotoDir()
88     void returnFromDir();
89
90     // copy content of "lines" to or from file
91     void update(bool read);
92
93     // String compare case insensitive
94     int strnicmp( const char *a, const char *b, int len );
95
96     // Concatenate two directory names (of file names)
97     // If src1 is terminated by dir separator then src2 is simply appended
98     // otherwise a dir separator is inserted first
99     void concatDirs(StringBuffer& src1, const char* src2);
100
101     // Initialize current dir. Current dir is initialized as configPath +
102     // context + name
103     void initCurrentDir();
104
105     // Convert a generic context to path file name
106     StringBuffer contextToPath(const char* cont);
107
108     // Rename a file in the current working directory (currentDir)
109     int renameFileInCwd(const char* src, const char* dst);
110
111     private:
112
113     static StringBuffer configPath;
114
115     public:
116
117         // ------------------------------------------ Constructors & destructors
118
119         /**
120          * Constructor.
121          *
122          * @param parent - a ManagementNode is usually under the context of a
123          *                 parent node.
124          * @param name - the node name
125          *
126          */
127         DeviceManagementNode(const char* parent, const char *leafName);
128         DeviceManagementNode(const char* fullName);
129
130         DeviceManagementNode(const DeviceManagementNode &other);
131         virtual ~DeviceManagementNode();
132
133         static void setConfigPath(const StringBuffer &p)        { configPath = p;       }
134         static const StringBuffer& getConfigPath()              { return configPath;    }
135         void lookupDir();
136         
137         // ----------------------------------------------------- Virtual methods
138
139         /*
140          * Returns the value of the given property
141          *
142          * @param property - the property name
143          */
144         virtual char* readPropertyValue(const char* property);
145
146
147         /*
148          * Sets a property value.
149          *
150          * @param property - the property name
151          * @param value - the property value (zero terminated string)
152          */
153         virtual void setPropertyValue(const char* property, const char* value);
154
155         /*
156          * Returns the children's name of the parent node.
157          */
158         char **getChildrenNames();
159
160         /*
161          * Find how many children are defined for this node in the underlying
162          * config system.
163          */
164         virtual int getChildrenMaxCount();
165
166         /*
167          * Creates a new ManagementNode with the exact content of this object.
168          * The new instance MUST be created with the C++ new opertator.
169          */
170         virtual ArrayElement* clone();
171
172
173 };
174
175 /** @endcond */
176 #endif