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

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/pjlib/src/pj/os_info.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: os_info.c 4411 2013-03-04 04:34:38Z 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 <pj/os.h>
 
21
#include <pj/ctype.h>
 
22
#include <pj/errno.h>
 
23
#include <pj/string.h>
 
24
 
 
25
/*
 
26
 * FYI these links contain useful infos about predefined macros across
 
27
 * platforms:
 
28
 *  - http://predef.sourceforge.net/preos.html
 
29
 */
 
30
 
 
31
#if defined(PJ_HAS_SYS_UTSNAME_H) && PJ_HAS_SYS_UTSNAME_H != 0
 
32
/* For uname() */
 
33
#   include <sys/utsname.h>
 
34
#   include <stdlib.h>
 
35
#   define PJ_HAS_UNAME         1
 
36
#endif
 
37
 
 
38
#if defined(PJ_HAS_LIMITS_H) && PJ_HAS_LIMITS_H != 0
 
39
/* Include <limits.h> to get <features.h> to get various glibc macros.
 
40
 * See http://predef.sourceforge.net/prelib.html
 
41
 */
 
42
#   include <limits.h>
 
43
#endif
 
44
 
 
45
#if defined(_MSC_VER)
 
46
/* For all Windows including mobile */
 
47
#   include <windows.h>
 
48
#endif
 
49
 
 
50
#if defined(PJ_DARWINOS) && PJ_DARWINOS != 0
 
51
#   include "TargetConditionals.h"
 
52
#endif
 
53
 
 
54
#ifndef PJ_SYS_INFO_BUFFER_SIZE
 
55
#   define PJ_SYS_INFO_BUFFER_SIZE      64
 
56
#endif
 
57
 
 
58
 
 
59
#if defined(PJ_DARWINOS) && PJ_DARWINOS != 0 && TARGET_OS_IPHONE
 
60
    void pj_iphone_os_get_sys_info(pj_sys_info *si, pj_str_t *si_buffer);
 
61
#endif
 
62
    
 
63
#if defined(PJ_SYMBIAN) && PJ_SYMBIAN != 0
 
64
    PJ_BEGIN_DECL
 
65
    unsigned pj_symbianos_get_model_info(char *buf, unsigned buf_size);
 
66
    unsigned pj_symbianos_get_platform_info(char *buf, unsigned buf_size);
 
67
    void pj_symbianos_get_sdk_info(pj_str_t *name, pj_uint32_t *ver);
 
68
    PJ_END_DECL
 
69
#endif
 
70
 
 
71
 
 
72
static char *ver_info(pj_uint32_t ver, char *buf)
 
73
{
 
74
    int len;
 
75
 
 
76
    if (ver == 0) {
 
77
        *buf = '\0';
 
78
        return buf;
 
79
    }
 
80
 
 
81
    sprintf(buf, "-%u.%u",
 
82
            (ver & 0xFF000000) >> 24,
 
83
            (ver & 0x00FF0000) >> 16);
 
84
    len = strlen(buf);
 
85
 
 
86
    if (ver & 0xFFFF) {
 
87
        sprintf(buf+len, ".%u", (ver & 0xFF00) >> 8);
 
88
        len = strlen(buf);
 
89
 
 
90
        if (ver & 0x00FF) {
 
91
            sprintf(buf+len, ".%u", (ver & 0xFF));
 
92
        }
 
93
    }
 
94
 
 
95
    return buf;
 
96
}
 
97
 
 
98
static pj_uint32_t parse_version(char *str)
 
99
{
 
100
    char *tok;
 
101
    int i, maxtok;
 
102
    pj_uint32_t version = 0;
 
103
    
 
104
    while (*str && !pj_isdigit(*str))
 
105
        str++;
 
106
 
 
107
    maxtok = 4;
 
108
    for (tok = strtok(str, ".-"), i=0; tok && i<maxtok;
 
109
         ++i, tok=strtok(NULL, ".-"))
 
110
    {
 
111
        int n;
 
112
 
 
113
        if (!pj_isdigit(*tok))
 
114
            break;
 
115
        
 
116
        n = atoi(tok);
 
117
        version |= (n << ((3-i)*8));
 
118
    }
 
119
    
 
120
    return version;
 
121
}
 
122
 
 
123
PJ_DEF(const pj_sys_info*) pj_get_sys_info(void)
 
