<commit_before>#include "helpers.h"
#include "domain/Card.h"
#include "domain/IncomingRequest.h"
#include "domain/DataKey.h"
#include "domain/Config.h"
#include "domain/Card.h"
#include <iostream>

#include <util/util_config.h>
#if defined(YBUTIL_WINDOWS)
#include <rpc.h>
#else
#include <unistd.h>
#include <fcntl.h>
#endif
#if defined(YB_USE_WX)
#include <wx/app.h>
#elif defined(YB_USE_QT)
#include <QCoreApplication>
#endif
#include <iostream>
#include <util/string_utils.h>
#include <util/element_tree.h>

using namespace Domain;
using namespace std;
using namespace Yb;

ElementTree::ElementPtr mk_resp(const string &status,
        const string &status_code = "")
{
    ElementTree::ElementPtr res = ElementTree::new_element("response");
    res->sub_element("status", status);
    if (!status_code.empty())
        res->sub_element("status_code", status_code);
    char buf[40];
    MilliSec t = get_cur_time_millisec();
    sprintf(buf, "%u.%03u", (unsigned)(t/1000), (unsigned)(t%1000));
    res->sub_element("ts", buf);
    return res;
}

Yb::LongInt
get_random()
{
    Yb::LongInt buf;
#if defined(__WIN32__) || defined(_WIN32)
    UUID new_uuid;
    UuidCreate(&new_uuid);
    buf = new_uuid.Data1;
    buf <<= 32;
    Yb::LongInt buf2 = (new_uuid.Data2 << 16) | new_uuid.Data3;
    buf += buf2;
#else
    int fd = open("/dev/urandom", O_RDONLY);
    if (fd == -1)
        throw std::runtime_error("can't open /dev/urandom");
    if (read(fd, &buf, sizeof(buf)) != sizeof(buf)) {
        close(fd);
        throw std::runtime_error("can't read from /dev/urandom");
    }
    close(fd);
#endif
    return buf;
}


ElementTree::ElementPtr bind_card(Session &session, ILogger &logger,
        const StringDict &params)
{
 
    
    ElementTree::ElementPtr resp = mk_resp("success");
    Domain::Card card;
    Yb::LongInt token = get_random();
    card.card_token = token;
    card.dt = Yb::now();
    card.pan = params["pan"];/*convert data to string*/
    card.expire_dt = Yb::dt_make(params.get_as<int>("expire_year"), params.get_as<int>("expire_month"), 1);/*convert string to date*/
    card.card_holder = params["card_holder"];
    std::string pan_m1 =  params["pan"].substr(0,6);
    std::string pan_m2 =  params["pan"].substr(16,20);
    card.pan_masked = pan_m1 + "****" + pan_m2;
    card.save(session);
    session.commit();
    int card_id = card.id;
    
    resp->sub_element("card_id",Yb::to_string(card_id));
    resp->sub_element("card_holder",card.card_holder);
    resp->sub_element("pan_masked", card.pan_masked);
    std::string expire_dtYear =Yb::to_string(params.get_as<string>("expire_year"));/*convert data to string*/
    std::string expire_dtMonth =Yb::to_string(params.get_as<string>("expire_month"));/*convert data to string*/
    std::string expire_dtCD = expire_dtMonth +"/"+ expire_dtYear;
    resp->sub_element("expire.dt",expire_dtCD);
  
    return resp;
}
<commit_msg>find card<commit_after>#include "helpers.h"
#include "domain/Card.h"
#include "domain/IncomingRequest.h"
#include "domain/DataKey.h"
#include "domain/Config.h"
#include "domain/Card.h"
#include <iostream>

#include <util/util_config.h>
#if defined(YBUTIL_WINDOWS)
#include <rpc.h>
#else
#include <unistd.h>
#include <fcntl.h>
#endif
#if defined(YB_USE_WX)
#include <wx/app.h>
#elif defined(YB_USE_QT)
#include <QCoreApplication>
#endif
#include <iostream>
#include <util/string_utils.h>
#include <util/element_tree.h>

using namespace Domain;
using namespace std;
using namespace Yb;

ElementTree::ElementPtr mk_resp(const string &status,
        const string &status_code = "")
{
    ElementTree::ElementPtr res = ElementTree::new_element("response");
    res->sub_element("status", status);
    if (!status_code.empty())
        res->sub_element("status_code", status_code);
    char buf[40];
    MilliSec t = get_cur_time_millisec();
    sprintf(buf, "%u.%03u", (unsigned)(t/1000), (unsigned)(t%1000));
    res->sub_element("ts", buf);
    return res;
}

Yb::LongInt
get_random()
{
    Yb::LongInt buf;
#if defined(__WIN32__) || defined(_WIN32)
    UUID new_uuid;
    UuidCreate(&new_uuid);
    buf = new_uuid.Data1;
    buf <<= 32;
    Yb::LongInt buf2 = (new_uuid.Data2 << 16) | new_uuid.Data3;
    buf += buf2;
#else
    int fd = open("/dev/urandom", O_RDONLY);
    if (fd == -1)
        throw std::runtime_error("can't open /dev/urandom");
    if (read(fd, &buf, sizeof(buf)) != sizeof(buf)) {
        close(fd);
        throw std::runtime_error("can't read from /dev/urandom");
    }
    close(fd);
#endif
    return buf;
}


ElementTree::ElementPtr bind_card(Session &session, ILogger &logger,
        const StringDict &params)
{
 
    
    ElementTree::ElementPtr resp = mk_resp("success");
    Domain::Card card;

    Yb::LongInt token = get_random();
    card.card_token = token;
    card.dt = Yb::now();
    card.pan = params["pan"];

    Card rs = Yb::query<Card>(session)
      .filter_by(Card::c.pan == params["pan"]).one();
    
    card.expire_dt = Yb::dt_make(params.get_as<int>("expire_year"), params.get_as<int>("expire_month"), 1);/*convert string to date*/
    card.card_holder = params["card_holder"];
    std::string pan_m1 =  params["pan"].substr(0,6);
    std::string pan_m2 =  params["pan"].substr(16,20);
    card.pan_masked = pan_m1 + "****" + pan_m2;
    card.save(session);
    session.commit();
    int card_id = card.id;
    
    resp->sub_element("card_id",Yb::to_string(card_id));
    resp->sub_element("card_holder",card.card_holder);
    resp->sub_element("pan_masked", card.pan_masked);
    std::string expire_dtYear = Yb::to_string(params.get_as<string>("expire_year"));/*convert data to string*/
    std::string expire_dtMonth =Yb::to_string(params.get_as<string>("expire_month"));/*convert data to string*/
    std::string expire_dtCD = expire_dtMonth +"/"+ expire_dtYear;
    resp->sub_element("expire.dt",expire_dtCD);
  
    return resp;
}

{'fraction_non_alphanumeric': 0.16765553483641296, 'fraction_numerical': 0.012544499067638583, 'mean_word_length': 4.2631578947368425, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2792141', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2137, 'n_words': 399}