src/shepp/SheppCommandFunctions.H

Go to the documentation of this file.
00001 /* ${copyright}$ */
00002 /* $Id: SheppCommandFunctions.H 780 2006-06-26 12:45:35Z eduardo $ */
00006 #ifndef __SHEPP_COMMAND_FUNCTIONS_H__
00007 #define __SHEPP_COMMAND_FUNCTIONS_H__
00008 
00009 #include <unistd.h>   //alarm
00010 
00011 #include "SheppGlobal.H"
00012 #include "SheppStrUtil.H"
00013 #include "SheppObjSet.H"
00014 #include "SheppPrint.H"
00015 
00016 #include "IoException.H"
00017 #include "TransportException.H"
00018 #include "EppException.H"
00019 #include "XmlException.H"
00020 
00021 #include "Login.H"
00022 #include "Logout.H"
00023 
00024 // Functions for eppsh commands
00025 int cmd_login(char *);
00026 int cmd_logout(char *);
00027 int cmd_hello(char *);
00028 int cmd_poll(char *);
00029 int cmd_domain(char *);
00030 int cmd_contact(char *);
00031 int cmd_brorg(char *);
00032 
00033 int cmd_xmlcmd(char *);
00034 int cmd_xmlrsp(char *);
00035 
00036 int cmd_server(char *);
00037 int cmd_port(char *);
00038 int cmd_client_pem(char *);
00039 int cmd_root_pem(char *);
00040 int cmd_pass(char *);
00041 int cmd_user(char *);
00042 int cmd_login_pw(char *);
00043 int cmd_login_new_pw(char *);
00044 int cmd_lang(char *);
00045 int cmd_connect(char *);
00046 int cmd_disconnect(char *);
00047 
00048 int cmd_help(char *);
00049 int cmd_about(char *);
00050 int cmd_quit(char *);
00051 
00052 int cmd_beauty(char *);
00053 int cmd_debug(char *);
00054 int cmd_autorsp(char *);
00055 int cmd_keepalive(char *);
00056 int cmd_peer_crt_check(char *);
00057 
00059 void init_commands()
00060 {
00061   SheppCommand cmd;
00062 
00063   //non-EPP commands
00064   cmd.reset("?", cmd_help, "This help screen");
00065   _commands.insert(_commands.end(), cmd);
00066   cmd.reset("help", cmd_help, "This help screen");
00067   _commands.insert(_commands.end(), cmd);
00068   cmd.reset("about", cmd_about, "shepp version information");
00069   _commands.insert(_commands.end(), cmd);
00070   cmd.reset("exit", cmd_quit, "Exit shepp\n");
00071   _commands.insert(_commands.end(), cmd);
00072 
00073   //runtime flags
00074   cmd.reset("beauty", cmd_beauty, "Turn XML beautifier on/off");
00075   _commands.insert(_commands.end(), cmd);
00076   cmd.reset("debug", cmd_debug, "Turn debug messages on/off");
00077   _commands.insert(_commands.end(), cmd);
00078   cmd.reset("autorsp", cmd_autorsp, "Turn auto-show response on/off");
00079   _commands.insert(_commands.end(), cmd);
00080   cmd.reset("keepalive", cmd_keepalive, "Turn keep-alive on/off");
00081   _commands.insert(_commands.end(), cmd);
00082   cmd.reset("peer-crt-check", cmd_peer_crt_check,
00083             "Turn peer's certificate check on/off\n");
00084   _commands.insert(_commands.end(), cmd);
00085 
00086   //connection related commands
00087   cmd.reset("server", cmd_server, "Sets server address");
00088   _commands.insert(_commands.end(), cmd);
00089   cmd.reset("port", cmd_port, "Sets server port");
00090   _commands.insert(_commands.end(), cmd);
00091   cmd.reset("client-pem", cmd_client_pem,
00092             "Sets client.pem certificate file location");
00093   _commands.insert(_commands.end(), cmd);
00094   cmd.reset("root-pem", cmd_root_pem,
00095             "Sets root.pem certificate file location");
00096   _commands.insert(_commands.end(), cmd);
00097   cmd.reset("pass", cmd_pass, "Sets SSL certificate passphrase");
00098   _commands.insert(_commands.end(), cmd);  
00099   cmd.reset("user", cmd_user, "Sets EPP Login username");
00100   _commands.insert(_commands.end(), cmd);
00101   cmd.reset("pw", cmd_login_pw, "Sets EPP Login password");
00102   _commands.insert(_commands.end(), cmd);
00103   cmd.reset("newpw", cmd_login_new_pw, "Sets new EPP Login password");
00104   _commands.insert(_commands.end(), cmd);
00105   cmd.reset("lang", cmd_lang, "Sets text language");
00106   _commands.insert(_commands.end(), cmd);
00107   cmd.reset("connect", cmd_connect, "Establishes connection");
00108   _commands.insert(_commands.end(), cmd);
00109   cmd.reset("disconnect", cmd_disconnect, "Closes connection\n");
00110   _commands.insert(_commands.end(), cmd);
00111 
00112   //EPP commands
00113   cmd.reset("login", cmd_login, "EPP Login");
00114   _commands.insert(_commands.end(), cmd);
00115   cmd.reset("logout", cmd_logout, "EPP Logout");
00116   _commands.insert(_commands.end(), cmd);
00117   cmd.reset("hello", cmd_hello, "EPP Hello");
00118   _commands.insert(_commands.end(), cmd);
00119   cmd.reset("poll", cmd_poll, "EPP Poll related actions");
00120   _commands.insert(_commands.end(), cmd);
00121   cmd.reset("domain", cmd_domain, "EPP Domain related actions");
00122   _commands.insert(_commands.end(), cmd);
00123   cmd.reset("contact", cmd_contact, "EPP Contact related actions");
00124   _commands.insert(_commands.end(), cmd);
00125   cmd.reset("brorg", cmd_brorg, "EPP BrOrg related actions\n");
00126   _commands.insert(_commands.end(), cmd);
00127 
00128   //XML related commands
00129   cmd.reset("xmlcmd", cmd_xmlcmd, "Show last command XML");
00130   _commands.insert(_commands.end(), cmd);
00131   cmd.reset("xmlrsp", cmd_xmlrsp, "Show last response XML");
00132   _commands.insert(_commands.end(), cmd);
00133 }
00134 
00136 
00140 const SheppCommand* find_command(string name)
00141 {
00142   CMD_CONTAINER<SheppCommand>::const_iterator it;
00143   for (it = _commands.begin(); it != _commands.end(); it++) {
00144     if ((*it).name == name) {
00145       return &(*it);
00146     }
00147   }
00148 
00149   return ((const SheppCommand *) NULL);
00150 }
00151 
00153 
00157 int cmd_server(char *arg)
00158 {
00159   vector<string> words = SheppStrUtil::parse_line(arg);
00160 
00161   if (words.size() != 0) {
00162     string new_port;
00163     string new_server;
00164     SheppStrUtil::split(words[0], new_server, new_port, ":", true);
00165     if (new_server != _server) {
00166       _server = new_server;
00167     }
00168     if (new_port != "" && _port != atoi(new_port.c_str())) {
00169       _port = atoi(new_port.c_str());
00170     }
00171   }
00172 
00173   if (_server != "") {
00174     printf("server %s:%d\n", _server.c_str(), _port);
00175   } else {
00176     printf("no server address given.\n");
00177   }
00178 
00179   return 0;
00180 }
00181 
00183 
00187 int cmd_port(char *arg)
00188 {
00189   vector<string> words = SheppStrUtil::parse_line(arg);
00190 
00191   if (words.size() == 1) {
00192     if (_port != atoi(words[0].c_str())) {
00193       _port = atoi(words[0].c_str());
00194     }
00195   }
00196 
00197   printf("port %d\n", _port);
00198 
00199   return 0;
00200 }
00201 
00203 
00207 int cmd_client_pem(char *arg)
00208 {
00209   vector<string> words = SheppStrUtil::parse_line(arg);
00210 
00211   if (words.size() == 1) {
00212     if (_client_pem != words[0]) {
00213       _client_pem = words[0];
00214       printf("Warning: changing cetificates requires you to reconnect.\n");
00215     }
00216   } else if (words.size() > 1) {
00217     printf("usage: client-pem <file>\n");
00218     return -1;
00219   }
00220 
00221   printf("Current client.pem is %s\n", _client_pem.c_str());
00222   return 0;
00223 }
00224 
00226 
00230 int cmd_root_pem(char *arg)
00231 {
00232   vector<string> words = SheppStrUtil::parse_line(arg);
00233 
00234   if (words.size() == 1) {
00235     if (_root_pem != words[0]) {
00236       _root_pem = words[0];
00237       printf("Warning: changing cetificates requires you to reconnect.\n");
00238     }
00239   } else if (words.size() > 1) {
00240     printf("usage: root-pem <file>\n");
00241     return -1;
00242   }
00243 
00244   printf("Current root.pem is %s\n", _root_pem.c_str());
00245   return 0;
00246 }
00247 
00249 
00253 int cmd_pass(char *arg)
00254 {
00255   _passphrase = (string) arg;
00256   return 0;
00257 }
00258 
00260 
00264 int cmd_user(char *arg)
00265 {
00266   vector<string> words = SheppStrUtil::parse_line(arg);
00267 
00268   if (words.size() == 0) {
00269     if (_user != "") {
00270       printf("username: %s\n", _user.c_str());
00271       return 0;
00272     } else {
00273       printf("no username given.\n");
00274       return -1;
00275     }
00276   }
00277 
00278   _user = words[0];
00279 
00280   return 0;
00281 }
00282 
00284 
00288 int cmd_login_pw(char *arg)
00289 {
00290   _login_pw = (string) arg;
00291   return 0;
00292 }
00293 
00295 
00299 int cmd_login_new_pw(char *arg)
00300 {
00301   _login_new_pw = (string) arg;
00302   _new_pw = true;
00303   return 0;
00304 }
00305 
00307 
00311 int cmd_lang(char *arg)
00312 {
00313   vector<string> words = SheppStrUtil::parse_line(arg);
00314 
00315   if (words.empty()) {
00316     printf("usage: lang [en|pt]\n");
00317     return -1;
00318   } else {
00319     _lang = words[0];
00320   }
00321 
00322   return 0;
00323 }
00324 
00326 
00330 int cmd_connect(char *arg)
00331 {
00332   if (cmd_server(arg) != 0) {
00333     return -1;
00334   }
00335 
00336   bool exception = false;
00337 
00338   // Session code goes here
00339   try {
00340     _session = auto_ptr<Session>(new Session(_server, _port));
00341     if (_peer_crt_check) {
00342       _session->enable_cert_common_name_check();
00343     } else {
00344       _session->disable_cert_common_name_check();
00345     }
00346     _session->connect(_client_pem, _root_pem, _passphrase);
00347     printf("Connected to %s\n", _server.c_str());
00348     
00349     Greeting *greeting = _session->get_greeting();  
00350     if (_debug) {
00351       if (greeting) {
00352         printf("Greeting received\n");
00353       }
00354     } //_debug
00355 
00356     _xmlrsp = _session->get_last_response();
00357     _xmlcmd = _session->get_last_command();
00358 
00359     _connected = true;
00360 
00361   } catch (const IoException &e) {
00362     printf("ERROR! IO Exception [%d]:\n[%s]\n", 
00363            e.get_code(), e.get_msg().c_str());
00364     exception = true;
00365   } catch (const TransportException &e) {
00366     printf("ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
00367            e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str());
00368     exception = true;
00369   } catch (const GeneralException &e) {
00370     printf("ERROR! General Exception [%d]:\n[%s]\n", 
00371            e.get_code(), e.get_msg().c_str());
00372     exception = true;
00373   }
00374 
00375   if (exception) {
00376 #if 0
00377     printf("error connecting to %s:%d\n", _server.c_str(), _port);
00378 #endif
00379     return -1;
00380   }
00381 
00382   // print greeting
00383   cmd_xmlrsp("");
00384 
00385   return 0;
00386 }
00387 
00389 
00393 int cmd_disconnect(char *arg)
00394 {
00395   if (_connected) {
00396     bool exception = false;
00397 
00398     // Session code goes here
00399     try {
00400       _session->disconnect();
00401       printf("disconnected from %s\n", _server.c_str());
00402       _connected = false;
00403     } catch (const TransportException &e) {
00404       printf("ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
00405              e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str());
00406       exception = true;
00407     } catch (const GeneralException &e) {
00408       printf("ERROR! General Exception [%d]:\n[%s]\n", 
00409              e.get_code(), e.get_msg().c_str());
00410       exception = true;
00411     }
00412 
00413     if (exception) {
00414       return -1;
00415     }
00416   } else {
00417     printf("not connected\n");
00418   }
00419 
00420   return 0;
00421 }
00422 
00424 
00428 int cmd_beauty(char *arg)
00429 {
00430   vector<string> words = SheppStrUtil::parse_line(arg);
00431 
00432   if (words.empty()) {
00433     if (_beauty) {
00434       printf("XML beautifier is ON\n");
00435     } else {
00436       printf("XML beautifier is OFF\n");
00437     }
00438     return 0;
00439   } else if (words.size() > 1) {
00440     printf("usage: beauty [on|off]\n");
00441     return -1;
00442   }
00443 
00444   if (words[0] == "on") {
00445     _beauty = true;
00446     printf("XML beautifier now ON\n");
00447   } else if (words[0] == "off") {
00448     _beauty = false;
00449     printf("XML beautifier now OFF\n");
00450   } else {
00451     printf("usage: beauty [on|off]\n");
00452     return -1;
00453   }
00454 
00455   return 0;
00456 }
00457 
00459 
00463 int cmd_debug(char *arg)
00464 {
00465   vector<string> words = SheppStrUtil::parse_line(arg);
00466 
00467   if (words.empty()) {
00468     if (_debug) {
00469       printf("Debug is ON\n");
00470     } else {
00471       printf("Debug is OFF\n");
00472     }
00473     return 0;
00474   } else if (words.size() > 1) {
00475     printf("usage: debug [on|off]\n");
00476     return -1;
00477   }
00478 
00479   if (words[0] == "on") {
00480     _debug = true;
00481     printf("Debug now ON\n");
00482   } else if (words[0] == "off") {
00483     _debug = false;
00484     printf("Debug now OFF\n");
00485   } else {
00486     printf("usage: beauty [on|off]\n");
00487     return -1;
00488   }
00489 
00490   return 0;
00491 }
00492 
00494 
00498 int cmd_autorsp(char *arg)
00499 {
00500   vector<string> words = SheppStrUtil::parse_line(arg);
00501 
00502   if (words.empty()) {
00503     if (_autorsp) {
00504       printf("autorsp is ON\n");
00505     } else {
00506       printf("autorsp is OFF\n");
00507     }
00508     return 0;
00509   } else if (words.size() > 1) {
00510     printf("usage: autorsp [on|off]\n");
00511     return -1;
00512   }
00513 
00514   if (words[0] == "on") {
00515     _autorsp = true;
00516     printf("autorsp now ON\n");
00517   } else if (words[0] == "off") {
00518     _autorsp = false;
00519     printf("autorsp now OFF\n");
00520   } else {
00521     printf("usage: autorsp [on|off]\n");
00522     return -1;
00523   }
00524 
00525   return 0;
00526 }
00527 
00529 
00533 int cmd_keepalive(char *arg)
00534 {
00535   vector<string> words = SheppStrUtil::parse_line(arg);
00536 
00537   if (words.empty()) {
00538     if (_keepalive) {
00539       printf("Keep-alive is ON\n");
00540     } else {
00541       printf("Keep-alive is OFF\n");
00542     }
00543     return 0;
00544   } else if (words.size() > 1) {
00545     printf("usage: keepalive [on|off]\n");
00546     return -1;
00547   }
00548 
00549   if (words[0] == "on") {
00550     _keepalive = true;
00551     printf("Keep-alive now ON\n");
00552   } else if (words[0] == "off") {
00553     _keepalive = false;
00554     printf("Keep-alive now OFF\n");
00555   } else {
00556     printf("usage: keepalive [on|off]\n");
00557     return -1;
00558   }
00559 
00560   if (_keepalive) {
00561     alarm(_keepalive_timer);
00562   } else {
00563     alarm(0);
00564   }
00565 
00566   return 0;
00567 }
00568 
00570 
00574 int cmd_peer_crt_check(char *arg)
00575 {
00576   vector<string> words = SheppStrUtil::parse_line(arg);
00577 
00578   if (words.empty()) {
00579     if (_peer_crt_check) {
00580       printf("Peer's certificate check is ON\n");
00581     } else {
00582       printf("Peer's certificate check is OFF\n");
00583     }
00584     return 0;
00585   } else if (words.size() > 1) {
00586     printf("usage: peer-crt-check [on|off]\n");
00587     return -1;
00588   }
00589 
00590   if (words[0] == "on") {
00591     _peer_crt_check = true;
00592     printf("Peer's certificate check now ON\n");
00593   } else if (words[0] == "off") {
00594     _peer_crt_check = false;
00595     printf("Peer's certificate check now OFF\n");
00596   } else {
00597     printf("usage: peer-crt-check [on|off]\n");
00598     return -1;
00599   }
00600 
00601   return 0;
00602 }
00603 
00605 static void sig_alrm(int signo)
00606 {
00607   if (_connected && !_cmd_running) {
00608     _ka_running = true;
00609     cmd_hello("keepalive");
00610     _ka_running = false;
00611   }
00612   alarm(_keepalive_timer);
00613 }
00614 
00616 
00620 int cmd_xmlcmd(char *arg)
00621 {
00622   if (!_connected) {
00623     printf("not connected\n");
00624     return -1;
00625   }
00626 
00627   if (_beauty) {
00628     // Convert to UTF8
00629     string last_command("");
00630     StrUtil::iso88591_to_utf8(_xmlcmd, last_command);
00631     
00632     if (_session->get_last_command() == "") {
00633       printf("\n");
00634       return 0;
00635     }
00636     try {
00637       StrUtil str_util;
00638       printf("%s\n", str_util.xml_beautifier(last_command).c_str());
00639     } catch (const XmlException &e) {
00640       printf("ERROR! XML Exception [%d]:\n[%s]\n", e.get_code(),
00641              e.get_msg().c_str());
00642     }
00643   } else {
00644     printf("%s\n", _session->get_last_command().c_str());
00645   }
00646   return 0;
00647 }
00648 
00650 
00654 int cmd_xmlrsp(char *arg)
00655 {
00656   if (!_connected) {
00657     printf("not connected\n");
00658     return -1;
00659   }
00660 
00661   if (_beauty) {
00662     // No need to convert to UTF8
00663     if (_xmlrsp == "") {
00664       printf("\n");
00665       return 0;
00666     }
00667     try {
00668       StrUtil str_util;
00669       printf("%s\n", str_util.xml_beautifier(_xmlrsp).c_str());
00670     } catch (const XmlException &e) {
00671       printf("ERROR! XML Exception [%d]:\n[%s]\n", e.get_code(),
00672              e.get_msg().c_str());
00673     }
00674   } else {
00675     printf("%s\n", _xmlrsp.c_str());
00676   }
00677   return 0;
00678 }
00679 
00680 // EPP action processing functions
00681 
00683 void print_cmd_sent_ok()
00684 {
00685   if (!_autorsp) {
00686     printf("Ok! Use 'xmlcmd' and 'xmlrsp' to view command/response "
00687            "XML code.\n");
00688   } else {
00689     cmd_xmlrsp("");
00690   }
00691 }
00692 
00694 
00697 int process_action(Action &act)
00698 {
00699   if (!_connected) {
00700     printf("not connected\n");
00701     return -1;
00702   }
00703 
00704   bool exception = false;
00705 
00706   // prevents concurrency with keep-alive
00707   if (!_ka_running) {
00708     _cmd_running = true;;
00709   } else {
00710     printf("ERROR! Keep-alive is running. Please try again.\n");
00711     return -1;
00712   }
00713 
00714   try {
00715     _session->process_action(&act);
00716     _xmlrsp = _session->get_last_response();
00717     _xmlcmd = _session->get_last_command();
00718   } catch (const EppException &e) {
00719     printf("ERROR! EPP Exception [%d]:\n[%s]\n", e.get_code(),
00720            e.get_msg().c_str());  
00721     exception = true;
00722   } catch (const IoException &e) {
00723     printf("ERROR! IO Exception [%d]:\n[%s]\n", 
00724            e.get_code(), e.get_msg().c_str());
00725     exception = true;
00726     _connected = false;
00727   } catch (const TransportException &e) {
00728     printf("ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
00729            e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str());
00730     exception = true;
00731     _connected = false;
00732   } catch (const GeneralException &e) {
00733     printf("ERROR! General Exception [%d]:\n[%s]\n", 
00734            e.get_code(), e.get_msg().c_str());
00735     exception = true;
00736   }
00737 
00738   if (exception) {
00739     _cmd_running = false;
00740     return -1;
00741   }
00742 
00743   print_cmd_sent_ok();
00744 
00745   // a command was just run; postpone keepalive alarm
00746   if (_keepalive) {
00747     alarm(_keepalive_timer);
00748   }
00749 
00750   _cmd_running = false;
00751   return 0;
00752 }
00753 
00755 
00759 int cmd_login(char *arg)
00760 {
00761   if (!_connected) {
00762     printf("not connected\n");
00763     return -1;
00764   }
00765 
00766   if (_user == "") {
00767     printf("no username given.\n");
00768     return -1;
00769   }
00770 
00771   Login act;
00772   LoginCmd *cmd = act.get_command();
00773 
00774   cmd->set_clID(_user);
00775   cmd->set_pw(_login_pw);
00776 
00777   if (_new_pw) {
00778     _new_pw = false;
00779     cmd->set_new_pw(_login_new_pw);
00780   }
00781 
00782   if (_lang != "" && _lang != "en") {
00783     cmd->set_lang(_lang);
00784   }
00785 
00786   if (process_action(act) != 0) {
00787     return -1;
00788   }
00789 
00790   return 0;
00791 }
00792 
00794 
00798 int cmd_logout(char *arg)
00799 {
00800   if (!_connected) {
00801     printf("not connected\n");
00802     return -1;
00803   }
00804 
00805   Logout act;
00806 
00807   if (process_action(act) != 0) {
00808     return -1;
00809   }  
00810 
00811   return 0;
00812 }
00813 
00815 
00819 int cmd_hello(char *arg)
00820 {
00821   if (!_connected) {
00822     printf("not connected\n");
00823     return -1;
00824   }
00825 
00826   vector<string> words = SheppStrUtil::parse_line(arg);
00827 
00828   if (_ka_running && 
00829       !(words.size() == 1 && words[0] == "keepalive")) {
00830     printf("ERROR! Keep-alive is running. Please try again.\n");
00831     return -1;
00832   }
00833 
00834   bool exception = false;
00835 
00836   // prevents concurrency with keep-alive
00837   if (!_ka_running) {
00838     _cmd_running = true;
00839   }
00840 
00841   try {
00842     if (_debug) {
00843       printf("Sending EPP Hello\n");
00844     }
00845     _session->send_hello();
00846     // updates _xmlcmd and _xmlrsp only if it's not a keep-alive run
00847     if (!_ka_running) {
00848       _xmlrsp = _session->get_last_response();
00849       _xmlcmd = _session->get_last_command();
00850     }
00851   } catch (const EppException &e) {
00852     printf("ERROR! EPP Exception [%d]:\n[%s]\n", e.get_code(),
00853            e.get_msg().c_str());  
00854     exception = true;
00855   } catch (const IoException &e) {
00856     printf("ERROR! IO Exception [%d]:\n[%s]\n", 
00857            e.get_code(), e.get_msg().c_str());
00858     exception = true;
00859     _connected = false;
00860   } catch (const TransportException &e) {
00861     printf("ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
00862            e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str());
00863     exception = true;
00864     _connected = false;
00865   } catch (const GeneralException &e) {
00866     printf("ERROR! General Exception [%d]:\n[%s]\n", 
00867            e.get_code(), e.get_msg().c_str());
00868     exception = true;
00869   }
00870 
00871   if (exception) {
00872     if (_cmd_running) {
00873       _cmd_running = false;
00874     }
00875     return -1;
00876   }
00877 
00878   if (!_ka_running) {
00879     print_cmd_sent_ok();
00880   }
00881 
00882   if (_cmd_running) {
00883     // a command was just run; postpone keepalive alarm
00884     if (_keepalive) {
00885       alarm(_keepalive_timer);
00886     }
00887     _cmd_running = false;
00888   }
00889   return 0;
00890 }
00891 
00892 // non-EPP commands
00893 
00895 
00899 int cmd_quit(char *arg)
00900 {
00901   if (_connected) {
00902     _session->disconnect();
00903   }
00904   printf("Bye\n");
00905   exit(0);
00906 }
00907 
00909 
00913 int cmd_help(char *arg)
00914 {
00915   CMD_CONTAINER<SheppCommand>::const_iterator it;
00916   for (it = _commands.begin(); it != _commands.end(); it++) {
00917     printf("%-16s %s\n", (*it).name.c_str(), (*it).brief.c_str());
00918   }
00919 
00920   return 0;
00921 }
00922 
00924 
00928 int cmd_about(char *arg)
00929 {
00930   printf("shepp version " SHEPP_VERSION ", an EPP client shell!\n");
00931   printf("Copyright 2006 Registro.br <libepp@registro.br>\n");
00932   printf("shepp is distributed with libepp-nicbr: "
00933          "http://registro.br/epp/index-EN.html\n");
00934 #if USE_BR_DOMAINS
00935   printf("Built with BrDomain EPP extension support.\n");
00936 #endif //USE_BR_DOMAINS
00937 
00938   return 0;
00939 }
00940 
00941 // -------------------------------------
00942 // Buggy Auto-complete related functions
00943 // -------------------------------------
00944 
00945 // char** shepp_completion __P((const char *, int, int));
00946 
00947 // // Attempts to auto-complete "text" with known commands
00948 // char** cpp_completion(string txt)
00949 // {
00950 //   set<string> matches_set;
00951 //   int len = strlen(txt.c_str());
00952 
00953 //   set<SheppCommand>::const_iterator it;
00954 //   for (it = commands.begin(); it != commands.end(); it++) {
00955 //     if (strncmp((*it).name.c_str(), txt.c_str(), len) == 0) {
00956 //       matches_set.insert((*it).name);
00957 //     }
00958 //   }
00959 
00960 //   char **matches = (char **) NULL;
00961 
00962 //   if (matches_set.size() > 0) {
00963 //     const int _DIMENSION = 128;
00964 //     matches = new char*[_DIMENSION];
00965 //     int j;
00966 //       for (j = 0; j < _DIMENSION; j++) {
00967 //         matches[j] = new char[_DIMENSION];
00968 //      bzero(matches[j], _DIMENSION);
00969 //       }
00970     
00971 //     set<string>::const_iterator it_str;
00972 //     for (it_str = matches_set.begin(), j = 0;
00973 //       it_str != matches_set.end();
00974 //       it_str++, j++) {
00975 //       matches[j] = new char[_DIMENSION];
00976 //       strncpy(matches[j], (*it_str).c_str(), strlen((*it_str).c_str()) + 1);
00977 // #if 0
00978 //       printf("found: [%s]\n", matches[j]);
00979 // #endif
00980 //     }
00981 //   }
00982 
00983 //   return matches;
00984 // }
00985 
00986 // char** shepp_completion (const char *text, int start, int end)
00987 // {
00988 //   char **matches = (char **)NULL;;
00989 
00990 //   // if 'text' starts at position '0' then it should be checked
00991 //   // against the command list
00992 //   if (start == 0) {
00993 //     //  matches = rl_completion_matches(text, command_generator);
00994 //     matches = cpp_completion(text);
00995 //   }
00996 
00997 //   return (matches);
00998 // }
00999 
01000 #endif //__SHEPP_COMMAND_FUNCTIONS_H__

Generated on Fri Jul 21 09:01:12 2006 for libepp_nicbr by  doxygen 1.4.6