int single_test(const char *string, GSM_Error expected) { GSM_Feature features[GSM_MAX_PHONE_FEATURES + 1]; GSM_Error real; real = GSM_SetFeatureString(features, string); if (real != expected) { printf("Failed parsing of %s (got %s, expected %s)\n", string, GSM_FeatureToString(real), GSM_FeatureToString(expected)); return 1; } return 0; }
GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num) { INI_Section *h; unsigned char section[50]={0}; gboolean found = FALSE; char *Temp = NULL; #if defined(WIN32) || defined(DJGPP) static const char *DefaultPort = "com2:"; #else static const char *DefaultPort = "/dev/ttyUSB0"; #endif static const char *DefaultModel = ""; static const char *DefaultConnection = "at"; static gboolean DefaultSynchronizeTime = FALSE; static const char *DefaultDebugFile = ""; static const char *DefaultDebugLevel = ""; static gboolean DefaultLockDevice = FALSE; static gboolean DefaultStartInfo = FALSE; /* By default all debug output will go to one filedescriptor */ static const gboolean DefaultUseGlobalDebugFile = TRUE; GSM_Error error = ERR_UNKNOWN; cfg->UseGlobalDebugFile = DefaultUseGlobalDebugFile; /* If we don't have valid config, bail out */ if (cfg_info == NULL) { error = ERR_UNCONFIGURED; goto fail; } /* Which section should we read? */ if (num == 0) { snprintf(section, sizeof(section) - 1, "gammu"); } else { snprintf(section, sizeof(section) - 1, "gammu%i", num); } /* Scan for section */ for (h = cfg_info; h != NULL; h = h->Next) { if (strcasecmp(section, h->SectionName) == 0) { found = TRUE; break; } } if (!found) { error = ERR_NONE_SECTION; goto fail; } /* Set device name */ free(cfg->Device); cfg->Device = INI_GetValue(cfg_info, section, "device", FALSE); if (!cfg->Device) { cfg->Device = INI_GetValue(cfg_info, section, "port", FALSE); if (!cfg->Device) { cfg->Device = strdup(DefaultPort); } else { cfg->Device = strdup(cfg->Device); } } else { cfg->Device = strdup(cfg->Device); } /* Set connection type */ free(cfg->Connection); cfg->Connection = INI_GetValue(cfg_info, section, "connection", FALSE); if (cfg->Connection == NULL) { cfg->Connection = strdup(DefaultConnection); } else { cfg->Connection = strdup(cfg->Connection); } /* Set time sync */ cfg->SyncTime = INI_GetBool(cfg_info, section, "synchronizetime", DefaultSynchronizeTime); /* Set debug file */ free(cfg->DebugFile); cfg->DebugFile = INI_GetValue(cfg_info, section, "logfile", FALSE); if (cfg->DebugFile == NULL) { cfg->DebugFile = strdup(DefaultDebugFile); } else { cfg->DebugFile = strdup(cfg->DebugFile); GSM_ExpandUserPath(&cfg->DebugFile); } /* Set file locking */ cfg->LockDevice = INI_GetBool(cfg_info, section, "use_locking", DefaultLockDevice); /* Set model */ Temp = INI_GetValue(cfg_info, section, "model", FALSE); if (Temp == NULL || strcmp(Temp, "auto") == 0) { strcpy(cfg->Model,DefaultModel); } else { if (strlen(Temp) >= sizeof(cfg->Model)) Temp[sizeof(cfg->Model) - 1] = '\0'; strcpy(cfg->Model,Temp); } /* Set Log format */ Temp = INI_GetValue(cfg_info, section, "logformat", FALSE); if (Temp == NULL) { strcpy(cfg->DebugLevel,DefaultDebugLevel); } else { if (strlen(Temp) >= sizeof(cfg->DebugLevel)) Temp[sizeof(cfg->DebugLevel) - 1] = '\0'; strcpy(cfg->DebugLevel,Temp); } /* Set startup info */ cfg->StartInfo = INI_GetBool(cfg_info, section, "startinfo", DefaultStartInfo); /* Read localised strings for some phones */ Temp = INI_GetValue(cfg_info, section, "reminder", FALSE); if (Temp == NULL) { strcpy(cfg->TextReminder,"Reminder"); } else { if (strlen(Temp) >= sizeof(cfg->TextReminder)) Temp[sizeof(cfg->TextReminder) - 1] = '\0'; strcpy(cfg->TextReminder,Temp); } Temp = INI_GetValue(cfg_info, section, "meeting", FALSE); if (Temp == NULL) { strcpy(cfg->TextMeeting,"Meeting"); } else { if (strlen(Temp) >= sizeof(cfg->TextMeeting)) Temp[sizeof(cfg->TextMeeting) - 1] = '\0'; strcpy(cfg->TextMeeting,Temp); } Temp = INI_GetValue(cfg_info, section, "call", FALSE); if (Temp == NULL) { strcpy(cfg->TextCall,"Call"); } else { if (strlen(Temp) >= sizeof(cfg->TextCall)) Temp[sizeof(cfg->TextCall) - 1] = '\0'; strcpy(cfg->TextCall,Temp); } Temp = INI_GetValue(cfg_info, section, "birthday", FALSE); if (Temp == NULL) { strcpy(cfg->TextBirthday,"Birthday"); } else { if (strlen(Temp) >= sizeof(cfg->TextBirthday)) Temp[sizeof(cfg->TextBirthday) - 1] = '\0'; strcpy(cfg->TextBirthday,Temp); } Temp = INI_GetValue(cfg_info, section, "memo", FALSE); if (Temp == NULL) { strcpy(cfg->TextMemo,"Memo"); } else { if (strlen(Temp) >= sizeof(cfg->TextMemo)) Temp[sizeof(cfg->TextMemo) - 1] = '\0'; strcpy(cfg->TextMemo,Temp); } /* Phone features */ Temp = INI_GetValue(cfg_info, section, "features", FALSE); if (Temp == NULL) { cfg->PhoneFeatures[0] = 0; } else { error = GSM_SetFeatureString(cfg->PhoneFeatures, Temp); if (error != ERR_NONE) { goto fail; } } return ERR_NONE; fail: /* Special case, this config needs to be somehow valid */ if (num == 0) { cfg->Device = strdup(DefaultPort); cfg->Connection = strdup(DefaultConnection); cfg->SyncTime = DefaultSynchronizeTime; cfg->DebugFile = strdup(DefaultDebugFile); cfg->LockDevice = DefaultLockDevice; strcpy(cfg->Model,DefaultModel); strcpy(cfg->DebugLevel,DefaultDebugLevel); cfg->StartInfo = DefaultStartInfo; strcpy(cfg->TextReminder,"Reminder"); strcpy(cfg->TextMeeting,"Meeting"); strcpy(cfg->TextCall,"Call"); strcpy(cfg->TextBirthday,"Birthday"); strcpy(cfg->TextMemo,"Memo"); cfg->PhoneFeatures[0] = 0; /* Indicate that we used defaults */ return ERR_USING_DEFAULTS; } return error; }