Add email verification #415

Merged
RElesgoe merged 37 commits from feature-email into develop 2020-08-08 14:25:00 -06:00
39 changed files with 9991 additions and 17 deletions

View file

@ -36,7 +36,15 @@ message(STATUS "*** {fmt} ***")
set(USE_INCLUDED_ZLIB_LIBRARY OFF)
if(WITH_BNETD)
cmake_policy(SET CMP0074 NEW)
if (WIN32)
set(CURL_LIBRARY ${CMAKE_SOURCE_DIR}/lib/curl/7.70.0/libcurl.lib)
set(CURL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include/curl/7.70.0)
endif()
find_package(CURL REQUIRED)
if (POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if (NOT DEFINED ZLIB_ROOT)
set(USE_INCLUDED_ZLIB_LIBRARY ON)

View file

@ -4,7 +4,8 @@ set(OUTPUT_CONFS ad.json anongame_infos.conf address_translation.conf
bnissue.txt bnmaps.conf bnxpcalc.conf
bnxplevel.conf channel.conf command_groups.conf realm.conf
sql_DB_layout.conf supportfile.conf topics.conf
tournament.conf versioncheck.json icons.conf)
tournament.conf versioncheck.json icons.conf
email_verification.conf cacert.pem)
foreach(CONF ${OUTPUT_CONFS})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${CONF}.in ${CMAKE_CURRENT_BINARY_DIR}/${CONF} @ONLY)
endforeach(CONF)
@ -20,7 +21,8 @@ if(WITH_BNETD)
bnetd_default_user.plain bnissue.txt bnmaps.conf
bnxpcalc.conf bnxplevel.conf channel.conf command_groups.conf
realm.conf sql_DB_layout.conf supportfile.conf topics.conf
tournament.conf versioncheck.json icons.conf)
tournament.conf versioncheck.json icons.conf
email_verification.conf cacert.pem)
endif(WITH_BNETD)
if(WITH_D2CS)

View file

@ -97,6 +97,7 @@ DBlayoutfile = "${SYSCONFDIR}/sql_DB_layout.conf"
supportfile = "${SYSCONFDIR}/supportfile.conf"
transfile = "${SYSCONFDIR}/address_translation.conf"
customicons_file = "${SYSCONFDIR}/icons.conf"
email_verification_file = "${SYSCONFDIR}/email_verification.conf"
# #
@ -370,6 +371,20 @@ passfail_bantime = 300
# Max users limit in private channels (0 = unlimited)
maxusers_per_channel = 0
# Verify account email address
# Upon account registration, sends an email to the user with a code that will
# be used to verify the registered email address.
# Set smtp_server_url, smtp_port, smtp_username, and smtp_password before enabling.
verify_account_email = false
# Number of minutes before an account email verification code expires
verify_account_email_expiration = 10
# Email address to use for the 'From' field in email verification emails.
verify_account_email_from_address = ""
verify_account_email_from_name = ""
# #
##############################################################################
@ -645,3 +660,37 @@ log_command_groups = 2345678
# set empty to log all commands
log_command_list = ""
# #
##############################################################################
###############################################################################
# SMTP #
#-----------------------------------------------------------------------------#
# Path to a CA certificate store file in PEM format, relative to ${SYSCONFDIR},
# containing X.509 certificates of public certificate authorities.
# See https://curl.haxx.se/docs/caextract.html
smtp_ca_cert_store = "${SYSCONFDIR}/cacert.pem"
# URL to download a new CA certificate store file.
smtp_ca_cert_store_remote_url = "https://curl.haxx.se/ca/cacert.pem"
# Number of days to wait before downloading a new cacert.pem
# Recommended value: 30
# Set to 0 to disable
smtp_ca_cert_store_fetch_interval = 30
# smtp_server_url = "smtp.gmail.com"
smtp_server_url = ""
smtp_port = 587
smtp_username = ""
# If your account has two-factor authentication (2FA) enabled, you will need to
# create a token through your SMTP provider.
smtp_password = ""
# #
##############################################################################

View file

@ -81,6 +81,7 @@ anongame_infos_file = conf\anongame_infos.conf
DBlayoutfile = conf\sql_DB_layout.conf
supportfile = conf\supportfile.conf
customicons_file = conf\icons.conf
email_verification_file = "conf\email_verification.conf"
# #
@ -353,6 +354,18 @@ passfail_bantime = 300
# Max users limit in private channels (0 = unlimited)
maxusers_per_channel = 0
# Verify account email address
# Upon account registration, sends an email to the user with a code that will
# be used to verify the registered email address.
# Set smtp_server_url, smtp_port, smtp_username, and smtp_password before enabling.
verify_account_email = false
# Number of minutes before an account email verification code expires
verify_account_email_expiration = 10
# Email address to use for the 'From' field in email verification emails.
verify_account_email_from_address = ""
# #
##############################################################################
@ -632,3 +645,37 @@ log_command_groups = 2345678
# set empty to log all commands
log_command_list = ""
# #
##############################################################################
###############################################################################
# SMTP #
#-----------------------------------------------------------------------------#
# Path to a CA certificate store file in PEM format, relative to ${SYSCONFDIR},
# containing X.509 certificates of public certificate authorities.
# See https://curl.haxx.se/docs/caextract.html
smtp_ca_cert_store = "conf\cacert.pem"
# URL to download a new CA certificate store file.
smtp_ca_cert_store_remote_url = "https://curl.haxx.se/ca/cacert.pem"
# Number of days to wait before downloading a new cacert.pem
# Recommended value: 30
# Set to 0 to disable
smtp_ca_cert_store_fetch_interval = 30
# smtp_server_url = "smtp.gmail.com"
smtp_server_url = ""
smtp_port = 587
smtp_username = ""
# If your account has two-factor authentication (2FA) enabled, you will need to
# create a token through your SMTP provider.
smtp_password = ""
# #
##############################################################################

3466
conf/cacert.pem.in Normal file

File diff suppressed because it is too large Load diff

View file

@ -73,6 +73,7 @@
1 /topic
1 /icon
1 /language /lang
1 /email
# /////////////////////////////
# ///// Operator commands /////

View file

@ -0,0 +1,9 @@
Hello {{account_name}},
Your verification code is {{account_email_verification_code}}.
This code will expire in {{account_email_verification_expiration}} minutes.
To verify your email address, enter /email verify {{account_email_verification_code}} in the PvPGN server.
{pvpgn_server_name}

View file

@ -450,7 +450,7 @@
--------------------------------------------------------
/rehash <mode>
Forces the server to reload specified config. Set "all" to reload all configs.
<mode> = all | i18n | channels | realms | autoupdate | news | versioncheck | ipbans | helpfile | banners | tracker | commandgroups | aliasfile | transfile | tournament | icons | anongame | topiclist | lua
<mode> = all | i18n | channels | realms | autoupdate | news | versioncheck | ipbans | helpfile | banners | tracker | commandgroups | aliasfile | transfile | tournament | icons | anongame | topiclist | lua | smtp | accountemailverification
%clan
--------------------------------------------------------
@ -647,4 +647,16 @@ Syntax for operator/admin:
Available maps:
%email
--------------------------------------------------------
/email <command> [option]
/email get
Displays your email address.
/email set <email address>
Sets your email address to the given email address. Type /email resendverification to receive a verification code at your new email address.
/email verify <code>
Verifies your email address
/email resendverification
Sends another email with a new verification code.

View file

@ -2071,6 +2071,65 @@
<item id="516" file="clan.cpp" function="clan_create">
<original>This is a newly created clan</original>
<translate></translate>
<item id="517" file="command.cpp" function="_handle_email_command">
<original>An error has occurred.</original>
<translate></translate>
</item>
<item id="518" file="command.cpp" function="_handle_email_command">
<original>Your email address is: {}</original>
<translate></translate>
</item>
<item id="519" file="command.cpp" function="_handle_email_command">
<original>Email address successfully set to {}.</original>
<translate></translate>
</item>
<item id="520" file="command.cpp" function="_handle_email_command">
<original>Successfully verified email address.</original>
<translate></translate>
</item>
<item id="521" file="command.cpp" function="_handle_email_command">
<original>The code has already expired.</original>
<translate></translate>
</item>
<item id="522" file="command.cpp" function="_handle_email_command">
<original>The code is incorrect.</original>
<translate></translate>
</item>
<item id="523" file="command.cpp" function="_handle_email_command">
<original>Regenerated verification code. Check your email.</original>
<translate></translate>
</item>
<item id="524" file="command.cpp" function="_handle_email_command">
<original>Your email address is already set to {}.</original>
<translate></translate>
</item>
<item id="525" file="command.cpp" function="_handle_email_command">
<original>Email address verification is disabled.</original>
<translate></translate>
</item>
<item id="526" file="command.cpp" function="_handle_email_command">
<original>The email address is too long, please use another one.</original>
<translate></translate>
</item>
<item id="527" file="command.cpp" function="_handle_email_command">
<original>You have not set an email address yet.</original>
<translate></translate>
</item>
<item id="528" file="command.cpp" function="_handle_email_command">
<original>An email has been sent, please check your inbox for the verification code.</original>
<translate></translate>
</item>
<item id="529" file="command.cpp" function="_handle_email_command">
<original>An error has occurred, could not send a verification email.</original>
<translate></translate>
</item>
<item id="530" file="command.cpp" function="_handle_finger_command">
<original>(Verified)</original>
<translate></translate>
</item>
<item id="531" file="command.cpp" function="_handle_finger_command">
<original>(Unverified)</original>
<translate></translate>
</item>
</items>
</root>

View file

@ -19,6 +19,7 @@
"acct_userid int","NULL"
"acct_passhash1 varchar(40)","NULL"
"acct_email varchar(128)","NULL"
"acct_email_verified varchar(6)","'false'"
"auth_admin varchar(6)","'false'"
"auth_normallogin varchar(6)","'true'"
"auth_changepass varchar(6)","'true'"
@ -39,6 +40,10 @@
"acct_lastlogin_ip varchar(16)","NULL"
:"DROP INDEX username"
:"CREATE UNIQUE INDEX username2 ON ${prefix}BNET (username)"
[${prefix}email_verification]
"uid int NOT NULL PRIMARY KEY","'0'"
code varchar(64)","NULL"
expiration int", "'0'"
[${prefix}WOL]
"uid int NOT NULL PRIMARY KEY","'0'"
"auth_apgar varchar(8)","NULL"

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,77 @@
#ifndef CURLINC_CURLVER_H
#define CURLINC_CURLVER_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
/* This header file contains nothing but libcurl version info, generated by
a script at release-time. This was made its own header file in 7.11.2 */
/* This is the global package copyright */
#define LIBCURL_COPYRIGHT "1996 - 2020 Daniel Stenberg, <daniel@haxx.se>."
/* This is the version number of the libcurl package from which this header
file origins: */
#define LIBCURL_VERSION "7.70.0"
/* The numeric version number is also available "in parts" by using these
defines: */
#define LIBCURL_VERSION_MAJOR 7
#define LIBCURL_VERSION_MINOR 70
#define LIBCURL_VERSION_PATCH 0
/* This is the numeric version of the libcurl version number, meant for easier
parsing and comparions by programs. The LIBCURL_VERSION_NUM define will
always follow this syntax:
0xXXYYZZ
Where XX, YY and ZZ are the main version, release and patch numbers in
hexadecimal (using 8 bits each). All three numbers are always represented
using two digits. 1.2 would appear as "0x010200" while version 9.11.7
appears as "0x090b07".
This 6-digit (24 bits) hexadecimal number does not show pre-release number,
and it is always a greater number in a more recent release. It makes
comparisons with greater than and less than work.
Note: This define is the full hex number and _does not_ use the
CURL_VERSION_BITS() macro since curl's own configure script greps for it
and needs it to contain the full number.
*/
#define LIBCURL_VERSION_NUM 0x074600
/*
* This is the date and time when the full source package was created. The
* timestamp is not stored in git, as the timestamp is properly set in the
* tarballs by the maketgz script.
*
* The format of the date follows this template:
*
* "2007-11-23"
*/
#define LIBCURL_TIMESTAMP "2020-04-29"
#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|(z))
#define CURL_AT_LEAST_VERSION(x,y,z) \
(LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z))
#endif /* CURLINC_CURLVER_H */

View file

@ -0,0 +1,112 @@
#ifndef CURLINC_EASY_H
#define CURLINC_EASY_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
CURL_EXTERN CURL *curl_easy_init(void);
CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl);
CURL_EXTERN void curl_easy_cleanup(CURL *curl);
/*
* NAME curl_easy_getinfo()
*
* DESCRIPTION
*
* Request internal information from the curl session with this function. The
* third argument MUST be a pointer to a long, a pointer to a char * or a
* pointer to a double (as the documentation describes elsewhere). The data
* pointed to will be filled in accordingly and can be relied upon only if the
* function returns CURLE_OK. This function is intended to get used *AFTER* a
* performed transfer, all results from this function are undefined until the
* transfer is completed.
*/
CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...);
/*
* NAME curl_easy_duphandle()
*
* DESCRIPTION
*
* Creates a new curl session handle with the same options set for the handle
* passed in. Duplicating a handle could only be a matter of cloning data and
* options, internal state info and things like persistent connections cannot
* be transferred. It is useful in multithreaded applications when you can run
* curl_easy_duphandle() for each new thread to avoid a series of identical
* curl_easy_setopt() invokes in every thread.
*/
CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl);
/*
* NAME curl_easy_reset()
*
* DESCRIPTION
*
* Re-initializes a CURL handle to the default values. This puts back the
* handle to the same state as it was in when it was just created.
*
* It does keep: live connections, the Session ID cache, the DNS cache and the
* cookies.
*/
CURL_EXTERN void curl_easy_reset(CURL *curl);
/*
* NAME curl_easy_recv()
*
* DESCRIPTION
*
* Receives data from the connected socket. Use after successful
* curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
*/
CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen,
size_t *n);
/*
* NAME curl_easy_send()
*
* DESCRIPTION
*
* Sends data over the connected socket. Use after successful
* curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
*/
CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer,
size_t buflen, size_t *n);
/*
* NAME curl_easy_upkeep()
*
* DESCRIPTION
*
* Performs connection upkeep for the given session handle.
*/
CURL_EXTERN CURLcode curl_easy_upkeep(CURL *curl);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,50 @@
#ifndef CURLINC_MPRINTF_H
#define CURLINC_MPRINTF_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include <stdarg.h>
#include <stdio.h> /* needed for FILE */
#include "curl.h" /* for CURL_EXTERN */
#ifdef __cplusplus
extern "C" {
#endif
CURL_EXTERN int curl_mprintf(const char *format, ...);
CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...);
CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...);
CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength,
const char *format, ...);
CURL_EXTERN int curl_mvprintf(const char *format, va_list args);
CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args);
CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args);
CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength,
const char *format, va_list args);
CURL_EXTERN char *curl_maprintf(const char *format, ...);
CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args);
#ifdef __cplusplus
}
#endif
#endif /* CURLINC_MPRINTF_H */

View file

