static void RefStringFree(void *elem) { gsifree((char *)((SBRefString *)elem)->str); #ifdef GSI_UNICODE gsifree((unsigned short *)((SBRefString *)elem)->str_W); #endif }
static void piGetGlobalKeysCallbackW ( CHAT chat, CHATBool success, const unsigned short * user, int num, const unsigned short ** keys, const unsigned short ** values, void * param ) { char* user_A = UCS2ToUTF8StringAlloc(user); char** keys_A = UCS2ToUTF8StringArrayAlloc(keys, num); char** values_A = UCS2ToUTF8StringArrayAlloc(values, num); int i; piGetGlobalKeysCallbackA(chat, success, user_A, num, (const char**)keys_A, (const char**)values_A, param); gsifree(user_A); for (i=0; i<num; i++) { if (keys_A != NULL) gsifree(keys_A[i]); if (values_A != NULL) gsifree(values_A[i]); } gsifree(keys_A); gsifree(values_A); }
static const unsigned short * piGetWatchKeyW ( const unsigned short * nick, const unsigned short * key, HashTable watchCache ) { #ifndef GSI_UNICODE GSI_UNUSED(nick); GSI_UNUSED(key); GSI_UNUSED(watchCache); return NULL; // can't use this function unless in GSI_UNICODE mode #else piCacheKey keyTemp; piCacheKey * cacheKey; char* nick_A = UCS2ToUTF8StringAlloc(nick); char* key_A = UCS2ToUTF8StringAlloc(key); keyTemp.nick = (char *)nick_A; keyTemp.key = (char *)key_A; cacheKey = (piCacheKey *)TableLookup(watchCache, &keyTemp); gsifree(nick_A); gsifree(key_A); if (!cacheKey) return NULL; if(cacheKey->value_W) return cacheKey->value_W; return L""; #endif }
/* KeyValFree * Frees the memory INSIDE a Bucket structure */ static void BucketFree(void *elem) { gsifree(((bucket_t *)elem)->name); if (((bucket_t *)elem)->type == bt_string && ((bucket_t *)elem)->vals.sval != NULL) gsifree(((bucket_t *)elem)->vals.sval); }
static void WatchCacheFree ( void * elem ) { piCacheKey * key = (piCacheKey *)elem; gsifree(key->nick); gsifree(key->key); gsifree(key->value); #ifdef GSI_UNICODE gsifree(key->value_W); #endif }
void ArrayFree(DArray array) { int i; GS_ASSERT(array); for (i = 0; i < array->count; i++) { FreeElement(array, i); } // mj to do: move these asserts into gsi_free. maybe, depends on whether user overloads them GS_ASSERT(array->list) GS_ASSERT(array) gsifree(array->list); gsifree(array); }
gsi_u32 wsLoginRemoteAuth(int partnerCode, int namespaceId, const gsi_char authtoken[WS_LOGIN_AUTHTOKEN_LEN], const gsi_char partnerChallenge[WS_LOGIN_PARTNERCHALLENGE_LEN], WSLoginCallback userCallback, void * userData) { GSXmlStreamWriter writer; WSIRequestData * requestData = NULL; //gsi_u8 encryptedChallenge[GS_CRYPT_RSA_BYTE_SIZE]; if (!wsiServiceAvailable()) return WSLogin_NoAvailabilityCheck; GS_ASSERT(partnerCode >= 0); // allocate the request values requestData = (WSIRequestData*)gsimalloc(sizeof(WSIRequestData)); if (requestData == NULL) return WSLogin_OutOfMemory; requestData->mUserCallback.mLoginCallback = userCallback; requestData->mUserData = userData; // encrypt the password (includes safety padding and hash) //wsiLoginEncryptPassword(partnerChallenge, encryptedChallenge); // create the xml request writer = gsXmlCreateStreamWriter(WS_AUTHSERVICE_NAMESPACES, WS_AUTHSERVICE_NAMESPACE_COUNT); if (writer != NULL) { GSSoapTask * aTask = NULL; if (gsi_is_false(gsXmlWriteOpenTag (writer, WS_AUTHSERVICE_NAMESPACE, WS_AUTHSERVICE_LOGINREMOTEAUTH)) || gsi_is_false(gsXmlWriteIntElement (writer, WS_AUTHSERVICE_NAMESPACE, "version", WS_AUTHSERVICE_PROTOVERSION)) || gsi_is_false(gsXmlWriteIntElement (writer, WS_AUTHSERVICE_NAMESPACE, "partnercode", (gsi_u32)partnerCode)) || gsi_is_false(gsXmlWriteIntElement (writer, WS_AUTHSERVICE_NAMESPACE, "namespaceid", (gsi_u32)namespaceId)) || gsi_is_false(gsXmlWriteTStringElement(writer, WS_AUTHSERVICE_NAMESPACE, "authtoken", authtoken)) || gsi_is_false(gsXmlWriteTStringElement(writer, WS_AUTHSERVICE_NAMESPACE, "challenge", partnerChallenge)) || //gsi_is_false(gsXmlWriteOpenTag (writer, WS_AUTHSERVICE_NAMESPACE, "challenge")) || //gsi_is_false(gsXmlWriteHexBinaryElement(writer, WS_AUTHSERVICE_NAMESPACE, "Value", encryptedChallenge, GS_CRYPT_RSA_BYTE_SIZE)) || //gsi_is_false(gsXmlWriteCloseTag (writer, WS_AUTHSERVICE_NAMESPACE, "challenge")) || gsi_is_false(gsXmlWriteCloseTag (writer, WS_AUTHSERVICE_NAMESPACE, WS_AUTHSERVICE_LOGINREMOTEAUTH)) || gsi_is_false(gsXmlCloseWriter (writer)) ) { gsXmlFreeWriter(writer); return WSLogin_OutOfMemory; } aTask = gsiExecuteSoap(wsAuthServiceURL, WS_AUTHSERVICE_LOGINREMOTEAUTH_SOAP, writer, wsLoginRemoteAuthCallback, (void*)requestData); if (aTask == NULL) { gsXmlFreeWriter(writer); gsifree(requestData); return WSLogin_OutOfMemory; } } return 0; }
static void ptaCallPatchCallback ( ptaPatchData * data, PTBool available, PTBool mandatory, const char * versionName, int fileID, const char * downloadURL ) { if(data->callback) { #ifndef GSI_UNICODE data->callback(available, mandatory, versionName, fileID, downloadURL, data->param); #else unsigned short versionName_W[255]; unsigned short downloadURL_W[PTA_MAX_STRING_SIZE*2]; UTF8ToUCS2String(versionName, versionName_W); AsciiToUCS2String(downloadURL, downloadURL_W); data->callback(available, mandatory, versionName_W, fileID, downloadURL_W, data->param); #endif } gsifree(data); }
GHTTPBool ghiSetRequestProxy ( GHTTPRequest request, const char * server ) { // Obtain the connection for this request GHIConnection* connection = ghiRequestToConnection(request); if (connection == NULL) return GHTTPFalse; // Free any existing proxy address. /////////////////////////////////// if(connection->proxyOverrideServer) { gsifree(connection->proxyOverrideServer); connection->proxyOverrideServer = NULL; connection->proxyOverridePort = GHI_DEFAULT_PORT; } // If a server was supplied, try to parse it if(server && *server) return ghiParseProxyServer(server, &connection->proxyOverrideServer, &connection->proxyOverridePort); // No server supplied results in proxy being cleared return GHTTPTrue; }
void FreeBucketSet(bucketset_t set) { assert(set); assert(set->buckets); TableFree(set->buckets); gsifree(set); }
static GVBool gviHardwareInitCapture(GVIDevice * device) { GVIHardwareData * data = (GVIHardwareData *)device->m_data; UInt32 size; OSStatus result; GVICapturedFrame * frame; int numCaptureBufferBytes; int numCaptureBufferFrames; int i; // get the capture format size = sizeof(AudioStreamBasicDescription); result = AudioDeviceGetProperty(device->m_deviceID, 0, true, kAudioDevicePropertyStreamFormat, &size, &data->m_captureStreamDescriptor); if(result != noErr) return GVFalse; // create a converter from the capture format to the GV format result = AudioConverterNew(&data->m_captureStreamDescriptor, &GVIVoiceFormat, &data->m_captureConverter); if(result != noErr) return GVFalse; // allocate a capture buffer data->m_captureBuffer = (GVSample *)gsimalloc(GVIBytesPerFrame); if(!data->m_captureBuffer) { AudioConverterDispose(data->m_captureConverter); return GVFalse; } // allocate space for holding captured frames numCaptureBufferBytes = gviMultiplyByBytesPerMillisecond(GVI_CAPTURE_BUFFER_MILLISECONDS); numCaptureBufferBytes = gviRoundUpToNearestMultiple(numCaptureBufferBytes, GVIBytesPerFrame); numCaptureBufferFrames = (numCaptureBufferBytes / GVIBytesPerFrame); for(i = 0 ; i < numCaptureBufferFrames ; i++) { frame = (GVICapturedFrame *)gsimalloc(sizeof(GVICapturedFrame) + GVIBytesPerFrame - sizeof(GVSample)); if(!frame) { gviFreeCapturedFrames(&data->m_captureAvailableFrames); gsifree(data->m_captureBuffer); AudioConverterDispose(data->m_captureConverter); return GVFalse; } gviPushFirstFrame(&data->m_captureAvailableFrames, frame); } // init the last crossed time data->m_captureLastCrossedThresholdTime = (data->m_captureClock - GVI_HOLD_THRESHOLD_FRAMES - 1); // add property listener AudioDeviceAddPropertyListener(device->m_deviceID, 0, true, kAudioDevicePropertyDeviceIsAlive, gviPropertyListener, device); #if GVI_VOLUME_IN_SOFTWARE // init volume data->m_captureVolume = (GVScalar)1.0; #endif return GVTrue; }
SCResult sciDestroyReport(SCIReport *theReport) { theReport->mReportState = SCIReportState_NONE; theReport->mCurEntityKeyCount = 0; theReport->mCurEntityStartPos = 0; // theReport->mNumPlayersReported = 0; theReport->mNumTeamsReported = 0; theReport->mNumResultsReported = 0; gsifree(theReport->mBuffer.mData); theReport->mBuffer.mData = NULL; theReport->mBuffer.mCapacity = 0; theReport->mBuffer.mLen = 0; theReport->mBuffer.mPos = 0; gsifree(theReport); return SCResult_NO_ERROR; }
static void gviCleanupPlayback(GVIHardwareData * data) { if(data->m_playbackSources) gviFreeSourceList(data->m_playbackSources); if(data->m_playbackConverter) AudioConverterDispose(data->m_playbackConverter); gsifree(data->m_playbackBuffer); }
static void gviCleanupCapture(GVIHardwareData * data) { if(data->m_captureConverter) AudioConverterDispose(data->m_captureConverter); gviFreeCapturedFrames(&data->m_captureAvailableFrames); gviFreeCapturedFrames(&data->m_capturedFrames); gsifree(data->m_captureBuffer); }
void SBServerFree(void *elem) { SBServer server = *(SBServer *)elem; //free all the keys.. TableFree(server->keyvals); server->keyvals = NULL; gsifree(server); }
SCResult SC_CALL sciCreateReport(gsi_u8 theSessionGuid[SC_SESSION_GUID_SIZE], gsi_u32 theHeaderVersion, gsi_u32 thePlayerCount, gsi_u32 theTeamCount, SCIReport ** theReportOut) { SCIReport * theNewReport; SCIReportHeader * theReportHeader; gsi_u8 * theReportData; // roster is [CCID (16) + TeamIndex (4)] * numplayers const gsi_u32 theRosterSize = SC_GUID_BINARY_SIZE * thePlayerCount + SC_REPORT_TEAMINDEX_LENGTH * thePlayerCount; GS_ASSERT(theReportOut != NULL); // allocate the report //GS_ASSERT(0); // todo: memalignment theNewReport = (SCIReport*)gsimalloc(sizeof(SCIReport)); if (theNewReport == NULL) return SCResult_OUT_OF_MEMORY; memset(theNewReport, 0, sizeof(SCIReport)); // allocate the report buffer (holds submission data) theReportData = (gsi_u8*)gsimalloc(SC_REPORT_BUFFER_BYTES); if (theReportData == NULL) { gsifree(theNewReport); return SCResult_OUT_OF_MEMORY; } memset(theReportData, 0, SC_REPORT_BUFFER_BYTES); theNewReport->mBuffer.mIsStatic = gsi_false; theNewReport->mBuffer.mCapacity = SC_REPORT_BUFFER_BYTES; // Fill in report header theReportHeader = (SCIReportHeader*)theReportData; memset(theReportHeader, 0, sizeof(SCIReportHeader)); theReportHeader->mProtocolVersion = htonl(SC_REPORT_PROTOCOL); theReportHeader->mDeveloperVersion = htonl(theHeaderVersion); theReportHeader->mRosterSectionLength = theRosterSize; theReportHeader->mAuthSectionLength = SC_REPORT_AUTHDATA_LENGTH * thePlayerCount; theReportHeader->mResultsSectionLength = SC_REPORT_ENTITYRESULT_LENGTH * (thePlayerCount + theTeamCount); theReportHeader->mPlayerCount = (gsi_u16)thePlayerCount; theReportHeader->mTeamCount = (gsi_u16)theTeamCount; //theReportHeader->mFlags = (gsi_u32)theOptionsFlags; // Finished, return new report theNewReport->mReportState = SCIReportState_ROSTER; theNewReport->mBuffer.mData = (char *)theReportData; theNewReport->mCurEntityStartPos = -1; theNewReport->mNumTeamsReported = 0; *theReportOut = theNewReport; GSI_UNUSED(theSessionGuid); return SCResult_NO_ERROR; }
/****************** ** LOOKUP PENDING** ******************/ void ghiDoLookupPending ( GHIConnection * connection ) { #if !defined(GSI_NO_THREADS) //check if lookup is complete connection->serverIP = gsiGetResolvedIP(*connection->handle); //make sure there were no problems with the IP if (connection->serverIP == GSI_ERROR_RESOLVING_HOSTNAME) { gsDebugFormat(GSIDebugCat_HTTP, GSIDebugType_State, GSIDebugLevel_HotError, "Error resolving hostname\n"); //free handle memory and set to NULL gsifree(connection->handle); connection->handle = NULL; //notify that the lookup failed connection->completed = GHTTPTrue; connection->result = GHTTPHostLookupFailed; return; } if (connection->serverIP == GSI_STILL_RESOLVING_HOSTNAME) { //lookup incomplete - keep calling this function connection->state = GHTTPLookupPending; ghiCallProgressCallback(connection, NULL, 0); } else { //free handle memory and set to NULL gsifree(connection->handle); connection->handle = NULL; gsDebugFormat(GSIDebugCat_HTTP, GSIDebugType_State, GSIDebugLevel_Comment, "DNS lookup complete\n"); //looks like we got ourselves a server! proceed with connection phase connection->state = GHTTPConnecting; ghiCallProgressCallback(connection, NULL, 0); } #endif }
int gsiStartThread(GSThreadFunc func, gsi_u32 theStackSize, void *arg, GSIThreadID *id) { const unsigned int stackSize = theStackSize; const int threadPriority = 3; struct ThreadParam param; void * stack; int threadID; // allocate a stack stack = gsimemalign(16, stackSize); if(!stack) return -1; // setup the thread parameters param.entry = func; param.stack = stack; param.stackSize = (int)stackSize; param.gpReg = &_gp; param.initPriority = threadPriority; // create the thread threadID = CreateThread(¶m); if(threadID == -1) { gsifree(stack); return -1; } // start the thread if(StartThread(threadID, arg) == -1) { DeleteThread(threadID); gsifree(stack); return -1; } // store the id *id = threadID; // Note: This was added to prevent PS2 lockups when starting multiple threads // The PS2 would block for approx 5 seconds msleep(1); return 0; }
static void SAKE_CALL sakeiFreeOutputRecord(int numFields, SAKEField *record) { int i; if(!record) return; //Check for binary data or unicode strings and free it if necessary for (i = 0; i < numFields; i++) { if (record[i].mType == SAKEFieldType_BINARY_DATA && record[i].mValue.mBinaryData.mValue != NULL) gsifree(record[i].mValue.mBinaryData.mValue); if (record[i].mType == SAKEFieldType_UNICODE_STRING) gsifree(record[i].mValue.mUnicodeString); } gsifree(record); }
static void WatchKeysFree ( void * elem ) { piWatchKey * key = (piWatchKey *)elem; gsifree(key->key); }
void gsiCleanupThread(GSIThreadID theThreadID) { OS_DestroyThread(&theThreadID.mThread); if(theThreadID.mStack) { gsifree(theThreadID.mStack); theThreadID.mStack = NULL; } }
/************** ** FUNCTIONS ** **************/ static void gviFreeCapturedFrames(GVICapturedFrame * frameHead) { GVICapturedFrame * frame; while(frameHead->m_next) { frame = frameHead->m_next; frameHead->m_next = frame->m_next; gsifree(frame); } }
// Frees a lock. //////////////// static void GFreeLock(GLock lock) { CRITICAL_SECTION * criticalSection = (CRITICAL_SECTION *)lock; if(!lock) return; DeleteCriticalSection(criticalSection); gsifree(criticalSection); }
static void ptaCallFilePlanetInfoCallback ( ptaFilePlanetInfoData * data, PTBool found, const char * description, const char * size, int numMirrors, char ** mirrorNames, char ** mirrorURLs ) { int i; if(data->callback) { if (!found) data->callback(data->fileID, PTFalse, NULL, NULL, 0, NULL, NULL, data->param); else { #ifndef GSI_UNICODE data->callback(data->fileID, found, description, size, numMirrors, (const char**)mirrorNames, (const char**)mirrorURLs, data->param); #else unsigned short description_W[255]; unsigned short size_W[1024]; unsigned short** mirrorNames_W; unsigned short** mirrorURLs_W; int i; UTF8ToUCS2String(description, description_W); AsciiToUCS2String(size, size_W); mirrorNames_W = UTF8ToUCS2StringArrayAlloc((const UTF8String *)mirrorNames, numMirrors); mirrorURLs_W = UTF8ToUCS2StringArrayAlloc((const UTF8String *)mirrorURLs, numMirrors); data->callback(data->fileID, found, description_W, size_W, numMirrors, (const unsigned short**)mirrorNames_W, (const unsigned short**)mirrorURLs_W, data->param); for (i=0; i < numMirrors; i++) { gsifree(mirrorNames[i]); gsifree(mirrorURLs[i]); } gsifree(mirrorNames); gsifree(mirrorURLs); #endif } } for(i = 0 ; i < numMirrors ; i++) { gsifree(mirrorNames[i]); gsifree(mirrorURLs[i]); } gsifree(data); }
/************** ** FUNCTIONS ** **************/ static void gviFreeArrayDevice(void * elem) { GVIDevice * device = *(GVIDevice **)elem; GVIPS2EyetoyData * data = (GVIPS2EyetoyData *)device->m_data; // close the device lgVidClose(data->m_handle); // cleanup the buffer gsifree(data->m_captureBuffer); // free the device gviFreeDevice(device); }
static void *DoSet(bucket_t *pbucket, void *value) { if (pbucket->type == bt_int) pbucket->vals.ival = *(int*)value; else if (pbucket->type == bt_float) pbucket->vals.fval = *(double *)value; else if (pbucket->type == bt_string) { if (pbucket->vals.sval != NULL) gsifree(pbucket->vals.sval); pbucket->vals.sval = (value == NULL ? NULL : stripchars(goastrdup((char *)value))); } return DoGet(pbucket); }
void ciSocketDisconnect(ciSocket * sock) { int i; ASSERT_SOCK(sock); // Shutdown the socket. /////////////////////// if(sock->sock != INVALID_SOCKET) { shutdown(sock->sock, 2); closesocket(sock->sock); } // We're disconnected. ////////////////////// sock->connectState = ciDisconnected; // gsifree the buffers. //////////////////// ciBufferFree(&sock->inputQueue); ciBufferFree(&sock->outputQueue); // gsifree the last-message pointers. ////////////////////////////////// gsifree(sock->lastMessage.message); gsifree(sock->lastMessage.server); gsifree(sock->lastMessage.nick); gsifree(sock->lastMessage.user); gsifree(sock->lastMessage.host); gsifree(sock->lastMessage.command); gsifree(sock->lastMessage.middle); gsifree(sock->lastMessage.param); for(i = 0 ; i < sock->lastMessage.numParams ; i++) gsifree(sock->lastMessage.params[i]); gsifree(sock->lastMessage.params); }
static void piPlayerChangedNickMap ( void * elem, void * clientData ) { piCacheKey * key = (piCacheKey *)elem; piPlayerChangedNickMapData * data = (piPlayerChangedNickMapData *)clientData; if(strcasecmp(key->nick, data->oldNick) == 0) { gsifree(key->nick); key->nick = goastrdup(data->newNick); } }
static int gviCountChannels(AudioDeviceID deviceID, bool input) { OSStatus result; UInt32 size; AudioBufferList * list; int numChannels; int i; // get the size of the buffer list result = AudioDeviceGetPropertyInfo(deviceID, 0, input, kAudioDevicePropertyStreamConfiguration, &size, NULL); if(result != noErr) return 0; // allocate the buffer list list = (AudioBufferList *)gsimalloc(size); if(list == NULL) return 0; // fill the buffer list result = AudioDeviceGetProperty(deviceID, 0, input, kAudioDevicePropertyStreamConfiguration, &size, list); if(result != noErr) { gsifree(list); return 0; } // count the number of channels numChannels = 0; for(i = 0 ; i < list->mNumberBuffers ; i++) numChannels += list->mBuffers[i].mNumberChannels; // free the list gsifree(list); return numChannels; }
void *BucketConcat(bucketset_t set, char *name, void *value) { bucket_t *pbucket = DoFind(set, name); char *temp, *s; if (!pbucket) return NULL; assert(pbucket->type == bt_string); s = DoGet(pbucket); temp = (char *)gsimalloc(strlen(s) + strlen(value) + 1); strcpy(temp,s); strcat(temp, value); DoSet(pbucket, temp); gsifree(temp); return DoGet(pbucket); }