[xmppd-dev] commit r1566 - in trunk/jabberd14: . jabberd/lib jsm/modules
mail at jabberd.org
mail at jabberd.org
Mon Nov 16 02:18:18 CET 2009
Author: mawis
Date: Mon Nov 16 02:18:17 2009
New Revision: 1566
Log:
Adding JSM configuration setting that will cause JSM to store presence information of all contact's of a user to xdb.
Modified:
trunk/jabberd14/ChangeLog
trunk/jabberd14/jabber.xml.dist.in
trunk/jabberd14/jabberd/lib/jabberdlib.h
trunk/jabberd14/jsm/modules/mod_presence.cc
Modified: trunk/jabberd14/ChangeLog
==============================================================================
--- trunk/jabberd14/ChangeLog Tue Nov 10 02:21:34 2009 (r1565)
+++ trunk/jabberd14/ChangeLog Mon Nov 16 02:18:17 2009 (r1566)
@@ -1,3 +1,9 @@
+2009-11-16 Matthias Wimmer <m at tthias.eu>
+
+ * jsm/modules/mod_presence.cc: allow jsm configuration to store presence
+ information of user's contacts
+ * jabberd/lib/jabberdlib.h: same
+
2009-11-10 Matthias Wimmer <m at tthias.eu>
* jsm/jsm.cc: porting changes in 1.6.x branch to trunk
* jabberd/jabberd.h: same
Modified: trunk/jabberd14/jabber.xml.dist.in
==============================================================================
--- trunk/jabberd14/jabber.xml.dist.in Tue Nov 10 02:21:34 2009 (r1565)
+++ trunk/jabberd14/jabber.xml.dist.in Mon Nov 16 02:18:17 2009 (r1566)
@@ -401,6 +401,7 @@
<!-- comment out or remove the following setting. -->
<presence>
<presence2xdb/>
+ <peerpresence2xdb/>
</presence>
<!-- The <history/> configuration element can be used to instruct -->
@@ -597,6 +598,14 @@
<set>INSERT INTO messages (user, realm, correspondent, type, storetime, delivertime, subject, body, xml) VALUES (SUBSTRING('{attribute::to}', 1, INSTR('{attribute::to}', '@')-1), SUBSTRING('{attribute::to}', INSTR('{attribute::to}', '@')+1), IF ('{message/attribute::direction}'='sent', SUBSTRING('{message/attribute::to}/', 1, INSTR('{message/attribute::to}/', '/')-1), SUBSTRING('{message/attribute::from}/', 1, INSTR('{message/attribute::from}/', '/')-1)), IF ('{message/attribute::direction}'='sent', 'sent', 'recv'), now(), IF ('{message/attribute::direction}'='sent', NULL, now()), '{message/subject/text()}', '{message/body/text()}', '{message}')</set>
<delete>DELETE FROM messages WHERE realm=SUBSTRING('{attribute::to}', INSTR('{attribute::to}', '@')+1) AND user=SUBSTRING('{attribute::to}', 1, INSTR('{attribute::to}', '@')-1)</delete>
</handler>
+ <handler ns='http://jabberd.org/ns/storedpeerpresence'>
+ <get>
+ <query>SELECT xml FROM peerpresence WHERE realm=SUBSTRING('{attribute::to}', INSTR('{attribute::to}', '@')+1) AND user=SUBSTRING('{attribute::to}', 1, INSTR('{attribute::to}', '@')-1) ORDER BY peerrealm, peeruser, peerresource</query>
+ <result group='foo'><value xmlns='http://jabberd.org/ns/xdbsql' value='1' parsed='parsed'/></result>
+ </get>
+ <set>INSERT INTO peerpresence (user, realm, peeruser, peerrealm, peerresource, presence, priority, status, timestamp, xml) VALUES (SUBSTRING('{attribute::to}', 1, INSTR('{attribute::to}', '@')-1), SUBSTRING('{attribute::to}', INSTR('{attribute::to}', '@')+1), SUBSTRING('{presence/attribute::from}', 1, INSTR('{presence/attribute::from}', '@')-1), IF(INSTR('{presence/attribute::from}', '/')=0, SUBSTRING('{presence/attribute::from}', INSTR('{presence/attribute::from}', '@')+1), SUBSTRING('{presence/attribute::from}', INSTR('{presence/attribute::from}', '@')+1, INSTR('{presence/attribute::from}', '/')-1-INSTR('{presence/attribute::from}', '@'))), IF(INSTR('{presence/attribute::from}', '/')=0, NULL, SUBSTRING('{presence/attribute::from}', INSTR('{presence/attribute::from}', '/')+1)), IF ('{presence}'='','unavailable', IF ('{presence/attribute::type}'='unavailable', 'unavailable', IF ('{presence/show/text()}'='','available', '{presence/show/text()}'))), IF ('{presence/priority/text()}'='', '0', '{presence/priority/text()}'), '{presence/status/text()}', now(), '{presence}')</set>
+ <delete>DELETE FROM peerpresence WHERE realm=SUBSTRING('{attribute::to}', INSTR('{attribute::to}', '@')+1) AND user=SUBSTRING('{attribute::to}', 1, INSTR('{attribute::to}', '@')-1) AND IF ('{attribute::matchpath}'='', 1=1, CONCAT(peeruser, '@', peerrealm, IF(peerresource IS NULL, '', CONCAT('/', peerresource)))=SUBSTRING(SUBSTRING('{attribute::matchpath}', 1, LENGTH('{attribute::matchpath}')-2), 17) AND SUBSTRING('{attribute::matchpath}', 1, 15)='presence[@from=')</delete>
+ </handler>
<handler ns="http://jabberd.org/ns/storedpresence">
<get>
<query>SELECT 'this namespace is never selected'</query>
Modified: trunk/jabberd14/jabberd/lib/jabberdlib.h
==============================================================================
--- trunk/jabberd14/jabberd/lib/jabberdlib.h Tue Nov 10 02:21:34 2009 (r1565)
+++ trunk/jabberd14/jabberd/lib/jabberdlib.h Mon Nov 16 02:18:17 2009 (r1566)
@@ -1276,6 +1276,7 @@
#define NS_XMPP_PING "urn:xmpp:ping"
#define NS_JABBERD_STOREDPRESENCE "http://jabberd.org/ns/storedpresence"
+#define NS_JABBERD_STOREDPEERPRESENCE "http://jabberd.org/ns/storedpeerpresence"
#define NS_JABBERD_STOREDREQUEST "http://jabberd.org/ns/storedsubscriptionrequest"
#define NS_JABBERD_STOREDSTATE "http://jabberd.org/ns/storedstate" /**< namespace to store internal state of jabberd */
#define NS_JABBERD_HISTORY "http://jabberd.org/ns/history"
Modified: trunk/jabberd14/jsm/modules/mod_presence.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_presence.cc Tue Nov 10 02:21:34 2009 (r1565)
+++ trunk/jabberd14/jsm/modules/mod_presence.cc Mon Nov 16 02:18:17 2009 (r1566)
@@ -75,6 +75,7 @@
typedef struct modpres_conf_struct {
jid bcc; /**< who gets a blind carbon copy of our presences */
int pres_to_xdb; /**< if the (primary) presence of a user should be stored in xdb */
+ int peerpres_to_xdb;/**< if the peer presence of a user should be stored in xdb */
} *modpres_conf, _modpres_conf;
/**
@@ -329,6 +330,30 @@
}
/**
+ * store the presence of a peer to xdb
+ *
+ * @param m the mapi struct
+ */
+static void mod_peerpresence_store(mapi m) {
+ // sanity check
+ if (!m)
+ return;
+
+ // do not store presence probes
+ if (jpacket_subtype(m->packet) == JPACKET__PROBE)
+ return;
+
+ // generate the path of the presence to be replaced
+ std::ostringstream xpath;
+ xpath << "presence[@from='" << jid_full(m->packet->from) << "']";
+
+ log_debug2(ZONE, LOGT_STORAGE, "storing peer presence by matched xdb: %s", xpath.str().c_str());
+
+ /* replace this message with nothing */
+ xdb_act_path(m->si->xc, m->user->id, NS_JABBERD_STOREDPEERPRESENCE, "insert", xpath.str().c_str(), m->si->std_namespace_prefixes, m->packet->x);
+}
+
+/**
* handles undirected outgoing presences (presences with no to attribute)
*
* checks that the presence's priority is in the valid range
@@ -697,12 +722,22 @@
*/
static mreturn mod_presence_deliver(mapi m, void *arg) {
session cur;
+ modpres_conf conf = static_cast<modpres_conf>(arg);
+
+ // security check
+ if (!conf)
+ return M_PASS;
if (m->packet->type != JPACKET_PRESENCE)
return M_IGNORE;
log_debug2(ZONE, LOGT_DELIVER, "deliver phase");
+ // store presence in xdb?
+ if (conf->peerpres_to_xdb) {
+ mod_peerpresence_store(m);
+ }
+
/* only if we HAVE a user, and it was sent to ONLY the user at server, and there is at least one session available */
if (m->user && !m->packet->to->has_resource() && js_session_primary(m->user) != NULL) {
log_debug2(ZONE, LOGT_DELIVER, "broadcasting to %s",m->user->id->get_node().c_str());
@@ -770,10 +805,12 @@
jid_append(conf->bcc,jid_new(si->p,xmlnode_get_data(cfg)));
} else if (j_strcmp(element_name, "presence2xdb") == 0) {
conf->pres_to_xdb++;
+ } else if (j_strcmp(element_name, "peerpresence2xdb") == 0) {
+ conf->peerpres_to_xdb++;
}
}
- js_mapi_register(si,e_DELIVER, mod_presence_deliver, NULL);
+ js_mapi_register(si,e_DELIVER, mod_presence_deliver, (void*)conf);
js_mapi_register(si,e_SESSION, mod_presence_session, (void*)conf);
js_mapi_register(si,e_DESERIALIZE, mod_presence_deserialize, (void*)conf);
js_mapi_register(si, e_DELETE, mod_presence_delete, NULL);
More information about the dev
mailing list