From: Asbjorn M. <ste...@us...> - 2002-03-15 14:53:52
|
Update of /cvsroot/epp-rtk/epp-rtk/c++/src In directory usw-pr-cvs1:/tmp/cvs-serv17718/src Modified Files: main_hello.cc main_login.cc testTools.cc testTools.h Log Message: -Added JavaDocs and explanatory comments to test programs/methods -Updated text in README file Index: main_hello.cc =================================================================== RCS file: /cvsroot/epp-rtk/epp-rtk/c++/src/main_hello.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** main_hello.cc 9 Mar 2002 11:58:01 -0000 1.7 --- main_hello.cc 15 Mar 2002 14:53:47 -0000 1.8 *************** *** 26,29 **** --- 26,34 ---- ************************************************************************/ + /** @file main_hello.cc + * @brief Test program for the <hello> command + * @author Asbjorn Steira Mikkelsen + */ + #include <string> #include <iostream.h> *************** *** 40,43 **** --- 45,51 ---- using namespace eppobject::epp; + /** Function that write the server response to cerr + * @param req Greeting returned from the server + */ void printRsp(const epp_Greeting_ref req) { *************** *** 194,203 **** int main(int argc, char * argv[]) { ! epp_Session test; string username, password; if(!handleArgs(test, argc, argv, username, password)) return 1; --- 202,215 ---- + /// Main part of test program for the <hello> command int main(int argc, char * argv[]) { ! // Initialize session object ! epp_Session test; string username, password; + // Handle arguments. This function might change the session object + // and username/password if(!handleArgs(test, argc, argv, username, password)) return 1; *************** *** 205,219 **** try { epp_Hello_ref l_obj(new epp_Hello()); epp_Greeting_ref myGr = test.connectAndGetGreeting(); test.processAction(l_obj); ! epp_Greeting_ref l_rsp = l_obj->getResponseData(); #ifndef TEST_IO_REQUEST2CERR printRsp(l_rsp); ! #endif return 0; --- 217,245 ---- try { + // Initialize <hello> command object epp_Hello_ref l_obj(new epp_Hello()); + // Connect to server and get the greeting. In this + // test program we do not do anything further with + // the returned greeting. epp_Greeting_ref myGr = test.connectAndGetGreeting(); + // As the <hello> request has no user-defined attributes + // we are ready to process the command. processAction will + // write the data to the server, wait for the response, + // parse the response, and put the data back into the + // session object. test.processAction(l_obj); ! ! // We then return the response data, for this command a ! // greeting epp_Greeting_ref l_rsp = l_obj->getResponseData(); #ifndef TEST_IO_REQUEST2CERR + // We then use the above function to print the response + // from the server printRsp(l_rsp); ! #endif ! // Finished return 0; Index: main_login.cc =================================================================== RCS file: /cvsroot/epp-rtk/epp-rtk/c++/src/main_login.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** main_login.cc 9 Mar 2002 11:58:01 -0000 1.8 --- main_login.cc 15 Mar 2002 14:53:47 -0000 1.9 *************** *** 26,29 **** --- 26,34 ---- ************************************************************************/ + /** @file main_login.cc + * @brief Test program for the <login> command + * @author Asbjorn Steira Mikkelsen + */ + #include <string> #include <vector> *************** *** 41,44 **** --- 46,53 ---- using namespace eppobject::epp; + + /** Function that write the server response to cerr + * @param req Response returned from the server + */ void printRsp(const epp_LoginRsp_ref req) { *************** *** 52,79 **** int main(int argc, char * argv[]) { epp_Session test; string username, password; if(!handleArgs(test, argc, argv, username, password)) return 1; try { epp_Options_ref ops(new epp_Options(epp_string("1.0"), epp_string("en"))); epp_Credentials_ref creds(new epp_Credentials()); - creds->m_client_id.ref(new epp_string(username)); creds->m_password.ref(new epp_string(password)); creds->m_new_password.ref(new epp_string("bar-FOO2")); creds->m_options = ops; ! epp_Command_ref cmd(new epp_Command()); cmd->m_creds = creds; cmd->m_client_trid.ref(new epp_trid("ABC-12345")); epp_objuri_seq_ref sers(new epp_objuri_seq); sers->push_back("urn:ietf:params:xml:ns:contact-1.0"); --- 61,96 ---- + /// Main part of test program for the <login> command int main(int argc, char * argv[]) { + // Initialize session object epp_Session test; string username, password; + // Handle arguments. This function might change the session object + // and username/password if(!handleArgs(test, argc, argv, username, password)) return 1; try { + + // Fill in options part of request epp_Options_ref ops(new epp_Options(epp_string("1.0"), epp_string("en"))); + // Fill in credentials part of request epp_Credentials_ref creds(new epp_Credentials()); creds->m_client_id.ref(new epp_string(username)); creds->m_password.ref(new epp_string(password)); creds->m_new_password.ref(new epp_string("bar-FOO2")); creds->m_options = ops; ! ! // Fill in command part of request epp_Command_ref cmd(new epp_Command()); cmd->m_creds = creds; cmd->m_client_trid.ref(new epp_trid("ABC-12345")); + // Fill in services part of request epp_objuri_seq_ref sers(new epp_objuri_seq); sers->push_back("urn:ietf:params:xml:ns:contact-1.0"); *************** *** 81,87 **** sers->push_back("urn:ietf:params:xml:ns:host-1.0"); epp_exturi_seq_ref extSers(new epp_exturi_seq); extSers->push_back("http://custom/obj1ext-1.0"); ! epp_LoginReq_ref l_req(new epp_LoginReq()); l_req->m_cmd = cmd; --- 98,106 ---- sers->push_back("urn:ietf:params:xml:ns:host-1.0"); + // Fill in extensions part of request epp_exturi_seq_ref extSers(new epp_exturi_seq); extSers->push_back("http://custom/obj1ext-1.0"); ! ! // Initialize and fill in the <login> request object epp_LoginReq_ref l_req(new epp_LoginReq()); l_req->m_cmd = cmd; *************** *** 89,105 **** --- 108,136 ---- l_req->m_extensions = extSers; + // Initialize <login> command object epp_Login_ref l_obj(new epp_Login()); + // Put the request data object into the command object l_obj->setRequestData(*l_req); + // Connect to server and get the greeting. In this + // test program we do not do anything further with + // the returned greeting. test.connectAndGetGreeting(); + // processAction will write the data object to the server, wait for + // the response, parse the response, and put the data back into the + // session object. test.processAction(l_obj); + // We then return the <login> response object epp_LoginRsp_ref l_rsp = l_obj->getResponseData(); #ifndef TEST_IO_REQUEST2CERR + // We then use the above function to print the response + // from the server printRsp(l_rsp); #endif + // Finished return 0; *************** *** 116,119 **** --- 147,153 ---- cerr << "</response>" << endl; #endif + } + catch(epptransport::epp_TrException ex) { + cout << "Exception: " << ex.getString() << endl; } catch(...) { Index: testTools.cc =================================================================== RCS file: /cvsroot/epp-rtk/epp-rtk/c++/src/testTools.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** testTools.cc 13 Mar 2002 20:30:30 -0000 1.10 --- testTools.cc 15 Mar 2002 14:53:47 -0000 1.11 *************** *** 27,30 **** --- 27,36 ---- + /** @file testTools.cc + * @brief Definition of helper functions used for testing toolkit + * @author Asbjorn Steira Mikkelsen + * @see testTools.h + */ + #include <map> #include "testTools.h" *************** *** 199,236 **** string & username, string & password) { ! //Change transport here: ! typedef epp_TransportSSL myTransport; typedef refcnt_ptr<myTransport> myTransport_ref; epp_TransportBase* transport = new myTransport; username = "testlogin"; password = "testpass"; ! typedef map<string, string> argsMap; argsMap commandArgs; ! if(argc > 1) { - if (!strcmp(argv[1], "-?")) - { - cout << argv[0]; - - if(transport->getType() != "epp_TransportIOStream") { - // Only relevant for connection-transport: - cout << " -n=<servername> -p=<serverPort>"; - } - - cout << " -l=<login> -s=<pass>"; - - if(transport->getType() == "epp_TransportSSL") { - // Only relevant for SSL-transport: - // <FIXME>Bug: -ca must include full path to file...</fixme> - cout << " -c=<cert> [-cadir=<cacertdir> -ca=<cacert>]"; - } - - cout << endl; - return false; - } // if "-?" for(int parm = 1; parm < argc; parm++) { --- 205,253 ---- string & username, string & password) { ! // CHANGE TRANSPORT HERE: ! typedef epp_TransportTCP myTransport; + // The transport handling in this function is a bit more + // complex than it needs to be for a Registrar, but this + // function needs to be capable of handling all types of + // transport. typedef refcnt_ptr<myTransport> myTransport_ref; epp_TransportBase* transport = new myTransport; + // Default user name and password username = "testlogin"; password = "testpass"; ! ! // Map that will contain all command line arguments typedef map<string, string> argsMap; argsMap commandArgs; ! ! // Check all arguments and fill in the above map if it ! // is valid for the current transport if(argc > 1) { + if (!strcmp(argv[1], "-?")) { + // Return with a line showing allowed command line arguments + + cout << argv[0]; + + if(transport->getType() != "epp_TransportIOStream") { + // Only relevant for connection-transports + cout << " -n=<servername> -p=<serverPort>"; + } + + cout << " -l=<login> -s=<pass>"; + + if(transport->getType() == "epp_TransportSSL") { + // Only relevant for SSL-transport + // <FIXME>Bug: -ca must include full path to file...</fixme> + cout << " -c=<cert> [-cadir=<cacertdir> -ca=<cacert>]"; + } + + cout << endl; + return false; + } // if "-?" + + // If not "-?", process the rest of the command line arguments for(int parm = 1; parm < argc; parm++) { *************** *** 242,247 **** if(transport->getType() != "epp_TransportIOStream") { - // Only relevant for connection-transport: if (!strncmp(argv[parm], "-n=", 3)) { commandArgs["n"] = &argv[parm][3]; --- 259,264 ---- if(transport->getType() != "epp_TransportIOStream") { + // Only relevant for connection-transports if (!strncmp(argv[parm], "-n=", 3)) { commandArgs["n"] = &argv[parm][3]; *************** *** 254,259 **** if(transport->getType() == "epp_TransportSSL") { - // Only relevant if the transport is using SSL... if (!strncmp(argv[parm], "-c=", 3)) { commandArgs["c"] = &argv[parm][3]; --- 271,276 ---- if(transport->getType() == "epp_TransportSSL") { + // Only relevant for SSL-transport if (!strncmp(argv[parm], "-c=", 3)) { commandArgs["c"] = &argv[parm][3]; *************** *** 282,285 **** --- 299,303 ---- #if 0 + // Write out all accepted command line arguments for( map<string, string>::const_iterator i = commandArgs.begin(); i != commandArgs.end(); ++i) *************** *** 289,312 **** #endif if(transport->getType() == "epp_TransportSSL" && (commandArgs["c"] != "" || commandArgs["ca"] != "")) { // cout << commandArgs["c"] << " " << commandArgs["ca"] << " " << commandArgs["cadir"] << endl; transport = new epp_TransportSSL(commandArgs["c"], commandArgs["ca"], commandArgs["cadir"]); } ! if(commandArgs["n"] != "") { transport->setServerName(commandArgs["n"]); } if(commandArgs["p"] != "") { transport->setServerPort(atol(commandArgs["p"].c_str())); } myTransport_ref mt(dynamic_cast<myTransport*>(transport)); - sess.setTransport(mt); ! // Do not delete this pointer, the ref-counter class takes care of it... ! // delete transport; return true; --- 307,340 ---- #endif + // If transport is SSL, and we need to set SSL-specific elements, we have to + // use the epp_TransportSSL constructor to set these. This is because the + // SSL-specific set/get methods are not part of the transport base class, and + // we want to be able to compile this file regardless of which transport to use. + // + // If you are always going to use SSL, you can use get/set methods directly. if(transport->getType() == "epp_TransportSSL" && (commandArgs["c"] != "" || commandArgs["ca"] != "")) { // cout << commandArgs["c"] << " " << commandArgs["ca"] << " " << commandArgs["cadir"] << endl; transport = new epp_TransportSSL(commandArgs["c"], commandArgs["ca"], commandArgs["cadir"]); } ! ! // Set server name, if applicable if(commandArgs["n"] != "") { transport->setServerName(commandArgs["n"]); } + // Set server port, if applicable if(commandArgs["p"] != "") { transport->setServerPort(atol(commandArgs["p"].c_str())); } + // Put the transport into the session class myTransport_ref mt(dynamic_cast<myTransport*>(transport)); sess.setTransport(mt); ! // Do not delete the transport pointer, ! // the ref-counter class takes care of it... ! // delete transport; + // Finished return true; *************** *** 318,321 **** --- 346,350 ---- #ifdef TEST_IO_REQUEST2CERR + // We do not want to login when using IOStream transport if(mySession.getTransport()->getType() == "epp_TransportIOStream") { return; *************** *** 323,326 **** --- 352,356 ---- #endif #ifdef TEST_IO_RESULT2CERR + // We do not want to login when using IOStream transport if(mySession.getTransport()->getType() == "epp_TransportIOStream") { return; *************** *** 329,339 **** try { ! // Filling Login-object: ! epp_LoginReq_ref l_req(new epp_LoginReq()); - l_req->m_cmd.ref(new epp_Command()); - l_req->m_cmd->m_creds.ref(new epp_Credentials()); l_req->m_cmd->m_creds->m_options.ref(new epp_Options(epp_string("1.0"), epp_string("en"))); --- 359,369 ---- try { ! ! // Initialize <login> request object and sub-elements epp_LoginReq_ref l_req(new epp_LoginReq()); l_req->m_cmd.ref(new epp_Command()); l_req->m_cmd->m_creds.ref(new epp_Credentials()); + + // Fill in credentials information l_req->m_cmd->m_creds->m_options.ref(new epp_Options(epp_string("1.0"), epp_string("en"))); *************** *** 341,364 **** l_req->m_cmd->m_creds->m_password.ref(new epp_string(password)); l_req->m_cmd->m_client_trid.ref(new epp_trid("LogIn-1")); l_req->m_services.ref(new epp_objuri_seq()); l_req->m_services->push_back("urn:ietf:params:xml:ns:contact-1.0"); l_req->m_services->push_back("urn:ietf:params:xml:ns:domain-1.0"); l_req->m_services->push_back("urn:ietf:params:xml:ns:host-1.0"); ! epp_Login_ref l_obj(new epp_Login()); l_obj->setRequestData(*l_req); ! // Process request and get response: ! epp_Greeting_ref myGr = mySession.connectAndGetGreeting(); mySession.processAction(l_obj); - epp_LoginRsp_ref l_rsp = l_obj->getResponseData(); ! // Print response: if(mySession.getTransport()->getType() == "epp_TransportIOStream") { printResponsePart(l_rsp->m_rsp); --- 371,401 ---- l_req->m_cmd->m_creds->m_password.ref(new epp_string(password)); + // Fill in client transaction ID l_req->m_cmd->m_client_trid.ref(new epp_trid("LogIn-1")); + // Fill in services information l_req->m_services.ref(new epp_objuri_seq()); l_req->m_services->push_back("urn:ietf:params:xml:ns:contact-1.0"); l_req->m_services->push_back("urn:ietf:params:xml:ns:domain-1.0"); l_req->m_services->push_back("urn:ietf:params:xml:ns:host-1.0"); ! ! // Initialize <login> command object epp_Login_ref l_obj(new epp_Login()); + // Put the request data object into the command object l_obj->setRequestData(*l_req); ! // Connect to server and get the greeting. epp_Greeting_ref myGr = mySession.connectAndGetGreeting(); + // processAction will write the data object to the server, wait for + // the response, parse the response, and put the data back into the + // session object. mySession.processAction(l_obj); ! // Return the <login> response object ! epp_LoginRsp_ref l_rsp = l_obj->getResponseData(); + // Print response if the transport is IOStream if(mySession.getTransport()->getType() == "epp_TransportIOStream") { printResponsePart(l_rsp->m_rsp); Index: testTools.h =================================================================== RCS file: /cvsroot/epp-rtk/epp-rtk/c++/src/testTools.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** testTools.h 8 Mar 2002 12:11:51 -0000 1.9 --- testTools.h 15 Mar 2002 14:53:48 -0000 1.10 *************** *** 30,33 **** --- 30,38 ---- + /** @file testTools.h + * @brief Definition of helper functions used for testing toolkit + * @author Asbjorn Steira Mikkelsen + */ + #include <string> #include <iostream.h> *************** *** 37,54 **** --- 42,111 ---- + /** Function that takes an eppobject::epp::epp_Result sequence and writes each + * of them to cerr on the same format as in the originally returned xml + * string + * @param results The results element returned from the server + */ void printResultsSeq(const eppobject::epp::epp_result_seq_ref results); + + /** Function that takes an eppobject::epp::epp_TransID object and writes + * it to cerr on the same format as in the originally returned xml + * string + * @param transID The transaction ID element returned from the server + */ void printTransID(const eppobject::epp::epp_TransID_ref transID); + /** Function that takes an eppobject::epp::epp_Response object and writes + * it to cerr on the same format as in the originally returned xml + * string + * @param response The response element returned from the server + */ void printResponsePart(const eppobject::epp::epp_Response_ref response); + + /** Function that takes an eppobject::epp::epp_Response object and writes + * everything up to a potential resData element to cerr on the same format + * as in the originally returned xml string + * @param response The response element returned from the server + */ void printResponsePart1(const eppobject::epp::epp_Response_ref response); + + /** Function that takes an eppobject::epp::epp_Response object and writes + * everything after a potential resData element to cerr on the same format + * as in the originally returned xml string + * @param response The response element returned from the server + */ void printResponsePart2(const eppobject::epp::epp_Response_ref response); + /** Function that writes to cerr a standard resData header + * @param object The object type (e.g., "domain") + * @param returnType The return type (e.g., "creData") + */ void printResDataHeaders(const string & object, const string & returntype); + + /** Function that writes to cerr a standard resData footer + * @param object The object type (e.g., "domain") + * @param returnType The return type (e.g., "creData") + */ void printResDataFooter(const string & object, const string & returntype); + /** Function that handles the command line arguments sent to the program + * and initializes the transport accordingly + * @param sess Session to use when communicating with server + * @param argc Count of command line arguments + * @param argv Actual command line arguments + * @param username Login name on server + * @param password Password on server + * @return true if arguments set correcetly, otherwise false + */ bool handleArgs(eppobject::epp::epp_Session & sess, int argc, char * argv[], string & username, string & password); + /** Function that tries to login to a server using information in the + * eppobject::epp::epp_Session object. + * @param mySession Session data to use when communication with server + * @param username Login name on server + * @param password Password on server + */ void testLogIn(eppobject::epp::epp_Session & mySession, const string & username, |