Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
introduced _EXPORT headers for win32
Browse files Browse the repository at this point in the history
* ... and moved HttpClient into its own header
  • Loading branch information
weigon committed Jun 14, 2018
1 parent e8f89c0 commit 53b398f
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 38 deletions.
46 changes: 46 additions & 0 deletions src/http/include/mysqlrouter/http_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef MYSQLROUTER_HTTP_CLIENT_INCLUDED
#define MYSQLROUTER_HTTP_CLIENT_INCLUDED

#include "mysqlrouter/http_client_export.h"
#include "mysqlrouter/http_common.h"

class HTTP_CLIENT_EXPORT HttpClient {
class impl;

std::unique_ptr<impl> pImpl;

IOContext &io_ctx_;
public:
HttpClient();
~HttpClient();
HttpClient(IOContext &io_ctx, const std::string &address, uint16_t port);

void make_request(HttpRequest *req, HttpMethod::type method, const std::string &uri);
void make_request_sync(HttpRequest *req, HttpMethod::type method, const std::string &uri);
};

#endif
42 changes: 42 additions & 0 deletions src/http/include/mysqlrouter/http_client_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef MYSQLROUTER_HTTP_CLIENT_EXPORT_INCLUDED
#define MYSQLROUTER_HTTP_CLIENT_EXPORT_INCLUDED

#ifdef _WIN32
# ifdef http_client_DEFINE_STATIC
# define HTTP_CLIENT_EXPORT
# else
# ifdef http_client_EXPORTS
# define HTTP_CLIENT_EXPORT __declspec(dllexport)
# else
# define HTTP_CLIENT_EXPORT __declspec(dllimport)
# endif
# endif
#else
# define HTTP_CLIENT_EXPORT
#endif

#endif
35 changes: 11 additions & 24 deletions src/http/include/mysqlrouter/http_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef MYSQLROUTER_HTTP_COMMON_INCLUDED
#define MYSQLROUTER_HTTP_COMMON_INCLUDED

#include "mysqlrouter/http_common_export.h"

#include <ctime>
#include <memory>
#include <functional> // std::function
Expand Down Expand Up @@ -185,7 +187,7 @@ namespace HttpStatusCode {
}
}

