Skip to content

Commit

Permalink
PubNub SDK v2.12.7 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Jan 20, 2021
1 parent 825479b commit 728bf25
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 13 deletions.
9 changes: 7 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: c-core
schema: 1
version: "2.12.6"
version: "2.12.7"
scm: github.com/pubnub/c-core
changelog:
- version: v2.12.7
date: Jan 20, 2021
changes:
- type: feature
text: "Added support for Universal Windows(UWP)."
- version: v2.12.6
date: Oct 3, 2020
changes:
Expand Down Expand Up @@ -503,7 +508,7 @@ supported-platforms:
-
version: PubNub FreeRTOS SDK
platforms:
- FreeRTOS+ 150825 or newer is supported. 
- FreeRTOS+ 150825 or newer is supported.
-
version: PubNub Qt SDK
platforms:
Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## [v2.12.6](https://github.com/pubnub/c-core/releases/tag/v2.12.6)
October 3 2020
## [v2.12.7](https://github.com/pubnub/c-core/releases/tag/v2.12.7)
January 20 2021

[Full Changelog](https://github.com/pubnub/c-core/compare/v2.12.5...v2.12.6)
[Full Changelog](https://github.com/pubnub/c-core/compare/v2.12.6...v2.12.7)

- Fix DNS servers rotation during transaction origin DNS resolution timeout.
- Added support for Universal Windows(UWP).


4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Pubnub C/C++ client libraries

[![Build Status](https://travis-ci.org/pubnub/c-core.svg?branch=master)](https://travis-ci.org/pubnub/c-core)
[![Build Status](https://travis-ci.com/pubnub/c-core.svg?branch=master)](https://travis-ci.com/pubnub/c-core)

This repository has the source for the C/C++ client libraries,
designed mostly for embedded systems, but perfectly suitable for
Expand Down Expand Up @@ -43,7 +43,7 @@ In this root directory we have some files, too:
- `posix.mk`: a "master" Makefile for POSIX - will build all the POSIX
Makefiles there are (doesn't build Qt - you might not have Qt)
- `windows.mk`: a "master" Makefile for Windows - will build all the
Windows Makefiles there are (doesn't build Qt, you might not have Qt)
Windows Makefiles there are (doesn't build Qt, you might not have Qt). For UWP support, use uwp.mk Makefile.
- `.pubnub.yml`: Standard Pubnub library description in YAML
- `.travis.yml`: Configuration for Travis CI (POSIX: Linux and MacOS)
- `.appveyor.yml`: Configuration for Appveyor CI (Windows)
Expand Down
2 changes: 1 addition & 1 deletion core/pubnub_version_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define INC_PUBNUB_VERSION_INTERNAL


#define PUBNUB_SDK_VERSION "2.12.6"
#define PUBNUB_SDK_VERSION "2.12.7"


#endif /* !defined INC_PUBNUB_VERSION_INTERNAL */
53 changes: 53 additions & 0 deletions openssl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,59 @@ of the MSVC standard `cl`, like:

nmake -f windows.mk CC=clang-cl

## Pubnub OpenSSL on Universal Windoows Platform (UWP)

OpenSSL doesn't cover threads, so there is some Windows-specific code.

But, the biggest issue is that OpenSSL is not a part of any Windows installation
`per se`. Actually, a typical Windows computer has dozens of OpenSSL libraries
used by various programs. We provide one solution for this in our sample
Makefile (`uwp.mk`) as described below.

You should decide what OpenSSL you want to compile & link against. To do
that, pass the path of your OpenSSL of choice as macro `OPENSSLPATH` to
`nmake`. We have found that OpenSSL
(could be found here https://github.com/openssl/openssl
at the time of this writing) works fine. To support UWP, you need to compile based on the instructions available at https://github.com/openssl/openssl/blob/master/NOTES-Windows.txt (check Special notes for Universal Windows Platform builds, aka VC-*-UWP).
We used the following commands to build OpenSSL library
1. vcvarsall.bat x86 onecore 10.0.19041.0
2. nmake clean
3. perl Configure VC-WIN32-ONECORE --prefix=C:\OpenSSL-Win32 --openssldir=C:\SSL no-shared enable-capieng
4. nmake test
5. nmake install_sw

For example, the default install directory of OpenSSL for 32-bit OpenSSL for Windows is
`c:\OpenSSL-Win32`, so to use that, you would:

nmake -f uwp.mk OPENSSLPATH=c:\OpenSSL-Win32

If you don't pass `OPENSSLPATH`, it will use a default, which might not be
good for you, so please check the default in `uwp.mk` before invoking
nmake without setting `OPENSSLPATH`.

We expect that the `OPENSSLPATH` has two sub-directories:

- `include`: with the OpenSSL include files
- `lib`: with OpenSSL (import) library files

In general, this should work with both import library files (for DLLs) and
static libraries, but that depends on your OpenSSL of choice. The important
thing here is that if you use import libraries, you will have to distribute
the DLLs that are a part of your OpenSSL with your applications.

The sample Makefile (`uwp.mk`) will build static
libraries (they will have `.lib` extension on Windows) so that they can be
used in building UWP applications. SSPI and Proxy is NOT supported at this time.

The sample Makefile is designed to work with MS Visual Studio compilers
(MSVS 2008 or newer should work fine). Rewriting it to use some other
compiler should not be too hard, mostly would involve changing the compiler
switches. But, if you have a compiler that supports MSVC switches
(like some Clang "distributions"), you should be able to use it instead
of the MSVC standard `cl`, like:

nmake -f uwp.mk CC=clang-cl

## Notes

We have not tested Pubnub OpenSSL on OSX yet.
Expand Down
4 changes: 4 additions & 0 deletions openssl/pbpal_add_system_certs_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
int pbpal_add_system_certs(pubnub_t* pb)
{
X509_STORE *cert_store = SSL_CTX_get_cert_store(pb->pal.ctx);
#if __UWP__
HCERTSTORE hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, NULL, CERT_SYSTEM_STORE_CURRENT_USER, L"ROOT");
#else
HCERTSTORE hStore = CertOpenSystemStoreW(0, L"ROOT");
#endif
PCCERT_CONTEXT pContext = NULL;

if (!hStore) {
Expand Down
8 changes: 5 additions & 3 deletions openssl/pbpal_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ static int pal_init(void)
{
static bool s_init = false;
if (!s_init) {
ERR_load_BIO_strings();
#if !defined(__UWP__)
ERR_load_BIO_strings(); //Per OpenSSL 3.0 this is deprecated. Allowing this stmt for non-UWP as it exists.
#endif
SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_algorithms();
Expand Down Expand Up @@ -282,7 +284,7 @@ enum pubnub_res pbpal_line_read_status(pubnub_t* pb)
PUBNUB_ASSERT_OPT(STATE_READ_LINE == pb->sock_state);

/* OpenSSL reads one TLS record at a time,
so, we need to call it in a loop to read äll there is
so, we need to call it in a loop to read �ll there is
*/
for (;;) {
if (pb->unreadlen == 0) {
Expand Down Expand Up @@ -381,7 +383,7 @@ enum pubnub_res pbpal_read_status(pubnub_t* pb)
PUBNUB_ASSERT_OPT(STATE_READ == pb->sock_state);

/* OpenSSL reads one TLS record at a time,
so, we need to call it in a loop to read äll there is
so, we need to call it in a loop to read �ll there is
*/
for (;;) {
if (0 == pb->unreadlen) {
Expand Down
26 changes: 26 additions & 0 deletions openssl/pbsha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,46 @@
/** This helper macro will calculate the SHA-256 on the message
in @p m, having the length @p l and store it in @p d.
*/
#if __UWP__
#define pbsha256_digest(m, l, d) do \
{ \
EVP_MD_CTX *ctx; \
ctx = EVP_MD_CTX_create(); \
const EVP_MD* md = EVP_get_digestbyname("SHA256" ); \
EVP_DigestInit(ctx, EVP_sha256()); \
EVP_DigestUpdate(ctx, (m)), (l))); \
EVP_DigestFinal(ctx, (d), NULL); \
EVP_MD_CTX_destroy(ctx); \
} while(0);
#else
#define pbsha256_digest(m, l, d) do { SHA256_CTX M_ctx_; \
SHA256_Init(&M_ctx_); \
SHA256_Update(&M_ctx_, (m), (l)); \
SHA256_Final((d), &M_ctx); \
} while (0)
#endif

/** This helper macro will calculate the SHA-256 on the message in @p str,
assuming it's an ASCIIZ string andd store it in @p d.
@warning This macro uses @p str twice!
*/
#if __UWP__
#define pbsha256_digest_str(str, d) do \
{ \
EVP_MD_CTX *ctx; \
ctx = EVP_MD_CTX_create(); \
const EVP_MD* md = EVP_get_digestbyname("SHA256" ); \
EVP_DigestInit(ctx, EVP_sha256()); \
EVP_DigestUpdate(ctx, str, strlen(str)); \
EVP_DigestFinal(ctx, d, NULL); \
EVP_MD_CTX_destroy(ctx); \
} while(0);
#else
#define pbsha256_digest_str(str, d) do { SHA256_CTX M_ctx_; \
SHA256_Init(&M_ctx_); \
SHA256_Update(&M_ctx_, (str), strlen(str)); \
SHA256_Final((d), &M_ctx_); \
} while (0)
#endif

#endif /* !defined INC_PBSHA256 */
64 changes: 64 additions & 0 deletions openssl/uwp.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c pbpal_openssl.c pbpal_connect_openssl.c pbpal_add_system_certs_windows.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\pubnub_free_with_timeout_std.c ..\windows\pbtimespec_elapsed_ms.c ..\core\pubnub_timers.c ..\core\pubnub_json_parse.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_ssl.c ..\core\pubnub_helper.c ..\windows\pubnub_version_windows.c ..\windows\pubnub_generate_uuid_windows.c pbpal_openssl_blocking_io.c ..\lib\base64\pbbase64.c ..\core\pubnub_crypto.c ..\core\pubnub_coreapi_ex.c pbaes256.c ..\core\c99\snprintf.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c ..\windows\msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c ..\core\pubnub_memory_block.c ..\lib\pbstr_remove_from_list.c ..\windows\pb_sleep_ms.c ..\core\pbauto_heartbeat.c ..\windows\pbauto_heartbeat_init_windows.c

OBJFILES = pubnub_pubsubapi.obj pubnub_coreapi.obj pubnub_ccore_pubsub.obj pubnub_ccore.obj pubnub_netcore.obj pbpal_resolv_and_connect_sockets.obj pbpal_handle_socket_error.obj pbpal_openssl.obj pbpal_connect_openssl.obj pbpal_add_system_certs_windows.obj pubnub_alloc_std.obj pubnub_assert_std.obj pubnub_generate_uuid.obj pubnub_blocking_io.obj pubnub_free_with_timeout_std.obj pbtimespec_elapsed_ms.obj pubnub_timers.obj pubnub_json_parse.obj md5.obj pb_strnlen_s.obj pubnub_ssl.obj pubnub_helper.obj pubnub_version_windows.obj pubnub_generate_uuid_windows.obj pbpal_openssl_blocking_io.obj windows_socket_blocking_io.obj pbbase64.obj pubnub_crypto.obj pubnub_coreapi_ex.obj pbaes256.obj snprintf.obj miniz_tinfl.obj miniz_tdef.obj miniz.obj pbcrc32.obj pbgzip_compress.obj pbgzip_decompress.obj pbcc_subscribe_v2.obj pubnub_subscribe_v2.obj msstopwatch_windows.obj pubnub_url_encode.obj pbcc_advanced_history.obj pubnub_advanced_history.obj pbcc_objects_api.obj pubnub_objects_api.obj pbcc_actions_api.obj pubnub_actions_api.obj pubnub_memory_block.obj pbstr_remove_from_list.obj pb_sleep_ms.obj pbauto_heartbeat.obj pbauto_heartbeat_init_windows.obj

!ifndef OPENSSLPATH
OPENSSLPATH=c:\OpenSSL-Win32
!endif

!IF EXISTS($(OPENSSLPATH)\lib\libssl.lib)
OPENSSL_LIBS=$(OPENSSLPATH)\lib\libssl.lib $(OPENSSLPATH)\lib\libcrypto.lib
!ELSEIF EXISTS($(OPENSSLPATH)\lib\ssleay32.lib)
OPENSSL_LIBS=$(OPENSSLPATH)\lib\ssleay32.lib $(OPENSSLPATH)\lib\libeay32.lib
!ELSE
!ERROR Cannot find OpenSSL libraries, OPENSSLPATH=$(OPENSSLPATH)
!ENDIF
LIBS=WindowsApp.lib IPHlpAPI.lib rpcrt4.lib Crypt32.lib $(OPENSSL_LIBS)

!ifndef ONLY_PUBSUB_API
ONLY_PUBSUB_API = 0
!endif

!ifndef USE_PROXY
USE_PROXY = 0
!endif

!if $(USE_PROXY)
PROXY_INTF_SOURCEFILES = ..\core\pubnub_proxy.c ..\core\pubnub_proxy_core.c ..\core\pbhttp_digest.c ..\core\pbntlm_core.c ..\core\pbntlm_packer_sspi.c ..\windows\pubnub_set_proxy_from_system_windows.c
PROXY_INTF_OBJFILES = pubnub_proxy.obj pubnub_proxy_core.obj pbhttp_digest.obj pbntlm_core.obj pbntlm_packer_sspi.obj pubnub_set_proxy_from_system_windows.obj
!endif

DEFINES=-D PUBNUB_THREADSAFE -D PUBNUB_LOG_LEVEL=PUBNUB_LOG_LEVEL_WARNING -D HAVE_STRERROR_S -D PUBNUB_ONLY_PUBSUB_API=$(ONLY_PUBSUB_API) -D PUBNUB_PROXY_API=$(USE_PROXY) -D PUBNUB_USE_WIN_SSPI=0
UDEFINES=-D "_UNICODE" -D "UNICODE" -D "WINAPI_FAMILY=WINAPI_FAMILY_APP" -D "__WRL_NO_DEFAULT_LIB__" -D "_CRT_SECURE_NO_WARNINGS" -D "_WINSOCK_DEPRECATED_NO_WARNINGS" -D "__UWP__" -D "HAVE_STRUCT_TIMESPEC"
CFLAGS = -Yu"pch.h" -Zi -Y- -MP -W3 -Gy -Zc:wchar_t $(UDEFINES) $(DEFINES) -Gm- -O2 -sdl -errorReport:prompt -WX- -Zc:forScope /Gd /Oy- /Oi /MD /FC -FU"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\lib\x86\store\references\platform.winmd"
# /Zi enables debugging, remove to get a smaller .exe and no .pdb
# /MP uses one compiler (`cl`) process for each input file, enabling faster build
# /analyze To run the static analyzer (not compatible w/clang-cl)

INCLUDES=-I .. -I . -I ..\core\c99 -I $(OPENSSLPATH)\include

all: pubnub_sync.lib pubnub_callback.lib

SYNC_INTF_SOURCEFILES= ..\core\pubnub_ntf_sync.c ..\core\pubnub_sync_subscribe_loop.c ..\core\srand_from_pubnub_time.c
SYNC_INTF_OBJFILES= pubnub_ntf_sync.obj pubnub_sync_subscribe_loop.obj srand_from_pubnub_time.obj

pubnub_sync.lib : $(SOURCEFILES) $(PROXY_INTF_SOURCEFILES) $(SYNC_INTF_SOURCEFILES)
$(CC) -c $(CFLAGS) $(INCLUDES) $(SOURCEFILES) $(PROXY_INTF_SOURCEFILES) $(SYNC_INTF_SOURCEFILES)
lib $(OBJFILES) $(SYNC_INTF_OBJFILES) $(PROXY_INTF_OBJFILES) -OUT:$@

CALLBACK_INTF_SOURCEFILES=pubnub_ntf_callback_windows.c pubnub_get_native_socket.c ..\core\pubnub_timer_list.c ..\lib\sockets\pbpal_ntf_callback_poller_poll.c ..\lib\sockets\pbpal_adns_sockets.c ..\lib\pubnub_dns_codec.c ..\core\pubnub_dns_servers.c ..\windows\pubnub_dns_system_servers.c ..\lib\pubnub_parse_ipv4_addr.c ..\lib\pubnub_parse_ipv6_addr.c ..\core\pbpal_ntf_callback_queue.c ..\core\pbpal_ntf_callback_admin.c ..\core\pbpal_ntf_callback_handle_timer_list.c ..\core\pubnub_callback_subscribe_loop.c
CALLBACK_INTF_OBJFILES=pubnub_ntf_callback_windows.obj pubnub_get_native_socket.obj pubnub_timer_list.obj pbpal_ntf_callback_poller_poll.obj pbpal_adns_sockets.obj pubnub_dns_codec.obj pubnub_dns_servers.obj pubnub_dns_system_servers.obj pubnub_parse_ipv4_addr.obj pubnub_parse_ipv6_addr.obj pbpal_ntf_callback_queue.obj pbpal_ntf_callback_admin.obj pbpal_ntf_callback_handle_timer_list.obj pubnub_callback_subscribe_loop.obj

pubnub_callback.lib : $(SOURCEFILES) $(PROXY_INTF_SOURCEFILES) $(CALLBACK_INTF_SOURCEFILES)
$(CC) -c $(CFLAGS) -DPUBNUB_CALLBACK_API $(INCLUDES) $(SOURCEFILES) $(PROXY_INTF_SOURCEFILES) $(CALLBACK_INTF_SOURCEFILES)
lib $(OBJFILES) $(CALLBACK_INTF_OBJFILES) $(PROXY_INTF_OBJFILES) -OUT:$@

clean:
del *.exe
del *.obj
del *.pdb
del *.il?
del *.lib
del *.c~
del *.h~
del *~
23 changes: 23 additions & 0 deletions windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ If you have Clang for Windows installed, this should work:

nmake -f windows.mk CC=clang-cl

# Pubnub C-core for the Universal Windows platform(UWP)

This is the part of C-core for the UWP platform.
It has a sample Makefile (`uwp.mk`), which will build, two (static) libraries will be created:

- `pubnub_sync.lib`: library for the "sync" interface
- `pubnub_callback.lib`: library for the "callback" interface

You are free to use these libraries in your projects, but keep in mind
that they are configured for the purposes of the samples. Please check
if those are right for you before using them.

So, to build the libraries, just run:

nmake uwp.mk

from a Visual Studio Command Prompt. This was tested mainly
on MSVS 2019 and Windows 10.

If you have Clang for Windows installed, this should work:

nmake -f uwp.mk CC=clang-cl

## Makefile for GCC

There is a Makefile for a `gcc` compatible compiler - `windows-gcc.mk`.
Expand Down
2 changes: 2 additions & 0 deletions windows/pubnub_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@

/** If true (!=0) will use Windows SSPI (for NTLM and such).
Otherwise, will use own implementation, if available. */
#ifndef PUBNUB_USE_WIN_SSPI
#define PUBNUB_USE_WIN_SSPI 1
#endif

/** The maximum length (in characters) of the host name of the proxy
that will be saved in the Pubnub context.
Expand Down
11 changes: 10 additions & 1 deletion windows/pubnub_generate_uuid_windows.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
#include "core/pubnub_generate_uuid.h"

#if __UWP__
#include <combaseapi.h>
#else
#include <rpc.h>

#endif

int pubnub_generate_uuid_v4_random(struct Pubnub_UUID *uuid)
{
UUID win_uuid;
#if __UWP__
if (S_OK != CoCreateGuid(&win_uuid)) {
return -1;
}
#else
if (RPC_S_OK != UuidCreate(&win_uuid)) {
return -1;
}
#endif
memcpy(uuid, &win_uuid, sizeof *uuid);

return 0;
Expand Down
Loading

0 comments on commit 728bf25

Please sign in to comment.