2 * Funambol is a mobile platform developed by Funambol, Inc.
3 * Copyright (C) 2003 - 2007 Funambol, Inc.
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.
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
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,
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.
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.
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".
36 #ifndef INCL_POSIX_DEVICE_MANAGEMENT_NODE
37 #define INCL_POSIX_DEVICE_MANAGEMENT_NODE
42 #include "base/fscapi.h"
43 #include "base/util/ArrayElement.h"
44 #include "spdm/ManagementNode.h"
45 #include "base/util/StringBuffer.h"
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
58 class DeviceManagementNode : public ManagementNode {
64 static StringBuffer configFile;
66 class line : public ArrayElement {
70 line(const char *newStr = NULL) { str = NULL; setLine(newStr); }
71 ~line() { free(str); }
72 ArrayElement *clone() { return new line(str); }
74 const char *getLine() { return str; }
75 void setLine(const char *newStr) { if (str) { free(str); } str = strdup(newStr ? newStr : ""); }
78 // the application's working directory
79 StringBuffer currentDir;
81 // change into directory which holds config file,
82 // creating directories if necessary for writing
84 // @return true for success, false for error - call returnFromDir() in both cases
85 bool gotoDir(bool read);
87 // return to original directory after a gotoDir()
90 // copy content of "lines" to or from file
91 void update(bool read);
93 // String compare case insensitive
94 int strnicmp( const char *a, const char *b, int len );
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);
101 // Initialize current dir. Current dir is initialized as configPath +
103 void initCurrentDir();
105 // Convert a generic context to path file name
106 StringBuffer contextToPath(const char* cont);
108 // Rename a file in the current working directory (currentDir)
109 int renameFileInCwd(const char* src, const char* dst);
113 static StringBuffer configPath;
117 // ------------------------------------------ Constructors & destructors
122 * @param parent - a ManagementNode is usually under the context of a
124 * @param name - the node name
127 DeviceManagementNode(const char* parent, const char *leafName);
128 DeviceManagementNode(const char* fullName);
130 DeviceManagementNode(const DeviceManagementNode &other);
131 virtual ~DeviceManagementNode();
133 static void setConfigPath(const StringBuffer &p) { configPath = p; }
134 static const StringBuffer& getConfigPath() { return configPath; }
137 // ----------------------------------------------------- Virtual methods
140 * Returns the value of the given property
142 * @param property - the property name
144 virtual char* readPropertyValue(const char* property);
148 * Sets a property value.
150 * @param property - the property name
151 * @param value - the property value (zero terminated string)
153 virtual void setPropertyValue(const char* property, const char* value);
156 * Returns the children's name of the parent node.
158 char **getChildrenNames();
161 * Find how many children are defined for this node in the underlying
164 virtual int getChildrenMaxCount();
167 * Creates a new ManagementNode with the exact content of this object.
168 * The new instance MUST be created with the C++ new opertator.
170 virtual ArrayElement* clone();