~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to daemon/src/config/config.cpp

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2012-02-18 21:47:09 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120218214709-6362d71gqdsdkrj5
Tags: 1.0.2-1
* New upstream release
  - remove logging patch (applied upstream)
  - update s390 patch since it was partially applied upstream
* Include the Evolution plugin as a separate binary package

* Fix compilation issues on SH4 (closes: #658987)
* Merge Ubuntu's binutils-gold linking fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
namespace Conf {
44
44
 
45
 
ConfigTree::~ConfigTree()
46
 
{
47
 
    // erase every new ItemMap (by CreateSection)
48
 
    SectionMap::iterator iter = sections_.begin();
49
 
 
50
 
    while (iter != sections_.end()) {
51
 
        delete iter->second;
52
 
        iter->second = NULL;
53
 
        iter++;
54
 
    }
55
 
}
56
 
 
57
45
void ConfigTree::addDefaultValue(const std::pair<std::string, std::string>& token, std::string section)
58
46
{
59
47
    defaultValueMap_.insert(token);
81
69
{
82
70
    // if we doesn't find the item, create it
83
71
    if (sections_.find(section) == sections_.end())
84
 
        sections_[section] = new ItemMap;
 
72
        sections_[section] = ItemMap();
85
73
}
86
74
 
87
75
/**
98
86
}
99
87
 
100
88
/** Retrieve the sections as an array */
101
 
TokenList
102
 
ConfigTree::getSections()
 
89
std::list<std::string>
 
90
ConfigTree::getSections() const
103
91
{
104
 
    TokenList sections;
105
 
 
106
 
    SectionMap::iterator iter = sections_.begin();
107
 
 
108
 
    while (iter != sections_.end()) {
109
 
        // add to token list the: iter->second;
 
92
    std::list<std::string> sections;
 
93
 
 
94
    for (SectionMap::const_iterator iter = sections_.begin(); iter != sections_.end(); ++iter)
110
95
        sections.push_back(iter->first);
111
 
        iter++;
112
 
    }
113
96
 
114
97
    return sections;
115
98
}
125
108
    SectionMap::iterator iter = sections_.find(section);
126
109
 
127
110
    if (iter == sections_.end()) {
128
 
        sections_[section] = new ItemMap;
 
111
        sections_[section] = ItemMap();
129
112
        iter = sections_.find(section);
130
113
    }
131
114
 
133
116
    if (iter != sections_.end()) {
134
117
        std::string name(item.getName());
135
118
 
136
 
        if (iter->second->find(name) == iter->second->end()) {
137
 
            (*(iter->second))[name] = item;
138
 
        }
 
119
        if (iter->second.find(name) == iter->second.end())
 
120
            iter->second[name] = item;
139
121
    }
140
122
}
141
123
 
163
145
bool
164
146
ConfigTree::getConfigTreeItemBoolValue(const std::string& section, const std::string& itemName) const
165
147
{
166
 
    std::string configItem = getConfigTreeItemValue(section, itemName);
167
 
 
168
 
    if (configItem == "true") {
169
 
        return true;
170
 
    }
171
 
 
172
 
    return false;
 
148
    return getConfigTreeItemValue(section, itemName) == "true";
173
149
}
174
150
 
175
151
bool
176
 
ConfigTree::getConfigTreeItemToken(const std::string& section, const std::string& itemName, TokenList& arg) const
 
152
ConfigTree::getConfigTreeItemToken(const std::string& section, const std::string& itemName, std::list<std::string>& arg) const
177
153
{
178
154
    const ConfigTreeItem *item = getConfigTreeItem(section, itemName);
179
155
 
186
162
        arg.push_back(item->getDefaultValue());
187
163
        return true;
188
164
    }
189
 
 
190
 
    return false;
 
165
    else
 
166
        return false;
191
167
}
192
168
 
193
169
/**
201
177
    if (iter == sections_.end())
202
178
        return NULL;
203
179
 
204
 
    ItemMap::const_iterator iterItem = iter->second->find(itemName);
 
180
    ItemMap::const_iterator iterItem = iter->second.find(itemName);
205
181
 
206
 
    if (iterItem == iter->second->end())
 
182
    if (iterItem == iter->second.end())
207
183
        return NULL;
208
184
 
209
185
    return & (iterItem->second);
215
191
 * @todo Élimier les 45,000 classes qui servent à rien pour Conf.
216
192
 * The true/false logic is useless here.
217
193
 */
218
 
bool
219
 
ConfigTree::setConfigTreeItem(const std::string& section,
 
194
void ConfigTree::setConfigTreeItem(const std::string& section,
220
195
                              const std::string& itemName,
221
196
                              const std::string& value)
222
197
{
223
 
 
224
198
    SectionMap::iterator iter = sections_.find(section);
225
199
 
226
200
    if (iter == sections_.end()) {
227
201
        // Not found, create section
228
 
        sections_[section] = new ItemMap;
 
202
        sections_[section] = ItemMap();
229
203
        iter = sections_.find(section);
230
204
    }
231
205
 
232
 
    ItemMap::iterator iterItem = iter->second->find(itemName);
 
206
    ItemMap::iterator iterItem = iter->second.find(itemName);
233
207
 
234
 
    if (iterItem == iter->second->end()) {
 
208
    if (iterItem == iter->second.end()) {
235
209
        // If not found, search in our default list to find
236
210
        // something that would fit.
237
211
        std::string defaultValue = getDefaultValue(itemName);
238
212
        addConfigTreeItem(section, ConfigTreeItem(itemName, value, defaultValue));
239
 
        return true;
 
213
        return;
240
214
    }
241
215
 
242
216
    // Use default value if the value is empty.
243
 
    if (value.empty() == true) {
 
217
    if (value.empty()) {
244
218
        iterItem->second.setValue(getDefaultValue(itemName));
245
 
        return true;
 
219
        return;
246
220
    }
247
221
 
248
222
    iterItem->second.setValue(value);
249
 
 
250
 
    return true;
 
223
    return;
251
224
}
252
225
 
253
226
// Save config to a file (ini format)
254
227
// return false if empty, no config, or enable to open
255
228
// return true if everything is ok
256
229
bool
257
 
ConfigTree::saveConfigTree(const std::string& fileName)
 
230
ConfigTree::saveConfigTree(const std::string& fileName) const
258
231
{
259
232
    DEBUG("ConfigTree: Save %s", fileName.c_str());
260
233
 
271
244
    }
272
245
 
273
246
    // for each section, for each item...
274
 
    SectionMap::iterator iter = sections_.begin();
275
 
 
276
 
    while (iter != sections_.end()) {
 
247
    for (SectionMap::const_iterator iter = sections_.begin(); iter != sections_.end(); ++iter) {
277
248
        file << "[" << iter->first << "]" << std::endl;
278
 
        ItemMap::iterator iterItem = iter->second->begin();
279
 
 
280
 
        while (iterItem != iter->second->end()) {
 
249
        for (ItemMap::const_iterator iterItem = iter->second.begin(); iterItem != iter->second.end(); ++iterItem)
281
250
            file << iterItem->first << "=" << iterItem->second.getValue() << std::endl;
282
 
            iterItem++;
283
 
        }
284
251
 
285
252
        file << std::endl;
286
 
 
287
 
        iter++;
288
253
    }
289
254
 
290
255
    file.close();
296
261
}
297
262
 
298
263
// Create the tree from an existing ini file
299
 
// 0 = error
300
 
// 1 = OK
301
 
// 2 = unable to open
302
 
int
 
264
// false = error
 
265
// true = OK
 
266
bool
303
267
ConfigTree::populateFromFile(const std::string& fileName)
304
268
{
305
269
    DEBUG("ConfigTree: Populate from file %s", fileName.c_str());
306
270
 
307
271
    if (fileName.empty())
308
 
        return 0;
 
272
        return false;
309
273
 
310
274
    std::fstream file;
311
275
 
315
279
        file.open(fileName.data(), std::fstream::out);
316
280
 
317
281
        if (!file.is_open())
318
 
            return 0;
 
282
            return false;
319
283
 
320
284
        file.close();
321
285
 
322
 
        return 2;
 
286
        return false;
323
287
    }
324
288
 
325
289
    // get length of file:
331
295
 
332
296
    if (length == 0) {
333
297
        file.close();
334
 
        return 2; // should load config
 
298
        return false; // should load config
335
299
    }
336
300
 
337
301
    std::string line;
338
 
 
339
 
    std::string section("");
340
 
    std::string key("");
341
 
    std::string val("");
 
302
    std::string section;
 
303
    std::string key;
 
304
    std::string val;
342
305
    std::string::size_type pos;
343
306
 
344
307
    while (!file.eof()) {
368
331
    if (chmod(fileName.c_str(), S_IRUSR | S_IWUSR))
369
332
        DEBUG("Failed to set permission on configuration file because: %m");
370
333
 
371
 
    return 1;
 
334
    return true;
372
335
}
373
336
 
374
 
TokenList
375
 
ConfigTreeIterator::begin()
 
337
std::list<std::string>
 
338
ConfigTreeIterator::begin() const
376
339
{
377
 
    TokenList tk;
 
340
    std::list<std::string> tk;
378
341
    iter_ = tree_->sections_.begin();
379
342
 
380
 
    if (iter_!=tree_->sections_.end()) {
381
 
        iterItem_ = iter_->second->begin();
 
343
    if (iter_ != tree_->sections_.end()) {
 
344
        iterItem_ = iter_->second.begin();
382
345
 
383
 
        if (iterItem_!=iter_->second->end()) {
 
346
        if (iterItem_ != iter_->second.end()) {
384
347
            tk.push_back(iter_->first);
385
348
            tk.push_back(iterItem_->first);
386
349
            tk.push_back(iterItem_->second.getType());
392
355
    return tk;
393
356
}
394
357
 
395
 
TokenList
 
358
std::list<std::string>
396
359
ConfigTreeIterator::next()
397
360
{
398
 
    TokenList tk;
 
361
    std::list<std::string> tk;
399
362
    // we return tk empty if we are at the end of the list...
400
363
 
401
364
    if (iter_ == tree_->sections_.end())
402
365
        return tk;
403
366
 
404
 
    if (iterItem_ != iter_->second->end())
 
367
    if (iterItem_ != iter_->second.end())
405
368
        iterItem_++;
406
369
 
407
 
    if (iterItem_ == iter_->second->end()) {
 
370
    if (iterItem_ == iter_->second.end()) {
408
371
        // if we increment, and we are at the end of a section
409
372
        iter_++;
410
373
 
411
374
        if (iter_ != tree_->sections_.end()) {
412
 
            iterItem_ = iter_->second->begin();
 
375
            iterItem_ = iter_->second.begin();
413
376
 
414
 
            if (iterItem_ != iter_->second->end()) {
 
377
            if (iterItem_ != iter_->second.end()) {
415
378
                tk.push_back(iter_->first);
416
379
                tk.push_back(iterItem_->first);
417
380
                tk.push_back(iterItem_->second.getType());