~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.2.1/pjmedia/src/pjmedia/errno.c

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-01-07 14:51:16 UTC
  • mfrom: (4.3.5 sid)
  • Revision ID: package-import@ubuntu.com-20150107145116-yxnafinf4lrdvrmx
Tags: 1.4.1-0.1ubuntu1
* Merge with Debian, remaining changes:
 - Drop soprano, nepomuk build-dep
* Drop ubuntu patches, now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: errno.c 4613 2013-10-08 09:08:13Z bennylp $ */
 
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 <pjmedia/errno.h>
 
21
#include <pjmedia/types.h>
 
22
#include <pj/string.h>
 
23
#if defined(PJMEDIA_SOUND_IMPLEMENTATION) && \
 
24
    PJMEDIA_SOUND_IMPLEMENTATION == PJMEDIA_SOUND_PORTAUDIO_SOUND
 
25
#   include <portaudio.h>
 
26
#endif
 
27
 
 
28
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
 
29
PJ_BEGIN_DECL
 
30
    const char* get_libsrtp_errstr(int err);
 
31
PJ_END_DECL
 
32
#endif
 
33
 
 
34
 
 
35
/* PJMEDIA's own error codes/messages 
 
36
 * MUST KEEP THIS ARRAY SORTED!!
 
37
 * Message must be limited to 64 chars!
 
38
 */
 
39
 
 
40
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
 
41
 
 
42
static const struct 
 
43
{
 
44
    int code;
 
45
    const char *msg;
 
46
} err_str[] = 
 
47
{
 
48
    /* Generic PJMEDIA errors, shouldn't be used! */
 
49
    PJ_BUILD_ERR( PJMEDIA_ERROR,            "Unspecified PJMEDIA error" ),
 
50
 
 
51
    /* SDP error. */
 
52
    PJ_BUILD_ERR( PJMEDIA_SDP_EINSDP,       "Invalid SDP descriptor" ),
 
53
    PJ_BUILD_ERR( PJMEDIA_SDP_EINVER,       "Invalid SDP version line" ),
 
54
    PJ_BUILD_ERR( PJMEDIA_SDP_EINORIGIN,    "Invalid SDP origin line" ),
 
55
    PJ_BUILD_ERR( PJMEDIA_SDP_EINTIME,      "Invalid SDP time line"),
 
56
    PJ_BUILD_ERR( PJMEDIA_SDP_EINNAME,      "SDP name/subject line is empty"),
 
57
    PJ_BUILD_ERR( PJMEDIA_SDP_EINCONN,      "Invalid SDP connection line"),
 
58
    PJ_BUILD_ERR( PJMEDIA_SDP_EMISSINGCONN, "Missing SDP connection info line"),
 
59
    PJ_BUILD_ERR( PJMEDIA_SDP_EINATTR,      "Invalid SDP attributes"),
 
60
    PJ_BUILD_ERR( PJMEDIA_SDP_EINRTPMAP,    "Invalid SDP rtpmap attribute"),
 
61
    PJ_BUILD_ERR( PJMEDIA_SDP_ERTPMAPTOOLONG,"SDP rtpmap attribute too long"),
 
62
    PJ_BUILD_ERR( PJMEDIA_SDP_EMISSINGRTPMAP,"Missing SDP rtpmap for dynamic payload type"),
 
63
    PJ_BUILD_ERR( PJMEDIA_SDP_EINMEDIA,     "Invalid SDP media line" ),
 
64
    PJ_BUILD_ERR( PJMEDIA_SDP_ENOFMT,       "No SDP payload format in the media line" ),
 
65
    PJ_BUILD_ERR( PJMEDIA_SDP_EINPT,        "Invalid SDP payload type in media line" ),
 
66
    PJ_BUILD_ERR( PJMEDIA_SDP_EINFMTP,      "Invalid SDP fmtp attribute" ),
 
67
    PJ_BUILD_ERR( PJMEDIA_SDP_EINRTCP,      "Invalid SDP rtcp attribyte" ),
 
68
    PJ_BUILD_ERR( PJMEDIA_SDP_EINPROTO,     "Invalid SDP media transport protocol" ),
 
69
    PJ_BUILD_ERR( PJMEDIA_SDP_EINBANDW,     "Invalid SDP bandwidth info line" ),
 
70
 
 
71
    /* SDP negotiator errors. */
 
72
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_EINSTATE,      "Invalid SDP negotiator state for operation" ),
 
73
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_ENOINITIAL,    "No initial local SDP in SDP negotiator" ),
 
74
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_ENOACTIVE,     "No active SDP in SDP negotiator" ),
 
75
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_ENONEG,        "No current local/remote offer/answer" ),
 
76
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_EMISMEDIA,     "SDP media count mismatch in offer/answer" ),
 
77
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_EINVANSMEDIA,  "SDP media type mismatch in offer/answer" ),
 
