Exemplo n.º 1
0
LLXMLRPCTransaction::Impl::~Impl()
{
	if (mResponse)
	{
		XMLRPC_RequestFree(mResponse, 1);
	}
	
	if (mHeaders)
	{
		curl_slist_free_all(mHeaders);
	}
	
	if (mRequestText)
	{
		XMLRPC_Free(mRequestText);
	}
	
	if (mCurl)
	{
		if (mCurlMulti)
		{
			curl_multi_remove_handle(mCurlMulti, mCurl);
		}
		curl_easy_cleanup(mCurl);
	}
	
	if (mCurlMulti)
	{
		curl_multi_cleanup(mCurlMulti);
	}
	
}
Exemplo n.º 2
0
XMLRPC_VALUE xsm_system_multicall_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData) {
   XMLRPC_VALUE xArray = XMLRPC_VectorRewind(XMLRPC_RequestGetData(input));
   XMLRPC_VALUE xReturn = XMLRPC_CreateVector(0, xmlrpc_vector_array);

   if (xArray) {
      XMLRPC_VALUE xMethodIter = XMLRPC_VectorRewind(xArray);

      while (xMethodIter) {
         XMLRPC_REQUEST request = XMLRPC_RequestNew();
         if(request) {
            const char* methodName = XMLRPC_VectorGetStringWithID(xMethodIter, "methodName");
            XMLRPC_VALUE params = XMLRPC_VectorGetValueWithID(xMethodIter, "params");

            if(methodName && params) {
               XMLRPC_VALUE xRandomArray = XMLRPC_CreateVector(0, xmlrpc_vector_array);
               XMLRPC_RequestSetMethodName(request, methodName);
               XMLRPC_RequestSetData(request, params);
               XMLRPC_RequestSetRequestType(request, xmlrpc_request_call);

               XMLRPC_AddValueToVector(xRandomArray, 
                                       XMLRPC_ServerCallMethod(server, request, userData));

               XMLRPC_AddValueToVector(xReturn, xRandomArray);
            }
            XMLRPC_RequestFree(request, 1);
         }
         xMethodIter = XMLRPC_VectorNext(xArray);
      }
   }
   return xReturn;
}
Exemplo n.º 3
0
         void XMLRPC::reset()
         {
#if BTG_EXTERNALIZATION_DEBUG
            BTG_NOTICE(logWrapper(), "XMLRPC::reset");
#endif
            XMLRPC_RequestFree(xmlrpc_request, 1);
            xmlrpc_request = XMLRPC_RequestNew();
            XMLRPC_RequestSetData(xmlrpc_request, XMLRPC_CreateVector(NULL, xmlrpc_vector_array));
            doRewind = true;
         }
Exemplo n.º 4
0
LLXMLRPCTransaction::Impl::~Impl()
{
	if (mCurlEasyRequestStateMachinePtr && mCurlEasyRequestStateMachinePtr->running())
	{
		llwarns << "Calling LLXMLRPCTransaction::Impl::~Impl while mCurlEasyRequestStateMachinePtr is still running" << llendl;
		mCurlEasyRequestStateMachinePtr->abort();
	}

	if (mResponse)
	{
		XMLRPC_RequestFree(mResponse, 1);
	}
}
Exemplo n.º 5
0
LLXMLRPCTransaction::Impl::~Impl()
{
	if (mResponse)
	{
		XMLRPC_RequestFree(mResponse, 1);
	}
	
	if (mRequestText)
	{
		XMLRPC_Free(mRequestText);
	}
	
	delete mCurlRequest;
}
Exemplo n.º 6
0
         bool XMLRPC::setBuffer(dBuffer & _buffer)
         {
            XMLRPC_REQUEST temp_request;

            t_uint buffSize = _buffer.size();

            char *s=new char[buffSize+1];
            _buffer.getBytes(reinterpret_cast<t_byteP>(s), buffSize);
            s[buffSize] = 0;

            /* in xml_element.c:695 fprintf(stderr...) is used on
               error conditions.. Might wan't to remove that */
#if BTG_EXTERNALIZATION_DEBUG
            BTG_NOTICE(logWrapper(), "Deserializing command from " << s << " of size " << buffSize);
#endif // BTG_EXTERNALIZATION_DEBUG
            temp_request = XMLRPC_REQUEST_FromXML(s, buffSize, NULL);

            delete[] s;

            if(!temp_request)
               {
                  return false;
               }

            if (XMLRPC_RequestGetError(temp_request))
               {
                  XMLRPC_RequestFree(temp_request, 1);
                  return false;
               }

            /* Parsed OK, free the current request */
            XMLRPC_RequestFree(xmlrpc_request, 1);
            xmlrpc_request = temp_request;
            doRewind = true;
            return true;
         }
