#include <glib.h>
#include <liberregxml/erregapi.h>
#include "scanThread.h"
Go to the source code of this file.
Copyright (C) 2007 iRex Technologies BV.
Definition in file commonData.h.
#define MAX_DIALUP_PROFILES 6 |
Definition at line 38 of file commonData.h.
#define MAX_WIRED_PROFILES 6 |
Definition at line 36 of file commonData.h.
#define MAX_WIRELESS_PROFILES 12 |
Definition at line 37 of file commonData.h.
#define REDIRECT_URL "https://ids.irexnet.com:443/redirector" |
Definition at line 34 of file commonData.h.
enum cmgrConnectType_t |
Definition at line 41 of file commonData.h.
00042 { 00043 cmgrConnectUnknown_e, 00044 cmgrConnectIDS_e, 00045 cmgrConnectPCShare_e, 00046 cmgrConnectUndef_e 00047 } cmgrConnectType_t;
void common_data_destroy | ( | void | ) |
Definition at line 63 of file commonData.c.
00064 { 00065 CN_LOGPRINTF("entry"); 00066 00067 if (g_netConfig) 00068 { 00069 erRegFreeNetworkProfiles(g_netConfig, g_networks); 00070 g_networks = NULL; 00071 g_netConfig = NULL; 00072 } 00073 00074 if (g_pcConfig) 00075 { 00076 erRegFreePCProfiles(g_pcConfig, g_pcshares); 00077 g_pcConfig = NULL; 00078 g_pcshares = NULL; 00079 } 00080 }
void common_data_destroy_network_profiles | ( | networkProfile_t * | pNetworks, | |
guint | nProfiles | |||
) |
Definition at line 531 of file commonData.c.
00533 { 00534 CN_LOGPRINTF("entry"); 00535 free_network_profile_t(pNetworks, nProfiles); 00536 }
int common_data_get_n_profiles | ( | void | ) |
Definition at line 180 of file commonData.c.
00181 { 00182 CN_LOGPRINTF("entry"); 00183 00184 g_return_val_if_fail((g_netConfig != NULL), 0); 00185 return g_netConfig->size; 00186 }
const regPCProfile_t* common_data_get_pcsharedata | ( | const gint | index | ) |
Definition at line 275 of file commonData.c.
00276 { 00277 CN_LOGPRINTF("entry: index [%d]", index); 00278 00279 g_return_val_if_fail((g_pcConfig != NULL), NULL); 00280 00281 if (index < g_pcConfig->size) 00282 { 00283 return g_pcshares[index]; 00284 } 00285 else 00286 { 00287 return NULL; 00288 } 00289 }
int common_data_get_profile_index | ( | networkProfile_t * | pNetworks, | |
int | nProfiles, | |||
int | regIndex | |||
) |
Definition at line 538 of file commonData.c.
00541 { 00542 CN_LOGPRINTF("entry"); 00543 00544 const networkProfile_t *settings; 00545 int i, j; 00546 int profileIndex = -1; 00547 00548 if ((nProfiles > 0) && (pNetworks)) 00549 { 00550 for (i = 0; i < nProfiles; i++) 00551 { 00552 settings = &pNetworks[i]; 00553 if (settings 00554 && settings->nRegProfiles 00555 && settings->regSettingsList 00556 && settings->regIndexList) 00557 { 00558 for (j = 0; j < settings->nRegProfiles; j++) 00559 { 00560 if (settings->regIndexList[j] == regIndex) 00561 { 00562 profileIndex = i; 00563 break; 00564 } 00565 } 00566 } 00567 } 00568 } 00569 00570 return profileIndex; 00571 }
const regNetworkProfile_t* common_data_get_profiledata | ( | const gint | index | ) |
Definition at line 209 of file commonData.c.
00210 { 00211 CN_LOGPRINTF("entry: index [%d]", index); 00212 00213 g_return_val_if_fail((g_netConfig != NULL), NULL); 00214 00215 if (index < g_netConfig->size) 00216 { 00217 return g_networks[index]; 00218 } 00219 else 00220 { 00221 return NULL; 00222 } 00223 }
int common_data_get_reg_index | ( | networkProfile_t * | pNetworks, | |
int | nProfiles, | |||
int | profileIndex | |||
) |
Definition at line 573 of file commonData.c.
00576 { 00577 CN_LOGPRINTF("entry"); 00578 00579 const networkProfile_t *settings; 00580 int regIndex = -1; 00581 00582 if ((nProfiles > 0) && (pNetworks)) 00583 { 00584 if ((profileIndex >= 0) && (profileIndex < nProfiles)) 00585 { 00586 settings = &pNetworks[profileIndex]; 00587 if (settings 00588 && (settings->nRegProfiles > 0) 00589 && settings->regSettingsList 00590 && settings->regIndexList) 00591 { 00592 if ((settings->nActiveIndex >= 0) 00593 && (settings->nActiveIndex < settings->nRegProfiles)) 00594 { 00595 regIndex = settings->regIndexList[settings->nActiveIndex]; 00596 } 00597 } 00598 } 00599 } 00600 00601 return regIndex; 00602 }
void common_data_init | ( | void | ) |
Definition at line 52 of file commonData.c.
00053 { 00054 CN_LOGPRINTF("entry"); 00055 00056 // Read all network profiles from registry 00057 erRegGetNetworkProfiles(&g_netConfig, &g_networks); 00058 00059 // Read all PC profiles from registry 00060 erRegGetPCProfiles(&g_pcConfig, &g_pcshares); 00061 }
int common_data_init_network_profiles | ( | connection_t | networkType, | |
networkProfile_t ** | pNetworks | |||
) |
Definition at line 467 of file commonData.c.
00469 { 00470 int i, profileIndex; 00471 int nRegNetworks; 00472 const regNetworkProfile_t* pRegNetwork; 00473 networkProfile_t* pNetwork; 00474 int nNetworks; 00475 networkProfile_t* pNetworksList; 00476 00477 CN_LOGPRINTF("entry networkType[%d]", networkType); 00478 00479 // get how many profiles in registry 00480 nRegNetworks = common_data_get_n_profiles(); 00481 if (nRegNetworks == 0) 00482 { 00483 CN_WARNPRINTF("No network profiles in registry."); 00484 return 0; 00485 } 00486 00487 // get how many 'networkType' profiles 00488 nNetworks = common_data_get_n_profiles_by_networktype(networkType); 00489 00490 // sepcial case 00491 if (nNetworks == 0) 00492 { 00493 CN_WARNPRINTF("Can't find any [%d] network profiles.", networkType); 00494 return 0; 00495 } 00496 00497 // get the 'networkType' profiles 00498 pNetworksList = new_network_profile_t(nNetworks); 00499 g_return_val_if_fail(pNetworksList != NULL, 0); 00500 00501 profileIndex = 0; 00502 for (i = 0; i < nRegNetworks; i++) 00503 { 00504 pRegNetwork = common_data_get_profiledata(i); 00505 if (pRegNetwork && pRegNetwork->connection == networkType) 00506 { 00507 pNetwork = &pNetworksList[profileIndex]; 00508 00509 // scanSettings 00510 pNetwork->scanSettings = NULL; 00511 // regSettingsList 00512 pNetwork->regSettingsList = g_new0(regNetworkProfile_t*, 1); 00513 pNetwork->regSettingsList[0] = erRegDupNetworkProfile(pRegNetwork); 00514 // regIndexList 00515 pNetwork->regIndexList = g_new0(int, 1); 00516 pNetwork->regIndexList[0] = i; 00517 // nRegProfiles 00518 pNetwork->nRegProfiles = 1; 00519 // nActiveIndex 00520 pNetwork->nActiveIndex = 0; 00521 00522 profileIndex++; 00523 } 00524 } 00525 00526 CN_LOGPRINTF("return nNetworks=%d", nNetworks); 00527 *pNetworks = pNetworksList; 00528 return nNetworks; 00529 }
gboolean common_data_reach_max_profiles | ( | connection_t | networkType | ) |
Definition at line 291 of file commonData.c.
00292 { 00293 CN_LOGPRINTF("entry networkType[%d]", networkType); 00294 int num, max; 00295 00296 switch (networkType) 00297 { 00298 case wired_t: 00299 max = MAX_WIRED_PROFILES; 00300 break; 00301 case wireless_t: 00302 max = MAX_WIRELESS_PROFILES; 00303 break; 00304 case dialup_t: 00305 max = MAX_DIALUP_PROFILES; 00306 break; 00307 default: 00308 CN_WARNPRINTF("unknow networkType[%d]", networkType); 00309 max = 0; 00310 break; 00311 } 00312 00313 num = common_data_get_n_profiles_by_networktype(networkType); 00314 CN_LOGPRINTF("num[%d] >= max[%d] ?", num, max); 00315 return ((num >= max) ? TRUE : FALSE); 00316 }
guint common_data_remove_profile | ( | guint | index | ) |
Definition at line 247 of file commonData.c.
00248 { 00249 CN_LOGPRINTF("entry: index [%d]", index); 00250 00251 int i; 00252 guint num_profiles = g_netConfig->size; 00253 g_return_val_if_fail((index < num_profiles), num_profiles); 00254 00255 // remove the last network ID 00256 g_free( g_netConfig->networkList[num_profiles-1] ); 00257 g_netConfig->networkList[num_profiles-1] = NULL; 00258 00259 // remove the specified network setting 00260 g_free( g_networks[index] ); 00261 for (i = index ; i < num_profiles - 1 ; i++) 00262 { 00263 g_networks[i] = g_networks[i+1]; 00264 } 00265 g_networks[num_profiles-1] = NULL; 00266 00267 // update profile count and report 00268 g_netConfig->size = num_profiles - 1; 00269 00270 g_configChanged = TRUE; 00271 00272 return g_netConfig->size; 00273 }
gboolean common_data_set_profiledata | ( | gint | index, | |
const regNetworkProfile_t * | setting, | |||
const gboolean | preferred | |||
) |
Definition at line 322 of file commonData.c.
00325 { 00326 gboolean addNew = FALSE; 00327 gboolean reachMax = FALSE; 00328 gboolean ok = FALSE; 00329 regNetworkProfile_t* tmp_setting; 00330 00331 CN_LOGPRINTF("entry: index [%d]", index); 00332 00333 g_return_val_if_fail((g_netConfig != NULL), ok); 00334 g_return_val_if_fail((index <= g_netConfig->size), ok); 00335 00336 // add new profile if needed 00337 while (g_netConfig->size <= index) 00338 { 00339 // before adding the new profile, check whether can add it or not 00340 g_return_val_if_fail(setting != NULL, ok); 00341 reachMax = common_data_reach_max_profiles(setting->connection); 00342 g_return_val_if_fail(reachMax == FALSE, ok); 00343 00344 common_data_add_profile(); 00345 addNew = TRUE; 00346 } 00347 00348 // make preferred if needed 00349 if (preferred && index < g_netConfig->size) 00350 { 00351 tmp_setting = g_networks[index]; 00352 while (index > 0) 00353 { 00354 g_networks[index] = g_networks[index-1]; 00355 --index; 00356 } 00357 g_networks[index] = tmp_setting; 00358 } 00359 00360 if ( setting == NULL 00361 || setting->name == NULL 00362 || setting->name[0] == '\0') 00363 { 00364 // empty setting 00365 common_data_remove_profile(index); 00366 } 00367 else 00368 { 00369 prepare_registry_write(); 00370 00371 // store profile 00372 gchar* ID = g_netConfig->networkList[index]; 00373 if ( erRegSetNetworkProfile(ID, (regNetworkProfile_t*)setting) 00374 && erRegValidate() ) 00375 { 00376 // refresh local administration if succeeded 00377 erRegFreeNetworkProfile( g_networks[index] ); 00378 g_networks[index] = erRegGetNetworkProfile(ID); 00379 ok = TRUE; 00380 } 00381 else 00382 { 00383 CN_LOGPRINTF("Set profile [%d] [%s] failed", index, ID); 00384 if (addNew) 00385 { 00386 // undo the changes if failed 00387 common_data_remove_profile(index); 00388 } 00389 } 00390 00391 do_registry_write(); 00392 } 00393 00394 g_configChanged = TRUE; 00395 return ok; 00396 }
void common_data_store | ( | void | ) |
Definition at line 82 of file commonData.c.
00083 { 00084 CN_LOGPRINTF("entry"); 00085 00086 if ( g_configChanged == FALSE) 00087 { 00088 // nothing to save 00089 return; 00090 } 00091 00092 gint index; 00093 char* theID; 00094 gboolean NWStored; 00095 regNetworkConfig_t* theNetworkConfig = NULL; 00096 regNetworkProfile_t* theNetworkProfile = NULL; 00097 00098 // refresh registry data 00099 prepare_registry_write(); 00100 00101 // remove all network profiles from registry ... 00102 theNetworkConfig = erRegGetNetworkConfig(); 00103 if (theNetworkConfig) 00104 { 00105 // remove old network profiles 00106 for (index = 0; index < theNetworkConfig->size; index++) 00107 { 00108 theID = theNetworkConfig->networkList[index]; 00109 if (erRegRemoveNetworkProfile(theID) == FALSE) 00110 { 00111 CN_WARNPRINTF("could not remove %s", 00112 theNetworkConfig->networkList[index]); 00113 } 00114 } 00115 erRegFreeNetworkConfig(theNetworkConfig); 00116 00117 // remove old netfork config 00118 erRegRemoveNetworkConfig(); 00119 } 00120 else 00121 { 00122 CN_WARNPRINTF("could not retrieve theNetworkConfig"); 00123 } 00124 00125 // ... then write our network profiles to registry ... 00126 theNetworkConfig = g_new0(regNetworkConfig_t, 1); 00127 theNetworkConfig->size = g_netConfig->size; 00128 CN_STOREPRINTF("theNetworkConfig->size %d", theNetworkConfig->size); 00129 theNetworkConfig->networkList = g_new0(gchar*, 00130 (theNetworkConfig->size + 1)); 00131 00132 for (index = 0 ; index < g_netConfig->size ; index++) 00133 { 00134 theNetworkProfile = g_networks[index]; 00135 00136 if (theNetworkProfile == NULL) 00137 { 00138 CN_STOREPRINTF("theNetworkProfile = NULL"); 00139 } 00140 else 00141 { 00142 theID = g_strdup_printf("NW_%d", index); 00143 NWStored = erRegSetNetworkProfile(theID, theNetworkProfile); 00144 00145 if (NWStored) 00146 { 00147 CN_STOREPRINTF("id %s was stored", theID); 00148 theNetworkConfig->networkList[index] = g_strdup(theID); 00149 } 00150 else 00151 { 00152 CN_STOREPRINTF("id %s was NOT stored", theID); 00153 if (theNetworkConfig->size > 0) 00154 { 00155 theNetworkConfig->size = theNetworkConfig->size - 1; 00156 } 00157 } 00158 } 00159 } 00160 if (theNetworkConfig->size > 0) 00161 { 00162 NWStored = erRegSetNetworkConfig(theNetworkConfig); 00163 CN_STOREPRINTF("erRegSetNetworkConfig() returned %s", 00164 (NWStored == TRUE) ? "TRUE" : "FALSE"); 00165 } 00166 erRegFreeNetworkConfig(theNetworkConfig); 00167 00168 // 00169 // ... and store registry to disk 00170 do_registry_write(); 00171 CN_STOREPRINTF("Stored registry"); 00172 g_configChanged = FALSE; 00173 }