Commit e7192283 authored by Ghislain MARY's avatar Ghislain MARY

Some changes to only use API allowed for WP8 applications.

parent 581a80f8
......@@ -66,7 +66,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;BELLESIP_EXPORTS;BELLESIP_INTERNAL_EXPORTS;HAVE_POLARSSL;HAVE_TUNNEL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;BELLESIP_EXPORTS;BELLESIP_INTERNAL_EXPORTS;HAVE_POLARSSL;HAVE_TUNNEL;HAVE_ANTLR_STRING_STREAM_NEW;HAVE_COMPILER_TLS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\antlr3\runtime\C\include;$(ProjectDir)..\..\..\src;$(ProjectDir)..\..\..\..\polarssl\include;$(ProjectDir)..\..\..\..\tunnel\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
......@@ -90,7 +90,7 @@
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;BELLESIP_EXPORTS;BELLESIP_INTERNAL_EXPORTS;HAVE_POLARSSL;HAVE_TUNNEL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;BELLESIP_EXPORTS;BELLESIP_INTERNAL_EXPORTS;HAVE_POLARSSL;HAVE_TUNNEL;HAVE_ANTLR_STRING_STREAM_NEW;HAVE_COMPILER_TLS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\antlr3\runtime\C\include;$(ProjectDir)..\..\..\src;$(ProjectDir)..\..\..\..\polarssl\include;$(ProjectDir)..\..\..\..\tunnel\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<StringPooling>true</StringPooling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
......@@ -116,7 +116,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;BELLESIP_EXPORTS;BELLESIP_INTERNAL_EXPORTS;HAVE_POLARSSL;HAVE_TUNNEL;_CRT_SECURE_NO_WARNINGS;HAVE_ANTLR_STRING_STREAM_NEW;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;BELLESIP_EXPORTS;BELLESIP_INTERNAL_EXPORTS;HAVE_POLARSSL;HAVE_TUNNEL;HAVE_ANTLR_STRING_STREAM_NEW;HAVE_COMPILER_TLS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\antlr3\runtime\C\include;$(ProjectDir)..\..\..\src;$(ProjectDir)..\..\..\..\polarssl\include;$(ProjectDir)..\..\..\..\tunnel\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
......@@ -141,7 +141,7 @@
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;BELLESIP_EXPORTS;BELLESIP_INTERNAL_EXPORTS;HAVE_POLARSSL;HAVE_TUNNEL;HAVE_ANTLR_STRING_STREAM_NEW;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;BELLESIP_EXPORTS;BELLESIP_INTERNAL_EXPORTS;HAVE_POLARSSL;HAVE_TUNNEL;HAVE_ANTLR_STRING_STREAM_NEW;HAVE_COMPILER_TLS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\antlr3\runtime\C\include;$(ProjectDir)..\..\..\src;$(ProjectDir)..\..\..\..\polarssl\include;$(ProjectDir)..\..\..\..\tunnel\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<StringPooling>true</StringPooling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
......
......@@ -164,15 +164,15 @@ static void __belle_sip_logv_out(belle_sip_log_level lev, const char *fmt, va_li
msg=belle_sip_strdup_vprintf(fmt,args);
#if defined(_MSC_VER) && !defined(_WIN32_WCE)
#ifndef _UNICODE
OutputDebugString(msg);
OutputDebugString("\r\n");
OutputDebugStringA(msg);
OutputDebugStringA("\r\n");
#else
{
int len=strlen(msg);
wchar_t *tmp=(wchar_t*)belle_sip_malloc((len+1)*sizeof(wchar_t));
mbstowcs(tmp,msg,len);
OutputDebugString(tmp);
OutputDebugString(L"\r\n");
OutputDebugStringW(tmp);
OutputDebugStringW(L"\r\n");
belle_sip_free(tmp);
}
#endif
......
......@@ -694,18 +694,23 @@ static void *dns_sa_addr(int af, void *sa) {
#if _WIN32
static int dns_inet_pton(int af, const void *src, void *dst) {
union { struct sockaddr_in sin; struct sockaddr_in6 sin6; } u;
wchar_t wsrc[MAX(INET6_ADDRSTRLEN, DNS_D_MAXNAME) + 1];
#ifndef HAVE_C99
int size_of_u = sizeof u;
#endif
u.sin.sin_family = af;
mbstowcs(wsrc, (const char *)src, sizeof(wsrc));
#ifdef HAVE_C99
if (0 != WSAStringToAddressA((void *)src, af, (void *)0, (struct sockaddr *)&u, &(int){ sizeof u }))
if (0 != WSAStringToAddressW(wsrc, af, (void *)0, (struct sockaddr *)&u, &(int){ sizeof u }))
#else
if (0 != WSAStringToAddressA((void *)src, af, (void *)0, (struct sockaddr *)&u, &size_of_u))
if (0 != WSAStringToAddressW(wsrc, af, (void *)0, (struct sockaddr *)&u, &size_of_u))
#endif
{
int error = WSAGetLastError();
return -1;
}
switch (af) {
case AF_INET6:
......@@ -723,6 +728,7 @@ static int dns_inet_pton(int af, const void *src, void *dst) {
static const char *dns_inet_ntop(int af, const void *src, void *dst, unsigned long lim) {
union { struct sockaddr_in sin; struct sockaddr_in6 sin6; } u;
wchar_t wdst[MAX(INET6_ADDRSTRLEN, DNS_D_MAXNAME) + 1];
/* NOTE: WSAAddressToString will print .sin_port unless zeroed. */
memset(&u, 0, sizeof u);
......@@ -741,9 +747,10 @@ static const char *dns_inet_ntop(int af, const void *src, void *dst, unsigned lo
return 0;
}
if (0 != WSAAddressToStringA((struct sockaddr *)&u, dns_sa_len(&u), (void *)0, dst, &lim))
if (0 != WSAAddressToStringW((struct sockaddr *)&u, dns_sa_len(&u), (void *)0, wdst, &lim))
return 0;
wcstombs((char *)dst, wdst, lim);
return dst;
} /* dns_inet_ntop() */
#else
......
......@@ -23,8 +23,8 @@
#include <process.h>
#include <time.h>
#ifndef TLS_OUT_OF_INDEXES
#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
#ifdef HAVE_COMPILER_TLS
static __declspec(thread) const void *current_thread_data = NULL;
#endif
static int sockets_initd=0;
......@@ -64,7 +64,22 @@ const char *belle_sip_get_socket_error_string(){
const char *belle_sip_get_socket_error_string_from_code(int code){
static TCHAR msgBuf[256];
FormatMessage(
#ifdef _UNICODE
static WCHAR wMsgBuf[256];
int ret;
FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
code,
0, // Default language
(LPWSTR) &wMsgBuf,
sizeof(wMsgBuf),
NULL);
ret = wcstombs(msgBuf, wMsgBuf, sizeof(msgBuf));
if (ret == sizeof(msgBuf)) msgBuf[sizeof(msgBuf) - 1] = '\0';
#else
FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
......@@ -74,31 +89,59 @@ const char *belle_sip_get_socket_error_string_from_code(int code){
sizeof(msgBuf),
NULL);
/*FIXME: should convert from TCHAR to UTF8 */
#endif
return (const char *)msgBuf;
}
int belle_sip_thread_key_create(belle_sip_thread_key_t *key, void (*destructor)(void*) ){
#ifdef HAVE_COMPILER_TLS
*key = (belle_sip_thread_key_t)&current_thread_data;
#else
*key=TlsAlloc();
if (*key==TLS_OUT_OF_INDEXES){
belle_sip_error("TlsAlloc(): TLS_OUT_OF_INDEXES.");
return -1;
}
#endif
return 0;
}
int belle_sip_thread_setspecific(belle_sip_thread_key_t key,const void *value){
#ifdef HAVE_COMPILER_TLS
current_thread_data = value;
return 0;
#else
return TlsSetValue(key,(void*)value) ? 0 : -1;
#endif
}
const void* belle_sip_thread_getspecific(belle_sip_thread_key_t key){
#ifdef HAVE_COMPILER_TLS
return current_thread_data;
#else
return TlsGetValue(key);
#endif
}
int belle_sip_thread_key_delete(belle_sip_thread_key_t key){
#ifdef HAVE_COMPILER_TLS
current_thread_data = NULL;
return 0;
#else
return TlsFree(key) ? 0 : -1;
#endif
}
#ifdef WINAPI_FAMILY_PHONE_APP
void belle_sip_sleep(unsigned int ms) {
HANDLE sleepEvent = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
if (!sleepEvent)
return;
WaitForSingleObjectEx(sleepEvent, ms, FALSE);
}
#endif
#else
#include <signal.h>
......
......@@ -99,8 +99,7 @@ const char *belle_sip_get_socket_error_string();
const char *belle_sip_get_socket_error_string_from_code(int code);
#ifdef WINAPI_FAMILY_PHONE_APP
void WINAPI Sleep(DWORD ms);
#define belle_sip_sleep Sleep
BELLESIP_INTERNAL_EXPORT void belle_sip_sleep(unsigned int ms);
#else
#define belle_sip_sleep Sleep
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment