1

I'm writing a small xmpp server using the qxmpp library. Now I want to do the routing of messages myself: If I understand the server's implementation correct, the server forwards a message with a bare JID (contact@myxmpp) in the 'to' attribute to all connected resources for this bare JID. I want to create an implementation that takes care of the priority and sends the message only to the "most available" resource.

The only way to achieve this with QXmppServer seems to be to change the to field to a full JID, but this is prohibited by RFC for this case. (RFC 6121, 8.5.2.1.1 last paragraph: "In all cases, the server MUST NOT rewrite the 'to' attribute".

Is there a trick I didn't see or is it impossible to achieve this with the current version 0.8.0 and I have to open an issue / create a patch for qxmpp?

Chris
  • 1,508
  • 1
  • 11
  • 30
  • What do you mean by `most available` resources? Do you mean to the resources that you want? – elgolondrino May 18 '14 at 19:45
  • @elgolondrino: I took the term from RFC which says "the server MUST either (a) deliver the message to the "most available" resource or resources (according to the server's implementation-specific algorithm". So basically yes, I mean the resource(s) that I want, e.g. the resources with highest presence priority or the resource that was used to send the last message. – Chris May 21 '14 at 11:17
  • My advice, create your class inherited from `QXmppServerExtension` and add object to your QXmppServer extension. Rewrite your own `handlestanza`, where you can catch every query that comes to your server and could manage it your way! – elgolondrino Jun 02 '14 at 19:05
  • @elgolondrino: Thanks for the advice. I'm doing so already (though I don't know what exactly you mean by "and add object to your extension"), but the only ways to actually send a stanza to a client are (as far as I have figured out) server()->sendPacket(...), server()->sendElement(..) and server()->handleElement(...) (the last causing the stanza also to be presented to my extension again). If I didn't catch anything wrong, all of them send the stanza to all connected resources when the 'to' attribute contains a bare JID. So this isn't a solution to my problem. – Chris Jun 03 '14 at 07:44
  • Well, I mean to say that having made your own class (e.g. let's say `ServerExtension`, inherited from `QXmppServerExtension`), add object of your class (aforementioned) to QXmppServer's extension. In your `ServerExtension`, override `handleStanza` method in order to catch every message in your extension. – elgolondrino Jun 04 '14 at 14:46
  • Once, `element` is received first, check `element.attribute("type")` for `chat`, `normal` for `isEmpty()`, then parse it with `QXmppMessage`, concerning the resources, I've created another class that holds `list` of connected clients, via this I managed to control to whom messages are sent. To send message from your `ServerExtension` use `server()->sendPacket(message)`, with changed `to` attribute! – elgolondrino Jun 04 '14 at 14:46
  • But that's the point: The RFC doesn't allow me to change the 'to' attribute (see the quote in my original question). The 'to' attribute has to stay 'user@server', but I want to send it only to one specific resource (or even have to if there are resources with negative priority). – Chris Jun 04 '14 at 16:12
  • Have you tried to change `to` in received `QXmppMessage` element and send it to specific resource? What was result? – elgolondrino Jun 04 '14 at 16:59
  • And also have noticed, RFC's restriction regarding message is only attached to `attribute` -> `headline`! :) – elgolondrino Jun 04 '14 at 17:09

0 Answers0