00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <sys/stat.h>
00034 #include <sys/types.h>
00035 #include <unistd.h>
00036
00037 #include <glib.h>
00038
00039 #include "erreglog.h"
00040 #include "erreg.h"
00041 #include "erregtypes_f.h"
00042 #include "erregrwlock.h"
00043 #include "erregxml.h"
00044 #include "system.h"
00045
00046
00048
00049
00050
00052
00053 gboolean regValidate(regRegistry_t* pRegistry)
00054 {
00055 ERREG_LOGPRINTF("entry");
00056 g_assert(pRegistry);
00057 g_assert(pRegistry->xmlCxt.pDoc);
00058
00059 gboolean bRet;
00060
00061 bRet = xsdValidateXmlDoc(&pRegistry->xsdCxt, pRegistry->xmlCxt.pDoc);
00062 if (bRet)
00063 {
00064 ERREG_LOGPRINTF("Validation succeeded, filename [%s]", pRegistry->xmlCxt.szFileName);
00065 }
00066 else
00067 {
00068 ERREG_ERRORPRINTF("Validation failed, filename [%s]", pRegistry->xmlCxt.szFileName);
00069 }
00070
00071 return bRet;
00072 }
00073
00074 static regRegistry_t *regParseSingleFile(const char *szXmlFile, const char *szXsdFile)
00075 {
00076 gboolean bRet = FALSE;
00077 regRegistry_t *pRegistry = NULL;
00078
00079 ERREG_LOGPRINTF("entry: xml [%s] xsd [%s]", szXmlFile, szXsdFile);
00080 g_assert(szXmlFile);
00081 g_assert(szXsdFile);
00082
00083
00084 pRegistry = g_new0(regRegistry_t, 1);
00085 g_assert(pRegistry != NULL);
00086
00087
00088 int nRet = ermXmlOpenFile(szXmlFile, &(pRegistry->xmlCxt));
00089 if (RET_OK == nRet)
00090 {
00091
00092 bRet = xsdLoad(&(pRegistry->xsdCxt), szXsdFile);
00093 if (bRet)
00094 {
00095
00096 bRet = regValidate(pRegistry);
00097 if (FALSE == bRet)
00098 {
00099 ERREG_ERRORPRINTF("xsd validation error on [%s] [%s]", szXmlFile, szXsdFile);
00100 }
00101 }
00102 else
00103 {
00104
00105 ERREG_ERRORPRINTF("xsdLoad error on [%s]", szXsdFile);
00106 }
00107 }
00108 else
00109 {
00110 ERREG_ERRORPRINTF("ermXmlOpenFile error on [%s]", szXmlFile);
00111 }
00112
00113
00114 if (FALSE == bRet)
00115 {
00116 regDestroy(pRegistry);
00117 pRegistry = NULL;
00118 }
00119
00120 ERREG_LOGPRINTF("leave: pRegistry [%p]", pRegistry);
00121 return pRegistry;
00122 }
00123
00124 regRegistry_t *regParseFiles(const char *szXmlFile, const char *szXsdFile)
00125 {
00126 ERREG_LOGPRINTF("entry: xml [%s] xsd [%s]", szXmlFile, szXsdFile);
00127 g_assert(szXmlFile);
00128 g_assert(szXsdFile);
00129
00130 regRegistry_t *pRegistry = NULL;
00131 gchar *cp;
00132
00133
00134 pRegistry = regParseSingleFile(szXmlFile, szXsdFile);
00135 if (pRegistry == NULL)
00136 {
00137
00138 cp = g_strdup_printf("%s.new", szXmlFile);
00139 ERREG_WARNPRINTF("Trying registry file [%s]", cp);
00140 pRegistry = regParseSingleFile(cp, szXsdFile);
00141 g_free(cp);
00142 if (pRegistry == NULL)
00143 {
00144
00145 cp = g_strdup_printf("%s.old", szXmlFile);
00146 ERREG_WARNPRINTF("Trying registry file [%s]", cp);
00147 pRegistry = regParseSingleFile(szXmlFile, cp);
00148 g_free(cp);
00149 }
00150
00151
00152 if (pRegistry)
00153 {
00154 pRegistry->changed = TRUE;
00155 if (erRegGetLockState() == lock_write)
00156 {
00157 regStore(pRegistry, szXmlFile);
00158 }
00159 }
00160 }
00161
00162 ERREG_LOGPRINTF("leave: pRegistry [%p]", pRegistry);
00163 return pRegistry;
00164 }
00165
00166 gboolean regStore(regRegistry_t *pRegistry, const char *szPath)
00167 {
00168
00169 ERREG_LOGPRINTF("entry: szPath [%s]", szPath);
00170 g_assert(pRegistry);
00171 g_assert(szPath);
00172
00173 gboolean bRet = FALSE;
00174 int rc;
00175 int n;
00176 char szDirPath[BUF_LEN];
00177 gchar *szPath_old = g_strdup_printf("%s.old", szPath);
00178 gchar *szPath_new = g_strdup_printf("%s.new", szPath);
00179
00180
00181 if (pRegistry->changed)
00182 {
00183 if ( regValidate(pRegistry) )
00184 {
00185
00186 n = readlink(REG_DIR, szDirPath, sizeof(szDirPath));
00187 if (n > 0 && n < sizeof(szDirPath))
00188 {
00189
00190 szDirPath[n] = '\0';
00191 }
00192 else
00193 {
00194 snprintf(szDirPath, sizeof(szDirPath), "%s", REG_DIR);
00195 }
00196
00197 mkdir(szDirPath, 0755);
00198
00199
00200 rename(szPath, szPath_old);
00201
00202
00203 rc = ermXmlSaveAs(&pRegistry->xmlCxt, szPath_new);
00204 if (RET_OK == rc)
00205 {
00206
00207 rc = rename(szPath_new, szPath);
00208 if (0 == rc)
00209 {
00210
00211 pRegistry->changed = FALSE;
00212 bRet = TRUE;
00213 }
00214 }
00215 else
00216 {
00217
00218 ERREG_ERRORPRINTF("Registry section [%d] save error [%s]", pRegistry->section, szPath_new);
00219 unlink(szPath_new);
00220 }
00221 }
00222 else
00223 {
00224 ERREG_ERRORPRINTF("Registry section [%d] validation error", pRegistry->section);
00225 }
00226 }
00227 else
00228 {
00229 ERREG_WARNPRINTF("Registry section [%d] not saved because no changes", pRegistry->section);
00230 bRet = TRUE;
00231 }
00232
00233 g_free(szPath_new);
00234 g_free(szPath_old);
00235 ERREG_LOGPRINTF("leave: bRet [%d]", bRet);
00236 return bRet;
00237 }
00238
00239 void regDestroy(regRegistry_t *pRegistry)
00240 {
00241 ERREG_LOGPRINTF("entry");
00242 g_assert(pRegistry);
00243
00244 ermXmlClose(&(pRegistry->xmlCxt));
00245 xsdUnload(&(pRegistry->xsdCxt));
00246 g_free(pRegistry);
00247 }
00248
00250
00251
00252
00254 regVersion_t *regGetVersion(const regRegistry_t *pRegistry)
00255 {
00256 regVersion_t *theVersion = NULL;
00257
00258 ERREG_LOGPRINTF("entry %p", pRegistry);
00259 g_assert(pRegistry);
00260 g_assert(pRegistry->xpaths);
00261 g_assert(pRegistry->xpaths->version);
00262
00263 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
00264 int nLen, nRet;
00265
00266 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00267
00268 theVersion = g_new0(regVersion_t, 1);
00269 g_assert(theVersion != NULL);
00270
00271 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->version, EL_REGISTRY);
00272 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
00273 if (RET_ERR == nRet)
00274 {
00275 ERREG_ERRORPRINTF("Can't get regVersion_t from memory.");
00276 regFreeVersion(theVersion);
00277 theVersion = NULL;
00278 return NULL;
00279 }
00280 else
00281 {
00282 theVersion->registry = g_strdup(szTmp);
00283 }
00284
00285 regDumpVersion(theVersion);
00286 return theVersion;
00287 }
00288
00289 gboolean regSetVersion(const regVersion_t *theVersion, regRegistry_t *pRegistry)
00290 {
00291 ERREG_LOGPRINTF("entry %p %p", theVersion, pRegistry);
00292 g_assert(theVersion);
00293 g_assert(pRegistry);
00294 g_assert(pRegistry->xpaths);
00295 g_assert(pRegistry->xpaths->version);
00296
00297 regDumpVersion(theVersion);
00298
00299 if (theVersion->registry)
00300 {
00301 char xpath[BUF_LEN + 1];
00302 int nLen, nRet;
00303
00304 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00305
00306 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->version, EL_REGISTRY);
00307 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00308 if (RET_OK == nRet)
00309 {
00310 nRet = ermXmlSetString(pXmlCxt, xpath, theVersion->registry);
00311 }
00312 if (RET_ERR == nRet)
00313 {
00314 return FALSE;
00315 }
00316 }
00317
00318 pRegistry->changed = TRUE;
00319 return TRUE;
00320 }
00321
00322 regUserProfile_t *regGetUserProfile(const regRegistry_t *pRegistry)
00323 {
00324 regUserProfile_t *theUserProfile = NULL;
00325
00326 ERREG_LOGPRINTF("entry");
00327 g_assert(pRegistry);
00328 g_assert(pRegistry->xpaths);
00329 g_assert(pRegistry->xpaths->userProfile);
00330
00331 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
00332 int nLen, nRet;
00333
00334 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00335
00336 theUserProfile = g_new0(regUserProfile_t, 1);
00337 g_assert(theUserProfile != NULL);
00338
00339
00340 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userProfile, EL_NAME);
00341 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
00342 if (RET_ERR == nRet)
00343 {
00344 ERREG_ERRORPRINTF("Can't get name from memory.");
00345 regFreeUserProfile(theUserProfile);
00346 theUserProfile = NULL;
00347 return NULL;
00348 }
00349 theUserProfile->name = g_strdup(szTmp);
00350
00351
00352 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userProfile, EL_EMAIL);
00353 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
00354 if (RET_ERR == nRet)
00355 {
00356 ERREG_ERRORPRINTF("Can't get email from memory.");
00357 regFreeUserProfile(theUserProfile);
00358 theUserProfile = NULL;
00359 return NULL;
00360 }
00361 theUserProfile->email = g_strdup(szTmp);
00362
00363
00364 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userProfile, EL_PASSWORD);
00365 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
00366 if (RET_ERR == nRet)
00367 {
00368 ERREG_ERRORPRINTF("Can't get password from memory.");
00369 regFreeUserProfile(theUserProfile);
00370 theUserProfile = NULL;
00371 return NULL;
00372 }
00373 theUserProfile->password = g_strdup(szTmp);
00374
00375
00376 gboolean bConfig = FALSE;
00377 char* cp = strstr(pRegistry->xpaths->userProfile, EL_CONFIG_ROOT);
00378 bConfig = (cp != NULL) ? TRUE : FALSE;
00379 ERREG_LOGPRINTF("bConfig=%d", bConfig);
00380 if (!bConfig)
00381 {
00382 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userProfile, EL_REDIRECT_URL);
00383 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
00384 if (RET_ERR == nRet)
00385 {
00386 ERREG_ERRORPRINTF("Can't get redirectUrl from memory.");
00387 regFreeUserProfile(theUserProfile);
00388 theUserProfile = NULL;
00389 return NULL;
00390 }
00391 theUserProfile->redirectUrl = g_strdup(szTmp);
00392 }
00393
00394 regDumpUserProfile(theUserProfile);
00395 return theUserProfile;
00396 }
00397
00398 gboolean regSetUserProfile(const regUserProfile_t *theUserProfile, regRegistry_t *pRegistry)
00399 {
00400 ERREG_LOGPRINTF("entry %p %p", theUserProfile, pRegistry);
00401 g_assert(theUserProfile);
00402 g_assert(pRegistry);
00403 g_assert(pRegistry->xpaths);
00404 g_assert(pRegistry->xpaths->userProfile);
00405
00406 regDumpUserProfile(theUserProfile);
00407
00408 char xpath[BUF_LEN + 1];
00409 int nLen, nRet = RET_OK;
00410
00411 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00412
00413
00414 if (theUserProfile->name)
00415 {
00416 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userProfile, EL_NAME);
00417 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00418 if (RET_OK == nRet)
00419 {
00420 nRet = ermXmlSetString(pXmlCxt, xpath, theUserProfile->name);
00421 }
00422 if (RET_ERR == nRet)
00423 {
00424 return FALSE;
00425 }
00426 }
00427
00428
00429 if (theUserProfile->email)
00430 {
00431 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userProfile, EL_EMAIL);
00432 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00433 if (RET_OK == nRet)
00434 {
00435 nRet = ermXmlSetString(pXmlCxt, xpath, theUserProfile->email);
00436 }
00437 if (RET_ERR == nRet)
00438 {
00439 return FALSE;
00440 }
00441 }
00442
00443
00444 if (theUserProfile->password)
00445 {
00446 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userProfile, EL_PASSWORD);
00447 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00448 if (RET_OK == nRet)
00449 {
00450 nRet = ermXmlSetString(pXmlCxt, xpath, theUserProfile->password);
00451 }
00452 if (RET_ERR == nRet)
00453 {
00454 return FALSE;
00455 }
00456 }
00457
00458
00459 if (theUserProfile->redirectUrl)
00460 {
00461 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userProfile, EL_REDIRECT_URL);
00462 nRet == ermXmlCheckXpath(pXmlCxt, xpath);
00463 if (RET_OK == nRet)
00464 {
00465 nRet = ermXmlSetString(pXmlCxt, xpath, theUserProfile->redirectUrl);
00466 }
00467 if (RET_ERR == nRet)
00468 {
00469 return FALSE;
00470 }
00471 }
00472
00473 pRegistry->changed = TRUE;
00474 return TRUE;
00475 }
00476
00477 regUserSetting_t *regGetUserSetting(const regRegistry_t *pRegistry)
00478 {
00479 regUserSetting_t *theUserSetting = NULL;
00480
00481 ERREG_LOGPRINTF("entry");
00482 g_assert(pRegistry);
00483 g_assert(pRegistry->xpaths);
00484 g_assert(pRegistry->xpaths->userSetting);
00485
00486 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
00487 int nLen, nRet;
00488 gboolean bEnable;
00489
00490 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00491
00492 theUserSetting = g_new0(regUserSetting_t, 1);
00493 g_assert(theUserSetting != NULL);
00494
00495
00496 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userSetting, EL_LANGUAGE);
00497 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
00498 if (RET_ERR == nRet)
00499 {
00500 ERREG_ERRORPRINTF("Can't get language from memory.");
00501 regFreeUserSetting(theUserSetting);
00502 theUserSetting = NULL;
00503 return NULL;
00504 }
00505 theUserSetting->language = g_strdup(szTmp);
00506
00507
00508 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->userSetting, EL_SOUND, EL_ENABLE);
00509 nRet = ermXmlGetBoolean(pXmlCxt, xpath, &bEnable);
00510 if (RET_ERR == nRet)
00511 {
00512 ERREG_ERRORPRINTF("Can't get sound enable flag from memory.");
00513 regFreeUserSetting(theUserSetting);
00514 theUserSetting = NULL;
00515 return NULL;
00516 }
00517
00518 if (!bEnable)
00519 {
00520 theUserSetting->volume = 0;
00521 }
00522 else
00523 {
00524 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->userSetting, EL_SOUND, EL_VOLUME);
00525 nRet = ermXmlGetInt(pXmlCxt, xpath, &theUserSetting->volume);
00526 if (RET_ERR == nRet)
00527 {
00528 ERREG_ERRORPRINTF("Can't get sound volume from memory.");
00529 regFreeUserSetting(theUserSetting);
00530 theUserSetting = NULL;
00531 return NULL;
00532 }
00533 }
00534
00535
00536 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->userSetting, EL_KEY_BUFFERING, EL_ENABLE);
00537 nRet = ermXmlGetBoolean(pXmlCxt, xpath, &bEnable);
00538 if (RET_ERR == nRet)
00539 {
00540 ERREG_ERRORPRINTF("Can't get key buffering enable flag from memory.");
00541 regFreeUserSetting(theUserSetting);
00542 theUserSetting = NULL;
00543 return NULL;
00544 }
00545
00546 if (!bEnable)
00547 {
00548 theUserSetting->keyBuffering = 0;
00549 }
00550 else
00551 {
00552 nLen =
00553 g_snprintf(xpath, BUF_LEN, "%s/%s/%s",
00554 pRegistry->xpaths->userSetting, EL_KEY_BUFFERING, EL_NUMBER_OF_KEYS);
00555 nRet = ermXmlGetInt(pXmlCxt, xpath, &theUserSetting->keyBuffering);
00556 if (RET_ERR == nRet)
00557 {
00558 ERREG_ERRORPRINTF("Can't get the number of key buffering from memory.");
00559 regFreeUserSetting(theUserSetting);
00560 theUserSetting = NULL;
00561 return NULL;
00562 }
00563 }
00564
00565
00566 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userSetting, EL_LONG_KP_TIMEOUT);
00567 nRet = ermXmlGetInt(pXmlCxt, xpath, &theUserSetting->longkeypressTimeout);
00568 if (RET_ERR == nRet)
00569 {
00570 ERREG_ERRORPRINTF("Can't get long key press timeout from memory.");
00571 regFreeUserSetting(theUserSetting);
00572 theUserSetting = NULL;
00573 return NULL;
00574 }
00575
00576
00577 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userSetting, EL_FLIPBAR_DIRECTION);
00578 nRet = ermXmlGetBoolean(pXmlCxt, xpath, &theUserSetting->flipbarLeftIsDown);
00579 if (RET_ERR == nRet)
00580 {
00581 ERREG_ERRORPRINTF("Can't get flipbar direction from memory.");
00582 regFreeUserSetting(theUserSetting);
00583 theUserSetting = NULL;
00584 return NULL;
00585 }
00586
00587 regDumpUserSetting(theUserSetting);
00588 return theUserSetting;
00589 }
00590
00591 gboolean regSetUserSetting(const regUserSetting_t *theUserSetting, regRegistry_t *pRegistry)
00592 {
00593 ERREG_LOGPRINTF("entry %p %p", theUserSetting, pRegistry);
00594 g_assert(theUserSetting);
00595 g_assert(pRegistry);
00596 g_assert(pRegistry->xpaths);
00597 g_assert(pRegistry->xpaths->userSetting);
00598
00599 regDumpUserSetting(theUserSetting);
00600
00601 char xpath[BUF_LEN + 1];
00602 int nLen, nRet;
00603 gboolean bEnable;
00604
00605 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00606
00607
00608 if (theUserSetting->language)
00609 {
00610 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userSetting, EL_LANGUAGE);
00611 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00612 if (RET_OK == nRet)
00613 {
00614 nRet = ermXmlSetString(pXmlCxt, xpath, theUserSetting->language);
00615 }
00616 if (RET_ERR == nRet)
00617 {
00618 return FALSE;
00619 }
00620 }
00621
00622
00623 if (theUserSetting->volume)
00624 {
00625 bEnable = TRUE;
00626 }
00627 else
00628 {
00629 bEnable = FALSE;
00630 }
00631 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->userSetting, EL_SOUND, EL_ENABLE);
00632 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00633 if (RET_OK == nRet)
00634 {
00635 nRet = ermXmlSetBoolean(pXmlCxt, xpath, bEnable);
00636 }
00637 if (RET_ERR == nRet)
00638 {
00639 return FALSE;
00640 }
00641
00642 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->userSetting, EL_SOUND, EL_VOLUME);
00643 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00644 if (RET_OK == nRet)
00645 {
00646 nRet = ermXmlSetInt(pXmlCxt, xpath, theUserSetting->volume);
00647 }
00648 if (RET_ERR == nRet)
00649 {
00650 return FALSE;
00651 }
00652
00653
00654 if (theUserSetting->keyBuffering)
00655 {
00656 bEnable = TRUE;
00657 }
00658 else
00659 {
00660 bEnable = FALSE;
00661 }
00662 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->userSetting, EL_KEY_BUFFERING, EL_ENABLE);
00663 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00664 if (RET_OK == nRet)
00665 {
00666 nRet = ermXmlSetBoolean(pXmlCxt, xpath, bEnable);
00667 }
00668 if (RET_ERR == nRet)
00669 {
00670 return FALSE;
00671 }
00672
00673 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->userSetting,
00674 EL_KEY_BUFFERING, EL_NUMBER_OF_KEYS);
00675 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00676 if (RET_OK == nRet)
00677 {
00678 nRet = ermXmlSetInt(pXmlCxt, xpath, theUserSetting->keyBuffering);
00679 }
00680 if (RET_ERR == nRet)
00681 {
00682 return FALSE;
00683 }
00684
00685
00686 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userSetting, EL_LONG_KP_TIMEOUT);
00687 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00688 if (RET_OK == nRet)
00689 {
00690 nRet = ermXmlSetInt(pXmlCxt, xpath, theUserSetting->longkeypressTimeout);
00691 }
00692 if (RET_ERR == nRet)
00693 {
00694 return FALSE;
00695 }
00696
00697
00698 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->userSetting, EL_FLIPBAR_DIRECTION);
00699 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00700 if (RET_OK == nRet)
00701 {
00702 nRet = ermXmlSetBoolean(pXmlCxt, xpath, theUserSetting->flipbarLeftIsDown);
00703 }
00704 if (RET_ERR == nRet)
00705 {
00706 return FALSE;
00707 }
00708
00709 pRegistry->changed = TRUE;
00710 return TRUE;
00711 }
00712
00713 regPCConfig_t *regGetPCConfig(const regRegistry_t *pRegistry)
00714 {
00715 regPCConfig_t *thePCConfig = NULL;
00716
00717 ERREG_LOGPRINTF("entry %p", pRegistry);
00718 g_assert(pRegistry);
00719 g_assert(pRegistry->xpaths);
00720 g_assert(pRegistry->xpaths->pcProfile);
00721
00722 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
00723 int nLen, i, nProfiles, nRet;
00724
00725 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00726
00727
00728 nLen = g_snprintf(xpath, BUF_LEN, "%s", pRegistry->xpaths->pcProfile);
00729 nRet = ermXmlGetNodeNr(pXmlCxt, xpath, &nProfiles);
00730 if (RET_ERR == nRet || 0 == nProfiles)
00731 {
00732 ERREG_ERRORPRINTF("%s not present", xpath);
00733 return NULL;
00734 }
00735
00736
00737 thePCConfig = g_new0(regPCConfig_t, 1);
00738 g_assert(thePCConfig != NULL);
00739
00740 thePCConfig->size = nProfiles;
00741 thePCConfig->pcList = g_new0(char *, nProfiles + 1);
00742 thePCConfig->pcList[nProfiles] = NULL;
00743
00744
00745 for (i = 1; i <= nProfiles; i++)
00746 {
00747 nLen = g_snprintf(xpath, BUF_LEN, "%s[%d]", pRegistry->xpaths->pcProfile, i);
00748 nRet = ermXmlGetAttributeString(pXmlCxt, xpath, ATTR_PROFILE_ID, szTmp, BUF_LEN);
00749 if (RET_OK == nRet)
00750 {
00751 thePCConfig->pcList[i - 1] = g_strdup(szTmp);
00752 }
00753 }
00754
00755 regDumpPCConfig(thePCConfig);
00756 return thePCConfig;
00757 }
00758
00759 gboolean regSetPCConfig(const regPCConfig_t *thePCConfig, regRegistry_t *pRegistry)
00760 {
00761 ERREG_LOGPRINTF("entry %p %p", thePCConfig, pRegistry);
00762 g_assert(thePCConfig);
00763 g_assert(pRegistry);
00764 g_assert(pRegistry->xpaths);
00765 g_assert(pRegistry->xpaths->pcProfile);
00766
00767 regDumpPCConfig(thePCConfig);
00768
00769 char xpath[BUF_LEN + 1];
00770 int nLen, i, nProfiles, nRet;
00771
00772 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00773
00774 nProfiles = thePCConfig->size;
00775 for (i = 1; i <= nProfiles; i++)
00776 {
00777 nLen = g_snprintf(xpath, BUF_LEN, "%s[%d]", pRegistry->xpaths->pcProfile, i);
00778 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
00779 if (RET_OK == nRet)
00780 {
00781 nRet = ermXmlSetAttributeString(pXmlCxt, xpath, ATTR_PROFILE_ID,
00782 thePCConfig->pcList[i - 1], strlen(thePCConfig->pcList[i - 1]));
00783 }
00784 if (RET_ERR == nRet)
00785 {
00786 return FALSE;
00787 }
00788 }
00789
00790 pRegistry->changed = TRUE;
00791 return TRUE;
00792 }
00793
00794 regPCProfile_t *regGetPCProfile(const char *ID, const regRegistry_t *pRegistry)
00795 {
00796 regPCProfile_t *thePCProfile = NULL;
00797
00798 ERREG_LOGPRINTF("entry %s %p", ID, pRegistry);
00799 g_assert(ID);
00800 g_assert(pRegistry);
00801 g_assert(pRegistry->xpaths);
00802 g_assert(pRegistry->xpaths->pcProfile);
00803
00804 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
00805 int nLen, nRet;
00806
00807 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00808
00809 thePCProfile = g_new0(regPCProfile_t, 1);
00810 g_assert(thePCProfile != NULL);
00811
00812
00813 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->pcProfile, ATTR_PROFILE_ID, ID);
00814
00815
00816 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_PROFILE_NAME);
00817 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
00818 if (RET_ERR == nRet)
00819 {
00820 g_snprintf(szTmp, BUF_LEN, "%s", ID);
00821 }
00822 thePCProfile->name = g_strdup(szTmp);
00823
00824
00825 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_PC_NAME);
00826 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
00827 if (RET_ERR == nRet)
00828 {
00829 ERREG_ERRORPRINTF("Can't get pcname from memory.");
00830 regFreePCProfile(thePCProfile);
00831 thePCProfile = NULL;
00832 return NULL;
00833 }
00834 thePCProfile->pcname = g_strdup(szTmp);
00835
00836
00837 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_SHARE_NAME);
00838 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
00839 if (RET_ERR == nRet)
00840 {
00841 ERREG_ERRORPRINTF("Can't get sharename from memory.");
00842 regFreePCProfile(thePCProfile);
00843 thePCProfile = NULL;
00844 return NULL;
00845 }
00846 thePCProfile->sharename = g_strdup(szTmp);
00847
00848
00849 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_WORKGROUP);
00850 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
00851 if (RET_ERR == nRet)
00852 {
00853 ERREG_ERRORPRINTF("Can't get workgroup from memory.");
00854 regFreePCProfile(thePCProfile);
00855 thePCProfile = NULL;
00856 return NULL;
00857 }
00858 thePCProfile->workgroup = g_strdup(szTmp);
00859
00860
00861 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_USER_NAME);
00862 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
00863 if (RET_ERR == nRet)
00864 {
00865 ERREG_ERRORPRINTF("Can't get username from memory.");
00866 regFreePCProfile(thePCProfile);
00867 thePCProfile = NULL;
00868 return NULL;
00869 }
00870 thePCProfile->username = g_strdup(szTmp);
00871
00872
00873 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_PASSWORD);
00874 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
00875 if (RET_ERR == nRet)
00876 {
00877 ERREG_ERRORPRINTF("Can't get password from memory.");
00878 regFreePCProfile(thePCProfile);
00879 thePCProfile = NULL;
00880 return NULL;
00881 }
00882 thePCProfile->password = g_strdup(szTmp);
00883
00884 regDumpPCProfile(ID, thePCProfile);
00885 return thePCProfile;
00886 }
00887
00888 gboolean regSetPCProfile(const char *ID, const regPCProfile_t *thePCProfile, regRegistry_t *pRegistry)
00889 {
00890 ERREG_LOGPRINTF("entry %s %p %p", ID, thePCProfile, pRegistry);
00891 g_assert(ID);
00892 g_assert(thePCProfile);
00893 g_assert(pRegistry);
00894 g_assert(pRegistry->xpaths);
00895 g_assert(pRegistry->xpaths->pcProfile);
00896
00897 regDumpPCProfile(ID, thePCProfile);
00898
00899 char xpath[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
00900 int nLen, nRet;
00901
00902 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
00903
00904
00905 if ((thePCProfile->pcname == NULL) || (thePCProfile->sharename == NULL))
00906 {
00907 ERREG_WARNPRINTF("Some fields in thePCProfile shouldn't containis NULL.");
00908 return FALSE;
00909 }
00910
00911
00912 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->pcProfile, ATTR_PROFILE_ID, ID);
00913
00914
00915 if (thePCProfile->name)
00916 {
00917 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_PROFILE_NAME);
00918 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
00919 if (RET_OK == nRet)
00920 {
00921 nRet = ermXmlSetString(pXmlCxt, xpathExt, thePCProfile->name);
00922 }
00923 if (RET_ERR == nRet)
00924 {
00925 return FALSE;
00926 }
00927 }
00928
00929
00930 if (thePCProfile->pcname)
00931 {
00932 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_PC_NAME);
00933 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
00934 if (RET_OK == nRet)
00935 {
00936 nRet = ermXmlSetString(pXmlCxt, xpathExt, thePCProfile->pcname);
00937 }
00938 if (RET_ERR == nRet)
00939 {
00940 return FALSE;
00941 }
00942 }
00943
00944
00945 if (thePCProfile->sharename)
00946 {
00947 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_SHARE_NAME);
00948 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
00949 if (RET_OK == nRet)
00950 {
00951 nRet = ermXmlSetString(pXmlCxt, xpathExt, thePCProfile->sharename);
00952 }
00953 if (RET_ERR == nRet)
00954 {
00955 return FALSE;
00956 }
00957 }
00958
00959
00960 if (thePCProfile->workgroup)
00961 {
00962 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_WORKGROUP);
00963 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
00964 if (RET_OK == nRet)
00965 {
00966 nRet = ermXmlSetString(pXmlCxt, xpathExt, thePCProfile->workgroup);
00967 }
00968 if (RET_ERR == nRet)
00969 {
00970 return FALSE;
00971 }
00972 }
00973
00974
00975 if (thePCProfile->username)
00976 {
00977 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_USER_NAME);
00978 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
00979 if (RET_OK == nRet)
00980 {
00981 nRet = ermXmlSetString(pXmlCxt, xpathExt, thePCProfile->username);
00982 }
00983 if (RET_ERR == nRet)
00984 {
00985 return FALSE;
00986 }
00987 }
00988
00989
00990 if (thePCProfile->password)
00991 {
00992 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_PASSWORD);
00993 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
00994 if (RET_OK == nRet)
00995 {
00996 nRet = ermXmlSetString(pXmlCxt, xpathExt, thePCProfile->password);
00997 }
00998 if (RET_ERR == nRet)
00999 {
01000 return FALSE;
01001 }
01002 }
01003
01004 pRegistry->changed = TRUE;
01005 return TRUE;
01006 }
01007
01008 gboolean regRemovePCProfile(const char *ID, regRegistry_t *pRegistry)
01009 {
01010 ERREG_LOGPRINTF("entry %s %p", ID, pRegistry);
01011 g_assert(ID);
01012 g_assert(pRegistry);
01013 g_assert(pRegistry->xpaths);
01014 g_assert(pRegistry->xpaths->pcProfile);
01015
01016 char xpath[BUF_LEN + 1];
01017 int nLen, nRet;
01018
01019 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01020
01021
01022 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->pcProfile, ATTR_PROFILE_ID, ID);
01023 nRet = ermXmlRemoveNode(pXmlCxt, xpath);
01024 if (RET_ERR == nRet)
01025 {
01026 return FALSE;
01027 }
01028
01029 return TRUE;
01030 }
01031
01032 gboolean regRemovePCConfig(regRegistry_t *pRegistry)
01033 {
01034 ERREG_LOGPRINTF("entry %p", pRegistry);
01035 g_assert(pRegistry);
01036 g_assert(pRegistry->xpaths);
01037 g_assert(pRegistry->xpaths->pcProfiles);
01038
01039 char xpath[BUF_LEN + 1];
01040 int nLen, nRet;
01041
01042 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01043
01044
01045 nLen = g_snprintf(xpath, BUF_LEN, "%s", pRegistry->xpaths->pcProfiles);
01046 nRet = ermXmlRemoveNode(pXmlCxt, xpath);
01047 if (RET_ERR == nRet)
01048 {
01049 return FALSE;
01050 }
01051
01052 return TRUE;
01053 }
01054
01055 void regGetPCProfiles(regPCConfig_t **pPCConfig, regPCProfile_t ***pPCs, const regRegistry_t* pRegistry)
01056 {
01057 int i;
01058 regPCConfig_t *thePCConfig = NULL;
01059 regPCProfile_t **thePCs = NULL;
01060
01061 ERREG_LOGPRINTF("entry");
01062 g_assert(pPCConfig);
01063 g_assert(pPCs);
01064 g_assert(pRegistry);
01065
01066
01067 regFreePCProfiles(*pPCConfig, *pPCs);
01068 *pPCConfig = NULL;
01069 *pPCs = NULL;
01070
01071
01072 thePCConfig = regGetPCConfig(pRegistry);
01073 if (thePCConfig == NULL)
01074 {
01075 ERREG_WARNPRINTF("thePCConfig not present");
01076 }
01077 else
01078 {
01079 ERREG_LOGPRINTF("thePCConfig exist");
01080
01081 thePCs = g_new0(regPCProfile_t *, thePCConfig->size);
01082 for (i = 0; i < thePCConfig->size; i++)
01083 {
01084
01085 thePCs[i] = regGetPCProfile(thePCConfig->pcList[i], pRegistry);
01086 ERREG_LOGPRINTF("thePCs[%d] = [%p]", i, thePCs[i]);
01087 }
01088 }
01089
01090 *pPCConfig = thePCConfig;
01091 *pPCs = thePCs;
01092 }
01093
01094 gboolean regSetPCProfiles(const regPCConfig_t *thePCConfig, const regPCProfile_t **thePCs, regRegistry_t* pRegistry)
01095 {
01096 ERREG_LOGPRINTF("entry");
01097 g_assert(thePCConfig);
01098 g_assert(thePCs);
01099 g_assert(pRegistry);
01100
01101 gboolean bRet = TRUE;
01102 gboolean b;
01103 int i;
01104
01105
01106 regRemovePCConfig(pRegistry);
01107
01108
01109 regSetPCConfig(thePCConfig, pRegistry);
01110 for (i = 0; i < thePCConfig->size; i++)
01111 {
01112 b = regSetPCProfile(thePCConfig->pcList[i], thePCs[i], pRegistry);
01113 if (FALSE == b)
01114 {
01115 bRet = FALSE;
01116 }
01117 }
01118
01119 if (bRet)
01120 {
01121 pRegistry->changed = TRUE;
01122 }
01123 return bRet;
01124 }
01125
01126 regAutoConnect_t *regGetAutoConnect(const regRegistry_t *pRegistry)
01127 {
01128 regAutoConnect_t *theAutoConnect = NULL;
01129
01130 ERREG_LOGPRINTF("entry %p", pRegistry);
01131 g_assert(pRegistry);
01132 g_assert(pRegistry->xpaths);
01133 g_assert(pRegistry->xpaths->autoConnect);
01134
01135 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
01136 int nLen, nRet;
01137
01138 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01139
01140 theAutoConnect = g_new0(regAutoConnect_t, 1);
01141 g_assert(theAutoConnect != NULL);
01142
01143
01144 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->autoConnect, EL_SERVER_TYPE);
01145 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
01146 if (RET_ERR == nRet)
01147 {
01148 ERREG_ERRORPRINTF("Can't get which server to connect from memory.");
01149 regFreeAutoConnect(theAutoConnect);
01150 theAutoConnect = NULL;
01151 return NULL;
01152 }
01153 theAutoConnect->backgroundConnectTo = regServerTypeToEnum(szTmp);
01154
01155
01156 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_BACKGOUND, EL_ENABLE);
01157 nRet = ermXmlGetBoolean(pXmlCxt, xpath, &theAutoConnect->backgroundEnable);
01158 if (RET_ERR == nRet)
01159 {
01160 ERREG_ERRORPRINTF("Can't get background enable flag from memory.");
01161 regFreeAutoConnect(theAutoConnect);
01162 theAutoConnect = NULL;
01163 return NULL;
01164 }
01165
01166
01167 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_BACKGOUND, EL_INTERVAL);
01168 nRet = ermXmlGetInt(pXmlCxt, xpath, &theAutoConnect->backgroundInterval);
01169 if (RET_ERR == nRet)
01170 {
01171 ERREG_ERRORPRINTF("Can't get background interval from memory.");
01172 regFreeAutoConnect(theAutoConnect);
01173 theAutoConnect = NULL;
01174 return NULL;
01175 }
01176
01177 regDumpAutoConnect(theAutoConnect);
01178 return theAutoConnect;
01179 }
01180
01181 gboolean regSetAutoConnect(const regAutoConnect_t *theAutoConnect, regRegistry_t *pRegistry)
01182 {
01183 ERREG_LOGPRINTF("entry %p %p", theAutoConnect, pRegistry);
01184 g_assert(theAutoConnect);
01185 g_assert(pRegistry);
01186 g_assert(pRegistry->xpaths);
01187 g_assert(pRegistry->xpaths->autoConnect);
01188
01189 regDumpAutoConnect(theAutoConnect);
01190
01191 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
01192 int nLen, nRet;
01193
01194 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01195
01196
01197 regServerTypeToString(theAutoConnect->backgroundConnectTo, szTmp, BUF_LEN);
01198 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->autoConnect, EL_SERVER_TYPE);
01199 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
01200 if (RET_OK == nRet)
01201 {
01202 nRet = ermXmlSetString(pXmlCxt, xpath, szTmp);
01203 }
01204 if (RET_ERR == nRet)
01205 {
01206 return FALSE;
01207 }
01208
01209
01210 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_BACKGOUND, EL_ENABLE);
01211 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
01212 if (RET_OK == nRet)
01213 {
01214 nRet = ermXmlSetBoolean(pXmlCxt, xpath, theAutoConnect->backgroundEnable);
01215 }
01216 if (RET_ERR == nRet)
01217 {
01218 return FALSE;
01219 }
01220
01221
01222 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_BACKGOUND, EL_INTERVAL);
01223 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
01224 if (RET_OK == nRet)
01225 {
01226 nRet = ermXmlSetInt(pXmlCxt, xpath, theAutoConnect->backgroundInterval);
01227 }
01228 if (RET_ERR == nRet)
01229 {
01230 return FALSE;
01231 }
01232
01233 pRegistry->changed = TRUE;
01234 return TRUE;
01235 }
01236
01237 static int lt(const void *l, const void *r)
01238 {
01239 return *(int *)l - *(int *)r;
01240 }
01241
01242
01243 static int rmDup(int arr[], int* pSize)
01244 {
01245 int i, tmpArr[*pSize];
01246 int nLastStored = -1;
01247 int pos = 0;
01248
01249 for (i=0; i<*pSize; i++)
01250 {
01251 if (arr[i] != nLastStored)
01252 {
01253 tmpArr[pos++] = arr[i];
01254 nLastStored = arr[i];
01255 }
01256 }
01257
01258 memcpy(arr, tmpArr, sizeof(int)*pos);
01259 return (*pSize = pos);
01260 }
01261
01262 regTimedIds_t *regGetTimedIds(const regRegistry_t *pRegistry)
01263 {
01264 regTimedIds_t *theTimedIds = NULL;
01265
01266 ERREG_LOGPRINTF("entry %p", pRegistry);
01267 g_assert(pRegistry);
01268 g_assert(pRegistry->xpaths);
01269 g_assert(pRegistry->xpaths->autoConnect);
01270
01271 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
01272 int nRet;
01273
01274 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01275
01276 theTimedIds = g_new0(regTimedIds_t, 1);
01277 g_assert(theTimedIds != NULL);
01278
01279
01280 g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_ENABLE_TIMEDIDS);
01281 nRet = ermXmlGetBoolean(pXmlCxt, xpath, &theTimedIds->enable);
01282 if (nRet == RET_ERR)
01283 {
01284 regFreeTimedIds(theTimedIds);
01285 return NULL;
01286 }
01287
01288
01289 g_snprintf(xpath, BUF_LEN, "%s/%s/%s/%s", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_TIMESET, EL_TIME);
01290 nRet = ermXmlGetNodeNr(pXmlCxt, xpath, &theTimedIds->timeCnt);
01291 if (nRet == RET_ERR)
01292 {
01293 regFreeTimedIds(theTimedIds);
01294 return NULL;
01295 }
01296
01297
01298 int i, hh, mm, ss;
01299 for (i=1; i<=theTimedIds->timeCnt; i++)
01300 {
01301 g_snprintf(xpath, BUF_LEN, "%s/%s/%s/%s[%d]", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_TIMESET, EL_TIME, i);
01302 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
01303
01304 if (RET_ERR == nRet)
01305 {
01306 regFreeTimedIds(theTimedIds);
01307 return NULL;
01308 }
01309
01310 sscanf(szTmp, "%02d:%02d:%02d", &hh, &mm, &ss);
01311 theTimedIds->timeSet[i-1] = hh*3600 + mm*60 + ss;
01312 }
01313
01314
01315 g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_ENABLE_SWUPDATE);
01316 nRet = ermXmlGetBoolean(pXmlCxt, xpath, &theTimedIds->swUpdate);
01317 if (nRet == RET_ERR)
01318 {
01319 regFreeTimedIds(theTimedIds);
01320 return NULL;
01321 }
01322
01323
01324 g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_ENABLE_SWITCHOFF);
01325 nRet = ermXmlGetBoolean(pXmlCxt, xpath, &theTimedIds->switchOff);
01326 if (nRet == RET_ERR)
01327 {
01328 regFreeTimedIds(theTimedIds);
01329 return NULL;
01330 }
01331
01332 regDumpTimedIds(theTimedIds);
01333 return theTimedIds;
01334 }
01335
01336 gboolean regRemoveTimeSet(regRegistry_t *pRegistry)
01337 {
01338 ERREG_LOGPRINTF("entry %p", pRegistry);
01339 g_assert(pRegistry);
01340 g_assert(pRegistry->xpaths);
01341 g_assert(pRegistry->xpaths->autoConnect);
01342
01343 char xpath[BUF_LEN + 1];
01344
01345 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01346
01347
01348 g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_TIMESET);
01349 if (ermXmlRemoveNode(pXmlCxt, xpath) == RET_ERR)
01350 {
01351 return FALSE;
01352 }
01353
01354 return TRUE;
01355 }
01356
01357 gboolean regSetTimedIds(regTimedIds_t *theTimedIds, regRegistry_t *pRegistry)
01358 {
01359 ERREG_LOGPRINTF("entry %p %p", theTimedIds, pRegistry);
01360 g_assert(theTimedIds);
01361 g_assert(pRegistry);
01362 g_assert(pRegistry->xpaths);
01363 g_assert(pRegistry->xpaths->autoConnect);
01364
01365 regDumpTimedIds(theTimedIds);
01366
01367 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
01368
01369 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01370
01371
01372 g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_ENABLE_TIMEDIDS);
01373 if (RET_ERR == ermXmlCheckXpath(pXmlCxt, xpath))
01374 {
01375 return FALSE;
01376 }
01377 if (RET_ERR == ermXmlSetBoolean(pXmlCxt, xpath, theTimedIds->enable))
01378 {
01379 return FALSE;
01380 }
01381
01382
01383
01384 qsort(theTimedIds->timeSet, theTimedIds->timeCnt, sizeof(int), lt);
01385
01386 rmDup(theTimedIds->timeSet, &theTimedIds->timeCnt);
01387
01388
01389 regRemoveTimeSet(pRegistry);
01390
01391 int i, hh, mm, ss;
01392 for (i=0; i<theTimedIds->timeCnt; i++)
01393 {
01394 g_snprintf(xpath, BUF_LEN, "%s/%s/%s/%s[%d]", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_TIMESET, EL_TIME, i+1);
01395
01396 if (RET_ERR == ermXmlCheckXpath(pXmlCxt, xpath))
01397 {
01398 return FALSE;
01399 }
01400
01401 hh = theTimedIds->timeSet[i] / 3600;
01402 mm = theTimedIds->timeSet[i] / 60 % 60;
01403 ss = theTimedIds->timeSet[i] % 60;
01404 snprintf(szTmp, BUF_LEN, "%02d:%02d:%02d", hh, mm, ss);
01405
01406 if (RET_ERR == ermXmlSetString(pXmlCxt, xpath, szTmp))
01407 {
01408 return FALSE;
01409 }
01410 }
01411
01412
01413 g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_ENABLE_SWUPDATE);
01414 if (RET_ERR == ermXmlCheckXpath(pXmlCxt, xpath))
01415 {
01416 return FALSE;
01417 }
01418 if (RET_ERR == ermXmlSetBoolean(pXmlCxt, xpath, theTimedIds->swUpdate))
01419 {
01420 return FALSE;
01421 }
01422
01423
01424 g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->autoConnect, EL_TIMED_IDS, EL_ENABLE_SWITCHOFF);
01425 if (RET_ERR == ermXmlCheckXpath(pXmlCxt, xpath))
01426 {
01427 return FALSE;
01428 }
01429 if (RET_ERR == ermXmlSetBoolean(pXmlCxt, xpath, theTimedIds->switchOff))
01430 {
01431 return FALSE;
01432 }
01433
01434 pRegistry->changed = TRUE;
01435 return TRUE;
01436 }
01437
01438 regContentCategory_t *regGetContentCategory(const char *ID, const regRegistry_t *pRegistry)
01439 {
01440 regContentCategory_t *theContentCategory = NULL;
01441
01442 ERREG_LOGPRINTF("entry: ID [%s] pRegistry [%p]", ID, pRegistry);
01443 g_assert(ID);
01444 g_assert(pRegistry);
01445 g_assert(pRegistry->xpaths);
01446 g_assert(pRegistry->xpaths->category);
01447
01448 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
01449 int nLen, nRet;
01450
01451 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01452
01453 theContentCategory = g_new0(regContentCategory_t, 1);
01454 g_assert(theContentCategory != NULL);
01455
01456 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->category, ATTR_TYPE, ID);
01457
01458
01459 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_LOCATION);
01460 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01461 if (RET_ERR == nRet)
01462 {
01463 ERREG_ERRORPRINTF("Can't get category from memory, xpath [%s]", xpath);
01464 regFreeContentCategory(theContentCategory);
01465 theContentCategory = NULL;
01466 return NULL;
01467 }
01468 theContentCategory->location = g_strdup(szTmp);
01469
01470
01471 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s/%s", xpath, EL_SORT, EL_SORT_ASCENDING);
01472 nRet = ermXmlGetBoolean(pXmlCxt, xpathExt, &theContentCategory->sortAscending);
01473 if (RET_ERR == nRet)
01474 {
01475 ERREG_ERRORPRINTF("Can't get sort from memory, xpath [%s]", xpath);
01476 regFreeContentCategory(theContentCategory);
01477 theContentCategory = NULL;
01478 return NULL;
01479 }
01480
01481 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s/%s", xpath, EL_SORT, EL_SORT_FIELD_TYPE);
01482 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01483 if (RET_ERR == nRet)
01484 {
01485 ERREG_ERRORPRINTF("Can't get sort field from memory, xpath [%s]", xpath);
01486 regFreeContentCategory(theContentCategory);
01487 theContentCategory = NULL;
01488 return NULL;
01489 }
01490 theContentCategory->sortFieldType = g_strdup(szTmp);
01491
01492 regDumpContentCategory(ID, theContentCategory);
01493 ERREG_LOGPRINTF("leave: theContentCategory [%p]", theContentCategory);
01494 return theContentCategory;
01495 }
01496
01497 gboolean regSetContentCategory(const char *ID, const regContentCategory_t *theContentCategory, regRegistry_t *pRegistry)
01498 {
01499 ERREG_LOGPRINTF("%s %p %p", ID, theContentCategory, pRegistry);
01500 g_assert(ID);
01501 g_assert(theContentCategory);
01502 g_assert(pRegistry);
01503 g_assert(pRegistry->xpaths);
01504 g_assert(pRegistry->xpaths->category);
01505
01506 regDumpContentCategory(ID, theContentCategory);
01507
01508 char xpath[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
01509 int nLen, nRet;
01510
01511 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01512
01513 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->category, ATTR_TYPE, ID);
01514
01515 if (theContentCategory->location)
01516 {
01517 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_LOCATION);
01518 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01519 if (RET_OK == nRet)
01520 {
01521 nRet = ermXmlSetString(pXmlCxt, xpathExt, theContentCategory->location);
01522 }
01523 if (RET_ERR == nRet)
01524 {
01525 return FALSE;
01526 }
01527 }
01528
01529 if (theContentCategory->sortFieldType)
01530 {
01531 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s/%s", xpath, EL_SORT, EL_SORT_FIELD_TYPE);
01532 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01533 if (RET_OK == nRet)
01534 {
01535 nRet = ermXmlSetString(pXmlCxt, xpathExt, theContentCategory->sortFieldType);
01536 }
01537 if (RET_ERR == nRet)
01538 {
01539 return FALSE;
01540 }
01541 }
01542
01543 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s/%s", xpath, EL_SORT, EL_SORT_ASCENDING);
01544 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01545 if (RET_OK == nRet)
01546 {
01547 nRet = ermXmlSetBoolean(pXmlCxt, xpathExt, theContentCategory->sortAscending);
01548 }
01549 if (RET_ERR == nRet)
01550 {
01551 return FALSE;
01552 }
01553
01554 pRegistry->changed = TRUE;
01555 return TRUE;
01556 }
01557
01558 regExportMemType_t *regGetExportMemType(const regRegistry_t *pRegistry)
01559 {
01560 regExportMemType_t *theExportMemType = NULL;
01561
01562 ERREG_LOGPRINTF("entry %p", pRegistry);
01563 g_assert(pRegistry);
01564 g_assert(pRegistry->xpaths);
01565 g_assert(pRegistry->xpaths->usbExport);
01566
01567 char szTmp[BUF_LEN + 1];
01568 int nRet;
01569
01570 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01571
01572 theExportMemType = g_new0(regExportMemType_t, 1);
01573 g_assert(theExportMemType != NULL);
01574
01575
01576 nRet = ermXmlGetString(pXmlCxt, pRegistry->xpaths->usbExport, szTmp, BUF_LEN);
01577 if (nRet == RET_ERR)
01578 {
01579 regFreeExportMemType(theExportMemType);
01580 return NULL;
01581 }
01582
01583 theExportMemType->location = g_strdup(szTmp);
01584 return theExportMemType;
01585 }
01586
01587 gboolean regSetExportMemType(const regExportMemType_t *theExportMemType, regRegistry_t *pRegistry)
01588 {
01589 ERREG_LOGPRINTF("%p %p", theExportMemType, pRegistry);
01590 g_assert(theExportMemType);
01591 g_assert(pRegistry);
01592 g_assert(pRegistry->xpaths);
01593 g_assert(pRegistry->xpaths->usbExport);
01594 g_assert(theExportMemType);
01595 g_assert(theExportMemType->location);
01596
01597 regDumpExportMemType(theExportMemType);
01598
01599 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01600
01601 if (RET_ERR == ermXmlCheckXpath(pXmlCxt, pRegistry->xpaths->usbExport))
01602 {
01603 return FALSE;
01604 }
01605 if (RET_ERR == ermXmlSetString(pXmlCxt, pRegistry->xpaths->usbExport, theExportMemType->location))
01606 {
01607 return FALSE;
01608 }
01609
01610 pRegistry->changed = TRUE;
01611 return TRUE;
01612 }
01613
01614 regLastRead_t *regGetLastRead(const char *ID, regRegistry_t *pRegistry)
01615 {
01616 regLastRead_t *theLastRead = NULL;
01617
01618 ERREG_LOGPRINTF("entry %s %p", ID, pRegistry);
01619 g_assert(ID);
01620 g_assert(pRegistry);
01621 g_assert(pRegistry->xpaths);
01622 g_assert(pRegistry->xpaths->lastRead);
01623
01624 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
01625 int nLen, nRet;
01626
01627 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01628
01629 theLastRead = g_new0(regLastRead_t, 1);
01630 g_assert(theLastRead != NULL);
01631
01632 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->lastRead, ATTR_TYPE, ID);
01633
01634
01635 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_EXT_NAME);
01636 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01637 if (RET_ERR == nRet)
01638 {
01639 ERREG_ERRORPRINTF("Can't get extension from memory.");
01640 regFreeLastRead(theLastRead);
01641 theLastRead = NULL;
01642 return NULL;
01643 }
01644 theLastRead->extension = g_strdup(szTmp);
01645
01646
01647 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_DOCUMENT_PATH);
01648 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01649 if (RET_ERR == nRet)
01650 {
01651 ERREG_ERRORPRINTF("Can't get documentPath from memory.");
01652 regFreeLastRead(theLastRead);
01653 theLastRead = NULL;
01654 return NULL;
01655 }
01656 theLastRead->documentPath = g_strdup(szTmp);
01657
01658
01659 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_MANIFEST_PATH);
01660 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01661 if (RET_ERR == nRet)
01662 {
01663 ERREG_ERRORPRINTF("Can't get manifestPath from memory.");
01664 regFreeLastRead(theLastRead);
01665 theLastRead = NULL;
01666 return NULL;
01667 }
01668 theLastRead->manifestPath = g_strdup(szTmp);
01669
01670
01671 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_POSITION);
01672 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01673 if (RET_ERR == nRet)
01674 {
01675 ERREG_ERRORPRINTF("Can't get position from memory.");
01676 regFreeLastRead(theLastRead);
01677 theLastRead = NULL;
01678 return NULL;
01679 }
01680 theLastRead->position = g_strdup(szTmp);
01681
01682 regDumpLastRead(ID, theLastRead);
01683 return theLastRead;
01684 }
01685
01686 gboolean regSetLastRead(const char *ID, const regLastRead_t *theLastRead, regRegistry_t *pRegistry)
01687 {
01688 ERREG_LOGPRINTF("entry %s %p %p", ID, theLastRead, pRegistry);
01689 g_assert(ID);
01690 g_assert(theLastRead);
01691 g_assert(pRegistry);
01692 g_assert(pRegistry->xpaths);
01693 g_assert(pRegistry->xpaths->lastRead);
01694
01695 regDumpLastRead(ID, theLastRead);
01696
01697 char xpath[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
01698 int nLen, nRet;
01699
01700 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01701
01702 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->lastRead, ATTR_TYPE, ID);
01703
01704 if (theLastRead->extension)
01705 {
01706 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_EXT_NAME);
01707 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01708 if (RET_OK == nRet)
01709 {
01710 nRet = ermXmlSetString(pXmlCxt, xpathExt, theLastRead->extension);
01711 }
01712 if (RET_ERR == nRet)
01713 {
01714 return FALSE;
01715 }
01716 }
01717
01718 if (theLastRead->documentPath)
01719 {
01720 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_DOCUMENT_PATH);
01721 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01722 if (RET_OK == nRet)
01723 {
01724 nRet = ermXmlSetString(pXmlCxt, xpathExt, theLastRead->documentPath);
01725 }
01726 if (RET_ERR == nRet)
01727 {
01728 return FALSE;
01729 }
01730 }
01731
01732 if (theLastRead->manifestPath)
01733 {
01734 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_MANIFEST_PATH);
01735 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01736 if (RET_OK == nRet)
01737 {
01738 nRet = ermXmlSetString(pXmlCxt, xpathExt, theLastRead->manifestPath);
01739 }
01740 if (RET_ERR == nRet)
01741 {
01742 return FALSE;
01743 }
01744 }
01745
01746 if (theLastRead->position)
01747 {
01748 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_POSITION);
01749 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01750 if (RET_OK == nRet)
01751 {
01752 nRet = ermXmlSetString(pXmlCxt, xpathExt, theLastRead->position);
01753 }
01754 if (RET_ERR == nRet)
01755 {
01756 return FALSE;
01757 }
01758 }
01759
01760 pRegistry->changed = TRUE;
01761 return TRUE;
01762 }
01763
01764 regUserAppList_t *regGetUserAppList(const regRegistry_t *pRegistry)
01765 {
01766 regUserAppList_t *theUserAppList = NULL;
01767
01768 ERREG_LOGPRINTF("entry %p", pRegistry);
01769 g_assert(pRegistry);
01770 g_assert(pRegistry->xpaths);
01771 g_assert(pRegistry->xpaths->application);
01772
01773 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
01774 int nLen, i, nApp, nRet;
01775
01776 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01777
01778
01779 nLen = g_snprintf(xpath, BUF_LEN, "%s", pRegistry->xpaths->application);
01780 nRet = ermXmlGetNodeNr(pXmlCxt, xpath, &nApp);
01781 if (RET_ERR == nRet || 0 == nApp)
01782 {
01783 ERREG_ERRORPRINTF("%s not present", xpath);
01784 return NULL;
01785 }
01786
01787
01788 theUserAppList = g_new0(regUserAppList_t, 1);
01789 theUserAppList->uaIDArraySize = nApp;
01790 theUserAppList->uaIDArray = g_new0(char *, nApp + 1);
01791 theUserAppList->uaIDArray[nApp] = NULL;
01792
01793
01794 for (i = 1; i <= nApp; i++)
01795 {
01796 nLen = g_snprintf(xpath, BUF_LEN, "%s[%d]", pRegistry->xpaths->application, i);
01797 nRet = ermXmlGetAttributeString(pXmlCxt, xpath, ATTR_TYPE, szTmp, BUF_LEN);
01798 if (RET_OK == nRet)
01799 {
01800 theUserAppList->uaIDArray[i - 1] = g_strdup(szTmp);
01801 }
01802 }
01803
01804 regDumpUserAppList(theUserAppList);
01805 return theUserAppList;
01806 }
01807
01808 regUserApp_t *regGetUserApp(const char *uaID, const regRegistry_t *pRegistry)
01809 {
01810 regUserApp_t *theUserApp = NULL;
01811
01812 ERREG_LOGPRINTF("entry %s %p", uaID, pRegistry);
01813 g_assert(uaID);
01814 g_assert(pRegistry);
01815 g_assert(pRegistry->xpaths);
01816 g_assert(pRegistry->xpaths->application);
01817
01818 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
01819 int nLen, nRet, nFormat;
01820
01821 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01822
01823 theUserApp = g_new0(regUserApp_t, 1);
01824 g_assert(theUserApp != NULL);
01825
01826 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->application, ATTR_TYPE, uaID);
01827
01828
01829 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_APP_CATEGORY);
01830 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01831 if (RET_ERR == nRet)
01832 {
01833 ERREG_ERRORPRINTF("%s not present", xpathExt);
01834 regFreeUserApp(theUserApp);
01835 return NULL;
01836 }
01837 theUserApp->szCategory = g_strdup(szTmp);
01838
01839
01840 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_ARG_MASK);
01841 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01842 if (RET_ERR == nRet)
01843 {
01844 ERREG_ERRORPRINTF("%s not present", xpathExt);
01845 regFreeUserApp(theUserApp);
01846 return NULL;
01847 }
01848 theUserApp->szArgMask = g_strdup(szTmp);
01849
01850
01851 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_EXECUTE);
01852 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01853 if (RET_ERR == nRet)
01854 {
01855 ERREG_ERRORPRINTF("%s not present", xpathExt);
01856 regFreeUserApp(theUserApp);
01857 return NULL;
01858 }
01859 theUserApp->szExec = g_strdup(szTmp);
01860
01861
01862 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_X_RES_NAME);
01863 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01864 if (RET_ERR == nRet)
01865 {
01866 ERREG_ERRORPRINTF("%s not present", xpathExt);
01867 regFreeUserApp(theUserApp);
01868 return NULL;
01869 }
01870 theUserApp->xResName = g_strdup(szTmp);
01871
01872
01873 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_IPC_CHANNEL);
01874 nRet = ermXmlGetInt(pXmlCxt, xpathExt, &(theUserApp->ipcChannel));
01875 if (RET_ERR == nRet)
01876 {
01877 ERREG_ERRORPRINTF("%s not present", xpathExt);
01878 regFreeUserApp(theUserApp);
01879 return NULL;
01880 }
01881
01882
01883 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_APP_ICON_PATH);
01884 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01885 if (RET_ERR == nRet)
01886 {
01887 ERREG_WARNPRINTF("%s not present", xpathExt);
01888 theUserApp->appIconPath = g_strdup(szTmp);
01889 }
01890
01891
01892 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s/%s", xpath, EL_SUPPORT_FORMAT, EL_EXT_NAME);
01893 nRet = ermXmlGetNodeNr(pXmlCxt, xpathExt, &nFormat);
01894 if ((RET_OK == nRet) && nFormat)
01895 {
01896 int i;
01897
01898 theUserApp->extensionArray = g_new0(char *, nFormat + 1);
01899 theUserApp->extensionArray[nFormat] = NULL;
01900 theUserApp->extensionArraySize = nFormat;
01901
01902 for (i = 1; i <= nFormat; i++)
01903 {
01904 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s/%s[%d]", xpath, EL_SUPPORT_FORMAT, EL_EXT_NAME, i);
01905 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
01906 if (RET_OK == nRet)
01907 {
01908 theUserApp->extensionArray[i - 1] = g_strdup(szTmp);
01909 }
01910 }
01911 }
01912
01913 regDumpUserApp(uaID, theUserApp);
01914 return theUserApp;
01915 }
01916
01917 gboolean regSetUserApp(const char *uaID, const regUserApp_t *theUserApp, regRegistry_t *pRegistry)
01918 {
01919 ERREG_LOGPRINTF("entry %s %p %p", uaID, theUserApp, pRegistry);
01920 g_assert(uaID);
01921 g_assert(theUserApp);
01922 g_assert(pRegistry);
01923 g_assert(pRegistry->xpaths);
01924 g_assert(pRegistry->xpaths->application);
01925
01926 regDumpUserApp(uaID, theUserApp);
01927
01928 char xpath[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
01929 int nLen, nRet;
01930
01931 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
01932
01933 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->application, ATTR_TYPE, uaID);
01934
01935
01936 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_APP_CATEGORY);
01937 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01938 if (RET_OK == nRet)
01939 {
01940 nRet = ermXmlSetString(pXmlCxt, xpathExt, theUserApp->szCategory);
01941 }
01942 if (RET_ERR == nRet)
01943 {
01944 return FALSE;
01945 }
01946
01947
01948 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_ARG_MASK);
01949 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01950 if (RET_OK == nRet)
01951 {
01952 nRet = ermXmlSetString(pXmlCxt, xpathExt, theUserApp->szArgMask);
01953 }
01954 if (RET_ERR == nRet)
01955 {
01956 return FALSE;
01957 }
01958
01959
01960 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_EXECUTE);
01961 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01962 if (RET_OK == nRet)
01963 {
01964 nRet = ermXmlSetString(pXmlCxt, xpathExt, theUserApp->szExec);
01965 }
01966 if (RET_ERR == nRet)
01967 {
01968 return FALSE;
01969 }
01970
01971
01972 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_X_RES_NAME);
01973 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01974 if (RET_OK == nRet)
01975 {
01976 nRet = ermXmlSetString(pXmlCxt, xpathExt, theUserApp->xResName);
01977 }
01978 if (RET_ERR == nRet)
01979 {
01980 return FALSE;
01981 }
01982
01983
01984 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_IPC_CHANNEL);
01985 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01986 if (RET_OK == nRet)
01987 {
01988 nRet = ermXmlSetInt(pXmlCxt, xpathExt, theUserApp->ipcChannel);
01989 }
01990 if (RET_ERR == nRet)
01991 {
01992 return FALSE;
01993 }
01994
01995 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_APP_ICON_PATH);
01996 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
01997 if (RET_OK == nRet)
01998 {
01999 nRet = ermXmlSetString(pXmlCxt, xpathExt, theUserApp->appIconPath);
02000 }
02001 if (RET_ERR == nRet)
02002 {
02003 return FALSE;
02004 }
02005
02006
02007 if (theUserApp->extensionArray && theUserApp->extensionArraySize)
02008 {
02009 int i;
02010
02011 for (i = 1; i <= theUserApp->extensionArraySize; i++)
02012 {
02013 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s/%s[%d]", xpath, EL_SUPPORT_FORMAT, EL_EXT_NAME, i);
02014 if (theUserApp->extensionArray[i - 1])
02015 {
02016 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
02017 if (RET_OK == nRet)
02018 {
02019 nRet = ermXmlSetString(pXmlCxt, xpathExt, theUserApp->extensionArray[i - 1]);
02020 }
02021 if (RET_ERR == nRet)
02022 {
02023 return FALSE;
02024 }
02025 }
02026 }
02027 }
02028
02029 pRegistry->changed = TRUE;
02030 return TRUE;
02031 }
02032
02039 regExtInfoList_t *regGetExtInfoList(const char *extension, const regRegistry_t * pRegistry)
02040 {
02041 regExtInfoList_t *theExtInfoList = NULL;
02042 xmlXPathObjectPtr xpathObj = NULL;
02043 xmlNodePtr* p_node = NULL;
02044 xmlNodeSetPtr extensionNodes = NULL;
02045
02046
02047 ERREG_LOGPRINTF("entry %p", pRegistry);
02048 g_assert(pRegistry);
02049 g_assert(pRegistry->xpaths);
02050 g_assert(pRegistry->xpaths->extensionInfos);
02051
02052 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02053
02054
02055 char xpath[BUF_LEN + 1] = {0};
02056 if (extension)
02057 {
02058 g_snprintf(xpath, BUF_LEN, "%s/%s[%s=\"%s\"]",
02059 pRegistry->xpaths->extensionInfos,
02060 EL_EXTENSION_INFO,
02061 EL_EXT_NAME,
02062 extension);
02063 }
02064 else
02065 {
02066 g_snprintf(xpath, BUF_LEN, "%s/%s",
02067 pRegistry->xpaths->extensionInfos,
02068 EL_EXTENSION_INFO);
02069 }
02070 xpathObj = ermXmlSelectNodes(pXmlCxt, xpath);
02071 if (xpathObj == NULL)
02072 {
02073 ERREG_WARNPRINTF("%s not found", xpath);
02074 return NULL;
02075 }
02076
02077
02078 extensionNodes = xpathObj->nodesetval;
02079
02080
02081 int num = extensionNodes->nodeNr;
02082 p_node = extensionNodes->nodeTab;
02083
02084
02085 theExtInfoList = g_new0(regExtInfoList_t, 1);
02086 g_assert(theExtInfoList != NULL);
02087 theExtInfoList->extArray = g_new0(regExtInfo_t, num);
02088 theExtInfoList->extArraySize = num;
02089
02090
02091 int i = 0;
02092 for (; i < num ; ++i, ++p_node)
02093 {
02094 xmlChar * content = 0;
02095
02096
02097
02098 xmlNodePtr iconPtr = ermXmlGetChildNode(*p_node, EL_EXT_ICON);
02099 content = xmlNodeGetContent(iconPtr);
02100 theExtInfoList->extArray[i].iconLocation = g_strdup(content);
02101 xmlFree(content);
02102
02103
02104 xmlNodePtr extPtr = ermXmlGetChildNode(*p_node, EL_EXT_NAME);
02105 content = xmlNodeGetContent(extPtr);
02106 theExtInfoList->extArray[i].extName = g_strdup(content);
02107 xmlFree(content);
02108
02109
02110 xmlNodePtr appPtr = ermXmlGetChildNode(*p_node, EL_ASSOCIATE_APP);
02111 content = xmlNodeGetContent(appPtr);
02112 theExtInfoList->extArray[i].associateApp = g_strdup(content);
02113 xmlFree(content);
02114
02115
02116 xmlNodePtr appOrderPtr = ermXmlGetChildNode(*p_node, EL_ASSOCIATE_ORDER);
02117 content = xmlNodeGetContent(appOrderPtr);
02118 int order = 1;
02119 if (content)
02120 {
02121 sscanf(content, "%d", &order);
02122 }
02123 theExtInfoList->extArray[i].associateOrder = order;
02124 }
02125 regDumpExtInfoList(theExtInfoList);
02126
02127 xmlXPathFreeObject(xpathObj);
02128 xpathObj = NULL;
02129
02130 return theExtInfoList;
02131 }
02132
02188 regStartUp_t *regGetStartUp(const regRegistry_t *pRegistry)
02189 {
02190 regStartUp_t *theStartUp = NULL;
02191
02192 ERREG_LOGPRINTF("entry");
02193 g_assert(pRegistry);
02194 g_assert(pRegistry->xpaths);
02195 g_assert(pRegistry->xpaths->startup);
02196
02197 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02198 int nLen, nRet;
02199
02200 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02201
02202 theStartUp = g_new0(regStartUp_t, 1);
02203 g_assert(theStartUp != NULL);
02204
02205
02206 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->startup, EL_BEHAVIOUR);
02207 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02208 if (RET_ERR == nRet)
02209 {
02210 regFreeStartUp(theStartUp);
02211 theStartUp = NULL;
02212 return NULL;
02213 }
02214 theStartUp->behaviour = regBehaviourToEnum(szTmp);
02215
02216
02217 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->startup, EL_DOCUMENT_PATH);
02218 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02219 if (RET_ERR == nRet)
02220 {
02221 regFreeStartUp(theStartUp);
02222 theStartUp = NULL;
02223 return NULL;
02224 }
02225 theStartUp->documentPath = g_strdup(szTmp);
02226
02227 regDumpStartUp(theStartUp);
02228 return theStartUp;
02229
02230 }
02231
02232 gboolean regSetStartUp(const regStartUp_t *theStartUp, regRegistry_t *pRegistry)
02233 {
02234 ERREG_LOGPRINTF("entry %p %p", theStartUp, pRegistry);
02235 g_assert(theStartUp);
02236 g_assert(pRegistry);
02237 g_assert(pRegistry->xpaths);
02238 g_assert(pRegistry->xpaths->startup);
02239
02240 regDumpStartUp(theStartUp);
02241
02242 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02243 int nLen, nRet = RET_OK;
02244
02245 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02246
02247
02248 if ((theStartUp->behaviour >=0) && (theStartUp->behaviour < behaviourUndefined_t))
02249 {
02250 regBehaviourToString(theStartUp->behaviour, szTmp, BUF_LEN);
02251 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->startup, EL_BEHAVIOUR);
02252 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02253 if (RET_OK == nRet)
02254 {
02255 nRet = ermXmlSetString(pXmlCxt, xpath, szTmp);
02256 }
02257 if (RET_ERR == nRet)
02258 {
02259 return FALSE;
02260 }
02261 }
02262
02263
02264 if (theStartUp->documentPath)
02265 {
02266 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->startup, EL_DOCUMENT_PATH);
02267 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02268 if (RET_OK == nRet)
02269 {
02270 nRet = ermXmlSetString(pXmlCxt, xpath, theStartUp->documentPath);
02271 }
02272 if (RET_ERR == nRet)
02273 {
02274 return FALSE;
02275 }
02276 }
02277
02278 pRegistry->changed = TRUE;
02279 return TRUE;
02280 }
02281
02283
02284
02285
02287 static gboolean getProxySettings(const regRegistry_t *pRegistry, const char *curXpath, regProxySetting_t *proxySettings)
02288 {
02289 ERREG_LOGPRINTF("entry %p, %s, %p", pRegistry, curXpath, proxySettings);
02290 g_assert(pRegistry);
02291 g_assert(curXpath);
02292 g_assert(proxySettings);
02293
02294 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02295 int nLen, nPort, nRet;
02296
02297 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02298
02299
02300 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_PROXY_DETAILS, EL_PROXY_SERVER);
02301 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02302 if (RET_ERR == nRet)
02303 {
02304 return FALSE;
02305 }
02306 proxySettings->address = g_strdup(szTmp);
02307
02308
02309 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_PROXY_DETAILS, EL_PROXY_PORT);
02310 nRet = ermXmlGetInt(pXmlCxt, xpath, &nPort);
02311 if (RET_ERR == nRet)
02312 {
02313 return FALSE;
02314 }
02315 proxySettings->port = g_strdup_printf("%d", nPort);
02316
02317 return TRUE;
02318 }
02319
02320 static gboolean getIpSettings(const regRegistry_t *pRegistry, const char *curXpath, regIpSetting_t *ipSettings)
02321 {
02322 ERREG_LOGPRINTF("entry %p %s %p", pRegistry, curXpath, ipSettings);
02323 g_assert(pRegistry);
02324 g_assert(curXpath);
02325 g_assert(ipSettings);
02326
02327 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02328 int nLen, nRet;
02329
02330 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02331
02332
02333 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_IP_STATIC_DETAILS, EL_IP_ADDRESS);
02334 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02335 if (RET_ERR == nRet)
02336 {
02337 return FALSE;
02338 }
02339 ipSettings->address = g_strdup(szTmp);
02340
02341
02342 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_IP_STATIC_DETAILS, EL_IP_NETMASK);
02343 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02344 if (RET_ERR == nRet)
02345 {
02346 return FALSE;
02347 }
02348 ipSettings->netmask = g_strdup(szTmp);
02349
02350
02351 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_IP_STATIC_DETAILS, EL_IP_DNS);
02352 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02353 if (RET_ERR == nRet)
02354 {
02355 return FALSE;
02356 }
02357 ipSettings->dns = g_strdup(szTmp);
02358
02359
02360 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_IP_STATIC_DETAILS, EL_IP_GATEWAY);
02361 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02362 if (RET_ERR == nRet)
02363 {
02364 return FALSE;
02365 }
02366 ipSettings->gateway = g_strdup(szTmp);
02367
02368 return TRUE;
02369 }
02370
02371 static gboolean getWirelessSettings(const regRegistry_t *pRegistry,
02372 const char *curXpath,
02373 regWirelessSetting_t *wirelessSettings)
02374 {
02375 ERREG_LOGPRINTF("entry %p %s %p", pRegistry, curXpath, wirelessSettings);
02376 g_assert(pRegistry);
02377 g_assert(curXpath);
02378 g_assert(wirelessSettings);
02379
02380 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02381 int nLen, nRet;
02382
02383 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02384
02385
02386 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_WLAN_DETAILS, EL_WLAN_SSID);
02387 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02388 if (RET_ERR == nRet)
02389 {
02390 return FALSE;
02391 }
02392 wirelessSettings->SSID = g_strdup(szTmp);
02393
02394
02395 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_WLAN_DETAILS, EL_WLAN_ENCRYPTION_TYPE);
02396 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02397 if (RET_ERR == nRet)
02398 {
02399 return FALSE;
02400 }
02401 wirelessSettings->encrType = regWlanEncrToEnum(szTmp);
02402
02403
02404 if (wirelessSettings->encrType == encr_wep_t || wirelessSettings->encrType == encr_wpa_t)
02405 {
02406 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_WLAN_DETAILS, EL_WLAN_ENCRYPTION_KEY);
02407 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02408 if (RET_ERR == nRet)
02409 {
02410 return FALSE;
02411 }
02412 wirelessSettings->encrKey = g_strdup(szTmp);
02413 }
02414
02415
02416 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_WLAN_DETAILS, EL_WLAN_BROADCAST);
02417 nRet = ermXmlGetBoolean(pXmlCxt, xpath, &wirelessSettings->broadcast);
02418 if (RET_ERR == nRet)
02419 {
02420
02421 wirelessSettings->broadcast = TRUE;
02422 }
02423
02424 return TRUE;
02425 }
02426
02427 static gboolean getDialupSettings(const regRegistry_t *pRegistry,
02428 const char *curXpath,
02429 regDialupSetting_t *dialupSettings)
02430 {
02431 ERREG_LOGPRINTF("entry %p %s %p", pRegistry, curXpath, dialupSettings);
02432 g_assert(pRegistry);
02433 g_assert(curXpath);
02434 g_assert(dialupSettings);
02435
02436 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02437 int nLen, nRet;
02438
02439 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02440
02441
02442 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_DIALUP_DETAILS, EL_DIALUP_PHONE);
02443 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02444 if (RET_ERR == nRet)
02445 {
02446 return FALSE;
02447 }
02448 dialupSettings->phone = g_strdup(szTmp);
02449
02450
02451 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_DIALUP_DETAILS, EL_DIALUP_USER);
02452 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02453 if (RET_ERR == nRet)
02454 {
02455 return FALSE;
02456 }
02457 dialupSettings->user = g_strdup(szTmp);
02458
02459
02460 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_DIALUP_DETAILS, EL_DIALUP_PASSWORD);
02461 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
02462 if (RET_ERR == nRet)
02463 {
02464 return FALSE;
02465 }
02466 dialupSettings->password = g_strdup(szTmp);
02467
02468 return TRUE;
02469 }
02470
02471 static int compare_profileID(const void* l, const void* r)
02472 {
02473 const char* left = *((char**) l);
02474 const char* right = *((char**) r);
02475
02476 g_assert(left);
02477 g_assert(right);
02478
02479 ERREG_LOGPRINTF("entry: left [%s] right [%s]", left, right);
02480
02481 if ( strncmp(left, "NW_", 3) == 0
02482 && strncmp(right, "NW_", 3) == 0)
02483 {
02484 return (atoi(left+3) - atoi(right+3));
02485 }
02486 else
02487 {
02488 return strcmp(left, right);
02489 }
02490 }
02491
02492 regNetworkConfig_t *regGetNetworkConfig(const regRegistry_t *pRegistry)
02493 {
02494 regNetworkConfig_t *theNetworkConfig = NULL;
02495
02496 ERREG_LOGPRINTF("entry %p", pRegistry);
02497 g_assert(pRegistry);
02498 g_assert(pRegistry->xpaths);
02499 g_assert(pRegistry->xpaths->networkProfile);
02500
02501 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02502 int nLen, i, nProfiles, nRet;
02503
02504 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02505
02506
02507 nLen = g_snprintf(xpath, BUF_LEN, "%s", pRegistry->xpaths->networkProfile);
02508 nRet = ermXmlGetNodeNr(pXmlCxt, xpath, &nProfiles);
02509 if (RET_ERR == nRet || 0 == nProfiles)
02510 {
02511 ERREG_ERRORPRINTF("%s not present", xpath);
02512 return NULL;
02513 }
02514
02515
02516 theNetworkConfig = g_new0(regNetworkConfig_t, 1);
02517 g_assert(theNetworkConfig != NULL);
02518
02519 theNetworkConfig->size = nProfiles;
02520 theNetworkConfig->networkList = g_new0(char *, nProfiles + 1);
02521 theNetworkConfig->networkList[nProfiles] = NULL;
02522
02523
02524 for (i = 1; i <= nProfiles; i++)
02525 {
02526 nLen = g_snprintf(xpath, BUF_LEN, "%s[%d]", pRegistry->xpaths->networkProfile, i);
02527 nRet = ermXmlGetAttributeString(pXmlCxt, xpath, ATTR_PROFILE_ID, szTmp, BUF_LEN);
02528 if (RET_OK == nRet)
02529 {
02530 theNetworkConfig->networkList[i - 1] = g_strdup(szTmp);
02531 }
02532 }
02533
02534
02535 qsort( theNetworkConfig->networkList,
02536 theNetworkConfig->size,
02537 sizeof(theNetworkConfig->networkList[0]),
02538 compare_profileID );
02539
02540 regDumpNetworkConfig(theNetworkConfig);
02541 return theNetworkConfig;
02542 }
02543
02544 gboolean regSetNetworkConfig(const regNetworkConfig_t *theNetworkConfig, regRegistry_t *pRegistry)
02545 {
02546 ERREG_LOGPRINTF("entry %p %p", theNetworkConfig, pRegistry);
02547 g_assert(theNetworkConfig);
02548 g_assert(pRegistry);
02549 g_assert(pRegistry->xpaths);
02550 g_assert(pRegistry->xpaths->networkProfile);
02551
02552 regDumpNetworkConfig(theNetworkConfig);
02553
02554 char xpath[BUF_LEN + 1];
02555 int nLen, i, nProfiles, nRet;
02556
02557 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02558
02559 nProfiles = theNetworkConfig->size;
02560 for (i = 1; i <= nProfiles; i++)
02561 {
02562 nLen = g_snprintf(xpath, BUF_LEN, "%s[%d]", pRegistry->xpaths->networkProfile, i);
02563 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02564 if (RET_OK == nRet)
02565 {
02566 nRet = ermXmlSetAttributeString(pXmlCxt, xpath, ATTR_PROFILE_ID,
02567 theNetworkConfig->networkList[i-1],
02568 strlen(theNetworkConfig->networkList[i-1]));
02569 }
02570 if (RET_ERR == nRet)
02571 {
02572 return FALSE;
02573 }
02574 }
02575
02576 pRegistry->changed = TRUE;
02577 return TRUE;
02578 }
02579
02580 regNetworkProfile_t *regGetNetworkProfile(const char *ID, const regRegistry_t *pRegistry)
02581 {
02582 regNetworkProfile_t *theNetworkProfile = NULL;
02583
02584 ERREG_LOGPRINTF("entry: ID [%s] pXmlCxt [%p]", ID, pRegistry);
02585 g_assert(ID);
02586 g_assert(pRegistry);
02587 g_assert(pRegistry->xpaths);
02588 g_assert(pRegistry->xpaths->networkProfile);
02589
02590 char xpath[BUF_LEN + 1], xpathExt[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02591 int nLen, nRet;
02592 gboolean bDhcp, bRet;
02593
02594 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02595
02596 theNetworkProfile = g_new0(regNetworkProfile_t, 1);
02597 g_assert(theNetworkProfile != NULL);
02598
02599 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]",
02600 pRegistry->xpaths->networkProfile, ATTR_PROFILE_ID, ID);
02601
02602
02603 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_PROFILE_NAME);
02604 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
02605 if (RET_ERR == nRet)
02606 {
02607 g_snprintf(szTmp, BUF_LEN, "%s", ID);
02608 }
02609 theNetworkProfile->name = g_strdup(szTmp);
02610
02611
02612 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_NETWORK_TYPE);
02613 nRet = ermXmlGetString(pXmlCxt, xpathExt, szTmp, BUF_LEN);
02614 if (RET_ERR == nRet)
02615 {
02616 ERREG_ERRORPRINTF("Can't get network type from memory.");
02617 regFreeNetworkProfile(theNetworkProfile);
02618 theNetworkProfile = NULL;
02619 return NULL;
02620 }
02621 theNetworkProfile->connection = regNetworkTypeToEnum(szTmp);
02622
02623
02624 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_USE_PROXY);
02625 nRet = ermXmlGetBoolean(pXmlCxt, xpathExt, &theNetworkProfile->proxy);
02626 if (RET_ERR == nRet)
02627 {
02628 ERREG_ERRORPRINTF("Can't get use proxy flag from memory.");
02629 regFreeNetworkProfile(theNetworkProfile);
02630 theNetworkProfile = NULL;
02631 return NULL;
02632 }
02633
02634
02635 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_USE_DHCP);
02636 nRet = ermXmlGetBoolean(pXmlCxt, xpathExt, &bDhcp);
02637 if (RET_ERR == nRet)
02638 {
02639 ERREG_ERRORPRINTF("Can't get use dhcp flag from memory.");
02640 regFreeNetworkProfile(theNetworkProfile);
02641 theNetworkProfile = NULL;
02642 return NULL;
02643 }
02644 theNetworkProfile->addressMode = regIpAddressToEnum(bDhcp);
02645
02646 if (theNetworkProfile->connection == wireless_t)
02647 {
02648
02649 theNetworkProfile->wirelessSettings = g_new0(regWirelessSetting_t, 1);
02650 bRet = getWirelessSettings(pRegistry, xpath, theNetworkProfile->wirelessSettings);
02651 if (FALSE == bRet)
02652 {
02653 regFreeWirelessSetting(theNetworkProfile->wirelessSettings);
02654 theNetworkProfile->wirelessSettings = NULL;
02655 theNetworkProfile->connection = wired_t;
02656 }
02657 }
02658 else if (theNetworkProfile->connection == dialup_t)
02659 {
02660
02661 theNetworkProfile->dialupSettings = g_new0(regDialupSetting_t, 1);
02662 bRet = getDialupSettings(pRegistry, xpath, theNetworkProfile->dialupSettings);
02663 if (FALSE == bRet)
02664 {
02665 regFreeDialupSetting(theNetworkProfile->dialupSettings);
02666 theNetworkProfile->dialupSettings = NULL;
02667 theNetworkProfile->connection = wired_t;
02668 }
02669 }
02670
02671
02672 if (theNetworkProfile->proxy == TRUE)
02673 {
02674 theNetworkProfile->proxySettings = g_new0(regProxySetting_t, 1);
02675 bRet = getProxySettings(pRegistry, xpath, theNetworkProfile->proxySettings);
02676 if (FALSE == bRet)
02677 {
02678 regFreeProxySetting(theNetworkProfile->proxySettings);
02679 theNetworkProfile->proxySettings = NULL;
02680 theNetworkProfile->proxy = FALSE;
02681 }
02682 }
02683
02684
02685 if (theNetworkProfile->addressMode == static_t)
02686 {
02687 theNetworkProfile->ipSettings = g_new0(regIpSetting_t, 1);
02688 bRet = getIpSettings(pRegistry, xpath, theNetworkProfile->ipSettings);
02689 if (FALSE == bRet)
02690 {
02691 regFreeIpSetting(theNetworkProfile->ipSettings);
02692 theNetworkProfile->ipSettings = NULL;
02693 theNetworkProfile->addressMode = dhcp_t;
02694 }
02695 }
02696
02697
02698 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_TIMESTAMP);
02699 nRet = ermXmlGetInt(pXmlCxt, xpathExt, &theNetworkProfile->timestamp);
02700 if (RET_ERR == nRet)
02701 {
02702 ERREG_LOGPRINTF("no timestamp found");
02703 theNetworkProfile->timestamp = 0;
02704 }
02705
02706 regDumpNetworkProfile(ID, theNetworkProfile);
02707 return theNetworkProfile;
02708 }
02709
02710
02711 static gboolean regChkNetworkProfile(const regNetworkProfile_t *theNetworkProfile)
02712 {
02713 ERREG_LOGPRINTF("entry %p", theNetworkProfile);
02714 g_assert(theNetworkProfile);
02715
02716 if (theNetworkProfile->addressMode == static_t)
02717 {
02718 if (theNetworkProfile->ipSettings)
02719 {
02720 if ((theNetworkProfile->ipSettings->address == NULL)
02721 || (theNetworkProfile->ipSettings->netmask == NULL)
02722 || (theNetworkProfile->ipSettings->dns == NULL)
02723 || (theNetworkProfile->ipSettings->gateway == NULL))
02724 {
02725 ERREG_WARNPRINTF("theNetworkProfile->ipSettings contains NULL");
02726 return FALSE;
02727 }
02728 }
02729 else
02730 {
02731 ERREG_WARNPRINTF("theNetworkProfile->ipSettings == NULL while address mode static_t");
02732 return FALSE;
02733 }
02734 }
02735
02736 if (theNetworkProfile->proxy == TRUE)
02737 {
02738 if (theNetworkProfile->proxySettings)
02739 {
02740 if ((theNetworkProfile->proxySettings->address == NULL)
02741 || (theNetworkProfile->proxySettings->port == NULL))
02742 {
02743 ERREG_WARNPRINTF("theNetworkProfile->proxySettings contains NULL");
02744 return FALSE;
02745 }
02746 }
02747 else
02748 {
02749 ERREG_WARNPRINTF("theNetworkProfile->proxySettings == NULL while proxy == TRUE");
02750 return FALSE;
02751 }
02752 }
02753
02754 if (theNetworkProfile->connection == wireless_t)
02755 {
02756 if (theNetworkProfile->wirelessSettings)
02757 {
02758 switch (theNetworkProfile->wirelessSettings->encrType)
02759 {
02760 case encr_none_t:
02761 break;
02762 case encr_wep_t:
02763 case encr_wpa_t:
02764 if (theNetworkProfile->wirelessSettings->encrKey == NULL
02765 )
02766 {
02767 ERREG_WARNPRINTF("theNetworkProfile->wirelessSettings->encrKey missing");
02768 return FALSE;
02769 }
02770 break;
02771 default:
02772 ERREG_WARNPRINTF
02773 ("theNetworkProfile->wirelessSettings->encrType illegal value [%d]",
02774 theNetworkProfile->wirelessSettings->encrType);
02775 return FALSE;
02776 }
02777 }
02778 else
02779 {
02780 ERREG_WARNPRINTF("theNetworkProfile->wirelessSettings == NULL while connection == wireless_t ");
02781 return FALSE;
02782 }
02783 }
02784
02785 return TRUE;
02786 }
02787
02788 static gboolean setWirelessSettings(regRegistry_t *pRegistry, char *curXpath, regWirelessSetting_t *wirelessSettings)
02789 {
02790 ERREG_LOGPRINTF("entry %p %s %p", pRegistry, curXpath, wirelessSettings);
02791 g_assert(pRegistry);
02792 g_assert(curXpath);
02793 g_assert(wirelessSettings);
02794
02795 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
02796 int nLen, nRet;
02797
02798 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02799
02800
02801 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_WLAN_DETAILS, EL_WLAN_SSID);
02802 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02803 if (RET_OK == nRet)
02804 {
02805 nRet = ermXmlSetString(pXmlCxt, xpath, wirelessSettings->SSID);
02806 }
02807 if (RET_ERR == nRet)
02808 {
02809 return FALSE;
02810 }
02811
02812
02813 regWlanEncrToString(wirelessSettings->encrType, szTmp, BUF_LEN);
02814 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_WLAN_DETAILS, EL_WLAN_ENCRYPTION_TYPE);
02815 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02816 if (RET_OK == nRet)
02817 {
02818 nRet = ermXmlSetString(pXmlCxt, xpath, szTmp);
02819 }
02820 if (RET_ERR == nRet)
02821 {
02822 return FALSE;
02823 }
02824
02825
02826 if (wirelessSettings->encrType == encr_wep_t || wirelessSettings->encrType == encr_wpa_t)
02827 {
02828 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_WLAN_DETAILS, EL_WLAN_ENCRYPTION_KEY);
02829 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02830 if (RET_OK == nRet)
02831 {
02832 nRet = ermXmlSetString(pXmlCxt, xpath, wirelessSettings->encrKey);
02833 }
02834 if (RET_ERR == nRet)
02835 {
02836 return FALSE;
02837 }
02838 }
02839
02840
02841 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_WLAN_DETAILS, EL_WLAN_BROADCAST);
02842 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02843 if (RET_OK == nRet)
02844 {
02845 nRet = ermXmlSetBoolean(pXmlCxt, xpath, wirelessSettings->broadcast);
02846 }
02847 if (RET_ERR == nRet)
02848 {
02849 return FALSE;
02850 }
02851
02852 return TRUE;
02853 }
02854
02855 static gboolean setDialupSettings(regRegistry_t *pRegistry, char *curXpath, regDialupSetting_t *dialupSettings)
02856 {
02857 ERREG_LOGPRINTF("entry %p %s %p", pRegistry, curXpath, dialupSettings);
02858 g_assert(pRegistry);
02859 g_assert(curXpath);
02860 g_assert(dialupSettings);
02861
02862 char xpath[BUF_LEN + 1];
02863 int nLen, nRet;
02864
02865 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02866
02867
02868 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_DIALUP_DETAILS, EL_DIALUP_PHONE);
02869 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02870 if (RET_OK == nRet)
02871 {
02872 nRet = ermXmlSetString(pXmlCxt, xpath, dialupSettings->phone);
02873 }
02874 if (RET_ERR == nRet)
02875 {
02876 return FALSE;
02877 }
02878
02879
02880 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_DIALUP_DETAILS, EL_DIALUP_USER);
02881 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02882 if (RET_OK == nRet)
02883 {
02884 nRet = ermXmlSetString(pXmlCxt, xpath, dialupSettings->user);
02885 }
02886 if (RET_ERR == nRet)
02887 {
02888 return FALSE;
02889 }
02890
02891
02892 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_DIALUP_DETAILS, EL_DIALUP_PASSWORD);
02893 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02894 if (RET_OK == nRet)
02895 {
02896 nRet = ermXmlSetString(pXmlCxt, xpath, dialupSettings->password);
02897 }
02898 if (RET_ERR == nRet)
02899 {
02900 return FALSE;
02901 }
02902
02903 return TRUE;
02904 }
02905
02906
02907 static gboolean setProxySettings(regRegistry_t *pRegistry, char *curXpath, regProxySetting_t *proxySettings)
02908 {
02909 ERREG_LOGPRINTF("entry %p %s %p", pRegistry, curXpath, proxySettings);
02910 g_assert(pRegistry);
02911 g_assert(curXpath);
02912 g_assert(proxySettings);
02913
02914 char xpath[BUF_LEN + 1];
02915 int nLen, nRet;
02916
02917 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02918
02919
02920 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_PROXY_DETAILS, EL_PROXY_SERVER);
02921 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02922 if (RET_OK == nRet)
02923 {
02924 nRet = ermXmlSetString(pXmlCxt, xpath, proxySettings->address);
02925 }
02926 if (RET_ERR == nRet)
02927 {
02928 return FALSE;
02929 }
02930
02931
02932 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_PROXY_DETAILS, EL_PROXY_PORT);
02933 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02934 if (RET_OK == nRet)
02935 {
02936 nRet = ermXmlSetString(pXmlCxt, xpath, proxySettings->port);
02937 }
02938 if (RET_ERR == nRet)
02939 {
02940 return FALSE;
02941 }
02942
02943 return TRUE;
02944 }
02945
02946 static gboolean setIpSettings(regRegistry_t *pRegistry, char *curXpath, regIpSetting_t *ipSettings)
02947 {
02948 ERREG_LOGPRINTF("entry %p %s %p", pRegistry, curXpath, ipSettings);
02949 g_assert(pRegistry);
02950 g_assert(curXpath);
02951 g_assert(ipSettings);
02952
02953 char xpath[BUF_LEN + 1];
02954 int nLen, nRet;
02955
02956 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
02957
02958
02959 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_IP_STATIC_DETAILS, EL_IP_ADDRESS);
02960 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02961 if (RET_OK == nRet)
02962 {
02963 nRet = ermXmlSetString(pXmlCxt, xpath, ipSettings->address);
02964 }
02965 if (RET_ERR == nRet)
02966 {
02967 return FALSE;
02968 }
02969
02970
02971 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_IP_STATIC_DETAILS, EL_IP_NETMASK);
02972 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02973 if (RET_OK == nRet)
02974 {
02975 nRet = ermXmlSetString(pXmlCxt, xpath, ipSettings->netmask);
02976 }
02977 if (RET_ERR == nRet)
02978 {
02979 return FALSE;
02980 }
02981
02982
02983 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_IP_STATIC_DETAILS, EL_IP_DNS);
02984 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02985 if (RET_OK == nRet)
02986 {
02987 nRet = ermXmlSetString(pXmlCxt, xpath, ipSettings->dns);
02988 }
02989 if (RET_ERR == nRet)
02990 {
02991 return FALSE;
02992 }
02993
02994
02995 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", curXpath, EL_IP_STATIC_DETAILS, EL_IP_GATEWAY);
02996 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
02997 if (RET_OK == nRet)
02998 {
02999 nRet = ermXmlSetString(pXmlCxt, xpath, ipSettings->gateway);
03000 }
03001 if (RET_ERR == nRet)
03002 {
03003 return FALSE;
03004 }
03005
03006 return TRUE;
03007 }
03008
03009 gboolean regSetNetworkProfile(const char *ID, const regNetworkProfile_t *theNetworkProfile, regRegistry_t *pRegistry)
03010 {
03011 ERREG_LOGPRINTF("entry %s %p %p", ID, theNetworkProfile, pRegistry);
03012 g_assert(ID);
03013 g_assert(theNetworkProfile);
03014 g_assert(pRegistry);
03015 g_assert(pRegistry->xpaths);
03016 g_assert(pRegistry->xpaths->networkProfile);
03017
03018 regDumpNetworkProfile(ID, theNetworkProfile);
03019
03020 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1], xpathExt[BUF_LEN + 1];
03021 int nLen, nRet;
03022 gboolean bDhcp, bRet;
03023
03024 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03025
03026 if (FALSE == regChkNetworkProfile(theNetworkProfile))
03027 {
03028 return FALSE;
03029 }
03030
03031
03032 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->networkProfile, ATTR_PROFILE_ID, ID);
03033
03034
03035 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_PROFILE_NAME);
03036 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
03037 if (RET_OK == nRet)
03038 {
03039 nRet = ermXmlSetString(pXmlCxt, xpathExt, theNetworkProfile->name);
03040 }
03041 if (RET_ERR == nRet)
03042 {
03043 return FALSE;
03044 }
03045
03046
03047 regNetworkTypeToString(theNetworkProfile->connection, szTmp, BUF_LEN);
03048 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_NETWORK_TYPE);
03049 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
03050 if (RET_OK == nRet)
03051 {
03052 nRet = ermXmlSetString(pXmlCxt, xpathExt, szTmp);
03053 }
03054 if (RET_ERR == nRet)
03055 {
03056 return FALSE;
03057 }
03058
03059
03060 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_USE_PROXY);
03061 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
03062 if (RET_OK == nRet)
03063 {
03064 nRet = ermXmlSetBoolean(pXmlCxt, xpathExt, theNetworkProfile->proxy);
03065 }
03066 if (RET_ERR == nRet)
03067 {
03068 return FALSE;
03069 }
03070
03071
03072 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_USE_DHCP);
03073 bDhcp = regIpAddressToBool(theNetworkProfile->addressMode);
03074 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
03075 if (RET_OK == nRet)
03076 {
03077 nRet = ermXmlSetBoolean(pXmlCxt, xpathExt, bDhcp);
03078 }
03079 if (RET_ERR == nRet)
03080 {
03081 return FALSE;
03082 }
03083
03084 if (theNetworkProfile->connection == wireless_t)
03085 {
03086
03087 bRet = setWirelessSettings(pRegistry, xpath, theNetworkProfile->wirelessSettings);
03088 if (FALSE == bRet)
03089 {
03090 return FALSE;
03091 }
03092 }
03093 else if (theNetworkProfile->connection == dialup_t)
03094 {
03095
03096 bRet = setDialupSettings(pRegistry, xpath, theNetworkProfile->dialupSettings);
03097 if (FALSE == bRet)
03098 {
03099 return FALSE;
03100 }
03101 }
03102
03103
03104 if (theNetworkProfile->proxy == TRUE)
03105 {
03106 bRet = setProxySettings(pRegistry, xpath, theNetworkProfile->proxySettings);
03107 if (FALSE == bRet)
03108 {
03109 return FALSE;
03110 }
03111 }
03112
03113
03114 if (theNetworkProfile->addressMode == static_t)
03115 {
03116 bRet = setIpSettings(pRegistry, xpath, theNetworkProfile->ipSettings);
03117 if (FALSE == bRet)
03118 {
03119 return FALSE;
03120 }
03121 }
03122
03123
03124 if (theNetworkProfile->timestamp != 0)
03125 {
03126 nLen = g_snprintf(xpathExt, BUF_LEN, "%s/%s", xpath, EL_TIMESTAMP);
03127 nRet = ermXmlCheckXpath(pXmlCxt, xpathExt);
03128 if (RET_OK == nRet)
03129 {
03130 nRet = ermXmlSetInt(pXmlCxt, xpathExt, theNetworkProfile->timestamp);
03131 }
03132 if (RET_ERR == nRet)
03133 {
03134 return FALSE;
03135 }
03136 }
03137
03138 pRegistry->changed = TRUE;
03139 return TRUE;
03140 }
03141
03142 gboolean regRemoveNetworkProfile(const char *ID, regRegistry_t *pRegistry)
03143 {
03144 ERREG_LOGPRINTF("entry %p", pRegistry);
03145 g_assert(ID);
03146 g_assert(pRegistry);
03147 g_assert(pRegistry->xpaths);
03148 g_assert(pRegistry->xpaths->networkProfile);
03149
03150 char xpath[BUF_LEN + 1];
03151 int nLen, nRet;
03152
03153 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03154
03155
03156 nLen = g_snprintf(xpath, BUF_LEN, "%s[@%s=\"%s\"]", pRegistry->xpaths->networkProfile, ATTR_PROFILE_ID, ID);
03157 nRet = ermXmlRemoveNode(pXmlCxt, xpath);
03158 if (RET_ERR == nRet)
03159 {
03160 return FALSE;
03161 }
03162
03163 return TRUE;
03164 }
03165
03166 gboolean regRemoveNetworkConfig(regRegistry_t *pRegistry)
03167 {
03168 ERREG_LOGPRINTF("entry %p", pRegistry);
03169 g_assert(pRegistry);
03170 g_assert(pRegistry->xpaths);
03171 g_assert(pRegistry->xpaths->networkProfiles);
03172
03173 char xpath[BUF_LEN + 1];
03174 int nLen, nRet;
03175
03176 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03177
03178
03179 nLen = g_snprintf(xpath, BUF_LEN, "%s", pRegistry->xpaths->networkProfiles);
03180 nRet = ermXmlRemoveNode(pXmlCxt, xpath);
03181 if (RET_ERR == nRet)
03182 {
03183 return FALSE;
03184 }
03185
03186 return TRUE;
03187 }
03188
03189 void regGetNetworkProfiles(regNetworkConfig_t **pNetworkConfig, regNetworkProfile_t ***pNetworks, const regRegistry_t* pRegistry)
03190 {
03191 int i;
03192 regNetworkConfig_t *theNetworkConfig = NULL;
03193 regNetworkProfile_t **theNetworks = NULL;
03194
03195 ERREG_LOGPRINTF("entry");
03196 g_assert(pNetworkConfig);
03197 g_assert(pNetworks);
03198 g_assert(pRegistry);
03199
03200
03201 regFreeNetworkProfiles(*pNetworkConfig, *pNetworks);
03202 *pNetworkConfig = NULL;
03203 *pNetworks = NULL;
03204
03205
03206 theNetworkConfig = regGetNetworkConfig(pRegistry);
03207 if (theNetworkConfig == NULL)
03208 {
03209 ERREG_WARNPRINTF("theNetworkConfig not present");
03210 }
03211 else
03212 {
03213 ERREG_LOGPRINTF("theNetworkConfig exist");
03214
03215 theNetworks = g_new0(regNetworkProfile_t *, theNetworkConfig->size);
03216 for (i = 0; i < theNetworkConfig->size; i++)
03217 {
03218
03219 theNetworks[i] = regGetNetworkProfile(theNetworkConfig->networkList[i], pRegistry);
03220 ERREG_LOGPRINTF("theNetworks[%d] = [%p]", i, theNetworks[i]);
03221 }
03222 }
03223
03224 *pNetworkConfig = theNetworkConfig;
03225 *pNetworks = theNetworks;
03226 }
03227
03228 gboolean regSetNetworkProfiles(const regNetworkConfig_t *theNetworkConfig, const regNetworkProfile_t **theNetworks, regRegistry_t* pRegistry)
03229 {
03230 ERREG_LOGPRINTF("entry");
03231 g_assert(theNetworkConfig);
03232 g_assert(theNetworks);
03233 g_assert(pRegistry);
03234
03235 gboolean bRet = TRUE;
03236 gboolean b;
03237 int i;
03238
03239
03240 regRemoveNetworkConfig(pRegistry);
03241
03242 regSetNetworkConfig(theNetworkConfig, pRegistry);
03243 for (i = 0; i < theNetworkConfig->size; i++)
03244 {
03245 b = regSetNetworkProfile(theNetworkConfig->networkList[i], theNetworks[i], pRegistry);
03246 if (FALSE == b)
03247 {
03248 bRet = FALSE;
03249 }
03250 }
03251
03252 if (bRet)
03253 {
03254 pRegistry->changed = TRUE;
03255 }
03256 return TRUE;
03257 }
03258
03259 regLastConnect_t *regGetLastConnect(const regRegistry_t *pRegistry)
03260 {
03261 regLastConnect_t *theLastConnect = NULL;
03262
03263 ERREG_LOGPRINTF("entry");
03264 g_assert(pRegistry);
03265 g_assert(pRegistry->xpaths);
03266 g_assert(pRegistry->xpaths->lastConnect);
03267
03268 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
03269 int nLen, nRet;
03270
03271 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03272
03273 theLastConnect = g_new0(regLastConnect_t, 1);
03274 g_assert(theLastConnect != NULL);
03275
03276
03277 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->lastConnect, EL_PROFILE_CONNECTED_IDS);
03278 nRet = ermXmlGetInt(pXmlCxt, xpath, &theLastConnect->profileConnectedIDS);
03279 if (RET_ERR == nRet)
03280 {
03281 regFreeLastConnect(theLastConnect);
03282 theLastConnect = NULL;
03283 return NULL;
03284 }
03285
03286
03287 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->lastConnect, EL_PROFILE_CONNECTED_PC);
03288 nRet = ermXmlGetInt(pXmlCxt, xpath, &theLastConnect->profileConnectedPC);
03289 if (RET_ERR == nRet)
03290 {
03291 regFreeLastConnect(theLastConnect);
03292 theLastConnect = NULL;
03293 return NULL;
03294 }
03295
03296
03297 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->lastConnect, EL_MANUAL_CONNECT_TYPE);
03298 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
03299 if (RET_ERR == nRet)
03300 {
03301 ERREG_ERRORPRINTF("Can't get which server to connect from memory.");
03302 regFreeLastConnect(theLastConnect);
03303 theLastConnect = NULL;
03304 return NULL;
03305 }
03306 theLastConnect->manualConnectType = regServerTypeToEnum(szTmp);
03307
03308 regDumpLastConnect(theLastConnect);
03309 return theLastConnect;
03310 }
03311
03312 gboolean regSetLastConnect(const regLastConnect_t *theLastConnect, regRegistry_t *pRegistry)
03313 {
03314 ERREG_LOGPRINTF("entry %p %p", theLastConnect, pRegistry);
03315 g_assert(theLastConnect);
03316 g_assert(pRegistry);
03317 g_assert(pRegistry->xpaths);
03318 g_assert(pRegistry->xpaths->lastConnect);
03319
03320 regDumpLastConnect(theLastConnect);
03321
03322 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1];
03323 int nLen, nRet = RET_OK;
03324
03325 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03326
03327
03328 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->lastConnect, EL_PROFILE_CONNECTED_IDS);
03329 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03330 if (RET_OK == nRet)
03331 {
03332 nRet = ermXmlSetInt(pXmlCxt, xpath, theLastConnect->profileConnectedIDS);
03333 }
03334 if (RET_ERR == nRet)
03335 {
03336 return FALSE;
03337 }
03338
03339
03340 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->lastConnect, EL_PROFILE_CONNECTED_PC);
03341 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03342 if (RET_OK == nRet)
03343 {
03344 nRet = ermXmlSetInt(pXmlCxt, xpath, theLastConnect->profileConnectedPC);
03345 }
03346 if (RET_ERR == nRet)
03347 {
03348 return FALSE;
03349 }
03350
03351
03352 regServerTypeToString(theLastConnect->manualConnectType, szTmp, BUF_LEN);
03353 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->lastConnect, EL_MANUAL_CONNECT_TYPE);
03354 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03355 if (RET_OK == nRet)
03356 {
03357 nRet = ermXmlSetString(pXmlCxt, xpath, szTmp);
03358 }
03359 if (RET_ERR == nRet)
03360 {
03361 return FALSE;
03362 }
03363
03364 pRegistry->changed = TRUE;
03365 return TRUE;
03366 }
03367
03368 gboolean regGetAutoConnectWlan(const regRegistry_t *pRegistry)
03369 {
03370 ERREG_LOGPRINTF("entry");
03371 g_assert(pRegistry);
03372 g_assert(pRegistry->xpaths);
03373 g_assert(pRegistry->xpaths->autoConnectWlan);
03374
03375 gboolean enable = TRUE;
03376 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03377 char* xpath = pRegistry->xpaths->autoConnectWlan;
03378 int nRet = ermXmlGetBoolean(pXmlCxt, xpath, &enable);
03379
03380 if (RET_ERR == nRet)
03381 {
03382 ERREG_ERRORPRINTF("Can't get the settings %s", xpath);
03383 }
03384
03385 regDumpAutoConnectWlan(enable);
03386 return enable;
03387 }
03388
03389 gboolean regSetAutoConnectWlan(gboolean enable, regRegistry_t *pRegistry)
03390 {
03391 ERREG_LOGPRINTF("entry %p", pRegistry);
03392 g_assert(pRegistry);
03393 g_assert(pRegistry->xpaths);
03394 g_assert(pRegistry->xpaths->autoConnectWlan);
03395
03396 regDumpAutoConnectWlan(enable);
03397
03398 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03399 char *xpath = pRegistry->xpaths->autoConnectWlan;
03400 int nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03401 if (RET_OK == nRet)
03402 {
03403 nRet = ermXmlSetBoolean(pXmlCxt, xpath, enable);
03404 }
03405 if (RET_ERR == nRet)
03406 {
03407 return FALSE;
03408 }
03409
03410 pRegistry->changed = TRUE;
03411 return TRUE;
03412 }
03413
03415
03416
03417
03419 regIconSet_t *regGetIconSet(const regRegistry_t *pRegistry)
03420 {
03421 regIconSet_t *theRegIconSet = NULL;
03422
03423 ERREG_LOGPRINTF("entry %p", pRegistry);
03424 g_assert(pRegistry);
03425 g_assert(pRegistry->xpaths);
03426 g_assert(pRegistry->xpaths->toolbarIcons);
03427 g_assert(pRegistry->xpaths->toolbarIcon);
03428
03429 char xpath[BUF_LEN + 1], szTmp[BUF_LEN + 1], szBase[BUF_LEN + 1];
03430 int nLen, nIcons, nFiles, i, j, nRet;
03431
03432 const erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03433
03434
03435 nLen = g_snprintf(xpath, BUF_LEN, "%s", pRegistry->xpaths->toolbarIcon);
03436 nRet = ermXmlGetNodeNr(pXmlCxt, xpath, &nIcons);
03437 if (RET_ERR == nRet || 0 == nIcons)
03438 {
03439 ERREG_ERRORPRINTF("%s not present", xpath);
03440 return NULL;
03441 }
03442
03443
03444 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->toolbarIcons, EL_ICON_BASE_PATH);
03445 nRet = ermXmlGetString(pXmlCxt, xpath, szBase, BUF_LEN);
03446 if (RET_ERR == nRet)
03447 {
03448 ERREG_ERRORPRINTF("%s not present", xpath);
03449 return NULL;
03450 }
03451
03452
03453 theRegIconSet = g_new0(regIconSet_t, 1);
03454 theRegIconSet->iconArray = g_new0(regIcon_t, nIcons);
03455 theRegIconSet->nIcons = nIcons;
03456
03457
03458 for (i = 1; i <= nIcons; i++)
03459 {
03460
03461 nLen = g_snprintf(xpath, BUF_LEN, "%s[%d]", pRegistry->xpaths->toolbarIcon, i);
03462 nRet = ermXmlGetAttributeString(pXmlCxt, xpath, ATTR_NAME, szTmp, BUF_LEN);
03463 if (RET_OK == nRet)
03464 {
03465 theRegIconSet->iconArray[i - 1].iconName = g_strdup(szTmp);
03466
03467
03468 nLen = g_snprintf(xpath, BUF_LEN, "%s[%d]/%s", pRegistry->xpaths->toolbarIcon, i, EL_ICON_FILE_NAME);
03469 nRet = ermXmlGetNodeNr(pXmlCxt, xpath, &nFiles);
03470
03471 if ((RET_OK == nRet) && (nFiles != 0))
03472 {
03473
03474 theRegIconSet->iconArray[i - 1].iconPathsSize = nFiles;
03475 theRegIconSet->iconArray[i - 1].iconPaths = g_new0(char *, (nFiles + 1));
03476 theRegIconSet->iconArray[i - 1].iconPaths[nFiles] = NULL;
03477
03478
03479 for (j = 1; j <= nFiles; j++)
03480 {
03481 nLen = g_snprintf(xpath, BUF_LEN, "%s[%d]/%s[@id=\"%d\"]",
03482 pRegistry->xpaths->toolbarIcon,
03483 i,
03484 EL_ICON_FILE_NAME,
03485 j );
03486 nRet = ermXmlGetString(pXmlCxt, xpath, szTmp, BUF_LEN);
03487 if (RET_OK == nRet)
03488 {
03489 theRegIconSet->iconArray[i - 1].iconPaths[j - 1] = g_strdup_printf("%s%s", szBase, szTmp);
03490 }
03491 }
03492 }
03493 }
03494 }
03495
03496 regDumpIconSet(theRegIconSet);
03497 return theRegIconSet;
03498 }
03499
03501
03502
03503
03505 deviceDetails_t* regGetDeviceDetails(const regRegistry_t *pRegistry)
03506 {
03507 deviceDetails_t *theDeviceDetails = NULL;
03508
03509 ERREG_LOGPRINTF("entry %p", pRegistry);
03510 g_assert(pRegistry);
03511 g_assert(pRegistry->xpaths);
03512
03513 char* cp = NULL;
03514
03515
03516 theDeviceDetails = g_new0(deviceDetails_t, 1);
03517 g_assert(theDeviceDetails != NULL);
03518
03519 theDeviceDetails->software = g_new0(software_t, 1);
03520 g_assert(theDeviceDetails->software);
03521
03522
03523 theDeviceDetails->software->szBuildName = g_strdup(get_software_version_commercial());
03524
03525
03526 theDeviceDetails->software->szBuildNum = g_strdup(get_software_version());
03527
03528
03529
03530 theDeviceDetails->szMacOfWireless = g_strdup(get_wlanmactxt_macAddress());
03531
03532
03533
03534 theDeviceDetails->szMacOfWired = g_strdup(get_sysset_macAddress());
03535
03536
03537 if (get_public_key(&cp) <= 0)
03538 {
03539 theDeviceDetails->szPublicKey = g_strdup("");
03540 }
03541 else
03542 {
03543 theDeviceDetails->szPublicKey = cp;
03544 }
03545
03546 regDumpDeviceDetails(theDeviceDetails);
03547 return theDeviceDetails;
03548 }
03549
03550 gboolean regSetDeviceDetails(const deviceDetails_t* theDeviceDetails, regRegistry_t* pRegistry)
03551 {
03552 ERREG_LOGPRINTF("entry %p %p", theDeviceDetails, pRegistry);
03553 g_assert(theDeviceDetails);
03554 g_assert(pRegistry);
03555 g_assert(pRegistry->xpaths);
03556 g_assert(pRegistry->xpaths->deviceDetails);
03557
03558 regDumpDeviceDetails(theDeviceDetails);
03559
03560 char xpath[BUF_LEN + 1];
03561 int nLen, nRet;
03562
03563 erManifest *pXmlCxt = &(pRegistry->xmlCxt);
03564
03565
03566 if (theDeviceDetails->software)
03567 {
03568
03569 if (theDeviceDetails->software->szBuildName)
03570 {
03571 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->deviceDetails, EL_SOFTWARE, EL_BUILD_NAME);
03572 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03573 if (RET_OK == nRet)
03574 {
03575 nRet = ermXmlSetString(pXmlCxt, xpath, theDeviceDetails->software->szBuildName);
03576 }
03577
03578 if (RET_ERR == nRet)
03579 {
03580 return FALSE;
03581 }
03582 }
03583
03584
03585 if (theDeviceDetails->software->szBuildNum)
03586 {
03587 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s/%s", pRegistry->xpaths->deviceDetails, EL_SOFTWARE, EL_BUILD_NUM);
03588 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03589 if (RET_OK == nRet)
03590 {
03591 nRet = ermXmlSetString(pXmlCxt, xpath, theDeviceDetails->software->szBuildNum);
03592 }
03593
03594 if (RET_ERR == nRet)
03595 {
03596 return FALSE;
03597 }
03598 }
03599 }
03600
03601
03602 if (theDeviceDetails->szMacOfWired)
03603 {
03604 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->deviceDetails, EL_MAC_OF_WIRED);
03605 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03606 if (RET_OK == nRet)
03607 {
03608 nRet = ermXmlSetString(pXmlCxt, xpath, theDeviceDetails->szMacOfWired);
03609 }
03610
03611 if (RET_ERR == nRet)
03612 {
03613 return FALSE;
03614 }
03615 }
03616
03617
03618 if (theDeviceDetails->szMacOfWireless)
03619 {
03620 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->deviceDetails, EL_MAC_OF_WIRELESS);
03621 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03622 if (RET_OK == nRet)
03623 {
03624 nRet = ermXmlSetString(pXmlCxt, xpath, theDeviceDetails->szMacOfWireless);
03625 }
03626
03627 if (RET_ERR == nRet)
03628 {
03629 return FALSE;
03630 }
03631 }
03632
03633
03634 if (theDeviceDetails->szPublicKey)
03635 {
03636 nLen = g_snprintf(xpath, BUF_LEN, "%s/%s", pRegistry->xpaths->deviceDetails, EL_PUBLIC_KEY);
03637 nRet = ermXmlCheckXpath(pXmlCxt, xpath);
03638 if (RET_OK == nRet)
03639 {
03640 nRet = ermXmlSetString(pXmlCxt, xpath, theDeviceDetails->szPublicKey);
03641 }
03642
03643 if (RET_ERR == nRet)
03644 {
03645 return FALSE;
03646 }
03647 }
03648
03649 pRegistry->changed = TRUE;
03650 return TRUE;
03651 }
03652