CIwHTTPQueue::~CIwHTTPQueue() { if (g_Result) { s3eFree(g_Result); } for (int u=m_Request.size()-1;u>=0;u--) { delete[] (char*)m_Request[u].pURL; } m_Request.clear(); }
bool CIwHTTPQueue::IsSizeAllowed() { if(m_MaxFileSize>=0) { if((int32)g_ResultLen>m_MaxFileSize) { if(g_Result) { s3eFree(g_Result); // Free now to avoid calling file callback g_Result = 0; } g_GotResult = true; // Set true to advance to next file in update call return false; } } return true; }
static int32 GotData(void* object, void*) { CIwHTTP * theHttpObject = (CIwHTTP*)object; // This is the callback indicating that a ReadContent call has // completed. Either we've finished, or a bigger buffer is // needed. If the correct ammount of data was supplied initially, // then this will only be called once. However, it may well be // called several times when using chunked encoding. // Firstly see if there's an error condition. if (theHttpObject->GetStatus() == S3E_RESULT_ERROR) { // Free data now s3eFree(g_Result); g_Result = 0; g_GotResult = true; } else if (theHttpObject->ContentReceived() != theHttpObject->ContentLength()) { // We have some data but not all of it. We need more space. uint32 oldLen = g_ResultLen; // If iwhttp has a guess how big the next bit of data is (this // basically means chunked encoding is being used), allocate // that much space. Otherwise guess. if (g_ResultLen < theHttpObject->ContentExpected()) g_ResultLen = theHttpObject->ContentExpected(); else g_ResultLen += 1024; if(!IwGetHTTPQueue()->IsSizeAllowed()) return 0; // Allocate some more space and fetch the data. g_Result = (char*)s3eRealloc(g_Result, g_ResultLen); theHttpObject->ReadContent(&g_Result[oldLen], g_ResultLen - oldLen, GotData); } else { uint32 code = theHttpObject->GetResponseCode(); g_ResultLen = theHttpObject->ContentReceived(); g_GotResult = true; _STL::string imageType; theHttpObject->GetHeader("content-type", imageType); const char* szImageType = imageType.c_str(); int len = strlen(szImageType); char* szImageTypeCpy = new char[len+1]; strcpy(szImageTypeCpy, szImageType); for (int i = 0; i < len;++i) { szImageTypeCpy[i] = tolower(szImageTypeCpy[i]); } strcpy((char*)g_szContentType, szImageTypeCpy); delete[] szImageTypeCpy; } return 0; }
void CIwHTTPQueue::Update() { if (m_Request.size()) { if (g_GotResult) { m_HTTP.Cancel(); g_GotResult = false; Request request = m_Request[0]; m_Request.erase(0); if (g_Result) { // Call the requests callback with the received data if (request.Callback) { request.Callback(request.pArgument, (const char*)g_szContentType, g_Result, g_ResultLen); } // Free result s3eFree(g_Result); g_szContentType[0] = 0; g_Result = 0; } else { if (request.CallbackError) { request.CallbackError(request.pArgument); } } delete[] (char*)request.pURL; // Begin fetching the next request if (m_Request.size()) { if (m_Request[0].Callback) { if (m_Request[0].usePost) { m_timeout = m_Request[0].timeout; m_requestStart = s3eTimerGetMs(); m_HTTP.Post(m_Request[0].pURL, m_Request[0].szBuffer, m_Request[0].bufferLen, GotHeaders, NULL); } else { m_timeout = m_Request[0].timeout; m_requestStart = s3eTimerGetMs(); m_HTTP.Get(m_Request[0].pURL, GotHeaders, NULL); } } else { g_GotResult = true; } } } else { uint64 now = s3eTimerGetMs(); if (m_Request[0].timeout != -1 && (now - m_requestStart) > m_Request[0].timeout) { m_Request[0].timeout = -1; g_GotResult = true; m_HTTP.Cancel(); s3eDeviceYield(0); } } } }
bool ExampleUpdate() { Button* pressed = GetSelectedButton(); if (pressed && pressed == g_MessageBox) s3eNewMessageBox("Title", "Hello world"); else if (pressed && pressed == g_NOFInitialize) { s3eNOFSettingVal *settings = (s3eNOFSettingVal*)s3eMalloc(sizeof(s3eNOFSettingVal) * 7); // Fill settings // UIOrientation value strncpy(settings[0].m_varName, "OpenFeintSettingDashboardOrientation", S3E_NOPENFEINT_SETTINGS_STRING_MAX); settings[0].m_intVal = s3eNOFUIInterfaceOrientationPortrait; // Shortdisplay name strncpy(settings[1].m_varName, "OpenFeintSettingShortDisplayName", S3E_NOPENFEINT_SETTINGS_STRING_MAX); strncpy(settings[1].m_stringVal, "FunkyRacers", S3E_NOPENFEINT_STRING_MAX); // Push Notification Setting strncpy(settings[2].m_varName, "OpenFeintSettingEnablePushNotifications", S3E_NOPENFEINT_SETTINGS_STRING_MAX); settings[2].m_intVal = 1; // TRUE/YES // Sandbox Notification Mode strncpy(settings[3].m_varName, "OpenFeintSettingUseSandboxPushNotificationServer", S3E_NOPENFEINT_SETTINGS_STRING_MAX); settings[3].m_intVal = 1; // Disable User generated content strncpy(settings[4].m_varName, "OpenFeintSettingDisableUserGeneratedContent", S3E_NOPENFEINT_SETTINGS_STRING_MAX); settings[4].m_intVal = 0; // Disable ask for approval in debug mode strncpy(settings[5].m_varName, "OpenFeintSettingAlwaysAskForApprovalInDebug", S3E_NOPENFEINT_SETTINGS_STRING_MAX); settings[5].m_intVal = 0; // Add GameId in settings as well as Android needs it strncpy(settings[1].m_varName, "GameID", S3E_NOPENFEINT_SETTINGS_STRING_MAX); strncpy(settings[1].m_stringVal, "330603", S3E_NOPENFEINT_STRING_MAX); s3eNOFArray array; array.m_count = 7; array.m_items = settings; s3eNOFinitializeWithProductKey("TD5741bq5dsEWStKk3rdMA", "HgjtDJBBRW8sBfASq9Iv6hDAfchXAHMYJvNU5gQ0", "RacingGame", &array); s3eFree(settings); AppendMessageColour(GREEN, "Called s3eNOFinitializeWithProductKey"); //g_doRender1 = false; // Lets try to give the API the token // const char* deviceToken = s3eIOSNotificationsGetRemoteNotificationToken(); // char tmp[40]; // const char *tmp1 = deviceToken; // memset(tmp,'\0', sizeof(tmp)); // // // need to get rid of spaces in middle // int i =0; // while(*tmp1) // { // if(*tmp1!=' ') // { // // not a space. we can copy // tmp[i] = *tmp1; // i++; // } // tmp1++; // } // // if (deviceToken) { // AppendMessageColour(BLUE,"Device token is %s",tmp); // s3eNOFapplicationDidRegisterForRemoteNotificationsWithDeviceToke(tmp); // } } else if (pressed && pressed == g_NOFShutdown) { s3eNOFshutdown(); AppendMessageColour(GREEN, "Called s3eNOFshutdown"); } else if (pressed && pressed == g_NOFLaunchDashboard) { // s3eNOFlaunchDashboard(); s3eNOFlaunchDashboard(); AppendMessageColour(GREEN, "Called s3eNOFlaunchDashboardWithListLeaderboardsPage"); } else if (pressed && pressed == g_NOFTestButton1) { /*const unsigned int max_achievements = 20; // whatever we think is max we need void* data = s3eMalloc(sizeof(s3eNOFAchievement) * max_achievements); if (data == NULL) { AppendMessageColour(RED, ("Couldn't allocate data")); return false; } s3eNOFArray achArray; achArray.m_items = data; achArray.m_count = max_achievements; s3eNOFachievements(&achArray); // AppendMessage("Size of achievement %d and double %d", // sizeof(s3eNOFAchievement), // sizeof(double)); for (uint i=0; i < achArray.m_count && i < max_achievements; i++) { // s3eNOFAchievement* ach = &((s3eNOFAchievement*)achArray.m_items[i]); // AppendMessage("Ach at %p", &((s3eNOFAchievement*)achArray.m_items)[i]); AppendMessage("Acheivement title %s", ((s3eNOFAchievement*)achArray.m_items)[i].title); } s3eFree(data);*/ //AppendMessage("Updating achievement 1205572"); // s3eNOFupdateAcheivementProgressionComplete("1205572", "77", true); // last param is ignored for android s3eNOFlaunchDashboardWithListLeaderboardsPage(); } else if (pressed && pressed == g_NOFTestButton2) { //s3eNOFdisplayAndSendChallenge(&g_nofChallengeDefinitions[1]); /* s3eNOFchallengeCompleteWithResult(kNOFChallengeResultRecipientLost, persistentChallengeId); AppendMessageColour(GREEN, "Called s3eNOFchallengeCompleteWithResult"); s3eNOFChallengeData chalData; const char *dd = "SCORE=5"; chalData.data = (void*)dd; chalData.length = strlen(dd); s3eNOFchallengeDisplayCompletionWithData(&chalData, "Challenge Lost", persistentChallengeId); AppendMessageColour(GREEN, "Called s3eNOFchallengeDisplayCompletionWithData"); */ /* s3eNOFAchievement *ach = (s3eNOFAchievement*)s3eMalloc(sizeof(s3eNOFAchievement)); AppendMessageColour(GREEN,"Calling s3eNOFachievement"); s3eNOFachievement(ach, "1117662"); AppendMessage("Achievement title %s", ach->title); // AppendMessage("Achievement description %s", ach->description); s3eFree(ach); */ //AppendMessage("Unlocking achievement 1117662"); // s3eNOFachievementUnlock("1117662"); // AppendMessage("User approved %d", s3eNOFhasUserApprovedFeint()); // AppendMessage("User is Online %d", s3eNOFisOnline()); // s3eNOFsubmitHighScore("844216", "50", "Beaten by Android", NULL); s3eNOFlaunchDashboardWithHighscorePage("844216"); } return true; }