@ -0,0 +1,456 @@
#ifndef CURLINC_MULTI_H
#define CURLINC_MULTI_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
/*
This is an "external" header file. Don't give away any internals here!
GOALS
o Enable a "pull" interface. The application that uses libcurl decides where
and when to ask libcurl to get/send data.
o Enable multiple simultaneous transfers in the same thread without making it
complicated for the application.
o Enable the application to select() on its own file descriptors and curl's
file descriptors simultaneous easily.
*/
/*
* This header file should not really need to include "curl.h" since curl.h
* itself includes this file and we expect user applications to do #include
* <curl/curl.h> without the need for especially including multi.h.
*
* For some reason we added this include here at one point, and rather than to
* break existing (wrongly written) libcurl applications, we leave it as-is
* but with this warning attached.
*/
#include "curl.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER)
typedef struct Curl_multi CURLM;
#else
typedef void CURLM;
#endif
typedef enum {
CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
curl_multi_socket*() soon */
CURLM_OK,
CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */
CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */
CURLM_INTERNAL_ERROR, /* this is a libcurl bug */
CURLM_BAD_SOCKET, /* the passed in socket argument did not match */
CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */
CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was
attempted to get added - again */
CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a
callback */
CURLM_WAKEUP_FAILURE, /* wakeup is unavailable or failed */
CURLM_BAD_FUNCTION_ARGUMENT, /* function called with a bad parameter */
CURLM_LAST
} CURLMcode;
/* just to make code nicer when using curl_multi_socket() you can now check
for CURLM_CALL_MULTI_SOCKET too in the same style it works for
curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */
#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM
/* bitmask bits for CURLMOPT_PIPELINING */
#define CURLPIPE_NOTHING 0L
#define CURLPIPE_HTTP1 1L
#define CURLPIPE_MULTIPLEX 2L
typedef enum {
CURLMSG_NONE, /* first, not used */
CURLMSG_DONE, /* This easy handle has completed. 'result' contains
the CURLcode of the transfer */
CURLMSG_LAST /* last, not used */
} CURLMSG;
struct CURLMsg {
CURLMSG msg; /* what this message means */
CURL *easy_handle; /* the handle it concerns */
union {
void *whatever; /* message-specific data */
CURLcode result; /* return code for transfer */
} data;
};
typedef struct CURLMsg CURLMsg;
/* Based on poll(2) structure and values.
* We don't use pollfd and POLL* constants explicitly
* to cover platforms without poll(). */
#define CURL_WAIT_POLLIN 0x0001
#define CURL_WAIT_POLLPRI 0x0002
#define CURL_WAIT_POLLOUT 0x0004
struct curl_waitfd {
curl_socket_t fd;
short events;
short revents; /* not supported yet */
};
/*
* Name: curl_multi_init()
*
* Desc: inititalize multi-style curl usage
*
* Returns: a new CURLM handle to use in all 'curl_multi' functions.
*/
CURL_EXTERN CURLM *curl_multi_init(void);
/*
* Name: curl_multi_add_handle()
*
* Desc: add a standard curl handle to the multi stack
*
* Returns: CURLMcode type, general multi error code.
*/
CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
CURL *curl_handle);
/*
* Name: curl_multi_remove_handle()
*
* Desc: removes a curl handle from the multi stack again
*
* Returns: CURLMcode type, general multi error code.
*/
CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
CURL *curl_handle);
/*
* Name: curl_multi_fdset()
*
* Desc: Ask curl for its fd_set sets. The app can use these to select() or
* poll() on. We want curl_multi_perform() called as soon as one of
* them are ready.
*
* Returns: CURLMcode type, general multi error code.
*/
CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
fd_set *read_fd_set,
fd_set *write_fd_set,
fd_set *exc_fd_set,
int *max_fd);
/*
* Name: curl_multi_wait()
*
* Desc: Poll on all fds within a CURLM set as well as any
* additional fds passed to the function.
*
* Returns: CURLMcode type, general multi error code.
*/
CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle,
struct curl_waitfd extra_fds[],
unsigned int extra_nfds,
int timeout_ms,
int *ret);
/*
* Name: curl_multi_poll()
*
* Desc: Poll on all fds within a CURLM set as well as any
* additional fds passed to the function.
*
* Returns: CURLMcode type, general multi error code.
*/
CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle,
struct curl_waitfd extra_fds[],
unsigned int extra_nfds,
int timeout_ms,
int *ret);
/*
* Name: curl_multi_wakeup()
*
* Desc: wakes up a sleeping curl_multi_poll call.
*
* Returns: CURLMcode type, general multi error code.
*/
CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle);
/*
* Name: curl_multi_perform()
*
* Desc: When the app thinks there's data available for curl it calls this
* function to read/write whatever there is right now. This returns
* as soon as the reads and writes are done. This function does not
* require that there actually is data available for reading or that
* data can be written, it can be called just in case. It returns
* the number of handles that still transfer data in the second
* argument's integer-pointer.
*
* Returns: CURLMcode type, general multi error code. *NOTE* that this only
* returns errors etc regarding the whole multi stack. There might
* still have occurred problems on individual transfers even when
* this returns OK.
*/
CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
int *running_handles);
/*
* Name: curl_multi_cleanup()
*
* Desc: Cleans up and removes a whole multi stack. It does not free or
* touch any individual easy handles in any way. We need to define
* in what state those handles will be if this function is called
* in the middle of a transfer.
*
* Returns: CURLMcode type, general multi error code.
*/
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
/*
* Name: curl_multi_info_read()
*
* Desc: Ask the multi handle if there's any messages/informationals from
* the individual transfers. Messages include informationals such as
* error code from the transfer or just the fact that a transfer is
* completed. More details on these should be written down as well.
*
* Repeated calls to this function will return a new struct each
* time, until a special "end of msgs" struct is returned as a signal
* that there is no more to get at this point.
*
* The data the returned pointer points to will not survive calling
* curl_multi_cleanup().
*
* The 'CURLMsg' struct is meant to be very simple and only contain
* very basic information. If more involved information is wanted,
* we will provide the particular "transfer handle" in that struct
* and that should/could/would be used in subsequent
* curl_easy_getinfo() calls (or similar). The point being that we
* must never expose complex structs to applications, as then we'll
* undoubtably get backwards compatibility problems in the future.
*
* Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
* of structs. It also writes the number of messages left in the
* queue (after this read) in the integer the second argument points
* to.
*/
CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
int *msgs_in_queue);
/*
* Name: curl_multi_strerror()
*
* Desc: The curl_multi_strerror function may be used to turn a CURLMcode
* value into the equivalent human readable error string. This is
* useful for printing meaningful error messages.
*
* Returns: A pointer to a zero-terminated error message.
*/
CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
/*
* Name: curl_multi_socket() and
* curl_multi_socket_all()
*
* Desc: An alternative version of curl_multi_perform() that allows the
* application to pass in one of the file descriptors that have been
* detected to have "action" on them and let libcurl perform.
* See man page for details.
*/
#define CURL_POLL_NONE 0
#define CURL_POLL_IN 1
#define CURL_POLL_OUT 2
#define CURL_POLL_INOUT 3
#define CURL_POLL_REMOVE 4
#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
#define CURL_CSELECT_IN 0x01
#define CURL_CSELECT_OUT 0x02
#define CURL_CSELECT_ERR 0x04
typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */
curl_socket_t s, /* socket */
int what, /* see above */
void *userp, /* private callback
pointer */
void *socketp); /* private socket
pointer */
/*
* Name: curl_multi_timer_callback
*
* Desc: Called by libcurl whenever the library detects a change in the
* maximum number of milliseconds the app is allowed to wait before
* curl_multi_socket() or curl_multi_perform() must be called
* (to allow libcurl's timed events to take place).
*
* Returns: The callback should return zero.
*/
typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */
long timeout_ms, /* see above */
void *userp); /* private callback
pointer */
CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
int *running_handles);
CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle,
curl_socket_t s,
int ev_bitmask,
int *running_handles);
CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle,
int *running_handles);
#ifndef CURL_ALLOW_OLD_MULTI_SOCKET
/* This macro below was added in 7.16.3 to push users who recompile to use
the new curl_multi_socket_action() instead of the old curl_multi_socket()
*/
#define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z)
#endif
/*
* Name: curl_multi_timeout()
*
* Desc: Returns the maximum number of milliseconds the app is allowed to
* wait before curl_multi_socket() or curl_multi_perform() must be
* called (to allow libcurl's timed events to take place).
*
* Returns: CURLM error code.
*/
CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
long *milliseconds);
typedef enum {
/* This is the socket callback function pointer */
CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1),
/* This is the argument passed to the socket callback */
CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2),
/* set to 1 to enable pipelining for this multi handle */
CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3),
/* This is the timer callback function pointer */
CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4),
/* This is the argument passed to the timer callback */
CURLOPT(CURLMOPT_TIMERDATA, CURLOPTTYPE_OBJECTPOINT, 5),
/* maximum number of entries in the connection cache */
CURLOPT(CURLMOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 6),
/* maximum number of (pipelining) connections to one host */
CURLOPT(CURLMOPT_MAX_HOST_CONNECTIONS, CURLOPTTYPE_LONG, 7),
/* maximum number of requests in a pipeline */
CURLOPT(CURLMOPT_MAX_PIPELINE_LENGTH, CURLOPTTYPE_LONG, 8),
/* a connection with a content-length longer than this
will not be considered for pipelining */
CURLOPT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 9),
/* a connection with a chunk length longer than this
will not be considered for pipelining */
CURLOPT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 10),
/* a list of site names(+port) that are blacklisted from
pipelining */
CURLOPT(CURLMOPT_PIPELINING_SITE_BL, CURLOPTTYPE_OBJECTPOINT, 11),
/* a list of server types that are blacklisted from
pipelining */
CURLOPT(CURLMOPT_PIPELINING_SERVER_BL, CURLOPTTYPE_OBJECTPOINT, 12),
/* maximum number of open connections in total */
CURLOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, CURLOPTTYPE_LONG, 13),
/* This is the server push callback function pointer */
CURLOPT(CURLMOPT_PUSHFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 14),
/* This is the argument passed to the server push callback */
CURLOPT(CURLMOPT_PUSHDATA, CURLOPTTYPE_OBJECTPOINT, 15),
/* maximum number of concurrent streams to support on a connection */
CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16),
CURLMOPT_LASTENTRY /* the last unused */
} CURLMoption;
/*
* Name: curl_multi_setopt()
*
* Desc: Sets options for the multi handle.
*
* Returns: CURLM error code.
*/
CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
CURLMoption option, ...);
/*
* Name: curl_multi_assign()
*
* Desc: This function sets an association in the multi handle between the
* given socket and a private pointer of the application. This is
* (only) useful for curl_multi_socket uses.
*
* Returns: CURLM error code.
*/
CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
curl_socket_t sockfd, void *sockp);
/*
* Name: curl_push_callback
*
* Desc: This callback gets called when a new stream is being pushed by the
* server. It approves or denies the new stream.
*
* Returns: CURL_PUSH_OK or CURL_PUSH_DENY.
*/
#define CURL_PUSH_OK 0
#define CURL_PUSH_DENY 1
struct curl_pushheaders; /* forward declaration only */
CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h,
size_t num);
CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h,
const char *name);
typedef int (*curl_push_callback)(CURL *parent,
CURL *easy,
size_t num_headers,
struct curl_pushheaders *headers,
void *userp);
#ifdef __cplusplus
} /* end of extern "C" */
#endif
#endif

View file

@ -0,0 +1,33 @@
#ifndef CURLINC_STDCHEADERS_H
#define CURLINC_STDCHEADERS_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include <sys/types.h>
size_t fread(void *, size_t, size_t, FILE *);
size_t fwrite(const void *, size_t, size_t, FILE *);
int strcasecmp(const char *, const char *);
int strncasecmp(const char *, const char *, size_t);
#endif /* CURLINC_STDCHEADERS_H */

View file

