00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PJ_ERRNO_H__
00021 #define __PJ_ERRNO_H__
00022
00027 #include <pj/types.h>
00028 #include <pj/compat/errno.h>
00029 #include <stdarg.h>
00030
00031 PJ_BEGIN_DECL
00032
00085 #define PJ_ERR_MSG_SIZE 80
00086
00090 #ifndef PJ_PERROR_TITLE_BUF_SIZE
00091 # define PJ_PERROR_TITLE_BUF_SIZE 120
00092 #endif
00093
00094
00103 PJ_DECL(pj_status_t) pj_get_os_error(void);
00104
00109 PJ_DECL(void) pj_set_os_error(pj_status_t code);
00110
00115 PJ_DECL(pj_status_t) pj_get_netos_error(void);
00116
00121 PJ_DECL(void) pj_set_netos_error(pj_status_t code);
00122
00123
00135 PJ_DECL(pj_str_t) pj_strerror( pj_status_t statcode,
00136 char *buf, pj_size_t bufsize);
00137
00176 #define PJ_PERROR(level,arg) do { \
00177 pj_perror_wrapper_##level(arg); \
00178 } while (0)
00179
00202 PJ_DECL(void) pj_perror(int log_level, const char *sender, pj_status_t status,
00203 const char *title_fmt, ...);
00204
00205
00215 typedef pj_str_t (*pj_error_callback)(pj_status_t e, char *msg, pj_size_t max);
00216
00217
00237 PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start_code,
00238 pj_status_t err_space,
00239 pj_error_callback f);
00240
00258 #ifndef PJ_RETURN_OS_ERROR
00259 # define PJ_RETURN_OS_ERROR(os_code) (os_code ? \
00260 PJ_STATUS_FROM_OS(os_code) : -1)
00261 #endif
00262
00263
00273 #if PJ_NATIVE_ERR_POSITIVE
00274 # define PJ_STATUS_FROM_OS(e) (e == 0 ? PJ_SUCCESS : e + PJ_ERRNO_START_SYS)
00275 #else
00276 # define PJ_STATUS_FROM_OS(e) (e == 0 ? PJ_SUCCESS : PJ_ERRNO_START_SYS - e)
00277 #endif
00278
00289 #if PJ_NATIVE_ERR_POSITIVE
00290 # define PJ_STATUS_TO_OS(e) (e == 0 ? PJ_SUCCESS : e - PJ_ERRNO_START_SYS)
00291 #else
00292 # define PJ_STATUS_TO_OS(e) (e == 0 ? PJ_SUCCESS : PJ_ERRNO_START_SYS - e)
00293 #endif
00294
00295
00309 #ifndef PJ_BUILD_ERR
00310 # define PJ_BUILD_ERR(code,msg) { code, msg " (" #code ")" }
00311 #endif
00312
00313
00318 #define PJ_EUNKNOWN (PJ_ERRNO_START_STATUS + 1)
00319
00323 #define PJ_EPENDING (PJ_ERRNO_START_STATUS + 2)
00324
00328 #define PJ_ETOOMANYCONN (PJ_ERRNO_START_STATUS + 3)
00329
00333 #define PJ_EINVAL (PJ_ERRNO_START_STATUS + 4)
00334
00338 #define PJ_ENAMETOOLONG (PJ_ERRNO_START_STATUS + 5)
00339
00343 #define PJ_ENOTFOUND (PJ_ERRNO_START_STATUS + 6)
00344
00348 #define PJ_ENOMEM (PJ_ERRNO_START_STATUS + 7)
00349
00353 #define PJ_EBUG (PJ_ERRNO_START_STATUS + 8)
00354
00358 #define PJ_ETIMEDOUT (PJ_ERRNO_START_STATUS + 9)
00359
00363 #define PJ_ETOOMANY (PJ_ERRNO_START_STATUS + 10)
00364
00368 #define PJ_EBUSY (PJ_ERRNO_START_STATUS + 11)
00369
00373 #define PJ_ENOTSUP (PJ_ERRNO_START_STATUS + 12)
00374
00378 #define PJ_EINVALIDOP (PJ_ERRNO_START_STATUS + 13)
00379
00383 #define PJ_ECANCELLED (PJ_ERRNO_START_STATUS + 14)
00384
00388 #define PJ_EEXISTS (PJ_ERRNO_START_STATUS + 15)
00389
00393 #define PJ_EEOF (PJ_ERRNO_START_STATUS + 16)
00394
00398 #define PJ_ETOOBIG (PJ_ERRNO_START_STATUS + 17)
00399
00404 #define PJ_ERESOLVE (PJ_ERRNO_START_STATUS + 18)
00405
00409 #define PJ_ETOOSMALL (PJ_ERRNO_START_STATUS + 19)
00410
00414 #define PJ_EIGNORED (PJ_ERRNO_START_STATUS + 20)
00415
00419 #define PJ_EIPV6NOTSUP (PJ_ERRNO_START_STATUS + 21)
00420
00424 #define PJ_EAFNOTSUP (PJ_ERRNO_START_STATUS + 22)
00425
00427
00429
00430
00434 #define PJ_ERRNO_START 20000
00435
00440 #define PJ_ERRNO_SPACE_SIZE 50000
00441
00446 #define PJ_ERRNO_START_STATUS (PJ_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
00447
00453 #define PJ_ERRNO_START_SYS (PJ_ERRNO_START_STATUS + PJ_ERRNO_SPACE_SIZE)
00454
00460 #define PJ_ERRNO_START_USER (PJ_ERRNO_START_SYS + PJ_ERRNO_SPACE_SIZE)
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476 void pj_errno_clear_handlers(void);
00477
00478
00479
00480
00487 #if PJ_LOG_MAX_LEVEL >= 1
00488 #define pj_perror_wrapper_1(arg) pj_perror_1 arg
00489
00490 PJ_DECL(void) pj_perror_1(const char *sender, pj_status_t status,
00491 const char *title_fmt, ...);
00492 #else
00493 #define pj_perror_wrapper_1(arg)
00494 #endif
00495
00502 #if PJ_LOG_MAX_LEVEL >= 2
00503 #define pj_perror_wrapper_2(arg) pj_perror_2 arg
00504
00505 PJ_DECL(void) pj_perror_2(const char *sender, pj_status_t status,
00506 const char *title_fmt, ...);
00507 #else
00508 #define pj_perror_wrapper_2(arg)
00509 #endif
00510
00517 #if PJ_LOG_MAX_LEVEL >= 3
00518 #define pj_perror_wrapper_3(arg) pj_perror_3 arg
00519
00520 PJ_DECL(void) pj_perror_3(const char *sender, pj_status_t status,
00521 const char *title_fmt, ...);
00522 #else
00523 #define pj_perror_wrapper_3(arg)
00524 #endif
00525
00532 #if PJ_LOG_MAX_LEVEL >= 4
00533 #define pj_perror_wrapper_4(arg) pj_perror_4 arg
00534
00535 PJ_DECL(void) pj_perror_4(const char *sender, pj_status_t status,
00536 const char *title_fmt, ...);
00537 #else
00538 #define pj_perror_wrapper_4(arg)
00539 #endif
00540
00547 #if PJ_LOG_MAX_LEVEL >= 5
00548 #define pj_perror_wrapper_5(arg) pj_perror_5 arg
00549
00550 PJ_DECL(void) pj_perror_5(const char *sender, pj_status_t status,
00551 const char *title_fmt, ...);
00552 #else
00553 #define pj_perror_wrapper_5(arg)
00554 #endif
00555
00562 #if PJ_LOG_MAX_LEVEL >= 6
00563 #define pj_perror_wrapper_6(arg) pj_perror_6 arg
00564
00565 PJ_DECL(void) pj_perror_6(const char *sender, pj_status_t status,
00566 const char *title_fmt, ...);
00567 #else
00568 #define pj_perror_wrapper_6(arg)
00569 #endif
00570
00571
00572
00573
00574 PJ_END_DECL
00575
00576 #endif
00577