LLXMLRPCTransaction::Impl::Impl(const std::string& uri,
		const std::string& method, LLXMLRPCValue params, bool useGzip)
	: mCurlRequest(0),
	  mStatus(LLXMLRPCTransaction::StatusNotStarted),
	  mURI(uri),
	  mRequestText(0), 
	  mResponse(0)
{
	XMLRPC_REQUEST request = XMLRPC_RequestNew();
	XMLRPC_RequestSetMethodName(request, method.c_str());
	XMLRPC_RequestSetRequestType(request, xmlrpc_request_call);
	XMLRPC_RequestSetData(request, params.getValue());
	
	init(request, useGzip);
    // DEV-28398: without this XMLRPC_RequestFree() call, it looks as though
    // the 'request' object is simply leaked. It's less clear to me whether we
    // should also ask to free request value data (second param 1), since the
    // data come from 'params'.
    XMLRPC_RequestFree(request, 1);
}
Exemplo n.º 8
0
LLIOPipe::EStatus LLFilterXMLRPCRequest2LLSD::process_impl(
	const LLChannelDescriptors& channels,
	buffer_ptr_t& buffer,
	bool& eos,
	LLSD& context,
	LLPumpIO* pump)
{
	LLFastTimer t(FTM_PROCESS_XMLRPC2LLSD_REQUEST);
	PUMP_DEBUG;
	if(!eos) return STATUS_BREAK;
	if(!buffer) return STATUS_ERROR;

	PUMP_DEBUG;
	// *FIX: This technique for reading data is far from optimal. We
	// need to have some kind of istream interface into the xml
	// parser...
	S32 bytes = buffer->countAfter(channels.in(), NULL);
	if(!bytes) return STATUS_ERROR;
	char* buf = new char[bytes + 1];
	buf[bytes] = '\0';
	buffer->readAfter(channels.in(), NULL, (U8*)buf, bytes);

	//lldebugs << "xmlrpc request: " << buf << llendl;
	
	// Check the value in the buffer. XMLRPC_REQUEST_FromXML will report a error code 4 if 
	// values that are less than 0x20 are passed to it, except
	// 0x09: Horizontal tab; 0x0a: New Line; 0x0d: Carriage
	U8* cur_pBuf = (U8*)buf;
    U8 cur_char;
	for (S32 i=0; i<bytes; i++) 
	{
        cur_char = *cur_pBuf;
		if (   cur_char < 0x20
            && 0x09 != cur_char
            && 0x0a != cur_char
            && 0x0d != cur_char )
        {
			*cur_pBuf = '?';
        }
		++cur_pBuf;
	}

	PUMP_DEBUG;
	XMLRPC_REQUEST request = XMLRPC_REQUEST_FromXML(
		buf,
		bytes,
		NULL);
	if(!request)
	{
		llwarns << "XML -> SD Request process parse error." << llendl;
		delete[] buf;
		return STATUS_ERROR;
	}

	PUMP_DEBUG;
	LLBufferStream stream(channels, buffer.get());
	stream.precision(DEFAULT_PRECISION);
	const char* name = XMLRPC_RequestGetMethodName(request);
	stream << LLSDRPC_REQUEST_HEADER_1 << (name ? name : "")
		   << LLSDRPC_REQUEST_HEADER_2;
	XMLRPC_VALUE param = XMLRPC_RequestGetData(request);
	if(param)
	{
		PUMP_DEBUG;
		S32 size = XMLRPC_VectorSize(param);
		if(size > 1)
		{
			// if there are multiple parameters, stuff the values into
			// an array so that the next step in the chain can read them.
			stream << "[";
		}
 		XMLRPC_VALUE current = XMLRPC_VectorRewind(param);
		bool needs_comma = false;
 		while(current)
 		{
			if(needs_comma)
			{
				stream << ",";
			}
			needs_comma = true;
 			stream_out(stream, current);
 			current = XMLRPC_VectorNext(param);
 		}
		if(size > 1)
		{
			// close the array
			stream << "]";
		}
	}
	stream << LLSDRPC_REQUEST_FOOTER << std::flush;
	XMLRPC_RequestFree(request, 1);
	delete[] buf;
	PUMP_DEBUG;
	return STATUS_DONE;
}
Exemplo n.º 9
0
LLIOPipe::EStatus LLFilterXMLRPCResponse2LLSD::process_impl(
	const LLChannelDescriptors& channels,
	buffer_ptr_t& buffer,
	bool& eos,
	LLSD& context,
	LLPumpIO* pump)
{
	LLFastTimer t(FTM_PROCESS_XMLRPC2LLSD_RESPONSE);

	PUMP_DEBUG;
	if(!eos) return STATUS_BREAK;
	if(!buffer) return STATUS_ERROR;

	PUMP_DEBUG;
	// *FIX: This technique for reading data is far from optimal. We
	// need to have some kind of istream interface into the xml
	// parser...
	S32 bytes = buffer->countAfter(channels.in(), NULL);
	if(!bytes) return STATUS_ERROR;
	char* buf = new char[bytes + 1];
	buf[bytes] = '\0';
	buffer->readAfter(channels.in(), NULL, (U8*)buf, bytes);

	//lldebugs << "xmlrpc response: " << buf << llendl;

	PUMP_DEBUG;
	XMLRPC_REQUEST response = XMLRPC_REQUEST_FromXML(
		buf,
		bytes,
		NULL);
	if(!response)
	{
		llwarns << "XML -> SD Response unable to parse xml." << llendl;
		delete[] buf;
		return STATUS_ERROR;
	}

	PUMP_DEBUG;
	LLBufferStream stream(channels, buffer.get());
	stream.precision(DEFAULT_PRECISION);
	if(XMLRPC_ResponseIsFault(response))
	{
		PUMP_DEBUG;
		stream << LLSDRPC_FAULT_HADER_1
			   << XMLRPC_GetResponseFaultCode(response)
			   << LLSDRPC_FAULT_HADER_2;
		const char* fault_str = XMLRPC_GetResponseFaultString(response);
		std::string fault_string;
		if(fault_str)
		{
			fault_string.assign(fault_str);
		}
		stream << "'" << LLSDNotationFormatter::escapeString(fault_string)
		   << "'" <<LLSDRPC_FAULT_FOOTER << std::flush;
	}
	else
	{
		PUMP_DEBUG;
		stream << LLSDRPC_RESPONSE_HEADER;
		XMLRPC_VALUE param = XMLRPC_RequestGetData(response);
		if(param)
		{
			stream_out(stream, param);
		}
		stream << LLSDRPC_RESPONSE_FOOTER << std::flush;
	}
	PUMP_DEBUG;
	XMLRPC_RequestFree(response, 1);
	delete[] buf;
	PUMP_DEBUG;
	return STATUS_DONE;
}
Exemplo n.º 10
0
	~XMLRPCInjector() { XMLRPC_RequestFree(mRequest, 1); XMLRPC_Free(const_cast<char*>(mRequestText)); }