@ -0,0 +1,504 @@
#ifndef CURLINC_SYSTEM_H
#define CURLINC_SYSTEM_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
/*
* Try to keep one section per platform, compiler and architecture, otherwise,
* if an existing section is reused for a different one and later on the
* original is adjusted, probably the piggybacking one can be adversely
* changed.
*
* In order to differentiate between platforms/compilers/architectures use
* only compiler built in predefined preprocessor symbols.
*
* curl_off_t
* ----------
*
* For any given platform/compiler curl_off_t must be typedef'ed to a 64-bit
* wide signed integral data type. The width of this data type must remain
* constant and independent of any possible large file support settings.
*
* As an exception to the above, curl_off_t shall be typedef'ed to a 32-bit
* wide signed integral data type if there is no 64-bit type.
*
* As a general rule, curl_off_t shall not be mapped to off_t. This rule shall
* only be violated if off_t is the only 64-bit data type available and the
* size of off_t is independent of large file support settings. Keep your
* build on the safe side avoiding an off_t gating. If you have a 64-bit
* off_t then take for sure that another 64-bit data type exists, dig deeper
* and you will find it.
*
*/
#if defined(__DJGPP__) || defined(__GO32__)
# if defined(__DJGPP__) && (__DJGPP__ > 1)
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# else
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__SALFORDC__)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__BORLANDC__)
# if (__BORLANDC__ < 0x520)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# else
# define CURL_TYPEOF_CURL_OFF_T __int64
# define CURL_FORMAT_CURL_OFF_T "I64d"
# define CURL_FORMAT_CURL_OFF_TU "I64u"
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__TURBOC__)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__WATCOMC__)
# if defined(__386__)
# define CURL_TYPEOF_CURL_OFF_T __int64
# define CURL_FORMAT_CURL_OFF_T "I64d"
# define CURL_FORMAT_CURL_OFF_TU "I64u"
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__POCC__)
# if (__POCC__ < 280)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# elif defined(_MSC_VER)
# define CURL_TYPEOF_CURL_OFF_T __int64
# define CURL_FORMAT_CURL_OFF_T "I64d"
# define CURL_FORMAT_CURL_OFF_TU "I64u"
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__LCC__)
# if defined(__e2k__) /* MCST eLbrus C Compiler */
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_SYS_SOCKET_H 1
# else /* Local (or Little) C Compiler */
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# define CURL_TYPEOF_CURL_SOCKLEN_T int
# endif
#elif defined(__SYMBIAN32__)
# if defined(__EABI__) /* Treat all ARM compilers equally */
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__CW32__)
# pragma longlong on
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__VC32__)
# define CURL_TYPEOF_CURL_OFF_T __int64
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
#elif defined(__MWERKS__)
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(_WIN32_WCE)
# define CURL_TYPEOF_CURL_OFF_T __int64
# define CURL_FORMAT_CURL_OFF_T "I64d"
# define CURL_FORMAT_CURL_OFF_TU "I64u"
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__MINGW32__)
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "I64d"
# define CURL_FORMAT_CURL_OFF_TU "I64u"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_WS2TCPIP_H 1
#elif defined(__VMS)
# if defined(__VAX)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# else
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
#elif defined(__OS400__)
# if defined(__ILEC400__)
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_SYS_SOCKET_H 1
# endif
#elif defined(__MVS__)
# if defined(__IBMC__) || defined(__IBMCPP__)
# if defined(_ILP32)
# elif defined(_LP64)
# endif
# if defined(_LONG_LONG)
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(_LP64)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# else
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_SYS_SOCKET_H 1
# endif
#elif defined(__370__)
# if defined(__IBMC__) || defined(__IBMCPP__)
# if defined(_ILP32)
# elif defined(_LP64)
# endif
# if defined(_LONG_LONG)
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(_LP64)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# else
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_SYS_SOCKET_H 1
# endif
#elif defined(TPF)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__TINYC__) /* also known as tcc */
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_SYS_SOCKET_H 1
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Oracle Solaris Studio */
# if !defined(__LP64) && (defined(__ILP32) || \
defined(__i386) || \
defined(__sparcv8) || \
defined(__sparcv8plus))
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__LP64) || \
defined(__amd64) || defined(__sparcv9)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_SYS_SOCKET_H 1
#elif defined(__xlc__) /* IBM xlc compiler */
# if !defined(_LP64)
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# else
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_SYS_SOCKET_H 1
/* ===================================== */
/* KEEP MSVC THE PENULTIMATE ENTRY */
/* ===================================== */
#elif defined(_MSC_VER)
# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
# define CURL_TYPEOF_CURL_OFF_T __int64
# define CURL_FORMAT_CURL_OFF_T "I64d"
# define CURL_FORMAT_CURL_OFF_TU "I64u"
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T int
/* ===================================== */
/* KEEP GENERIC GCC THE LAST ENTRY */
/* ===================================== */
#elif defined(__GNUC__) && !defined(_SCO_DS)
# if !defined(__LP64__) && \
(defined(__ILP32__) || defined(__i386__) || defined(__hppa__) || \
defined(__ppc__) || defined(__powerpc__) || defined(__arm__) || \
defined(__sparc__) || defined(__mips__) || defined(__sh__) || \
defined(__XTENSA__) || \
(defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 4) || \
(defined(__LONG_MAX__) && __LONG_MAX__ == 2147483647L))
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__LP64__) || \
defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) || \
defined(__e2k__) || \
(defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 8) || \
(defined(__LONG_MAX__) && __LONG_MAX__ == 9223372036854775807L)
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
# define CURL_PULL_SYS_TYPES_H 1
# define CURL_PULL_SYS_SOCKET_H 1
#else
/* generic "safe guess" on old 32 bit style */
# define CURL_TYPEOF_CURL_OFF_T long
# define CURL_FORMAT_CURL_OFF_T "ld"
# define CURL_FORMAT_CURL_OFF_TU "lu"
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# define CURL_TYPEOF_CURL_SOCKLEN_T int
#endif
#ifdef _AIX
/* AIX needs <sys/poll.h> */
#define CURL_PULL_SYS_POLL_H
#endif
/* CURL_PULL_WS2TCPIP_H is defined above when inclusion of header file */
/* ws2tcpip.h is required here to properly make type definitions below. */
#ifdef CURL_PULL_WS2TCPIP_H
# include <winsock2.h>
# include <windows.h>
# include <ws2tcpip.h>
#endif
/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */
/* sys/types.h is required here to properly make type definitions below. */
#ifdef CURL_PULL_SYS_TYPES_H
# include <sys/types.h>
#endif
/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */
/* sys/socket.h is required here to properly make type definitions below. */
#ifdef CURL_PULL_SYS_SOCKET_H
# include <sys/socket.h>
#endif
/* CURL_PULL_SYS_POLL_H is defined above when inclusion of header file */
/* sys/poll.h is required here to properly make type definitions below. */
#ifdef CURL_PULL_SYS_POLL_H
# include <sys/poll.h>
#endif
/* Data type definition of curl_socklen_t. */
#ifdef CURL_TYPEOF_CURL_SOCKLEN_T
typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t;
#endif
/* Data type definition of curl_off_t. */
#ifdef CURL_TYPEOF_CURL_OFF_T
typedef CURL_TYPEOF_CURL_OFF_T curl_off_t;
#endif
/*
* CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow
* these to be visible and exported by the external libcurl interface API,
* while also making them visible to the library internals, simply including
* curl_setup.h, without actually needing to include curl.h internally.
* If some day this section would grow big enough, all this should be moved
* to its own header file.
*/
/*
* Figure out if we can use the ## preprocessor operator, which is supported
* by ISO/ANSI C and C++. Some compilers support it without setting __STDC__
* or __cplusplus so we need to carefully check for them too.
*/
#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
defined(__ILEC400__)
/* This compiler is believed to have an ISO compatible preprocessor */
#define CURL_ISOCPP
#else
/* This compiler is believed NOT to have an ISO compatible preprocessor */
#undef CURL_ISOCPP
#endif
/*
* Macros for minimum-width signed and unsigned curl_off_t integer constants.
*/
#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551)
# define CURLINC_OFF_T_C_HLPR2(x) x
# define CURLINC_OFF_T_C_HLPR1(x) CURLINC_OFF_T_C_HLPR2(x)
# define CURL_OFF_T_C(Val) CURLINC_OFF_T_C_HLPR1(Val) ## \
CURLINC_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T)
# define CURL_OFF_TU_C(Val) CURLINC_OFF_T_C_HLPR1(Val) ## \
CURLINC_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU)
#else
# ifdef CURL_ISOCPP
# define CURLINC_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix
# else
# define CURLINC_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix
# endif
# define CURLINC_OFF_T_C_HLPR1(Val,Suffix) CURLINC_OFF_T_C_HLPR2(Val,Suffix)
# define CURL_OFF_T_C(Val) CURLINC_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T)
# define CURL_OFF_TU_C(Val) CURLINC_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU)
#endif
#endif /* CURLINC_SYSTEM_H */

View file

