bool GDNativeLibrary::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name.begins_with("platform/")) { set_library_path(name.get_slice("/", 1), p_value); return true; } return false; }
struct server_server *TTrafficServerForm::allocate_servers( struct server_reply *sr, struct client_protocol *sp ) { char *tmpc; char err_msg[1024]; char **argv; struct server_server *tmp; tmp=new struct server_server(); if (!tmp) { Application->MessageBox( "Unable to allocate server", Caption, TMessageButtons() << smbOK, smsWarning ); return( NULL ); } argv=new char *[2]; argv[0]=new char( 0 ); argv[1]=new char[1024]; strcpy( argv[1], ServerComboBox->Items->Strings[ServerComboBox->ItemIndex].c_str () ); tmpc=set_library_path( 2, argv, 1, -1, "server", err_msg, 1024 ); delete argv[0]; delete []argv[1]; delete []argv; if (!tmpc) { Application->MessageBox( err_msg, Caption, TMessageButtons() << smbOK, smsWarning ); return( NULL ); } tmp->serv=new server( tmpc ); delete []tmpc; if (!tmp->serv) { Application->MessageBox( "Unable to allocate server library", Caption, TMessageButtons() << smbOK, smsWarning ); delete tmp; return( NULL ); } if (!tmp->serv->isOk()) { Application->MessageBox( "Unable to initialize server library", Caption, TMessageButtons() << smbOK, smsWarning ); delete tmp->serv; delete tmp; return( NULL ); } tmp->handle=tmp->serv->InitServer( &sp, ProtocolsListBox->Items->Count, &sr, 1 ); if (!tmp->handle) { delete tmp->serv; delete tmp; Application->MessageBox( "Unable to initialize server", Caption, TMessageButtons() << smbOK, smsWarning ); return( NULL ); } return( tmp ); }
//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- struct server_reply *TTrafficServerForm::allocate_reply() { struct server_reply *tmp; char *tmpc; char err_msg[1024]; char **argv; tmp=new struct server_reply(); if (!tmp) { Application->MessageBox( "Out of memory", Caption, TMessageButtons() << smbOK, smsWarning ); return( NULL ); } argv=new char *[2]; argv[0]=new char( 0 ); argv[1]=new char[1024]; strcpy( argv[1], ReplyComboBox->Items->Strings[ReplyComboBox->ItemIndex].c_str() ); tmpc=set_library_path( 2, argv, 1, -1, "reply", err_msg, 1024 ); delete argv[0]; delete []argv[1]; delete []argv; if (!tmpc) { Application->MessageBox( err_msg, Caption, TMessageButtons() << smbOK, smsWarning ); return( NULL ); } tmp->rep=new reply( tmpc ); delete []tmpc; if (!tmp->rep) { Application->MessageBox( "Out of memory", Caption, TMessageButtons() << smbOK, smsWarning ); return( NULL ); } if (!tmp->rep->isOk()) { Application->MessageBox( "Unable to load reply library", Caption, TMessageButtons() << smbOK, smsWarning ); delete tmp; return( NULL ); } return( tmp ); }
struct client_protocol *TTrafficServerForm::allocate_protocol() { std::map <char *,struct client_protocol *,cpc_map> known_prot; struct client_protocol *tmp; char *tmpc; char err_msg[1024]; char **argv; char *port; int nport; tmp=new struct client_protocol[ProtocolsListBox->Items->Count]; if (!tmp) { Application->MessageBox( "Unable to allocate server protocol", Caption, TMessageButtons() << smbOK, smsWarning ); return( NULL ); } tmpc=NULL; for (int cnt=0; cnt<ProtocolsListBox->Items->Count; cnt++) { if (tmpc) delete []tmpc; tmpc=NULL; argv=new char *[2]; argv[0]=new char(0); argv[1]=new char[1024]; strcpy( argv[1], ProtocolsListBox->Items->Strings[cnt].c_str() ); *(strrchr( argv[1], ':' ))=0; port=strchr( ProtocolsListBox->Items->Strings[cnt].c_str(), ':' )+1; nport=atol( port ); tmpc=set_library_path( 2, argv, 1, -1, "protocol", err_msg, 1024 ); delete argv[0]; delete []argv[1]; delete []argv; if (!tmpc) { Application->MessageBox( err_msg, Caption, TMessageButtons() << smbOK, smsWarning ); return( NULL ); } std::map <char *,struct client_protocol *,cpc_map>::iterator cur = known_prot. find( tmpc ); tmp[cnt].proto=NULL; tmp[cnt].proto_handle=NULL; tmp[cnt].connection=NULL; if (cur==known_prot.end()) { // first time this protocol come's up... tmp[cnt].proto=new protocol( tmpc ); if (!tmp[cnt].proto) { Application->MessageBox( "Unable to allocate memory for protocol", Caption, TMessageButtons() << smbOK, smsWarning ); } else { if (!tmp[cnt].proto->isOk()) { Application->MessageBox( "Unable to initialize protocol", Caption, TMessageButtons() << smbOK, smsWarning ); delete tmp[cnt].proto; tmp[cnt].proto=NULL; } else { tmp[cnt].proto_handle=tmp[cnt].proto->InitProtocol( 1 ); if (!tmp[cnt].proto_handle) { Application->MessageBox( "Unable to start server for protocol", Caption, TMessageButtons() << smbOK, smsWarning ); } else { tmp[cnt].connection=tmp[cnt].proto->ListenForConnections( tmp[cnt].proto_handle, nport, 10, NULL ); if (!tmp[cnt].connection) { Application->MessageBox( "Unable to listen for protocol", Caption, TMessageButtons() << smbOK, smsWarning ); } else { known_prot[tmpc]=&(tmp[cnt]); } } } } } else { // we have seen this protocol before - so just a new connection tmp[cnt].proto=(known_prot[tmpc])->proto; tmp[cnt].proto_handle=(known_prot[tmpc])->proto_handle; tmp[cnt].connection=tmp[cnt].proto->ListenForConnections( tmp[cnt].proto_handle, nport, 10, NULL ); if (!tmp[cnt].connection) { Application->MessageBox( "Unable to listen for protocol", Caption, TMessageButtons() << smbOK, smsWarning ); } } } if (tmpc) delete []tmpc; tmpc=NULL; return( tmp ); }
config_info::config_info( int argc, char **argv ) { int dn=-1, cn=-1, pn=-1, lp=-1; is_version=0; num_clients=1; protocol_lib_path=NULL; client_lib_path=NULL; payload_lib_path=NULL; client_min=client_max=client_inc=client_time=0; payload_min=payload_max=payload_inc=payload_time=0; protocol_dest_port=0; protocol_dest_address=NULL; installed=0; error_string=NULL; if (argc<3) { if (argv[1] && strcmp( argv[1], "-v" )) { set_error( "Not enough parameters specified" ); return; } } for (int cnt=1;cnt<argc;cnt++) { int result; if (argv[cnt][0]!='-' && argv[cnt][0]!='/') { set_error( "Parameter specified that does not start with - or /" ); return; } switch (argv[cnt][1]) { case 'd': result=parse_protocol_data( cnt, argc, argv, &dn ); if (result) return; cnt+=1; continue; case 'c': result=parse_client_data( cnt, argc, argv, &cn ); if (result) return; cnt+=1; continue; case 'p': result=parse_payload_data( cnt, argc, argv, &pn ); if (result) return; cnt+=1; continue; case 'n': // num clients if (!argv[cnt+1]) { set_error( "Parameter specified without value" ); return; } num_clients=atol( argv[cnt+1] ); cnt+=1; continue; case 'L': // lib path if (!argv[cnt+1]) { set_error( "Parameter specified without value" ); return; } lp=cnt+1; cnt+=1; continue; case 'v': // version char buf[1024]; snprintf( buf, 1024, "%s version %s", PRODUCT_NAME, PRODUCT_VERSION ); set_error( buf ); is_version=1; return; default: set_error( "Unknown parameter specified" ); return; } } // Logic checking if (dn==-1 || cn==-1 || pn==-1) { set_error( "You must specify -cn and -dn and -pn" ); return; } if (num_clients<1) { set_error( "You must specify at least one client" ); return; } char err_msg[1024]; protocol_lib_path=set_library_path( argc, argv, dn, lp, "protocol", err_msg, 1024 ); if (!protocol_lib_path) { set_error( err_msg ); return; } client_lib_path=set_library_path( argc, argv, cn, lp, "client", err_msg, 1024 ); if (!client_lib_path) { set_error( err_msg ); return; } payload_lib_path=set_library_path( argc, argv, pn, lp, "payload", err_msg, 1024 ); if (!payload_lib_path) { set_error( err_msg ); return; } if (protocol_dest_port<=0) { set_error( "Protocol destination port must be defined" ); return; } if (!protocol_dest_address) { set_error( "Protocol destination address must be defined" ); return; } installed=1; }