78
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_EINVANSTP,     "SDP media transport type mismatch in offer/answer" ),
 
79
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_EANSNOMEDIA,   "No common SDP media payload in answer" ),
 
80
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_ENOMEDIA,      "No active media stream after negotiation" ),
 
81
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_NOANSCODEC,    "No suitable codec for remote offer"),
 
82
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_NOANSTELEVENT, "No suitable telephone-event for remote offer"),
 
83
    PJ_BUILD_ERR( PJMEDIA_SDPNEG_NOANSUNKNOWN,  "No suitable answer for unknown remote offer"),
 
84
 
 
85
    /* SDP comparison results */
 
86
    PJ_BUILD_ERR( PJMEDIA_SDP_EMEDIANOTEQUAL,   "SDP media descriptor not equal" ),
 
87
    PJ_BUILD_ERR( PJMEDIA_SDP_EPORTNOTEQUAL,    "Port in SDP media descriptor not equal" ),
 
88
    PJ_BUILD_ERR( PJMEDIA_SDP_ETPORTNOTEQUAL,   "Transport in SDP media descriptor not equal" ),
 
89
    PJ_BUILD_ERR( PJMEDIA_SDP_EFORMATNOTEQUAL,  "Format in SDP media descriptor not equal" ),
 
90
    PJ_BUILD_ERR( PJMEDIA_SDP_ECONNNOTEQUAL,    "SDP connection line not equal" ),
 
91
    PJ_BUILD_ERR( PJMEDIA_SDP_EATTRNOTEQUAL,    "SDP attributes not equal" ),
 
92
    PJ_BUILD_ERR( PJMEDIA_SDP_EDIRNOTEQUAL,     "SDP media direction not equal" ),
 
93
    PJ_BUILD_ERR( PJMEDIA_SDP_EFMTPNOTEQUAL,    "SDP fmtp attribute not equal" ),
 
94
    PJ_BUILD_ERR( PJMEDIA_SDP_ERTPMAPNOTEQUAL,  "SDP rtpmap attribute not equal" ),
 
95
    PJ_BUILD_ERR( PJMEDIA_SDP_ESESSNOTEQUAL,    "SDP session descriptor not equal" ),
 
96
    PJ_BUILD_ERR( PJMEDIA_SDP_EORIGINNOTEQUAL,  "SDP origin line not equal" ),
 
97
    PJ_BUILD_ERR( PJMEDIA_SDP_ENAMENOTEQUAL,    "SDP name/subject line not equal" ),
 
98
    PJ_BUILD_ERR( PJMEDIA_SDP_ETIMENOTEQUAL,    "SDP time line not equal" ),
 
99
 
 
100
    /* Codec errors. */
 
101
    PJ_BUILD_ERR( PJMEDIA_CODEC_EUNSUP,         "Unsupported media codec" ),
 
102
    PJ_BUILD_ERR( PJMEDIA_CODEC_EFAILED,        "Codec internal creation error" ),
 
103
    PJ_BUILD_ERR( PJMEDIA_CODEC_EFRMTOOSHORT,   "Codec frame is too short" ),
 
104
    PJ_BUILD_ERR( PJMEDIA_CODEC_EPCMTOOSHORT,   "PCM frame is too short" ),
 
105
    PJ_BUILD_ERR( PJMEDIA_CODEC_EFRMINLEN,      "Invalid codec frame length" ),
 
106
    PJ_BUILD_ERR( PJMEDIA_CODEC_EPCMFRMINLEN,   "Invalid PCM frame length" ),
 
107
    PJ_BUILD_ERR( PJMEDIA_CODEC_EINMODE,        "Invalid codec mode (no fmtp?)" ),
 
108
    PJ_BUILD_ERR( PJMEDIA_CODEC_EBADBITSTREAM,  "Bad or corrupted bitstream" ),
 
109
 
 
110
    /* Media errors. */
 
111
    PJ_BUILD_ERR( PJMEDIA_EINVALIDIP,       "Invalid remote media (IP) address" ),
 
112
    PJ_BUILD_ERR( PJMEDIA_EASYMCODEC,       "Asymetric media codec is not supported" ),
 
113
    PJ_BUILD_ERR( PJMEDIA_EINVALIDPT,       "Invalid media payload type" ),
 
114
    PJ_BUILD_ERR( PJMEDIA_EMISSINGRTPMAP,   "Missing rtpmap in media description" ),
 
115
    PJ_BUILD_ERR( PJMEDIA_EINVALIMEDIATYPE, "Invalid media type" ),
 
116
    PJ_BUILD_ERR( PJMEDIA_EREMOTENODTMF,    "Remote does not support DTMF" ),
 
117
    PJ_BUILD_ERR( PJMEDIA_RTP_EINDTMF,      "Invalid DTMF digit" ),
 