@ -0,0 +1,699 @@
#ifndef CURLINC_TYPECHECK_GCC_H
#define CURLINC_TYPECHECK_GCC_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
/* wraps curl_easy_setopt() with typechecking */
/* To add a new kind of warning, add an
* if(curlcheck_sometype_option(_curl_opt))
* if(!curlcheck_sometype(value))
* _curl_easy_setopt_err_sometype();
* block and define curlcheck_sometype_option, curlcheck_sometype and
* _curl_easy_setopt_err_sometype below
*
* NOTE: We use two nested 'if' statements here instead of the && operator, in
* order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x
* when compiling with -Wlogical-op.
*
* To add an option that uses the same type as an existing option, you'll just
* need to extend the appropriate _curl_*_option macro
*/
#define curl_easy_setopt(handle, option, value) \
__extension__({ \
__typeof__(option) _curl_opt = option; \
if(__builtin_constant_p(_curl_opt)) { \
if(curlcheck_long_option(_curl_opt)) \
if(!curlcheck_long(value)) \
_curl_easy_setopt_err_long(); \
if(curlcheck_off_t_option(_curl_opt)) \
if(!curlcheck_off_t(value)) \
_curl_easy_setopt_err_curl_off_t(); \
if(curlcheck_string_option(_curl_opt)) \
if(!curlcheck_string(value)) \
_curl_easy_setopt_err_string(); \
if(curlcheck_write_cb_option(_curl_opt)) \
if(!curlcheck_write_cb(value)) \
_curl_easy_setopt_err_write_callback(); \
if((_curl_opt) == CURLOPT_RESOLVER_START_FUNCTION) \
if(!curlcheck_resolver_start_callback(value)) \
_curl_easy_setopt_err_resolver_start_callback(); \
if((_curl_opt) == CURLOPT_READFUNCTION) \
if(!curlcheck_read_cb(value)) \
_curl_easy_setopt_err_read_cb(); \
if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \
if(!curlcheck_ioctl_cb(value)) \
_curl_easy_setopt_err_ioctl_cb(); \
if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \
if(!curlcheck_sockopt_cb(value)) \
_curl_easy_setopt_err_sockopt_cb(); \
if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \
if(!curlcheck_opensocket_cb(value)) \
_curl_easy_setopt_err_opensocket_cb(); \
if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \
if(!curlcheck_progress_cb(value)) \
_curl_easy_setopt_err_progress_cb(); \
if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \
if(!curlcheck_debug_cb(value)) \
_curl_easy_setopt_err_debug_cb(); \
if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \
if(!curlcheck_ssl_ctx_cb(value)) \
_curl_easy_setopt_err_ssl_ctx_cb(); \
if(curlcheck_conv_cb_option(_curl_opt)) \
if(!curlcheck_conv_cb(value)) \
_curl_easy_setopt_err_conv_cb(); \
if((_curl_opt) == CURLOPT_SEEKFUNCTION) \
if(!curlcheck_seek_cb(value)) \
_curl_easy_setopt_err_seek_cb(); \
if(curlcheck_cb_data_option(_curl_opt)) \
if(!curlcheck_cb_data(value)) \
_curl_easy_setopt_err_cb_data(); \
if((_curl_opt) == CURLOPT_ERRORBUFFER) \
if(!curlcheck_error_buffer(value)) \
_curl_easy_setopt_err_error_buffer(); \
if((_curl_opt) == CURLOPT_STDERR) \
if(!curlcheck_FILE(value)) \
_curl_easy_setopt_err_FILE(); \
if(curlcheck_postfields_option(_curl_opt)) \
if(!curlcheck_postfields(value)) \
_curl_easy_setopt_err_postfields(); \
if((_curl_opt) == CURLOPT_HTTPPOST) \
if(!curlcheck_arr((value), struct curl_httppost)) \
_curl_easy_setopt_err_curl_httpost(); \
if((_curl_opt) == CURLOPT_MIMEPOST) \
if(!curlcheck_ptr((value), curl_mime)) \
_curl_easy_setopt_err_curl_mimepost(); \
if(curlcheck_slist_option(_curl_opt)) \
if(!curlcheck_arr((value), struct curl_slist)) \
_curl_easy_setopt_err_curl_slist(); \
if((_curl_opt) == CURLOPT_SHARE) \
if(!curlcheck_ptr((value), CURLSH)) \
_curl_easy_setopt_err_CURLSH(); \
} \
curl_easy_setopt(handle, _curl_opt, value); \
})
/* wraps curl_easy_getinfo() with typechecking */
#define curl_easy_getinfo(handle, info, arg) \
__extension__({ \
__typeof__(info) _curl_info = info; \
if(__builtin_constant_p(_curl_info)) { \
if(curlcheck_string_info(_curl_info)) \
if(!curlcheck_arr((arg), char *)) \
_curl_easy_getinfo_err_string(); \
if(curlcheck_long_info(_curl_info)) \
if(!curlcheck_arr((arg), long)) \
_curl_easy_getinfo_err_long(); \
if(curlcheck_double_info(_curl_info)) \
if(!curlcheck_arr((arg), double)) \
_curl_easy_getinfo_err_double(); \
if(curlcheck_slist_info(_curl_info)) \
if(!curlcheck_arr((arg), struct curl_slist *)) \
_curl_easy_getinfo_err_curl_slist(); \
if(curlcheck_tlssessioninfo_info(_curl_info)) \
if(!curlcheck_arr((arg), struct curl_tlssessioninfo *)) \
_curl_easy_getinfo_err_curl_tlssesssioninfo(); \
if(curlcheck_certinfo_info(_curl_info)) \
if(!curlcheck_arr((arg), struct curl_certinfo *)) \
_curl_easy_getinfo_err_curl_certinfo(); \
if(curlcheck_socket_info(_curl_info)) \
if(!curlcheck_arr((arg), curl_socket_t)) \
_curl_easy_getinfo_err_curl_socket(); \
if(curlcheck_off_t_info(_curl_info)) \
if(!curlcheck_arr((arg), curl_off_t)) \
_curl_easy_getinfo_err_curl_off_t(); \
} \
curl_easy_getinfo(handle, _curl_info, arg); \
})
/*
* For now, just make sure that the functions are called with three arguments
*/
#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param)
#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param)
/* the actual warnings, triggered by calling the _curl_easy_setopt_err*
* functions */
/* To define a new warning, use _CURL_WARNING(identifier, "message") */
#define CURLWARNING(id, message) \
static void __attribute__((__warning__(message))) \
__attribute__((__unused__)) __attribute__((__noinline__)) \
id(void) { __asm__(""); }
CURLWARNING(_curl_easy_setopt_err_long,
"curl_easy_setopt expects a long argument for this option")
CURLWARNING(_curl_easy_setopt_err_curl_off_t,
"curl_easy_setopt expects a curl_off_t argument for this option")
CURLWARNING(_curl_easy_setopt_err_string,
"curl_easy_setopt expects a "
"string ('char *' or char[]) argument for this option"
)
CURLWARNING(_curl_easy_setopt_err_write_callback,
"curl_easy_setopt expects a curl_write_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_resolver_start_callback,
"curl_easy_setopt expects a "
"curl_resolver_start_callback argument for this option"
)
CURLWARNING(_curl_easy_setopt_err_read_cb,
"curl_easy_setopt expects a curl_read_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_ioctl_cb,
"curl_easy_setopt expects a curl_ioctl_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_sockopt_cb,
"curl_easy_setopt expects a curl_sockopt_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_opensocket_cb,
"curl_easy_setopt expects a "
"curl_opensocket_callback argument for this option"
)
CURLWARNING(_curl_easy_setopt_err_progress_cb,
"curl_easy_setopt expects a curl_progress_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_debug_cb,
"curl_easy_setopt expects a curl_debug_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_ssl_ctx_cb,
"curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_conv_cb,
"curl_easy_setopt expects a curl_conv_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_seek_cb,
"curl_easy_setopt expects a curl_seek_callback argument for this option")
CURLWARNING(_curl_easy_setopt_err_cb_data,
"curl_easy_setopt expects a "
"private data pointer as argument for this option")
CURLWARNING(_curl_easy_setopt_err_error_buffer,
"curl_easy_setopt expects a "
"char buffer of CURL_ERROR_SIZE as argument for this option")
CURLWARNING(_curl_easy_setopt_err_FILE,
"curl_easy_setopt expects a 'FILE *' argument for this option")
CURLWARNING(_curl_easy_setopt_err_postfields,
"curl_easy_setopt expects a 'void *' or 'char *' argument for this option")
CURLWARNING(_curl_easy_setopt_err_curl_httpost,
"curl_easy_setopt expects a 'struct curl_httppost *' "
"argument for this option")
CURLWARNING(_curl_easy_setopt_err_curl_mimepost,
"curl_easy_setopt expects a 'curl_mime *' "
"argument for this option")
CURLWARNING(_curl_easy_setopt_err_curl_slist,
"curl_easy_setopt expects a 'struct curl_slist *' argument for this option")
CURLWARNING(_curl_easy_setopt_err_CURLSH,
"curl_easy_setopt expects a CURLSH* argument for this option")
CURLWARNING(_curl_easy_getinfo_err_string,
"curl_easy_getinfo expects a pointer to 'char *' for this info")
CURLWARNING(_curl_easy_getinfo_err_long,
"curl_easy_getinfo expects a pointer to long for this info")
CURLWARNING(_curl_easy_getinfo_err_double,
"curl_easy_getinfo expects a pointer to double for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_slist,
"curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_tlssesssioninfo,
"curl_easy_getinfo expects a pointer to "
"'struct curl_tlssessioninfo *' for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_certinfo,
"curl_easy_getinfo expects a pointer to "
"'struct curl_certinfo *' for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_socket,
"curl_easy_getinfo expects a pointer to curl_socket_t for this info")
CURLWARNING(_curl_easy_getinfo_err_curl_off_t,
"curl_easy_getinfo expects a pointer to curl_off_t for this info")
/* groups of curl_easy_setops options that take the same type of argument */
/* To add a new option to one of the groups, just add
* (option) == CURLOPT_SOMETHING
* to the or-expression. If the option takes a long or curl_off_t, you don't
* have to do anything
*/
/* evaluates to true if option takes a long argument */
#define curlcheck_long_option(option) \
(0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT)
#define curlcheck_off_t_option(option) \
((option) > CURLOPTTYPE_OFF_T)
/* evaluates to true if option takes a char* argument */
#define curlcheck_string_option(option) \
((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \
(option) == CURLOPT_ACCEPT_ENCODING || \
(option) == CURLOPT_ALTSVC || \
(option) == CURLOPT_CAINFO || \
(option) == CURLOPT_CAPATH || \
(option) == CURLOPT_COOKIE || \
(option) == CURLOPT_COOKIEFILE || \
(option) == CURLOPT_COOKIEJAR || \
(option) == CURLOPT_COOKIELIST || \
(option) == CURLOPT_CRLFILE || \
(option) == CURLOPT_CUSTOMREQUEST || \
(option) == CURLOPT_DEFAULT_PROTOCOL || \
(option) == CURLOPT_DNS_INTERFACE || \
(option) == CURLOPT_DNS_LOCAL_IP4 || \
(option) == CURLOPT_DNS_LOCAL_IP6 || \
(option) == CURLOPT_DNS_SERVERS || \
(option) == CURLOPT_DOH_URL || \
(option) == CURLOPT_EGDSOCKET || \
(option) == CURLOPT_FTPPORT || \
(option) == CURLOPT_FTP_ACCOUNT || \
(option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \
(option) == CURLOPT_INTERFACE || \
(option) == CURLOPT_ISSUERCERT || \
(option) == CURLOPT_KEYPASSWD || \
(option) == CURLOPT_KRBLEVEL || \
(option) == CURLOPT_LOGIN_OPTIONS || \
(option) == CURLOPT_MAIL_AUTH || \
(option) == CURLOPT_MAIL_FROM || \
(option) == CURLOPT_NETRC_FILE || \
(option) == CURLOPT_NOPROXY || \
(option) == CURLOPT_PASSWORD || \
(option) == CURLOPT_PINNEDPUBLICKEY || \
(option) == CURLOPT_PRE_PROXY || \
(option) == CURLOPT_PROXY || \
(option) == CURLOPT_PROXYPASSWORD || \
(option) == CURLOPT_PROXYUSERNAME || \
(option) == CURLOPT_PROXYUSERPWD || \
(option) == CURLOPT_PROXY_CAINFO || \
(option) == CURLOPT_PROXY_CAPATH || \
(option) == CURLOPT_PROXY_CRLFILE || \
(option) == CURLOPT_PROXY_KEYPASSWD || \
(option) == CURLOPT_PROXY_PINNEDPUBLICKEY || \
(option) == CURLOPT_PROXY_SERVICE_NAME || \
(option) == CURLOPT_PROXY_SSLCERT || \
(option) == CURLOPT_PROXY_SSLCERTTYPE || \
(option) == CURLOPT_PROXY_SSLKEY || \
(option) == CURLOPT_PROXY_SSLKEYTYPE || \
(option) == CURLOPT_PROXY_SSL_CIPHER_LIST || \
(option) == CURLOPT_PROXY_TLS13_CIPHERS || \
(option) == CURLOPT_PROXY_TLSAUTH_PASSWORD || \
(option) == CURLOPT_PROXY_TLSAUTH_TYPE || \
(option) == CURLOPT_PROXY_TLSAUTH_USERNAME || \
(option) == CURLOPT_RANDOM_FILE || \
(option) == CURLOPT_RANGE || \
(option) == CURLOPT_REFERER || \
(option) == CURLOPT_REQUEST_TARGET || \
(option) == CURLOPT_RTSP_SESSION_ID || \
(option) == CURLOPT_RTSP_STREAM_URI || \
(option) == CURLOPT_RTSP_TRANSPORT || \
(option) == CURLOPT_SASL_AUTHZID || \
(option) == CURLOPT_SERVICE_NAME || \
(option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \
(option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \
(option) == CURLOPT_SSH_KNOWNHOSTS || \
(option) == CURLOPT_SSH_PRIVATE_KEYFILE || \
(option) == CURLOPT_SSH_PUBLIC_KEYFILE || \
(option) == CURLOPT_SSLCERT || \
(option) == CURLOPT_SSLCERTTYPE || \
(option) == CURLOPT_SSLENGINE || \
(option) == CURLOPT_SSLKEY || \
(option) == CURLOPT_SSLKEYTYPE || \
(option) == CURLOPT_SSL_CIPHER_LIST || \
(option) == CURLOPT_TLS13_CIPHERS || \
(option) == CURLOPT_TLSAUTH_PASSWORD || \
(option) == CURLOPT_TLSAUTH_TYPE || \
(option) == CURLOPT_TLSAUTH_USERNAME || \
(option) == CURLOPT_UNIX_SOCKET_PATH || \
(option) == CURLOPT_URL || \
(option) == CURLOPT_USERAGENT || \
(option) == CURLOPT_USERNAME || \
(option) == CURLOPT_USERPWD || \
(option) == CURLOPT_XOAUTH2_BEARER || \
0)
/* evaluates to true if option takes a curl_write_callback argument */
#define curlcheck_write_cb_option(option) \
((option) == CURLOPT_HEADERFUNCTION || \
(option) == CURLOPT_WRITEFUNCTION)
/* evaluates to true if option takes a curl_conv_callback argument */
#define curlcheck_conv_cb_option(option) \
((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \
(option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \
(option) == CURLOPT_CONV_FROM_UTF8_FUNCTION)
/* evaluates to true if option takes a data argument to pass to a callback */
#define curlcheck_cb_data_option(option) \
((option) == CURLOPT_CHUNK_DATA || \
(option) == CURLOPT_CLOSESOCKETDATA || \
(option) == CURLOPT_DEBUGDATA || \
(option) == CURLOPT_FNMATCH_DATA || \
(option) == CURLOPT_HEADERDATA || \
(option) == CURLOPT_INTERLEAVEDATA || \
(option) == CURLOPT_IOCTLDATA || \
(option) == CURLOPT_OPENSOCKETDATA || \
(option) == CURLOPT_PRIVATE || \
(option) == CURLOPT_PROGRESSDATA || \
(option) == CURLOPT_READDATA || \
(option) == CURLOPT_SEEKDATA || \
(option) == CURLOPT_SOCKOPTDATA || \
(option) == CURLOPT_SSH_KEYDATA || \
(option) == CURLOPT_SSL_CTX_DATA || \
(option) == CURLOPT_WRITEDATA || \
(option) == CURLOPT_RESOLVER_START_DATA || \
(option) == CURLOPT_TRAILERDATA || \
0)
/* evaluates to true if option takes a POST data argument (void* or char*) */
#define curlcheck_postfields_option(option) \
((option) == CURLOPT_POSTFIELDS || \
(option) == CURLOPT_COPYPOSTFIELDS || \
0)
/* evaluates to true if option takes a struct curl_slist * argument */
#define curlcheck_slist_option(option) \
((option) == CURLOPT_HTTP200ALIASES || \
(option) == CURLOPT_HTTPHEADER || \
(option) == CURLOPT_MAIL_RCPT || \
(option) == CURLOPT_POSTQUOTE || \
(option) == CURLOPT_PREQUOTE || \
(option) == CURLOPT_PROXYHEADER || \
(option) == CURLOPT_QUOTE || \
(option) == CURLOPT_RESOLVE || \
(option) == CURLOPT_TELNETOPTIONS || \
(option) == CURLOPT_CONNECT_TO || \
0)
/* groups of curl_easy_getinfo infos that take the same type of argument */
/* evaluates to true if info expects a pointer to char * argument */
#define curlcheck_string_info(info) \
(CURLINFO_STRING < (info) && (info) < CURLINFO_LONG)
/* evaluates to true if info expects a pointer to long argument */
#define curlcheck_long_info(info) \
(CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE)
/* evaluates to true if info expects a pointer to double argument */
#define curlcheck_double_info(info) \
(CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST)
/* true if info expects a pointer to struct curl_slist * argument */
#define curlcheck_slist_info(info) \
(((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST))
/* true if info expects a pointer to struct curl_tlssessioninfo * argument */
#define curlcheck_tlssessioninfo_info(info) \
(((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION))
/* true if info expects a pointer to struct curl_certinfo * argument */
#define curlcheck_certinfo_info(info) ((info) == CURLINFO_CERTINFO)
/* true if info expects a pointer to struct curl_socket_t argument */
#define curlcheck_socket_info(info) \
(CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T)
/* true if info expects a pointer to curl_off_t argument */
#define curlcheck_off_t_info(info) \
(CURLINFO_OFF_T < (info))
/* typecheck helpers -- check whether given expression has requested type*/
/* For pointers, you can use the curlcheck_ptr/curlcheck_arr macros,
* otherwise define a new macro. Search for __builtin_types_compatible_p
* in the GCC manual.
* NOTE: these macros MUST NOT EVALUATE their arguments! The argument is
* the actual expression passed to the curl_easy_setopt macro. This
* means that you can only apply the sizeof and __typeof__ operators, no
* == or whatsoever.
*/
/* XXX: should evaluate to true if expr is a pointer */
#define curlcheck_any_ptr(expr) \
(sizeof(expr) == sizeof(void *))
/* evaluates to true if expr is NULL */
/* XXX: must not evaluate expr, so this check is not accurate */
#define curlcheck_NULL(expr) \
(__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL)))
/* evaluates to true if expr is type*, const type* or NULL */
#define curlcheck_ptr(expr, type) \
(curlcheck_NULL(expr) || \
__builtin_types_compatible_p(__typeof__(expr), type *) || \
__builtin_types_compatible_p(__typeof__(expr), const type *))
/* evaluates to true if expr is one of type[], type*, NULL or const type* */
#define curlcheck_arr(expr, type) \
(curlcheck_ptr((expr), type) || \
__builtin_types_compatible_p(__typeof__(expr), type []))
/* evaluates to true if expr is a string */
#define curlcheck_string(expr) \
(curlcheck_arr((expr), char) || \
curlcheck_arr((expr), signed char) || \
curlcheck_arr((expr), unsigned char))
/* evaluates to true if expr is a long (no matter the signedness)
* XXX: for now, int is also accepted (and therefore short and char, which
* are promoted to int when passed to a variadic function) */
#define curlcheck_long(expr) \
(__builtin_types_compatible_p(__typeof__(expr), long) || \
__builtin_types_compatible_p(__typeof__(expr), signed long) || \
__builtin_types_compatible_p(__typeof__(expr), unsigned long) || \
__builtin_types_compatible_p(__typeof__(expr), int) || \
__builtin_types_compatible_p(__typeof__(expr), signed int) || \
__builtin_types_compatible_p(__typeof__(expr), unsigned int) || \
__builtin_types_compatible_p(__typeof__(expr), short) || \
__builtin_types_compatible_p(__typeof__(expr), signed short) || \
__builtin_types_compatible_p(__typeof__(expr), unsigned short) || \
__builtin_types_compatible_p(__typeof__(expr), char) || \
__builtin_types_compatible_p(__typeof__(expr), signed char) || \
__builtin_types_compatible_p(__typeof__(expr), unsigned char))
/* evaluates to true if expr is of type curl_off_t */
#define curlcheck_off_t(expr) \
(__builtin_types_compatible_p(__typeof__(expr), curl_off_t))
/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */
/* XXX: also check size of an char[] array? */
#define curlcheck_error_buffer(expr) \
(curlcheck_NULL(expr) || \
__builtin_types_compatible_p(__typeof__(expr), char *) || \
__builtin_types_compatible_p(__typeof__(expr), char[]))
/* evaluates to true if expr is of type (const) void* or (const) FILE* */
#if 0
#define curlcheck_cb_data(expr) \
(curlcheck_ptr((expr), void) || \
curlcheck_ptr((expr), FILE))
#else /* be less strict */
#define curlcheck_cb_data(expr) \
curlcheck_any_ptr(expr)
#endif
/* evaluates to true if expr is of type FILE* */
#define curlcheck_FILE(expr) \
(curlcheck_NULL(expr) || \
(__builtin_types_compatible_p(__typeof__(expr), FILE *)))
/* evaluates to true if expr can be passed as POST data (void* or char*) */
#define curlcheck_postfields(expr) \
(curlcheck_ptr((expr), void) || \
curlcheck_arr((expr), char) || \
curlcheck_arr((expr), unsigned char))
/* helper: __builtin_types_compatible_p distinguishes between functions and
* function pointers, hide it */
#define curlcheck_cb_compatible(func, type) \
(__builtin_types_compatible_p(__typeof__(func), type) || \
__builtin_types_compatible_p(__typeof__(func) *, type))
/* evaluates to true if expr is of type curl_resolver_start_callback */
#define curlcheck_resolver_start_callback(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_resolver_start_callback))
/* evaluates to true if expr is of type curl_read_callback or "similar" */
#define curlcheck_read_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), __typeof__(fread) *) || \
curlcheck_cb_compatible((expr), curl_read_callback) || \
curlcheck_cb_compatible((expr), _curl_read_callback1) || \
curlcheck_cb_compatible((expr), _curl_read_callback2) || \
curlcheck_cb_compatible((expr), _curl_read_callback3) || \
curlcheck_cb_compatible((expr), _curl_read_callback4) || \
curlcheck_cb_compatible((expr), _curl_read_callback5) || \
curlcheck_cb_compatible((expr), _curl_read_callback6))
typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *);
typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *);
typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *);
typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *);
typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *);
typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *);
/* evaluates to true if expr is of type curl_write_callback or "similar" */
#define curlcheck_write_cb(expr) \
(curlcheck_read_cb(expr) || \
curlcheck_cb_compatible((expr), __typeof__(fwrite) *) || \
curlcheck_cb_compatible((expr), curl_write_callback) || \
curlcheck_cb_compatible((expr), _curl_write_callback1) || \
curlcheck_cb_compatible((expr), _curl_write_callback2) || \
curlcheck_cb_compatible((expr), _curl_write_callback3) || \
curlcheck_cb_compatible((expr), _curl_write_callback4) || \
curlcheck_cb_compatible((expr), _curl_write_callback5) || \
curlcheck_cb_compatible((expr), _curl_write_callback6))
typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *);
typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t,
const void *);
typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *);
typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *);
typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t,
const void *);
typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *);
/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */
#define curlcheck_ioctl_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_ioctl_callback) || \
curlcheck_cb_compatible((expr), _curl_ioctl_callback1) || \
curlcheck_cb_compatible((expr), _curl_ioctl_callback2) || \
curlcheck_cb_compatible((expr), _curl_ioctl_callback3) || \
curlcheck_cb_compatible((expr), _curl_ioctl_callback4))
typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *);
typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *);
typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *);
typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *);
/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */
#define curlcheck_sockopt_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_sockopt_callback) || \
curlcheck_cb_compatible((expr), _curl_sockopt_callback1) || \
curlcheck_cb_compatible((expr), _curl_sockopt_callback2))
typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype);
typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t,
curlsocktype);
/* evaluates to true if expr is of type curl_opensocket_callback or
"similar" */
#define curlcheck_opensocket_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_opensocket_callback) || \
curlcheck_cb_compatible((expr), _curl_opensocket_callback1) || \
curlcheck_cb_compatible((expr), _curl_opensocket_callback2) || \
curlcheck_cb_compatible((expr), _curl_opensocket_callback3) || \
curlcheck_cb_compatible((expr), _curl_opensocket_callback4))
typedef curl_socket_t (*_curl_opensocket_callback1)
(void *, curlsocktype, struct curl_sockaddr *);
typedef curl_socket_t (*_curl_opensocket_callback2)
(void *, curlsocktype, const struct curl_sockaddr *);
typedef curl_socket_t (*_curl_opensocket_callback3)
(const void *, curlsocktype, struct curl_sockaddr *);
typedef curl_socket_t (*_curl_opensocket_callback4)
(const void *, curlsocktype, const struct curl_sockaddr *);
/* evaluates to true if expr is of type curl_progress_callback or "similar" */
#define curlcheck_progress_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_progress_callback) || \
curlcheck_cb_compatible((expr), _curl_progress_callback1) || \
curlcheck_cb_compatible((expr), _curl_progress_callback2))
typedef int (*_curl_progress_callback1)(void *,
double, double, double, double);
typedef int (*_curl_progress_callback2)(const void *,
double, double, double, double);
/* evaluates to true if expr is of type curl_debug_callback or "similar" */
#define curlcheck_debug_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_debug_callback) || \
curlcheck_cb_compatible((expr), _curl_debug_callback1) || \
curlcheck_cb_compatible((expr), _curl_debug_callback2) || \
curlcheck_cb_compatible((expr), _curl_debug_callback3) || \
curlcheck_cb_compatible((expr), _curl_debug_callback4) || \
curlcheck_cb_compatible((expr), _curl_debug_callback5) || \
curlcheck_cb_compatible((expr), _curl_debug_callback6) || \
curlcheck_cb_compatible((expr), _curl_debug_callback7) || \
curlcheck_cb_compatible((expr), _curl_debug_callback8))
typedef int (*_curl_debug_callback1) (CURL *,
curl_infotype, char *, size_t, void *);
typedef int (*_curl_debug_callback2) (CURL *,
curl_infotype, char *, size_t, const void *);
typedef int (*_curl_debug_callback3) (CURL *,
curl_infotype, const char *, size_t, void *);
typedef int (*_curl_debug_callback4) (CURL *,
curl_infotype, const char *, size_t, const void *);
typedef int (*_curl_debug_callback5) (CURL *,
curl_infotype, unsigned char *, size_t, void *);
typedef int (*_curl_debug_callback6) (CURL *,
curl_infotype, unsigned char *, size_t, const void *);
typedef int (*_curl_debug_callback7) (CURL *,
curl_infotype, const unsigned char *, size_t, void *);
typedef int (*_curl_debug_callback8) (CURL *,
curl_infotype, const unsigned char *, size_t, const void *);
/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */
/* this is getting even messier... */
#define curlcheck_ssl_ctx_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_ssl_ctx_callback) || \
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback1) || \
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback2) || \
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback3) || \
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback4) || \
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback5) || \
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback6) || \
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback7) || \
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback8))
typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *);
typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *);
typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *);
typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *,
const void *);
#ifdef HEADER_SSL_H
/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX
* this will of course break if we're included before OpenSSL headers...
*/
typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *);
typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *);
typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *);
typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX,
const void *);
#else
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5;
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6;
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7;
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8;
#endif
/* evaluates to true if expr is of type curl_conv_callback or "similar" */
#define curlcheck_conv_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_conv_callback) || \
curlcheck_cb_compatible((expr), _curl_conv_callback1) || \
curlcheck_cb_compatible((expr), _curl_conv_callback2) || \
curlcheck_cb_compatible((expr), _curl_conv_callback3) || \
curlcheck_cb_compatible((expr), _curl_conv_callback4))
typedef CURLcode (*_curl_conv_callback1)(char *, size_t length);
typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length);
typedef CURLcode (*_curl_conv_callback3)(void *, size_t length);
typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length);
/* evaluates to true if expr is of type curl_seek_callback or "similar" */
#define curlcheck_seek_cb(expr) \
(curlcheck_NULL(expr) || \
curlcheck_cb_compatible((expr), curl_seek_callback) || \
curlcheck_cb_compatible((expr), _curl_seek_callback1) || \
curlcheck_cb_compatible((expr), _curl_seek_callback2))
typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int);
typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int);
#endif /* CURLINC_TYPECHECK_GCC_H */

