~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjsip/src/pjsip-simple/errno.c

  • Committer: Jackson Doak
  • Date: 2013-07-10 21:04:46 UTC
  • mfrom: (20.1.3 sid)
  • Revision ID: noskcaj@ubuntu.com-20130710210446-y8f587vza807icr9
Properly merged from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: errno.c 3553 2011-05-05 06:14:19Z nanang $ */
 
2
/*
 
3
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
 
4
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
#include <pjsip-simple/errno.h>
 
21
#include <pj/string.h>
 
22
 
 
23
/* PJSIP-SIMPLE's own error codes/messages
 
24
 * MUST KEEP THIS ARRAY SORTED!!
 
25
 * Message must be limited to 64 chars!
 
26
 */
 
27
 
 
28
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
 
29
 
 
30
static const struct
 
31
{
 
32
    int code;
 
33
    const char *msg;
 
34
} err_str[] =
 
35
{
 
36
    /* Event errors */
 
37
    { PJSIP_SIMPLE_ENOPKG,          "No SIP event package with the specified name" },
 
38
    { PJSIP_SIMPLE_EPKGEXISTS,      "SIP event package already exist" },
 
39
 
 
40
    /* Presence errors */
 
41
    { PJSIP_SIMPLE_ENOTSUBSCRIBE,   "Expecting SUBSCRIBE request" },
 
42
    { PJSIP_SIMPLE_ENOPRESENCE,     "No presence associated with the subscription" },
 
43
    { PJSIP_SIMPLE_ENOPRESENCEINFO, "No presence info in the server subscription" },
 
44
    { PJSIP_SIMPLE_EBADCONTENT,     "Bad Content-Type for presence" },
 
45
    { PJSIP_SIMPLE_EBADPIDF,        "Bad PIDF content for presence" },
 
46
    { PJSIP_SIMPLE_EBADXPIDF,       "Bad XPIDF content for presence" },
 
47
    { PJSIP_SIMPLE_EBADRPID,        "Invalid or bad RPID document"},
 
48
 
 
49
    /* isComposing errors. */
 
50
    { PJSIP_SIMPLE_EBADISCOMPOSE,   "Bad isComposing indication/XML message" },
 
51
};
 
52
 
 
53
 
 
54
#endif  /* PJ_HAS_ERROR_STRING */
 
55
 
 
56
 
 
57
/*
 
58
 * pjsipsimple_strerror()
 
59
 */
 
60
PJ_DEF(pj_str_t) pjsipsimple_strerror( pj_status_t statcode,
 
61
                                       char *buf, pj_size_t bufsize )
 
62
{
 
63
    pj_str_t errstr;
 
64
 
 
65
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
 
66
 
 
67
    if (statcode >= PJSIP_SIMPLE_ERRNO_START &&
 
68
        statcode < PJSIP_SIMPLE_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
 
69
    {
 
70
        /* Find the error in the table.
 
71
         * Use binary search!
 
72
         */
 
73
        int first = 0;
 
74
        int n = PJ_ARRAY_SIZE(err_str);
 
75
 
 
76
        while (n > 0) {
 
77
            int half = n/2;
 
78
            int mid = first + half;
 
79
 
 
80
            if (err_str[mid].code < statcode) {
 
81
                first = mid+1;
 
82
                n -= (half+1);
 
83
            } else if (err_str[mid].code > statcode) {
 
84
                n = half;
 
85
            } else {
 
86
                first = mid;
 
87
                break;
 
88
            }
 
89
        }
 
90
 
 
91
 
 
92
        if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) {
 
93
            pj_str_t msg;
 
94
 
 
95
            msg.ptr = (char*)err_str[first].msg;
 
96
            msg.slen = pj_ansi_strlen(err_str[first].msg);
 
97
 
 
98
            errstr.ptr = buf;
 
99
            pj_strncpy_with_null(&errstr, &msg, bufsize);
 
100
            return errstr;
 
101
 
 
102
        }
 
103
    }
 
104
 
 
105
#endif  /* PJ_HAS_ERROR_STRING */
 
106
 
 
107
 
 
108
    /* Error not found. */
 
109
    errstr.ptr = buf;
 
110
    errstr.slen = pj_ansi_snprintf(buf, bufsize,
 
111
                                   "Unknown pjsip-simple error %d",
 
112
                                   statcode);
 
113
 
 
114
    return errstr;
 
115
}