Пример #1
0
func (p *pidginImporter) importAllFrom(accountsFile, prefsFile, blistFile, keyFile, fprFile string) (*config.ApplicationConfig, bool) {
	accounts, ok1 := p.importAccounts(accountsFile)
	globalPrefs, ok2 := p.importGlobalPrefs(prefsFile)
	peerPrefs, ok3 := p.importPeerPrefs(blistFile)
	keys, ok4 := p.importKeysFrom(keyFile)
	fprs, ok5 := p.importFingerprintsFrom(fprFile)

	if !ok1 {
		return nil, false
	}

	res := &config.ApplicationConfig{}
	for name, ac := range accounts {
		res.Add(ac)
		if ok2 {
			if globalPrefs.enabled {
				if globalPrefs.onlyPrivate {
					ac.AlwaysEncrypt = true
					ac.OTRAutoStartSession = true
				} else if globalPrefs.automatic {
					ac.OTRAutoStartSession = true
					ac.OTRAutoAppendTag = true
				}
			} else {
				ac.AlwaysEncrypt = false
			}
		}
		if ok3 {
			if ss, ok := peerPrefs[name]; ok {
				for p, sp := range ss {
					if sp.enabled {
						if sp.onlyPrivate {
							ac.AlwaysEncryptWith = append(ac.AlwaysEncryptWith, p)
						}
					} else {
						ac.DontEncryptWith = append(ac.DontEncryptWith, p)
					}
				}
			}
		}
		if ok4 {
			if kk, ok := keys[name]; ok {
				ac.PrivateKeys = [][]byte{kk}
			}
		}
		if ok5 {
			if fprs, ok := fprs[name]; ok {
				ac.KnownFingerprints = make([]config.KnownFingerprint, len(fprs))
				sort.Sort(config.ByNaturalOrder(fprs))
				for ix, fpr := range fprs {
					ac.KnownFingerprints[ix] = *fpr
				}
			}
		}
	}

	sort.Sort(config.ByAccountNameAlphabetic(res.Accounts))

	return res, true
}
Пример #2
0
func mergeAll(
	accounts map[string]gajimAccountInfo,
	accountOTRSettings map[string]gajimOTRSettings,
	accountAndPeerOTRSettings map[gajimAccountAndPeer]gajimOTRSettings,
	fprs map[string][]*config.KnownFingerprint,
	keys map[string][]byte,
) *config.ApplicationConfig {

	res := &config.ApplicationConfig{}

	for name, ac := range accounts {
		if name != "Local" {
			a := mergeAccountInformation(ac, accountOTRSettings[name], getPeerSettingsFor(name, accountAndPeerOTRSettings), fprs[name], keys[name])
			res.Add(a)
		}
	}

	sort.Sort(config.ByAccountNameAlphabetic(res.Accounts))

	return res
}
Пример #3
0
func (p *adiumImporter) importAllFrom(accountMappingsFile, accountsFile, prefsFile, blistFile, keyFile, fprFile string) (*config.ApplicationConfig, bool) {
	accountMappings, ok0 := p.readAccountMappings(accountMappingsFile)
	accounts, ok1 := p.importAccounts(accountsFile)
	globalPrefs, ok2 := p.importGlobalPrefs(prefsFile)
	peerPrefs, ok3 := p.importPeerPrefs(blistFile)
	keysRaw, ok4 := p.importKeysFrom(keyFile)
	fprsRaw, ok5 := p.importFingerprintsFrom(fprFile)

	if !ok0 || !ok1 {
		return nil, false
	}

	keys := make(map[string][]byte)
	for k, v := range keysRaw {
		keys[accountMappings[k].uid] = v
	}

	fprs := make(map[string][]*config.KnownFingerprint)
	for k, v := range fprsRaw {
		fprs[accountMappings[k].uid] = v
	}

	res := &config.ApplicationConfig{}
	for name, ac := range accounts {
		res.Add(ac)
		if ok2 {
			if globalPrefs.enabled {
				if globalPrefs.onlyPrivate {
					ac.AlwaysEncrypt = true
					ac.OTRAutoStartSession = true
				} else if globalPrefs.automatic {
					ac.OTRAutoStartSession = true
					ac.OTRAutoAppendTag = true
				}
			} else {
				ac.AlwaysEncrypt = false
			}
		}
		if ok3 {
			if ss, ok := peerPrefs[name]; ok {
				for p, sp := range ss {
					if sp.enabled {
						if sp.onlyPrivate {
							ac.AlwaysEncryptWith = append(ac.AlwaysEncryptWith, p)
						}
					} else {
						ac.DontEncryptWith = append(ac.DontEncryptWith, p)
					}
				}
			}
		}
		if ok4 {
			if kk, ok := keys[name]; ok {
				ac.PrivateKeys = [][]byte{kk}
			}
		}
		if ok5 {
			if fprs, ok := fprs[name]; ok {
				ac.Peers = nil
				sort.Sort(config.LegacyByNaturalOrder(fprs))
				for _, kfpr := range fprs {
					fpr := ac.EnsurePeer(kfpr.UserID).EnsureHasFingerprint(kfpr.Fingerprint)
					if !kfpr.Untrusted {
						fpr.Trusted = true
					}
				}
			}
		}
	}

	sort.Sort(config.ByAccountNameAlphabetic(res.Accounts))

	return res, true
}