124
{
 
125
    static char si_buffer[PJ_SYS_INFO_BUFFER_SIZE];
 
126
    static pj_sys_info si;
 
127
    static pj_bool_t si_initialized;
 
128
    unsigned left = PJ_SYS_INFO_BUFFER_SIZE, len;
 
129
 
 
130
    if (si_initialized)
 
131
        return &si;
 
132
 
 
133
    si.machine.ptr = si.os_name.ptr = si.sdk_name.ptr = si.info.ptr = "";
 
134
 
 
135
#define ALLOC_CP_STR(str,field) \
 
136
        do { \
 
137
            len = pj_ansi_strlen(str); \
 
138
            if (len && left >= len+1) { \
 
139
                si.field.ptr = si_buffer + PJ_SYS_INFO_BUFFER_SIZE - left; \
 
140
                si.field.slen = len; \
 
141
                pj_memcpy(si.field.ptr, str, len+1); \
 
142
                left -= (len+1); \
 
143
            } \
 
144
        } while (0)
 
145
 
 
146
    /*
 
147
     * Machine and OS info.
 
148
     */
 
149
#if defined(PJ_HAS_UNAME) && PJ_HAS_UNAME
 
150
    #if defined(PJ_DARWINOS) && PJ_DARWINOS != 0 && TARGET_OS_IPHONE && \
 
151
        (!defined TARGET_IPHONE_SIMULATOR || TARGET_IPHONE_SIMULATOR == 0)
 
152
    {
 
153
        pj_str_t buf = {si_buffer + PJ_SYS_INFO_BUFFER_SIZE - left, left};
 
154
        pj_str_t machine = {"arm", 3};
 
155
        pj_str_t sdk_name = {"iOS-SDK", 7};
 
156
        char tmp[PJ_SYS_INFO_BUFFER_SIZE];
 
157
        
 
158
        pj_iphone_os_get_sys_info(&si, &buf);
 
159
        left -= si.os_name.slen + 1;
 
160
 
 
161
        si.os_ver = parse_version(si.machine.ptr);
 
162
        
 
163
        si.machine = machine;
 
164
        si.sdk_name = sdk_name;
 
165
 
 
166
        #ifdef PJ_SDK_NAME
 
167
        pj_memcpy(tmp, PJ_SDK_NAME, pj_ansi_strlen(PJ_SDK_NAME) + 1);
 
168
        si.sdk_ver = parse_version(tmp);
 
169
        #endif
 
170
    }
 
171
    #else    
 
172
    {
 
173
        struct utsname u;
 
174
 
 
175
        /* Successful uname() returns zero on Linux and positive value
 
176
         * on OpenSolaris.
 
177
         */
 
178
        if (uname(&u) == -1)
 
179
            goto get_sdk_info;
 
180
 
 
181
        ALLOC_CP_STR(u.machine, machine);
 
182
        ALLOC_CP_STR(u.sysname, os_name);
 
183
        
 
184
        si.os_ver = parse_version(u.release);
 
185
    }
 
186
    #endif
 
187
#elif defined(_MSC_VER)
 
188
    {
 
189
        OSVERSIONINFO ovi;
 
190
 
 
191
        ovi.dwOSVersionInfoSize = sizeof(ovi);
 
192
 
 
193
        if (GetVersionEx(&ovi) == FALSE)
 
194
            goto get_sdk_info;
 
195
 
 
196
        si.os_ver = (ovi.dwMajorVersion << 24) |
 
197
                    (ovi.dwMinorVersion << 16);
 
198
        #if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE
 
199
            si.os_name = pj_str("wince");
 
200
        #else
 
201
            si.os_name = pj_str("win32");
 
202
        #endif
 
203
    }
 
204
 
 
205
    {
 
206
        SYSTEM_INFO wsi;
 
207
 
 
208
        GetSystemInfo(&wsi);
 
209
        switch (wsi.wProcessorArchitecture) {
 
210
    #if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE
 
211
        case PROCESSOR_ARCHITECTURE_ARM:
 
212
            si.machine = pj_str("arm");
 
213
            break;
 
214
        case PROCESSOR_ARCHITECTURE_SHX:
 
215
            si.machine = pj_str("shx");
 
216
            break;
 
217
    #else
 
218
        case PROCESSOR_ARCHITECTURE_AMD64:
 
219
            si.machine = pj_str("x86_64");
 
220
            break;
 
221
        case PROCESSOR_ARCHITECTURE_IA64:
 
222
            si.machine = pj_str("ia64");
 
223
            break;
 
224
        case PROCESSOR_ARCHITECTURE_INTEL:
 
225
            si.machine = pj_str("i386");
 
226
            break;
 
227
    #endif      /* PJ_WIN32_WINCE */
 
228
        }
 
229
    }
 
230
#elif defined(PJ_SYMBIAN) && PJ_SYMBIAN != 0
 
231
    {
 
232
        pj_symbianos_get_model_info(si_buffer, sizeof(si_buffer));
 
233
        ALLOC_CP_STR(si_buffer, machine);
 
234
        
 
235
        char *p = si_buffer + sizeof(si_buffer) - left;
 
236
        unsigned plen;
 
237
        plen = pj_symbianos_get_platform_info(p, left);
 
238
        if (plen) {
 
239
            /* Output format will be "Series60vX.X" */
 
240
            si.os_name = pj_str("S60");
 
241
            si.os_ver  = parse_version(p+9);
 
242
        } else {
 
243
            si.os_name = pj_str("Unknown");
 
244
        }
 
245
        
 
246
        /* Avoid compile warning on Symbian. */
 
247
        goto get_sdk_info;
 
248
    }
 
249
#endif
 
250
 
 
251
    /*
 
252
     * SDK info.
 
253
     */
 
254
get_sdk_info:
 
255
 
 
256
#if defined(__GLIBC__)
 
257
    si.sdk_ver = (__GLIBC__ << 24) |
 
258
                 (__GLIBC_MINOR__ << 16);
 
259
    si.sdk_name = pj_str("glibc");
 
260
#elif defined(__GNU_LIBRARY__)
 
261
    si.sdk_ver = (__GNU_LIBRARY__ << 24) |
 
262
                 (__GNU_LIBRARY_MINOR__ << 16);
 
263
    si.sdk_name = pj_str("libc");
 
264
#elif defined(__UCLIBC__)
 
265
    si.sdk_ver = (__UCLIBC_MAJOR__ << 24) |
 
266
                 (__UCLIBC_MINOR__ << 16);
 
267
    si.sdk_name = pj_str("uclibc");
 
268
#elif defined(_WIN32_WCE) && _WIN32_WCE
 
269
    /* Old window mobile declares _WIN32_WCE as decimal (e.g. 300, 420, etc.),
 
270
     * but then it was changed to use hex, e.g. 0x420, etc. See
 
271
     * http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesnative/thread/8a97c59f-5a1c-4bc6-99e6-427f065ff439/
 
272
     */
 
273
    #if _WIN32_WCE <= 500
 
274
        si.sdk_ver = ( (_WIN32_WCE / 100) << 24) |
 
275
                     ( ((_WIN32_WCE % 100) / 10) << 16) |
 
276
                     ( (_WIN32_WCE % 10) << 8);
 
277
    #else
 
278
        si.sdk_ver = ( ((_WIN32_WCE & 0xFF00) >> 8) << 24) |
 
279
                     ( ((_WIN32_WCE & 0x00F0) >> 4) << 16) |
 
280
                     ( ((_WIN32_WCE & 0x000F) >> 0) << 8);
 
281
    #endif
 
282
    si.sdk_name = pj_str("cesdk");
 
283
#elif defined(_MSC_VER)
 
284
    /* No SDK info is easily obtainable for Visual C, so lets just use
 
285
     * _MSC_VER. The _MSC_VER macro reports the major and minor versions
 
286
     * of the compiler. For example, 1310 for Microsoft Visual C++ .NET 2003.
 
287
     * 1310 represents version 13 and a 1.0 point release.
 
288
     * The Visual C++ 2005 compiler version is 1400.
 
289
     */
 
290
    si.sdk_ver = ((_MSC_VER / 100) << 24) |
 
291
                 (((_MSC_VER % 100) / 10) << 16) |
 
292
                 ((_MSC_VER % 10) << 8);
 
293
    si.sdk_name = pj_str("msvc");
 
294
#elif defined(PJ_SYMBIAN) && PJ_SYMBIAN != 0
 
295
    pj_symbianos_get_sdk_info(&si.sdk_name, &si.sdk_ver);
 
296
#endif
 
297
 
 
298
    /*
 
299
     * Build the info string.
 
300
     */
 
301
    {
 
302
        char tmp[PJ_SYS_INFO_BUFFER_SIZE];
 
303
        char os_ver[20], sdk_ver[20];
 
304
        int cnt;
 
305
 
 
306
        cnt = pj_ansi_snprintf(tmp, sizeof(tmp),
 
307
                               "%s%s%s%s%s%s%s",
 
308
                               si.os_name.ptr,
 
309
                               ver_info(si.os_ver, os_ver),
 
310
                               (si.machine.slen ? "/" : ""),
 
311
                               si.machine.ptr,
 
312
                               (si.sdk_name.slen ? "/" : ""),
 
313
                               si.sdk_name.ptr,
 
314
                               ver_info(si.sdk_ver, sdk_ver));
 
315
        if (cnt > 0 && cnt < (int)sizeof(tmp)) {
 
316
            ALLOC_CP_STR(tmp, info);
 
317
        }
 
318
    }
 
319
 
 
320
    si_initialized = PJ_TRUE;
 
321
    return &si;
 
322
}