2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Mono.Directory.LDAP / Mono.Directory.LDAP / LDAPMessage.cs
1 //
2 // Mono.Directory.LDAP.LDAPMessage
3 //
4 // Author:
5 //    Chris Toshok (toshok@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9 //
10 // Just enough (for now) LDAP support to get System.DirectoryServices
11 // working.
12
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System;
35 using System.Runtime.InteropServices;
36
37 namespace Mono.Directory.LDAP 
38 {
39         public class LDAPMessage {
40
41                 internal LDAPMessage(LDAP ld, IntPtr ldm) {
42                         this.ld = ld;
43                         this.ldm = ldm;
44                 }
45
46                 public LDAPMessage FirstMessage () {
47                         IntPtr nm = ldap_first_message (ld.NativeLDAP ,ldm);
48
49                         if (nm == IntPtr.Zero)
50                                 return null;
51                         else
52                                 return new LDAPMessage (ld, nm);
53                 }
54
55                 public LDAPMessage NextMessage () {
56                         IntPtr nm = ldap_next_message (ld.NativeLDAP ,ldm);
57
58                         if (nm == IntPtr.Zero)
59                                 return null;
60                         else
61                                 return new LDAPMessage (ld, nm);
62                 }
63
64                 public int CountMessages () {
65                         return ldap_count_messages (ld.NativeLDAP, ldm);
66                 }
67
68                 public LDAPMessage FirstEntry() {
69                         IntPtr nm = ldap_first_entry (ld.NativeLDAP ,ldm);
70
71                         if (nm == IntPtr.Zero)
72                                 return null;
73                         else
74                                 return new LDAPMessage (ld, nm);
75                 }
76
77                 public LDAPMessage NextEntry() {
78                         IntPtr nm = ldap_next_entry (ld.NativeLDAP ,ldm);
79
80                         if (nm == IntPtr.Zero)
81                                 return null;
82                         else
83                                 return new LDAPMessage (ld, nm);
84                 }
85
86                 public int CountEntries() {
87                         return ldap_count_entries (ld.NativeLDAP, ldm);
88                 }
89
90                 public string DN {
91                         get { return ldap_get_dn (ld.NativeLDAP, ldm); }
92                 }
93
94                 [MonoTODO]
95                 public string[] GetValues (string target) {
96                   throw new NotImplementedException ();
97                   /*
98                         string[] ldap_values;
99
100                         Console.WriteLine ("calling ldap_get_values ({0})", target);
101
102                         ldap_values = ldap_get_values (ld.NativeLDAP, ldm, target);
103
104                         if (ldap_values != null) {
105                           string[] rv;
106                           int i;
107
108                           rv = new string[ldap_values.Length - 1];
109                           for (i = 0; i < ldap_values.Length - 1; i ++)
110                             rv[i] = ldap_values[i];
111
112                           return rv;
113                         }
114                         else {
115                           return null;
116                         }
117                   */
118                 }
119
120                 [DllImport("ldap")]
121                 extern static string ldap_get_dn (IntPtr ld, IntPtr ldm);
122
123                 [DllImport("ldap")]
124                 extern static IntPtr ldap_first_message (IntPtr ld, IntPtr ldm);
125
126                 [DllImport("ldap")]
127                 extern static IntPtr ldap_next_message (IntPtr ld, IntPtr ldm);
128
129                 [DllImport("ldap")]
130                 extern static int ldap_count_messages (IntPtr ld, IntPtr ldm);
131
132                 [DllImport("ldap")]
133                 extern static IntPtr ldap_first_entry (IntPtr ld, IntPtr ldm);
134
135                 [DllImport("ldap")]
136                 extern static IntPtr ldap_next_entry (IntPtr ld, IntPtr ldm);
137
138                 [DllImport("ldap")]
139                 extern static int ldap_count_entries (IntPtr ld, IntPtr ldm);
140
141                 [DllImport("ldap")]
142                 extern static string ldap_first_attribute (IntPtr ld, IntPtr ldm, out IntPtr ber);
143
144                 [DllImport("ldap")]
145                 extern static string ldap_next_attribute (IntPtr ld, IntPtr ldm, IntPtr ber);
146
147                 /*
148                 [DllImport("ldapglue")]
149                 extern static void ldapsharp_get_values (IntPtr ld, IntPtr ldm, string target,
150                                                          out string[] values, out int count);
151                 */
152                 IntPtr ldm;
153                 LDAP   ld;
154         }
155 }