Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DiscoverInfo() as thin wrapper around RawInformation() #151

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion xmpp_information_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ func (c *Client) Discovery() (string, error) {
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, XMPPNS_DISCO_ITEMS, "")
}

// Discover information about a node
// Discover information about a node. Empty node queries info about server itself.
func (c *Client) DiscoverNodeInfo(node string) (string, error) {
query := fmt.Sprintf("<query xmlns='%s' node='%s'/>", XMPPNS_DISCO_INFO, node)
return c.RawInformation(c.jid, c.domain, "info3", IQTypeGet, query)
}

// Discover information about given item from given jid.
func (c *Client) DiscoverInfo(from string, to string) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason to be able to define the from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be able to do this. Query info about whether client is able to join muc or not, just before blindly try to join.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why not use c.Jid, e.g. as done here instead of making it configurable?

Is there any reason that you might have an connection of jid1 that would request this info claiming to be jid2? Actually I'd assume the server would not allow you to impersonate another JID, therefore I don't see why this should be made configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was about year ago, so i don't quite remember why, to be honest. But this mechanics works in conjunction with jabber.ru server and I have to use it this way, otherwise I did not suggest it as PR. If you see it questionable you can always close this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in the example you linked me you also set from to your own JID (I'm pretty sure faking a JID wouldn't work anyway). So if you don't make it configurable but use c.jid, like DiscoverNodeInfo() does, your code should also work.

query := fmt.Sprintf("<query xmlns='%s'/>", XMPPNS_DISCO_INFO)
return c.RawInformation(from, to, "info3", IQTypeGet, query)
}

// Discover items that the server exposes
func (c *Client) DiscoverServerItems() (string, error) {
return c.DiscoverEntityItems(c.domain)
Expand Down