Example #1
0
QByteArray Oauth::HmacSha1(QString secretKey, QString data, QString tokenSecret)
{
    QString signingKey = QString("%1&%2").arg(Escape(secretKey),Escape(tokenSecret));

    unsigned char result[EVP_MAX_MD_SIZE];
    unsigned int resultlen = 0;
    HMAC(
         EVP_sha1(),
         qPrintable(signingKey),
         signingKey.toLocal8Bit().length(),
         (unsigned char*)data.toLocal8Bit().data(),
         data.toLocal8Bit().length(),
         result,
         &resultlen
         );
    char* cbase64 = base64(result,resultlen);
    QByteArray resultArray(cbase64);
    qDebug() << resultArray;
    resultArray = resultArray.toPercentEncoding();
    free(cbase64);
    return resultArray;
}
hkDemo::Result WorldRayCastMultithreadedDemo::stepDemo()
{
	// const WorldRayCastMultithreadedDemoVariant& variant = g_WorldRayCastMultithreadedDemoVariants[m_variantId];

	m_time += m_timestep;

	// The start point of the ray remains fixed in world space with the destination point of the
	// ray being varied in both the X and Y directions. This is achieved with simple
	// sine and cosine functions calls using the current time as the varying parameter:

	hkReal xDir = 12.0f * hkMath::sin(m_time * 0.3f);
	hkReal yDir = 12.0f * hkMath::cos(m_time * 0.3f);

	// For this demo an array of size 1 is sufficient.
	hkArray<hkpWorldRayCastOutput> resultArray(1);

	const int numCommands = 1;
	hkArray<hkpWorldRayCastCommand> commands(numCommands);
	{
		hkpWorldRayCastCommand& command = commands[0];
		command.m_rayInput.m_from							. set(0.0f, 0.0f, 15.0f);
		command.m_rayInput.m_to								. set( xDir, yDir, -15.0f);
		command.m_rayInput.m_enableShapeCollectionFilter	= false;
		command.m_rayInput.m_filterInfo						= 0;
		command.m_results									= resultArray.begin();
		command.m_resultsCapacity							= 1;
		command.m_numResultsOut								= 0;
	}

	//
	// create the job header
	//
	hkpCollisionQueryJobHeader* jobHeader;
	{
		jobHeader = hkAllocateChunk<hkpCollisionQueryJobHeader>(1, HK_MEMORY_CLASS_DEMO);
	}

	//
	// setup hkpWorldRayCastJob
	//
	m_world->markForRead();
	hkpWorldRayCastJob worldRayCastJob(m_world->getCollisionInput(), jobHeader, commands.begin(), numCommands, m_world->m_broadPhase, &m_semaphore);
	m_world->unmarkForRead();

	//
	// Put the job on the queue, kick-off the PPU/SPU threads and wait for everything to finish.
	//
	{
		m_world->lockReadOnly();

		//
		// Put the raycast job on the job queue.
		//


		worldRayCastJob.setRunsOnSpuOrPpu();
		m_jobQueue->addJob( worldRayCastJob, hkJobQueue::JOB_LOW_PRIORITY );

		m_jobThreadPool->processAllJobs( m_jobQueue );

		m_jobThreadPool->waitForCompletion();

		//
		// Wait for the one single job we started to finish.
		//
		m_semaphore.acquire();

		m_world->unlockReadOnly();
	}

	//
	// Display results.
	//
	if( commands[0].m_numResultsOut > 0 )
	{
		hkVector4 intersectionPointWorld;
		intersectionPointWorld.setInterpolate4( commands[0].m_rayInput.m_from, commands[0].m_rayInput.m_to, commands[0].m_results->m_hitFraction );
		HK_DISPLAY_LINE( commands[0].m_rayInput.m_from, intersectionPointWorld, hkColor::RED);
		HK_DISPLAY_ARROW( intersectionPointWorld, commands[0].m_results->m_normal, hkColor::CYAN);
	}
	else
	{
		// Otherwise draw as GREY
		HK_DISPLAY_LINE(commands[0].m_rayInput.m_from, commands[0].m_rayInput.m_to, hkColor::rgbFromChars(200, 200, 200));
	}

	//
	// Free temporarily allocated memory.
	//
	hkDeallocateChunk(jobHeader, 1, HK_MEMORY_CLASS_DEMO);

	return hkDefaultPhysicsDemo::stepDemo();
}
NS_IMETHODIMP
MailEwsLoadCalendarItemsCallback::LocalOperation(void * response) {
    load_item_response * r = (load_item_response *)response;
    if (!r) return NS_OK;

    ews_item ** item = r->item;
    nsresult rv;

    mailews_logger << "create calIEvent on main threads:"
                   << r->item_count
                   << std::endl;

    nsCOMPtr<nsIMutableArray> calendarItems =
		    do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCString ownerEmail;
	rv = GetOwnerEmail(m_pIncomingServer, ownerEmail);
	NS_ENSURE_SUCCESS(rv, rv);

    for(int i=0;i < r->item_count;i++) {
        if (item[i]->item_type == EWS_Item_Calendar) {
            ews_calendar_item * cal_item = (ews_calendar_item*)item[i];

	        nsCOMPtr<calIEvent> e =
			        do_CreateInstance(CAL_EVENT_CONTRACTID, &rv);
	        NS_ENSURE_SUCCESS(rv, rv);

            if (item[i]->mime_content) {
                char *decodedContent =
                        PL_Base64Decode(item[i]->mime_content,
                                        strlen(item[i]->mime_content),
                                        nullptr);
                nsCString data;
                data.Adopt(decodedContent);

                CleanUpIcalString(data);

                rv = e->SetIcalString(data);
                NS_ENSURE_SUCCESS(rv, rv);

                nsCString uid(((ews_calendar_item*)item[i])->uid);
                
                if (uid.IsEmpty()) {
                    GenerateUid(uid);
                    mailews_logger << "generate uid for event:"
                                   << item[i]->item_id
                                   << ","
                                   << item[i]->change_key
                                   << ","
                                   << uid.get()
                                   << std::endl
                                   << data.get()
                                   << std::endl;
                }
                e->SetId(uid);

                nsCOMPtr<calIDateTime> dtStart;
                e->GetStartDate(getter_AddRefs(dtStart));

                if (!dtStart) {
                    mailews_logger << "skip no start date event:"
                                   << item[i]->item_id
                                   << ","
                                   << item[i]->change_key
                                   << ","
                                   << uid.get()
                                   << std::endl
                                   << data.get()
                                   << std::endl;
                    continue;
                }

                rv = e->RemoveAllAttendees();
                NS_ENSURE_SUCCESS(rv, rv);
	
                rv = UpdateAttendee(e,
                                    (ews_calendar_item*)item[i],
                                    ownerEmail,
                                    true);
                NS_ENSURE_SUCCESS(rv, rv);
                rv = UpdateAttendee(e,
                                    (ews_calendar_item*)item[i],
                                    ownerEmail,
                                    false);
                NS_ENSURE_SUCCESS(rv, rv);
                rv = UpdateOccurrence(e,
                                      (ews_calendar_item*)item[i]);
                NS_ENSURE_SUCCESS(rv, rv);

                rv = UpdateStatus(e,
                                  ownerEmail);
                NS_ENSURE_SUCCESS(rv, rv);
            } else {
                rv = From(m_pIncomingServer,
                          (ews_calendar_item *)item[i], e);
                NS_ENSURE_SUCCESS(rv, rv);
            }

	        //Save item id
            rv = SetPropertyString(e,
                                   NS_LITERAL_STRING("X-ITEM-ID"),
                                   nsCString(item[i]->item_id));
	        NS_ENSURE_SUCCESS(rv, rv);

	        //Save change key
            rv = SetPropertyString(e,
                                   NS_LITERAL_STRING("X-CHANGE-KEY"),
                                   nsCString(item[i]->change_key));
	        NS_ENSURE_SUCCESS(rv, rv);

            //Save Master id
            if (cal_item->recurring_master_id) {
                rv = SetPropertyString(e,
                                       NS_LITERAL_STRING("X-MASTER_ID"),
                                       nsCString(cal_item->recurring_master_id));
                NS_ENSURE_SUCCESS(rv, rv);

                rv = SetPropertyString(e,
                                       NS_LITERAL_STRING("X-MASTER_UID"),
                                       nsCString(cal_item->recurring_master_uid));
                NS_ENSURE_SUCCESS(rv, rv);
            } else if (cal_item->calendar_item_type ==
                       EWS_CalendarItemType_Single) {
                e->SetRecurrenceId(nullptr);
            }

	        calendarItems->AppendElement(e, false);
        }
    }

    nsCOMPtr<nsIArray> resultArray(do_QueryInterface(calendarItems));
    
    mailews_logger << "create calIEvent on main threads done:"
                   << r->item_count
                   << std::endl;
    return m_pCalCallback->OnResult(resultArray);
}