Exemplo n.º 11
0
/* with the exception of the registration calls, most everything in main
 * only needs to be written once per server.
 */
char* clientCallback( char* filebuf )
{
    XMLRPC_SERVER server;
    XMLRPC_REQUEST request, response;

    /* create a new server object */
    server = XMLRPC_ServerCreate(  );

    /* Register public methods with the server */
    XMLRPC_ServerRegisterMethod( server, "start", x_startCallback );
    XMLRPC_ServerRegisterMethod( server, "stop", x_stopCallback );
    XMLRPC_ServerRegisterMethod( server, "rm", x_rmCallback );
    XMLRPC_ServerRegisterMethod( server, "mkdir", x_mkdirCallback );
    XMLRPC_ServerRegisterMethod( server, "execute", x_executeCallback );
    XMLRPC_ServerRegisterMethod( server, "checkcore", x_checkCoreCallback );
    XMLRPC_ServerRegisterMethod( server, "listTests", x_listTestsCallback );
    XMLRPC_ServerRegisterMethod( server, "runTests", x_runTestsCallback );
    XMLRPC_ServerRegisterMethod( server, "listMachines", x_listMachinesCallback );
    XMLRPC_ServerRegisterMethod( server, "getConfig", x_getConfigCallback );
    XMLRPC_ServerRegisterMethod( server, "setConfig", x_setConfigCallback );

    /* Now, let's get the client's request from stdin....
     * This will be read from a  socket
     */
    {
        /*         char filebuf[4096];     // not that intelligent.  sue me.
                   int len =
                   fread( filebuf, sizeof( char ), sizeof( filebuf ) - 1,

                   if( len ) {
                   filebuf[len] = 0;
                   stdin );
                   */
        // parse the xml into a request structure
        request =
            XMLRPC_REQUEST_FromXML( ( const char * )filebuf,
                    strlen(filebuf), NULL );
        //         }
    }
    if( !request ) {
        fprintf( stderr, "bogus xmlrpc request\n" );
        return 0;
    }
    /*
     *  The interesting part is below
     */

    /* create a response struct */
    response = XMLRPC_RequestNew( );
    XMLRPC_RequestSetRequestType( response, xmlrpc_request_response );

    /* call server method with client request and assign the response to our response struct */
    XMLRPC_RequestSetData( response,
            XMLRPC_ServerCallMethod( server, request,
                NULL ) );

    /* be courteous. reply in same vocabulary/manner as the request. */
    XMLRPC_RequestSetOutputOptions( response,
            XMLRPC_RequestGetOutputOptions
            ( request ) );

    /* serialize server response as XML */
    char *outBuf = XMLRPC_REQUEST_ToXML( response, 0 );

    if( outBuf ) {
        printf( outBuf );
    }
    // cleanup.  null safe.
    XMLRPC_RequestFree( request, 1 );
    XMLRPC_RequestFree( response, 1 );
    XMLRPC_ServerDestroy( server );

    return outBuf;
}
void LLUserAuth::authenticate(
	const std::string& auth_uri,
	const std::string& method,
	const std::string& firstname,
	const std::string& lastname,
	LLUUID web_login_key,
	const std::string& start,
	BOOL skip_optional,
	BOOL accept_tos,
	BOOL accept_critical_message,
	BOOL last_exec_froze, 
	const std::vector<const char*>& requested_options,
	const std::string& hashed_mac,
	const std::string& hashed_volume_serial)
{
	LL_INFOS2("AppInit", "Authentication") << "Authenticating: " << firstname << " " << lastname << ", "
			<< /*dpasswd.c_str() <<*/ LL_ENDL;
	std::ostringstream option_str;
	option_str << "Options: ";
	std::ostream_iterator<const char*> appender(option_str, ", ");
	std::copy(requested_options.begin(), requested_options.end(), appender);
	option_str << "END";
	
	LL_INFOS2("AppInit", "Authentication") << option_str.str() << LL_ENDL;

	mAuthResponse = E_NO_RESPONSE_YET;
	//mDownloadTimer.reset();	

	std::string strMac;
	std::string strHDD;
	char mac[MAX_STRING];
	char hdd[MAX_STRING];

	strMac.assign(web_login_key.asString());
	strMac.append(hashed_mac.c_str());

	strHDD.assign(web_login_key.asString());
	strHDD.append(hashed_volume_serial.c_str());

	LLMD5 md5Mac((const unsigned char *)strMac.c_str());
	LLMD5 md5HDD((const unsigned char *)strHDD.c_str());

	md5Mac.hex_digest(mac);
	md5HDD.hex_digest(hdd);

	// create the request
	XMLRPC_REQUEST request = XMLRPC_RequestNew();
	XMLRPC_RequestSetMethodName(request, method.c_str());
	XMLRPC_RequestSetRequestType(request, xmlrpc_request_call);

	// stuff the parameters
	XMLRPC_VALUE params = XMLRPC_CreateVector(NULL, xmlrpc_vector_struct);
	XMLRPC_VectorAppendString(params, "first", firstname.c_str(), 0);
	XMLRPC_VectorAppendString(params, "last", lastname.c_str(), 0);
	XMLRPC_VectorAppendString(params, "web_login_key", web_login_key.getString().c_str(), 0);
	XMLRPC_VectorAppendString(params, "start", start.c_str(), 0);
	XMLRPC_VectorAppendString(params, "version", gCurrentVersion.c_str(), 0); // Includes channel name
	XMLRPC_VectorAppendString(params, "channel", gSavedSettings.getString("VersionChannelName").c_str(), 0);
	XMLRPC_VectorAppendString(params, "platform", PLATFORM_STRING, 0);
	XMLRPC_VectorAppendString(params, "mac", mac, 0);
	// A bit of security through obscurity: id0 is volume_serial
	XMLRPC_VectorAppendString(params, "id0", hdd, 0);
	if (skip_optional)
	{
		XMLRPC_VectorAppendString(params, "skipoptional", "true", 0);
	}
	if (accept_tos)
	{
		XMLRPC_VectorAppendString(params, "agree_to_tos", "true", 0);
	}
	if (accept_critical_message)
	{
		XMLRPC_VectorAppendString(params, "read_critical", "true", 0);
	}
	XMLRPC_VectorAppendInt(params, "last_exec_event", (int) last_exec_froze);

	// append optional requests in an array
	XMLRPC_VALUE options = XMLRPC_CreateVector("options", xmlrpc_vector_array);
	std::vector<const char*>::const_iterator it = requested_options.begin();
	std::vector<const char*>::const_iterator end = requested_options.end();
	for( ; it < end; ++it)
	{
		XMLRPC_VectorAppendString(options, NULL, (*it), 0);
	}
	XMLRPC_AddValueToVector(params, options);

	// put the parameters on the request
	XMLRPC_RequestSetData(request, params);

	mTransaction = new LLXMLRPCTransaction(auth_uri, request);
	
	XMLRPC_RequestFree(request, 1);

	LL_INFOS2("AppInit", "Authentication") << "LLUserAuth::authenticate: uri=" << auth_uri << LL_ENDL;
}
// passwd is already MD5 hashed by the time we get to it.
void LLUserAuth::authenticate(
	const std::string& auth_uri,
	const std::string& method,
	const std::string& firstname,
	const std::string& lastname,
	const std::string& passwd,
	const std::string& start,
	BOOL skip_optional,
	BOOL accept_tos,
	BOOL accept_critical_message,
	BOOL last_exec_froze, 
	const std::vector<const char*>& requested_options,
	const std::string& hashed_mac,
	const std::string& hashed_volume_serial)
{
	std::string dpasswd("$1$");
	dpasswd.append(passwd);
	LL_INFOS2("AppInit", "Authentication") << "Authenticating: " << firstname << " " << lastname << ", "
			<< /*dpasswd.c_str() <<*/ LL_ENDL;
	std::ostringstream option_str;
	option_str << "Options: ";
	std::ostream_iterator<const char*> appender(option_str, ", ");
	std::copy(requested_options.begin(), requested_options.end(), appender);
	option_str << "END";

	LL_INFOS2("AppInit", "Authentication") << option_str.str().c_str() << LL_ENDL;

	mAuthResponse = E_NO_RESPONSE_YET;
	//mDownloadTimer.reset();

	std::string strMac;
	std::string strHDD;
	char mac[MAX_STRING];
	char hdd[MAX_STRING];

	strMac.assign(firstname);
	strMac.append(lastname);
	strMac.append(dpasswd.c_str());
	strMac.append(hashed_mac.c_str());

	strHDD.assign(firstname);
	strHDD.append(lastname);
	strHDD.append(dpasswd.c_str());
	strHDD.append(hashed_volume_serial.c_str());

	LLMD5 md5Mac((const unsigned char *)strMac.c_str());
	LLMD5 md5HDD((const unsigned char *)strHDD.c_str());

	md5Mac.hex_digest(mac);
	md5HDD.hex_digest(hdd);

	// create the request
	XMLRPC_REQUEST request = XMLRPC_RequestNew();
	XMLRPC_RequestSetMethodName(request, method.c_str());
	XMLRPC_RequestSetRequestType(request, xmlrpc_request_call);

	// stuff the parameters
	XMLRPC_VALUE params = XMLRPC_CreateVector(NULL, xmlrpc_vector_struct);
	XMLRPC_VectorAppendString(params, "first", firstname.c_str(), 0);
	XMLRPC_VectorAppendString(params, "last", lastname.c_str(), 0);
	XMLRPC_VectorAppendString(params, "passwd", dpasswd.c_str(), 0);
	XMLRPC_VectorAppendString(params, "start", start.c_str(), 0);

	// To log into OpenLife, we need to spoof our version or it complains about an out of date viewer.
	// This will likely break OpenLife logins through SLProxy!
	// -Patrick Sapinski (Wednesday, October 21, 2009)
	if (auth_uri.find("logingrid.net") != -1) {
		XMLRPC_VectorAppendString(params, "version", "Openlife R17 1.17.0.336", 0);
		XMLRPC_VectorAppendString(params, "channel", "Second Life Release", 0); //OLG uses the original channel name.

	}
	else {
		XMLRPC_VectorAppendString(params, "version", gCurrentVersion.c_str(), 0); // Includes channel name
		XMLRPC_VectorAppendString(params, "channel", gSavedSettings.getString("VersionChannelName").c_str(), 0);
	}

	XMLRPC_VectorAppendString(params, "platform", PLATFORM_STRING, 0);
	XMLRPC_VectorAppendString(params, "mac", mac, 0);
	// A bit of security through obscurity: id0 is volume_serial
	XMLRPC_VectorAppendString(params, "id0", hdd, 0);
	if (skip_optional)
	{
		XMLRPC_VectorAppendString(params, "skipoptional", "true", 0);
	}
	if (accept_tos)
	{
		XMLRPC_VectorAppendString(params, "agree_to_tos", "true", 0);
	}
	if (accept_critical_message)
	{
		XMLRPC_VectorAppendString(params, "read_critical", "true", 0);
	}
	XMLRPC_VectorAppendInt(params, "last_exec_event", (int) last_exec_froze);

	// append optional requests in an array
	XMLRPC_VALUE options = XMLRPC_CreateVector("options", xmlrpc_vector_array);
	std::vector<const char*>::const_iterator it = requested_options.begin();
	std::vector<const char*>::const_iterator end = requested_options.end();
	for( ; it < end; ++it)
	{
		XMLRPC_VectorAppendString(options, NULL, (*it), 0);
	}
	XMLRPC_AddValueToVector(params, options);

	// put the parameters on the request
	XMLRPC_RequestSetData(request, params);

	mTransaction = new LLXMLRPCTransaction(auth_uri, request);
	
	XMLRPC_RequestFree(request, 1);

	LL_INFOS2("AppInit", "Authentication") << "LLUserAuth::authenticate: uri=" << auth_uri << LL_ENDL;
}
Exemplo n.º 14
0
int main(int argc, char **argv)
{
   int i;
   XMLRPC_SERVER  server;
   XMLRPC_REQUEST xRequest=0;
   XMLRPC_REQUEST response;
   STRUCT_XMLRPC_REQUEST_OUTPUT_OPTIONS call_options;

   /* args */
   int verbosity = 0;
   int version = 0;
   int escaping = 0;
   int output = 0;
   char *methodName = "method_TestNormal";
   char *encoding = 0;

   /* for every argument (after the program name) */
   for(i=1; i<argc; i++) {
      char* arg = argv[i];

      if(*arg == '-') {
         char* key = arg + 1;
         char* val = argv[i+1];

         if(key && (!strcmp(key, "help") || !strcmp(key, "-help"))) {
            print_help();
            return 0;
         }

         if(key && val) {
            if(!strcmp(key, "verbosity")) {
               if(!strcmp(val, "pretty")) {
                  verbosity = 0;
               }
               else if(!strcmp(val, "none")) {
                  verbosity = 1;
               }
               else if(!strcmp(val, "newlines")) {
                  verbosity = 2;
               }
            }
            else if(!strcmp(key, "version")) {
               if(!strcmp(val, "xmlrpc")) {
                  version = 0;
               }
               else if(!strcmp(val, "simple")) {
                  version = 1;
               }
            }
            else if(!strcmp(key, "escaping")) {
               if(!strcmp(val, "markup")) {
                  escaping |= xml_elem_markup_escaping ;
               }
               else if(!strcmp(val, "cdata")) {
                  escaping |= xml_elem_cdata_escaping;
               }
               else if(!strcmp(val, "non-ascii")) {
                  escaping |= xml_elem_non_ascii_escaping;
               }
               else if(!strcmp(val, "non-print")) {
                  escaping |= xml_elem_non_print_escaping;
               }
            }
            else if(!strcmp(key, "encoding")) {
               encoding = val;
            }
            else if(!strcmp(key, "output")) {
               if(!strcmp(val, "response")) {
                  output = 0;
               }
               else if(!strcmp(val, "xRequest")) {
                  output = 1;
               }
               else if(!strcmp(val, "both")) {
                  output = 2;
               }
            }
            else if(!strcmp(key, "method")) {
               methodName = val;
            }

            i++;
         }
      }
   }

   /* create a new server object */
   server = XMLRPC_ServerCreate();

   XMLRPC_ServerRegisterMethod(server, "validator1.arrayOfStructsTest", validator1_arrayOfStructsTest);
   XMLRPC_ServerRegisterMethod(server, "validator1.countTheEntities", validator1_countTheEntities);
   XMLRPC_ServerRegisterMethod(server, "validator1.easyStructTest", validator1_easyStructTest);
   XMLRPC_ServerRegisterMethod(server, "validator1.echoStructTest", validator1_echoStructTest);
   XMLRPC_ServerRegisterMethod(server, "validator1.manyTypesTest", validator1_manyTypesTest);
   XMLRPC_ServerRegisterMethod(server, "validator1.moderateSizeArrayCheck", validator1_moderateSizeArrayCheck);
   XMLRPC_ServerRegisterMethod(server, "validator1.nestedStructTest", validator1_nestedStructTest);
   XMLRPC_ServerRegisterMethod(server, "validator1.simpleStructReturnTest", validator1_simpleStructReturnTest);

   /* Now, let's get the client's xRequest from stdin.... */
   {
      char* filebuf[1024 * 100];
      int len = fread(filebuf, sizeof(char), sizeof(filebuf)-1, stdin);
      if(len) {
         filebuf[len] = 0;
         xRequest = XMLRPC_REQUEST_FromXML((const char*)filebuf, len, NULL);
      }
   }

   if(!xRequest) {
      fprintf(stderr, "bogus xmlrpc xRequest\n");
      return 1;
   }


   /* create a response struct */
   response = XMLRPC_RequestNew();
   XMLRPC_RequestSetRequestType(response, xmlrpc_request_response);

   /* Set various xml output options.  Or we could just use defaults. */
   call_options.xml_elem_opts.verbosity = verbosity == 1 ? xml_elem_no_white_space : (verbosity == 2 ? xml_elem_newlines_only : xml_elem_pretty);
   call_options.xml_elem_opts.escaping = escaping;
   call_options.version = (version == 1) ? xmlrpc_version_simple : xmlrpc_version_1_0;
   call_options.xml_elem_opts.encoding = encoding;
   XMLRPC_RequestSetOutputOptions(response, &call_options);

   /* call server method with client xRequest and assign the response to our response struct */
   XMLRPC_RequestSetData(response, XMLRPC_ServerCallMethod(server, xRequest, NULL));


   if(output == 1 || output == 2) {
      /* serialize client request as XML */
      char *outBuf;
      XMLRPC_RequestSetOutputOptions(xRequest, &call_options);
      outBuf = XMLRPC_REQUEST_ToXML(xRequest, 0);

      if(outBuf) {
         printf("%s\n\n --- \n\n", outBuf);
         free(outBuf);
      }
   }

   if(output == 0 || output == 2) {
      /* serialize server response as XML */
      char *outBuf = XMLRPC_REQUEST_ToXML(response, 0);

      if(outBuf) {
         printf(outBuf);
         free(outBuf);
      }
   }

   if(xRequest) {
      /* Free xRequest */
      XMLRPC_RequestFree(xRequest, 1);
   }
   if(response) {
      /* free response */
      XMLRPC_RequestFree(response, 1);
   }
   if(server) {
      XMLRPC_ServerDestroy(server);
   }

   return 0;
}
Exemplo n.º 15
0
 XMLRPC::~XMLRPC()
 {
    XMLRPC_RequestFree(xmlrpc_request, 1);
 }
