<commit_before>/******************************************************************************
 *
 * Definition of the QRBG Service Access class. (For declaration see: QRBG.h
 * file)
 *
 * Designed and written by <NAME>, Jan/2007.
 * Developed in Rudjer Boskovic Institute, Zagreb, Croatia.
 * Contact: stevie at ieee dot org.
 *
 * Last revision: 2007-07-19
 * Version: 0.31
 *
 * NOTE: QRBG code compiles on both Linux and Windows machines (tested with 
 *       gcc/g++ 3.2.2 and Microsoft Visual C++ 8.0)
 *
 *****************************************************************************
 *
 * Copyright (c) 2007 <NAME> and Rudjer Boskovic Institute.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#include "QRBG.h"

#include <sys/types.h>
#include <string.h>     // memcpy


#ifdef PLATFORM_WIN
    // windows includes
#   define WIN32_LEAN_AND_MEAN      // Exclude rarely-used stuff from Windows headers

#   include <winsock2.h>
#   include <WS2tcpip.h>
#   include <windows.h>
#   include <errno.h>

#   define GetLastSocketError() WSAGetLastError()

#   pragma comment(lib, "ws2_32.lib")   // link with winsock2 library
#endif

#ifdef PLATFORM_LINUX
    // linux includes
#   include <sys/socket.h>
#   include <netinet/in.h>
#   include <arpa/inet.h> 
#   include <netdb.h>
#   include <unistd.h>

#   include <errno.h>
    extern int errno;

#   define GetLastSocketError() errno

#endif

#define ASSERT(assertion)

// WinSock's recv() fails if called with too large buffer size, so
// limit maximum amount of data that could be received in
// one recv() call.
//#define INTERNAL_SOCKET_MAX_BUFFER    65536
#define INTERNAL_SOCKET_MAX_BUFFER  1048576

const char* QRBG::ServerResponseDescription[] = {
    "OK",
    "Service was shutting down",
    "Server was/is experiencing internal errors",
    "Service said we have requested some unsupported operation",
    "Service said we sent an ill-formed request packet",
    "Service said we were sending our request too slow",
    "Authentication failed",
    "User quota exceeded"
};

const char* QRBG::ServerResponseRemedy[] = {
    "None",
    "Try again later",
    "Try again later",
    "Upgrade your client software",
    "Upgrade your client software",
    "Check your network connection",
    "Check your login credentials",
    "Try again later, or contact Service admin to increase your quota(s)"
};


// Initializes class data members, initializes network subsystem.
// Throws exceptions upon failure (memory / winsock).
QRBG::QRBG(size_t cacheSize /*= DEFAULT_CACHE_SIZE*/) /* throw(NetworkSubsystemError, bad_alloc) */
: port(0), hSocket(-1)
, outBuffer(NULL)
, inBuffer(NULL)
, outBufferSize(4096) /* WARNING: 'outBuffer' MUST be large enough to store whole request header before sending! */
, inBufferSize(cacheSize)
, inBufferNextElemIdx(inBufferSize) {
    *szHostname = *szUsername = *szPassword = 0;

    // initialize socket subsystem
#ifdef PLATFORM_WIN
    // initialize winsock

    WORD wVersionRequested;
    WSADATA wsaData;

    wVersionRequested = MAKEWORD(2, 2);

    int err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0) {
        // we could not find a usable WinSock DLL (Winsock v2.2 was requested/required)
        throw NetworkSubsystemError();
    }

    // Confirm that the WinSock DLL supports 2.2.
    // Note: if the DLL supports versions greater than 2.2 in addition to 2.2, 
    // it will still return 2.2 in wVersion since that is the version we requested.
    if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
        // we could not find a usable WinSock DLL
        WSACleanup( );
        throw NetworkSubsystemError();
    }
#elif defined(PLATFORM_LINUX)
    // there's no need for linux sockets to init