View file

@ -0,0 +1,125 @@
#ifndef CURLINC_URLAPI_H
#define CURLINC_URLAPI_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2018 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curl.h"
#ifdef __cplusplus
extern "C" {
#endif
/* the error codes for the URL API */
typedef enum {
CURLUE_OK,
CURLUE_BAD_HANDLE, /* 1 */
CURLUE_BAD_PARTPOINTER, /* 2 */
CURLUE_MALFORMED_INPUT, /* 3 */
CURLUE_BAD_PORT_NUMBER, /* 4 */
CURLUE_UNSUPPORTED_SCHEME, /* 5 */
CURLUE_URLDECODE, /* 6 */
CURLUE_OUT_OF_MEMORY, /* 7 */
CURLUE_USER_NOT_ALLOWED, /* 8 */
CURLUE_UNKNOWN_PART, /* 9 */
CURLUE_NO_SCHEME, /* 10 */
CURLUE_NO_USER, /* 11 */
CURLUE_NO_PASSWORD, /* 12 */
CURLUE_NO_OPTIONS, /* 13 */
CURLUE_NO_HOST, /* 14 */
CURLUE_NO_PORT, /* 15 */
CURLUE_NO_QUERY, /* 16 */
CURLUE_NO_FRAGMENT /* 17 */
} CURLUcode;
typedef enum {
CURLUPART_URL,
CURLUPART_SCHEME,
CURLUPART_USER,
CURLUPART_PASSWORD,
CURLUPART_OPTIONS,
CURLUPART_HOST,
CURLUPART_PORT,
CURLUPART_PATH,
CURLUPART_QUERY,
CURLUPART_FRAGMENT,
CURLUPART_ZONEID /* added in 7.65.0 */
} CURLUPart;
#define CURLU_DEFAULT_PORT (1<<0) /* return default port number */
#define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set,
if the port number matches the
default for the scheme */
#define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if
missing */
#define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */
#define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */
#define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */
#define CURLU_URLDECODE (1<<6) /* URL decode on get */
#define CURLU_URLENCODE (1<<7) /* URL encode on set */
#define CURLU_APPENDQUERY (1<<8) /* append a form style part */
#define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */
#define CURLU_NO_AUTHORITY (1<<10) /* Allow empty authority when the
scheme is unknown. */
typedef struct Curl_URL CURLU;
/*
* curl_url() creates a new CURLU handle and returns a pointer to it.
* Must be freed with curl_url_cleanup().
*/
CURL_EXTERN CURLU *curl_url(void);
/*
* curl_url_cleanup() frees the CURLU handle and related resources used for
* the URL parsing. It will not free strings previously returned with the URL
* API.
*/
CURL_EXTERN void curl_url_cleanup(CURLU *handle);
/*
* curl_url_dup() duplicates a CURLU handle and returns a new copy. The new
* handle must also be freed with curl_url_cleanup().
*/
CURL_EXTERN CURLU *curl_url_dup(CURLU *in);
/*
* curl_url_get() extracts a specific part of the URL from a CURLU
* handle. Returns error code. The returned pointer MUST be freed with
* curl_free() afterwards.
*/
CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what,
char **part, unsigned int flags);
/*
* curl_url_set() sets a specific part of the URL in a CURLU handle. Returns
* error code. The passed in string will be copied. Passing a NULL instead of
* a part string, clears that part.
*/
CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what,
const char *part, unsigned int flags);
#ifdef __cplusplus
} /* end of extern "C" */
#endif
#endif /* CURLINC_URLAPI_H */

Binary file not shown.

BIN
lib/curl/7.70.0/libcurl.dll Normal file

Binary file not shown.

BIN
lib/curl/7.70.0/libcurl.lib Normal file

Binary file not shown.

Binary file not shown.

View file