118
    PJ_BUILD_ERR( PJMEDIA_RTP_EREMNORFC2833,"Remote does not support RFC 2833" ),
 
119
    PJ_BUILD_ERR( PJMEDIA_EBADFMT,          "Bad format"),
 
120
 
 
121
    /* RTP session errors. */
 
122
    PJ_BUILD_ERR( PJMEDIA_RTP_EINPKT,       "Invalid RTP packet" ),
 
123
    PJ_BUILD_ERR( PJMEDIA_RTP_EINPACK,      "Invalid RTP packing (internal error)" ),
 
124
    PJ_BUILD_ERR( PJMEDIA_RTP_EINVER,       "Invalid RTP version" ),
 
125
    PJ_BUILD_ERR( PJMEDIA_RTP_EINSSRC,      "RTP packet SSRC id mismatch" ),
 
126
    PJ_BUILD_ERR( PJMEDIA_RTP_EINPT,        "RTP packet payload type mismatch" ),
 
127
    PJ_BUILD_ERR( PJMEDIA_RTP_EINLEN,       "Invalid RTP packet length" ),
 
128
    PJ_BUILD_ERR( PJMEDIA_RTP_ESESSRESTART,    "RTP session restarted" ),
 
129
    PJ_BUILD_ERR( PJMEDIA_RTP_ESESSPROBATION,  "RTP session in probation" ),
 
130
    PJ_BUILD_ERR( PJMEDIA_RTP_EBADSEQ,      "Bad sequence number in RTP packet" ),
 
131
    PJ_BUILD_ERR( PJMEDIA_RTP_EBADDEST,     "RTP media port destination is not configured" ),
 
132
    PJ_BUILD_ERR( PJMEDIA_RTP_ENOCONFIG,    "RTP is not configured" ),
 
133
    
 
134
    /* Media port errors: */
 
135
    PJ_BUILD_ERR( PJMEDIA_ENOTCOMPATIBLE,   "Media ports are not compatible" ),
 
136
    PJ_BUILD_ERR( PJMEDIA_ENCCLOCKRATE,     "Media ports have incompatible clock rate" ),
 
137
    PJ_BUILD_ERR( PJMEDIA_ENCSAMPLESPFRAME, "Media ports have incompatible samples per frame" ),
 
138
    PJ_BUILD_ERR( PJMEDIA_ENCTYPE,          "Media ports have incompatible media type" ),
 
139
    PJ_BUILD_ERR( PJMEDIA_ENCBITS,          "Media ports have incompatible bits per sample" ),
 
140
    PJ_BUILD_ERR( PJMEDIA_ENCBYTES,         "Media ports have incompatible bytes per frame" ),
 
141
    PJ_BUILD_ERR( PJMEDIA_ENCCHANNEL,       "Media ports have incompatible number of channels" ),
 
142
 
 
143
    /* Media file errors: */
 
144
    PJ_BUILD_ERR( PJMEDIA_ENOTVALIDWAVE,    "Not a valid WAVE file" ),
 
145
    PJ_BUILD_ERR( PJMEDIA_EWAVEUNSUPP,      "Unsupported WAVE file format" ),
 
146
    PJ_BUILD_ERR( PJMEDIA_EWAVETOOSHORT,    "WAVE file too short" ),
 
147
    PJ_BUILD_ERR( PJMEDIA_EFRMFILETOOBIG,   "Sound frame too large for file buffer"),
 
148
    PJ_BUILD_ERR( PJMEDIA_EAVIUNSUPP,       "Unsupported AVI file"),
 
149
 
 
150
    /* Sound device errors: */
 
151
    PJ_BUILD_ERR( PJMEDIA_ENOSNDREC,        "No suitable sound capture device" ),
 
152
    PJ_BUILD_ERR( PJMEDIA_ENOSNDPLAY,       "No suitable sound playback device" ),
 
153
    PJ_BUILD_ERR( PJMEDIA_ESNDINDEVID,      "Invalid sound device ID" ),
 
154
    PJ_BUILD_ERR( PJMEDIA_ESNDINSAMPLEFMT,  "Invalid sample format for sound device" ),
 
155
 
 
156
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
 
157
    /* SRTP transport errors: */
 
158
    PJ_BUILD_ERR( PJMEDIA_SRTP_ECRYPTONOTMATCH, "SRTP crypto-suite name not match the offerer tag" ),
 
159
    PJ_BUILD_ERR( PJMEDIA_SRTP_EINKEYLEN,       "Invalid SRTP key length for specific crypto" ),
 
160
    PJ_BUILD_ERR( PJMEDIA_SRTP_ENOTSUPCRYPTO,   "Unsupported SRTP crypto-suite" ),
 
161
    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPAMBIGUEANS,  "SRTP SDP contains ambigue answer" ),
 
162
    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPDUPCRYPTOTAG,"Duplicated SRTP crypto tag" ),
 
