apr_portable.h

Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /* This header file is where you should put ANY platform specific information.
00018  * This should be the only header file that programs need to include that 
00019  * actually has platform dependant code which refers to the .
00020  */
00021 #ifndef APR_PORTABLE_H
00022 #define APR_PORTABLE_H
00023 /**
00024  * @file apr_portable.h
00025  * @brief APR Portability Routines
00026  */
00027 
00028 #include "apr.h"
00029 #include "apr_pools.h"
00030 #include "apr_thread_proc.h"
00031 #include "apr_file_io.h"
00032 #include "apr_network_io.h"
00033 #include "apr_errno.h"
00034 #include "apr_global_mutex.h"
00035 #include "apr_proc_mutex.h"
00036 #include "apr_time.h"
00037 #include "apr_dso.h"
00038 #include "apr_shm.h"
00039 
00040 #if APR_HAVE_DIRENT_H
00041 #include <dirent.h>
00042 #endif
00043 #if APR_HAVE_FCNTL_H
00044 #include <fcntl.h>
00045 #endif
00046 #if APR_HAVE_PTHREAD_H
00047 #include <pthread.h>
00048 #endif
00049 
00050 #ifdef __cplusplus
00051 extern "C" {
00052 #endif /* __cplusplus */
00053 
00054 /**
00055  * @defgroup apr_portabile Portability Routines
00056  * @ingroup APR 
00057  * @{
00058  */
00059 
00060 #ifdef WIN32
00061 /* The primitives for Windows types */
00062 typedef HANDLE                apr_os_file_t;
00063 typedef HANDLE                apr_os_dir_t;
00064 typedef SOCKET                apr_os_sock_t;
00065 typedef HANDLE                apr_os_proc_mutex_t;
00066 typedef HANDLE                apr_os_thread_t;
00067 typedef HANDLE                apr_os_proc_t;
00068 typedef DWORD                 apr_os_threadkey_t; 
00069 typedef FILETIME              apr_os_imp_time_t;
00070 typedef SYSTEMTIME            apr_os_exp_time_t;
00071 typedef HANDLE                apr_os_dso_handle_t;
00072 typedef HANDLE                apr_os_shm_t;
00073 
00074 #elif defined(OS2)
00075 typedef HFILE                 apr_os_file_t;
00076 typedef HDIR                  apr_os_dir_t;
00077 typedef int                   apr_os_sock_t;
00078 typedef HMTX                  apr_os_proc_mutex_t;
00079 typedef TID                   apr_os_thread_t;
00080 typedef PID                   apr_os_proc_t;
00081 typedef PULONG                apr_os_threadkey_t; 
00082 typedef struct timeval        apr_os_imp_time_t;
00083 typedef struct tm             apr_os_exp_time_t;
00084 typedef HMODULE               apr_os_dso_handle_t;
00085 typedef void*                 apr_os_shm_t;
00086 
00087 #elif defined(__BEOS__)
00088 #include <kernel/OS.h>
00089 #include <kernel/image.h>
00090 
00091 struct apr_os_proc_mutex_t {
00092         sem_id sem;
00093         int32  ben;
00094 };
00095 
00096 typedef int                   apr_os_file_t;
00097 typedef DIR                   apr_os_dir_t;
00098 typedef int                   apr_os_sock_t;
00099 typedef struct apr_os_proc_mutex_t  apr_os_proc_mutex_t;
00100 typedef thread_id             apr_os_thread_t;
00101 typedef thread_id             apr_os_proc_t;
00102 typedef int                   apr_os_threadkey_t;
00103 typedef struct timeval        apr_os_imp_time_t;
00104 typedef struct tm             apr_os_exp_time_t;
00105 typedef image_id              apr_os_dso_handle_t;
00106 typedef void*                 apr_os_shm_t;
00107 
00108 #elif defined(NETWARE)
00109 typedef int                   apr_os_file_t;
00110 typedef DIR                   apr_os_dir_t;
00111 typedef int                   apr_os_sock_t;
00112 typedef NXMutex_t             apr_os_proc_mutex_t;
00113 typedef NXThreadId_t          apr_os_thread_t;
00114 typedef long                  apr_os_proc_t;
00115 typedef NXKey_t               apr_os_threadkey_t; 
00116 typedef struct timeval        apr_os_imp_time_t;
00117 typedef struct tm             apr_os_exp_time_t;
00118 typedef void *                apr_os_dso_handle_t;
00119 typedef void*                 apr_os_shm_t;
00120 
00121 #else
00122 /* Any other OS should go above this one.  This is the lowest common
00123  * denominator typedefs for  all UNIX-like systems.  :)
00124  */
00125 
00126 /** Basic OS process mutex structure. */
00127 struct apr_os_proc_mutex_t {
00128 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
00129     /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
00130     int crossproc;
00131 #endif
00132 #if APR_HAS_PROC_PTHREAD_SERIALIZE
00133     /** Value used for PTHREAD serialization */
00134     pthread_mutex_t *pthread_interproc;
00135 #endif
00136 #if APR_HAS_THREADS
00137     /* If no threads, no need for thread locks */
00138 #if APR_USE_PTHREAD_SERIALIZE
00139     /** This value is currently unused within APR and Apache */ 
00140     pthread_mutex_t *intraproc;
00141 #endif
00142 #endif
00143 };
00144 
00145 typedef int                   apr_os_file_t;        /**< native file */
00146 typedef DIR                   apr_os_dir_t;         /**< native dir */
00147 typedef int                   apr_os_sock_t;        /**< native dir */
00148 typedef struct apr_os_proc_mutex_t  apr_os_proc_mutex_t; /**< native proces
00149                                                           *   mutex
00150                                                           */
00151 #if APR_HAS_THREADS && APR_HAVE_PTHREAD_H 
00152 typedef pthread_t             apr_os_thread_t;      /**< native thread */
00153 typedef pthread_key_t         apr_os_threadkey_t;   /**< native thread address
00154                                                      *   space */
00155 #endif
00156 typedef pid_t                 apr_os_proc_t;        /**< native pid */
00157 typedef struct timeval        apr_os_imp_time_t;    /**< native timeval */
00158 typedef struct tm             apr_os_exp_time_t;    /**< native tm */
00159 /** @var apr_os_dso_handle_t
00160  * native dso types
00161  */
00162 #if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
00163 #include <dl.h>
00164 typedef shl_t                 apr_os_dso_handle_t;
00165 #elif defined(DARWIN)
00166 #include <mach-o/dyld.h>
00167 typedef NSModule              apr_os_dso_handle_t;
00168 #else
00169 typedef void *                apr_os_dso_handle_t;
00170 #endif
00171 typedef void*                 apr_os_shm_t;         /**< native SHM */
00172 
00173 #endif
00174 
00175 /**
00176  * @typedef apr_os_sock_info_t
00177  * @brief alias for local OS socket
00178  */
00179 /**
00180  * everything APR needs to know about an active socket to construct
00181  * an APR socket from it; currently, this is platform-independent
00182  */
00183 struct apr_os_sock_info_t {
00184     apr_os_sock_t *os_sock; /**< always required */
00185     struct sockaddr *local; /**< NULL if not yet bound */
00186     struct sockaddr *remote; /**< NULL if not connected */
00187     int family;             /**< always required (APR_INET, APR_INET6, etc.) */
00188     int type;               /**< always required (SOCK_STREAM, SOCK_DGRAM, etc.) */
00189     int protocol;           /**< 0 or actual protocol (APR_PROTO_SCTP, APR_PROTO_TCP, etc.) */
00190 };
00191 
00192 typedef struct apr_os_sock_info_t apr_os_sock_info_t;
00193 
00194 #if APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)
00195 /** Opaque global mutex type */
00196 #define apr_os_global_mutex_t apr_os_proc_mutex_t
00197 /** @return apr_os_global_mutex */
00198 #define apr_os_global_mutex_get apr_os_proc_mutex_get
00199 #else
00200     /** Thread and process mutex for those platforms where process mutexes
00201      *  are not held in threads.
00202      */
00203     struct apr_os_global_mutex_t {
00204         apr_pool_t *pool;
00205         apr_proc_mutex_t *proc_mutex;
00206 #if APR_HAS_THREADS
00207         apr_thread_mutex_t *thread_mutex;
00208 #endif /* APR_HAS_THREADS */
00209     };
00210     typedef struct apr_os_global_mutex_t apr_os_global_mutex_t;
00211 
00212 APR_DECLARE(apr_status_t) apr_os_global_mutex_get(apr_os_global_mutex_t *ospmutex, 
00213                                                 apr_global_mutex_t *pmutex);
00214 #endif
00215 
00216 
00217 /**
00218  * convert the file from apr type to os specific type.
00219  * @param thefile The os specific file we are converting to
00220  * @param file The apr file to convert.
00221  * @remark On Unix, it is only possible to get a file descriptor from 
00222  *         an apr file type.
00223  */
00224 APR_DECLARE(apr_status_t) apr_os_file_get(apr_os_file_t *thefile,
00225                                           apr_file_t *file);
00226 
00227 /**
00228  * convert the dir from apr type to os specific type.
00229  * @param thedir The os specific dir we are converting to
00230  * @param dir The apr dir to convert.
00231  */   
00232 APR_DECLARE(apr_status_t) apr_os_dir_get(apr_os_dir_t **thedir, 
00233                                          apr_dir_t *dir);
00234 
00235 /**
00236  * Convert the socket from an apr type to an OS specific socket
00237  * @param thesock The socket to convert.
00238  * @param sock The os specifc equivelant of the apr socket..
00239  */
00240 APR_DECLARE(apr_status_t) apr_os_sock_get(apr_os_sock_t *thesock,
00241                                           apr_socket_t *sock);
00242 
00243 /**
00244  * Convert the proc mutex from os specific type to apr type
00245  * @param ospmutex The os specific proc mutex we are converting to.
00246  * @param pmutex The apr proc mutex to convert.
00247  */
00248 APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex, 
00249                                                 apr_proc_mutex_t *pmutex);
00250 
00251 /**
00252  * Get the exploded time in the platforms native format.
00253  * @param ostime the native time format
00254  * @param aprtime the time to convert
00255  */
00256 APR_DECLARE(apr_status_t) apr_os_exp_time_get(apr_os_exp_time_t **ostime,
00257                                  apr_time_exp_t *aprtime);
00258 
00259 /**
00260  * Get the imploded time in the platforms native format.
00261  * @param ostime  the native time format
00262  * @param aprtime the time to convert
00263  */
00264 APR_DECLARE(apr_status_t) apr_os_imp_time_get(apr_os_imp_time_t **ostime, 
00265                                               apr_time_t *aprtime);
00266 
00267 /**
00268  * convert the shm from apr type to os specific type.
00269  * @param osshm The os specific shm representation
00270  * @param shm The apr shm to convert.
00271  */   
00272 APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,
00273                                          apr_shm_t *shm);
00274 
00275 #if APR_HAS_THREADS || defined(DOXYGEN)
00276 /** 
00277  * @defgroup apr_os_thread Thread portability Routines
00278  * @{ 
00279  */
00280 /**
00281  * convert the thread to os specific type from apr type.
00282  * @param thethd The apr thread to convert
00283  * @param thd The os specific thread we are converting to
00284  */
00285 APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd, 
00286                                             apr_thread_t *thd);
00287 
00288 /**
00289  * convert the thread private memory key to os specific type from an apr type.
00290  * @param thekey The apr handle we are converting from.
00291  * @param key The os specific handle we are converting to.
00292  */
00293 APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey,
00294                                                apr_threadkey_t *key);
00295 
00296 /**
00297  * convert the thread from os specific type to apr type.
00298  * @param thd The apr thread we are converting to.
00299  * @param thethd The os specific thread to convert
00300  * @param cont The pool to use if it is needed.
00301  */
00302 APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd,
00303                                             apr_os_thread_t *thethd,
00304                                             apr_pool_t *cont);
00305 
00306 /**
00307  * convert the thread private memory key from os specific type to apr type.
00308  * @param key The apr handle we are converting to.
00309  * @param thekey The os specific handle to convert
00310  * @param cont The pool to use if it is needed.
00311  */
00312 APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
00313                                                apr_os_threadkey_t *thekey,
00314                                                apr_pool_t *cont);
00315 /**
00316  * Get the thread ID
00317  */
00318 APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void);
00319 
00320 /**
00321  * Compare two thread id's
00322  * @param tid1 1st Thread ID to compare
00323  * @param tid2 2nd Thread ID to compare
00324  */ 
00325 APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1, 
00326                                      apr_os_thread_t tid2);
00327 
00328 /** @} */
00329 #endif /* APR_HAS_THREADS */
00330 
00331 /**
00332  * convert the file from os specific type to apr type.
00333  * @param file The apr file we are converting to.
00334  * @param thefile The os specific file to convert
00335  * @param flags The flags that were used to open this file.
00336  * @param cont The pool to use if it is needed.
00337  * @remark On Unix, it is only possible to put a file descriptor into
00338  *         an apr file type.
00339  */
00340 APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file,
00341                                           apr_os_file_t *thefile,
00342                                           apr_int32_t flags, apr_pool_t *cont); 
00343 
00344 /**
00345  * convert the file from os specific type to apr type.
00346  * @param file The apr file we are converting to.
00347  * @param thefile The os specific pipe to convert
00348  * @param cont The pool to use if it is needed.
00349  * @remark On Unix, it is only possible to put a file descriptor into
00350  *         an apr file type.
00351  */
00352 APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file,
00353                                           apr_os_file_t *thefile,
00354                                           apr_pool_t *cont);
00355 
00356 /**
00357  * convert the file from os specific type to apr type.
00358  * @param file The apr file we are converting to.
00359  * @param thefile The os specific pipe to convert
00360  * @param register_cleanup A cleanup will be registered on the apr_file_t
00361  *   to issue apr_file_close().
00362  * @param cont The pool to use if it is needed.
00363  * @remark On Unix, it is only possible to put a file descriptor into
00364  *         an apr file type.
00365  */
00366 APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
00367                                              apr_os_file_t *thefile,
00368                                              int register_cleanup,
00369                                              apr_pool_t *cont);
00370 
00371 /**
00372  * convert the dir from os specific type to apr type.
00373  * @param dir The apr dir we are converting to.
00374  * @param thedir The os specific dir to convert
00375  * @param cont The pool to use when creating to apr directory.
00376  */
00377 APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir,
00378                                          apr_os_dir_t *thedir,
00379                                          apr_pool_t *cont); 
00380 
00381 /**
00382  * Convert a socket from the os specific type to the apr type
00383  * @param sock The pool to use.
00384  * @param thesock The socket to convert to.
00385  * @param cont The socket we are converting to an apr type.
00386  * @remark If it is a true socket, it is best to call apr_os_sock_make()
00387  *         and provide APR with more information about the socket.
00388  */
00389 APR_DECLARE(apr_status_t) apr_os_sock_put(apr_socket_t **sock, 
00390                                           apr_os_sock_t *thesock, 
00391                                           apr_pool_t *cont);
00392 
00393 /**
00394  * Create a socket from an existing descriptor and local and remote
00395  * socket addresses.
00396  * @param apr_sock The new socket that has been set up
00397  * @param os_sock_info The os representation of the socket handle and
00398  *        other characteristics of the socket
00399  * @param cont The pool to use
00400  * @remark If you only know the descriptor/handle or if it isn't really
00401  *         a true socket, use apr_os_sock_put() instead.
00402  */
00403 APR_DECLARE(apr_status_t) apr_os_sock_make(apr_socket_t **apr_sock,
00404                                            apr_os_sock_info_t *os_sock_info,
00405                                            apr_pool_t *cont);
00406 
00407 /**
00408  * Convert the proc mutex from os specific type to apr type
00409  * @param pmutex The apr proc mutex we are converting to.
00410  * @param ospmutex The os specific proc mutex to convert.
00411  * @param cont The pool to use if it is needed.
00412  */
00413 APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
00414                                                 apr_os_proc_mutex_t *ospmutex,
00415                                                 apr_pool_t *cont); 
00416 
00417 /**
00418  * Put the imploded time in the APR format.
00419  * @param aprtime the APR time format
00420  * @param ostime the time to convert
00421  * @param cont the pool to use if necessary
00422  */
00423 APR_DECLARE(apr_status_t) apr_os_imp_time_put(apr_time_t *aprtime,
00424                                               apr_os_imp_time_t **ostime,
00425                                               apr_pool_t *cont); 
00426 
00427 /**
00428  * Put the exploded time in the APR format.
00429  * @param aprtime the APR time format
00430  * @param ostime the time to convert
00431  * @param cont the pool to use if necessary
00432  */
00433 APR_DECLARE(apr_status_t) apr_os_exp_time_put(apr_time_exp_t *aprtime,
00434                                               apr_os_exp_time_t **ostime,
00435                                               apr_pool_t *cont); 
00436 
00437 /**
00438  * convert the shared memory from os specific type to apr type.
00439  * @param shm The apr shm representation of osshm
00440  * @param osshm The os specific shm identity
00441  * @param cont The pool to use if it is needed.
00442  * @remark On fork()ed architectures, this is typically nothing more than
00443  * the memory block mapped.  On non-fork architectures, this is typically
00444  * some internal handle to pass the mapping from process to process.
00445  */
00446 APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **shm,
00447                                          apr_os_shm_t *osshm,
00448                                          apr_pool_t *cont); 
00449 
00450 
00451 #if APR_HAS_DSO || defined(DOXYGEN)
00452 /** 
00453  * @defgroup apr_os_dso DSO (Dynamic Loading) Portabiliity Routines
00454  * @{
00455  */
00456 /**
00457  * convert the dso handle from os specific to apr
00458  * @param dso The apr handle we are converting to
00459  * @param thedso the os specific handle to convert
00460  * @param pool the pool to use if it is needed
00461  */
00462 APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **dso,
00463                                                 apr_os_dso_handle_t thedso,
00464                                                 apr_pool_t *pool);
00465 
00466 /**
00467  * convert the apr dso handle into an os specific one
00468  * @param aprdso The apr dso handle to convert
00469  * @param dso The os specific dso to return
00470  */
00471 APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *dso,
00472                                                 apr_dso_handle_t *aprdso);
00473 
00474 #if APR_HAS_OS_UUID
00475 /**
00476  * Private: apr-util's apr_uuid module when supported by the platform
00477  */
00478 APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data);
00479 #endif
00480 
00481 /** @} */
00482 #endif /* APR_HAS_DSO */
00483 
00484 
00485 /**
00486  * Get the name of the system default characer set.
00487  * @param pool the pool to allocate the name from, if needed
00488  */
00489 APR_DECLARE(const char*) apr_os_default_encoding(apr_pool_t *pool);
00490 
00491 
00492 /**
00493  * Get the name of the current locale character set.
00494  * @param pool the pool to allocate the name from, if needed
00495  * @remark Defers to apr_os_default_encoding if the current locale's
00496  * data can't be retreved on this system.
00497  */
00498 APR_DECLARE(const char*) apr_os_locale_encoding(apr_pool_t *pool);
00499 
00500 /** @} */
00501 
00502 #ifdef __cplusplus
00503 }
00504 #endif
00505 
00506 #endif  /* ! APR_PORTABLE_H */

Generated on Mon Nov 26 11:23:52 2007 for Apache Portable Runtime by  doxygen 1.5.2