@ -1,5 +1,6 @@
set(BNETD_SOURCES
account.cpp account.h account_wrap.cpp account_wrap.h adbanner.cpp
account.cpp account.h account_email_verification.cpp account_email_verification.h
account_wrap.cpp account_wrap.h adbanner.cpp
adbanner.h alias_command.cpp alias_command.h anongame.cpp
anongame_gameresult.cpp anongame_gameresult.h anongame.h
anongame_infos.cpp anongame_infos.h anongame_maplists.cpp
@ -7,8 +8,8 @@ set(BNETD_SOURCES
attrlayer.h autoupdate.cpp autoupdate.h channel_conv.cpp channel_conv.h
channel.cpp channel.h character.cpp character.h clan.cpp clan.h
cmdline.cpp cmdline.h command.cpp command_groups.cpp command_groups.h
command.h connection.cpp connection.h file.cpp file.h file_plain.cpp
file_plain.h friends.cpp friends.h game_conv.cpp
command.h connection.cpp connection.h file.cpp file.h
file_plain.cpp file_plain.h friends.cpp friends.h game_conv.cpp
game_conv.h game.cpp game.h handle_anongame.cpp handle_anongame.h
handle_apireg.cpp handle_apireg.h handle_bnet.cpp handle_bnet.h
handle_bot.cpp handle_bot.h handle_d2cs.cpp handle_d2cs.h
@ -20,9 +21,9 @@ set(BNETD_SOURCES
ipban.cpp ipban.h irc.cpp irc.h ladder_calc.cpp ladder_calc.h ladder.cpp
ladder.h mail.cpp mail.h main.cpp message.cpp message.h news.cpp news.h
output.cpp output.h prefs.cpp prefs.h quota.h realm.cpp realm.h
runprog.cpp runprog.h server.cpp server.h sql_common.cpp sql_common.h
sql_dbcreator.cpp sql_dbcreator.h sql_mysql.cpp sql_mysql.h sql_odbc.cpp
sql_odbc.h sql_pgsql.cpp sql_pgsql.h sql_sqlite3.cpp sql_sqlite3.h
runprog.cpp runprog.h server.cpp server.h smtp.cpp smtp.h sql_common.cpp
sql_common.h sql_dbcreator.cpp sql_dbcreator.h sql_mysql.cpp sql_mysql.h
sql_odbc.cpp sql_odbc.h sql_pgsql.cpp sql_pgsql.h sql_sqlite3.cpp sql_sqlite3.h
storage.cpp storage_file.cpp storage_file.h storage.h
storage_sql.cpp storage_sql.h support.cpp support.h
team.cpp team.h tick.cpp tick.h timer.cpp timer.h topic.cpp topic.h
@ -51,6 +52,7 @@ endif(WITH_WIN32_GUI)
target_include_directories(bnetd
PRIVATE
${ZLIB_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
${LUA_INCLUDE_DIR}
${MYSQL_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
@ -58,7 +60,7 @@ target_include_directories(bnetd
${ODBC_INCLUDE_DIR}
)
target_link_libraries(bnetd PRIVATE common compat fmt win32 ${NETWORK_LIBRARIES} ${ZLIB_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES} ${PGSQL_LIBRARIES} ${ODBC_LIBRARIES} ${LUA_LIBRARIES})
target_link_libraries(bnetd PRIVATE common compat fmt win32 ${NETWORK_LIBRARIES} ${ZLIB_LIBRARIES} ${CURL_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES} ${PGSQL_LIBRARIES} ${ODBC_LIBRARIES} ${LUA_LIBRARIES})
install(TARGETS bnetd DESTINATION ${SBINDIR})
@ -73,4 +75,4 @@ if (WIN32 AND USE_INCLUDED_ZLIB_LIBRARY)
DESTINATION
${SBINDIR}
)
endif()
endif()

View file

@ -0,0 +1,194 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "common/setup_before.h"
#include "account_email_verification.h"
#include <fstream>
#include <iterator>
#include <limits>
#include <random>
#include <string>
#include <curl/curl.h>
#include "common/eventlog.h"
#include "account.h"
#include "account_wrap.h"
#include "prefs.h"
#include "server.h"
#include "smtp.h"
#include "common/setup_after.h"
namespace pvpgn
{
namespace bnetd
{
static std::string message;
static std::string verify_account_email_from_address;
static std::string verify_account_email_from_name;
bool account_email_verification_load(const char* filepath, const char* prefs_servername, const char* prefs_verify_account_email_from_address, const char* prefs_verify_account_email_from_name)
{
if (filepath == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL filepath");
return false;
}
if (prefs_servername == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL prefs_servername");
return false;
}
if (prefs_verify_account_email_from_address == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL prefs_verify_account_email_from_address");
return false;
}
if (prefs_verify_account_email_from_name == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL prefs_verify_account_email_from_name");
return false;
}
std::ifstream infile{ filepath };
if (!infile.is_open())
{
eventlog(eventlog_level_error, __FUNCTION__, "Could not open email verification message file ({})", filepath);
return false;
}
try
{
std::string raw_message{ std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>() };
message = fmt::format(raw_message, fmt::arg("pvpgn_server_name", prefs_servername));
eventlog(eventlog_level_info, __FUNCTION__, "Succesfully loaded email verification message ({} bytes)", message.length());
}
catch (const std::exception& e)
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to load email verification message ({})", e.what());
return false;
}
verify_account_email_from_address = prefs_verify_account_email_from_address;
verify_account_email_from_name = prefs_verify_account_email_from_name;
return true;
}
void account_email_verification_unload()
{
message.clear();
verify_account_email_from_address.clear();
}
/**
* If successful, sets "BNET\\acct\\email\\verified" attribute to true and sets "email_verification\\code"
* attribute and "email_verification\\expiration" attribute to 0 for the given account.
*/
AccountVerifyEmailStatus account_verify_email(t_account* account, const std::string& code)
{
if (account == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return AccountVerifyEmailStatus::FailureOther;
}
const char* account_code = account_get_email_verification_code(account);
if (account_code == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "Could not retrieve email verification code for account uid {}", account_get_uid(account));
return AccountVerifyEmailStatus::FailureOther;
}
unsigned int account_expiration = account_get_email_verification_expiration(account);
if (account_expiration == 0)
{
eventlog(eventlog_level_error, __FUNCTION__, "Could not retrieve email verification expiration date for account uid {}", account_get_uid(account));
return AccountVerifyEmailStatus::FailureOther;
}
if (now >= account_expiration)
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to verify email for account uid {} (Email verification code expired)", account_get_uid(account));
return AccountVerifyEmailStatus::FailureCodeExpired;
}
if (code.compare(account_code) != 0)
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to verify email for account uid {} (Incorrect email verification code)", account_get_uid(account));
return AccountVerifyEmailStatus::FailureCodeIncorrect;
}
int verified = account_set_email_verified(account, true);
if (verified != 0)
{
eventlog(eventlog_level_error, __FUNCTION__, "Could not verify email code for account uid {}", account_get_uid(account));
return AccountVerifyEmailStatus::FailureOther;
}
account_set_email_verification_code(account, "");
account_set_email_verification_expiration(account, 0);
eventlog(eventlog_level_info, __FUNCTION__, "Succesfully verified email address ({}) account uid {}", account_get_email(account), account_get_uid(account));
return AccountVerifyEmailStatus::Success;
}
/**
* Generates an email verification code and saves it in the "email_verification\\code" attribute for the given account. Sets the "email_verification\\expiration" attribute
* to X minutes from current time, where X is the value of 'verify_account_email_expiration' in bnetd.conf.
* Sends an email containing the email verification code to the registered email address of the account.
*/
bool account_generate_email_verification_code(t_account* account)
{
if (account == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return false;
}
static std::random_device rdevice;
static std::default_random_engine rengine(rdevice());
static std::uniform_int_distribution<unsigned int> uniform_dist(100000, 999999);
std::time_t expiration = now + (60ull * prefs_get_verify_account_email_expiration());
std::string code = fmt::to_string(uniform_dist(rengine));
int a = account_set_email_verification_expiration(account, expiration);
int b = account_set_email_verification_code(account, code.c_str());
if (!(a == 0 && b == 0))
{
eventlog(eventlog_level_error, __FUNCTION__, "Could not generate an email verification code for account uid {}", account_get_uid(account));
return false;
}
std::string personalized_message = fmt::format(message, fmt::arg("account_name", account_get_name(account)), fmt::arg("account_email_verification_code", code), fmt::arg("account_email_verification_expiration", prefs_get_verify_account_email_expiration()));
eventlog(eventlog_level_debug, __FUNCTION__, "Sending email verification code to {} for account uid {}", account_get_email(account), account_get_uid(account));
smtp_send_email(account_get_email(account), verify_account_email_from_address, verify_account_email_from_name, "Email Verification", personalized_message);
return true;
}
}
}

View file

@ -0,0 +1,54 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef INCLUDED_EMAIL_VERIFICATION_H
#define INCLUDED_EMAIL_VERIFICATION_H
#ifndef JUST_NEED_TYPES
#define JUST_NEED_TYPES
#include "account.h"
#undef JUST_NEED_TYPES
#endif
#include <string>
namespace pvpgn
{
namespace bnetd
{
enum class AccountVerifyEmailStatus
{
Success,
FailureCodeExpired,
FailureCodeIncorrect,
FailureOther
};
bool account_email_verification_load(const char* filepath, const char* prefs_servername, const char* prefs_verify_account_email_from_address, const char* prefs_verify_account_email_from_name);
void account_email_verification_unload();
AccountVerifyEmailStatus account_verify_email(t_account* account, const std::string& code);
bool account_generate_email_verification_code(t_account* account);
}
}
#endif

View file

@ -23,6 +23,8 @@
#include <memory>
#include <string>
#include <fmt/format.h>
#include "compat/strcasecmp.h"
#include "common/bnet_protocol.h"
@ -2641,6 +2643,78 @@ namespace pvpgn
return account_set_strattr(account, "BNET\\acct\\email", email.c_str());
}
extern int account_get_email_verified(t_account* account)
{
if (account == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return -1;
}
return account_get_boolattr(account, "BNET\\acct\\email\\verified");
}
extern int account_set_email_verified(t_account* account, bool is_verified)
{
if (account == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return -1;
}
return account_set_boolattr(account, "BNET\\acct\\email\\verified", is_verified ? 1 : 0);
}
extern char const * account_get_email_verification_code(t_account* account)
{
if (account == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return nullptr;
}
return account_get_strattr(account, "email_verification\\code");
}
extern int account_set_email_verification_code(t_account* account, char const * verification_code)
{
if (account == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return -1;
}
if (verification_code == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL verification_code");
return -1;
}
return account_set_strattr(account, "email_verification\\code", verification_code);
}
extern unsigned int account_get_email_verification_expiration(t_account* account)
{
if (account == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return 0;
}
return account_get_numattr(account, "email_verification\\expiration");
}
extern int account_set_email_verification_expiration(t_account* account, unsigned int expiration_date)
{
if (account == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return -1;
}
return account_set_numattr(account, "email_verification\\expiration", expiration_date);
}
extern int account_set_userlang(t_account * account, const char * lang)
{
if (lang)

View file

@ -264,6 +264,12 @@ namespace pvpgn
extern int account_set_email(t_account * account, std::string email);
extern char const * account_get_email(t_account * account);
extern int account_get_email_verified(t_account* account);
extern int account_set_email_verified(t_account* account, bool is_verified);
extern char const* account_get_email_verification_code(t_account* account);
extern int account_set_email_verification_code(t_account* account, char const * verification_code);
extern unsigned int account_get_email_verification_expiration(t_account* account);
extern int account_set_email_verification_expiration(t_account* account, unsigned int expiration_date);
extern int account_set_userlang(t_account * account, const char * lang);
extern int account_set_userlang(t_account * account, std::string lang);

View file

@ -82,6 +82,7 @@
#include "icons.h"
#include "userlog.h"
#include "i18n.h"
#include "account_email_verification.h"
#include "attrlayer.h"
@ -421,6 +422,7 @@ namespace pvpgn
static int _handle_clearstats_command(t_connection * c, char const * text);
static int _handle_tos_command(t_connection * c, char const * text);
static int _handle_alert_command(t_connection * c, char const * text);
static int _handle_email_command(t_connection * c, char const * text);
static const t_command_table_row standard_command_table[] =
{
@ -541,6 +543,7 @@ namespace pvpgn
{ "/language", handle_language_command },
{ "/lang", handle_language_command },
{ "/log", handle_log_command },
{ "/email", _handle_email_command},
{ NULL, NULL }
@ -3524,7 +3527,9 @@ namespace pvpgn
account_get_auth_mute(account) == 1 ? yes : no);
message_send_text(c, message_type_info, c, msgtemp);
msgtemp = localize(c, "Email: {}", account_get_email(account));
msgtemp = localize(c, "Email: {} {}",
account_get_email(account),
account_get_email_verified(account) == 1 ? localize(c, "(Verified)") : localize(c, "(Unverified)"));
message_send_text(c, message_type_info, c, msgtemp);
msgtemp = localize(c, "Last login Owner: {}", account_get_ll_owner(account));
@ -3876,6 +3881,10 @@ namespace pvpgn
mode = restart_mode_anongame;
else if (mode_str == "lua")
mode = restart_mode_lua;
else if (mode_str == "smtp")
mode = restart_mode_smtp;
else if (mode_str == "accountemailverification")
mode = restart_mode_accountemailverification;
else
{
message_send_text(c, message_type_info, c, localize(c, "Invalid mode."));
@ -5237,5 +5246,150 @@ namespace pvpgn
return 0;
}
static int _handle_email_command(t_connection* c, char const* text)
{
std::vector<std::string> args = split_command(text, 2);
if (args[1].empty())
{
describe_command(c, args[0].c_str());
return -1;
}
t_account* account = conn_get_account(c);
if (args[1] == "get")
{
const char* email = account_get_email(account);
if (email == nullptr)
{
message_send_text(c, message_type_error, c, localize(c, "You have not set an email address yet."));
return -1;
}
message_send_text(c, message_type_info, c, localize(c, "Your email address is: {}", email));
}
else if (args[1] == "set")
{
if (args[2].empty())
{
describe_command(c, args[0].c_str());
return -1;
}
// FIXME: check format of email address
const char* current_email = account_get_email(account);
if (current_email != nullptr && args[2].compare(current_email) == 0)
{
message_send_text(c, message_type_error, c, localize(c, "Your email address is already set to {}.", args[2]));
return 0;
}
if ((args[2].length() + 1) > MAX_EMAIL_STR)
{
message_send_text(c, message_type_error, c, localize(c, "The email address is too long, please use another one.", args[2]));
return -1;
}
int set_email_result = account_set_email(account, args[2]);
if (set_email_result != 0)
{
message_send_text(c, message_type_error, c, localize(c, "An error has occurred."));
return -1;
}
account_set_email_verified(account, false);
message_send_text(c, message_type_info, c, localize(c, "Email address successfully set to {}.", args[2]));
if (prefs_get_verify_account_email() == 1)
{
bool send_verification_code_successful = account_generate_email_verification_code(account);
if (send_verification_code_successful)
{
message_send_text(c, message_type_info, c, localize(c, "An email has been sent, please check your inbox for the verification code."));
}
else
{
message_send_text(c, message_type_error, c, localize(c, "An error has occurred, could not send a verification email."));
}
}
}
else if (args[1] == "verify")
{
if (prefs_get_verify_account_email() == 0)
{
message_send_text(c, message_type_info, c, localize(c, "Email address verification is disabled."));
return -1;
}
if (args[2].empty())
{
describe_command(c, args[0].c_str());
return -1;
}
int is_verified = account_get_email_verified(account);
if (is_verified == 1)
{
message_send_text(c, message_type_info, c, localize(c, "Your email address has already been verified."));
return -1;
}
AccountVerifyEmailStatus verify_email_status = account_verify_email(account, args[2]);
switch (verify_email_status)
{
case AccountVerifyEmailStatus::Success:
message_send_text(c, message_type_info, c, localize(c, "Successfully verified email address."));
break;
case AccountVerifyEmailStatus::FailureCodeExpired:
message_send_text(c, message_type_error, c, localize(c, "The code has already expired."));
return -1;
case AccountVerifyEmailStatus::FailureCodeIncorrect:
message_send_text(c, message_type_error, c, localize(c, "The code is incorrect."));
return -1;
case AccountVerifyEmailStatus::FailureOther:
default:
message_send_text(c, message_type_error, c, localize(c, "An error has occurred."));
return -1;
}
}
else if (args[1] == "resendverification")
{
if (prefs_get_verify_account_email() == 0)
{
message_send_text(c, message_type_info, c, localize(c, "Email address verification is disabled."));
return -1;
}
int is_verified = account_get_email_verified(account);
if (is_verified == 1)
{
message_send_text(c, message_type_info, c, localize(c, "Your email address has already been verified."));
return -1;
}
bool resend_verification_code_successful = account_generate_email_verification_code(account);
if (resend_verification_code_successful)
{
message_send_text(c, message_type_info, c, localize(c, "Regenerated verification code. Check your email."));
}
else
{
message_send_text(c, message_type_error, c, localize(c, "An error has occurred."));
return -1;
}
}
else
{
describe_command(c, args[0].c_str());
return -1;
}
return 0;
}
}
}

View file

@ -32,6 +32,7 @@
#include "compat/strcasecmp.h"
#include "account_email_verification.h"
#include "prefs.h"
#include "irc.h"
#include "account.h"
@ -874,7 +875,17 @@ namespace pvpgn
eventlog(eventlog_level_debug, __FUNCTION__, "WOLHASH: {}", wol_pass_hash);
account_set_wol_apgar(tempacct, wol_pass_hash);
if (apiregmember_get_email(apiregmember))
account_set_email(tempacct, apiregmember_get_email(apiregmember));
{
if (account_set_email(tempacct, apiregmember_get_email(apiregmember)) == 0)
{
account_set_email_verified(tempacct, false);
if (prefs_get_verify_account_email() == 1)
{
account_generate_email_verification_code(account);
}
}
}
std::snprintf(message, sizeof(message), "Welcome in the amazing world of PvPGN! Your login can be used for all PvPGN Supported games!");
std::snprintf(hresult, sizeof(hresult), "0");
}

View file

@ -50,6 +50,7 @@
#include "common/bnetsrp3.h"
#include "common/xstring.h"
#include "account_email_verification.h"
#include "handlers.h"
#include "connection.h"
#include "prefs.h"
@ -5448,7 +5449,15 @@ namespace pvpgn
return 0;
}
else
{
account_set_email_verified(account, false);
eventlog(eventlog_level_info, __FUNCTION__, "[{}] init account \"{}\" email to \"{}\"", conn_get_socket(c), account_get_name(account), email);
if (prefs_get_verify_account_email() == 1)
{
account_generate_email_verification_code(account);
}
}
return 0;
}
@ -5493,7 +5502,15 @@ namespace pvpgn
return 0;
}
else
{
account_set_email_verified(account, false);
eventlog(eventlog_level_info, __FUNCTION__, "[{}] change account \"{}\" email to \"{}\"", conn_get_socket(c), account_get_name(account), newaddr);
if (prefs_get_verify_account_email() == 1)
{
account_generate_email_verification_code(account);
}
}
return 0;
}

View file

