├── m4 ├── README ├── ltversion.m4 ├── as-ac-expand.m4 ├── ltsugar.m4 └── lt~obsolete.m4 ├── client ├── libvmrestclient.exp ├── Makefile.am ├── includes.h └── libmain.c ├── test └── scripts │ ├── data │ ├── out │ │ ├── resData.txt │ │ └── resHeader.txt │ ├── input │ │ ├── sampleSuccess.txt │ │ └── smalldata.txt │ └── expected │ │ ├── SampleHeader.txt │ │ ├── SampleShortHeader.txt │ │ ├── SampleBadUrl.txt │ │ ├── SampleBadMethod.txt │ │ └── SampleBadContentLength.txt │ ├── TestCustomClientInfiniteData.sh │ ├── TestCustomClientNonSSL.sh │ ├── TestLargeDataInLoop.sh │ ├── TestSmallDataInLoop.sh │ ├── BUGS_TC │ ├── BUG-2076723 │ │ ├── README │ │ └── persistentConnection.c │ └── BUG-2052415 │ │ ├── README │ │ └── restclient.c │ ├── infiteData.c │ └── restclient.c ├── include ├── Makefile.am ├── public │ └── Makefile.am ├── vmrestsys.h └── vmrestdefines.h ├── tools ├── Makefile.am └── rest-cli │ ├── Makefile.am │ ├── main.c │ └── includes.h ├── server ├── Makefile.am ├── vmrestd │ ├── Makefile.am │ ├── defines.h │ ├── includes.h │ ├── prototypes.h │ ├── ssl-context.c │ └── vmrestd.vcproj ├── restengine │ ├── Makefile.am │ ├── includes.h │ ├── structs.h │ ├── httpMain.c │ └── defines.h └── server.vcproj ├── docs ├── ReST-Engine.docx ├── SampleRestEngineConfigPlain.cfg └── SampleRestEngineConfigSecure.cfg ├── Makefile.am ├── transport ├── Makefile.am ├── api │ ├── Makefile.am │ ├── defines.h │ ├── libmain.c │ ├── includes.h │ └── api.c ├── win │ ├── externs.h │ ├── globals.c │ ├── defines.h │ ├── ReadMe.txt │ ├── includes.h │ ├── structs.h │ ├── libmain.c │ └── prototypes.h ├── posix │ ├── Makefile.am │ ├── extern.h │ ├── global.c │ ├── includes.h │ ├── structs.h │ ├── defines.h │ ├── libmain.c │ ├── prototypes.h │ └── secureSocket.c ├── include │ ├── vmwinsock.h │ └── vmsockposix.h ├── ReadMe.txt └── transport.vcproj ├── .gitignore ├── common ├── Makefile.am ├── libmain.c ├── includes.h ├── utils.c ├── memory.c ├── logging.c └── common.vcproj ├── lin_build.sh ├── Makefile ├── README.md ├── win_build.cmd ├── configure.ac ├── td4.sln ├── api └── api.vcproj └── LICENSE /m4/README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /client/libvmrestclient.exp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/scripts/data/out/resData.txt: -------------------------------------------------------------------------------- 1 | KK -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = \ 3 | public 4 | -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = \ 3 | rest-cli 4 | -------------------------------------------------------------------------------- /server/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = \ 3 | restengine \ 4 | vmrestd 5 | 6 | -------------------------------------------------------------------------------- /include/public/Makefile.am: -------------------------------------------------------------------------------- 1 | vmrestincludedir=$(includedir) 2 | vmrestinclude_HEADERS=vmrest.h 3 | -------------------------------------------------------------------------------- /docs/ReST-Engine.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vmware-archive/c-rest-engine/HEAD/docs/ReST-Engine.docx -------------------------------------------------------------------------------- /test/scripts/data/out/resHeader.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Connection:close 3 | Content-Length:2 4 | 5 | -------------------------------------------------------------------------------- /test/scripts/data/input/sampleSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Connection:close 3 | Content-Length:0 4 | 5 | 6 | -------------------------------------------------------------------------------- /test/scripts/data/expected/SampleHeader.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Connection:close 3 | Content-Length:0 4 | 5 | -------------------------------------------------------------------------------- /test/scripts/data/expected/SampleShortHeader.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Connection:close 3 | Content-Length:2 4 | 5 | -------------------------------------------------------------------------------- /test/scripts/data/expected/SampleBadUrl.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 404 URI Not Found 2 | Connection:close 3 | Content-Length:0 4 | 5 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | SUBDIRS = \ 4 | include \ 5 | common \ 6 | transport \ 7 | server 8 | -------------------------------------------------------------------------------- /test/scripts/data/expected/SampleBadMethod.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 405 Method Not Allowed 2 | Connection:close 3 | Content-Length:0 4 | 5 | -------------------------------------------------------------------------------- /test/scripts/data/input/smalldata.txt: -------------------------------------------------------------------------------- 1 | Randongagnadfgnfsd ajfndf ads dfskljdklsg sdfgm sdklf ends with my name Kumar Kaushik 2 | -------------------------------------------------------------------------------- /test/scripts/data/expected/SampleBadContentLength.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 408 Request Timeout 2 | Connection:close 3 | Content-Length:0 4 | 5 | -------------------------------------------------------------------------------- /transport/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | ## Copyright (c) VMware Inc. All rights Reserved. 3 | # 4 | 5 | SUBDIRS = \ 6 | posix \ 7 | api 8 | -------------------------------------------------------------------------------- /docs/SampleRestEngineConfigPlain.cfg: -------------------------------------------------------------------------------- 1 | SSL-Certificate /foo/bar 2 | SSL-Key /root/junk 3 | Port 81p 4 | Log-File /tmp/restServer.log 5 | Client-Count 5 6 | Worker-Thread-Count 5 7 | -------------------------------------------------------------------------------- /docs/SampleRestEngineConfigSecure.cfg: -------------------------------------------------------------------------------- 1 | SSL-Certificate /root/mycert.pem 2 | SSL-Key /root/mycert.pem 3 | Port 81 4 | Log-File /tmp/restServer.log 5 | Client-Count 5 6 | Worker-Thread-Count 5 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # http://www.gnu.org/software/automake 2 | 3 | Makefile.in 4 | 5 | # http://www.gnu.org/software/autoconf 6 | 7 | /autom4te.cache 8 | /aclocal.m4 9 | /compile 10 | /configure 11 | /depcomp 12 | /install-sh 13 | /missing 14 | /stamp-h1 15 | -------------------------------------------------------------------------------- /tools/rest-cli/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = rest-cli 2 | 3 | rest_cli_SOURCES = \ 4 | main.c 5 | 6 | rest_cli_CPPFLAGS = \ 7 | -I$(top_srcdir)/include \ 8 | -I$(top_srcdir)/include/public \ 9 | @OPENSSL_INCLUDES@ 10 | 11 | rest_cli_LDADD = \ 12 | $(top_builddir)/common/libcommon.la \ 13 | $(top_builddir)/client/libvmrestclient.la 14 | -------------------------------------------------------------------------------- /common/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libcommon.la 2 | 3 | libcommon_la_SOURCES = \ 4 | libmain.c \ 5 | memory.c \ 6 | utils.c \ 7 | logging.c \ 8 | threads.c \ 9 | sockinterface.c 10 | 11 | libcommon_la_CPPFLAGS = \ 12 | -I$(top_srcdir)/include \ 13 | -I$(top_srcdir)/include/public \ 14 | @OPENSSL_INCLUDES@ 15 | 16 | libcommon_la_LDFLAGS = \ 17 | -static \ 18 | @OPENSSL_LDFLAGS@ 19 | -------------------------------------------------------------------------------- /client/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libvmrestclient.la 2 | 3 | libvmrestclient_la_CPPFLAGS = \ 4 | -I$(top_srcdir)/include \ 5 | -I$(top_srcdir)/include/public \ 6 | @OPENSSL_INCLUDES@ 7 | 8 | libvmrestclient_la_SOURCES = \ 9 | libmain.c 10 | 11 | libvmrestclient_la_LIBADD = \ 12 | @top_builddir@/common/libcommon.la \ 13 | @UUID_LIBS@ \ 14 | @CRYPTO_LIBS@ \ 15 | @PTHREAD_LIBS@ 16 | 17 | libvmrestclient_la_LDFLAGS = \ 18 | @OPENSSL_LDFLAGS@ 19 | 20 | -------------------------------------------------------------------------------- /transport/api/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) VMware Inc. All rights Reserved. 3 | # 4 | 5 | noinst_LTLIBRARIES = libvmsock.la 6 | 7 | libvmsock_la_SOURCES = \ 8 | api.c \ 9 | libmain.c 10 | 11 | libvmsock_la_CPPFLAGS = \ 12 | -I$(top_srcdir)/include \ 13 | -I$(top_srcdir)/include/public \ 14 | -I$(top_srcdir)/transport/include \ 15 | -DHAVE_ARPA_INET_H 16 | 17 | libvmsock_la_LDFLAGS = \ 18 | -static 19 | 20 | libvmsock_la_LIBADD = \ 21 | $(top_builddir)/transport/posix/libvmsockposix.la 22 | -------------------------------------------------------------------------------- /server/vmrestd/Makefile.am: -------------------------------------------------------------------------------- 1 | sbin_PROGRAMS = vmrestd 2 | 3 | vmrestd_SOURCES = \ 4 | main.c \ 5 | ssl-context.c 6 | 7 | vmrestd_CPPFLAGS = \ 8 | -I$(top_srcdir)/include \ 9 | -I$(top_srcdir)/include/public \ 10 | @OPENSSL_INCLUDES@ 11 | 12 | vmrestd_LDADD = \ 13 | $(top_builddir)/common/libcommon.la \ 14 | $(top_builddir)/server/restengine/librestengine.la \ 15 | @UUID_LIBS@ \ 16 | @CRYPTO_LIBS@ \ 17 | @PTHREAD_LIBS@ 18 | 19 | vmrestd_LDFLAGS = \ 20 | -rdynamic \ 21 | @OPENSSL_LDFLAGS@ 22 | -------------------------------------------------------------------------------- /transport/win/externs.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | -------------------------------------------------------------------------------- /transport/win/globals.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | -------------------------------------------------------------------------------- /transport/posix/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) VMware Inc. All rights Reserved. 3 | # 4 | 5 | noinst_LTLIBRARIES = libvmsockposix.la 6 | 7 | libvmsockposix_la_SOURCES = \ 8 | libmain.c \ 9 | global.c \ 10 | secureSocket.c \ 11 | socket.c 12 | 13 | libvmsockposix_la_CPPFLAGS = \ 14 | -I$(top_srcdir)/include \ 15 | -I$(top_srcdir)/include/public \ 16 | -I$(top_srcdir)/transport/include \ 17 | -DHAVE_SYS_EPOLL_H \ 18 | -DHAVE_FCNTL_H \ 19 | -DHAVE_ARPA_INET_H 20 | 21 | libvmsockposix_la_LDFLAGS = \ 22 | -static \ 23 | @LWBASE_LIBS@ \ 24 | @PTHREAD_LIBS@ 25 | -------------------------------------------------------------------------------- /tools/rest-cli/main.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /common/libmain.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | uint32_t 17 | VmRESTCommonInit( 18 | void 19 | ) 20 | { 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /transport/win/defines.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #define VM_SOCK_WINDOWS_DEFAULT_LISTEN_QUEUE_SIZE (5) 15 | #define VM_SOCK_WINDOWS_DEFAULT_QUEUE_SIZE (64) 16 | -------------------------------------------------------------------------------- /client/includes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | -------------------------------------------------------------------------------- /tools/rest-cli/includes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #ifndef WIN32 15 | #include 16 | #else 17 | #include 18 | #endif 19 | 20 | 21 | #include 22 | #include 23 | 24 | -------------------------------------------------------------------------------- /server/restengine/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = librestengine.la 2 | 3 | librestengine_la_CPPFLAGS = \ 4 | -I$(top_srcdir)/include \ 5 | -I$(top_srcdir)/include/public \ 6 | @OPENSSL_INCLUDES@ 7 | 8 | librestengine_la_SOURCES = \ 9 | httpValidate.c \ 10 | libmain.c \ 11 | httpProtocolHead.c \ 12 | httpAllocStruct.c \ 13 | httpUtilsInternal.c \ 14 | httpUtilsExternal.c \ 15 | httpMain.c \ 16 | restProtocolHead.c 17 | 18 | librestengine_la_LIBADD = \ 19 | @top_builddir@/common/libcommon.la \ 20 | @top_builddir@/transport/api/libvmsock.la \ 21 | @UUID_LIBS@ \ 22 | @CRYPTO_LIBS@ \ 23 | @PTHREAD_LIBS@ 24 | 25 | librestengine_la_LDFLAGS = \ 26 | @OPENSSL_LDFLAGS@ 27 | 28 | -------------------------------------------------------------------------------- /transport/include/vmwinsock.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | DWORD 15 | VmWinSockInitialize( 16 | PVM_SOCK_PACKAGE* ppPackage 17 | ); 18 | 19 | VOID 20 | VmWinSockShutdown( 21 | PVM_SOCK_PACKAGE pPackage 22 | ); 23 | -------------------------------------------------------------------------------- /transport/include/vmsockposix.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | DWORD 15 | VmSockPosixInitialize( 16 | PVM_SOCK_PACKAGE* ppPackage 17 | ); 18 | 19 | VOID 20 | VmSockPosixShutdown( 21 | PVM_SOCK_PACKAGE pPackage 22 | ); 23 | -------------------------------------------------------------------------------- /client/libmain.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | int vmrest_syslog_level; 16 | 17 | uint32_t 18 | VmRESTClientInit( 19 | void 20 | ) 21 | { 22 | vmrest_syslog_level = VMREST_LOG_LEVEL_DEBUG; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /server/vmrestd/defines.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #define MAX_RESOURCE 10 15 | #define MAX_DATA_LEN 4096 16 | #define MAX_CONFIG_PARAMS_LEN 20 17 | #define MAX_DIRECTORY_LENGTH 256 18 | #define MAX_IN_MEM_PAYLOAD_LEN 100000 19 | 20 | -------------------------------------------------------------------------------- /transport/posix/extern.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | extern int gSSLisedInstaceCount; 15 | extern pthread_mutex_t* gSSLThreadLock; 16 | extern pthread_mutex_t gGlobalMutex; 17 | extern SSL_CTX* gpSSLCTX; 18 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /test/scripts/TestCustomClientInfiniteData.sh: -------------------------------------------------------------------------------- 1 | # !/bin/bash 2 | TOPDIR=`pwd` 3 | IPADDR="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)" 4 | PORT="81" 5 | 6 | # Compile from source in the same directory 7 | gcc -o $TOPDIR/infiteData $TOPDIR/infiteData.c 8 | 9 | $TOPDIR/infiteData $IPADDR $PORT "15000" "TEST 1" 10 | 11 | $TOPDIR/infiteData $IPADDR $PORT "1" "TEST 2" 12 | 13 | $TOPDIR/infiteData $IPADDR $PORT "10" "TEST 3" 14 | 15 | $TOPDIR/infiteData $IPADDR $PORT "512" "TEST 4" 16 | 17 | $TOPDIR/infiteData $IPADDR $PORT "4095" "TEST 5" 18 | 19 | $TOPDIR/infiteData $IPADDR $PORT "5000" "TEST 6" 20 | 21 | $TOPDIR/infiteData $IPADDR $PORT "10000" "TEST 7" 22 | 23 | $TOPDIR/infiteData $IPADDR $PORT "32000" "TEST 8" 24 | 25 | $TOPDIR/infiteData $IPADDR $PORT "1024" "TEST 9" 26 | 27 | rm -f $TOPDIR/infiteData 28 | 29 | -------------------------------------------------------------------------------- /transport/posix/global.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | int gSSLisedInstaceCount = INVALID; 17 | pthread_mutex_t* gSSLThreadLock = NULL; 18 | pthread_mutex_t gGlobalMutex = PTHREAD_MUTEX_INITIALIZER; 19 | SSL_CTX* gpSSLCTX = NULL; 20 | 21 | -------------------------------------------------------------------------------- /transport/api/defines.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #define BAIL_ON_VMSOCK_ERROR(dwError) \ 15 | do { \ 16 | if (dwError) { \ 17 | goto error; \ 18 | } \ 19 | } while(0) 20 | 21 | #ifdef WIN32 22 | #define inet_pton(x, y, z) InetPtonA(x, y, z) 23 | #endif 24 | -------------------------------------------------------------------------------- /test/scripts/TestCustomClientNonSSL.sh: -------------------------------------------------------------------------------- 1 | # !/bin/bash 2 | TOPDIR=`pwd` 3 | IPADDR="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)" 4 | PORT="81" 5 | 6 | # Compile from source in the same directory 7 | gcc -o $TOPDIR/NonSSLClient $TOPDIR/restclient.c 8 | 9 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 1" 10 | 11 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 2" 12 | 13 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 3" 14 | 15 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 4" 16 | 17 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 5" 18 | 19 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 6" 20 | 21 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 7" 22 | 23 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 8" 24 | 25 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 9" 26 | 27 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 10" 28 | 29 | $TOPDIR/NonSSLClient $IPADDR $PORT "TEST 11" 30 | 31 | rm -f $TOPDIR/NonSSLClient 32 | 33 | -------------------------------------------------------------------------------- /test/scripts/TestLargeDataInLoop.sh: -------------------------------------------------------------------------------- 1 | # !/bin/bash 2 | TOPDIR=`pwd` 3 | INDIR=$TOPDIR/data/input 4 | OUTDIR=$TOPDIR/data/out 5 | EXPECTEDDIR=$TOPDIR/data/expected 6 | IPADDR="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)" 7 | PORT="81" 8 | 9 | #=========================== TEST 1 : Large Data In Loop ========================================= 10 | 11 | for i in `seq 1 100`; 12 | do 13 | rm -f $OUTDIR/resHeader.txt 14 | rm -f $OUTDIR/resData.txt 15 | 16 | curl -v -D $OUTDIR/resHeader.txt -o $OUTDIR/resData.txt -X GET -d @$INDIR/largedata.txt http://$IPADDR:$PORT/v1/pkg?x=y 2&> xx.txt 17 | 18 | header=$(<$OUTDIR/resHeader.txt) 19 | data=$(<$OUTDIR/resData.txt) 20 | 21 | inputData=$(<$INDIR/largedata.txt) 22 | 23 | if [ "$data" == "$inputData" ] 24 | then 25 | echo "PASSED-TEST $i: Large data" 26 | else 27 | echo "FAILED-TEST $i: Large data" 28 | break 29 | fi 30 | done 31 | -------------------------------------------------------------------------------- /test/scripts/TestSmallDataInLoop.sh: -------------------------------------------------------------------------------- 1 | # !/bin/bash 2 | TOPDIR=`pwd` 3 | INDIR=$TOPDIR/data/input 4 | OUTDIR=$TOPDIR/data/out 5 | EXPECTEDDIR=$TOPDIR/data/expected 6 | IPADDR="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)" 7 | PORT="81" 8 | 9 | #=========================== TEST 1 : Echo Small data ========================================= 10 | 11 | for i in `seq 1 1000`; 12 | do 13 | rm -f $OUTDIR/resHeader.txt 14 | rm -f $OUTDIR/resData.txt 15 | 16 | curl -v -D $OUTDIR/resHeader.txt -o $OUTDIR/resData.txt -X GET -d @$INDIR/smalldata.txt http://$IPADDR:$PORT/v1/pkg?x=y 2&> xx.txt 17 | header=$(<$OUTDIR/resHeader.txt) 18 | data=$(<$OUTDIR/resData.txt) 19 | 20 | inputData=$(<$INDIR/smalldata.txt) 21 | 22 | if [ "$data" == "$inputData" ] 23 | then 24 | echo "PASSED-TEST $i - Small data test" 25 | else 26 | echo "FAILED-TEST $i: Small data test" 27 | break 28 | fi 29 | done 30 | -------------------------------------------------------------------------------- /server/vmrestd/includes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #ifndef WIN32 15 | #include 16 | #include 17 | #else 18 | typedef __int32 int32_t; 19 | typedef __int64 int64_t; 20 | typedef unsigned __int32 uint32_t; 21 | typedef unsigned __int64 uint64_t; 22 | typedef unsigned __int16 uint16_t; 23 | typedef unsigned __int8 uint8_t; 24 | #endif 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "defines.h" 33 | #include "prototypes.h" 34 | 35 | -------------------------------------------------------------------------------- /common/includes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include 15 | 16 | #ifndef WIN32 17 | #include 18 | #include 19 | #else 20 | typedef __int32 int32_t; 21 | typedef __int64 int64_t; 22 | typedef unsigned __int32 uint32_t; 23 | typedef unsigned __int64 uint64_t; 24 | typedef unsigned __int16 uint16_t; 25 | typedef unsigned __int8 uint8_t; 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | -------------------------------------------------------------------------------- /test/scripts/BUGS_TC/BUG-2076723/README: -------------------------------------------------------------------------------- 1 | Bugzilla Id: 2076723 2 | 3 | Category: New feature/Critical 4 | 5 | Description: 6 | In secure version (HTTPS) of c-rest-engine, all connection requests are transactional. 7 | This means each request is served via new connection. This introduces steps involving 8 | openssl handshake which is known to cause significant performance delays. 9 | 10 | Requirements: 11 | 1. Re-use TCP connections originating from same host and port to server. 12 | 2. Support HTTP header "connection: keep-alive" 13 | 14 | Feature Testing: 15 | Use available libcurl based client to open one single connection and send multiple 16 | HTTP(S) request. 17 | 18 | Steps to test. 19 | 1. Compile the persistentConnection.c file with the following command. 20 | "gcc -o persistentConnection persistentConnection.c -lcurl" 21 | 2. Run the test with following command. 22 | "./persistentConnection https://:/v1/pkg?x=y 2>/dev/null" 23 | 24 | Example: 25 | "./persistentConnection https://172.16.127.131:81/v1/pkg?x=y 2>/dev/null" 26 | 27 | -------------------------------------------------------------------------------- /server/restengine/includes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #ifndef WIN32 15 | #include 16 | #include 17 | #else 18 | typedef __int32 int32_t; 19 | typedef __int64 int64_t; 20 | typedef unsigned __int32 uint32_t; 21 | typedef unsigned __int64 uint64_t; 22 | typedef unsigned __int16 uint16_t; 23 | typedef unsigned __int8 uint8_t; 24 | #endif 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "defines.h" 33 | #include "structs.h" 34 | #include "prototype.h" 35 | -------------------------------------------------------------------------------- /transport/posix/includes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "defines.h" 23 | #include "structs.h" 24 | #include "prototypes.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "extern.h" 34 | 35 | -------------------------------------------------------------------------------- /transport/api/libmain.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | DWORD 17 | VmwSockInitialize( 18 | PVMREST_HANDLE pRESTHandle 19 | ) 20 | { 21 | DWORD dwError = 0; 22 | 23 | if (pRESTHandle) 24 | { 25 | #ifdef _WIN32 26 | dwError = VmWinSockInitialize(&(pRESTHandle->pPackage)); 27 | #else 28 | dwError = VmSockPosixInitialize(&(pRESTHandle->pPackage)); 29 | #endif 30 | } 31 | 32 | return dwError; 33 | } 34 | 35 | VOID 36 | VmwSockShutdown( 37 | PVMREST_HANDLE pRESTHandle 38 | ) 39 | { 40 | if (pRESTHandle && pRESTHandle->pPackage) 41 | { 42 | #ifdef _WIN32 43 | VmWinSockShutdown(pRESTHandle->pPackage); 44 | #else 45 | VmSockPosixShutdown(pRESTHandle->pPackage); 46 | #endif 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /transport/api/includes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #ifndef _WIN32 15 | #include 16 | #include 17 | #else 18 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 19 | #include 20 | typedef __int32 int32_t; 21 | typedef __int64 int64_t; 22 | typedef unsigned __int32 uint32_t; 23 | typedef unsigned __int64 uint64_t; 24 | typedef unsigned __int16 uint16_t; 25 | typedef unsigned __int8 uint8_t; 26 | #include 27 | #include 28 | #include 29 | #include 30 | #endif 31 | 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef _WIN32 38 | #include 39 | #else 40 | #include 41 | #include 42 | #endif 43 | 44 | 45 | 46 | #include "defines.h" 47 | -------------------------------------------------------------------------------- /test/scripts/BUGS_TC/BUG-2052415/README: -------------------------------------------------------------------------------- 1 | Bugzilla Id: 2052415 2 | 3 | Category: Catastrophic/Crash 4 | 5 | Description: 6 | Server crash observed when client opens number of connection and times out. No data is sent. 7 | 8 | Step to reproduce: 9 | 10 | Specific configuration: 11 | 1. Worker threads count 2. 12 | 2. No Secure connection required. 13 | 14 | 15 | Start server( Keep it running ) 16 | Refer RUN-SIMPLE-SERVER doc in test/scripts directory. (TODO) 17 | 18 | Open terminal on Ubuntu VM( or any other distro) 19 | 1. Wget the source file from the same directory (restclient.c) 20 | 2. Edit SERVER_IP and SERVER_PORT macro in the source file to your server. 21 | 3. Compile the downloaded client source (gcc -o restclient restclient.c) 22 | 4. Install "parallel" on the Ubuntu distro 23 | 5. Run following command 24 | "seq 0 100 | parallel -j50 ./restclient" 25 | 26 | 27 | Server will crash. This might take anything between couple of second to 10-15 mins. 28 | 29 | 30 | ROOT CAUSE: 31 | Bad memory write happened for back pointer reference for timer socket which was already freed. 32 | This was reported by valgrind also. 33 | 34 | Fix: 35 | Setting appropiate back pointer to NULL at right place. 36 | 37 | 38 | Test: 39 | Ran the same test for serveral hours. No crash seen. 40 | Ran under valgrind, no bad write reported. 41 | All c-rest-engine BVT 42 | -------------------------------------------------------------------------------- /server/vmrestd/prototypes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | uint32_t 15 | VmHandleEchoData( 16 | PVMREST_HANDLE pRESTHandle, 17 | PREST_REQUEST pRequest, 18 | PREST_RESPONSE* ppResponse, 19 | uint32_t paramsCount 20 | ); 21 | 22 | uint32_t 23 | VmHandleEchoData1( 24 | PVMREST_HANDLE pRESTHandle, 25 | PREST_REQUEST pRequest, 26 | PREST_RESPONSE* ppResponse, 27 | uint32_t paramsCount 28 | ); 29 | 30 | uint32_t 31 | VmTESTInitSSL( 32 | char* sslKey, 33 | char* sslCert, 34 | SSL_CTX** ppSSLCtx 35 | ); 36 | 37 | void 38 | VmRESTShutdownSSL( 39 | SSL_CTX* sslCtx 40 | ); 41 | 42 | -------------------------------------------------------------------------------- /lin_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # script to build for Linux and optionally install the resulted RPM 3 | # Author: Danut Moraru 4 | 5 | install=false 6 | while [ $# -gt 0 ] 7 | do 8 | case "$1" in 9 | -i) install=true;; 10 | esac 11 | shift 12 | done 13 | 14 | pushd build 15 | make -f Makefile.bootstrap DEBUG=1 16 | if [ $? -eq 0 ]; then 17 | if [ $install = true ]; then 18 | rpm -e vmware-rest 19 | port=$(cat ../docs/SampleRestEngineConfigPlain.cfg | grep Port | cut -d' ' -f2 | cut -d'p' -f1 | cut -d'P' -f1) 20 | version=$(cat package/rpm/vmware-rest.spec | grep Version | cut -d' ' -f2) 21 | release=$(cat package/rpm/vmware-rest.spec | grep Release | cut -d' ' -f2) 22 | pushd rpmbuild/RPMS/x86_64 23 | rpm -ivh vmware-rest-$version-$release.x86_64.rpm 24 | popd 25 | iptables -C INPUT -p tcp --dport $port -j ACCEPT 26 | if [ $? -ne 0 ]; then 27 | iptables -A INPUT -p tcp --dport $port -j ACCEPT 28 | iptables -A OUTPUT -p tcp --dport $port -j ACCEPT 29 | fi 30 | cp ../docs/SampleRestEngineConfigPlain.cfg /tmp/restconfig.txt 31 | cp ../docs/SampleRestEngineConfigPlain.cfg /root/restconfig.txt 32 | fi 33 | else 34 | if [ $install = true ]; then 35 | echo "Build failed!" 36 | else 37 | echo "Build failed, abandoning installation!" 38 | fi 39 | fi 40 | popd 41 | -------------------------------------------------------------------------------- /transport/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | STATIC LIBRARY : vmsock Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this vmsock library project for you. 6 | 7 | No source files were created as part of your project. 8 | 9 | 10 | vmsock.vcxproj 11 | This is the main project file for VC++ projects generated using an Application Wizard. 12 | It contains information about the version of Visual C++ that generated the file, and 13 | information about the platforms, configurations, and project features selected with the 14 | Application Wizard. 15 | 16 | vmsock.vcxproj.filters 17 | This is the filters file for VC++ projects generated using an Application Wizard. 18 | It contains information about the association between the files in your project 19 | and the filters. This association is used in the IDE to show grouping of files with 20 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 21 | "Source Files" filter). 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | Other notes: 25 | 26 | AppWizard uses "TODO:" comments to indicate parts of the source code you 27 | should add to or customize. 28 | 29 | ///////////////////////////////////////////////////////////////////////////// 30 | -------------------------------------------------------------------------------- /transport/win/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | STATIC LIBRARY : vmsockwin Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this vmsockwin library project for you. 6 | 7 | No source files were created as part of your project. 8 | 9 | 10 | vmsockwin.vcxproj 11 | This is the main project file for VC++ projects generated using an Application Wizard. 12 | It contains information about the version of Visual C++ that generated the file, and 13 | information about the platforms, configurations, and project features selected with the 14 | Application Wizard. 15 | 16 | vmsockwin.vcxproj.filters 17 | This is the filters file for VC++ projects generated using an Application Wizard. 18 | It contains information about the association between the files in your project 19 | and the filters. This association is used in the IDE to show grouping of files with 20 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 21 | "Source Files" filter). 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | Other notes: 25 | 26 | AppWizard uses "TODO:" comments to indicate parts of the source code you 27 | should add to or customize. 28 | 29 | ///////////////////////////////////////////////////////////////////////////// 30 | -------------------------------------------------------------------------------- /transport/win/includes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | /* 15 | * Module Name: REST engine socket library 16 | * 17 | * Filename: includes.h 18 | * 19 | * Abstract: 20 | * 21 | * REST Engine main module include file 22 | * 23 | */ 24 | 25 | #pragma once 26 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 27 | #include 28 | typedef __int32 int32_t; 29 | typedef __int64 int64_t; 30 | typedef unsigned __int32 uint32_t; 31 | typedef unsigned __int64 uint64_t; 32 | typedef unsigned __int16 uint16_t; 33 | typedef unsigned __int8 uint8_t; 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include "openssl\ssl.h" 42 | #include "openssl\err.h" 43 | #include 44 | #include 45 | #include 46 | #include "defines.h" 47 | #include "structs.h" 48 | #include "prototypes.h" 49 | 50 | -------------------------------------------------------------------------------- /common/utils.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | uint32_t 17 | VmRESTUtilsConvertInttoString( 18 | int num, 19 | char* str 20 | ) 21 | { 22 | uint32_t dwError = 0; 23 | if(str == NULL) 24 | { 25 | dwError = 1; 26 | } 27 | BAIL_ON_VMREST_ERROR(dwError); 28 | sprintf(str, "%d", num); 29 | 30 | cleanup: 31 | return dwError; 32 | error: 33 | goto cleanup; 34 | 35 | } 36 | 37 | char 38 | VmRESTUtilsGetLastChar( 39 | char* src 40 | ) 41 | { 42 | char ret = '\0'; 43 | char* temp = NULL; 44 | 45 | if (src == NULL || (strlen(src) > MAX_SERVER_PORT_LEN)) 46 | { 47 | return ret; 48 | } 49 | temp = src; 50 | while (*temp != '\0') 51 | { 52 | ret = *temp; 53 | temp++; 54 | } 55 | return ret; 56 | } 57 | -------------------------------------------------------------------------------- /m4/as-ac-expand.m4: -------------------------------------------------------------------------------- 1 | dnl as-ac-expand.m4 0.2.0 -*- autoconf -*- 2 | dnl autostars m4 macro for expanding directories using configure's prefix 3 | 4 | dnl (C) 2003, 2004, 2005 Thomas Vander Stichele 5 | 6 | dnl Copying and distribution of this file, with or without modification, 7 | dnl are permitted in any medium without royalty provided the copyright 8 | dnl notice and this notice are preserved. 9 | 10 | dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR) 11 | 12 | dnl example: 13 | dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir) 14 | dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local 15 | 16 | AC_DEFUN([AS_AC_EXPAND], 17 | [ 18 | EXP_VAR=[$1] 19 | FROM_VAR=[$2] 20 | 21 | dnl first expand prefix and exec_prefix if necessary 22 | prefix_save=$prefix 23 | exec_prefix_save=$exec_prefix 24 | 25 | dnl if no prefix given, then use /usr/local, the default prefix 26 | if test "x$prefix" = "xNONE"; then 27 | prefix="$ac_default_prefix" 28 | fi 29 | dnl if no exec_prefix given, then use prefix 30 | if test "x$exec_prefix" = "xNONE"; then 31 | exec_prefix=$prefix 32 | fi 33 | 34 | full_var="$FROM_VAR" 35 | dnl loop until it doesn't change anymore 36 | while true; do 37 | new_full_var="`eval echo $full_var`" 38 | if test "x$new_full_var" = "x$full_var"; then break; fi 39 | full_var=$new_full_var 40 | done 41 | 42 | dnl clean up 43 | full_var=$new_full_var 44 | AC_SUBST([$1], "$full_var") 45 | 46 | dnl restore prefix and exec_prefix 47 | prefix=$prefix_save 48 | exec_prefix=$exec_prefix_save 49 | ]) 50 | 51 | -------------------------------------------------------------------------------- /transport/posix/structs.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | typedef struct _VM_SOCKET 15 | { 16 | VM_SOCK_TYPE type; 17 | struct sockaddr addr; 18 | socklen_t addrLen; 19 | PVMREST_MUTEX pMutex; 20 | int fd; 21 | SSL* ssl; 22 | BOOLEAN bSSLHandShakeCompleted; 23 | BOOLEAN bTimerExpired; 24 | char* pszBuffer; 25 | uint32_t nBufData; 26 | uint32_t nProcessed; 27 | PREST_REQUEST pRequest; 28 | struct _VM_SOCKET* pIoSocket; 29 | struct _VM_SOCKET* pTimerSocket; 30 | } VM_SOCKET; 31 | 32 | typedef struct _VM_SOCK_EVENT_QUEUE 33 | { 34 | PVMREST_MUTEX pMutex; 35 | uint32_t bShutdown; 36 | PVM_SOCKET pSignalReader; 37 | PVM_SOCKET pSignalWriter; 38 | VM_SOCK_POSIX_EVENT_STATE state; 39 | int epollFd; 40 | struct epoll_event * pEventArray; 41 | DWORD dwSize; 42 | int nReady; 43 | int iReady; 44 | uint32_t thrCnt; 45 | } VM_SOCK_EVENT_QUEUE; 46 | -------------------------------------------------------------------------------- /transport/posix/defines.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #define VM_SOCK_POSIX_DEFAULT_LISTEN_QUEUE_SIZE 8092 15 | 16 | #define VM_SOCK_POSIX_DEFAULT_QUEUE_SIZE (256) 17 | #define VM_SOCK_POSIX_DEFAULT_WORKER_THR_COUNT 5 18 | 19 | #ifndef PopEntryList 20 | #define PopEntryList(ListHead) \ 21 | (ListHead)->Next;\ 22 | {\ 23 | PSINGLE_LIST_ENTRY FirstEntry;\ 24 | FirstEntry = (ListHead)->Next;\ 25 | if (FirstEntry != NULL) { \ 26 | (ListHead)->Next = FirstEntry->Next;\ 27 | } \ 28 | } 29 | #endif 30 | 31 | #ifndef PushEntryList 32 | #define PushEntryList(ListHead,Entry) \ 33 | (Entry)->Next = (ListHead)->Next; \ 34 | (ListHead)->Next = (Entry) 35 | #endif 36 | 37 | #ifndef CONTAINING_RECORD 38 | #define CONTAINING_RECORD(address, type, field) ((type *)( \ 39 | (PCHAR)(address) - \ 40 | (uint64_t)(uintptr_t)(&((type *)0)->field))) 41 | 42 | #endif 43 | 44 | typedef enum 45 | { 46 | VM_SOCK_POSIX_EVENT_STATE_UNKNOWN = 0, 47 | VM_SOCK_POSIX_EVENT_STATE_WAIT, 48 | VM_SOCK_POSIX_EVENT_STATE_PROCESS 49 | } VM_SOCK_POSIX_EVENT_STATE; 50 | 51 | /**** Transport internal error codes ****/ 52 | #define VM_SOCK_POSIX_ERROR_SYS_CALL_FAILED 5100 53 | #define VM_SOCK_POSIX_ERROR_BROKEN_PIPE 5101 54 | #define MAX_RETRY_ATTEMPTS 50000 55 | 56 | 57 | -------------------------------------------------------------------------------- /transport/win/structs.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | typedef struct _VM_SOCKET 15 | { 16 | SOCKET hSocket; 17 | VM_SOCK_PROTOCOL protocol; 18 | VM_SOCK_TYPE type; 19 | ULONG refCount; 20 | PVM_SOCK_EVENT_QUEUE pEventQueue; 21 | PVM_STREAM_BUFFER pStreamBuffer; 22 | HANDLE hThreadListen; 23 | struct sockaddr_storage addr; 24 | SSL* ssl; 25 | int addrLen; 26 | VM_SOCK_TYPE v4v6; 27 | uint32_t wThrCnt; 28 | } VM_SOCKET; 29 | 30 | typedef struct _VM_SOCK_EVENT_QUEUE 31 | { 32 | HANDLE hIOCP; 33 | HANDLE hEventListen; 34 | BOOL bShutdown; 35 | PVMREST_MUTEX pMutex; 36 | VM_SOCKET* pListenerTCPv4; 37 | VM_SOCKET* pListenerTCPv6; 38 | uint32_t thrCnt; 39 | }VM_SOCK_EVENT_QUEUE; 40 | 41 | typedef struct _VM_SOCK_IO_CONTEXT 42 | { 43 | OVERLAPPED Overlapped; 44 | VM_SOCK_EVENT_TYPE eventType; 45 | VM_SOCK_IO_BUFFER IoBuffer; 46 | CHAR DataBuffer[1]; 47 | } VM_SOCK_IO_CONTEXT, *PVM_SOCK_IO_CONTEXT; 48 | 49 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) VMware Inc. All rights Reserved. 2 | 3 | # 4 | # This Makefile is used for both gobuild and local builds 5 | # 6 | 7 | GOBUILD_AUTO_COMPONENTS = 1 8 | 9 | GOBUILD_TARGET ?= trident 10 | 11 | ifeq ($(OS),Windows_NT) 12 | # 13 | # # Windows... 14 | # This Makefile is used by gobuild harness 15 | # # 16 | 17 | SRCROOT := .. 18 | MAKEROOT=$(SRCROOT)/support/make 19 | include $(MAKEROOT)/makedefs.mk 20 | 21 | $(info SRCROOT: [$(SRCROOT)]) 22 | $(info BUILDROOT: [$(BUILDROOT)]) 23 | $(info PUBLISH_DIR: [$(PUBLISH_DIR)]) 24 | 25 | all: gobuild-deps-copy 26 | win_build.cmd SIGN 27 | $(CP) build.log $(BUILDLOG_DIR) 28 | $(MKDIR) -p $(PUBLISH_DIR)/win64/Debug 29 | $(MKDIR) -p $(PUBLISH_DIR)/win64/Release 30 | $(MKDIR) -p $(PUBLISH_DIR)/win64/include 31 | $(CP) -frv x64/Debug/*.dll $(PUBLISH_DIR)/win64/Debug 32 | $(CP) -frv x64/Release/*.dll $(PUBLISH_DIR)/win64/Release 33 | $(CP) -frv x64/Debug/*.exe $(PUBLISH_DIR)/win64/Debug 34 | $(CP) -frv x64/Release/*.exe $(PUBLISH_DIR)/win64/Release 35 | $(CP) -frv include/public/*.h $(PUBLISH_DIR)/win64/include 36 | 37 | #include $(MAKEROOT)/makeimpl.mk 38 | 39 | ifdef GOBUILD_TARGET 40 | ifndef GOBUILD_SPECINFO_MK 41 | GOBUILD_SPECINFO_MK = 1 42 | .PHONY: $(GOBUILD_SPECINFO_MK) 43 | $(GOBUILD_SPECINFO_MK): 44 | 45 | endif 46 | 47 | .PHONY: gobuild-deps-copy deps 48 | 49 | deps: $(GOBUILD_SPECINFO_MK) gobuild-deps-copy 50 | 51 | gobuild-deps-copy: $(GOBUILD_SPECINFO_MK) 52 | endif 53 | 54 | else 55 | 56 | GOBUILD_AUTO_COMPONENTS_HOSTTYPE = linux64 57 | 58 | SRCROOT=. 59 | MAKEROOT=$(SRCROOT)/support/make 60 | include $(MAKEROOT)/makedefs.mk 61 | 62 | MAKEFILENAME = Makefile.vmware 63 | DIRS = build 64 | 65 | scrub : clean 66 | $(RM) -rf obj gobuild 67 | 68 | CLEANMORE = \ 69 | aclocal.m4 \ 70 | autom4te.cache \ 71 | Makefile.in \ 72 | config.guess \ 73 | config.sub \ 74 | configure \ 75 | depcomp \ 76 | include/config.h.in* \ 77 | install-sh \ 78 | ltmain.sh \ 79 | missing 80 | 81 | include $(MAKEROOT)/makeimpl.mk 82 | 83 | clean: 84 | @for i in `find $(CURDIR) -name Makefile.in`; do \ 85 | $(RM) -f $$i; \ 86 | done 87 | endif 88 | -------------------------------------------------------------------------------- /test/scripts/BUGS_TC/BUG-2052415/restclient.c: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * This test client will open connection to server but will not send any 3 | * data. This will make server to timeout and execute the timeout code 4 | * path. Please refer README in the same folder for more information 5 | **************************************************************************/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /************** EDIT THIS **************/ 20 | 21 | #define SERVER_IP "172.16.127.131" 22 | #define SERVER_PORT "81" 23 | 24 | /***************************************/ 25 | 26 | 27 | #define MAXDATASIZE 4096 28 | 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | int sockfd = -1; 33 | int nBytes = 0; 34 | char buf[MAXDATASIZE] = {0}; 35 | struct addrinfo hints, *servinfo, *p; 36 | int rv; 37 | char s[INET6_ADDRSTRLEN]; 38 | 39 | again: 40 | memset(&hints, 0, sizeof(hints)); 41 | hints.ai_family = AF_UNSPEC; 42 | hints.ai_socktype = SOCK_STREAM; 43 | 44 | if ((rv = getaddrinfo(SERVER_IP, SERVER_PORT, &hints, &servinfo)) != 0) { 45 | fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); 46 | return 1; 47 | } 48 | 49 | for(p = servinfo; p != NULL; p = p->ai_next) { 50 | if ((sockfd = socket(p->ai_family, p->ai_socktype, 51 | p->ai_protocol)) == -1) { 52 | perror("client: socket"); 53 | continue; 54 | } 55 | 56 | if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { 57 | close(sockfd); 58 | perror("client: connect"); 59 | continue; 60 | } 61 | 62 | break; 63 | } 64 | 65 | if (p == NULL) { 66 | printf("client: failed to connect\n"); 67 | return 2; 68 | } 69 | 70 | freeaddrinfo(servinfo); 71 | 72 | nBytes = read(sockfd, buf, MAXDATASIZE); 73 | 74 | close(sockfd); 75 | goto again; 76 | 77 | return 0; 78 | 79 | } 80 | -------------------------------------------------------------------------------- /include/vmrestsys.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #ifdef HAVE_PTHREAD_H 15 | #include 16 | #endif 17 | 18 | #ifdef HAVE_ERRNO_H 19 | #include 20 | #endif 21 | 22 | #ifdef HAVE_STDDEF_H 23 | #include 24 | #endif 25 | 26 | #ifdef HAVE_STDIO_H 27 | #include 28 | #endif 29 | 30 | #ifdef HAVE_STDLIB_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_STRING_H 35 | #include 36 | #endif 37 | 38 | #ifdef HAVE_STDARG_H 39 | #include 40 | #endif 41 | 42 | #ifdef HAVE_ASSERT_H 43 | #include 44 | #endif 45 | 46 | #ifdef HAVE_SYS_STAT_H 47 | #include 48 | #endif 49 | 50 | #ifdef HAVE_SYS_TYPES_H 51 | #include 52 | #endif 53 | 54 | #ifdef HAVE_SYS_SOCKET_H 55 | #include 56 | #endif 57 | 58 | #ifdef HAVE_NETINET_IN_H 59 | #include 60 | #endif 61 | 62 | #ifdef HAVE_SIGNAL_H 63 | #include 64 | #endif 65 | 66 | #ifdef HAVE_UNISTD_H 67 | #include 68 | #endif 69 | 70 | #ifdef HAVE_CTYPE_H 71 | #include 72 | #endif 73 | 74 | #ifdef HAVE_NETDB_H 75 | #include 76 | #endif 77 | 78 | #ifdef HAVE_SYSLOG_H 79 | #include 80 | #endif 81 | 82 | #ifdef HAVE_LOCALE_H 83 | #include 84 | #endif 85 | 86 | #ifdef HAVE_LW_BASE_H 87 | #include 88 | #endif 89 | 90 | #ifdef HAVE_OPENSSL_CRYPTO_H 91 | #include 92 | #endif 93 | 94 | #ifdef HAVE_OPENSSL_SSL_H 95 | #include 96 | #endif 97 | 98 | #ifdef HAVE_OPENSSL_ERR_H 99 | #include 100 | #endif 101 | 102 | #ifdef HAVE_UUID_UUID_H 103 | #include 104 | #endif 105 | 106 | #ifdef HAVE_TERMIOS_H 107 | #include 108 | #endif 109 | 110 | #ifdef HAVE_LIMITS_H 111 | #include 112 | #endif 113 | 114 | #ifndef WIN32 115 | #include 116 | #else 117 | #include 118 | #include 119 | #pragma comment (lib, "ws2_32.lib") 120 | #endif 121 | -------------------------------------------------------------------------------- /common/memory.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | uint32_t 17 | VmRESTAllocateMemory( 18 | size_t dwSize, 19 | void** ppMemory 20 | ) 21 | { 22 | uint32_t dwError = 0; 23 | void* pMemory = NULL; 24 | 25 | if (!ppMemory || !dwSize) 26 | { 27 | dwError = EINVAL; 28 | BAIL_ON_VMREST_ERROR(dwError); 29 | } 30 | 31 | pMemory = calloc(1, dwSize); 32 | if (!pMemory) 33 | { 34 | dwError = ENOMEM; 35 | BAIL_ON_VMREST_ERROR(dwError); 36 | } 37 | 38 | *ppMemory = pMemory; 39 | 40 | cleanup: 41 | 42 | return dwError; 43 | 44 | error: 45 | VMREST_SAFE_FREE_MEMORY(pMemory); 46 | 47 | goto cleanup; 48 | } 49 | 50 | 51 | void 52 | VmRESTFreeMemory( 53 | void* pMemory 54 | ) 55 | { 56 | if (pMemory) 57 | { 58 | free(pMemory); 59 | } 60 | 61 | } 62 | 63 | uint32_t 64 | VmRESTReallocateMemory( 65 | void* pMemory, 66 | void** ppNewMemory, 67 | size_t dwSize 68 | ) 69 | { 70 | uint32_t dwError = 0; 71 | void* pNewMemory = NULL; 72 | 73 | if (!ppNewMemory) 74 | { 75 | dwError = EINVAL; 76 | BAIL_ON_VMREST_ERROR(dwError); 77 | } 78 | 79 | if (pMemory) 80 | { 81 | pNewMemory = realloc(pMemory, dwSize); 82 | } 83 | else 84 | { 85 | dwError = VmRESTAllocateMemory(dwSize, &pNewMemory); 86 | BAIL_ON_VMREST_ERROR(dwError); 87 | } 88 | 89 | if (!pNewMemory) 90 | { 91 | dwError = ENOMEM; 92 | BAIL_ON_VMREST_ERROR(dwError); 93 | } 94 | 95 | *ppNewMemory = pNewMemory; 96 | 97 | cleanup: 98 | 99 | return dwError; 100 | 101 | error: 102 | 103 | goto cleanup; 104 | } 105 | 106 | -------------------------------------------------------------------------------- /transport/posix/libmain.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | DWORD 17 | VmSockPosixInitialize( 18 | PVM_SOCK_PACKAGE* ppPackage 19 | ) 20 | { 21 | 22 | return VmRESTGetSockPackagePosix(ppPackage); 23 | 24 | } 25 | 26 | VOID 27 | VmSockPosixShutdown( 28 | PVM_SOCK_PACKAGE pPackage 29 | ) 30 | { 31 | VmRESTFreeSockPackagePosix(pPackage); 32 | } 33 | 34 | uint32_t 35 | VmRESTGetSockPackagePosix( 36 | PVM_SOCK_PACKAGE* ppSockPackagePosix 37 | ) 38 | { 39 | uint32_t dwError = REST_ENGINE_SUCCESS; 40 | PVM_SOCK_PACKAGE pSockPackagePosix = NULL; 41 | 42 | if (!ppSockPackagePosix) 43 | { 44 | dwError = REST_ERROR_NO_MEMORY; 45 | BAIL_ON_VMREST_ERROR(dwError); 46 | } 47 | 48 | pSockPackagePosix = *ppSockPackagePosix; 49 | 50 | pSockPackagePosix->pfnStartServerSocket = &VmSockPosixStartServer; 51 | pSockPackagePosix->pfnCreateEventQueue = &VmSockPosixCreateEventQueue; 52 | pSockPackagePosix->pfnAddEventToQueue = &VmSockPosixAddEventToQueueInLock; 53 | pSockPackagePosix->pfnDeleteEventFromQueue = &VmSockPosixDeleteEventFromQueue; 54 | pSockPackagePosix->pfnWaitForEvent = &VmSockPosixWaitForEvent; 55 | pSockPackagePosix->pfnCloseEventQueue = &VmSockPosixCloseEventQueue; 56 | pSockPackagePosix->pfnRead = &VmSockPosixRead; 57 | pSockPackagePosix->pfnWrite = &VmSockPosixWrite; 58 | pSockPackagePosix->pfnReleaseSocket = &VmSockPosixReleaseSocket; 59 | pSockPackagePosix->pfnCloseSocket = &VmSockPosixCloseSocket; 60 | pSockPackagePosix->pfnGetRequestHandle = &VmSockPosixGetRequestHandle; 61 | pSockPackagePosix->pfnSetRequestHandle = &VmSockPosixSetRequestHandle; 62 | pSockPackagePosix->pfnGetPeerInfo = &VmSockPosixGetPeerInfo; 63 | 64 | cleanup: 65 | 66 | return dwError; 67 | 68 | error: 69 | 70 | goto cleanup; 71 | 72 | } 73 | 74 | VOID 75 | VmRESTFreeSockPackagePosix( 76 | PVM_SOCK_PACKAGE pSockPackagePosix 77 | ) 78 | { 79 | if (pSockPackagePosix) 80 | { 81 | /* Do nothing */ 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | C-REST-Engine 2 | ===================== 3 | C-REST-Engine is a minimal embedded HTTP(S) server written in C. Its primary intent is to 4 | enable REST(Representational State Transfer) API support for C daemons. 5 | 6 | C-REST-Engine can also be easily consumed via copenAPI project to adhere open API 7 | specification by linux foundation previously known as swagger API specs. 8 | 9 | Platforms 10 | --------- 11 | 12 | C-REST-Engine provides library for following platforms 13 | 14 | 1. Linux(.so) 15 | 16 | 2. Windows(.dll) 17 | 18 | 19 | Design Goals 20 | ------------- 21 | 22 | 1. Provides REST RPC mechanism for services and daemons written in ANSI C. 23 | 24 | 2. Provides both Secure Socket Layer(SSL) and plain text communicatiom 25 | over wire. 26 | 27 | 3. Should be small in size. 28 | 29 | 4. High performance. 30 | 31 | 5. Easily extensive. 32 | 33 | 34 | Prerequisites 35 | ------------- 36 | 37 | C-REST-Engine uses following open source project. 38 | 39 | Linux: 40 | 41 | 1. Openssl (Linux) 42 | 43 | Windows: 44 | 45 | 1. OpensSL (Windows) 46 | 47 | 2. rd-platform-sdk-windows (VMWare internal POSIX library implementation) 48 | 49 | 50 | Source code 51 | ----------- 52 | 53 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 54 | git clone https://github.com/vmware/c-rest-engine.git 55 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 | 57 | Build 58 | ----- 59 | 60 | These build instructions are to build C-REST-Engine on VMware's Photon Linux 61 | distribution. 62 | 63 | 1. Clone c-rest-engine git repository onto your Photon (Full) installation. 64 | 65 | 2. "cd build" 66 | 67 | 3. For RPM build: 68 | "make -f Makefile.bootstrap DEBUG=1" 69 | 70 | For object file in same directory: 71 | "autoreconf -mif .. && ../configure && make" 72 | 73 | 4. As part of a successful build, the following RPMs should be created in the 74 | 75 | 1. c-rest-engine/build/rpmbuild/RPMS/x86_64/c-rest-engine--.x86_64.rpm 76 | 77 | Installation 78 | ------------ 79 | 80 | 1. While building from source: 81 | 82 | Use RPM install command to install the above generated RPM. 83 | 84 | "rpm -ivh trident/build/rpmbuild/RPMS/x86_64/c-rest-engine-.x86_64.rpm" 85 | 86 | The installed libraries will go in following folder 87 | "/usr/lib64/" 88 | 89 | NOTE: If previous version of same RPM is already installed please delete it 90 | using the following command "rpm -e c-rest-engine" 91 | 92 | 2. Using package manager on Photon OS Linux distribution. 93 | 94 | Pre-built library for trident are available through the following YUM 95 | repositories that can be configured on your Photon deployment. 96 | 97 | After the following YUM repositories have been configured, it should be possible 98 | to install the trident using "tdnf install vmware-rest". 99 | 100 | -------------------------------------------------------------------------------- /win_build.cmd: -------------------------------------------------------------------------------- 1 | 2 | @echo on 3 | set LOGDIR=%CD% 4 | set LOG=%CD%\build.log 5 | set DEBUGLOG=%CD%\debug_build.log 6 | set RELEASELOG=%CD%\release_build.log 7 | 8 | set WINSDK_PATH=%TCROOT%\win32\winsdk-7.0.7600 9 | set VC_PATH=%WINSDK_PATH%\VC 10 | set FRAMEWORK_PATH=%windir%\Microsoft.NET\Framework\v3.5 11 | set BASE_PATH=%VC_PATH%\bin\amd64;%VC_PATH%\vcpackages;%WINSDK_PATH%\bin 12 | set BASE_PATH=%BASE_PATH%;%TCROOT%\win32\bin;%WIX_PATH% 13 | set BASE_PATH=%BASE_PATH%;%SystemRoot%\system32;%SystemRoot% 14 | set BASE_PATH=%BASE_PATH%;%SystemRoot%\SysWOW64\wbem;%SystemRoot%\system32\wbem 15 | set CPU=AMD64 16 | set INCLUDE=%VC_PATH%\atlmfc\Include;%VC_PATH%\Include;%WINSDK_PATH%\Include; 17 | set LIB=%VC_PATH%\atlmfc\Lib\amd64;%VC_PATH%\lib\amd64;%WINSDK_PATH%\Lib\x64; 18 | set LIBPATH=%FRAMEWORK_PATH%;%VC_PATH%\atlmfc\Lib\amd64;%VC_PATH%\lib\amd64;%WINSDK_PATH%\Lib\x64; 19 | set MS_BUILD="%windir%\Microsoft.NET\Framework\v3.5\MSBuild.exe" 20 | 21 | set PATH=%TCROOT%\win32\make-3.81;%TCROOT%\win32\cygwin-1.5.19-4\bin;%BASE_PATH%;%WINSDK_PATH%\dll\amd64\Microsoft.VC90.DebugCRT;%WINSDK_PATH%\bin 22 | 23 | (echo starting trident build )>%LOG% 24 | 25 | set BUILD_VS2008="%TCROOT%\win32\winsdk-7.0.7600\VC\vcpackages\vcbuild.exe" 26 | (echo BUILD_VS2008=%BUILD_VS2008%)>>%LOG% 27 | 28 | pushd . 29 | 30 | (echo )>>%LOG% 31 | (echo =======================================================================================)>>%LOG% 32 | (echo Building trident )>%LOG% 33 | 34 | echo Build Debug x64 35 | %BUILD_VS2008% td4.sln /logfile:%DEBUGLOG% /Rebuild "Debug|x64" /useenv /showenv /logcommands /Time 36 | if errorlevel 1 ( 37 | (echo VS 2008 td4.sln Debug x64 FAILED)>>%DEBUGLOG% 38 | echo VS 2008 td4.sln Debug x64 FAILED 39 | goto error 40 | ) 41 | 42 | (echo DONE building trident)>%LOG% 43 | 44 | (echo )>>%LOG% 45 | (echo =======================================================================================)>>%LOG% 46 | 47 | (echo )>>%LOG% 48 | (echo =======================================================================================)>>%LOG% 49 | (echo Building trident )>%LOG% 50 | 51 | echo Build Release x64 52 | %BUILD_VS2008% td4.sln /logfile:%RELEASELOG% /Rebuild "Release|x64" /useenv /showenv /logcommands /Time 53 | if errorlevel 1 ( 54 | (echo VS 2008 td4.sln Release x64 FAILED)>>%RELEASELOG% 55 | echo VS 2008 td4.sln Release x64 FAILED 56 | goto error 57 | ) 58 | 59 | (echo DONE building trident)>%LOG% 60 | 61 | (echo )>>%LOG% 62 | (echo =======================================================================================)>>%LOG% 63 | 64 | 65 | goto end 66 | 67 | :error 68 | 69 | (echo !!!!!!!!!!Build FAILED!!!!!!!!!! [Log: "%LOG%"])>>%LOG% 70 | echo !!!!!!!!!!Build FAILED!!!!!!!!!! [Log: "%LOG%"] 71 | if not %BUILDLOG_DIR% == "" ( 72 | copy %LOGDIR%\*.log %BUILDLOG_DIR:/=\% 73 | ) 74 | popd 75 | exit /B 1 76 | 77 | :end 78 | 79 | (echo !!!!!!!!!!Build succeeded!!!!!!!!!!)>>%LOG% 80 | echo !!!!!!!!!!Build succeeded!!!!!!!!!! 81 | if not "%BUILDLOG_DIR%" == "" ( 82 | copy %LOGDIR%\*.log %BUILDLOG_DIR:/=\% 83 | ) 84 | 85 | popd 86 | exit /B 0 87 | -------------------------------------------------------------------------------- /transport/win/libmain.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | DWORD 17 | VmWinSockInitialize( 18 | PVM_SOCK_PACKAGE* ppPackage 19 | ) 20 | { 21 | DWORD dwError = 0; 22 | WSADATA wsaData = { 0 }; 23 | 24 | dwError = WSAStartup(MAKEWORD(2, 2), &wsaData); 25 | BAIL_ON_VMREST_ERROR(dwError); 26 | 27 | dwError = VmRESTGetSockPackageWin(ppPackage); 28 | BAIL_ON_VMREST_ERROR(dwError); 29 | 30 | cleanup: 31 | 32 | return dwError; 33 | 34 | error: 35 | 36 | *ppPackage = NULL; 37 | 38 | goto cleanup; 39 | } 40 | 41 | VOID 42 | VmWinSockShutdown( 43 | PVM_SOCK_PACKAGE pPackage 44 | ) 45 | { 46 | // WSACleanup(); 47 | } 48 | 49 | 50 | uint32_t 51 | VmRESTGetSockPackageWin( 52 | PVM_SOCK_PACKAGE* ppSockPackageWin 53 | ) 54 | { 55 | uint32_t dwError = REST_ENGINE_SUCCESS; 56 | PVM_SOCK_PACKAGE pSockPackageWin = NULL; 57 | 58 | if (!ppSockPackageWin) 59 | { 60 | dwError = REST_ENGINE_NO_MEMORY; 61 | BAIL_ON_VMREST_ERROR(dwError); 62 | } 63 | 64 | pSockPackageWin = *ppSockPackageWin; 65 | 66 | pSockPackageWin->pfnOpenServerSocket = &VmSockWinOpenServer; 67 | pSockPackageWin->pfnCreateEventQueue = &VmSockWinCreateEventQueue; 68 | pSockPackageWin->pfnAddEventQueue = &VmSockWinEventQueueAdd; 69 | pSockPackageWin->pfnWaitForEvent = &VmSockWinWaitForEvent; 70 | pSockPackageWin->pfnCloseEventQueue = &VmSockWinCloseEventQueue; 71 | pSockPackageWin->pfnRead = &VmSockWinRead; 72 | pSockPackageWin->pfnWrite = &VmSockWinWrite; 73 | pSockPackageWin->pfnAcquireSocket = &VmSockWinAcquire; 74 | pSockPackageWin->pfnReleaseSocket = &VmSockWinRelease; 75 | pSockPackageWin->pfnCloseSocket = &VmSockWinClose; 76 | pSockPackageWin->pfnAllocateIoBuffer = &VmSockWinAllocateIoBuffer; 77 | pSockPackageWin->pfnReleaseIoBuffer = &VmSockWinFreeIoBuffer; 78 | pSockPackageWin->pfnGetStreamBuffer = &VmSockWinGetStreamBuffer; 79 | pSockPackageWin->pfnSetStreamBuffer = &VmSockWinSetStreamBuffer; 80 | 81 | cleanup: 82 | 83 | return dwError; 84 | 85 | error: 86 | 87 | goto cleanup; 88 | 89 | } 90 | 91 | VOID 92 | VmRESTFreeSockPackageWin( 93 | PVM_SOCK_PACKAGE pSockPackageWin 94 | ) 95 | { 96 | if (pSockPackageWin) 97 | { 98 | /* Do nothing */ 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /test/scripts/infiteData.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | void 15 | VmSockPosixSetSocketNonBlocking( 16 | int server_fd 17 | ) 18 | { 19 | int cur_flags = 0; 20 | int set_flags = 0; 21 | 22 | cur_flags = fcntl(server_fd, F_GETFL, 0); 23 | cur_flags |= O_NONBLOCK; 24 | set_flags = fcntl(server_fd, F_SETFL, cur_flags); 25 | 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | int sockfd, numbytes; 31 | char *buf = NULL; 32 | char* res = NULL; 33 | char expected[512]; 34 | char expected1[512]; 35 | char out[512]; 36 | struct addrinfo hints, *servinfo, *p; 37 | int rv; 38 | char s[INET6_ADDRSTRLEN]; 39 | int c = 0, x = 0; 40 | int max_data_size = 0; 41 | 42 | if (argc != 5) { 43 | printf("Wrong number of arguments supplied to test program\n"); 44 | exit(1); 45 | } 46 | 47 | max_data_size = atoi(argv[3]); 48 | 49 | buf = (char*)malloc(max_data_size); 50 | 51 | memset(buf, '\0',max_data_size); 52 | memset(expected, '\0', 512); 53 | memset(expected1, '\0', 512); 54 | memset(out, '\0', 512); 55 | strcpy(expected, "HTTP/1.1 408 Request Timeout\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 56 | strcpy(expected1, "HTTP/1.1 414 URI too Long\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 57 | 58 | memset(&hints, 0, sizeof(hints)); 59 | hints.ai_family = AF_UNSPEC; 60 | hints.ai_socktype = SOCK_STREAM; 61 | 62 | if ((rv = getaddrinfo(argv[1], argv[2], &hints, &servinfo)) != 0) { 63 | fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); 64 | return 1; 65 | } 66 | 67 | for(p = servinfo; p != NULL; p = p->ai_next) { 68 | if ((sockfd = socket(p->ai_family, p->ai_socktype, 69 | p->ai_protocol)) == -1) { 70 | perror("client: socket"); 71 | continue; 72 | } 73 | 74 | if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { 75 | close(sockfd); 76 | perror("client: connect"); 77 | continue; 78 | } 79 | 80 | break; 81 | } 82 | 83 | if (p == NULL) { 84 | printf("client: failed to connect\n"); 85 | return 2; 86 | } 87 | 88 | freeaddrinfo(servinfo); 89 | 90 | res = expected; 91 | if (((strcmp(argv[4], "TEST 1") == 0) || (strcmp(argv[4], "TEST 8") == 0))) 92 | { 93 | res = expected1; 94 | } 95 | 96 | memset(buf, 'B', max_data_size); 97 | write(sockfd, buf, max_data_size); 98 | x = read(sockfd, out, 512); 99 | 100 | // printf("\n\n%s\n\n", out); 101 | sleep(1); 102 | 103 | if (strcmp(out, res) == 0) 104 | { 105 | printf("\n%s PASSED\n", argv[4]); 106 | } 107 | else 108 | { 109 | printf("\n%s FAILED\n", argv[4]); 110 | } 111 | 112 | close(sockfd); 113 | free(buf); 114 | return 0; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /test/scripts/BUGS_TC/BUG-2076723/persistentConnection.c: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | * This test client uses libcurl to open connection to server and re-uses 3 | * the same connection to send multiple HTTPS requests. 4 | **************************************************************************/ 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | struct string 15 | { 16 | char *ptr; 17 | size_t len; 18 | }; 19 | 20 | void init_string(struct string *s) 21 | { 22 | s->len = 0; 23 | s->ptr = malloc(s->len+1); 24 | if (s->ptr == NULL) 25 | { 26 | fprintf(stderr, "malloc() failed\n"); 27 | exit(EXIT_FAILURE); 28 | } 29 | s->ptr[0] = '\0'; 30 | } 31 | 32 | size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s) 33 | { 34 | size_t new_len = s->len + size*nmemb; 35 | s->ptr = realloc(s->ptr, new_len+1); 36 | if (s->ptr == NULL) 37 | { 38 | fprintf(stderr, "realloc() failed\n"); 39 | exit(EXIT_FAILURE); 40 | } 41 | memcpy(s->ptr+s->len, ptr, size*nmemb); 42 | s->ptr[new_len] = '\0'; 43 | s->len = new_len; 44 | return size*nmemb; 45 | } 46 | 47 | int main (int argc, char *argv[]) 48 | { 49 | CURL* curl = NULL; 50 | CURLcode res = 0; 51 | int ct = 0; 52 | char expected[512] = {0}; 53 | 54 | if (argc != 2) { 55 | printf("Wrong number of arguments supplied to test program\n"); 56 | exit(1); 57 | } 58 | 59 | struct string s; 60 | curl_global_init(CURL_GLOBAL_ALL); 61 | 62 | curl = curl_easy_init(); 63 | if(curl) 64 | { 65 | try: 66 | init_string(&s); 67 | struct curl_slist *chunk = NULL; 68 | 69 | curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); 70 | curl_easy_setopt(curl, CURLOPT_HEADER, 1L); 71 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); 72 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); 73 | curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); 74 | 75 | if (ct == 500) 76 | { 77 | chunk = curl_slist_append(chunk, "Connection:close"); 78 | strcpy(expected,"HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length:13\r\n\r\nKumar Kaushik"); 79 | } 80 | else 81 | { 82 | chunk = curl_slist_append(chunk, "Connection:keep-alive"); 83 | strcpy(expected,"HTTP/1.1 200 OK\r\nConnection:keep-alive\r\nContent-Length:13\r\n\r\nKumar Kaushik"); 84 | } 85 | curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); 86 | 87 | curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "Kumar Kaushik"); 88 | curl_easy_setopt(curl, CURLOPT_URL, argv[1]); 89 | 90 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); 91 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); 92 | res = curl_easy_perform(curl); 93 | if(res != CURLE_OK) 94 | { 95 | fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); 96 | } 97 | 98 | if (strcmp(expected, s.ptr) == 0) 99 | { 100 | printf("Test passed, iteration %d\n", ct); 101 | } 102 | else 103 | { 104 | printf("Test failed, iteration %d\n", ct); 105 | } 106 | //printf("\n===============\n%s\n==========\n", s.ptr); 107 | free(s.ptr); 108 | 109 | ct++; 110 | 111 | if (ct <= 500) 112 | { 113 | goto try; 114 | } 115 | 116 | curl_easy_cleanup(curl); 117 | } 118 | 119 | return 0; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /server/restengine/structs.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | typedef struct _REST_ENG_GLOBALS 15 | { 16 | PVMREST_THREAD pThreadpool; 17 | uint32_t nThreads; 18 | pthread_mutex_t mutex; 19 | PREST_ENDPOINT pEndPointQueue; 20 | uint32_t useEndPoint; 21 | REST_PROCESSOR internalHandler; 22 | 23 | } REST_ENG_GLOBALS; 24 | 25 | typedef struct _VM_REST_HTTP_MESSAGE_BODY 26 | { 27 | char buffer[MAX_DATA_BUFFER_LEN]; 28 | 29 | }VM_REST_HTTP_MESSAGE_BODY, *PVM_REST_HTTP_MESSAGE_BODY; 30 | 31 | typedef struct _VM_REST_URL_PARAMS 32 | { 33 | char key[MAX_KEY_VAL_PARAM_LEN]; 34 | char value[MAX_KEY_VAL_PARAM_LEN]; 35 | 36 | }VM_REST_URL_PARAMS, *PVM_REST_URL_PARAMS; 37 | 38 | /* http protocol structures */ 39 | 40 | typedef struct _VM_REST_HTTP_REQUEST_LINE 41 | { 42 | char method[MAX_METHOD_LEN]; 43 | char uri[MAX_URI_LEN]; 44 | char version[MAX_VERSION_LEN]; 45 | 46 | }VM_REST_HTTP_REQUEST_LINE, *PVM_REST_HTTP_REQUEST_LINE; 47 | 48 | typedef struct _VM_REST_HTTP_STATUS_LINE 49 | { 50 | char version[MAX_VERSION_LEN]; 51 | char statusCode[MAX_STATUS_LEN]; 52 | char reason_phrase[MAX_REA_PHRASE_LEN]; 53 | 54 | }VM_REST_HTTP_STATUS_LINE, *PVM_REST_HTTP_STATUS_LINE; 55 | 56 | typedef struct _VM_REST_HTTP_HEADER_NODE 57 | { 58 | char header[MAX_HTTP_HEADER_ATTR_LEN]; 59 | char value[MAX_HTTP_HEADER_VAL_LEN]; 60 | struct _VM_REST_HTTP_HEADER_NODE *next; 61 | 62 | }VM_REST_HTTP_HEADER_NODE, *PVM_REST_HTTP_HEADER_NODE; 63 | 64 | typedef struct _MISC_HEADER_QUEUE { 65 | 66 | PVM_REST_HTTP_HEADER_NODE head; 67 | 68 | }MISC_HEADER_QUEUE, *PMISC_HEADER_QUEUE; 69 | 70 | typedef struct _VM_REST_HTTP_REQUEST_PACKET 71 | { 72 | PVM_REST_HTTP_REQUEST_LINE requestLine; 73 | PMISC_HEADER_QUEUE miscHeader; 74 | PVM_SOCKET pSocket; 75 | uint32_t dataRemaining; 76 | VM_REST_URL_PARAMS paramArray[MAX_URL_PARAMS_ARR_SIZE]; 77 | uint32_t dataNotRcvd; 78 | VM_REST_PROCESSING_STATE state; 79 | PREST_RESPONSE pResponse; 80 | HTTP_PAYLOAD_TYPE payloadType; 81 | uint32_t nPayload; 82 | char* pszPayload; 83 | int clientPort; 84 | char clientIP[MAX_CLIENT_IP_ADDR_LEN]; 85 | uint32_t nBytesGetPayload; 86 | 87 | }VM_REST_HTTP_REQUEST_PACKET, *PVM_REST_HTTP_REQUEST_PACKET; 88 | 89 | typedef struct _VM_REST_HTTP_RESPONSE_PACKET 90 | { 91 | PVM_REST_HTTP_STATUS_LINE statusLine; 92 | PVM_REST_HTTP_MESSAGE_BODY messageBody; 93 | PMISC_HEADER_QUEUE miscHeader; 94 | PVM_SOCKET pSocket; 95 | PVM_REST_HTTP_REQUEST_PACKET requestPacket; 96 | BOOLEAN bHeaderSent; 97 | 98 | }VM_REST_HTTP_RESPONSE_PACKET, *PVM_REST_HTTP_RESPONSE_PACKET; 99 | 100 | struct _VM_REST_RESPONSE_DATA 101 | { 102 | int junk; 103 | }VM_REST_RESPONSE_DATA, *PVM_REST_RESPONSE_DATA; 104 | 105 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.59) 2 | 3 | AC_INIT([vrest], [1.0.0], [support@vmware.com]) 4 | AC_CANONICAL_SYSTEM 5 | AM_INIT_AUTOMAKE([-Wall -Werror foreign]) 6 | AC_CONFIG_HEADERS([include/config.h]) 7 | AC_CONFIG_MACRO_DIR([m4]) 8 | m4_pattern_allow([AM_PROG_AR]) 9 | AM_PROG_AR 10 | 11 | AC_PROG_CC 12 | AC_PROG_LIBTOOL 13 | 14 | dnl Check supported operating systems 15 | dnl 16 | 17 | case "${host_os}:${host_cpu}" in 18 | 19 | linux*:x86_64) 20 | ;; 21 | *) 22 | AC_ERROR("Unsupported operating system - ${host_os}:${host_cpu}") 23 | ;; 24 | esac 25 | 26 | CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_GNU_SOURCE -fPIC" 27 | CFLAGS="" 28 | 29 | AM_CPPFLAGS="$AM_CPPFLAGS -I${top_srcdir}/include" 30 | AM_CFLAGS="$AM_CFLAGS -Wall -Werror -fno-strict-aliasing" 31 | 32 | AC_SUBST(AM_CPPFLAGS) 33 | AC_SUBST(AM_CFLAGS) 34 | 35 | AC_ARG_ENABLE([debug], 36 | [AC_HELP_STRING([--enable-debug], [enable debugging (default: disabled)])], 37 | [ 38 | if test x"$enableval" = x"yes" 39 | then 40 | AM_CFLAGS="$AM_CFLAGS -g -O0" 41 | AM_CPPFLAGS="$AM_CPPFLAGS -DDEBUG -DLDAP_DEBUG" 42 | fi 43 | ]) 44 | 45 | # openssl component 46 | 47 | AC_ARG_WITH([ssl], 48 | [AC_HELP_STRING([--with-ssl=], [use SSL binaries rooted at prefix ])], 49 | [ 50 | OPENSSL_BASE_PATH="$withval" 51 | OPENSSL_INCLUDES="-I$withval/include" 52 | OPENSSL_LDFLAGS="-L$withval/lib64 -Wl,-rpath,/opt/vmware/lib64 -Wl,-rpath-link,/opt/vmware/lib64" 53 | ]) 54 | 55 | AC_ARG_WITH([ssl-includes], 56 | [AC_HELP_STRING([--with-ssl-includes=], [use SSL headers located in prefix ])], 57 | [ 58 | OPENSSL_INCLUDES="-I$withval" 59 | ]) 60 | 61 | AC_ARG_WITH([ssl-libs], 62 | [AC_HELP_STRING([--with-ssl-libs=], [use SSL libraries located in prefix ])], 63 | [ 64 | OPENSSL_LDFLAGS="-L$withval" 65 | ]) 66 | 67 | AC_SUBST(OPENSSL_BASE_PATH) 68 | AC_SUBST(OPENSSL_INCLUDES) 69 | AC_SUBST(OPENSSL_LDFLAGS) 70 | 71 | CPPFLAGS="$CPPFLAGS $OPENSSL_INCLUDES" 72 | 73 | AC_CHECK_HEADERS(openssl/crypto.h openssl/ssl.h openssl/err.h) 74 | 75 | AC_HEADER_STDC 76 | AC_CHECK_HEADERS(pthread.h errno.h sys/types.h stdio.h string.h strings.h) 77 | AC_CHECK_HEADERS(unistd.h time.h inttypes.h sys/socket.h netdb.h syslog.h) 78 | AC_CHECK_HEADERS(stdlib.h locale.h stddef.h stdarg.h assert.h signal.h) 79 | AC_CHECK_HEADERS(ctype.h netinet/in.h) 80 | 81 | AC_C_CONST 82 | AC_TYPE_SIZE_T 83 | 84 | AC_FUNC_VPRINTF 85 | AC_CHECK_FUNCS(strerror) 86 | 87 | AC_CHECK_LIB([dl], [dlopen], [DL_LIBS="-ldl"]) 88 | AC_CHECK_LIB([pthread], [pthread_self], [PTHREAD_LIBS="-lpthread"]) 89 | AC_CHECK_LIB([uuid],[uuid_copy], [UUID_LIBS="-luuid"], [], [$LW_LDFLAGS -luuid]) 90 | AC_CHECK_LIB( 91 | [crypto], 92 | [MD5_Init], 93 | [CRYPTO_LIBS="-lcrypto -lssl"], 94 | [], 95 | [$OPENSSL_LDFLAGS]) 96 | 97 | AC_CHECK_LIB([shadow], [getspnam], [SHADOW_LIBS="-lshadow"]) 98 | AC_CHECK_LIB([crypt], [crypt_r], [CRYPT_LIBS="-lcrypt"]) 99 | 100 | AC_SUBST(DL_LIBS) 101 | AC_SUBST(PTHREAD_LIBS) 102 | AC_SUBST(CRYPTO_LIBS) 103 | AC_SUBST(UUID_LIBS) 104 | 105 | REST_PREFIX_DIR=$prefix 106 | AC_SUBST(REST_PREFIX_DIR) 107 | 108 | vmrestconfdir="$datadir/config" 109 | AC_SUBST(vmrestconfdir) 110 | AS_AC_EXPAND(VMREST_CONFIG_DIR, $vmrestconfdir) 111 | AC_SUBST(VMREST_CONFIG_DIR) 112 | AC_DEFINE_UNQUOTED(VMREST_CONFIG_DIR, "$VMREST_CONFIG_DIR", [Config directory]) 113 | 114 | AC_CONFIG_FILES([Makefile 115 | include/Makefile 116 | include/public/Makefile 117 | common/Makefile 118 | transport/Makefile 119 | transport/api/Makefile 120 | transport/posix/Makefile 121 | server/Makefile 122 | server/restengine/Makefile 123 | server/vmrestd/Makefile 124 | client/Makefile 125 | tools/Makefile 126 | tools/rest-cli/Makefile 127 | build/package/rpm/c-rest-engine.spec 128 | ]) 129 | AC_OUTPUT 130 | 131 | -------------------------------------------------------------------------------- /transport/posix/prototypes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | DWORD 15 | VmSockPosixStartServer( 16 | PVMREST_HANDLE pRESTHandle, 17 | VM_SOCK_CREATE_FLAGS dwFlags, 18 | PVM_SOCKET* ppSocket 19 | ); 20 | 21 | DWORD 22 | VmSockPosixCreateEventQueue( 23 | PVMREST_HANDLE pRESTHandle, 24 | PVM_SOCK_EVENT_QUEUE* ppQueue 25 | ); 26 | 27 | DWORD 28 | VmSockPosixAddEventToQueueInLock( 29 | PVMREST_HANDLE pRESTHandle, 30 | PVM_SOCK_EVENT_QUEUE pQueue, 31 | PVM_SOCKET pSocket 32 | ); 33 | 34 | DWORD 35 | VmSockPosixDeleteEventFromQueue( 36 | PVMREST_HANDLE pRESTHandle, 37 | PVM_SOCK_EVENT_QUEUE pQueue, 38 | PVM_SOCKET pSocket 39 | ); 40 | 41 | DWORD 42 | VmSockPosixWaitForEvent( 43 | PVMREST_HANDLE pRESTHandle, 44 | PVM_SOCK_EVENT_QUEUE pQueue, 45 | int iTimeoutMS, 46 | PVM_SOCKET* ppSocket, 47 | PVM_SOCK_EVENT_TYPE pEventType 48 | ); 49 | 50 | DWORD 51 | VmSockPosixCloseEventQueue( 52 | PVMREST_HANDLE pRESTHandle, 53 | PVM_SOCK_EVENT_QUEUE pQueue, 54 | uint32_t waitSecond 55 | ); 56 | 57 | DWORD 58 | VmSockPosixSetNonBlocking( 59 | PVMREST_HANDLE pRESTHandle, 60 | PVM_SOCKET pSocket 61 | ); 62 | 63 | DWORD 64 | VmSockPosixRead( 65 | PVMREST_HANDLE pRESTHandle, 66 | PVM_SOCKET pSocket, 67 | char** ppszBuffer, 68 | uint32_t* nBufLen 69 | ); 70 | 71 | DWORD 72 | VmSockPosixWrite( 73 | PVMREST_HANDLE pRESTHandle, 74 | PVM_SOCKET pSocket, 75 | char* pszBuffer, 76 | uint32_t nBufLen 77 | ); 78 | 79 | VOID 80 | VmSockPosixReleaseSocket( 81 | PVMREST_HANDLE pRESTHandle, 82 | PVM_SOCKET pSocket 83 | ); 84 | 85 | DWORD 86 | VmSockPosixCloseSocket( 87 | PVMREST_HANDLE pRESTHandle, 88 | PVM_SOCKET pSocket 89 | ); 90 | 91 | DWORD 92 | VmSockPosixGetRequestHandle( 93 | PVMREST_HANDLE pRESTHandle, 94 | PVM_SOCKET pSocket, 95 | PREST_REQUEST* ppRequest 96 | ); 97 | 98 | DWORD 99 | VmSockPosixSetRequestHandle( 100 | PVMREST_HANDLE pRESTHandle, 101 | PVM_SOCKET pSocket, 102 | PREST_REQUEST pRequest, 103 | uint32_t nProcessed, 104 | BOOLEAN bKeepAlive 105 | ); 106 | 107 | DWORD 108 | VmSockPosixGetPeerInfo( 109 | PVMREST_HANDLE pRESTHandle, 110 | PVM_SOCKET pSocket, 111 | char* pIpAddress, 112 | uint32_t nLen, 113 | int* pPortNo 114 | ); 115 | 116 | uint32_t 117 | VmRESTGetSockPackagePosix( 118 | PVM_SOCK_PACKAGE* ppSockPackagePosix 119 | ); 120 | 121 | VOID 122 | VmRESTFreeSockPackagePosix( 123 | PVM_SOCK_PACKAGE pSockPackagePosix 124 | ); 125 | 126 | uint32_t 127 | VmRESTSSLThreadLockInit( 128 | void 129 | ); 130 | 131 | void 132 | VmRESTSSLThreadLockShutdown( 133 | void 134 | ); 135 | 136 | uint32_t 137 | VmRESTSecureSocket( 138 | PVMREST_HANDLE pRESTHandle, 139 | char* certificate, 140 | char* key 141 | ); 142 | 143 | void 144 | VmRESTSecureSocketShutdown( 145 | PVMREST_HANDLE pRESTHandle 146 | ); 147 | -------------------------------------------------------------------------------- /server/restengine/httpMain.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | uint32_t 17 | VmHTTPInit( 18 | PVMREST_HANDLE pRESTHandle, 19 | PREST_CONF pConfig 20 | ) 21 | { 22 | uint32_t dwError = REST_ENGINE_SUCCESS; 23 | 24 | if (!pRESTHandle || !pConfig) 25 | { 26 | dwError = REST_ERROR_INVALID_CONFIG; 27 | } 28 | BAIL_ON_VMREST_ERROR(dwError); 29 | 30 | dwError = VmRESTCopyConfig( 31 | pConfig, 32 | &(pRESTHandle->pRESTConfig) 33 | ); 34 | BAIL_ON_VMREST_ERROR(dwError); 35 | 36 | /**** Validate the config param ****/ 37 | dwError = VmRESTValidateConfig( 38 | pRESTHandle, 39 | pRESTHandle->pRESTConfig 40 | ); 41 | BAIL_ON_VMREST_ERROR(dwError); 42 | 43 | /**** Init logging and transport ****/ 44 | dwError = VmRESTInitProtocolServer( 45 | pRESTHandle 46 | ); 47 | BAIL_ON_VMREST_ERROR(dwError); 48 | 49 | pRESTHandle->debugLogLevel = pRESTHandle->pRESTConfig->debugLogLevel; 50 | 51 | /**** Update context Info for this lib instance ****/ 52 | pRESTHandle->pInstanceGlobal->useEndPoint = 0; 53 | 54 | VMREST_LOG_INFO(pRESTHandle,"%s","C-REST_ENGINE: Library initialized ..."); 55 | 56 | cleanup: 57 | 58 | return dwError; 59 | 60 | error: 61 | 62 | goto cleanup; 63 | } 64 | 65 | uint32_t 66 | VmHTTPStart( 67 | PVMREST_HANDLE pRESTHandle 68 | ) 69 | { 70 | uint32_t dwError = REST_ENGINE_SUCCESS; 71 | 72 | dwError = VmRESTStartProtocolServer( 73 | pRESTHandle 74 | ); 75 | BAIL_ON_VMREST_ERROR(dwError); 76 | 77 | VMREST_LOG_INFO(pRESTHandle,"%s","C-REST_ENGINE: Library started ..."); 78 | 79 | cleanup: 80 | 81 | return dwError; 82 | error: 83 | goto cleanup; 84 | } 85 | 86 | uint32_t 87 | VmHTTPRegisterHandler( 88 | PVMREST_HANDLE pRESTHandle, 89 | PREST_PROCESSOR pHandler 90 | ) 91 | { 92 | uint32_t dwError = REST_ENGINE_SUCCESS; 93 | 94 | if (!pHandler || !pRESTHandle) 95 | { 96 | dwError = REST_ERROR_INVALID_REST_PROCESSER; 97 | } 98 | BAIL_ON_VMREST_ERROR(dwError); 99 | pRESTHandle->pHttpHandler = pHandler; 100 | 101 | cleanup: 102 | return dwError; 103 | error: 104 | goto cleanup; 105 | } 106 | 107 | uint32_t 108 | VmHTTPUnRegisterHandler( 109 | PVMREST_HANDLE pRESTHandle 110 | ) 111 | { 112 | uint32_t dwError = REST_ENGINE_SUCCESS; 113 | 114 | if (pRESTHandle == NULL) 115 | { 116 | dwError = REST_ERROR_INVALID_REST_PROCESSER; 117 | } 118 | BAIL_ON_VMREST_ERROR(dwError); 119 | 120 | pRESTHandle->pHttpHandler = NULL; 121 | 122 | cleanup: 123 | return dwError; 124 | error: 125 | goto cleanup; 126 | } 127 | 128 | uint32_t 129 | VmHTTPStop( 130 | PVMREST_HANDLE pRESTHandle, 131 | uint32_t waitSecond 132 | ) 133 | { 134 | uint32_t dwError = REST_ENGINE_SUCCESS; 135 | 136 | VMREST_LOG_INFO(pRESTHandle,"%s","C-REST_ENGINE: Stopping library ... No more requests will be accepted"); 137 | 138 | dwError = VmRESTStopProtocolServer( 139 | pRESTHandle, 140 | waitSecond 141 | ); 142 | BAIL_ON_VMREST_ERROR(dwError); 143 | 144 | VMREST_LOG_INFO(pRESTHandle,"%s", "C-REST-ENGINE: Library stopped ..."); 145 | 146 | cleanup: 147 | 148 | return dwError; 149 | error: 150 | 151 | VMREST_LOG_ERROR(pRESTHandle,"C-REST-ENGINE: Library stop failed ... Do not attempt shutdown, dwError = %u", dwError); 152 | goto cleanup; 153 | } 154 | 155 | void 156 | VmHTTPShutdown( 157 | PVMREST_HANDLE pRESTHandle 158 | ) 159 | { 160 | VMREST_LOG_INFO(pRESTHandle,"%s","C-REST-ENGINE: Shutting down Library"); 161 | VmRESTShutdownProtocolServer( 162 | pRESTHandle 163 | ); 164 | 165 | if (pRESTHandle) 166 | { 167 | VmRESTFreeHandle(pRESTHandle); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /common/logging.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | #define NSECS_PER_MSEC 1000000 17 | #define EXTRA_LOG_MESSAGE_LEN 128 18 | #define MAX_LOG_MESSAGE_LEN 4096 19 | 20 | static const char * 21 | logLevelToTag( 22 | int level 23 | ); 24 | 25 | static 26 | int 27 | logLevelToSysLogLevel( 28 | int level 29 | ); 30 | 31 | uint32_t 32 | VmRESTLogInitialize( 33 | PVMREST_HANDLE pRESTHandle 34 | ) 35 | { 36 | uint32_t dwError = REST_ENGINE_SUCCESS; 37 | 38 | if (!pRESTHandle || !pRESTHandle->pRESTConfig) 39 | { 40 | dwError = REST_ENGINE_FAILURE; 41 | } 42 | BAIL_ON_VMREST_ERROR(dwError); 43 | 44 | if ((!(IsNullOrEmptyString(pRESTHandle->pRESTConfig->pszDebugLogFile))) && (pRESTHandle->pRESTConfig->useSysLog == FALSE)) 45 | { 46 | if ((pRESTHandle->logFile = fopen(pRESTHandle->pRESTConfig->pszDebugLogFile, "a")) == NULL) 47 | { 48 | fprintf( stderr, "logFileName: \"%s\" open failed", pRESTHandle->pRESTConfig->pszDebugLogFile); 49 | dwError = REST_ENGINE_FAILURE; 50 | } 51 | } 52 | BAIL_ON_VMREST_ERROR(dwError); 53 | 54 | cleanup: 55 | 56 | return dwError; 57 | 58 | error: 59 | 60 | goto cleanup; 61 | 62 | } 63 | 64 | void 65 | VmRESTLogTerminate( 66 | PVMREST_HANDLE pRESTHandle 67 | ) 68 | { 69 | if (pRESTHandle && pRESTHandle->logFile != NULL) 70 | { 71 | fclose(pRESTHandle->logFile); 72 | pRESTHandle->logFile = NULL; 73 | } 74 | } 75 | 76 | void 77 | VmRESTLog( 78 | PVMREST_HANDLE pRESTHandle, 79 | VMREST_LOG_LEVEL level, 80 | const char* fmt, 81 | ...) 82 | { 83 | char extraLogMessage[EXTRA_LOG_MESSAGE_LEN] = {0}; 84 | char logMessage[MAX_LOG_MESSAGE_LEN]; 85 | struct tm* tm_info = NULL; 86 | struct timeval tv = {0}; 87 | 88 | va_list va; 89 | const char* logLevelTag = ""; 90 | int sysLogLevel = 0; 91 | 92 | if (!pRESTHandle || !pRESTHandle->pRESTConfig) 93 | { 94 | return; 95 | } 96 | 97 | if (level <= pRESTHandle->debugLogLevel) 98 | { 99 | va_start( va, fmt ); 100 | vsnprintf( logMessage, sizeof(logMessage), fmt, va ); 101 | logMessage[sizeof(logMessage)-1] = '\0'; 102 | va_end( va ); 103 | gettimeofday(&tv, NULL); 104 | 105 | tm_info = localtime(&tv.tv_sec); 106 | logLevelTag = logLevelToTag(level); 107 | strftime(extraLogMessage, sizeof(extraLogMessage) - 1, "%F %T", tm_info); 108 | 109 | if (pRESTHandle->pRESTConfig->useSysLog) 110 | { 111 | sysLogLevel = logLevelToSysLogLevel(level); 112 | syslog(sysLogLevel, "%s:%lu t@%lu %-3.7s: %s\n", extraLogMessage, (long unsigned)(tv.tv_usec), (unsigned long) pthread_self(),(logLevelTag? logLevelTag : "UNKNOWN"),logMessage); 113 | } 114 | else if (pRESTHandle->logFile != NULL) 115 | { 116 | fprintf(pRESTHandle->logFile, "%s:%lu t@%lu %-3.7s: %s\n", extraLogMessage, (long unsigned)(tv.tv_usec), (unsigned long) pthread_self(),(logLevelTag? logLevelTag : "UNKNOWN"),logMessage); 117 | fflush( pRESTHandle->logFile ); 118 | } 119 | } 120 | } 121 | 122 | static const char * 123 | logLevelToTag( 124 | int level 125 | ) 126 | { 127 | switch( level ) 128 | { 129 | case VMREST_LOG_LEVEL_ERROR: 130 | return "ERROR"; 131 | case VMREST_LOG_LEVEL_WARNING: 132 | return "WARNING"; 133 | case VMREST_LOG_LEVEL_INFO: 134 | return "INFO"; 135 | case VMREST_LOG_LEVEL_DEBUG: 136 | return "DEBUG"; 137 | default: 138 | return "DEBUG"; 139 | } 140 | } 141 | 142 | static int 143 | logLevelToSysLogLevel( 144 | int level) 145 | { 146 | switch( level ) 147 | { 148 | case VMREST_LOG_LEVEL_ERROR: 149 | return LOG_ERR; 150 | case VMREST_LOG_LEVEL_WARNING: 151 | return LOG_WARNING; 152 | case VMREST_LOG_LEVEL_DEBUG: 153 | return LOG_DEBUG; 154 | case VMREST_LOG_LEVEL_INFO: 155 | return LOG_INFO; 156 | default: 157 | return LOG_ERR; 158 | } 159 | } 160 | 161 | 162 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 4 | # Written by Gary V. Vaughan, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 6 ltsugar.m4 11 | 12 | # This is to help aclocal find these macros, as it can't see m4_define. 13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 14 | 15 | 16 | # lt_join(SEP, ARG1, [ARG2...]) 17 | # ----------------------------- 18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 19 | # associated separator. 20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 21 | # versions in m4sugar had bugs. 22 | m4_define([lt_join], 23 | [m4_if([$#], [1], [], 24 | [$#], [2], [[$2]], 25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 26 | m4_define([_lt_join], 27 | [m4_if([$#$2], [2], [], 28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 29 | 30 | 31 | # lt_car(LIST) 32 | # lt_cdr(LIST) 33 | # ------------ 34 | # Manipulate m4 lists. 35 | # These macros are necessary as long as will still need to support 36 | # Autoconf-2.59 which quotes differently. 37 | m4_define([lt_car], [[$1]]) 38 | m4_define([lt_cdr], 39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 40 | [$#], 1, [], 41 | [m4_dquote(m4_shift($@))])]) 42 | m4_define([lt_unquote], $1) 43 | 44 | 45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 46 | # ------------------------------------------ 47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. 48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 51 | # than defined and empty). 52 | # 53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 55 | m4_define([lt_append], 56 | [m4_define([$1], 57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 58 | 59 | 60 | 61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 62 | # ---------------------------------------------------------- 63 | # Produce a SEP delimited list of all paired combinations of elements of 64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 65 | # has the form PREFIXmINFIXSUFFIXn. 66 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 67 | m4_define([lt_combine], 68 | [m4_if(m4_eval([$# > 3]), [1], 69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 70 | [[m4_foreach([_Lt_prefix], [$2], 71 | [m4_foreach([_Lt_suffix], 72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 74 | 75 | 76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 77 | # ----------------------------------------------------------------------- 78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 80 | m4_define([lt_if_append_uniq], 81 | [m4_ifdef([$1], 82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 83 | [lt_append([$1], [$2], [$3])$4], 84 | [$5])], 85 | [lt_append([$1], [$2], [$3])$4])]) 86 | 87 | 88 | # lt_dict_add(DICT, KEY, VALUE) 89 | # ----------------------------- 90 | m4_define([lt_dict_add], 91 | [m4_define([$1($2)], [$3])]) 92 | 93 | 94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 95 | # -------------------------------------------- 96 | m4_define([lt_dict_add_subkey], 97 | [m4_define([$1($2:$3)], [$4])]) 98 | 99 | 100 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 101 | # ---------------------------------- 102 | m4_define([lt_dict_fetch], 103 | [m4_ifval([$3], 104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 106 | 107 | 108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 109 | # ----------------------------------------------------------------- 110 | m4_define([lt_if_dict_fetch], 111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 112 | [$5], 113 | [$6])]) 114 | 115 | 116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 117 | # -------------------------------------------------------------- 118 | m4_define([lt_dict_filter], 119 | [m4_if([$5], [], [], 120 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 123 | ]) 124 | -------------------------------------------------------------------------------- /td4.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "common\common.vcproj", "{D15EDE19-E534-46B2-8464-2857D5D57B85}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vmrestd", "server\vmrestd\vmrestd.vcproj", "{8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {D15EDE19-E534-46B2-8464-2857D5D57B85} = {D15EDE19-E534-46B2-8464-2857D5D57B85} 9 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE} = {6EC03452-CFAA-4B1C-86FE-6859CC7270EE} 10 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D} = {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D} 11 | {F4ADC8FA-CED1-4435-95ED-561A11A34556} = {F4ADC8FA-CED1-4435-95ED-561A11A34556} 12 | EndProjectSection 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "transport", "transport\transport.vcproj", "{F4ADC8FA-CED1-4435-95ED-561A11A34556}" 15 | ProjectSection(ProjectDependencies) = postProject 16 | {D15EDE19-E534-46B2-8464-2857D5D57B85} = {D15EDE19-E534-46B2-8464-2857D5D57B85} 17 | EndProjectSection 18 | EndProject 19 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "api", "api\api.vcproj", "{6EC03452-CFAA-4B1C-86FE-6859CC7270EE}" 20 | ProjectSection(ProjectDependencies) = postProject 21 | {D15EDE19-E534-46B2-8464-2857D5D57B85} = {D15EDE19-E534-46B2-8464-2857D5D57B85} 22 | {F4ADC8FA-CED1-4435-95ED-561A11A34556} = {F4ADC8FA-CED1-4435-95ED-561A11A34556} 23 | EndProjectSection 24 | EndProject 25 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "server\server.vcproj", "{062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}" 26 | ProjectSection(ProjectDependencies) = postProject 27 | {D15EDE19-E534-46B2-8464-2857D5D57B85} = {D15EDE19-E534-46B2-8464-2857D5D57B85} 28 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE} = {6EC03452-CFAA-4B1C-86FE-6859CC7270EE} 29 | {F4ADC8FA-CED1-4435-95ED-561A11A34556} = {F4ADC8FA-CED1-4435-95ED-561A11A34556} 30 | EndProjectSection 31 | EndProject 32 | Global 33 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 34 | Debug|Win32 = Debug|Win32 35 | Debug|x64 = Debug|x64 36 | Release|Win32 = Release|Win32 37 | Release|x64 = Release|x64 38 | EndGlobalSection 39 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 40 | {D15EDE19-E534-46B2-8464-2857D5D57B85}.Debug|Win32.ActiveCfg = Debug|Win32 41 | {D15EDE19-E534-46B2-8464-2857D5D57B85}.Debug|Win32.Build.0 = Debug|Win32 42 | {D15EDE19-E534-46B2-8464-2857D5D57B85}.Debug|x64.ActiveCfg = Debug|x64 43 | {D15EDE19-E534-46B2-8464-2857D5D57B85}.Debug|x64.Build.0 = Debug|x64 44 | {D15EDE19-E534-46B2-8464-2857D5D57B85}.Release|Win32.ActiveCfg = Release|Win32 45 | {D15EDE19-E534-46B2-8464-2857D5D57B85}.Release|Win32.Build.0 = Release|Win32 46 | {D15EDE19-E534-46B2-8464-2857D5D57B85}.Release|x64.ActiveCfg = Release|x64 47 | {D15EDE19-E534-46B2-8464-2857D5D57B85}.Release|x64.Build.0 = Release|x64 48 | {8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}.Debug|Win32.ActiveCfg = Debug|Win32 49 | {8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}.Debug|Win32.Build.0 = Debug|Win32 50 | {8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}.Debug|x64.ActiveCfg = Debug|x64 51 | {8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}.Debug|x64.Build.0 = Debug|x64 52 | {8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}.Release|Win32.ActiveCfg = Release|Win32 53 | {8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}.Release|Win32.Build.0 = Release|Win32 54 | {8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}.Release|x64.ActiveCfg = Release|x64 55 | {8A0CBFD8-1FC7-4F8E-9BC9-083A11F6EA99}.Release|x64.Build.0 = Release|x64 56 | {F4ADC8FA-CED1-4435-95ED-561A11A34556}.Debug|Win32.ActiveCfg = Debug|Win32 57 | {F4ADC8FA-CED1-4435-95ED-561A11A34556}.Debug|Win32.Build.0 = Debug|Win32 58 | {F4ADC8FA-CED1-4435-95ED-561A11A34556}.Debug|x64.ActiveCfg = Debug|x64 59 | {F4ADC8FA-CED1-4435-95ED-561A11A34556}.Debug|x64.Build.0 = Debug|x64 60 | {F4ADC8FA-CED1-4435-95ED-561A11A34556}.Release|Win32.ActiveCfg = Release|Win32 61 | {F4ADC8FA-CED1-4435-95ED-561A11A34556}.Release|Win32.Build.0 = Release|Win32 62 | {F4ADC8FA-CED1-4435-95ED-561A11A34556}.Release|x64.ActiveCfg = Release|x64 63 | {F4ADC8FA-CED1-4435-95ED-561A11A34556}.Release|x64.Build.0 = Release|x64 64 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE}.Debug|Win32.ActiveCfg = Debug|Win32 65 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE}.Debug|Win32.Build.0 = Debug|Win32 66 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE}.Debug|x64.ActiveCfg = Debug|x64 67 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE}.Debug|x64.Build.0 = Debug|x64 68 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE}.Release|Win32.ActiveCfg = Release|Win32 69 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE}.Release|Win32.Build.0 = Release|Win32 70 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE}.Release|x64.ActiveCfg = Release|x64 71 | {6EC03452-CFAA-4B1C-86FE-6859CC7270EE}.Release|x64.Build.0 = Release|x64 72 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}.Debug|Win32.ActiveCfg = Debug|Win32 73 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}.Debug|Win32.Build.0 = Debug|Win32 74 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}.Debug|x64.ActiveCfg = Debug|x64 75 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}.Debug|x64.Build.0 = Debug|x64 76 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}.Release|Win32.ActiveCfg = Release|Win32 77 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}.Release|Win32.Build.0 = Release|Win32 78 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}.Release|x64.ActiveCfg = Release|x64 79 | {062357CE-AEC4-425B-B4EB-EE6D6A1CC96D}.Release|x64.Build.0 = Release|x64 80 | EndGlobalSection 81 | GlobalSection(SolutionProperties) = preSolution 82 | HideSolutionNode = FALSE 83 | EndGlobalSection 84 | EndGlobal 85 | -------------------------------------------------------------------------------- /server/restengine/defines.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | typedef void* (PFN_VMREST_THR_ROUTINE)(void*); 15 | 16 | #define VMREST_WORKER_THREAD_COUNT 5 17 | 18 | /* HTTP protocol header defines */ 19 | 20 | #define MAX_METHOD_LEN 10 21 | #define MAX_URI_LEN 10240 22 | #define MAX_VERSION_LEN 9 23 | #define MAX_STATUS_LEN 4 24 | #define MAX_REA_PHRASE_LEN 32 25 | #define MAX_STOP_WAIT_SECONDS 600 26 | #define HTTP_VER_LEN 8 27 | #define HTTP_CHUNK_DATA_MIN_LEN 3 28 | #define HTTP_CHUNKED_DATA_LEN 8 29 | #define HTTP_MIN_CHUNK_DATA_LEN 3 30 | #define HTTP_CRLF_LEN 2 31 | 32 | #define MAX_KEY_VAL_PARAM_LEN 1024 33 | #define MAX_URL_PARAMS_ARR_SIZE 5 34 | #define MAX_EXTRA_CRLF_BUF_SIZE 10 35 | #define MAX_DATA_BUFFER_LEN 4096 36 | #define MAX_REQ_LIN_LEN 11264 37 | #define MAX_CLIENT_IP_ADDR_LEN 47 38 | #define MAX_CONTENT_LEN_STR_SIZE 10 39 | 40 | #define MAX_HTTP_HEADER_ATTR_LEN 64 41 | #define MAX_HTTP_HEADER_VAL_LEN 8192 42 | 43 | #define DEFAULT_WORKER_THR_CNT "5" 44 | #define DEFAULT_CLIENT_CNT "5" 45 | #define DEFAULT_DEBUG_FILE "/tmp/restServer.log" 46 | #define MAX_WORKER_THR_CNT 50000 47 | #define MAX_CLIENT_CNT 50000 48 | #define MAX_READ_RETRIES 50000 49 | #define MAX_PORT_NUMBER 65535 50 | #define ERROR_SYS_CALL_FAILED 5100 51 | 52 | #define HTTP_HEADER_STR_CONTENT_LENGTH "Content-Length" 53 | #define HTTP_HEADER_STR_TRANSFER_ENCODING "Transfer-Encoding" 54 | #define HTTP_HEADER_STR_EXPECT "Expect" 55 | #define HTTP_STATUSCODE_STR_100 "100" 56 | #define HTTP_REASON_STR_CONTINUE "Continue" 57 | #define HTTP_VALID_METHODS_COUNT 8 58 | 59 | typedef enum _HTTP_PAYLOAD_TYPE 60 | { 61 | HTTP_PAYLOAD_TYPE_INVALID = -1, 62 | HTTP_PAYLOAD_CONTENT_LENGTH = 1, 63 | HTTP_PAYLOAD_TRANSFER_ENCODING 64 | }HTTP_PAYLOAD_TYPE; 65 | 66 | typedef enum _VM_REST_INSTANCE_STATE 67 | { 68 | VMREST_INSTANCE_UNINITIALIZED = -1, 69 | VMREST_INSTANCE_INITIALIZED = 1, 70 | VMREST_INSTANCE_STARTED = 2, 71 | VMREST_INSTANCE_STOPPED = 3, 72 | VMREST_INSTANCE_SHUTDOWN = 4 73 | }VM_REST_INSTANCE_STATE; 74 | 75 | typedef enum _VM_REST_PROCESSING_STATE 76 | { 77 | PROCESS_INVALID = -1, 78 | PROCESS_REQUEST_LINE = 1, 79 | PROCESS_REQUEST_HEADERS, 80 | PROCESS_REQUEST_PAYLOAD, 81 | PROCESS_APPLICATION_CALLBACK 82 | }VM_REST_PROCESSING_STATE; 83 | 84 | typedef enum _HTTP_METHODS 85 | { 86 | HTTP_METHOD_GET = 1, 87 | HTTP_METHOD_HEAD, 88 | HTTP_METHOD_POST, 89 | HTTP_METHOD_PUT, 90 | HTTP_METHOD_DELETE, 91 | HTTP_METHOD_TRACE, 92 | HTTP_METHOD_CONNECT 93 | }HTTP_METHODS; 94 | 95 | /* 96 | * Please DO NOT change first and last header of any 97 | * category. 98 | * If new header has to be added, then it should be 99 | * added INBETWEEN first and last header of the same category 100 | * excluding first and last. 101 | * Various category are: 102 | * 103 | * HTTP_REQUEST_HEADER 104 | * HTTP_RESPONSE_HEADER 105 | * HTTP_GENERAL_HEADER 106 | * HTTP_ENTITY_HEADER 107 | */ 108 | 109 | typedef enum _HTTP_HEADERS 110 | { 111 | HTTP_REQUEST_HEADER_ACCEPT = 1, 112 | HTTP_REQUEST_HEADER_ACCEPT_CHARSET, 113 | HTTP_REQUEST_HEADER_ACCEPT_ENCODING, 114 | HTTP_REQUEST_HEADER_ACCEPT_LANGUAGE, 115 | HTTP_REQUEST_HEADER_ACCEPT_AUTHORIZATION, 116 | HTTP_REQUEST_HEADER_FROM, 117 | HTTP_REQUEST_HEADER_HOST, 118 | HTTP_REQUEST_HEADER_REFERER, 119 | HTTP_RESPONSE_HEADER_ACCEPT_RANGE, 120 | HTTP_RESPONSE_HEADER_LOCATION, 121 | HTTP_RESPONSE_HEADER_PROXY_AUTH, 122 | HTTP_RESPONSE_HEADER_SERVER, 123 | HTTP_GENERAL_HEADER_CACHE_CONTROL, 124 | HTTP_GENERAL_HEADER_CONNECTION, 125 | HTTP_GENERAL_HEADER_TRAILER, 126 | HTTP_GENERAL_HEADER_TRANSFER_ENCODING, 127 | HTTP_ENTITY_HEADER_ALLOW, 128 | HTTP_ENTITY_HEADER_CONTENT_ENCODING, 129 | HTTP_ENTITY_HEADER_CONTENT_LANGUAGE, 130 | HTTP_ENTITY_HEADER_CONTENT_LENGTH, 131 | HTTP_ENTITY_HEADER_CONTENT_LOCATION, 132 | HTTP_ENTITY_HEADER_CONTENT_MD5, 133 | HTTP_ENTITY_HEADER_CONTENT_RANGE, 134 | HTTP_ENTITY_HEADER_CONTENT_TYPE, 135 | HTTP_MISC_HEADER_ALL 136 | }HTTP_HEADERS; 137 | 138 | typedef enum _HTTP_STATUS_CODE 139 | { 140 | CONTINUE = 100, 141 | SWITCHING_PROTOCOL, 142 | OK = 200, 143 | CREATED, 144 | ACCEPTED, 145 | NON_AUTH_INFO, 146 | NO_CONTENT, 147 | RESET_CONTENT, 148 | PARTIAL_CONTENT, 149 | MULTIPLE_CHOICES = 300, 150 | MOVED_PERMANENTLY, 151 | FOUND, 152 | SEE_OTHER, 153 | NOT_MODIFIED, 154 | USE_PROXY, 155 | TEMPORARY_REDIRECT, 156 | BAD_REQUEST = 400, 157 | UNAUTHORIZED, 158 | PAYMENT_REQUIRED, 159 | FORBIDDEN, 160 | NOT_FOUND, 161 | METHOD_NOT_ALLOWED, 162 | NOT_ACCEPTABLE, 163 | PROXY_AUTH_REQUIRED, 164 | REQUEST_TIMEOUT, 165 | CONFLICT, 166 | GONE, 167 | LENGTH_REQUIRED, 168 | PRECONDITION_FAILED, 169 | REQUEST_ENTITY_TOO_LARGE, 170 | REQUEST_URI_TOO_LARGE, 171 | UNSUPPORTED_MEDIA_TYPE, 172 | REQUEST_RANGE_NOT_SATISFIABLE, 173 | EXPECTATION_FAILED, 174 | REQUEST_HEADER_FIELD_TOO_LARGE = 431, 175 | INTERNAL_SERVER_ERROR = 500, 176 | NOT_IMPLEMENTED, 177 | BAD_GATEWAY, 178 | SERVICE_UNAVAILABLE, 179 | GATEWAY_TIMEOUT, 180 | HTTP_VERSION_NOT_SUPPORTED 181 | }HTTP_STATUS_CODE; 182 | 183 | -------------------------------------------------------------------------------- /m4/lt~obsolete.m4: -------------------------------------------------------------------------------- 1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004. 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 5 lt~obsolete.m4 11 | 12 | # These exist entirely to fool aclocal when bootstrapping libtool. 13 | # 14 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) 15 | # which have later been changed to m4_define as they aren't part of the 16 | # exported API, or moved to Autoconf or Automake where they belong. 17 | # 18 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN 19 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us 20 | # using a macro with the same name in our local m4/libtool.m4 it'll 21 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define 22 | # and doesn't know about Autoconf macros at all.) 23 | # 24 | # So we provide this file, which has a silly filename so it's always 25 | # included after everything else. This provides aclocal with the 26 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything 27 | # because those macros already exist, or will be overwritten later. 28 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 29 | # 30 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. 31 | # Yes, that means every name once taken will need to remain here until 32 | # we give up compatibility with versions before 1.7, at which point 33 | # we need to keep only those names which we still refer to. 34 | 35 | # This is to help aclocal find these macros, as it can't see m4_define. 36 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) 37 | 38 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) 39 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) 40 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) 41 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) 42 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) 43 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) 44 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) 45 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) 46 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) 47 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) 48 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) 49 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) 50 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) 51 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) 52 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) 53 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) 54 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) 55 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) 56 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) 57 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) 58 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) 59 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) 60 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) 61 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) 62 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) 63 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) 64 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) 65 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) 66 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) 67 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) 68 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) 69 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) 70 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) 71 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) 72 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) 73 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) 74 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) 75 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) 76 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) 77 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) 78 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) 79 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) 80 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) 81 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) 82 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) 83 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) 84 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) 85 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) 86 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) 87 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) 88 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) 89 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) 90 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) 91 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) 92 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) 93 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) 94 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) 95 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) 96 | m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) 97 | m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) 98 | m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) 99 | -------------------------------------------------------------------------------- /test/scripts/restclient.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | //#define PORT 61001 14 | #define MAXDATASIZE 4096 15 | 16 | void 17 | VmSockPosixSetSocketNonBlocking( 18 | int server_fd 19 | ) 20 | { 21 | int cur_flags = 0; 22 | int set_flags = 0; 23 | 24 | cur_flags = fcntl(server_fd, F_GETFL, 0); 25 | cur_flags |= O_NONBLOCK; 26 | set_flags = fcntl(server_fd, F_SETFL, cur_flags); 27 | 28 | } 29 | 30 | void 31 | getExpectedResult( 32 | char* testID, 33 | char* input, 34 | char* expected 35 | ) 36 | { 37 | if (!testID || !input || !expected) 38 | { 39 | return; 40 | } 41 | if (strcmp(testID, "TEST 1") == 0) 42 | { 43 | strcpy(input, "GET /v1/pkg HTTP/1.1\r\nHost: SITE\r\nConnection: Keep-Alive\r\nTransfer-Encoding:chunked\r\n\r\n6\r\nThis i\r\n9\r\ns payload\r\n0\r\n"); 44 | strcpy(expected, "HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length:15\r\n\r\nThis is payload"); 45 | } 46 | else if (strcmp(testID, "TEST 2") == 0) 47 | { 48 | strcpy(input, "GET /v1/pkg?x=y HTTP/1.1\r\nHost: SITE\r\nConnection: Keep-Alive\r\nContent-Length: 15\r\n\r\nThis is payload"); 49 | strcpy(expected, "HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length:15\r\n\r\nThis is payload"); 50 | } 51 | else if (strcmp(testID, "TEST 3") == 0) 52 | { 53 | strcpy(input, "GET /v1/pkg?cn=tom_077&cn=Users&dc=vsphere&dc=local HTTP/1.1\r\nAuthorization: Basic wqBjbj1BZG1pbmlzdHJhdG9yLGNuPVVzZXJzLGRjPXZzcGhlcmUsZGM9bG9jYWw6\r\nUser-Agent: curl/7.19.7 (x86_64-suse-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8j zlib/1.2.7 libidn/1.10\r\nHost: localhost\r\nAccept: */*\r\nContent-Length: 82\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n[ { \"op\": \"replace\", \"path\": \"description\", \"value\": \"My fourth Description\" }]"); 54 | 55 | strcpy(expected, "HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length:82\r\n\r\n[ { \"op\": \"replace\", \"path\": \"description\", \"value\": \"My fourth Description\" }]"); 56 | } 57 | else if (strcmp(testID, "TEST 4") == 0) 58 | { 59 | strcpy(input, "DELETE /v1/pkg?cn=random5&cn=Users&dc=vsphere&dc=local HTTP/1.1\r\nAuthorization: Basic wqBjbj1BZG1pbmlzdHJhdG9yLGNuPVVzZXJzLGRjPXZzcGhlcmUsZGM9bG9jYWw6\r\nUser-Agent: curl/7.19.7 (x86_64-suse-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8j zlib/1.2.7 libidn/1.10\r\nHost: localhost\r\nAccept: */*\r\n\r\n"); 60 | strcpy(expected, "HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 61 | } 62 | else if (strcmp(testID, "TEST 5") == 0) 63 | { 64 | strcpy(input, "GET /v1/pkg?x=y HTTP/1.1\r\nHost: SITE\r\nConnection: Keep-Alive\r\nContent-Length: 20\r\n\r\nThis"); 65 | strcpy(expected, "HTTP/1.1 408 Request Timeout\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 66 | } 67 | else if (strcmp(testID, "TEST 6") == 0) 68 | { 69 | strcpy(input, "Non HTTP Junk Data which should be discarded totally\r\n\r\ndfdfafdsfadsf"); 70 | strcpy(expected, "HTTP/1.1 405 Method Not Allowed\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 71 | } 72 | else if (strcmp(testID, "TEST 7") == 0) 73 | { 74 | strcpy(input, "GET /v1/pkg?x=y HTTP/1.1\r\nHost: SITE\r\nConnection: Keep-Alive\r\n\r\nThis is payload"); 75 | strcpy(expected, "HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 76 | } 77 | else if (strcmp(testID, "TEST 8") == 0) 78 | { 79 | strcpy(input, "GET /v1/pkg?x=y HTTP/1.1\r\nHost: SITE\r\nContent-Length: 25\r\n\r\nThis is payload with CRLF\r\n"); 80 | strcpy(expected, "HTTP/1.1 200 OK\r\nConnection:close\r\nContent-Length:25\r\n\r\nThis is payload with CRLF"); 81 | } 82 | else if (strcmp(testID, "TEST 9") == 0) 83 | { 84 | strcpy(input, "GET /v1/pkg?x=y HTTP/1.1\r\nHost: SITE\r\nContent-Length: 28\r\nTransfer-Encoding:chunked\r\n\r\nThis is payload with4\r\ndfdf\r\n"); 85 | strcpy(expected, "HTTP/1.1 411 Length Required\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 86 | } 87 | else if (strcmp(testID, "TEST 10") == 0) 88 | { 89 | strcpy(input, " "); 90 | strcpy(expected, "HTTP/1.1 408 Request Timeout\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 91 | } 92 | else if (strcmp(testID, "TEST 11") == 0) 93 | { 94 | strcpy(input, "\r\n\r\b\r\n\r\n"); 95 | strcpy(expected, "HTTP/1.1 405 Method Not Allowed\r\nConnection:close\r\nContent-Length:0\r\n\r\n"); 96 | } 97 | 98 | 99 | } 100 | 101 | int main(int argc, char *argv[]) 102 | { 103 | int sockfd, numbytes; 104 | char buf[MAXDATASIZE]; 105 | char expected[MAXDATASIZE]; 106 | struct addrinfo hints, *servinfo, *p; 107 | int rv; 108 | char s[INET6_ADDRSTRLEN]; 109 | int c = 0; 110 | 111 | if (argc != 4) { 112 | printf("Wrong number of arguments supplied to test program\n"); 113 | exit(1); 114 | } 115 | 116 | memset(buf, '\0',MAXDATASIZE); 117 | memset(expected, '\0',MAXDATASIZE); 118 | 119 | memset(&hints, 0, sizeof(hints)); 120 | hints.ai_family = AF_UNSPEC; 121 | hints.ai_socktype = SOCK_STREAM; 122 | 123 | if ((rv = getaddrinfo(argv[1], argv[2], &hints, &servinfo)) != 0) { 124 | fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); 125 | return 1; 126 | } 127 | 128 | for(p = servinfo; p != NULL; p = p->ai_next) { 129 | if ((sockfd = socket(p->ai_family, p->ai_socktype, 130 | p->ai_protocol)) == -1) { 131 | perror("client: socket"); 132 | continue; 133 | } 134 | 135 | if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { 136 | close(sockfd); 137 | perror("client: connect"); 138 | continue; 139 | } 140 | 141 | break; 142 | } 143 | 144 | if (p == NULL) { 145 | printf("client: failed to connect\n"); 146 | return 2; 147 | } 148 | 149 | freeaddrinfo(servinfo); 150 | 151 | getExpectedResult(argv[3],buf ,expected); 152 | 153 | write(sockfd, buf, strlen(buf)); 154 | 155 | memset(buf, '\0',MAXDATASIZE); 156 | sleep(1); 157 | 158 | 159 | while(1) 160 | { 161 | int x = 0; 162 | x = read(sockfd, buf, MAXDATASIZE); 163 | if (x == 0){ 164 | break; 165 | } 166 | if (strcmp(buf, expected) == 0) 167 | { 168 | printf("\n%s PASSED\n", argv[3]); 169 | } 170 | else 171 | { 172 | printf("%s",buf); 173 | printf("\n%s FAILED\n", argv[3]); 174 | } 175 | 176 | sleep(1); 177 | memset(buf, '0',MAXDATASIZE); 178 | c++; 179 | } 180 | close(sockfd); 181 | return 0; 182 | } 183 | 184 | -------------------------------------------------------------------------------- /transport/posix/secureSocket.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | static 17 | void 18 | VmRESTSSLThreadLockCallback( 19 | int mode, 20 | int type, 21 | char* file, 22 | int line 23 | ); 24 | 25 | static 26 | unsigned long 27 | VmRESTSSLThreadId( 28 | void 29 | ); 30 | 31 | static 32 | void 33 | VmRESTSSLThreadLockCallback( 34 | int mode, 35 | int type, 36 | char* file, 37 | int line 38 | ) 39 | { 40 | (void)line; 41 | (void)file; 42 | if(mode & CRYPTO_LOCK) 43 | { 44 | pthread_mutex_lock(&(gSSLThreadLock[type])); 45 | } 46 | else 47 | { 48 | pthread_mutex_unlock(&(gSSLThreadLock[type])); 49 | } 50 | } 51 | 52 | static 53 | unsigned long 54 | VmRESTSSLThreadId( 55 | void 56 | ) 57 | { 58 | unsigned long ret = 0; 59 | 60 | ret = (unsigned long)pthread_self(); 61 | return ret; 62 | } 63 | 64 | uint32_t 65 | VmRESTSSLThreadLockInit( 66 | void 67 | ) 68 | { 69 | uint32_t dwError = REST_ENGINE_SUCCESS; 70 | int i = 0; 71 | 72 | gSSLThreadLock = (pthread_mutex_t *)OPENSSL_malloc( 73 | CRYPTO_num_locks() * sizeof(pthread_mutex_t) 74 | ); 75 | if (gSSLThreadLock == NULL) 76 | { 77 | dwError = REST_ERROR_NO_MEMORY; 78 | } 79 | BAIL_ON_VMREST_ERROR(dwError); 80 | 81 | for(i = 0; i < CRYPTO_num_locks(); i++) 82 | { 83 | pthread_mutex_init(&(gSSLThreadLock[i]), NULL); 84 | } 85 | 86 | CRYPTO_set_id_callback((unsigned long (*)())VmRESTSSLThreadId); 87 | CRYPTO_set_locking_callback((void (*)())VmRESTSSLThreadLockCallback); 88 | 89 | cleanup: 90 | return dwError; 91 | error: 92 | dwError = VMREST_TRANSPORT_SSL_ERROR; 93 | goto cleanup; 94 | } 95 | 96 | void 97 | VmRESTSSLThreadLockShutdown( 98 | void 99 | ) 100 | { 101 | int i = 0; 102 | 103 | CRYPTO_set_locking_callback(NULL); 104 | 105 | for( i = 0; i < CRYPTO_num_locks(); i++) 106 | { 107 | pthread_mutex_destroy(&(gSSLThreadLock[i])); 108 | } 109 | OPENSSL_free(gSSLThreadLock); 110 | } 111 | 112 | uint32_t 113 | VmRESTSecureSocket( 114 | PVMREST_HANDLE pRESTHandle, 115 | char* certificate, 116 | char* key 117 | ) 118 | { 119 | uint32_t dwError = REST_ENGINE_SUCCESS; 120 | int ret = 0; 121 | long options = 0; 122 | const SSL_METHOD* method = NULL; 123 | SSL_CTX* context = NULL; 124 | 125 | if (!key || !certificate || !pRESTHandle || !(pRESTHandle->pRESTConfig)) 126 | { 127 | VMREST_LOG_ERROR(pRESTHandle,"Invalid params"); 128 | dwError = VMREST_TRANSPORT_INVALID_PARAM; 129 | } 130 | BAIL_ON_VMREST_ERROR(dwError); 131 | 132 | OpenSSL_add_all_algorithms(); 133 | SSL_load_error_strings(); 134 | method = SSLv23_server_method(); 135 | context = SSL_CTX_new(method); 136 | if ( context == NULL ) 137 | { 138 | VMREST_LOG_ERROR(pRESTHandle,"SSL context is NULL"); 139 | dwError = VMREST_TRANSPORT_SSL_CONFIG_ERROR; 140 | } 141 | BAIL_ON_VMREST_ERROR(dwError); 142 | 143 | options = SSL_CTX_get_options(context); 144 | 145 | options = options | pRESTHandle->pRESTConfig->SSLCtxOptionsFlag; 146 | 147 | options = SSL_CTX_set_options(context, options); 148 | 149 | ret = SSL_CTX_set_cipher_list(context, pRESTHandle->pRESTConfig->pszSSLCipherList); 150 | if (ret == 0) 151 | { 152 | VMREST_LOG_ERROR(pRESTHandle,"%s", "SSL_CTX_set_cipher_list() : Cannot apply security approved cipher suites"); 153 | dwError = VMREST_TRANSPORT_SSL_INVALID_CIPHER_SUITES; 154 | } 155 | BAIL_ON_VMREST_ERROR(dwError); 156 | 157 | ret = SSL_CTX_use_certificate_file(context, certificate, SSL_FILETYPE_PEM); 158 | if (ret <= 0) 159 | { 160 | VMREST_LOG_ERROR(pRESTHandle,"Cannot Use SSL certificate"); 161 | dwError = VMREST_TRANSPORT_SSL_CERTIFICATE_ERROR; 162 | } 163 | BAIL_ON_VMREST_ERROR(dwError); 164 | 165 | ret = SSL_CTX_use_PrivateKey_file(context, key, SSL_FILETYPE_PEM); 166 | if (ret <= 0) 167 | { 168 | VMREST_LOG_ERROR(pRESTHandle,"Cannot use private key file"); 169 | dwError = VMREST_TRANSPORT_SSL_PRIVATEKEY_ERROR; 170 | BAIL_ON_VMREST_ERROR(dwError); 171 | } 172 | if (!SSL_CTX_check_private_key(context)) 173 | { 174 | VMREST_LOG_ERROR(pRESTHandle,"Error in Private Key"); 175 | dwError = VMREST_TRANSPORT_SSL_PRIVATEKEY_CHECK_ERROR; 176 | BAIL_ON_VMREST_ERROR(dwError); 177 | } 178 | 179 | pRESTHandle->pSSLInfo->sslContext = context; 180 | 181 | cleanup: 182 | return dwError; 183 | 184 | error: 185 | dwError = VMREST_TRANSPORT_SSL_ERROR; 186 | goto cleanup; 187 | } 188 | 189 | void 190 | VmRESTSecureSocketShutdown( 191 | PVMREST_HANDLE pRESTHandle 192 | ) 193 | { 194 | BOOLEAN bDestroyGlobalMutex = FALSE; 195 | 196 | if (!pRESTHandle || !pRESTHandle->pSSLInfo) 197 | { 198 | VMREST_LOG_ERROR(pRESTHandle,"%s","Invalid params"); 199 | return; 200 | } 201 | 202 | /**** Free SSL context only when it is allocated and managed by library ****/ 203 | if((pRESTHandle->pSSLInfo->isCertSet == SSL_INFO_FROM_CONFIG_FILE) || (pRESTHandle->pSSLInfo->isCertSet == SSL_INFO_FROM_BUFFER_API)) 204 | { 205 | pthread_mutex_lock(&gGlobalMutex); 206 | gSSLisedInstaceCount--; 207 | if (gSSLisedInstaceCount == 0) 208 | { 209 | if (pRESTHandle->pSSLInfo->sslContext) 210 | { 211 | VmRESTFreeMemory(pRESTHandle->pSSLInfo->sslContext); 212 | pRESTHandle->pSSLInfo->sslContext = NULL; 213 | } 214 | VmRESTSSLThreadLockShutdown(); 215 | gSSLThreadLock = NULL; 216 | bDestroyGlobalMutex = TRUE; 217 | gSSLisedInstaceCount = INVALID; 218 | } 219 | else 220 | { 221 | pRESTHandle->pSSLInfo->sslContext = NULL; 222 | } 223 | pthread_mutex_unlock(&gGlobalMutex); 224 | 225 | if (bDestroyGlobalMutex) 226 | { 227 | pthread_mutex_destroy(&gGlobalMutex); 228 | } 229 | } 230 | else 231 | { 232 | /**** Don't free context as it was passed by application ****/ 233 | pRESTHandle->pSSLInfo->sslContext = NULL; 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /transport/win/prototypes.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | /** 15 | * @brief initialize windows socket package 16 | * 17 | * @param[in] ppPackage pointer to socket package 18 | * 19 | * @return DWORD - 0 on success 20 | */ 21 | 22 | 23 | DWORD 24 | VmWinSockInitialize( 25 | PVM_SOCK_PACKAGE* ppPackage 26 | ); 27 | 28 | /** 29 | * @brief shutdown windows socket package 30 | * 31 | */ 32 | VOID 33 | VmWinSockShutdown( 34 | PVM_SOCK_PACKAGE pPackage 35 | ); 36 | 37 | /** 38 | * @brief Opens a server socket 39 | * 40 | * @param[in] usPort 16 bit local port number that the server listens on 41 | * @param[in,optional] iListenQueueSize 42 | * size of connection acceptance queue. 43 | * This value can be (-1) to use the default value. 44 | * 45 | * @param[in] dwFlags 32 bit flags defining socket creation preferences 46 | * @param[out] ppSocket Pointer to created socket 47 | * 48 | * @return 0 on success 49 | */ 50 | DWORD 51 | VmSockWinOpenServer( 52 | PVMREST_HANDLE pRESTHandle, 53 | USHORT usPort, 54 | int iListenQueueSize, 55 | VM_SOCK_CREATE_FLAGS dwFlags, 56 | PVM_SOCKET* ppSocket, 57 | char* sslCert, 58 | char* sslKey 59 | ); 60 | 61 | /** 62 | * @brief Creates a Event queue to be used for detecting events on sockets 63 | * 64 | * @param[in,optional] iEventQueueSize 65 | * specifies the event queue size 66 | * This value can be (-1) to use the default value 67 | * @param[out] ppQueue Pointer to accept created event queue 68 | * 69 | * @return 0 on success 70 | */ 71 | DWORD 72 | VmSockWinCreateEventQueue( 73 | PVMREST_HANDLE pRESTHandle, 74 | int iEventQueueSize, 75 | PVM_SOCK_EVENT_QUEUE* ppQueue 76 | ); 77 | 78 | /** 79 | * @brief Adds a socket to the event queue 80 | * 81 | * @param[in] pQueue Pointer to Event queue 82 | * @param[in] pSocket Pointer to Socket 83 | * 84 | * @return 0 on success 85 | */ 86 | DWORD 87 | VmSockWinEventQueueAdd( 88 | PVMREST_HANDLE pRESTHandle, 89 | PVM_SOCK_EVENT_QUEUE pQueue, 90 | PVM_SOCKET pSocket 91 | ); 92 | 93 | /** 94 | * @brief Waits for an event on the event queue 95 | * 96 | * @param[in] pQueue Pointer to event queue 97 | * @param[in,optional] iTimeoutMS 98 | * Timeout in milliseconds 99 | * Waits forever if (-1) is passed in. 100 | * @param[out] ppSocket Pointer to socket that has an event 101 | * @param[in,out] pEventType Event type detected on socket 102 | * 103 | * @return 0 on success 104 | */ 105 | DWORD 106 | VmSockWinWaitForEvent( 107 | PVMREST_HANDLE pRESTHandle, 108 | PVM_SOCK_EVENT_QUEUE pQueue, 109 | int iTimeoutMS, 110 | PVM_SOCKET* ppSocket, 111 | PVM_SOCK_EVENT_TYPE pEventType, 112 | PVM_SOCK_IO_BUFFER* ppIoEvent 113 | ); 114 | 115 | /** 116 | * @brief Closes and frees event queue 117 | * 118 | * @param[in] pQueue Pointer to event queue 119 | * 120 | * @return 0 on success 121 | */ 122 | 123 | VOID 124 | VmSockWinCloseEventQueue( 125 | PVMREST_HANDLE pRESTHandle, 126 | PVM_SOCK_EVENT_QUEUE pQueue 127 | ); 128 | 129 | /** 130 | * @brief Reads data from the socket 131 | * 132 | * @param[in] pSocket Pointer to socket 133 | * @param[in] pBuffer Buffer to read the data into 134 | * @param[in] dwBufSize Maximum size of the passed in buffer 135 | * @param[in,out] pdwBytesRead Number of bytes read in to the buffer 136 | * @param[in,out,optional] pClientAddress Client address to fill in optionally 137 | * @param[in,out,optional] pAddrLength Length of the client address 138 | * 139 | * @return 0 on success 140 | */ 141 | DWORD 142 | VmSockWinRead( 143 | PVMREST_HANDLE pRESTHandle, 144 | PVM_SOCKET pSocket, 145 | PVM_SOCK_IO_BUFFER pIoBuffer 146 | ); 147 | 148 | /** 149 | * @brief Writes data to the socket 150 | * 151 | * @param[in] pSocket Pointer to socket 152 | * @param[in] pBuffer Buffer from which bytes have to be written 153 | * @param[in] dwBufLen Number of bytes to write from the buffer 154 | * @param[in,out] pdwBytesRead Number of bytes written to the socket 155 | * @param[in,optional] pClientAddress Client address to send to 156 | * @param[in,optional] addrLength Length of the client address 157 | * 158 | * In case of UDP sockets, it is mandatory to provide the client address and 159 | * length. 160 | * 161 | * @return 0 on success 162 | */ 163 | DWORD 164 | VmSockWinWrite( 165 | PVMREST_HANDLE pRESTHandle, 166 | PVM_SOCKET pSocket, 167 | struct sockaddr* pClientAddress, 168 | socklen_t addrLength, 169 | PVM_SOCK_IO_BUFFER pIoBuffer 170 | ); 171 | 172 | /** 173 | * @brief Acquires a reference on the socket 174 | * 175 | * @return Pointer to acquired socket 176 | */ 177 | 178 | PVM_SOCKET 179 | VmSockWinAcquire( 180 | PVMREST_HANDLE pRESTHandle, 181 | PVM_SOCKET pSocket 182 | ); 183 | 184 | /** 185 | * @brief Releases current reference to socket 186 | * 187 | */ 188 | VOID 189 | VmSockWinRelease( 190 | PVMREST_HANDLE pRESTHandle, 191 | PVM_SOCKET pSocket 192 | ); 193 | 194 | /** 195 | * @brief Closes the socket 196 | * This call does not release the reference to the socket or free it. 197 | */ 198 | DWORD 199 | VmSockWinClose( 200 | PVMREST_HANDLE pRESTHandle, 201 | PVM_SOCKET pSocket 202 | ); 203 | 204 | DWORD 205 | VmSockWinAllocateIoBuffer( 206 | PVMREST_HANDLE pRESTHandle, 207 | VM_SOCK_EVENT_TYPE eventType, 208 | DWORD dwSize, 209 | PVM_SOCK_IO_BUFFER* ppIoContext 210 | ); 211 | 212 | /** 213 | * @brief Free socket IO Buffer 214 | * 215 | * @param[in] pIoBuffer 216 | * 217 | * @return VOID - 0 on success 218 | */ 219 | VOID 220 | VmSockWinFreeIoBuffer( 221 | PVMREST_HANDLE pRESTHandle, 222 | PVM_SOCK_IO_BUFFER pIoBuffer 223 | ); 224 | 225 | VOID 226 | VmSockWinGetStreamBuffer( 227 | PVMREST_HANDLE pRESTHandle, 228 | PVM_SOCKET pSocket, 229 | PVM_STREAM_BUFFER* ppStreamBuffer 230 | ); 231 | 232 | VOID 233 | VmSockWinSetStreamBuffer( 234 | PVMREST_HANDLE pRESTHandle, 235 | PVM_SOCKET pSocket, 236 | PVM_STREAM_BUFFER pStreamBuffer 237 | ); 238 | 239 | uint32_t 240 | VmRESTGetSockPackageWin( 241 | PVM_SOCK_PACKAGE* ppSockPackageWin 242 | ); 243 | 244 | VOID 245 | VmRESTFreeSockPackageWin( 246 | PVM_SOCK_PACKAGE pSockPackageWin 247 | ); 248 | -------------------------------------------------------------------------------- /include/vmrestdefines.h: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #ifndef __VREST_DEFINE_H__ 15 | #define __VREST_DEFINE_H__ 16 | 17 | /***** global macros **************/ 18 | #define PASS 1 19 | #define FAIL 0 20 | 21 | #ifndef WIN32 22 | #define ERROR_NOT_SUPPORTED 100 23 | #endif 24 | 25 | #define VMREST_HTTP_INVALID_PARAMS 61001 26 | #define VMREST_HTTP_VALIDATION_FAILED 61002 27 | 28 | #define VMREST_APPLICATION_INVALID_PARAMS 61011 29 | #define VMREST_APPLICATION_VALIDATION_FAILED 61012 30 | #define VMREST_APPLICATION_NO_CB_REGISTERED 61013 31 | #define VMREST_APPLICATION_NO_METHOD_GET_CB 61014 32 | #define VMREST_APPLICATION_NO_METHOD_HEAD_CB 61015 33 | #define VMREST_APPLICATION_NO_METHOD_POST_CB 61016 34 | #define VMREST_APPLICATION_NO_METHOD_PUT_CB 61017 35 | #define VMREST_APPLICATION_NO_METHOD_DELETE_CB 61018 36 | #define VMREST_APPLICATION_NO_METHOD_TRACE_CB 61019 37 | #define VMREST_APPLICATION_NO_METHOD_CONNECT_CB 61020 38 | 39 | 40 | #define VMREST_TRANSPORT_INVALID_PARAM 61100 41 | #define VMREST_TRANSPORT_SSL_ERROR 61101 42 | #define VMREST_TRANSPORT_SSL_CONFIG_ERROR 61102 43 | #define VMREST_TRANSPORT_SSL_CERTIFICATE_ERROR 61103 44 | #define VMREST_TRANSPORT_SSL_PRIVATEKEY_ERROR 61104 45 | #define VMREST_TRANSPORT_SSL_PRIVATEKEY_CHECK_ERROR 61105 46 | #define VMREST_TRANSPORT_SSL_ACCEPT_FAILED 61106 47 | #define VMREST_TRANSPORT_SSL_INVALID_CIPHER_SUITES 61007 48 | 49 | #define VMREST_TRANSPORT_QUEUE_INIT_FAILED 61111 50 | #define VMREST_TRANSPORT_SERVER_THREAD_CREATE_FAILED 61112 51 | #define VMREST_TRANSPORT_SOCKET_GET_ADDRINFO_ERROR 61113 52 | #define VMREST_TRANSPORT_SOCKET_SETSOCKOPT_ERROR 61114 53 | #define VMREST_TRANSPORT_SOCKET_BIND_ERROR 61115 54 | #define VMREST_TRANSPORT_SOCKET_LISTEN_ERROR 61116 55 | #define VMREST_TRANSPORT_EPOLL_CREATE_ERROR 61117 56 | #define VMREST_TRANSPORT_EPOLL_CTL_ERROR 61118 57 | #define VMREST_TRANSPORT_SOCKET_NON_BLOCK_ERROR 61119 58 | #define VMREST_TRANSPORT_QUEUE_EMPTY 61120 59 | #define VMREST_TRANSPORT_ACCEPT_CONN_FAILED 61121 60 | #define VMREST_TRANSPORT_INSERT_CLIENT_INGLOBAL_ERROR 61122 61 | #define VMREST_TRANSPORT_MAX_CONN_REACHED_ERROR 61123 62 | #define VMREST_TRANSPORT_MUTEX_INIT_FAILED 61124 63 | #define VMREST_TRANSPORT_COND_INIT_FAILED 61125 64 | #define VMREST_TRANSPORT_SERVER_THREAD_START_FAILED 61126 65 | 66 | 67 | #define VMREST_TRANSPORT_DEFERRED_TIMEOUT_PROCESS 61127 68 | #define VMREST_TRANSPORT_SOCK_READ_FAILED 61128 69 | #define VMREST_TRANSPORT_SOCK_WRITE_FAILED 61129 70 | #define VMREST_TRANSPORT_SOCK_GET_HANDLE_FAILED 61130 71 | #define VMREST_TRANSPORT_SOCK_SET_HANDLE_FAILED 61131 72 | #define VMREST_TRANSPORT_SOCK_DATA_OVER_LIMIT 61132 73 | #define VMREST_TRANSPORT_REMOTE_CONN_CLOSED 61133 74 | 75 | #define ERROR_TRANSPORT_INVALID_PARAMS 61040 76 | #define ERROR_TRANSPORT_VALIDATION_FAILED 61041 77 | 78 | #define SSL_INFO_NOT_SET 0 79 | #define SSL_INFO_NO_SSL_PLAIN 1 80 | #define SSL_INFO_FROM_CONFIG_FILE 2 81 | #define SSL_INFO_FROM_BUFFER_API 3 82 | #define SSL_INFO_USE_APP_CONTEXT 4 83 | 84 | #define VMREST_MAX_SSL_CIPHER_LIST_LEN 256 85 | #define VMREST_DEFAULT_SSL_CIPHER_LIST "!aNULL:kECDH+AESGCM:ECDH+AESGCM:RSA+AESGCM:kECDH+AES:ECDH+AES:RSA+AES" 86 | #define VMREST_DEFAULT_SSL_CTX_OPTION_FLAG SSL_OP_NO_TLSv1|SSL_OP_NO_SSLv3|SSL_OP_NO_SSLv2 87 | 88 | #define VMREST_DEFAULT_WORKER_THR_COUNT 5 89 | #define VMREST_DEFAULT_CLIENT_COUNT 100 90 | #define VMREST_DEFAULT_CONN_TIMEOUT_SEC 60 91 | #define VMREST_DEFAULT_CONN_PAYLOAD_LIMIT_MB 25 92 | 93 | #define VMREST_MAX_WORKER_THR_COUNT 100 94 | #define VMREST_MAX_CLIENT_COUNT 10000 95 | #define VMREST_MAX_CONN_TIMEOUT_SEC 600 96 | #define VMREST_MAX_CONN_PAYLOAD_LIMIT_MB 50 97 | 98 | 99 | #define TRUE 1 100 | #define FALSE 0 101 | 102 | #define INVALID -1 103 | 104 | 105 | #ifndef WIN32 106 | #define ERROR_SUCCESS 0 107 | #define ERROR_INVALID_PARAMETER 101 108 | #define ERROR_CONNECTION_UNAVAIL 102 109 | #define ERROR_INVALID_STATE 103 110 | #define ERROR_INTERNAL_ERROR 104 111 | 112 | #endif 113 | 114 | #ifndef _WIN32 115 | #define VMREST_SF_INIT( fieldName, fieldValue ) fieldName = fieldValue 116 | #else 117 | #define VMREST_SF_INIT( fieldName, fieldValue ) fieldValue 118 | #endif 119 | 120 | #ifdef __cplusplus 121 | extern "C" { 122 | #endif 123 | 124 | #define VMREST_SAFE_FREE_STRINGA(PTR) \ 125 | do { \ 126 | if ((PTR)) { \ 127 | VmRESTFreeStringA(PTR); \ 128 | (PTR) = NULL; \ 129 | } \ 130 | } while(0) 131 | 132 | #define VMREST_SECURE_FREE_STRINGA(PTR) \ 133 | do { \ 134 | if ((PTR)) { \ 135 | if (*(PTR)) { \ 136 | memset(PTR, 0, strlen(PTR)); \ 137 | } \ 138 | VmRESTFreeStringA(PTR); \ 139 | (PTR) = NULL; \ 140 | } \ 141 | } while(0) 142 | 143 | #define VMREST_SAFE_FREE_MEMORY(PTR) \ 144 | do { \ 145 | if ((PTR)) { \ 146 | VmRESTFreeMemory(PTR); \ 147 | (PTR) = NULL; \ 148 | } \ 149 | } while(0) 150 | 151 | #define BAIL_ON_VMREST_ERROR(dwError) \ 152 | do { \ 153 | if (dwError) { \ 154 | goto error; \ 155 | } \ 156 | } while(0) 157 | 158 | #define BAIL_ON_VMREST_INVALID_POINTER(p, errCode) \ 159 | if (p == NULL) { \ 160 | errCode = ERROR_INVALID_PARAMETER; \ 161 | BAIL_ON_VMREST_ERROR(errCode); \ 162 | } 163 | 164 | #ifndef IsNullOrEmptyString 165 | #define IsNullOrEmptyString(str) (!(str) || !(*str)) 166 | #endif 167 | 168 | #ifndef VMREST_SAFE_STRING 169 | #define VMREST_SAFE_STRING(str) ((str) ? (str) : "") 170 | #endif 171 | 172 | #ifdef __cplusplus 173 | } 174 | #endif 175 | 176 | #endif /* __VREST_DEFINE_H__ */ 177 | -------------------------------------------------------------------------------- /server/vmrestd/ssl-context.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | pthread_mutex_t* gTESTSSLThreadLock = NULL; 17 | pthread_mutex_t gTESTGlobalMutex = PTHREAD_MUTEX_INITIALIZER; 18 | int gTESTSSLisedInstaceCount = -1; 19 | 20 | 21 | static 22 | void 23 | VmTESTSSLThreadLockCallback( 24 | int mode, 25 | int type, 26 | char* file, 27 | int line 28 | ); 29 | 30 | static 31 | unsigned long 32 | VmTESTSSLThreadId( 33 | void 34 | ); 35 | 36 | static 37 | uint32_t 38 | VmTESTSSLThreadLockInit( 39 | void 40 | ); 41 | 42 | static 43 | void 44 | VmTESTSSLThreadLockShutdown( 45 | void 46 | ); 47 | 48 | static 49 | uint32_t 50 | VmTESTSecureSocket( 51 | char* certificate, 52 | char* key, 53 | SSL_CTX** ppSSLCtx 54 | ); 55 | 56 | 57 | static 58 | void 59 | VmTESTSSLThreadLockCallback( 60 | int mode, 61 | int type, 62 | char* file, 63 | int line 64 | ) 65 | { 66 | (void)line; 67 | (void)file; 68 | if(mode & CRYPTO_LOCK) 69 | { 70 | pthread_mutex_lock(&(gTESTSSLThreadLock[type])); 71 | } 72 | else 73 | { 74 | pthread_mutex_unlock(&(gTESTSSLThreadLock[type])); 75 | } 76 | } 77 | 78 | static 79 | unsigned long 80 | VmTESTSSLThreadId( 81 | void 82 | ) 83 | { 84 | unsigned long ret = 0; 85 | 86 | ret = (unsigned long)pthread_self(); 87 | return ret; 88 | } 89 | 90 | static 91 | uint32_t 92 | VmTESTSSLThreadLockInit( 93 | void 94 | ) 95 | { 96 | uint32_t dwError = REST_ENGINE_SUCCESS; 97 | int i = 0; 98 | 99 | gTESTSSLThreadLock = (pthread_mutex_t *)OPENSSL_malloc( 100 | CRYPTO_num_locks() * sizeof(pthread_mutex_t) 101 | ); 102 | if (gTESTSSLThreadLock == NULL) 103 | { 104 | dwError = 102; 105 | } 106 | BAIL_ON_VMREST_ERROR(dwError); 107 | 108 | for(i = 0; i < CRYPTO_num_locks(); i++) 109 | { 110 | pthread_mutex_init(&(gTESTSSLThreadLock[i]), NULL); 111 | } 112 | 113 | CRYPTO_set_id_callback((unsigned long (*)())VmTESTSSLThreadId); 114 | CRYPTO_set_locking_callback((void (*)())VmTESTSSLThreadLockCallback); 115 | 116 | cleanup: 117 | return dwError; 118 | error: 119 | dwError = VMREST_TRANSPORT_SSL_ERROR; 120 | goto cleanup; 121 | } 122 | 123 | static 124 | void 125 | VmTESTSSLThreadLockShutdown( 126 | void 127 | ) 128 | { 129 | int i = 0; 130 | 131 | CRYPTO_set_locking_callback(NULL); 132 | 133 | for( i = 0; i < CRYPTO_num_locks(); i++) 134 | { 135 | pthread_mutex_destroy(&(gTESTSSLThreadLock[i])); 136 | } 137 | OPENSSL_free(gTESTSSLThreadLock); 138 | } 139 | 140 | static 141 | uint32_t 142 | VmTESTSecureSocket( 143 | char* certificate, 144 | char* key, 145 | SSL_CTX** ppSSLCtx 146 | ) 147 | { 148 | uint32_t dwError = REST_ENGINE_SUCCESS; 149 | int ret = 0; 150 | long options = 0; 151 | const SSL_METHOD* method = NULL; 152 | SSL_CTX* context = NULL; 153 | 154 | if (key == NULL || certificate == NULL) 155 | { 156 | dwError = VMREST_TRANSPORT_INVALID_PARAM; 157 | } 158 | BAIL_ON_VMREST_ERROR(dwError); 159 | 160 | OpenSSL_add_all_algorithms(); 161 | SSL_load_error_strings(); 162 | method = SSLv23_server_method(); 163 | context = SSL_CTX_new(method); 164 | if ( context == NULL ) 165 | { 166 | dwError = VMREST_TRANSPORT_SSL_CONFIG_ERROR; 167 | } 168 | BAIL_ON_VMREST_ERROR(dwError); 169 | 170 | options = SSL_CTX_get_options(context); 171 | 172 | options = options | SSL_OP_NO_TLSv1|SSL_OP_NO_SSLv3|SSL_OP_NO_SSLv2; 173 | 174 | options = SSL_CTX_set_options(context, options); 175 | 176 | ret = SSL_CTX_set_cipher_list(context, "!aNULL:kECDH+AESGCM:ECDH+AESGCM:RSA+AESGCM:kECDH+AES:ECDH+AES:RSA+AES"); 177 | if (ret == 0) 178 | { 179 | dwError = VMREST_TRANSPORT_SSL_INVALID_CIPHER_SUITES; 180 | } 181 | BAIL_ON_VMREST_ERROR(dwError); 182 | 183 | ret = SSL_CTX_use_certificate_file(context, certificate, SSL_FILETYPE_PEM); 184 | if (ret <= 0) 185 | { 186 | dwError = VMREST_TRANSPORT_SSL_CERTIFICATE_ERROR; 187 | } 188 | BAIL_ON_VMREST_ERROR(dwError); 189 | 190 | ret = SSL_CTX_use_PrivateKey_file(context, key, SSL_FILETYPE_PEM); 191 | if (ret <= 0) 192 | { 193 | dwError = VMREST_TRANSPORT_SSL_PRIVATEKEY_ERROR; 194 | BAIL_ON_VMREST_ERROR(dwError); 195 | } 196 | if (!SSL_CTX_check_private_key(context)) 197 | { 198 | dwError = VMREST_TRANSPORT_SSL_PRIVATEKEY_CHECK_ERROR; 199 | BAIL_ON_VMREST_ERROR(dwError); 200 | } 201 | 202 | *ppSSLCtx = context; 203 | 204 | cleanup: 205 | return dwError; 206 | 207 | error: 208 | dwError = VMREST_TRANSPORT_SSL_ERROR; 209 | goto cleanup; 210 | } 211 | 212 | 213 | uint32_t 214 | VmTESTInitSSL( 215 | char* sslKey, 216 | char* sslCert, 217 | SSL_CTX** ppSSLCtx 218 | ) 219 | { 220 | uint32_t dwError = 0; 221 | 222 | SSL_library_init(); 223 | dwError = VmTESTSecureSocket( 224 | sslCert, 225 | sslKey, 226 | ppSSLCtx 227 | ); 228 | 229 | BAIL_ON_VMREST_ERROR(dwError); 230 | 231 | pthread_mutex_lock(&gTESTGlobalMutex); 232 | if (gTESTSSLisedInstaceCount == 0) 233 | { 234 | dwError = VmTESTSSLThreadLockInit(); 235 | gTESTSSLisedInstaceCount++; 236 | } 237 | pthread_mutex_unlock(&gTESTGlobalMutex); 238 | BAIL_ON_VMREST_ERROR(dwError); 239 | 240 | cleanup: 241 | return dwError; 242 | 243 | error: 244 | dwError = VMREST_TRANSPORT_SSL_ERROR; 245 | goto cleanup; 246 | 247 | } 248 | 249 | void 250 | VmRESTShutdownSSL( 251 | SSL_CTX* sslCtx 252 | ) 253 | { 254 | uint32_t destroyGlobalMutex = 0; 255 | 256 | if (sslCtx != NULL) 257 | { 258 | free(sslCtx); 259 | } 260 | 261 | pthread_mutex_lock(&gTESTGlobalMutex); 262 | gTESTSSLisedInstaceCount--; 263 | if (gTESTSSLisedInstaceCount == 0) 264 | { 265 | VmTESTSSLThreadLockShutdown(); 266 | gTESTSSLThreadLock = NULL; 267 | destroyGlobalMutex = 1; 268 | gTESTSSLisedInstaceCount = -1; 269 | } 270 | pthread_mutex_unlock(&gTESTGlobalMutex); 271 | if (destroyGlobalMutex) 272 | { 273 | pthread_mutex_destroy(&gTESTGlobalMutex); 274 | } 275 | } 276 | 277 | 278 | -------------------------------------------------------------------------------- /api/api.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 29 | 32 | 35 | 38 | 41 | 44 | 55 | 58 | 61 | 64 | 67 | 70 | 73 | 76 | 79 | 82 | 83 | 90 | 93 | 96 | 99 | 102 | 106 | 118 | 121 | 124 | 127 | 130 | 133 | 136 | 139 | 142 | 145 | 146 | 154 | 157 | 160 | 163 | 166 | 169 | 180 | 183 | 186 | 189 | 192 | 195 | 198 | 201 | 204 | 207 | 208 | 216 | 219 | 222 | 225 | 228 | 232 | 244 | 247 | 250 | 253 | 256 | 259 | 262 | 265 | 268 | 271 | 272 | 273 | 274 | 275 | 276 | 281 | 284 | 285 | 288 | 289 | 290 | 295 | 298 | 299 | 302 | 303 | 306 | 307 | 308 | 313 | 314 | 315 | 316 | 317 | 318 | -------------------------------------------------------------------------------- /transport/api/api.c: -------------------------------------------------------------------------------- 1 | /* C-REST-Engine 2 | * 3 | * Copyright (c) 2017 VMware, Inc. All Rights Reserved. 4 | * 5 | * This product is licensed to you under the Apache 2.0 license (the "License"). 6 | * You may not use this product except in compliance with the Apache 2.0 License. 7 | * 8 | * This product may include a number of subcomponents with separate copyright 9 | * notices and license terms. Your use of these subcomponents is subject to the 10 | * terms and conditions of the subcomponent's license, as noted in the LICENSE file. 11 | * 12 | */ 13 | 14 | #include "includes.h" 15 | 16 | #ifdef WIN32 17 | #pragma comment(lib, "Ws2_32.lib") 18 | #define inet_pton(x, y, z) InetPtonA(x, y, z) 19 | #endif 20 | 21 | DWORD 22 | VmwSockStartServer( 23 | PVMREST_HANDLE pRESTHandle, 24 | VM_SOCK_CREATE_FLAGS dwFlags, 25 | PVM_SOCKET* ppSocket 26 | ) 27 | { 28 | DWORD dwError = REST_ENGINE_SUCCESS; 29 | 30 | if (!ppSocket || !pRESTHandle) 31 | { 32 | dwError = ERROR_INVALID_PARAMETER; 33 | BAIL_ON_VMSOCK_ERROR(dwError); 34 | } 35 | 36 | dwError = pRESTHandle->pPackage->pfnStartServerSocket( 37 | pRESTHandle, 38 | dwFlags, 39 | ppSocket); 40 | error: 41 | 42 | return dwError; 43 | } 44 | 45 | DWORD 46 | VmwSockCreateEventQueue( 47 | PVMREST_HANDLE pRESTHandle, 48 | PVM_SOCK_EVENT_QUEUE* ppQueue 49 | ) 50 | { 51 | DWORD dwError = REST_ENGINE_SUCCESS; 52 | 53 | if (!ppQueue || !pRESTHandle) 54 | { 55 | dwError = ERROR_INVALID_PARAMETER; 56 | BAIL_ON_VMSOCK_ERROR(dwError); 57 | } 58 | 59 | dwError = pRESTHandle->pPackage->pfnCreateEventQueue(pRESTHandle, ppQueue); 60 | 61 | error: 62 | 63 | return dwError; 64 | } 65 | 66 | DWORD 67 | VmwSockAddEventToQueueInLock( 68 | PVMREST_HANDLE pRESTHandle, 69 | PVM_SOCK_EVENT_QUEUE pQueue, 70 | PVM_SOCKET pSocket 71 | ) 72 | { 73 | DWORD dwError = REST_ENGINE_SUCCESS; 74 | 75 | if (!pQueue || !pSocket || !pRESTHandle) 76 | { 77 | dwError = ERROR_INVALID_PARAMETER; 78 | BAIL_ON_VMSOCK_ERROR(dwError); 79 | } 80 | 81 | dwError = pRESTHandle->pPackage->pfnAddEventToQueue(pRESTHandle,pQueue, pSocket); 82 | 83 | error: 84 | 85 | return dwError; 86 | } 87 | 88 | DWORD 89 | VmwSockDeleteEventFromQueue( 90 | PVMREST_HANDLE pRESTHandle, 91 | PVM_SOCK_EVENT_QUEUE pQueue, 92 | PVM_SOCKET pSocket 93 | ) 94 | { 95 | DWORD dwError = REST_ENGINE_SUCCESS; 96 | 97 | if (!pQueue || !pSocket || !pRESTHandle) 98 | { 99 | dwError = ERROR_INVALID_PARAMETER; 100 | BAIL_ON_VMSOCK_ERROR(dwError); 101 | } 102 | 103 | dwError = pRESTHandle->pPackage->pfnDeleteEventFromQueue(pRESTHandle,pQueue, pSocket); 104 | 105 | error: 106 | 107 | return dwError; 108 | } 109 | 110 | 111 | DWORD 112 | VmwSockWaitForEvent( 113 | PVMREST_HANDLE pRESTHandle, 114 | PVM_SOCK_EVENT_QUEUE pQueue, 115 | int iTimeoutMS, 116 | PVM_SOCKET* ppSocket, 117 | PVM_SOCK_EVENT_TYPE pEventType 118 | ) 119 | { 120 | DWORD dwError = REST_ENGINE_SUCCESS; 121 | 122 | if (!pQueue || !ppSocket || !pEventType || !pRESTHandle) 123 | { 124 | dwError = ERROR_INVALID_PARAMETER; 125 | BAIL_ON_VMSOCK_ERROR(dwError); 126 | } 127 | 128 | dwError = pRESTHandle->pPackage->pfnWaitForEvent( 129 | pRESTHandle, 130 | pQueue, 131 | iTimeoutMS, 132 | ppSocket, 133 | pEventType 134 | ); 135 | 136 | error: 137 | 138 | return dwError; 139 | } 140 | 141 | DWORD 142 | VmwSockCloseEventQueue( 143 | PVMREST_HANDLE pRESTHandle, 144 | PVM_SOCK_EVENT_QUEUE pQueue, 145 | uint32_t waitSecond 146 | ) 147 | { 148 | DWORD dwError = REST_ENGINE_SUCCESS; 149 | 150 | if (!pRESTHandle) 151 | { 152 | dwError = REST_ENGINE_FAILURE; 153 | } 154 | BAIL_ON_VMREST_ERROR(dwError); 155 | 156 | if (pQueue) 157 | { 158 | dwError = pRESTHandle->pPackage->pfnCloseEventQueue(pRESTHandle,pQueue,waitSecond); 159 | } 160 | BAIL_ON_VMREST_ERROR(dwError); 161 | 162 | error: 163 | 164 | return dwError; 165 | 166 | } 167 | 168 | DWORD 169 | VmwSockRead( 170 | PVMREST_HANDLE pRESTHandle, 171 | PVM_SOCKET pSocket, 172 | char** ppszBuffer, 173 | uint32_t* nBufLen 174 | ) 175 | { 176 | DWORD dwError = REST_ENGINE_SUCCESS; 177 | 178 | if (!pSocket || !ppszBuffer || !pRESTHandle) 179 | { 180 | dwError = ERROR_INVALID_PARAMETER; 181 | BAIL_ON_VMSOCK_ERROR(dwError); 182 | } 183 | 184 | dwError = pRESTHandle->pPackage->pfnRead( 185 | pRESTHandle, 186 | pSocket, 187 | ppszBuffer, 188 | nBufLen); 189 | 190 | error: 191 | 192 | return dwError; 193 | } 194 | 195 | DWORD 196 | VmwSockWrite( 197 | PVMREST_HANDLE pRESTHandle, 198 | PVM_SOCKET pSocket, 199 | char* pszBuffer, 200 | uint32_t nBufLen 201 | ) 202 | { 203 | DWORD dwError = REST_ENGINE_SUCCESS; 204 | 205 | if (!pSocket || !pszBuffer || !pRESTHandle) 206 | { 207 | dwError = ERROR_INVALID_PARAMETER; 208 | BAIL_ON_VMSOCK_ERROR(dwError); 209 | } 210 | 211 | dwError = pRESTHandle->pPackage->pfnWrite( 212 | pRESTHandle, 213 | pSocket, 214 | pszBuffer, 215 | nBufLen); 216 | BAIL_ON_VMSOCK_ERROR(dwError); 217 | 218 | error: 219 | 220 | return dwError; 221 | } 222 | 223 | VOID 224 | VmwSockRelease( 225 | PVMREST_HANDLE pRESTHandle, 226 | PVM_SOCKET pSocket 227 | ) 228 | { 229 | if (pSocket) 230 | { 231 | pRESTHandle->pPackage->pfnReleaseSocket(pRESTHandle, pSocket); 232 | } 233 | } 234 | 235 | DWORD 236 | VmwSockClose( 237 | PVMREST_HANDLE pRESTHandle, 238 | PVM_SOCKET pSocket 239 | ) 240 | { 241 | DWORD dwError = 0; 242 | 243 | dwError = pRESTHandle->pPackage->pfnCloseSocket(pRESTHandle, pSocket); 244 | BAIL_ON_VMSOCK_ERROR(dwError); 245 | 246 | error: 247 | 248 | return dwError; 249 | } 250 | 251 | DWORD 252 | VmwSockGetRequestHandle( 253 | PVMREST_HANDLE pRESTHandle, 254 | PVM_SOCKET pSocket, 255 | PREST_REQUEST* ppRequest 256 | ) 257 | { 258 | DWORD dwError = REST_ENGINE_SUCCESS; 259 | 260 | dwError = pRESTHandle->pPackage->pfnGetRequestHandle(pRESTHandle,pSocket, ppRequest); 261 | 262 | return dwError; 263 | } 264 | 265 | DWORD 266 | VmwSockSetRequestHandle( 267 | PVMREST_HANDLE pRESTHandle, 268 | PVM_SOCKET pSocket, 269 | PREST_REQUEST pRequest, 270 | uint32_t nProcessed, 271 | BOOLEAN bPersistentConn 272 | ) 273 | { 274 | DWORD dwError = REST_ENGINE_SUCCESS; 275 | 276 | dwError = pRESTHandle->pPackage->pfnSetRequestHandle(pRESTHandle,pSocket,pRequest, nProcessed, bPersistentConn); 277 | 278 | return dwError; 279 | } 280 | 281 | DWORD 282 | VmwSockGetPeerInfo( 283 | PVMREST_HANDLE pRESTHandle, 284 | PVM_SOCKET pSocket, 285 | char* pIpAddress, 286 | uint32_t nLen, 287 | int* pPortNo 288 | ) 289 | { 290 | DWORD dwError = REST_ENGINE_SUCCESS; 291 | 292 | dwError = pRESTHandle->pPackage->pfnGetPeerInfo(pRESTHandle, pSocket, pIpAddress, nLen, pPortNo); 293 | 294 | return dwError; 295 | } 296 | 297 | 298 | -------------------------------------------------------------------------------- /common/common.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 29 | 32 | 35 | 38 | 41 | 44 | 56 | 59 | 62 | 65 | 68 | 71 | 74 | 77 | 80 | 83 | 84 | 91 | 94 | 97 | 100 | 103 | 107 | 119 | 122 | 125 | 128 | 133 | 136 | 139 | 142 | 145 | 148 | 149 | 157 | 160 | 163 | 166 | 169 | 172 | 183 | 186 | 189 | 192 | 195 | 198 | 201 | 204 | 207 | 210 | 211 | 219 | 222 | 225 | 228 | 231 | 235 | 247 | 250 | 253 | 256 | 261 | 264 | 267 | 270 | 273 | 276 | 277 | 278 | 279 | 280 | 281 | 286 | 289 | 290 | 293 | 294 | 297 | 298 | 301 | 302 | 305 | 306 | 309 | 310 | 311 | 316 | 319 | 320 | 321 | 326 | 327 | 328 | 329 | 330 | 331 | -------------------------------------------------------------------------------- /transport/transport.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 29 | 32 | 35 | 38 | 41 | 44 | 56 | 59 | 62 | 65 | 68 | 71 | 74 | 77 | 80 | 83 | 84 | 91 | 94 | 97 | 100 | 103 | 107 | 119 | 122 | 125 | 128 | 133 | 136 | 139 | 142 | 145 | 148 | 149 | 157 | 160 | 163 | 166 | 169 | 172 | 183 | 186 | 189 | 192 | 195 | 198 | 201 | 204 | 207 | 210 | 211 | 219 | 222 | 225 | 228 | 231 | 235 | 247 | 250 | 253 | 256 | 261 | 264 | 267 | 270 | 273 | 276 | 277 | 278 | 279 | 280 | 281 | 286 | 289 | 290 | 293 | 294 | 295 | 300 | 303 | 304 | 307 | 308 | 311 | 312 | 315 | 316 | 319 | 320 | 321 | 326 | 327 | 328 | 329 | 330 | 331 | -------------------------------------------------------------------------------- /server/vmrestd/vmrestd.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 29 | 32 | 35 | 38 | 41 | 44 | 55 | 58 | 61 | 64 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 92 | 93 | 100 | 103 | 106 | 109 | 112 | 116 | 128 | 131 | 134 | 137 | 146 | 149 | 152 | 155 | 158 | 161 | 164 | 167 | 168 | 176 | 179 | 182 | 185 | 188 | 191 | 202 | 205 | 208 | 211 | 220 | 223 | 226 | 229 | 232 | 235 | 238 | 241 | 242 | 250 | 253 | 256 | 259 | 262 | 266 | 278 | 281 | 284 | 287 | 298 | 301 | 304 | 307 | 310 | 313 | 316 | 319 | 320 | 321 | 322 | 323 | 324 | 329 | 332 | 333 | 336 | 337 | 340 | 341 | 342 | 347 | 350 | 351 | 354 | 355 | 358 | 359 | 362 | 363 | 366 | 367 | 368 | 373 | 374 | 375 | 376 | 377 | 378 | -------------------------------------------------------------------------------- /server/server.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 29 | 32 | 35 | 38 | 41 | 44 | 55 | 58 | 61 | 64 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 92 | 93 | 100 | 103 | 106 | 109 | 112 | 116 | 128 | 131 | 134 | 137 | 146 | 149 | 152 | 155 | 158 | 161 | 164 | 167 | 168 | 176 | 179 | 182 | 185 | 188 | 191 | 202 | 205 | 208 | 211 | 220 | 223 | 226 | 229 | 232 | 235 | 238 | 241 | 242 | 250 | 253 | 256 | 259 | 262 | 266 | 278 | 281 | 284 | 287 | 298 | 301 | 304 | 307 | 310 | 313 | 316 | 319 | 320 | 321 | 322 | 323 | 324 | 329 | 332 | 333 | 336 | 337 | 340 | 341 | 344 | 345 | 348 | 349 | 352 | 353 | 356 | 357 | 360 | 361 | 362 | 367 | 370 | 371 | 374 | 375 | 378 | 379 | 382 | 383 | 386 | 387 | 388 | 393 | 394 | 395 | 396 | 397 | 398 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | C-REST-Engine 2 | Copyright © 2017 VMware, Inc. All rights reserved 3 | 4 | The Apache 2.0 license (the License) set forth below applies to all 5 | parts of the VMware C-REST-Engine project. You may not use this file 6 | except in compliance with the License. 7 | 8 | Apache License 9 | 10 | Version 2.0, January 2004 11 | http://www.apache.org/licenses/ 12 | 13 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 14 | 15 | 1. Definitions. 16 | 17 | "License" shall mean the terms and conditions for use, reproduction, 18 | and distribution as defined by Sections 1 through 9 of this document. 19 | 20 | "Licensor" shall mean the copyright owner or entity authorized by the 21 | copyright owner that is granting the License. 22 | 23 | "Legal Entity" shall mean the union of the acting entity and all other 24 | entities that control, are controlled by, or are under common control 25 | with that entity. For the purposes of this definition, "control" means 26 | (i) the power, direct or indirect, to cause the direction or management 27 | of such entity, whether by contract or otherwise, or (ii) ownership 28 | of fifty percent (50%) or more of the outstanding shares, or (iii) 29 | beneficial ownership of such entity. 30 | 31 | "You" (or "Your") shall mean an individual or Legal Entity exercising 32 | permissions granted by this License. 33 | 34 | "Source" form shall mean the preferred form for making modifications, 35 | including but not limited to software source code, documentation source, 36 | and configuration files. 37 | 38 | "Object" form shall mean any form resulting from mechanical transformation 39 | or translation of a Source form, including but not limited to compiled 40 | object code, generated documentation, and conversions to other media 41 | types. 42 | 43 | "Work" shall mean the work of authorship, whether in Source or 44 | Object form, made available under the License, as indicated by a copyright 45 | notice that is included in or attached to the work (an example is provided 46 | in the Appendix below). 47 | 48 | "Derivative Works" shall mean any work, whether in Source or Object form, 49 | that is based on (or derived from) the Work and for which the editorial 50 | revisions, annotations, elaborations, or other modifications represent, 51 | as a whole, an original work of authorship. For the purposes of this 52 | License, Derivative Works shall not include works that remain separable 53 | from, or merely link (or bind by name) to the interfaces of, the Work 54 | and Derivative Works thereof. 55 | 56 | "Contribution" shall mean any work of authorship, including the 57 | original version of the Work and any modifications or additions to 58 | that Work or Derivative Works thereof, that is intentionally submitted 59 | to Licensor for inclusion in the Work by the copyright owner or by an 60 | individual or Legal Entity authorized to submit on behalf of the copyright 61 | owner. For the purposes of this definition, "submitted" means any form of 62 | electronic, verbal, or written communication sent to the Licensor or its 63 | representatives, including but not limited to communication on electronic 64 | mailing lists, source code control systems, and issue tracking systems 65 | that are managed by, or on behalf of, the Licensor for the purpose of 66 | discussing and improving the Work, but excluding communication that is 67 | conspicuously marked or otherwise designated in writing by the copyright 68 | owner as "Not a Contribution." 69 | 70 | "Contributor" shall mean Licensor and any individual or Legal Entity 71 | on behalf of whom a Contribution has been received by Licensor and 72 | subsequently incorporated within the Work. 73 | 74 | 2. Grant of Copyright License. 75 | Subject to the terms and conditions of this License, each Contributor 76 | hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, 77 | royalty-free, irrevocable copyright license to reproduce, prepare 78 | Derivative Works of, publicly display, publicly perform, sublicense, and 79 | distribute the Work and such Derivative Works in Source or Object form. 80 | 81 | 3. Grant of Patent License. 82 | Subject to the terms and conditions of this License, each Contributor 83 | hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, 84 | royalty- free, irrevocable (except as stated in this section) patent 85 | license to make, have made, use, offer to sell, sell, import, and 86 | otherwise transfer the Work, where such license applies only to those 87 | patent claims licensable by such Contributor that are necessarily 88 | infringed by their Contribution(s) alone or by combination of 89 | their Contribution(s) with the Work to which such Contribution(s) 90 | was submitted. If You institute patent litigation against any entity 91 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 92 | Work or a Contribution incorporated within the Work constitutes direct 93 | or contributory patent infringement, then any patent licenses granted 94 | to You under this License for that Work shall terminate as of the date 95 | such litigation is filed. 96 | 97 | 4. Redistribution. 98 | You may reproduce and distribute copies of the Work or Derivative Works 99 | thereof in any medium, with or without modifications, and in Source or 100 | Object form, provided that You meet the following conditions: 101 | 102 | a. You must give any other recipients of the Work or Derivative Works 103 | a copy of this License; and 104 | 105 | b. You must cause any modified files to carry prominent notices stating 106 | that You changed the files; and 107 | 108 | c. You must retain, in the Source form of any Derivative Works that 109 | You distribute, all copyright, patent, trademark, and attribution 110 | notices from the Source form of the Work, excluding those notices 111 | that do not pertain to any part of the Derivative Works; and 112 | 113 | d. If the Work includes a "NOTICE" text file as part of its 114 | distribution, then any Derivative Works that You distribute must 115 | include a readable copy of the attribution notices contained 116 | within such NOTICE file, excluding those notices that do not 117 | pertain to any part of the Derivative Works, in at least one of 118 | the following places: within a NOTICE text file distributed as part 119 | of the Derivative Works; within the Source form or documentation, 120 | if provided along with the Derivative Works; or, within a display 121 | generated by the Derivative Works, if and wherever such third-party 122 | notices normally appear. The contents of the NOTICE file are for 123 | informational purposes only and do not modify the License. You 124 | may add Your own attribution notices within Derivative Works that 125 | You distribute, alongside or as an addendum to the NOTICE text 126 | from the Work, provided that such additional attribution notices 127 | cannot be construed as modifying the License. You may add Your own 128 | copyright statement to Your modifications and may provide additional 129 | or different license terms and conditions for use, reproduction, or 130 | distribution of Your modifications, or for any such Derivative Works 131 | as a whole, provided Your use, reproduction, and distribution of the 132 | Work otherwise complies with the conditions stated in this License. 133 | 134 | 5. Submission of Contributions. 135 | Unless You explicitly state otherwise, any Contribution intentionally 136 | submitted for inclusion in the Work by You to the Licensor shall be 137 | under the terms and conditions of this License, without any additional 138 | terms or conditions. Notwithstanding the above, nothing herein shall 139 | supersede or modify the terms of any separate license agreement you may 140 | have executed with Licensor regarding such Contributions. 141 | 142 | 6. Trademarks. 143 | This License does not grant permission to use the trade names, trademarks, 144 | service marks, or product names of the Licensor, except as required for 145 | reasonable and customary use in describing the origin of the Work and 146 | reproducing the content of the NOTICE file. 147 | 148 | 7. Disclaimer of Warranty. 149 | Unless required by applicable law or agreed to in writing, Licensor 150 | provides the Work (and each Contributor provides its Contributions) on 151 | an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 152 | express or implied, including, without limitation, any warranties or 153 | conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR 154 | A PARTICULAR PURPOSE. You are solely responsible for determining the 155 | appropriateness of using or redistributing the Work and assume any risks 156 | associated with Your exercise of permissions under this License. 157 | 158 | 8. Limitation of Liability. 159 | In no event and under no legal theory, whether in tort (including 160 | negligence), contract, or otherwise, unless required by applicable law 161 | (such as deliberate and grossly negligent acts) or agreed to in writing, 162 | shall any Contributor be liable to You for damages, including any direct, 163 | indirect, special, incidental, or consequential damages of any character 164 | arising as a result of this License or out of the use or inability to 165 | use the Work (including but not limited to damages for loss of goodwill, 166 | work stoppage, computer failure or malfunction, or any and all other 167 | commercial damages or losses), even if such Contributor has been advised 168 | of the possibility of such damages. 169 | 170 | 9. Accepting Warranty or Additional Liability. 171 | While redistributing the Work or Derivative Works thereof, You may 172 | choose to offer, and charge a fee for, acceptance of support, warranty, 173 | indemnity, or other liability obligations and/or rights consistent with 174 | this License. However, in accepting such obligations, You may act only 175 | on Your own behalf and on Your sole responsibility, not on behalf of 176 | any other Contributor, and only if You agree to indemnify, defend, and 177 | hold each Contributor harmless for any liability incurred by, or claims 178 | asserted against, such Contributor by reason of your accepting any such 179 | warranty or additional liability. 180 | 181 | END OF TERMS AND CONDITIONS 182 | --------------------------------------------------------------------------------