[JDEV] Patch for service discovery support in JIT

Matthias Wimmer m at tthias.net
Fri Dec 5 08:46:05 CST 2003


Hi!

I implemented service discovery (aka "disco") for JIT today. You can
find the changes in the attached patch file.


Tot kijk
    Matthias

-- 
Fon: +49-(0)70 0770 07770       http://matthias.wimmer.name/
HAM: DB1MW                      xmpp:mawis at charente.de
-------------- next part --------------
diff -Naur jit/jabberd/lib/lib.h jit-disco/jabberd/lib/lib.h
--- jit/jabberd/lib/lib.h	2003-06-02 12:10:16.000000000 +0200
+++ jit-disco/jabberd/lib/lib.h	2003-12-05 15:32:24.000000000 +0100
@@ -650,6 +650,8 @@
 #define NS_ENVELOPE  "jabber:x:envelope"
 #define NS_EXPIRE    "jabber:x:expire"
 #define NS_XHTML     "http://www.w3.org/1999/xhtml"
+#define NS_DISCO_ITEMS "http://jabber.org/protocol/disco#items"
+#define NS_DISCO_INFO "http://jabber.org/protocol/disco#info"
 
 #define NS_XDBGINSERT "jabber:xdb:ginsert"
 #define NS_XDBNSLIST  "jabber:xdb:nslist"
diff -Naur jit/jit/jit/icqtransport.h jit-disco/jit/jit/icqtransport.h
--- jit/jit/jit/icqtransport.h	2003-06-02 12:10:18.000000000 +0200
+++ jit-disco/jit/jit/icqtransport.h	2003-12-05 15:32:24.000000000 +0100
@@ -290,6 +290,10 @@
 void it_iq_gateway_set(session s, jpacket jp);
 void it_iq_browse_server(iti ti, jpacket jp);
 void it_iq_browse_user(session s, jpacket jp);
+void it_iq_disco_items_server(iti ti, jpacket jp);
+void it_iq_disco_info_server(iti ti, jpacket jp);
+void it_iq_disco_items_user(session s, jpacket jp);
+void it_iq_disco_info_user(session s, jpacket jp);
 
 
 void it_save_contacts(session s);
diff -Naur jit/jit/jit/iq.c jit-disco/jit/jit/iq.c
--- jit/jit/jit/iq.c	2003-04-29 15:35:22.000000000 +0200
+++ jit-disco/jit/jit/iq.c	2003-12-05 15:32:24.000000000 +0100
@@ -29,6 +29,10 @@
 void it_iq_gateway_set(session s, jpacket jp);
 void it_iq_browse_server(iti ti, jpacket jp);
 void it_iq_browse_user(session s, jpacket jp);
+void it_iq_disco_items_server(iti ti, jpacket jp);
+void it_iq_disco_info_server(iti ti, jpacket jp);
+void it_iq_disco_items_user(session s, jpacket jp);
+void it_iq_disco_info_user(session s, jpacket jp);
 
 void SendSearchUINRequest(session s,UIN_t uin);
 void SendSearchUsersRequest(session s, 
@@ -73,6 +77,10 @@
           it_iq_gateway_get(s,jp);
         else if (j_strcmp(ns,NS_BROWSE) == 0)
           jp->to->user ? it_iq_browse_user(s,jp) : it_iq_browse_server(s->ti,jp);    
+	else if (j_strcmp(ns,NS_DISCO_ITEMS) == 0)
+	  jp->to->user ? it_iq_disco_items_user(s,jp) : it_iq_disco_items_server(s->ti,jp);
+	else if (j_strcmp(ns,NS_DISCO_INFO) == 0)
+	  jp->to->user ? it_iq_disco_info_user(s,jp) : it_iq_disco_info_server(s->ti,jp);
         else if (j_strcmp(ns,NS_VCARD) == 0)
           jp->to->user ? it_iq_vcard(s,jp) : it_iq_vcard_server(s->ti,jp);
         else if (j_strcmp(ns,NS_LAST) == 0)
@@ -507,6 +515,52 @@
     it_deliver(ti,jp->x);
 }
 