@ -88,6 +88,8 @@
#include "handle_apireg.h"
#include "i18n.h"
#include "userlog.h"
#include "account_email_verification.h"
#include "smtp.h"
#ifdef WIN32
#include "win32/windump.h"
#endif
@ -373,10 +375,10 @@ int pre_server_startup(void)
{
AdBannerList.unload();
}
AdBannerList.load(prefs_get_adfile());
}
catch (const std::exception& e)
catch (const std::exception & e)
{
eventlog(eventlog_level_error, __FUNCTION__, "{}", e.what());
}
@ -420,6 +422,30 @@ int pre_server_startup(void)
eventlog(eventlog_level_error, __FUNCTION__, "could not load realm list");
//topiclist_load(std::string(prefs_get_topicfile()));
userlog_init();
if (prefs_get_verify_account_email() == 1)
{
if (smtp_init(prefs_get_smtp_ca_cert_store_file(), prefs_get_smtp_server_url(), prefs_get_smtp_port(), prefs_get_smtp_username(), prefs_get_smtp_password()))
{
eventlog(eventlog_level_info, __FUNCTION__, "Successfully initialized SMTP client");
}
else
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to initialize SMTP client");
eventlog(eventlog_level_error, __FUNCTION__, "Disabling account email verification");
prefs_set_verify_account_email(false);
}
if (!account_email_verification_load(prefs_get_email_verification_file(), prefs_get_servername(), prefs_get_verify_account_email_from_address(), prefs_get_verify_account_email_from_name()))
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to load email verification message");
eventlog(eventlog_level_error, __FUNCTION__, "Disabling account email verification");
prefs_set_verify_account_email(false);
}
}
else
{
eventlog(eventlog_level_debug, __FUNCTION__, "Config option 'verify_account_email' is false");
}
#ifdef WITH_LUA
lua_load(prefs_get_scriptdir());
@ -435,6 +461,9 @@ void post_server_shutdown(int status)
{
case 0:
//topiclist_unload();
account_email_verification_unload();
smtp_cleanup();
account_email_verification_unload();
realmlist_destroy();
teamlist_unload();
clanlist_unload();

View file

@ -144,6 +144,7 @@ namespace pvpgn
char const * command_groups_file;
char const * tournament_file;
char const * customicons_file;
char const * email_verification_file;
char const * scriptdir;
char const * aliasfile;
char const * anongame_infos_file;
@ -156,6 +157,10 @@ namespace pvpgn
unsigned int passfail_count;
unsigned int passfail_bantime;
unsigned int maxusers_per_channel;
unsigned int verify_account_email;
unsigned int verify_account_email_expiration;
char const* verify_account_email_from_address;
char const * verify_account_email_from_name;
char const * supportfile;
char const * allowed_clients;
char const * ladder_games;
@ -168,6 +173,13 @@ namespace pvpgn
unsigned int log_commands;
char const * log_command_groups;
char const * log_command_list;
char const * smtp_ca_cert_store_file;
char const * smtp_ca_cert_store_remote_url;
unsigned int smtp_ca_cert_store_fetch_interval;
char const * smtp_server_url;
unsigned int smtp_port;
char const * smtp_username;
char const * smtp_password;
char const * apiregaddrs;
char const * wolv1addrs;
@ -589,6 +601,10 @@ namespace pvpgn
static const char *conf_get_customicons_file(void);
static int conf_setdef_customicons_file(void);
static int conf_set_email_verification_file(const char* valstr);
static const char* conf_get_email_verification_file(void);
static int conf_setdef_email_verification_file(void);
static int conf_set_scriptdir(const char *valstr);
static const char *conf_get_scriptdir(void);
static int conf_setdef_scriptdir(void);
@ -637,6 +653,22 @@ namespace pvpgn
static const char *conf_get_maxusers_per_channel(void);
static int conf_setdef_maxusers_per_channel(void);
static int conf_set_verify_account_email(const char* valstr);
static const char* conf_get_verify_account_email(void);
static int conf_setdef_verify_account_email(void);
static int conf_set_verify_account_email_expiration(const char* valstr);
static const char* conf_get_verify_account_email_expiration(void);
static int conf_setdef_verify_account_email_expiration(void);
static int conf_set_verify_account_email_from_address(const char* valstr);
static const char* conf_get_verify_account_email_from_address(void);
static int conf_setdef_verify_account_email_from_address(void);
static int conf_set_verify_account_email_from_name(const char* valstr);
static const char* conf_get_verify_account_email_from_name(void);
static int conf_setdef_verify_account_email_from_name(void);
static int conf_set_allowed_clients(const char *valstr);
static const char *conf_get_allowed_clients(void);
static int conf_setdef_allowed_clients(void);
@ -681,6 +713,34 @@ namespace pvpgn
static const char *conf_get_log_command_list(void);
static int conf_setdef_log_command_list(void);
static int conf_set_smtp_ca_cert_store_file(const char* valstr);
static const char* conf_get_smtp_ca_cert_store_file(void);
static int conf_setdef_smtp_ca_cert_store_file(void);
static int conf_set_smtp_ca_cert_store_remote_url(const char* valstr);
static const char* conf_get_smtp_ca_cert_store_remote_url(void);
static int conf_setdef_smtp_ca_cert_store_remote_url(void);
static int conf_set_smtp_ca_cert_store_fetch_interval(const char* valstr);
static const char* conf_get_smtp_ca_cert_store_fetch_interval(void);
static int conf_setdef_smtp_ca_cert_store_fetch_interval(void);
static int conf_set_smtp_server_url(const char* valstr);
static const char* conf_get_smtp_server_url(void);
static int conf_setdef_smtp_server_url(void);
static int conf_set_smtp_port(const char* valstr);
static const char* conf_get_smtp_port(void);
static int conf_setdef_smtp_port(void);
static int conf_set_smtp_username(const char* valstr);
static const char* conf_get_smtp_username(void);
static int conf_setdef_smtp_username(void);
static int conf_set_smtp_password(const char* valstr);
static const char* conf_get_smtp_password(void);
static int conf_setdef_smtp_password(void);
static int conf_setdef_apireg_addrs(void);
static int conf_set_apireg_addrs(const char *valstr);
@ -827,6 +887,7 @@ namespace pvpgn
{ "command_groups_file", conf_set_command_groups_file, conf_get_command_groups_file, conf_setdef_command_groups_file },
{ "tournament_file", conf_set_tournament_file, conf_get_tournament_file, conf_setdef_tournament_file },
{ "customicons_file", conf_set_customicons_file, conf_get_customicons_file, conf_setdef_customicons_file },
{ "email_verification_file", conf_set_email_verification_file, conf_get_email_verification_file, conf_setdef_email_verification_file },
{ "scriptdir", conf_set_scriptdir, conf_get_scriptdir, conf_setdef_scriptdir },
{ "aliasfile", conf_set_aliasfile, conf_get_aliasfile, conf_setdef_aliasfile },
{ "anongame_infos_file", conf_set_anongame_infos_file, conf_get_anongame_infos_file, conf_setdef_anongame_infos_file },
@ -839,6 +900,10 @@ namespace pvpgn
{ "passfail_count", conf_set_passfail_count, conf_get_passfail_count, conf_setdef_passfail_count },
{ "passfail_bantime", conf_set_passfail_bantime, conf_get_passfail_bantime, conf_setdef_passfail_bantime },
{ "maxusers_per_channel", conf_set_maxusers_per_channel, conf_get_maxusers_per_channel, conf_setdef_maxusers_per_channel },
{ "verify_account_email", conf_set_verify_account_email, conf_get_verify_account_email, conf_setdef_verify_account_email },
{ "verify_account_email_expiration", conf_set_verify_account_email_expiration, conf_get_verify_account_email_expiration, conf_setdef_verify_account_email_expiration },
{ "verify_account_email_from_address", conf_set_verify_account_email_from_address, conf_get_verify_account_email_from_address, conf_setdef_verify_account_email_from_address },
{ "verify_account_email_from_name", conf_set_verify_account_email_from_name, conf_get_verify_account_email_from_name, conf_setdef_verify_account_email_from_name },
{ "allowed_clients", conf_set_allowed_clients, conf_get_allowed_clients, conf_setdef_allowed_clients },
{ "ladder_games", conf_set_ladder_games, conf_get_ladder_games, conf_setdef_ladder_games },
{ "max_connections", conf_set_max_connections, conf_get_max_connections, conf_setdef_max_connections },
@ -850,6 +915,13 @@ namespace pvpgn
{ "log_commands", conf_set_log_commands, conf_get_log_commands, conf_setdef_log_commands },
{ "log_command_groups", conf_set_log_command_groups, conf_get_log_command_groups, conf_setdef_log_command_groups },
{ "log_command_list", conf_set_log_command_list, conf_get_log_command_list, conf_setdef_log_command_list },
{ "smtp_ca_cert_store_file", conf_set_smtp_ca_cert_store_file, conf_get_smtp_ca_cert_store_file, conf_setdef_smtp_ca_cert_store_file },
{ "smtp_ca_cert_store_remote_url", conf_set_smtp_ca_cert_store_remote_url, conf_get_smtp_ca_cert_store_remote_url, conf_setdef_smtp_ca_cert_store_remote_url },
{ "smtp_ca_cert_store_fetch_interval", conf_set_smtp_ca_cert_store_fetch_interval, conf_get_smtp_ca_cert_store_fetch_interval, conf_setdef_smtp_ca_cert_store_fetch_interval },
{ "smtp_server_url", conf_set_smtp_server_url, conf_get_smtp_server_url, conf_setdef_smtp_server_url, },
{ "smtp_port", conf_set_smtp_port, conf_get_smtp_port, conf_setdef_smtp_port },
{ "smtp_username", conf_set_smtp_username, conf_get_smtp_username, conf_setdef_smtp_username },
{ "smtp_password", conf_set_smtp_password, conf_get_smtp_password, conf_setdef_smtp_password },
{ "apiregaddrs", conf_set_apireg_addrs, conf_get_apireg_addrs, conf_setdef_apireg_addrs },
{ "wgameresaddrs", conf_set_wgameres_addrs, conf_get_wgameres_addrs, conf_setdef_wgameres_addrs },
@ -3050,6 +3122,28 @@ namespace pvpgn
return prefs_runtime_config.customicons_file;
}
extern char const* prefs_get_email_verification_file(void)
{
return prefs_runtime_config.email_verification_file;
}
static int conf_set_email_verification_file(const char* valstr)
{
return conf_set_str(&prefs_runtime_config.email_verification_file, valstr, NULL);
}
static const char* conf_get_email_verification_file(void)
{
return prefs_runtime_config.email_verification_file;
}
static int conf_setdef_email_verification_file(void)
{
return conf_set_str(&prefs_runtime_config.email_verification_file, NULL, BNETD_EMAIL_VERIFICATION_FILE);
}
extern char const * prefs_get_scriptdir(void)
{
return prefs_runtime_config.scriptdir;
@ -3312,6 +3406,95 @@ namespace pvpgn
}
extern unsigned int prefs_get_verify_account_email(void)
{
return prefs_runtime_config.verify_account_email;
}
extern void prefs_set_verify_account_email(bool enable)
{
prefs_runtime_config.verify_account_email = enable ? 1 : 0;
}
static int conf_set_verify_account_email(const char* valstr)
{
return conf_set_bool(&prefs_runtime_config.verify_account_email, valstr, 0);
}
static const char* conf_get_verify_account_email(void)
{
return conf_get_bool(prefs_runtime_config.verify_account_email);
}
static int conf_setdef_verify_account_email(void)
{
return conf_set_bool(&prefs_runtime_config.verify_account_email, nullptr, 0);
}
extern unsigned int prefs_get_verify_account_email_expiration(void)
{
return prefs_runtime_config.verify_account_email_expiration;
}
static int conf_set_verify_account_email_expiration(const char* valstr)
{
return conf_set_int(&prefs_runtime_config.verify_account_email_expiration, valstr, 0);
}
static const char* conf_get_verify_account_email_expiration(void)
{
return conf_get_int(prefs_runtime_config.verify_account_email_expiration);
}
static int conf_setdef_verify_account_email_expiration(void)
{
return conf_set_int(&prefs_runtime_config.verify_account_email_expiration, nullptr, 10);
}
extern char const* prefs_get_verify_account_email_from_address(void)
{
return prefs_runtime_config.verify_account_email_from_address;
}
static int conf_set_verify_account_email_from_address(const char* valstr)
{
return conf_set_str(&prefs_runtime_config.verify_account_email_from_address, valstr, NULL);
}
static const char* conf_get_verify_account_email_from_address(void)
{
return prefs_runtime_config.verify_account_email_from_address;
}
static int conf_setdef_verify_account_email_from_address(void)
{
return conf_set_str(&prefs_runtime_config.verify_account_email_from_address, NULL, NULL);
}
extern char const* prefs_get_verify_account_email_from_name(void)
{
return prefs_runtime_config.verify_account_email_from_name;
}
static int conf_set_verify_account_email_from_name(const char* valstr)
{
return conf_set_str(&prefs_runtime_config.verify_account_email_from_name, valstr, NULL);
}
static const char* conf_get_verify_account_email_from_name(void)
{
return prefs_runtime_config.verify_account_email_from_name;
}
static int conf_setdef_verify_account_email_from_name(void)
{
return conf_set_str(&prefs_runtime_config.verify_account_email_from_name, NULL, NULL);
}
extern char const * prefs_get_supportfile(void)
{
return prefs_runtime_config.supportfile;
@ -3563,6 +3746,152 @@ namespace pvpgn
}
extern char const * prefs_get_smtp_ca_cert_store_file(void)
{
return prefs_runtime_config.smtp_ca_cert_store_file;
}
static int conf_set_smtp_ca_cert_store_file(const char* valstr)
{
return conf_set_str(&prefs_runtime_config.smtp_ca_cert_store_file, valstr, NULL);
}
static const char* conf_get_smtp_ca_cert_store_file(void)
{
return prefs_runtime_config.smtp_ca_cert_store_file;
}
static int conf_setdef_smtp_ca_cert_store_file(void)
{
return conf_set_str(&prefs_runtime_config.smtp_ca_cert_store_file, NULL, NULL);
}
extern char const * prefs_get_smtp_ca_cert_store_remote_url(void)
{
return prefs_runtime_config.smtp_ca_cert_store_remote_url;
}
static int conf_set_smtp_ca_cert_store_remote_url(const char* valstr)
{
return conf_set_str(&prefs_runtime_config.smtp_ca_cert_store_remote_url, valstr, NULL);
}
static const char* conf_get_smtp_ca_cert_store_remote_url(void)
{
return prefs_runtime_config.smtp_ca_cert_store_remote_url;
}
static int conf_setdef_smtp_ca_cert_store_remote_url(void)
{
return conf_set_str(&prefs_runtime_config.smtp_ca_cert_store_remote_url, NULL, NULL);
}
extern unsigned int prefs_get_smtp_ca_cert_store_fetch_interval(void)
{
return prefs_runtime_config.smtp_ca_cert_store_fetch_interval;
}
static int conf_set_smtp_ca_cert_store_fetch_interval(const char* valstr)
{
return conf_set_int(&prefs_runtime_config.smtp_ca_cert_store_fetch_interval, valstr, NULL);
}
static const char* conf_get_smtp_ca_cert_store_fetch_interval(void)
{
return conf_get_int(prefs_runtime_config.smtp_ca_cert_store_fetch_interval);
}
static int conf_setdef_smtp_ca_cert_store_fetch_interval(void)
{
return conf_set_int(&prefs_runtime_config.smtp_ca_cert_store_fetch_interval, NULL, 30);
}
extern char const * prefs_get_smtp_server_url(void)
{
return prefs_runtime_config.smtp_server_url;
}
static int conf_set_smtp_server_url(const char* valstr)
{
return conf_set_str(&prefs_runtime_config.smtp_server_url, valstr, NULL);
}
static const char* conf_get_smtp_server_url(void)
{
return prefs_runtime_config.smtp_server_url;
}
static int conf_setdef_smtp_server_url(void)
{
return conf_set_str(&prefs_runtime_config.smtp_server_url, NULL, NULL);
}
extern unsigned int prefs_get_smtp_port(void)
{
return prefs_runtime_config.smtp_port;
}
static int conf_set_smtp_port(const char* valstr)
{
return conf_set_int(&prefs_runtime_config.smtp_port, valstr, NULL);
}
static const char* conf_get_smtp_port(void)
{
return conf_get_int(prefs_runtime_config.smtp_port);
}
static int conf_setdef_smtp_port(void)
{
return conf_set_int(&prefs_runtime_config.smtp_port, NULL, 587);
}
extern char const * prefs_get_smtp_username(void)
{
return prefs_runtime_config.smtp_username;
}
static int conf_set_smtp_username(const char* valstr)
{
return conf_set_str(&prefs_runtime_config.smtp_username, valstr, NULL);
}
static const char* conf_get_smtp_username(void)
{
return prefs_runtime_config.smtp_username;
}
static int conf_setdef_smtp_username(void)
{
return conf_set_str(&prefs_runtime_config.smtp_username, NULL, NULL);
}
extern char const * prefs_get_smtp_password(void)
{
return prefs_runtime_config.smtp_password;
}
static int conf_set_smtp_password(const char* valstr)
{
return conf_set_str(&prefs_runtime_config.smtp_password, valstr, NULL);
}
static const char* conf_get_smtp_password(void)
{
return prefs_runtime_config.smtp_password;
}
static int conf_setdef_smtp_password(void)
{
return conf_set_str(&prefs_runtime_config.smtp_password, NULL, NULL);
}
/**
* Westwood Online Extensions

View file

@ -153,6 +153,7 @@ namespace pvpgn
extern char const * prefs_get_command_groups_file(void);
extern char const * prefs_get_tournament_file(void);
extern char const * prefs_get_customicons_file(void);
extern char const* prefs_get_email_verification_file(void);
extern char const * prefs_get_scriptdir(void);
extern char const * prefs_get_aliasfile(void);
@ -170,6 +171,11 @@ namespace pvpgn
extern unsigned int prefs_get_passfail_count(void);
extern unsigned int prefs_get_passfail_bantime(void);
extern unsigned int prefs_get_maxusers_per_channel(void);
extern unsigned int prefs_get_verify_account_email(void);
extern void prefs_set_verify_account_email(bool enable);
extern unsigned int prefs_get_verify_account_email_expiration(void);
extern char const* prefs_get_verify_account_email_from_address(void);
extern char const* prefs_get_verify_account_email_from_name(void);
extern char const * prefs_get_supportfile(void);
extern char const * prefs_get_allowed_clients(void);
extern char const * prefs_get_ladder_games(void);
@ -182,6 +188,14 @@ namespace pvpgn
extern unsigned int prefs_get_log_commands(void);
extern char const * prefs_get_log_command_groups(void);
extern char const * prefs_get_log_command_list(void);
extern char const * prefs_get_smtp_ca_cert_store_file(void);
extern char const * prefs_get_smtp_ca_cert_store_remote_url(void);
extern unsigned int prefs_get_smtp_ca_cert_store_fetch_interval(void);
extern char const * prefs_get_smtp_server_url(void);
extern unsigned int prefs_get_smtp_port(void);
extern char const * prefs_get_smtp_username(void);
extern char const * prefs_get_smtp_password(void);
/**
* Westwood Online Extensions

View file

@ -87,6 +87,8 @@
#include "anongame_infos.h"
#include "topic.h"
#include "i18n.h"
#include "smtp.h"
#include "account_email_verification.h"
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
@ -1255,6 +1257,7 @@ namespace pvpgn
next_savetime = starttime + prefs_get_user_sync_timer();
war3_ladder_updatetime = starttime - prefs_get_war3_ladder_update_secs();
output_updatetime = starttime - prefs_get_output_update_secs();
std::time_t download_smtp_ca_cert_store_time = starttime + (86400ll * prefs_get_smtp_ca_cert_store_fetch_interval()); // 86400 seconds in 1 day
for (;;)
{
@ -1349,6 +1352,13 @@ namespace pvpgn
output_write_to_file();
}
if (prefs_get_smtp_ca_cert_store_fetch_interval() != 0 && now >= download_smtp_ca_cert_store_time)
{
download_smtp_ca_cert_store_time = now + (86400ll * prefs_get_smtp_ca_cert_store_fetch_interval());
download_ca_cert_store();
}
if (do_save)
{
@ -1506,6 +1516,34 @@ namespace pvpgn
}
#endif
if (prefs_get_verify_account_email() == 1)
{
if (do_restart == restart_mode_all || do_restart == restart_mode_smtp)
{
if (smtp_reconfig(prefs_get_smtp_ca_cert_store_file(), prefs_get_smtp_server_url(), prefs_get_smtp_port(), prefs_get_smtp_username(), prefs_get_smtp_password()))
{
eventlog(eventlog_level_info, __FUNCTION__, "Successfully reconfigured SMTP client");
}
else
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to reconfigure SMTP client");
eventlog(eventlog_level_error, __FUNCTION__, "Disabling account email verification");
prefs_set_verify_account_email(false);
}
}
if (do_restart == restart_mode_all || do_restart == restart_mode_accountemailverification)
{
account_email_verification_unload();
if (!account_email_verification_load(prefs_get_email_verification_file(), prefs_get_servername(), prefs_get_verify_account_email_from_address(), prefs_get_verify_account_email_from_name()))
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to load email verification message");
eventlog(eventlog_level_error, __FUNCTION__, "Disabling account email verification");
prefs_set_verify_account_email(false);
}
}
}
eventlog(eventlog_level_info, __FUNCTION__, "done reconfiguring");
do_restart = 0;

View file

@ -92,7 +92,9 @@ namespace pvpgn
restart_mode_tournament,
restart_mode_icons,
restart_mode_anongame,
restart_mode_lua
restart_mode_lua,
restart_mode_smtp,
restart_mode_accountemailverification
};
extern unsigned int server_get_uptime(void);

400
src/bnetd/smtp.cpp Normal file
View file

@ -0,0 +1,400 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "common/setup_before.h"
#include "smtp.h"
#include <array>
#include <atomic>
#include <cstdint>
#include <ctime>
#include <fstream>
#include <mutex>
#include <string>
#include <thread>
#include <tuple>
#include <curl/curl.h>
#include <fmt/core.h>
#include <fmt/chrono.h>
#include "common/eventlog.h"
#include "common/xalloc.h"
#include "prefs.h"
#include "server.h"
#include "common/setup_after.h"
#define SMTP_TIMEOUT_DEFAULT 1000
namespace pvpgn
{
namespace bnetd
{
static bool is_curl_initialized = false;
static std::thread smtp_thread;
static std::array<std::tuple<CURLM*, std::mutex>, 2> handles_and_mutexes = {};
static std::atomic<bool> need_to_download_ca_cert_store(false);
// smtp data
static std::string smtp_ca_cert_store;
static std::string smtp_server_url;
static long smtp_port;
static std::string smtp_username;
static std::string smtp_password;
typedef struct
{
std::string message;
std::size_t bytes_remaining;
} read_callback_message;
// Callback function for CURLOPT_WRITEFUNCTION.
static std::size_t write_callback(char* ptr, std::size_t size, std::size_t nmemb, void* userdata)
{
try
{
const std::size_t total_size = size * nmemb;
std::string* buffer = static_cast<std::string*>(userdata);
buffer->append(ptr, ptr + total_size);
return total_size;
}
catch (const std::exception& e)
{
return 0;
}
}
static void smtp_consumer()
{
while (is_curl_initialized == true)
{
// check if a new ca cert store file needs to be downloaded
if (need_to_download_ca_cert_store.load() == true)
{
need_to_download_ca_cert_store.store(false);
CURL* curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL, prefs_get_smtp_ca_cert_store_remote_url());
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl_handle, CURLOPT_USE_SSL, static_cast<long>(CURLUSESSL_ALL));
curl_easy_setopt(curl_handle, CURLOPT_CAINFO, smtp_ca_cert_store.c_str());
std::string buffer;
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, static_cast<void*>(&buffer));
CURLcode c = curl_easy_perform(curl_handle);
curl_easy_cleanup(curl_handle);
std::ofstream ca_cert_store_file(prefs_get_smtp_ca_cert_store_file(), std::ios::binary);
if (ca_cert_store_file.is_open())
{
ca_cert_store_file << buffer;
}
}
// now handle pending curl easy handles
for (auto& tuple : handles_and_mutexes)
{
CURLM* curl_multi_handle = std::get<0>(tuple);
std::mutex& curl_multi_handle_mutex = std::get<1>(tuple);
if (curl_multi_handle_mutex.try_lock() == false)
{
continue;
}
long timeout = -1;
curl_multi_timeout(curl_multi_handle, &timeout);
if (timeout == -1)
{
timeout = SMTP_TIMEOUT_DEFAULT;
}
curl_multi_poll(curl_multi_handle, nullptr, 0, timeout, nullptr);
int running_handles = 0; // unused
curl_multi_perform(curl_multi_handle, &running_handles);
// After calling curl_multi_perform(), free all curl easy handles that are done.
{
struct CURLMsg* curlmsg;
do
{
int msgq = 0;
curlmsg = curl_multi_info_read(curl_multi_handle, &msgq);
if (curlmsg && (curlmsg->msg == CURLMSG_DONE))
{
CURL* curl = curlmsg->easy_handle;
running_handles -= 1;
curl_multi_remove_handle(curl_multi_handle, curl);
struct curl_slist* recipient = nullptr;
curl_easy_getinfo(curl, CURLINFO_PRIVATE, &recipient);
if (recipient != nullptr)
{
curl_slist_free_all(recipient);
}
curl_easy_cleanup(curl);
}
} while (curlmsg);
}
curl_multi_handle_mutex.unlock();
}
}
}
// This function will be called at least twice for every message, the last call must return 0.
static std::size_t read_callback(char* buffer, std::size_t size, std::size_t nitems, void* message)
{
read_callback_message* rcbmessage = static_cast<read_callback_message*>(message);
std::size_t buffer_size = size * nitems;
// Copy at least (rcbmessage->bytes_remaining) bytes and at most (buffer_size) bytes
std::size_t copy_size = rcbmessage->bytes_remaining <= buffer_size ? rcbmessage->bytes_remaining : buffer_size;
if (copy_size > 0)
{
std::memcpy(buffer, rcbmessage->message.c_str(), copy_size);
rcbmessage->bytes_remaining -= copy_size;
}
return copy_size;
}
/**
* Initializes smtp_server_url, smtp_port, smtp_username, and smtp_password from the four function parameters.
* Will return false if prefs_smtp_port is greater than 65535.
*/
static bool smtp_config(const char* prefs_smtp_ca_cert_store, const char* prefs_smtp_server_url, unsigned int prefs_smtp_port, const char* prefs_smtp_username, const char* prefs_smtp_password)
{
if (prefs_smtp_ca_cert_store == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "Received NULL prefs_smtp_ca_cert_store");
return false;
}
if (prefs_smtp_server_url == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "Received NULL prefs_smtp_server_url");
return false;
}
// ports are 16 bit integers, so they should never be above UINT16_MAX (65,535)
if (prefs_smtp_port > UINT16_MAX)
{
eventlog(eventlog_level_error, __FUNCTION__, "Received out-of-range port number ({})", prefs_smtp_port);
return false;
}
if (prefs_smtp_username == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "Received NULL prefs_smtp_username");
return false;
}
if (prefs_smtp_password == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "Received NULL prefs_smtp_password");
return false;
}
smtp_ca_cert_store = prefs_smtp_ca_cert_store;
smtp_server_url = fmt::format("smtps://{}", prefs_smtp_server_url);
smtp_port = prefs_smtp_port;
smtp_username = prefs_smtp_username;
smtp_password = prefs_smtp_password;
return true;
}
/**
* Initializes libcurl's global context if it hasn't already been initialized.
* There must only be exactly one call to smtp_init() and smtp_cleanup().
*
* On success, returns true.
* On failure, returns false. Will fail if libcurl couldn't initialize global context.
*/
bool smtp_init(const char* prefs_smtp_ca_cert_store, const char* prefs_smtp_server_url, unsigned int prefs_smtp_port, const char* prefs_smtp_username, const char* prefs_smtp_password)
{
if (is_curl_initialized)
{
eventlog(eventlog_level_error, __FUNCTION__, "libcurl has already been initialized");
return false;
}
if (smtp_config(prefs_smtp_ca_cert_store, prefs_smtp_server_url, prefs_smtp_port, prefs_smtp_username, prefs_smtp_password) == false)
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to set SMTP data");
return false;
}
for (auto& tuple : handles_and_mutexes)
{
CURLM** curl_multi_handle = &std::get<0>(tuple);
*curl_multi_handle = curl_multi_init();
if (*curl_multi_handle == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to initialize curl multi handle");
return false;
}
}
if (curl_global_init(CURL_GLOBAL_NOTHING) != 0)
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to initialize curl global context");
return false;
}
smtp_thread = std::thread(smtp_consumer);
is_curl_initialized = true;
return true;
}
bool smtp_reconfig(const char* prefs_smtp_ca_cert_store, const char* prefs_smtp_server_url, unsigned int prefs_smtp_port, const char* prefs_smtp_username, const char* prefs_smtp_password)
{
return smtp_config(prefs_smtp_ca_cert_store, prefs_smtp_server_url, prefs_smtp_port, prefs_smtp_username, prefs_smtp_password);
}
void smtp_cleanup()
{
if (is_curl_initialized)
{
is_curl_initialized = false;
// wait for the smtp thread to finish executing
smtp_thread.join();
// free all the curl multi handles
for (auto& tuple : handles_and_mutexes)
{
CURLM* curl_multi_handle = std::get<0>(tuple);
curl_multi_cleanup(curl_multi_handle);
}
// free curl's global context
curl_global_cleanup();
}
}
void smtp_send_email(const std::string& to_address, const std::string& from_address, const std::string& from_name, const std::string& subject, std::string message)
{
if (!is_curl_initialized)
{
eventlog(eventlog_level_debug, __FUNCTION__, "libcurl not initialized, returning without attempting to send email");
return;
}
CURL* curl = curl_easy_init();
if (curl == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to initialize CURL easy handle");
return;
}
// direct curl to use TLS
curl_easy_setopt(curl, CURLOPT_USE_SSL, static_cast<long>(CURLUSESSL_ALL));
curl_easy_setopt(curl, CURLOPT_CAINFO, smtp_ca_cert_store.c_str());
// set smtp server connection information
curl_easy_setopt(curl, CURLOPT_URL, smtp_server_url.c_str());
curl_easy_setopt(curl, CURLOPT_PORT, smtp_port);
curl_easy_setopt(curl, CURLOPT_USERNAME, smtp_username.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, smtp_password.c_str());
// set 'from' address
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, fmt::format("<{}>", from_address).c_str());
// set 'to' address
struct curl_slist* recipient = curl_slist_append(nullptr, fmt::format("<{}>", to_address).c_str());
if (recipient == nullptr)
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to append recipient address to recipient list");
return;
}
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipient);
// store pointer to recipient struct in the handle and retrieve it later to free the memory
curl_easy_setopt(curl, CURLOPT_PRIVATE, reinterpret_cast<void*>(recipient));
// set function for curl to call when it wants to read the message into curl's desired buffer
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
// prepend email headers to the message
message.insert(0, fmt::format("MIME-Version: 1.0\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\nDate: {:%a, %d %b %Y %T %z}\r\nFrom: {} <{}>\r\nTo: <{}>\r\nSubject: {}\r\n\r\n", *std::localtime(&now), from_name, from_address, to_address, subject));
// this is the pointer that will be passed in to read_callback().
// passing in a pointer to the message alone is not sufficient because read_callback() is called by curl at least twice.
// the buffer provided by curl may not be sufficiently large enough for read_callback() to copy the entire message into during a single call.
// therefore read_callback() needs a way to keep track of the number of bytes it still needs to copy from the message.
read_callback_message* rcbmessage = static_cast<read_callback_message*>(xmalloc(sizeof(read_callback_message)));
rcbmessage->message = message;
rcbmessage->bytes_remaining = message.length() + 1;
curl_easy_setopt(curl, CURLOPT_READDATA, static_cast<void*>(rcbmessage));
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
// lock an available mutex and then add the curl easy handle to the associated curl multi handle
while (true)
{
for (auto& tuple : handles_and_mutexes)
{
std::mutex& curl_multi_handle_mutex = std::get<1>(tuple);
if (curl_multi_handle_mutex.try_lock() == false)
{
continue;
}
CURLM* curl_multi_handle = std::get<0>(tuple);
CURLMcode code = curl_multi_add_handle(curl_multi_handle, curl);
if (code == CURLE_OK)
{
eventlog(eventlog_level_trace, __FUNCTION__, "Added handle to CURL multi handle ({})", curl_multi_handle);
}
else
{
eventlog(eventlog_level_error, __FUNCTION__, "Failed to add handle to CURL multi handle (CURLMcode: {})", code);
}
curl_multi_handle_mutex.unlock();
return;
}
}
}
// The actual logic is in smtp_consumer()
bool download_ca_cert_store()
{
need_to_download_ca_cert_store.store(true);
return true;
}
}
}

