root/trunk/src/disco.c

Revision 680, 5.9 kB (checked in by jajcus, 3 years ago)

- dates in the copyright header updated

Line 
1 /* $Id: disco.c,v 1.13 2004/04/13 17:44:07 jajcus Exp $ */
2
3 /*
4  *  (C) Copyright 2002-2006 Jacek Konieczny [jajcus(a)jajcus,net]
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 Version 2 as
8  *  published by the Free Software Foundation.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include "ggtrans.h"
21 #include "jabber.h"
22 #include "iq.h"
23 #include "browse.h"
24 #include "conf.h"
25 #include "jid.h"
26 #include "sessions.h"
27 #include "debug.h"
28
29 static const char *extra_features[]={NULL};
30
31 static void disco_session(gpointer key,gpointer value,gpointer data){
32 const char *jid=(char *)key;
33 const Session *sess=(Session *)value;
34 xmlnode result=(xmlnode)data;
35 xmlnode n;
36 char *str;
37
38         n=xmlnode_insert_tag(result,"item");
39         xmlnode_put_attrib(n,"jid",jid);
40         str=session_get_info_string(sess);
41         xmlnode_put_attrib(n,"name",str);
42         g_free(str);
43 }
44
45 static void disco_online_users(Stream *s,const char *from,const char * to, const char *id,xmlnode q){
46 xmlnode result;
47 char *jid;
48
49         jid=jid_normalized(from,0);
50         if (jid==NULL){
51                 debug(N_("Bad 'from' address"));
52                 return;
53         }
54
55         if (g_list_find_custom(admins,jid,(GCompareFunc)strcmp)==NULL){
56                 g_free(jid);
57                 jabber_iq_send_error(s,from,to,id,405,_("You are not allowed to browse users"));
58                 return;
59         }
60         g_free(jid);
61
62         result=xmlnode_new_tag("query");
63         xmlnode_put_attrib(result,"xmlns","http://jabber.org/protocol/disco#items");
64         xmlnode_put_attrib(result,"node","online_users");
65
66         g_hash_table_foreach(sessions_jid,disco_session,result);
67
68         jabber_iq_send_result(s,from,to,id,result);
69         xmlnode_free(result);
70 }
71
72 void jabber_iq_get_server_disco_items(Stream *s,const char *from,const char * to,const char *id,xmlnode q){
73 xmlnode result;
74 xmlnode n;
75 char *jid,*node;
76
77         jid=jid_normalized(from,0);
78         if (jid==NULL){
79                 debug(N_("Bad 'from' address"));
80                 return;
81         }
82
83         node=xmlnode_get_attrib(q,"node");
84         if (node && node[0]){
85                 if (!strcmp(node,"online_users"))
86                         disco_online_users(s,from,to,id,q);
87                 else jabber_iq_send_error(s,from,to,id,404,_("Disco request for unknown node"));
88                 return;
89         }
90         result=xmlnode_new_tag("query");
91         xmlnode_put_attrib(result,"xmlns","http://jabber.org/protocol/disco#items");
92         if (g_list_find_custom(admins,jid,(GCompareFunc)strcmp)!=NULL){
93                 n=xmlnode_insert_tag(result,"item");
94                 xmlnode_put_attrib(n,"jid",my_name);
95                 xmlnode_put_attrib(n,"node","online_users");
96                 xmlnode_put_attrib(n,"name",_("Online users"));
97         }
98         else debug("%s not admin",jid);
99         g_free(jid);
100         jabber_iq_send_result(s,from,to,id,result);
101         xmlnode_free(result);
102 }
103
104 void jabber_iq_get_server_disco_info(Stream *s,const char *from,const char * to,const char *id,xmlnode q){
105 xmlnode result;
106 xmlnode n,n1;
107 char *str,*node;
108 int i;
109
110         node=xmlnode_get_attrib(q,"node");
111         if (node && node[0]){
112                 if (!strcmp(node,"online_users")){
113                         result=xmlnode_new_tag("query");
114                         xmlnode_put_attrib(result,"xmlns","http://jabber.org/protocol/disco#info");
115                         xmlnode_put_attrib(result,"node","online_users");
116                         n=xmlnode_insert_tag(result,"identity");
117                         xmlnode_put_attrib(n,"category","hierarchy");
118                         xmlnode_put_attrib(n,"type","branch");
119                         xmlnode_put_attrib(n,"name",_("Online users"));
120                         jabber_iq_send_result(s,from,to,id,result);
121                         xmlnode_free(result);
122                 }
123                 jabber_iq_send_error(s,from,to,id,404,_("Disco request for unknown node"));
124                 return;
125         }
126         result=xmlnode_new_tag("query");
127         xmlnode_put_attrib(result,"xmlns","http://jabber.org/protocol/disco#info");
128         n=xmlnode_insert_tag(result,"identity");
129         xmlnode_put_attrib(n,"category","gateway");
130         xmlnode_put_attrib(n,"type","gadu-gadu");
131         n1=xmlnode_get_tag(config,"vCard/FN");
132         if (n1){
133                 str=xmlnode_get_data(n1);
134                 if (str) xmlnode_put_attrib(n,"name",str);
135         }
136
137         for(i=0;server_iq_ns[i].ns;i++){
138                 if (i && !strcmp(server_iq_ns[i-1].ns,server_iq_ns[i].ns)){
139                         /* workaround for the WinJab bug :-) */
140                         continue;
141                 }
142                 n=xmlnode_insert_tag(result,"feature");
143                 xmlnode_put_attrib(n,"var",server_iq_ns[i].ns);
144         }
145         for(i=0;extra_features[i];i++){
146                 n=xmlnode_insert_tag(result,"feature");
147                 xmlnode_put_attrib(n,"var",extra_features[i]);
148         }
149
150         jabber_iq_send_result(s,from,to,id,result);
151         xmlnode_free(result);
152 }
153
154 void jabber_iq_get_client_disco_items(Stream *s,const char *from,const char * to,const char *id,xmlnode q){
155 xmlnode result;
156 char *node;
157
158         node=xmlnode_get_attrib(q,"node");
159         if (node && node[0]){
160                 jabber_iq_send_error(s,from,to,id,404,_("Disco request for unknown node"));
161                 return;
162         }
163
164         result=xmlnode_new_tag("query");
165         xmlnode_put_attrib(result,"xmlns","http://jabber.org/protocol/disco#items");
166         jabber_iq_send_result(s,from,to,id,result);
167         xmlnode_free(result);
168 }
169
170 void jabber_iq_get_client_disco_info(Stream *s,const char *from,const char * to,const char *id,xmlnode q){
171 xmlnode result;
172 xmlnode n;
173 char *str, *node;
174 int i;
175
176         node=xmlnode_get_attrib(q,"node");
177         if (node && node[0]){
178                 jabber_iq_send_error(s,from,to,id,404,_("Disco request for unknown node"));
179                 return;
180         }
181
182         result=xmlnode_new_tag("query");
183         xmlnode_put_attrib(result,"xmlns","http://jabber.org/protocol/disco#info");
184         n=xmlnode_insert_tag(result,"identity");
185         xmlnode_put_attrib(n,"category","client");
186         xmlnode_put_attrib(n,"type","pc");
187         str=g_strdup_printf("GG user #%u",jid_get_uin(to));
188         xmlnode_put_attrib(n,"name",str);
189         g_free(str);
190
191         for(i=0;client_iq_ns[i].ns;i++){
192                 if (i && !strcmp(client_iq_ns[i-1].ns,client_iq_ns[i].ns)){
193                         /* workaround for the WinJab bug workaround :-) */
194                         continue;
195                 }
196                 n=xmlnode_insert_tag(result,"feature");
197                 xmlnode_put_attrib(n,"var",client_iq_ns[i].ns);
198         }
199         jabber_iq_send_result(s,from,to,id,result);
200         xmlnode_free(result);
201 }
202
Note: See TracBrowser for help on using the browser.