#endif
<commit_msg>gcc warning fix: constructor variables not initialized in declared order<commit_after>/******************************************************************************
 *
 * Definition of the QRBG Service Access class. (For declaration see: QRBG.h
 * file)
 *
 * Designed and written by <NAME>, Jan/2007.
 * Developed in Rudjer Boskovic Institute, Zagreb, Croatia.
 * Contact: stevie at ieee dot org.
 *
 * Last revision: 2007-07-19
 * Version: 0.31
 *
 * NOTE: QRBG code compiles on both Linux and Windows machines (tested with 
 *       gcc/g++ 3.2.2 and Microsoft Visual C++ 8.0)
 *
 *****************************************************************************
 *
 * Copyright (c) 2007 <NAME> and Rudjer Boskovic Institute.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#include "QRBG.h"

#include <sys/types.h>
#include <string.h>     // memcpy


#ifdef PLATFORM_WIN
    // windows includes
#   define WIN32_LEAN_AND_MEAN      // Exclude rarely-used stuff from Windows headers

#   include <winsock2.h>
#   include <WS2tcpip.h>
#   include <windows.h>
#   include <errno.h>

#   define GetLastSocketError() WSAGetLastError()

#   pragma comment(lib, "ws2_32.lib")   // link with winsock2 library
#endif

#ifdef PLATFORM_LINUX
    // linux includes
#   include <sys/socket.h>
#   include <netinet/in.h>
#   include <arpa/inet.h> 
#   include <netdb.h>
#   include <unistd.h>

#   include <errno.h>
    extern int errno;

#   define GetLastSocketError() errno

#endif

#define ASSERT(assertion)

// WinSock's recv() fails if called with too large buffer size, so
// limit maximum amount of data that could be received in
// one recv() call.
//#define INTERNAL_SOCKET_MAX_BUFFER    65536
#define INTERNAL_SOCKET_MAX_BUFFER  1048576

const char* QRBG::ServerResponseDescription[] = {
    "OK",
    "Service was shutting down",
    "Server was/is experiencing internal errors",
    "Service said we have requested some unsupported operation",
    "Service said we sent an ill-formed request packet",
    "Service said we were sending our request too slow",
    "Authentication failed",
    "User quota exceeded"
};

const char* QRBG::ServerResponseRemedy[] = {
    "None",
    "Try again later",
    "Try again later",
    "Upgrade your client software",
    "Upgrade your client software",
    "Check your network connection",
    "Check your login credentials",
    "Try again later, or contact Service admin to increase your quota(s)"
};


// Initializes class data members, initializes network subsystem.
// Throws exceptions upon failure (memory / winsock).
QRBG::QRBG(size_t cacheSize /*= DEFAULT_CACHE_SIZE*/) /* throw(NetworkSubsystemError, bad_alloc) */
: port(0), hSocket(-1)
, outBuffer(NULL)
, outBufferSize(4096) /* WARNING: 'outBuffer' MUST be large enough to store whole request header before sending! */
, inBuffer(NULL)
, inBufferSize(cacheSize)
, inBufferNextElemIdx(inBufferSize) {
    *szHostname = *szUsername = *szPassword = 0;

    // initialize socket subsystem
#ifdef PLATFORM_WIN
    // initialize winsock

    WORD wVersionRequested;
    WSADATA wsaData;

    wVersionRequested = MAKEWORD(2, 2);

    int err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0) {
        // we could not find a usable WinSock DLL (Winsock v2.2 was requested/required)
        throw NetworkSubsystemError();
    }

    // Confirm that the WinSock DLL supports 2.2.
    // Note: if the DLL supports versions greater than 2.2 in addition to 2.2, 
    // it will still return 2.2 in wVersion since that is the version we requested.
    if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
        // we could not find a usable WinSock DLL
        WSACleanup( );
        throw NetworkSubsystemError();
    }
#elif defined(PLATFORM_LINUX)
    // there's no need for linux sockets to init
#endif

{'fraction_non_alphanumeric': 0.12100196667011696, 'fraction_numerical': 0.013663181865231343, 'mean_word_length': 3.6857419980601356, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '858795', 'n_tokens_mistral': 2938, 'n_tokens_neox': 2716, 'n_words': 1083}