#include "erregtypes.h"
#include "erregxml.h"
#include "erreg.h"
Go to the source code of this file.
Copyright (C) 2007 iRex Technologies B.V. All rights reserved.
Definition in file erregnwprofiles.h.
#define DEFAULT_ADDRESS_MODE dhcp_t |
Definition at line 50 of file erregnwprofiles.h.
#define DEFAULT_USE_PROXY FALSE |
Definition at line 52 of file erregnwprofiles.h.
#define DEFAULT_WLAN_BROADCAST TRUE |
Definition at line 48 of file erregnwprofiles.h.
#define DEFAULT_WLAN_ENCRYPTION_KEY "" |
Definition at line 47 of file erregnwprofiles.h.
#define DEFAULT_WLAN_ENCRYPTION_TYPE encr_none_t |
Definition at line 46 of file erregnwprofiles.h.
#define DEFAULT_WLAN_SSID "ereader" |
Definition at line 45 of file erregnwprofiles.h.
#define REG_NWPROFILES_XML_FILE "nwprofiles.xml" |
Definition at line 38 of file erregnwprofiles.h.
#define REG_NWPROFILES_XSD_PATH TEMPLATE_DIR "/nwprofiles.xsd" |
Definition at line 39 of file erregnwprofiles.h.
#define WIRED_NETWORK_NAME "Wired network" |
Definition at line 42 of file erregnwprofiles.h.
#define WIRELESS_NETWORK_NAME "Wireless network" |
Definition at line 43 of file erregnwprofiles.h.
void nwRegAddNetworkProfileToList | ( | regNetworkConfig_t ** | pNetworkConfig, | |
regNetworkProfile_t *** | pNetworks, | |||
regNetworkProfile_t * | pNewNetworkProfile | |||
) |
Definition at line 388 of file erregnwprofiles.c.
00391 { 00392 ERREG_NWPROFILES_LOGPRINTF("entry"); 00393 00394 regNetworkConfig_t *pNewNetworkConfig = NULL, *pOldNetworkConfig = NULL; 00395 regNetworkProfile_t **pNewNetworks = NULL, **pOldNetworks = NULL; 00396 int i; 00397 00398 pOldNetworkConfig = *pNetworkConfig; 00399 pOldNetworks = *pNetworks; 00400 00401 // update the pNewNetworkConfig 00402 pNewNetworkConfig = nwRegNewNetworkConfig(pOldNetworkConfig->size+1); 00403 00404 // update the pNewNetworks 00405 pNewNetworks = g_new0(regNetworkProfile_t *, pNewNetworkConfig->size); 00406 for (i = 0; i < pOldNetworkConfig->size; i++) 00407 { 00408 pNewNetworks[i] = pOldNetworks[i]; 00409 } 00410 pNewNetworks[pNewNetworkConfig->size - 1] = pNewNetworkProfile; 00411 00412 // free the memory 00413 regFreeNetworkConfig(pOldNetworkConfig); 00414 g_free(pOldNetworks); 00415 00416 // return 00417 *pNetworkConfig = pNewNetworkConfig; 00418 *pNetworks = pNewNetworks; 00419 }
void nwRegDeleteNetworkProfileFromList | ( | regNetworkConfig_t ** | pNetworkConfig, | |
regNetworkProfile_t *** | pNetworks, | |||
const char * | ID | |||
) |
Definition at line 424 of file erregnwprofiles.c.
00426 { 00427 ERREG_NWPROFILES_LOGPRINTF("entry"); 00428 00429 regNetworkConfig_t *pNewNetworkConfig = NULL, *pOldNetworkConfig = NULL; 00430 regNetworkProfile_t **pNewNetworks = NULL, **pOldNetworks = NULL; 00431 int i, index; 00432 00433 pOldNetworkConfig = *pNetworkConfig; 00434 pOldNetworks = *pNetworks; 00435 00436 // update the pNewNetworkConfig 00437 pNewNetworkConfig= nwRegNewNetworkConfig(pOldNetworkConfig->size-1); 00438 00439 // update the pNewNetworks 00440 pNewNetworks = g_new0(regNetworkProfile_t *, pNewNetworkConfig->size); 00441 index = nwRegGetNetworkProfileFromList(pOldNetworkConfig, ID); 00442 for (i = 0; i < index; i++) 00443 { 00444 pNewNetworks[i] = pOldNetworks[i]; 00445 } 00446 for (i = index + 1; i < pOldNetworkConfig->size; i++) 00447 { 00448 pNewNetworks[i - 1] = pOldNetworks[i]; 00449 } 00450 00451 // free the memory 00452 regFreeNetworkConfig(pOldNetworkConfig); 00453 regFreeNetworkProfile(pOldNetworks[index]); 00454 g_free(pOldNetworks); 00455 00456 // return 00457 *pNetworkConfig = pNewNetworkConfig; 00458 *pNetworks = pNewNetworks; 00459 }
void nwRegDestroyXpathList | ( | regRegistry_t * | pRegistry | ) |
Definition at line 84 of file erregnwprofiles.c.
00085 { 00086 ERREG_NWPROFILES_LOGPRINTF("entry"); 00087 g_assert(pRegistry); 00088 00089 g_free(pRegistry->xpaths); 00090 pRegistry->xpaths = NULL; 00091 }
int nwRegGetNetworkProfileFromList | ( | const regNetworkConfig_t * | pNetworkConfig, | |
const char * | ID | |||
) |
Definition at line 363 of file erregnwprofiles.c.
00365 { 00366 ERREG_NWPROFILES_LOGPRINTF("entry"); 00367 00368 int index = -1; // return value: -1 = error 00369 int i; 00370 00371 // get the index by walking through the networkList 00372 for (i = 0; i < pNetworkConfig->size; i++) 00373 { 00374 if (!strcmp(pNetworkConfig->networkList[i], ID)) 00375 { 00376 index = i; 00377 break; 00378 } 00379 } 00380 00381 return index; 00382 }
void nwRegInitXpathList | ( | regRegistry_t * | pRegistry | ) |
Definition at line 68 of file erregnwprofiles.c.
00069 { 00070 ERREG_NWPROFILES_LOGPRINTF("entry"); 00071 g_assert(pRegistry); 00072 00073 xpathList_t *xpaths = g_new0(xpathList_t, 1); 00074 g_assert(xpaths); 00075 00076 xpaths->networkProfiles = "/" EL_REGISTRY_ROOT "/" EL_NETWORK_PROFILES; 00077 xpaths->networkProfile = "/" EL_REGISTRY_ROOT "/" EL_NETWORK_PROFILES "/" EL_NETWORK_PROFILE; 00078 xpaths->lastConnect = "/" EL_REGISTRY_ROOT "/" EL_LAST_CONNECT; 00079 xpaths->autoConnectWlan = "/" EL_REGISTRY_ROOT "/" EL_AUTO_CONNECT_WLAN; 00080 00081 pRegistry->xpaths = xpaths; 00082 }
regLoad_t nwRegLoad | ( | regRegistry_t ** | ppRegistry | ) |
Definition at line 268 of file erregnwprofiles.c.
00269 { 00270 ERREG_NWPROFILES_LOGPRINTF("entry"); 00271 00272 const char* path_registry = REG_DIR "/" REG_NWPROFILES_XML_FILE; 00273 const char* path_template = TEMPLATE_DIR "/" REG_NWPROFILES_XML_FILE; 00274 const char* path_xsd = REG_NWPROFILES_XSD_PATH; 00275 00276 regRegistry_t* pRegistry = NULL; 00277 regLoad_t ret = loadOk_t; 00278 00279 // load normal registry file 00280 pRegistry = regParseFiles(path_registry, path_xsd); 00281 if (pRegistry) 00282 { 00283 ERREG_NWPROFILES_LOGPRINTF("Loading nwprofiles registry succeeded."); 00284 ret = loadOk_t; 00285 } 00286 else 00287 { 00288 // open failed: try template registry 00289 pRegistry = regParseFiles(path_template, path_xsd); 00290 if (pRegistry) 00291 { 00292 ERREG_NWPROFILES_WARNPRINTF("Loading nwprofiles registry failed, " 00293 "but loading template succeeded."); 00294 ret = loadTemplate_t; 00295 } 00296 else 00297 { 00298 ERREG_NWPROFILES_ERRORPRINTF("Loading nwprofiles registry failed " 00299 "and loading template failed."); 00300 pRegistry = nwRegLoadFromMinSet(); 00301 if (pRegistry) 00302 { 00303 ret = loadMinSet_t; 00304 } 00305 else 00306 { 00307 ERREG_NWPROFILES_ERRORPRINTF("Loading nwprofiles registry " 00308 "and template and minset failed."); 00309 ret = loadError_t; 00310 } 00311 } 00312 00313 // store the recovered registry values 00314 if (pRegistry) 00315 { 00316 pRegistry->changed = TRUE; 00317 if (erRegGetLockState() == lock_write) 00318 { 00319 regStore(pRegistry, path_registry); 00320 } 00321 } 00322 } 00323 00324 // add frequently used xpaths 00325 if (pRegistry) 00326 { 00327 nwRegInitXpathList(pRegistry); 00328 } 00329 00330 *ppRegistry = pRegistry; 00331 return ret; 00332 00333 }
regNetworkConfig_t* nwRegNewNetworkConfig | ( | int | size | ) |
Definition at line 132 of file erregnwprofiles.c.
00133 { 00134 ERREG_NWPROFILES_LOGPRINTF("entry"); 00135 00136 regNetworkConfig_t *theNetworkConfig = NULL; 00137 00138 theNetworkConfig = g_new0(regNetworkConfig_t, 1); 00139 if (theNetworkConfig) 00140 { 00141 int i = 0; 00142 00143 theNetworkConfig->size = size; 00144 theNetworkConfig->networkList = g_new0(char *, theNetworkConfig->size + 1); 00145 for (i = 0; i < size; i++) 00146 { 00147 theNetworkConfig->networkList[i] = g_strdup_printf("NW_%d", i); 00148 } 00149 theNetworkConfig->networkList[size] = NULL; 00150 } 00151 else 00152 { 00153 ERREG_NWPROFILES_ERRORPRINTF("memory allocation error"); 00154 } 00155 00156 regDumpNetworkConfig(theNetworkConfig); 00157 00158 return theNetworkConfig; 00159 }
regNetworkProfile_t* nwRegNewNetworkProfile | ( | const char * | ID, | |
connection_t | connection | |||
) |
Definition at line 161 of file erregnwprofiles.c.
00162 { 00163 ERREG_NWPROFILES_LOGPRINTF("%s, %d", ID, connection); 00164 00165 regNetworkProfile_t *theNetworkProfile = NULL; 00166 00167 theNetworkProfile = g_new0(regNetworkProfile_t, 1); 00168 if (theNetworkProfile) 00169 { 00170 if (wired_t == connection) 00171 { 00172 theNetworkProfile->name = g_strdup(WIRED_NETWORK_NAME); 00173 } 00174 else if (wireless_t == connection) 00175 { 00176 theNetworkProfile->name = g_strdup(WIRELESS_NETWORK_NAME); 00177 } 00178 else 00179 { 00180 theNetworkProfile->name = g_strdup(ID); 00181 } 00182 00183 // connection 00184 theNetworkProfile->connection = connection; 00185 00186 // address mode 00187 theNetworkProfile->addressMode = DEFAULT_ADDRESS_MODE; 00188 00189 // proxy 00190 theNetworkProfile->proxy = DEFAULT_USE_PROXY; 00191 00192 if (theNetworkProfile->connection == wireless_t) 00193 { 00194 theNetworkProfile->wirelessSettings = g_new0(regWirelessSetting_t, 1); 00195 if (theNetworkProfile->wirelessSettings) 00196 { 00197 // ssid 00198 theNetworkProfile->wirelessSettings->SSID = g_strdup(DEFAULT_WLAN_SSID); 00199 00200 // encrType 00201 theNetworkProfile->wirelessSettings->encrType = DEFAULT_WLAN_ENCRYPTION_TYPE; 00202 if (theNetworkProfile->wirelessSettings->encrType != encr_none_t) 00203 { 00204 // encrKey 00205 theNetworkProfile->wirelessSettings->encrKey = g_strdup(DEFAULT_WLAN_ENCRYPTION_KEY); 00206 } 00207 00208 // wlan broadcast 00209 theNetworkProfile->wirelessSettings->broadcast = DEFAULT_WLAN_BROADCAST; 00210 } 00211 else 00212 { 00213 ERREG_NWPROFILES_ERRORPRINTF("memory allocation error"); 00214 } 00215 } 00216 } 00217 else 00218 { 00219 ERREG_NWPROFILES_ERRORPRINTF("memory allocation error"); 00220 } 00221 00222 regDumpNetworkProfile(ID, theNetworkProfile); 00223 00224 return theNetworkProfile; 00225 }
void nwRegNewNetworkProfiles | ( | regNetworkConfig_t ** | pNetworkConfig, | |
regNetworkProfile_t *** | pNetworks | |||
) |
Definition at line 228 of file erregnwprofiles.c.
00229 { 00230 ERREG_NWPROFILES_LOGPRINTF("entry"); 00231 00232 regNetworkConfig_t *theNetworkConfig = NULL; 00233 regNetworkProfile_t **theNetworks = NULL; 00234 00235 theNetworkConfig = nwRegNewNetworkConfig(2); 00236 if (theNetworkConfig) 00237 { 00238 theNetworks = g_new0(regNetworkProfile_t *, theNetworkConfig->size); 00239 if (theNetworks) 00240 { 00241 theNetworks[0] = nwRegNewNetworkProfile(theNetworkConfig->networkList[0], wired_t); 00242 theNetworks[1] = nwRegNewNetworkProfile(theNetworkConfig->networkList[1], wireless_t); 00243 } 00244 else 00245 { 00246 ERREG_NWPROFILES_ERRORPRINTF("memory error"); 00247 00248 regFreeNetworkConfig(theNetworkConfig); 00249 theNetworkConfig = NULL; 00250 } 00251 } 00252 else 00253 { 00254 ERREG_NWPROFILES_ERRORPRINTF("memory error"); 00255 } 00256 00257 *pNetworkConfig = theNetworkConfig; 00258 *pNetworks = theNetworks; 00259 }
void nwRegSetNetworkProfileDefault | ( | regNetworkConfig_t ** | pNetworkConfig, | |
regNetworkProfile_t *** | pNetworks, | |||
const char * | ID | |||
) |
Definition at line 463 of file erregnwprofiles.c.
00465 { 00466 ERREG_NWPROFILES_LOGPRINTF("entry"); 00467 00468 regNetworkConfig_t *pOldNetworkConfig = NULL; 00469 regNetworkProfile_t **pNewNetworks = NULL, **pOldNetworks = NULL; 00470 regNetworkProfile_t *pNetworkProfile = NULL; 00471 int i, index; 00472 00473 pOldNetworkConfig = *pNetworkConfig; 00474 pOldNetworks = *pNetworks; 00475 00476 // update the pNewNetworks 00477 pNewNetworks = g_new0(regNetworkProfile_t *, pOldNetworkConfig->size); 00478 index = nwRegGetNetworkProfileFromList(pOldNetworkConfig, ID); 00479 for (i = 0; i < pOldNetworkConfig->size; i++) 00480 { 00481 pNetworkProfile = pOldNetworks[i]; 00482 00483 if (i < index) 00484 { 00485 pNewNetworks[i + 1] = pOldNetworks[i]; 00486 } 00487 else if (i == index) 00488 { 00489 pNewNetworks[0] = pNetworkProfile; 00490 } 00491 else // if (i > index) 00492 { 00493 pNewNetworks[i] = pOldNetworks[i]; 00494 } 00495 } 00496 00497 // free the memory 00498 g_free(pOldNetworks); 00499 00500 // return 00501 *pNetworks = pNewNetworks; 00502 }
gboolean nwRegStore | ( | regRegistry_t * | pRegistry | ) |
Definition at line 346 of file erregnwprofiles.c.
00347 { 00348 g_assert(pRegistry); 00349 00350 return regStore(pRegistry, REG_DIR "/" REG_NWPROFILES_XML_FILE); 00351 }
void nwRegUnload | ( | regRegistry_t * | pRegistry | ) |
Definition at line 335 of file erregnwprofiles.c.
00336 { 00337 ERREG_NWPROFILES_LOGPRINTF("entry"); 00338 00339 if (pRegistry) 00340 { 00341 nwRegDestroyXpathList(pRegistry); 00342 regDestroy(pRegistry); 00343 } 00344 }