1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
|
#include "llviewerprecompiledheaders.h"
#include "hippoGridManager.h"
#include <cctype>
#include <stdtypes.h>
#include <lldir.h>
#include <lleconomy.h>
#include <llerror.h>
#include <llfile.h>
#include <llhttpclient.h>
#include <llsdserialize.h>
#include "lltrans.h"
#include "llviewercontrol.h"
#include "llweb.h"
#include "hippoRestRequest.h"
// ********************************************************************
// Global Variables
HippoGridManager *gHippoGridManager = 0;
HippoGridInfo HippoGridInfo::FALLBACK_GRIDINFO("");
// ********************************************************************
// ********************************************************************
// HippoGridInfo
// ********************************************************************
// ********************************************************************
// ********************************************************************
// Initialize
HippoGridInfo::HippoGridInfo(const std::string &gridNick) :
mPlatform(PLATFORM_OTHER),
mRenderCompat(true),
mCurrencySymbol("OS$"),
mRealCurrencySymbol("US$"),
mDirectoryFee(30)
{
std::string nick = gridNick;
mGridNick = sanitizeGridNick( nick );
}
// ********************************************************************
// Getters
HippoGridInfo::Platform HippoGridInfo::getPlatform()
{
return mPlatform;
}
bool HippoGridInfo::isOpenSimulator() const
{
return (mPlatform == HippoGridInfo::PLATFORM_OPENSIM);
}
bool HippoGridInfo::isSecondLife() const
{
return (mPlatform == HippoGridInfo::PLATFORM_SECONDLIFE);
}
const std::string& HippoGridInfo::getGridNick() const
{
return mGridNick;
}
const std::string& HippoGridInfo::getGridName() const
{
return mGridName;
}
const std::string& HippoGridInfo::getLoginUri() const
{
return mLoginUri;
}
const std::string& HippoGridInfo::getLoginPage() const
{
return mLoginPage;
}
const std::string& HippoGridInfo::getHelperUri() const
{
return mHelperUri;
}
const std::string& HippoGridInfo::getWebSite() const
{
return mWebSite;
}
const std::string& HippoGridInfo::getSupportUrl() const
{
return mSupportUrl;
}
const std::string& HippoGridInfo::getRegisterUrl() const
{
return mRegisterUrl;
}
const std::string& HippoGridInfo::getPasswordUrl() const
{
return mPasswordUrl;
}
const std::string& HippoGridInfo::getSearchUrl() const
{
return mSearchUrl;
}
const std::string& HippoGridInfo::getFirstName() const
{
return mFirstName;
}
const std::string& HippoGridInfo::getLastName() const
{
return mLastName;
}
const std::string& HippoGridInfo::getAvatarPassword() const
{
return mAvatarPassword;
}
bool HippoGridInfo::isRenderCompat() const
{
return mRenderCompat;
}
const std::string& HippoGridInfo::getCurrencySymbol() const
{
return mCurrencySymbol;
}
const std::string& HippoGridInfo::getRealCurrencySymbol() const
{
return mRealCurrencySymbol;
}
// ********************************************************************
// Setters
void HippoGridInfo::setPlatform(Platform platform)
{
mPlatform = platform;
mCurrencySymbol = (mPlatform == PLATFORM_SECONDLIFE)? "L$": "OS$";
}
void HippoGridInfo::setPlatform(const std::string &platform)
{
std::string tmp = platform;
for (unsigned i=0; i<platform.size(); i++)
tmp[i] = tolower(tmp[i]);
if (tmp == "opensim") {
setPlatform(PLATFORM_OPENSIM);
} else if (tmp == "secondlife") {
setPlatform(PLATFORM_SECONDLIFE);
} else {
setPlatform(PLATFORM_OTHER);
llwarns << "Unknown platform '" << platform << "'." << llendl;
}
}
void HippoGridInfo::setGridName(const std::string &gridName)
{
mGridName = gridName;
}
void HippoGridInfo::setLoginUri(const std::string &loginUri)
{
std::string uri = loginUri;
mLoginUri = sanitizeUri(uri);
}
void HippoGridInfo::setLoginPage(const std::string &loginPage)
{
mLoginPage = loginPage;
}
void HippoGridInfo::setHelperUri(const std::string &helperUri)
{
std::string uri = helperUri;
mHelperUri = sanitizeUri(uri);
}
void HippoGridInfo::setWebSite(const std::string &website)
{
mWebSite = website;
}
void HippoGridInfo::setSupportUrl(const std::string &url)
{
mSupportUrl = url;
}
void HippoGridInfo::setRegisterUrl(const std::string &url)
{
mRegisterUrl = url;
}
void HippoGridInfo::setPasswordUrl(const std::string &url)
{
mPasswordUrl = url;
}
void HippoGridInfo::setSearchUrl(const std::string &url)
{
mSearchUrl = url;
}
void HippoGridInfo::setFirstName(const std::string &firstName)
{
mFirstName = firstName;
}
void HippoGridInfo::setLastName(const std::string &lastName)
{
mLastName = lastName;
}
void HippoGridInfo::setAvatarPassword(const std::string &avatarPassword)
{
mAvatarPassword = avatarPassword;
}
void HippoGridInfo::setRenderCompat(bool compat)
{
mRenderCompat = compat;
}
void HippoGridInfo::setCurrencySymbol(const std::string &sym)
{
mCurrencySymbol = sym.substr(0, 3);
}
void HippoGridInfo::setRealCurrencySymbol(const std::string &sym)
{
mRealCurrencySymbol = sym.substr(0, 3);
}
void HippoGridInfo::setDirectoryFee(int fee)
{
mDirectoryFee = fee;
}
// ********************************************************************
// Grid Info
std::string HippoGridInfo::getSearchUrl(SearchType ty, bool is_web) const
{
// Don't worry about whether or not mSearchUrl is empty here anymore -- MC
if (is_web)
{
if (mPlatform == PLATFORM_SECONDLIFE)
{
// Second Life defaults
if (ty == SEARCH_ALL_EMPTY) {
return gSavedSettings.getString("SearchURLDefault");
} else if (ty == SEARCH_ALL_QUERY) {
return gSavedSettings.getString("SearchURLQuery");
} else if (ty == SEARCH_ALL_TEMPLATE) {
return gSavedSettings.getString("SearchURLSuffix2");
} else {
llinfos << "Illegal search URL type " << ty << llendl;
return "";
}
}
else
{
// OpenSim and other web search defaults
if (ty == SEARCH_ALL_EMPTY) {
return gSavedSettings.getString("SearchURLDefaultOpenSim");
} else if (ty == SEARCH_ALL_QUERY) {
return gSavedSettings.getString("SearchURLQueryOpenSim");
} else if (ty == SEARCH_ALL_TEMPLATE) {
return gSavedSettings.getString("SearchURLSuffixOpenSim");
} else {
llinfos << "Illegal search URL type " << ty << llendl;
return "";
}
}
}
else
{
// Use the old search all
if (ty == SEARCH_ALL_EMPTY) {
return (mSearchUrl + "panel=All&");
} else if (ty == SEARCH_ALL_QUERY) {
return (mSearchUrl + "q=[QUERY]&s=[COLLECTION]&");
} else if (ty == SEARCH_ALL_TEMPLATE) {
return "lang=[LANG]&m=[MATURE]&t=[TEEN]®ion=[REGION]&x=[X]&y=[Y]&z=[Z]&session=[SESSION]";
} else {
llinfos << "Illegal search URL type " << ty << llendl;
return "";
}
}
}
//static
void HippoGridInfo::onXmlElementStart(void *userData, const XML_Char *name, const XML_Char **atts)
{
HippoGridInfo *self = (HippoGridInfo*)userData;
if (strcasecmp(name, "gridnick") == 0)
self->mXmlState = XML_GRIDNICK;
else if (strcasecmp(name, "gridname") == 0)
self->mXmlState = XML_GRIDNAME;
else if (strcasecmp(name, "platform") == 0)
self->mXmlState = XML_PLATFORM;
else if ((strcasecmp(name, "login") == 0) || (strcasecmp(name, "loginuri") == 0))
self->mXmlState = XML_LOGINURI;
else if ((strcasecmp(name, "welcome") == 0) || (strcasecmp(name, "loginpage") == 0))
self->mXmlState = XML_LOGINPAGE;
else if ((strcasecmp(name, "economy") == 0) || (strcasecmp(name, "helperuri") == 0))
self->mXmlState = XML_HELPERURI;
else if ((strcasecmp(name, "about") == 0) || (strcasecmp(name, "website") == 0))
self->mXmlState = XML_WEBSITE;
else if ((strcasecmp(name, "help") == 0) || (strcasecmp(name, "support") == 0))
self->mXmlState = XML_SUPPORT;
else if ((strcasecmp(name, "register") == 0) || (strcasecmp(name, "account") == 0))
self->mXmlState = XML_REGISTER;
else if (strcasecmp(name, "password") == 0)
self->mXmlState = XML_PASSWORD;
//else if (strcasecmp(name, "search") == 0)
//self->mXmlState = XML_SEARCH;
}
//static
void HippoGridInfo::onXmlElementEnd(void *userData, const XML_Char *name)
{
HippoGridInfo *self = (HippoGridInfo*)userData;
self->mXmlState = XML_VOID;
}
//static
void HippoGridInfo::onXmlCharacterData(void *userData, const XML_Char *s, int len)
{
HippoGridInfo *self = (HippoGridInfo*)userData;
switch (self->mXmlState) {
case XML_GRIDNICK: {
if (self->mGridNick == "") self->mGridNick.assign(s, len);
self->mGridNick = sanitizeGridNick(self->mGridNick);
break;
}
case XML_PLATFORM: {
std::string platform(s, len);
self->setPlatform(platform);
break;
}
case XML_LOGINURI: {
std::string loginuri(s, len);
self->mLoginUri = sanitizeUri( loginuri );
break;
}
case XML_HELPERURI: {
std::string helperuri(s, len);
self->mHelperUri = sanitizeUri( helperuri );
break;
}
case XML_SEARCH: {
//self->mSearchUrl.assign(s, len);
//sanitizeQueryUrl(mSearchUrl);
break;
}
case XML_GRIDNAME: self->mGridName.assign(s, len); break;
case XML_LOGINPAGE: self->mLoginPage.assign(s, len); break;
case XML_WEBSITE: self->mWebSite.assign(s, len); break;
case XML_SUPPORT: self->mSupportUrl.assign(s, len); break;
case XML_REGISTER: self->mRegisterUrl.assign(s, len); break;
case XML_PASSWORD: self->mPasswordUrl.assign(s, len); break;
case XML_VOID: break;
}
}
bool HippoGridInfo::retrieveGridInfo()
{
if (mLoginUri == "") return false;
// If last character in uri is not "/"
std::string uri = mLoginUri;
if (uri.compare(uri.length()-1, 1, "/") != 0)
{
uri += '/';
}
std::string reply;
int result = HippoRestRequest::getBlocking(uri + "get_grid_info", &reply);
if (result != 200) return false;
llinfos << "Received: " << reply << llendl;
bool success = true;
XML_Parser parser = XML_ParserCreate(0);
XML_SetUserData(parser, this);
XML_SetElementHandler(parser, onXmlElementStart, onXmlElementEnd);
XML_SetCharacterDataHandler(parser, onXmlCharacterData);
mXmlState = XML_VOID;
if (!XML_Parse(parser, reply.data(), reply.size(), TRUE)) {
llwarns << "XML Parse Error: " << XML_ErrorString(XML_GetErrorCode(parser)) << llendl;
success = false;
}
XML_ParserFree(parser);
return success;
}
std::string HippoGridInfo::getUploadFee() const
{
std::string fee;
formatFee(fee, LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(), true);
return fee;
}
std::string HippoGridInfo::getGroupCreationFee() const
{
std::string fee;
formatFee(fee, LLGlobalEconomy::Singleton::getInstance()->getPriceGroupCreate(), false);
return fee;
}
std::string HippoGridInfo::getDirectoryFee() const
{
std::string fee;
formatFee(fee, mDirectoryFee, true);
if (fee != LLTrans::getString("hippo_label_free")) fee += "/" + LLTrans::getString("hippo_label_week");
return fee;
}
void HippoGridInfo::formatFee(std::string &fee, int cost, bool showFree) const
{
if (showFree && (cost == 0)) {
fee = LLTrans::getString("hippo_label_free");
} else {
fee = llformat("%s%d", getCurrencySymbol().c_str(), cost);
}
}
// ********************************************************************
// Static Helpers
// static
const char *HippoGridInfo::getPlatformString(Platform platform)
{
static const char *platformStrings[PLATFORM_LAST] = {
"Other", "OpenSim", "SecondLife"
};
if ((platform < PLATFORM_OTHER) || (platform >= PLATFORM_LAST))
platform = PLATFORM_OTHER;
return platformStrings[platform];
}
// static
std::string HippoGridInfo::sanitizeGridNick(std::string &gridnick)
{
std::string tmp;
int size = gridnick.size();
for (int i=0; i<size; i++) {
char c = gridnick[i];
if ((c == '_') || isalnum(c)) {
tmp += tolower(c);
} else if (isspace(c)) {
tmp += "_";
}
}
return tmp;
}
// static
std::string HippoGridInfo::sanitizeUri(std::string &uri)
{
// if (uri.empty()) {
// return "";
// }
// // If last character in uri is not "/"
// // NOTE: This wrongly assumes that all URIs should end with "/"!
// if (uri.compare(uri.length()-1, 1, "/") != 0) {
// return uri + '/';
// }
return uri;
}
void HippoGridInfo::initFallback()
{
FALLBACK_GRIDINFO.mGridNick = "localhost";
FALLBACK_GRIDINFO.setPlatform(PLATFORM_OPENSIM);
FALLBACK_GRIDINFO.setGridName("Local Host");
FALLBACK_GRIDINFO.setLoginUri("http://127.0.0.1:9000/");
FALLBACK_GRIDINFO.setHelperUri("http://127.0.0.1:9000/");
}
// ********************************************************************
// ********************************************************************
// HippoGridManager
// ********************************************************************
// ********************************************************************
// ********************************************************************
// Initialize
HippoGridManager::HippoGridManager() :
mConnectedGrid(0),
mDefaultGridsVersion(0)
{
}
HippoGridManager::~HippoGridManager()
{
cleanup();
}
void HippoGridManager::cleanup()
{
std::map<std::string, HippoGridInfo*>::iterator it, end = mGridInfo.end();
for (it=mGridInfo.begin(); it != end; ++it) {
delete it->second;
}
mGridInfo.clear();
}
void HippoGridManager::init()
{
HippoGridInfo::initFallback();
loadFromFile();
// !!!### gSavedSettings.getControl("CmdLineLoginURI");
// !!!### gSavedSettings.getString("CmdLineLoginPage");
// !!!### gSavedSettings.getString("CmdLineHelperURI");
// !!!### LLString::compareInsensitive(gGridInfo[grid_index].mLabel, grid_name.c_str()))
}
void HippoGridManager::discardAndReload()
{
cleanup();
loadFromFile();
}
// ********************************************************************
// Public Access
HippoGridInfo* HippoGridManager::getGrid(const std::string &grid) const
{
std::map<std::string, HippoGridInfo*>::const_iterator it;
it = mGridInfo.find(grid);
if (it != mGridInfo.end()) {
return it->second;
} else {
return 0;
}
}
HippoGridInfo* HippoGridManager::getConnectedGrid() const
{
return (mConnectedGrid)? mConnectedGrid: getCurrentGrid();
}
HippoGridInfo* HippoGridManager::getCurrentGrid() const
{
HippoGridInfo *grid = getGrid(mCurrentGrid);
if (grid) {
return grid;
} else {
return &HippoGridInfo::FALLBACK_GRIDINFO;
}
}
const std::string& HippoGridManager::getDefaultGridNick() const
{
return mDefaultGrid;
}
const std::string& HippoGridManager::getCurrentGridNick() const
{
return mCurrentGrid;
}
void HippoGridManager::setCurrentGridAsConnected()
{
mConnectedGrid = getCurrentGrid();
}
void HippoGridManager::addGrid(HippoGridInfo *grid)
{
if (!grid) return;
const std::string &nick = grid->getGridNick();
if (nick == "") {
llwarns << "Ignoring to try adding grid with empty nick." << llendl;
delete grid;
return;
}
if (mGridInfo.find(nick) != mGridInfo.end()) {
llwarns << "Ignoring to try adding existing grid " << nick << '.' << llendl;
delete grid;
return;
}
mGridInfo[nick] = grid;
}
void HippoGridManager::deleteGrid(const std::string &grid)
{
GridIterator it = mGridInfo.find(grid);
if (it == mGridInfo.end()) {
llwarns << "Trying to delete non-existing grid " << grid << '.' << llendl;
return;
}
mGridInfo.erase(it);
llinfos << "Number of grids now: " << mGridInfo.size() << llendl;
if (mGridInfo.empty()) llinfos << "Grid info map is empty." << llendl;
if (grid == mDefaultGrid)
setDefaultGrid(""); // sets first grid, if map not empty
if (grid == mCurrentGrid)
mCurrentGrid = mDefaultGrid;
}
void HippoGridManager::setDefaultGrid(const std::string &grid)
{
GridIterator it = mGridInfo.find(grid);
if (it != mGridInfo.end()) {
mDefaultGrid = grid;
} else if (mGridInfo.find("secondlife") != mGridInfo.end()) {
mDefaultGrid = "secondlife";
} else if (!mGridInfo.empty()) {
mDefaultGrid = mGridInfo.begin()->first;
} else {
mDefaultGrid = "";
}
}
void HippoGridManager::setCurrentGrid(const std::string &grid)
{
GridIterator it = mGridInfo.find(grid);
if (it != mGridInfo.end()) {
mCurrentGrid = grid;
} else if (!mGridInfo.empty()) {
llwarns << "Unknown grid '" << grid << "'. Setting to default grid." << llendl;
mCurrentGrid = mDefaultGrid;
}
}
// ********************************************************************
// Persistent Store
void HippoGridManager::loadFromFile()
{
mDefaultGridsVersion = 0;
// load user grid info
parseFile(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml"), false);
// merge default grid info, if newer. Force load, if list of grids is empty.
parseFile(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "default_grids.xml"), !mGridInfo.empty());
// merge grid info from web site, if newer. Force load, if list of grids is empty.
if (gSavedSettings.getBOOL("CheckForGridUpdates"))
parseUrl("http://imprudenceviewer.org/app/grids/", !mGridInfo.empty());
std::string last_grid = gSavedSettings.getString("LastSelectedGrid");
if (last_grid.empty()) last_grid = gSavedSettings.getString("DefaultGrid");
setDefaultGrid(last_grid);
setCurrentGrid(last_grid);
}
void HippoGridManager::parseUrl(const char *url, bool mergeIfNewer)
{
llinfos << "Loading grid info from '" << url << "'." << llendl;
// query update server
std::string escaped_url = LLWeb::escapeURL(url);
LLSD response = LLHTTPClient::blockingGet(url);
// check response, return on error
S32 status = response["status"].asInteger();
if ((status != 200) || !response["body"].isArray()) {
llinfos << "GridInfo Update failed (" << status << "): "
<< (response["body"].isString()? response["body"].asString(): "<unknown error>")
<< llendl;
return;
}
LLSD gridInfo = response["body"];
parseData(gridInfo, mergeIfNewer);
}
void HippoGridManager::parseFile(const std::string &fileName, bool mergeIfNewer)
{
llifstream infile;
infile.open(fileName.c_str());
if(!infile.is_open()) {
llwarns << "Cannot find grid info file " << fileName << " to load." << llendl;
return;
}
LLSD gridInfo;
if (LLSDSerialize::fromXML(gridInfo, infile) <= 0) {
llwarns << "Unable to parse grid info file " << fileName << '.' << llendl;
return;
}
llinfos << "Loading grid info file " << fileName << '.' << llendl;
parseData(gridInfo, mergeIfNewer);
}
void HippoGridManager::parseData(LLSD &gridInfo, bool mergeIfNewer)
{
if (mergeIfNewer) {
LLSD::array_const_iterator it, end = gridInfo.endArray();
for (it = gridInfo.beginArray(); it != end; ++it) {
LLSD gridMap = *it;
if (gridMap.has("default_grids_version")) {
int version = gridMap["default_grids_version"];
if (version <= mDefaultGridsVersion) return;
else break;
}
}
if (it == end) {
llwarns << "Grid data has no version number." << llendl;
return;
}
}
llinfos << "Loading grid data." << llendl;
LLSD::array_const_iterator it, end = gridInfo.endArray();
for (it = gridInfo.beginArray(); it != end; ++it) {
LLSD gridMap = *it;
if (gridMap.has("default_grids_version")) {
mDefaultGridsVersion = gridMap["default_grids_version"];
} else if (gridMap.has("gridnick") && gridMap.has("loginuri")) {
std::string gridnick = gridMap["gridnick"];
HippoGridInfo *grid;
GridIterator it = mGridInfo.find(gridnick);
bool newGrid = (it == mGridInfo.end());
if (newGrid) {
// create new grid info
grid = new HippoGridInfo(gridnick);
} else {
// update existing grid info
grid = it->second;
}
grid->setLoginUri(gridMap["loginuri"]);
if (gridMap.has("platform")) grid->setPlatform(gridMap["platform"]);
if (gridMap.has("gridname")) grid->setGridName(gridMap["gridname"]);
if (gridMap.has("loginpage")) grid->setLoginPage(gridMap["loginpage"]);
if (gridMap.has("helperuri")) grid->setHelperUri(gridMap["helperuri"]);
if (gridMap.has("website")) grid->setWebSite(gridMap["website"]);
if (gridMap.has("support")) grid->setSupportUrl(gridMap["support"]);
if (gridMap.has("register")) grid->setRegisterUrl(gridMap["register"]);
if (gridMap.has("password")) grid->setPasswordUrl(gridMap["password"]);
//if (gridMap.has("search")) grid->setSearchUrl(gridMap["search"]);
if (gridMap.has("render_compat")) grid->setRenderCompat(gridMap["render_compat"]);
// if (gridMap.has("firstname")) grid->setFirstName(gridMap["firstname"]);
// if (gridMap.has("lastname")) grid->setLastName(gridMap["lastname"]);
// if (gridMap.has("avatarpassword")) grid->setAvatarPassword(gridMap["avatarpassword"]);
if (newGrid) addGrid(grid);
}
}
}
void HippoGridManager::saveFile()
{
// save default grid to client settings
gSavedSettings.setString("DefaultGrid", mDefaultGrid);
// build LLSD
LLSD gridInfo;
gridInfo[0]["default_grids_version"] = mDefaultGridsVersion;
// add grids
S32 i = 1;
GridIterator it, end = mGridInfo.end();
for (it = mGridInfo.begin(); it != end; ++it, i++) {
HippoGridInfo *grid = it->second;
gridInfo[i]["gridnick"] = grid->getGridNick();
gridInfo[i]["platform"] = HippoGridInfo::getPlatformString(grid->getPlatform());
gridInfo[i]["gridname"] = grid->getGridName();
gridInfo[i]["loginuri"] = grid->getLoginUri();
gridInfo[i]["loginpage"] = grid->getLoginPage();
gridInfo[i]["helperuri"] = grid->getHelperUri();
gridInfo[i]["website"] = grid->getWebSite();
gridInfo[i]["support"] = grid->getSupportUrl();
gridInfo[i]["register"] = grid->getRegisterUrl();
gridInfo[i]["password"] = grid->getPasswordUrl();
// gridInfo[i]["firstname"] = grid->getFirstName();
// gridInfo[i]["lastname"] = grid->getLastName();
// gridInfo[i]["avatarpassword"] = grid->getAvatarPassword();
//gridInfo[i]["search"] = grid->getSearchUrl();
gridInfo[i]["render_compat"] = grid->isRenderCompat();
}
// write client grid info file
std::string fileName = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml");
llofstream file;
file.open(fileName.c_str());
if (file.is_open()) {
LLSDSerialize::toPrettyXML(gridInfo, file);
file.close();
llinfos << "Saved grids to " << fileName << llendl;
} else {
llerrs << "Unable to open grid info file: " << fileName << llendl;
}
}
|