#pragma implementation #include "tcptool.h" #include "tcptool.m" #include #include #include MODULE_DEFINE_VERSION(tcptool); static const char *keymenu=NULL; const char K_TCPTOOL[]="tcptool"; static const char K_SESSIONINDEX[]="sessionindex"; static HELP_FILE help_tcptool ("tcptool","tcptool"); static int tcptool_editserv ( SSTRING &host, SSTRING &port, SSTRING &comment) { int ret = -1; DIALOG dia; dia.settype (DIATYPE_POPUP); dia.newf_str (MSG_U(F_HOST,"Host"),host); dia.last_noempty(); dia.newf_str (MSG_U(F_PORT,"Service"),port); dia.last_noempty(); dia.newf_str (MSG_U(F_COMMENT,"Comment"),comment); int nof = 0; while (1){ MENU_STATUS code = dia.edit (MSG_U(T_SERVICE,"Service setup") ,"",help_tcptool,nof); if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else{ ret = 0; break; } } return ret; } class SESSION_RECORD: public ARRAY_OBJ{ public: SSTRING host; SSTRING port; SSTRING comment; /*~PROTOBEG~ SESSION_RECORD */ /*~PROTOEND~ SESSION_RECORD */ }; class SESSION_RECORDS: public ARRAY{ /*~PROTOBEG~ SESSION_RECORDS */ public: SESSION_RECORD *getitem (int no)const; /*~PROTOEND~ SESSION_RECORDS */ }; PUBLIC SESSION_RECORD *SESSION_RECORDS::getitem(int no) const { return (SESSION_RECORD *)ARRAY::getitem(no); } static int cmp_by_hostport(const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { SESSION_RECORD *r1 = (SESSION_RECORD*)o1; SESSION_RECORD *r2 = (SESSION_RECORD*)o2; int ret = r1->host.cmp(r2->host); if (ret == 0) ret = r1->port.cmp(r2->port); return ret; } static void tcptool_menu() { static const char *menuopt[]={ MSG_U(M_SET,"Define"), MSG_U(M_MACROS,"macros"), MSG_U(M_CONNECT,"Connect"),MSG_U(M_SERVICE,"to a TCP service"), NULL }; (MSG_R(M_tcptool),"",help_nil,menuopt); SESSION_RECORDS recs; if (no == 0){ xconf_notice ("Sorry, not done yet!"); }else if (no == 1){ (MSG_U(T_SESSIONS,"Sessions") ,MSG_U(I_SESSIONS,"Pick a session configuration\n" "or add a new one\n" "Use the third mouse button to change a configuration") ,help_tcptool); newf_head (MSG_U(H_SESSION,"Host\tProtocol\tComment")); addwhat (MSG_U(I_ADDSESSION,"A new session configuration")); glocal.recs.remove_all(); SSTRINGS idxs; int nb = linuxconf_getall (K_TCPTOOL,K_SESSIONINDEX,idxs,false); for (int i=0; iget(); SESSION_RECORD *rec = new SESSION_RECORD; glocal.recs.add(rec); SSTRING key; key.setfromf ("host_%s",idx); rec->host.setfrom (linuxconf_getval(K_TCPTOOL,key.get(),"")); key.setfromf ("port_%s",idx); rec->port.setfrom (linuxconf_getval(K_TCPTOOL,key.get(),"")); key.setfromf ("comment_%s",idx); rec->comment.setfrom (linuxconf_getval(K_TCPTOOL,key.get(),"")); } glocal.recs.sort(cmp_by_hostport); for (int i=0; ihost.get(),"%s\t%s" ,rec->port.get(),rec->comment.get()); } SESSION_RECORD *rec = glocal.recs.getitem(no); if (uistate.rightb){ if (tcptool_editserv (rec->host,rec->port,rec->comment)!=-1){ SSTRING key; key.setfromf("host_%d",no); linuxconf_replace (K_TCPTOOL,key.get(),rec->host); key.setfromf("port_%d",no); linuxconf_replace (K_TCPTOOL,key.get(),rec->port); key.setfromf("comment_%d",no); linuxconf_replace (K_TCPTOOL,key.get(),rec->comment); linuxconf_save(); } }else{ session (rec->host.get(),rec->port.get()); } SSTRING host,port,comment; if (tcptool_editserv (host,port,comment)!=-1){ int no = glocal.recs.getnb(); SSTRING key; key.setfrom (no); linuxconf_add (K_TCPTOOL,K_SESSIONINDEX,key); key.setfromf("host_%d",no); linuxconf_replace (K_TCPTOOL,key.get(),host); key.setfromf("port_%d",no); linuxconf_replace (K_TCPTOOL,key.get(),port); key.setfromf("comment_%d",no); linuxconf_replace (K_TCPTOOL,key.get(),comment); linuxconf_save(); session (host.get(),port.get()); } } } ("tcptool",PACKAGE_REV); tb.add (new SSTRING(MSG_U(T_USAGE ,"linuxconf --modulemain tcptool usage\n" "\n" " tcptool --option ...\n"))); if (context == MENU_NETWORK_MISC){ keymenu = MSG_U(M_tcptool,"Chat with TCP services"); dia.new_menuitem ("tcptool","",keymenu); } if (context == MENU_NETWORK_MISC){ if (key == keymenu){ tcptool_menu(); } } return 0; int ret = LNCF_NOT_APPLICABLE; #if 0 // ### Check the variable key to provide your own html hook ret = 0; #endif return ret; int ret = -1; if (argc == 1){ tcptool_menu(); }else{ printusage(); } return ret;