<commit_before>/*
 * This file is part of the FreeStreamer project,
 * (C)Copyright 2011-2014 <NAME>.
 * See the file ''LICENSE'' for using the code.
 */

#include "http_stream.h"
#include "audio_queue.h"
#include "id3_parser.h"
#include "stream_configuration.h"

//#define HS_DEBUG 1

#if !defined (HS_DEBUG)
#define HS_TRACE(...) do {} while (0)
#define HS_TRACE_CFSTRING(X) do {} while (0)
#else
#define HS_TRACE(...) printf(__VA_ARGS__)
#define HS_TRACE_CFSTRING(X) HS_TRACE("%s\n", CFStringGetCStringPtr(X, kCFStringEncodingMacRoman))
#endif

/*
 * Comment the following line to disable ID3 tag support:
 */
#define INCLUDE_ID3TAG_SUPPORT 1

namespace astreamer {

CFStringRef HTTP_Stream::httpRequestMethod   = CFSTR("GET");
CFStringRef HTTP_Stream::httpUserAgentHeader = CFSTR("User-Agent");
CFStringRef HTTP_Stream::httpUserAgentValue  = CFSTR("aStreamer/1.0");
CFStringRef HTTP_Stream::httpRangeHeader     = CFSTR("Range");
CFStringRef HTTP_Stream::icyMetaDataHeader = CFSTR("Icy-MetaData");
CFStringRef HTTP_Stream::icyMetaDataValue  = CFSTR("1"); /* always request ICY metadata, if available */

    
/* HTTP_Stream: public */
HTTP_Stream::HTTP_Stream() :
    m_readStream(0),
    m_scheduledInRunLoop(false),
    m_readPending(false),
    m_delegate(0),
    m_url(0),
    m_httpHeadersParsed(false),
    m_contentType(0),
    m_contentLength(0),
    
    m_icyStream(false),
    m_icyHeaderCR(false),
    m_icyHeadersRead(false),
    m_icyHeadersParsed(false),
    
    m_icyName(0),
    
    m_icyMetaDataInterval(0),
    m_dataByteReadCount(0),
    m_metaDataBytesRemaining(0),
    
    m_httpReadBuffer(0),
    m_icyReadBuffer(0),
    
    m_id3Parser(new ID3_Parser())
{
    m_id3Parser->m_delegate = this;
}

HTTP_Stream::~HTTP_Stream()
{
    close();
    
    for (std::vector<CFMutableStringRef>::iterator h = m_icyHeaderLines.begin(); h != m_icyHeaderLines.end(); ++h) {
        CFRelease(*h);
    }
    
    m_icyHeaderLines.clear();
    
    if (m_contentType) {
        CFRelease(m_contentType), m_contentType = 0;
    }
    
    if (m_icyName) {
        CFRelease(m_icyName), m_icyName = 0;
    }
    
    if (m_httpReadBuffer) {
        delete m_httpReadBuffer, m_httpReadBuffer = 0;
    }
    if (m_icyReadBuffer) {
        delete m_icyReadBuffer, m_icyReadBuffer = 0;<commit_msg>Fix a memory leak.<commit_after>/*
 * This file is part of the FreeStreamer project,
 * (C)Copyright 2011-2014 <NAME>.
 * See the file ''LICENSE'' for using the code.
 */

#include "http_stream.h"
#include "audio_queue.h"
#include "id3_parser.h"
#include "stream_configuration.h"

//#define HS_DEBUG 1

#if !defined (HS_DEBUG)
#define HS_TRACE(...) do {} while (0)
#define HS_TRACE_CFSTRING(X) do {} while (0)
#else
#define HS_TRACE(...) printf(__VA_ARGS__)
#define HS_TRACE_CFSTRING(X) HS_TRACE("%s\n", CFStringGetCStringPtr(X, kCFStringEncodingMacRoman))
#endif

/*
 * Comment the following line to disable ID3 tag support:
 */
#define INCLUDE_ID3TAG_SUPPORT 1

namespace astreamer {

CFStringRef HTTP_Stream::httpRequestMethod   = CFSTR("GET");
CFStringRef HTTP_Stream::httpUserAgentHeader = CFSTR("User-Agent");
CFStringRef HTTP_Stream::httpUserAgentValue  = CFSTR("aStreamer/1.0");
CFStringRef HTTP_Stream::httpRangeHeader     = CFSTR("Range");
CFStringRef HTTP_Stream::icyMetaDataHeader = CFSTR("Icy-MetaData");
CFStringRef HTTP_Stream::icyMetaDataValue  = CFSTR("1"); /* always request ICY metadata, if available */

    
/* HTTP_Stream: public */
HTTP_Stream::HTTP_Stream() :
    m_readStream(0),
    m_scheduledInRunLoop(false),
    m_readPending(false),
    m_delegate(0),
    m_url(0),
    m_httpHeadersParsed(false),
    m_contentType(0),
    m_contentLength(0),
    
    m_icyStream(false),
    m_icyHeaderCR(false),
    m_icyHeadersRead(false),
    m_icyHeadersParsed(false),
    
    m_icyName(0),
    
    m_icyMetaDataInterval(0),
    m_dataByteReadCount(0),
    m_metaDataBytesRemaining(0),
    
    m_httpReadBuffer(0),
    m_icyReadBuffer(0),
    
    m_id3Parser(new ID3_Parser())
{
    m_id3Parser->m_delegate = this;
}

HTTP_Stream::~HTTP_Stream()
{
    close();
    
    for (std::vector<CFMutableStringRef>::iterator h = m_icyHeaderLines.begin(); h != m_icyHeaderLines.end(); ++h) {
        CFRelease(*h);
    }
    
    m_icyHeaderLines.clear();
    
    if (m_contentType) {
        CFRelease(m_contentType), m_contentType = 0;
    }
    
    if (m_icyName) {
        CFRelease(m_icyName), m_icyName = 0;
    }
    
    if (m_httpReadBuffer) {
        delete [] m_httpReadBuffer, m_httpReadBuffer = 0;
    }
    if (m_icyReadBuffer) {
        delete [] m_icyReadBuffer, m_icyReadBuffer = 0;
{'fraction_non_alphanumeric': 0.12870430456413584, 'fraction_numerical': 0.015574302401038288, 'mean_word_length': 3.9667024704618687, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3362584', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1632, 'n_words': 302}