コード例 #1
0
ファイル: session.go プロジェクト: PMaynard/coyim
func (s *Session) receivedClientPresence(stanza *xmpp.ClientPresence) bool {
	switch stanza.Type {
	case "subscribe":
		s.R.SubscribeRequest(stanza.From, either(stanza.ID, "0000"), s.GetConfig().ID())
		s.publishPeerEvent(
			SubscriptionRequest,
			xmpp.RemoveResourceFromJid(stanza.From),
		)
	case "unavailable":
		if !s.R.PeerBecameUnavailable(stanza.From) {
			return true
		}

		s.publishEvent(PresenceEvent{
			Session:        s,
			ClientPresence: stanza,
			Gone:           true,
		})
	case "":
		if !s.R.PeerPresenceUpdate(stanza.From, stanza.Show, stanza.Status, s.GetConfig().ID()) {
			return true
		}

		s.publishEvent(PresenceEvent{
			Session:        s,
			ClientPresence: stanza,
			Gone:           false,
		})
	case "subscribed":
		s.R.Subscribed(stanza.From)
		s.publishPeerEvent(
			Subscribed,
			xmpp.RemoveResourceFromJid(stanza.From),
		)
	case "unsubscribe":
		s.R.Unsubscribed(stanza.From)
		s.publishPeerEvent(
			Unsubscribe,
			xmpp.RemoveResourceFromJid(stanza.From),
		)
	case "unsubscribed":
		// Ignore
	case "error":
		s.warn(fmt.Sprintf("Got a presence error from %s: %#v\n", stanza.From, stanza.Error))
		s.R.LatestError(stanza.From, stanza.Error.Code, stanza.Error.Type, stanza.Error.Any.Space+" "+stanza.Error.Any.Local)
	default:
		s.info(fmt.Sprintf("unrecognized presence: %#v", stanza))
	}
	return true
}
コード例 #2
0
ファイル: session_events.go プロジェクト: PMaynard/coyim
func (c *cliUI) handlePresenceEvent(ev session.PresenceEvent) {
	if ev.Session.GetConfig().HideStatusUpdates {
		return
	}

	from := xmpp.RemoveResourceFromJid(ev.From)

	var line []byte
	line = append(line, []byte(fmt.Sprintf("   (%s) ", time.Now().Format(time.Kitchen)))...)
	line = append(line, c.term.Escape.Magenta...)
	line = append(line, []byte(from)...)
	line = append(line, ':')
	line = append(line, c.term.Escape.Reset...)
	line = append(line, ' ')

	if ev.Gone {
		line = append(line, []byte("offline")...)
	} else if len(ev.Show) > 0 {
		line = append(line, []byte(ev.Show)...)
	} else {
		line = append(line, []byte("online")...)
	}
	line = append(line, ' ')
	line = append(line, []byte(ev.Status)...)
	line = append(line, '\n')
	c.term.Write(line)
}
コード例 #3
0
ファイル: session.go プロジェクト: 0x27/coyim
func (s *Session) processClientMessage(stanza *xmpp.ClientMessage) {
	log.Printf("-> Stanza %#v\n", stanza)

	from := xmpp.RemoveResourceFromJid(stanza.From)

	//TODO: investigate which errors are recoverable
	//https://xmpp.org/rfcs/rfc3920.html#stanzas-error
	if stanza.Type == "error" && stanza.Error != nil {
		s.alert(fmt.Sprintf("Error reported from %s: %#v", from, stanza.Error))
		return
	}

	//TODO: Add a more general solution to XEP's
	if len(stanza.Body) == 0 && len(stanza.Extensions) > 0 {
		//Extension only stanza
		return
	}

	var err error
	var messageTime time.Time
	if stanza.Delay != nil && len(stanza.Delay.Stamp) > 0 {
		// An XEP-0203 Delayed Delivery <delay/> element exists for
		// this message, meaning that someone sent it while we were
		// offline. Let's show the timestamp for when the message was
		// sent, rather than time.Now().
		messageTime, err = time.Parse(time.RFC3339, stanza.Delay.Stamp)
		if err != nil {
			s.alert("Can not parse Delayed Delivery timestamp, using quoted string instead.")
		}
	} else {
		messageTime = time.Now()
	}

	s.receiveClientMessage(from, messageTime, stanza.Body)
}
コード例 #4
0
ファイル: peer.go プロジェクト: 0x27/coyim
func peerWithPendingSubscribe(jid, id, belongsTo string) *Peer {
	return &Peer{
		Jid:                xmpp.RemoveResourceFromJid(jid),
		PendingSubscribeID: id,
		BelongsTo:          belongsTo,
	}
}
コード例 #5
0
ファイル: peer.go プロジェクト: 0x27/coyim
// PeerWithState returns a new Peer that contains the given state information
func PeerWithState(jid, status, statusMsg, belongsTo string) *Peer {
	return &Peer{
		Jid:       xmpp.RemoveResourceFromJid(jid),
		Status:    status,
		StatusMsg: statusMsg,
		Online:    true,
		BelongsTo: belongsTo,
	}
}
コード例 #6
0
ファイル: peer.go プロジェクト: 0x27/coyim
// PeerFrom returns a new Peer that contains the same information as the RosterEntry given
func PeerFrom(e xmpp.RosterEntry, belongsTo string) *Peer {
	return &Peer{
		Jid:          xmpp.RemoveResourceFromJid(e.Jid),
		Subscription: e.Subscription,
		Name:         e.Name,
		Groups:       toSet(e.Group...),
		BelongsTo:    belongsTo,
	}
}
コード例 #7
0
ファイル: list.go プロジェクト: PMaynard/coyim
// Remove returns the Peer with the jid from the List - it will first turn the jid into a bare jid.
// It returns true if it could remove the entry and false otherwise. It also returns the removed entry.
func (l *List) Remove(jid string) (*Peer, bool) {
	j := xmpp.RemoveResourceFromJid(jid)

	if v, ok := l.peers[j]; ok {
		delete(l.peers, j)
		return v, true
	}

	return nil, false
}
コード例 #8
0
ファイル: pidgin_like.go プロジェクト: PMaynard/coyim
func importPeerPrefsPidginStyle(f string) (map[string]map[string]*pidginOTRSettings, bool) {
	content, err := ioutil.ReadFile(f)
	if err != nil {
		return nil, false
	}

	var a pidginBlistXML
	err = xml.Unmarshal(content, &a)
	if err != nil {
		return nil, false
	}

	res := make(map[string]map[string]*pidginOTRSettings)

	for _, p := range a.Peers {
		if p.Protocol == "prpl-jabber" {
			haveOTR := false
			settings := &pidginOTRSettings{}
			for _, s := range p.Settings {
				switch s.Name {
				case "OTR/enabled":
					haveOTR = true
					settings.enabled = s.Value == "1"
				case "OTR/automatic":
					haveOTR = true
					settings.automatic = s.Value == "1"
				case "OTR/avoidloggingotr":
					haveOTR = true
					settings.avoidLoggingOTR = s.Value == "1"
				case "OTR/onlyprivate":
					haveOTR = true
					settings.onlyPrivate = s.Value == "1"
				}
			}
			if haveOTR {
				getOrMake(res, xmpp.RemoveResourceFromJid(p.Account))[xmpp.RemoveResourceFromJid(p.Name)] = settings

			}
		}
	}

	return res, true
}
コード例 #9
0
ファイル: account.go プロジェクト: 0x27/coyim
// ShouldEncryptTo returns true if the connection with this peer should be encrypted
func (a *Account) ShouldEncryptTo(jid string) bool {
	if a.AlwaysEncrypt {
		return true
	}

	bareJid := xmpp.RemoveResourceFromJid(jid)
	for _, contact := range a.AlwaysEncryptWith {
		if contact == bareJid {
			return true
		}
	}

	return false
}
コード例 #10
0
ファイル: account_events.go プロジェクト: PMaynard/coyim
func (u *gtkUI) handleMessageEvent(ev session.MessageEvent) {
	account := u.findAccountForSession(ev.Session)
	if account == nil {
		//TODO error
		return
	}

	u.roster.messageReceived(
		account,
		xmpp.RemoveResourceFromJid(ev.From),
		ev.When,
		ev.Encrypted,
		ev.Body,
	)
}
コード例 #11
0
ファイル: peer.go プロジェクト: PMaynard/coyim
// PeerFrom returns a new Peer that contains the same information as the RosterEntry given
func PeerFrom(e xmpp.RosterEntry, conf *config.Account) *Peer {
	belongsTo := conf.ID()
	var nickname string
	p, ok := conf.GetPeer(e.Jid)
	if ok {
		nickname = p.Nickname
	}
	return &Peer{
		Jid:          xmpp.RemoveResourceFromJid(e.Jid),
		Subscription: e.Subscription,
		Name:         e.Name,
		Nickname:     nickname,
		Groups:       toSet(e.Group...),
		BelongsTo:    belongsTo,
	}
}
コード例 #12
0
ファイル: pidgin_like.go プロジェクト: PMaynard/coyim
func importAccountsPidginStyle(f string) (map[string]*config.Account, bool) {
	content, err := ioutil.ReadFile(f)
	if err != nil {
		return nil, false
	}

	var a pidginAccountsXML
	err = xml.Unmarshal(content, &a)
	if err != nil {
		return nil, false
	}

	res := make(map[string]*config.Account)
	for _, ac := range a.Accounts {
		if ac.Protocol == "prpl-jabber" {
			nm := xmpp.RemoveResourceFromJid(ac.Name)
			a := &config.Account{}
			a.Account = nm
			a.Password = ac.Password
			settings := ac.settingsAsMap()
			a.Port = parseIntOr(settings["port"], 5222)

			a.Proxies = make([]string, 0)
			for _, px := range ac.Proxy {
				if px.Type == "tor" {
					a.RequireTor = true
				}
				a.Proxies = append(a.Proxies,
					composeProxyString(px.Type, px.Username, px.Password, px.Host, strconv.Itoa(px.Port)),
				)
			}

			if settings["connect_server"] != "" {
				a.Server = settings["connect_server"]
			}

			if strings.HasSuffix(a.Server, ".onion") {
				a.RequireTor = true
			}

			res[nm] = a
		}
	}

	return res, true
}
コード例 #13
0
ファイル: account_events.go プロジェクト: PMaynard/coyim
func (u *gtkUI) handlePresenceEvent(ev session.PresenceEvent) {
	if ev.Session.GetConfig().HideStatusUpdates {
		return
	}

	log.Printf("[%s] Presence from %v: show: %v status: %v gone: %v\n", ev.To, ev.From, ev.Show, ev.Status, ev.Gone)
	u.rosterUpdated()

	account := u.findAccountForSession(ev.Session)
	if account == nil {
		return
	}

	u.roster.presenceUpdated(
		account,
		xmpp.RemoveResourceFromJid(ev.From),
		ev.Show,
		ev.Status,
		ev.Gone,
	)
}
コード例 #14
0
ファイル: account.go プロジェクト: 0x27/coyim
// Is returns true if this account represents the same identity as the given JID
func (a *Account) Is(jid string) bool {
	return a.Account == xmpp.RemoveResourceFromJid(jid)
}
コード例 #15
0
ファイル: list.go プロジェクト: PMaynard/coyim
// Get returns the peer if it's known and false otherwise
func (l *List) Get(jid string) (*Peer, bool) {
	v, ok := l.peers[xmpp.RemoveResourceFromJid(jid)]
	return v, ok
}