163
    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPINCRYPTO,    "Invalid SRTP crypto attribute" ),
 
164
    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPINCRYPTOTAG, "Invalid SRTP crypto tag" ),
 
165
    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPINTRANSPORT, "Invalid SDP media transport for SRTP" ),
 
166
    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPREQCRYPTO,   "SRTP crypto attribute required" ),
 
167
    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPREQSECTP,    "Secure transport required in SDP media descriptor" )
 
168
#endif
 
169
 
 
170
};
 
171
 
 
172
#endif  /* PJ_HAS_ERROR_STRING */
 
173
 
 
174
 
 
175
 
 
176
/*
 
177
 * pjmedia_strerror()
 
178
 */
 
179
PJ_DEF(pj_str_t) pjmedia_strerror( pj_status_t statcode, 
 
180
                                   char *buf, pj_size_t bufsize )
 
181
{
 
182
    pj_str_t errstr;
 
183
 
 
184
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
 
185
 
 
186
    /* See if the error comes from PortAudio. */
 
187
#if defined(PJMEDIA_SOUND_IMPLEMENTATION) && \
 
188
    PJMEDIA_SOUND_IMPLEMENTATION == PJMEDIA_SOUND_PORTAUDIO_SOUND
 
189
    if (statcode >= PJMEDIA_PORTAUDIO_ERRNO_START &&
 
190
        statcode <= PJMEDIA_PORTAUDIO_ERRNO_END)
 
191
    {
 
192
 
 
193
        //int pa_err = statcode - PJMEDIA_ERRNO_FROM_PORTAUDIO(0);
 
194
        int pa_err = PJMEDIA_PORTAUDIO_ERRNO_START - statcode;
 
195
        pj_str_t msg;
 
196
        
 
197
        msg.ptr = (char*)Pa_GetErrorText(pa_err);
 
198
        msg.slen = pj_ansi_strlen(msg.ptr);
 
199
 
 
200
        errstr.ptr = buf;
 
201
        pj_strncpy_with_null(&errstr, &msg, bufsize);
 
202
        return errstr;
 
203
 
 
204
    } else 
 
205
#endif  /* PJMEDIA_SOUND_IMPLEMENTATION */
 
206
 
 
207
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
 
208
    /* LIBSRTP error */
 
209
    if (statcode >= PJMEDIA_LIBSRTP_ERRNO_START &&
 
210
        statcode <  PJMEDIA_LIBSRTP_ERRNO_END)
 
211
    {
 
212
        int err = statcode - PJMEDIA_LIBSRTP_ERRNO_START;
 
213
        pj_str_t msg;
 
214
        
 
215
        msg = pj_str((char*)get_libsrtp_errstr(err));
 
216
 
 
217
        errstr.ptr = buf;
 
218
        pj_strncpy_with_null(&errstr, &msg, bufsize);
 
219
        return errstr;
 
220
    
 
221
    } else
 
222
#endif
 
223
    
 
224
    /* PJMEDIA error */
 
225
    if (statcode >= PJMEDIA_ERRNO_START && 
 
226
               statcode < PJMEDIA_ERRNO_END)
 
227
    {
 
228
        /* Find the error in the table.
 
229
         * Use binary search!
 
230
         */
 
231
        int first = 0;
 
232
        int n = PJ_ARRAY_SIZE(err_str);
 
233
 
 
234
        while (n > 0) {
 
235
            int half = n/2;
 
236
            int mid = first + half;
 
237
 
 
238
            if (err_str[mid].code < statcode) {
 
239
                first = mid+1;
 
240
                n -= (half+1);
 
241
            } else if (err_str[mid].code > statcode) {
 
242
                n = half;
 
243
            } else {
 
244
                first = mid;
 
245
                break;
 
246
            }
 
247
        }
 
248
 
 
249
 
 
250
        if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) {
 
251
            pj_str_t msg;
 
252
            
 
253
            msg.ptr = (char*)err_str[first].msg;
 
254
            msg.slen = pj_ansi_strlen(err_str[first].msg);
 
255
 
 
256
            errstr.ptr = buf;
 
257
            pj_strncpy_with_null(&errstr, &msg, bufsize);
 
258
            return errstr;
 
259
 
 
260
        } 
 
261
    } 
 
262
#endif  /* PJ_HAS_ERROR_STRING */
 
263
 
 
264
    /* Error not found. */
 
265
    errstr.ptr = buf;
 
266
    errstr.slen = pj_ansi_snprintf(buf, bufsize, 
 
267
                                   "Unknown pjmedia error %d",
 
268
                                   statcode);
 
269
    if (errstr.slen < 1 || errstr.slen >= (pj_ssize_t)bufsize)
 
270
        errstr.slen = bufsize - 1;
 
271
    return errstr;
 
272
}
 
273