void CSearchDlg::OnFieldChanged( wxEvent& WXUNUSED(evt) ) { bool enable = false; // These are the IDs of the search-fields int textfields[] = { IDC_SEARCHNAME, IDC_EDITSEARCHEXTENSION }; for ( uint16 i = 0; i < itemsof(textfields); i++ ) { enable |= !CastChild( textfields[i], wxTextCtrl )->GetValue().IsEmpty(); } // Check if either of the dropdowns have been changed enable |= (CastChild(IDC_SEARCHMINSIZE, wxChoice)->GetSelection() != 2); enable |= (CastChild(IDC_SEARCHMAXSIZE, wxChoice)->GetSelection() != 2); enable |= (CastChild(IDC_TypeSearch, wxChoice)->GetSelection() > 0); enable |= (CastChild(ID_AUTOCATASSIGN, wxChoice)->GetSelection() > 0); // These are the IDs of the search-fields int spinfields[] = { IDC_SPINSEARCHMIN, IDC_SPINSEARCHMAX, IDC_SPINSEARCHAVAIBILITY }; for ( uint16 i = 0; i < itemsof(spinfields); i++ ) { enable |= (CastChild( spinfields[i], wxSpinCtrl )->GetValue() > 0); } // Enable the "Reset" button if any fields contain text FindWindow(IDC_SEARCH_RESET)->Enable( enable ); // Enable the Server Search button if the Name field contains text enable = !CastChild( IDC_SEARCHNAME, wxTextCtrl )->GetValue().IsEmpty(); FindWindow(IDC_STARTS)->Enable( enable ); }
bool dbEvent::wait(unsigned msec) { static struct sembuf sops[] = {{0, -1, 0}, {0, 1, 0}}; wait_status ws = wait_semaphore(e, msec, sops, itemsof(sops)); assert(ws != wait_error); return ws == wait_ok; }
// Enables or disables the node connect button depending on the conents of the text fields void CKadDlg::OnFieldsChange(wxCommandEvent& WXUNUSED(evt)) { // These are the IDs of the search-fields int textfields[] = { ID_NODE_IP1, ID_NODE_IP2, ID_NODE_IP3, ID_NODE_IP4, ID_NODE_PORT}; bool enable = true; for ( uint16 i = 0; i < itemsof(textfields); i++ ) { enable &= !CastChild(textfields[i], wxTextCtrl)->GetValue().IsEmpty(); } // Enable the node connect button if all fields contain text FindWindowById(ID_NODECONNECT)->Enable( enable ); }
int sem_init(int& sem, char const* name, unsigned init_value) { key_t key = IPC_PRIVATE; int semid; struct sembuf sops[3]; sops[0].sem_num = 1; sops[0].sem_op = 0; /* check if semaphore was already initialized */ sops[0].sem_flg = IPC_NOWAIT; sops[1].sem_num = 1; sops[1].sem_op = 1; /* mark semaphore as initialized */ sops[1].sem_flg = 0; sops[2].sem_num = 0; sops[2].sem_op = init_value; sops[2].sem_flg = 0; if (name != NULL) { int fd; char* path = (char*)name; if (strchr(name, '/') == NULL) { path = new char[strlen(name)+strlen(keyFileDir)+1]; sprintf(path, "%s%s", keyFileDir, name); } fd = open(path, O_WRONLY|O_CREAT, ACCESS_PERMISSION_MASK); if (fd < 0) { if (path != name) { delete[] path; } PRINT_ERROR("open"); return -1; } close(fd); key = getKeyFromFile(path); if (path != name) { delete[] path; } if (key < 0) { PRINT_ERROR("getKeyFromFile"); return -1; } } semid = semget(key, 2, IPC_CREAT|ACCESS_PERMISSION_MASK); if (semid < 0) { PRINT_ERROR("semget"); return -1; } if (semop(semid, sops, itemsof(sops)) != 0 && errno != EAGAIN) { PRINT_ERROR("semop"); return -1; } sem = semid; return 0; }
{"addClient", addClient}, {"addSegment", addSegment}, {"addHistory", addHistory}, {"editManager", editManager}, {"editClient", editClient}, {"editSegment", editSegment}, {"editHistory", editHistory} }; #ifdef USE_EXTERNAL_HTTP_SERVER CGIapi wwwServer(db, itemsof(dispatchTable), dispatchTable); char* defaultAddress = "localhost:6101"; socket_t::socket_domain domain = socket_t::sock_local_domain; #else #ifdef USE_QUEUE_MANAGER HTTPapi wwwServer(db, itemsof(dispatchTable), dispatchTable, true); #else HTTPapi wwwServer(db, itemsof(dispatchTable), dispatchTable, false); #endif char* defaultAddress = "localhost:80"; socket_t::socket_domain domain = socket_t::sock_global_domain; #endif int main(int argc, char* argv[]) { char* address = (argc > 1) ? argv[1] : defaultAddress; if (!wwwServer.open(address, domain)) { fprintf(stderr, "Failed to open WWW session\n"); return EXIT_FAILURE; } if (!db.open(_T("clidb"))) {
void dbEvent::reset() { static struct sembuf sops[] = {{0, -1, IPC_NOWAIT}}; int rc = semop(e, sops, itemsof(sops)); assert(rc == 0 || errno == EAGAIN); }
void dbEvent::signal() { static struct sembuf sops[] = {{0, 0, IPC_NOWAIT}, {0, 1, 0}}; int rc = semop(e, sops, itemsof(sops)); assert(rc == 0 || errno == EAGAIN); }
void GrSetFontPath(char *p) { int chr,totlen = 0,npath,plen = 0; char path[200],*plist[100]; if(!p || (*p == '\0')) return; for (npath = 0; npath < itemsof(plist); ++npath) plist[npath] = NULL; npath = 0; setup_ALLOC(); path[0] = '\0'; while(((chr = *p++) != '\0') || (plen > 0)) { int pathchr = TRUE; switch(chr) { case ':': #ifdef __MSDOS__ if((plen == 1) && isalpha(path[0])) break; #endif case ';': pathchr = FALSE; break; case '\0': p--; pathchr = FALSE; break; #ifdef __MSDOS__ case '\\': chr = '/'; break; #endif default: #ifdef __MSDOS__ chr = tolower(chr); #endif if(isspace(chr)) pathchr = FALSE; break; } if(pathchr) { path[plen++] = chr; continue; } if(plen > 0) { if(path[plen - 1] != '/') path[plen++] = '/'; path[plen++] = '\0'; plist[npath] = ALLOC((size_t)plen); if(plist[npath] == NULL) goto error; strcpy(plist[npath],path); totlen += plen; plen = 0; if(++npath == itemsof(plist)) break; } } if(_GrFontFileInfo.path != NULL) free(_GrFontFileInfo.path); _GrFontFileInfo.path = NULL; _GrFontFileInfo.npath = npath; if(npath > 0) { _GrFontFileInfo.path = malloc((sizeof(char *) * npath) + totlen); if(_GrFontFileInfo.path == NULL) goto error; p = (char *)(&_GrFontFileInfo.path[npath]); for(plen = 0; plen < npath; plen++) { _GrFontFileInfo.path[plen] = p; strcpy(p,plist[plen]); p += strlen(p) + 1; } } goto done; error: if(_GrFontFileInfo.path != NULL) free(_GrFontFileInfo.path); _GrFontFileInfo.path = NULL; _GrFontFileInfo.npath = 0; done: for (npath = 0; npath < itemsof(plist); ++npath) FREE(plist[npath]); reset_ALLOC(); }
CamuleDlg::CamuleDlg( wxWindow* pParent, const wxString &title, wxPoint where, wxSize dlg_size) : wxFrame( pParent, -1, title, where, dlg_size, wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT| wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX, wxT("aMule")), m_activewnd(NULL), m_transferwnd(NULL), m_serverwnd(NULL), m_sharedfileswnd(NULL), m_searchwnd(NULL), m_chatwnd(NULL), m_statisticswnd(NULL), m_kademliawnd(NULL), m_prefsDialog(NULL), m_srv_split_pos(0), m_imagelist(16,16), m_tblist(32,32), m_prefsVisible(false), m_wndToolbar(NULL), m_wndTaskbarNotifier(NULL), m_nActiveDialog(DT_NETWORKS_WND), m_is_safe_state(false), m_BlinkMessages(false), m_CurrentBlinkBitmap(24), m_last_iconizing(0), m_skinFileName(), m_clientSkinNames(CLIENT_SKIN_SIZE) { // Initialize skin names m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer"); m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting"); m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue"); m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull"); m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown"); m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol"); m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent"); m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy"); m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey"); m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow"); m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload"); m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend"); m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule"); m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey"); m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid"); m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule"); m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant"); m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza"); m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule"); m_clientSkinNames[Client_Unknown] = wxT("Unknown"); m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile"); m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile"); m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile"); m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile"); m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile"); m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly"); m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted"); // wxWidgets send idle events to ALL WINDOWS by default... *SIGH* wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED); wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED); wxInitAllImageHandlers(); Apply_Clients_Skin(); #ifdef __WINDOWS__ wxSystemOptions::SetOption(wxT("msw.remap"), 0); #endif #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__)) // this crashes on Mac with wx 2.9 SetIcon(wxICON(aMule)); #endif srand(time(NULL)); // Create new sizer and stuff a wxPanel in there. wxFlexGridSizer *s_main = new wxFlexGridSizer(1); s_main->AddGrowableCol(0); s_main->AddGrowableRow(0); wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize); s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0); muleDlg(p_cnt, false, true); SetSizer(s_main, true); m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos); AddLogLineN(wxEmptyString); AddLogLineN(wxT(" - ") + CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion()); AddLogLineN(wxT(" ") + CFormat(_("Running on %s")) % wxGetOsDescription()); AddLogLineN(wxT(" - ") + wxString(_("Visit http://www.amule.org to check if a new version is available."))); AddLogLineN(wxEmptyString); #ifdef ENABLE_IP2COUNTRY m_GeoIPavailable = true; m_IP2Country = new CIP2Country(thePrefs::GetConfigDir()); #else m_GeoIPavailable = false; #endif m_searchwnd = new CSearchDlg(p_cnt); m_transferwnd = new CTransferWnd(p_cnt); m_sharedfileswnd = new CSharedFilesWnd(p_cnt); m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics); m_chatwnd = new CChatWnd(p_cnt); m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg); m_serverwnd->Show(false); m_searchwnd->Show(false); m_transferwnd->Show(false); m_sharedfileswnd->Show(false); m_statisticswnd->Show(false); m_chatwnd->Show(false); // Create the GUI timer gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT); if (!gui_timer) { AddLogLineN(_("FATAL ERROR: Failed to create Timer")); exit(1); } // Set transfers as active window Create_Toolbar(thePrefs::VerticalToolbar()); SetActiveDialog(DT_TRANSFER_WND, m_transferwnd); m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true ); bool override_where = (where != wxDefaultPosition); bool override_size = ( (dlg_size.x != DEFAULT_SIZE_X) || (dlg_size.y != DEFAULT_SIZE_Y) ); if (!LoadGUIPrefs(override_where, override_size)) { // Prefs not loaded for some reason, exit AddLogLineC(wxT("Error! Unable to load Preferences") ); return; } // Prepare the dialog, sets the splitter-position (AFTER window size is set) m_transferwnd->Prepare(); m_is_safe_state = true; // Init statistics stuff, better do it asap m_statisticswnd->Init(); m_kademliawnd->Init(); m_searchwnd->UpdateCatChoice(); if (thePrefs::UseTrayIcon()) { CreateSystray(); } Show(true); // Must we start minimized? if (thePrefs::GetStartMinimized()) { DoIconize(true); } // Set shortcut keys wxAcceleratorEntry entries[] = { wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT) }; SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries)); ShowED2KLinksHandler( thePrefs::GetFED2KLH() ); wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook); wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook); wxASSERT(logs_notebook->GetPageCount() == 4); wxASSERT(networks_notebook->GetPageCount() == 2); for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) { m_logpages[i].page = logs_notebook->GetPage(i); m_logpages[i].name = logs_notebook->GetPageText(i); } for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) { m_networkpages[i].page = networks_notebook->GetPage(i); m_networkpages[i].name = networks_notebook->GetPageText(i); } DoNetworkRearrange(); }
}; static GrVideoMode modes[] = { /* pres. bpp wdt hgt BIOS scan priv. &ext */ { TRUE, 1, 80, 25, 0x07, 160, 0, &_GrViDrvEGAVGAtextModeExt }, { TRUE, 1, 80, 43, 0x07, 160, 0, &_GrViDrvEGAVGAcustomTextModeExt }, { TRUE, 4, 40, 25, 0x01, 80, 0, &_GrViDrvEGAVGAtextModeExt }, { TRUE, 4, 80, 25, 0x03, 160, 0, &_GrViDrvEGAVGAtextModeExt }, { TRUE, 4, 80, 43, 0x03, 160, 0, &_GrViDrvEGAVGAcustomTextModeExt }, { TRUE, 1, 320, 200, 0x0d, 40, 0, &gr1ext }, { TRUE, 1, 640, 200, 0x0e, 80, 0, &gr1ext }, { TRUE, 1, 640, 350, 0x10, 80, 0, &gr1ext }, { TRUE, 4, 320, 200, 0x0d, 40, 0, &gr4ext }, { TRUE, 4, 640, 200, 0x0e, 80, 0, &gr4ext }, { TRUE, 4, 640, 350, 0x10, 80, 0, &gr4ext } }; GrVideoDriver _GrVideoDriverSTDEGA = { "stdega", /* name */ GR_EGA, /* adapter type */ NULL, /* inherit modes from this driver */ modes, /* mode table */ itemsof(modes), /* # of modes */ _GrViDrvDetectEGA, /* detection routine */ _GrViDrvInitEGAVGA, /* initialization routine */ _GrViDrvResetEGAVGA, /* reset routine */ _gr_selectmode, /* standard mode select routine */ 0 /* no additional capabilities */ };
int sem_init(int& sem, char const* name, unsigned init_value) { key_t key = IPC_PRIVATE; int semid; struct sembuf sops[3]; sops[0].sem_num = 1; sops[0].sem_op = 0; /* check if semaphore was already initialized */ sops[0].sem_flg = IPC_NOWAIT; sops[1].sem_num = 1; sops[1].sem_op = 1; /* mark semaphore as initialized */ sops[1].sem_flg = 0; sops[2].sem_num = 0; sops[2].sem_op = init_value; sops[2].sem_flg = 0; if (name != NULL) { int fd; char* path = (char*)name; if (strchr(name, '/') == NULL) { path = new char[strlen(name)+strlen(keyFileDir)+1]; sprintf(path, "%s%s", keyFileDir, name); } fd = open(path, O_WRONLY|O_CREAT, 0777); if (fd < 0) { OsSysLog::add(FAC_DB, PRI_CRIT, "Error attempting to open '%s' for writing.", path); if (path != name) { delete[] path; } PRINT_ERROR("open"); return -1; } close(fd); key = getKeyFromFile(path); OsSysLog::add(FAC_DB, PRI_DEBUG, "sem_init path = '%s', key = 0x%x", path, key); if (path != name) { delete[] path; } if (key < 0) { PRINT_ERROR("getKeyFromFile"); return -1; } } OsSysLog::add(FAC_DB, PRI_DEBUG, "sem_init semget(0x%x, 2, IPC_CREAT|0777)", key); semid = semget(key, 2, IPC_CREAT|0777); if (semid < 0) { PRINT_ERROR("semget"); OsSysLog::add(FAC_DB, PRI_CRIT, "sem_init semget failed - error: %s, key = 0x%x", strerror(errno), key); return -1; } if (semop(semid, sops, itemsof(sops)) != 0 && errno != EAGAIN) { PRINT_ERROR("semop"); return -1; } sem = semid; return 0; }
CUpDownClient* CClientList::FindMatchingClient( CUpDownClient* client ) { typedef std::pair<IDMap::const_iterator, IDMap::const_iterator> IDMapIteratorPair; wxCHECK(client, NULL); const uint32 userIP = client->GetIP(); const uint32 userID = client->GetUserIDHybrid(); const uint16 userPort = client->GetUserPort(); const uint16 userKadPort = client->GetKadPort(); // LowID clients need a different set of checks if (client->HasLowID()) { // User is firewalled ... Must do two checks. if (userIP && (userPort || userKadPort)) { IDMapIteratorPair range = m_ipList.equal_range(userIP); for ( ; range.first != range.second; ++range.first ) { CUpDownClient* other = range.first->second.GetClient(); wxASSERT(userIP == other->GetIP()); if (userPort && (userPort == other->GetUserPort())) { return other; } else if (userKadPort && (userKadPort == other->GetKadPort())) { return other; } } } const uint32 serverIP = client->GetServerIP(); const uint32 serverPort = client->GetServerPort(); if (userID && serverIP && serverPort) { IDMapIteratorPair range = m_clientList.equal_range(userID); for (; range.first != range.second; ++range.first) { CUpDownClient* other = range.first->second.GetClient(); wxASSERT(userID == other->GetUserIDHybrid()); // For lowid, we also have to check the server if (serverIP == other->GetServerIP()) { if (serverPort == other->GetServerPort()) { return other; } } } } } else if (userPort || userKadPort) { // Check by IP first, then by ID struct { const IDMap& map; uint32 value; } toCheck[] = { { m_ipList, userIP }, { m_clientList, userID } }; for (size_t i = 0; i < itemsof(toCheck); ++i) { if (toCheck[i].value == 0) { // We may not have both (or any) of these values. continue; } IDMapIteratorPair range = toCheck[i].map.equal_range(toCheck[i].value); if (userPort) { IDMap::const_iterator it = range.first; for (; it != range.second; ++it) { if (userPort == it->second.GetUserPort()) { return it->second.GetClient(); } } } if (userKadPort) { IDMap::const_iterator it = range.first; for (; it != range.second; ++it) { if (userKadPort == it->second.GetClient()->GetKadPort()) { return it->second.GetClient(); } } } } } // If anything else fails, then we look at hashes if ( client->HasValidHash() ) { // Find all items with the specified hash std::pair<HashMap::iterator, HashMap::iterator> range = m_hashList.equal_range( client->GetUserHash() ); // Just return the first item if any if ( range.first != range.second ) { return range.first->second.GetClient(); } } // Nothing found, must be a new client return NULL; }
static GrxVideoMode *select_mode(GrxVideoDriver *drv, int w, int h, int bpp, int txt, unsigned int *ep) { int i; if(!txt && !(modes[1].user_data & SDL_FULLSCREEN)) { for(i = 1; i < NUM_RESOS; i++) if(modes[i].width == w && modes[i].height == h) goto done; if(w <= MaxWidth && h <= MaxHeight) { modes[i].present = TRUE; modes[i].width = w; modes[i].height = h; } else modes[i].present = FALSE; } done: return(_gr_select_mode(drv, w, h, bpp, txt, ep)); } GrxVideoDriver _GrVideoDriverSDL = { .name = "sdl", /* name */ .inherit = NULL, /* inherit modes from this driver */ .modes = modes, /* mode table */ .n_modes = itemsof(modes), /* # of modes */ .detect = detect, /* detection routine */ .init = init, /* initialization routine */ .reset = reset, /* reset routine */ .select_mode = select_mode, /* special mode select routine */ .flags = 0, /* no additional capabilities */ };