I am coding a backup/restore server, the client is PHP and the server is VC++ 2003 with XMLRPC++. I am able to backup successfully from the XMLRPC Server to the PHP client. However, when I try to restore from the XMLRPC server to the PHP client, PHP sends over the base64 encoded string as part of the parameters of the XMLRPC call. The size of the data being send over are always longer than the orig file content, I supppose that's becuz I specify base64 as the data type for the data that's being sent over. So, on the server side, when I writes that to the file, it ends up as totally different content.
My code snippet from VS 2003 VC++
std::string destFilename=(std::string)params[1];
std::cout << "Restoring local file "; std::cout << destFilename; std::cout << "\n";
poutputFile.open(((std::string)destFilename).c_str(), std::ios::in | std::ios::binary | std::ios::beg);
poutputFile.clear();
if (poutputFile.is_open())
{
std::cout << params[1]; std::cout << " opened successfully\n";
// THIS IS THE FILE CONTENT IN BASE64
XmlRpc::XmlRpcValue::BinaryData& data=params[2];
// TRY TO DECODE IT, BUT IT CRASH
std::string decodedStr=XmlRpc::XmlRpcUtil::xmlDecode((std::string)data);
// TRY TO USE BINARYDATA PUSH_BACK, NOGO
//for (int n=0;n<params[2].size();n++)
//{
// char c;
// data.push_back(c);
// poutputFile.put(c);
//}
//data.write(poutputFile);
//params[2].write(poutputFile);
// THIS CRASH IF I USE XMLDECODE, SO NO HELP
std::cout << "Decoded string size : "; std::cout << strlen(decodedStr.c_str()); std::cout << "\n";
for (int n=0; n<decodedStr.size();n++)
{
poutputFile.put(decodedStr[n]);
}
// THIS IS JUST USING DIRECT WRITE WITH THE DATA RECEIVED, NOGO, FILE WILL BE CORRUPTED
//for (int n=0; n<data.size();n++)
//{
// char c;
// data.push_back(c);
// std::cout << "Writing "; std::cout << n; std::cout << " bytes\n";
// poutputFile.put(c);
//}
std::cout << destFilename; std::cout << " restored successfully.\n";;
poutputFile.close();
result="File restored successfully";
}
else
{
result="Failed to open restore file";
}
Runtime info,
XmlRpcSocket::nbRead: read/recv returned 1448.
XmlRpcSocket::nbRead: read/recv returned 1448.
XmlRpcSocket::nbRead: read/recv returned -1.
XmlRpcSocket::nbRead: read/recv returned 3092.
XmlRpcSocket::nbRead: read/recv returned -1.
XmlRpcServerConnection::readRequest read 43428 bytes. // FILE SUPPOSE TO BE 32KB
XmlRpcServerConnection::executeRequest: server calling method 'remoteCopyFile'
Recevied remoteFileCopy request with PUT
Restoring local file C:\\SCOT\\REPORT\\DATA\\Picklist.xml
C:\\SCOT\\REPORT\\DATA\\Picklist.xml opened successfully
XmlRpcServerConnection::generateResponse:
HTTP/1.1 200 OK
Server: XMLRPC++ 0.7
Content-Type: text/xml
Content-length: 116
Hi all,
I am coding a backup/restore server, the client is PHP and the server is VC++ 2003 with XMLRPC++. I am able to backup successfully from the XMLRPC Server to the PHP client. However, when I try to restore from the XMLRPC server to the PHP client, PHP sends over the base64 encoded string as part of the parameters of the XMLRPC call. The size of the data being send over are always longer than the orig file content, I supppose that's becuz I specify base64 as the data type for the data that's being sent over. So, on the server side, when I writes that to the file, it ends up as totally different content.
My code snippet from VS 2003 VC++
std::string destFilename=(std::string)params[1];
std::cout << "Restoring local file "; std::cout << destFilename; std::cout << "\n";
poutputFile.open(((std::string)destFilename).c_str(), std::ios::in | std::ios::binary | std::ios::beg);
poutputFile.clear();
if (poutputFile.is_open())
{
std::cout << params[1]; std::cout << " opened successfully\n";
// THIS IS THE FILE CONTENT IN BASE64
XmlRpc::XmlRpcValue::BinaryData& data=params[2];
// TRY TO DECODE IT, BUT IT CRASH
std::string decodedStr=XmlRpc::XmlRpcUtil::xmlDecode((std::string)data);
// TRY TO USE BINARYDATA PUSH_BACK, NOGO
//for (int n=0;n<params[2].size();n++)
//{
// char c;
// data.push_back(c);
// poutputFile.put(c);
//}
//data.write(poutputFile);
//params[2].write(poutputFile);
// THIS CRASH IF I USE XMLDECODE, SO NO HELP
std::cout << "Decoded string size : "; std::cout << strlen(decodedStr.c_str()); std::cout << "\n";
for (int n=0; n<decodedStr.size();n++)
{
poutputFile.put(decodedStr[n]);
}
// THIS IS JUST USING DIRECT WRITE WITH THE DATA RECEIVED, NOGO, FILE WILL BE CORRUPTED
//for (int n=0; n<data.size();n++)
//{
// char c;
// data.push_back(c);
// std::cout << "Writing "; std::cout << n; std::cout << " bytes\n";
// poutputFile.put(c);
//}
std::cout << destFilename; std::cout << " restored successfully.\n";;
poutputFile.close();
result="File restored successfully";
}
else
{
result="Failed to open restore file";
}
Runtime info,
XmlRpcSocket::nbRead: read/recv returned 1448.
XmlRpcSocket::nbRead: read/recv returned 1448.
XmlRpcSocket::nbRead: read/recv returned -1.
XmlRpcSocket::nbRead: read/recv returned 3092.
XmlRpcSocket::nbRead: read/recv returned -1.
XmlRpcServerConnection::readRequest read 43428 bytes. // FILE SUPPOSE TO BE 32KB
XmlRpcServerConnection::executeRequest: server calling method 'remoteCopyFile'
Recevied remoteFileCopy request with PUT
Restoring local file C:\\SCOT\\REPORT\\DATA\\Picklist.xml
C:\\SCOT\\REPORT\\DATA\\Picklist.xml opened successfully
XmlRpcServerConnection::generateResponse:
HTTP/1.1 200 OK
Server: XMLRPC++ 0.7
Content-Type: text/xml
Content-length: 116
<?xml version="1.0"?>
<methodResponse><params><param>
<value>Failed</value>
</param></params></methodResponse>
Any help will be deeply appreciated.
Thanks, D.
I am using, more or less, the same thing. Not with a back up, but another kind of files.
My code looks like this:
// File info as binary
XmlRpcValue::BinaryData &fileInfo = params [0];
long lSize = fileInfosize();
char *fileBuffer = 0;
fileBuffer = new char[lSize];
for(int i = 0; i < lSize; i++)
{
fileBuffer[i] = decodingImage[i];
}
FILE *FD = fopen (strFileName.c_str(), "wb");
if(FD == 0)
{
result [0] = SENSOR_OPENING_FILE;
delete [] fileBuffer;
return;
}
for (int i = 0; i < lSize; i++)
{
fwrite(&fileBuffer[i],sizeof(char),1,FD);
}
fclose(FD);
I have no try it using iostreams as you do, and I thing the second for can be taken out, but, you know, "never touch a running system..."
Quique
Ooops...
The code should be:
/ File info as binary
XmlRpcValue::BinaryData &fileInfo = params [0];
long lSize = fileInfo.size();
char *fileBuffer = 0;
fileBuffer = new char[lSize];
for(int i = 0; i < lSize; i++)
fileBuffer[i] = fileInfo [i];
FILE *FD = fopen (strFileName.c_str(), "wb");
if(FD == 0)
{
result [0] = SENSOR_OPENING_FILE;
delete [] fileBuffer;
return;
}
for (int i = 0; i < lSize; i++)
fwrite(&fileBuffer[i],sizeof(char),1,FD);
fclose(FD);
Sorry...