51 #include <wx/xml/xml.h>
52 #include <wx/wfstream.h>
53 #include <wx/sstream.h>
54 #include <wx/mstream.h>
55 #include <wx/protocol/http.h>
88 return(
Assign(MetaData) );
101 return(
Load(File, Extension) );
114 return(
Load(Stream) );
126 void CSG_MetaData::_On_Construction(
void)
146 delete(m_pChildren[i]);
156 m_Prop_Names .
Clear();
157 m_Prop_Values.
Clear();
198 return(
Ins_Child(MetaData, -1, bAddChildren) );
223 pChildren[i] = pChildren[i - 1];
236 pChild->m_Name = Name;
237 pChild->m_Content = Content;
269 pChild->
Assign(MetaData, bAddChildren);
289 if( from_Index != to_Index )
294 if( from_Index < to_Index )
296 for(
int i=from_Index; i<to_Index; i++)
298 pChildren[i] = pChildren[i + 1];
303 for(
int i=from_Index; i>to_Index; i--)
305 pChildren[i] = pChildren[i - 1];
309 pChildren[to_Index] = pChild;
327 delete(pChildren[Index]);
331 pChildren[i] = pChildren[j];
345 if( Name.
Find(
'.') > 0 )
361 if( &MetaData !=
this )
387 else if( Name && *Name )
428 if( Name.
Find(
'.') > 0 )
442 int CSG_MetaData::_Get_Child(
const CSG_String &Name)
const
463 return( bNoCase ? !m_Name.
CmpNoCase(String) : !m_Name.
Cmp(String) );
512 wxString s; va_list argptr;
515 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
516 va_start(argptr, _Format);
517 s.PrintfV(_Format, argptr);
519 va_start(argptr, Format);
520 s.PrintfV(Format, argptr);
531 wxString s; va_list argptr;
534 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
535 va_start(argptr, _Format);
536 s.PrintfV(_Format, argptr);
538 va_start(argptr, Format);
539 s.PrintfV(Format, argptr);
550 return( bNoCase ? !m_Content.
CmpNoCase(String) : !m_Content.
Cmp(String) );
561 if( !Value.
is_Empty() &&_Get_Property(Name) < 0 )
563 m_Prop_Names .
Add(Name );
564 m_Prop_Values.
Add(Value);
605 m_Prop_Names .
Del(i);
606 m_Prop_Values.
Del(i);
617 int Index = _Get_Property(Name);
621 m_Prop_Values[Index] = Value;
625 else if( bAddIfNotExists )
627 m_Prop_Names .
Add(Name);
628 m_Prop_Values.
Add(Value);
679 int CSG_MetaData::_Get_Property(
const CSG_String &Name)
const
681 for(
int i=0; i<m_Prop_Names.
Get_Count(); i++)
683 if( Name.
CmpNoCase(m_Prop_Names[i]) == 0 )
711 wxXmlDocument XML; wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
717 wxStringOutputStream Stream;
721 s = &Stream.GetString();
759 if( &MetaData !=
this )
791 if( File.
Find(
"http://") == 0 )
815 if( XML.Load(_File.
c_str()) )
817 _Load(XML.GetRoot());
835 _Load(XML.GetRoot());
844 void CSG_MetaData::_Load(wxXmlNode *pNode)
846 m_Name = pNode->GetName ().wc_str();
847 m_Content = pNode->GetNodeContent().wc_str();
850 wxXmlAttribute *pProperty = pNode->GetAttributes();
854 Add_Property(&pProperty->GetName(), &pProperty->GetValue());
856 pProperty = pProperty->GetNext();
860 wxXmlNode *pChild = pNode->GetChildren();
864 if( pChild->GetType() != wxXML_TEXT_NODE )
869 pChild = pChild->GetNext();
881 wxXmlDocument XML; wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
898 wxXmlDocument XML; wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
913 void CSG_MetaData::_Save(wxXmlNode *pNode)
const
920 wxXmlNode *pChild =
new wxXmlNode(pNode, wxXML_TEXT_NODE,
SG_T(
"TEXT"));
948 wxXmlDocument XML; wxMemoryInputStream Stream((
const void *)_XML.
b_str(), (
size_t)_XML.
Length());
950 if( XML.Load(Stream) )
952 _Load(XML.GetRoot());
963 wxXmlDocument XML; wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
969 wxMemoryOutputStream Stream;
971 if( XML.Save(Stream) )
973 CSG_Array s(
sizeof(
char), Stream.GetSize());
998 if( Username && *Username ) { HTTP.SetUser (Username); }
999 if( Password && *Password ) { HTTP.SetPassword(Password); }
1001 wxString s = Server.
c_str();
1003 if( s.Find(
"http://") == 0 )
1005 s = s.Right(s.Length() - wxString(
"http://").Length());
1008 if( !HTTP.Connect(s) )
1021 wxInputStream *pStream = HTTP.GetInputStream(s);
1030 if( XML.Load(*pStream) )
1032 _Load(XML.GetRoot());
1083 for(
bool bQuota=
false;;)
1087 if( !c || c ==
'\n' ) {
break; }
else
1091 Element += c; bQuota = !bQuota;
1093 else if( bQuota || (c !=
' ' && c !=
'\t' && c !=
',') )
1105 else if( Element.
Find(
'[') >= 0 )
1111 else if( Element.
Find(
']') >= 0 )
1118 else if( Element.
Find(
'{') >= 0 )
1131 else if( Element.
Find(
'}') >= 0 )
1143 if( Value.
Find(
'\"') > -1 )
1185 Create(Server, Username, Password);
1195 if( Username && *Username ) {
m_pHTTP->SetUser (Username); }
1196 if( Password && *Password ) {
m_pHTTP->SetPassword(Password); }
1198 wxString Host = Server.
c_str();
1200 unsigned short Port = 80;
1202 #define SERVER_TRIM(s, p) { wxString sp(p); sp += "://"; if( s.Find(p) == 0 ) { s = s.Right(s.Length() - sp.Length()); } }
1207 if( Host.Find(
":") >= 0 )
1211 if( Host.AfterLast(
':').ToLong(&_Port) )
1213 Port = (
unsigned short)_Port;
1216 Host = Host.BeforeLast(
':');
1219 if( !
m_pHTTP->Connect(Host, Port) )
1255 wxInputStream * CSG_HTTP::_Request(
const CSG_String &Request)
1269 wxInputStream *pStream =
m_pHTTP->GetInputStream(s);
1271 if( pStream && !pStream->CanRead() )
1284 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1288 if( !XML.Load(*pStream) )
1295 Answer.
Destroy(); Answer._Load(XML.GetRoot());
1305 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1316 while( pStream->CanRead() )
1320 pStream->Read(&Byte,
sizeof(Byte));
1333 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1344 while( pStream->CanRead() )
1348 pStream->Read(&Byte,
sizeof(Byte));
1361 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1363 wxFileOutputStream *pFile =
new wxFileOutputStream(File);
1372 pFile->Write(*pStream);
1389 #include <wx/protocol/ftp.h>
1396 if( _Source.
Find(
"ftp://") == 0 )
1408 if( Username && *Username ) { ftp.SetUser (Username); }
1409 if( Password && *Password ) { ftp.SetPassword(Password); }
1411 if( !ftp.Connect(ftpHost.
c_str(), Port) )
1432 if( ftp.GetFileSize(ftpFile.
c_str()) == -1 )
1441 wxInputStream *pStream = ftp.GetInputStream(ftpFile.
c_str());
1454 wxFileOutputStream *pFile =
new wxFileOutputStream(
SG_File_Make_Path(Target_Directory, ftpFile).c_str());
1469 pFile->Write(*pStream);