jabberd2  2.2.17
mod_deliver.c
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19  */
20 
21 #include "sm.h"
22 
31 {
32  /* ensure from is set correctly if not already by client */
33  if(pkt->from == NULL || jid_compare_user(pkt->from, sess->jid) != 0) {
34  if(pkt->from != NULL)
35  jid_free(pkt->from);
36 
37  pkt->from = jid_dup(sess->jid);
38  nad_set_attr(pkt->nad, 1, -1, "from", jid_full(pkt->from), 0);
39  }
40 
41  /* no to address means its to us */
42  if(pkt->to == NULL) {
43  /* drop iq-result packets */
44  /* user client is confirming all iq-set, but we usually do not track these
45  * confirmations and we need to drop it here, not loop back to client */
46  if(pkt->type == pkt_IQ_RESULT) {
47  pkt_free(pkt);
48  return mod_HANDLED;
49  }
50 
51  /* iq packets without to should have been already handled by modules */
52  if(pkt->type & pkt_IQ) {
54  }
55 
56  /* supplant user jid as 'to' */
57  pkt->to = jid_dup(sess->jid);
58  nad_set_attr(pkt->nad, 1, -1, "to", jid_full(pkt->to), 0);
59  }
60 
61  /* let it go on the wire */
62  pkt_router(pkt);
63 
64  return mod_HANDLED;
65 }
66 
68 {
69  sess_t sess;
70 
71  /* if there's a resource, send it direct */
72  if(*pkt->to->resource != '\0') {
73  /* find the session */
74  sess = sess_match(user, pkt->to->resource);
75 
76  /* and send it straight there */
77  if(sess != NULL) {
78  pkt_sess(pkt, sess);
79  return mod_HANDLED;
80  }
81 
82  /* no session */
83  if(pkt->type & pkt_PRESENCE) {
84  pkt_free(pkt);
85  return mod_HANDLED;
86 
87  } else if(pkt->type & pkt_IQ)
89 
90  /* unmatched messages will fall through (XMPP-IM r20 s11 rule 2) */
91  }
92 
93  return mod_PASS;
94 }
95 
96 DLLEXPORT int module_init(mod_instance_t mi, char *arg) {
97  module_t mod = mi->mod;
98 
99  if(mod->init) return 0;
100 
101  mod->in_sess = _deliver_in_sess;
103 
104  feature_register(mod->mm->sm, "message");
105 
106  return 0;
107 }