| 1 |
// |
|---|
| 2 |
// Softec |
|---|
| 3 |
// |
|---|
| 4 |
// Contact: |
|---|
| 5 |
// |
|---|
| 6 |
// Designed by Denis Gervalle and Olivier Desaive |
|---|
| 7 |
// Written by Denis Gervalle |
|---|
| 8 |
// |
|---|
| 9 |
// Copyright 2004 by SOFTEC. All rights reserved. |
|---|
| 10 |
// |
|---|
| 11 |
using System; |
|---|
| 12 |
using System.Runtime.InteropServices; |
|---|
| 13 |
using System.Text; |
|---|
| 14 |
using System.Diagnostics; |
|---|
| 15 |
|
|---|
| 16 |
namespace Softec.AprSharp |
|---|
| 17 |
{ |
|---|
| 18 |
|
|---|
| 19 |
///<summary>Embeds all APR external calls</summary> |
|---|
| 20 |
///<remark>Take care to call apr_initialize</remark> |
|---|
| 21 |
public class Apr |
|---|
| 22 |
{ |
|---|
| 23 |
// no instance constructor ! |
|---|
| 24 |
private Apr() { } |
|---|
| 25 |
|
|---|
| 26 |
static Apr() |
|---|
| 27 |
{ |
|---|
| 28 |
int apr_status; |
|---|
| 29 |
Debug.Write("apr_initialize..."); |
|---|
| 30 |
apr_status = apr_initialize(); |
|---|
| 31 |
Debug.WriteLine("Done"); |
|---|
| 32 |
if( apr_status != 0 ) |
|---|
| 33 |
throw new AprException(apr_status); |
|---|
| 34 |
|
|---|
| 35 |
//FIXME: Shoud shedule a call to apr_terminate |
|---|
| 36 |
// at process exit |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
#region Initialize / Terminate |
|---|
| 40 |
[DllImport("apr-0")] |
|---|
| 41 |
private static extern int apr_initialize( ); |
|---|
| 42 |
|
|---|
| 43 |
[DllImport("apr-0")] |
|---|
| 44 |
private static extern void apr_terminate( ); |
|---|
| 45 |
#endregion |
|---|
| 46 |
|
|---|
| 47 |
#region Error |
|---|
| 48 |
[DllImport("apr-0"), CLSCompliant(false)] |
|---|
| 49 |
private static extern void apr_strerror(int apr_status, |
|---|
| 50 |
StringBuilder buf, |
|---|
| 51 |
uint size); |
|---|
| 52 |
|
|---|
| 53 |
public static string StrError(int apr_status) |
|---|
| 54 |
{ |
|---|
| 55 |
StringBuilder buf = new StringBuilder (1024); |
|---|
| 56 |
Apr.apr_strerror(apr_status, buf, (uint)buf.Capacity); |
|---|
| 57 |
return(buf.ToString()); |
|---|
| 58 |
} |
|---|
| 59 |
#endregion |
|---|
| 60 |
|
|---|
| 61 |
#region Allocator |
|---|
| 62 |
[DllImport("apr-0")] static extern |
|---|
| 63 |
internal int apr_allocator_create(out IntPtr allocator); |
|---|
| 64 |
|
|---|
| 65 |
[DllImport("apr-0")] static extern |
|---|
| 66 |
internal void apr_allocator_destroy(IntPtr allocator); |
|---|
| 67 |
|
|---|
| 68 |
[DllImport("apr-0")] static extern |
|---|
| 69 |
internal IntPtr apr_allocator_alloc(IntPtr allocator, |
|---|
| 70 |
uint size); |
|---|
| 71 |
|
|---|
| 72 |
[DllImport("apr-0")] static extern |
|---|
| 73 |
internal void apr_allocator_free(IntPtr allocator, |
|---|
| 74 |
IntPtr memnode); |
|---|
| 75 |
|
|---|
| 76 |
[DllImport("apr-0")] static extern |
|---|
| 77 |
internal void apr_allocator_owner_set(IntPtr allocator, |
|---|
| 78 |
IntPtr pool); |
|---|
| 79 |
|
|---|
| 80 |
[DllImport("apr-0")] static extern |
|---|
| 81 |
internal IntPtr apr_allocator_owner_get(IntPtr allocator); |
|---|
| 82 |
|
|---|
| 83 |
[DllImport("apr-0"), CLSCompliant(false)] static extern |
|---|
| 84 |
internal void apr_allocator_max_free_set(IntPtr allocator, |
|---|
| 85 |
uint size); |
|---|
| 86 |
|
|---|
| 87 |
[DllImport("apr-0")] static extern |
|---|
| 88 |
internal void apr_allocator_mutex_set(IntPtr allocator, |
|---|
| 89 |
IntPtr mutex); |
|---|
| 90 |
|
|---|
| 91 |
[DllImport("apr-0")] static extern |
|---|
| 92 |
internal IntPtr apr_allocator_mutex_get(IntPtr allocator); |
|---|
| 93 |
#endregion |
|---|
| 94 |
|
|---|
| 95 |
#region ThreadMutex |
|---|
| 96 |
[DllImport("apr-0")] static extern |
|---|
| 97 |
internal int apr_thread_mutex_create(out IntPtr mutext, |
|---|
| 98 |
uint flags, |
|---|
| 99 |
IntPtr pool); |
|---|
| 100 |
|
|---|
| 101 |
[DllImport("apr-0")] static extern |
|---|
| 102 |
internal int apr_thread_mutex_lock(IntPtr mutex); |
|---|
| 103 |
|
|---|
| 104 |
[DllImport("apr-0")] static extern |
|---|
| 105 |
internal int apr_thread_mutex_trylock(IntPtr mutex); |
|---|
| 106 |
|
|---|
| 107 |
[DllImport("apr-0")] static extern |
|---|
| 108 |
internal int apr_thread_mutex_unlock(IntPtr mutex); |
|---|
| 109 |
|
|---|
| 110 |
[DllImport("apr-0")] static extern |
|---|
| 111 |
internal int apr_thread_mutex_destroy(IntPtr mutex); |
|---|
| 112 |
|
|---|
| 113 |
[DllImport("apr-0")] static extern |
|---|
| 114 |
internal IntPtr apr_thread_mutex_pool_get(IntPtr mutex); |
|---|
| 115 |
#endregion |
|---|
| 116 |
|
|---|
| 117 |
#region Pool |
|---|
| 118 |
[DllImport("apr-0")] static extern |
|---|
| 119 |
internal int apr_pool_create_ex(out IntPtr newpool, IntPtr parent, |
|---|
| 120 |
IntPtr abort_fn, IntPtr allocator); |
|---|
| 121 |
|
|---|
| 122 |
[DllImport("apr-0")] static extern |
|---|
| 123 |
internal void apr_pool_destroy(IntPtr p); |
|---|
| 124 |
|
|---|
| 125 |
[DllImport("apr-0")] static extern |
|---|
| 126 |
internal IntPtr apr_pool_allocator_get(IntPtr pool); |
|---|
| 127 |
|
|---|
| 128 |
[DllImport("apr-0")] static extern |
|---|
| 129 |
internal void apr_pool_clear(IntPtr pool); |
|---|
| 130 |
|
|---|
| 131 |
[DllImport("apr-0")] static extern |
|---|
| 132 |
internal IntPtr apr_palloc(IntPtr pool, uint size); |
|---|
| 133 |
|
|---|
| 134 |
[DllImport("apr-0")] static extern |
|---|
| 135 |
internal IntPtr apr_pcalloc(IntPtr pool, uint size); |
|---|
| 136 |
|
|---|
| 137 |
[DllImport("apr-0")] static extern |
|---|
| 138 |
internal IntPtr apr_pool_parent_get(IntPtr pool); |
|---|
| 139 |
|
|---|
| 140 |
[DllImport("apr-0")] static extern |
|---|
| 141 |
internal int apr_pool_is_ancestor(IntPtr a, IntPtr b); |
|---|
| 142 |
/* |
|---|
| 143 |
[DllImport("apr-0")] static extern |
|---|
| 144 |
internal void apr_pool_tag(IntPtr pool, IntPtr tag); |
|---|
| 145 |
|
|---|
| 146 |
internal delegate int AprPoolCleanUpDelegate(IntPtr data); |
|---|
| 147 |
|
|---|
| 148 |
[DllImport("apr-0")] static extern |
|---|
| 149 |
internal int apr_pool_userdata_set(IntPtr data, |
|---|
| 150 |
IntPtr key, |
|---|
| 151 |
AprPoolCleanUpDelegate cleanup, |
|---|
| 152 |
IntPtr pool); |
|---|
| 153 |
|
|---|
| 154 |
[DllImport("apr-0")] static extern |
|---|
| 155 |
internal int apr_pool_userdata_setn(IntPtr data, |
|---|
| 156 |
IntPtr key, |
|---|
| 157 |
AprPoolCleanUpDelegate cleanup, |
|---|
| 158 |
IntPtr pool); |
|---|
| 159 |
|
|---|
| 160 |
[DllImport("apr-0")] static extern |
|---|
| 161 |
internal int apr_pool_userdata_get(out IntPtr data, |
|---|
| 162 |
IntPtr key, |
|---|
| 163 |
IntPtr pool); |
|---|
| 164 |
|
|---|
| 165 |
[DllImport("apr-0")] static extern |
|---|
| 166 |
internal void apr_pool_cleanup_register(IntPtr pool, |
|---|
| 167 |
IntPtr data, |
|---|
| 168 |
AprPoolCleanUpDelegate plaincleanup, |
|---|
| 169 |
AprPoolCleanUpDelegate childcleanup); |
|---|
| 170 |
|
|---|
| 171 |
[DllImport("apr-0")] static extern |
|---|
| 172 |
internal void apr_pool_cleanup_kill(IntPtr pool, |
|---|
| 173 |
IntPtr data, |
|---|
| 174 |
AprPoolCleanUpDelegate cleanup); |
|---|
| 175 |
|
|---|
| 176 |
[DllImport("apr-0")] static extern |
|---|
| 177 |
internal void apr_pool_child_cleanup_set(IntPtr pool, |
|---|
| 178 |
IntPtr data, |
|---|
| 179 |
AprPoolCleanUpDelegate plaincleanup, |
|---|
| 180 |
AprPoolCleanUpDelegate childcleanup); |
|---|
| 181 |
|
|---|
| 182 |
[DllImport("apr-0")] static extern |
|---|
| 183 |
internal int apr_pool_cleanup_run(IntPtr pool, |
|---|
| 184 |
IntPtr data, |
|---|
| 185 |
AprPoolCleanUpDelegate cleanup); |
|---|
| 186 |
|
|---|
| 187 |
[DllImport("apr-0")] static extern |
|---|
| 188 |
internal int apr_pool_cleanup_null(IntPtr data); |
|---|
| 189 |
|
|---|
| 190 |
[DllImport("apr-0")] static extern |
|---|
| 191 |
internal void apr_pool_cleanup_for_exec(); |
|---|
| 192 |
*/ |
|---|
| 193 |
#endregion |
|---|
| 194 |
|
|---|
| 195 |
#region AprTime |
|---|
| 196 |
[DllImport("apr-0")] static extern |
|---|
| 197 |
internal long apr_time_now(); |
|---|
| 198 |
|
|---|
| 199 |
[DllImport("apr-0")] static extern |
|---|
| 200 |
internal int apr_ctime(StringBuilder date_str, long input); |
|---|
| 201 |
|
|---|
| 202 |
[DllImport("apr-0")] static extern |
|---|
| 203 |
internal int apr_rfc822_date(StringBuilder date_str, long input); |
|---|
| 204 |
#endregion |
|---|
| 205 |
|
|---|
| 206 |
#region AprTimeExp |
|---|
| 207 |
[DllImport("apr-0")] static extern |
|---|
| 208 |
internal int apr_time_exp_gmt(IntPtr result, long input); |
|---|
| 209 |
|
|---|
| 210 |
[DllImport("apr-0")] static extern |
|---|
| 211 |
internal int apr_time_exp_gmt_get(out long result, IntPtr input); |
|---|
| 212 |
|
|---|
| 213 |
[DllImport("apr-0")] static extern |
|---|
| 214 |
internal int apr_time_exp_get(out long result, IntPtr input); |
|---|
| 215 |
|
|---|
| 216 |
[DllImport("apr-0")] static extern |
|---|
| 217 |
internal int apr_time_exp_lt(IntPtr result, long input); |
|---|
| 218 |
|
|---|
| 219 |
[DllImport("apr-0")] static extern |
|---|
| 220 |
internal int apr_time_exp_tz(IntPtr result, long input, int offset); |
|---|
| 221 |
|
|---|
| 222 |
[DllImport("apr-0")] static extern |
|---|
| 223 |
internal int apr_strftime(StringBuilder s, out uint retsize, |
|---|
| 224 |
uint maxsize, string Format, IntPtr input); |
|---|
| 225 |
#endregion |
|---|
| 226 |
|
|---|
| 227 |
#region AprString |
|---|
| 228 |
[DllImport("apr-0")] static extern |
|---|
| 229 |
internal IntPtr apr_pstrdup(IntPtr pool, IntPtr str); |
|---|
| 230 |
[DllImport("apr-0", CharSet=CharSet.Ansi)] static extern |
|---|
| 231 |
internal IntPtr apr_pstrdup(IntPtr pool, string str); |
|---|
| 232 |
|
|---|
| 233 |
[DllImport("apr-0")] static extern |
|---|
| 234 |
internal IntPtr apr_pstrndup(IntPtr pool, IntPtr str, uint size); |
|---|
| 235 |
[DllImport("apr-0", CharSet=CharSet.Ansi)] static extern |
|---|
| 236 |
internal IntPtr apr_pstrndup(IntPtr pool, string str, uint size); |
|---|
| 237 |
/* |
|---|
| 238 |
[DllImport("apr-0")] static extern |
|---|
| 239 |
internal IntPtr apr_pmemdup(IntPtr pool, IntPtr mem, uint size); |
|---|
| 240 |
|
|---|
| 241 |
[DllImport("apr-0")] static extern |
|---|
| 242 |
internal IntPtr apr_pstrmemdup(IntPtr pool, IntPtr str, uint size); |
|---|
| 243 |
[DllImport("apr-0", CharSet=CharSet.Ansi)] static extern |
|---|
| 244 |
internal IntPtr apr_pstrmemdup(IntPtr pool, string str, uint size); |
|---|
| 245 |
|
|---|
| 246 |
[DllImport("apr-0")] static extern |
|---|
| 247 |
internal int apr_strnatcmp(IntPtr stra, IntPtr strb); |
|---|
| 248 |
[DllImport("apr-0")] static extern |
|---|
| 249 |
internal int apr_strnatcmp(IntPtr stra, string strb); |
|---|
| 250 |
|
|---|
| 251 |
[DllImport("apr-0")] static extern |
|---|
| 252 |
internal int apr_strnatcasecmp(IntPtr stra, IntPtr strb); |
|---|
| 253 |
[DllImport("apr-0")] static extern |
|---|
| 254 |
internal int apr_strnatcasecmp(IntPtr stra, string strb); |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
[DllImport("apr-0")] static extern |
|---|
| 258 |
internal char * apr_pstrcat (apr_pool_t *p,...) |
|---|
| 259 |
|
|---|
| 260 |
[DllImport("apr-0")] static extern |
|---|
| 261 |
internal char * apr_pstrcatv (apr_pool_t *p, const struct iovec *vec, apr_size_t nvec, apr_size_t *nbytes) |
|---|
| 262 |
|
|---|
| 263 |
[DllImport("apr-0")] static extern |
|---|
| 264 |
internal char * apr_pvsprintf (apr_pool_t *p, const char *fmt, va_list ap) |
|---|
| 265 |
|
|---|
| 266 |
[DllImport("apr-0")] static extern |
|---|
| 267 |
internal char * apr_psprintf (apr_pool_t *p, const char *fmt,...) |
|---|
| 268 |
|
|---|
| 269 |
[DllImport("apr-0")] static extern |
|---|
| 270 |
internal char * apr_cpystrn (char *dst, const char *src, apr_size_t dst_size) |
|---|
| 271 |
|
|---|
| 272 |
[DllImport("apr-0")] static extern |
|---|
| 273 |
internal char * apr_collapse_spaces (char *dest, const char *src) |
|---|
| 274 |
|
|---|
| 275 |
[DllImport("apr-0")] static extern |
|---|
| 276 |
internal apr_status_t apr_tokenize_to_argv (const char *arg_str, char ***argv_out, apr_pool_t *token_context) |
|---|
| 277 |
|
|---|
| 278 |
[DllImport("apr-0")] static extern |
|---|
| 279 |
internal char * apr_strtok (char *str, const char *sep, char **last) |
|---|
| 280 |
|
|---|
| 281 |
[DllImport("apr-0")] static extern |
|---|
| 282 |
internal char * apr_itoa (apr_pool_t *p, int n) |
|---|
| 283 |
|
|---|
| 284 |
[DllImport("apr-0")] static extern |
|---|
| 285 |
internal char * apr_ltoa (apr_pool_t *p, long n) |
|---|
| 286 |
|
|---|
| 287 |
[DllImport("apr-0")] static extern |
|---|
| 288 |
internal char * apr_off_t_toa (apr_pool_t *p, apr_off_t n) |
|---|
| 289 |
|
|---|
| 290 |
[DllImport("apr-0")] static extern |
|---|
| 291 |
internal apr_int64_t apr_strtoi64 (const char *buf, char **end, int base) |
|---|
| 292 |
|
|---|
| 293 |
[DllImport("apr-0")] static extern |
|---|
| 294 |
internal apr_int64_t apr_atoi64 (const char *buf) |
|---|
| 295 |
|
|---|
| 296 |
[DllImport("apr-0")] static extern |
|---|
| 297 |
internal char * apr_strfsize (apr_off_t size, char *buf) |
|---|
| 298 |
*/ |
|---|
| 299 |
#endregion |
|---|
| 300 |
} |
|---|
| 301 |
} |
|---|