From 6cbba81e8937d6793705608e7e68e83ec950dd2a Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Thu, 2 Feb 2006 19:15:03 +0000 Subject: Added framework for attaching custom error message handler git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@128 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/errno.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 5 deletions(-) (limited to 'pjlib/src/pj/errno.c') diff --git a/pjlib/src/pj/errno.c b/pjlib/src/pj/errno.c index d214d687..9c2d072f 100644 --- a/pjlib/src/pj/errno.c +++ b/pjlib/src/pj/errno.c @@ -18,6 +18,7 @@ */ #include #include +#include #include /* Prototype for platform specific error message, which will be defined @@ -26,6 +27,18 @@ extern int platform_strerror( pj_os_err_type code, char *buf, pj_size_t bufsize ); +#define PJLIB_MAX_ERR_MSG_HANDLER 8 + +/* Error message handler. */ +static unsigned err_msg_hnd_cnt; +static struct err_msg_hnd +{ + pj_status_t begin; + pj_status_t end; + pj_str_t (*strerror)(pj_status_t, char*, pj_size_t); + +} err_msg_hnd[PJLIB_MAX_ERR_MSG_HANDLER]; + /* PJLIB's own error codes/messages */ static const struct { @@ -76,6 +89,45 @@ static int pjlib_error(pj_status_t code, char *buf, pj_size_t size) return 3; } +#define IN_RANGE(val,start,end) ((val)>=(start) && (val)<(end)) + +/* Register strerror handle. */ +PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start, + pj_status_t space, + pj_str_t (*f)(pj_status_t,char*, + pj_size_t)) +{ + unsigned i; + + /* Check arguments. */ + PJ_ASSERT_RETURN(start && space && f, PJ_EINVAL); + + /* Check if there aren't too many handlers registered. */ + PJ_ASSERT_RETURN(err_msg_hnd_cnt < PJ_ARRAY_SIZE(err_msg_hnd), + PJ_ETOOMANY); + + /* Start error must be greater than PJ_ERRNO_START_USER */ + PJ_ASSERT_RETURN(start >= PJ_ERRNO_START_USER, PJ_EEXISTS); + + /* Check that no existing handler has covered the specified range. */ + for (i=0; i