+void it_iq_disco_items_server(iti ti, jpacket jp)
+{
+    xmlnode q;
+
+    q = xmlnode_insert_tag(jutil_iqresult(jp->x),"query");
+    xmlnode_put_attrib(q,"xmlns",NS_DISCO_ITEMS);
+
+    it_deliver(ti,jp->x);
+}
+
+void it_iq_disco_info_server(iti ti, jpacket jp)
+{
+    xmlnode q, info;
+
+    q = xmlnode_insert_tag(jutil_iqresult(jp->x),"query");
+    xmlnode_put_attrib(q,"xmlns",NS_DISCO_INFO);
+
+    info = xmlnode_insert_tag(q,"identity");
+    xmlnode_put_attrib(info,"category", "gateway");
+    xmlnode_put_attrib(info,"type", "icq");
+    xmlnode_put_attrib(info,"name",xmlnode_get_tag_data(ti->vcard,"FN"));
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_REGISTER);
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_SEARCH);
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_VERSION);
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_TIME);
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_GATEWAY);
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_VCARD);
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_LAST);
+
+    it_deliver(ti,jp->x);
+}
+
 void it_iq_browse_user(session s, jpacket jp)
 {
     xmlnode browse;
@@ -538,6 +592,81 @@
     it_deliver(s->ti,jp->x);
 }
 
+void it_iq_disco_items_user(session s, jpacket jp)
+{
+    xmlnode q;
+    UIN_t uin;
+
+    if (s->type == stype_register)
+    {
+	queue_elem queue;
+
+	queue = pmalloco(jp->p,sizeof(_queue_elem));
+	queue->elem = (void *)jp;
+      
+	QUEUE_PUT(s->queue,s->queue_last,queue);
+	return;
+    }
+
+    uin = it_jid2uin(jp->from);
+    if (uin == 0)
+    {
+	jutil_error(jp->x,TERROR_BAD);
+	it_deliver(s->ti,jp->x);
+	return;
+    }
+
+    jutil_iqresult(jp->x);
+    q = xmlnode_insert_tag(jp->x,"query");
+    xmlnode_put_attrib(q,"xmlns",NS_DISCO_ITEMS);
+
+    it_deliver(s->ti,jp->x);
+}
+
+void it_iq_disco_info_user(session s, jpacket jp)
+{
+    xmlnode q,info;
+    UIN_t uin;
+    char uinstr[21];
+
+    if (s->type == stype_register)
+    {
+	queue_elem queue;
+
+	queue = pmalloco(jp->p,sizeof(_queue_elem));
+	queue->elem = (void *)jp;
+      
+	QUEUE_PUT(s->queue,s->queue_last,queue);
+	return;
+    }
+
+    uin = it_jid2uin(jp->from);
+    if (uin == 0)
+    {
+	jutil_error(jp->x,TERROR_BAD);
+	it_deliver(s->ti,jp->x);
+	return;
+    }
+
+    jutil_iqresult(jp->x);
+    q = xmlnode_insert_tag(jp->x,"query");
+    xmlnode_put_attrib(q,"xmlns",NS_DISCO_INFO);
+    
+    info = xmlnode_insert_tag(q,"identity");
+    xmlnode_put_attrib(info,"category","client");
+    xmlnode_put_attrib(info,"type","pc");
+    snprintf(uinstr,21,"%d",uin);
+    xmlnode_put_attrib(info,"name",uinstr);
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_VCARD);
+
+    info = xmlnode_insert_tag(q,"feature");
+    xmlnode_put_attrib(info,"var",NS_LAST);
+
+    it_deliver(s->ti,jp->x);
+}
+
 /** Send reply to a version inquiry to Jabber */
 void it_iq_version(iti ti, jpacket jp)
 {
diff -Naur jit/jit/jit/unknown.c jit-disco/jit/jit/unknown.c
--- jit/jit/jit/unknown.c	2003-04-29 15:35:22.000000000 +0200
+++ jit-disco/jit/jit/unknown.c	2003-12-05 15:34:16.000000000 +0100
@@ -90,6 +90,10 @@
             it_iq_time(ti,jp);
         else if (j_strcmp(ns,NS_VCARD) == 0)
             it_iq_vcard_server(ti,jp);
+	else if (j_strcmp(ns,NS_DISCO_ITEMS) == 0)
+	    it_iq_disco_items_server(ti,jp);
+	else if (j_strcmp(ns,NS_DISCO_INFO) == 0)
+	    it_iq_disco_info_server(ti,jp);
         else if (j_strcmp(ns,NS_LAST) == 0)
             jp->to->user == NULL ? it_iq_last_server(ti,jp) : xmlnode_free(jp->x);
         else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://www.jabber.org/jdev/attachments/20031205/55969133/attachment-0002.pgp>


More information about the JDev mailing list