static int suitebTest( const BOOLEAN isServer, const int testNo, const char *hostName, const int port, const int flags ) { BOOLEAN isServerTest = FALSE; int value = testNo, status; if( value < 0 ) { isServerTest = TRUE; value = -value; } /* Set up default argument values if required */ if( hostName == NULL ) hostName = "localhost"; /* Run the test client or server */ createMutex(); if( isServer ) status = suitebServer( value, hostName, port, flags, isServerTest ); else status = suitebClient( value, hostName, port, flags, isServerTest ); destroyMutex(); return( status ); }
OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _audio_sample_rate(audio_sample_rate), _audio_buffer_size(audio_buffer_size), _screen_changeid(0), _egl_surface_width(0), _egl_surface_height(0), _htc_fail(true), _force_redraw(false), _game_texture(0), _overlay_texture(0), _mouse_texture(0), _mouse_texture_palette(0), _mouse_texture_rgb(0), _mouse_hotspot(), _mouse_keycolor(0), _use_mouse_palette(false), _graphicsMode(0), _fullscreen(true), _ar_correction(true), _show_mouse(false), _show_overlay(false), _enable_zoning(false), _mixer(0), _shake_offset(0), _queuedEventTime(0), _event_queue_lock(createMutex()), _touch_pt_down(), _touch_pt_scroll(), _touch_pt_dt(), _eventScaleX(100), _eventScaleY(100), // TODO put these values in some option dlg? _touchpad_mode(true), _touchpad_scale(66), _dpad_scale(4), _fingersDown(0), _trackball_scale(2), _joystick_scale(10) { _fsFactory = new POSIXFilesystemFactory(); Common::String mf = getSystemProperty("ro.product.manufacturer"); LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s", mf.c_str(), getSystemProperty("ro.product.model").c_str(), getSystemProperty("ro.product.brand").c_str(), getSystemProperty("ro.build.fingerprint").c_str(), getSystemProperty("ro.build.display.id").c_str(), getSystemProperty("ro.build.version.sdk").c_str(), getSystemProperty("ro.product.cpu.abi").c_str()); mf.toLowercase(); /*_htc_fail = mf.contains("htc"); if (_htc_fail) LOGI("Enabling HTC workaround");*/ }
int testSessionRTCSServer( void ) { int status; createMutex(); acquireMutex(); status = connectRTCS( CRYPT_SESSION_RTCS_SERVER, FALSE, FALSE ); destroyMutex(); return( status ); }
void Core::createThread(Threaded *target) { if(!threadedEventMutex) { threadedEventMutex = createMutex(); } target->eventMutex = threadedEventMutex; target->core = this; lockMutex(threadedEventMutex); threads.push_back(target); unlockMutex(threadedEventMutex); }
void Pool::init(int aThreadCount) { if (aThreadCount > 0) { mMaxTask = 0; mWorkMutex = createMutex(); mRunning = 1; mTasksRunning = 0; mThreadCount = aThreadCount; mThread = new ThreadHandle[aThreadCount]; int i; for (i = 0; i < mThreadCount; i++) { mThread[i] = createThread(poolWorker, this); } } }
int testSessionOCSPClientServer( void ) { HANDLE hThread; unsigned threadID; int status; /* Start the server and wait for it to initialise */ createMutex(); hThread = ( HANDLE ) _beginthreadex( NULL, 0, ocspServerThread, NULL, 0, &threadID ); Sleep( 1000 ); /* Connect to the local server */ status = connectOCSP( CRYPT_SESSION_OCSP, FALSE, FALSE, TRUE ); waitForThread( hThread ); destroyMutex(); return( status ); }
int testSessionHTTPCertstoreClientServer( void ) { HANDLE hThread; unsigned threadID; int status; /* Start the server and wait for it to initialise */ createMutex(); hThread = ( HANDLE ) _beginthreadex( NULL, 0, certstoreServerThread, NULL, 0, &threadID ); Sleep( 1000 ); /* Connect to the local server */ status = connectCertstoreClient(); waitForThread( hThread ); destroyMutex(); return( status ); }
void initL7DeviceDiscovery(int deviceId) { IPOQUE_PROTOCOL_BITMASK all; u32 detection_tick_resolution = 1000; myGlobals.device[deviceId].l7.l7handler = ipoque_init_detection_module(detection_tick_resolution, malloc_wrapper, debug_printf); if(myGlobals.device[deviceId].l7.l7handler == NULL) { traceEvent(CONST_TRACE_ERROR, "Unable to initialize L7 engine: disabling L7 discovery for deviceId %u", deviceId); return; } // enable all protocols IPOQUE_BITMASK_SET_ALL(all); ipoque_set_protocol_detection_bitmask2(myGlobals.device[deviceId].l7.l7handler, &all); /* ************************** */ createMutex(&myGlobals.device[deviceId].l7.l7Mutex); }
int printf(const char* format,...){ va_list args; va_start( args, format ); int safe = createMutex("safePrint"); lockMutex(safe); int n; char strnum[10]; char* str; while(*format!='\0'){ if(*format!='%'){ putc(*format); }else{ switch(*(++format)){ case '%': putc('%'); break; case 'd': case 'i': n=va_arg(args,int); int length=intToString(strnum,n); printCharArray(strnum,length); break; case 'c': n=(char)va_arg(args,int); putc((char)n); break; case 's': str=(char*)va_arg(args,char*); printCharArray(str, strlen(str)); break; } } format++; } unlockMutex(safe); return 0; }
int createPipe(int size, int flags) { Spipe *p = newSpipeData(); if(!p) return -1; int pid = getpid(); enterProcessCriticalCode(pid); int fd = open_fd(); if(fd < 0) return fd; idStream *is = getStreamData(getpid(), fd); createMutex(&p->locker); p->memory = malloc(size+4); p->seek = 0; p->offset = 0; p->size = size; p->ready_read_wid = createAdvWaitCond("waiter", 0); p->ready_write_wid = createAdvWaitCond("waiter", 0); p->fully_flushed_wid = createAdvWaitCond("waiter", 0); p->fully_empty_wid = createAdvWaitCond("waiter", 0); p->flags = flags; is->fd = p->id; is->type = PIPE_STREAM; is->mode = O_RDWR; is->pid = pid; is->read = __pread; is->write = __pwrite; is->flush = __pflush; is->lseek = __plseek; is->close = __pclose; wakeOneWaitCond(p->ready_write_wid); leaveProcessCriticalCode(pid); return fd; }
int testSessionSuiteBClientServer( void ) { HANDLE hThread; unsigned threadID; BOOLEAN isServerTest = FALSE; int value = -1, status; /* +ve = client, -ve = server */ /* Start the server */ createMutex(); hThread = ( HANDLE ) _beginthreadex( NULL, 0, suitebServerThread, &value, 0, &threadID ); Sleep( 1000 ); /* Connect to the local server */ if( value < 0 ) { isServerTest = TRUE; value = -value; } status = suitebClient( value, "localhost", 0, FALSE, isServerTest ); waitForThread( hThread ); destroyMutex(); return( status ); }
void OSystem_SDL::initBackend() { assert(!_inited); int joystick_num = ConfMan.getInt("joystick_num"); uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; if (ConfMan.hasKey("disable_sdl_parachute")) sdlFlags |= SDL_INIT_NOPARACHUTE; #ifdef _WIN32_WCE if (ConfMan.hasKey("use_GDI") && ConfMan.getBool("use_GDI")) { SDL_VideoInit("windib", 0); sdlFlags ^= SDL_INIT_VIDEO; } #endif if (joystick_num > -1) sdlFlags |= SDL_INIT_JOYSTICK; if (SDL_Init(sdlFlags) == -1) { error("Could not initialize SDL: %s", SDL_GetError()); } _graphicsMutex = createMutex(); SDL_ShowCursor(SDL_DISABLE); // Enable unicode support if possible SDL_EnableUNICODE(1); memset(&_oldVideoMode, 0, sizeof(_oldVideoMode)); memset(&_videoMode, 0, sizeof(_videoMode)); memset(&_transactionDetails, 0, sizeof(_transactionDetails)); _cksumValid = false; #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && !defined(DISABLE_SCALERS) _videoMode.mode = GFX_DOUBLESIZE; _videoMode.scaleFactor = 2; _videoMode.aspectRatioCorrection = ConfMan.getBool("aspect_ratio"); _scalerProc = Normal2x; #else // for small screen platforms _videoMode.mode = GFX_NORMAL; _videoMode.scaleFactor = 1; _videoMode.aspectRatioCorrection = false; _scalerProc = Normal1x; #endif _scalerType = 0; _modeFlags = 0; #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) _videoMode.fullscreen = ConfMan.getBool("fullscreen"); #else _videoMode.fullscreen = true; #endif #if !defined(MACOSX) && !defined(__SYMBIAN32__) // Setup a custom program icon. // Don't set icon on OS X, as we use a nicer external icon there. // Don't for Symbian: it uses the EScummVM.aif file for the icon. setupIcon(); #endif // enable joystick if (joystick_num > -1 && SDL_NumJoysticks() > 0) { printf("Using joystick: %s\n", SDL_JoystickName(0)); _joystick = SDL_JoystickOpen(joystick_num); } // Create the savefile manager, if none exists yet (we check for this to // allow subclasses to provide their own). if (_savefile == 0) { #ifdef UNIX _savefile = new POSIXSaveFileManager(); #else _savefile = new DefaultSaveFileManager(); #endif } // Create and hook up the mixer, if none exists yet (we check for this to // allow subclasses to provide their own). if (_mixer == 0) { setupMixer(); } // Create and hook up the timer manager, if none exists yet (we check for // this to allow subclasses to provide their own). if (_timer == 0) { // Note: We could implement a custom SDLTimerManager by using // SDL_AddTimer. That might yield better timer resolution, but it would // also change the semantics of a timer: Right now, ScummVM timers // *never* run in parallel, due to the way they are implemented. If we // switched to SDL_AddTimer, each timer might run in a separate thread. // However, not all our code is prepared for that, so we can't just // switch. Still, it's a potential future change to keep in mind. _timer = new DefaultTimerManager(); _timerID = SDL_AddTimer(10, &timer_handler, _timer); } // Invoke parent implementation of this method OSystem::initBackend(); _inited = true; }
/* * Initialize all global run-time parameters to default (reasonable!!!) values */ void initNtopGlobals(int argc, char * argv[], int argc_started, char *argv_started[]) { int i, bufLen; char *startedAs, *defaultPath, *c; /* * Notice the program name */ if((c = strrchr(argv[0], CONST_PATH_SEP)) == NULL) myGlobals.program_name = argv[0]; else myGlobals.program_name = &c[1]; /* * save command line parameters */ myGlobals.ntop_argc = argc; myGlobals.ntop_argv = argv; initUserPrefs(&myGlobals.runningPref); /* Overrides for above */ if (strcmp(myGlobals.program_name, "ntopd") == 0) { myGlobals.runningPref.daemonMode = 1; } myGlobals.checkVersionStatus = FLAG_CHECKVERSION_NOTCHECKED; myGlobals.checkVersionStatusAgain = 1; /* Other flags (to be set via command line options one day) */ myGlobals.enableFragmentHandling = 1; /* Search paths */ myGlobals.dataFileDirs = _dataFileDirs; myGlobals.pluginDirs = _pluginDirs; myGlobals.configFileDirs = _configFileDirs; #ifdef WIN32 defaultPath = _wdir; #else defaultPath = CFG_DBFILE_DIR; #endif myGlobals.dbPath = strdup(defaultPath); /* a NULL pointer will break the logic */ /* NB: we can't init rrdPath here, because initGdbm hasn't been run */ /* list of available NICs */ myGlobals.allDevs = NULL; /* the table of enabled NICs */ myGlobals.numDevices = 0; myGlobals.device = calloc(MAX_NUM_DEVICES, sizeof(NtopInterface)); if(myGlobals.device == NULL) { traceEvent(CONST_TRACE_WARNING, "Not enough memory :-("); exit(-1); } /* Databases */ myGlobals.pwFile = NULL; /* the table of broadcast entries */ myGlobals.broadcastEntry = NULL; /* the table of other hosts entries */ myGlobals.otherHostEntry = NULL; /* administrative */ myGlobals.shortDomainName = NULL; myGlobals.numThreads = 0; /* # of running threads */ #ifdef HAVE_OPENSSL myGlobals.sslInitialized = 0; myGlobals.runningPref.sslPort = 0; /* Disabled by default: enabled via -W */ #endif myGlobals.dnsSniffCount = 0; myGlobals.dnsSniffRequestCount = 0; myGlobals.dnsSniffFailedCount = 0; myGlobals.dnsSniffARPACount = 0; myGlobals.dnsSniffStoredInCache = 0; /* Misc */ myGlobals.separator = " "; myGlobals.thisZone = gmt2local(0); /* seconds offset from gmt to local time */ myGlobals.numPurgedHosts = 0; myGlobals.numTerminatedSessions = 0; /* Time */ myGlobals.actTime = time(NULL); myGlobals.initialSniffTime = 0; myGlobals.lastRefreshTime = 0; myGlobals.lastPktTime.tv_sec = 0; myGlobals.lastPktTime.tv_usec = 0; /* Monitored Protocols */ myGlobals.numActServices = 0; myGlobals.udpSvc = NULL; myGlobals.tcpSvc = NULL; myGlobals.ipTrafficProtosNames = NULL; myGlobals.numIpProtosToMonitor = 0; myGlobals.ipPortMapper.numElements = 0; myGlobals.ipPortMapper.theMapper = NULL; myGlobals.ipPortMapper.numSlots = 0; myGlobals.numHandledSIGPIPEerrors = 0; for(i=0; i<=1; i++) { myGlobals.numHandledRequests[i] = 0; myGlobals.numHandledBadrequests[i] = 0; myGlobals.numSuccessfulRequests[i] = 0; myGlobals.numUnsuccessfulInvalidrequests[i] = 0; myGlobals.numUnsuccessfulInvalidmethod[i] = 0; myGlobals.numUnsuccessfulInvalidversion[i] = 0; myGlobals.numUnsuccessfulTimeout[i] = 0; myGlobals.numUnsuccessfulNotfound[i] = 0; myGlobals.numUnsuccessfulDenied[i] = 0; myGlobals.numUnsuccessfulForbidden[i] = 0; } myGlobals.numSSIRequests = 0; myGlobals.numBadSSIRequests = 0; myGlobals.numHandledSSIRequests = 0; createMutex(&myGlobals.geolocalizationMutex); /* GeoIP mutex */ /* create the logView stuff Mutex first... must be before the 1st traceEvent() call */ createMutex(&myGlobals.logViewMutex); /* synchronize logView buffer */ #ifdef FORPRENPTL #warning Making version for Pre NPTL Thread Library... createMutex(&myGlobals.preNPTLlogMutex); /* synchronize logView buffer */ #endif myGlobals.logViewNext = 0; myGlobals.logView = (char**)calloc(sizeof(char*), CONST_LOG_VIEW_BUFFER_SIZE); /* traceEvent(CONST_TRACE_INFO, "Initializing semaphores, mutexes and threads"); */ /* ============================================================ * Create semaphores and mutexes associated with packet capture * ============================================================ */ #ifdef HAVE_PTHREAD_ATFORK i = pthread_atfork(NULL, NULL, &reinitMutexes); /* traceEvent(CONST_TRACE_INFO, "NOTE: atfork() handler registered for mutexes, rc %d", i); */ #endif createMutex(&myGlobals.gdbmMutex); /* data to synchronize thread access to db files */ createMutex(&myGlobals.portsMutex); /* Avoid race conditions while handling ports */ for(i=0; i<NUM_SESSION_MUTEXES; i++) createMutex(&myGlobals.sessionsMutex[i]); /* data to synchronize sessions access */ createMutex(&myGlobals.purgePortsMutex); /* data to synchronize port purge access */ createMutex(&myGlobals.purgeMutex); /* synchronize purging */ createMutex(&myGlobals.securityItemsMutex); createMutex(&myGlobals.hostsHashLockMutex); createMutex(&myGlobals.serialLockMutex); /* Serial host locking */ for(i=0; i<CONST_HASH_INITIAL_SIZE; i++) { createMutex(&myGlobals.hostsHashMutex[i]); myGlobals.hostsHashMutexNumLocks[i] = 0; } myGlobals.receivedPackets = 0; myGlobals.receivedPacketsProcessed = 0; myGlobals.receivedPacketsQueued = 0; myGlobals.receivedPacketsLostQ = 0; /* NB: Log View is allocated in main.c so it's available for the very 1st traceEvent() */ for (i = 0; i < CONST_NUM_TRANSACTION_ENTRIES; i ++) memset(&myGlobals.transTimeHash[i], 0, sizeof(TransactionTime)); myGlobals.dummyEthAddress[0] = '\0'; /* * Setup the mtu and header size tables. * * We set only the ones we specifically know... anything else will * get mtu=CONST_UNKNOWN_MTU, header=0 * * If mtuSize is wrong, the only problem will be 1) erroneous-/mis-classification * of packets as "too long", 2) the suspicious packet file, if one, may have * extra or missing entries, and 3) an erroneous line in the report. * * If headerSize is wrong, there are no known problems. * * Remember that for most protocols, mtu isn't fixed - it's set by the routers * and can be tuned by the sysadmin, isp, et al for "best results". * * These do need to be periodically resynced with tcpdump.org and with user experience. * * History: * 15Sep2002 - BStrauss * */ { int ii; for (ii=0; ii<MAX_DLT_ARRAY; ii++) { _mtuSize[ii] = CONST_UNKNOWN_MTU; _headerSize[ii] = 0; } } _mtuSize[DLT_NULL] = 8232 /* no link-layer encapsulation */; _headerSize[DLT_NULL] = CONST_NULL_HDRLEN; #ifdef MAKE_WITH_JUMBO_FRAMES _mtuSize[DLT_EN10MB] = 9000 /* Ethernet (1000Mb+ Jumbo Frames) */; #else /* 1500 + 14 bytes header Courtesy of Andreas Pfaller <*****@*****.**> */ _mtuSize[DLT_EN10MB] = 1500+sizeof(struct ether_header) /* Ethernet (10Mb) */; #endif _headerSize[DLT_EN10MB] = sizeof(struct ether_header); _mtuSize[DLT_PRONET] = 17914 /* Proteon ProNET Token Ring */; _headerSize[DLT_PRONET] = sizeof(struct tokenRing_header); _mtuSize[DLT_IEEE802] = 4096+sizeof(struct tokenRing_header) /* IEEE 802 Networks */; _headerSize[DLT_IEEE802] = 1492; /* NOTE: This has to be wrong... */ /* _mtuSize[DLT_PPP] = ? Point-to-point Protocol */ _headerSize[DLT_PPP] = CONST_PPP_HDRLEN; /* Courtesy of Richard Parvass <*****@*****.**> */ _mtuSize[DLT_FDDI] = 4470 /* FDDI */; _headerSize[DLT_FDDI] = sizeof(struct fddi_header); _mtuSize[DLT_ATM_RFC1483] = 9180 /* LLC/SNAP encapsulated atm */; _headerSize[DLT_ATM_RFC1483] = 0; /* _mtuSize[DLT_RAW] = ? raw IP */ _headerSize[DLT_RAW] = 0; /* Others defined in bpf.h at tcpdump.org as of the resync - it would be NICE to have values for these... */ /* _mtuSize[DLT_EN3MB] = ? Experimental Ethernet (3Mb) */ /* _mtuSize[DLT_AX25] = ? Amateur Radio AX.25 */ /* _mtuSize[DLT_CHAOS] = ? Chaos */ /* _mtuSize[DLT_ARCNET] = ? ARCNET */ /* _mtuSize[DLT_SLIP] = ? Serial Line IP */ /* _mtuSize[DLT_SLIP_BSDOS] = ? BSD/OS Serial Line IP */ /* _mtuSize[DLT_PPP_BSDOS] = ? BSD/OS Point-to-point Protocol */ /* _mtuSize[DLT_ATM_CLIP] = ? Linux Classical-IP over ATM */ /* _mtuSize[DLT_PPP_SERIAL] = ? PPP over serial with HDLC encapsulation */ /* _mtuSize[DLT_PPP_ETHER] = ? PPP over Ethernet */ /* _mtuSize[DLT_C_HDLC] = ? Cisco HDLC */ /* _mtuSize[DLT_IEEE802_11] = ? IEEE 802.11 wireless */ /* _mtuSize[DLT_FRELAY] = ? */ /* _mtuSize[DLT_LOOP] = ? */ /* _mtuSize[DLT_LINUX_SLL] = ? */ /* _mtuSize[DLT_LTALK] = ? */ /* _mtuSize[DLT_ECONET] = ? */ /* _mtuSize[DLT_IPFILTER] = ? */ /* _mtuSize[DLT_PFLOG] = ? */ /* _mtuSize[DLT_CISCO_IOS] = ? */ /* _mtuSize[DLT_PRISM_HEADER] = ? */ /* _mtuSize[DLT_AIRONET_HEADER] = ? */ /* _mtuSize[DLT_HHDLC] = ? */ /* _mtuSize[DLT_IP_OVER_FC] = ? */ /* _mtuSize[DLT_SUNATM] = ? Solaris+SunATM */ myGlobals.mtuSize = _mtuSize; myGlobals.headerSize = _headerSize; /* ********************************** */ myGlobals.numPurgedHosts = myGlobals.numTerminatedSessions = 0; /* Dummy value just to be safe: it will be set later on */ myGlobals.l7.numSupportedProtocols = 2 * IPOQUE_MAX_SUPPORTED_PROTOCOLS; myGlobals.broadcastEntry = (HostTraffic*)malloc(sizeof(HostTraffic)); memset(myGlobals.broadcastEntry, 0, sizeof(HostTraffic)); myGlobals.broadcastEntry->l7.traffic = (ProtoTraffic*)calloc(myGlobals.l7.numSupportedProtocols+1, sizeof(ProtoTraffic)); resetHostsVariables(myGlobals.broadcastEntry); /* Set address to FF:FF:FF:FF:FF:FF */ for(i=0; i<LEN_ETHERNET_ADDRESS; i++) myGlobals.broadcastEntry->ethAddress[i] = 0xFF; myGlobals.broadcastEntry->hostIp4Address.s_addr = 0xFFFFFFFF; strncpy(myGlobals.broadcastEntry->hostNumIpAddress, "broadcast", sizeof(myGlobals.broadcastEntry->hostNumIpAddress)); strncpy(myGlobals.broadcastEntry->hostResolvedName, myGlobals.broadcastEntry->hostNumIpAddress, sizeof(myGlobals.broadcastEntry->hostNumIpAddress)); myGlobals.broadcastEntry->hostResolvedNameType = FLAG_HOST_SYM_ADDR_TYPE_FAKE; strcpy(myGlobals.broadcastEntry->ethAddressString, "FF:FF:FF:FF:FF:FF"); setHostFlag(FLAG_SUBNET_LOCALHOST, myGlobals.broadcastEntry); setHostFlag(FLAG_BROADCAST_HOST, myGlobals.broadcastEntry); setHostFlag(FLAG_SUBNET_PSEUDO_LOCALHOST, myGlobals.broadcastEntry); memset(&myGlobals.broadcastEntry->hostSerial, 0, sizeof(HostSerial)); myGlobals.broadcastEntry->serialHostIndex = ++myGlobals.hostSerialCounter; /* Start from 1 (0 = UNKNOWN_SERIAL_INDEX) */ myGlobals.broadcastEntry->magic = CONST_MAGIC_NUMBER; allocateOtherHosts(); /* ********************************** */ bufLen = 0; for (i=0; i<argc_started; i++) { bufLen += (int)(2 + strlen(argv_started[i])); } startedAs = (char*)malloc(bufLen); memset(startedAs, 0, (size_t) bufLen); for (i=0; i<argc_started; i++) { if (argv_started[i] != NULL) { int displ = (int)strlen(startedAs); snprintf(&startedAs[displ], bufLen-displ, "%s ", argv_started[i]); } } myGlobals.startedAs = startedAs; /* Efficiency is the ability to fill-up ATM cells so that they can be efficiently used by applications */ myGlobals.cellLength = 47; /* FIX - this is valid only for ATM */ }