2011-01-23 15:15:30 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-10-11 22:42:49 +02:00
|
|
|
#include "ticketparser.h"
|
|
|
|
#include "core/log.h"
|
2011-01-05 22:24:11 +01:00
|
|
|
#include "core/misc.h"
|
|
|
|
|
|
|
|
|
2010-10-11 22:42:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool TicketParser::IsWhite(int c)
|
|
|
|
{
|
|
|
|
return (c==' ' || c=='\t' || c==13);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::SkipLine()
|
|
|
|
{
|
|
|
|
while( *pchar!=0 && *pchar!=10 )
|
|
|
|
pchar += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::SkipWhite()
|
|
|
|
{
|
|
|
|
while( IsWhite(*pchar) || *pchar=='#' )
|
|
|
|
{
|
|
|
|
if( *pchar=='#' )
|
|
|
|
SkipLine();
|
|
|
|
else
|
|
|
|
pchar += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::SkipWhiteLines()
|
|
|
|
{
|
|
|
|
while( IsWhite(*pchar) || *pchar == 10 || *pchar=='#' )
|
|
|
|
{
|
|
|
|
if( *pchar=='#' )
|
|
|
|
SkipLine();
|
|
|
|
else
|
|
|
|
pchar += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void TicketParser::ReadTextQuoted(std::wstring & text)
|
2010-10-11 22:42:49 +02:00
|
|
|
{
|
|
|
|
pchar += 1;
|
|
|
|
|
|
|
|
while( *pchar!=0 && *pchar!=10 && *pchar!='\"' )
|
|
|
|
{
|
|
|
|
if( *pchar == '\\' )
|
|
|
|
pchar += 1;
|
|
|
|
|
|
|
|
text += *pchar;
|
|
|
|
pchar += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *pchar == '\"' )
|
|
|
|
pchar += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void TicketParser::ReadTextSimple(std::wstring & text, bool comma_separator)
|
2010-10-11 22:42:49 +02:00
|
|
|
{
|
|
|
|
while( *pchar!=0 && *pchar!=10 && !IsWhite(*pchar) && *pchar!='(' && *pchar!=')' &&
|
|
|
|
(!comma_separator || *pchar!=',' ) )
|
|
|
|
{
|
|
|
|
text += *pchar;
|
|
|
|
pchar += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void TicketParser::ReadText(std::wstring & text, bool comma_separator)
|
2010-10-11 22:42:49 +02:00
|
|
|
{
|
|
|
|
SkipWhite();
|
|
|
|
text.clear();
|
|
|
|
|
|
|
|
if( *pchar == '\"' )
|
|
|
|
ReadTextQuoted(text);
|
|
|
|
else
|
|
|
|
ReadTextSimple(text, comma_separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::CheckId(int & id, bool & def)
|
|
|
|
{
|
|
|
|
if( *pchar != '(' )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// dont set id and def here
|
|
|
|
// there are only changed if exists
|
|
|
|
pchar += 1;
|
|
|
|
|
|
|
|
while( *pchar!=0 && *pchar!=10 && *pchar!=')' )
|
|
|
|
{
|
|
|
|
ReadText(id_str, true);
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
if( id_str == L"def" )
|
2010-10-11 22:42:49 +02:00
|
|
|
def = true;
|
|
|
|
else
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
id = Toi(id_str);
|
2010-10-11 22:42:49 +02:00
|
|
|
|
|
|
|
if( *pchar == ',' )
|
|
|
|
pchar += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *pchar == ')' )
|
|
|
|
pchar += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TicketParser::ReadItemType()
|
|
|
|
{
|
|
|
|
ReadText(type);
|
|
|
|
|
|
|
|
if( type.empty() )
|
|
|
|
return false;
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
if( type == L"integer" )
|
2010-10-11 22:42:49 +02:00
|
|
|
item.type = TicketConf::TicketItem::TypeInteger;
|
|
|
|
else
|
2011-01-05 22:24:11 +01:00
|
|
|
if( type == L"progress" )
|
|
|
|
item.type = TicketConf::TicketItem::TypeProgress;
|
|
|
|
else
|
2010-11-21 01:19:17 +01:00
|
|
|
if( type == L"select" )
|
2010-10-11 22:42:49 +02:00
|
|
|
item.type = TicketConf::TicketItem::TypeSelect;
|
|
|
|
else
|
2011-01-05 22:24:11 +01:00
|
|
|
if( type == L"string" )
|
|
|
|
item.type = TicketConf::TicketItem::TypeString;
|
|
|
|
else
|
|
|
|
if( type == L"images" )
|
|
|
|
item.type = TicketConf::TicketItem::TypeImages;
|
|
|
|
else
|
|
|
|
if( type == L"files" )
|
|
|
|
item.type = TicketConf::TicketItem::TypeFiles;
|
|
|
|
else
|
2010-10-11 22:42:49 +02:00
|
|
|
{
|
|
|
|
error = WINIX_TICKET_ERR_UKNOWN_TYPE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::SetItemId()
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
bool def;
|
|
|
|
|
|
|
|
id = (!pconf->tab.empty()) ? pconf->tab.back().id + 1 : 0;
|
|
|
|
CheckId(id, def);
|
|
|
|
|
|
|
|
item.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TicketParser::ReadItemName()
|
|
|
|
{
|
|
|
|
ReadText(item.name);
|
|
|
|
|
|
|
|
if( item.name.empty() )
|
|
|
|
{
|
|
|
|
error = WINIX_TICKET_ERR_NO_ITEM_NAME;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::ReadItemInteger()
|
|
|
|
{
|
|
|
|
ReadText(int_min);
|
|
|
|
ReadText(int_max);
|
|
|
|
|
|
|
|
if( !int_min.empty() )
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
item.integer_min = Toi(int_min);
|
2010-10-11 22:42:49 +02:00
|
|
|
|
|
|
|
if( !int_max.empty() )
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
item.integer_max = Toi(int_max);
|
2010-10-11 22:42:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::ReadItemSelect()
|
|
|
|
{
|
|
|
|
bool def;
|
|
|
|
|
|
|
|
while( *pchar!=0 && *pchar!=10 )
|
|
|
|
{
|
|
|
|
ReadText(select.name);
|
|
|
|
select.id = (!item.select.empty()) ? item.select.back().id + 1 : 0;
|
|
|
|
def = false;
|
|
|
|
CheckId(select.id, def);
|
|
|
|
|
|
|
|
if( !select.name.empty() )
|
|
|
|
{
|
|
|
|
item.select.push_back(select);
|
|
|
|
|
|
|
|
if( def )
|
|
|
|
item.select_default = item.select.size() - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
void TicketParser::ReadItemString()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TicketParser::ReadItemFiles()
|
|
|
|
{
|
|
|
|
ReadText(item.upload_dir);
|
|
|
|
|
|
|
|
if( item.upload_dir.empty() )
|
|
|
|
{
|
|
|
|
error = WINIX_TICKET_ERR_NO_UPLOAD_DIR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadText(int_max);
|
|
|
|
|
|
|
|
if( !int_max.empty() )
|
|
|
|
item.max_files = Toi(int_max);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-11 22:42:49 +02:00
|
|
|
bool TicketParser::CheckEndLine()
|
|
|
|
{
|
|
|
|
SkipWhite();
|
|
|
|
|
|
|
|
if( *pchar != 0 && *pchar != 10 )
|
|
|
|
{
|
|
|
|
error = WINIX_TICKET_ERR_SYNTAX_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TicketParser::ReadItem()
|
|
|
|
{
|
|
|
|
SkipWhiteLines();
|
|
|
|
item.Clear();
|
|
|
|
|
|
|
|
if( !ReadItemType() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SetItemId();
|
|
|
|
|
|
|
|
if( !ReadItemName() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeInteger )
|
|
|
|
ReadItemInteger();
|
|
|
|
else
|
2011-01-05 22:24:11 +01:00
|
|
|
if( item.type == TicketConf::TicketItem::TypeProgress )
|
|
|
|
ReadItemInteger();
|
|
|
|
else
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeSelect )
|
2010-10-11 22:42:49 +02:00
|
|
|
ReadItemSelect();
|
2011-01-05 22:24:11 +01:00
|
|
|
else
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeString || item.type == TicketConf::TicketItem::TypeMultistring )
|
|
|
|
ReadItemString();
|
|
|
|
else
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeImages || item.type == TicketConf::TicketItem::TypeFiles )
|
|
|
|
if( !ReadItemFiles() )
|
|
|
|
return false;
|
2010-10-11 22:42:49 +02:00
|
|
|
|
|
|
|
if( !CheckEndLine() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::LogItemInteger(TicketConf::TicketItem & item)
|
|
|
|
{
|
|
|
|
log << log3 << "TicketParser: item_type: integer"
|
|
|
|
<< ", item_name: " << item.name
|
|
|
|
<< ", item_id: " << item.id
|
|
|
|
<< ", min: " << item.integer_min
|
|
|
|
<< ", max: " << item.integer_max
|
|
|
|
<< logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
void TicketParser::LogItemProgress(TicketConf::TicketItem & item)
|
|
|
|
{
|
|
|
|
log << log3 << "TicketParser: item_type: progress"
|
|
|
|
<< ", item_name: " << item.name
|
|
|
|
<< ", item_id: " << item.id
|
|
|
|
<< ", min: " << item.integer_min
|
|
|
|
<< ", max: " << item.integer_max
|
|
|
|
<< logend;
|
|
|
|
}
|
|
|
|
|
2010-10-11 22:42:49 +02:00
|
|
|
void TicketParser::LogItemSelect(TicketConf::TicketItem & item)
|
|
|
|
{
|
|
|
|
log << log3 << "TicketParser: item_type: select"
|
|
|
|
<< ", item_name: " << item.name
|
|
|
|
<< ", item_id: " << item.id
|
|
|
|
<< ", options: ";
|
|
|
|
|
|
|
|
for(size_t i=0 ; i<item.select.size() ; ++i)
|
|
|
|
{
|
|
|
|
log << item.select[i].name << "(" << item.select[i].id;
|
|
|
|
|
|
|
|
if( item.select_default == i )
|
|
|
|
log << ", def";
|
|
|
|
|
|
|
|
log << ")";
|
|
|
|
|
|
|
|
if( i+1 < item.select.size() )
|
|
|
|
log << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
log << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
void TicketParser::LogItemString(TicketConf::TicketItem & item)
|
|
|
|
{
|
|
|
|
log << log3 << "TicketParser: item_type: string"
|
|
|
|
<< ", item_name: " << item.name
|
|
|
|
<< ", item_id: " << item.id
|
|
|
|
<< logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::LogItemMultistring(TicketConf::TicketItem & item)
|
|
|
|
{
|
|
|
|
log << log3 << "TicketParser: item_type: multistring"
|
|
|
|
<< ", item_name: " << item.name
|
|
|
|
<< ", item_id: " << item.id
|
|
|
|
<< logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::LogItemImages(TicketConf::TicketItem & item)
|
|
|
|
{
|
|
|
|
log << log3 << "TicketParser: item_type: images"
|
|
|
|
<< ", item_name: " << item.name
|
|
|
|
<< ", item_id: " << item.id
|
|
|
|
<< ", item_upload_dir: " << item.upload_dir
|
|
|
|
<< logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TicketParser::LogItemFiles(TicketConf::TicketItem & item)
|
|
|
|
{
|
|
|
|
log << log3 << "TicketParser: item_type: files"
|
|
|
|
<< ", item_name: " << item.name
|
|
|
|
<< ", item_id: " << item.id
|
|
|
|
<< ", item_upload_dir: " << item.upload_dir
|
|
|
|
<< logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-11 22:42:49 +02:00
|
|
|
void TicketParser::LogItem(TicketConf::TicketItem & item)
|
|
|
|
{
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeInteger )
|
|
|
|
LogItemInteger(item);
|
|
|
|
else
|
2011-01-05 22:24:11 +01:00
|
|
|
if( item.type == TicketConf::TicketItem::TypeProgress )
|
|
|
|
LogItemProgress(item);
|
|
|
|
else
|
2010-10-11 22:42:49 +02:00
|
|
|
if( item.type == TicketConf::TicketItem::TypeSelect )
|
|
|
|
LogItemSelect(item);
|
2011-01-05 22:24:11 +01:00
|
|
|
else
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeString )
|
|
|
|
LogItemString(item);
|
|
|
|
else
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeMultistring )
|
|
|
|
LogItemMultistring(item);
|
|
|
|
else
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeImages )
|
|
|
|
LogItemImages(item);
|
|
|
|
else
|
|
|
|
if( item.type == TicketConf::TicketItem::TypeFiles )
|
|
|
|
LogItemFiles(item);
|
|
|
|
else
|
|
|
|
log << log1 << "TicketParser: unknown item type" << logend;
|
2010-10-11 22:42:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
int TicketParser::Parse(const wchar_t * str, TicketConf & conf)
|
2010-10-11 22:42:49 +02:00
|
|
|
{
|
|
|
|
pchar = str;
|
|
|
|
pconf = &conf;
|
|
|
|
error = WINIX_TICKET_ERR_OK;
|
|
|
|
conf.Clear();
|
|
|
|
|
|
|
|
while( ReadItem() )
|
|
|
|
{
|
|
|
|
conf.tab.push_back(item);
|
|
|
|
LogItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( error != WINIX_TICKET_ERR_OK )
|
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
log << log1 << "TicketParser: some errors occured during parsing the config (clearing the table)" << logend;
|
2010-10-11 22:42:49 +02:00
|
|
|
conf.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
int TicketParser::Parse(const std::wstring & str, TicketConf & conf)
|
2010-10-11 22:42:49 +02:00
|
|
|
{
|
|
|
|
return Parse(str.c_str(), conf);
|
|
|
|
}
|