class HttpUri {
class HTTP_COMMON_EXPORT HttpUri {
struct impl;

std::unique_ptr<impl> pImpl;
Expand All @@ -200,7 +202,7 @@ class HttpUri {
};

// wrapper around evbuffer
class HttpBuffer {
class HTTP_COMMON_EXPORT HttpBuffer {
struct impl;

std::unique_ptr<impl> pImpl;
Expand All @@ -220,7 +222,7 @@ class HttpBuffer {
std::vector<uint8_t> pop_front(size_t length);
};

class HttpHeaders {
class HTTP_COMMON_EXPORT HttpHeaders {
struct impl;

std::unique_ptr<impl> pImpl;
Expand Down Expand Up @@ -275,7 +277,7 @@ namespace HttpMethod {
constexpr type Patch { 1 << Pos::Patch };
};

class IOContext {
class HTTP_COMMON_EXPORT IOContext {
class impl;

std::unique_ptr<impl> pImpl;
Expand All @@ -286,7 +288,7 @@ class IOContext {
void dispatch();
};

class HttpRequest {
class HTTP_COMMON_EXPORT HttpRequest {
class impl;

std::unique_ptr<impl> pImpl;
Expand Down Expand Up @@ -332,26 +334,11 @@ class HttpRequest {
std::string error_msg();
};

class HttpClient {
class impl;

std::unique_ptr<impl> pImpl;

IOContext &io_ctx_;
public:
HttpClient();
~HttpClient();
HttpClient(IOContext &io_ctx, const std::string &address, uint16_t port);

void make_request(HttpRequest *req, HttpMethod::type method, const std::string &uri);
void make_request_sync(HttpRequest *req, HttpMethod::type method, const std::string &uri);
};

// http_time.cc

bool is_modified_since(const HttpRequest &req, time_t last_modified);
void add_last_modified(HttpRequest &req, time_t last_modified);
time_t time_from_rfc5322_fixdate(const char *date_buf);
int time_to_rfc5322_fixdate(time_t ts, char *date_buf, size_t date_buf_len);
HTTP_COMMON_EXPORT bool is_modified_since(const HttpRequest &req, time_t last_modified);
HTTP_COMMON_EXPORT void add_last_modified(HttpRequest &req, time_t last_modified);
HTTP_COMMON_EXPORT time_t time_from_rfc5322_fixdate(const char *date_buf);
HTTP_COMMON_EXPORT int time_to_rfc5322_fixdate(time_t ts, char *date_buf, size_t date_buf_len);

#endif
42 changes: 42 additions & 0 deletions src/http/include/mysqlrouter/http_common_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef MYSQLROUTER_HTTP_COMMON_EXPORT_INCLUDED
#define MYSQLROUTER_HTTP_COMMON_EXPORT_INCLUDED

#ifdef _WIN32
# ifdef http_common_DEFINE_STATIC
# define HTTP_COMMON_EXPORT
# else
# ifdef http_common_EXPORTS
# define HTTP_COMMON_EXPORT __declspec(dllexport)
# else
# define HTTP_COMMON_EXPORT __declspec(dllimport)
# endif
# endif
#else
# define HTTP_COMMON_EXPORT
#endif

#endif
5 changes: 3 additions & 2 deletions src/http/include/mysqlrouter/http_server_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
#include <mutex>

#include "mysqlrouter/http_common.h"
#include "mysqlrouter/http_server_export.h"

class BaseRequestHandler {
class HTTP_SERVER_EXPORT BaseRequestHandler {
public:
void call(HttpRequest &req, void *me) {
auto *my = static_cast<BaseRequestHandler *>(me);
Expand All @@ -41,7 +42,7 @@ class BaseRequestHandler {
virtual ~BaseRequestHandler() = default;
};

class HttpServerComponent {
class HTTP_SERVER_EXPORT HttpServerComponent {
// disable copy, as we are a single-instance
HttpServerComponent(HttpServerComponent const &) = delete;
void operator=(HttpServerComponent const &) = delete;
Expand Down
42 changes: 42 additions & 0 deletions src/http/include/mysqlrouter/http_server_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef MYSQLROUTER_HTTP_SERVER_EXPORT_INCLUDED
#define MYSQLROUTER_HTTP_SERVER_EXPORT_INCLUDED

#ifdef _WIN32
# ifdef http_server_DEFINE_STATIC
# define HTTP_SERVER_EXPORT
# else
# ifdef http_server_EXPORTS
# define HTTP_SERVER_EXPORT __declspec(dllexport)
# else
# define HTTP_SERVER_EXPORT __declspec(dllimport)
# endif
# endif
#else
# define HTTP_SERVER_EXPORT
#endif

#endif
2 changes: 1 addition & 1 deletion src/http/include/mysqlrouter/rest_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef MYSQL_ROUTER_REST_CLIENT_H_INCLUDED
#define MYSQL_ROUTER_REST_CLIENT_H_INCLUDED

#include "mysqlrouter/http_common.h"
#include "mysqlrouter/http_client.h"

class RestClient {
public:
Expand Down
2 changes: 1 addition & 1 deletion src/http/src/http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <string>
#include <iostream>

#include "mysqlrouter/http_common.h"
#include "mysqlrouter/http_client.h"
#include "http_request_impl.h"

class IOContext::impl {
Expand Down
9 changes: 1 addition & 8 deletions src/http/src/http_server_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,11 @@ static void start(PluginFuncEnv* env) {
}
}

#if defined(_MSC_VER) && defined(http_server_EXPORTS)
/* We are building this library */
# define DLLEXPORT __declspec(dllexport)
#else
# define DLLEXPORT
#endif

const char *plugin_requires[] = {
};

extern "C" {
Plugin DLLEXPORT harness_plugin_http_server = {
Plugin HTTP_SERVER_EXPORT harness_plugin_http_server = {
PLUGIN_ABI_VERSION,
ARCHITECTURE_DESCRIPTOR,
"HTTP_SERVER",
Expand Down
2 changes: 1 addition & 1 deletion src/http/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ include_directories(../include ../src)

add_test_file(test_time.cc
MODULE http
LIB_DEPENDS http_common
LIB_DEPENDS http_client
INCLUDE_DIRS ${GTEST_INCLUDE_DIRS}
)
2 changes: 1 addition & 1 deletion src/http/tests/test_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "gmock/gmock.h"

#include "mysqlrouter/http_common.h"
#include "mysqlrouter/http_client.h"

#ifdef _WIN32
#include <WinSock2.h>
Expand Down

0 comments on commit 53b398f

Please sign in to comment.