34
src/bnetd/smtp.h Normal file
View file

@ -0,0 +1,34 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <string>
namespace pvpgn
{
namespace bnetd
{
bool smtp_init(const char* prefs_smtp_ca_cert_store, const char* prefs_smtp_server_url, unsigned int prefs_smtp_port, const char* prefs_smtp_username, const char* prefs_smtp_password);
bool smtp_reconfig(const char* prefs_smtp_ca_cert_store, const char* prefs_smtp_server_url, unsigned int prefs_smtp_port, const char* prefs_smtp_username, const char* prefs_smtp_password);
void smtp_cleanup();
void smtp_send_email(const std::string& to_address, const std::string& from_address, const std::string& from_name, const std::string& subject, std::string message);
bool download_ca_cert_store();
}
}

View file

@ -158,6 +158,7 @@ const char * const BNETD_SUPPORT_FILE = "conf/supportfile.conf";
const char * const BNETD_COMMAND_GROUPS_FILE = "conf/command_groups.conf";
const char * const BNETD_TOURNAMENT_FILE = "conf/tournament.conf";
const char * const BNETD_CUSTOMICONS_FILE = "conf/icons.conf";
const char * const BNETD_EMAIL_VERIFICATION_FILE = "conf/email_verification.conf";
const char * const BNETD_ALIASFILE = "conf/bnalias.conf";
/* time limit for new member as newer(whom cannot be promoted) in clan, (hrs) */
const unsigned CLAN_NEWER_TIME = 168;