[JDEV] Patch for service discovery support in JIT

Matthias Wimmer m at tthias.net
Thu Dec 11 18:35:24 CST 2003


Hi!


I updated my patch that implements service discovery in JIT. The
difference is, that a different name for the SMS part of JIT can be
specified for discovery (and browsing) in the configuration file.
Else you get the same description for the transport and the SMS part of
it in the agents list of jabberd2.


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-12 01:10:16.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/jabber-icq.example jit-disco/jit/jabber-icq.example
--- jit/jit/jabber-icq.example	2003-04-08 12:08:28.000000000 +0200
+++ jit-disco/jit/jabber-icq.example	2003-12-12 01:14:19.000000000 +0100
@@ -51,6 +51,7 @@
         <host>sms.icq.localhost</host>
   	<show>away</show>
 	<status></status>
+	<name>SMS over Jabber ICQ Transport</name>
       </sms>
 
       <instructions>Please enter your UIN and password</instructions>
diff -Naur jit/jit/jit/icqtransport.c jit-disco/jit/jit/icqtransport.c
--- jit/jit/jit/icqtransport.c	2003-04-29 15:35:22.000000000 +0200
+++ jit-disco/jit/jit/icqtransport.c	2003-12-12 01:18:04.000000000 +0100
@@ -122,6 +122,12 @@
         if (ti->sms_status) {
           log_debug(ZONE,"sms st %s ",ti->sms_status);
         }
+
+        ti->sms_name = pstrdup(p,xmlnode_get_tag_data(cur,"name"));
+
+	if (ti->sms_name) {
+	  log_debug(ZONE,"sms name %s",ti->sms_name);
+	}
       }
     }
 
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-12 01:13:57.000000000 +0100
@@ -81,6 +81,8 @@
     icqstatus sms_show;
     /** Away message of SMS contacts */
     char *sms_status;
+    /** Name of the SMS node for browsing and discovery */
+    char *sms_name;
     /** use "chat" as standard message type? */
     int msg_chat;
     time_t start;
@@ -290,6 +292,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-12 01:20:36.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)
@@ -498,7 +506,10 @@
 
     xmlnode_put_attrib(q,"type","icq");
     xmlnode_put_attrib(q,"jid",jp->to->server);
-    xmlnode_put_attrib(q,"name",xmlnode_get_tag_data(ti->vcard,"FN"));
+    if (ti->sms_id && ti->sms_name && j_strcasecmp(jp->to->server, ti->sms_id)==0)
+	xmlnode_put_attrib(q,"name",ti->sms_name);
+    else
+	xmlnode_put_attrib(q,"name",xmlnode_get_tag_data(ti->vcard,"FN"));
 
     xmlnode_insert_cdata(xmlnode_insert_tag(q,"ns"),NS_REGISTER,-1);
     xmlnode_insert_cdata(xmlnode_insert_tag(q,"ns"),NS_SEARCH,-1);
@@ -507,6 +518,55 @@
     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");
+    if (ti->sms_id && ti->sms_name && j_strcasecmp(jp->to->server, ti->sms_id)==0)
+	xmlnode_put_attrib(info,"name",ti->sms_name);
+    else
+	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 +598,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-12 01:10: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


More information about the JDev mailing list