| 1 |
// AprSharp, a wrapper library around the Apache Portable Runtime Library |
|---|
| 2 |
#region Copyright (C) 2004 SOFTEC sa. |
|---|
| 3 |
// |
|---|
| 4 |
// This library is free software; you can redistribute it and/or |
|---|
| 5 |
// modify it under the terms of the GNU Lesser General Public |
|---|
| 6 |
// License as published by the Free Software Foundation; either |
|---|
| 7 |
// version 2.1 of the License, or (at your option) any later version. |
|---|
| 8 |
// |
|---|
| 9 |
// This library is distributed in the hope that it will be useful, |
|---|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 12 |
// Lesser General Public License for more details. |
|---|
| 13 |
// |
|---|
| 14 |
// You should have received a copy of the GNU Lesser General Public |
|---|
| 15 |
// License along with this library; if not, write to the Free Software |
|---|
| 16 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 |
// |
|---|
| 18 |
// Sources, support options and lastest version of the complete library |
|---|
| 19 |
// is available from: |
|---|
| 20 |
// http://www.softec.st/AprSharp |
|---|
| 21 |
// |
|---|
| 22 |
// |
|---|
| 23 |
// Initial authors : |
|---|
| 24 |
// Denis Gervalle |
|---|
| 25 |
// Olivier Desaive |
|---|
| 26 |
#endregion |
|---|
| 27 |
// |
|---|
| 28 |
using System; |
|---|
| 29 |
using System.Runtime.InteropServices; |
|---|
| 30 |
using System.Text; |
|---|
| 31 |
using System.Diagnostics; |
|---|
| 32 |
|
|---|
| 33 |
namespace Softec.AprSharp |
|---|
| 34 |
{ |
|---|
| 35 |
|
|---|
| 36 |
///<summary>Embeds all APR external calls</summary> |
|---|
| 37 |
///<remark>Take care to call apr_initialize</remark> |
|---|
| 38 |
public sealed class Apr |
|---|
| 39 |
{ |
|---|
| 40 |
#if WIN32 |
|---|
| 41 |
private const string AprLibrary = "libapr"; |
|---|
| 42 |
#else |
|---|
| 43 |
private const string AprLibrary = "apr-0"; |
|---|
| 44 |
#endif |
|---|
| 45 |
|
|---|
| 46 |
// no instance constructor ! |
|---|
| 47 |
private Apr() { } |
|---|
| 48 |
|
|---|
| 49 |
static Apr() |
|---|
| 50 |
{ |
|---|
| 51 |
int apr_status; |
|---|
| 52 |
Debug.Write("apr_initialize..."); |
|---|
| 53 |
apr_status = apr_initialize(); |
|---|
| 54 |
Debug.WriteLine("Done"); |
|---|
| 55 |
if( apr_status != 0 ) |
|---|
| 56 |
throw new AprException(apr_status); |
|---|
| 57 |
|
|---|
| 58 |
//FIXME: Shoud shedule a call to apr_terminate |
|---|
| 59 |
// at process exit |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
public static void Terminate() |
|---|
| 63 |
{ |
|---|
| 64 |
Debug.Write("apr_terminate..."); |
|---|
| 65 |
apr_terminate(); |
|---|
| 66 |
Debug.WriteLine("Done"); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
#region Initialize / Terminate |
|---|
| 70 |
[DllImport(AprLibrary)] |
|---|
| 71 |
private static extern int apr_initialize( ); |
|---|
| 72 |
|
|---|
| 73 |
[DllImport(AprLibrary)] |
|---|
| 74 |
private static extern void apr_terminate( ); |
|---|
| 75 |
#endregion |
|---|
| 76 |
|
|---|
| 77 |
#region Error |
|---|
| 78 |
[DllImport(AprLibrary)] // CLSCompliant(false) |
|---|
| 79 |
private static extern void apr_strerror(int apr_status, |
|---|
| 80 |
StringBuilder buf, |
|---|
| 81 |
uint size); |
|---|
| 82 |
|
|---|
| 83 |
public static string StrError(int apr_status) |
|---|
| 84 |
{ |
|---|
| 85 |
StringBuilder buf = new StringBuilder (1024); |
|---|
| 86 |
Apr.apr_strerror(apr_status, buf, (uint)buf.Capacity); |
|---|
| 87 |
return(buf.ToString()); |
|---|
| 88 |
} |
|---|
| 89 |
#endregion |
|---|
| 90 |
|
|---|
| 91 |
#region Allocator |
|---|
| 92 |
[DllImport(AprLibrary)] static extern |
|---|
| 93 |
internal int apr_allocator_create(out IntPtr allocator); |
|---|
| 94 |
|
|---|
| 95 |
[DllImport(AprLibrary)] static extern |
|---|
| 96 |
internal void apr_allocator_destroy(IntPtr allocator); |
|---|
| 97 |
|
|---|
| 98 |
[DllImport(AprLibrary)] /* CLSCompliant(false) */ static extern |
|---|
| 99 |
internal IntPtr apr_allocator_alloc(IntPtr allocator, |
|---|
| 100 |
uint size); |
|---|
| 101 |
|
|---|
| 102 |
[DllImport(AprLibrary)] static extern |
|---|
| 103 |
internal void apr_allocator_free(IntPtr allocator, |
|---|
| 104 |
IntPtr memnode); |
|---|
| 105 |
|
|---|
| 106 |
[DllImport(AprLibrary)] static extern |
|---|
| 107 |
internal void apr_allocator_owner_set(IntPtr allocator, |
|---|
| 108 |
IntPtr pool); |
|---|
| 109 |
|
|---|
| 110 |
[DllImport(AprLibrary)] static extern |
|---|
| 111 |
internal IntPtr apr_allocator_owner_get(IntPtr allocator); |
|---|
| 112 |
|
|---|
| 113 |
[DllImport(AprLibrary)] /* CLSCompliant(false) */ static extern |
|---|
| 114 |
internal void apr_allocator_max_free_set(IntPtr allocator, |
|---|
| 115 |
uint size); |
|---|
| 116 |
|
|---|
| 117 |
[DllImport(AprLibrary)] static extern |
|---|
| 118 |
internal void apr_allocator_mutex_set(IntPtr allocator, |
|---|
| 119 |
IntPtr mutex); |
|---|
| 120 |
|
|---|
| 121 |
[DllImport(AprLibrary)] static extern |
|---|
| 122 |
internal IntPtr apr_allocator_mutex_get(IntPtr allocator); |
|---|
| 123 |
#endregion |
|---|
| 124 |
|
|---|
| 125 |
#region ThreadMutex |
|---|
| 126 |
[DllImport(AprLibrary)] /* CLSCompliant(false) */ static extern |
|---|
| 127 |
internal int apr_thread_mutex_create(out IntPtr mutext, |
|---|
| 128 |
uint flags, |
|---|
| 129 |
IntPtr pool); |
|---|
| 130 |
|
|---|
| 131 |
[DllImport(AprLibrary)] static extern |
|---|
| 132 |
internal int apr_thread_mutex_lock(IntPtr mutex); |
|---|
| 133 |
|
|---|
| 134 |
[DllImport(AprLibrary)] static extern |
|---|
| 135 |
internal int apr_thread_mutex_trylock(IntPtr mutex); |
|---|
| 136 |
|
|---|
| 137 |
[DllImport(AprLibrary)] static extern |
|---|
| 138 |
internal int apr_thread_mutex_unlock(IntPtr mutex); |
|---|
| 139 |
|
|---|
| 140 |
[DllImport(AprLibrary)] static extern |
|---|
| 141 |
internal int apr_thread_mutex_destroy(IntPtr mutex); |
|---|
| 142 |
|
|---|
| 143 |
[DllImport(AprLibrary)] static extern |
|---|
| 144 |
internal IntPtr apr_thread_mutex_pool_get(IntPtr mutex); |
|---|
| 145 |
#endregion |
|---|
| 146 |
|
|---|
| 147 |
#region Pool |
|---|
| 148 |
[DllImport(AprLibrary)] static extern |
|---|
| 149 |
internal int apr_pool_create_ex(out IntPtr newpool, IntPtr parent, |
|---|
| 150 |
IntPtr abort_fn, IntPtr allocator); |
|---|
| 151 |
|
|---|
| 152 |
[DllImport(AprLibrary)] static extern |
|---|
| 153 |
internal void apr_pool_destroy(IntPtr p); |
|---|
| 154 |
|
|---|
| 155 |
[DllImport(AprLibrary)] static extern |
|---|
| 156 |
internal IntPtr apr_pool_allocator_get(IntPtr pool); |
|---|
| 157 |
|
|---|
| 158 |
[DllImport(AprLibrary)] static extern |
|---|
| 159 |
internal void apr_pool_clear(IntPtr pool); |
|---|
| 160 |
|
|---|
| 161 |
[DllImport(AprLibrary)] /* CLSCompliant(false) */ static extern |
|---|
| 162 |
internal IntPtr apr_palloc(IntPtr pool, uint size); |
|---|
| 163 |
|
|---|
| 164 |
[DllImport(AprLibrary)] /* CLSCompliant(false) */ static extern |
|---|
| 165 |
internal IntPtr apr_pcalloc(IntPtr pool, uint size); |
|---|
| 166 |
|
|---|
| 167 |
[DllImport(AprLibrary)] static extern |
|---|
| 168 |
internal IntPtr apr_pool_parent_get(IntPtr pool); |
|---|
| 169 |
|
|---|
| 170 |
[DllImport(AprLibrary)] static extern |
|---|
| 171 |
internal int apr_pool_is_ancestor(IntPtr a, IntPtr b); |
|---|
| 172 |
/* |
|---|
| 173 |
[DllImport(AprLibrary)] static extern |
|---|
| 174 |
internal void apr_pool_tag(IntPtr pool, IntPtr tag); |
|---|
| 175 |
|
|---|
| 176 |
internal delegate int AprPoolCleanUpDelegate(IntPtr data); |
|---|
| 177 |
|
|---|
| 178 |
[DllImport(AprLibrary)] static extern |
|---|
| 179 |
internal int apr_pool_userdata_set(IntPtr data, |
|---|
| 180 |
IntPtr key, |
|---|
| 181 |
AprPoolCleanUpDelegate cleanup, |
|---|
| 182 |
IntPtr pool); |
|---|
| 183 |
|
|---|
| 184 |
[DllImport(AprLibrary)] static extern |
|---|
| 185 |
internal int apr_pool_userdata_setn(IntPtr data, |
|---|
| 186 |
IntPtr key, |
|---|
| 187 |
AprPoolCleanUpDelegate cleanup, |
|---|
| 188 |
IntPtr pool); |
|---|
| 189 |
|
|---|
| 190 |
[DllImport(AprLibrary)] static extern |
|---|
| 191 |
internal int apr_pool_userdata_get(out IntPtr data, |
|---|
| 192 |
IntPtr key, |
|---|
| 193 |
IntPtr pool); |
|---|
| 194 |
|
|---|
| 195 |
[DllImport(AprLibrary)] static extern |
|---|
| 196 |
internal void apr_pool_cleanup_register(IntPtr pool, |
|---|
| 197 |
IntPtr data, |
|---|
| 198 |
AprPoolCleanUpDelegate plaincleanup, |
|---|
| 199 |
AprPoolCleanUpDelegate childcleanup); |
|---|
| 200 |
|
|---|
| 201 |
[DllImport(AprLibrary)] static extern |
|---|
| 202 |
internal void apr_pool_cleanup_kill(IntPtr pool, |
|---|
| 203 |
IntPtr data, |
|---|
| 204 |
AprPoolCleanUpDelegate cleanup); |
|---|
| 205 |
|
|---|
| 206 |
[DllImport(AprLibrary)] static extern |
|---|
| 207 |
internal void apr_pool_child_cleanup_set(IntPtr pool, |
|---|
| 208 |
IntPtr data, |
|---|
| 209 |
AprPoolCleanUpDelegate plaincleanup, |
|---|
| 210 |
AprPoolCleanUpDelegate childcleanup); |
|---|
| 211 |
|
|---|
| 212 |
[DllImport(AprLibrary)] static extern |
|---|
| 213 |
internal int apr_pool_cleanup_run(IntPtr pool, |
|---|
| 214 |
IntPtr data, |
|---|
| 215 |
AprPoolCleanUpDelegate cleanup); |
|---|
| 216 |
|
|---|
| 217 |
[DllImport(AprLibrary)] static extern |
|---|
| 218 |
internal int apr_pool_cleanup_null(IntPtr data); |
|---|
| 219 |
|
|---|
| 220 |
[DllImport(AprLibrary)] static extern |
|---|
| 221 |
internal void apr_pool_cleanup_for_exec(); |
|---|
| 222 |
*/ |
|---|
| 223 |
#endregion |
|---|
| 224 |
|
|---|
| 225 |
#region AprTime |
|---|
| 226 |
[DllImport(AprLibrary)] static extern |
|---|
| 227 |
internal long apr_time_now(); |
|---|
| 228 |
|
|---|
| 229 |
[DllImport(AprLibrary)] static extern |
|---|
| 230 |
internal int apr_ctime(StringBuilder date_str, long input); |
|---|
| 231 |
|
|---|
| 232 |
[DllImport(AprLibrary)] static extern |
|---|
| 233 |
internal int apr_rfc822_date(StringBuilder date_str, long input); |
|---|
| 234 |
#endregion |
|---|
| 235 |
|
|---|
| 236 |
#region AprTimeExp |
|---|
| 237 |
[DllImport(AprLibrary)] static extern |
|---|
| 238 |
internal int apr_time_exp_gmt(IntPtr result, long input); |
|---|
| 239 |
|
|---|
| 240 |
[DllImport(AprLibrary)] static extern |
|---|
| 241 |
internal int apr_time_exp_gmt_get(out long result, IntPtr input); |
|---|
| 242 |
|
|---|
| 243 |
[DllImport(AprLibrary)] static extern |
|---|
| 244 |
internal int apr_time_exp_get(out long result, IntPtr input); |
|---|
| 245 |
|
|---|
| 246 |
[DllImport(AprLibrary)] static extern |
|---|
| 247 |
internal int apr_time_exp_lt(IntPtr result, long input); |
|---|
| 248 |
|
|---|
| 249 |
[DllImport(AprLibrary)] static extern |
|---|
| 250 |
internal int apr_time_exp_tz(IntPtr result, long input, int offset); |
|---|
| 251 |
|
|---|
| 252 |
[DllImport(AprLibrary)] /* CLSCompliant(false) */ static extern |
|---|
| 253 |
internal int apr_strftime(StringBuilder s, out uint retsize, |
|---|
| 254 |
uint maxsize, string Format, IntPtr input); |
|---|
| 255 |
#endregion |
|---|
| 256 |
|
|---|
| 257 |
#region AprString |
|---|
| 258 |
[DllImport(AprLibrary)] static extern |
|---|
| 259 |
internal IntPtr apr_pstrdup(IntPtr pool, IntPtr str); |
|---|
| 260 |
[DllImport(AprLibrary, CharSet=CharSet.Ansi)] static extern |
|---|
| 261 |
internal IntPtr apr_pstrdup(IntPtr pool, string str); |
|---|
| 262 |
|
|---|
| 263 |
[DllImport(AprLibrary)] /* CLSCompliant(false) */ static extern |
|---|
| 264 |
internal IntPtr apr_pstrndup(IntPtr pool, IntPtr str, uint size); |
|---|
| 265 |
[DllImport(AprLibrary, CharSet=CharSet.Ansi)] /* CLSCompliant(false) */ static extern |
|---|
| 266 |
internal IntPtr apr_pstrndup(IntPtr pool, string str, uint size); |
|---|
| 267 |
#endregion |
|---|
| 268 |
|
|---|
| 269 |
#region AprHash |
|---|
| 270 |
[DllImport(AprLibrary)] static extern |
|---|
| 271 |
internal IntPtr apr_hash_make(IntPtr pool); |
|---|
| 272 |
|
|---|
| 273 |
[DllImport(AprLibrary)] static extern |
|---|
| 274 |
internal IntPtr apr_hash_copy (IntPtr pool, IntPtr h); |
|---|
| 275 |
|
|---|
| 276 |
[DllImport(AprLibrary)] static extern |
|---|
| 277 |
internal void apr_hash_set (IntPtr ht, IntPtr key, int klen, IntPtr val); |
|---|
| 278 |
|
|---|
| 279 |
[DllImport(AprLibrary)] static extern |
|---|
| 280 |
internal IntPtr apr_hash_get (IntPtr ht, IntPtr key, int klen); |
|---|
| 281 |
|
|---|
| 282 |
[DllImport(AprLibrary)] /* CLSCompliant(false) */ static extern |
|---|
| 283 |
internal uint apr_hash_count(IntPtr ht); |
|---|
| 284 |
|
|---|
| 285 |
[DllImport(AprLibrary)] static extern |
|---|
| 286 |
internal IntPtr apr_hash_overlay (IntPtr p, IntPtr overlayh, IntPtr baseh); |
|---|
| 287 |
|
|---|
| 288 |
[DllImport(AprLibrary)] static extern |
|---|
| 289 |
internal IntPtr apr_hash_pool_get(IntPtr thehash); |
|---|
| 290 |
|
|---|
| 291 |
[DllImport(AprLibrary)] static extern |
|---|
| 292 |
internal IntPtr apr_hash_first (IntPtr p, IntPtr ht); |
|---|
| 293 |
|
|---|
| 294 |
[DllImport(AprLibrary)] static extern |
|---|
| 295 |
internal IntPtr apr_hash_next(IntPtr hi); |
|---|
| 296 |
|
|---|
| 297 |
[DllImport(AprLibrary)] static extern |
|---|
| 298 |
internal void apr_hash_this(IntPtr hi, out IntPtr key, out int klen, out IntPtr val); |
|---|
| 299 |
#endregion |
|---|
| 300 |
|
|---|
| 301 |
#region AprHash |
|---|
| 302 |
[DllImport(AprLibrary)] static extern |
|---|
| 303 |
internal IntPtr apr_array_make(IntPtr pool, int elts, int elt_size); |
|---|
| 304 |
|
|---|
| 305 |
[DllImport(AprLibrary)] static extern |
|---|
| 306 |
internal IntPtr apr_array_copy(IntPtr pool, IntPtr arr); |
|---|
| 307 |
|
|---|
| 308 |
[DllImport(AprLibrary)] static extern |
|---|
| 309 |
internal IntPtr apr_array_copy_hdr(IntPtr pool, IntPtr arr); |
|---|
| 310 |
|
|---|
| 311 |
[DllImport(AprLibrary)] static extern |
|---|
| 312 |
internal IntPtr apr_array_append (IntPtr pool, IntPtr first, IntPtr second); |
|---|
| 313 |
|
|---|
| 314 |
[DllImport(AprLibrary)] static extern |
|---|
| 315 |
internal void apr_array_cat (IntPtr dst, IntPtr src); |
|---|
| 316 |
|
|---|
| 317 |
[DllImport(AprLibrary, CharSet=CharSet.Ansi)] static extern |
|---|
| 318 |
internal IntPtr apr_array_pstrcat (IntPtr pool, IntPtr arr, char sep); |
|---|
| 319 |
|
|---|
| 320 |
[DllImport(AprLibrary)] static extern |
|---|
| 321 |
internal IntPtr apr_array_push(IntPtr arr); |
|---|
| 322 |
|
|---|
| 323 |
[DllImport(AprLibrary)] static extern |
|---|
| 324 |
internal IntPtr apr_array_pop(IntPtr arr); |
|---|
| 325 |
|
|---|
| 326 |
[DllImport(AprLibrary)] static extern |
|---|
| 327 |
internal bool apr_is_empty_array(IntPtr arr); |
|---|
| 328 |
#endregion |
|---|
| 329 |
|
|---|
| 330 |
#region AprFile |
|---|
| 331 |
[DllImport(AprLibrary, CharSet=CharSet.Ansi)] static extern |
|---|
| 332 |
internal int apr_file_open(out IntPtr new_file, string fname, |
|---|
| 333 |
int flag, int perm, IntPtr pool); |
|---|
| 334 |
|
|---|
| 335 |
[DllImport(AprLibrary)] static extern |
|---|
| 336 |
internal int apr_file_close(IntPtr file); |
|---|
| 337 |
|
|---|
| 338 |
[DllImport(AprLibrary)] static extern |
|---|
| 339 |
internal int apr_file_open_stdin(out IntPtr thefile, IntPtr pool); |
|---|
| 340 |
|
|---|
| 341 |
[DllImport(AprLibrary)] static extern |
|---|
| 342 |
internal int apr_file_open_stdout(out IntPtr thefile, IntPtr pool); |
|---|
| 343 |
|
|---|
| 344 |
[DllImport(AprLibrary)] static extern |
|---|
| 345 |
internal int apr_file_open_stderr(out IntPtr thefile, IntPtr pool); |
|---|
| 346 |
#endregion |
|---|
| 347 |
} |
|---|
| 348 |
} |
|---|