Exemplo n.º 16
0
// passwd is already MD5 hashed by the time we get to it.
void LLUserAuth::authenticate(
	const std::string& auth_uri,
	const std::string& method,
	const std::string& firstname,
	const std::string& lastname,
	const std::string& passwd,
	const std::string& start,
	BOOL skip_optional,
	BOOL accept_tos,
	BOOL accept_critical_message,
	BOOL last_exec_froze, 
	const std::vector<const char*>& requested_options,
	const std::string& hashed_mac,
	const std::string& hashed_volume_serial)
{
	std::string dpasswd("$1$");
	dpasswd.append(passwd);
	LL_INFOS2("AppInit", "Authentication") << "Authenticating: " << firstname << " " << lastname << ", "
			<< /*dpasswd.c_str() <<*/ LL_ENDL;
	std::ostringstream option_str;
	option_str << "Options: ";
	std::ostream_iterator<const char*> appender(option_str, ", ");
	std::copy(requested_options.begin(), requested_options.end(), appender);
	option_str << "END";

	LL_INFOS2("AppInit", "Authentication") << option_str.str().c_str() << LL_ENDL;

	mAuthResponse = E_NO_RESPONSE_YET;
	//mDownloadTimer.reset();
	
	// create the request
	XMLRPC_REQUEST request = XMLRPC_RequestNew();
	XMLRPC_RequestSetMethodName(request, method.c_str());
	XMLRPC_RequestSetRequestType(request, xmlrpc_request_call);

	// stuff the parameters
	XMLRPC_VALUE params = XMLRPC_CreateVector(NULL, xmlrpc_vector_struct);
	XMLRPC_VectorAppendString(params, "first", firstname.c_str(), 0);
	XMLRPC_VectorAppendString(params, "last", lastname.c_str(), 0);
	XMLRPC_VectorAppendString(params, "passwd", dpasswd.c_str(), 0);
	XMLRPC_VectorAppendString(params, "start", start.c_str(), 0);
	// <edit>
	//XMLRPC_VectorAppendString(params, "version", gCurrentVersion.c_str(), 0); // Includes channel name
	//XMLRPC_VectorAppendString(params, "channel", gSavedSettings.getString("VersionChannelName").c_str(), 0);
	
	//WOW NEIL YOU ARE SO AWESOME!!
	
	XMLRPC_VectorAppendString(params, "version", std::string(
		gSavedSettings.getString("SpecifiedChannel") + " " +
		llformat("%d", gSavedSettings.getU32("SpecifiedVersionMaj")) + "." +
		llformat("%d", gSavedSettings.getU32("SpecifiedVersionMin")) + "." +
		llformat("%d", gSavedSettings.getU32("SpecifiedVersionPatch")) + "." +
		llformat("%d", gSavedSettings.getU32("SpecifiedVersionBuild"))
	).c_str(), 0); // Includes channel name
	
	XMLRPC_VectorAppendString(params, "channel", gSavedSettings.getString("SpecifiedChannel").c_str(), 0);
	// </edit>
	XMLRPC_VectorAppendString(params, "platform", PLATFORM_STRING, 0);
	// <edit>
	if(gSavedSettings.getBOOL("SpecifyMAC"))
		XMLRPC_VectorAppendString(params, "mac", gSavedSettings.getString("SpecifiedMAC").c_str(), 0);
	else
	// </edit>
	XMLRPC_VectorAppendString(params, "mac", hashed_mac.c_str(), 0);
	// A bit of security through obscurity: id0 is volume_serial
	// <edit>
	if(gSavedSettings.getBOOL("SpecifyID0"))
		XMLRPC_VectorAppendString(params, "id0", gSavedSettings.getString("SpecifiedID0").c_str(), 0);
	else
	// </edit>
	XMLRPC_VectorAppendString(params, "id0", hashed_volume_serial.c_str(), 0);
	if (skip_optional)
	{
		XMLRPC_VectorAppendString(params, "skipoptional", "true", 0);
	}
	if (accept_tos)
	{
		XMLRPC_VectorAppendString(params, "agree_to_tos", "true", 0);
	}
	if (accept_critical_message)
	{
		XMLRPC_VectorAppendString(params, "read_critical", "true", 0);
	}
	XMLRPC_VectorAppendInt(params, "last_exec_event", (int) last_exec_froze);

	// append optional requests in an array
	XMLRPC_VALUE options = XMLRPC_CreateVector("options", xmlrpc_vector_array);
	std::vector<const char*>::const_iterator it = requested_options.begin();
	std::vector<const char*>::const_iterator end = requested_options.end();
	for( ; it < end; ++it)
	{
		XMLRPC_VectorAppendString(options, NULL, (*it), 0);
	}
	XMLRPC_AddValueToVector(params, options);

	// put the parameters on the request
	XMLRPC_RequestSetData(request, params);

	mTransaction = new LLXMLRPCTransaction(auth_uri, request);
	
	XMLRPC_RequestFree(request, 1);

	LL_INFOS2("AppInit", "Authentication") << "LLUserAuth::authenticate: uri=" << auth_uri << LL_ENDL;
}