<commit_before>#include "httpcontent.h"

HttpContent::HttpContent() {
    InitializeListHead(&m_ListContent);  //ʼLIST_ENTRY
    m_count = 0;
    m_length = 0;
}
HttpContent::~HttpContent() {
    release();
}

/*
ݿ
*/
void HttpContent::insert(const char *buf, int len)
{
    struct _list_httpcontent_block_ *pBlock = NULL;

    if(len <= 0) return;    //

    //init

    pBlock = (struct _list_httpcontent_block_*)malloc(sizeof(struct _list_httpcontent_block_));
    memset(pBlock, 0, sizeof(struct _list_httpcontent_block_));

    pBlock->buf = (char*)malloc(len);
    memset(pBlock->buf, 0, len);
    pBlock->len = len;


    memcpy_s(pBlock->buf, len, buf, len);

    m_length += len;    //ϵĿռ䳤

    //뵽б
    InsertTailList(&m_ListContent, (PLIST_ENTRY)&pBlock->list_entry);

    //һ
    m_count++;
}

char * HttpContent::getbuffer(size_t *len)
{
    char *result = NULL;
    size_t pos = 0;
    result = (char*)malloc(m_length);
    memset(result, 0, m_length);
    PLIST_ENTRY plist = NULL;
    struct _list_httpcontent_block_ *pelem = NULL;
    for (plist = m_ListContent.Flink; plist != &m_ListContent; plist = plist->Flink)
    {
        pelem = CONTAINING_RECORD(plist, struct _list_httpcontent_block_, list_entry);
        memcpy_s(result + pos, m_length - pos, pelem->buf, pelem->len);
        pos = pos + pelem->len;
    }
    *len = pos;
    return result;
}

void HttpContent::release()
{
    PLIST_ENTRY plist;
    struct _list_httpcontent_block_ *pelem = NULL;
    int i = 0;
    for (plist = m_ListContent.Flink; plist != &m_ListContent; plist = plist->Flink)
    {
        pelem = CONTAINING_RECORD(plist, struct _list_httpcontent_block_, list_entry);
        if (pelem->buf != NULL) free(pelem->buf);
    }

    for (i = 0; i < m_count; i++)
    {
        PLIST_ENTRY pList = RemoveHeadList(&m_ListContent);
        free(pList);
    }

    m_count = 0;

}<commit_msg>fix some bugs<commit_after>#include "httpcontent.h"

HttpContent::HttpContent() {
    InitializeListHead(&m_ListContent);  //ʼLIST_ENTRY
    m_count = 0;
    m_length = 0;
}
HttpContent::~HttpContent() {
    release();
}

/*
ݿ
*/
void HttpContent::insert(const char *buf, int len)
{
    struct _list_httpcontent_block_ *pBlock = NULL;

    if(len <= 0) return;    //

    //init

    pBlock = (struct _list_httpcontent_block_*)malloc(sizeof(struct _list_httpcontent_block_));
    memset(pBlock, 0, sizeof(struct _list_httpcontent_block_));

    pBlock->buf = (char*)malloc(len);
    memset(pBlock->buf, 0, len);
    pBlock->len = len;


    memcpy_s(pBlock->buf, len, buf, len);

    m_length += len;    //ϵĿռ䳤

    //뵽б
    InsertTailList(&m_ListContent, (PLIST_ENTRY)&pBlock->list_entry);

    //һ
    m_count++;
}

char * HttpContent::getbuffer(size_t *len)
{
    char *result = NULL;
    size_t pos = 0;

    if(m_length == 0)
        return NULL;

    result = (char*)malloc(m_length);
    memset(result, 0, m_length);

    PLIST_ENTRY plist = NULL;
    struct _list_httpcontent_block_ *pelem = NULL;
    for (plist = m_ListContent.Flink; plist != &m_ListContent; plist = plist->Flink)
    {
        pelem = CONTAINING_RECORD(plist, struct _list_httpcontent_block_, list_entry);
        memcpy_s(result + pos, m_length - pos, pelem->buf, pelem->len);
        pos = pos + pelem->len;
    }
    *len = pos;
    return result;
}

void HttpContent::release()
{
    PLIST_ENTRY plist;
    struct _list_httpcontent_block_ *pelem = NULL;
    int i = 0;
    for (plist = m_ListContent.Flink; plist != &m_ListContent; plist = plist->Flink)
    {
        pelem = CONTAINING_RECORD(plist, struct _list_httpcontent_block_, list_entry);
        if (pelem->buf != NULL) free(pelem->buf);
    }

    for (i = 0; i < m_count; i++)
    {
        PLIST_ENTRY pList = RemoveHeadList(&m_ListContent);
        free(pList);
    }

    m_count = 0;
    m_length = 0;

}
{'fraction_non_alphanumeric': 0.13574778530484627, 'fraction_numerical': 0.005732152162584679, 'mean_word_length': 3.0840425531914892, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '6854446', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1412, 'n_words': 284}