]> Pileus Git - ~andy/sunrise/blob - net-nds/lat/files/lat-1.1.6-service_finder_cs.patch
net-p2p/mute: New Ebuild for bug #60392 thanks to Sébastien Cérèze
[~andy/sunrise] / net-nds / lat / files / lat-1.1.6-service_finder_cs.patch
1 diff -Naur lat.orig/ServiceFinder.cs lat/ServiceFinder.cs
2 --- lat.orig/ServiceFinder.cs   1970-01-01 01:00:00.000000000 +0100
3 +++ lat/ServiceFinder.cs        2006-09-04 22:27:08.000000000 +0200
4 @@ -0,0 +1,107 @@
5 +// 
6 +// lat - ServiceFinder.cs
7 +// Author: Loren Bandiera
8 +// Copyright 2005-2006 MMG Security, Inc.
9 +//
10 +// This program is free software; you can redistribute it and/or modify
11 +// it under the terms of the GNU General Public License as published by
12 +// the Free Software Foundation; Version 2 
13 +//
14 +// This program is distributed in the hope that it will be useful,
15 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
16 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 +// GNU General Public License for more details.
18 +//
19 +// You should have received a copy of the GNU General Public License
20 +// along with this program; if not, write to the Free Software
21 +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 +//
23 +//
24 +
25 +using System;
26 +using Avahi;
27 +
28 +namespace lat
29 +{
30 +       public class ServiceEventArgs : EventArgs
31 +       {
32 +               Connection conn;
33 +
34 +               public ServiceEventArgs (Connection conn)
35 +               {
36 +                       this.conn = conn;
37 +               }
38 +
39 +               public Connection FoundConnection
40 +               {
41 +                       get { return conn; }
42 +               }       
43 +       }
44 +
45 +       public delegate void ServiceEventHandler (object o, ServiceEventArgs args);
46 +
47 +       public class ServiceFinder
48 +       {
49 +               Client client;
50 +               ServiceBrowser sb;
51 +
52 +        public event ServiceEventHandler Found;
53 +
54 +               public ServiceFinder ()
55 +               {
56 +                       client = new Client();                  
57 +               }
58 +
59 +               public void Start ()
60 +               {
61 +                       try {                           
62 +                               sb = new ServiceBrowser (client, "_ldap._tcp");
63 +                               sb.ServiceAdded += OnServiceAdded;
64 +                               sb.ServiceRemoved += OnServiceRemoved;
65 +                       } catch (ClientException ce) {
66 +                               Log.Debug (ce);
67 +                       }
68 +               }
69 +               
70 +               public void Stop ()
71 +               {
72 +                       sb.Dispose ();
73 +               }
74 +
75 +           void OnServiceResolved (object o, ServiceInfoArgs args) 
76 +               {
77 +                       (o as ServiceResolver).Dispose ();
78 +               
79 +                       ConnectionData cd = new ConnectionData ();
80 +                       cd.Name = String.Format ("{0} ({1})", args.Service.Name, args.Service.Address);
81 +                       cd.Host = args.Service.Address.ToString ();
82 +                       cd.Port = args.Service.Port;
83 +                       cd.UserName = "";
84 +                       cd.Pass = "";
85 +                       cd.SavePassword = false;
86 +                       cd.ServerType = Util.GetServerType ("Generic LDAP server");
87 +                       cd.Dynamic = true;
88 +
89 +                       Log.Debug ("Found LDAP service {0} on {1} port {2}", 
90 +                               args.Service.Name, args.Service.Address, args.Service.Port);
91 +
92 +                       if (args.Service.Port == 636)
93 +                               cd.Encryption = EncryptionType.SSL;
94 +                       
95 +                       Connection conn = new Connection (cd);
96 +                       
97 +                       if (Found != null)
98 +                Found (this, new ServiceEventArgs (conn));
99 +               }
100 +
101 +               void OnServiceAdded (object o, ServiceInfoArgs args) 
102 +               {
103 +                       ServiceResolver resolver = new ServiceResolver (client, args.Service);
104 +                       resolver.Found += OnServiceResolved;
105 +        }
106 +
107 +               void OnServiceRemoved (object o, ServiceInfoArgs args)
108 +               {
109 +               }
110 +       }
111 +}